iPXE
fcp.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stddef.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <errno.h>
31 #include <stdio.h>
32 #include <assert.h>
33 #include <byteswap.h>
34 #include <ipxe/refcnt.h>
35 #include <ipxe/list.h>
36 #include <ipxe/interface.h>
37 #include <ipxe/xfer.h>
38 #include <ipxe/iobuf.h>
39 #include <ipxe/open.h>
40 #include <ipxe/process.h>
41 #include <ipxe/uri.h>
42 #include <ipxe/acpi.h>
43 #include <ipxe/scsi.h>
44 #include <ipxe/device.h>
45 #include <ipxe/edd.h>
46 #include <ipxe/fc.h>
47 #include <ipxe/fcels.h>
48 #include <ipxe/fcp.h>
49 
50 /** @file
51  *
52  * Fibre Channel Protocol
53  *
54  */
55 
56 /* Disambiguate the various error causes */
57 #define ERANGE_READ_DATA_ORDERING \
58  __einfo_error ( EINFO_ERANGE_READ_DATA_ORDERING )
59 #define EINFO_ERANGE_READ_DATA_ORDERING \
60  __einfo_uniqify ( EINFO_ERANGE, 0x01, "Read data out of order" )
61 #define ERANGE_READ_DATA_OVERRUN \
62  __einfo_error ( EINFO_ERANGE_READ_DATA_OVERRUN )
63 #define EINFO_ERANGE_READ_DATA_OVERRUN \
64  __einfo_uniqify ( EINFO_ERANGE, 0x02, "Read data overrun" )
65 #define ERANGE_WRITE_DATA_STUCK \
66  __einfo_error ( EINFO_ERANGE_WRITE_DATA_STUCK )
67 #define EINFO_ERANGE_WRITE_DATA_STUCK \
68  __einfo_uniqify ( EINFO_ERANGE, 0x03, "Write data stuck" )
69 #define ERANGE_WRITE_DATA_OVERRUN \
70  __einfo_error ( EINFO_ERANGE_WRITE_DATA_OVERRUN )
71 #define EINFO_ERANGE_WRITE_DATA_OVERRUN \
72  __einfo_uniqify ( EINFO_ERANGE, 0x04, "Write data overrun" )
73 #define ERANGE_DATA_UNDERRUN \
74  __einfo_error ( EINFO_ERANGE_DATA_UNDERRUN )
75 #define EINFO_ERANGE_DATA_UNDERRUN \
76  __einfo_uniqify ( EINFO_ERANGE, 0x05, "Data underrun" )
77 
78 /******************************************************************************
79  *
80  * PRLI
81  *
82  ******************************************************************************
83  */
84 
86 
87 /**
88  * Transmit FCP PRLI
89  *
90  * @v els Fibre Channel ELS transaction
91  * @ret rc Return status code
92  */
93 static int fcp_prli_tx ( struct fc_els *els ) {
95 
96  /* Build service parameter page */
97  memset ( &param, 0, sizeof ( param ) );
99 
100  return fc_els_prli_tx ( els, &fcp_prli_descriptor, &param );
101 }
102 
103 /**
104  * Receive FCP PRLI
105  *
106  * @v els Fibre Channel ELS transaction
107  * @v frame ELS frame
108  * @v len Length of ELS frame
109  * @ret rc Return status code
110  */
111 static int fcp_prli_rx ( struct fc_els *els, void *data, size_t len ) {
112  return fc_els_prli_rx ( els, &fcp_prli_descriptor, data, len );
113 }
114 
115 /**
116  * Detect FCP PRLI
117  *
118  * @v els Fibre Channel ELS transaction
119  * @v data ELS frame
120  * @v len Length of ELS frame
121  * @ret rc Return status code
122  */
123 static int fcp_prli_detect ( struct fc_els *els, const void *data,
124  size_t len ) {
125  return fc_els_prli_detect ( els, &fcp_prli_descriptor, data, len );
126 }
127 
128 /** FCP PRLI ELS handler */
129 struct fc_els_handler fcp_prli_handler __fc_els_handler = {
130  .name = "PRLI-FCP",
131  .tx = fcp_prli_tx,
132  .rx = fcp_prli_rx,
133  .detect = fcp_prli_detect,
134 };
135 
136 /** FCP PRLI descriptor */
137 struct fc_els_prli_descriptor fcp_prli_descriptor __fc_els_prli_descriptor = {
138  .type = FC_TYPE_FCP,
139  .param_len = sizeof ( struct fcp_prli_service_parameters ),
140  .handler = &fcp_prli_handler,
141 };
142 
143 /******************************************************************************
144  *
145  * FCP devices and commands
146  *
147  ******************************************************************************
148  */
149 
150 /** An FCP device */
151 struct fcp_device {
152  /** Reference count */
153  struct refcnt refcnt;
154  /** Fibre Channel upper-layer protocol user */
156  /** SCSI command issuing interface */
157  struct interface scsi;
158  /** List of active commands */
160 
161  /** Fibre Channel WWN (for boot firmware table) */
162  struct fc_name wwn;
163  /** SCSI LUN (for boot firmware table) */
164  struct scsi_lun lun;
165 };
166 
167 /** An FCP command */
168 struct fcp_command {
169  /** Reference count */
170  struct refcnt refcnt;
171  /** FCP SCSI device */
173  /** List of active commands */
174  struct list_head list;
175  /** SCSI command interface */
176  struct interface scsi;
177  /** Fibre Channel exchange interface */
178  struct interface xchg;
179  /** Send process */
180  struct process process;
181  /** Send current IU
182  *
183  * @v fcpcmd FCP command
184  * @ret rc Return status code
185  */
186  int ( * send ) ( struct fcp_command *fcpcmd );
187  /** SCSI command */
189  /** Data offset within command */
190  size_t offset;
191  /** Length of data remaining to be sent within this IU */
192  size_t remaining;
193  /** Exchange ID */
195 };
196 
197 /**
198  * Get reference to FCP device
199  *
200  * @v fcpdev FCP device
201  * @ret fcpdev FCP device
202  */
203 static inline __attribute__ (( always_inline )) struct fcp_device *
204 fcpdev_get ( struct fcp_device *fcpdev ) {
205  ref_get ( &fcpdev->refcnt );
206  return fcpdev;
207 }
208 
209 /**
210  * Drop reference to FCP device
211  *
212  * @v fcpdev FCP device
213  */
214 static inline __attribute__ (( always_inline )) void
215 fcpdev_put ( struct fcp_device *fcpdev ) {
216  ref_put ( &fcpdev->refcnt );
217 }
218 
219 /**
220  * Get reference to FCP command
221  *
222  * @v fcpcmd FCP command
223  * @ret fcpcmd FCP command
224  */
225 static inline __attribute__ (( always_inline )) struct fcp_command *
226 fcpcmd_get ( struct fcp_command *fcpcmd ) {
227  ref_get ( &fcpcmd->refcnt );
228  return fcpcmd;
229 }
230 
231 /**
232  * Drop reference to FCP command
233  *
234  * @v fcpcmd FCP command
235  */
236 static inline __attribute__ (( always_inline )) void
237 fcpcmd_put ( struct fcp_command *fcpcmd ) {
238  ref_put ( &fcpcmd->refcnt );
239 }
240 
241 /**
242  * Start FCP command sending
243  *
244  * @v fcpcmd FCP command
245  * @v send Send method
246  */
247 static inline __attribute__ (( always_inline )) void
249  int ( * send ) ( struct fcp_command *fcpcmd ) ) {
250  fcpcmd->send = send;
251  process_add ( &fcpcmd->process );
252 }
253 
254 /**
255  * Stop FCP command sending
256  *
257  * @v fcpcmd FCP command
258  */
259 static inline __attribute__ (( always_inline )) void
260 fcpcmd_stop_send ( struct fcp_command *fcpcmd ) {
261  process_del ( &fcpcmd->process );
262 }
263 
264 /**
265  * Free FCP command
266  *
267  * @v refcnt Reference count
268  */
269 static void fcpcmd_free ( struct refcnt *refcnt ) {
270  struct fcp_command *fcpcmd =
271  container_of ( refcnt, struct fcp_command, refcnt );
272 
273  /* Remove from list of commands */
274  list_del ( &fcpcmd->list );
275  fcpdev_put ( fcpcmd->fcpdev );
276 
277  /* Free command */
278  free ( fcpcmd );
279 }
280 
281 /**
282  * Close FCP command
283  *
284  * @v fcpcmd FCP command
285  * @v rc Reason for close
286  */
287 static void fcpcmd_close ( struct fcp_command *fcpcmd, int rc ) {
288  struct fcp_device *fcpdev = fcpcmd->fcpdev;
289 
290  if ( rc != 0 ) {
291  DBGC ( fcpdev, "FCP %p xchg %04x closed: %s\n",
292  fcpdev, fcpcmd->xchg_id, strerror ( rc ) );
293  }
294 
295  /* Stop sending */
296  fcpcmd_stop_send ( fcpcmd );
297 
298  /* Shut down interfaces */
299  intf_shutdown ( &fcpcmd->scsi, rc );
300  intf_shutdown ( &fcpcmd->xchg, rc );
301 }
302 
303 /**
304  * Close FCP command in error
305  *
306  * @v fcpcmd FCP command
307  * @v rc Reason for close
308  */
309 static void fcpcmd_close_err ( struct fcp_command *fcpcmd, int rc ) {
310  if ( rc == 0 )
311  rc = -EPIPE;
312  fcpcmd_close ( fcpcmd, rc );
313 }
314 
315 /**
316  * Send FCP command IU
317  *
318  * @v fcpcmd FCP command
319  * @ret rc Return status code
320  */
321 static int fcpcmd_send_cmnd ( struct fcp_command *fcpcmd ) {
322  struct fcp_device *fcpdev = fcpcmd->fcpdev;
323  struct scsi_cmd *command = &fcpcmd->command;
324  struct io_buffer *iobuf;
325  struct fcp_cmnd *cmnd;
326  struct xfer_metadata meta;
327  int rc;
328 
329  /* Sanity check */
330  if ( command->data_in_len && command->data_out_len ) {
331  DBGC ( fcpdev, "FCP %p xchg %04x cannot handle bidirectional "
332  "command\n", fcpdev, fcpcmd->xchg_id );
333  return -ENOTSUP;
334  }
335 
336  /* Allocate I/O buffer */
337  iobuf = xfer_alloc_iob ( &fcpcmd->xchg, sizeof ( *cmnd ) );
338  if ( ! iobuf ) {
339  DBGC ( fcpdev, "FCP %p xchg %04x cannot allocate command IU\n",
340  fcpdev, fcpcmd->xchg_id );
341  return -ENOMEM;
342  }
343 
344  /* Construct command IU frame */
345  cmnd = iob_put ( iobuf, sizeof ( *cmnd ) );
346  memset ( cmnd, 0, sizeof ( *cmnd ) );
347  memcpy ( &cmnd->lun, &command->lun, sizeof ( cmnd->lun ) );
348  assert ( ! ( command->data_in_len && command->data_out_len ) );
349  if ( command->data_in_len )
350  cmnd->dirn |= FCP_CMND_RDDATA;
351  if ( command->data_out_len )
352  cmnd->dirn |= FCP_CMND_WRDATA;
353  memcpy ( &cmnd->cdb, &fcpcmd->command.cdb, sizeof ( cmnd->cdb ) );
354  cmnd->len = htonl ( command->data_in_len + command->data_out_len );
355  memset ( &meta, 0, sizeof ( meta ) );
356  meta.flags = ( XFER_FL_CMD_STAT | XFER_FL_OVER );
357  DBGC2 ( fcpdev, "FCP %p xchg %04x CMND " SCSI_CDB_FORMAT " %04x\n",
358  fcpdev, fcpcmd->xchg_id, SCSI_CDB_DATA ( cmnd->cdb ),
359  ntohl ( cmnd->len ) );
360 
361  /* No further data to send within this IU */
362  fcpcmd_stop_send ( fcpcmd );
363 
364  /* Send command IU frame */
365  if ( ( rc = xfer_deliver ( &fcpcmd->xchg, iob_disown ( iobuf ),
366  &meta ) ) != 0 ) {
367  DBGC ( fcpdev, "FCP %p xchg %04x cannot deliver command IU: "
368  "%s\n", fcpdev, fcpcmd->xchg_id, strerror ( rc ) );
369  return rc;
370  }
371 
372  return 0;
373 }
374 
375 /**
376  * Handle FCP read data IU
377  *
378  * @v fcpcmd FCP command
379  * @v iobuf I/O buffer
380  * @v meta Data transfer metadata
381  * @ret rc Return status code
382  */
383 static int fcpcmd_recv_rddata ( struct fcp_command *fcpcmd,
384  struct io_buffer *iobuf,
385  struct xfer_metadata *meta ) {
386  struct fcp_device *fcpdev = fcpcmd->fcpdev;
387  struct scsi_cmd *command = &fcpcmd->command;
388  size_t offset = meta->offset;
389  size_t len = iob_len ( iobuf );
390  int rc;
391 
392  /* Sanity checks */
393  if ( ! ( meta->flags & XFER_FL_ABS_OFFSET ) ) {
394  DBGC ( fcpdev, "FCP %p xchg %04x read data missing offset\n",
395  fcpdev, fcpcmd->xchg_id );
397  goto done;
398  }
399  if ( offset != fcpcmd->offset ) {
400  DBGC ( fcpdev, "FCP %p xchg %04x read data out of order "
401  "(expected %zd, received %zd)\n",
402  fcpdev, fcpcmd->xchg_id, fcpcmd->offset, offset );
404  goto done;
405  }
406  if ( ( offset + len ) > command->data_in_len ) {
407  DBGC ( fcpdev, "FCP %p xchg %04x read data overrun (max %zd, "
408  "received %zd)\n", fcpdev, fcpcmd->xchg_id,
409  command->data_in_len, ( offset + len ) );
411  goto done;
412  }
413  DBGC2 ( fcpdev, "FCP %p xchg %04x RDDATA [%08zx,%08zx)\n",
414  fcpdev, fcpcmd->xchg_id, offset, ( offset + len ) );
415 
416  /* Copy to user buffer */
417  copy_to_user ( command->data_in, offset, iobuf->data, len );
418  fcpcmd->offset += len;
419  assert ( fcpcmd->offset <= command->data_in_len );
420 
421  rc = 0;
422  done:
423  free_iob ( iobuf );
424  return rc;
425 }
426 
427 /**
428  * Send FCP write data IU
429  *
430  * @v fcpcmd FCP command
431  * @ret rc Return status code
432  */
433 static int fcpcmd_send_wrdata ( struct fcp_command *fcpcmd ) {
434  struct fcp_device *fcpdev = fcpcmd->fcpdev;
435  struct scsi_cmd *command = &fcpcmd->command;
436  struct io_buffer *iobuf;
437  struct xfer_metadata meta;
438  size_t len;
439  int rc;
440 
441  /* Calculate length to be sent */
442  len = xfer_window ( &fcpcmd->xchg );
443  if ( len > fcpcmd->remaining )
444  len = fcpcmd->remaining;
445 
446  /* Sanity checks */
447  if ( len == 0 ) {
448  DBGC ( fcpdev, "FCP %p xchg %04x write data stuck\n",
449  fcpdev, fcpcmd->xchg_id );
450  return -ERANGE_WRITE_DATA_STUCK;
451  }
452  if ( ( fcpcmd->offset + len ) > command->data_out_len ) {
453  DBGC ( fcpdev, "FCP %p xchg %04x write data overrun (max %zd, "
454  "requested %zd)\n", fcpdev, fcpcmd->xchg_id,
455  command->data_out_len, ( fcpcmd->offset + len ) );
457  }
458 
459  /* Allocate I/O buffer */
460  iobuf = xfer_alloc_iob ( &fcpcmd->xchg, len );
461  if ( ! iobuf ) {
462  DBGC ( fcpdev, "FCP %p xchg %04x cannot allocate write data "
463  "IU for %zd bytes\n", fcpdev, fcpcmd->xchg_id, len );
464  return -ENOMEM;
465  }
466 
467  /* Construct data IU frame */
468  copy_from_user ( iob_put ( iobuf, len ), command->data_out,
469  fcpcmd->offset, len );
470  memset ( &meta, 0, sizeof ( meta ) );
472  meta.offset = fcpcmd->offset;
473  DBGC2 ( fcpdev, "FCP %p xchg %04x WRDATA [%08zx,%04zx)\n",
474  fcpdev, fcpcmd->xchg_id, fcpcmd->offset,
475  ( fcpcmd->offset + iob_len ( iobuf ) ) );
476 
477  /* Calculate amount of data remaining to be sent within this IU */
478  assert ( len <= fcpcmd->remaining );
479  fcpcmd->offset += len;
480  fcpcmd->remaining -= len;
481  assert ( fcpcmd->offset <= command->data_out_len );
482  if ( fcpcmd->remaining == 0 ) {
483  fcpcmd_stop_send ( fcpcmd );
484  meta.flags |= XFER_FL_OVER;
485  }
486 
487  /* Send data IU frame */
488  if ( ( rc = xfer_deliver ( &fcpcmd->xchg, iob_disown ( iobuf ),
489  &meta ) ) != 0 ) {
490  DBGC ( fcpdev, "FCP %p xchg %04x cannot deliver write data "
491  "IU: %s\n", fcpdev, fcpcmd->xchg_id, strerror ( rc ) );
492  return rc;
493  }
494 
495  return 0;
496 }
497 
498 /**
499  * Handle FCP transfer ready IU
500  *
501  * @v fcpcmd FCP command
502  * @v iobuf I/O buffer
503  * @v meta Data transfer metadata
504  * @ret rc Return status code
505  */
506 static int fcpcmd_recv_xfer_rdy ( struct fcp_command *fcpcmd,
507  struct io_buffer *iobuf,
508  struct xfer_metadata *meta __unused ) {
509  struct fcp_device *fcpdev = fcpcmd->fcpdev;
510  struct fcp_xfer_rdy *xfer_rdy = iobuf->data;
511  int rc;
512 
513  /* Sanity checks */
514  if ( iob_len ( iobuf ) != sizeof ( *xfer_rdy ) ) {
515  DBGC ( fcpdev, "FCP %p xchg %04x received invalid transfer "
516  "ready IU:\n", fcpdev, fcpcmd->xchg_id );
517  DBGC_HDA ( fcpdev, 0, iobuf->data, iob_len ( iobuf ) );
518  rc = -EPROTO;
519  goto done;
520  }
521  if ( ntohl ( xfer_rdy->offset ) != fcpcmd->offset ) {
522  /* We do not advertise out-of-order delivery */
523  DBGC ( fcpdev, "FCP %p xchg %04x cannot support out-of-order "
524  "delivery (expected %zd, requested %d)\n",
525  fcpdev, fcpcmd->xchg_id, fcpcmd->offset,
526  ntohl ( xfer_rdy->offset ) );
527  rc = -EPROTO;
528  goto done;
529  }
530  DBGC2 ( fcpdev, "FCP %p xchg %04x XFER_RDY [%08x,%08x)\n",
531  fcpdev, fcpcmd->xchg_id, ntohl ( xfer_rdy->offset ),
532  ( ntohl ( xfer_rdy->offset ) + ntohl ( xfer_rdy->len ) ) );
533 
534  /* Start sending requested data */
535  fcpcmd->remaining = ntohl ( xfer_rdy->len );
537 
538  rc = 0;
539  done:
540  free_iob ( iobuf );
541  return rc;
542 }
543 
544 /**
545  * Handle FCP response IU
546  *
547  * @v fcpcmd FCP command
548  * @v iobuf I/O buffer
549  * @v meta Data transfer metadata
550  * @ret rc Return status code
551  */
552 static int fcpcmd_recv_rsp ( struct fcp_command *fcpcmd,
553  struct io_buffer *iobuf,
554  struct xfer_metadata *meta __unused ) {
555  struct fcp_device *fcpdev = fcpcmd->fcpdev;
556  struct scsi_cmd *command = &fcpcmd->command;
557  struct fcp_rsp *rsp = iobuf->data;
558  struct scsi_rsp response;
559  int rc;
560 
561  /* Sanity check */
562  if ( ( iob_len ( iobuf ) < sizeof ( *rsp ) ) ||
563  ( iob_len ( iobuf ) < ( sizeof ( *rsp ) +
565  fcp_rsp_sense_data_len ( rsp ) ) ) ) {
566  DBGC ( fcpdev, "FCP %p xchg %04x received invalid response "
567  "IU:\n", fcpdev, fcpcmd->xchg_id );
568  DBGC_HDA ( fcpdev, 0, iobuf->data, iob_len ( iobuf ) );
569  rc = -EPROTO;
570  goto done;
571  }
572  DBGC2 ( fcpdev, "FCP %p xchg %04x RSP stat %02x resid %08x flags %02x"
573  "%s%s%s%s\n", fcpdev, fcpcmd->xchg_id, rsp->status,
574  ntohl ( rsp->residual ), rsp->flags,
575  ( ( rsp->flags & FCP_RSP_RESPONSE_LEN_VALID ) ? " resp" : "" ),
576  ( ( rsp->flags & FCP_RSP_SENSE_LEN_VALID ) ? " sense" : "" ),
577  ( ( rsp->flags & FCP_RSP_RESIDUAL_OVERRUN ) ? " over" : "" ),
578  ( ( rsp->flags & FCP_RSP_RESIDUAL_UNDERRUN ) ? " under" : "" ));
579  if ( fcp_rsp_response_data ( rsp ) ) {
580  DBGC2 ( fcpdev, "FCP %p xchg %04x response data:\n",
581  fcpdev, fcpcmd->xchg_id );
582  DBGC2_HDA ( fcpdev, 0, fcp_rsp_response_data ( rsp ),
584  }
585  if ( fcp_rsp_sense_data ( rsp ) ) {
586  DBGC2 ( fcpdev, "FCP %p xchg %04x sense data:\n",
587  fcpdev, fcpcmd->xchg_id );
588  DBGC2_HDA ( fcpdev, 0, fcp_rsp_sense_data ( rsp ),
590  }
591 
592  /* Check for locally-detected command underrun */
593  if ( ( rsp->status == 0 ) &&
594  ( fcpcmd->offset != ( command->data_in_len +
595  command->data_out_len ) ) ) {
596  DBGC ( fcpdev, "FCP %p xchg %04x data underrun (expected %zd, "
597  "got %zd)\n", fcpdev, fcpcmd->xchg_id,
598  ( command->data_in_len + command->data_out_len ),
599  fcpcmd->offset );
601  goto done;
602  }
603 
604  /* Build SCSI response */
605  memset ( &response, 0, sizeof ( response ) );
606  response.status = rsp->status;
607  if ( rsp->flags & ( FCP_RSP_RESIDUAL_OVERRUN |
609  response.overrun = ntohl ( rsp->residual );
610  if ( rsp->flags & FCP_RSP_RESIDUAL_UNDERRUN )
611  response.overrun = -response.overrun;
612  }
614  fcp_rsp_sense_data_len ( rsp ), &response.sense );
615 
616  /* Free buffer before sending response, to minimise
617  * out-of-memory errors.
618  */
619  free_iob ( iob_disown ( iobuf ) );
620 
621  /* Send SCSI response */
622  scsi_response ( &fcpcmd->scsi, &response );
623 
624  /* Terminate command */
625  fcpcmd_close ( fcpcmd, 0 );
626 
627  rc = 0;
628  done:
629  free_iob ( iobuf );
630  return rc;
631 }
632 
633 /**
634  * Handle unknown FCP IU
635  *
636  * @v fcpcmd FCP command
637  * @v iobuf I/O buffer
638  * @v meta Data transfer metadata
639  * @ret rc Return status code
640  */
641 static int fcpcmd_recv_unknown ( struct fcp_command *fcpcmd,
642  struct io_buffer *iobuf,
643  struct xfer_metadata *meta __unused ) {
644  struct fcp_device *fcpdev = fcpcmd->fcpdev;
645 
646  DBGC ( fcpdev, "FCP %p xchg %04x received unknown IU:\n",
647  fcpdev, fcpcmd->xchg_id );
648  DBGC_HDA ( fcpdev, 0, iobuf->data, iob_len ( iobuf ) );
649  free_iob ( iobuf );
650  return -EPROTO;
651 }
652 
653 /**
654  * Transmit FCP frame
655  *
656  * @v fcpcmd FCP command
657  */
658 static void fcpcmd_step ( struct fcp_command *fcpcmd ) {
659  int rc;
660 
661  /* Send the current IU */
662  if ( ( rc = fcpcmd->send ( fcpcmd ) ) != 0 ) {
663  /* Treat failure as a fatal error */
664  fcpcmd_close ( fcpcmd, rc );
665  }
666 }
667 
668 /**
669  * Receive FCP frame
670  *
671  * @v fcpcmd FCP command
672  * @v iobuf I/O buffer
673  * @v meta Data transfer metadata
674  * @ret rc Return status code
675  */
676 static int fcpcmd_deliver ( struct fcp_command *fcpcmd,
677  struct io_buffer *iobuf,
678  struct xfer_metadata *meta ) {
679  int ( * fcpcmd_recv ) ( struct fcp_command *fcpcmd,
680  struct io_buffer *iobuf,
681  struct xfer_metadata *meta );
682  int rc;
683 
684  /* Determine handler */
685  switch ( meta->flags & ( XFER_FL_CMD_STAT | XFER_FL_RESPONSE ) ) {
686  case ( XFER_FL_RESPONSE ) :
687  fcpcmd_recv = fcpcmd_recv_rddata;
688  break;
689  case ( XFER_FL_CMD_STAT ) :
690  fcpcmd_recv = fcpcmd_recv_xfer_rdy;
691  break;
693  fcpcmd_recv = fcpcmd_recv_rsp;
694  break;
695  default:
696  fcpcmd_recv = fcpcmd_recv_unknown;
697  break;
698  }
699 
700  /* Handle IU */
701  if ( ( rc = fcpcmd_recv ( fcpcmd, iob_disown ( iobuf ), meta ) ) != 0 ){
702  /* Treat any error as fatal to the command */
703  fcpcmd_close ( fcpcmd, rc );
704  }
705 
706  return rc;
707 }
708 
709 /** FCP command SCSI interface operations */
712 };
713 
714 /** FCP command SCSI interface descriptor */
716  INTF_DESC_PASSTHRU ( struct fcp_command, scsi, fcpcmd_scsi_op, xchg );
717 
718 /** FCP command Fibre Channel exchange interface operations */
722 };
723 
724 /** FCP command Fibre Channel exchange interface descriptor */
726  INTF_DESC_PASSTHRU ( struct fcp_command, xchg, fcpcmd_xchg_op, scsi );
727 
728 /** FCP command process descriptor */
731 
732 /**
733  * Issue FCP SCSI command
734  *
735  * @v fcpdev FCP device
736  * @v parent Parent interface
737  * @v command SCSI command
738  * @ret tag Command tag, or negative error
739  */
740 static int fcpdev_scsi_command ( struct fcp_device *fcpdev,
741  struct interface *parent,
742  struct scsi_cmd *command ) {
743  struct fcp_prli_service_parameters *param = fcpdev->user.ulp->param;
744  struct fcp_command *fcpcmd;
745  int xchg_id;
746  int rc;
747 
748  /* Check link */
749  if ( ( rc = fcpdev->user.ulp->link.rc ) != 0 ) {
750  DBGC ( fcpdev, "FCP %p could not issue command while link is "
751  "down: %s\n", fcpdev, strerror ( rc ) );
752  goto err_link;
753  }
754 
755  /* Check target capability */
756  assert ( param != NULL );
757  assert ( fcpdev->user.ulp->param_len >= sizeof ( *param ) );
758  if ( ! ( param->flags & htonl ( FCP_PRLI_TARGET ) ) ) {
759  DBGC ( fcpdev, "FCP %p could not issue command: not a target\n",
760  fcpdev );
761  rc = -ENOTTY;
762  goto err_target;
763  }
764 
765  /* Allocate and initialise structure */
766  fcpcmd = zalloc ( sizeof ( *fcpcmd ) );
767  if ( ! fcpcmd ) {
768  rc = -ENOMEM;
769  goto err_zalloc;
770  }
771  ref_init ( &fcpcmd->refcnt, fcpcmd_free );
772  intf_init ( &fcpcmd->scsi, &fcpcmd_scsi_desc, &fcpcmd->refcnt );
773  intf_init ( &fcpcmd->xchg, &fcpcmd_xchg_desc, &fcpcmd->refcnt );
775  &fcpcmd->refcnt );
776  fcpcmd->fcpdev = fcpdev_get ( fcpdev );
777  list_add ( &fcpcmd->list, &fcpdev->fcpcmds );
778  memcpy ( &fcpcmd->command, command, sizeof ( fcpcmd->command ) );
779 
780  /* Create new exchange */
781  if ( ( xchg_id = fc_xchg_originate ( &fcpcmd->xchg,
782  fcpdev->user.ulp->peer->port,
783  &fcpdev->user.ulp->peer->port_id,
784  FC_TYPE_FCP ) ) < 0 ) {
785  rc = xchg_id;
786  DBGC ( fcpdev, "FCP %p could not create exchange: %s\n",
787  fcpdev, strerror ( rc ) );
788  goto err_xchg_originate;
789  }
790  fcpcmd->xchg_id = xchg_id;
791 
792  /* Start sending command IU */
794 
795  /* Attach to parent interface, mortalise self, and return */
796  intf_plug_plug ( &fcpcmd->scsi, parent );
797  ref_put ( &fcpcmd->refcnt );
798  return ( FCP_TAG_MAGIC | fcpcmd->xchg_id );
799 
800  err_xchg_originate:
801  fcpcmd_close ( fcpcmd, rc );
802  ref_put ( &fcpcmd->refcnt );
803  err_zalloc:
804  err_target:
805  err_link:
806  return rc;
807 }
808 
809 /**
810  * Close FCP device
811  *
812  * @v fcpdev FCP device
813  * @v rc Reason for close
814  */
815 static void fcpdev_close ( struct fcp_device *fcpdev, int rc ) {
816  struct fcp_command *fcpcmd;
817  struct fcp_command *tmp;
818 
819  DBGC ( fcpdev, "FCP %p closed: %s\n", fcpdev, strerror ( rc ) );
820 
821  /* Shut down interfaces */
822  intf_shutdown ( &fcpdev->scsi, rc );
823 
824  /* Shut down any active commands */
826  fcpcmd_get ( fcpcmd );
827  fcpcmd_close ( fcpcmd, rc );
828  fcpcmd_put ( fcpcmd );
829  }
830 
831  /* Drop reference to ULP */
832  fc_ulp_detach ( &fcpdev->user );
833 }
834 
835 /**
836  * Check FCP device flow-control window
837  *
838  * @v fcpdev FCP device
839  * @ret len Length of window
840  */
841 static size_t fcpdev_window ( struct fcp_device *fcpdev ) {
842  return ( fc_link_ok ( &fcpdev->user.ulp->link ) ?
843  ~( ( size_t ) 0 ) : 0 );
844 }
845 
846 /**
847  * Describe FCP device using EDD
848  *
849  * @v fcpdev FCP device
850  * @v type EDD interface type
851  * @v path EDD device path
852  * @ret rc Return status code
853  */
854 static int fcpdev_edd_describe ( struct fcp_device *fcpdev,
855  struct edd_interface_type *type,
856  union edd_device_path *path ) {
857  union {
858  struct fc_name fc;
859  uint64_t u64;
860  } wwn;
861  union {
862  struct scsi_lun scsi;
863  uint64_t u64;
864  } lun;
865 
867  memcpy ( &wwn.fc, &fcpdev->wwn, sizeof ( wwn.fc ) );
868  path->fibre.wwn = be64_to_cpu ( wwn.u64 );
869  memcpy ( &lun.scsi, &fcpdev->lun, sizeof ( lun.scsi ) );
870  path->fibre.lun = be64_to_cpu ( lun.u64 );
871  return 0;
872 }
873 
874 /**
875  * Identify device underlying FCP device
876  *
877  * @v fcpdev FCP device
878  * @ret device Underlying device
879  */
880 static struct device * fcpdev_identify_device ( struct fcp_device *fcpdev ) {
881 
882  /* We know the underlying device only if the link is up;
883  * otherwise we don't have a port to examine.
884  */
885  if ( ! fc_link_ok ( &fcpdev->user.ulp->link ) ) {
886  DBGC ( fcpdev, "FCP %p doesn't know underlying device "
887  "until link is up\n", fcpdev );
888  return NULL;
889  }
890 
891  /* Hand off to port's transport interface */
892  assert ( fcpdev->user.ulp->peer->port != NULL );
893  return identify_device ( &fcpdev->user.ulp->peer->port->transport );
894 }
895 
896 /** FCP device SCSI interface operations */
900  INTF_OP ( intf_close, struct fcp_device *, fcpdev_close ),
902  INTF_OP ( identify_device, struct fcp_device *,
904 };
905 
906 /** FCP device SCSI interface descriptor */
908  INTF_DESC ( struct fcp_device, scsi, fcpdev_scsi_op );
909 
910 /**
911  * Examine FCP ULP link state
912  *
913  * @v user Fibre Channel upper-layer protocol user
914  */
915 static void fcpdev_examine ( struct fc_ulp_user *user ) {
916  struct fcp_device *fcpdev =
917  container_of ( user, struct fcp_device, user );
918 
919  if ( fc_link_ok ( &fcpdev->user.ulp->link ) ) {
920  DBGC ( fcpdev, "FCP %p link is up\n", fcpdev );
921  } else {
922  DBGC ( fcpdev, "FCP %p link is down: %s\n",
923  fcpdev, strerror ( fcpdev->user.ulp->link.rc ) );
924  }
925 
926  /* Notify SCSI layer of window change */
927  xfer_window_changed ( &fcpdev->scsi );
928 }
929 
930 /**
931  * Open FCP device
932  *
933  * @v parent Parent interface
934  * @v wwn Fibre Channel WWN
935  * @v lun SCSI LUN
936  * @ret rc Return status code
937  */
938 static int fcpdev_open ( struct interface *parent, struct fc_name *wwn,
939  struct scsi_lun *lun ) {
940  struct fc_ulp *ulp;
941  struct fcp_device *fcpdev;
942  int rc;
943 
944  /* Get Fibre Channel ULP interface */
946  if ( ! ulp ) {
947  rc = -ENOMEM;
948  goto err_ulp_get;
949  }
950 
951  /* Allocate and initialise structure */
952  fcpdev = zalloc ( sizeof ( *fcpdev ) );
953  if ( ! fcpdev ) {
954  rc = -ENOMEM;
955  goto err_zalloc;
956  }
957  ref_init ( &fcpdev->refcnt, NULL );
958  intf_init ( &fcpdev->scsi, &fcpdev_scsi_desc, &fcpdev->refcnt );
959  INIT_LIST_HEAD ( &fcpdev->fcpcmds );
960  fc_ulp_user_init ( &fcpdev->user, fcpdev_examine, &fcpdev->refcnt );
961 
962  DBGC ( fcpdev, "FCP %p opened for %s\n", fcpdev, fc_ntoa ( wwn ) );
963 
964  /* Attach to Fibre Channel ULP */
965  fc_ulp_attach ( ulp, &fcpdev->user );
966 
967  /* Preserve parameters required for boot firmware table */
968  memcpy ( &fcpdev->wwn, wwn, sizeof ( fcpdev->wwn ) );
969  memcpy ( &fcpdev->lun, lun, sizeof ( fcpdev->lun ) );
970 
971  /* Attach SCSI device to parent interface */
972  if ( ( rc = scsi_open ( parent, &fcpdev->scsi, lun ) ) != 0 ) {
973  DBGC ( fcpdev, "FCP %p could not create SCSI device: %s\n",
974  fcpdev, strerror ( rc ) );
975  goto err_scsi_open;
976  }
977 
978  /* Drop temporary reference to ULP */
979  fc_ulp_put ( ulp );
980 
981  /* Mortalise self and return */
982  ref_put ( &fcpdev->refcnt );
983  return 0;
984 
985  err_scsi_open:
986  fcpdev_close ( fcpdev, rc );
987  ref_put ( &fcpdev->refcnt );
988  err_zalloc:
989  fc_ulp_put ( ulp );
990  err_ulp_get:
991  return rc;
992 }
993 
994 /******************************************************************************
995  *
996  * FCP URIs
997  *
998  ******************************************************************************
999  */
1000 
1001 /**
1002  * Parse FCP URI
1003  *
1004  * @v uri URI
1005  * @ret wwn Fibre Channel WWN
1006  * @ret lun SCSI LUN
1007  * @ret rc Return status code
1008  *
1009  * An FCP URI has the form "fcp:<wwn>:<lun>" or "fcp://<wwn>/<lun>"
1010  */
1011 static int fcp_parse_uri ( struct uri *uri, struct fc_name *wwn,
1012  struct scsi_lun *lun ) {
1013  char wwn_buf[ FC_NAME_STRLEN + 1 /* NUL */ ];
1014  const char *wwn_text;
1015  const char *lun_text;
1016  int rc;
1017 
1018  /* Extract WWN and LUN texts from URI */
1019  if ( uri->opaque ) {
1020  /* "fcp:<wwn>:<lun>" */
1021  if ( snprintf ( wwn_buf, sizeof ( wwn_buf ), "%s",
1022  uri->opaque ) < ( FC_NAME_STRLEN + 1 /* : */ ) )
1023  return -EINVAL;
1024  if ( uri->opaque[FC_NAME_STRLEN] != ':' )
1025  return -EINVAL;
1026  wwn_text = wwn_buf;
1027  lun_text = &uri->opaque[FC_NAME_STRLEN + 1];
1028  } else {
1029  /* If host exists, path must also exist */
1030  if ( ! ( uri->host && uri->path ) )
1031  return -EINVAL;
1032  if ( uri->path[0] != '/' )
1033  return -EINVAL;
1034  wwn_text = uri->host;
1035  lun_text = ( uri->path + 1 );
1036  }
1037 
1038  /* Parse WWN */
1039  if ( ( rc = fc_aton ( wwn_text, wwn ) ) != 0 )
1040  return rc;
1041 
1042  /* Parse LUN */
1043  if ( ( rc = scsi_parse_lun ( lun_text, lun ) ) != 0 )
1044  return rc;
1045 
1046  return 0;
1047 }
1048 
1049 /**
1050  * Open FCP URI
1051  *
1052  * @v parent Parent interface
1053  * @v uri URI
1054  * @ret rc Return status code
1055  */
1056 static int fcp_open ( struct interface *parent, struct uri *uri ) {
1057  struct fc_name wwn;
1058  struct scsi_lun lun;
1059  int rc;
1060 
1061  /* Parse URI */
1062  if ( ( rc = fcp_parse_uri ( uri, &wwn, &lun ) ) != 0 )
1063  return rc;
1064 
1065  /* Open FCP device */
1066  if ( ( rc = fcpdev_open ( parent, &wwn, &lun ) ) != 0 )
1067  return rc;
1068 
1069  return 0;
1070 }
1071 
1072 /** FCP URI opener */
1073 struct uri_opener fcp_uri_opener __uri_opener = {
1074  .scheme = "fcp",
1075  .open = fcp_open,
1076 };
void scsi_parse_sense(const void *data, size_t len, struct scsi_sns_descriptor *sense)
Parse SCSI sense data.
Definition: scsi.c:146
A process.
Definition: process.h:17
void fc_ulp_detach(struct fc_ulp_user *user)
Detach Fibre Channel upper-layer protocol user.
Definition: fc.c:1625
#define __attribute__(x)
Definition: compiler.h:10
static struct fcp_command * fcpcmd_get(struct fcp_command *fcpcmd)
Get reference to FCP command.
Definition: fcp.c:226
#define EINVAL
Invalid argument.
Definition: errno.h:428
An object interface operation.
Definition: interface.h:17
static struct interface_operation fcpdev_scsi_op[]
FCP device SCSI interface operations.
Definition: fcp.c:897
#define FCP_RSP_RESIDUAL_OVERRUN
Residual represents overrun.
Definition: fcp.h:80
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:145
static struct interface_descriptor fcpdev_scsi_desc
FCP device SCSI interface descriptor.
Definition: fcp.c:907
unsigned short uint16_t
Definition: stdint.h:11
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:244
#define iob_put(iobuf, len)
Definition: iobuf.h:116
Data transfer metadata.
Definition: xfer.h:22
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:273
An FCP transfer ready IU.
Definition: fcp.h:46
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
#define ERANGE_WRITE_DATA_OVERRUN
Definition: fcp.c:69
#define EDD_INTF_TYPE_FIBRE
EDD Fibre Channel interface type.
Definition: edd.h:65
int fc_aton(const char *wwn_text, struct fc_name *wwn)
Parse Fibre Channel WWN.
Definition: fc.c:144
#define ERANGE_WRITE_DATA_STUCK
Definition: fcp.c:65
static int fcpcmd_deliver(struct fcp_command *fcpcmd, struct io_buffer *iobuf, struct xfer_metadata *meta)
Receive FCP frame.
Definition: fcp.c:676
struct process process
Send process.
Definition: fcp.c:180
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
uint64_t wwn
WWN.
Definition: edd.h:131
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:47
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
Error codes.
static int fcpdev_open(struct interface *parent, struct fc_name *wwn, struct scsi_lun *lun)
Open FCP device.
Definition: fcp.c:938
An EDD device path.
Definition: edd.h:98
#define FCP_PRLI_NO_READ_RDY
Read FCP_XFER_RDY disabled.
Definition: fcp.h:140
A Fibre Channel extended link services handler.
Definition: fcels.h:352
A command-line command.
Definition: command.h:9
u16 fc
802.11 Frame Control field
Definition: ieee80211.h:14
I/O buffers.
Fibre Channel Protocol.
Definition: fc.h:193
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
static struct interface_operation fcpcmd_xchg_op[]
FCP command Fibre Channel exchange interface operations.
Definition: fcp.c:719
uint8_t type
Type.
Definition: ena.h:16
#define EPIPE
Broken pipe.
Definition: errno.h:619
union scsi_cdb cdb
SCSI CDB.
Definition: fcp.h:31
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
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
An FCP command IU.
Definition: fcp.h:19
#define DBGC(...)
Definition: compiler.h:505
static int fcp_parse_uri(struct uri *uri, struct fc_name *wwn, struct scsi_lun *lun)
Parse FCP URI.
Definition: fcp.c:1011
A process descriptor.
Definition: process.h:31
static int fcpcmd_send_cmnd(struct fcp_command *fcpcmd)
Send FCP command IU.
Definition: fcp.c:321
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:641
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
static void fcpcmd_close(struct fcp_command *fcpcmd, int rc)
Close FCP command.
Definition: fcp.c:287
unsigned long long uint64_t
Definition: stdint.h:13
static void fcpcmd_stop_send(struct fcp_command *fcpcmd)
Stop FCP command sending.
Definition: fcp.c:260
static struct process_descriptor fcpcmd_process_desc
FCP command process descriptor.
Definition: fcp.c:729
#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:157
#define cpu_to_le64(value)
Definition: byteswap.h:108
const char * fc_ntoa(const struct fc_name *wwn)
Format Fibre Channel WWN.
Definition: fc.c:127
uint32_t offset
Relative offset of data.
Definition: fcp.h:48
union scsi_cdb cdb
CDB for this command.
Definition: scsi.h:253
int scsi_open(struct interface *block, struct interface *scsi, struct scsi_lun *lun)
Open SCSI device.
Definition: scsi.c:980
struct refcnt refcnt
Reference count.
Definition: fcp.c:153
Uniform Resource Identifiers.
struct fc_peer * peer
Fibre Channel peer.
Definition: fc.h:417
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79
static int fcpcmd_send_wrdata(struct fcp_command *fcpcmd)
Send FCP write data IU.
Definition: fcp.c:433
#define htonl(value)
Definition: byteswap.h:133
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:115
An EDD interface type.
Definition: edd.h:40
struct fc_els_prli_descriptor fcp_prli_descriptor __fc_els_prli_descriptor
FCP PRLI descriptor.
Definition: fcp.c:85
#define FCP_RSP_RESIDUAL_UNDERRUN
Residual represents underrun.
Definition: fcp.h:83
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:552
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
A doubly-linked list entry (or list head)
Definition: list.h:18
Data transfer interfaces.
static void fcpcmd_free(struct refcnt *refcnt)
Free FCP command.
Definition: fcp.c:269
A reference counter.
Definition: refcnt.h:26
struct fc_port * port
Fibre Channel port, if known.
Definition: fc.h:354
#define XFER_FL_RESPONSE
Data content is a response.
Definition: xfer.h:63
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
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
int fc_els_prli_tx(struct fc_els *els, struct fc_els_prli_descriptor *descriptor, void *param)
Transmit PRLI.
Definition: fcels.c:950
#define ENOMEM
Not enough space.
Definition: errno.h:534
A hardware device.
Definition: device.h:73
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:208
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void * memcpy(void *dest, const void *src, size_t len) __nonnull
const char * name
Name.
Definition: fcels.h:354
static int fcpdev_scsi_command(struct fcp_device *fcpdev, struct interface *parent, struct scsi_cmd *command)
Issue FCP SCSI command.
Definition: fcp.c:740
Assertions.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
A SCSI command.
Definition: scsi.c:262
Fibre Channel Protocol.
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static int fcp_prli_rx(struct fc_els *els, void *data, size_t len)
Receive FCP PRLI.
Definition: fcp.c:111
An object interface.
Definition: interface.h:109
void fc_ulp_attach(struct fc_ulp *ulp, struct fc_ulp_user *user)
Attach Fibre Channel upper-layer protocol user.
Definition: fc.c:1607
int scsi_parse_lun(const char *lun_string, struct scsi_lun *lun)
Parse SCSI LUN.
Definition: scsi.c:117
struct ntlm_data user
User name.
Definition: ntlm.h:20
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
static struct interface_descriptor fcpcmd_xchg_desc
FCP command Fibre Channel exchange interface descriptor.
Definition: fcp.c:725
size_t param_len
Service parameter length.
Definition: fc.h:433
#define DBGC_HDA(...)
Definition: compiler.h:506
Object interfaces.
static void fcpdev_put(struct fcp_device *fcpdev)
Drop reference to FCP device.
Definition: fcp.c:215
static int fc_link_ok(struct fc_link_state *link)
Check Fibre Channel link state.
Definition: fc.h:108
#define FCP_CMND_RDDATA
Command includes data-in.
Definition: fcp.h:40
const char * path
Path.
Definition: uri.h:66
static void fcpcmd_start_send(struct fcp_command *fcpcmd, int(*send)(struct fcp_command *fcpcmd))
Start FCP command sending.
Definition: fcp.c:248
static void * fcp_rsp_response_data(struct fcp_rsp *rsp)
Get response data portion of FCP response.
Definition: fcp.h:91
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
const char * scheme
URI protocol name.
Definition: open.h:53
uint64_t u64
Definition: stdint.h:25
struct interface scsi
SCSI command interface.
Definition: fcp.c:176
struct interface scsi
SCSI command issuing interface.
Definition: fcp.c:157
struct scsi_lun lun
SCSI LUN.
Definition: fcp.h:21
static struct fcp_device * fcpdev_get(struct fcp_device *fcpdev)
Get reference to FCP device.
Definition: fcp.c:204
uint8_t lun
Logical Unit Number.
Definition: edd.h:32
#define FCP_TAG_MAGIC
FCP tag magic marker.
Definition: fcp.h:43
#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:447
#define EPROTO
Protocol error.
Definition: errno.h:624
static struct interface_operation fcpcmd_scsi_op[]
FCP command SCSI interface operations.
Definition: fcp.c:710
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:383
static int fcp_open(struct interface *parent, struct uri *uri)
Open FCP URI.
Definition: fcp.c:1056
void process_add(struct process *process)
Add process to process list.
Definition: process.c:59
int meta(WINDOW *, bool)
Linked lists.
#define DBGC2_HDA(...)
Definition: compiler.h:523
uint64_t rsp
Definition: librm.h:267
An object interface descriptor.
Definition: interface.h:40
A Fibre Channel extended link services transaction.
Definition: fcels.h:323
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
#define FCP_PRLI_INITIATOR
Has initiator functionality.
Definition: fcp.h:146
ACPI data structures.
#define be64_to_cpu(value)
Definition: byteswap.h:117
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
void * param
Service parameters, if any.
Definition: fc.h:431
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
struct hv_monitor_parameter param[4][32]
Parameters.
Definition: hyperv.h:24
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
uint8_t status
SCSI status code.
Definition: scsi.h:324
uint8_t * tmp
Definition: entropy.h:156
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
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 fc_link_state link
Link state monitor.
Definition: fc.h:427
struct scsi_cmd command
SCSI command.
Definition: fcp.c:188
#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:193
Processes.
struct fc_name wwn
Fibre Channel WWN (for boot firmware table)
Definition: fcp.c:162
#define SCSI_CDB_DATA(cdb)
printf() parameters for dumping a scsi_cdb
Definition: scsi.h:223
Data transfer interface opening.
struct interface xchg
Fibre Channel exchange interface.
Definition: fcp.c:178
uint16_t xchg_id
Exchange ID.
Definition: fcp.c:194
A Fibre Channel upper-layer protocol user.
Definition: fc.h:453
static size_t fcpdev_window(struct fcp_device *fcpdev)
Check FCP device flow-control window.
Definition: fcp.c:841
#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
#define ERANGE_READ_DATA_OVERRUN
Definition: fcp.c:61
uint8_t lun
Logical Unit Number.
Definition: edd.h:109
Fibre Channel.
#define FCP_RSP_RESPONSE_LEN_VALID
Response length field is valid.
Definition: fcp.h:74
const char * host
Host name.
Definition: uri.h:62
struct list_head list
List of active commands.
Definition: fcp.c:174
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:506
size_t offset
Data offset within command.
Definition: fcp.c:190
static void fcpcmd_step(struct fcp_command *fcpcmd)
Transmit FCP frame.
Definition: fcp.c:658
struct scsi_lun lun
SCSI LUN (for boot firmware table)
Definition: fcp.c:164
A Fibre Channel name.
Definition: fc.h:29
static int fcp_prli_detect(struct fc_els *els, const void *data, size_t len)
Detect FCP PRLI.
Definition: fcp.c:123
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
void scsi_response(struct interface *intf, struct scsi_rsp *response)
Report SCSI response.
Definition: scsi.c:206
SCSI devices.
A SCSI command information unit.
Definition: scsi.h:249
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:65
static int fcp_prli_tx(struct fc_els *els)
Transmit FCP PRLI.
Definition: fcp.c:93
static struct interface_descriptor fcpcmd_scsi_desc
FCP command SCSI interface descriptor.
Definition: fcp.c:715
#define SCSI_CDB_FORMAT
printf() format for dumping a scsi_cdb
Definition: scsi.h:219
static struct device * fcpdev_identify_device(struct fcp_device *fcpdev)
Identify device underlying FCP device.
Definition: fcp.c:880
uint32_t len
Length.
Definition: ena.h:14
An FCP PRLI service parameter page.
Definition: fcp.h:131
const char * opaque
Opaque part.
Definition: uri.h:56
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
struct refcnt refcnt
Reference count.
Definition: fcp.c:170
struct scsi_sns_descriptor sense
Autosense data (if any)
Definition: scsi.h:333
size_t remaining
Length of data remaining to be sent within this IU.
Definition: fcp.c:192
void * data
Start of data.
Definition: iobuf.h:44
#define PROC_DESC(object_type, process, _step)
Define a process descriptor.
Definition: process.h:82
struct interface transport
Transport interface.
Definition: fc.h:261
#define ERANGE_DATA_UNDERRUN
Definition: fcp.c:73
static void fc_ulp_put(struct fc_ulp *ulp)
Drop reference to Fibre Channel upper-layer protocol.
Definition: fc.h:485
Reference counting.
static void fcpcmd_put(struct fcp_command *fcpcmd)
Drop reference to FCP command.
Definition: fcp.c:237
uint32_t len
Data length.
Definition: fcp.h:33
Device model.
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:50
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition: interface.h:82
A SCSI LUN.
Definition: scsi.h:236
Enhanced Disk Drive specification.
#define XFER_FL_OVER
Sender is relinquishing use of half-duplex channel.
Definition: xfer.h:50
struct device * identify_device(struct interface *intf)
Identify a device behind an interface.
Definition: device.c:125
static void fcpdev_examine(struct fc_ulp_user *user)
Examine FCP ULP link state.
Definition: fcp.c:915
#define FCP_RSP_SENSE_LEN_VALID
Sense length field is valid.
Definition: fcp.h:77
struct list_head fcpcmds
List of active commands.
Definition: fcp.c:159
struct fc_ulp_user user
Fibre Channel upper-layer protocol user.
Definition: fcp.c:155
An FCP response IU.
Definition: fcp.h:56
int(* send)(struct fcp_command *fcpcmd)
Send current IU.
Definition: fcp.c:186
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
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
struct fc_els_handler fcp_prli_handler __fc_els_handler
FCP PRLI ELS handler.
Definition: fcp.c:129
uint32_t len
Burst length.
Definition: fcp.h:50
#define FCP_CMND_WRDATA
Command includes data-out.
Definition: fcp.h:37
unsigned int type
Upper-layer protocol type.
Definition: fcels.h:388
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
A URI opener.
Definition: open.h:47
#define FC_NAME_STRLEN
Length of Fibre Channel name text.
Definition: fc.h:34
A Fibre Channel ELS PRLI descriptor.
Definition: fcels.h:386
An FCP command.
Definition: fcp.c:168
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
struct uri_opener fcp_uri_opener __uri_opener
FCP URI opener.
Definition: fcp.c:1073
static void fcpcmd_close_err(struct fcp_command *fcpcmd, int rc)
Close FCP command in error.
Definition: fcp.c:309
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
String functions.
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
uint8_t dirn
Direction.
Definition: fcp.h:29
struct bofm_section_header done
Definition: bofm_test.c:46
ssize_t overrun
Data overrun (or negative underrun)
Definition: scsi.h:326
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:854
struct fcp_device * fcpdev
FCP SCSI device.
Definition: fcp.c:172
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
A Fibre Channel upper-layer protocol.
Definition: fc.h:413
#define ERANGE_READ_DATA_ORDERING
Definition: fcp.c:57
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
Fibre Channel Extended Link Services.
void * memset(void *dest, int character, size_t len) __nonnull
uint64_t wwn
WWN.
Definition: edd.h:30
An FCP device.
Definition: fcp.c:151
A persistent I/O buffer.
Definition: iobuf.h:32
struct arbelprm_send_doorbell send
Definition: arbel.h:11
static void fcpdev_close(struct fcp_device *fcpdev, int rc)
Close FCP device.
Definition: fcp.c:815