scsi.h File Reference

SCSI devices. More...

#include <stdint.h>
#include <gpxe/blockdev.h>
#include <gpxe/uaccess.h>
#include <gpxe/refcnt.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...
union  scsi_cdb
 A SCSI Command Data Block. More...
struct  scsi_command
 A SCSI command. More...
struct  scsi_lun
 A SCSI LUN. More...
struct  scsi_device
 A SCSI device. More...

Defines

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

Functions

 FILE_LICENCE (GPL2_OR_LATER)
int scsi_detached_command (struct scsi_device *scsi, struct scsi_command *command)
int init_scsidev (struct scsi_device *scsi)
 Initialise SCSI device.
int scsi_parse_lun (const char *lun_string, struct scsi_lun *lun)
 Parse SCSI LUN.

Variables

struct scsi_cdb_read_10 packed
 A SCSI "READ (10)" CDB.


Detailed Description

SCSI devices.

Definition in file scsi.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

int scsi_detached_command ( struct scsi_device scsi,
struct scsi_command command 
)

int init_scsidev ( struct scsi_device scsi  ) 

Initialise SCSI device.

Parameters:
scsi SCSI device
Return values:
rc Return status code
Initialises a SCSI device. The scsi_device::command and scsi_device::lun fields must already be filled in. This function will configure scsi_device::blockdev, including issuing a READ CAPACITY call to determine the block size and total device size.

Definition at line 289 of file scsi.c.

References scsi_device::blockdev, block_device::blocks, DBGC, block_device::op, SCSI_MAX_DUMMY_READ_CAP, scsi_read_capacity_10(), scsi_read_capacity_16(), and strerror().

Referenced by ib_srpboot(), and iscsiboot().

00289                                               {
00290         unsigned int i;
00291         int rc;
00292 
00293         /* Issue some theoretically extraneous READ CAPACITY (10)
00294          * commands, solely in order to draw out the "CHECK CONDITION
00295          * (power-on occurred)", "CHECK CONDITION (reported LUNs data
00296          * has changed)" etc. that some dumb targets insist on sending
00297          * as an error at start of day.  The precise command that we
00298          * use is unimportant; we just need to provide the target with
00299          * an opportunity to send its responses.
00300          */
00301         for ( i = 0 ; i < SCSI_MAX_DUMMY_READ_CAP ; i++ ) {
00302                 if ( ( rc = scsi_read_capacity_10 ( &scsi->blockdev ) ) == 0 )
00303                         break;
00304                 DBGC ( scsi, "SCSI %p ignoring start-of-day error (#%d)\n",
00305                        scsi, ( i + 1 ) );
00306         }
00307 
00308         /* Try READ CAPACITY (10), which is a mandatory command, first. */
00309         scsi->blockdev.op = &scsi_operations_10;
00310         if ( ( rc = scsi_read_capacity_10 ( &scsi->blockdev ) ) != 0 ) {
00311                 DBGC ( scsi, "SCSI %p could not READ CAPACITY (10): %s\n",
00312                        scsi, strerror ( rc ) );
00313                 return rc;
00314         }
00315 
00316         /* If capacity range was exceeded (i.e. capacity.lba was
00317          * 0xffffffff, meaning that blockdev->blocks is now zero), use
00318          * READ CAPACITY (16) instead.  READ CAPACITY (16) is not
00319          * mandatory, so we can't just use it straight off.
00320          */
00321         if ( scsi->blockdev.blocks == 0 ) {
00322                 scsi->blockdev.op = &scsi_operations_16;
00323                 if ( ( rc = scsi_read_capacity_16 ( &scsi->blockdev ) ) != 0 ){
00324                         DBGC ( scsi, "SCSI %p could not READ CAPACITY (16): "
00325                                "%s\n", scsi, strerror ( rc ) );
00326                         return rc;
00327                 }
00328         }
00329 
00330         DBGC ( scsi, "SCSI %p using READ/WRITE (%d) commands\n", scsi,
00331                ( ( scsi->blockdev.op == &scsi_operations_10 ) ? 10 : 16 ) );
00332         DBGC ( scsi, "SCSI %p capacity is %ld MB (%#llx blocks)\n", scsi,
00333                ( ( unsigned long ) ( scsi->blockdev.blocks >> 11 ) ),
00334                scsi->blockdev.blocks );
00335 
00336         return 0;
00337 }

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

Parse SCSI LUN.

Parameters:
lun_string LUN string representation
lun LUN to fill in
Return values:
rc Return status code

Definition at line 346 of file scsi.c.

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

Referenced by ib_srp_parse_lun(), and iscsi_parse_root_path().

00346                                                                     {
00347         char *p;
00348         int i;
00349 
00350         memset ( lun, 0, sizeof ( *lun ) );
00351         if ( lun_string ) {
00352                 p = ( char * ) lun_string;
00353                 for ( i = 0 ; i < 4 ; i++ ) {
00354                         lun->u16[i] = htons ( strtoul ( p, &p, 16 ) );
00355                         if ( *p == '\0' )
00356                                 break;
00357                         if ( *p != '-' )
00358                                 return -EINVAL;
00359                         p++;
00360                 }
00361                 if ( *p )
00362                         return -EINVAL;
00363         }
00364 
00365         return 0;
00366 }


Generated on Tue Apr 6 20:01:52 2010 for gPXE by  doxygen 1.5.7.1