2 * Copyright (c) 2016, Avago Technologies
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 #ifndef _NVME_FC_DRIVER_H
15 #define _NVME_FC_DRIVER_H 1
19 * ********************** LLDD FC-NVME Host API ********************
21 * For FC LLDD's that are the NVME Host role.
23 * ******************************************************************
28 /* FC Port role bitmask - can merge with FC Port Roles in fc transport */
29 #define FC_PORT_ROLE_NVME_INITIATOR 0x10
30 #define FC_PORT_ROLE_NVME_TARGET 0x20
31 #define FC_PORT_ROLE_NVME_DISCOVERY 0x40
35 * struct nvme_fc_port_info - port-specific ids and FC connection-specific
36 * data element used during NVME Host role
39 * Static fields describing the port being registered:
40 * @node_name: FC WWNN for the port
41 * @port_name: FC WWPN for the port
42 * @port_role: What NVME roles are supported (see FC_PORT_ROLE_xxx)
43 * @dev_loss_tmo: maximum delay for reconnects to an association on
44 * this device. Used only on a remoteport.
46 * Initialization values for dynamic port fields:
47 * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must
50 struct nvme_fc_port_info {
60 * struct nvmefc_ls_req - Request structure passed from NVME-FC transport
61 * to LLDD in order to perform a NVME FC-4 LS
62 * request and obtain a response.
64 * Values set by the NVME-FC layer prior to calling the LLDD ls_req
66 * @rqstaddr: pointer to request buffer
67 * @rqstdma: PCI DMA address of request buffer
68 * @rqstlen: Length, in bytes, of request buffer
69 * @rspaddr: pointer to response buffer
70 * @rspdma: PCI DMA address of response buffer
71 * @rsplen: Length, in bytes, of response buffer
72 * @timeout: Maximum amount of time, in seconds, to wait for the LS response.
73 * If timeout exceeded, LLDD to abort LS exchange and complete
74 * LS request with error status.
75 * @private: pointer to memory allocated alongside the ls request structure
76 * that is specifically for the LLDD to use while processing the
77 * request. The length of the buffer corresponds to the
78 * lsrqst_priv_sz value specified in the nvme_fc_port_template
79 * supplied by the LLDD.
80 * @done: The callback routine the LLDD is to invoke upon completion of
81 * the LS request. req argument is the pointer to the original LS
82 * request structure. Status argument must be 0 upon success, a
83 * negative errno on failure (example: -ENXIO).
85 struct nvmefc_ls_req {
96 void (*done)(struct nvmefc_ls_req *req, int status);
98 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
101 enum nvmefc_fcp_datadir {
102 NVMEFC_FCP_NODATA, /* payload_length and sg_cnt will be zero */
109 * struct nvmefc_fcp_req - Request structure passed from NVME-FC transport
110 * to LLDD in order to perform a NVME FCP IO operation.
112 * Values set by the NVME-FC layer prior to calling the LLDD fcp_io
114 * @cmdaddr: pointer to the FCP CMD IU buffer
115 * @rspaddr: pointer to the FCP RSP IU buffer
116 * @cmddma: PCI DMA address of the FCP CMD IU buffer
117 * @rspdma: PCI DMA address of the FCP RSP IU buffer
118 * @cmdlen: Length, in bytes, of the FCP CMD IU buffer
119 * @rsplen: Length, in bytes, of the FCP RSP IU buffer
120 * @payload_length: Length of DATA_IN or DATA_OUT payload data to transfer
121 * @sg_table: scatter/gather structure for payload data
122 * @first_sgl: memory for 1st scatter/gather list segment for payload data
123 * @sg_cnt: number of elements in the scatter/gather list
124 * @io_dir: direction of the FCP request (see NVMEFC_FCP_xxx)
125 * @sqid: The nvme SQID the command is being issued on
126 * @done: The callback routine the LLDD is to invoke upon completion of
127 * the FCP operation. req argument is the pointer to the original
129 * @private: pointer to memory allocated alongside the FCP operation
130 * request structure that is specifically for the LLDD to use
131 * while processing the operation. The length of the buffer
132 * corresponds to the fcprqst_priv_sz value specified in the
133 * nvme_fc_port_template supplied by the LLDD.
135 * Values set by the LLDD indicating completion status of the FCP operation.
136 * Must be set prior to calling the done() callback.
137 * @transferred_length: amount of payload data, in bytes, that were
138 * transferred. Should equal payload_length on success.
139 * @rcv_rsplen: length, in bytes, of the FCP RSP IU received.
140 * @status: Completion status of the FCP operation. must be 0 upon success,
141 * negative errno value upon failure (ex: -EIO). Note: this is
142 * NOT a reflection of the NVME CQE completion status. Only the
143 * status of the FCP operation at the NVME-FC level.
145 struct nvmefc_fcp_req {
154 struct sg_table sg_table;
155 struct scatterlist *first_sgl;
157 enum nvmefc_fcp_datadir io_dir;
161 void (*done)(struct nvmefc_fcp_req *req);
165 u32 transferred_length;
168 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
172 * Direct copy of fc_port_state enum. For later merging
174 enum nvme_fc_obj_state {
176 FC_OBJSTATE_NOTPRESENT,
178 FC_OBJSTATE_OFFLINE, /* User has taken Port Offline */
180 FC_OBJSTATE_BYPASSED,
181 FC_OBJSTATE_DIAGNOSTICS,
182 FC_OBJSTATE_LINKDOWN,
184 FC_OBJSTATE_LOOPBACK,
190 * struct nvme_fc_local_port - structure used between NVME-FC transport and
191 * a LLDD to reference a local NVME host port.
192 * Allocated/created by the nvme_fc_register_localport()
193 * transport interface.
195 * Fields with static values for the port. Initialized by the
196 * port_info struct supplied to the registration call.
197 * @port_num: NVME-FC transport host port number
198 * @port_role: NVME roles are supported on the port (see FC_PORT_ROLE_xxx)
199 * @node_name: FC WWNN for the port
200 * @port_name: FC WWPN for the port
201 * @private: pointer to memory allocated alongside the local port
202 * structure that is specifically for the LLDD to use.
203 * The length of the buffer corresponds to the local_priv_sz
204 * value specified in the nvme_fc_port_template supplied by
206 * @dev_loss_tmo: maximum delay for reconnects to an association on
207 * this device. To modify, lldd must call
208 * nvme_fc_set_remoteport_devloss().
210 * Fields with dynamic values. Values may change base on link state. LLDD
211 * may reference fields directly to change them. Initialized by the
212 * port_info struct supplied to the registration call.
213 * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must
215 * @port_state: Operational state of the port.
217 struct nvme_fc_local_port {
218 /* static/read-only fields */
228 enum nvme_fc_obj_state port_state;
229 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
233 * struct nvme_fc_remote_port - structure used between NVME-FC transport and
234 * a LLDD to reference a remote NVME subsystem port.
235 * Allocated/created by the nvme_fc_register_remoteport()
236 * transport interface.
238 * Fields with static values for the port. Initialized by the
239 * port_info struct supplied to the registration call.
240 * @port_num: NVME-FC transport remote subsystem port number
241 * @port_role: NVME roles are supported on the port (see FC_PORT_ROLE_xxx)
242 * @node_name: FC WWNN for the port
243 * @port_name: FC WWPN for the port
244 * @localport: pointer to the NVME-FC local host port the subsystem is
246 * @private: pointer to memory allocated alongside the remote port
247 * structure that is specifically for the LLDD to use.
248 * The length of the buffer corresponds to the remote_priv_sz
249 * value specified in the nvme_fc_port_template supplied by
252 * Fields with dynamic values. Values may change base on link or login
253 * state. LLDD may reference fields directly to change them. Initialized by
254 * the port_info struct supplied to the registration call.
255 * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must
257 * @port_state: Operational state of the remote port. Valid values are
260 struct nvme_fc_remote_port {
266 struct nvme_fc_local_port *localport;
272 enum nvme_fc_obj_state port_state;
273 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
277 * struct nvme_fc_port_template - structure containing static entrypoints and
278 * operational parameters for an LLDD that supports NVME host
279 * behavior. Passed by reference in port registrations.
280 * NVME-FC transport remembers template reference and may
281 * access it during runtime operation.
283 * Host/Initiator Transport Entrypoints/Parameters:
285 * @localport_delete: The LLDD initiates deletion of a localport via
286 * nvme_fc_deregister_localport(). However, the teardown is
287 * asynchronous. This routine is called upon the completion of the
288 * teardown to inform the LLDD that the localport has been deleted.
289 * Entrypoint is Mandatory.
291 * @remoteport_delete: The LLDD initiates deletion of a remoteport via
292 * nvme_fc_deregister_remoteport(). However, the teardown is
293 * asynchronous. This routine is called upon the completion of the
294 * teardown to inform the LLDD that the remoteport has been deleted.
295 * Entrypoint is Mandatory.
297 * @create_queue: Upon creating a host<->controller association, queues are
298 * created such that they can be affinitized to cpus/cores. This
299 * callback into the LLDD to notify that a controller queue is being
300 * created. The LLDD may choose to allocate an associated hw queue
301 * or map it onto a shared hw queue. Upon return from the call, the
302 * LLDD specifies a handle that will be given back to it for any
303 * command that is posted to the controller queue. The handle can
304 * be used by the LLDD to map quickly to the proper hw queue for
305 * command execution. The mask of cpu's that will map to this queue
306 * at the block-level is also passed in. The LLDD should use the
307 * queue id and/or cpu masks to ensure proper affinitization of the
308 * controller queue to the hw queue.
309 * Entrypoint is Optional.
311 * @delete_queue: This is the inverse of the crete_queue. During
312 * host<->controller association teardown, this routine is called
313 * when a controller queue is being terminated. Any association with
314 * a hw queue should be termined. If there is a unique hw queue, the
315 * hw queue should be torn down.
316 * Entrypoint is Optional.
318 * @poll_queue: Called to poll for the completion of an io on a blk queue.
319 * Entrypoint is Optional.
321 * @ls_req: Called to issue a FC-NVME FC-4 LS service request.
322 * The nvme_fc_ls_req structure will fully describe the buffers for
323 * the request payload and where to place the response payload. The
324 * LLDD is to allocate an exchange, issue the LS request, obtain the
325 * LS response, and call the "done" routine specified in the request
326 * structure (argument to done is the ls request structure itself).
327 * Entrypoint is Mandatory.
329 * @fcp_io: called to issue a FC-NVME I/O request. The I/O may be for
330 * an admin queue or an i/o queue. The nvmefc_fcp_req structure will
331 * fully describe the io: the buffer containing the FC-NVME CMD IU
332 * (which contains the SQE), the sg list for the payload if applicable,
333 * and the buffer to place the FC-NVME RSP IU into. The LLDD will
334 * complete the i/o, indicating the amount of data transferred or
335 * any transport error, and call the "done" routine specified in the
336 * request structure (argument to done is the fcp request structure
338 * Entrypoint is Mandatory.
340 * @ls_abort: called to request the LLDD to abort the indicated ls request.
341 * The call may return before the abort has completed. After aborting
342 * the request, the LLDD must still call the ls request done routine
343 * indicating an FC transport Aborted status.
344 * Entrypoint is Mandatory.
346 * @fcp_abort: called to request the LLDD to abort the indicated fcp request.
347 * The call may return before the abort has completed. After aborting
348 * the request, the LLDD must still call the fcp request done routine
349 * indicating an FC transport Aborted status.
350 * Entrypoint is Mandatory.
352 * @max_hw_queues: indicates the maximum number of hw queues the LLDD
353 * supports for cpu affinitization.
354 * Value is Mandatory. Must be at least 1.
356 * @max_sgl_segments: indicates the maximum number of sgl segments supported
358 * Value is Mandatory. Must be at least 1. Recommend at least 256.
360 * @max_dif_sgl_segments: indicates the maximum number of sgl segments
361 * supported by the LLDD for DIF operations.
362 * Value is Mandatory. Must be at least 1. Recommend at least 256.
364 * @dma_boundary: indicates the dma address boundary where dma mappings
365 * will be split across.
366 * Value is Mandatory. Typical value is 0xFFFFFFFF to split across
367 * 4Gig address boundarys
369 * @local_priv_sz: The LLDD sets this field to the amount of additional
370 * memory that it would like fc nvme layer to allocate on the LLDD's
371 * behalf whenever a localport is allocated. The additional memory
372 * area solely for the of the LLDD and its location is specified by
373 * the localport->private pointer.
374 * Value is Mandatory. Allowed to be zero.
376 * @remote_priv_sz: The LLDD sets this field to the amount of additional
377 * memory that it would like fc nvme layer to allocate on the LLDD's
378 * behalf whenever a remoteport is allocated. The additional memory
379 * area solely for the of the LLDD and its location is specified by
380 * the remoteport->private pointer.
381 * Value is Mandatory. Allowed to be zero.
383 * @lsrqst_priv_sz: The LLDD sets this field to the amount of additional
384 * memory that it would like fc nvme layer to allocate on the LLDD's
385 * behalf whenever a ls request structure is allocated. The additional
386 * memory area solely for the of the LLDD and its location is
387 * specified by the ls_request->private pointer.
388 * Value is Mandatory. Allowed to be zero.
390 * @fcprqst_priv_sz: The LLDD sets this field to the amount of additional
391 * memory that it would like fc nvme layer to allocate on the LLDD's
392 * behalf whenever a fcp request structure is allocated. The additional
393 * memory area solely for the of the LLDD and its location is
394 * specified by the fcp_request->private pointer.
395 * Value is Mandatory. Allowed to be zero.
397 struct nvme_fc_port_template {
398 /* initiator-based functions */
399 void (*localport_delete)(struct nvme_fc_local_port *);
400 void (*remoteport_delete)(struct nvme_fc_remote_port *);
401 int (*create_queue)(struct nvme_fc_local_port *,
402 unsigned int qidx, u16 qsize,
404 void (*delete_queue)(struct nvme_fc_local_port *,
405 unsigned int qidx, void *handle);
406 int (*ls_req)(struct nvme_fc_local_port *,
407 struct nvme_fc_remote_port *,
408 struct nvmefc_ls_req *);
409 int (*fcp_io)(struct nvme_fc_local_port *,
410 struct nvme_fc_remote_port *,
411 void *hw_queue_handle,
412 struct nvmefc_fcp_req *);
413 void (*ls_abort)(struct nvme_fc_local_port *,
414 struct nvme_fc_remote_port *,
415 struct nvmefc_ls_req *);
416 void (*fcp_abort)(struct nvme_fc_local_port *,
417 struct nvme_fc_remote_port *,
418 void *hw_queue_handle,
419 struct nvmefc_fcp_req *);
422 u16 max_sgl_segments;
423 u16 max_dif_sgl_segments;
426 /* sizes of additional private data for data structures */
435 * Initiator/Host functions
438 int nvme_fc_register_localport(struct nvme_fc_port_info *pinfo,
439 struct nvme_fc_port_template *template,
441 struct nvme_fc_local_port **lport_p);
443 int nvme_fc_unregister_localport(struct nvme_fc_local_port *localport);
445 int nvme_fc_register_remoteport(struct nvme_fc_local_port *localport,
446 struct nvme_fc_port_info *pinfo,
447 struct nvme_fc_remote_port **rport_p);
449 int nvme_fc_unregister_remoteport(struct nvme_fc_remote_port *remoteport);
451 void nvme_fc_rescan_remoteport(struct nvme_fc_remote_port *remoteport);
453 int nvme_fc_set_remoteport_devloss(struct nvme_fc_remote_port *remoteport,
458 * *************** LLDD FC-NVME Target/Subsystem API ***************
460 * For FC LLDD's that are the NVME Subsystem role
462 * ******************************************************************
466 * struct nvmet_fc_port_info - port-specific ids and FC connection-specific
467 * data element used during NVME Subsystem role
470 * Static fields describing the port being registered:
471 * @node_name: FC WWNN for the port
472 * @port_name: FC WWPN for the port
474 * Initialization values for dynamic port fields:
475 * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must
478 struct nvmet_fc_port_info {
486 * struct nvmefc_tgt_ls_req - Structure used between LLDD and NVMET-FC
487 * layer to represent the exchange context for
488 * a FC-NVME Link Service (LS).
490 * The structure is allocated by the LLDD whenever a LS Request is received
491 * from the FC link. The address of the structure is passed to the nvmet-fc
492 * layer via the nvmet_fc_rcv_ls_req() call. The address of the structure
493 * will be passed back to the LLDD when the response is to be transmit.
494 * The LLDD is to use the address to map back to the LLDD exchange structure
495 * which maintains information such as the targetport the LS was received
496 * on, the remote FC NVME initiator that sent the LS, and any FC exchange
497 * context. Upon completion of the LS response transmit, the address of the
498 * structure will be passed back to the LS rsp done() routine, allowing the
499 * nvmet-fc layer to release dma resources. Upon completion of the done()
500 * routine, no further access will be made by the nvmet-fc layer and the
501 * LLDD can de-allocate the structure.
503 * Field initialization:
504 * At the time of the nvmet_fc_rcv_ls_req() call, there is no content that
505 * is valid in the structure.
507 * When the structure is used for the LLDD->xmt_ls_rsp() call, the nvmet-fc
508 * layer will fully set the fields in order to specify the response
509 * payload buffer and its length as well as the done routine to be called
510 * upon compeletion of the transmit. The nvmet-fc layer will also set a
511 * private pointer for its own use in the done routine.
513 * Values set by the NVMET-FC layer prior to calling the LLDD xmt_ls_rsp
515 * @rspbuf: pointer to the LS response buffer
516 * @rspdma: PCI DMA address of the LS response buffer
517 * @rsplen: Length, in bytes, of the LS response buffer
518 * @done: The callback routine the LLDD is to invoke upon completion of
519 * transmitting the LS response. req argument is the pointer to
520 * the original ls request.
521 * @nvmet_fc_private: pointer to an internal NVMET-FC layer structure used
522 * as part of the NVMET-FC processing. The LLDD is not to access
525 struct nvmefc_tgt_ls_req {
530 void (*done)(struct nvmefc_tgt_ls_req *req);
531 void *nvmet_fc_private; /* LLDD is not to access !! */
534 /* Operations that NVME-FC layer may request the LLDD to perform for FCP */
536 NVMET_FCOP_READDATA = 1, /* xmt data to initiator */
537 NVMET_FCOP_WRITEDATA = 2, /* xmt data from initiator */
538 NVMET_FCOP_READDATA_RSP = 3, /* xmt data to initiator and send
541 NVMET_FCOP_RSP = 4, /* send rsp frame */
545 * struct nvmefc_tgt_fcp_req - Structure used between LLDD and NVMET-FC
546 * layer to represent the exchange context and
547 * the specific FC-NVME IU operation(s) to perform
548 * for a FC-NVME FCP IO.
550 * Structure used between LLDD and nvmet-fc layer to represent the exchange
551 * context for a FC-NVME FCP I/O operation (e.g. a nvme sqe, the sqe-related
552 * memory transfers, and its assocated cqe transfer).
554 * The structure is allocated by the LLDD whenever a FCP CMD IU is received
555 * from the FC link. The address of the structure is passed to the nvmet-fc
556 * layer via the nvmet_fc_rcv_fcp_req() call. The address of the structure
557 * will be passed back to the LLDD for the data operations and transmit of
558 * the response. The LLDD is to use the address to map back to the LLDD
559 * exchange structure which maintains information such as the targetport
560 * the FCP I/O was received on, the remote FC NVME initiator that sent the
561 * FCP I/O, and any FC exchange context. Upon completion of the FCP target
562 * operation, the address of the structure will be passed back to the FCP
563 * op done() routine, allowing the nvmet-fc layer to release dma resources.
564 * Upon completion of the done() routine for either RSP or ABORT ops, no
565 * further access will be made by the nvmet-fc layer and the LLDD can
566 * de-allocate the structure.
568 * Field initialization:
569 * At the time of the nvmet_fc_rcv_fcp_req() call, there is no content that
570 * is valid in the structure.
572 * When the structure is used for an FCP target operation, the nvmet-fc
573 * layer will fully set the fields in order to specify the scattergather
574 * list, the transfer length, as well as the done routine to be called
575 * upon compeletion of the operation. The nvmet-fc layer will also set a
576 * private pointer for its own use in the done routine.
578 * Values set by the NVMET-FC layer prior to calling the LLDD fcp_op
580 * @op: Indicates the FCP IU operation to perform (see NVMET_FCOP_xxx)
581 * @hwqid: Specifies the hw queue index (0..N-1, where N is the
582 * max_hw_queues value from the LLD's nvmet_fc_target_template)
583 * that the operation is to use.
584 * @offset: Indicates the DATA_OUT/DATA_IN payload offset to be tranferred.
585 * Field is only valid on WRITEDATA, READDATA, or READDATA_RSP ops.
586 * @timeout: amount of time, in seconds, to wait for a response from the NVME
587 * host. A value of 0 is an infinite wait.
588 * Valid only for the following ops:
589 * WRITEDATA: caps the wait for data reception
590 * READDATA_RSP & RSP: caps wait for FCP_CONF reception (if used)
591 * @transfer_length: the length, in bytes, of the DATA_OUT or DATA_IN payload
592 * that is to be transferred.
593 * Valid only for the WRITEDATA, READDATA, or READDATA_RSP ops.
594 * @ba_rjt: Contains the BA_RJT payload that is to be transferred.
595 * Valid only for the NVMET_FCOP_BA_RJT op.
596 * @sg: Scatter/gather list for the DATA_OUT/DATA_IN payload data.
597 * Valid only for the WRITEDATA, READDATA, or READDATA_RSP ops.
598 * @sg_cnt: Number of valid entries in the scatter/gather list.
599 * Valid only for the WRITEDATA, READDATA, or READDATA_RSP ops.
600 * @rspaddr: pointer to the FCP RSP IU buffer to be transmit
601 * Used by RSP and READDATA_RSP ops
602 * @rspdma: PCI DMA address of the FCP RSP IU buffer
603 * Used by RSP and READDATA_RSP ops
604 * @rsplen: Length, in bytes, of the FCP RSP IU buffer
605 * Used by RSP and READDATA_RSP ops
606 * @done: The callback routine the LLDD is to invoke upon completion of
607 * the operation. req argument is the pointer to the original
608 * FCP subsystem op request.
609 * @nvmet_fc_private: pointer to an internal NVMET-FC layer structure used
610 * as part of the NVMET-FC processing. The LLDD is not to
611 * reference this field.
613 * Values set by the LLDD indicating completion status of the FCP operation.
614 * Must be set prior to calling the done() callback.
615 * @transferred_length: amount of DATA_OUT payload data received by a
616 * a WRITEDATA operation. If not a WRITEDATA operation, value must
617 * be set to 0. Should equal transfer_length on success.
618 * @fcp_error: status of the FCP operation. Must be 0 on success; on failure
619 * must be a NVME_SC_FC_xxxx value.
621 struct nvmefc_tgt_fcp_req {
627 struct fc_ba_rjt ba_rjt;
628 struct scatterlist *sg;
634 void (*done)(struct nvmefc_tgt_fcp_req *);
636 void *nvmet_fc_private; /* LLDD is not to access !! */
638 u32 transferred_length;
643 /* Target Features (Bit fields) LLDD supports */
645 NVMET_FCTGTFEAT_READDATA_RSP = (1 << 0),
646 /* Bit 0: supports the NVMET_FCPOP_READDATA_RSP op, which
647 * sends (the last) Read Data sequence followed by the RSP
648 * sequence in one LLDD operation. Errors during Data
649 * sequence transmit must not allow RSP sequence to be sent.
655 * struct nvmet_fc_target_port - structure used between NVME-FC transport and
656 * a LLDD to reference a local NVME subsystem port.
657 * Allocated/created by the nvme_fc_register_targetport()
658 * transport interface.
660 * Fields with static values for the port. Initialized by the
661 * port_info struct supplied to the registration call.
662 * @port_num: NVME-FC transport subsytem port number
663 * @node_name: FC WWNN for the port
664 * @port_name: FC WWPN for the port
665 * @private: pointer to memory allocated alongside the local port
666 * structure that is specifically for the LLDD to use.
667 * The length of the buffer corresponds to the target_priv_sz
668 * value specified in the nvme_fc_target_template supplied by
671 * Fields with dynamic values. Values may change base on link state. LLDD
672 * may reference fields directly to change them. Initialized by the
673 * port_info struct supplied to the registration call.
674 * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must
676 * @port_state: Operational state of the port.
678 struct nvmet_fc_target_port {
679 /* static/read-only fields */
688 enum nvme_fc_obj_state port_state;
689 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
693 * struct nvmet_fc_target_template - structure containing static entrypoints
694 * and operational parameters for an LLDD that supports NVME
695 * subsystem behavior. Passed by reference in port
696 * registrations. NVME-FC transport remembers template
697 * reference and may access it during runtime operation.
699 * Subsystem/Target Transport Entrypoints/Parameters:
701 * @targetport_delete: The LLDD initiates deletion of a targetport via
702 * nvmet_fc_unregister_targetport(). However, the teardown is
703 * asynchronous. This routine is called upon the completion of the
704 * teardown to inform the LLDD that the targetport has been deleted.
705 * Entrypoint is Mandatory.
707 * @xmt_ls_rsp: Called to transmit the response to a FC-NVME FC-4 LS service.
708 * The nvmefc_tgt_ls_req structure is the same LLDD-supplied exchange
709 * structure specified in the nvmet_fc_rcv_ls_req() call made when
710 * the LS request was received. The structure will fully describe
711 * the buffers for the response payload and the dma address of the
712 * payload. The LLDD is to transmit the response (or return a non-zero
713 * errno status), and upon completion of the transmit, call the
714 * "done" routine specified in the nvmefc_tgt_ls_req structure
715 * (argument to done is the ls reqwuest structure itself).
716 * After calling the done routine, the LLDD shall consider the
717 * LS handling complete and the nvmefc_tgt_ls_req structure may
719 * Entrypoint is Mandatory.
721 * @fcp_op: Called to perform a data transfer or transmit a response.
722 * The nvmefc_tgt_fcp_req structure is the same LLDD-supplied
723 * exchange structure specified in the nvmet_fc_rcv_fcp_req() call
724 * made when the FCP CMD IU was received. The op field in the
725 * structure shall indicate the operation for the LLDD to perform
726 * relative to the io.
727 * NVMET_FCOP_READDATA operation: the LLDD is to send the
728 * payload data (described by sglist) to the host in 1 or
729 * more FC sequences (preferrably 1). Note: the fc-nvme layer
730 * may call the READDATA operation multiple times for longer
732 * NVMET_FCOP_WRITEDATA operation: the LLDD is to receive the
733 * payload data (described by sglist) from the host via 1 or
734 * more FC sequences (preferrably 1). The LLDD is to generate
735 * the XFER_RDY IU(s) corresponding to the data being requested.
736 * Note: the FC-NVME layer may call the WRITEDATA operation
737 * multiple times for longer payloads.
738 * NVMET_FCOP_READDATA_RSP operation: the LLDD is to send the
739 * payload data (described by sglist) to the host in 1 or
740 * more FC sequences (preferrably 1). If an error occurs during
741 * payload data transmission, the LLDD is to set the
742 * nvmefc_tgt_fcp_req fcp_error and transferred_length field, then
743 * consider the operation complete. On error, the LLDD is to not
744 * transmit the FCP_RSP iu. If all payload data is transferred
745 * successfully, the LLDD is to update the nvmefc_tgt_fcp_req
746 * transferred_length field and may subsequently transmit the
747 * FCP_RSP iu payload (described by rspbuf, rspdma, rsplen).
748 * If FCP_CONF is supported, the LLDD is to await FCP_CONF
749 * reception to confirm the RSP reception by the host. The LLDD
750 * may retramsit the FCP_RSP iu if necessary per FC-NVME. Upon
751 * transmission of the FCP_RSP iu if FCP_CONF is not supported,
752 * or upon success/failure of FCP_CONF if it is supported, the
753 * LLDD is to set the nvmefc_tgt_fcp_req fcp_error field and
754 * consider the operation complete.
755 * NVMET_FCOP_RSP: the LLDD is to transmit the FCP_RSP iu payload
756 * (described by rspbuf, rspdma, rsplen). If FCP_CONF is
757 * supported, the LLDD is to await FCP_CONF reception to confirm
758 * the RSP reception by the host. The LLDD may retramsit the
759 * FCP_RSP iu if FCP_CONF is not received per FC-NVME. Upon
760 * transmission of the FCP_RSP iu if FCP_CONF is not supported,
761 * or upon success/failure of FCP_CONF if it is supported, the
762 * LLDD is to set the nvmefc_tgt_fcp_req fcp_error field and
763 * consider the operation complete.
764 * Upon completing the indicated operation, the LLDD is to set the
765 * status fields for the operation (tranferred_length and fcp_error
766 * status) in the request, then call the "done" routine
767 * indicated in the fcp request. After the operation completes,
768 * regardless of whether the FCP_RSP iu was successfully transmit,
769 * the LLDD-supplied exchange structure must remain valid until the
770 * transport calls the fcp_req_release() callback to return ownership
771 * of the exchange structure back to the LLDD so that it may be used
772 * for another fcp command.
773 * Note: when calling the done routine for READDATA or WRITEDATA
774 * operations, the fc-nvme layer may immediate convert, in the same
775 * thread and before returning to the LLDD, the fcp operation to
776 * the next operation for the fcp io and call the LLDDs fcp_op
777 * call again. If fields in the fcp request are to be accessed post
778 * the done call, the LLDD should save their values prior to calling
779 * the done routine, and inspect the save values after the done
781 * Returns 0 on success, -<errno> on failure (Ex: -EIO)
782 * Entrypoint is Mandatory.
784 * @fcp_abort: Called by the transport to abort an active command.
785 * The command may be in-between operations (nothing active in LLDD)
786 * or may have an active WRITEDATA operation pending. The LLDD is to
787 * initiate the ABTS process for the command and return from the
788 * callback. The ABTS does not need to be complete on the command.
789 * The fcp_abort callback inherently cannot fail. After the
790 * fcp_abort() callback completes, the transport will wait for any
791 * outstanding operation (if there was one) to complete, then will
792 * call the fcp_req_release() callback to return the command's
793 * exchange context back to the LLDD.
794 * Entrypoint is Mandatory.
796 * @fcp_req_release: Called by the transport to return a nvmefc_tgt_fcp_req
797 * to the LLDD after all operations on the fcp operation are complete.
798 * This may be due to the command completing or upon completion of
800 * Entrypoint is Mandatory.
802 * @defer_rcv: Called by the transport to signal the LLLD that it has
803 * begun processing of a previously received NVME CMD IU. The LLDD
804 * is now free to re-use the rcv buffer associated with the
805 * nvmefc_tgt_fcp_req.
806 * Entrypoint is Optional.
808 * @max_hw_queues: indicates the maximum number of hw queues the LLDD
809 * supports for cpu affinitization.
810 * Value is Mandatory. Must be at least 1.
812 * @max_sgl_segments: indicates the maximum number of sgl segments supported
814 * Value is Mandatory. Must be at least 1. Recommend at least 256.
816 * @max_dif_sgl_segments: indicates the maximum number of sgl segments
817 * supported by the LLDD for DIF operations.
818 * Value is Mandatory. Must be at least 1. Recommend at least 256.
820 * @dma_boundary: indicates the dma address boundary where dma mappings
821 * will be split across.
822 * Value is Mandatory. Typical value is 0xFFFFFFFF to split across
823 * 4Gig address boundarys
825 * @target_features: The LLDD sets bits in this field to correspond to
826 * optional features that are supported by the LLDD.
827 * Refer to the NVMET_FCTGTFEAT_xxx values.
828 * Value is Mandatory. Allowed to be zero.
830 * @target_priv_sz: The LLDD sets this field to the amount of additional
831 * memory that it would like fc nvme layer to allocate on the LLDD's
832 * behalf whenever a targetport is allocated. The additional memory
833 * area solely for the of the LLDD and its location is specified by
834 * the targetport->private pointer.
835 * Value is Mandatory. Allowed to be zero.
837 struct nvmet_fc_target_template {
838 void (*targetport_delete)(struct nvmet_fc_target_port *tgtport);
839 int (*xmt_ls_rsp)(struct nvmet_fc_target_port *tgtport,
840 struct nvmefc_tgt_ls_req *tls_req);
841 int (*fcp_op)(struct nvmet_fc_target_port *tgtport,
842 struct nvmefc_tgt_fcp_req *fcpreq);
843 void (*fcp_abort)(struct nvmet_fc_target_port *tgtport,
844 struct nvmefc_tgt_fcp_req *fcpreq);
845 void (*fcp_req_release)(struct nvmet_fc_target_port *tgtport,
846 struct nvmefc_tgt_fcp_req *fcpreq);
847 void (*defer_rcv)(struct nvmet_fc_target_port *tgtport,
848 struct nvmefc_tgt_fcp_req *fcpreq);
851 u16 max_sgl_segments;
852 u16 max_dif_sgl_segments;
861 int nvmet_fc_register_targetport(struct nvmet_fc_port_info *portinfo,
862 struct nvmet_fc_target_template *template,
864 struct nvmet_fc_target_port **tgtport_p);
866 int nvmet_fc_unregister_targetport(struct nvmet_fc_target_port *tgtport);
868 int nvmet_fc_rcv_ls_req(struct nvmet_fc_target_port *tgtport,
869 struct nvmefc_tgt_ls_req *lsreq,
870 void *lsreqbuf, u32 lsreqbuf_len);
872 int nvmet_fc_rcv_fcp_req(struct nvmet_fc_target_port *tgtport,
873 struct nvmefc_tgt_fcp_req *fcpreq,
874 void *cmdiubuf, u32 cmdiubuf_len);
876 void nvmet_fc_rcv_fcp_abort(struct nvmet_fc_target_port *tgtport,
877 struct nvmefc_tgt_fcp_req *fcpreq);
879 #endif /* _NVME_FC_DRIVER_H */