iPXE
scsi.h File Reference

SCSI devices. More...

#include <stdint.h>
#include <ipxe/interface.h>

Go to the source code of this file.

Data Structures

struct  scsi_cdb_read_10
 A SCSI "READ (10)" CDB. More...
struct  scsi_cdb_read_16
 A SCSI "READ (16)" CDB. More...
struct  scsi_cdb_write_10
 A SCSI "WRITE (10)" CDB. More...
struct  scsi_cdb_write_16
 A SCSI "WRITE (16)" CDB. More...
struct  scsi_cdb_read_capacity_10
 A SCSI "READ CAPACITY (10)" CDB. More...
struct  scsi_capacity_10
 SCSI "READ CAPACITY (10)" parameter data. More...
struct  scsi_cdb_read_capacity_16
 A SCSI "READ CAPACITY (16)" CDB. More...
struct  scsi_capacity_16
 SCSI "READ CAPACITY (16)" parameter data. More...
struct  scsi_cdb_test_unit_ready
 A SCSI "TEST UNIT READY" CDB. More...
union  scsi_cdb
 A SCSI Command Data Block. More...
struct  scsi_lun
 A SCSI LUN. More...
struct  scsi_cmd
 A SCSI command information unit. More...
struct  scsi_sns_fixed
 SCSI fixed-format sense data. More...
struct  scsi_sns_descriptor
 SCSI descriptor-format sense data. More...
union  scsi_sns
 SCSI sense data. More...
struct  scsi_rsp
 A SCSI response information unit. More...

Macros

#define SCSI_MAX_BLOCK_10   0xffffffffULL
 Maximum block for READ/WRITE (10) commands.
#define SCSI_OPCODE_READ_10   0x28
 READ (10)
#define SCSI_OPCODE_READ_16   0x88
 READ (16)
#define SCSI_OPCODE_WRITE_10   0x2a
 WRITE (10)
#define SCSI_OPCODE_WRITE_16   0x8a
 WRITE (16)
#define SCSI_OPCODE_READ_CAPACITY_10   0x25
 READ CAPACITY (10)
#define SCSI_OPCODE_SERVICE_ACTION_IN   0x9e
 SERVICE ACTION IN.
#define SCSI_SERVICE_ACTION_READ_CAPACITY_16   0x10
 READ CAPACITY (16)
#define SCSI_OPCODE_TEST_UNIT_READY   0x00
 TEST UNIT READY.
#define SCSI_FL_FUA_NV   0x02
 Force unit access to NVS.
#define SCSI_FL_FUA   0x08
 Force unit access.
#define SCSI_FL_DPO   0x10
 Disable cache page out.
#define SCSI_CDB_FORMAT
 printf() format for dumping a scsi_cdb
#define SCSI_CDB_DATA(cdb)
 printf() parameters for dumping a scsi_cdb
#define SCSI_LUN_FORMAT   "%04x-%04x-%04x-%04x"
 printf() format for dumping a scsi_lun
#define SCSI_LUN_DATA(lun)
 printf() parameters for dumping a scsi_lun
#define SCSI_SENSE_CODE_MASK   0x7f
 SCSI sense response code mask.
#define SCSI_SENSE_FIXED(code)
 Test if SCSI sense data is in fixed format.
#define SCSI_SENSE_KEY_MASK   0x0f
 SCSI sense key mask.
#define scsi_command_TYPE(object_type)
#define scsi_response_TYPE(object_type)

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
struct scsi_cdb_read_10 __attribute__ ((packed))
int scsi_parse_lun (const char *lun_string, struct scsi_lun *lun)
 Parse SCSI LUN.
void scsi_parse_sense (const void *data, size_t len, struct scsi_sns_descriptor *sense)
 Parse SCSI sense data.
int scsi_command (struct interface *control, struct interface *data, struct scsi_cmd *command)
 Issue SCSI command.
