iPXE
Data Structures | Macros | Enumerations | Functions | Variables
scsi.c File Reference

SCSI block device. More...

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <byteswap.h>
#include <errno.h>
#include <ipxe/list.h>
#include <ipxe/process.h>
#include <ipxe/xfer.h>
#include <ipxe/blockdev.h>
#include <ipxe/scsi.h>

Go to the source code of this file.

Data Structures

struct  scsi_device
 A SCSI device. More...
 
struct  scsi_command
 A SCSI command. More...
 
struct  scsi_command_type
 A SCSI command type. More...
 
struct  scsi_read_capacity_private
 SCSI READ CAPACITY private data. More...
 

Macros

#define SCSI_READY_MAX_RETRIES   10
 Maximum number of TEST UNIT READY retries. More...
 
#define EIO_NO_SENSE   __einfo_error ( EINFO_EIO_NO_SENSE )
 
#define EINFO_EIO_NO_SENSE   __einfo_uniqify ( EINFO_EIO, 0x00, "No sense" )
 
#define EIO_RECOVERED_ERROR   __einfo_error ( EINFO_EIO_RECOVERED_ERROR )
 
#define EINFO_EIO_RECOVERED_ERROR   __einfo_uniqify ( EINFO_EIO, 0x01, "Recovered error" )
 
#define EIO_NOT_READY   __einfo_error ( EINFO_EIO_NOT_READY )
 
#define EINFO_EIO_NOT_READY   __einfo_uniqify ( EINFO_EIO, 0x02, "Not ready" )
 
#define EIO_MEDIUM_ERROR   __einfo_error ( EINFO_EIO_MEDIUM_ERROR )
 
#define EINFO_EIO_MEDIUM_ERROR   __einfo_uniqify ( EINFO_EIO, 0x03, "Medium error" )
 
#define EIO_HARDWARE_ERROR   __einfo_error ( EINFO_EIO_HARDWARE_ERROR )
 
#define EINFO_EIO_HARDWARE_ERROR   __einfo_uniqify ( EINFO_EIO, 0x04, "Hardware error" )
 
#define EIO_ILLEGAL_REQUEST   __einfo_error ( EINFO_EIO_ILLEGAL_REQUEST )
 
#define EINFO_EIO_ILLEGAL_REQUEST   __einfo_uniqify ( EINFO_EIO, 0x05, "Illegal request" )
 
#define EIO_UNIT_ATTENTION   __einfo_error ( EINFO_EIO_UNIT_ATTENTION )
 
#define EINFO_EIO_UNIT_ATTENTION   __einfo_uniqify ( EINFO_EIO, 0x06, "Unit attention" )
 
#define EIO_DATA_PROTECT   __einfo_error ( EINFO_EIO_DATA_PROTECT )
 
#define EINFO_EIO_DATA_PROTECT   __einfo_uniqify ( EINFO_EIO, 0x07, "Data protect" )
 
#define EIO_BLANK_CHECK   __einfo_error ( EINFO_EIO_BLANK_CHECK )
 
#define EINFO_EIO_BLANK_CHECK   __einfo_uniqify ( EINFO_EIO, 0x08, "Blank check" )
 
#define EIO_VENDOR_SPECIFIC   __einfo_error ( EINFO_EIO_VENDOR_SPECIFIC )
 
#define EINFO_EIO_VENDOR_SPECIFIC   __einfo_uniqify ( EINFO_EIO, 0x09, "Vendor specific" )
 
#define EIO_COPY_ABORTED   __einfo_error ( EINFO_EIO_COPY_ABORTED )
 
#define EINFO_EIO_COPY_ABORTED   __einfo_uniqify ( EINFO_EIO, 0x0a, "Copy aborted" )
 
#define EIO_ABORTED_COMMAND   __einfo_error ( EINFO_EIO_ABORTED_COMMAND )
 
#define EINFO_EIO_ABORTED_COMMAND   __einfo_uniqify ( EINFO_EIO, 0x0b, "Aborted command" )
 
#define EIO_RESERVED   __einfo_error ( EINFO_EIO_RESERVED )
 
#define EINFO_EIO_RESERVED   __einfo_uniqify ( EINFO_EIO, 0x0c, "Reserved" )
 
#define EIO_VOLUME_OVERFLOW   __einfo_error ( EINFO_EIO_VOLUME_OVERFLOW )
 
#define EINFO_EIO_VOLUME_OVERFLOW   __einfo_uniqify ( EINFO_EIO, 0x0d, "Volume overflow" )
 
#define EIO_MISCOMPARE   __einfo_error ( EINFO_EIO_MISCOMPARE )
 
#define EINFO_EIO_MISCOMPARE   __einfo_uniqify ( EINFO_EIO, 0x0e, "Miscompare" )
 
#define EIO_COMPLETED   __einfo_error ( EINFO_EIO_COMPLETED )
 
#define EINFO_EIO_COMPLETED   __einfo_uniqify ( EINFO_EIO, 0x0f, "Completed" )
 
#define EIO_SENSE(key)
 

Enumerations

enum  scsi_device_flags { SCSIDEV_UNIT_TESTED = 0x0001, SCSIDEV_UNIT_READY = 0x0002 }
 SCSI device flags. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
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...
 
static struct scsi_devicescsidev_get (struct scsi_device *scsidev)
 Get reference to SCSI device. More...
 
static void scsidev_put (struct scsi_device *scsidev)
 Drop reference to SCSI device. More...
 
static struct scsi_commandscsicmd_get (struct scsi_command *scsicmd)
 Get reference to SCSI command. More...
 
static void scsicmd_put (struct scsi_command *scsicmd)
 Drop reference to SCSI command. More...
 
static void * scsicmd_priv (struct scsi_command *scsicmd)
 Get SCSI command private data. More...
 
static void scsicmd_free (struct refcnt *refcnt)
 Free SCSI command. More...
 
static void scsicmd_close (struct scsi_command *scsicmd, int rc)
 Close SCSI command. More...
 
static int scsicmd_command (struct scsi_command *scsicmd)
 Construct and issue SCSI command. More...
 
static void scsicmd_done (struct scsi_command *scsicmd, int rc)
 Handle SCSI command completion. More...
 
static void scsicmd_response (struct scsi_command *scsicmd, struct scsi_rsp *response)
 Handle SCSI response. More...
 
static void scsicmd_read_cmd (struct scsi_command *scsicmd, struct scsi_cmd *command)
 Construct SCSI READ command. More...
 
static void scsicmd_write_cmd (struct scsi_command *scsicmd, struct scsi_cmd *command)
 Construct SCSI WRITE command. More...
 
static void scsicmd_read_capacity_cmd (struct scsi_command *scsicmd, struct scsi_cmd *command)
 Construct SCSI READ CAPACITY command. More...
 
static void scsicmd_read_capacity_done (struct scsi_command *scsicmd, int rc)
 Handle SCSI READ CAPACITY command completion. More...
 
static void scsicmd_test_unit_ready_cmd (struct scsi_command *scsicmd __unused, struct scsi_cmd *command)
 Construct SCSI TEST UNIT READY command. More...
 
