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 scsicmd->type->cmd ( scsicmd, &command );
426
427 /* Issue command */
428 if ( ( tag = scsi_command ( &scsidev->scsi, &scsicmd->scsi,
429 &command ) ) < 0 ) {
430 rc = tag;
431 DBGC ( scsidev, "SCSI %p could not issue command: %s\n",
432 scsidev, strerror ( rc ) );
433 return rc;
434 }
435
436 /* Record tag */
437 if ( scsicmd->tag ) {
438 DBGC ( scsidev, "SCSI %p tag %08x is now tag %08x\n",
439 scsidev, scsicmd->tag, tag );
440 }
441 scsicmd->tag = tag;
442 DBGC2 ( scsidev, "SCSI %p tag %08x %s " SCSI_CDB_FORMAT "\n",
443 scsidev, scsicmd->tag, scsicmd->type->name,
444 SCSI_CDB_DATA ( command.cdb ) );
445
446 return 0;
447}
448
449/**
450 * Handle SCSI command completion
451 *
452 * @v scsicmd SCSI command
453 * @v rc Reason for close
454 */
455static void scsicmd_done ( struct scsi_command *scsicmd, int rc ) {
456
457 /* Restart SCSI interface */
458 intf_restart ( &scsicmd->scsi, rc );
459
460 /* Hand over to the command completion handler */
461 scsicmd->type->done ( scsicmd, rc );
462}
463
464/**
465 * Handle SCSI response
466 *
467 * @v scsicmd SCSI command
468 * @v response SCSI response
469 */
470static void scsicmd_response ( struct scsi_command *scsicmd,
471 struct scsi_rsp *response ) {
472 struct scsi_device *scsidev = scsicmd->scsidev;
473 size_t overrun;
474 size_t underrun;
475 int rc;
476
477 if ( response->status == 0 ) {
478 scsicmd_done ( scsicmd, 0 );
479 } else {
480 DBGC ( scsidev, "SCSI %p tag %08x status %02x",
481 scsidev, scsicmd->tag, response->status );
482 if ( response->overrun > 0 ) {
483 overrun = response->overrun;
484 DBGC ( scsidev, " overrun +%zd", overrun );
485 } else if ( response->overrun < 0 ) {
486 underrun = -(response->overrun);
487 DBGC ( scsidev, " underrun -%zd", underrun );
488 }
489 DBGC ( scsidev, " sense %02x key %02x additional %04x\n",
490 ( response->sense.code & SCSI_SENSE_CODE_MASK ),
491 ( response->sense.key & SCSI_SENSE_KEY_MASK ),
492 ntohs ( response->sense.additional ) );
493
494 /* Construct error number from sense data */
495 rc = -EIO_SENSE ( response->sense.key & SCSI_SENSE_KEY_MASK );
496 scsicmd_done ( scsicmd, rc );
497 }
498}
499
500/**
501 * Construct SCSI READ command
502 *
503 * @v scsicmd SCSI command
504 * @v command SCSI command IU
505 */
506static void scsicmd_read_cmd ( struct scsi_command *scsicmd,
507 struct scsi_cmd *command ) {
508
509 if ( ( scsicmd->lba + scsicmd->count ) > SCSI_MAX_BLOCK_10 ) {
510 /* Use READ (16) */
511 command->cdb.read16.opcode = SCSI_OPCODE_READ_16;
512 command->cdb.read16.lba = cpu_to_be64 ( scsicmd->lba );
513 command->cdb.read16.len = cpu_to_be32 ( scsicmd->count );
514 } else {
515 /* Use READ (10) */
516 command->cdb.read10.opcode = SCSI_OPCODE_READ_10;
517 command->cdb.read10.lba = cpu_to_be32 ( scsicmd->lba );
518 command->cdb.read10.len = cpu_to_be16 ( scsicmd->count );
519 }
520 command->data_in = scsicmd->buffer;
521 command->data_in_len = scsicmd->len;
522}
523
524/** SCSI READ command type */
526 .name = "READ",
527 .cmd = scsicmd_read_cmd,
528 .done = scsicmd_close,
529};
530
531/**
532 * Construct SCSI WRITE command
533 *
534 * @v scsicmd SCSI command
535 * @v command SCSI command IU
536 */
537static void scsicmd_write_cmd ( struct scsi_command *scsicmd,
538 struct scsi_cmd *command ) {
539
540 if ( ( scsicmd->lba + scsicmd->count ) > SCSI_MAX_BLOCK_10 ) {
541 /* Use WRITE (16) */
542 command->cdb.write16.opcode = SCSI_OPCODE_WRITE_16;
543 command->cdb.write16.lba = cpu_to_be64 ( scsicmd->lba );
544 command->cdb.write16.len = cpu_to_be32 ( scsicmd->count );
545 } else {
546 /* Use WRITE (10) */
547 command->cdb.write10.opcode = SCSI_OPCODE_WRITE_10;
548 command->cdb.write10.lba = cpu_to_be32 ( scsicmd->lba );
549 command->cdb.write10.len = cpu_to_be16 ( scsicmd->count );
550 }
551 command->data_out = scsicmd->buffer;
552 command->data_out_len = scsicmd->len;
553}
554
555/** SCSI WRITE command type */
557 .name = "WRITE",
558 .cmd = scsicmd_write_cmd,
559 .done = scsicmd_close,
560};
561
562/** SCSI READ CAPACITY private data */
564 /** Use READ CAPACITY (16) */
565 int use16;
566 /** Data buffer for READ CAPACITY commands */
567 union {
568 /** Data buffer for READ CAPACITY (10) */
570 /** Data buffer for READ CAPACITY (16) */
573};
574
575/**
576 * Construct SCSI READ CAPACITY command
577 *
578 * @v scsicmd SCSI command
579 * @v command SCSI command IU
580 */
581static void scsicmd_read_capacity_cmd ( struct scsi_command *scsicmd,
582 struct scsi_cmd *command ) {
583 struct scsi_read_capacity_private *priv = scsicmd_priv ( scsicmd );
584 struct scsi_cdb_read_capacity_16 *readcap16 = &command->cdb.readcap16;
585 struct scsi_cdb_read_capacity_10 *readcap10 = &command->cdb.readcap10;
586 struct scsi_capacity_16 *capacity16 = &priv->capacity.capacity16;
587 struct scsi_capacity_10 *capacity10 = &priv->capacity.capacity10;
588
589 if ( priv->use16 ) {
590 /* Use READ CAPACITY (16) */
592 readcap16->service_action =
594 readcap16->len = cpu_to_be32 ( sizeof ( *capacity16 ) );
595 command->data_in = capacity16;
596 command->data_in_len = sizeof ( *capacity16 );
597 } else {
598 /* Use READ CAPACITY (10) */
600 command->data_in = capacity10;
601 command->data_in_len = sizeof ( *capacity10 );
602 }
603}
604
605/**
606 * Handle SCSI READ CAPACITY command completion
607 *
608 * @v scsicmd SCSI command
609 * @v rc Reason for completion
610 */
611static void scsicmd_read_capacity_done ( struct scsi_command *scsicmd,
612 int rc ) {
613 struct scsi_device *scsidev = scsicmd->scsidev;
614 struct scsi_read_capacity_private *priv = scsicmd_priv ( scsicmd );
615 struct scsi_capacity_16 *capacity16 = &priv->capacity.capacity16;
616 struct scsi_capacity_10 *capacity10 = &priv->capacity.capacity10;
617 struct block_device_capacity capacity;
618
619 /* Close if command failed */
620 if ( rc != 0 ) {
621 scsicmd_close ( scsicmd, rc );
622 return;
623 }
624
625 /* Extract capacity */
626 if ( priv->use16 ) {
627 capacity.blocks = ( be64_to_cpu ( capacity16->lba ) + 1 );
628 capacity.blksize = be32_to_cpu ( capacity16->blksize );
629 } else {
630 capacity.blocks = ( be32_to_cpu ( capacity10->lba ) + 1 );
631 capacity.blksize = be32_to_cpu ( capacity10->blksize );
632
633 /* If capacity range was exceeded (i.e. capacity.lba
634 * was 0xffffffff, meaning that blockdev->blocks is
635 * now zero), use READ CAPACITY (16) instead. READ
636 * CAPACITY (16) is not mandatory, so we can't just
637 * use it straight off.
638 */
639 if ( capacity.blocks == 0 ) {
640 priv->use16 = 1;
641 if ( ( rc = scsicmd_command ( scsicmd ) ) != 0 ) {
642 scsicmd_close ( scsicmd, rc );
643 return;
644 }
645 return;
646 }
647 }
648 capacity.max_count = -1U;
649
650 /* Allow transport layer to update capacity */
651 block_capacity ( &scsidev->scsi, &capacity );
652
653 /* Return capacity to caller */
654 block_capacity ( &scsicmd->block, &capacity );
655
656 /* Close command */
657 scsicmd_close ( scsicmd, 0 );
658}
659
660/** SCSI READ CAPACITY command type */
662 .name = "READ CAPACITY",
663 .priv_len = sizeof ( struct scsi_read_capacity_private ),
666};
667
668/**
669 * Construct SCSI TEST UNIT READY command
670 *
671 * @v scsicmd SCSI command
672 * @v command SCSI command IU
673 */
675 struct scsi_cmd *command ) {
676 struct scsi_cdb_test_unit_ready *testready = &command->cdb.testready;
677
679}
680
681/** SCSI TEST UNIT READY command type */
683 .name = "TEST UNIT READY",
685 .done = scsicmd_close,
686};
687
688/** SCSI command block interface operations */
692
693/** SCSI command block interface descriptor */
696 scsicmd_block_op, scsi );
697
698/** SCSI command SCSI interface operations */
703
704/** SCSI command SCSI interface descriptor */
706 INTF_DESC_PASSTHRU ( struct scsi_command, scsi,
708
709/**
710 * Create SCSI command
711 *
712 * @v scsidev SCSI device
713 * @v block Block data interface
714 * @v type SCSI command type
715 * @v lba Starting logical block address
716 * @v count Number of blocks to transfer
717 * @v buffer Data buffer
718 * @v len Length of data buffer
719 * @ret rc Return status code
720 */
721static int scsidev_command ( struct scsi_device *scsidev,
722 struct interface *block,
723 struct scsi_command_type *type,
724 uint64_t lba, unsigned int count,
725 void *buffer, size_t len ) {
726 struct scsi_command *scsicmd;
727 int rc;
728
729 /* Allocate and initialise structure */
730 scsicmd = zalloc ( sizeof ( *scsicmd ) + type->priv_len );
731 if ( ! scsicmd ) {
732 rc = -ENOMEM;
733 goto err_zalloc;
734 }
735 ref_init ( &scsicmd->refcnt, scsicmd_free );
736 intf_init ( &scsicmd->block, &scsicmd_block_desc, &scsicmd->refcnt );
737 intf_init ( &scsicmd->scsi, &scsicmd_scsi_desc,
738 &scsicmd->refcnt );
739 scsicmd->scsidev = scsidev_get ( scsidev );
740 list_add ( &scsicmd->list, &scsidev->cmds );
741 scsicmd->type = type;
742 scsicmd->lba = lba;
743 scsicmd->count = count;
744 scsicmd->buffer = buffer;
745 scsicmd->len = len;
746
747 /* Issue SCSI command */
748 if ( ( rc = scsicmd_command ( scsicmd ) ) != 0 )
749 goto err_command;
750
751 /* Attach to parent interface, transfer reference to list, and return */
752 intf_plug_plug ( &scsicmd->block, block );
753 return 0;
754
755 err_command:
756 scsicmd_close ( scsicmd, rc );
757 ref_put ( &scsicmd->refcnt );
758 err_zalloc:
759 return rc;
760}
761
762/**
763 * Issue SCSI block read
764 *
765 * @v scsidev SCSI device
766 * @v block Block data interface
767 * @v lba Starting logical block address
768 * @v count Number of blocks to transfer
769 * @v buffer Data buffer
770 * @v len Length of data buffer
771 * @ret rc Return status code
772
773 */
774static int scsidev_read ( struct scsi_device *scsidev,
775 struct interface *block,
776 uint64_t lba, unsigned int count,
777 void *buffer, size_t len ) {
779 lba, count, buffer, len );
780}
781
782/**
783 * Issue SCSI block write
784 *
785 * @v scsidev SCSI device
786 * @v block Block data interface
787 * @v lba Starting logical block address
788 * @v count Number of blocks to transfer
789 * @v buffer Data buffer
790 * @v len Length of data buffer
791 * @ret rc Return status code
792 */
793static int scsidev_write ( struct scsi_device *scsidev,
794 struct interface *block,
795 uint64_t lba, unsigned int count,
796 void *buffer, size_t len ) {
798 lba, count, buffer, len );
799}
800
801/**
802 * Read SCSI device capacity
803 *
804 * @v scsidev SCSI device
805 * @v block Block data interface
806 * @ret rc Return status code
807 */
809 struct interface *block ) {
811 0, 0, NULL, 0 );
812}
813
814/**
815 * Test to see if SCSI device is ready
816 *
817 * @v scsidev SCSI device
818 * @v block Block data interface
819 * @ret rc Return status code
820 */
822 struct interface *block ) {
824 0, 0, NULL, 0 );
825}
826
827/**
828 * Check SCSI device flow-control window
829 *
830 * @v scsidev SCSI device
831 * @ret len Length of window
832 */
833static size_t scsidev_window ( struct scsi_device *scsidev ) {
834
835 /* Refuse commands until unit is confirmed ready */
836 if ( ! ( scsidev->flags & SCSIDEV_UNIT_READY ) )
837 return 0;
838
839 return xfer_window ( &scsidev->scsi );
840}
841
842/**
843 * Close SCSI device
844 *
845 * @v scsidev SCSI device
846 * @v rc Reason for close
847 */
848static void scsidev_close ( struct scsi_device *scsidev, int rc ) {
849 struct scsi_command *scsicmd;
850 struct scsi_command *tmp;
851
852 /* Stop process */
854
855 /* Shut down interfaces */
857 NULL );
858
859 /* Shut down any remaining commands */
861 scsicmd_close ( scsicmd, rc );
862}
863
864/** SCSI device block interface operations */
873
874/** SCSI device block interface descriptor */
877 scsidev_block_op, scsi );
878
879/**
880 * Handle SCSI TEST UNIT READY response
881 *
882 * @v scsidev SCSI device
883 * @v rc Reason for close
884 */
885static void scsidev_ready ( struct scsi_device *scsidev, int rc ) {
886
887 /* Shut down interface */
888 intf_restart ( &scsidev->ready, rc );
889
890 /* Mark device as ready, if applicable */
891 if ( rc == 0 ) {
892 DBGC ( scsidev, "SCSI %p unit is ready\n", scsidev );
893 scsidev->flags |= SCSIDEV_UNIT_READY;
894 xfer_window_changed ( &scsidev->block );
895 return;
896 }
897 DBGC ( scsidev, "SCSI %p not ready: %s\n", scsidev, strerror ( rc ) );
898
899 /* SCSI targets have an annoying habit of returning occasional
900 * pointless "error" messages such as "power-on occurred", so
901 * we have to be prepared to retry commands.
902 *
903 * For most commands, we rely on the caller (e.g. the generic
904 * SAN device layer) to retry commands as needed. However, a
905 * TEST UNIT READY failure is used as an indication that the
906 * whole SCSI device is unavailable and should be closed. We
907 * must therefore perform this retry loop within the SCSI
908 * layer.
909 */
910 if ( scsidev->retries++ < SCSI_READY_MAX_RETRIES ) {
911 DBGC ( scsidev, "SCSI %p retrying (retry %d)\n",
912 scsidev, scsidev->retries );
913 scsidev->flags &= ~SCSIDEV_UNIT_TESTED;
914 process_add ( &scsidev->process );
915 return;
916 }
917
918 /* Close device */
919 DBGC ( scsidev, "SCSI %p never became ready: %s\n",
920 scsidev, strerror ( rc ) );
921 scsidev_close ( scsidev, rc );
922}
923
924/** SCSI device TEST UNIT READY interface operations */
928
929/** SCSI device TEST UNIT READY interface descriptor */
931 INTF_DESC ( struct scsi_device, ready, scsidev_ready_op );
932
933/**
934 * SCSI TEST UNIT READY process
935 *
936 * @v scsidev SCSI device
937 */
938static void scsidev_step ( struct scsi_device *scsidev ) {
939 int rc;
940
941 /* Do nothing if we have already issued TEST UNIT READY */
942 if ( scsidev->flags & SCSIDEV_UNIT_TESTED )
943 return;
944
945 /* Wait until underlying SCSI device is ready */
946 if ( xfer_window ( &scsidev->scsi ) == 0 )
947 return;
948
949 DBGC ( scsidev, "SCSI %p waiting for unit to become ready\n",
950 scsidev );
951
952 /* Mark TEST UNIT READY as sent */
953 scsidev->flags |= SCSIDEV_UNIT_TESTED;
954
955 /* Issue TEST UNIT READY command */
956 if ( ( rc = scsidev_test_unit_ready ( scsidev, &scsidev->ready )) !=0){
957 scsidev_close ( scsidev, rc );
958 return;
959 }
960}
961
962/** SCSI device SCSI interface operations */
967
968/** SCSI device SCSI interface descriptor */
970 INTF_DESC_PASSTHRU ( struct scsi_device, scsi,
972
973/** SCSI device process descriptor */
976
977/**
978 * Open SCSI device
979 *
980 * @v block Block control interface
981 * @v scsi SCSI control interface
982 * @v lun SCSI LUN
983 * @ret rc Return status code
984 */
985int scsi_open ( struct interface *block, struct interface *scsi,
986 struct scsi_lun *lun ) {
987 struct scsi_device *scsidev;
988
989 /* Allocate and initialise structure */
990 scsidev = zalloc ( sizeof ( *scsidev ) );
991 if ( ! scsidev )
992 return -ENOMEM;
993 ref_init ( &scsidev->refcnt, NULL );
994 intf_init ( &scsidev->block, &scsidev_block_desc, &scsidev->refcnt );
995 intf_init ( &scsidev->scsi, &scsidev_scsi_desc, &scsidev->refcnt );
996 intf_init ( &scsidev->ready, &scsidev_ready_desc, &scsidev->refcnt );
998 &scsidev->refcnt );
999 INIT_LIST_HEAD ( &scsidev->cmds );
1000 memcpy ( &scsidev->lun, lun, sizeof ( scsidev->lun ) );
1001 DBGC ( scsidev, "SCSI %p created for LUN " SCSI_LUN_FORMAT "\n",
1002 scsidev, SCSI_LUN_DATA ( scsidev->lun ) );
1003
1004 /* Attach to SCSI and parent interfaces, mortalise self, and return */
1005 intf_plug_plug ( &scsidev->scsi, scsi );
1006 intf_plug_plug ( &scsidev->block, block );
1007 ref_put ( &scsidev->refcnt );
1008 return 0;
1009}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
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:573
#define DBGC2(...)
Definition compiler.h:522
#define DBGC(...)
Definition compiler.h:505
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
uint64_t lba
Starting block number.
Definition int13.h:11
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define EINVAL
Invalid argument.
Definition errno.h:429
#define EOPNOTSUPP
Operation not supported on socket.
Definition errno.h:605
#define ENOMEM
Not enough space.
Definition errno.h:535
#define SCSI_CDB_DATA(cdb)
printf() parameters for dumping a scsi_cdb
Definition scsi.h:223
#define SCSI_CDB_FORMAT
printf() format for dumping a scsi_cdb
Definition scsi.h:219
#define SCSI_OPCODE_SERVICE_ACTION_IN
SERVICE ACTION IN.
Definition scsi.h:29
#define SCSI_OPCODE_READ_10
READ (10)
Definition scsi.h:24
#define SCSI_OPCODE_TEST_UNIT_READY
TEST UNIT READY.
Definition scsi.h:31
#define SCSI_OPCODE_WRITE_16
WRITE (16)
Definition scsi.h:27
#define SCSI_OPCODE_READ_CAPACITY_10
READ CAPACITY (10)
Definition scsi.h:28
#define SCSI_OPCODE_READ_16
READ (16)
Definition scsi.h:25
#define SCSI_OPCODE_WRITE_10
WRITE (10)
Definition scsi.h:26
#define SCSI_SERVICE_ACTION_READ_CAPACITY_16
READ CAPACITY (16)
Definition scsi.h:30
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#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:662
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:506
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:525
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:705
static struct scsi_command_type scsicmd_write
SCSI WRITE command type.
Definition scsi.c:556
static struct interface_descriptor scsidev_ready_desc
SCSI device TEST UNIT READY interface descriptor.
Definition scsi.c:930
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:793
int scsi_open(struct interface *block, struct interface *scsi, struct scsi_lun *lun)
Open SCSI device.
Definition scsi.c:985
static struct interface_descriptor scsidev_scsi_desc
SCSI device SCSI interface descriptor.
Definition scsi.c:969
static struct interface_descriptor scsidev_block_desc
SCSI device block interface descriptor.
Definition scsi.c:875
static void scsicmd_write_cmd(struct scsi_command *scsicmd, struct scsi_cmd *command)
Construct SCSI WRITE command.
Definition scsi.c:537
static struct interface_descriptor scsicmd_block_desc
SCSI command block interface descriptor.
Definition scsi.c:694
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:938
static int scsidev_test_unit_ready(struct scsi_device *scsidev, struct interface *block)
Test to see if SCSI device is ready.
Definition scsi.c:821
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:721
static void scsicmd_done(struct scsi_command *scsicmd, int rc)
Handle SCSI command completion.
Definition scsi.c:455
static void scsicmd_read_capacity_cmd(struct scsi_command *scsicmd, struct scsi_cmd *command)
Construct SCSI READ CAPACITY command.
Definition scsi.c:581
#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:885
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:699
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:833
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:974
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:682
static struct interface_operation scsidev_ready_op[]
SCSI device TEST UNIT READY interface operations.
Definition scsi.c:925
static int scsidev_read_capacity(struct scsi_device *scsidev, struct interface *block)
Read SCSI device capacity.
Definition scsi.c:808
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:774
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:674
static struct scsi_command_type scsicmd_read_capacity
SCSI READ CAPACITY command type.
Definition scsi.c:661
static void scsidev_close(struct scsi_device *scsidev, int rc)
Close SCSI device.
Definition scsi.c:848
static void scsicmd_response(struct scsi_command *scsicmd, struct scsi_rsp *response)
Handle SCSI response.
Definition scsi.c:470
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:611
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:689
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:963
static struct interface_operation scsidev_block_op[]
SCSI device block interface operations.
Definition scsi.c:865
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:319
#define scsi_response_TYPE(object_type)
Definition scsi.h:347
#define SCSI_SENSE_FIXED(code)
Test if SCSI sense data is in fixed format.
Definition scsi.h:316
#define SCSI_SENSE_CODE_MASK
SCSI sense response code mask.
Definition scsi.h:309
#define SCSI_LUN_FORMAT
printf() format for dumping a scsi_lun
Definition scsi.h:241
#define SCSI_MAX_BLOCK_10
Maximum block for READ/WRITE (10) commands.
Definition scsi.h:17
#define SCSI_LUN_DATA(lun)
printf() parameters for dumping a scsi_lun
Definition scsi.h:244
#define scsi_command_TYPE(object_type)
Definition scsi.h:342
#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:485
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:157
uint32_t lba
Maximum logical block number.
Definition scsi.h:159
uint32_t blksize
Block length in bytes.
Definition scsi.h:161
SCSI "READ CAPACITY (16)" parameter data.
Definition scsi.h:187
uint32_t blksize
Block length in bytes.
Definition scsi.h:191
uint64_t lba
Maximum logical block number.
Definition scsi.h:189
A SCSI "READ CAPACITY (10)" CDB.
Definition scsi.h:140
uint8_t opcode
Opcode (0x25)
Definition scsi.h:142
A SCSI "READ CAPACITY (16)" CDB.
Definition scsi.h:165
uint8_t service_action
Service action.
Definition scsi.h:169
uint8_t opcode
Opcode (0x9e)
Definition scsi.h:167
uint32_t len
Transfer length.
Definition scsi.h:179
A SCSI "TEST UNIT READY" CDB.
Definition scsi.h:197
uint8_t opcode
Opcode (0x00)
Definition scsi.h:199
A SCSI command information unit.
Definition scsi.h:249
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:236
SCSI READ CAPACITY private data.
Definition scsi.c:563
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:571
int use16
Use READ CAPACITY (16)
Definition scsi.c:565
struct scsi_capacity_10 capacity10
Data buffer for READ CAPACITY (10)
Definition scsi.c:569
A SCSI response information unit.
Definition scsi.h:322
struct scsi_sns_descriptor sense
Autosense data (if any)
Definition scsi.h:333
uint8_t status
SCSI status code.
Definition scsi.h:324
ssize_t overrun
Data overrun (or negative underrun)
Definition scsi.h:326
SCSI descriptor-format sense data.
Definition scsi.h:289
uint8_t code
Response code.
Definition scsi.h:291
uint8_t key
Sense key.
Definition scsi.h:293
uint16_t additional
Additional sense code and qualifier.
Definition scsi.h:295
uint16_t additional
Additional sense code and qualifier.
Definition scsi.h:285
static struct tlan_private * priv
Definition tlan.c:225
SCSI sense data.
Definition scsi.h:299
struct scsi_sns_fixed fixed
Fixed-format sense data.
Definition scsi.h:303
uint8_t code
Response code.
Definition scsi.h:301
struct scsi_sns_descriptor desc
Descriptor-format sense data.
Definition scsi.h:305
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.