void scsi_response (struct interface *intf, struct scsi_rsp *response)
 Report SCSI response.
int scsi_open (struct interface *block, struct interface *scsi, struct scsi_lun *lun)
 Open SCSI device.

Variables

uint8_t opcode
 Opcode (0x28)
uint8_t flags
 Flags.
uint32_t lba
 Start address.
uint8_t group
 Group number.
uint16_t len
 Transfer length.
uint8_t control
 Control byte.
uint8_t reserved_a
 Reserved.
uint8_t reserved_b [3]
 Reserved.
uint32_t blksize
 Block length in bytes.
uint8_t service_action
 Service action.
uint8_t reserved
 Reserved.
union scsi_cdb __attribute__
uint16_t u16 [4]
uint8_t code
 Response code.
uint8_t key
 Sense key.
uint32_t info
 Information.
uint32_t cs_info
 Command-specific information.
uint16_t additional
 Additional sense code and qualifier.

Detailed Description

SCSI devices.

Definition in file scsi.h.

Macro Definition Documentation

◆ SCSI_MAX_BLOCK_10

#define SCSI_MAX_BLOCK_10   0xffffffffULL

Maximum block for READ/WRITE (10) commands.

Definition at line 17 of file scsi.h.

Referenced by scsicmd_read_cmd(), and scsicmd_write_cmd().

◆ SCSI_LUN_FORMAT

#define SCSI_LUN_FORMAT   "%04x-%04x-%04x-%04x"

printf() format for dumping a scsi_lun

Definition at line 241 of file scsi.h.

Referenced by ibft_fill_target(), and scsi_open().

◆ SCSI_LUN_DATA

#define SCSI_LUN_DATA ( lun)
Value:
ntohs ( (lun).u16[0] ), ntohs ( (lun).u16[1] ), \
ntohs ( (lun).u16[2] ), ntohs ( (lun).u16[3] )
uint8_t lun
Logical Unit Number.
Definition edd.h:3
#define ntohs(value)
Definition byteswap.h:137
#define u16
Definition vga.h:20

printf() parameters for dumping a scsi_lun

Definition at line 244 of file scsi.h.

244#define SCSI_LUN_DATA(lun) \
245 ntohs ( (lun).u16[0] ), ntohs ( (lun).u16[1] ), \
246 ntohs ( (lun).u16[2] ), ntohs ( (lun).u16[3] )

Referenced by ibft_fill_target(), and scsi_open().

◆ SCSI_SENSE_CODE_MASK

#define SCSI_SENSE_CODE_MASK   0x7f

SCSI sense response code mask.

Definition at line 309 of file scsi.h.

Referenced by scsicmd_response().

◆ SCSI_SENSE_FIXED

#define SCSI_SENSE_FIXED ( code)
Value:
( ( (code) & 0x7e ) == 0x70 )
static unsigned int code
Response code.
Definition hyperv.h:26

Test if SCSI sense data is in fixed format.

Parameters
codeResponse code
Return values
is_fixedSense data is in fixed format

Definition at line 316 of file scsi.h.

Referenced by scsi_parse_sense().

◆ SCSI_SENSE_KEY_MASK

#define SCSI_SENSE_KEY_MASK   0x0f

SCSI sense key mask.

Definition at line 319 of file scsi.h.

Referenced by scsicmd_response().

◆ scsi_command_TYPE

#define scsi_command_TYPE ( object_type)
Value:
typeof ( int ( object_type, struct interface *data, \
struct scsi_cmd *command ) )
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
uint8_t data[48]
Additional event data.
Definition ena.h:11
A command-line command.
Definition command.h:10
An object interface.
Definition interface.h:125
A SCSI command information unit.
Definition scsi.h:249

Definition at line 342 of file scsi.h.

342#define scsi_command_TYPE( object_type ) \
343 typeof ( int ( object_type, struct interface *data, \
344 struct scsi_cmd *command ) )

