iPXE
Data Structures | Macros | Functions | Variables
scsi.h File Reference

SCSI devices. More...

#include <stdint.h>
#include <ipxe/uaccess.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. More...
 
#define SCSI_OPCODE_READ_10   0x28
 READ (10) More...
 
#define SCSI_OPCODE_READ_16   0x88
 READ (16) More...
 
#define SCSI_OPCODE_WRITE_10   0x2a
 WRITE (10) More...
 
#define SCSI_OPCODE_WRITE_16   0x8a
 WRITE (16) More...
 
#define SCSI_OPCODE_READ_CAPACITY_10   0x25
 READ CAPACITY (10) More...
 
#define SCSI_OPCODE_SERVICE_ACTION_IN   0x9e
 SERVICE ACTION IN. More...
 
#define SCSI_SERVICE_ACTION_READ_CAPACITY_16   0x10
 READ CAPACITY (16) More...
 
#define SCSI_OPCODE_TEST_UNIT_READY   0x00
 TEST UNIT READY. More...
 
#define SCSI_FL_FUA_NV   0x02
 Force unit access to NVS. More...
 
#define SCSI_FL_FUA   0x08
 Force unit access. More...
 
#define SCSI_FL_DPO   0x10
 Disable cache page out. More...
 
#define SCSI_CDB_FORMAT
 printf() format for dumping a scsi_cdb More...
 
#define SCSI_CDB_DATA(cdb)
 printf() parameters for dumping a scsi_cdb More...
 
#define SCSI_LUN_FORMAT   "%04x-%04x-%04x-%04x"
 printf() format for dumping a scsi_lun More...
 
#define SCSI_LUN_DATA(lun)
 printf() parameters for dumping a scsi_lun More...
 
#define SCSI_SENSE_CODE_MASK   0x7f
 SCSI sense response code mask. More...
 
#define SCSI_SENSE_FIXED(code)   ( ( (code) & 0x7e ) == 0x70 )
 Test if SCSI sense data is in fixed format. More...
 
#define SCSI_SENSE_KEY_MASK   0x0f
 SCSI sense key mask. More...
 
#define scsi_command_TYPE(object_type)
 
#define scsi_response_TYPE(object_type)   typeof ( void ( object_type, struct scsi_rsp *response ) )
 

Functions

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

Variables

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

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.

◆ 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.

◆ 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] )
uint16_t u16
Definition: stdint.h:21
#define ntohs(value)
Definition: byteswap.h:136
uint8_t lun
Logical Unit Number.
Definition: edd.h:32

printf() parameters for dumping a scsi_lun

Definition at line 244 of file scsi.h.

◆ SCSI_SENSE_CODE_MASK

#define SCSI_SENSE_CODE_MASK   0x7f

SCSI sense response code mask.

Definition at line 309 of file scsi.h.

◆ SCSI_SENSE_FIXED

#define SCSI_SENSE_FIXED (   code)    ( ( (code) & 0x7e ) == 0x70 )

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.

◆ SCSI_SENSE_KEY_MASK

#define SCSI_SENSE_KEY_MASK   0x0f

SCSI sense key mask.

Definition at line 319 of file scsi.h.

◆ scsi_command_TYPE

#define scsi_command_TYPE (   object_type)
Value:
typeof ( int ( object_type, struct interface *data, \
struct scsi_cmd *command ) )
A command-line command.
Definition: command.h:9
An object interface.
Definition: interface.h:109
A SCSI command information unit.
Definition: scsi.h:249
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

Definition at line 342 of file scsi.h.

◆ scsi_response_TYPE

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

Definition at line 347 of file scsi.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ scsi_parse_lun()

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

Parse SCSI LUN.

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

Definition at line 117 of file scsi.c.

