iPXE
Data Structures | Macros | Functions | Variables
fcp.c File Reference

Fibre Channel Protocol. More...

#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <assert.h>
#include <byteswap.h>
#include <ipxe/refcnt.h>
#include <ipxe/list.h>
#include <ipxe/interface.h>
#include <ipxe/xfer.h>
#include <ipxe/iobuf.h>
#include <ipxe/open.h>
#include <ipxe/process.h>
#include <ipxe/uri.h>
#include <ipxe/acpi.h>
#include <ipxe/scsi.h>
#include <ipxe/device.h>
#include <ipxe/edd.h>
#include <ipxe/efi/efi_path.h>
#include <ipxe/fc.h>
#include <ipxe/fcels.h>
#include <ipxe/fcp.h>

Go to the source code of this file.

Data Structures

struct  fcp_device
 An FCP device. More...
 
struct  fcp_command
 An FCP command. More...
 

Macros

#define ERANGE_READ_DATA_ORDERING   __einfo_error ( EINFO_ERANGE_READ_DATA_ORDERING )
 
#define EINFO_ERANGE_READ_DATA_ORDERING   __einfo_uniqify ( EINFO_ERANGE, 0x01, "Read data out of order" )
 
#define ERANGE_READ_DATA_OVERRUN   __einfo_error ( EINFO_ERANGE_READ_DATA_OVERRUN )
 
#define EINFO_ERANGE_READ_DATA_OVERRUN   __einfo_uniqify ( EINFO_ERANGE, 0x02, "Read data overrun" )
 
#define ERANGE_WRITE_DATA_STUCK   __einfo_error ( EINFO_ERANGE_WRITE_DATA_STUCK )
 
#define EINFO_ERANGE_WRITE_DATA_STUCK   __einfo_uniqify ( EINFO_ERANGE, 0x03, "Write data stuck" )
 
#define ERANGE_WRITE_DATA_OVERRUN   __einfo_error ( EINFO_ERANGE_WRITE_DATA_OVERRUN )
 
#define EINFO_ERANGE_WRITE_DATA_OVERRUN   __einfo_uniqify ( EINFO_ERANGE, 0x04, "Write data overrun" )
 
#define ERANGE_DATA_UNDERRUN   __einfo_error ( EINFO_ERANGE_DATA_UNDERRUN )
 
#define EINFO_ERANGE_DATA_UNDERRUN   __einfo_uniqify ( EINFO_ERANGE, 0x05, "Data underrun" )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int fcp_prli_tx (struct fc_els *els)
 Transmit FCP PRLI. More...
 
static int fcp_prli_rx (struct fc_els *els, void *data, size_t len)
 Receive FCP PRLI. More...
 
static int fcp_prli_detect (struct fc_els *els, const void *data, size_t len)
 Detect FCP PRLI. More...
 
static struct fcp_devicefcpdev_get (struct fcp_device *fcpdev)
 Get reference to FCP device. More...
 
static void fcpdev_put (struct fcp_device *fcpdev)
 Drop reference to FCP device. More...
 
static struct fcp_commandfcpcmd_get (struct fcp_command *fcpcmd)
 Get reference to FCP command. More...
 
static void fcpcmd_put (struct fcp_command *fcpcmd)
 Drop reference to FCP command. More...
 
static void fcpcmd_start_send (struct fcp_command *fcpcmd, int(*send)(struct fcp_command *fcpcmd))
 Start FCP command sending. More...
 
static void fcpcmd_stop_send (struct fcp_command *fcpcmd)
 Stop FCP command sending. More...
 
static void fcpcmd_free (struct refcnt *refcnt)
 Free FCP command. More...
 
static void fcpcmd_close (struct fcp_command *fcpcmd, int rc)
 Close FCP command. More...
 
static void fcpcmd_close_err (struct fcp_command *fcpcmd, int rc)
 Close FCP command in error. More...
 
static int fcpcmd_send_cmnd (struct fcp_command *fcpcmd)
 Send FCP command IU. More...
 