Referenced by scsi_command().

◆ scsi_response_TYPE

#define scsi_response_TYPE ( object_type)
Value:
typeof ( void ( object_type, struct scsi_rsp *response ) )
A SCSI response information unit.
Definition scsi.h:322

Definition at line 347 of file scsi.h.

347#define scsi_response_TYPE( object_type ) \
348 typeof ( void ( object_type, struct scsi_rsp *response ) )

Referenced by scsi_response().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ scsi_parse_lun()

int scsi_parse_lun ( const char * lun_string,
struct scsi_lun * lun )
extern

Parse SCSI LUN.

Parameters
lun_stringLUN string representation
lunLUN to fill in
Return values
rcReturn status code

Definition at line 118 of file scsi.c.

118 {
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}
#define EINVAL
Invalid argument.
Definition errno.h:429
#define htons(value)
Definition byteswap.h:136
void * memset(void *dest, int character, size_t len) __nonnull
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition string.c:485

References EINVAL, htons, lun, memset(), and strtoul().

Referenced by fcp_parse_uri(), ib_srp_parse_lun(), and iscsi_parse_root_path().

◆ scsi_parse_sense()

void scsi_parse_sense ( const void * data,
size_t len,
struct scsi_sns_descriptor * sense )
extern

Parse SCSI sense data.

Parameters
dataRaw sense data
lenLength of raw sense data
senseDescriptor-format sense data to fill in

Definition at line 147 of file scsi.c.

148 {
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}
ring len
Length.
Definition dwmac.h:226
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define SCSI_SENSE_FIXED(code)
Test if SCSI sense data is in fixed format.
Definition scsi.h:316
uint16_t additional
Additional sense code and qualifier.
Definition scsi.h:295
uint16_t additional
Additional sense code and qualifier.
Definition scsi.h:285
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

References scsi_sns_descriptor::additional, scsi_sns_fixed::additional, scsi_sns::code, data, scsi_sns::desc, scsi_sns::fixed, len, memcpy(), memset(), and SCSI_SENSE_FIXED.

Referenced by fcpcmd_recv_rsp(), iscsi_rx_scsi_response(), and srp_rsp().

◆ scsi_command()

int scsi_command ( struct interface * control,
struct interface * data,
struct scsi_cmd * command )
extern

Issue SCSI command.

Parameters
controlSCSI control interface
dataSCSI data interface
commandSCSI command
Return values
tagCommand tag, or negative error

Definition at line 182 of file scsi.c.

183 {
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}
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
#define EOPNOTSUPP
Operation not supported on socket.
Definition errno.h:605
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition interface.c:160
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition interface.c:150
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition interface.h:270
uint32_t control
Control.
Definition myson.h:3
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327
#define scsi_command_TYPE(object_type)
Definition scsi.h:342
A SCSI command.
Definition scsi.c:263

References control, data, dest, EOPNOTSUPP, intf_get_dest_op, intf_object(), intf_put(), op, and scsi_command_TYPE.

◆ scsi_response()

void scsi_response ( struct interface * intf,
struct scsi_rsp * response )
extern

Report SCSI response.

Parameters
interfaceSCSI command interface
responseSCSI response

Definition at line 207 of file scsi.c.

207 {
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}
void scsi_response(struct interface *intf, struct scsi_rsp *response)
Report SCSI response.
Definition scsi.c:207
#define scsi_response_TYPE(object_type)
Definition scsi.h:347
struct interface * intf
Original interface.
Definition interface.h:159

References dest, interface::intf, intf_get_dest_op, intf_object(), intf_put(), op, scsi_response(), and scsi_response_TYPE.

Referenced by fcpcmd_recv_rsp(), iscsi_scsi_done(), scsi_response(), and srp_rsp().

◆ scsi_open()

int scsi_open ( struct interface * block,
struct interface * scsi,
struct scsi_lun * lun )
extern

