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 =
209  intf_get_dest_op ( intf, scsi_response, &dest );
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_read_capacity_private *priv = scsicmd_priv ( scsicmd );
613  struct scsi_capacity_16 *capacity16 = &priv->capacity.capacity16;
614  struct scsi_capacity_10 *capacity10 = &priv->capacity.capacity10;
615  struct block_device_capacity capacity;
616 
617  /* Close if command failed */
618  if ( rc != 0 ) {
619  scsicmd_close ( scsicmd, rc );
620  return;
621  }
622 
623  /* Extract capacity */
624  if ( priv->use16 ) {
625  capacity.blocks = ( be64_to_cpu ( capacity16->lba ) + 1 );
626  capacity.blksize = be32_to_cpu ( capacity16->blksize );
627  } else {
628  capacity.blocks = ( be32_to_cpu ( capacity10->lba ) + 1 );
629  capacity.blksize = be32_to_cpu ( capacity10->blksize );
630 
631  /* If capacity range was exceeded (i.e. capacity.lba
632  * was 0xffffffff, meaning that blockdev->blocks is
633  * now zero), use READ CAPACITY (16) instead. READ
634  * CAPACITY (16) is not mandatory, so we can't just
635  * use it straight off.
636  */
637  if ( capacity.blocks == 0 ) {
638  priv->use16 = 1;
639  if ( ( rc = scsicmd_command ( scsicmd ) ) != 0 ) {
640  scsicmd_close ( scsicmd, rc );
641  return;
642  }
643  return;
644  }
645  }
646  capacity.max_count = -1U;
647 
648  /* Return capacity to caller */
649  block_capacity ( &scsicmd->block, &capacity );
650 
651  /* Close command */
652  scsicmd_close ( scsicmd, 0 );
653 }
654 
655 /** SCSI READ CAPACITY command type */
657  .name = "READ CAPACITY",
658  .priv_len = sizeof ( struct scsi_read_capacity_private ),
661 };
662 
663 /**
664  * Construct SCSI TEST UNIT READY command
665  *
666  * @v scsicmd SCSI command
667  * @v command SCSI command IU
668  */
669 static void scsicmd_test_unit_ready_cmd ( struct scsi_command *scsicmd __unused,
670  struct scsi_cmd *command ) {
671  struct scsi_cdb_test_unit_ready *testready = &command->cdb.testready;
672 
673  testready->opcode = SCSI_OPCODE_TEST_UNIT_READY;
674 }
675 
676 /** SCSI TEST UNIT READY command type */
678  .name = "TEST UNIT READY",
680  .done = scsicmd_close,
681 };
682 
683 /** SCSI command block interface operations */
686 };
687 
688 /** SCSI command block interface descriptor */
691  scsicmd_block_op, scsi );
692 
693 /** SCSI command SCSI interface operations */
697 };
698 
699 /** SCSI command SCSI interface descriptor */
701  INTF_DESC_PASSTHRU ( struct scsi_command, scsi,
703 
704 /**
705  * Create SCSI command
706  *
707  * @v scsidev SCSI device
708  * @v block Block data interface
709  * @v type SCSI command type
710  * @v lba Starting logical block address
711  * @v count Number of blocks to transfer
712  * @v buffer Data buffer
713  * @v len Length of data buffer
714  * @ret rc Return status code
715  */
716 static int scsidev_command ( struct scsi_device *scsidev,
717  struct interface *block,
718  struct scsi_command_type *type,
719  uint64_t lba, unsigned int count,
720  userptr_t buffer, size_t len ) {
721  struct scsi_command *scsicmd;
722  int rc;
723 
724  /* Allocate and initialise structure */
725  scsicmd = zalloc ( sizeof ( *scsicmd ) + type->priv_len );
726  if ( ! scsicmd ) {
727  rc = -ENOMEM;
728  goto err_zalloc;
729  }
730  ref_init ( &scsicmd->refcnt, scsicmd_free );
731  intf_init ( &scsicmd->block, &scsicmd_block_desc, &scsicmd->refcnt );
732  intf_init ( &scsicmd->scsi, &scsicmd_scsi_desc,
733  &scsicmd->refcnt );
734  scsicmd->scsidev = scsidev_get ( scsidev );
735  list_add ( &scsicmd->list, &scsidev->cmds );
736  scsicmd->type = type;
737  scsicmd->lba = lba;
738  scsicmd->count = count;
739  scsicmd->buffer = buffer;
740  scsicmd->len = len;
741 
742  /* Issue SCSI command */
743  if ( ( rc = scsicmd_command ( scsicmd ) ) != 0 )
744  goto err_command;
745 
746  /* Attach to parent interface, transfer reference to list, and return */
747  intf_plug_plug ( &scsicmd->block, block );
748  return 0;
749 
750  err_command:
751  scsicmd_close ( scsicmd, rc );
752  ref_put ( &scsicmd->refcnt );
753  err_zalloc:
754  return rc;
755 }
756 
757 /**
758  * Issue SCSI block read
759  *
760  * @v scsidev SCSI device
761  * @v block Block data interface
762  * @v lba Starting logical block address
763  * @v count Number of blocks to transfer
764  * @v buffer Data buffer
765  * @v len Length of data buffer
766  * @ret rc Return status code
767 
768  */
769 static int scsidev_read ( struct scsi_device *scsidev,
770  struct interface *block,
771  uint64_t lba, unsigned int count,
772  userptr_t buffer, size_t len ) {
774  lba, count, buffer, len );
775 }
776 
777 /**
778  * Issue SCSI block write
779  *
780  * @v scsidev SCSI device
781  * @v block Block data interface
782  * @v lba Starting logical block address
783  * @v count Number of blocks to transfer
784  * @v buffer Data buffer
785  * @v len Length of data buffer
786  * @ret rc Return status code
787  */
788 static int scsidev_write ( struct scsi_device *scsidev,
789  struct interface *block,
790  uint64_t lba, unsigned int count,
791  userptr_t buffer, size_t len ) {
793  lba, count, buffer, len );
794 }
795 
796 /**
797  * Read SCSI device capacity
798  *
799  * @v scsidev SCSI device
800  * @v block Block data interface
801  * @ret rc Return status code
802  */
804  struct interface *block ) {
806  0, 0, UNULL, 0 );
807 }
808 
809 /**
810  * Test to see if SCSI device is ready
811  *
812  * @v scsidev SCSI device
813  * @v block Block data interface
814  * @ret rc Return status code
815  */
817  struct interface *block ) {
819  0, 0, UNULL, 0 );
820 }
821 
822 /**
823  * Check SCSI device flow-control window
824  *
825  * @v scsidev SCSI device
826  * @ret len Length of window
827  */
828 static size_t scsidev_window ( struct scsi_device *scsidev ) {
829 
830  /* Refuse commands until unit is confirmed ready */
831  if ( ! ( scsidev->flags & SCSIDEV_UNIT_READY ) )
832  return 0;
833 
834  return xfer_window ( &scsidev->scsi );
835 }
836 
837 /**
838  * Close SCSI device
839  *
840  * @v scsidev SCSI device
841  * @v rc Reason for close
842  */
843 static void scsidev_close ( struct scsi_device *scsidev, int rc ) {
844  struct scsi_command *scsicmd;
845  struct scsi_command *tmp;
846 
847  /* Stop process */
849 
850  /* Shut down interfaces */
852  NULL );
853 
854  /* Shut down any remaining commands */
855  list_for_each_entry_safe ( scsicmd, tmp, &scsidev->cmds, list )
856  scsicmd_close ( scsicmd, rc );
857 }
858 
859 /** SCSI device block interface operations */
867 };
868 
869 /** SCSI device block interface descriptor */
872  scsidev_block_op, scsi );
873 
874 /**
875  * Handle SCSI TEST UNIT READY response
876  *
877  * @v scsidev SCSI device
878  * @v rc Reason for close
879  */
880 static void scsidev_ready ( struct scsi_device *scsidev, int rc ) {
881 
882  /* Shut down interface */
883  intf_restart ( &scsidev->ready, rc );
884 
885  /* Mark device as ready, if applicable */
886  if ( rc == 0 ) {
887  DBGC ( scsidev, "SCSI %p unit is ready\n", scsidev );
888  scsidev->flags |= SCSIDEV_UNIT_READY;
889  xfer_window_changed ( &scsidev->block );
890  return;
891  }
892  DBGC ( scsidev, "SCSI %p not ready: %s\n", scsidev, strerror ( rc ) );
893 
894  /* SCSI targets have an annoying habit of returning occasional
895  * pointless "error" messages such as "power-on occurred", so
896  * we have to be prepared to retry commands.
897  *
898  * For most commands, we rely on the caller (e.g. the generic
899  * SAN device layer) to retry commands as needed. However, a
900  * TEST UNIT READY failure is used as an indication that the
901  * whole SCSI device is unavailable and should be closed. We
902  * must therefore perform this retry loop within the SCSI
903  * layer.
904  */
905  if ( scsidev->retries++ < SCSI_READY_MAX_RETRIES ) {
906  DBGC ( scsidev, "SCSI %p retrying (retry %d)\n",
907  scsidev, scsidev->retries );
908  scsidev->flags &= ~SCSIDEV_UNIT_TESTED;
909  process_add ( &scsidev->process );
910  return;
911  }
912 
913  /* Close device */
914  DBGC ( scsidev, "SCSI %p never became ready: %s\n",
915  scsidev, strerror ( rc ) );
916  scsidev_close ( scsidev, rc );
917 }
918 
919 /** SCSI device TEST UNIT READY interface operations */
922 };
923 
924 /** SCSI device TEST UNIT READY interface descriptor */
926  INTF_DESC ( struct scsi_device, ready, scsidev_ready_op );
927 
928 /**
929  * SCSI TEST UNIT READY process
930  *
931  * @v scsidev SCSI device
932  */
933 static void scsidev_step ( struct scsi_device *scsidev ) {
934  int rc;
935 
936  /* Do nothing if we have already issued TEST UNIT READY */
937  if ( scsidev->flags & SCSIDEV_UNIT_TESTED )
938  return;
939 
940  /* Wait until underlying SCSI device is ready */
941  if ( xfer_window ( &scsidev->scsi ) == 0 )
942  return;
943 
944  DBGC ( scsidev, "SCSI %p waiting for unit to become ready\n",
945  scsidev );
946 
947  /* Mark TEST UNIT READY as sent */
948  scsidev->flags |= SCSIDEV_UNIT_TESTED;
949 
950  /* Issue TEST UNIT READY command */
951  if ( ( rc = scsidev_test_unit_ready ( scsidev, &scsidev->ready )) !=0){
952  scsidev_close ( scsidev, rc );
953  return;
954  }
955 }
956 
957 /** SCSI device SCSI interface operations */
961 };
962 
963 /** SCSI device SCSI interface descriptor */
965  INTF_DESC_PASSTHRU ( struct scsi_device, scsi,
967 
968 /** SCSI device process descriptor */
971 
972 /**
973  * Open SCSI device
974  *
975  * @v block Block control interface
976  * @v scsi SCSI control interface
977  * @v lun SCSI LUN
978  * @ret rc Return status code
979  */
980 int scsi_open ( struct interface *block, struct interface *scsi,
981  struct scsi_lun *lun ) {
982  struct scsi_device *scsidev;
983 
984  /* Allocate and initialise structure */
985  scsidev = zalloc ( sizeof ( *scsidev ) );
986  if ( ! scsidev )
987  return -ENOMEM;
988  ref_init ( &scsidev->refcnt, NULL );
989  intf_init ( &scsidev->block, &scsidev_block_desc, &scsidev->refcnt );
990  intf_init ( &scsidev->scsi, &scsidev_scsi_desc, &scsidev->refcnt );
991  intf_init ( &scsidev->ready, &scsidev_ready_desc, &scsidev->refcnt );
993  &scsidev->refcnt );
994  INIT_LIST_HEAD ( &scsidev->cmds );
995  memcpy ( &scsidev->lun, lun, sizeof ( scsidev->lun ) );
996  DBGC ( scsidev, "SCSI %p created for LUN " SCSI_LUN_FORMAT "\n",
997  scsidev, SCSI_LUN_DATA ( scsidev->lun ) );
998 
999  /* Attach to SCSI and parent interfaces, mortalise self, and return */
1000  intf_plug_plug ( &scsidev->scsi, scsi );
1001  intf_plug_plug ( &scsidev->block, block );
1002  ref_put ( &scsidev->refcnt );
1003  return 0;
1004 }
#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:684
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:716
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:145
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:244
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:337
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:700
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:441
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
uint8_t type
Type.
Definition: ena.h:16
SCSI "READ CAPACITY (10)" parameter data.
Definition: scsi.h:157
uint16_t block
Definition: tftp.h:12
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:102
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:803
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:870
#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:320
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:980
#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:677
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:115
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:925
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:154
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.
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
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:958
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:769
#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:656
#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:109
#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:843
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:816
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:447
#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:880
void process_add(struct process *process)
Add process to process list.
Definition: process.c:59
Linked lists.
An object interface descriptor.
Definition: interface.h:40
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
uint8_t * tmp
Definition: entropy.h:156
#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
#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:788
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:828
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:933
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:65
static struct interface_descriptor scsicmd_block_desc
SCSI command block interface descriptor.
Definition: scsi.c:689
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
#define DBGC2(...)
Definition: compiler.h:522
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:964
#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:144
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:860
#define cpu_to_be64(value)
Definition: byteswap.h:111
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:82
A SCSI LUN.
Definition: scsi.h:236
uint8_t command
Command.
Definition: intel.h:18
struct interface block
Block data interface.
Definition: scsi.c:271
static struct process_descriptor scsidev_process_desc
SCSI device process descriptor.
Definition: scsi.c:969
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:694
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
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:173
#define SCSI_OPCODE_TEST_UNIT_READY
TEST UNIT READY.
Definition: scsi.h:31
union scsi_read_capacity_private::@349 capacity
Data buffer for READ CAPACITY commands.
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:362
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:920
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:214
#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:669
#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