static int fcpcmd_recv_rddata (struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Handle FCP read data IU. More...
 
static int fcpcmd_send_wrdata (struct fcp_command *fcpcmd)
 Send FCP write data IU. More...
 
static int fcpcmd_recv_xfer_rdy (struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
 Handle FCP transfer ready IU. More...
 
static int fcpcmd_recv_rsp (struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
 Handle FCP response IU. More...
 
static int fcpcmd_recv_unknown (struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
 Handle unknown FCP IU. More...
 
static void fcpcmd_step (struct fcp_command *fcpcmd)
 Transmit FCP frame. More...
 
static int fcpcmd_deliver (struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Receive FCP frame. More...
 
static int fcpdev_scsi_command (struct fcp_device *fcpdev, struct interface *parent, struct scsi_cmd *command)
 Issue FCP SCSI command. More...
 
static void fcpdev_close (struct fcp_device *fcpdev, int rc)
 Close FCP device. More...
 
static size_t fcpdev_window (struct fcp_device *fcpdev)
 Check FCP device flow-control window. More...
 
static int fcpdev_edd_describe (struct fcp_device *fcpdev, struct edd_interface_type *type, union edd_device_path *path)
 Describe FCP device using EDD. More...
 
static struct devicefcpdev_identify_device (struct fcp_device *fcpdev)
 Identify device underlying FCP device. More...
 
static EFI_DEVICE_PATH_PROTOCOLfcpdev_efi_describe (struct fcp_device *fcpdev)
 Describe as an EFI device path. More...
 
static void fcpdev_examine (struct fc_ulp_user *user)
 Examine FCP ULP link state. More...
 
static int fcpdev_open (struct interface *parent, struct fc_name *wwn, struct scsi_lun *lun)
 Open FCP device. More...
 
static int fcp_parse_uri (struct uri *uri, struct fc_name *wwn, struct scsi_lun *lun)
 Parse FCP URI. More...
 
static int fcp_open (struct interface *parent, struct uri *uri)
 Open FCP URI. More...
 

Variables

struct fc_els_prli_descriptor fcp_prli_descriptor __fc_els_prli_descriptor
 FCP PRLI descriptor. More...
 
struct fc_els_handler fcp_prli_handler __fc_els_handler
 FCP PRLI ELS handler. More...
 
static struct interface_operation fcpcmd_scsi_op []
 FCP command SCSI interface operations. More...
 
static struct interface_descriptor fcpcmd_scsi_desc
 FCP command SCSI interface descriptor. More...
 
static struct interface_operation fcpcmd_xchg_op []
 FCP command Fibre Channel exchange interface operations. More...
 
static struct interface_descriptor fcpcmd_xchg_desc
 FCP command Fibre Channel exchange interface descriptor. More...
 
static struct process_descriptor fcpcmd_process_desc
 FCP command process descriptor. More...
 
static struct interface_operation fcpdev_scsi_op []
 FCP device SCSI interface operations. More...
 
static struct interface_descriptor fcpdev_scsi_desc
 FCP device SCSI interface descriptor. More...
 
struct uri_opener fcp_uri_opener __uri_opener
 FCP URI opener. More...
 

Detailed Description

Fibre Channel Protocol.

Definition in file fcp.c.

Macro Definition Documentation

◆ ERANGE_READ_DATA_ORDERING

#define ERANGE_READ_DATA_ORDERING   __einfo_error ( EINFO_ERANGE_READ_DATA_ORDERING )

Definition at line 58 of file fcp.c.

◆ EINFO_ERANGE_READ_DATA_ORDERING

#define EINFO_ERANGE_READ_DATA_ORDERING   __einfo_uniqify ( EINFO_ERANGE, 0x01, "Read data out of order" )

Definition at line 60 of file fcp.c.

◆ ERANGE_READ_DATA_OVERRUN

#define ERANGE_READ_DATA_OVERRUN   __einfo_error ( EINFO_ERANGE_READ_DATA_OVERRUN )

Definition at line 62 of file fcp.c.

◆ EINFO_ERANGE_READ_DATA_OVERRUN

#define EINFO_ERANGE_READ_DATA_OVERRUN   __einfo_uniqify ( EINFO_ERANGE, 0x02, "Read data overrun" )

Definition at line 64 of file fcp.c.

◆ ERANGE_WRITE_DATA_STUCK

#define ERANGE_WRITE_DATA_STUCK   __einfo_error ( EINFO_ERANGE_WRITE_DATA_STUCK )

Definition at line 66 of file fcp.c.

◆ EINFO_ERANGE_WRITE_DATA_STUCK

#define EINFO_ERANGE_WRITE_DATA_STUCK   __einfo_uniqify ( EINFO_ERANGE, 0x03, "Write data stuck" )

Definition at line 68 of file fcp.c.

◆ ERANGE_WRITE_DATA_OVERRUN

#define ERANGE_WRITE_DATA_OVERRUN   __einfo_error ( EINFO_ERANGE_WRITE_DATA_OVERRUN )

Definition at line 70 of file fcp.c.

◆ EINFO_ERANGE_WRITE_DATA_OVERRUN

#define EINFO_ERANGE_WRITE_DATA_OVERRUN   __einfo_uniqify ( EINFO_ERANGE, 0x04, "Write data overrun" )

Definition at line 72 of file fcp.c.

◆ ERANGE_DATA_UNDERRUN

#define ERANGE_DATA_UNDERRUN   __einfo_error ( EINFO_ERANGE_DATA_UNDERRUN )

Definition at line 74 of file fcp.c.

◆ EINFO_ERANGE_DATA_UNDERRUN

#define EINFO_ERANGE_DATA_UNDERRUN   __einfo_uniqify ( EINFO_ERANGE, 0x05, "Data underrun" )

Definition at line 76 of file fcp.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ fcp_prli_tx()

static int fcp_prli_tx ( struct fc_els els)
static

Transmit FCP PRLI.

Parameters
elsFibre Channel ELS transaction
Return values
rcReturn status code

Definition at line 94 of file fcp.c.

94  {
96 
97  /* Build service parameter page */
98  memset ( &param, 0, sizeof ( param ) );
100 
101  return fc_els_prli_tx ( els, &fcp_prli_descriptor, &param );
102 }
#define FCP_PRLI_NO_READ_RDY
Read FCP_XFER_RDY disabled.
Definition: fcp.h:140
#define htonl(value)
Definition: byteswap.h:133
int fc_els_prli_tx(struct fc_els *els, struct fc_els_prli_descriptor *descriptor, void *param)
Transmit PRLI.
Definition: fcels.c:950
#define FCP_PRLI_INITIATOR
Has initiator functionality.
Definition: fcp.h:146
struct hv_monitor_parameter param[4][32]
Parameters.
Definition: hyperv.h:24
An FCP PRLI service parameter page.
Definition: fcp.h:131
void * memset(void *dest, int character, size_t len) __nonnull

References fc_els_prli_tx(), FCP_PRLI_INITIATOR, FCP_PRLI_NO_READ_RDY, htonl, memset(), and param.

◆ fcp_prli_rx()

static int fcp_prli_rx ( struct fc_els els,
void *  data,
size_t  len 
)
static

Receive FCP PRLI.

Parameters
elsFibre Channel ELS transaction
frameELS frame
lenLength of ELS frame
Return values
rcReturn status code

Definition at line 112 of file fcp.c.

112  {
113  return fc_els_prli_rx ( els, &fcp_prli_descriptor, data, len );
114 }
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int fc_els_prli_rx(struct fc_els *els, struct fc_els_prli_descriptor *descriptor, void *data, size_t len)
Receive PRLI.
Definition: fcels.c:1006

References data, fc_els_prli_rx(), and len.

◆ fcp_prli_detect()

static int fcp_prli_detect ( struct fc_els els,
const void *  data,
size_t  len 
)
static

Detect FCP PRLI.

Parameters
elsFibre Channel ELS transaction
dataELS frame
lenLength of ELS frame
Return values
rcReturn status code

Definition at line 124 of file fcp.c.

125  {
126  return fc_els_prli_detect ( els, &fcp_prli_descriptor, data, len );
127 }
int fc_els_prli_detect(struct fc_els *els __unused, struct fc_els_prli_descriptor *descriptor, const void *data, size_t len)
Detect PRLI.
Definition: fcels.c:1092
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References data, fc_els_prli_detect(), and len.

◆ fcpdev_get()

static struct fcp_device* fcpdev_get ( struct fcp_device fcpdev)
inlinestatic

Get reference to FCP device.

Parameters
fcpdevFCP device
Return values
fcpdevFCP device

Definition at line 203 of file fcp.c.

203  {
204  ref_get ( &fcpdev->refcnt );
205  return fcpdev;
206 }
struct refcnt refcnt
Reference count.
Definition: fcp.c:154
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92

References ref_get, and fcp_device::refcnt.

Referenced by fcpdev_scsi_command().

◆ fcpdev_put()

static void fcpdev_put ( struct fcp_device fcpdev)
inlinestatic

Drop reference to FCP device.

Parameters
fcpdevFCP device

Definition at line 214 of file fcp.c.

214  {
215  ref_put ( &fcpdev->refcnt );
216 }
struct refcnt refcnt
Reference count.
Definition: fcp.c:154
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References ref_put, and fcp_device::refcnt.

Referenced by fcpcmd_free().

◆ fcpcmd_get()

static struct fcp_command* fcpcmd_get ( struct fcp_command fcpcmd)
inlinestatic

Get reference to FCP command.

Parameters
fcpcmdFCP command
Return values
fcpcmdFCP command

Definition at line 225 of file fcp.c.

225  {
226  ref_get ( &fcpcmd->refcnt );
227  return fcpcmd;
228 }
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
struct refcnt refcnt
Reference count.
Definition: fcp.c:169

References ref_get, and fcp_command::refcnt.

Referenced by fcpdev_close().

◆ fcpcmd_put()

static void fcpcmd_put ( struct fcp_command fcpcmd)
inlinestatic

Drop reference to FCP command.

Parameters
fcpcmdFCP command

Definition at line 236 of file fcp.c.

236  {
237  ref_put ( &fcpcmd->refcnt );
238 }
struct refcnt refcnt
Reference count.
Definition: fcp.c:169
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References ref_put, and fcp_command::refcnt.

Referenced by fcpdev_close().

◆ fcpcmd_start_send()

static void fcpcmd_start_send ( struct fcp_command fcpcmd,
int(*)(struct fcp_command *fcpcmd)  send 
)
inlinestatic

Start FCP command sending.

Parameters
fcpcmdFCP command
sendSend method

Definition at line 247 of file fcp.c.

248  {
249  fcpcmd->send = send;
250  process_add ( &fcpcmd->process );
251 }
struct process process
Send process.
Definition: fcp.c:179
void process_add(struct process *process)
Add process to process list.
Definition: process.c:59
int(* send)(struct fcp_command *fcpcmd)
Send current IU.
Definition: fcp.c:185
struct arbelprm_send_doorbell send
Definition: arbel.h:11

References fcp_command::process, process_add(), fcp_command::send, and send.

Referenced by fcpcmd_recv_xfer_rdy(), and fcpdev_scsi_command().

◆ fcpcmd_stop_send()

static void fcpcmd_stop_send ( struct fcp_command fcpcmd)
inlinestatic

Stop FCP command sending.

Parameters
fcpcmdFCP command

Definition at line 259 of file fcp.c.

259  {
260  process_del ( &fcpcmd->process );
261 }
struct process process
Send process.
Definition: fcp.c:179
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79

References fcp_command::process, and process_del().

Referenced by fcpcmd_close(), fcpcmd_send_cmnd(), and fcpcmd_send_wrdata().

◆ fcpcmd_free()

static void fcpcmd_free ( struct refcnt refcnt)
static

Free FCP command.

Parameters
refcntReference count

Definition at line 268 of file fcp.c.

268  {
269  struct fcp_command *fcpcmd =
270  container_of ( refcnt, struct fcp_command, refcnt );
271 
272  /* Remove from list of commands */
273  list_del ( &fcpcmd->list );
274  fcpdev_put ( fcpcmd->fcpdev );
275 
276  /* Free command */
277  free ( fcpcmd );
278 }
A reference counter.
Definition: refcnt.h:26
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static void fcpdev_put(struct fcp_device *fcpdev)
Drop reference to FCP device.
Definition: fcp.c:214
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct list_head list
List of active commands.
Definition: fcp.c:173
An FCP command.
Definition: fcp.c:167
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171

References container_of, fcp_command::fcpdev, fcpdev_put(), free, fcp_command::list, and list_del.

Referenced by fcpdev_scsi_command().

◆ fcpcmd_close()

static void fcpcmd_close ( struct fcp_command fcpcmd,
int  rc 
)
static

Close FCP command.

Parameters
fcpcmdFCP command
rcReason for close

Definition at line 286 of file fcp.c.

286  {
287  struct fcp_device *fcpdev = fcpcmd->fcpdev;
288 
289  if ( rc != 0 ) {
290  DBGC ( fcpdev, "FCP %p xchg %04x closed: %s\n",
291  fcpdev, fcpcmd->xchg_id, strerror ( rc ) );
292  }
293 
294  /* Stop sending */
295  fcpcmd_stop_send ( fcpcmd );
296 
297  /* Shut down interfaces */
298  intf_shutdown ( &fcpcmd->scsi, rc );
299  intf_shutdown ( &fcpcmd->xchg, rc );
300 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
#define DBGC(...)
Definition: compiler.h:505
static void fcpcmd_stop_send(struct fcp_command *fcpcmd)
Stop FCP command sending.
Definition: fcp.c:259
struct interface scsi
SCSI command interface.
Definition: fcp.c:175
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct interface xchg
Fibre Channel exchange interface.
Definition: fcp.c:177
uint16_t xchg_id
Exchange ID.
Definition: fcp.c:193
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171
An FCP device.
Definition: fcp.c:152

References DBGC, fcpcmd_stop_send(), fcp_command::fcpdev, intf_shutdown(), rc, fcp_command::scsi, strerror(), fcp_command::xchg, and fcp_command::xchg_id.

Referenced by fcpcmd_close_err(), fcpcmd_deliver(), fcpcmd_recv_rsp(), fcpcmd_step(), fcpdev_close(), and fcpdev_scsi_command().

◆ fcpcmd_close_err()

static void fcpcmd_close_err ( struct fcp_command fcpcmd,
int  rc 
)
static

Close FCP command in error.

Parameters
fcpcmdFCP command
rcReason for close

Definition at line 308 of file fcp.c.

308  {
309  if ( rc == 0 )
310  rc = -EPIPE;
311  fcpcmd_close ( fcpcmd, rc );
312 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EPIPE
Broken pipe.
Definition: errno.h:619
static void fcpcmd_close(struct fcp_command *fcpcmd, int rc)
Close FCP command.
Definition: fcp.c:286

References EPIPE, fcpcmd_close(), and rc.

◆ fcpcmd_send_cmnd()

static int fcpcmd_send_cmnd ( struct fcp_command fcpcmd)
static

Send FCP command IU.

Parameters
fcpcmdFCP command
Return values
rcReturn status code

Definition at line 320 of file fcp.c.

320  {
321  struct fcp_device *fcpdev = fcpcmd->fcpdev;
322  struct scsi_cmd *command = &fcpcmd->command;
323  struct io_buffer *iobuf;
324  struct fcp_cmnd *cmnd;
325  struct xfer_metadata meta;
326  int rc;
327 
328  /* Sanity check */
329  if ( command->data_in_len && command->data_out_len ) {
330  DBGC ( fcpdev, "FCP %p xchg %04x cannot handle bidirectional "
331  "command\n", fcpdev, fcpcmd->xchg_id );
332  return -ENOTSUP;
333  }
334 
335  /* Allocate I/O buffer */
336  iobuf = xfer_alloc_iob ( &fcpcmd->xchg, sizeof ( *cmnd ) );
337  if ( ! iobuf ) {
338  DBGC ( fcpdev, "FCP %p xchg %04x cannot allocate command IU\n",
339  fcpdev, fcpcmd->xchg_id );
340  return -ENOMEM;
341  }
342 
343  /* Construct command IU frame */
344  cmnd = iob_put ( iobuf, sizeof ( *cmnd ) );
345  memset ( cmnd, 0, sizeof ( *cmnd ) );
346  memcpy ( &cmnd->lun, &command->lun, sizeof ( cmnd->lun ) );
347  assert ( ! ( command->data_in_len && command->data_out_len ) );
348  if ( command->data_in_len )
349  cmnd->dirn |= FCP_CMND_RDDATA;
350  if ( command->data_out_len )
351  cmnd->dirn |= FCP_CMND_WRDATA;
352  memcpy ( &cmnd->cdb, &fcpcmd->command.cdb, sizeof ( cmnd->cdb ) );
353  cmnd->len = htonl ( command->data_in_len + command->data_out_len );
354  memset ( &meta, 0, sizeof ( meta ) );
355  meta.flags = ( XFER_FL_CMD_STAT | XFER_FL_OVER );
356  DBGC2 ( fcpdev, "FCP %p xchg %04x CMND " SCSI_CDB_FORMAT " %04x\n",
357  fcpdev, fcpcmd->xchg_id, SCSI_CDB_DATA ( cmnd->cdb ),
358  ntohl ( cmnd->len ) );
359 
360  /* No further data to send within this IU */
361  fcpcmd_stop_send ( fcpcmd );
362 
363  /* Send command IU frame */
364  if ( ( rc = xfer_deliver ( &fcpcmd->xchg, iob_disown ( iobuf ),
365  &meta ) ) != 0 ) {
366  DBGC ( fcpdev, "FCP %p xchg %04x cannot deliver command IU: "
367  "%s\n", fcpdev, fcpcmd->xchg_id, strerror ( rc ) );
368  return rc;
369  }
370 
371  return 0;
372 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
Data transfer metadata.
Definition: xfer.h:22
A command-line command.
Definition: command.h:9
union scsi_cdb cdb
SCSI CDB.
Definition: fcp.h:31
An FCP command IU.
Definition: fcp.h:19
#define DBGC(...)
Definition: compiler.h:505
static void fcpcmd_stop_send(struct fcp_command *fcpcmd)
Stop FCP command sending.
Definition: fcp.c:259
#define ntohl(value)
Definition: byteswap.h:134
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition: xfer.c:158
union scsi_cdb cdb
CDB for this command.
Definition: scsi.h:253
#define htonl(value)
Definition: byteswap.h:133
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define FCP_CMND_RDDATA
Command includes data-in.
Definition: fcp.h:40
struct scsi_lun lun
SCSI LUN.
Definition: fcp.h:21
int meta(WINDOW *, bool)
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct scsi_cmd command
SCSI command.
Definition: fcp.c:187
#define XFER_FL_CMD_STAT
Data content represents a command or status message.
Definition: xfer.h:60
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
#define SCSI_CDB_DATA(cdb)
printf() parameters for dumping a scsi_cdb
Definition: scsi.h:223
struct interface xchg
Fibre Channel exchange interface.
Definition: fcp.c:177
uint16_t xchg_id
Exchange ID.
Definition: fcp.c:193
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
uint32_t len
Data length.
Definition: fcp.h:33
#define XFER_FL_OVER
Sender is relinquishing use of half-duplex channel.
Definition: xfer.h:50
#define FCP_CMND_WRDATA
Command includes data-out.
Definition: fcp.h:37
uint8_t dirn
Direction.
Definition: fcp.h:29
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171
void * memset(void *dest, int character, size_t len) __nonnull
An FCP device.
Definition: fcp.c:152
A persistent I/O buffer.
Definition: iobuf.h:33

References assert(), scsi_cmd::cdb, fcp_cmnd::cdb, fcp_command::command, DBGC, DBGC2, fcp_cmnd::dirn, ENOMEM, ENOTSUP, FCP_CMND_RDDATA, FCP_CMND_WRDATA, fcpcmd_stop_send(), fcp_command::fcpdev, htonl, iob_disown, iob_put, fcp_cmnd::len, fcp_cmnd::lun, memcpy(), memset(), meta(), ntohl, rc, SCSI_CDB_DATA, SCSI_CDB_FORMAT, strerror(), fcp_command::xchg, fcp_command::xchg_id, xfer_alloc_iob(), xfer_deliver(), XFER_FL_CMD_STAT, and XFER_FL_OVER.

Referenced by fcpdev_scsi_command().

◆ fcpcmd_recv_rddata()

static int fcpcmd_recv_rddata ( struct fcp_command fcpcmd,
struct io_buffer iobuf,
struct xfer_metadata meta 
)
static

Handle FCP read data IU.

Parameters
fcpcmdFCP command
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 382 of file fcp.c.

384  {
385  struct fcp_device *fcpdev = fcpcmd->fcpdev;
386  struct scsi_cmd *command = &fcpcmd->command;
387  size_t offset = meta->offset;
388  size_t len = iob_len ( iobuf );
389  int rc;
390 
391  /* Sanity checks */
392  if ( ! ( meta->flags & XFER_FL_ABS_OFFSET ) ) {
393  DBGC ( fcpdev, "FCP %p xchg %04x read data missing offset\n",
394  fcpdev, fcpcmd->xchg_id );
396  goto done;
397  }
398  if ( offset != fcpcmd->offset ) {
399  DBGC ( fcpdev, "FCP %p xchg %04x read data out of order "
400  "(expected %zd, received %zd)\n",
401  fcpdev, fcpcmd->xchg_id, fcpcmd->offset, offset );
403  goto done;
404  }
405  if ( ( offset + len ) > command->data_in_len ) {
406  DBGC ( fcpdev, "FCP %p xchg %04x read data overrun (max %zd, "
407  "received %zd)\n", fcpdev, fcpcmd->xchg_id,
408  command->data_in_len, ( offset + len ) );
410  goto done;
411  }
412  DBGC2 ( fcpdev, "FCP %p xchg %04x RDDATA [%08zx,%08zx)\n",
413  fcpdev, fcpcmd->xchg_id, offset, ( offset + len ) );
414 
415  /* Copy to user buffer */
416  copy_to_user ( command->data_in, offset, iobuf->data, len );
417  fcpcmd->offset += len;
418  assert ( fcpcmd->offset <= command->data_in_len );
419 
420  rc = 0;
421  done:
422  free_iob ( iobuf );
423  return rc;
424 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:47
A command-line command.
Definition: command.h:9
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
int meta(WINDOW *, bool)
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
static __always_inline void copy_to_user(userptr_t dest, off_t dest_off, const void *src, size_t len)
Copy data to user buffer.
Definition: uaccess.h:324
struct scsi_cmd command
SCSI command.
Definition: fcp.c:187
uint16_t xchg_id
Exchange ID.
Definition: fcp.c:193
#define ERANGE_READ_DATA_OVERRUN
Definition: fcp.c:62
size_t offset
Data offset within command.
Definition: fcp.c:189
A SCSI command information unit.
Definition: scsi.h:249
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:48
struct bofm_section_header done
Definition: bofm_test.c:46
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171
#define ERANGE_READ_DATA_ORDERING
Definition: fcp.c:58
An FCP device.
Definition: fcp.c:152

References assert(), fcp_command::command, copy_to_user(), io_buffer::data, DBGC, DBGC2, done, ERANGE_READ_DATA_ORDERING, ERANGE_READ_DATA_OVERRUN, fcp_command::fcpdev, free_iob(), iob_len(), len, meta(), fcp_command::offset, offset, rc, fcp_command::xchg_id, and XFER_FL_ABS_OFFSET.

Referenced by fcpcmd_deliver().

◆ fcpcmd_send_wrdata()

static int fcpcmd_send_wrdata ( struct fcp_command fcpcmd)
static

Send FCP write data IU.

Parameters
fcpcmdFCP command
Return values
rcReturn status code

Definition at line 432 of file fcp.c.

432  {
433  struct fcp_device *fcpdev = fcpcmd->fcpdev;
434  struct scsi_cmd *command = &fcpcmd->command;
435  struct io_buffer *iobuf;
436  struct xfer_metadata meta;
437  size_t len;
438  int rc;
439 
440  /* Calculate length to be sent */
441  len = xfer_window ( &fcpcmd->xchg );
442  if ( len > fcpcmd->remaining )
443  len = fcpcmd->remaining;
444 
445  /* Sanity checks */
446  if ( len == 0 ) {
447  DBGC ( fcpdev, "FCP %p xchg %04x write data stuck\n",
448  fcpdev, fcpcmd->xchg_id );
449  return -ERANGE_WRITE_DATA_STUCK;
450  }
451  if ( ( fcpcmd->offset + len ) > command->data_out_len ) {
452  DBGC ( fcpdev, "FCP %p xchg %04x write data overrun (max %zd, "
453  "requested %zd)\n", fcpdev, fcpcmd->xchg_id,
454  command->data_out_len, ( fcpcmd->offset + len ) );
456  }
457 
458  /* Allocate I/O buffer */
459  iobuf = xfer_alloc_iob ( &fcpcmd->xchg, len );
460  if ( ! iobuf ) {
461  DBGC ( fcpdev, "FCP %p xchg %04x cannot allocate write data "
462  "IU for %zd bytes\n", fcpdev, fcpcmd->xchg_id, len );
463  return -ENOMEM;
464  }
465 
466  /* Construct data IU frame */
467  copy_from_user ( iob_put ( iobuf, len ), command->data_out,
468  fcpcmd->offset, len );
469  memset ( &meta, 0, sizeof ( meta ) );
471  meta.offset = fcpcmd->offset;
472  DBGC2 ( fcpdev, "FCP %p xchg %04x WRDATA [%08zx,%04zx)\n",
473  fcpdev, fcpcmd->xchg_id, fcpcmd->offset,
474  ( fcpcmd->offset + iob_len ( iobuf ) ) );
475 
476  /* Calculate amount of data remaining to be sent within this IU */
477  assert ( len <= fcpcmd->remaining );
478  fcpcmd->offset += len;
479  fcpcmd->remaining -= len;
480  assert ( fcpcmd->offset <= command->data_out_len );
481  if ( fcpcmd->remaining == 0 ) {
482  fcpcmd_stop_send ( fcpcmd );
483  meta.flags |= XFER_FL_OVER;
484  }
485 
486  /* Send data IU frame */
487  if ( ( rc = xfer_deliver ( &fcpcmd->xchg, iob_disown ( iobuf ),
488  &meta ) ) != 0 ) {
489  DBGC ( fcpdev, "FCP %p xchg %04x cannot deliver write data "
490  "IU: %s\n", fcpdev, fcpcmd->xchg_id, strerror ( rc ) );
491  return rc;
492  }
493 
494  return 0;
495 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
Data transfer metadata.
Definition: xfer.h:22
#define ERANGE_WRITE_DATA_OVERRUN
Definition: fcp.c:70
#define ERANGE_WRITE_DATA_STUCK
Definition: fcp.c:66
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:47
A command-line command.
Definition: command.h:9
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
#define DBGC(...)
Definition: compiler.h:505
static void fcpcmd_stop_send(struct fcp_command *fcpcmd)
Stop FCP command sending.
Definition: fcp.c:259
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition: xfer.c:158
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
#define XFER_FL_RESPONSE
Data content is a response.
Definition: xfer.h:63
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int meta(WINDOW *, bool)
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
struct scsi_cmd command
SCSI command.
Definition: fcp.c:187
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
struct interface xchg
Fibre Channel exchange interface.
Definition: fcp.c:177
uint16_t xchg_id
Exchange ID.
Definition: fcp.c:193
size_t offset
Data offset within command.
Definition: fcp.c:189
A SCSI command information unit.
Definition: scsi.h:249
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
size_t remaining
Length of data remaining to be sent within this IU.
Definition: fcp.c:191
#define XFER_FL_OVER
Sender is relinquishing use of half-duplex channel.
Definition: xfer.h:50
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171
void * memset(void *dest, int character, size_t len) __nonnull
An FCP device.
Definition: fcp.c:152
A persistent I/O buffer.
Definition: iobuf.h:33

References assert(), fcp_command::command, copy_from_user(), DBGC, DBGC2, ENOMEM, ERANGE_WRITE_DATA_OVERRUN, ERANGE_WRITE_DATA_STUCK, fcpcmd_stop_send(), fcp_command::fcpdev, iob_disown, iob_len(), iob_put, len, memset(), meta(), fcp_command::offset, rc, fcp_command::remaining, strerror(), fcp_command::xchg, fcp_command::xchg_id, xfer_alloc_iob(), xfer_deliver(), XFER_FL_ABS_OFFSET, XFER_FL_OVER, XFER_FL_RESPONSE, and xfer_window().

Referenced by fcpcmd_recv_xfer_rdy().

◆ fcpcmd_recv_xfer_rdy()

static int fcpcmd_recv_xfer_rdy ( struct fcp_command fcpcmd,
struct io_buffer iobuf,
struct xfer_metadata *meta  __unused 
)
static

Handle FCP transfer ready IU.

Parameters
fcpcmdFCP command
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 505 of file fcp.c.

507  {
508  struct fcp_device *fcpdev = fcpcmd->fcpdev;
509  struct fcp_xfer_rdy *xfer_rdy = iobuf->data;
510  int rc;
511 
512  /* Sanity checks */
513  if ( iob_len ( iobuf ) != sizeof ( *xfer_rdy ) ) {
514  DBGC ( fcpdev, "FCP %p xchg %04x received invalid transfer "
515  "ready IU:\n", fcpdev, fcpcmd->xchg_id );
516  DBGC_HDA ( fcpdev, 0, iobuf->data, iob_len ( iobuf ) );
517  rc = -EPROTO;
518  goto done;
519  }
520  if ( ntohl ( xfer_rdy->offset ) != fcpcmd->offset ) {
521  /* We do not advertise out-of-order delivery */
522  DBGC ( fcpdev, "FCP %p xchg %04x cannot support out-of-order "
523  "delivery (expected %zd, requested %d)\n",
524  fcpdev, fcpcmd->xchg_id, fcpcmd->offset,
525  ntohl ( xfer_rdy->offset ) );
526  rc = -EPROTO;
527  goto done;
528  }
529  DBGC2 ( fcpdev, "FCP %p xchg %04x XFER_RDY [%08x,%08x)\n",
530  fcpdev, fcpcmd->xchg_id, ntohl ( xfer_rdy->offset ),
531  ( ntohl ( xfer_rdy->offset ) + ntohl ( xfer_rdy->len ) ) );
532 
533  /* Start sending requested data */
534  fcpcmd->remaining = ntohl ( xfer_rdy->len );
536 
537  rc = 0;
538  done:
539  free_iob ( iobuf );
540  return rc;
541 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An FCP transfer ready IU.
Definition: fcp.h:46
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
#define ntohl(value)
Definition: byteswap.h:134
uint32_t offset
Relative offset of data.
Definition: fcp.h:48
static int fcpcmd_send_wrdata(struct fcp_command *fcpcmd)
Send FCP write data IU.
Definition: fcp.c:432
#define DBGC_HDA(...)
Definition: compiler.h:506
static void fcpcmd_start_send(struct fcp_command *fcpcmd, int(*send)(struct fcp_command *fcpcmd))
Start FCP command sending.
Definition: fcp.c:247
#define EPROTO
Protocol error.
Definition: errno.h:624
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
uint16_t xchg_id
Exchange ID.
Definition: fcp.c:193
size_t offset
Data offset within command.
Definition: fcp.c:189
#define DBGC2(...)
Definition: compiler.h:522
size_t remaining
Length of data remaining to be sent within this IU.
Definition: fcp.c:191
void * data
Start of data.
Definition: iobuf.h:48
uint32_t len
Burst length.
Definition: fcp.h:50
struct bofm_section_header done
Definition: bofm_test.c:46
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171
An FCP device.
Definition: fcp.c:152

References io_buffer::data, DBGC, DBGC2, DBGC_HDA, done, EPROTO, fcpcmd_send_wrdata(), fcpcmd_start_send(), fcp_command::fcpdev, free_iob(), iob_len(), fcp_xfer_rdy::len, ntohl, fcp_xfer_rdy::offset, fcp_command::offset, rc, fcp_command::remaining, and fcp_command::xchg_id.

Referenced by fcpcmd_deliver().

◆ fcpcmd_recv_rsp()

static int fcpcmd_recv_rsp ( struct fcp_command fcpcmd,
struct io_buffer iobuf,
struct xfer_metadata *meta  __unused 
)
static

Handle FCP response IU.

Parameters
fcpcmdFCP command
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 551 of file fcp.c.

553  {
554  struct fcp_device *fcpdev = fcpcmd->fcpdev;
555  struct scsi_cmd *command = &fcpcmd->command;
556  struct fcp_rsp *rsp = iobuf->data;
557  struct scsi_rsp response;
558  int rc;
559 
560  /* Sanity check */
561  if ( ( iob_len ( iobuf ) < sizeof ( *rsp ) ) ||
562  ( iob_len ( iobuf ) < ( sizeof ( *rsp ) +
564  fcp_rsp_sense_data_len ( rsp ) ) ) ) {
565  DBGC ( fcpdev, "FCP %p xchg %04x received invalid response "
566  "IU:\n", fcpdev, fcpcmd->xchg_id );
567  DBGC_HDA ( fcpdev, 0, iobuf->data, iob_len ( iobuf ) );
568  rc = -EPROTO;
569  goto done;
570  }
571  DBGC2 ( fcpdev, "FCP %p xchg %04x RSP stat %02x resid %08x flags %02x"
572  "%s%s%s%s\n", fcpdev, fcpcmd->xchg_id, rsp->status,
573  ntohl ( rsp->residual ), rsp->flags,
574  ( ( rsp->flags & FCP_RSP_RESPONSE_LEN_VALID ) ? " resp" : "" ),
575  ( ( rsp->flags & FCP_RSP_SENSE_LEN_VALID ) ? " sense" : "" ),
576  ( ( rsp->flags & FCP_RSP_RESIDUAL_OVERRUN ) ? " over" : "" ),
577  ( ( rsp->flags & FCP_RSP_RESIDUAL_UNDERRUN ) ? " under" : "" ));
578  if ( fcp_rsp_response_data ( rsp ) ) {
579  DBGC2 ( fcpdev, "FCP %p xchg %04x response data:\n",
580  fcpdev, fcpcmd->xchg_id );
581  DBGC2_HDA ( fcpdev, 0, fcp_rsp_response_data ( rsp ),
583  }
584  if ( fcp_rsp_sense_data ( rsp ) ) {
585  DBGC2 ( fcpdev, "FCP %p xchg %04x sense data:\n",
586  fcpdev, fcpcmd->xchg_id );
587  DBGC2_HDA ( fcpdev, 0, fcp_rsp_sense_data ( rsp ),
589  }
590 
591  /* Check for locally-detected command underrun */
592  if ( ( rsp->status == 0 ) &&
593  ( fcpcmd->offset != ( command->data_in_len +
594  command->data_out_len ) ) ) {
595  DBGC ( fcpdev, "FCP %p xchg %04x data underrun (expected %zd, "
596  "got %zd)\n", fcpdev, fcpcmd->xchg_id,
597  ( command->data_in_len + command->data_out_len ),
598  fcpcmd->offset );
600  goto done;
601  }
602 
603  /* Build SCSI response */
604  memset ( &response, 0, sizeof ( response ) );
605  response.status = rsp->status;
606  if ( rsp->flags & ( FCP_RSP_RESIDUAL_OVERRUN |
608  response.overrun = ntohl ( rsp->residual );
609  if ( rsp->flags & FCP_RSP_RESIDUAL_UNDERRUN )
610  response.overrun = -response.overrun;
611  }
613  fcp_rsp_sense_data_len ( rsp ), &response.sense );
614 
615  /* Free buffer before sending response, to minimise
616  * out-of-memory errors.
617  */
618  free_iob ( iob_disown ( iobuf ) );
619 
620  /* Send SCSI response */
621  scsi_response ( &fcpcmd->scsi, &response );
622 
623  /* Terminate command */
624  fcpcmd_close ( fcpcmd, 0 );
625 
626  rc = 0;
627  done:
628  free_iob ( iobuf );
629  return rc;
630 }
void scsi_parse_sense(const void *data, size_t len, struct scsi_sns_descriptor *sense)
Parse SCSI sense data.
Definition: scsi.c:146
#define FCP_RSP_RESIDUAL_OVERRUN
Residual represents overrun.
Definition: fcp.h:80
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A command-line command.
Definition: command.h:9
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
static void fcpcmd_close(struct fcp_command *fcpcmd, int rc)
Close FCP command.
Definition: fcp.c:286
#define ntohl(value)
Definition: byteswap.h:134
#define FCP_RSP_RESIDUAL_UNDERRUN
Residual represents underrun.
Definition: fcp.h:83
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
static void * fcp_rsp_sense_data(struct fcp_rsp *rsp)
Get sense data portion of FCP response.
Definition: fcp.h:113
A SCSI response information unit.
Definition: scsi.h:322
#define DBGC_HDA(...)
Definition: compiler.h:506
static void * fcp_rsp_response_data(struct fcp_rsp *rsp)
Get response data portion of FCP response.
Definition: fcp.h:91
struct interface scsi
SCSI command interface.
Definition: fcp.c:175
#define EPROTO
Protocol error.
Definition: errno.h:624
#define DBGC2_HDA(...)
Definition: compiler.h:523
uint64_t rsp
Definition: librm.h:267
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
static size_t fcp_rsp_response_data_len(struct fcp_rsp *rsp)
Get length of response data portion of FCP response.
Definition: fcp.h:102
struct scsi_cmd command
SCSI command.
Definition: fcp.c:187
uint16_t xchg_id
Exchange ID.
Definition: fcp.c:193
#define FCP_RSP_RESPONSE_LEN_VALID
Response length field is valid.
Definition: fcp.h:74
size_t offset
Data offset within command.
Definition: fcp.c:189
void scsi_response(struct interface *intf, struct scsi_rsp *response)
Report SCSI response.
Definition: scsi.c:206
A SCSI command information unit.
Definition: scsi.h:249
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:48
#define ERANGE_DATA_UNDERRUN
Definition: fcp.c:74
#define FCP_RSP_SENSE_LEN_VALID
Sense length field is valid.
Definition: fcp.h:77
An FCP response IU.
Definition: fcp.h:56
struct bofm_section_header done
Definition: bofm_test.c:46
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171
static size_t fcp_rsp_sense_data_len(struct fcp_rsp *rsp)
Get length of sense data portion of FCP response.
Definition: fcp.h:125
void * memset(void *dest, int character, size_t len) __nonnull
An FCP device.
Definition: fcp.c:152

References fcp_command::command, io_buffer::data, DBGC, DBGC2, DBGC2_HDA, DBGC_HDA, done, EPROTO, ERANGE_DATA_UNDERRUN, FCP_RSP_RESIDUAL_OVERRUN, FCP_RSP_RESIDUAL_UNDERRUN, fcp_rsp_response_data(), fcp_rsp_response_data_len(), FCP_RSP_RESPONSE_LEN_VALID, fcp_rsp_sense_data(), fcp_rsp_sense_data_len(), FCP_RSP_SENSE_LEN_VALID, fcpcmd_close(), fcp_command::fcpdev, free_iob(), iob_disown, iob_len(), memset(), ntohl, fcp_command::offset, scsi_rsp::overrun, rc, rsp, fcp_command::scsi, scsi_parse_sense(), scsi_response(), scsi_rsp::sense, scsi_rsp::status, and fcp_command::xchg_id.

Referenced by fcpcmd_deliver().

◆ fcpcmd_recv_unknown()

static int fcpcmd_recv_unknown ( struct fcp_command fcpcmd,
struct io_buffer iobuf,
struct xfer_metadata *meta  __unused 
)
static

Handle unknown FCP IU.

Parameters
fcpcmdFCP command
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 640 of file fcp.c.

642  {
643  struct fcp_device *fcpdev = fcpcmd->fcpdev;
644 
645  DBGC ( fcpdev, "FCP %p xchg %04x received unknown IU:\n",
646  fcpdev, fcpcmd->xchg_id );
647  DBGC_HDA ( fcpdev, 0, iobuf->data, iob_len ( iobuf ) );
648  free_iob ( iobuf );
649  return -EPROTO;
650 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
#define DBGC_HDA(...)
Definition: compiler.h:506
#define EPROTO
Protocol error.
Definition: errno.h:624
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
uint16_t xchg_id
Exchange ID.
Definition: fcp.c:193
void * data
Start of data.
Definition: iobuf.h:48
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171
An FCP device.
Definition: fcp.c:152

References io_buffer::data, DBGC, DBGC_HDA, EPROTO, fcp_command::fcpdev, free_iob(), iob_len(), and fcp_command::xchg_id.

Referenced by fcpcmd_deliver().

◆ fcpcmd_step()

static void fcpcmd_step ( struct fcp_command fcpcmd)
static

Transmit FCP frame.

Parameters
fcpcmdFCP command

Definition at line 657 of file fcp.c.

657  {
658  int rc;
659 
660  /* Send the current IU */
661  if ( ( rc = fcpcmd->send ( fcpcmd ) ) != 0 ) {
662  /* Treat failure as a fatal error */
663  fcpcmd_close ( fcpcmd, rc );
664  }
665 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void fcpcmd_close(struct fcp_command *fcpcmd, int rc)
Close FCP command.
Definition: fcp.c:286
int(* send)(struct fcp_command *fcpcmd)
Send current IU.
Definition: fcp.c:185

References fcpcmd_close(), rc, and fcp_command::send.

◆ fcpcmd_deliver()

static int fcpcmd_deliver ( struct fcp_command fcpcmd,
struct io_buffer iobuf,
struct xfer_metadata meta 
)
static

Receive FCP frame.

Parameters
fcpcmdFCP command
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 675 of file fcp.c.

677  {
678  int ( * fcpcmd_recv ) ( struct fcp_command *fcpcmd,
679  struct io_buffer *iobuf,
680  struct xfer_metadata *meta );
681  int rc;
682 
683  /* Determine handler */
684  switch ( meta->flags & ( XFER_FL_CMD_STAT | XFER_FL_RESPONSE ) ) {
685  case ( XFER_FL_RESPONSE ) :
686  fcpcmd_recv = fcpcmd_recv_rddata;
687  break;
688  case ( XFER_FL_CMD_STAT ) :
689  fcpcmd_recv = fcpcmd_recv_xfer_rdy;
690  break;
692  fcpcmd_recv = fcpcmd_recv_rsp;
693  break;
694  default:
695  fcpcmd_recv = fcpcmd_recv_unknown;
696  break;
697  }
698 
699  /* Handle IU */
700  if ( ( rc = fcpcmd_recv ( fcpcmd, iob_disown ( iobuf ), meta ) ) != 0 ){
701  /* Treat any error as fatal to the command */
702  fcpcmd_close ( fcpcmd, rc );
703  }
704 
705  return rc;
706 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Data transfer metadata.
Definition: xfer.h:22
static int fcpcmd_recv_unknown(struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Handle unknown FCP IU.
Definition: fcp.c:640
static void fcpcmd_close(struct fcp_command *fcpcmd, int rc)
Close FCP command.
Definition: fcp.c:286
static int fcpcmd_recv_rsp(struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Handle FCP response IU.
Definition: fcp.c:551
#define XFER_FL_RESPONSE
Data content is a response.
Definition: xfer.h:63
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
static int fcpcmd_recv_rddata(struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta)
Handle FCP read data IU.
Definition: fcp.c:382
int meta(WINDOW *, bool)
#define XFER_FL_CMD_STAT
Data content represents a command or status message.
Definition: xfer.h:60
static int fcpcmd_recv_xfer_rdy(struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Handle FCP transfer ready IU.
Definition: fcp.c:505
An FCP command.
Definition: fcp.c:167
A persistent I/O buffer.
Definition: iobuf.h:33

References fcpcmd_close(), fcpcmd_recv_rddata(), fcpcmd_recv_rsp(), fcpcmd_recv_unknown(), fcpcmd_recv_xfer_rdy(), iob_disown, meta(), rc, XFER_FL_CMD_STAT, and XFER_FL_RESPONSE.

◆ fcpdev_scsi_command()

static int fcpdev_scsi_command ( struct fcp_device fcpdev,
struct interface parent,
struct scsi_cmd command 
)
static

Issue FCP SCSI command.

Parameters
fcpdevFCP device
parentParent interface
commandSCSI command
Return values
tagCommand tag, or negative error

Definition at line 739 of file fcp.c.

741  {
742  struct fcp_prli_service_parameters *param = fcpdev->user.ulp->param;
743  struct fcp_command *fcpcmd;
744  int xchg_id;
745  int rc;
746 
747  /* Check link */
748  if ( ( rc = fcpdev->user.ulp->link.rc ) != 0 ) {
749  DBGC ( fcpdev, "FCP %p could not issue command while link is "
750  "down: %s\n", fcpdev, strerror ( rc ) );
751  goto err_link;
752  }
753 
754  /* Check target capability */
755  assert ( param != NULL );
756  assert ( fcpdev->user.ulp->param_len >= sizeof ( *param ) );
757  if ( ! ( param->flags & htonl ( FCP_PRLI_TARGET ) ) ) {
758  DBGC ( fcpdev, "FCP %p could not issue command: not a target\n",
759  fcpdev );
760  rc = -ENOTTY;
761  goto err_target;
762  }
763 
764  /* Allocate and initialise structure */
765  fcpcmd = zalloc ( sizeof ( *fcpcmd ) );
766  if ( ! fcpcmd ) {
767  rc = -ENOMEM;
768  goto err_zalloc;
769  }
770  ref_init ( &fcpcmd->refcnt, fcpcmd_free );
771  intf_init ( &fcpcmd->scsi, &fcpcmd_scsi_desc, &fcpcmd->refcnt );
772  intf_init ( &fcpcmd->xchg, &fcpcmd_xchg_desc, &fcpcmd->refcnt );
774  &fcpcmd->refcnt );
775  fcpcmd->fcpdev = fcpdev_get ( fcpdev );
776  list_add ( &fcpcmd->list, &fcpdev->fcpcmds );
777  memcpy ( &fcpcmd->command, command, sizeof ( fcpcmd->command ) );
778 
779  /* Create new exchange */
780  if ( ( xchg_id = fc_xchg_originate ( &fcpcmd->xchg,
781  fcpdev->user.ulp->peer->port,
782  &fcpdev->user.ulp->peer->port_id,
783  FC_TYPE_FCP ) ) < 0 ) {
784  rc = xchg_id;
785  DBGC ( fcpdev, "FCP %p could not create exchange: %s\n",
786  fcpdev, strerror ( rc ) );
787  goto err_xchg_originate;
788  }
789  fcpcmd->xchg_id = xchg_id;
790 
791  /* Start sending command IU */
793 
794  /* Attach to parent interface, mortalise self, and return */
795  intf_plug_plug ( &fcpcmd->scsi, parent );
796  ref_put ( &fcpcmd->refcnt );
797  return ( FCP_TAG_MAGIC | fcpcmd->xchg_id );
798 
799  err_xchg_originate:
800  fcpcmd_close ( fcpcmd, rc );
801  ref_put ( &fcpcmd->refcnt );
802  err_zalloc:
803  err_target:
804  err_link:
805  return rc;
806 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct fc_ulp * ulp
Fibre Channel upper layer protocol.
Definition: fc.h:455
int fc_xchg_originate(struct interface *parent, struct fc_port *port, struct fc_port_id *peer_port_id, unsigned int type)
Originate a new Fibre Channel exchange.
Definition: fc.c:728
struct process process
Send process.
Definition: fcp.c:179
#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
A command-line command.
Definition: command.h:9
Fibre Channel Protocol.
Definition: fc.h:193
#define DBGC(...)
Definition: compiler.h:505
static int fcpcmd_send_cmnd(struct fcp_command *fcpcmd)
Send FCP command IU.
Definition: fcp.c:320
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
static void fcpcmd_close(struct fcp_command *fcpcmd, int rc)
Close FCP command.
Definition: fcp.c:286
static struct process_descriptor fcpcmd_process_desc
FCP command process descriptor.
Definition: fcp.c:728
struct fc_peer * peer
Fibre Channel peer.
Definition: fc.h:417
#define htonl(value)
Definition: byteswap.h:133
static void fcpcmd_free(struct refcnt *refcnt)
Free FCP command.
Definition: fcp.c:268
struct fc_port * port
Fibre Channel port, if known.
Definition: fc.h:354
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct interface_descriptor fcpcmd_xchg_desc
FCP command Fibre Channel exchange interface descriptor.
Definition: fcp.c:724
size_t param_len
Service parameter length.
Definition: fc.h:433
static void fcpcmd_start_send(struct fcp_command *fcpcmd, int(*send)(struct fcp_command *fcpcmd))
Start FCP command sending.
Definition: fcp.c:247
struct interface scsi
SCSI command interface.
Definition: fcp.c:175
static struct fcp_device * fcpdev_get(struct fcp_device *fcpdev)
Get reference to FCP device.
Definition: fcp.c:203
#define FCP_TAG_MAGIC
FCP tag magic marker.
Definition: fcp.h:43
struct fc_port_id port_id
Peer port ID, if known.
Definition: fc.h:356
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
void * param
Service parameters, if any.
Definition: fc.h:431
struct hv_monitor_parameter param[4][32]
Parameters.
Definition: hyperv.h:24
struct fc_link_state link
Link state monitor.
Definition: fc.h:427
struct scsi_cmd command
SCSI command.
Definition: fcp.c:187
struct interface xchg
Fibre Channel exchange interface.
Definition: fcp.c:177
uint16_t xchg_id
Exchange ID.
Definition: fcp.c:193
#define FCP_PRLI_TARGET
Has target functionality.
Definition: fcp.h:143
static void process_init_stopped(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process without adding to process list.
Definition: process.h:145
struct list_head list
List of active commands.
Definition: fcp.c:173
static struct interface_descriptor fcpcmd_scsi_desc
FCP command SCSI interface descriptor.
Definition: fcp.c:714
An FCP PRLI service parameter page.
Definition: fcp.h:131
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
struct refcnt refcnt
Reference count.
Definition: fcp.c:169
struct list_head fcpcmds
List of active commands.
Definition: fcp.c:160
struct fc_ulp_user user
Fibre Channel upper-layer protocol user.
Definition: fcp.c:156
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
An FCP command.
Definition: fcp.c:167
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References assert(), fcp_command::command, DBGC, ENOMEM, ENOTTY, FC_TYPE_FCP, fc_xchg_originate(), FCP_PRLI_TARGET, FCP_TAG_MAGIC, fcpcmd_close(), fcpcmd_free(), fcpcmd_process_desc, fcpcmd_scsi_desc, fcpcmd_send_cmnd(), fcpcmd_start_send(), fcpcmd_xchg_desc, fcp_device::fcpcmds, fcp_command::fcpdev, fcpdev_get(), htonl, intf_init(), intf_plug_plug(), fc_ulp::link, fcp_command::list, list_add, memcpy(), NULL, param, fc_ulp::param, fc_ulp::param_len, fc_ulp::peer, fc_peer::port, fc_peer::port_id, fcp_command::process, process_init_stopped(), fc_link_state::rc, rc, ref_init, ref_put, fcp_command::refcnt, fcp_command::scsi, strerror(), fc_ulp_user::ulp, fcp_device::user, fcp_command::xchg, fcp_command::xchg_id, and zalloc().

◆ fcpdev_close()

static void fcpdev_close ( struct fcp_device fcpdev,
int  rc 
)
static

Close FCP device.

Parameters
fcpdevFCP device
rcReason for close

Definition at line 814 of file fcp.c.

814  {
815  struct fcp_command *fcpcmd;
816  struct fcp_command *tmp;
817 
818  DBGC ( fcpdev, "FCP %p closed: %s\n", fcpdev, strerror ( rc ) );
819 
820  /* Shut down interfaces */
821  intf_shutdown ( &fcpdev->scsi, rc );
822 
823  /* Shut down any active commands */
825  fcpcmd_get ( fcpcmd );
826  fcpcmd_close ( fcpcmd, rc );
827  fcpcmd_put ( fcpcmd );
828  }
829 
830  /* Drop reference to ULP */
831  fc_ulp_detach ( &fcpdev->user );
832 }
void fc_ulp_detach(struct fc_ulp_user *user)
Detach Fibre Channel upper-layer protocol user.
Definition: fc.c:1625
static struct fcp_command * fcpcmd_get(struct fcp_command *fcpcmd)
Get reference to FCP command.
Definition: fcp.c:225
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
#define DBGC(...)
Definition: compiler.h:505
static void fcpcmd_close(struct fcp_command *fcpcmd, int rc)
Close FCP command.
Definition: fcp.c:286
unsigned long tmp
Definition: linux_pci.h:53
struct interface scsi
SCSI command issuing interface.
Definition: fcp.c:158
#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
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct list_head list
List of active commands.
Definition: fcp.c:173
static void fcpcmd_put(struct fcp_command *fcpcmd)
Drop reference to FCP command.
Definition: fcp.c:236
struct list_head fcpcmds
List of active commands.
Definition: fcp.c:160
struct fc_ulp_user user
Fibre Channel upper-layer protocol user.
Definition: fcp.c:156
An FCP command.
Definition: fcp.c:167
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171

References DBGC, fc_ulp_detach(), fcpcmd_close(), fcpcmd_get(), fcpcmd_put(), fcp_device::fcpcmds, fcp_command::fcpdev, intf_shutdown(), fcp_command::list, list_for_each_entry_safe, rc, fcp_device::scsi, strerror(), tmp, and fcp_device::user.

Referenced by fcpdev_open().

◆ fcpdev_window()

static size_t fcpdev_window ( struct fcp_device fcpdev)
static

Check FCP device flow-control window.

Parameters
fcpdevFCP device
Return values
lenLength of window

Definition at line 840 of file fcp.c.

840  {
841  return ( fc_link_ok ( &fcpdev->user.ulp->link ) ?
842  ~( ( size_t ) 0 ) : 0 );
843 }
struct fc_ulp * ulp
Fibre Channel upper layer protocol.
Definition: fc.h:455
static int fc_link_ok(struct fc_link_state *link)
Check Fibre Channel link state.
Definition: fc.h:108
struct fc_link_state link
Link state monitor.
Definition: fc.h:427
struct fc_ulp_user user
Fibre Channel upper-layer protocol user.
Definition: fcp.c:156
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:171

References fc_link_ok(), fcp_command::fcpdev, fc_ulp::link, fc_ulp_user::ulp, and fcp_device::user.

◆ fcpdev_edd_describe()

static int fcpdev_edd_describe ( struct fcp_device fcpdev,
struct edd_interface_type type,
union edd_device_path path 
)
static

Describe FCP device using EDD.

Parameters
fcpdevFCP device
typeEDD interface type
pathEDD device path
Return values
rcReturn status code

Definition at line 853 of file fcp.c.

855  {
856  union {
857  struct fc_name fc;
858  uint64_t u64;
859  } wwn;
860  union {
861  struct scsi_lun scsi;
862  uint64_t u64;
863  } lun;
864 
866  memcpy ( &wwn.fc, &fcpdev->desc.wwn, sizeof ( wwn.fc ) );
867  path->fibre.wwn = be64_to_cpu ( wwn.u64 );
868  memcpy ( &lun.scsi, &fcpdev->desc.lun, sizeof ( lun.scsi ) );
869  path->fibre.lun = be64_to_cpu ( lun.u64 );
870  return 0;
871 }
#define EDD_INTF_TYPE_FIBRE
EDD Fibre Channel interface type.
Definition: edd.h:65
uint64_t wwn
WWN.
Definition: edd.h:131
u16 fc
802.11 Frame Control field
Definition: ieee80211.h:14
unsigned long long uint64_t
Definition: stdint.h:13
#define cpu_to_le64(value)
Definition: byteswap.h:108
struct fc_name wwn
Fibre Channel WWN.
Definition: fcp.h:169
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint64_t u64
Definition: stdint.h:25
struct fcp_description desc
Device description (for boot firmware table)
Definition: fcp.c:163
uint8_t lun
Logical Unit Number.
Definition: edd.h:32
#define be64_to_cpu(value)
Definition: byteswap.h:117
uint8_t lun
Logical Unit Number.
Definition: edd.h:109
A Fibre Channel name.
Definition: fc.h:29
struct scsi_lun lun
SCSI LUN.
Definition: fcp.h:171
uint32_t type
Operating system type.
Definition: ena.h:12
A SCSI LUN.
Definition: scsi.h:236
uint64_t wwn
WWN.
Definition: edd.h:30

References be64_to_cpu, cpu_to_le64, fcp_device::desc, EDD_INTF_TYPE_FIBRE, fc, lun, edd_device_path::lun, fcp_description::lun, memcpy(), type, wwn, edd_device_path::wwn, and fcp_description::wwn.

◆ fcpdev_identify_device()

static struct device* fcpdev_identify_device ( struct fcp_device fcpdev)
static

Identify device underlying FCP device.

Parameters
fcpdevFCP device
Return values
deviceUnderlying device

Definition at line 879 of file fcp.c.

879  {
880 
881  /* We know the underlying device only if the link is up;
882  * otherwise we don't have a port to examine.
883  */
884  if ( ! fc_link_ok ( &fcpdev->user.ulp->link ) ) {
885  DBGC ( fcpdev, "FCP %p doesn't know underlying device "
886  "until link is up\n", fcpdev );
887  return NULL;
888  }
889 
890  /* Hand off to port's transport interface */
891  assert ( fcpdev->user.ulp->peer->port != NULL );
892  return identify_device ( &fcpdev->user.ulp->peer->port->transport );
893 }
struct fc_ulp * ulp
Fibre Channel upper layer protocol.
Definition: fc.h:455
#define DBGC(...)
Definition: compiler.h:505
struct fc_peer * peer
Fibre Channel peer.
Definition: fc.h:417
struct fc_port * port
Fibre Channel port, if known.
Definition: fc.h:354
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static int fc_link_ok(struct fc_link_state *link)
Check Fibre Channel link state.
Definition: fc.h:108
struct fc_link_state link
Link state monitor.
Definition: fc.h:427
struct interface transport
Transport interface.
Definition: fc.h:261
struct device * identify_device(struct interface *intf)
Identify a device behind an interface.
Definition: device.c:125
struct fc_ulp_user user
Fibre Channel upper-layer protocol user.
Definition: fcp.c:156
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), DBGC, fc_link_ok(), identify_device(), fc_ulp::link, NULL, fc_ulp::peer, fc_peer::port, fc_port::transport, fc_ulp_user::ulp, and fcp_device::user.

◆ fcpdev_efi_describe()

static EFI_DEVICE_PATH_PROTOCOL* fcpdev_efi_describe ( struct fcp_device fcpdev)
static

Describe as an EFI device path.

Parameters
fcpFCP device
Return values
pathEFI device path, or NULL on error

Definition at line 902 of file fcp.c.

902  {
903 
904  return efi_fcp_path ( &fcpdev->desc );
905 }
struct fcp_description desc
Device description (for boot firmware table)
Definition: fcp.c:163
EFI_DEVICE_PATH_PROTOCOL * efi_fcp_path(struct fcp_description *desc)
Construct EFI device path for Fibre Channel device.
Definition: efi_path.c:543

References fcp_device::desc, and efi_fcp_path().

◆ fcpdev_examine()

static void fcpdev_examine ( struct fc_ulp_user user)
static

Examine FCP ULP link state.

Parameters
userFibre Channel upper-layer protocol user

Definition at line 927 of file fcp.c.

927  {
928  struct fcp_device *fcpdev =
929  container_of ( user, struct fcp_device, user );
930 
931  if ( fc_link_ok ( &fcpdev->user.ulp->link ) ) {
932  DBGC ( fcpdev, "FCP %p link is up\n", fcpdev );
933  } else {
934  DBGC ( fcpdev, "FCP %p link is down: %s\n",
935  fcpdev, strerror ( fcpdev->user.ulp->link.rc ) );
936  }
937 
938  /* Notify SCSI layer of window change */
939  xfer_window_changed ( &fcpdev->scsi );
940 }
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:146
struct fc_ulp * ulp
Fibre Channel upper layer protocol.
Definition: fc.h:455
#define DBGC(...)
Definition: compiler.h:505
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct ntlm_data user
User name.
Definition: ntlm.h:20
static int fc_link_ok(struct fc_link_state *link)
Check Fibre Channel link state.
Definition: fc.h:108
struct interface scsi
SCSI command issuing interface.
Definition: fcp.c:158
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct fc_link_state link
Link state monitor.
Definition: fc.h:427
struct fc_ulp_user user
Fibre Channel upper-layer protocol user.
Definition: fcp.c:156
An FCP device.
Definition: fcp.c:152

References container_of, DBGC, fc_link_ok(), fc_ulp::link, fc_link_state::rc, fcp_device::scsi, strerror(), fc_ulp_user::ulp, user, fcp_device::user, and xfer_window_changed().

Referenced by fcpdev_open().

◆ fcpdev_open()

static int fcpdev_open ( struct interface parent,
struct fc_name wwn,
struct scsi_lun lun 
)
static

Open FCP device.

Parameters
parentParent interface
wwnFibre Channel WWN
lunSCSI LUN
Return values
rcReturn status code

Definition at line 950 of file fcp.c.

951  {
952  struct fc_ulp *ulp;
953  struct fcp_device *fcpdev;
954  int rc;
955 
956  /* Get Fibre Channel ULP interface */
958  if ( ! ulp ) {
959  rc = -ENOMEM;
960  goto err_ulp_get;
961  }
962 
963  /* Allocate and initialise structure */
964  fcpdev = zalloc ( sizeof ( *fcpdev ) );
965  if ( ! fcpdev ) {
966  rc = -ENOMEM;
967  goto err_zalloc;
968  }
969  ref_init ( &fcpdev->refcnt, NULL );
970  intf_init ( &fcpdev->scsi, &fcpdev_scsi_desc, &fcpdev->refcnt );
971  INIT_LIST_HEAD ( &fcpdev->fcpcmds );
972  fc_ulp_user_init ( &fcpdev->user, fcpdev_examine, &fcpdev->refcnt );
973 
974  DBGC ( fcpdev, "FCP %p opened for %s\n", fcpdev, fc_ntoa ( wwn ) );
975 
976  /* Attach to Fibre Channel ULP */
977  fc_ulp_attach ( ulp, &fcpdev->user );
978 
979  /* Preserve parameters required for boot firmware table */
980  memcpy ( &fcpdev->desc.wwn, wwn, sizeof ( fcpdev->desc.wwn ) );
981  memcpy ( &fcpdev->desc.lun, lun, sizeof ( fcpdev->desc.lun ) );
982 
983  /* Attach SCSI device to parent interface */
984  if ( ( rc = scsi_open ( parent, &fcpdev->scsi, lun ) ) != 0 ) {
985  DBGC ( fcpdev, "FCP %p could not create SCSI device: %s\n",
986  fcpdev, strerror ( rc ) );
987  goto err_scsi_open;
988  }
989 
990  /* Drop temporary reference to ULP */
991  fc_ulp_put ( ulp );
992 
993  /* Mortalise self and return */
994  ref_put ( &fcpdev->refcnt );
995  return 0;
996 
997  err_scsi_open:
998  fcpdev_close ( fcpdev, rc );
999  ref_put ( &fcpdev->refcnt );
1000  err_zalloc:
1001  fc_ulp_put ( ulp );
1002  err_ulp_get:
1003  return rc;
1004 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct interface_descriptor fcpdev_scsi_desc
FCP device SCSI interface descriptor.
Definition: fcp.c:919
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
Fibre Channel Protocol.
Definition: fc.h:193
#define DBGC(...)
Definition: compiler.h:505
const char * fc_ntoa(const struct fc_name *wwn)
Format Fibre Channel WWN.
Definition: fc.c:127
int scsi_open(struct interface *block, struct interface *scsi, struct scsi_lun *lun)
Open SCSI device.
Definition: scsi.c:984
struct refcnt refcnt
Reference count.
Definition: fcp.c:154
struct fc_name wwn
Fibre Channel WWN.
Definition: fcp.h:169
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void fc_ulp_attach(struct fc_ulp *ulp, struct fc_ulp_user *user)
Attach Fibre Channel upper-layer protocol user.
Definition: fc.c:1607
struct interface scsi
SCSI command issuing interface.
Definition: fcp.c:158
struct fcp_description desc
Device description (for boot firmware table)
Definition: fcp.c:163
uint8_t lun
Logical Unit Number.
Definition: edd.h:32
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
struct scsi_lun lun
SCSI LUN.
Definition: fcp.h:171
static void fc_ulp_put(struct fc_ulp *ulp)
Drop reference to Fibre Channel upper-layer protocol.
Definition: fc.h:485
static void fcpdev_examine(struct fc_ulp_user *user)
Examine FCP ULP link state.
Definition: fcp.c:927
struct list_head fcpcmds
List of active commands.
Definition: fcp.c:160
struct fc_ulp_user user
Fibre Channel upper-layer protocol user.
Definition: fcp.c:156
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
struct fc_ulp * fc_ulp_get_wwn_type(const struct fc_name *port_wwn, unsigned int type)
Get Fibre Channel upper-layer protocol by port name and type.
Definition: fc.c:1880
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static void fc_ulp_user_init(struct fc_ulp_user *user, void(*examine)(struct fc_ulp_user *user), struct refcnt *refcnt)
Initialise Fibre Channel upper-layer protocol user.
Definition: fc.h:519
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
A Fibre Channel upper-layer protocol.
Definition: fc.h:413
uint64_t wwn
WWN.
Definition: edd.h:30
An FCP device.
Definition: fcp.c:152
static void fcpdev_close(struct fcp_device *fcpdev, int rc)
Close FCP device.
Definition: fcp.c:814

References DBGC, fcp_device::desc, ENOMEM, fc_ntoa(), FC_TYPE_FCP, fc_ulp_attach(), fc_ulp_get_wwn_type(), fc_ulp_put(), fc_ulp_user_init(), fcp_device::fcpcmds, fcpdev_close(), fcpdev_examine(), fcpdev_scsi_desc, INIT_LIST_HEAD, intf_init(), lun, fcp_description::lun, memcpy(), NULL, rc, ref_init, ref_put, fcp_device::refcnt, fcp_device::scsi, scsi_open(), strerror(), fcp_device::user, wwn, fcp_description::wwn, and zalloc().

Referenced by fcp_open().

◆ fcp_parse_uri()

static int fcp_parse_uri ( struct uri uri,
struct fc_name wwn,
struct scsi_lun lun 
)
static

Parse FCP URI.

Parameters
uriURI
Return values
wwnFibre Channel WWN
lunSCSI LUN
rcReturn status code

An FCP URI has the form "fcp:<wwn>:<lun>" or "fcp://<wwn>/<lun>"

Definition at line 1023 of file fcp.c.

1024  {
1025  char wwn_buf[ FC_NAME_STRLEN + 1 /* NUL */ ];
1026  const char *wwn_text;
1027  const char *lun_text;
1028  int rc;
1029 
1030  /* Extract WWN and LUN texts from URI */
1031  if ( uri->opaque ) {
1032  /* "fcp:<wwn>:<lun>" */
1033  if ( snprintf ( wwn_buf, sizeof ( wwn_buf ), "%s",
1034  uri->opaque ) < ( FC_NAME_STRLEN + 1 /* : */ ) )
1035  return -EINVAL;
1036  if ( uri->opaque[FC_NAME_STRLEN] != ':' )
1037  return -EINVAL;
1038  wwn_text = wwn_buf;
1039  lun_text = &uri->opaque[FC_NAME_STRLEN + 1];
1040  } else {
1041  /* If host exists, path must also exist */
1042  if ( ! ( uri->host && uri->path ) )
1043  return -EINVAL;
1044  if ( uri->path[0] != '/' )
1045  return -EINVAL;
1046  wwn_text = uri->host;
1047  lun_text = ( uri->path + 1 );
1048  }
1049 
1050  /* Parse WWN */
1051  if ( ( rc = fc_aton ( wwn_text, wwn ) ) != 0 )
1052  return rc;
1053 
1054  /* Parse LUN */
1055  if ( ( rc = scsi_parse_lun ( lun_text, lun ) ) != 0 )
1056  return rc;
1057 
1058  return 0;
1059 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int fc_aton(const char *wwn_text, struct fc_name *wwn)
Parse Fibre Channel WWN.
Definition: fc.c:144
int scsi_parse_lun(const char *lun_string, struct scsi_lun *lun)
Parse SCSI LUN.
Definition: scsi.c:117
const char * path
Path (after URI decoding)
Definition: uri.h:80
uint8_t lun
Logical Unit Number.
Definition: edd.h:32
const char * host
Host name.
Definition: uri.h:76
const char * opaque
Opaque part.
Definition: uri.h:70
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
A Uniform Resource Identifier.
Definition: uri.h:64
#define FC_NAME_STRLEN
Length of Fibre Channel name text.
Definition: fc.h:34
uint64_t wwn
WWN.
Definition: edd.h:30

References EINVAL, fc_aton(), FC_NAME_STRLEN, uri::host, lun, uri::opaque, uri::path, rc, scsi_parse_lun(), snprintf(), and wwn.

Referenced by fcp_open().

◆ fcp_open()

static int fcp_open ( struct interface parent,
struct uri uri 
)
static

Open FCP URI.

Parameters
parentParent interface
uriURI
Return values
rcReturn status code

Definition at line 1068 of file fcp.c.

1068  {
1069  struct fc_name wwn;
1070  struct scsi_lun lun;
1071  int rc;
1072 
1073  /* Parse URI */
1074  if ( ( rc = fcp_parse_uri ( uri, &wwn, &lun ) ) != 0 )
1075  return rc;
1076 
1077  /* Open FCP device */
1078  if ( ( rc = fcpdev_open ( parent, &wwn, &lun ) ) != 0 )
1079  return rc;
1080 
1081  return 0;
1082 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int fcpdev_open(struct interface *parent, struct fc_name *wwn, struct scsi_lun *lun)
Open FCP device.
Definition: fcp.c:950
static int fcp_parse_uri(struct uri *uri, struct fc_name *wwn, struct scsi_lun *lun)
Parse FCP URI.
Definition: fcp.c:1023
uint8_t lun
Logical Unit Number.
Definition: edd.h:32
A Fibre Channel name.
Definition: fc.h:29
A Uniform Resource Identifier.
Definition: uri.h:64
A SCSI LUN.
Definition: scsi.h:236
uint64_t wwn
WWN.
Definition: edd.h:30

References fcp_parse_uri(), fcpdev_open(), lun, rc, and wwn.

Variable Documentation

◆ __fc_els_prli_descriptor

struct fc_els_prli_descriptor fcp_prli_descriptor __fc_els_prli_descriptor
Initial value:
= {
.type = FC_TYPE_FCP,
.param_len = sizeof ( struct fcp_prli_service_parameters ),
.handler = &fcp_prli_handler,
}
Fibre Channel Protocol.
Definition: fc.h:193
An FCP PRLI service parameter page.
Definition: fcp.h:131

FCP PRLI descriptor.

Definition at line 86 of file fcp.c.

◆ __fc_els_handler

struct fc_els_handler fcp_prli_handler __fc_els_handler
Initial value:
= {
.name = "PRLI-FCP",
.tx = fcp_prli_tx,
.rx = fcp_prli_rx,
.detect = fcp_prli_detect,
}
static int fcp_prli_rx(struct fc_els *els, void *data, size_t len)
Receive FCP PRLI.
Definition: fcp.c:112
static int fcp_prli_detect(struct fc_els *els, const void *data, size_t len)
Detect FCP PRLI.
Definition: fcp.c:124
static int fcp_prli_tx(struct fc_els *els)
Transmit FCP PRLI.
Definition: fcp.c:94

FCP PRLI ELS handler.

Definition at line 130 of file fcp.c.

◆ fcpcmd_scsi_op

struct interface_operation fcpcmd_scsi_op[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static void fcpcmd_close(struct fcp_command *fcpcmd, int rc)
Close FCP command.
Definition: fcp.c:286
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
An FCP command.
Definition: fcp.c:167

FCP command SCSI interface operations.

Definition at line 709 of file fcp.c.

◆ fcpcmd_scsi_desc

struct interface_descriptor fcpcmd_scsi_desc
static
Initial value:
=
static struct interface_operation fcpcmd_scsi_op[]
FCP command SCSI interface operations.
Definition: fcp.c:709
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97
An FCP command.
Definition: fcp.c:167

FCP command SCSI interface descriptor.

Definition at line 714 of file fcp.c.

Referenced by fcpdev_scsi_command().

◆ fcpcmd_xchg_op

struct interface_operation fcpcmd_xchg_op[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
static int fcpcmd_deliver(struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta)
Receive FCP frame.
Definition: fcp.c:675
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
An FCP command.
Definition: fcp.c:167
static void fcpcmd_close_err(struct fcp_command *fcpcmd, int rc)
Close FCP command in error.
Definition: fcp.c:308

FCP command Fibre Channel exchange interface operations.

Definition at line 718 of file fcp.c.

◆ fcpcmd_xchg_desc

struct interface_descriptor fcpcmd_xchg_desc
static
Initial value:
=
static struct interface_operation fcpcmd_xchg_op[]
FCP command Fibre Channel exchange interface operations.
Definition: fcp.c:718
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:97
An FCP command.
Definition: fcp.c:167

FCP command Fibre Channel exchange interface descriptor.

Definition at line 724 of file fcp.c.

Referenced by fcpdev_scsi_command().

◆ fcpcmd_process_desc

struct process_descriptor fcpcmd_process_desc
static
Initial value:
=
A process.
Definition: process.h:17
static void fcpcmd_step(struct fcp_command *fcpcmd)
Transmit FCP frame.
Definition: fcp.c:657
#define PROC_DESC(object_type, process, _step)
Define a process descriptor.
Definition: process.h:82
An FCP command.
Definition: fcp.c:167

FCP command process descriptor.

Definition at line 728 of file fcp.c.

Referenced by fcpdev_scsi_command().

◆ fcpdev_scsi_op

struct interface_operation fcpdev_scsi_op[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
int edd_describe(struct interface *intf, struct edd_interface_type *type, union edd_device_path *path)
Describe a disk device using EDD.
Definition: edd.c:44
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
static int fcpdev_scsi_command(struct fcp_device *fcpdev, struct interface *parent, struct scsi_cmd *command)
Issue FCP SCSI command.
Definition: fcp.c:739
A SCSI command.
Definition: scsi.c:262
static EFI_DEVICE_PATH_PROTOCOL * fcpdev_efi_describe(struct fcp_device *fcpdev)
Describe as an EFI device path.
Definition: fcp.c:902
#define EFI_INTF_OP
Definition: efi.h:350
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
static size_t fcpdev_window(struct fcp_device *fcpdev)
Check FCP device flow-control window.
Definition: fcp.c:840
EFI_DEVICE_PATH_PROTOCOL * efi_describe(struct interface *intf)
Describe object as an EFI device path.
Definition: efi_path.c:680
static struct device * fcpdev_identify_device(struct fcp_device *fcpdev)
Identify device underlying FCP device.
Definition: fcp.c:879
struct device * identify_device(struct interface *intf)
Identify a device behind an interface.
Definition: device.c:125
static int fcpdev_edd_describe(struct fcp_device *fcpdev, struct edd_interface_type *type, union edd_device_path *path)
Describe FCP device using EDD.
Definition: fcp.c:853
An FCP device.
Definition: fcp.c:152
static void fcpdev_close(struct fcp_device *fcpdev, int rc)
Close FCP device.
Definition: fcp.c:814

FCP device SCSI interface operations.

Definition at line 908 of file fcp.c.

◆ fcpdev_scsi_desc

struct interface_descriptor fcpdev_scsi_desc
static
Initial value:
=
static struct interface_operation fcpdev_scsi_op[]
FCP device SCSI interface operations.
Definition: fcp.c:908
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80
An FCP device.
Definition: fcp.c:152

FCP device SCSI interface descriptor.

Definition at line 919 of file fcp.c.

Referenced by fcpdev_open().

◆ __uri_opener

struct uri_opener fcp_uri_opener __uri_opener
Initial value:
= {
.scheme = "fcp",
.open = fcp_open,
}
static int fcp_open(struct interface *parent, struct uri *uri)
Open FCP URI.
Definition: fcp.c:1068

FCP URI opener.

Definition at line 1085 of file fcp.c.