117  {
118  char *p;
119  int i;
120 
121  memset ( lun, 0, sizeof ( *lun ) );
122  if ( lun_string ) {
123  p = ( char * ) lun_string;
124  for ( i = 0 ; i < 4 ; i++ ) {
125  lun->u16[i] = htons ( strtoul ( p, &p, 16 ) );
126  if ( *p == '\0' )
127  break;
128  if ( *p != '-' )
129  return -EINVAL;
130  p++;
131  }
132  if ( *p )
133  return -EINVAL;
134  }
135 
136  return 0;
137 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:456
uint8_t lun
Logical Unit Number.
Definition: edd.h:32
#define htons(value)
Definition: byteswap.h:135
void * memset(void *dest, int character, size_t len) __nonnull

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 
)

Parse SCSI sense data.

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

Definition at line 146 of file scsi.c.

147  {
148  const union scsi_sns *sns = data;
149 
150  /* Avoid returning uninitialised data */
151  memset ( sense, 0, sizeof ( *sense ) );
152 
153  /* Copy, assuming descriptor-format data */
154  if ( len < sizeof ( sns->desc ) )
155  return;
156  memcpy ( sense, &sns->desc, sizeof ( *sense ) );
157 
158  /* Convert fixed-format to descriptor-format, if applicable */
159  if ( len < sizeof ( sns->fixed ) )
160  return;
161  if ( ! SCSI_SENSE_FIXED ( sns->code ) )
162  return;
163  sense->additional = sns->fixed.additional;
164 }
SCSI sense data.
Definition: scsi.h:299
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint16_t additional
Additional sense code and qualifier.
Definition: scsi.h:285
#define SCSI_SENSE_FIXED(code)
Test if SCSI sense data is in fixed format.
Definition: scsi.h:316
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
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint16_t additional
Additional sense code and qualifier.
Definition: scsi.h:295
void * memset(void *dest, int character, size_t len) __nonnull

References scsi_sns_fixed::additional, scsi_sns_descriptor::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 
)

Issue SCSI command.

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

Definition at line 181 of file scsi.c.

182  {
183  struct interface *dest;
184  scsi_command_TYPE ( void * ) *op =
186  void *object = intf_object ( dest );
187  int tap;
188 
189  if ( op ) {
190  tap = op ( object, data, command );
191  } else {
192  /* Default is to fail to issue the command */
193  tap = -EOPNOTSUPP;
194  }
195 
196  intf_put ( dest );
197  return tap;
198 }
#define scsi_command_TYPE(object_type)
Definition: scsi.h:342
A command-line command.
Definition: command.h:9
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:154
A SCSI command.
Definition: scsi.c:262
An object interface.
Definition: interface.h:109
static void * dest
Definition: strings.h:176
uint32_t control
Control.
Definition: myson.h:14
#define EOPNOTSUPP
Operation not supported on socket.
Definition: errno.h:604
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:144
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:214

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 
)

Report SCSI response.

Parameters
interfaceSCSI command interface
responseSCSI response

Definition at line 206 of file scsi.c.

206  {
207  struct interface *dest;
208  scsi_response_TYPE ( void * ) *op =
209  intf_get_dest_op ( intf, scsi_response, &dest );
210  void *object = intf_object ( dest );
211 
212  if ( op ) {
213  op ( object, response );
214  } else {
215  /* Default is to ignore the response */
216  }
217 
218  intf_put ( dest );
219 }
#define scsi_response_TYPE(object_type)
Definition: scsi.h:347
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:154
An object interface.
Definition: interface.h:109
static void * dest
Definition: strings.h:176
void scsi_response(struct interface *intf, struct scsi_rsp *response)
Report SCSI response.
Definition: scsi.c:206
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:144
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:214

References dest, 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 
)

Open SCSI device.

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

Definition at line 980 of file scsi.c.

