iPXE
scsi.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stddef.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <byteswap.h>
30 #include <errno.h>
31 #include <ipxe/list.h>
32 #include <ipxe/process.h>
33 #include <ipxe/xfer.h>
34 #include <ipxe/blockdev.h>
35 #include <ipxe/scsi.h>
36 
37 /** @file
38  *
39  * SCSI block device
40  *
41  */
42 
43 /** Maximum number of TEST UNIT READY retries */
44 #define SCSI_READY_MAX_RETRIES 10
45 
46 /* Error numbers generated by SCSI sense data */
47 #define EIO_NO_SENSE __einfo_error ( EINFO_EIO_NO_SENSE )
48 #define EINFO_EIO_NO_SENSE \
49  __einfo_uniqify ( EINFO_EIO, 0x00, "No sense" )
50 #define EIO_RECOVERED_ERROR __einfo_error ( EINFO_EIO_RECOVERED_ERROR )
51 #define EINFO_EIO_RECOVERED_ERROR \
52  __einfo_uniqify ( EINFO_EIO, 0x01, "Recovered error" )
53 #define EIO_NOT_READY __einfo_error ( EINFO_EIO_NOT_READY )
54 #define EINFO_EIO_NOT_READY \
55  __einfo_uniqify ( EINFO_EIO, 0x02, "Not ready" )
56 #define EIO_MEDIUM_ERROR __einfo_error ( EINFO_EIO_MEDIUM_ERROR )
57 #define EINFO_EIO_MEDIUM_ERROR \
58  __einfo_uniqify ( EINFO_EIO, 0x03, "Medium error" )
59 #define EIO_HARDWARE_ERROR __einfo_error ( EINFO_EIO_HARDWARE_ERROR )
60 #define EINFO_EIO_HARDWARE_ERROR \
61  __einfo_uniqify ( EINFO_EIO, 0x04, "Hardware error" )
62 #define EIO_ILLEGAL_REQUEST __einfo_error ( EINFO_EIO_ILLEGAL_REQUEST )
63 #define EINFO_EIO_ILLEGAL_REQUEST \
64  __einfo_uniqify ( EINFO_EIO, 0x05, "Illegal request" )
65 #define EIO_UNIT_ATTENTION __einfo_error ( EINFO_EIO_UNIT_ATTENTION )
66 #define EINFO_EIO_UNIT_ATTENTION \
67  __einfo_uniqify ( EINFO_EIO, 0x06, "Unit attention" )
68 #define EIO_DATA_PROTECT __einfo_error ( EINFO_EIO_DATA_PROTECT )
69 #define EINFO_EIO_DATA_PROTECT \
70  __einfo_uniqify ( EINFO_EIO, 0x07, "Data protect" )
71 #define EIO_BLANK_CHECK __einfo_error ( EINFO_EIO_BLANK_CHECK )
72 #define EINFO_EIO_BLANK_CHECK \
73  __einfo_uniqify ( EINFO_EIO, 0x08, "Blank check" )
74 #define EIO_VENDOR_SPECIFIC __einfo_error ( EINFO_EIO_VENDOR_SPECIFIC )
75 #define EINFO_EIO_VENDOR_SPECIFIC \
76  __einfo_uniqify ( EINFO_EIO, 0x09, "Vendor specific" )
77 #define EIO_COPY_ABORTED __einfo_error ( EINFO_EIO_COPY_ABORTED )
78 #define EINFO_EIO_COPY_ABORTED \
79  __einfo_uniqify ( EINFO_EIO, 0x0a, "Copy aborted" )
80 #define EIO_ABORTED_COMMAND __einfo_error ( EINFO_EIO_ABORTED_COMMAND )
81 #define EINFO_EIO_ABORTED_COMMAND \
82  __einfo_uniqify ( EINFO_EIO, 0x0b, "Aborted command" )
83 #define EIO_RESERVED __einfo_error ( EINFO_EIO_RESERVED )
84 #define EINFO_EIO_RESERVED \
85  __einfo_uniqify ( EINFO_EIO, 0x0c, "Reserved" )
86 #define EIO_VOLUME_OVERFLOW __einfo_error ( EINFO_EIO_VOLUME_OVERFLOW )
87 #define EINFO_EIO_VOLUME_OVERFLOW \
88  __einfo_uniqify ( EINFO_EIO, 0x0d, "Volume overflow" )
89 #define EIO_MISCOMPARE __einfo_error ( EINFO_EIO_MISCOMPARE )
90 #define EINFO_EIO_MISCOMPARE \
91  __einfo_uniqify ( EINFO_EIO, 0x0e, "Miscompare" )
92 #define EIO_COMPLETED __einfo_error ( EINFO_EIO_COMPLETED )
93 #define EINFO_EIO_COMPLETED \
94  __einfo_uniqify ( EINFO_EIO, 0x0f, "Completed" )
95 #define EIO_SENSE( key ) \
96  EUNIQ ( EINFO_EIO, (key), EIO_NO_SENSE, EIO_RECOVERED_ERROR, \
97  EIO_NOT_READY, EIO_MEDIUM_ERROR, EIO_HARDWARE_ERROR, \
98  EIO_ILLEGAL_REQUEST, EIO_UNIT_ATTENTION, \
99  EIO_DATA_PROTECT, EIO_BLANK_CHECK, EIO_VENDOR_SPECIFIC, \
100  EIO_COPY_ABORTED, EIO_ABORTED_COMMAND, EIO_RESERVED, \
101  EIO_VOLUME_OVERFLOW, EIO_MISCOMPARE, EIO_COMPLETED )
102 
103 /******************************************************************************
104  *
105  * Utility functions
106  *
107  ******************************************************************************
108  */
109 
110 /**
111  * Parse SCSI LUN
112  *
113  * @v lun_string LUN string representation
114  * @v lun LUN to fill in
115  * @ret rc Return status code
116  */
117 int scsi_parse_lun ( const char *lun_string, struct scsi_lun *lun ) {
118  char *p;
119  int i;
120 
121  memset ( lun, 0, sizeof ( *lun ) );
122  if ( lun_string ) {
123  p = ( char * ) lun_string;
124  for ( i = 0 ; i < 4 ; i++ ) {
125  lun->u16[i] = htons ( strtoul ( p, &p, 16 ) );
126  if ( *p == '\0' )
127  break;
128  if ( *p != '-' )
129  return -EINVAL;
130  p++;
131  }
132  if ( *p )
133  return -EINVAL;
134  }
135 
136  return 0;
137 }
138 
139 /**
140  * Parse SCSI sense data
141  *
142  * @v data Raw sense data
143  * @v len Length of raw sense data
144  * @v sense Descriptor-format sense data to fill in
145  */
146 void scsi_parse_sense ( const void *data, size_t len,
147  struct scsi_sns_descriptor *sense ) {
148  const union scsi_sns *sns = data;
149 
150  /* Avoid returning uninitialised data */
151  memset ( sense, 0, sizeof ( *sense ) );
152 
153  /* Copy, assuming descriptor-format data */
154  if ( len < sizeof ( sns->desc ) )
155  return;
156  memcpy ( sense, &sns->desc, sizeof ( *sense ) );
157 
158  /* Convert fixed-format to descriptor-format, if applicable */
159  if ( len < sizeof ( sns->fixed ) )
160  return;
161  if ( ! SCSI_SENSE_FIXED ( sns->code ) )
162  return;
163  sense->additional = sns->fixed.additional;
164 }
165 
166 /******************************************************************************
167  *
168  * Interface methods
169  *
170  ******************************************************************************
171  */
172 
173 /**
174  * Issue SCSI command
175  *
176  * @v control SCSI control interface
177  * @v data SCSI data interface
178  * @v command SCSI command
179  * @ret tag Command tag, or negative error
180  */
181 int scsi_command ( struct interface *control, struct interface *data,
182  struct scsi_cmd *command ) {
183  struct interface *dest;
184  scsi_command_TYPE ( void * ) *op =
186  void *object = intf_object ( dest );
187  int tap;
188 
189  if ( op ) {
190  tap = op ( object, data, command );
191  } else {
192  /* Default is to fail to issue the command */
193  tap = -EOPNOTSUPP;
194  }
195 
196  intf_put ( dest );
197  return tap;
198 }
199 
200 /**
201  * Report SCSI response
202  *
203  * @v interface SCSI command interface
204  * @v response SCSI response
205  */
206 void scsi_response ( struct interface *intf, struct scsi_rsp *response ) {
207  struct interface *dest;
208  scsi_response_TYPE ( void * ) *op =
210  void *object = intf_object ( dest );
211 
212  if ( op ) {
213  op ( object, response );
214  } else {
215  /* Default is to ignore the response */
216  }
217 
218  intf_put ( dest );
219 }
220 
221 /******************************************************************************
222  *
223  * SCSI devices and commands
224  *
225  ******************************************************************************
226  */
227 
228 /** A SCSI device */
229 struct scsi_device {
230  /** Reference count */
231  struct refcnt refcnt;
232  /** Block control interface */
233  struct interface block;
234  /** SCSI control interface */
235  struct interface scsi;
236 
237  /** SCSI LUN */
238  struct scsi_lun lun;
239  /** Flags */
240  unsigned int flags;
241 
242  /** TEST UNIT READY interface */
243  struct interface ready;
244  /** TEST UNIT READY process */
245  struct process process;
246  /** TEST UNIT READY retry count */
247  unsigned int retries;
248 
249  /** List of commands */
250  struct list_head cmds;
251 };
252 
253 /** SCSI device flags */
255  /** TEST UNIT READY has been issued */
257  /** TEST UNIT READY has completed successfully */
259 };
260 
261 /** A SCSI command */
262 struct scsi_command {
263  /** Reference count */
264  struct refcnt refcnt;
265  /** SCSI device */
267  /** List of SCSI commands */
268  struct list_head list;
269 
270  /** Block data interface */
271  struct interface block;
272  /** SCSI data interface */
273  struct interface scsi;
274 
275  /** Command type */
277  /** Starting logical block address */
279  /** Number of blocks */
280  unsigned int count;
281  /** Data buffer */
283  /** Length of data buffer */
284  size_t len;
285  /** Command tag */
287 
288  /** Private data */
290 };
291 
292 /** A SCSI command type */
294  /** Name */
295  const char *name;
296  /** Additional working space */
297  size_t priv_len;
298  /**
299  * Construct SCSI command IU
300  *
301  * @v scsicmd SCSI command
302  * @v command SCSI command IU
303  */
304  void ( * cmd ) ( struct scsi_command *scsicmd,
305  struct scsi_cmd *command );
306  /**
307  * Handle SCSI command completion
308  *
309  * @v scsicmd SCSI command
310  * @v rc Reason for completion
311  */
312  void ( * done ) ( struct scsi_command *scsicmd, int rc );
313 };
314 
315 /**
316  * Get reference to SCSI device
317  *
318  * @v scsidev SCSI device
319  * @ret scsidev SCSI device
320  */
321 static inline __attribute__ (( always_inline )) struct scsi_device *
322 scsidev_get ( struct scsi_device *scsidev ) {
323  ref_get ( &scsidev->refcnt );
324  return scsidev;
325 }
326 
327 /**
328  * Drop reference to SCSI device
329  *
330  * @v scsidev SCSI device
331  */
332 static inline __attribute__ (( always_inline )) void
333 scsidev_put ( struct scsi_device *scsidev ) {
334  ref_put ( &scsidev->refcnt );
335 }
336 
337 /**
338  * Get reference to SCSI command
339  *
340  * @v scsicmd SCSI command
341  * @ret scsicmd SCSI command
342  */
343 static inline __attribute__ (( always_inline )) struct scsi_command *
344 scsicmd_get ( struct scsi_command *scsicmd ) {
345  ref_get ( &scsicmd->refcnt );
346  return scsicmd;
347 }
348 
349 /**
350  * Drop reference to SCSI command
351  *
352  * @v scsicmd SCSI command
353  */
354 static inline __attribute__ (( always_inline )) void
355 scsicmd_put ( struct scsi_command *scsicmd ) {
356  ref_put ( &scsicmd->refcnt );
357 }
358 
359 /**
360  * Get SCSI command private data
361  *
362  * @v scsicmd SCSI command
363  * @ret priv Private data
364  */
365 static inline __attribute__ (( always_inline )) void *
366 scsicmd_priv ( struct scsi_command *scsicmd ) {
367  return scsicmd->priv;
368 }
369 
370 /**
371  * Free SCSI command
372  *
373  * @v refcnt Reference count
374  */
375 static void scsicmd_free ( struct refcnt *refcnt ) {
376  struct scsi_command *scsicmd =
377  container_of ( refcnt, struct scsi_command, refcnt );
378 
379  /* Drop reference to SCSI device */
380  scsidev_put ( scsicmd->scsidev );
381 
382  /* Free command */
383  free ( scsicmd );
384 }
385 
386 /**
387  * Close SCSI command
388  *
389  * @v scsicmd SCSI command
390  * @v rc Reason for close
391  */
392 static void scsicmd_close ( struct scsi_command *scsicmd, int rc ) {
393  struct scsi_device *scsidev = scsicmd->scsidev;
394 
395  if ( rc != 0 ) {
396  DBGC ( scsidev, "SCSI %p tag %08x closed: %s\n",
397  scsidev, scsicmd->tag, strerror ( rc ) );
398  }
399 
400  /* Remove from list of commands */
401  list_del ( &scsicmd->list );
402 
403  /* Shut down interfaces */
404  intfs_shutdown ( rc, &scsicmd->scsi, &scsicmd->block, NULL );
405 
406  /* Drop list's reference */
407  scsicmd_put ( scsicmd );
408 }
409 
410 /**
411  * Construct and issue SCSI command
412  *
413  * @ret rc Return status code
414  */
415 static int scsicmd_command ( struct scsi_command *scsicmd ) {
416  struct scsi_device *scsidev = scsicmd->scsidev;
417  struct scsi_cmd command;
418  int tag;
419  int rc;
420 
421  /* Construct command */
422  memset ( &command, 0, sizeof ( command ) );
423  memcpy ( &command.lun, &scsidev->lun, sizeof ( command.lun ) );
424  scsicmd->type->cmd ( scsicmd, &command );
425 
426  /* Issue command */
427  if ( ( tag = scsi_command ( &scsidev->scsi, &scsicmd->scsi,
428  &command ) ) < 0 ) {
429  rc = tag;
430  DBGC ( scsidev, "SCSI %p could not issue command: %s\n",
431  scsidev, strerror ( rc ) );
432  return rc;
433  }
434 
435  /* Record tag */
436  if ( scsicmd->tag ) {
437  DBGC ( scsidev, "SCSI %p tag %08x is now tag %08x\n",
438  scsidev, scsicmd->tag, tag );
439  }
440  scsicmd->tag = tag;
441  DBGC2 ( scsidev, "SCSI %p tag %08x %s " SCSI_CDB_FORMAT "\n",
442  scsidev, scsicmd->tag, scsicmd->type->name,
443  SCSI_CDB_DATA ( command.cdb ) );
444 
445  return 0;
446 }
447 
448 /**
449  * Handle SCSI command completion
450  *
451  * @v scsicmd SCSI command
452  * @v rc Reason for close
453  */
454 static void scsicmd_done ( struct scsi_command *scsicmd, int rc ) {
455 
456  /* Restart SCSI interface */
457  intf_restart ( &scsicmd->scsi, rc );
458 
459  /* Hand over to the command completion handler */
460  scsicmd->type->done ( scsicmd, rc );
461 }
462 
463 /**
464  * Handle SCSI response
465  *
466  * @v scsicmd SCSI command
467  * @v response SCSI response
468  */
469 static void scsicmd_response ( struct scsi_command *scsicmd,
470  struct scsi_rsp *response ) {
471  struct scsi_device *scsidev = scsicmd->scsidev;
472  size_t overrun;
473  size_t underrun;
474  int rc;
475 
476  if ( response->status == 0 ) {
477  scsicmd_done ( scsicmd, 0 );
478  } else {
479  DBGC ( scsidev, "SCSI %p tag %08x status %02x",
480  scsidev, scsicmd->tag, response->status );
481  if ( response->overrun > 0 ) {
482  overrun = response->overrun;
483  DBGC ( scsidev, " overrun +%zd", overrun );
484  } else if ( response->overrun < 0 ) {
485  underrun = -(response->overrun);
486  DBGC ( scsidev, " underrun -%zd", underrun );
487  }
488  DBGC ( scsidev, " sense %02x key %02x additional %04x\n",
489  ( response->sense.code & SCSI_SENSE_CODE_MASK ),
490  ( response->sense.key & SCSI_SENSE_KEY_MASK ),
491  ntohs ( response->sense.additional ) );
492 
493  /* Construct error number from sense data */
494  rc = -EIO_SENSE ( response->sense.key & SCSI_SENSE_KEY_MASK );
495  scsicmd_done ( scsicmd, rc );
496  }
497 }
498 
499 /**
500  * Construct SCSI READ command
501  *
502  * @v scsicmd SCSI command
503  * @v command SCSI command IU
504  */
505 static void scsicmd_read_cmd ( struct scsi_command *scsicmd,
506  struct scsi_cmd *command ) {
507 
508  if ( ( scsicmd->lba + scsicmd->count ) > SCSI_MAX_BLOCK_10 ) {
509  /* Use READ (16) */
510  command->cdb.read16.opcode = SCSI_OPCODE_READ_16;
511  command->cdb.read16.lba = cpu_to_be64 ( scsicmd->lba );
512  command->cdb.read16.len = cpu_to_be32 ( scsicmd->count );
513  } else {
514  /* Use READ (10) */
515  command->cdb.read10.opcode = SCSI_OPCODE_READ_10;
516  command->cdb.read10.lba = cpu_to_be32 ( scsicmd->lba );
517  command->cdb.read10.len = cpu_to_be16 ( scsicmd->count );
518  }
519  command->data_in = scsicmd->buffer;
520  command->data_in_len = scsicmd->len;
521 }
522 
523 /** SCSI READ command type */
525  .name = "READ",
526  .cmd = scsicmd_read_cmd,
527  .done = scsicmd_close,
528 };
529 
530 /**
531  * Construct SCSI WRITE command
532  *
533  * @v scsicmd SCSI command
534  * @v command SCSI command IU
535  */
536 static void scsicmd_write_cmd ( struct scsi_command *scsicmd,
537  struct scsi_cmd *command ) {
538 
539  if ( ( scsicmd->lba + scsicmd->count ) > SCSI_MAX_BLOCK_10 ) {
540  /* Use WRITE (16) */
541  command->cdb.write16.opcode = SCSI_OPCODE_WRITE_16;
542  command->cdb.write16.lba = cpu_to_be64 ( scsicmd->lba );
543  command->cdb.write16.len = cpu_to_be32 ( scsicmd->count );
544  } else {
545  /* Use WRITE (10) */
546  command->cdb.write10.opcode = SCSI_OPCODE_WRITE_10;
547  command->cdb.write10.lba = cpu_to_be32 ( scsicmd->lba );
548  command->cdb.write10.len = cpu_to_be16 ( scsicmd->count );
549  }
550  command->data_out = scsicmd->buffer;
551  command->data_out_len = scsicmd->len;
552 }
553 
554 /** SCSI WRITE command type */
556  .name = "WRITE",
557  .cmd = scsicmd_write_cmd,
558  .done = scsicmd_close,
559 };
560 
561 /** SCSI READ CAPACITY private data */
563  /** Use READ CAPACITY (16) */
564  int use16;
565  /** Data buffer for READ CAPACITY commands */
566  union {
567  /** Data buffer for READ CAPACITY (10) */
569  /** Data buffer for READ CAPACITY (16) */
571  } capacity;
572 };
573 
574 /**
575  * Construct SCSI READ CAPACITY command
576  *
577  * @v scsicmd SCSI command
578  * @v command SCSI command IU
579  */
580 static void scsicmd_read_capacity_cmd ( struct scsi_command *scsicmd,
581  struct scsi_cmd *command ) {
582  struct scsi_read_capacity_private *priv = scsicmd_priv ( scsicmd );
583  struct scsi_cdb_read_capacity_16 *readcap16 = &command->cdb.readcap16;
584  struct scsi_cdb_read_capacity_10 *readcap10 = &command->cdb.readcap10;
585  struct scsi_capacity_16 *capacity16 = &priv->capacity.capacity16;
586  struct scsi_capacity_10 *capacity10 = &priv->capacity.capacity10;
587 
588  if ( priv->use16 ) {
589  /* Use READ CAPACITY (16) */
591  readcap16->service_action =
593  readcap16->len = cpu_to_be32 ( sizeof ( *capacity16 ) );
594  command->data_in = virt_to_user ( capacity16 );
595  command->data_in_len = sizeof ( *capacity16 );
596  } else {
597  /* Use READ CAPACITY (10) */
599  command->data_in = virt_to_user ( capacity10 );
600  command->data_in_len = sizeof ( *capacity10 );
601  }
602 }
603 
604 /**
605  * Handle SCSI READ CAPACITY command completion
606  *
607  * @v scsicmd SCSI command
608  * @v rc Reason for completion
609  */
610 static void scsicmd_read_capacity_done ( struct scsi_command *scsicmd,
611  int rc ) {
612  struct scsi_device *scsidev = scsicmd->scsidev;
613  struct scsi_read_capacity_private *priv = scsicmd_priv ( scsicmd );
614  struct scsi_capacity_16 *capacity16 = &priv->capacity.capacity16;
615  struct scsi_capacity_10 *capacity10 = &priv->capacity.capacity10;
616  struct block_device_capacity capacity;
617 
618  /* Close if command failed */
619  if ( rc != 0 ) {
620  scsicmd_close ( scsicmd, rc );
621  return;
622  }
623 
624  /* Extract capacity */
625  if ( priv->use16 ) {
626  capacity.blocks = ( be64_to_cpu ( capacity16->lba ) + 1 );
627  capacity.blksize = be32_to_cpu ( capacity16->blksize );
628  } else {
629  capacity.blocks = ( be32_to_cpu ( capacity10->lba ) + 1 );
630  capacity.blksize = be32_to_cpu ( capacity10->blksize );
631 
632  /* If capacity range was exceeded (i.e. capacity.lba
633  * was 0xffffffff, meaning that blockdev->blocks is
634  * now zero), use READ CAPACITY (16) instead. READ
635  * CAPACITY (16) is not mandatory, so we can't just
636  * use it straight off.
637  */
638  if ( capacity.blocks == 0 ) {
639  priv->use16 = 1;
640  if ( ( rc = scsicmd_command ( scsicmd ) ) != 0 ) {
641  scsicmd_close ( scsicmd, rc );
642  return;
643  }
644  return;
645  }
646  }
647  capacity.max_count = -1U;
648 
649  /* Allow transport layer to update capacity */
650  block_capacity ( &scsidev->scsi, &capacity );
651 
652  /* Return capacity to caller */
653  block_capacity ( &scsicmd->block, &capacity );
654 
655  /* Close command */
656  scsicmd_close ( scsicmd, 0 );
657 }
658 
659 /** SCSI READ CAPACITY command type */
661  .name = "READ CAPACITY",
662  .priv_len = sizeof ( struct scsi_read_capacity_private ),
665 };
666 
667 /**
668  * Construct SCSI TEST UNIT READY command
669  *
670  * @v scsicmd SCSI command
671  * @v command SCSI command IU
672  */
673 static void scsicmd_test_unit_ready_cmd ( struct scsi_command *scsicmd __unused,
674  struct scsi_cmd *command ) {
675  struct scsi_cdb_test_unit_ready *testready = &command->cdb.testready;
676 
677  testready->opcode = SCSI_OPCODE_TEST_UNIT_READY;
678 }
679 
680 /** SCSI TEST UNIT READY command type */
682  .name = "TEST UNIT READY",
684  .done = scsicmd_close,
685 };
686 
687 /** SCSI command block interface operations */
690 };
691 
692 /** SCSI command block interface descriptor */
695  scsicmd_block_op, scsi );
696 
697 /** SCSI command SCSI interface operations */
701 };
702 
703 /** SCSI command SCSI interface descriptor */
705  INTF_DESC_PASSTHRU ( struct scsi_command, scsi,
707 
708 /**
709  * Create SCSI command
710  *
711  * @v scsidev SCSI device
712  * @v block Block data interface
713  * @v type SCSI command type
714  * @v lba Starting logical block address
715  * @v count Number of blocks to transfer
716  * @v buffer Data buffer
717  * @v len Length of data buffer
718  * @ret rc Return status code
719  */
720 static int scsidev_command ( struct scsi_device *scsidev,
721  struct interface *block,
722  struct scsi_command_type *type,
723  uint64_t lba, unsigned int count,
724  userptr_t buffer, size_t len ) {
725  struct scsi_command *scsicmd;
726  int rc;
727 
728  /* Allocate and initialise structure */
729  scsicmd = zalloc ( sizeof ( *scsicmd ) + type->priv_len );
730  if ( ! scsicmd ) {
731  rc = -ENOMEM;
732  goto err_zalloc;
733  }
734  ref_init ( &scsicmd->refcnt, scsicmd_free );
735  intf_init ( &scsicmd->block, &scsicmd_block_desc, &scsicmd->refcnt );
736  intf_init ( &scsicmd->scsi, &scsicmd_scsi_desc,
737  &scsicmd->refcnt );
738  scsicmd->scsidev = scsidev_get ( scsidev );
739  list_add ( &scsicmd->list, &scsidev->cmds );
740  scsicmd->type = type;
741  scsicmd->lba = lba;
742  scsicmd->count = count;
743  scsicmd->buffer = buffer;
744  scsicmd->len = len;
745 
746  /* Issue SCSI command */
747  if ( ( rc = scsicmd_command ( scsicmd ) ) != 0 )
748  goto err_command;
749 
750  /* Attach to parent interface, transfer reference to list, and return */
751  intf_plug_plug ( &scsicmd->block, block );
752  return 0;
753 
754  err_command:
755  scsicmd_close ( scsicmd, rc );
756  ref_put ( &scsicmd->refcnt );
757  err_zalloc:
758  return rc;
759 }
760 
761 /**
762  * Issue SCSI block read
763  *
764  * @v scsidev SCSI device
765  * @v block Block data interface
766  * @v lba Starting logical block address
767  * @v count Number of blocks to transfer
768  * @v buffer Data buffer
769  * @v len Length of data buffer
770  * @ret rc Return status code
771 
772  */
773 static int scsidev_read ( struct scsi_device *scsidev,
774  struct interface *block,
775  uint64_t lba, unsigned int count,
776  userptr_t buffer, size_t len ) {
778  lba, count, buffer, len );
779 }
780 
781 /**
782  * Issue SCSI block write
783  *
784  * @v scsidev SCSI device
785  * @v block Block data interface
786  * @v lba Starting logical block address
787  * @v count Number of blocks to transfer
788  * @v buffer Data buffer
789  * @v len Length of data buffer
790  * @ret rc Return status code
791  */
792 static int scsidev_write ( struct scsi_device *scsidev,
793  struct interface *block,
794  uint64_t lba, unsigned int count,
795  userptr_t buffer, size_t len ) {
797  lba, count, buffer, len );
798 }
799 
800 /**
801  * Read SCSI device capacity
802  *
803  * @v scsidev SCSI device
804  * @v block Block data interface
805  * @ret rc Return status code
806  */
808  struct interface *block ) {
810  0, 0, UNULL, 0 );
811 }
812 
813 /**
814  * Test to see if SCSI device is ready
815  *
816  * @v scsidev SCSI device
817  * @v block Block data interface
818  * @ret rc Return status code
819  */
821  struct interface *block ) {
823  0, 0, UNULL, 0 );
824 }
825 
826 /**
827  * Check SCSI device flow-control window
828  *
829  * @v scsidev SCSI device
830  * @ret len Length of window
831  */
832 static size_t scsidev_window ( struct scsi_device *scsidev ) {
833 
834  /* Refuse commands until unit is confirmed ready */
835  if ( ! ( scsidev->flags & SCSIDEV_UNIT_READY ) )
836  return 0;
837 
838  return xfer_window ( &scsidev->scsi );
839 }
840 
841 /**
842  * Close SCSI device
843  *
844  * @v scsidev SCSI device
845  * @v rc Reason for close
846  */
847 static void scsidev_close ( struct scsi_device *scsidev, int rc ) {
848  struct scsi_command *scsicmd;
849  struct scsi_command *tmp;
850 
851  /* Stop process */
853 
854  /* Shut down interfaces */
856  NULL );
857 
858  /* Shut down any remaining commands */
859  list_for_each_entry_safe ( scsicmd, tmp, &scsidev->cmds, list )
860  scsicmd_close ( scsicmd, rc );
861 }
862 
863 /** SCSI device block interface operations */
871 };
872 
873 /** SCSI device block interface descriptor */
876  scsidev_block_op, scsi );
877 
878 /**
879  * Handle SCSI TEST UNIT READY response
880  *
881  * @v scsidev SCSI device
882  * @v rc Reason for close
883  */
884 static void scsidev_ready ( struct scsi_device *scsidev, int rc ) {
885 
886  /* Shut down interface */
887  intf_restart ( &scsidev->ready, rc );
888 
889  /* Mark device as ready, if applicable */
890  if ( rc == 0 ) {
891  DBGC ( scsidev, "SCSI %p unit is ready\n", scsidev );
892  scsidev->flags |= SCSIDEV_UNIT_READY;
893  xfer_window_changed ( &scsidev->block );
894  return;
895  }
896  DBGC ( scsidev, "SCSI %p not ready: %s\n", scsidev, strerror ( rc ) );
897 
898  /* SCSI targets have an annoying habit of returning occasional
899  * pointless "error" messages such as "power-on occurred", so
900  * we have to be prepared to retry commands.
901  *
902  * For most commands, we rely on the caller (e.g. the generic
903  * SAN device layer) to retry commands as needed. However, a
904  * TEST UNIT READY failure is used as an indication that the
905  * whole SCSI device is unavailable and should be closed. We
906  * must therefore perform this retry loop within the SCSI
907  * layer.
908  */
909  if ( scsidev->retries++ < SCSI_READY_MAX_RETRIES ) {
910  DBGC ( scsidev, "SCSI %p retrying (retry %d)\n",
911  scsidev, scsidev->retries );
912  scsidev->flags &= ~SCSIDEV_UNIT_TESTED;
913  process_add ( &scsidev->process );
914  return;
915  }
916 
917  /* Close device */
918  DBGC ( scsidev, "SCSI %p never became ready: %s\n",
919  scsidev, strerror ( rc ) );
920  scsidev_close ( scsidev, rc );
921 }
922 
923 /** SCSI device TEST UNIT READY interface operations */
926 };
927 
928 /** SCSI device TEST UNIT READY interface descriptor */
930  INTF_DESC ( struct scsi_device, ready, scsidev_ready_op );
931 
932 /**
933  * SCSI TEST UNIT READY process
934  *
935  * @v scsidev SCSI device
936  */
937 static void scsidev_step ( struct scsi_device *scsidev ) {
938  int rc;
939 
940  /* Do nothing if we have already issued TEST UNIT READY */
941  if ( scsidev->flags & SCSIDEV_UNIT_TESTED )
942  return;
943 
944  /* Wait until underlying SCSI device is ready */
945  if ( xfer_window ( &scsidev->scsi ) == 0 )
946  return;
947 
948  DBGC ( scsidev, "SCSI %p waiting for unit to become ready\n",
949  scsidev );
950 
951  /* Mark TEST UNIT READY as sent */
952  scsidev->flags |= SCSIDEV_UNIT_TESTED;
953 
954  /* Issue TEST UNIT READY command */
955  if ( ( rc = scsidev_test_unit_ready ( scsidev, &scsidev->ready )) !=0){
956  scsidev_close ( scsidev, rc );
957  return;
958  }
959 }
960 
961 /** SCSI device SCSI interface operations */
965 };
966 
967 /** SCSI device SCSI interface descriptor */
969  INTF_DESC_PASSTHRU ( struct scsi_device, scsi,
971 
972 /** SCSI device process descriptor */
975 
976 /**
977  * Open SCSI device
978  *
979  * @v block Block control interface
980  * @v scsi SCSI control interface
981  * @v lun SCSI LUN
982  * @ret rc Return status code
983  */
984 int scsi_open ( struct interface *block, struct interface *scsi,
985  struct scsi_lun *lun ) {
986  struct scsi_device *scsidev;
987 
988  /* Allocate and initialise structure */
989  scsidev = zalloc ( sizeof ( *scsidev ) );
990  if ( ! scsidev )
991  return -ENOMEM;
992  ref_init ( &scsidev->refcnt, NULL );
993  intf_init ( &scsidev->block, &scsidev_block_desc, &scsidev->refcnt );
994  intf_init ( &scsidev->scsi, &scsidev_scsi_desc, &scsidev->refcnt );
995  intf_init ( &scsidev->ready, &scsidev_ready_desc, &scsidev->refcnt );
997  &scsidev->refcnt );
998  INIT_LIST_HEAD ( &scsidev->cmds );
999  memcpy ( &scsidev->lun, lun, sizeof ( scsidev->lun ) );
1000  DBGC ( scsidev, "SCSI %p created for LUN " SCSI_LUN_FORMAT "\n",
1001  scsidev, SCSI_LUN_DATA ( scsidev->lun ) );
1002 
1003  /* Attach to SCSI and parent interfaces, mortalise self, and return */
1004  intf_plug_plug ( &scsidev->scsi, scsi );
1005  intf_plug_plug ( &scsidev->block, block );
1006  ref_put ( &scsidev->refcnt );
1007  return 0;
1008 }
#define cpu_to_be16(value)
Definition: byteswap.h:109
uint8_t priv[0]
Private data.
Definition: scsi.c:289
void scsi_parse_sense(const void *data, size_t len, struct scsi_sns_descriptor *sense)
Parse SCSI sense data.
Definition: scsi.c:146
A process.
Definition: process.h:17
#define __attribute__(x)
Definition: compiler.h:10
struct interface scsi
SCSI control interface.
Definition: scsi.c:235
int block_write(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Write to block device.
Definition: blockdev.c:78
#define scsi_command_TYPE(object_type)
Definition: scsi.h:342
#define EINVAL
Invalid argument.
Definition: errno.h:428
static struct interface_operation scsicmd_block_op[]
SCSI command block interface operations.
Definition: scsi.c:688
An object interface operation.
Definition: interface.h:17
static int scsidev_command(struct scsi_device *scsidev, struct interface *block, struct scsi_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Create SCSI command.
Definition: scsi.c:720
A SCSI device.
Definition: scsi.c:229
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:146
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void scsicmd_put(struct scsi_command *scsicmd)
Drop reference to SCSI command.
Definition: scsi.c:355
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:343
scsi_device_flags
SCSI device flags.
Definition: scsi.c:254
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
unsigned int max_count
Maximum number of blocks per single transfer.
Definition: blockdev.h:24
#define SCSI_READY_MAX_RETRIES
Maximum number of TEST UNIT READY retries.
Definition: scsi.c:44
static struct interface_descriptor scsicmd_scsi_desc
SCSI command SCSI interface descriptor.
Definition: scsi.c:704
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:471
uint32_t lba
Start address.
Definition: scsi.h:23
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
Error codes.
A command-line command.
Definition: command.h:9
#define SCSI_SENSE_CODE_MASK
SCSI sense response code mask.
Definition: scsi.h:309
uint32_t len
Transfer length.
Definition: scsi.h:179
void block_capacity(struct interface *intf, struct block_device_capacity *capacity)
Report block device capacity.
Definition: blockdev.c:129
#define SCSI_SENSE_KEY_MASK
SCSI sense key mask.
Definition: scsi.h:319
struct list_head cmds
List of commands.
Definition: scsi.c:250
SCSI "READ CAPACITY (10)" parameter data.
Definition: scsi.h:157
static void process_init(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process and add to process list.
Definition: process.h:161
static void scsicmd_close(struct scsi_command *scsicmd, int rc)
Close SCSI command.
Definition: scsi.c:392
struct scsi_capacity_16 capacity16
Data buffer for READ CAPACITY (16)
Definition: scsi.c:570
#define DBGC(...)
Definition: compiler.h:505
A process descriptor.
Definition: process.h:31
const char * name
Name.
Definition: scsi.c:295
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
A SCSI command type.
Definition: scsi.c:293
unsigned long long uint64_t
Definition: stdint.h:13
static int scsidev_read_capacity(struct scsi_device *scsidev, struct interface *block)
Read SCSI device capacity.
Definition: scsi.c:807
int block_read(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Read from block device.
Definition: blockdev.c:47
static struct interface_descriptor scsidev_block_desc
SCSI device block interface descriptor.
Definition: scsi.c:874
#define ntohs(value)
Definition: byteswap.h:136
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
SCSI sense data.
Definition: scsi.h:299
#define PROC_DESC_ONCE(object_type, process, _step)
Define a process descriptor for a process that runs only once.
Definition: process.h:97
#define scsi_response_TYPE(object_type)
Definition: scsi.h:347
void intfs_shutdown(int rc,...)
Shut down multiple object interfaces.
Definition: interface.c:326
int scsi_command(struct interface *control, struct interface *data, struct scsi_cmd *command)
Issue SCSI command.
Definition: scsi.c:181
int scsi_open(struct interface *block, struct interface *scsi, struct scsi_lun *lun)
Open SCSI device.
Definition: scsi.c:984
#define SCSI_MAX_BLOCK_10
Maximum block for READ/WRITE (10) commands.
Definition: scsi.h:17
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79
static struct scsi_command_type scsicmd_test_unit_ready
SCSI TEST UNIT READY command type.
Definition: scsi.c:681
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
int use16
Use READ CAPACITY (16)
Definition: scsi.c:564
static struct interface_descriptor scsidev_ready_desc
SCSI device TEST UNIT READY interface descriptor.
Definition: scsi.c:929
uint32_t blksize
Block length in bytes.
Definition: scsi.h:161
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
A doubly-linked list entry (or list head)
Definition: list.h:18
SCSI "READ CAPACITY (16)" parameter data.
Definition: scsi.h:187
SCSI descriptor-format sense data.
Definition: scsi.h:289
Data transfer interfaces.
struct interface * intf
Original interface.
Definition: interface.h:158
A reference counter.
Definition: refcnt.h:26
uint32_t blksize
Block length in bytes.
Definition: scsi.h:191
static void scsicmd_response(struct scsi_command *scsicmd, struct scsi_rsp *response)
Handle SCSI response.
Definition: scsi.c:469
#define SCSI_OPCODE_WRITE_10
WRITE (10)
Definition: scsi.h:26
unsigned long tmp
Definition: linux_pci.h:53
TEST UNIT READY has been issued.
Definition: scsi.c:256
static struct interface_operation scsidev_scsi_op[]
SCSI device SCSI interface operations.
Definition: scsi.c:962
SCSI READ CAPACITY private data.
Definition: scsi.c:562
static int scsidev_read(struct scsi_device *scsidev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Issue SCSI block read.
Definition: scsi.c:773
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
uint8_t code
Response code.
Definition: scsi.h:291
struct interface ready
TEST UNIT READY interface.
Definition: scsi.c:243
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct refcnt refcnt
Reference count.
Definition: scsi.c:231
static struct scsi_command_type scsicmd_read
SCSI READ command type.
Definition: scsi.c:524
A SCSI "TEST UNIT READY" CDB.
Definition: scsi.h:197
static void scsicmd_done(struct scsi_command *scsicmd, int rc)
Handle SCSI command completion.
Definition: scsi.c:454
uint16_t additional
Additional sense code and qualifier.
Definition: scsi.h:285
#define be32_to_cpu(value)
Definition: byteswap.h:116
A SCSI command.
Definition: scsi.c:262
static struct scsi_command_type scsicmd_read_capacity
SCSI READ CAPACITY command type.
Definition: scsi.c:660
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
userptr_t buffer
Data buffer.
Definition: scsi.c:282
An object interface.
Definition: interface.h:124
#define SCSI_OPCODE_READ_16
READ (16)
Definition: scsi.h:25
#define SCSI_SENSE_FIXED(code)
Test if SCSI sense data is in fixed format.
Definition: scsi.h:316
struct scsi_capacity_10 capacity10
Data buffer for READ CAPACITY (10)
Definition: scsi.c:568
int scsi_parse_lun(const char *lun_string, struct scsi_lun *lun)
Parse SCSI LUN.
Definition: scsi.c:117
A SCSI response information unit.
Definition: scsi.h:322
static void scsidev_close(struct scsi_device *scsidev, int rc)
Close SCSI device.
Definition: scsi.c:847
unsigned int count
Number of blocks.
Definition: scsi.c:280
size_t len
Length of data buffer.
Definition: scsi.c:284
struct interface block
Block control interface.
Definition: scsi.c:233
A SCSI "READ CAPACITY (10)" CDB.
Definition: scsi.h:140
static int scsidev_test_unit_ready(struct scsi_device *scsidev, struct interface *block)
Test to see if SCSI device is ready.
Definition: scsi.c:820
struct interface scsi
SCSI data interface.
Definition: scsi.c:273
struct scsi_command_type * type
Command type.
Definition: scsi.c:276
uint64_t blocks
Total number of blocks.
Definition: blockdev.h:20
uint8_t lun
Logical Unit Number.
Definition: edd.h:32
static void * dest
Definition: strings.h:176
uint8_t opcode
Opcode (0x25)
Definition: scsi.h:142
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:458
#define EIO_SENSE(key)
Definition: scsi.c:95
static void scsidev_ready(struct scsi_device *scsidev, int rc)
Handle SCSI TEST UNIT READY response.
Definition: scsi.c:884
void process_add(struct process *process)
Add process to process list.
Definition: process.c:59
Linked lists.
union scsi_read_capacity_private::@356 capacity
Data buffer for READ CAPACITY commands.
An object interface descriptor.
Definition: interface.h:55
Block devices.
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define be64_to_cpu(value)
Definition: byteswap.h:117
static void scsicmd_free(struct refcnt *refcnt)
Free SCSI command.
Definition: scsi.c:375
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct refcnt refcnt
Reference count.
Definition: scsi.c:264
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
uint8_t status
SCSI status code.
Definition: scsi.h:324
uint32_t tag
Command tag.
Definition: scsi.c:286
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
uint32_t control
Control.
Definition: myson.h:14
#define SCSI_OPCODE_READ_10
READ (10)
Definition: scsi.h:24
#define EOPNOTSUPP
Operation not supported on socket.
Definition: errno.h:604
struct scsi_sns_fixed fixed
Fixed-format sense data.
Definition: scsi.h:303
Processes.
uint8_t code
Response code.
Definition: scsi.h:301
uint32_t lba
Maximum logical block number.
Definition: scsi.h:159
unsigned char uint8_t
Definition: stdint.h:10
#define SCSI_CDB_DATA(cdb)
printf() parameters for dumping a scsi_cdb
Definition: scsi.h:223
static void scsicmd_read_capacity_cmd(struct scsi_command *scsicmd, struct scsi_cmd *command)
Construct SCSI READ CAPACITY command.
Definition: scsi.c:580
static struct scsi_device * scsidev_get(struct scsi_device *scsidev)
Get reference to SCSI device.
Definition: scsi.c:322
struct list_head list
List of SCSI commands.
Definition: scsi.c:268
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
static void scsicmd_read_cmd(struct scsi_command *scsicmd, struct scsi_cmd *command)
Construct SCSI READ command.
Definition: scsi.c:505
static int command
Definition: epic100.c:68
#define SCSI_LUN_FORMAT
printf() format for dumping a scsi_lun
Definition: scsi.h:241
unsigned int uint32_t
Definition: stdint.h:12
static int scsidev_write(struct scsi_device *scsidev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Issue SCSI block write.
Definition: scsi.c:792
static struct scsi_command * scsicmd_get(struct scsi_command *scsicmd)
Get reference to SCSI command.
Definition: scsi.c:344
void(* done)(struct scsi_command *scsicmd, int rc)
Handle SCSI command completion.
Definition: scsi.c:312
static size_t scsidev_window(struct scsi_device *scsidev)
Check SCSI device flow-control window.
Definition: scsi.c:832
uint64_t lba
Maximum logical block number.
Definition: scsi.h:189
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
static void scsidev_step(struct scsi_device *scsidev)
SCSI TEST UNIT READY process.
Definition: scsi.c:937
void scsi_response(struct interface *intf, struct scsi_rsp *response)
Report SCSI response.
Definition: scsi.c:206
SCSI devices.
A SCSI command information unit.
Definition: scsi.h:249
#define SCSI_LUN_DATA(lun)
printf() parameters for dumping a scsi_lun
Definition: scsi.h:244
#define cpu_to_be32(value)
Definition: byteswap.h:110
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80
static struct interface_descriptor scsicmd_block_desc
SCSI command block interface descriptor.
Definition: scsi.c:693
TEST UNIT READY has completed successfully.
Definition: scsi.c:258
#define SCSI_CDB_FORMAT
printf() format for dumping a scsi_cdb
Definition: scsi.h:219
#define UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
struct scsi_sns_descriptor desc
Descriptor-format sense data.
Definition: scsi.h:305
uint32_t len
Length.
Definition: ena.h:14
Block device capacity.
Definition: blockdev.h:18
uint32_t type
Operating system type.
Definition: ena.h:12
#define DBGC2(...)
Definition: compiler.h:522
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
static struct tlan_private * priv
Definition: tlan.c:224
static void scsidev_put(struct scsi_device *scsidev)
Drop reference to SCSI device.
Definition: scsi.c:333
struct scsi_sns_descriptor sense
Autosense data (if any)
Definition: scsi.h:333
unsigned int flags
Flags.
Definition: scsi.c:240
uint8_t opcode
Opcode (0x00)
Definition: scsi.h:199
static struct interface_descriptor scsidev_scsi_desc
SCSI device SCSI interface descriptor.
Definition: scsi.c:968
#define SCSI_OPCODE_WRITE_16
WRITE (16)
Definition: scsi.h:27
uint16_t count
Number of entries.
Definition: ena.h:22
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
uint8_t opcode
Opcode (0x9e)
Definition: scsi.h:167
static struct interface_operation scsidev_block_op[]
SCSI device block interface operations.
Definition: scsi.c:864
#define cpu_to_be64(value)
Definition: byteswap.h:111
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static void scsicmd_read_capacity_done(struct scsi_command *scsicmd, int rc)
Handle SCSI READ CAPACITY command completion.
Definition: scsi.c:610
#define SCSI_SERVICE_ACTION_READ_CAPACITY_16
READ CAPACITY (16)
Definition: scsi.h:30
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97
A SCSI LUN.
Definition: scsi.h:236
struct interface block
Block data interface.
Definition: scsi.c:271
static struct process_descriptor scsidev_process_desc
SCSI device process descriptor.
Definition: scsi.c:973
struct scsi_lun lun
SCSI LUN.
Definition: scsi.c:238
static struct scsi_command_type scsicmd_write
SCSI WRITE command type.
Definition: scsi.c:555
static struct interface_operation scsicmd_scsi_op[]
SCSI command SCSI interface operations.
Definition: scsi.c:698
uint8_t key
Sense key.
Definition: scsi.h:293
A SCSI "READ CAPACITY (16)" CDB.
Definition: scsi.h:165
static int scsicmd_command(struct scsi_command *scsicmd)
Construct and issue SCSI command.
Definition: scsi.c:415
int block_read_capacity(struct interface *control, struct interface *data)
Read block device capacity.
Definition: blockdev.c:105
uint64_t lba
Starting logical block address.
Definition: scsi.c:278
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define SCSI_OPCODE_TEST_UNIT_READY
TEST UNIT READY.
Definition: scsi.h:31
size_t priv_len
Additional working space.
Definition: scsi.c:297
unsigned int retries
TEST UNIT READY retry count.
Definition: scsi.c:247
uint64_t tag
Identity tag.
Definition: edd.h:30
#define SCSI_OPCODE_READ_CAPACITY_10
READ CAPACITY (10)
Definition: scsi.h:28
static void scsicmd_write_cmd(struct scsi_command *scsicmd, struct scsi_cmd *command)
Construct SCSI WRITE command.
Definition: scsi.c:536
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
static struct interface_operation scsidev_ready_op[]
SCSI device TEST UNIT READY interface operations.
Definition: scsi.c:924
String functions.
uint8_t service_action
Service action.
Definition: scsi.h:169
#define htons(value)
Definition: byteswap.h:135
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269
#define SCSI_OPCODE_SERVICE_ACTION_IN
SERVICE ACTION IN.
Definition: scsi.h:29
ssize_t overrun
Data overrun (or negative underrun)
Definition: scsi.h:326
struct process process
TEST UNIT READY process.
Definition: scsi.c:245
void(* cmd)(struct scsi_command *scsicmd, struct scsi_cmd *command)
Construct SCSI command IU.
Definition: scsi.c:304
static void scsicmd_test_unit_ready_cmd(struct scsi_command *scsicmd __unused, struct scsi_cmd *command)
Construct SCSI TEST UNIT READY command.
Definition: scsi.c:673
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
size_t blksize
Block size.
Definition: blockdev.h:22
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33
uint16_t additional
Additional sense code and qualifier.
Definition: scsi.h:295
void * memset(void *dest, int character, size_t len) __nonnull
static void * scsicmd_priv(struct scsi_command *scsicmd)
Get SCSI command private data.
Definition: scsi.c:366