static int scsidev_command (struct scsi_device *scsidev, struct interface *block, struct scsi_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
 Create SCSI command. More...
 
static int scsidev_read (struct scsi_device *scsidev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
 Issue SCSI block read. More...
 
static int scsidev_write (struct scsi_device *scsidev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
 Issue SCSI block write. More...
 
static int scsidev_read_capacity (struct scsi_device *scsidev, struct interface *block)
 Read SCSI device capacity. More...
 
static int scsidev_test_unit_ready (struct scsi_device *scsidev, struct interface *block)
 Test to see if SCSI device is ready. More...
 
static size_t scsidev_window (struct scsi_device *scsidev)
 Check SCSI device flow-control window. More...
 
static void scsidev_close (struct scsi_device *scsidev, int rc)
 Close SCSI device. More...
 
static void scsidev_ready (struct scsi_device *scsidev, int rc)
 Handle SCSI TEST UNIT READY response. More...
 
static void scsidev_step (struct scsi_device *scsidev)
 SCSI TEST UNIT READY process. More...
 
int scsi_open (struct interface *block, struct interface *scsi, struct scsi_lun *lun)
 Open SCSI device. More...
 

Variables

static struct scsi_command_type scsicmd_read
 SCSI READ command type. More...
 
static struct scsi_command_type scsicmd_write
 SCSI WRITE command type. More...
 
static struct scsi_command_type scsicmd_read_capacity
 SCSI READ CAPACITY command type. More...
 
static struct scsi_command_type scsicmd_test_unit_ready
 SCSI TEST UNIT READY command type. More...
 
static struct interface_operation scsicmd_block_op []
 SCSI command block interface operations. More...
 
static struct interface_descriptor scsicmd_block_desc
 SCSI command block interface descriptor. More...
 
static struct interface_operation scsicmd_scsi_op []
 SCSI command SCSI interface operations. More...
 
static struct interface_descriptor scsicmd_scsi_desc
 SCSI command SCSI interface descriptor. More...
 
static struct interface_operation scsidev_block_op []
 SCSI device block interface operations. More...
 
static struct interface_descriptor scsidev_block_desc
 SCSI device block interface descriptor. More...
 
static struct interface_operation scsidev_ready_op []
 SCSI device TEST UNIT READY interface operations. More...
 
static struct interface_descriptor scsidev_ready_desc
 SCSI device TEST UNIT READY interface descriptor. More...
 
static struct interface_operation scsidev_scsi_op []
 SCSI device SCSI interface operations. More...
 
static struct interface_descriptor scsidev_scsi_desc
 SCSI device SCSI interface descriptor. More...
 
static struct process_descriptor scsidev_process_desc
 SCSI device process descriptor. More...
 

Detailed Description

SCSI block device.

Definition in file scsi.c.

Macro Definition Documentation

◆ SCSI_READY_MAX_RETRIES

#define SCSI_READY_MAX_RETRIES   10

Maximum number of TEST UNIT READY retries.

Definition at line 44 of file scsi.c.

◆ EIO_NO_SENSE

#define EIO_NO_SENSE   __einfo_error ( EINFO_EIO_NO_SENSE )

Definition at line 47 of file scsi.c.

◆ EINFO_EIO_NO_SENSE

#define EINFO_EIO_NO_SENSE   __einfo_uniqify ( EINFO_EIO, 0x00, "No sense" )

Definition at line 48 of file scsi.c.

◆ EIO_RECOVERED_ERROR

#define EIO_RECOVERED_ERROR   __einfo_error ( EINFO_EIO_RECOVERED_ERROR )

Definition at line 50 of file scsi.c.

◆ EINFO_EIO_RECOVERED_ERROR

#define EINFO_EIO_RECOVERED_ERROR   __einfo_uniqify ( EINFO_EIO, 0x01, "Recovered error" )

Definition at line 51 of file scsi.c.

◆ EIO_NOT_READY

#define EIO_NOT_READY   __einfo_error ( EINFO_EIO_NOT_READY )

Definition at line 53 of file scsi.c.

◆ EINFO_EIO_NOT_READY

#define EINFO_EIO_NOT_READY   __einfo_uniqify ( EINFO_EIO, 0x02, "Not ready" )

Definition at line 54 of file scsi.c.

◆ EIO_MEDIUM_ERROR

#define EIO_MEDIUM_ERROR   __einfo_error ( EINFO_EIO_MEDIUM_ERROR )

Definition at line 56 of file scsi.c.

◆ EINFO_EIO_MEDIUM_ERROR

#define EINFO_EIO_MEDIUM_ERROR   __einfo_uniqify ( EINFO_EIO, 0x03, "Medium error" )

Definition at line 57 of file scsi.c.

◆ EIO_HARDWARE_ERROR

#define EIO_HARDWARE_ERROR   __einfo_error ( EINFO_EIO_HARDWARE_ERROR )

Definition at line 59 of file scsi.c.

◆ EINFO_EIO_HARDWARE_ERROR

#define EINFO_EIO_HARDWARE_ERROR   __einfo_uniqify ( EINFO_EIO, 0x04, "Hardware error" )

Definition at line 60 of file scsi.c.

◆ EIO_ILLEGAL_REQUEST

#define EIO_ILLEGAL_REQUEST   __einfo_error ( EINFO_EIO_ILLEGAL_REQUEST )

Definition at line 62 of file scsi.c.

◆ EINFO_EIO_ILLEGAL_REQUEST

#define EINFO_EIO_ILLEGAL_REQUEST   __einfo_uniqify ( EINFO_EIO, 0x05, "Illegal request" )

Definition at line 63 of file scsi.c.

◆ EIO_UNIT_ATTENTION

#define EIO_UNIT_ATTENTION   __einfo_error ( EINFO_EIO_UNIT_ATTENTION )

Definition at line 65 of file scsi.c.

◆ EINFO_EIO_UNIT_ATTENTION

#define EINFO_EIO_UNIT_ATTENTION   __einfo_uniqify ( EINFO_EIO, 0x06, "Unit attention" )

Definition at line 66 of file scsi.c.

◆ EIO_DATA_PROTECT

#define EIO_DATA_PROTECT   __einfo_error ( EINFO_EIO_DATA_PROTECT )

Definition at line 68 of file scsi.c.

◆ EINFO_EIO_DATA_PROTECT

#define EINFO_EIO_DATA_PROTECT   __einfo_uniqify ( EINFO_EIO, 0x07, "Data protect" )

Definition at line 69 of file scsi.c.

◆ EIO_BLANK_CHECK

#define EIO_BLANK_CHECK   __einfo_error ( EINFO_EIO_BLANK_CHECK )

Definition at line 71 of file scsi.c.

◆ EINFO_EIO_BLANK_CHECK

#define EINFO_EIO_BLANK_CHECK   __einfo_uniqify ( EINFO_EIO, 0x08, "Blank check" )

Definition at line 72 of file scsi.c.

◆ EIO_VENDOR_SPECIFIC

#define EIO_VENDOR_SPECIFIC   __einfo_error ( EINFO_EIO_VENDOR_SPECIFIC )

Definition at line 74 of file scsi.c.

◆ EINFO_EIO_VENDOR_SPECIFIC

#define EINFO_EIO_VENDOR_SPECIFIC   __einfo_uniqify ( EINFO_EIO, 0x09, "Vendor specific" )

Definition at line 75 of file scsi.c.

◆ EIO_COPY_ABORTED

#define EIO_COPY_ABORTED   __einfo_error ( EINFO_EIO_COPY_ABORTED )

Definition at line 77 of file scsi.c.

◆ EINFO_EIO_COPY_ABORTED

#define EINFO_EIO_COPY_ABORTED   __einfo_uniqify ( EINFO_EIO, 0x0a, "Copy aborted" )

Definition at line 78 of file scsi.c.

◆ EIO_ABORTED_COMMAND

#define EIO_ABORTED_COMMAND   __einfo_error ( EINFO_EIO_ABORTED_COMMAND )

Definition at line 80 of file scsi.c.

◆ EINFO_EIO_ABORTED_COMMAND

#define EINFO_EIO_ABORTED_COMMAND   __einfo_uniqify ( EINFO_EIO, 0x0b, "Aborted command" )

Definition at line 81 of file scsi.c.

◆ EIO_RESERVED

#define EIO_RESERVED   __einfo_error ( EINFO_EIO_RESERVED )

Definition at line 83 of file scsi.c.

◆ EINFO_EIO_RESERVED

#define EINFO_EIO_RESERVED   __einfo_uniqify ( EINFO_EIO, 0x0c, "Reserved" )

Definition at line 84 of file scsi.c.

◆ EIO_VOLUME_OVERFLOW

#define EIO_VOLUME_OVERFLOW   __einfo_error ( EINFO_EIO_VOLUME_OVERFLOW )

Definition at line 86 of file scsi.c.

◆ EINFO_EIO_VOLUME_OVERFLOW

#define EINFO_EIO_VOLUME_OVERFLOW   __einfo_uniqify ( EINFO_EIO, 0x0d, "Volume overflow" )

Definition at line 87 of file scsi.c.

◆ EIO_MISCOMPARE

#define EIO_MISCOMPARE   __einfo_error ( EINFO_EIO_MISCOMPARE )

Definition at line 89 of file scsi.c.

◆ EINFO_EIO_MISCOMPARE

#define EINFO_EIO_MISCOMPARE   __einfo_uniqify ( EINFO_EIO, 0x0e, "Miscompare" )

Definition at line 90 of file scsi.c.

◆ EIO_COMPLETED

#define EIO_COMPLETED   __einfo_error ( EINFO_EIO_COMPLETED )

Definition at line 92 of file scsi.c.

◆ EINFO_EIO_COMPLETED

#define EINFO_EIO_COMPLETED   __einfo_uniqify ( EINFO_EIO, 0x0f, "Completed" )

Definition at line 93 of file scsi.c.

◆ EIO_SENSE

#define EIO_SENSE (   key)
Value:
#define EIO_VOLUME_OVERFLOW
Definition: scsi.c:86
#define EIO_RESERVED
Definition: scsi.c:83
#define EIO_UNIT_ATTENTION
Definition: scsi.c:65
#define EIO_MISCOMPARE
Definition: scsi.c:89
#define EIO_DATA_PROTECT
Definition: scsi.c:68
#define EIO_ABORTED_COMMAND
Definition: scsi.c:80
#define EIO_VENDOR_SPECIFIC
Definition: scsi.c:74
#define EIO_NO_SENSE
Definition: scsi.c:47
#define EIO_COMPLETED
Definition: scsi.c:92
#define EIO_COPY_ABORTED
Definition: scsi.c:77
#define EIO_NOT_READY
Definition: scsi.c:53
#define EINFO_EIO
Definition: errno.h:434
#define EIO_BLANK_CHECK
Definition: scsi.c:71
#define EIO_MEDIUM_ERROR
Definition: scsi.c:56
#define EIO_ILLEGAL_REQUEST
Definition: scsi.c:62
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition: errno.h:225
#define EIO_RECOVERED_ERROR
Definition: scsi.c:50
#define EIO_HARDWARE_ERROR
Definition: scsi.c:59
union @382 key
Sense key.
Definition: crypto.h:284

Definition at line 95 of file scsi.c.

Enumeration Type Documentation

◆ scsi_device_flags

SCSI device flags.

Enumerator
SCSIDEV_UNIT_TESTED 

TEST UNIT READY has been issued.

SCSIDEV_UNIT_READY 

TEST UNIT READY has completed successfully.

Definition at line 254 of file scsi.c.

254  {
255  /** TEST UNIT READY has been issued */
256  SCSIDEV_UNIT_TESTED = 0x0001,
257  /** TEST UNIT READY has completed successfully */
258  SCSIDEV_UNIT_READY = 0x0002,
259 };
TEST UNIT READY has been issued.
Definition: scsi.c:256
TEST UNIT READY has completed successfully.
Definition: scsi.c:258

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:471
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
uint8_t data[48]
Additional event data.
Definition: ena.h:22
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:159
A SCSI command.
Definition: scsi.c:262
An object interface.
Definition: interface.h:124
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:149
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269

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 =
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:159
struct interface * intf
Original interface.
Definition: interface.h:158
An object interface.
Definition: interface.h:124
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:149
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269

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

◆ scsidev_get()

static struct scsi_device* scsidev_get ( struct scsi_device scsidev)
inlinestatic

Get reference to SCSI device.

Parameters
scsidevSCSI device
Return values
scsidevSCSI device

Definition at line 322 of file scsi.c.

322  {
323  ref_get ( &scsidev->refcnt );
324  return scsidev;
325 }
struct refcnt refcnt
Reference count.
Definition: scsi.c:231
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92

References ref_get, and scsi_device::refcnt.

Referenced by scsidev_command().

◆ scsidev_put()

static void scsidev_put ( struct scsi_device scsidev)
inlinestatic

Drop reference to SCSI device.

Parameters
scsidevSCSI device

Definition at line 333 of file scsi.c.

333  {
334  ref_put ( &scsidev->refcnt );
335 }
struct refcnt refcnt
Reference count.
Definition: scsi.c:231
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References ref_put, and scsi_device::refcnt.

Referenced by scsicmd_free().

◆ scsicmd_get()

static struct scsi_command* scsicmd_get ( struct scsi_command scsicmd)
inlinestatic

Get reference to SCSI command.

Parameters
scsicmdSCSI command
Return values
scsicmdSCSI command

Definition at line 344 of file scsi.c.

344  {
345  ref_get ( &scsicmd->refcnt );
346  return scsicmd;
347 }
struct refcnt refcnt
Reference count.
Definition: scsi.c:264
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92

References ref_get, and scsi_command::refcnt.

◆ scsicmd_put()

static void scsicmd_put ( struct scsi_command scsicmd)
inlinestatic

Drop reference to SCSI command.

Parameters
scsicmdSCSI command

Definition at line 355 of file scsi.c.

355  {
356  ref_put ( &scsicmd->refcnt );
357 }
struct refcnt refcnt
Reference count.
Definition: scsi.c:264
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References ref_put, and scsi_command::refcnt.

Referenced by scsicmd_close().

◆ scsicmd_priv()

static void* scsicmd_priv ( struct scsi_command scsicmd)
inlinestatic

Get SCSI command private data.

Parameters
scsicmdSCSI command
Return values
privPrivate data

Definition at line 366 of file scsi.c.

366  {
367  return scsicmd->priv;
368 }
uint8_t priv[0]
Private data.
Definition: scsi.c:289

References scsi_command::priv.

Referenced by scsicmd_read_capacity_cmd(), and scsicmd_read_capacity_done().

◆ scsicmd_free()

static void scsicmd_free ( struct refcnt refcnt)
static

Free SCSI command.

Parameters
refcntReference count

Definition at line 375 of file scsi.c.

375  {
376  struct scsi_command *scsicmd =
377  container_of ( refcnt, struct scsi_command, refcnt );
378 
379  /* Drop reference to SCSI device */
380  scsidev_put ( scsicmd->scsidev );
381 
382  /* Free command */
383  free ( scsicmd );
384 }
A reference counter.
Definition: refcnt.h:26
A SCSI command.
Definition: scsi.c:262
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
static void scsidev_put(struct scsi_device *scsidev)
Drop reference to SCSI device.
Definition: scsi.c:333

References container_of, free, scsi_command::scsidev, and scsidev_put().

Referenced by scsidev_command().

◆ scsicmd_close()

static void scsicmd_close ( struct scsi_command scsicmd,
int  rc 
)
static

Close SCSI command.

Parameters
scsicmdSCSI command
rcReason for close

Definition at line 392 of file scsi.c.

392  {
393  struct scsi_device *scsidev = scsicmd->scsidev;
394 
395  if ( rc != 0 ) {
396  DBGC ( scsidev, "SCSI %p tag %08x closed: %s\n",
397  scsidev, scsicmd->tag, strerror ( rc ) );
398  }
399 
400  /* Remove from list of commands */
401  list_del ( &scsicmd->list );
402 
403  /* Shut down interfaces */
404  intfs_shutdown ( rc, &scsicmd->scsi, &scsicmd->block, NULL );
405 
406  /* Drop list's reference */
407  scsicmd_put ( scsicmd );
408 }
A SCSI device.
Definition: scsi.c:229
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void scsicmd_put(struct scsi_command *scsicmd)
Drop reference to SCSI command.
Definition: scsi.c:355
#define DBGC(...)
Definition: compiler.h:505
void intfs_shutdown(int rc,...)
Shut down multiple object interfaces.
Definition: interface.c:326
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct interface scsi
SCSI data interface.
Definition: scsi.c:273
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint32_t tag
Command tag.
Definition: scsi.c:286
struct list_head list
List of SCSI commands.
Definition: scsi.c:268
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
struct interface block
Block data interface.
Definition: scsi.c:271
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References scsi_command::block, DBGC, intfs_shutdown(), scsi_command::list, list_del, NULL, rc, scsi_command::scsi, scsicmd_put(), scsi_command::scsidev, strerror(), and scsi_command::tag.

Referenced by scsicmd_read_capacity_done(), scsidev_close(), and scsidev_command().

◆ scsicmd_command()

static int scsicmd_command ( struct scsi_command scsicmd)
static

Construct and issue SCSI command.

Return values
rcReturn status code

Definition at line 415 of file scsi.c.

415  {
416  struct scsi_device *scsidev = scsicmd->scsidev;
417  struct scsi_cmd command;
418  int tag;
419  int rc;
420 
421  /* Construct command */
422  memset ( &command, 0, sizeof ( command ) );
423  memcpy ( &command.lun, &scsidev->lun, sizeof ( command.lun ) );
424  scsicmd->type->cmd ( scsicmd, &command );
425 
426  /* Issue command */
427  if ( ( tag = scsi_command ( &scsidev->scsi, &scsicmd->scsi,
428  &command ) ) < 0 ) {
429  rc = tag;
430  DBGC ( scsidev, "SCSI %p could not issue command: %s\n",
431  scsidev, strerror ( rc ) );
432  return rc;
433  }
434 
435  /* Record tag */
436  if ( scsicmd->tag ) {
437  DBGC ( scsidev, "SCSI %p tag %08x is now tag %08x\n",
438  scsidev, scsicmd->tag, tag );
439  }
440  scsicmd->tag = tag;
441  DBGC2 ( scsidev, "SCSI %p tag %08x %s " SCSI_CDB_FORMAT "\n",
442  scsidev, scsicmd->tag, scsicmd->type->name,
443  SCSI_CDB_DATA ( command.cdb ) );
444 
445  return 0;
446 }
struct interface scsi
SCSI control interface.
Definition: scsi.c:235
A SCSI device.
Definition: scsi.c:229
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A command-line command.
Definition: command.h:9
#define DBGC(...)
Definition: compiler.h:505
const char * name
Name.
Definition: scsi.c:295
void * memcpy(void *dest, const void *src, size_t len) __nonnull
A SCSI command.
Definition: scsi.c:262
struct interface scsi
SCSI data interface.
Definition: scsi.c:273
struct scsi_command_type * type
Command type.
Definition: scsi.c:276
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint32_t tag
Command tag.
Definition: scsi.c:286
#define SCSI_CDB_DATA(cdb)
printf() parameters for dumping a scsi_cdb
Definition: scsi.h:223
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
A SCSI command information unit.
Definition: scsi.h:249
#define SCSI_CDB_FORMAT
printf() format for dumping a scsi_cdb
Definition: scsi.h:219
#define DBGC2(...)
Definition: compiler.h:522
struct scsi_lun lun
SCSI LUN.
Definition: scsi.c:238
uint64_t tag
Identity tag.
Definition: edd.h:30
void(* cmd)(struct scsi_command *scsicmd, struct scsi_cmd *command)
Construct SCSI command IU.
Definition: scsi.c:304
void * memset(void *dest, int character, size_t len) __nonnull

References scsi_command_type::cmd, DBGC, DBGC2, scsi_device::lun, memcpy(), memset(), scsi_command_type::name, rc, scsi_command::scsi, scsi_device::scsi, SCSI_CDB_DATA, SCSI_CDB_FORMAT, scsi_command::scsidev, strerror(), tag, scsi_command::tag, and scsi_command::type.

Referenced by scsicmd_read_capacity_done(), and scsidev_command().

◆ scsicmd_done()

static void scsicmd_done ( struct scsi_command scsicmd,
int  rc 
)
static

Handle SCSI command completion.

Parameters
scsicmdSCSI command
rcReason for close

Definition at line 454 of file scsi.c.

454  {
455 
456  /* Restart SCSI interface */
457  intf_restart ( &scsicmd->scsi, rc );
458 
459  /* Hand over to the command completion handler */
460  scsicmd->type->done ( scsicmd, rc );
461 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:343
struct interface scsi
SCSI data interface.
Definition: scsi.c:273
struct scsi_command_type * type
Command type.
Definition: scsi.c:276
void(* done)(struct scsi_command *scsicmd, int rc)
Handle SCSI command completion.
Definition: scsi.c:312

References scsi_command_type::done, intf_restart(), rc, scsi_command::scsi, and scsi_command::type.

Referenced by scsicmd_response().

◆ scsicmd_response()

static void scsicmd_response ( struct scsi_command scsicmd,
struct scsi_rsp response 
)
static

Handle SCSI response.

Parameters
scsicmdSCSI command
responseSCSI response

Definition at line 469 of file scsi.c.

470  {
471  struct scsi_device *scsidev = scsicmd->scsidev;
472  size_t overrun;
473  size_t underrun;
474  int rc;
475 
476  if ( response->status == 0 ) {
477  scsicmd_done ( scsicmd, 0 );
478  } else {
479  DBGC ( scsidev, "SCSI %p tag %08x status %02x",
480  scsidev, scsicmd->tag, response->status );
481  if ( response->overrun > 0 ) {
482  overrun = response->overrun;
483  DBGC ( scsidev, " overrun +%zd", overrun );
484  } else if ( response->overrun < 0 ) {
485  underrun = -(response->overrun);
486  DBGC ( scsidev, " underrun -%zd", underrun );
487  }
488  DBGC ( scsidev, " sense %02x key %02x additional %04x\n",
489  ( response->sense.code & SCSI_SENSE_CODE_MASK ),
490  ( response->sense.key & SCSI_SENSE_KEY_MASK ),
491  ntohs ( response->sense.additional ) );
492 
493  /* Construct error number from sense data */
494  rc = -EIO_SENSE ( response->sense.key & SCSI_SENSE_KEY_MASK );
495  scsicmd_done ( scsicmd, rc );
496  }
497 }
A SCSI device.
Definition: scsi.c:229
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define SCSI_SENSE_CODE_MASK
SCSI sense response code mask.
Definition: scsi.h:309
#define SCSI_SENSE_KEY_MASK
SCSI sense key mask.
Definition: scsi.h:319
#define DBGC(...)
Definition: compiler.h:505
#define ntohs(value)
Definition: byteswap.h:136
uint8_t code
Response code.
Definition: scsi.h:291
static void scsicmd_done(struct scsi_command *scsicmd, int rc)
Handle SCSI command completion.
Definition: scsi.c:454
#define EIO_SENSE(key)
Definition: scsi.c:95
uint8_t status
SCSI status code.
Definition: scsi.h:324
uint32_t tag
Command tag.
Definition: scsi.c:286
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
struct scsi_sns_descriptor sense
Autosense data (if any)
Definition: scsi.h:333
uint8_t key
Sense key.
Definition: scsi.h:293
ssize_t overrun
Data overrun (or negative underrun)
Definition: scsi.h:326
uint16_t additional
Additional sense code and qualifier.
Definition: scsi.h:295

References scsi_sns_descriptor::additional, scsi_sns_descriptor::code, DBGC, EIO_SENSE, scsi_sns_descriptor::key, ntohs, scsi_rsp::overrun, rc, SCSI_SENSE_CODE_MASK, SCSI_SENSE_KEY_MASK, scsicmd_done(), scsi_command::scsidev, scsi_rsp::sense, scsi_rsp::status, and scsi_command::tag.

◆ scsicmd_read_cmd()

static void scsicmd_read_cmd ( struct scsi_command scsicmd,
struct scsi_cmd command 
)
static

Construct SCSI READ command.

Parameters
scsicmdSCSI command
commandSCSI command IU

Definition at line 505 of file scsi.c.

506  {
507 
508  if ( ( scsicmd->lba + scsicmd->count ) > SCSI_MAX_BLOCK_10 ) {
509  /* Use READ (16) */
510  command->cdb.read16.opcode = SCSI_OPCODE_READ_16;
511  command->cdb.read16.lba = cpu_to_be64 ( scsicmd->lba );
512  command->cdb.read16.len = cpu_to_be32 ( scsicmd->count );
513  } else {
514  /* Use READ (10) */
515  command->cdb.read10.opcode = SCSI_OPCODE_READ_10;
516  command->cdb.read10.lba = cpu_to_be32 ( scsicmd->lba );
517  command->cdb.read10.len = cpu_to_be16 ( scsicmd->count );
518  }
519  command->data_in = scsicmd->buffer;
520  command->data_in_len = scsicmd->len;
521 }
#define cpu_to_be16(value)
Definition: byteswap.h:109
A command-line command.
Definition: command.h:9
#define SCSI_MAX_BLOCK_10
Maximum block for READ/WRITE (10) commands.
Definition: scsi.h:17
userptr_t buffer
Data buffer.
Definition: scsi.c:282
#define SCSI_OPCODE_READ_16
READ (16)
Definition: scsi.h:25
unsigned int count
Number of blocks.
Definition: scsi.c:280
size_t len
Length of data buffer.
Definition: scsi.c:284
#define SCSI_OPCODE_READ_10
READ (10)
Definition: scsi.h:24
#define cpu_to_be32(value)
Definition: byteswap.h:110
#define cpu_to_be64(value)
Definition: byteswap.h:111
uint64_t lba
Starting logical block address.
Definition: scsi.c:278

References scsi_command::buffer, scsi_command::count, cpu_to_be16, cpu_to_be32, cpu_to_be64, scsi_command::lba, scsi_command::len, SCSI_MAX_BLOCK_10, SCSI_OPCODE_READ_10, and SCSI_OPCODE_READ_16.

◆ scsicmd_write_cmd()

static void scsicmd_write_cmd ( struct scsi_command scsicmd,
struct scsi_cmd command 
)
static

Construct SCSI WRITE command.

Parameters
scsicmdSCSI command
commandSCSI command IU

Definition at line 536 of file scsi.c.

537  {
538 
539  if ( ( scsicmd->lba + scsicmd->count ) > SCSI_MAX_BLOCK_10 ) {
540  /* Use WRITE (16) */
541  command->cdb.write16.opcode = SCSI_OPCODE_WRITE_16;
542  command->cdb.write16.lba = cpu_to_be64 ( scsicmd->lba );
543  command->cdb.write16.len = cpu_to_be32 ( scsicmd->count );
544  } else {
545  /* Use WRITE (10) */
546  command->cdb.write10.opcode = SCSI_OPCODE_WRITE_10;
547  command->cdb.write10.lba = cpu_to_be32 ( scsicmd->lba );
548  command->cdb.write10.len = cpu_to_be16 ( scsicmd->count );
549  }
550  command->data_out = scsicmd->buffer;
551  command->data_out_len = scsicmd->len;
552 }
#define cpu_to_be16(value)
Definition: byteswap.h:109
A command-line command.
Definition: command.h:9
#define SCSI_MAX_BLOCK_10
Maximum block for READ/WRITE (10) commands.
Definition: scsi.h:17
#define SCSI_OPCODE_WRITE_10
WRITE (10)
Definition: scsi.h:26
userptr_t buffer
Data buffer.
Definition: scsi.c:282
unsigned int count
Number of blocks.
Definition: scsi.c:280
size_t len
Length of data buffer.
Definition: scsi.c:284
#define cpu_to_be32(value)
Definition: byteswap.h:110
#define SCSI_OPCODE_WRITE_16
WRITE (16)
Definition: scsi.h:27
#define cpu_to_be64(value)
Definition: byteswap.h:111
uint64_t lba
Starting logical block address.
Definition: scsi.c:278

References scsi_command::buffer, scsi_command::count, cpu_to_be16, cpu_to_be32, cpu_to_be64, scsi_command::lba, scsi_command::len, SCSI_MAX_BLOCK_10, SCSI_OPCODE_WRITE_10, and SCSI_OPCODE_WRITE_16.

◆ scsicmd_read_capacity_cmd()

static void scsicmd_read_capacity_cmd ( struct scsi_command scsicmd,
struct scsi_cmd command 
)
static

Construct SCSI READ CAPACITY command.

Parameters
scsicmdSCSI command
commandSCSI command IU

Definition at line 580 of file scsi.c.

581  {
582  struct scsi_read_capacity_private *priv = scsicmd_priv ( scsicmd );
583  struct scsi_cdb_read_capacity_16 *readcap16 = &command->cdb.readcap16;
584  struct scsi_cdb_read_capacity_10 *readcap10 = &command->cdb.readcap10;
585  struct scsi_capacity_16 *capacity16 = &priv->capacity.capacity16;
586  struct scsi_capacity_10 *capacity10 = &priv->capacity.capacity10;
587 
588  if ( priv->use16 ) {
589  /* Use READ CAPACITY (16) */
591  readcap16->service_action =
593  readcap16->len = cpu_to_be32 ( sizeof ( *capacity16 ) );
594  command->data_in = virt_to_user ( capacity16 );
595  command->data_in_len = sizeof ( *capacity16 );
596  } else {
597  /* Use READ CAPACITY (10) */
599  command->data_in = virt_to_user ( capacity10 );
600  command->data_in_len = sizeof ( *capacity10 );
601  }
602 }
A command-line command.
Definition: command.h:9
uint32_t len
Transfer length.
Definition: scsi.h:179
SCSI "READ CAPACITY (10)" parameter data.
Definition: scsi.h:157
SCSI "READ CAPACITY (16)" parameter data.
Definition: scsi.h:187
SCSI READ CAPACITY private data.
Definition: scsi.c:562
A SCSI "READ CAPACITY (10)" CDB.
Definition: scsi.h:140
uint8_t opcode
Opcode (0x25)
Definition: scsi.h:142
#define cpu_to_be32(value)
Definition: byteswap.h:110
static struct tlan_private * priv
Definition: tlan.c:224
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
uint8_t opcode
Opcode (0x9e)
Definition: scsi.h:167
#define SCSI_SERVICE_ACTION_READ_CAPACITY_16
READ CAPACITY (16)
Definition: scsi.h:30
A SCSI "READ CAPACITY (16)" CDB.
Definition: scsi.h:165
#define SCSI_OPCODE_READ_CAPACITY_10
READ CAPACITY (10)
Definition: scsi.h:28
uint8_t service_action
Service action.
Definition: scsi.h:169
#define SCSI_OPCODE_SERVICE_ACTION_IN
SERVICE ACTION IN.
Definition: scsi.h:29
static void * scsicmd_priv(struct scsi_command *scsicmd)
Get SCSI command private data.
Definition: scsi.c:366

References cpu_to_be32, scsi_cdb_read_capacity_16::len, scsi_cdb_read_capacity_10::opcode, scsi_cdb_read_capacity_16::opcode, priv, SCSI_OPCODE_READ_CAPACITY_10, SCSI_OPCODE_SERVICE_ACTION_IN, SCSI_SERVICE_ACTION_READ_CAPACITY_16, scsicmd_priv(), scsi_cdb_read_capacity_16::service_action, and virt_to_user().

◆ scsicmd_read_capacity_done()

static void scsicmd_read_capacity_done ( struct scsi_command scsicmd,
int  rc 
)
static

Handle SCSI READ CAPACITY command completion.

Parameters
scsicmdSCSI command
rcReason for completion

Definition at line 610 of file scsi.c.

611  {
612  struct scsi_device *scsidev = scsicmd->scsidev;
613  struct scsi_read_capacity_private *priv = scsicmd_priv ( scsicmd );
614  struct scsi_capacity_16 *capacity16 = &priv->capacity.capacity16;
615  struct scsi_capacity_10 *capacity10 = &priv->capacity.capacity10;
616  struct block_device_capacity capacity;
617 
618  /* Close if command failed */
619  if ( rc != 0 ) {
620  scsicmd_close ( scsicmd, rc );
621  return;
622  }
623 
624  /* Extract capacity */
625  if ( priv->use16 ) {
626  capacity.blocks = ( be64_to_cpu ( capacity16->lba ) + 1 );
627  capacity.blksize = be32_to_cpu ( capacity16->blksize );
628  } else {
629  capacity.blocks = ( be32_to_cpu ( capacity10->lba ) + 1 );
630  capacity.blksize = be32_to_cpu ( capacity10->blksize );
631 
632  /* If capacity range was exceeded (i.e. capacity.lba
633  * was 0xffffffff, meaning that blockdev->blocks is
634  * now zero), use READ CAPACITY (16) instead. READ
635  * CAPACITY (16) is not mandatory, so we can't just
636  * use it straight off.
637  */
638  if ( capacity.blocks == 0 ) {
639  priv->use16 = 1;
640  if ( ( rc = scsicmd_command ( scsicmd ) ) != 0 ) {
641  scsicmd_close ( scsicmd, rc );
642  return;
643  }
644  return;
645  }
646  }
647  capacity.max_count = -1U;
648 
649  /* Allow transport layer to update capacity */
650  block_capacity ( &scsidev->scsi, &capacity );
651 
652  /* Return capacity to caller */
653  block_capacity ( &scsicmd->block, &capacity );
654 
655  /* Close command */
656  scsicmd_close ( scsicmd, 0 );
657 }
struct interface scsi
SCSI control interface.
Definition: scsi.c:235
A SCSI device.
Definition: scsi.c:229
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void block_capacity(struct interface *intf, struct block_device_capacity *capacity)
Report block device capacity.
Definition: blockdev.c:129
SCSI "READ CAPACITY (10)" parameter data.
Definition: scsi.h:157
static void scsicmd_close(struct scsi_command *scsicmd, int rc)
Close SCSI command.
Definition: scsi.c:392
uint32_t blksize
Block length in bytes.
Definition: scsi.h:161
SCSI "READ CAPACITY (16)" parameter data.
Definition: scsi.h:187
uint32_t blksize
Block length in bytes.
Definition: scsi.h:191
SCSI READ CAPACITY private data.
Definition: scsi.c:562
#define be32_to_cpu(value)
Definition: byteswap.h:116
#define be64_to_cpu(value)
Definition: byteswap.h:117
uint32_t lba
Maximum logical block number.
Definition: scsi.h:159
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
uint64_t lba
Maximum logical block number.
Definition: scsi.h:189
Block device capacity.
Definition: blockdev.h:18
static struct tlan_private * priv
Definition: tlan.c:224
struct interface block
Block data interface.
Definition: scsi.c:271
static int scsicmd_command(struct scsi_command *scsicmd)
Construct and issue SCSI command.
Definition: scsi.c:415
static void * scsicmd_priv(struct scsi_command *scsicmd)
Get SCSI command private data.
Definition: scsi.c:366

References be32_to_cpu, be64_to_cpu, block_device_capacity::blksize, scsi_capacity_10::blksize, scsi_capacity_16::blksize, scsi_command::block, block_capacity(), block_device_capacity::blocks, scsi_capacity_10::lba, scsi_capacity_16::lba, block_device_capacity::max_count, priv, rc, scsi_device::scsi, scsicmd_close(), scsicmd_command(), scsicmd_priv(), and scsi_command::scsidev.

◆ scsicmd_test_unit_ready_cmd()

static void scsicmd_test_unit_ready_cmd ( struct scsi_command *scsicmd  __unused,
struct scsi_cmd command 
)
static

Construct SCSI TEST UNIT READY command.

Parameters
scsicmdSCSI command
commandSCSI command IU

Definition at line 673 of file scsi.c.

674  {
675  struct scsi_cdb_test_unit_ready *testready = &command->cdb.testready;
676 
677  testready->opcode = SCSI_OPCODE_TEST_UNIT_READY;
678 }
A command-line command.
Definition: command.h:9
A SCSI "TEST UNIT READY" CDB.
Definition: scsi.h:197
uint8_t opcode
Opcode (0x00)
Definition: scsi.h:199
#define SCSI_OPCODE_TEST_UNIT_READY
TEST UNIT READY.
Definition: scsi.h:31

References scsi_cdb_test_unit_ready::opcode, and SCSI_OPCODE_TEST_UNIT_READY.

◆ scsidev_command()

static int scsidev_command ( struct scsi_device scsidev,
struct interface block,
struct scsi_command_type type,
uint64_t  lba,
unsigned int  count,
userptr_t  buffer,
size_t  len 
)
static

Create SCSI command.

Parameters
scsidevSCSI device
blockBlock data interface
typeSCSI command type
lbaStarting logical block address
countNumber of blocks to transfer
bufferData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 720 of file scsi.c.

724  {
725  struct scsi_command *scsicmd;
726  int rc;
727 
728  /* Allocate and initialise structure */
729  scsicmd = zalloc ( sizeof ( *scsicmd ) + type->priv_len );
730  if ( ! scsicmd ) {
731  rc = -ENOMEM;
732  goto err_zalloc;
733  }
734  ref_init ( &scsicmd->refcnt, scsicmd_free );
735  intf_init ( &scsicmd->block, &scsicmd_block_desc, &scsicmd->refcnt );
736  intf_init ( &scsicmd->scsi, &scsicmd_scsi_desc,
737  &scsicmd->refcnt );
738  scsicmd->scsidev = scsidev_get ( scsidev );
739  list_add ( &scsicmd->list, &scsidev->cmds );
740  scsicmd->type = type;
741  scsicmd->lba = lba;
742  scsicmd->count = count;
743  scsicmd->buffer = buffer;
744  scsicmd->len = len;
745 
746  /* Issue SCSI command */
747  if ( ( rc = scsicmd_command ( scsicmd ) ) != 0 )
748  goto err_command;
749 
750  /* Attach to parent interface, transfer reference to list, and return */
751  intf_plug_plug ( &scsicmd->block, block );
752  return 0;
753 
754  err_command:
755  scsicmd_close ( scsicmd, rc );
756  ref_put ( &scsicmd->refcnt );
757  err_zalloc:
758  return rc;
759 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct interface_descriptor scsicmd_scsi_desc
SCSI command SCSI interface descriptor.
Definition: scsi.c:704
uint32_t lba
Start address.
Definition: scsi.h:23
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
struct list_head cmds
List of commands.
Definition: scsi.c:250
uint32_t type
Operating system type.
Definition: ena.h:12
static void scsicmd_close(struct scsi_command *scsicmd, int rc)
Close SCSI command.
Definition: scsi.c:392
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
#define ENOMEM
Not enough space.
Definition: errno.h:534
A SCSI command.
Definition: scsi.c:262
userptr_t buffer
Data buffer.
Definition: scsi.c:282
unsigned int count
Number of blocks.
Definition: scsi.c:280
size_t len
Length of data buffer.
Definition: scsi.c:284
struct interface scsi
SCSI data interface.
Definition: scsi.c:273
struct scsi_command_type * type
Command type.
Definition: scsi.c:276
static void scsicmd_free(struct refcnt *refcnt)
Free SCSI command.
Definition: scsi.c:375
struct refcnt refcnt
Reference count.
Definition: scsi.c:264
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static struct scsi_device * scsidev_get(struct scsi_device *scsidev)
Get reference to SCSI device.
Definition: scsi.c:322
struct list_head list
List of SCSI commands.
Definition: scsi.c:268
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
static struct interface_descriptor scsicmd_block_desc
SCSI command block interface descriptor.
Definition: scsi.c:693
uint32_t len
Length.
Definition: ena.h:14
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
uint16_t count
Number of entries.
Definition: ena.h:22
struct interface block
Block data interface.
Definition: scsi.c:271
static int scsicmd_command(struct scsi_command *scsicmd)
Construct and issue SCSI command.
Definition: scsi.c:415
uint64_t lba
Starting logical block address.
Definition: scsi.c:278
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References block, scsi_command::block, buffer, scsi_command::buffer, scsi_device::cmds, count, scsi_command::count, ENOMEM, intf_init(), intf_plug_plug(), lba, scsi_command::lba, len, scsi_command::len, scsi_command::list, list_add, rc, ref_init, ref_put, scsi_command::refcnt, scsi_command::scsi, scsicmd_block_desc, scsicmd_close(), scsicmd_command(), scsicmd_free(), scsicmd_scsi_desc, scsi_command::scsidev, scsidev_get(), type, scsi_command::type, and zalloc().

Referenced by scsidev_read(), scsidev_read_capacity(), scsidev_test_unit_ready(), and scsidev_write().

◆ scsidev_read()

static int scsidev_read ( struct scsi_device scsidev,
struct interface block,
uint64_t  lba,
unsigned int  count,
userptr_t  buffer,
size_t  len 
)
static

Issue SCSI block read.

Parameters
scsidevSCSI device
blockBlock data interface
lbaStarting logical block address
countNumber of blocks to transfer
bufferData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 773 of file scsi.c.

776  {
778  lba, count, buffer, len );
779 }
static int scsidev_command(struct scsi_device *scsidev, struct interface *block, struct scsi_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Create SCSI command.
Definition: scsi.c:720
uint32_t lba
Start address.
Definition: scsi.h:23
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
static struct scsi_command_type scsicmd_read
SCSI READ command type.
Definition: scsi.c:524
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
uint32_t len
Length.
Definition: ena.h:14
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
uint16_t count
Number of entries.
Definition: ena.h:22

References block, buffer, count, lba, len, scsicmd_read, scsi_command::scsidev, and scsidev_command().

◆ scsidev_write()

static int scsidev_write ( struct scsi_device scsidev,
struct interface block,
uint64_t  lba,
unsigned int  count,
userptr_t  buffer,
size_t  len 
)
static

Issue SCSI block write.

Parameters
scsidevSCSI device
blockBlock data interface
lbaStarting logical block address
countNumber of blocks to transfer
bufferData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 792 of file scsi.c.

795  {
797  lba, count, buffer, len );
798 }
static int scsidev_command(struct scsi_device *scsidev, struct interface *block, struct scsi_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Create SCSI command.
Definition: scsi.c:720
uint32_t lba
Start address.
Definition: scsi.h:23
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
uint32_t len
Length.
Definition: ena.h:14
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
uint16_t count
Number of entries.
Definition: ena.h:22
static struct scsi_command_type scsicmd_write
SCSI WRITE command type.
Definition: scsi.c:555

References block, buffer, count, lba, len, scsicmd_write, scsi_command::scsidev, and scsidev_command().

◆ scsidev_read_capacity()

static int scsidev_read_capacity ( struct scsi_device scsidev,
struct interface block 
)
static

Read SCSI device capacity.

Parameters
scsidevSCSI device
blockBlock data interface
Return values
rcReturn status code

Definition at line 807 of file scsi.c.

808  {
810  0, 0, UNULL, 0 );
811 }
static int scsidev_command(struct scsi_device *scsidev, struct interface *block, struct scsi_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Create SCSI command.
Definition: scsi.c:720
static struct scsi_command_type scsicmd_read_capacity
SCSI READ CAPACITY command type.
Definition: scsi.c:660
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
#define UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12

References block, scsicmd_read_capacity, scsi_command::scsidev, scsidev_command(), and UNULL.

◆ scsidev_test_unit_ready()

static int scsidev_test_unit_ready ( struct scsi_device scsidev,
struct interface block 
)
static

Test to see if SCSI device is ready.

Parameters
scsidevSCSI device
blockBlock data interface
Return values
rcReturn status code

Definition at line 820 of file scsi.c.

821  {
823  0, 0, UNULL, 0 );
824 }
static int scsidev_command(struct scsi_device *scsidev, struct interface *block, struct scsi_command_type *type, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Create SCSI command.
Definition: scsi.c:720
static struct scsi_command_type scsicmd_test_unit_ready
SCSI TEST UNIT READY command type.
Definition: scsi.c:681
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
#define UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12

References block, scsicmd_test_unit_ready, scsi_command::scsidev, scsidev_command(), and UNULL.

Referenced by scsidev_step().

◆ scsidev_window()

static size_t scsidev_window ( struct scsi_device scsidev)
static

Check SCSI device flow-control window.

Parameters
scsidevSCSI device
Return values
lenLength of window

Definition at line 832 of file scsi.c.

832  {
833 
834  /* Refuse commands until unit is confirmed ready */
835  if ( ! ( scsidev->flags & SCSIDEV_UNIT_READY ) )
836  return 0;
837 
838  return xfer_window ( &scsidev->scsi );
839 }
struct interface scsi
SCSI control interface.
Definition: scsi.c:235
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
TEST UNIT READY has completed successfully.
Definition: scsi.c:258
unsigned int flags
Flags.
Definition: scsi.c:240

References scsi_device::flags, scsi_device::scsi, scsi_command::scsidev, SCSIDEV_UNIT_READY, and xfer_window().

◆ scsidev_close()

static void scsidev_close ( struct scsi_device scsidev,
int  rc 
)
static

Close SCSI device.

Parameters
scsidevSCSI device
rcReason for close

Definition at line 847 of file scsi.c.

847  {
848  struct scsi_command *scsicmd;
849  struct scsi_command *tmp;
850 
851  /* Stop process */
853 
854  /* Shut down interfaces */
856  NULL );
857 
858  /* Shut down any remaining commands */
859  list_for_each_entry_safe ( scsicmd, tmp, &scsidev->cmds, list )
860  scsicmd_close ( scsicmd, rc );
861 }
struct interface scsi
SCSI control interface.
Definition: scsi.c:235
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct list_head cmds
List of commands.
Definition: scsi.c:250
static void scsicmd_close(struct scsi_command *scsicmd, int rc)
Close SCSI command.
Definition: scsi.c:392
void intfs_shutdown(int rc,...)
Shut down multiple object interfaces.
Definition: interface.c:326
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79
unsigned long tmp
Definition: linux_pci.h:53
struct interface ready
TEST UNIT READY interface.
Definition: scsi.c:243
A SCSI command.
Definition: scsi.c:262
struct interface block
Block control interface.
Definition: scsi.c:233
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:458
struct list_head list
List of SCSI commands.
Definition: scsi.c:268
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct process process
TEST UNIT READY process.
Definition: scsi.c:245

References scsi_device::block, scsi_device::cmds, intfs_shutdown(), scsi_command::list, list_for_each_entry_safe, NULL, scsi_device::process, process_del(), rc, scsi_device::ready, scsi_device::scsi, scsicmd_close(), scsi_command::scsidev, and tmp.

Referenced by scsidev_ready(), and scsidev_step().

◆ scsidev_ready()

static void scsidev_ready ( struct scsi_device scsidev,
int  rc 
)
static

Handle SCSI TEST UNIT READY response.

Parameters
scsidevSCSI device
rcReason for close

Definition at line 884 of file scsi.c.

884  {
885 
886  /* Shut down interface */
887  intf_restart ( &scsidev->ready, rc );
888 
889  /* Mark device as ready, if applicable */
890  if ( rc == 0 ) {
891  DBGC ( scsidev, "SCSI %p unit is ready\n", scsidev );
894  return;
895  }
896  DBGC ( scsidev, "SCSI %p not ready: %s\n", scsidev, strerror ( rc ) );
897 
898  /* SCSI targets have an annoying habit of returning occasional
899  * pointless "error" messages such as "power-on occurred", so
900  * we have to be prepared to retry commands.
901  *
902  * For most commands, we rely on the caller (e.g. the generic
903  * SAN device layer) to retry commands as needed. However, a
904  * TEST UNIT READY failure is used as an indication that the
905  * whole SCSI device is unavailable and should be closed. We
906  * must therefore perform this retry loop within the SCSI
907  * layer.
908  */
910  DBGC ( scsidev, "SCSI %p retrying (retry %d)\n",
911  scsidev, scsidev->retries );
914  return;
915  }
916 
917  /* Close device */
918  DBGC ( scsidev, "SCSI %p never became ready: %s\n",
919  scsidev, strerror ( rc ) );
920  scsidev_close ( scsidev, rc );
921 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:146
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:343
#define SCSI_READY_MAX_RETRIES
Maximum number of TEST UNIT READY retries.
Definition: scsi.c:44
#define DBGC(...)
Definition: compiler.h:505
TEST UNIT READY has been issued.
Definition: scsi.c:256
struct interface ready
TEST UNIT READY interface.
Definition: scsi.c:243
static void scsidev_close(struct scsi_device *scsidev, int rc)
Close SCSI device.
Definition: scsi.c:847
struct interface block
Block control interface.
Definition: scsi.c:233
void process_add(struct process *process)
Add process to process list.
Definition: process.c:59
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
TEST UNIT READY has completed successfully.
Definition: scsi.c:258
unsigned int flags
Flags.
Definition: scsi.c:240
unsigned int retries
TEST UNIT READY retry count.
Definition: scsi.c:247
struct process process
TEST UNIT READY process.
Definition: scsi.c:245

References scsi_device::block, DBGC, scsi_device::flags, intf_restart(), scsi_device::process, process_add(), rc, scsi_device::ready, scsi_device::retries, SCSI_READY_MAX_RETRIES, scsidev_close(), SCSIDEV_UNIT_READY, SCSIDEV_UNIT_TESTED, strerror(), and xfer_window_changed().

◆ scsidev_step()

static void scsidev_step ( struct scsi_device scsidev)
static

SCSI TEST UNIT READY process.

Parameters
scsidevSCSI device

Definition at line 937 of file scsi.c.

937  {
938  int rc;
939 
940  /* Do nothing if we have already issued TEST UNIT READY */
942  return;
943 
944  /* Wait until underlying SCSI device is ready */
945  if ( xfer_window ( &scsidev->scsi ) == 0 )
946  return;
947 
948  DBGC ( scsidev, "SCSI %p waiting for unit to become ready\n",
949  scsidev );
950 
951  /* Mark TEST UNIT READY as sent */
953 
954  /* Issue TEST UNIT READY command */
955  if ( ( rc = scsidev_test_unit_ready ( scsidev, &scsidev->ready )) !=0){
956  scsidev_close ( scsidev, rc );
957  return;
958  }
959 }
struct interface scsi
SCSI control interface.
Definition: scsi.c:235
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
TEST UNIT READY has been issued.
Definition: scsi.c:256
struct interface ready
TEST UNIT READY interface.
Definition: scsi.c:243
static void scsidev_close(struct scsi_device *scsidev, int rc)
Close SCSI device.
Definition: scsi.c:847
static int scsidev_test_unit_ready(struct scsi_device *scsidev, struct interface *block)
Test to see if SCSI device is ready.
Definition: scsi.c:820
struct scsi_device * scsidev
SCSI device.
Definition: scsi.c:266
unsigned int flags
Flags.
Definition: scsi.c:240

References DBGC, scsi_device::flags, rc, scsi_device::ready, scsi_device::scsi, scsidev_close(), scsidev_test_unit_ready(), SCSIDEV_UNIT_TESTED, and xfer_window().

◆ 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 984 of file scsi.c.

985  {
986  struct scsi_device *scsidev;
987 
988  /* Allocate and initialise structure */
989  scsidev = zalloc ( sizeof ( *scsidev ) );
990  if ( ! scsidev )
991  return -ENOMEM;
992  ref_init ( &scsidev->refcnt, NULL );
993  intf_init ( &scsidev->block, &scsidev_block_desc, &scsidev->refcnt );
994  intf_init ( &scsidev->scsi, &scsidev_scsi_desc, &scsidev->refcnt );
995  intf_init ( &scsidev->ready, &scsidev_ready_desc, &scsidev->refcnt );
997  &scsidev->refcnt );
998  INIT_LIST_HEAD ( &scsidev->cmds );
999  memcpy ( &scsidev->lun, lun, sizeof ( scsidev->lun ) );
1000  DBGC ( scsidev, "SCSI %p created for LUN " SCSI_LUN_FORMAT "\n",
1001  scsidev, SCSI_LUN_DATA ( scsidev->lun ) );
1002 
1003  /* Attach to SCSI and parent interfaces, mortalise self, and return */
1004  intf_plug_plug ( &scsidev->scsi, scsi );
1005  intf_plug_plug ( &scsidev->block, block );
1006  ref_put ( &scsidev->refcnt );
1007  return 0;
1008 }
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
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:107
static struct interface_descriptor scsidev_block_desc
SCSI device block interface descriptor.
Definition: scsi.c:874
static struct interface_descriptor scsidev_ready_desc
SCSI device TEST UNIT READY interface descriptor.
Definition: scsi.c:929
#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
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
static struct interface_descriptor scsidev_scsi_desc
SCSI device SCSI interface descriptor.
Definition: scsi.c:968
static struct process_descriptor scsidev_process_desc
SCSI device process descriptor.
Definition: scsi.c:973
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:203
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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(), srp_open(), and usbblk_open_uri().

Variable Documentation

◆ scsicmd_read

struct scsi_command_type scsicmd_read
static
Initial value:
= {
.name = "READ",
.done = scsicmd_close,
}
static void scsicmd_close(struct scsi_command *scsicmd, int rc)
Close SCSI command.
Definition: scsi.c:392
static void scsicmd_read_cmd(struct scsi_command *scsicmd, struct scsi_cmd *command)
Construct SCSI READ command.
Definition: scsi.c:505

SCSI READ command type.

Definition at line 524 of file scsi.c.

Referenced by scsidev_read().

◆ scsicmd_write

struct scsi_command_type scsicmd_write
static
Initial value:
= {
.name = "WRITE",
.done = scsicmd_close,
}
static void scsicmd_close(struct scsi_command *scsicmd, int rc)
Close SCSI command.
Definition: scsi.c:392
static void scsicmd_write_cmd(struct scsi_command *scsicmd, struct scsi_cmd *command)
Construct SCSI WRITE command.
Definition: scsi.c:536

SCSI WRITE command type.

Definition at line 555 of file scsi.c.

Referenced by scsidev_write().

◆ scsicmd_read_capacity

struct scsi_command_type scsicmd_read_capacity
static
Initial value:
= {
.name = "READ CAPACITY",
.priv_len = sizeof ( struct scsi_read_capacity_private ),
}
SCSI READ CAPACITY private data.
Definition: scsi.c:562
static void scsicmd_read_capacity_cmd(struct scsi_command *scsicmd, struct scsi_cmd *command)
Construct SCSI READ CAPACITY command.
Definition: scsi.c:580
static void scsicmd_read_capacity_done(struct scsi_command *scsicmd, int rc)
Handle SCSI READ CAPACITY command completion.
Definition: scsi.c:610
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29

SCSI READ CAPACITY command type.

Definition at line 660 of file scsi.c.

Referenced by scsidev_read_capacity().

◆ scsicmd_test_unit_ready

struct scsi_command_type scsicmd_test_unit_ready
static
Initial value:
= {
.name = "TEST UNIT READY",
.done = scsicmd_close,
}
static void scsicmd_close(struct scsi_command *scsicmd, int rc)
Close SCSI command.
Definition: scsi.c:392
static void scsicmd_test_unit_ready_cmd(struct scsi_command *scsicmd __unused, struct scsi_cmd *command)
Construct SCSI TEST UNIT READY command.
Definition: scsi.c:673

SCSI TEST UNIT READY command type.

Definition at line 681 of file scsi.c.

Referenced by scsidev_test_unit_ready().

◆ scsicmd_block_op

struct interface_operation scsicmd_block_op[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void scsicmd_close(struct scsi_command *scsicmd, int rc)
Close SCSI command.
Definition: scsi.c:392
A SCSI command.
Definition: scsi.c:262
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32

SCSI command block interface operations.

Definition at line 688 of file scsi.c.

◆ scsicmd_block_desc

struct interface_descriptor scsicmd_block_desc
static
Initial value:
=
static struct interface_operation scsicmd_block_op[]
SCSI command block interface operations.
Definition: scsi.c:688
A SCSI command.
Definition: scsi.c:262
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97

SCSI command block interface descriptor.

Definition at line 693 of file scsi.c.

Referenced by scsidev_command().

◆ scsicmd_scsi_op

struct interface_operation scsicmd_scsi_op[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void scsicmd_response(struct scsi_command *scsicmd, struct scsi_rsp *response)
Handle SCSI response.
Definition: scsi.c:469
static void scsicmd_done(struct scsi_command *scsicmd, int rc)
Handle SCSI command completion.
Definition: scsi.c:454
A SCSI command.
Definition: scsi.c:262
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
void scsi_response(struct interface *intf, struct scsi_rsp *response)
Report SCSI response.
Definition: scsi.c:206

SCSI command SCSI interface operations.

Definition at line 698 of file scsi.c.

◆ scsicmd_scsi_desc

struct interface_descriptor scsicmd_scsi_desc
static
Initial value:
=
A SCSI command.
Definition: scsi.c:262
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97
static struct interface_operation scsicmd_scsi_op[]
SCSI command SCSI interface operations.
Definition: scsi.c:698

SCSI command SCSI interface descriptor.

Definition at line 704 of file scsi.c.

Referenced by scsidev_command().

◆ scsidev_block_op

struct interface_operation scsidev_block_op[]
static
Initial value:
= {
}
int block_write(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Write to block device.
Definition: blockdev.c:78
A SCSI device.
Definition: scsi.c:229
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static int scsidev_read_capacity(struct scsi_device *scsidev, struct interface *block)
Read SCSI device capacity.
Definition: scsi.c:807
int block_read(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Read from block device.
Definition: blockdev.c:47
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
static int scsidev_read(struct scsi_device *scsidev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Issue SCSI block read.
Definition: scsi.c:773
static void scsidev_close(struct scsi_device *scsidev, int rc)
Close SCSI device.
Definition: scsi.c:847
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
static int scsidev_write(struct scsi_device *scsidev, struct interface *block, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)
Issue SCSI block write.
Definition: scsi.c:792
static size_t scsidev_window(struct scsi_device *scsidev)
Check SCSI device flow-control window.
Definition: scsi.c:832
int block_read_capacity(struct interface *control, struct interface *data)
Read block device capacity.
Definition: blockdev.c:105

SCSI device block interface operations.

Definition at line 864 of file scsi.c.

◆ scsidev_block_desc

struct interface_descriptor scsidev_block_desc
static
Initial value:
=
A SCSI device.
Definition: scsi.c:229
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
static struct interface_operation scsidev_block_op[]
SCSI device block interface operations.
Definition: scsi.c:864
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97

SCSI device block interface descriptor.

Definition at line 874 of file scsi.c.

Referenced by scsi_open().

◆ scsidev_ready_op

struct interface_operation scsidev_ready_op[]
static
Initial value:
= {
}
A SCSI device.
Definition: scsi.c:229
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void scsidev_ready(struct scsi_device *scsidev, int rc)
Handle SCSI TEST UNIT READY response.
Definition: scsi.c:884
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32

SCSI device TEST UNIT READY interface operations.

Definition at line 924 of file scsi.c.

◆ scsidev_ready_desc

struct interface_descriptor scsidev_ready_desc
static
Initial value:
=
A SCSI device.
Definition: scsi.c:229
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80
static struct interface_operation scsidev_ready_op[]
SCSI device TEST UNIT READY interface operations.
Definition: scsi.c:924

SCSI device TEST UNIT READY interface descriptor.

Definition at line 929 of file scsi.c.

Referenced by scsi_open().

◆ scsidev_scsi_op

struct interface_operation scsidev_scsi_op[]
static
Initial value:
= {
}
A SCSI device.
Definition: scsi.c:229
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:146
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void scsidev_close(struct scsi_device *scsidev, int rc)
Close SCSI device.
Definition: scsi.c:847
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
static void scsidev_step(struct scsi_device *scsidev)
SCSI TEST UNIT READY process.
Definition: scsi.c:937

SCSI device SCSI interface operations.

Definition at line 962 of file scsi.c.

◆ scsidev_scsi_desc

struct interface_descriptor scsidev_scsi_desc
static
Initial value:
=
A SCSI device.
Definition: scsi.c:229
static struct interface_operation scsidev_scsi_op[]
SCSI device SCSI interface operations.
Definition: scsi.c:962
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97

SCSI device SCSI interface descriptor.

Definition at line 968 of file scsi.c.

Referenced by scsi_open().

◆ scsidev_process_desc

struct process_descriptor scsidev_process_desc
static
Initial value:
=
A process.
Definition: process.h:17
A SCSI device.
Definition: scsi.c:229
#define PROC_DESC_ONCE(object_type, process, _step)
Define a process descriptor for a process that runs only once.
Definition: process.h:97
static void scsidev_step(struct scsi_device *scsidev)
SCSI TEST UNIT READY process.
Definition: scsi.c:937

SCSI device process descriptor.

Definition at line 973 of file scsi.c.

Referenced by scsi_open().