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