1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2016, Avago Technologies
6 #ifndef _NVME_FC_DRIVER_H
7 #define _NVME_FC_DRIVER_H 1
9 #include <linux/scatterlist.h>
10 #include <linux/blk-mq.h>
14 * ********************** FC-NVME LS API ********************
16 * Data structures used by both FC-NVME hosts and FC-NVME
17 * targets to perform FC-NVME LS requests or transmit
20 * ***********************************************************
24 * struct nvmefc_ls_req - Request structure passed from the transport
25 * to the LLDD to perform a NVME-FC LS request and obtain
27 * Used by nvme-fc transport (host) to send LS's such as
28 * Create Association, Create Connection and Disconnect
30 * Used by the nvmet-fc transport (controller) to send
31 * LS's such as Disconnect Association.
33 * Values set by the requestor prior to calling the LLDD ls_req entrypoint:
34 * @rqstaddr: pointer to request buffer
35 * @rqstdma: PCI DMA address of request buffer
36 * @rqstlen: Length, in bytes, of request buffer
37 * @rspaddr: pointer to response buffer
38 * @rspdma: PCI DMA address of response buffer
39 * @rsplen: Length, in bytes, of response buffer
40 * @timeout: Maximum amount of time, in seconds, to wait for the LS response.
41 * If timeout exceeded, LLDD to abort LS exchange and complete
42 * LS request with error status.
43 * @private: pointer to memory allocated alongside the ls request structure
44 * that is specifically for the LLDD to use while processing the
45 * request. The length of the buffer corresponds to the
46 * lsrqst_priv_sz value specified in the xxx_template supplied
48 * @done: The callback routine the LLDD is to invoke upon completion of
49 * the LS request. req argument is the pointer to the original LS
50 * request structure. Status argument must be 0 upon success, a
51 * negative errno on failure (example: -ENXIO).
53 struct nvmefc_ls_req {
64 void (*done)(struct nvmefc_ls_req *req, int status);
66 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
70 * struct nvmefc_ls_rsp - Structure passed from the transport to the LLDD
71 * to request the transmit the NVME-FC LS response to a
72 * NVME-FC LS request. The structure originates in the LLDD
73 * and is given to the transport via the xxx_rcv_ls_req()
74 * transport routine. As such, the structure represents the
75 * FC exchange context for the NVME-FC LS request that was
76 * received and which the response is to be sent for.
77 * Used by the LLDD to pass the nvmet-fc transport (controller)
78 * received LS's such as Create Association, Create Connection
79 * and Disconnect Association.
80 * Used by the LLDD to pass the nvme-fc transport (host)
81 * received LS's such as Disconnect Association or Disconnect
84 * The structure is allocated by the LLDD whenever a LS Request is received
85 * from the FC link. The address of the structure is passed to the nvmet-fc
86 * or nvme-fc layer via the xxx_rcv_ls_req() transport routines.
88 * The address of the structure is to be passed back to the LLDD
89 * when the response is to be transmit. The LLDD will use the address to
90 * map back to the LLDD exchange structure which maintains information such
91 * the remote N_Port that sent the LS as well as any FC exchange context.
92 * Upon completion of the LS response transmit, the LLDD will pass the
93 * address of the structure back to the transport LS rsp done() routine,
94 * allowing the transport release dma resources. Upon completion of
95 * the done() routine, no further access to the structure will be made by
96 * the transport and the LLDD can de-allocate the structure.
98 * Field initialization:
99 * At the time of the xxx_rcv_ls_req() call, there is no content that
100 * is valid in the structure.
102 * When the structure is used for the LLDD->xmt_ls_rsp() call, the
103 * transport layer will fully set the fields in order to specify the
104 * response payload buffer and its length as well as the done routine
105 * to be called upon completion of the transmit. The transport layer
106 * will also set a private pointer for its own use in the done routine.
108 * Values set by the transport layer prior to calling the LLDD xmt_ls_rsp
110 * @rspbuf: pointer to the LS response buffer
111 * @rspdma: PCI DMA address of the LS response buffer
112 * @rsplen: Length, in bytes, of the LS response buffer
113 * @done: The callback routine the LLDD is to invoke upon completion of
114 * transmitting the LS response. req argument is the pointer to
115 * the original ls request.
116 * @nvme_fc_private: pointer to an internal transport-specific structure
117 * used as part of the transport done() processing. The LLDD is
118 * not to access this pointer.
120 struct nvmefc_ls_rsp {
125 void (*done)(struct nvmefc_ls_rsp *rsp);
126 void *nvme_fc_private; /* LLDD is not to access !! */
132 * ********************** LLDD FC-NVME Host API ********************
134 * For FC LLDD's that are the NVME Host role.
136 * ******************************************************************
141 * struct nvme_fc_port_info - port-specific ids and FC connection-specific
142 * data element used during NVME Host role
145 * Static fields describing the port being registered:
146 * @node_name: FC WWNN for the port
147 * @port_name: FC WWPN for the port
148 * @port_role: What NVME roles are supported (see FC_PORT_ROLE_xxx)
149 * @dev_loss_tmo: maximum delay for reconnects to an association on
150 * this device. Used only on a remoteport.
152 * Initialization values for dynamic port fields:
153 * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must
156 struct nvme_fc_port_info {
164 enum nvmefc_fcp_datadir {
165 NVMEFC_FCP_NODATA, /* payload_length and sg_cnt will be zero */
172 * struct nvmefc_fcp_req - Request structure passed from NVME-FC transport
173 * to LLDD in order to perform a NVME FCP IO operation.
175 * Values set by the NVME-FC layer prior to calling the LLDD fcp_io
177 * @cmdaddr: pointer to the FCP CMD IU buffer
178 * @rspaddr: pointer to the FCP RSP IU buffer
179 * @cmddma: PCI DMA address of the FCP CMD IU buffer
180 * @rspdma: PCI DMA address of the FCP RSP IU buffer
181 * @cmdlen: Length, in bytes, of the FCP CMD IU buffer
182 * @rsplen: Length, in bytes, of the FCP RSP IU buffer
183 * @payload_length: Length of DATA_IN or DATA_OUT payload data to transfer
184 * @sg_table: scatter/gather structure for payload data
185 * @first_sgl: memory for 1st scatter/gather list segment for payload data
186 * @sg_cnt: number of elements in the scatter/gather list
187 * @io_dir: direction of the FCP request (see NVMEFC_FCP_xxx)
188 * @sqid: The nvme SQID the command is being issued on
189 * @done: The callback routine the LLDD is to invoke upon completion of
190 * the FCP operation. req argument is the pointer to the original
192 * @private: pointer to memory allocated alongside the FCP operation
193 * request structure that is specifically for the LLDD to use
194 * while processing the operation. The length of the buffer
195 * corresponds to the fcprqst_priv_sz value specified in the
196 * nvme_fc_port_template supplied by the LLDD.
198 * Values set by the LLDD indicating completion status of the FCP operation.
199 * Must be set prior to calling the done() callback.
200 * @transferred_length: amount of payload data, in bytes, that were
201 * transferred. Should equal payload_length on success.
202 * @rcv_rsplen: length, in bytes, of the FCP RSP IU received.
203 * @status: Completion status of the FCP operation. must be 0 upon success,
204 * negative errno value upon failure (ex: -EIO). Note: this is
205 * NOT a reflection of the NVME CQE completion status. Only the
206 * status of the FCP operation at the NVME-FC level.
208 struct nvmefc_fcp_req {
217 struct sg_table sg_table;
218 struct scatterlist *first_sgl;
220 enum nvmefc_fcp_datadir io_dir;
224 void (*done)(struct nvmefc_fcp_req *req);
228 u32 transferred_length;
231 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
235 * Direct copy of fc_port_state enum. For later merging
237 enum nvme_fc_obj_state {
239 FC_OBJSTATE_NOTPRESENT,
241 FC_OBJSTATE_OFFLINE, /* User has taken Port Offline */
243 FC_OBJSTATE_BYPASSED,
244 FC_OBJSTATE_DIAGNOSTICS,
245 FC_OBJSTATE_LINKDOWN,
247 FC_OBJSTATE_LOOPBACK,
253 * struct nvme_fc_local_port - structure used between NVME-FC transport and
254 * a LLDD to reference a local NVME host port.
255 * Allocated/created by the nvme_fc_register_localport()
256 * transport interface.
258 * Fields with static values for the port. Initialized by the
259 * port_info struct supplied to the registration call.
260 * @port_num: NVME-FC transport host port number
261 * @port_role: NVME roles are supported on the port (see FC_PORT_ROLE_xxx)
262 * @node_name: FC WWNN for the port
263 * @port_name: FC WWPN for the port
264 * @private: pointer to memory allocated alongside the local port
265 * structure that is specifically for the LLDD to use.
266 * The length of the buffer corresponds to the local_priv_sz
267 * value specified in the nvme_fc_port_template supplied by
269 * @dev_loss_tmo: maximum delay for reconnects to an association on
270 * this device. To modify, lldd must call
271 * nvme_fc_set_remoteport_devloss().
273 * Fields with dynamic values. Values may change base on link state. LLDD
274 * may reference fields directly to change them. Initialized by the
275 * port_info struct supplied to the registration call.
276 * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must
278 * @port_state: Operational state of the port.
280 struct nvme_fc_local_port {
281 /* static/read-only fields */
291 enum nvme_fc_obj_state port_state;
292 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
296 * struct nvme_fc_remote_port - structure used between NVME-FC transport and
297 * a LLDD to reference a remote NVME subsystem port.
298 * Allocated/created by the nvme_fc_register_remoteport()
299 * transport interface.
301 * Fields with static values for the port. Initialized by the
302 * port_info struct supplied to the registration call.
303 * @port_num: NVME-FC transport remote subsystem port number
304 * @port_role: NVME roles are supported on the port (see FC_PORT_ROLE_xxx)
305 * @node_name: FC WWNN for the port
306 * @port_name: FC WWPN for the port
307 * @localport: pointer to the NVME-FC local host port the subsystem is
309 * @private: pointer to memory allocated alongside the remote port
310 * structure that is specifically for the LLDD to use.
311 * The length of the buffer corresponds to the remote_priv_sz
312 * value specified in the nvme_fc_port_template supplied by
315 * Fields with dynamic values. Values may change base on link or login
316 * state. LLDD may reference fields directly to change them. Initialized by
317 * the port_info struct supplied to the registration call.
318 * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must
320 * @port_state: Operational state of the remote port. Valid values are
323 struct nvme_fc_remote_port {
329 struct nvme_fc_local_port *localport;
335 enum nvme_fc_obj_state port_state;
336 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
340 * struct nvme_fc_port_template - structure containing static entrypoints and
341 * operational parameters for an LLDD that supports NVME host
342 * behavior. Passed by reference in port registrations.
343 * NVME-FC transport remembers template reference and may
344 * access it during runtime operation.
346 * Host/Initiator Transport Entrypoints/Parameters:
348 * @localport_delete: The LLDD initiates deletion of a localport via
349 * nvme_fc_deregister_localport(). However, the teardown is
350 * asynchronous. This routine is called upon the completion of the
351 * teardown to inform the LLDD that the localport has been deleted.
352 * Entrypoint is Mandatory.
354 * @remoteport_delete: The LLDD initiates deletion of a remoteport via
355 * nvme_fc_deregister_remoteport(). However, the teardown is
356 * asynchronous. This routine is called upon the completion of the
357 * teardown to inform the LLDD that the remoteport has been deleted.
358 * Entrypoint is Mandatory.
360 * @create_queue: Upon creating a host<->controller association, queues are
361 * created such that they can be affinitized to cpus/cores. This
362 * callback into the LLDD to notify that a controller queue is being
363 * created. The LLDD may choose to allocate an associated hw queue
364 * or map it onto a shared hw queue. Upon return from the call, the
365 * LLDD specifies a handle that will be given back to it for any
366 * command that is posted to the controller queue. The handle can
367 * be used by the LLDD to map quickly to the proper hw queue for
368 * command execution. The mask of cpu's that will map to this queue
369 * at the block-level is also passed in. The LLDD should use the
370 * queue id and/or cpu masks to ensure proper affinitization of the
371 * controller queue to the hw queue.
372 * Entrypoint is Optional.
374 * @delete_queue: This is the inverse of the crete_queue. During
375 * host<->controller association teardown, this routine is called
376 * when a controller queue is being terminated. Any association with
377 * a hw queue should be termined. If there is a unique hw queue, the
378 * hw queue should be torn down.
379 * Entrypoint is Optional.
381 * @poll_queue: Called to poll for the completion of an io on a blk queue.
382 * Entrypoint is Optional.
384 * @ls_req: Called to issue a FC-NVME FC-4 LS service request.
385 * The nvme_fc_ls_req structure will fully describe the buffers for
386 * the request payload and where to place the response payload. The
387 * LLDD is to allocate an exchange, issue the LS request, obtain the
388 * LS response, and call the "done" routine specified in the request
389 * structure (argument to done is the ls request structure itself).
390 * Entrypoint is Mandatory.
392 * @fcp_io: called to issue a FC-NVME I/O request. The I/O may be for
393 * an admin queue or an i/o queue. The nvmefc_fcp_req structure will
394 * fully describe the io: the buffer containing the FC-NVME CMD IU
395 * (which contains the SQE), the sg list for the payload if applicable,
396 * and the buffer to place the FC-NVME RSP IU into. The LLDD will
397 * complete the i/o, indicating the amount of data transferred or
398 * any transport error, and call the "done" routine specified in the
399 * request structure (argument to done is the fcp request structure
401 * Entrypoint is Mandatory.
403 * @ls_abort: called to request the LLDD to abort the indicated ls request.
404 * The call may return before the abort has completed. After aborting
405 * the request, the LLDD must still call the ls request done routine
406 * indicating an FC transport Aborted status.
407 * Entrypoint is Mandatory.
409 * @fcp_abort: called to request the LLDD to abort the indicated fcp request.
410 * The call may return before the abort has completed. After aborting
411 * the request, the LLDD must still call the fcp request done routine
412 * indicating an FC transport Aborted status.
413 * Entrypoint is Mandatory.
415 * @xmt_ls_rsp: Called to transmit the response to a FC-NVME FC-4 LS service.
416 * The nvmefc_ls_rsp structure is the same LLDD-supplied exchange
417 * structure specified in the nvme_fc_rcv_ls_req() call made when
418 * the LS request was received. The structure will fully describe
419 * the buffers for the response payload and the dma address of the
420 * payload. The LLDD is to transmit the response (or return a
421 * non-zero errno status), and upon completion of the transmit, call
422 * the "done" routine specified in the nvmefc_ls_rsp structure
423 * (argument to done is the address of the nvmefc_ls_rsp structure
424 * itself). Upon the completion of the done routine, the LLDD shall
425 * consider the LS handling complete and the nvmefc_ls_rsp structure
426 * may be freed/released.
427 * Entrypoint is mandatory if the LLDD calls the nvme_fc_rcv_ls_req()
430 * @max_hw_queues: indicates the maximum number of hw queues the LLDD
431 * supports for cpu affinitization.
432 * Value is Mandatory. Must be at least 1.
434 * @max_sgl_segments: indicates the maximum number of sgl segments supported
436 * Value is Mandatory. Must be at least 1. Recommend at least 256.
438 * @max_dif_sgl_segments: indicates the maximum number of sgl segments
439 * supported by the LLDD for DIF operations.
440 * Value is Mandatory. Must be at least 1. Recommend at least 256.
442 * @dma_boundary: indicates the dma address boundary where dma mappings
443 * will be split across.
444 * Value is Mandatory. Typical value is 0xFFFFFFFF to split across
445 * 4Gig address boundarys
447 * @local_priv_sz: The LLDD sets this field to the amount of additional
448 * memory that it would like fc nvme layer to allocate on the LLDD's
449 * behalf whenever a localport is allocated. The additional memory
450 * area solely for the of the LLDD and its location is specified by
451 * the localport->private pointer.
452 * Value is Mandatory. Allowed to be zero.
454 * @remote_priv_sz: The LLDD sets this field to the amount of additional
455 * memory that it would like fc nvme layer to allocate on the LLDD's
456 * behalf whenever a remoteport is allocated. The additional memory
457 * area solely for the of the LLDD and its location is specified by
458 * the remoteport->private pointer.
459 * Value is Mandatory. Allowed to be zero.
461 * @lsrqst_priv_sz: The LLDD sets this field to the amount of additional
462 * memory that it would like fc nvme layer to allocate on the LLDD's
463 * behalf whenever a ls request structure is allocated. The additional
464 * memory area is solely for use by the LLDD and its location is
465 * specified by the ls_request->private pointer.
466 * Value is Mandatory. Allowed to be zero.
468 * @fcprqst_priv_sz: The LLDD sets this field to the amount of additional
469 * memory that it would like fc nvme layer to allocate on the LLDD's
470 * behalf whenever a fcp request structure is allocated. The additional
471 * memory area solely for the of the LLDD and its location is
472 * specified by the fcp_request->private pointer.
473 * Value is Mandatory. Allowed to be zero.
475 struct nvme_fc_port_template {
476 /* initiator-based functions */
477 void (*localport_delete)(struct nvme_fc_local_port *);
478 void (*remoteport_delete)(struct nvme_fc_remote_port *);
479 int (*create_queue)(struct nvme_fc_local_port *,
480 unsigned int qidx, u16 qsize,
482 void (*delete_queue)(struct nvme_fc_local_port *,
483 unsigned int qidx, void *handle);
484 int (*ls_req)(struct nvme_fc_local_port *,
485 struct nvme_fc_remote_port *,
486 struct nvmefc_ls_req *);
487 int (*fcp_io)(struct nvme_fc_local_port *,
488 struct nvme_fc_remote_port *,
489 void *hw_queue_handle,
490 struct nvmefc_fcp_req *);
491 void (*ls_abort)(struct nvme_fc_local_port *,
492 struct nvme_fc_remote_port *,
493 struct nvmefc_ls_req *);
494 void (*fcp_abort)(struct nvme_fc_local_port *,
495 struct nvme_fc_remote_port *,
496 void *hw_queue_handle,
497 struct nvmefc_fcp_req *);
498 int (*xmt_ls_rsp)(struct nvme_fc_local_port *localport,
499 struct nvme_fc_remote_port *rport,
500 struct nvmefc_ls_rsp *ls_rsp);
501 void (*map_queues)(struct nvme_fc_local_port *localport,
502 struct blk_mq_queue_map *map);
505 u16 max_sgl_segments;
506 u16 max_dif_sgl_segments;
509 /* sizes of additional private data for data structures */
518 * Initiator/Host functions
521 int nvme_fc_register_localport(struct nvme_fc_port_info *pinfo,
522 struct nvme_fc_port_template *template,
524 struct nvme_fc_local_port **lport_p);
526 int nvme_fc_unregister_localport(struct nvme_fc_local_port *localport);
528 int nvme_fc_register_remoteport(struct nvme_fc_local_port *localport,
529 struct nvme_fc_port_info *pinfo,
530 struct nvme_fc_remote_port **rport_p);
532 int nvme_fc_unregister_remoteport(struct nvme_fc_remote_port *remoteport);
534 void nvme_fc_rescan_remoteport(struct nvme_fc_remote_port *remoteport);
536 int nvme_fc_set_remoteport_devloss(struct nvme_fc_remote_port *remoteport,
540 * Routine called to pass a NVME-FC LS request, received by the lldd,
541 * to the nvme-fc transport.
543 * If the return value is zero: the LS was successfully accepted by the
545 * If the return value is non-zero: the transport has not accepted the
546 * LS. The lldd should ABTS-LS the LS.
548 * Note: if the LLDD receives and ABTS for the LS prior to the transport
549 * calling the ops->xmt_ls_rsp() routine to transmit a response, the LLDD
550 * shall mark the LS as aborted, and when the xmt_ls_rsp() is called: the
551 * response shall not be transmit and the struct nvmefc_ls_rsp() done
552 * routine shall be called. The LLDD may transmit the ABTS response as
553 * soon as the LS was marked or can delay until the xmt_ls_rsp() call is
555 * Note: if an RCV LS was successfully posted to the transport and the
556 * remoteport is then unregistered before xmt_ls_rsp() was called for
557 * the lsrsp structure, the transport will still call xmt_ls_rsp()
558 * afterward to cleanup the outstanding lsrsp structure. The LLDD should
559 * noop the transmission of the rsp and call the lsrsp->done() routine
560 * to allow the lsrsp structure to be released.
562 int nvme_fc_rcv_ls_req(struct nvme_fc_remote_port *remoteport,
563 struct nvmefc_ls_rsp *lsrsp,
564 void *lsreqbuf, u32 lsreqbuf_len);
569 * *************** LLDD FC-NVME Target/Subsystem API ***************
571 * For FC LLDD's that are the NVME Subsystem role
573 * ******************************************************************
577 * struct nvmet_fc_port_info - port-specific ids and FC connection-specific
578 * data element used during NVME Subsystem role
581 * Static fields describing the port being registered:
582 * @node_name: FC WWNN for the port
583 * @port_name: FC WWPN for the port
585 * Initialization values for dynamic port fields:
586 * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must
589 struct nvmet_fc_port_info {
596 /* Operations that NVME-FC layer may request the LLDD to perform for FCP */
598 NVMET_FCOP_READDATA = 1, /* xmt data to initiator */
599 NVMET_FCOP_WRITEDATA = 2, /* xmt data from initiator */
600 NVMET_FCOP_READDATA_RSP = 3, /* xmt data to initiator and send
603 NVMET_FCOP_RSP = 4, /* send rsp frame */
607 * struct nvmefc_tgt_fcp_req - Structure used between LLDD and NVMET-FC
608 * layer to represent the exchange context and
609 * the specific FC-NVME IU operation(s) to perform
610 * for a FC-NVME FCP IO.
612 * Structure used between LLDD and nvmet-fc layer to represent the exchange
613 * context for a FC-NVME FCP I/O operation (e.g. a nvme sqe, the sqe-related
614 * memory transfers, and its assocated cqe transfer).
616 * The structure is allocated by the LLDD whenever a FCP CMD IU is received
617 * from the FC link. The address of the structure is passed to the nvmet-fc
618 * layer via the nvmet_fc_rcv_fcp_req() call. The address of the structure
619 * will be passed back to the LLDD for the data operations and transmit of
620 * the response. The LLDD is to use the address to map back to the LLDD
621 * exchange structure which maintains information such as the targetport
622 * the FCP I/O was received on, the remote FC NVME initiator that sent the
623 * FCP I/O, and any FC exchange context. Upon completion of the FCP target
624 * operation, the address of the structure will be passed back to the FCP
625 * op done() routine, allowing the nvmet-fc layer to release dma resources.
626 * Upon completion of the done() routine for either RSP or ABORT ops, no
627 * further access will be made by the nvmet-fc layer and the LLDD can
628 * de-allocate the structure.
630 * Field initialization:
631 * At the time of the nvmet_fc_rcv_fcp_req() call, there is no content that
632 * is valid in the structure.
634 * When the structure is used for an FCP target operation, the nvmet-fc
635 * layer will fully set the fields in order to specify the scattergather
636 * list, the transfer length, as well as the done routine to be called
637 * upon compeletion of the operation. The nvmet-fc layer will also set a
638 * private pointer for its own use in the done routine.
640 * Values set by the NVMET-FC layer prior to calling the LLDD fcp_op
642 * @op: Indicates the FCP IU operation to perform (see NVMET_FCOP_xxx)
643 * @hwqid: Specifies the hw queue index (0..N-1, where N is the
644 * max_hw_queues value from the LLD's nvmet_fc_target_template)
645 * that the operation is to use.
646 * @offset: Indicates the DATA_OUT/DATA_IN payload offset to be tranferred.
647 * Field is only valid on WRITEDATA, READDATA, or READDATA_RSP ops.
648 * @timeout: amount of time, in seconds, to wait for a response from the NVME
649 * host. A value of 0 is an infinite wait.
650 * Valid only for the following ops:
651 * WRITEDATA: caps the wait for data reception
652 * READDATA_RSP & RSP: caps wait for FCP_CONF reception (if used)
653 * @transfer_length: the length, in bytes, of the DATA_OUT or DATA_IN payload
654 * that is to be transferred.
655 * Valid only for the WRITEDATA, READDATA, or READDATA_RSP ops.
656 * @ba_rjt: Contains the BA_RJT payload that is to be transferred.
657 * Valid only for the NVMET_FCOP_BA_RJT op.
658 * @sg: Scatter/gather list for the DATA_OUT/DATA_IN payload data.
659 * Valid only for the WRITEDATA, READDATA, or READDATA_RSP ops.
660 * @sg_cnt: Number of valid entries in the scatter/gather list.
661 * Valid only for the WRITEDATA, READDATA, or READDATA_RSP ops.
662 * @rspaddr: pointer to the FCP RSP IU buffer to be transmit
663 * Used by RSP and READDATA_RSP ops
664 * @rspdma: PCI DMA address of the FCP RSP IU buffer
665 * Used by RSP and READDATA_RSP ops
666 * @rsplen: Length, in bytes, of the FCP RSP IU buffer
667 * Used by RSP and READDATA_RSP ops
668 * @done: The callback routine the LLDD is to invoke upon completion of
669 * the operation. req argument is the pointer to the original
670 * FCP subsystem op request.
671 * @nvmet_fc_private: pointer to an internal NVMET-FC layer structure used
672 * as part of the NVMET-FC processing. The LLDD is not to
673 * reference this field.
675 * Values set by the LLDD indicating completion status of the FCP operation.
676 * Must be set prior to calling the done() callback.
677 * @transferred_length: amount of DATA_OUT payload data received by a
678 * WRITEDATA operation. If not a WRITEDATA operation, value must
679 * be set to 0. Should equal transfer_length on success.
680 * @fcp_error: status of the FCP operation. Must be 0 on success; on failure
681 * must be a NVME_SC_FC_xxxx value.
683 struct nvmefc_tgt_fcp_req {
689 struct fc_ba_rjt ba_rjt;
690 struct scatterlist *sg;
696 void (*done)(struct nvmefc_tgt_fcp_req *);
698 void *nvmet_fc_private; /* LLDD is not to access !! */
700 u32 transferred_length;
705 /* Target Features (Bit fields) LLDD supports */
707 NVMET_FCTGTFEAT_READDATA_RSP = (1 << 0),
708 /* Bit 0: supports the NVMET_FCPOP_READDATA_RSP op, which
709 * sends (the last) Read Data sequence followed by the RSP
710 * sequence in one LLDD operation. Errors during Data
711 * sequence transmit must not allow RSP sequence to be sent.
717 * struct nvmet_fc_target_port - structure used between NVME-FC transport and
718 * a LLDD to reference a local NVME subsystem port.
719 * Allocated/created by the nvme_fc_register_targetport()
720 * transport interface.
722 * Fields with static values for the port. Initialized by the
723 * port_info struct supplied to the registration call.
724 * @port_num: NVME-FC transport subsystem port number
725 * @node_name: FC WWNN for the port
726 * @port_name: FC WWPN for the port
727 * @private: pointer to memory allocated alongside the local port
728 * structure that is specifically for the LLDD to use.
729 * The length of the buffer corresponds to the target_priv_sz
730 * value specified in the nvme_fc_target_template supplied by
733 * Fields with dynamic values. Values may change base on link state. LLDD
734 * may reference fields directly to change them. Initialized by the
735 * port_info struct supplied to the registration call.
736 * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must
738 * @port_state: Operational state of the port.
740 struct nvmet_fc_target_port {
741 /* static/read-only fields */
750 enum nvme_fc_obj_state port_state;
751 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
755 * struct nvmet_fc_target_template - structure containing static entrypoints
756 * and operational parameters for an LLDD that supports NVME
757 * subsystem behavior. Passed by reference in port
758 * registrations. NVME-FC transport remembers template
759 * reference and may access it during runtime operation.
761 * Subsystem/Target Transport Entrypoints/Parameters:
763 * @targetport_delete: The LLDD initiates deletion of a targetport via
764 * nvmet_fc_unregister_targetport(). However, the teardown is
765 * asynchronous. This routine is called upon the completion of the
766 * teardown to inform the LLDD that the targetport has been deleted.
767 * Entrypoint is Mandatory.
769 * @xmt_ls_rsp: Called to transmit the response to a FC-NVME FC-4 LS service.
770 * The nvmefc_ls_rsp structure is the same LLDD-supplied exchange
771 * structure specified in the nvmet_fc_rcv_ls_req() call made when
772 * the LS request was received. The structure will fully describe
773 * the buffers for the response payload and the dma address of the
774 * payload. The LLDD is to transmit the response (or return a
775 * non-zero errno status), and upon completion of the transmit, call
776 * the "done" routine specified in the nvmefc_ls_rsp structure
777 * (argument to done is the address of the nvmefc_ls_rsp structure
778 * itself). Upon the completion of the done() routine, the LLDD shall
779 * consider the LS handling complete and the nvmefc_ls_rsp structure
780 * may be freed/released.
781 * The transport will always call the xmt_ls_rsp() routine for any
783 * Entrypoint is Mandatory.
785 * @map_queues: This functions lets the driver expose the queue mapping
786 * to the block layer.
787 * Entrypoint is Optional.
789 * @fcp_op: Called to perform a data transfer or transmit a response.
790 * The nvmefc_tgt_fcp_req structure is the same LLDD-supplied
791 * exchange structure specified in the nvmet_fc_rcv_fcp_req() call
792 * made when the FCP CMD IU was received. The op field in the
793 * structure shall indicate the operation for the LLDD to perform
794 * relative to the io.
795 * NVMET_FCOP_READDATA operation: the LLDD is to send the
796 * payload data (described by sglist) to the host in 1 or
797 * more FC sequences (preferrably 1). Note: the fc-nvme layer
798 * may call the READDATA operation multiple times for longer
800 * NVMET_FCOP_WRITEDATA operation: the LLDD is to receive the
801 * payload data (described by sglist) from the host via 1 or
802 * more FC sequences (preferrably 1). The LLDD is to generate
803 * the XFER_RDY IU(s) corresponding to the data being requested.
804 * Note: the FC-NVME layer may call the WRITEDATA operation
805 * multiple times for longer payloads.
806 * NVMET_FCOP_READDATA_RSP operation: the LLDD is to send the
807 * payload data (described by sglist) to the host in 1 or
808 * more FC sequences (preferrably 1). If an error occurs during
809 * payload data transmission, the LLDD is to set the
810 * nvmefc_tgt_fcp_req fcp_error and transferred_length field, then
811 * consider the operation complete. On error, the LLDD is to not
812 * transmit the FCP_RSP iu. If all payload data is transferred
813 * successfully, the LLDD is to update the nvmefc_tgt_fcp_req
814 * transferred_length field and may subsequently transmit the
815 * FCP_RSP iu payload (described by rspbuf, rspdma, rsplen).
816 * If FCP_CONF is supported, the LLDD is to await FCP_CONF
817 * reception to confirm the RSP reception by the host. The LLDD
818 * may retramsit the FCP_RSP iu if necessary per FC-NVME. Upon
819 * transmission of the FCP_RSP iu if FCP_CONF is not supported,
820 * or upon success/failure of FCP_CONF if it is supported, the
821 * LLDD is to set the nvmefc_tgt_fcp_req fcp_error field and
822 * consider the operation complete.
823 * NVMET_FCOP_RSP: the LLDD is to transmit the FCP_RSP iu payload
824 * (described by rspbuf, rspdma, rsplen). If FCP_CONF is
825 * supported, the LLDD is to await FCP_CONF reception to confirm
826 * the RSP reception by the host. The LLDD may retramsit the
827 * FCP_RSP iu if FCP_CONF is not received per FC-NVME. Upon
828 * transmission of the FCP_RSP iu if FCP_CONF is not supported,
829 * or upon success/failure of FCP_CONF if it is supported, the
830 * LLDD is to set the nvmefc_tgt_fcp_req fcp_error field and
831 * consider the operation complete.
832 * Upon completing the indicated operation, the LLDD is to set the
833 * status fields for the operation (tranferred_length and fcp_error
834 * status) in the request, then call the "done" routine
835 * indicated in the fcp request. After the operation completes,
836 * regardless of whether the FCP_RSP iu was successfully transmit,
837 * the LLDD-supplied exchange structure must remain valid until the
838 * transport calls the fcp_req_release() callback to return ownership
839 * of the exchange structure back to the LLDD so that it may be used
840 * for another fcp command.
841 * Note: when calling the done routine for READDATA or WRITEDATA
842 * operations, the fc-nvme layer may immediate convert, in the same
843 * thread and before returning to the LLDD, the fcp operation to
844 * the next operation for the fcp io and call the LLDDs fcp_op
845 * call again. If fields in the fcp request are to be accessed post
846 * the done call, the LLDD should save their values prior to calling
847 * the done routine, and inspect the save values after the done
849 * Returns 0 on success, -<errno> on failure (Ex: -EIO)
850 * Entrypoint is Mandatory.
852 * @fcp_abort: Called by the transport to abort an active command.
853 * The command may be in-between operations (nothing active in LLDD)
854 * or may have an active WRITEDATA operation pending. The LLDD is to
855 * initiate the ABTS process for the command and return from the
856 * callback. The ABTS does not need to be complete on the command.
857 * The fcp_abort callback inherently cannot fail. After the
858 * fcp_abort() callback completes, the transport will wait for any
859 * outstanding operation (if there was one) to complete, then will
860 * call the fcp_req_release() callback to return the command's
861 * exchange context back to the LLDD.
862 * Entrypoint is Mandatory.
864 * @fcp_req_release: Called by the transport to return a nvmefc_tgt_fcp_req
865 * to the LLDD after all operations on the fcp operation are complete.
866 * This may be due to the command completing or upon completion of
868 * Entrypoint is Mandatory.
870 * @defer_rcv: Called by the transport to signal the LLLD that it has
871 * begun processing of a previously received NVME CMD IU. The LLDD
872 * is now free to re-use the rcv buffer associated with the
873 * nvmefc_tgt_fcp_req.
874 * Entrypoint is Optional.
876 * @discovery_event: Called by the transport to generate an RSCN
877 * change notifications to NVME initiators. The RSCN notifications
878 * should cause the initiator to rescan the discovery controller
881 * @ls_req: Called to issue a FC-NVME FC-4 LS service request.
882 * The nvme_fc_ls_req structure will fully describe the buffers for
883 * the request payload and where to place the response payload.
884 * The targetport that is to issue the LS request is identified by
885 * the targetport argument. The remote port that is to receive the
886 * LS request is identified by the hosthandle argument. The nvmet-fc
887 * transport is only allowed to issue FC-NVME LS's on behalf of an
888 * association that was created prior by a Create Association LS.
889 * The hosthandle will originate from the LLDD in the struct
890 * nvmefc_ls_rsp structure for the Create Association LS that
891 * was delivered to the transport. The transport will save the
892 * hosthandle as an attribute of the association. If the LLDD
893 * loses connectivity with the remote port, it must call the
894 * nvmet_fc_invalidate_host() routine to remove any references to
895 * the remote port in the transport.
896 * The LLDD is to allocate an exchange, issue the LS request, obtain
897 * the LS response, and call the "done" routine specified in the
898 * request structure (argument to done is the ls request structure
900 * Entrypoint is Optional - but highly recommended.
902 * @ls_abort: called to request the LLDD to abort the indicated ls request.
903 * The call may return before the abort has completed. After aborting
904 * the request, the LLDD must still call the ls request done routine
905 * indicating an FC transport Aborted status.
906 * Entrypoint is Mandatory if the ls_req entry point is specified.
908 * @host_release: called to inform the LLDD that the request to invalidate
909 * the host port indicated by the hosthandle has been fully completed.
910 * No associations exist with the host port and there will be no
911 * further references to hosthandle.
912 * Entrypoint is Mandatory if the lldd calls nvmet_fc_invalidate_host().
914 * @max_hw_queues: indicates the maximum number of hw queues the LLDD
915 * supports for cpu affinitization.
916 * Value is Mandatory. Must be at least 1.
918 * @max_sgl_segments: indicates the maximum number of sgl segments supported
920 * Value is Mandatory. Must be at least 1. Recommend at least 256.
922 * @max_dif_sgl_segments: indicates the maximum number of sgl segments
923 * supported by the LLDD for DIF operations.
924 * Value is Mandatory. Must be at least 1. Recommend at least 256.
926 * @dma_boundary: indicates the dma address boundary where dma mappings
927 * will be split across.
928 * Value is Mandatory. Typical value is 0xFFFFFFFF to split across
929 * 4Gig address boundarys
931 * @target_features: The LLDD sets bits in this field to correspond to
932 * optional features that are supported by the LLDD.
933 * Refer to the NVMET_FCTGTFEAT_xxx values.
934 * Value is Mandatory. Allowed to be zero.
936 * @target_priv_sz: The LLDD sets this field to the amount of additional
937 * memory that it would like fc nvme layer to allocate on the LLDD's
938 * behalf whenever a targetport is allocated. The additional memory
939 * area solely for the of the LLDD and its location is specified by
940 * the targetport->private pointer.
941 * Value is Mandatory. Allowed to be zero.
943 * @lsrqst_priv_sz: The LLDD sets this field to the amount of additional
944 * memory that it would like nvmet-fc layer to allocate on the LLDD's
945 * behalf whenever a ls request structure is allocated. The additional
946 * memory area is solely for use by the LLDD and its location is
947 * specified by the ls_request->private pointer.
948 * Value is Mandatory. Allowed to be zero.
951 struct nvmet_fc_target_template {
952 void (*targetport_delete)(struct nvmet_fc_target_port *tgtport);
953 int (*xmt_ls_rsp)(struct nvmet_fc_target_port *tgtport,
954 struct nvmefc_ls_rsp *ls_rsp);
955 int (*fcp_op)(struct nvmet_fc_target_port *tgtport,
956 struct nvmefc_tgt_fcp_req *fcpreq);
957 void (*fcp_abort)(struct nvmet_fc_target_port *tgtport,
958 struct nvmefc_tgt_fcp_req *fcpreq);
959 void (*fcp_req_release)(struct nvmet_fc_target_port *tgtport,
960 struct nvmefc_tgt_fcp_req *fcpreq);
961 void (*defer_rcv)(struct nvmet_fc_target_port *tgtport,
962 struct nvmefc_tgt_fcp_req *fcpreq);
963 void (*discovery_event)(struct nvmet_fc_target_port *tgtport);
964 int (*ls_req)(struct nvmet_fc_target_port *targetport,
965 void *hosthandle, struct nvmefc_ls_req *lsreq);
966 void (*ls_abort)(struct nvmet_fc_target_port *targetport,
967 void *hosthandle, struct nvmefc_ls_req *lsreq);
968 void (*host_release)(void *hosthandle);
971 u16 max_sgl_segments;
972 u16 max_dif_sgl_segments;
977 /* sizes of additional private data for data structures */
983 int nvmet_fc_register_targetport(struct nvmet_fc_port_info *portinfo,
984 struct nvmet_fc_target_template *template,
986 struct nvmet_fc_target_port **tgtport_p);
988 int nvmet_fc_unregister_targetport(struct nvmet_fc_target_port *tgtport);
991 * Routine called to pass a NVME-FC LS request, received by the lldd,
992 * to the nvmet-fc transport.
994 * If the return value is zero: the LS was successfully accepted by the
996 * If the return value is non-zero: the transport has not accepted the
997 * LS. The lldd should ABTS-LS the LS.
999 * Note: if the LLDD receives and ABTS for the LS prior to the transport
1000 * calling the ops->xmt_ls_rsp() routine to transmit a response, the LLDD
1001 * shall mark the LS as aborted, and when the xmt_ls_rsp() is called: the
1002 * response shall not be transmit and the struct nvmefc_ls_rsp() done
1003 * routine shall be called. The LLDD may transmit the ABTS response as
1004 * soon as the LS was marked or can delay until the xmt_ls_rsp() call is
1006 * Note: if an RCV LS was successfully posted to the transport and the
1007 * targetport is then unregistered before xmt_ls_rsp() was called for
1008 * the lsrsp structure, the transport will still call xmt_ls_rsp()
1009 * afterward to cleanup the outstanding lsrsp structure. The LLDD should
1010 * noop the transmission of the rsp and call the lsrsp->done() routine
1011 * to allow the lsrsp structure to be released.
1013 int nvmet_fc_rcv_ls_req(struct nvmet_fc_target_port *tgtport,
1015 struct nvmefc_ls_rsp *rsp,
1016 void *lsreqbuf, u32 lsreqbuf_len);
1019 * Routine called by the LLDD whenever it has a logout or loss of
1020 * connectivity to a NVME-FC host port which there had been active
1021 * NVMe controllers for. The host port is indicated by the
1022 * hosthandle. The hosthandle is given to the nvmet-fc transport
1023 * when a NVME LS was received, typically to create a new association.
1024 * The nvmet-fc transport will cache the hostport value with the
1025 * association for use in LS requests for the association.
1026 * When the LLDD calls this routine, the nvmet-fc transport will
1027 * immediately terminate all associations that were created with
1028 * the hosthandle host port.
1029 * The LLDD, after calling this routine and having control returned,
1030 * must assume the transport may subsequently utilize hosthandle as
1031 * part of sending LS's to terminate the association. The LLDD
1032 * should reject the LS's if they are attempted.
1033 * Once the last association has terminated for the hosthandle host
1034 * port, the nvmet-fc transport will call the ops->host_release()
1035 * callback. As of the callback, the nvmet-fc transport will no
1036 * longer reference hosthandle.
1038 void nvmet_fc_invalidate_host(struct nvmet_fc_target_port *tgtport,
1042 * If nvmet_fc_rcv_fcp_req returns non-zero, the transport has not accepted
1043 * the FCP cmd. The lldd should ABTS-LS the cmd.
1045 int nvmet_fc_rcv_fcp_req(struct nvmet_fc_target_port *tgtport,
1046 struct nvmefc_tgt_fcp_req *fcpreq,
1047 void *cmdiubuf, u32 cmdiubuf_len);
1049 void nvmet_fc_rcv_fcp_abort(struct nvmet_fc_target_port *tgtport,
1050 struct nvmefc_tgt_fcp_req *fcpreq);
1052 #endif /* _NVME_FC_DRIVER_H */