iPXE
Data Structures | Defines | 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...

Defines

#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)   ( ( (code) & 0x7e ) == 0x70 )
 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)   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.
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.


Define Documentation

#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().

#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().

#define SCSI_LUN_DATA (   lun)
Value:
ntohs ( (lun).u16[0] ), ntohs ( (lun).u16[1] ),                   \
        ntohs ( (lun).u16[2] ), ntohs ( (lun).u16[3] )

printf() parameters for dumping a scsi_lun

Definition at line 244 of file scsi.h.

Referenced by ibft_fill_target(), and scsi_open().

#define SCSI_SENSE_CODE_MASK   0x7f

SCSI sense response code mask.

Definition at line 309 of file scsi.h.

Referenced by scsicmd_response().

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

Referenced by scsi_parse_sense().

#define SCSI_SENSE_KEY_MASK   0x0f

SCSI sense key mask.

Definition at line 319 of file scsi.h.

Referenced by scsicmd_response().

#define scsi_command_TYPE (   object_type)
Value:
typeof ( int ( object_type, struct interface *data,             \
                       struct scsi_cmd *command ) )

Definition at line 342 of file scsi.h.

Referenced by scsi_command().

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

Definition at line 347 of file scsi.h.

Referenced by scsi_response().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
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.

References EINVAL, htons, memset(), strtoul(), and scsi_lun::u16.

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

                                                                    {
        char *p;
        int i;

        memset ( lun, 0, sizeof ( *lun ) );
        if ( lun_string ) {
                p = ( char * ) lun_string;
                for ( i = 0 ; i < 4 ; i++ ) {
                        lun->u16[i] = htons ( strtoul ( p, &p, 16 ) );
                        if ( *p == '\0' )
                                break;
                        if ( *p != '-' )
                                return -EINVAL;
                        p++;
                }
                if ( *p )
                        return -EINVAL;
        }

        return 0;
}
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.

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

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

                                                            {
        const union scsi_sns *sns = data;

        /* Avoid returning uninitialised data */
        memset ( sense, 0, sizeof ( *sense ) );

        /* Copy, assuming descriptor-format data */
        if ( len < sizeof ( sns->desc ) )
                return;
        memcpy ( sense, &sns->desc, sizeof ( *sense ) );

        /* Convert fixed-format to descriptor-format, if applicable */
        if ( len < sizeof ( sns->fixed ) )
                return;
        if ( ! SCSI_SENSE_FIXED ( sns->code ) )
                return;
        sense->additional = sns->fixed.additional;
}
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.

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

                                              {
        struct interface *dest;
        scsi_command_TYPE ( void * ) *op =
                intf_get_dest_op ( control, scsi_command, &dest );
        void *object = intf_object ( dest );
        int tap;

        if ( op ) {
                tap = op ( object, data, command );
        } else {
                /* Default is to fail to issue the command */
                tap = -EOPNOTSUPP;
        }

        intf_put ( dest );
        return tap;
}
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.

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().

                                                                         {
        struct interface *dest;
        scsi_response_TYPE ( void * ) *op =
                intf_get_dest_op ( intf, scsi_response, &dest );
        void *object = intf_object ( dest );

        if ( op ) {
                op ( object, response );
        } else {
                /* Default is to ignore the response */
        }

        intf_put ( dest );
}
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.

References scsi_device::block, scsi_device::cmds, DBGC, ENOMEM, INIT_LIST_HEAD, intf_init(), intf_plug_plug(), 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, and zalloc().

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

                                       {
        struct scsi_device *scsidev;

        /* Allocate and initialise structure */
        scsidev = zalloc ( sizeof ( *scsidev ) );
        if ( ! scsidev )
                return -ENOMEM;
        ref_init ( &scsidev->refcnt, NULL );
        intf_init ( &scsidev->block, &scsidev_block_desc, &scsidev->refcnt );
        intf_init ( &scsidev->scsi, &scsidev_scsi_desc, &scsidev->refcnt );
        intf_init ( &scsidev->ready, &scsidev_ready_desc, &scsidev->refcnt );
        process_init ( &scsidev->process, &scsidev_process_desc,
                       &scsidev->refcnt );
        INIT_LIST_HEAD ( &scsidev->cmds );
        memcpy ( &scsidev->lun, lun, sizeof ( scsidev->lun ) );
        DBGC ( scsidev, "SCSI %p created for LUN " SCSI_LUN_FORMAT "\n",
               scsidev, SCSI_LUN_DATA ( scsidev->lun ) );

        /* Attach to SCSI and parent interfaces, mortalise self, and return */
        intf_plug_plug ( &scsidev->scsi, scsi );
        intf_plug_plug ( &scsidev->block, block );
        ref_put ( &scsidev->refcnt );
        return 0;
}

Variable Documentation

Opcode (0x28)

Opcode (0x00)

Opcode (0x9e)

Opcode (0x25)

Opcode (0x8a)

Opcode (0x2a)

Opcode (0x88)

Definition at line 73 of file scsi.h.

Flags.

Definition at line 75 of file scsi.h.

Group number.

Definition at line 82 of file scsi.h.

Referenced by vmbus_signal_monitor().

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

Control byte.

Definition at line 89 of file scsi.h.

Reserved.

Definition at line 158 of file scsi.h.

Reserved.

Definition at line 165 of file scsi.h.

Block length in bytes.

Definition at line 166 of file scsi.h.

Service action.

Definition at line 188 of file scsi.h.

Reserved.

Definition at line 200 of file scsi.h.

Definition at line 239 of file scsi.h.

Response code.

Definition at line 288 of file scsi.h.

Referenced by ar9300_eeprom_restore_internal(), deflate_inflate(), hook_bios_interrupt(), and vesafb_rc().

Sense key.

Definition at line 292 of file scsi.h.

Information.

Definition at line 294 of file scsi.h.

Command-specific information.

Definition at line 298 of file scsi.h.

Additional sense code and qualifier.

Definition at line 300 of file scsi.h.