981  {
982  struct scsi_device *scsidev;
983 
984  /* Allocate and initialise structure */
985  scsidev = zalloc ( sizeof ( *scsidev ) );
986  if ( ! scsidev )
987  return -ENOMEM;
988  ref_init ( &scsidev->refcnt, NULL );
989  intf_init ( &scsidev->block, &scsidev_block_desc, &scsidev->refcnt );
990  intf_init ( &scsidev->scsi, &scsidev_scsi_desc, &scsidev->refcnt );
991  intf_init ( &scsidev->ready, &scsidev_ready_desc, &scsidev->refcnt );
993  &scsidev->refcnt );
994  INIT_LIST_HEAD ( &scsidev->cmds );
995  memcpy ( &scsidev->lun, lun, sizeof ( scsidev->lun ) );
996  DBGC ( scsidev, "SCSI %p created for LUN " SCSI_LUN_FORMAT "\n",
997  scsidev, SCSI_LUN_DATA ( scsidev->lun ) );
998 
999  /* Attach to SCSI and parent interfaces, mortalise self, and return */
1000  intf_plug_plug ( &scsidev->scsi, scsi );
1001  intf_plug_plug ( &scsidev->block, block );
1002  ref_put ( &scsidev->refcnt );
1003  return 0;
1004 }
struct interface scsi
SCSI control interface.
Definition: scsi.c:235
A SCSI device.
Definition: scsi.c:229
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
struct list_head cmds
List of commands.
Definition: scsi.c:250
uint16_t block
Definition: tftp.h:12
static void process_init(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process and add to process list.
Definition: process.h:161
#define DBGC(...)
Definition: compiler.h:505
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
static struct interface_descriptor scsidev_block_desc
SCSI device block interface descriptor.
Definition: scsi.c:870
static struct interface_descriptor scsidev_ready_desc
SCSI device TEST UNIT READY interface descriptor.
Definition: scsi.c:925
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct interface ready
TEST UNIT READY interface.
Definition: scsi.c:243
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct refcnt refcnt
Reference count.
Definition: scsi.c:231
struct interface block
Block control interface.
Definition: scsi.c:233
uint8_t lun
Logical Unit Number.
Definition: edd.h:32
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#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
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
static struct interface_descriptor scsidev_scsi_desc
SCSI device SCSI interface descriptor.
Definition: scsi.c:964
static struct process_descriptor scsidev_process_desc
SCSI device process descriptor.
Definition: scsi.c:969
struct scsi_lun lun
SCSI LUN.
Definition: scsi.c:238
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct process process
TEST UNIT READY process.
Definition: scsi.c:245
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

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(), and srp_open().

Variable Documentation

◆ opcode

uint8_t opcode

Opcode (0x28)

Opcode (0x00)

Opcode (0x9e)

Opcode (0x25)

Opcode (0x8a)

Opcode (0x2a)

Opcode (0x88)

Definition at line 16 of file scsi.h.

◆ flags

uint8_t flags

Flags.

Definition at line 18 of file scsi.h.

◆ group

uint8_t group

Group number.

Definition at line 25 of file scsi.h.

Referenced by vmbus_signal_monitor().

◆ 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 30 of file scsi.h.

◆ control

uint8_t control

Control byte.

Definition at line 32 of file scsi.h.

◆ reserved_a

uint8_t reserved_a

Reserved.

Definition at line 18 of file scsi.h.

◆ reserved_b

uint8_t reserved_b[3]

Reserved.

Definition at line 25 of file scsi.h.

◆ blksize

uint32_t blksize

Block length in bytes.

Definition at line 18 of file scsi.h.

◆ service_action

uint8_t service_action

Service action.

Definition at line 18 of file scsi.h.

◆ reserved

uint8_t reserved

Reserved.

Definition at line 30 of file scsi.h.

◆ u16

Definition at line 15 of file scsi.h.

◆ code

uint8_t code

◆ key

uint8_t key

Sense key.

Definition at line 20 of file scsi.h.

◆ info

uint32_t info

Information.

Definition at line 22 of file scsi.h.

◆ cs_info

uint32_t cs_info

Command-specific information.

Definition at line 26 of file scsi.h.

◆ additional

uint16_t additional

Additional sense code and qualifier.

Definition at line 28 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().