2 * Copyright (c) 2016 Avago Technologies. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful.
9 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
10 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
11 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO
12 * THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.
13 * See the GNU General Public License for more details, a copy of which
14 * can be found in the file COPYING included with this package
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/module.h>
19 #include <linux/parser.h>
20 #include <uapi/scsi/fc/fc_fs.h>
21 #include <uapi/scsi/fc/fc_els.h>
22 #include <linux/delay.h>
26 #include <linux/nvme-fc-driver.h>
27 #include <linux/nvme-fc.h>
30 /* *************************** Data Structures/Defines ****************** */
34 * We handle AEN commands ourselves and don't even let the
35 * block layer know about them.
37 #define NVME_FC_NR_AEN_COMMANDS 1
38 #define NVME_FC_AQ_BLKMQ_DEPTH \
39 (NVMF_AQ_DEPTH - NVME_FC_NR_AEN_COMMANDS)
40 #define AEN_CMDID_BASE (NVME_FC_AQ_BLKMQ_DEPTH + 1)
42 enum nvme_fc_queue_flags {
43 NVME_FC_Q_CONNECTED = (1 << 0),
46 #define NVMEFC_QUEUE_DELAY 3 /* ms units */
48 struct nvme_fc_queue {
49 struct nvme_fc_ctrl *ctrl;
51 struct blk_mq_hw_ctx *hctx;
54 size_t cmnd_capsule_len;
63 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
65 enum nvme_fcop_flags {
66 FCOP_FLAGS_TERMIO = (1 << 0),
67 FCOP_FLAGS_RELEASED = (1 << 1),
68 FCOP_FLAGS_COMPLETE = (1 << 2),
69 FCOP_FLAGS_AEN = (1 << 3),
72 struct nvmefc_ls_req_op {
73 struct nvmefc_ls_req ls_req;
75 struct nvme_fc_rport *rport;
76 struct nvme_fc_queue *queue;
81 struct completion ls_done;
82 struct list_head lsreq_list; /* rport->ls_req_list */
86 enum nvme_fcpop_state {
87 FCPOP_STATE_UNINIT = 0,
89 FCPOP_STATE_ACTIVE = 2,
90 FCPOP_STATE_ABORTED = 3,
91 FCPOP_STATE_COMPLETE = 4,
94 struct nvme_fc_fcp_op {
95 struct nvme_request nreq; /*
98 * the 1st element in the
100 * associated with the
103 struct nvmefc_fcp_req fcp_req;
105 struct nvme_fc_ctrl *ctrl;
106 struct nvme_fc_queue *queue;
114 struct nvme_fc_cmd_iu cmd_iu;
115 struct nvme_fc_ersp_iu rsp_iu;
118 struct nvme_fc_lport {
119 struct nvme_fc_local_port localport;
122 struct list_head port_list; /* nvme_fc_port_list */
123 struct list_head endp_list;
124 struct device *dev; /* physical device for dma */
125 struct nvme_fc_port_template *ops;
127 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
129 struct nvme_fc_rport {
130 struct nvme_fc_remote_port remoteport;
132 struct list_head endp_list; /* for lport->endp_list */
133 struct list_head ctrl_list;
134 struct list_head ls_req_list;
135 struct device *dev; /* physical device for dma */
136 struct nvme_fc_lport *lport;
139 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */
141 enum nvme_fcctrl_flags {
142 FCCTRL_TERMIO = (1 << 0),
145 struct nvme_fc_ctrl {
147 struct nvme_fc_queue *queues;
149 struct nvme_fc_lport *lport;
150 struct nvme_fc_rport *rport;
158 struct list_head ctrl_list; /* rport->ctrl_list */
160 struct blk_mq_tag_set admin_tag_set;
161 struct blk_mq_tag_set tag_set;
163 struct work_struct delete_work;
164 struct work_struct reset_work;
165 struct delayed_work connect_work;
171 struct nvme_fc_fcp_op aen_ops[NVME_FC_NR_AEN_COMMANDS];
173 struct nvme_ctrl ctrl;
176 static inline struct nvme_fc_ctrl *
177 to_fc_ctrl(struct nvme_ctrl *ctrl)
179 return container_of(ctrl, struct nvme_fc_ctrl, ctrl);
182 static inline struct nvme_fc_lport *
183 localport_to_lport(struct nvme_fc_local_port *portptr)
185 return container_of(portptr, struct nvme_fc_lport, localport);
188 static inline struct nvme_fc_rport *
189 remoteport_to_rport(struct nvme_fc_remote_port *portptr)
191 return container_of(portptr, struct nvme_fc_rport, remoteport);
194 static inline struct nvmefc_ls_req_op *
195 ls_req_to_lsop(struct nvmefc_ls_req *lsreq)
197 return container_of(lsreq, struct nvmefc_ls_req_op, ls_req);
200 static inline struct nvme_fc_fcp_op *
201 fcp_req_to_fcp_op(struct nvmefc_fcp_req *fcpreq)
203 return container_of(fcpreq, struct nvme_fc_fcp_op, fcp_req);
208 /* *************************** Globals **************************** */
211 static DEFINE_SPINLOCK(nvme_fc_lock);
213 static LIST_HEAD(nvme_fc_lport_list);
214 static DEFINE_IDA(nvme_fc_local_port_cnt);
215 static DEFINE_IDA(nvme_fc_ctrl_cnt);
220 /* *********************** FC-NVME Port Management ************************ */
222 static int __nvme_fc_del_ctrl(struct nvme_fc_ctrl *);
223 static void __nvme_fc_delete_hw_queue(struct nvme_fc_ctrl *,
224 struct nvme_fc_queue *, unsigned int);
228 * nvme_fc_register_localport - transport entry point called by an
229 * LLDD to register the existence of a NVME
231 * @pinfo: pointer to information about the port to be registered
232 * @template: LLDD entrypoints and operational parameters for the port
233 * @dev: physical hardware device node port corresponds to. Will be
234 * used for DMA mappings
235 * @lport_p: pointer to a local port pointer. Upon success, the routine
236 * will allocate a nvme_fc_local_port structure and place its
237 * address in the local port pointer. Upon failure, local port
238 * pointer will be set to 0.
241 * a completion status. Must be 0 upon success; a negative errno
242 * (ex: -ENXIO) upon failure.
245 nvme_fc_register_localport(struct nvme_fc_port_info *pinfo,
246 struct nvme_fc_port_template *template,
248 struct nvme_fc_local_port **portptr)
250 struct nvme_fc_lport *newrec;
254 if (!template->localport_delete || !template->remoteport_delete ||
255 !template->ls_req || !template->fcp_io ||
256 !template->ls_abort || !template->fcp_abort ||
257 !template->max_hw_queues || !template->max_sgl_segments ||
258 !template->max_dif_sgl_segments || !template->dma_boundary) {
260 goto out_reghost_failed;
263 newrec = kmalloc((sizeof(*newrec) + template->local_priv_sz),
267 goto out_reghost_failed;
270 idx = ida_simple_get(&nvme_fc_local_port_cnt, 0, 0, GFP_KERNEL);
276 if (!get_device(dev) && dev) {
281 INIT_LIST_HEAD(&newrec->port_list);
282 INIT_LIST_HEAD(&newrec->endp_list);
283 kref_init(&newrec->ref);
284 newrec->ops = template;
286 ida_init(&newrec->endp_cnt);
287 newrec->localport.private = &newrec[1];
288 newrec->localport.node_name = pinfo->node_name;
289 newrec->localport.port_name = pinfo->port_name;
290 newrec->localport.port_role = pinfo->port_role;
291 newrec->localport.port_id = pinfo->port_id;
292 newrec->localport.port_state = FC_OBJSTATE_ONLINE;
293 newrec->localport.port_num = idx;
295 spin_lock_irqsave(&nvme_fc_lock, flags);
296 list_add_tail(&newrec->port_list, &nvme_fc_lport_list);
297 spin_unlock_irqrestore(&nvme_fc_lock, flags);
300 dma_set_seg_boundary(dev, template->dma_boundary);
302 *portptr = &newrec->localport;
306 ida_simple_remove(&nvme_fc_local_port_cnt, idx);
314 EXPORT_SYMBOL_GPL(nvme_fc_register_localport);
317 nvme_fc_free_lport(struct kref *ref)
319 struct nvme_fc_lport *lport =
320 container_of(ref, struct nvme_fc_lport, ref);
323 WARN_ON(lport->localport.port_state != FC_OBJSTATE_DELETED);
324 WARN_ON(!list_empty(&lport->endp_list));
326 /* remove from transport list */
327 spin_lock_irqsave(&nvme_fc_lock, flags);
328 list_del(&lport->port_list);
329 spin_unlock_irqrestore(&nvme_fc_lock, flags);
331 /* let the LLDD know we've finished tearing it down */
332 lport->ops->localport_delete(&lport->localport);
334 ida_simple_remove(&nvme_fc_local_port_cnt, lport->localport.port_num);
335 ida_destroy(&lport->endp_cnt);
337 put_device(lport->dev);
343 nvme_fc_lport_put(struct nvme_fc_lport *lport)
345 kref_put(&lport->ref, nvme_fc_free_lport);
349 nvme_fc_lport_get(struct nvme_fc_lport *lport)
351 return kref_get_unless_zero(&lport->ref);
355 * nvme_fc_unregister_localport - transport entry point called by an
356 * LLDD to deregister/remove a previously
357 * registered a NVME host FC port.
358 * @localport: pointer to the (registered) local port that is to be
362 * a completion status. Must be 0 upon success; a negative errno
363 * (ex: -ENXIO) upon failure.
366 nvme_fc_unregister_localport(struct nvme_fc_local_port *portptr)
368 struct nvme_fc_lport *lport = localport_to_lport(portptr);
374 spin_lock_irqsave(&nvme_fc_lock, flags);
376 if (portptr->port_state != FC_OBJSTATE_ONLINE) {
377 spin_unlock_irqrestore(&nvme_fc_lock, flags);
380 portptr->port_state = FC_OBJSTATE_DELETED;
382 spin_unlock_irqrestore(&nvme_fc_lock, flags);
384 nvme_fc_lport_put(lport);
388 EXPORT_SYMBOL_GPL(nvme_fc_unregister_localport);
391 * nvme_fc_register_remoteport - transport entry point called by an
392 * LLDD to register the existence of a NVME
393 * subsystem FC port on its fabric.
394 * @localport: pointer to the (registered) local port that the remote
395 * subsystem port is connected to.
396 * @pinfo: pointer to information about the port to be registered
397 * @rport_p: pointer to a remote port pointer. Upon success, the routine
398 * will allocate a nvme_fc_remote_port structure and place its
399 * address in the remote port pointer. Upon failure, remote port
400 * pointer will be set to 0.
403 * a completion status. Must be 0 upon success; a negative errno
404 * (ex: -ENXIO) upon failure.
407 nvme_fc_register_remoteport(struct nvme_fc_local_port *localport,
408 struct nvme_fc_port_info *pinfo,
409 struct nvme_fc_remote_port **portptr)
411 struct nvme_fc_lport *lport = localport_to_lport(localport);
412 struct nvme_fc_rport *newrec;
416 newrec = kmalloc((sizeof(*newrec) + lport->ops->remote_priv_sz),
420 goto out_reghost_failed;
423 if (!nvme_fc_lport_get(lport)) {
425 goto out_kfree_rport;
428 idx = ida_simple_get(&lport->endp_cnt, 0, 0, GFP_KERNEL);
434 INIT_LIST_HEAD(&newrec->endp_list);
435 INIT_LIST_HEAD(&newrec->ctrl_list);
436 INIT_LIST_HEAD(&newrec->ls_req_list);
437 kref_init(&newrec->ref);
438 spin_lock_init(&newrec->lock);
439 newrec->remoteport.localport = &lport->localport;
440 newrec->dev = lport->dev;
441 newrec->lport = lport;
442 newrec->remoteport.private = &newrec[1];
443 newrec->remoteport.port_role = pinfo->port_role;
444 newrec->remoteport.node_name = pinfo->node_name;
445 newrec->remoteport.port_name = pinfo->port_name;
446 newrec->remoteport.port_id = pinfo->port_id;
447 newrec->remoteport.port_state = FC_OBJSTATE_ONLINE;
448 newrec->remoteport.port_num = idx;
450 spin_lock_irqsave(&nvme_fc_lock, flags);
451 list_add_tail(&newrec->endp_list, &lport->endp_list);
452 spin_unlock_irqrestore(&nvme_fc_lock, flags);
454 *portptr = &newrec->remoteport;
458 nvme_fc_lport_put(lport);
465 EXPORT_SYMBOL_GPL(nvme_fc_register_remoteport);
468 nvme_fc_free_rport(struct kref *ref)
470 struct nvme_fc_rport *rport =
471 container_of(ref, struct nvme_fc_rport, ref);
472 struct nvme_fc_lport *lport =
473 localport_to_lport(rport->remoteport.localport);
476 WARN_ON(rport->remoteport.port_state != FC_OBJSTATE_DELETED);
477 WARN_ON(!list_empty(&rport->ctrl_list));
479 /* remove from lport list */
480 spin_lock_irqsave(&nvme_fc_lock, flags);
481 list_del(&rport->endp_list);
482 spin_unlock_irqrestore(&nvme_fc_lock, flags);
484 /* let the LLDD know we've finished tearing it down */
485 lport->ops->remoteport_delete(&rport->remoteport);
487 ida_simple_remove(&lport->endp_cnt, rport->remoteport.port_num);
491 nvme_fc_lport_put(lport);
495 nvme_fc_rport_put(struct nvme_fc_rport *rport)
497 kref_put(&rport->ref, nvme_fc_free_rport);
501 nvme_fc_rport_get(struct nvme_fc_rport *rport)
503 return kref_get_unless_zero(&rport->ref);
507 nvme_fc_abort_lsops(struct nvme_fc_rport *rport)
509 struct nvmefc_ls_req_op *lsop;
513 spin_lock_irqsave(&rport->lock, flags);
515 list_for_each_entry(lsop, &rport->ls_req_list, lsreq_list) {
516 if (!(lsop->flags & FCOP_FLAGS_TERMIO)) {
517 lsop->flags |= FCOP_FLAGS_TERMIO;
518 spin_unlock_irqrestore(&rport->lock, flags);
519 rport->lport->ops->ls_abort(&rport->lport->localport,
525 spin_unlock_irqrestore(&rport->lock, flags);
531 * nvme_fc_unregister_remoteport - transport entry point called by an
532 * LLDD to deregister/remove a previously
533 * registered a NVME subsystem FC port.
534 * @remoteport: pointer to the (registered) remote port that is to be
538 * a completion status. Must be 0 upon success; a negative errno
539 * (ex: -ENXIO) upon failure.
542 nvme_fc_unregister_remoteport(struct nvme_fc_remote_port *portptr)
544 struct nvme_fc_rport *rport = remoteport_to_rport(portptr);
545 struct nvme_fc_ctrl *ctrl;
551 spin_lock_irqsave(&rport->lock, flags);
553 if (portptr->port_state != FC_OBJSTATE_ONLINE) {
554 spin_unlock_irqrestore(&rport->lock, flags);
557 portptr->port_state = FC_OBJSTATE_DELETED;
559 /* tear down all associations to the remote port */
560 list_for_each_entry(ctrl, &rport->ctrl_list, ctrl_list)
561 __nvme_fc_del_ctrl(ctrl);
563 spin_unlock_irqrestore(&rport->lock, flags);
565 nvme_fc_abort_lsops(rport);
567 nvme_fc_rport_put(rport);
570 EXPORT_SYMBOL_GPL(nvme_fc_unregister_remoteport);
573 /* *********************** FC-NVME DMA Handling **************************** */
576 * The fcloop device passes in a NULL device pointer. Real LLD's will
577 * pass in a valid device pointer. If NULL is passed to the dma mapping
578 * routines, depending on the platform, it may or may not succeed, and
582 * Wrapper all the dma routines and check the dev pointer.
584 * If simple mappings (return just a dma address, we'll noop them,
585 * returning a dma address of 0.
587 * On more complex mappings (dma_map_sg), a pseudo routine fills
588 * in the scatter list, setting all dma addresses to 0.
591 static inline dma_addr_t
592 fc_dma_map_single(struct device *dev, void *ptr, size_t size,
593 enum dma_data_direction dir)
595 return dev ? dma_map_single(dev, ptr, size, dir) : (dma_addr_t)0L;
599 fc_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
601 return dev ? dma_mapping_error(dev, dma_addr) : 0;
605 fc_dma_unmap_single(struct device *dev, dma_addr_t addr, size_t size,
606 enum dma_data_direction dir)
609 dma_unmap_single(dev, addr, size, dir);
613 fc_dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, size_t size,
614 enum dma_data_direction dir)
617 dma_sync_single_for_cpu(dev, addr, size, dir);
621 fc_dma_sync_single_for_device(struct device *dev, dma_addr_t addr, size_t size,
622 enum dma_data_direction dir)
625 dma_sync_single_for_device(dev, addr, size, dir);
628 /* pseudo dma_map_sg call */
630 fc_map_sg(struct scatterlist *sg, int nents)
632 struct scatterlist *s;
635 WARN_ON(nents == 0 || sg[0].length == 0);
637 for_each_sg(sg, s, nents, i) {
639 #ifdef CONFIG_NEED_SG_DMA_LENGTH
640 s->dma_length = s->length;
647 fc_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
648 enum dma_data_direction dir)
650 return dev ? dma_map_sg(dev, sg, nents, dir) : fc_map_sg(sg, nents);
654 fc_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
655 enum dma_data_direction dir)
658 dma_unmap_sg(dev, sg, nents, dir);
662 /* *********************** FC-NVME LS Handling **************************** */
664 static void nvme_fc_ctrl_put(struct nvme_fc_ctrl *);
665 static int nvme_fc_ctrl_get(struct nvme_fc_ctrl *);
669 __nvme_fc_finish_ls_req(struct nvmefc_ls_req_op *lsop)
671 struct nvme_fc_rport *rport = lsop->rport;
672 struct nvmefc_ls_req *lsreq = &lsop->ls_req;
675 spin_lock_irqsave(&rport->lock, flags);
677 if (!lsop->req_queued) {
678 spin_unlock_irqrestore(&rport->lock, flags);
682 list_del(&lsop->lsreq_list);
684 lsop->req_queued = false;
686 spin_unlock_irqrestore(&rport->lock, flags);
688 fc_dma_unmap_single(rport->dev, lsreq->rqstdma,
689 (lsreq->rqstlen + lsreq->rsplen),
692 nvme_fc_rport_put(rport);
696 __nvme_fc_send_ls_req(struct nvme_fc_rport *rport,
697 struct nvmefc_ls_req_op *lsop,
698 void (*done)(struct nvmefc_ls_req *req, int status))
700 struct nvmefc_ls_req *lsreq = &lsop->ls_req;
704 if (rport->remoteport.port_state != FC_OBJSTATE_ONLINE)
705 return -ECONNREFUSED;
707 if (!nvme_fc_rport_get(rport))
712 lsop->req_queued = false;
713 INIT_LIST_HEAD(&lsop->lsreq_list);
714 init_completion(&lsop->ls_done);
716 lsreq->rqstdma = fc_dma_map_single(rport->dev, lsreq->rqstaddr,
717 lsreq->rqstlen + lsreq->rsplen,
719 if (fc_dma_mapping_error(rport->dev, lsreq->rqstdma)) {
723 lsreq->rspdma = lsreq->rqstdma + lsreq->rqstlen;
725 spin_lock_irqsave(&rport->lock, flags);
727 list_add_tail(&lsop->lsreq_list, &rport->ls_req_list);
729 lsop->req_queued = true;
731 spin_unlock_irqrestore(&rport->lock, flags);
733 ret = rport->lport->ops->ls_req(&rport->lport->localport,
734 &rport->remoteport, lsreq);
741 lsop->ls_error = ret;
742 spin_lock_irqsave(&rport->lock, flags);
743 lsop->req_queued = false;
744 list_del(&lsop->lsreq_list);
745 spin_unlock_irqrestore(&rport->lock, flags);
746 fc_dma_unmap_single(rport->dev, lsreq->rqstdma,
747 (lsreq->rqstlen + lsreq->rsplen),
750 nvme_fc_rport_put(rport);
756 nvme_fc_send_ls_req_done(struct nvmefc_ls_req *lsreq, int status)
758 struct nvmefc_ls_req_op *lsop = ls_req_to_lsop(lsreq);
760 lsop->ls_error = status;
761 complete(&lsop->ls_done);
765 nvme_fc_send_ls_req(struct nvme_fc_rport *rport, struct nvmefc_ls_req_op *lsop)
767 struct nvmefc_ls_req *lsreq = &lsop->ls_req;
768 struct fcnvme_ls_rjt *rjt = lsreq->rspaddr;
771 ret = __nvme_fc_send_ls_req(rport, lsop, nvme_fc_send_ls_req_done);
775 * No timeout/not interruptible as we need the struct
776 * to exist until the lldd calls us back. Thus mandate
777 * wait until driver calls back. lldd responsible for
780 wait_for_completion(&lsop->ls_done);
782 __nvme_fc_finish_ls_req(lsop);
784 ret = lsop->ls_error;
790 /* ACC or RJT payload ? */
791 if (rjt->w0.ls_cmd == FCNVME_LS_RJT)
798 nvme_fc_send_ls_req_async(struct nvme_fc_rport *rport,
799 struct nvmefc_ls_req_op *lsop,
800 void (*done)(struct nvmefc_ls_req *req, int status))
802 /* don't wait for completion */
804 return __nvme_fc_send_ls_req(rport, lsop, done);
807 /* Validation Error indexes into the string table below */
811 VERR_LSDESC_RQST = 2,
812 VERR_LSDESC_RQST_LEN = 3,
814 VERR_ASSOC_ID_LEN = 5,
816 VERR_CONN_ID_LEN = 7,
818 VERR_CR_ASSOC_ACC_LEN = 9,
820 VERR_CR_CONN_ACC_LEN = 11,
822 VERR_DISCONN_ACC_LEN = 13,
825 static char *validation_errors[] = {
829 "Bad LSDESC_RQST Length",
830 "Not Association ID",
831 "Bad Association ID Length",
833 "Bad Connection ID Length",
835 "Bad CR_ASSOC ACC Length",
837 "Bad CR_CONN ACC Length",
838 "Not Disconnect Rqst",
839 "Bad Disconnect ACC Length",
843 nvme_fc_connect_admin_queue(struct nvme_fc_ctrl *ctrl,
844 struct nvme_fc_queue *queue, u16 qsize, u16 ersp_ratio)
846 struct nvmefc_ls_req_op *lsop;
847 struct nvmefc_ls_req *lsreq;
848 struct fcnvme_ls_cr_assoc_rqst *assoc_rqst;
849 struct fcnvme_ls_cr_assoc_acc *assoc_acc;
852 lsop = kzalloc((sizeof(*lsop) +
853 ctrl->lport->ops->lsrqst_priv_sz +
854 sizeof(*assoc_rqst) + sizeof(*assoc_acc)), GFP_KERNEL);
859 lsreq = &lsop->ls_req;
861 lsreq->private = (void *)&lsop[1];
862 assoc_rqst = (struct fcnvme_ls_cr_assoc_rqst *)
863 (lsreq->private + ctrl->lport->ops->lsrqst_priv_sz);
864 assoc_acc = (struct fcnvme_ls_cr_assoc_acc *)&assoc_rqst[1];
866 assoc_rqst->w0.ls_cmd = FCNVME_LS_CREATE_ASSOCIATION;
867 assoc_rqst->desc_list_len =
868 cpu_to_be32(sizeof(struct fcnvme_lsdesc_cr_assoc_cmd));
870 assoc_rqst->assoc_cmd.desc_tag =
871 cpu_to_be32(FCNVME_LSDESC_CREATE_ASSOC_CMD);
872 assoc_rqst->assoc_cmd.desc_len =
874 sizeof(struct fcnvme_lsdesc_cr_assoc_cmd));
876 assoc_rqst->assoc_cmd.ersp_ratio = cpu_to_be16(ersp_ratio);
877 assoc_rqst->assoc_cmd.sqsize = cpu_to_be16(qsize);
878 /* Linux supports only Dynamic controllers */
879 assoc_rqst->assoc_cmd.cntlid = cpu_to_be16(0xffff);
880 uuid_copy(&assoc_rqst->assoc_cmd.hostid, &ctrl->ctrl.opts->host->id);
881 strncpy(assoc_rqst->assoc_cmd.hostnqn, ctrl->ctrl.opts->host->nqn,
882 min(FCNVME_ASSOC_HOSTNQN_LEN, NVMF_NQN_SIZE));
883 strncpy(assoc_rqst->assoc_cmd.subnqn, ctrl->ctrl.opts->subsysnqn,
884 min(FCNVME_ASSOC_SUBNQN_LEN, NVMF_NQN_SIZE));
887 lsreq->rqstaddr = assoc_rqst;
888 lsreq->rqstlen = sizeof(*assoc_rqst);
889 lsreq->rspaddr = assoc_acc;
890 lsreq->rsplen = sizeof(*assoc_acc);
891 lsreq->timeout = NVME_FC_CONNECT_TIMEOUT_SEC;
893 ret = nvme_fc_send_ls_req(ctrl->rport, lsop);
895 goto out_free_buffer;
897 /* process connect LS completion */
899 /* validate the ACC response */
900 if (assoc_acc->hdr.w0.ls_cmd != FCNVME_LS_ACC)
902 else if (assoc_acc->hdr.desc_list_len !=
904 sizeof(struct fcnvme_ls_cr_assoc_acc)))
905 fcret = VERR_CR_ASSOC_ACC_LEN;
906 else if (assoc_acc->hdr.rqst.desc_tag !=
907 cpu_to_be32(FCNVME_LSDESC_RQST))
908 fcret = VERR_LSDESC_RQST;
909 else if (assoc_acc->hdr.rqst.desc_len !=
910 fcnvme_lsdesc_len(sizeof(struct fcnvme_lsdesc_rqst)))
911 fcret = VERR_LSDESC_RQST_LEN;
912 else if (assoc_acc->hdr.rqst.w0.ls_cmd != FCNVME_LS_CREATE_ASSOCIATION)
913 fcret = VERR_CR_ASSOC;
914 else if (assoc_acc->associd.desc_tag !=
915 cpu_to_be32(FCNVME_LSDESC_ASSOC_ID))
916 fcret = VERR_ASSOC_ID;
917 else if (assoc_acc->associd.desc_len !=
919 sizeof(struct fcnvme_lsdesc_assoc_id)))
920 fcret = VERR_ASSOC_ID_LEN;
921 else if (assoc_acc->connectid.desc_tag !=
922 cpu_to_be32(FCNVME_LSDESC_CONN_ID))
923 fcret = VERR_CONN_ID;
924 else if (assoc_acc->connectid.desc_len !=
925 fcnvme_lsdesc_len(sizeof(struct fcnvme_lsdesc_conn_id)))
926 fcret = VERR_CONN_ID_LEN;
931 "q %d connect failed: %s\n",
932 queue->qnum, validation_errors[fcret]);
934 ctrl->association_id =
935 be64_to_cpu(assoc_acc->associd.association_id);
936 queue->connection_id =
937 be64_to_cpu(assoc_acc->connectid.connection_id);
938 set_bit(NVME_FC_Q_CONNECTED, &queue->flags);
946 "queue %d connect admin queue failed (%d).\n",
952 nvme_fc_connect_queue(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue,
953 u16 qsize, u16 ersp_ratio)
955 struct nvmefc_ls_req_op *lsop;
956 struct nvmefc_ls_req *lsreq;
957 struct fcnvme_ls_cr_conn_rqst *conn_rqst;
958 struct fcnvme_ls_cr_conn_acc *conn_acc;
961 lsop = kzalloc((sizeof(*lsop) +
962 ctrl->lport->ops->lsrqst_priv_sz +
963 sizeof(*conn_rqst) + sizeof(*conn_acc)), GFP_KERNEL);
968 lsreq = &lsop->ls_req;
970 lsreq->private = (void *)&lsop[1];
971 conn_rqst = (struct fcnvme_ls_cr_conn_rqst *)
972 (lsreq->private + ctrl->lport->ops->lsrqst_priv_sz);
973 conn_acc = (struct fcnvme_ls_cr_conn_acc *)&conn_rqst[1];
975 conn_rqst->w0.ls_cmd = FCNVME_LS_CREATE_CONNECTION;
976 conn_rqst->desc_list_len = cpu_to_be32(
977 sizeof(struct fcnvme_lsdesc_assoc_id) +
978 sizeof(struct fcnvme_lsdesc_cr_conn_cmd));
980 conn_rqst->associd.desc_tag = cpu_to_be32(FCNVME_LSDESC_ASSOC_ID);
981 conn_rqst->associd.desc_len =
983 sizeof(struct fcnvme_lsdesc_assoc_id));
984 conn_rqst->associd.association_id = cpu_to_be64(ctrl->association_id);
985 conn_rqst->connect_cmd.desc_tag =
986 cpu_to_be32(FCNVME_LSDESC_CREATE_CONN_CMD);
987 conn_rqst->connect_cmd.desc_len =
989 sizeof(struct fcnvme_lsdesc_cr_conn_cmd));
990 conn_rqst->connect_cmd.ersp_ratio = cpu_to_be16(ersp_ratio);
991 conn_rqst->connect_cmd.qid = cpu_to_be16(queue->qnum);
992 conn_rqst->connect_cmd.sqsize = cpu_to_be16(qsize);
995 lsreq->rqstaddr = conn_rqst;
996 lsreq->rqstlen = sizeof(*conn_rqst);
997 lsreq->rspaddr = conn_acc;
998 lsreq->rsplen = sizeof(*conn_acc);
999 lsreq->timeout = NVME_FC_CONNECT_TIMEOUT_SEC;
1001 ret = nvme_fc_send_ls_req(ctrl->rport, lsop);
1003 goto out_free_buffer;
1005 /* process connect LS completion */
1007 /* validate the ACC response */
1008 if (conn_acc->hdr.w0.ls_cmd != FCNVME_LS_ACC)
1010 else if (conn_acc->hdr.desc_list_len !=
1011 fcnvme_lsdesc_len(sizeof(struct fcnvme_ls_cr_conn_acc)))
1012 fcret = VERR_CR_CONN_ACC_LEN;
1013 else if (conn_acc->hdr.rqst.desc_tag != cpu_to_be32(FCNVME_LSDESC_RQST))
1014 fcret = VERR_LSDESC_RQST;
1015 else if (conn_acc->hdr.rqst.desc_len !=
1016 fcnvme_lsdesc_len(sizeof(struct fcnvme_lsdesc_rqst)))
1017 fcret = VERR_LSDESC_RQST_LEN;
1018 else if (conn_acc->hdr.rqst.w0.ls_cmd != FCNVME_LS_CREATE_CONNECTION)
1019 fcret = VERR_CR_CONN;
1020 else if (conn_acc->connectid.desc_tag !=
1021 cpu_to_be32(FCNVME_LSDESC_CONN_ID))
1022 fcret = VERR_CONN_ID;
1023 else if (conn_acc->connectid.desc_len !=
1024 fcnvme_lsdesc_len(sizeof(struct fcnvme_lsdesc_conn_id)))
1025 fcret = VERR_CONN_ID_LEN;
1030 "q %d connect failed: %s\n",
1031 queue->qnum, validation_errors[fcret]);
1033 queue->connection_id =
1034 be64_to_cpu(conn_acc->connectid.connection_id);
1035 set_bit(NVME_FC_Q_CONNECTED, &queue->flags);
1043 "queue %d connect command failed (%d).\n",
1049 nvme_fc_disconnect_assoc_done(struct nvmefc_ls_req *lsreq, int status)
1051 struct nvmefc_ls_req_op *lsop = ls_req_to_lsop(lsreq);
1053 __nvme_fc_finish_ls_req(lsop);
1055 /* fc-nvme iniator doesn't care about success or failure of cmd */
1061 * This routine sends a FC-NVME LS to disconnect (aka terminate)
1062 * the FC-NVME Association. Terminating the association also
1063 * terminates the FC-NVME connections (per queue, both admin and io
1064 * queues) that are part of the association. E.g. things are torn
1065 * down, and the related FC-NVME Association ID and Connection IDs
1068 * The behavior of the fc-nvme initiator is such that it's
1069 * understanding of the association and connections will implicitly
1070 * be torn down. The action is implicit as it may be due to a loss of
1071 * connectivity with the fc-nvme target, so you may never get a
1072 * response even if you tried. As such, the action of this routine
1073 * is to asynchronously send the LS, ignore any results of the LS, and
1074 * continue on with terminating the association. If the fc-nvme target
1075 * is present and receives the LS, it too can tear down.
1078 nvme_fc_xmt_disconnect_assoc(struct nvme_fc_ctrl *ctrl)
1080 struct fcnvme_ls_disconnect_rqst *discon_rqst;
1081 struct fcnvme_ls_disconnect_acc *discon_acc;
1082 struct nvmefc_ls_req_op *lsop;
1083 struct nvmefc_ls_req *lsreq;
1086 lsop = kzalloc((sizeof(*lsop) +
1087 ctrl->lport->ops->lsrqst_priv_sz +
1088 sizeof(*discon_rqst) + sizeof(*discon_acc)),
1091 /* couldn't sent it... too bad */
1094 lsreq = &lsop->ls_req;
1096 lsreq->private = (void *)&lsop[1];
1097 discon_rqst = (struct fcnvme_ls_disconnect_rqst *)
1098 (lsreq->private + ctrl->lport->ops->lsrqst_priv_sz);
1099 discon_acc = (struct fcnvme_ls_disconnect_acc *)&discon_rqst[1];
1101 discon_rqst->w0.ls_cmd = FCNVME_LS_DISCONNECT;
1102 discon_rqst->desc_list_len = cpu_to_be32(
1103 sizeof(struct fcnvme_lsdesc_assoc_id) +
1104 sizeof(struct fcnvme_lsdesc_disconn_cmd));
1106 discon_rqst->associd.desc_tag = cpu_to_be32(FCNVME_LSDESC_ASSOC_ID);
1107 discon_rqst->associd.desc_len =
1109 sizeof(struct fcnvme_lsdesc_assoc_id));
1111 discon_rqst->associd.association_id = cpu_to_be64(ctrl->association_id);
1113 discon_rqst->discon_cmd.desc_tag = cpu_to_be32(
1114 FCNVME_LSDESC_DISCONN_CMD);
1115 discon_rqst->discon_cmd.desc_len =
1117 sizeof(struct fcnvme_lsdesc_disconn_cmd));
1118 discon_rqst->discon_cmd.scope = FCNVME_DISCONN_ASSOCIATION;
1119 discon_rqst->discon_cmd.id = cpu_to_be64(ctrl->association_id);
1121 lsreq->rqstaddr = discon_rqst;
1122 lsreq->rqstlen = sizeof(*discon_rqst);
1123 lsreq->rspaddr = discon_acc;
1124 lsreq->rsplen = sizeof(*discon_acc);
1125 lsreq->timeout = NVME_FC_CONNECT_TIMEOUT_SEC;
1127 ret = nvme_fc_send_ls_req_async(ctrl->rport, lsop,
1128 nvme_fc_disconnect_assoc_done);
1132 /* only meaningful part to terminating the association */
1133 ctrl->association_id = 0;
1137 /* *********************** NVME Ctrl Routines **************************** */
1139 static void __nvme_fc_final_op_cleanup(struct request *rq);
1140 static void nvme_fc_error_recovery(struct nvme_fc_ctrl *ctrl, char *errmsg);
1143 nvme_fc_reinit_request(void *data, struct request *rq)
1145 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
1146 struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu;
1148 memset(cmdiu, 0, sizeof(*cmdiu));
1149 cmdiu->scsi_id = NVME_CMD_SCSI_ID;
1150 cmdiu->fc_id = NVME_CMD_FC_ID;
1151 cmdiu->iu_len = cpu_to_be16(sizeof(*cmdiu) / sizeof(u32));
1152 memset(&op->rsp_iu, 0, sizeof(op->rsp_iu));
1158 __nvme_fc_exit_request(struct nvme_fc_ctrl *ctrl,
1159 struct nvme_fc_fcp_op *op)
1161 fc_dma_unmap_single(ctrl->lport->dev, op->fcp_req.rspdma,
1162 sizeof(op->rsp_iu), DMA_FROM_DEVICE);
1163 fc_dma_unmap_single(ctrl->lport->dev, op->fcp_req.cmddma,
1164 sizeof(op->cmd_iu), DMA_TO_DEVICE);
1166 atomic_set(&op->state, FCPOP_STATE_UNINIT);
1170 nvme_fc_exit_request(struct blk_mq_tag_set *set, struct request *rq,
1171 unsigned int hctx_idx)
1173 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
1175 return __nvme_fc_exit_request(set->driver_data, op);
1179 __nvme_fc_abort_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_fcp_op *op)
1183 state = atomic_xchg(&op->state, FCPOP_STATE_ABORTED);
1184 if (state != FCPOP_STATE_ACTIVE) {
1185 atomic_set(&op->state, state);
1189 ctrl->lport->ops->fcp_abort(&ctrl->lport->localport,
1190 &ctrl->rport->remoteport,
1191 op->queue->lldd_handle,
1198 nvme_fc_abort_aen_ops(struct nvme_fc_ctrl *ctrl)
1200 struct nvme_fc_fcp_op *aen_op = ctrl->aen_ops;
1201 unsigned long flags;
1204 for (i = 0; i < NVME_FC_NR_AEN_COMMANDS; i++, aen_op++) {
1205 if (atomic_read(&aen_op->state) != FCPOP_STATE_ACTIVE)
1208 spin_lock_irqsave(&ctrl->lock, flags);
1209 if (ctrl->flags & FCCTRL_TERMIO) {
1211 aen_op->flags |= FCOP_FLAGS_TERMIO;
1213 spin_unlock_irqrestore(&ctrl->lock, flags);
1215 ret = __nvme_fc_abort_op(ctrl, aen_op);
1218 * if __nvme_fc_abort_op failed the io wasn't
1219 * active. Thus this call path is running in
1220 * parallel to the io complete. Treat as non-error.
1223 /* back out the flags/counters */
1224 spin_lock_irqsave(&ctrl->lock, flags);
1225 if (ctrl->flags & FCCTRL_TERMIO)
1227 aen_op->flags &= ~FCOP_FLAGS_TERMIO;
1228 spin_unlock_irqrestore(&ctrl->lock, flags);
1235 __nvme_fc_fcpop_chk_teardowns(struct nvme_fc_ctrl *ctrl,
1236 struct nvme_fc_fcp_op *op)
1238 unsigned long flags;
1239 bool complete_rq = false;
1241 spin_lock_irqsave(&ctrl->lock, flags);
1242 if (unlikely(op->flags & FCOP_FLAGS_TERMIO)) {
1243 if (ctrl->flags & FCCTRL_TERMIO)
1246 if (op->flags & FCOP_FLAGS_RELEASED)
1249 op->flags |= FCOP_FLAGS_COMPLETE;
1250 spin_unlock_irqrestore(&ctrl->lock, flags);
1256 nvme_fc_fcpio_done(struct nvmefc_fcp_req *req)
1258 struct nvme_fc_fcp_op *op = fcp_req_to_fcp_op(req);
1259 struct request *rq = op->rq;
1260 struct nvmefc_fcp_req *freq = &op->fcp_req;
1261 struct nvme_fc_ctrl *ctrl = op->ctrl;
1262 struct nvme_fc_queue *queue = op->queue;
1263 struct nvme_completion *cqe = &op->rsp_iu.cqe;
1264 struct nvme_command *sqe = &op->cmd_iu.sqe;
1265 __le16 status = cpu_to_le16(NVME_SC_SUCCESS << 1);
1266 union nvme_result result;
1267 bool complete_rq, terminate_assoc = true;
1271 * The current linux implementation of a nvme controller
1272 * allocates a single tag set for all io queues and sizes
1273 * the io queues to fully hold all possible tags. Thus, the
1274 * implementation does not reference or care about the sqhd
1275 * value as it never needs to use the sqhd/sqtail pointers
1276 * for submission pacing.
1278 * This affects the FC-NVME implementation in two ways:
1279 * 1) As the value doesn't matter, we don't need to waste
1280 * cycles extracting it from ERSPs and stamping it in the
1281 * cases where the transport fabricates CQEs on successful
1283 * 2) The FC-NVME implementation requires that delivery of
1284 * ERSP completions are to go back to the nvme layer in order
1285 * relative to the rsn, such that the sqhd value will always
1286 * be "in order" for the nvme layer. As the nvme layer in
1287 * linux doesn't care about sqhd, there's no need to return
1291 * As the core nvme layer in linux currently does not look at
1292 * every field in the cqe - in cases where the FC transport must
1293 * fabricate a CQE, the following fields will not be set as they
1294 * are not referenced:
1295 * cqe.sqid, cqe.sqhd, cqe.command_id
1297 * Failure or error of an individual i/o, in a transport
1298 * detected fashion unrelated to the nvme completion status,
1299 * potentially cause the initiator and target sides to get out
1300 * of sync on SQ head/tail (aka outstanding io count allowed).
1301 * Per FC-NVME spec, failure of an individual command requires
1302 * the connection to be terminated, which in turn requires the
1303 * association to be terminated.
1306 fc_dma_sync_single_for_cpu(ctrl->lport->dev, op->fcp_req.rspdma,
1307 sizeof(op->rsp_iu), DMA_FROM_DEVICE);
1309 if (atomic_read(&op->state) == FCPOP_STATE_ABORTED)
1310 status = cpu_to_le16((NVME_SC_ABORT_REQ | NVME_SC_DNR) << 1);
1311 else if (freq->status)
1312 status = cpu_to_le16(NVME_SC_FC_TRANSPORT_ERROR << 1);
1315 * For the linux implementation, if we have an unsuccesful
1316 * status, they blk-mq layer can typically be called with the
1317 * non-zero status and the content of the cqe isn't important.
1323 * command completed successfully relative to the wire
1324 * protocol. However, validate anything received and
1325 * extract the status and result from the cqe (create it
1329 switch (freq->rcv_rsplen) {
1332 case NVME_FC_SIZEOF_ZEROS_RSP:
1334 * No response payload or 12 bytes of payload (which
1335 * should all be zeros) are considered successful and
1336 * no payload in the CQE by the transport.
1338 if (freq->transferred_length !=
1339 be32_to_cpu(op->cmd_iu.data_len)) {
1340 status = cpu_to_le16(NVME_SC_FC_TRANSPORT_ERROR << 1);
1346 case sizeof(struct nvme_fc_ersp_iu):
1348 * The ERSP IU contains a full completion with CQE.
1349 * Validate ERSP IU and look at cqe.
1351 if (unlikely(be16_to_cpu(op->rsp_iu.iu_len) !=
1352 (freq->rcv_rsplen / 4) ||
1353 be32_to_cpu(op->rsp_iu.xfrd_len) !=
1354 freq->transferred_length ||
1355 op->rsp_iu.status_code ||
1356 sqe->common.command_id != cqe->command_id)) {
1357 status = cpu_to_le16(NVME_SC_FC_TRANSPORT_ERROR << 1);
1360 result = cqe->result;
1361 status = cqe->status;
1365 status = cpu_to_le16(NVME_SC_FC_TRANSPORT_ERROR << 1);
1369 terminate_assoc = false;
1372 if (op->flags & FCOP_FLAGS_AEN) {
1373 nvme_complete_async_event(&queue->ctrl->ctrl, status, &result);
1374 complete_rq = __nvme_fc_fcpop_chk_teardowns(ctrl, op);
1375 atomic_set(&op->state, FCPOP_STATE_IDLE);
1376 op->flags = FCOP_FLAGS_AEN; /* clear other flags */
1377 nvme_fc_ctrl_put(ctrl);
1381 complete_rq = __nvme_fc_fcpop_chk_teardowns(ctrl, op);
1383 if (unlikely(op->flags & FCOP_FLAGS_TERMIO)) {
1384 status = cpu_to_le16(NVME_SC_ABORT_REQ << 1);
1385 if (blk_queue_dying(rq->q))
1386 status |= cpu_to_le16(NVME_SC_DNR << 1);
1388 nvme_end_request(rq, status, result);
1390 __nvme_fc_final_op_cleanup(rq);
1393 if (terminate_assoc)
1394 nvme_fc_error_recovery(ctrl, "transport detected io error");
1398 __nvme_fc_init_request(struct nvme_fc_ctrl *ctrl,
1399 struct nvme_fc_queue *queue, struct nvme_fc_fcp_op *op,
1400 struct request *rq, u32 rqno)
1402 struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu;
1405 memset(op, 0, sizeof(*op));
1406 op->fcp_req.cmdaddr = &op->cmd_iu;
1407 op->fcp_req.cmdlen = sizeof(op->cmd_iu);
1408 op->fcp_req.rspaddr = &op->rsp_iu;
1409 op->fcp_req.rsplen = sizeof(op->rsp_iu);
1410 op->fcp_req.done = nvme_fc_fcpio_done;
1411 op->fcp_req.first_sgl = (struct scatterlist *)&op[1];
1412 op->fcp_req.private = &op->fcp_req.first_sgl[SG_CHUNK_SIZE];
1418 cmdiu->scsi_id = NVME_CMD_SCSI_ID;
1419 cmdiu->fc_id = NVME_CMD_FC_ID;
1420 cmdiu->iu_len = cpu_to_be16(sizeof(*cmdiu) / sizeof(u32));
1422 op->fcp_req.cmddma = fc_dma_map_single(ctrl->lport->dev,
1423 &op->cmd_iu, sizeof(op->cmd_iu), DMA_TO_DEVICE);
1424 if (fc_dma_mapping_error(ctrl->lport->dev, op->fcp_req.cmddma)) {
1426 "FCP Op failed - cmdiu dma mapping failed.\n");
1431 op->fcp_req.rspdma = fc_dma_map_single(ctrl->lport->dev,
1432 &op->rsp_iu, sizeof(op->rsp_iu),
1434 if (fc_dma_mapping_error(ctrl->lport->dev, op->fcp_req.rspdma)) {
1436 "FCP Op failed - rspiu dma mapping failed.\n");
1440 atomic_set(&op->state, FCPOP_STATE_IDLE);
1446 nvme_fc_init_request(struct blk_mq_tag_set *set, struct request *rq,
1447 unsigned int hctx_idx, unsigned int numa_node)
1449 struct nvme_fc_ctrl *ctrl = set->driver_data;
1450 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
1451 int queue_idx = (set == &ctrl->tag_set) ? hctx_idx + 1 : 0;
1452 struct nvme_fc_queue *queue = &ctrl->queues[queue_idx];
1454 return __nvme_fc_init_request(ctrl, queue, op, rq, queue->rqcnt++);
1458 nvme_fc_init_aen_ops(struct nvme_fc_ctrl *ctrl)
1460 struct nvme_fc_fcp_op *aen_op;
1461 struct nvme_fc_cmd_iu *cmdiu;
1462 struct nvme_command *sqe;
1466 aen_op = ctrl->aen_ops;
1467 for (i = 0; i < NVME_FC_NR_AEN_COMMANDS; i++, aen_op++) {
1468 private = kzalloc(ctrl->lport->ops->fcprqst_priv_sz,
1473 cmdiu = &aen_op->cmd_iu;
1475 ret = __nvme_fc_init_request(ctrl, &ctrl->queues[0],
1476 aen_op, (struct request *)NULL,
1477 (AEN_CMDID_BASE + i));
1483 aen_op->flags = FCOP_FLAGS_AEN;
1484 aen_op->fcp_req.first_sgl = NULL; /* no sg list */
1485 aen_op->fcp_req.private = private;
1487 memset(sqe, 0, sizeof(*sqe));
1488 sqe->common.opcode = nvme_admin_async_event;
1489 /* Note: core layer may overwrite the sqe.command_id value */
1490 sqe->common.command_id = AEN_CMDID_BASE + i;
1496 nvme_fc_term_aen_ops(struct nvme_fc_ctrl *ctrl)
1498 struct nvme_fc_fcp_op *aen_op;
1501 aen_op = ctrl->aen_ops;
1502 for (i = 0; i < NVME_FC_NR_AEN_COMMANDS; i++, aen_op++) {
1503 if (!aen_op->fcp_req.private)
1506 __nvme_fc_exit_request(ctrl, aen_op);
1508 kfree(aen_op->fcp_req.private);
1509 aen_op->fcp_req.private = NULL;
1514 __nvme_fc_init_hctx(struct blk_mq_hw_ctx *hctx, struct nvme_fc_ctrl *ctrl,
1517 struct nvme_fc_queue *queue = &ctrl->queues[qidx];
1519 hctx->driver_data = queue;
1524 nvme_fc_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
1525 unsigned int hctx_idx)
1527 struct nvme_fc_ctrl *ctrl = data;
1529 __nvme_fc_init_hctx(hctx, ctrl, hctx_idx + 1);
1535 nvme_fc_init_admin_hctx(struct blk_mq_hw_ctx *hctx, void *data,
1536 unsigned int hctx_idx)
1538 struct nvme_fc_ctrl *ctrl = data;
1540 __nvme_fc_init_hctx(hctx, ctrl, hctx_idx);
1546 nvme_fc_init_queue(struct nvme_fc_ctrl *ctrl, int idx, size_t queue_size)
1548 struct nvme_fc_queue *queue;
1550 queue = &ctrl->queues[idx];
1551 memset(queue, 0, sizeof(*queue));
1554 atomic_set(&queue->csn, 1);
1555 queue->dev = ctrl->dev;
1558 queue->cmnd_capsule_len = ctrl->ctrl.ioccsz * 16;
1560 queue->cmnd_capsule_len = sizeof(struct nvme_command);
1562 queue->queue_size = queue_size;
1565 * Considered whether we should allocate buffers for all SQEs
1566 * and CQEs and dma map them - mapping their respective entries
1567 * into the request structures (kernel vm addr and dma address)
1568 * thus the driver could use the buffers/mappings directly.
1569 * It only makes sense if the LLDD would use them for its
1570 * messaging api. It's very unlikely most adapter api's would use
1571 * a native NVME sqe/cqe. More reasonable if FC-NVME IU payload
1572 * structures were used instead.
1577 * This routine terminates a queue at the transport level.
1578 * The transport has already ensured that all outstanding ios on
1579 * the queue have been terminated.
1580 * The transport will send a Disconnect LS request to terminate
1581 * the queue's connection. Termination of the admin queue will also
1582 * terminate the association at the target.
1585 nvme_fc_free_queue(struct nvme_fc_queue *queue)
1587 if (!test_and_clear_bit(NVME_FC_Q_CONNECTED, &queue->flags))
1591 * Current implementation never disconnects a single queue.
1592 * It always terminates a whole association. So there is never
1593 * a disconnect(queue) LS sent to the target.
1596 queue->connection_id = 0;
1597 clear_bit(NVME_FC_Q_CONNECTED, &queue->flags);
1601 __nvme_fc_delete_hw_queue(struct nvme_fc_ctrl *ctrl,
1602 struct nvme_fc_queue *queue, unsigned int qidx)
1604 if (ctrl->lport->ops->delete_queue)
1605 ctrl->lport->ops->delete_queue(&ctrl->lport->localport, qidx,
1606 queue->lldd_handle);
1607 queue->lldd_handle = NULL;
1611 nvme_fc_free_io_queues(struct nvme_fc_ctrl *ctrl)
1615 for (i = 1; i < ctrl->queue_count; i++)
1616 nvme_fc_free_queue(&ctrl->queues[i]);
1620 __nvme_fc_create_hw_queue(struct nvme_fc_ctrl *ctrl,
1621 struct nvme_fc_queue *queue, unsigned int qidx, u16 qsize)
1625 queue->lldd_handle = NULL;
1626 if (ctrl->lport->ops->create_queue)
1627 ret = ctrl->lport->ops->create_queue(&ctrl->lport->localport,
1628 qidx, qsize, &queue->lldd_handle);
1634 nvme_fc_delete_hw_io_queues(struct nvme_fc_ctrl *ctrl)
1636 struct nvme_fc_queue *queue = &ctrl->queues[ctrl->queue_count - 1];
1639 for (i = ctrl->queue_count - 1; i >= 1; i--, queue--)
1640 __nvme_fc_delete_hw_queue(ctrl, queue, i);
1644 nvme_fc_create_hw_io_queues(struct nvme_fc_ctrl *ctrl, u16 qsize)
1646 struct nvme_fc_queue *queue = &ctrl->queues[1];
1649 for (i = 1; i < ctrl->queue_count; i++, queue++) {
1650 ret = __nvme_fc_create_hw_queue(ctrl, queue, i, qsize);
1659 __nvme_fc_delete_hw_queue(ctrl, &ctrl->queues[i], i);
1664 nvme_fc_connect_io_queues(struct nvme_fc_ctrl *ctrl, u16 qsize)
1668 for (i = 1; i < ctrl->queue_count; i++) {
1669 ret = nvme_fc_connect_queue(ctrl, &ctrl->queues[i], qsize,
1673 ret = nvmf_connect_io_queue(&ctrl->ctrl, i);
1682 nvme_fc_init_io_queues(struct nvme_fc_ctrl *ctrl)
1686 for (i = 1; i < ctrl->queue_count; i++)
1687 nvme_fc_init_queue(ctrl, i, ctrl->ctrl.sqsize);
1691 nvme_fc_ctrl_free(struct kref *ref)
1693 struct nvme_fc_ctrl *ctrl =
1694 container_of(ref, struct nvme_fc_ctrl, ref);
1695 unsigned long flags;
1697 if (ctrl->ctrl.tagset) {
1698 blk_cleanup_queue(ctrl->ctrl.connect_q);
1699 blk_mq_free_tag_set(&ctrl->tag_set);
1702 /* remove from rport list */
1703 spin_lock_irqsave(&ctrl->rport->lock, flags);
1704 list_del(&ctrl->ctrl_list);
1705 spin_unlock_irqrestore(&ctrl->rport->lock, flags);
1707 blk_cleanup_queue(ctrl->ctrl.admin_q);
1708 blk_mq_free_tag_set(&ctrl->admin_tag_set);
1710 kfree(ctrl->queues);
1712 put_device(ctrl->dev);
1713 nvme_fc_rport_put(ctrl->rport);
1715 ida_simple_remove(&nvme_fc_ctrl_cnt, ctrl->cnum);
1716 if (ctrl->ctrl.opts)
1717 nvmf_free_options(ctrl->ctrl.opts);
1722 nvme_fc_ctrl_put(struct nvme_fc_ctrl *ctrl)
1724 kref_put(&ctrl->ref, nvme_fc_ctrl_free);
1728 nvme_fc_ctrl_get(struct nvme_fc_ctrl *ctrl)
1730 return kref_get_unless_zero(&ctrl->ref);
1734 * All accesses from nvme core layer done - can now free the
1735 * controller. Called after last nvme_put_ctrl() call
1738 nvme_fc_nvme_ctrl_freed(struct nvme_ctrl *nctrl)
1740 struct nvme_fc_ctrl *ctrl = to_fc_ctrl(nctrl);
1742 WARN_ON(nctrl != &ctrl->ctrl);
1744 nvme_fc_ctrl_put(ctrl);
1748 nvme_fc_error_recovery(struct nvme_fc_ctrl *ctrl, char *errmsg)
1750 dev_warn(ctrl->ctrl.device,
1751 "NVME-FC{%d}: transport association error detected: %s\n",
1752 ctrl->cnum, errmsg);
1753 dev_warn(ctrl->ctrl.device,
1754 "NVME-FC{%d}: resetting controller\n", ctrl->cnum);
1756 /* stop the queues on error, cleanup is in reset thread */
1757 if (ctrl->queue_count > 1)
1758 nvme_stop_queues(&ctrl->ctrl);
1760 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_RECONNECTING)) {
1761 dev_err(ctrl->ctrl.device,
1762 "NVME-FC{%d}: error_recovery: Couldn't change state "
1763 "to RECONNECTING\n", ctrl->cnum);
1767 if (!queue_work(nvme_wq, &ctrl->reset_work))
1768 dev_err(ctrl->ctrl.device,
1769 "NVME-FC{%d}: error_recovery: Failed to schedule "
1770 "reset work\n", ctrl->cnum);
1773 static enum blk_eh_timer_return
1774 nvme_fc_timeout(struct request *rq, bool reserved)
1776 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
1777 struct nvme_fc_ctrl *ctrl = op->ctrl;
1781 return BLK_EH_RESET_TIMER;
1783 ret = __nvme_fc_abort_op(ctrl, op);
1785 /* io wasn't active to abort consider it done */
1786 return BLK_EH_HANDLED;
1789 * we can't individually ABTS an io without affecting the queue,
1790 * thus killing the queue, adn thus the association.
1791 * So resolve by performing a controller reset, which will stop
1792 * the host/io stack, terminate the association on the link,
1793 * and recreate an association on the link.
1795 nvme_fc_error_recovery(ctrl, "io timeout error");
1797 return BLK_EH_HANDLED;
1801 nvme_fc_map_data(struct nvme_fc_ctrl *ctrl, struct request *rq,
1802 struct nvme_fc_fcp_op *op)
1804 struct nvmefc_fcp_req *freq = &op->fcp_req;
1805 enum dma_data_direction dir;
1810 if (!blk_rq_payload_bytes(rq))
1813 freq->sg_table.sgl = freq->first_sgl;
1814 ret = sg_alloc_table_chained(&freq->sg_table,
1815 blk_rq_nr_phys_segments(rq), freq->sg_table.sgl);
1819 op->nents = blk_rq_map_sg(rq->q, rq, freq->sg_table.sgl);
1820 WARN_ON(op->nents > blk_rq_nr_phys_segments(rq));
1821 dir = (rq_data_dir(rq) == WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
1822 freq->sg_cnt = fc_dma_map_sg(ctrl->lport->dev, freq->sg_table.sgl,
1824 if (unlikely(freq->sg_cnt <= 0)) {
1825 sg_free_table_chained(&freq->sg_table, true);
1831 * TODO: blk_integrity_rq(rq) for DIF
1837 nvme_fc_unmap_data(struct nvme_fc_ctrl *ctrl, struct request *rq,
1838 struct nvme_fc_fcp_op *op)
1840 struct nvmefc_fcp_req *freq = &op->fcp_req;
1845 fc_dma_unmap_sg(ctrl->lport->dev, freq->sg_table.sgl, op->nents,
1846 ((rq_data_dir(rq) == WRITE) ?
1847 DMA_TO_DEVICE : DMA_FROM_DEVICE));
1849 nvme_cleanup_cmd(rq);
1851 sg_free_table_chained(&freq->sg_table, true);
1857 * In FC, the queue is a logical thing. At transport connect, the target
1858 * creates its "queue" and returns a handle that is to be given to the
1859 * target whenever it posts something to the corresponding SQ. When an
1860 * SQE is sent on a SQ, FC effectively considers the SQE, or rather the
1861 * command contained within the SQE, an io, and assigns a FC exchange
1862 * to it. The SQE and the associated SQ handle are sent in the initial
1863 * CMD IU sents on the exchange. All transfers relative to the io occur
1864 * as part of the exchange. The CQE is the last thing for the io,
1865 * which is transferred (explicitly or implicitly) with the RSP IU
1866 * sent on the exchange. After the CQE is received, the FC exchange is
1867 * terminaed and the Exchange may be used on a different io.
1869 * The transport to LLDD api has the transport making a request for a
1870 * new fcp io request to the LLDD. The LLDD then allocates a FC exchange
1871 * resource and transfers the command. The LLDD will then process all
1872 * steps to complete the io. Upon completion, the transport done routine
1875 * So - while the operation is outstanding to the LLDD, there is a link
1876 * level FC exchange resource that is also outstanding. This must be
1877 * considered in all cleanup operations.
1880 nvme_fc_start_fcp_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue,
1881 struct nvme_fc_fcp_op *op, u32 data_len,
1882 enum nvmefc_fcp_datadir io_dir)
1884 struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu;
1885 struct nvme_command *sqe = &cmdiu->sqe;
1890 * before attempting to send the io, check to see if we believe
1891 * the target device is present
1893 if (ctrl->rport->remoteport.port_state != FC_OBJSTATE_ONLINE)
1894 return BLK_STS_IOERR;
1896 if (!nvme_fc_ctrl_get(ctrl))
1897 return BLK_STS_IOERR;
1899 /* format the FC-NVME CMD IU and fcp_req */
1900 cmdiu->connection_id = cpu_to_be64(queue->connection_id);
1901 csn = atomic_inc_return(&queue->csn);
1902 cmdiu->csn = cpu_to_be32(csn);
1903 cmdiu->data_len = cpu_to_be32(data_len);
1905 case NVMEFC_FCP_WRITE:
1906 cmdiu->flags = FCNVME_CMD_FLAGS_WRITE;
1908 case NVMEFC_FCP_READ:
1909 cmdiu->flags = FCNVME_CMD_FLAGS_READ;
1911 case NVMEFC_FCP_NODATA:
1915 op->fcp_req.payload_length = data_len;
1916 op->fcp_req.io_dir = io_dir;
1917 op->fcp_req.transferred_length = 0;
1918 op->fcp_req.rcv_rsplen = 0;
1919 op->fcp_req.status = NVME_SC_SUCCESS;
1920 op->fcp_req.sqid = cpu_to_le16(queue->qnum);
1923 * validate per fabric rules, set fields mandated by fabric spec
1924 * as well as those by FC-NVME spec.
1926 WARN_ON_ONCE(sqe->common.metadata);
1927 WARN_ON_ONCE(sqe->common.dptr.prp1);
1928 WARN_ON_ONCE(sqe->common.dptr.prp2);
1929 sqe->common.flags |= NVME_CMD_SGL_METABUF;
1932 * format SQE DPTR field per FC-NVME rules
1933 * type=data block descr; subtype=offset;
1934 * offset is currently 0.
1936 sqe->rw.dptr.sgl.type = NVME_SGL_FMT_OFFSET;
1937 sqe->rw.dptr.sgl.length = cpu_to_le32(data_len);
1938 sqe->rw.dptr.sgl.addr = 0;
1940 if (!(op->flags & FCOP_FLAGS_AEN)) {
1941 ret = nvme_fc_map_data(ctrl, op->rq, op);
1943 nvme_cleanup_cmd(op->rq);
1944 nvme_fc_ctrl_put(ctrl);
1945 if (ret == -ENOMEM || ret == -EAGAIN)
1946 return BLK_STS_RESOURCE;
1947 return BLK_STS_IOERR;
1951 fc_dma_sync_single_for_device(ctrl->lport->dev, op->fcp_req.cmddma,
1952 sizeof(op->cmd_iu), DMA_TO_DEVICE);
1954 atomic_set(&op->state, FCPOP_STATE_ACTIVE);
1956 if (!(op->flags & FCOP_FLAGS_AEN))
1957 blk_mq_start_request(op->rq);
1959 ret = ctrl->lport->ops->fcp_io(&ctrl->lport->localport,
1960 &ctrl->rport->remoteport,
1961 queue->lldd_handle, &op->fcp_req);
1964 if (op->rq) { /* normal request */
1965 nvme_fc_unmap_data(ctrl, op->rq, op);
1966 nvme_cleanup_cmd(op->rq);
1968 /* else - aen. no cleanup needed */
1970 nvme_fc_ctrl_put(ctrl);
1973 return BLK_STS_IOERR;
1976 blk_mq_stop_hw_queues(op->rq->q);
1977 blk_mq_delay_queue(queue->hctx, NVMEFC_QUEUE_DELAY);
1979 return BLK_STS_RESOURCE;
1986 nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx,
1987 const struct blk_mq_queue_data *bd)
1989 struct nvme_ns *ns = hctx->queue->queuedata;
1990 struct nvme_fc_queue *queue = hctx->driver_data;
1991 struct nvme_fc_ctrl *ctrl = queue->ctrl;
1992 struct request *rq = bd->rq;
1993 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
1994 struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu;
1995 struct nvme_command *sqe = &cmdiu->sqe;
1996 enum nvmefc_fcp_datadir io_dir;
2000 ret = nvme_setup_cmd(ns, rq, sqe);
2004 data_len = blk_rq_payload_bytes(rq);
2006 io_dir = ((rq_data_dir(rq) == WRITE) ?
2007 NVMEFC_FCP_WRITE : NVMEFC_FCP_READ);
2009 io_dir = NVMEFC_FCP_NODATA;
2011 return nvme_fc_start_fcp_op(ctrl, queue, op, data_len, io_dir);
2014 static struct blk_mq_tags *
2015 nvme_fc_tagset(struct nvme_fc_queue *queue)
2017 if (queue->qnum == 0)
2018 return queue->ctrl->admin_tag_set.tags[queue->qnum];
2020 return queue->ctrl->tag_set.tags[queue->qnum - 1];
2024 nvme_fc_poll(struct blk_mq_hw_ctx *hctx, unsigned int tag)
2027 struct nvme_fc_queue *queue = hctx->driver_data;
2028 struct nvme_fc_ctrl *ctrl = queue->ctrl;
2029 struct request *req;
2030 struct nvme_fc_fcp_op *op;
2032 req = blk_mq_tag_to_rq(nvme_fc_tagset(queue), tag);
2036 op = blk_mq_rq_to_pdu(req);
2038 if ((atomic_read(&op->state) == FCPOP_STATE_ACTIVE) &&
2039 (ctrl->lport->ops->poll_queue))
2040 ctrl->lport->ops->poll_queue(&ctrl->lport->localport,
2041 queue->lldd_handle);
2043 return ((atomic_read(&op->state) != FCPOP_STATE_ACTIVE));
2047 nvme_fc_submit_async_event(struct nvme_ctrl *arg, int aer_idx)
2049 struct nvme_fc_ctrl *ctrl = to_fc_ctrl(arg);
2050 struct nvme_fc_fcp_op *aen_op;
2051 unsigned long flags;
2052 bool terminating = false;
2055 if (aer_idx > NVME_FC_NR_AEN_COMMANDS)
2058 spin_lock_irqsave(&ctrl->lock, flags);
2059 if (ctrl->flags & FCCTRL_TERMIO)
2061 spin_unlock_irqrestore(&ctrl->lock, flags);
2066 aen_op = &ctrl->aen_ops[aer_idx];
2068 ret = nvme_fc_start_fcp_op(ctrl, aen_op->queue, aen_op, 0,
2071 dev_err(ctrl->ctrl.device,
2072 "failed async event work [%d]\n", aer_idx);
2076 __nvme_fc_final_op_cleanup(struct request *rq)
2078 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
2079 struct nvme_fc_ctrl *ctrl = op->ctrl;
2081 atomic_set(&op->state, FCPOP_STATE_IDLE);
2082 op->flags &= ~(FCOP_FLAGS_TERMIO | FCOP_FLAGS_RELEASED |
2083 FCOP_FLAGS_COMPLETE);
2085 nvme_cleanup_cmd(rq);
2086 nvme_fc_unmap_data(ctrl, rq, op);
2087 nvme_complete_rq(rq);
2088 nvme_fc_ctrl_put(ctrl);
2093 nvme_fc_complete_rq(struct request *rq)
2095 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
2096 struct nvme_fc_ctrl *ctrl = op->ctrl;
2097 unsigned long flags;
2098 bool completed = false;
2101 * the core layer, on controller resets after calling
2102 * nvme_shutdown_ctrl(), calls complete_rq without our
2103 * calling blk_mq_complete_request(), thus there may still
2104 * be live i/o outstanding with the LLDD. Means transport has
2105 * to track complete calls vs fcpio_done calls to know what
2106 * path to take on completes and dones.
2108 spin_lock_irqsave(&ctrl->lock, flags);
2109 if (op->flags & FCOP_FLAGS_COMPLETE)
2112 op->flags |= FCOP_FLAGS_RELEASED;
2113 spin_unlock_irqrestore(&ctrl->lock, flags);
2116 __nvme_fc_final_op_cleanup(rq);
2120 * This routine is used by the transport when it needs to find active
2121 * io on a queue that is to be terminated. The transport uses
2122 * blk_mq_tagset_busy_itr() to find the busy requests, which then invoke
2123 * this routine to kill them on a 1 by 1 basis.
2125 * As FC allocates FC exchange for each io, the transport must contact
2126 * the LLDD to terminate the exchange, thus releasing the FC exchange.
2127 * After terminating the exchange the LLDD will call the transport's
2128 * normal io done path for the request, but it will have an aborted
2129 * status. The done path will return the io request back to the block
2130 * layer with an error status.
2133 nvme_fc_terminate_exchange(struct request *req, void *data, bool reserved)
2135 struct nvme_ctrl *nctrl = data;
2136 struct nvme_fc_ctrl *ctrl = to_fc_ctrl(nctrl);
2137 struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(req);
2138 unsigned long flags;
2141 if (!blk_mq_request_started(req))
2144 spin_lock_irqsave(&ctrl->lock, flags);
2145 if (ctrl->flags & FCCTRL_TERMIO) {
2147 op->flags |= FCOP_FLAGS_TERMIO;
2149 spin_unlock_irqrestore(&ctrl->lock, flags);
2151 status = __nvme_fc_abort_op(ctrl, op);
2154 * if __nvme_fc_abort_op failed the io wasn't
2155 * active. Thus this call path is running in
2156 * parallel to the io complete. Treat as non-error.
2159 /* back out the flags/counters */
2160 spin_lock_irqsave(&ctrl->lock, flags);
2161 if (ctrl->flags & FCCTRL_TERMIO)
2163 op->flags &= ~FCOP_FLAGS_TERMIO;
2164 spin_unlock_irqrestore(&ctrl->lock, flags);
2170 static const struct blk_mq_ops nvme_fc_mq_ops = {
2171 .queue_rq = nvme_fc_queue_rq,
2172 .complete = nvme_fc_complete_rq,
2173 .init_request = nvme_fc_init_request,
2174 .exit_request = nvme_fc_exit_request,
2175 .reinit_request = nvme_fc_reinit_request,
2176 .init_hctx = nvme_fc_init_hctx,
2177 .poll = nvme_fc_poll,
2178 .timeout = nvme_fc_timeout,
2182 nvme_fc_create_io_queues(struct nvme_fc_ctrl *ctrl)
2184 struct nvmf_ctrl_options *opts = ctrl->ctrl.opts;
2187 ret = nvme_set_queue_count(&ctrl->ctrl, &opts->nr_io_queues);
2189 dev_info(ctrl->ctrl.device,
2190 "set_queue_count failed: %d\n", ret);
2194 ctrl->queue_count = opts->nr_io_queues + 1;
2195 if (!opts->nr_io_queues)
2198 nvme_fc_init_io_queues(ctrl);
2200 memset(&ctrl->tag_set, 0, sizeof(ctrl->tag_set));
2201 ctrl->tag_set.ops = &nvme_fc_mq_ops;
2202 ctrl->tag_set.queue_depth = ctrl->ctrl.opts->queue_size;
2203 ctrl->tag_set.reserved_tags = 1; /* fabric connect */
2204 ctrl->tag_set.numa_node = NUMA_NO_NODE;
2205 ctrl->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
2206 ctrl->tag_set.cmd_size = sizeof(struct nvme_fc_fcp_op) +
2208 sizeof(struct scatterlist)) +
2209 ctrl->lport->ops->fcprqst_priv_sz;
2210 ctrl->tag_set.driver_data = ctrl;
2211 ctrl->tag_set.nr_hw_queues = ctrl->queue_count - 1;
2212 ctrl->tag_set.timeout = NVME_IO_TIMEOUT;
2214 ret = blk_mq_alloc_tag_set(&ctrl->tag_set);
2218 ctrl->ctrl.tagset = &ctrl->tag_set;
2220 ctrl->ctrl.connect_q = blk_mq_init_queue(&ctrl->tag_set);
2221 if (IS_ERR(ctrl->ctrl.connect_q)) {
2222 ret = PTR_ERR(ctrl->ctrl.connect_q);
2223 goto out_free_tag_set;
2226 ret = nvme_fc_create_hw_io_queues(ctrl, ctrl->ctrl.opts->queue_size);
2228 goto out_cleanup_blk_queue;
2230 ret = nvme_fc_connect_io_queues(ctrl, ctrl->ctrl.opts->queue_size);
2232 goto out_delete_hw_queues;
2236 out_delete_hw_queues:
2237 nvme_fc_delete_hw_io_queues(ctrl);
2238 out_cleanup_blk_queue:
2239 nvme_stop_keep_alive(&ctrl->ctrl);
2240 blk_cleanup_queue(ctrl->ctrl.connect_q);
2242 blk_mq_free_tag_set(&ctrl->tag_set);
2243 nvme_fc_free_io_queues(ctrl);
2245 /* force put free routine to ignore io queues */
2246 ctrl->ctrl.tagset = NULL;
2252 nvme_fc_reinit_io_queues(struct nvme_fc_ctrl *ctrl)
2254 struct nvmf_ctrl_options *opts = ctrl->ctrl.opts;
2257 ret = nvme_set_queue_count(&ctrl->ctrl, &opts->nr_io_queues);
2259 dev_info(ctrl->ctrl.device,
2260 "set_queue_count failed: %d\n", ret);
2264 /* check for io queues existing */
2265 if (ctrl->queue_count == 1)
2268 nvme_fc_init_io_queues(ctrl);
2270 ret = blk_mq_reinit_tagset(&ctrl->tag_set);
2272 goto out_free_io_queues;
2274 ret = nvme_fc_create_hw_io_queues(ctrl, ctrl->ctrl.opts->queue_size);
2276 goto out_free_io_queues;
2278 ret = nvme_fc_connect_io_queues(ctrl, ctrl->ctrl.opts->queue_size);
2280 goto out_delete_hw_queues;
2284 out_delete_hw_queues:
2285 nvme_fc_delete_hw_io_queues(ctrl);
2287 nvme_fc_free_io_queues(ctrl);
2292 * This routine restarts the controller on the host side, and
2293 * on the link side, recreates the controller association.
2296 nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
2298 struct nvmf_ctrl_options *opts = ctrl->ctrl.opts;
2303 ++ctrl->ctrl.nr_reconnects;
2306 * Create the admin queue
2309 nvme_fc_init_queue(ctrl, 0, NVME_FC_AQ_BLKMQ_DEPTH);
2311 ret = __nvme_fc_create_hw_queue(ctrl, &ctrl->queues[0], 0,
2312 NVME_FC_AQ_BLKMQ_DEPTH);
2314 goto out_free_queue;
2316 ret = nvme_fc_connect_admin_queue(ctrl, &ctrl->queues[0],
2317 NVME_FC_AQ_BLKMQ_DEPTH,
2318 (NVME_FC_AQ_BLKMQ_DEPTH / 4));
2320 goto out_delete_hw_queue;
2322 if (ctrl->ctrl.state != NVME_CTRL_NEW)
2323 blk_mq_start_stopped_hw_queues(ctrl->ctrl.admin_q, true);
2325 ret = nvmf_connect_admin_queue(&ctrl->ctrl);
2327 goto out_disconnect_admin_queue;
2330 * Check controller capabilities
2332 * todo:- add code to check if ctrl attributes changed from
2333 * prior connection values
2336 ret = nvmf_reg_read64(&ctrl->ctrl, NVME_REG_CAP, &ctrl->cap);
2338 dev_err(ctrl->ctrl.device,
2339 "prop_get NVME_REG_CAP failed\n");
2340 goto out_disconnect_admin_queue;
2344 min_t(int, NVME_CAP_MQES(ctrl->cap) + 1, ctrl->ctrl.sqsize);
2346 ret = nvme_enable_ctrl(&ctrl->ctrl, ctrl->cap);
2348 goto out_disconnect_admin_queue;
2350 segs = min_t(u32, NVME_FC_MAX_SEGMENTS,
2351 ctrl->lport->ops->max_sgl_segments);
2352 ctrl->ctrl.max_hw_sectors = (segs - 1) << (PAGE_SHIFT - 9);
2354 ret = nvme_init_identify(&ctrl->ctrl);
2356 goto out_disconnect_admin_queue;
2360 /* FC-NVME does not have other data in the capsule */
2361 if (ctrl->ctrl.icdoff) {
2362 dev_err(ctrl->ctrl.device, "icdoff %d is not supported!\n",
2364 goto out_disconnect_admin_queue;
2367 nvme_start_keep_alive(&ctrl->ctrl);
2369 /* FC-NVME supports normal SGL Data Block Descriptors */
2371 if (opts->queue_size > ctrl->ctrl.maxcmd) {
2372 /* warn if maxcmd is lower than queue_size */
2373 dev_warn(ctrl->ctrl.device,
2374 "queue_size %zu > ctrl maxcmd %u, reducing "
2376 opts->queue_size, ctrl->ctrl.maxcmd);
2377 opts->queue_size = ctrl->ctrl.maxcmd;
2380 ret = nvme_fc_init_aen_ops(ctrl);
2382 goto out_term_aen_ops;
2385 * Create the io queues
2388 if (ctrl->queue_count > 1) {
2389 if (ctrl->ctrl.state == NVME_CTRL_NEW)
2390 ret = nvme_fc_create_io_queues(ctrl);
2392 ret = nvme_fc_reinit_io_queues(ctrl);
2394 goto out_term_aen_ops;
2397 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
2398 WARN_ON_ONCE(!changed);
2400 ctrl->ctrl.nr_reconnects = 0;
2402 if (ctrl->queue_count > 1) {
2403 nvme_start_queues(&ctrl->ctrl);
2404 nvme_queue_scan(&ctrl->ctrl);
2405 nvme_queue_async_events(&ctrl->ctrl);
2408 return 0; /* Success */
2411 nvme_fc_term_aen_ops(ctrl);
2412 nvme_stop_keep_alive(&ctrl->ctrl);
2413 out_disconnect_admin_queue:
2414 /* send a Disconnect(association) LS to fc-nvme target */
2415 nvme_fc_xmt_disconnect_assoc(ctrl);
2416 out_delete_hw_queue:
2417 __nvme_fc_delete_hw_queue(ctrl, &ctrl->queues[0], 0);
2419 nvme_fc_free_queue(&ctrl->queues[0]);
2425 * This routine stops operation of the controller on the host side.
2426 * On the host os stack side: Admin and IO queues are stopped,
2427 * outstanding ios on them terminated via FC ABTS.
2428 * On the link side: the association is terminated.
2431 nvme_fc_delete_association(struct nvme_fc_ctrl *ctrl)
2433 unsigned long flags;
2435 nvme_stop_keep_alive(&ctrl->ctrl);
2437 spin_lock_irqsave(&ctrl->lock, flags);
2438 ctrl->flags |= FCCTRL_TERMIO;
2440 spin_unlock_irqrestore(&ctrl->lock, flags);
2443 * If io queues are present, stop them and terminate all outstanding
2444 * ios on them. As FC allocates FC exchange for each io, the
2445 * transport must contact the LLDD to terminate the exchange,
2446 * thus releasing the FC exchange. We use blk_mq_tagset_busy_itr()
2447 * to tell us what io's are busy and invoke a transport routine
2448 * to kill them with the LLDD. After terminating the exchange
2449 * the LLDD will call the transport's normal io done path, but it
2450 * will have an aborted status. The done path will return the
2451 * io requests back to the block layer as part of normal completions
2452 * (but with error status).
2454 if (ctrl->queue_count > 1) {
2455 nvme_stop_queues(&ctrl->ctrl);
2456 blk_mq_tagset_busy_iter(&ctrl->tag_set,
2457 nvme_fc_terminate_exchange, &ctrl->ctrl);
2461 * Other transports, which don't have link-level contexts bound
2462 * to sqe's, would try to gracefully shutdown the controller by
2463 * writing the registers for shutdown and polling (call
2464 * nvme_shutdown_ctrl()). Given a bunch of i/o was potentially
2465 * just aborted and we will wait on those contexts, and given
2466 * there was no indication of how live the controlelr is on the
2467 * link, don't send more io to create more contexts for the
2468 * shutdown. Let the controller fail via keepalive failure if
2469 * its still present.
2473 * clean up the admin queue. Same thing as above.
2474 * use blk_mq_tagset_busy_itr() and the transport routine to
2475 * terminate the exchanges.
2477 blk_mq_stop_hw_queues(ctrl->ctrl.admin_q);
2478 blk_mq_tagset_busy_iter(&ctrl->admin_tag_set,
2479 nvme_fc_terminate_exchange, &ctrl->ctrl);
2481 /* kill the aens as they are a separate path */
2482 nvme_fc_abort_aen_ops(ctrl);
2484 /* wait for all io that had to be aborted */
2485 spin_lock_irqsave(&ctrl->lock, flags);
2486 while (ctrl->iocnt) {
2487 spin_unlock_irqrestore(&ctrl->lock, flags);
2489 spin_lock_irqsave(&ctrl->lock, flags);
2491 ctrl->flags &= ~FCCTRL_TERMIO;
2492 spin_unlock_irqrestore(&ctrl->lock, flags);
2494 nvme_fc_term_aen_ops(ctrl);
2497 * send a Disconnect(association) LS to fc-nvme target
2498 * Note: could have been sent at top of process, but
2499 * cleaner on link traffic if after the aborts complete.
2500 * Note: if association doesn't exist, association_id will be 0
2502 if (ctrl->association_id)
2503 nvme_fc_xmt_disconnect_assoc(ctrl);
2505 if (ctrl->ctrl.tagset) {
2506 nvme_fc_delete_hw_io_queues(ctrl);
2507 nvme_fc_free_io_queues(ctrl);
2510 __nvme_fc_delete_hw_queue(ctrl, &ctrl->queues[0], 0);
2511 nvme_fc_free_queue(&ctrl->queues[0]);
2515 nvme_fc_delete_ctrl_work(struct work_struct *work)
2517 struct nvme_fc_ctrl *ctrl =
2518 container_of(work, struct nvme_fc_ctrl, delete_work);
2520 cancel_work_sync(&ctrl->reset_work);
2521 cancel_delayed_work_sync(&ctrl->connect_work);
2524 * kill the association on the link side. this will block
2525 * waiting for io to terminate
2527 nvme_fc_delete_association(ctrl);
2530 * tear down the controller
2531 * After the last reference on the nvme ctrl is removed,
2532 * the transport nvme_fc_nvme_ctrl_freed() callback will be
2533 * invoked. From there, the transport will tear down it's
2534 * logical queues and association.
2536 nvme_uninit_ctrl(&ctrl->ctrl);
2538 nvme_put_ctrl(&ctrl->ctrl);
2542 __nvme_fc_schedule_delete_work(struct nvme_fc_ctrl *ctrl)
2544 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_DELETING))
2547 if (!queue_work(nvme_wq, &ctrl->delete_work))
2554 __nvme_fc_del_ctrl(struct nvme_fc_ctrl *ctrl)
2556 return __nvme_fc_schedule_delete_work(ctrl) ? -EBUSY : 0;
2560 * Request from nvme core layer to delete the controller
2563 nvme_fc_del_nvme_ctrl(struct nvme_ctrl *nctrl)
2565 struct nvme_fc_ctrl *ctrl = to_fc_ctrl(nctrl);
2568 if (!kref_get_unless_zero(&ctrl->ctrl.kref))
2571 ret = __nvme_fc_del_ctrl(ctrl);
2574 flush_workqueue(nvme_wq);
2576 nvme_put_ctrl(&ctrl->ctrl);
2582 nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)
2584 /* If we are resetting/deleting then do nothing */
2585 if (ctrl->ctrl.state != NVME_CTRL_RECONNECTING) {
2586 WARN_ON_ONCE(ctrl->ctrl.state == NVME_CTRL_NEW ||
2587 ctrl->ctrl.state == NVME_CTRL_LIVE);
2591 dev_info(ctrl->ctrl.device,
2592 "NVME-FC{%d}: reset: Reconnect attempt failed (%d)\n",
2593 ctrl->cnum, status);
2595 if (nvmf_should_reconnect(&ctrl->ctrl)) {
2596 dev_info(ctrl->ctrl.device,
2597 "NVME-FC{%d}: Reconnect attempt in %d seconds.\n",
2598 ctrl->cnum, ctrl->ctrl.opts->reconnect_delay);
2599 queue_delayed_work(nvme_wq, &ctrl->connect_work,
2600 ctrl->ctrl.opts->reconnect_delay * HZ);
2602 dev_warn(ctrl->ctrl.device,
2603 "NVME-FC{%d}: Max reconnect attempts (%d) "
2604 "reached. Removing controller\n",
2605 ctrl->cnum, ctrl->ctrl.nr_reconnects);
2606 WARN_ON(__nvme_fc_schedule_delete_work(ctrl));
2611 nvme_fc_reset_ctrl_work(struct work_struct *work)
2613 struct nvme_fc_ctrl *ctrl =
2614 container_of(work, struct nvme_fc_ctrl, reset_work);
2617 /* will block will waiting for io to terminate */
2618 nvme_fc_delete_association(ctrl);
2620 ret = nvme_fc_create_association(ctrl);
2622 nvme_fc_reconnect_or_delete(ctrl, ret);
2624 dev_info(ctrl->ctrl.device,
2625 "NVME-FC{%d}: controller reset complete\n", ctrl->cnum);
2629 * called by the nvme core layer, for sysfs interface that requests
2630 * a reset of the nvme controller
2633 nvme_fc_reset_nvme_ctrl(struct nvme_ctrl *nctrl)
2635 struct nvme_fc_ctrl *ctrl = to_fc_ctrl(nctrl);
2637 dev_info(ctrl->ctrl.device,
2638 "NVME-FC{%d}: admin requested controller reset\n", ctrl->cnum);
2640 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_RESETTING))
2643 if (!queue_work(nvme_wq, &ctrl->reset_work))
2646 flush_work(&ctrl->reset_work);
2651 static const struct nvme_ctrl_ops nvme_fc_ctrl_ops = {
2653 .module = THIS_MODULE,
2654 .flags = NVME_F_FABRICS,
2655 .reg_read32 = nvmf_reg_read32,
2656 .reg_read64 = nvmf_reg_read64,
2657 .reg_write32 = nvmf_reg_write32,
2658 .reset_ctrl = nvme_fc_reset_nvme_ctrl,
2659 .free_ctrl = nvme_fc_nvme_ctrl_freed,
2660 .submit_async_event = nvme_fc_submit_async_event,
2661 .delete_ctrl = nvme_fc_del_nvme_ctrl,
2662 .get_subsysnqn = nvmf_get_subsysnqn,
2663 .get_address = nvmf_get_address,
2667 nvme_fc_connect_ctrl_work(struct work_struct *work)
2671 struct nvme_fc_ctrl *ctrl =
2672 container_of(to_delayed_work(work),
2673 struct nvme_fc_ctrl, connect_work);
2675 ret = nvme_fc_create_association(ctrl);
2677 nvme_fc_reconnect_or_delete(ctrl, ret);
2679 dev_info(ctrl->ctrl.device,
2680 "NVME-FC{%d}: controller reconnect complete\n",
2685 static const struct blk_mq_ops nvme_fc_admin_mq_ops = {
2686 .queue_rq = nvme_fc_queue_rq,
2687 .complete = nvme_fc_complete_rq,
2688 .init_request = nvme_fc_init_request,
2689 .exit_request = nvme_fc_exit_request,
2690 .reinit_request = nvme_fc_reinit_request,
2691 .init_hctx = nvme_fc_init_admin_hctx,
2692 .timeout = nvme_fc_timeout,
2696 static struct nvme_ctrl *
2697 nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
2698 struct nvme_fc_lport *lport, struct nvme_fc_rport *rport)
2700 struct nvme_fc_ctrl *ctrl;
2701 unsigned long flags;
2704 if (!(rport->remoteport.port_role &
2705 (FC_PORT_ROLE_NVME_DISCOVERY | FC_PORT_ROLE_NVME_TARGET))) {
2710 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
2716 idx = ida_simple_get(&nvme_fc_ctrl_cnt, 0, 0, GFP_KERNEL);
2722 ctrl->ctrl.opts = opts;
2723 INIT_LIST_HEAD(&ctrl->ctrl_list);
2724 ctrl->lport = lport;
2725 ctrl->rport = rport;
2726 ctrl->dev = lport->dev;
2729 get_device(ctrl->dev);
2730 kref_init(&ctrl->ref);
2732 INIT_WORK(&ctrl->delete_work, nvme_fc_delete_ctrl_work);
2733 INIT_WORK(&ctrl->reset_work, nvme_fc_reset_ctrl_work);
2734 INIT_DELAYED_WORK(&ctrl->connect_work, nvme_fc_connect_ctrl_work);
2735 spin_lock_init(&ctrl->lock);
2737 /* io queue count */
2738 ctrl->queue_count = min_t(unsigned int,
2740 lport->ops->max_hw_queues);
2741 opts->nr_io_queues = ctrl->queue_count; /* so opts has valid value */
2742 ctrl->queue_count++; /* +1 for admin queue */
2744 ctrl->ctrl.sqsize = opts->queue_size - 1;
2745 ctrl->ctrl.kato = opts->kato;
2748 ctrl->queues = kcalloc(ctrl->queue_count, sizeof(struct nvme_fc_queue),
2753 memset(&ctrl->admin_tag_set, 0, sizeof(ctrl->admin_tag_set));
2754 ctrl->admin_tag_set.ops = &nvme_fc_admin_mq_ops;
2755 ctrl->admin_tag_set.queue_depth = NVME_FC_AQ_BLKMQ_DEPTH;
2756 ctrl->admin_tag_set.reserved_tags = 2; /* fabric connect + Keep-Alive */
2757 ctrl->admin_tag_set.numa_node = NUMA_NO_NODE;
2758 ctrl->admin_tag_set.cmd_size = sizeof(struct nvme_fc_fcp_op) +
2760 sizeof(struct scatterlist)) +
2761 ctrl->lport->ops->fcprqst_priv_sz;
2762 ctrl->admin_tag_set.driver_data = ctrl;
2763 ctrl->admin_tag_set.nr_hw_queues = 1;
2764 ctrl->admin_tag_set.timeout = ADMIN_TIMEOUT;
2766 ret = blk_mq_alloc_tag_set(&ctrl->admin_tag_set);
2768 goto out_free_queues;
2770 ctrl->ctrl.admin_q = blk_mq_init_queue(&ctrl->admin_tag_set);
2771 if (IS_ERR(ctrl->ctrl.admin_q)) {
2772 ret = PTR_ERR(ctrl->ctrl.admin_q);
2773 goto out_free_admin_tag_set;
2777 * Would have been nice to init io queues tag set as well.
2778 * However, we require interaction from the controller
2779 * for max io queue count before we can do so.
2780 * Defer this to the connect path.
2783 ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_fc_ctrl_ops, 0);
2785 goto out_cleanup_admin_q;
2787 /* at this point, teardown path changes to ref counting on nvme ctrl */
2789 spin_lock_irqsave(&rport->lock, flags);
2790 list_add_tail(&ctrl->ctrl_list, &rport->ctrl_list);
2791 spin_unlock_irqrestore(&rport->lock, flags);
2793 ret = nvme_fc_create_association(ctrl);
2795 ctrl->ctrl.opts = NULL;
2796 /* initiate nvme ctrl ref counting teardown */
2797 nvme_uninit_ctrl(&ctrl->ctrl);
2798 nvme_put_ctrl(&ctrl->ctrl);
2800 /* as we're past the point where we transition to the ref
2801 * counting teardown path, if we return a bad pointer here,
2802 * the calling routine, thinking it's prior to the
2803 * transition, will do an rport put. Since the teardown
2804 * path also does a rport put, we do an extra get here to
2805 * so proper order/teardown happens.
2807 nvme_fc_rport_get(rport);
2811 return ERR_PTR(ret);
2814 kref_get(&ctrl->ctrl.kref);
2816 dev_info(ctrl->ctrl.device,
2817 "NVME-FC{%d}: new ctrl: NQN \"%s\"\n",
2818 ctrl->cnum, ctrl->ctrl.opts->subsysnqn);
2822 out_cleanup_admin_q:
2823 blk_cleanup_queue(ctrl->ctrl.admin_q);
2824 out_free_admin_tag_set:
2825 blk_mq_free_tag_set(&ctrl->admin_tag_set);
2827 kfree(ctrl->queues);
2829 put_device(ctrl->dev);
2830 ida_simple_remove(&nvme_fc_ctrl_cnt, ctrl->cnum);
2834 /* exit via here doesn't follow ctlr ref points */
2835 return ERR_PTR(ret);
2840 FCT_TRADDR_WWNN = 1 << 0,
2841 FCT_TRADDR_WWPN = 1 << 1,
2844 struct nvmet_fc_traddr {
2849 static const match_table_t traddr_opt_tokens = {
2850 { FCT_TRADDR_WWNN, "nn-%s" },
2851 { FCT_TRADDR_WWPN, "pn-%s" },
2852 { FCT_TRADDR_ERR, NULL }
2856 nvme_fc_parse_address(struct nvmet_fc_traddr *traddr, char *buf)
2858 substring_t args[MAX_OPT_ARGS];
2859 char *options, *o, *p;
2863 options = o = kstrdup(buf, GFP_KERNEL);
2867 while ((p = strsep(&o, ":\n")) != NULL) {
2871 token = match_token(p, traddr_opt_tokens, args);
2873 case FCT_TRADDR_WWNN:
2874 if (match_u64(args, &token64)) {
2878 traddr->nn = token64;
2880 case FCT_TRADDR_WWPN:
2881 if (match_u64(args, &token64)) {
2885 traddr->pn = token64;
2888 pr_warn("unknown traddr token or missing value '%s'\n",
2900 static struct nvme_ctrl *
2901 nvme_fc_create_ctrl(struct device *dev, struct nvmf_ctrl_options *opts)
2903 struct nvme_fc_lport *lport;
2904 struct nvme_fc_rport *rport;
2905 struct nvme_ctrl *ctrl;
2906 struct nvmet_fc_traddr laddr = { 0L, 0L };
2907 struct nvmet_fc_traddr raddr = { 0L, 0L };
2908 unsigned long flags;
2911 ret = nvme_fc_parse_address(&raddr, opts->traddr);
2912 if (ret || !raddr.nn || !raddr.pn)
2913 return ERR_PTR(-EINVAL);
2915 ret = nvme_fc_parse_address(&laddr, opts->host_traddr);
2916 if (ret || !laddr.nn || !laddr.pn)
2917 return ERR_PTR(-EINVAL);
2919 /* find the host and remote ports to connect together */
2920 spin_lock_irqsave(&nvme_fc_lock, flags);
2921 list_for_each_entry(lport, &nvme_fc_lport_list, port_list) {
2922 if (lport->localport.node_name != laddr.nn ||
2923 lport->localport.port_name != laddr.pn)
2926 list_for_each_entry(rport, &lport->endp_list, endp_list) {
2927 if (rport->remoteport.node_name != raddr.nn ||
2928 rport->remoteport.port_name != raddr.pn)
2931 /* if fail to get reference fall through. Will error */
2932 if (!nvme_fc_rport_get(rport))
2935 spin_unlock_irqrestore(&nvme_fc_lock, flags);
2937 ctrl = nvme_fc_init_ctrl(dev, opts, lport, rport);
2939 nvme_fc_rport_put(rport);
2943 spin_unlock_irqrestore(&nvme_fc_lock, flags);
2945 return ERR_PTR(-ENOENT);
2949 static struct nvmf_transport_ops nvme_fc_transport = {
2951 .required_opts = NVMF_OPT_TRADDR | NVMF_OPT_HOST_TRADDR,
2952 .allowed_opts = NVMF_OPT_RECONNECT_DELAY | NVMF_OPT_CTRL_LOSS_TMO,
2953 .create_ctrl = nvme_fc_create_ctrl,
2956 static int __init nvme_fc_init_module(void)
2958 return nvmf_register_transport(&nvme_fc_transport);
2961 static void __exit nvme_fc_exit_module(void)
2963 /* sanity check - all lports should be removed */
2964 if (!list_empty(&nvme_fc_lport_list))
2965 pr_warn("%s: localport list not empty\n", __func__);
2967 nvmf_unregister_transport(&nvme_fc_transport);
2969 ida_destroy(&nvme_fc_local_port_cnt);
2970 ida_destroy(&nvme_fc_ctrl_cnt);
2973 module_init(nvme_fc_init_module);
2974 module_exit(nvme_fc_exit_module);
2976 MODULE_LICENSE("GPL v2");