iPXE
scsi.h File Reference

SCSI devices. More...

#include <stdint.h>
#include <ipxe/interface.h>
#include <ipxe/xferbuf.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)
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.

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 18 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 242 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 245 of file scsi.h.

245#define SCSI_LUN_DATA(lun) \
246 ntohs ( (lun).u16[0] ), ntohs ( (lun).u16[1] ), \
247 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 300 of file scsi.h.

Referenced by scsicmd_response().

◆ SCSI_SENSE_FIXED

#define SCSI_SENSE_FIXED ( code)
Value:
( ( (code) & 0x7e ) == 0x70 )
static unsigned int 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 307 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 310 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:250

Definition at line 333 of file scsi.h.

333#define scsi_command_TYPE( object_type ) \
334 typeof ( int ( object_type, struct interface *data, \
335 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:313

Definition at line 338 of file scsi.h.

338#define scsi_response_TYPE( object_type ) \
339 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:472
#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:516

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:307
uint16_t additional
Additional sense code and qualifier.
Definition scsi.h:286
uint16_t additional
Additional sense code and qualifier.
Definition scsi.h:276
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

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:648
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:333
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:338
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 987 of file scsi.c.

988 {
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
#define DBGC(...)
Definition compiler.h:530
#define ENOMEM
Not enough space.
Definition errno.h:578
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:718
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:932
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 struct process_descriptor scsidev_process_desc
SCSI device process descriptor.
Definition scsi.c:976
#define SCSI_LUN_FORMAT
printf() format for dumping a scsi_lun
Definition scsi.h:242
#define SCSI_LUN_DATA(lun)
printf() parameters for dumping a scsi_lun
Definition scsi.h:245
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().