Open SCSI device.

Parameters
blockBlock control interface
scsiSCSI control interface
lunSCSI LUN
Return values
rcReturn status code

Definition at line 985 of file scsi.c.

986 {
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
#define DBGC(...)
Definition compiler.h:505
#define ENOMEM
Not enough space.
Definition errno.h:535
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition interface.c:108
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
uint8_t block[3][8]
DES-encrypted blocks.
Definition mschapv2.h:1
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
#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 interface_descriptor scsidev_ready_desc
SCSI device TEST UNIT READY interface descriptor.
Definition scsi.c:930
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 struct process_descriptor scsidev_process_desc
SCSI device process descriptor.
Definition scsi.c:974
#define SCSI_LUN_FORMAT
printf() format for dumping a scsi_lun
Definition scsi.h:241
#define SCSI_LUN_DATA(lun)
printf() parameters for dumping a scsi_lun
Definition scsi.h:244
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
struct refcnt refcnt
Reference count.
Definition scsi.c:232

References block, scsi_device::block, scsi_device::cmds, DBGC, ENOMEM, INIT_LIST_HEAD, intf_init(), intf_plug_plug(), lun, scsi_device::lun, memcpy(), NULL, scsi_device::process, process_init(), scsi_device::ready, ref_init, ref_put, scsi_device::refcnt, scsi_device::scsi, SCSI_LUN_DATA, SCSI_LUN_FORMAT, scsidev_block_desc, scsidev_process_desc, scsidev_ready_desc, scsidev_scsi_desc, and zalloc().

Referenced by fcpdev_open(), iscsi_open(), srp_open(), and usbblk_open_uri().

Variable Documentation

◆ opcode

uint8_t opcode

Opcode (0x28)

Opcode (0x00)

Opcode (0x9e)

Opcode (0x25)

Opcode (0x8a)

Opcode (0x2a)

Opcode (0x88)

Definition at line 1 of file scsi.h.

◆ flags

uint8_t flags

Flags.

Definition at line 3 of file scsi.h.

◆ lba

uint64_t lba

Start address.

Maximum logical block number.

Logical block address.

This is a logical block number, in big-endian order.

Applicable only if the PMI bit is set.

Definition at line 8 of file scsi.h.

◆ group

uint8_t group

Group number.

Definition at line 10 of file scsi.h.

◆ len

uint8_t len

Transfer length.

Additional sense length.

This is a logical block count, in big-endian order.

This is the size of the data-in buffer, in bytes.

Definition at line 15 of file scsi.h.

◆ control

uint8_t control

Control byte.

Definition at line 17 of file scsi.h.

◆ reserved_a

uint8_t reserved_a

Reserved.

Definition at line 3 of file scsi.h.

◆ reserved_b

uint8_t reserved_b[3]

Reserved.

Definition at line 10 of file scsi.h.

◆ blksize

uint32_t blksize

Block length in bytes.

Definition at line 3 of file scsi.h.

◆ service_action

uint8_t service_action

Service action.

Definition at line 3 of file scsi.h.

◆ reserved

uint8_t reserved

Reserved.

Definition at line 15 of file scsi.h.

◆ u16

Definition at line 0 of file scsi.h.

◆ code

uint8_t code

Response code.

Definition at line 1 of file scsi.h.

◆ key

uint8_t key

Sense key.

Definition at line 5 of file scsi.h.

◆ info

uint32_t info

Information.

Definition at line 7 of file scsi.h.

◆ cs_info

uint32_t cs_info

Command-specific information.

Definition at line 11 of file scsi.h.

◆ additional

uint16_t additional

Additional sense code and qualifier.

Definition at line 13 of file scsi.h.

Referenced by drbg_generate(), drbg_generate_algorithm(), drbg_reseed(), drbg_reseed_algorithm(), hmac_drbg_generate(), hmac_drbg_reseed(), and rbg_generate().