2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2017 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/scatterlist.h>
10 #include <linux/delay.h>
11 #include <linux/nvme.h>
12 #include <linux/nvme-fc.h>
14 static struct nvme_fc_port_template qla_nvme_fc_transport
;
16 static void qla_nvme_unregister_remote_port(struct work_struct
*);
18 int qla_nvme_register_remote(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
20 struct nvme_rport
*rport
;
23 if (!IS_ENABLED(CONFIG_NVME_FC
))
26 if (fcport
->nvme_flag
& NVME_FLAG_REGISTERED
)
29 if (!vha
->flags
.nvme_enabled
) {
30 ql_log(ql_log_info
, vha
, 0x2100,
31 "%s: Not registering target since Host NVME is not enabled\n",
36 if (!(fcport
->nvme_prli_service_param
&
37 (NVME_PRLI_SP_TARGET
| NVME_PRLI_SP_DISCOVERY
)))
40 INIT_WORK(&fcport
->nvme_del_work
, qla_nvme_unregister_remote_port
);
41 rport
= kzalloc(sizeof(*rport
), GFP_KERNEL
);
43 ql_log(ql_log_warn
, vha
, 0x2101,
44 "%s: unable to alloc memory\n", __func__
);
48 rport
->req
.port_name
= wwn_to_u64(fcport
->port_name
);
49 rport
->req
.node_name
= wwn_to_u64(fcport
->node_name
);
50 rport
->req
.port_role
= 0;
52 if (fcport
->nvme_prli_service_param
& NVME_PRLI_SP_INITIATOR
)
53 rport
->req
.port_role
= FC_PORT_ROLE_NVME_INITIATOR
;
55 if (fcport
->nvme_prli_service_param
& NVME_PRLI_SP_TARGET
)
56 rport
->req
.port_role
|= FC_PORT_ROLE_NVME_TARGET
;
58 if (fcport
->nvme_prli_service_param
& NVME_PRLI_SP_DISCOVERY
)
59 rport
->req
.port_role
|= FC_PORT_ROLE_NVME_DISCOVERY
;
61 rport
->req
.port_id
= fcport
->d_id
.b24
;
63 ql_log(ql_log_info
, vha
, 0x2102,
64 "%s: traddr=pn-0x%016llx:nn-0x%016llx PortID:%06x\n",
65 __func__
, rport
->req
.port_name
, rport
->req
.node_name
,
68 ret
= nvme_fc_register_remoteport(vha
->nvme_local_port
, &rport
->req
,
69 &fcport
->nvme_remote_port
);
71 ql_log(ql_log_warn
, vha
, 0x212e,
72 "Failed to register remote port. Transport returned %d\n",
77 fcport
->nvme_remote_port
->private = fcport
;
78 fcport
->nvme_flag
|= NVME_FLAG_REGISTERED
;
79 atomic_set(&fcport
->nvme_ref_count
, 1);
80 init_waitqueue_head(&fcport
->nvme_waitQ
);
81 rport
->fcport
= fcport
;
82 list_add_tail(&rport
->list
, &vha
->nvme_rport_list
);
86 /* Allocate a queue for NVMe traffic */
87 static int qla_nvme_alloc_queue(struct nvme_fc_local_port
*lport
, unsigned int qidx
,
88 u16 qsize
, void **handle
)
90 struct scsi_qla_host
*vha
;
91 struct qla_hw_data
*ha
;
92 struct qla_qpair
*qpair
;
97 vha
= (struct scsi_qla_host
*)lport
->private;
100 ql_log(ql_log_info
, vha
, 0x2104,
101 "%s: handle %p, idx =%d, qsize %d\n",
102 __func__
, handle
, qidx
, qsize
);
104 if (qidx
> qla_nvme_fc_transport
.max_hw_queues
) {
105 ql_log(ql_log_warn
, vha
, 0x212f,
106 "%s: Illegal qidx=%d. Max=%d\n",
107 __func__
, qidx
, qla_nvme_fc_transport
.max_hw_queues
);
111 if (ha
->queue_pair_map
[qidx
]) {
112 *handle
= ha
->queue_pair_map
[qidx
];
113 ql_log(ql_log_info
, vha
, 0x2121,
114 "Returning existing qpair of %p for idx=%x\n",
119 ql_log(ql_log_warn
, vha
, 0xffff,
120 "allocating q for idx=%x w/o cpu mask\n", qidx
);
121 qpair
= qla2xxx_create_qpair(vha
, 5, vha
->vp_idx
, true);
123 ql_log(ql_log_warn
, vha
, 0x2122,
124 "Failed to allocate qpair\n");
132 static void qla_nvme_sp_ls_done(void *ptr
, int res
)
135 struct srb_iocb
*nvme
;
136 struct nvmefc_ls_req
*fd
;
137 struct nvme_private
*priv
;
139 if (atomic_read(&sp
->ref_count
) == 0) {
140 ql_log(ql_log_warn
, sp
->fcport
->vha
, 0x2123,
141 "SP reference-count to ZERO on LS_done -- sp=%p.\n", sp
);
145 if (!atomic_dec_and_test(&sp
->ref_count
))
151 nvme
= &sp
->u
.iocb_cmd
;
152 fd
= nvme
->u
.nvme
.desc
;
154 priv
->comp_status
= res
;
155 schedule_work(&priv
->ls_work
);
156 /* work schedule doesn't need the sp */
160 static void qla_nvme_sp_done(void *ptr
, int res
)
163 struct srb_iocb
*nvme
;
164 struct nvmefc_fcp_req
*fd
;
166 nvme
= &sp
->u
.iocb_cmd
;
167 fd
= nvme
->u
.nvme
.desc
;
169 if (!atomic_dec_and_test(&sp
->ref_count
))
172 if (!(sp
->fcport
->nvme_flag
& NVME_FLAG_REGISTERED
))
175 if (unlikely(nvme
->u
.nvme
.comp_status
|| res
))
176 fd
->status
= -EINVAL
;
180 fd
->rcv_rsplen
= nvme
->u
.nvme
.rsp_pyld_len
;
183 qla2xxx_rel_qpair_sp(sp
->qpair
, sp
);
186 static void qla_nvme_ls_abort(struct nvme_fc_local_port
*lport
,
187 struct nvme_fc_remote_port
*rport
, struct nvmefc_ls_req
*fd
)
189 struct nvme_private
*priv
= fd
->private;
190 fc_port_t
*fcport
= rport
->private;
191 srb_t
*sp
= priv
->sp
;
193 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
195 rval
= ha
->isp_ops
->abort_command(sp
);
196 if (rval
!= QLA_SUCCESS
)
197 ql_log(ql_log_warn
, fcport
->vha
, 0x2125,
198 "%s: failed to abort LS command for SP:%p rval=%x\n",
201 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x212b,
202 "%s: aborted sp:%p on fcport:%p\n", __func__
, sp
, fcport
);
205 static void qla_nvme_ls_complete(struct work_struct
*work
)
207 struct nvme_private
*priv
=
208 container_of(work
, struct nvme_private
, ls_work
);
209 struct nvmefc_ls_req
*fd
= priv
->fd
;
211 fd
->done(fd
, priv
->comp_status
);
214 static int qla_nvme_ls_req(struct nvme_fc_local_port
*lport
,
215 struct nvme_fc_remote_port
*rport
, struct nvmefc_ls_req
*fd
)
217 fc_port_t
*fcport
= (fc_port_t
*)rport
->private;
218 struct srb_iocb
*nvme
;
219 struct nvme_private
*priv
= fd
->private;
220 struct scsi_qla_host
*vha
;
221 int rval
= QLA_FUNCTION_FAILED
;
222 struct qla_hw_data
*ha
;
225 if (!(fcport
->nvme_flag
& NVME_FLAG_REGISTERED
))
230 /* Alloc SRB structure */
231 sp
= qla2x00_get_sp(vha
, fcport
, GFP_ATOMIC
);
235 sp
->type
= SRB_NVME_LS
;
236 sp
->name
= "nvme_ls";
237 sp
->done
= qla_nvme_sp_ls_done
;
238 atomic_set(&sp
->ref_count
, 1);
239 init_waitqueue_head(&sp
->nvme_ls_waitQ
);
240 nvme
= &sp
->u
.iocb_cmd
;
243 INIT_WORK(&priv
->ls_work
, qla_nvme_ls_complete
);
244 nvme
->u
.nvme
.desc
= fd
;
245 nvme
->u
.nvme
.dir
= 0;
247 nvme
->u
.nvme
.cmd_len
= fd
->rqstlen
;
248 nvme
->u
.nvme
.rsp_len
= fd
->rsplen
;
249 nvme
->u
.nvme
.rsp_dma
= fd
->rspdma
;
250 nvme
->u
.nvme
.timeout_sec
= fd
->timeout
;
251 nvme
->u
.nvme
.cmd_dma
= dma_map_single(&ha
->pdev
->dev
, fd
->rqstaddr
,
252 fd
->rqstlen
, DMA_TO_DEVICE
);
253 dma_sync_single_for_device(&ha
->pdev
->dev
, nvme
->u
.nvme
.cmd_dma
,
254 fd
->rqstlen
, DMA_TO_DEVICE
);
256 rval
= qla2x00_start_sp(sp
);
257 if (rval
!= QLA_SUCCESS
) {
258 ql_log(ql_log_warn
, vha
, 0x700e,
259 "qla2x00_start_sp failed = %d\n", rval
);
260 atomic_dec(&sp
->ref_count
);
261 wake_up(&sp
->nvme_ls_waitQ
);
268 static void qla_nvme_fcp_abort(struct nvme_fc_local_port
*lport
,
269 struct nvme_fc_remote_port
*rport
, void *hw_queue_handle
,
270 struct nvmefc_fcp_req
*fd
)
272 struct nvme_private
*priv
= fd
->private;
273 srb_t
*sp
= priv
->sp
;
275 fc_port_t
*fcport
= rport
->private;
276 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
278 rval
= ha
->isp_ops
->abort_command(sp
);
280 ql_log(ql_log_warn
, fcport
->vha
, 0x2127,
281 "%s: failed to abort command for SP:%p rval=%x\n",
284 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x2126,
285 "%s: aborted sp:%p on fcport:%p\n", __func__
, sp
, fcport
);
288 static void qla_nvme_poll(struct nvme_fc_local_port
*lport
, void *hw_queue_handle
)
290 struct scsi_qla_host
*vha
= lport
->private;
292 struct qla_qpair
*qpair
= (struct qla_qpair
*)hw_queue_handle
;
294 /* Acquire ring specific lock */
295 spin_lock_irqsave(&qpair
->qp_lock
, flags
);
296 qla24xx_process_response_queue(vha
, qpair
->rsp
);
297 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
300 static int qla2x00_start_nvme_mq(srb_t
*sp
)
306 struct cmd_nvme
*cmd_pkt
;
312 struct req_que
*req
= NULL
;
313 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
314 struct qla_hw_data
*ha
= vha
->hw
;
315 struct qla_qpair
*qpair
= sp
->qpair
;
316 struct srb_iocb
*nvme
= &sp
->u
.iocb_cmd
;
317 struct scatterlist
*sgl
, *sg
;
318 struct nvmefc_fcp_req
*fd
= nvme
->u
.nvme
.desc
;
319 uint32_t rval
= QLA_SUCCESS
;
321 /* Setup qpair pointers */
323 tot_dsds
= fd
->sg_cnt
;
325 /* Acquire qpair specific lock */
326 spin_lock_irqsave(&qpair
->qp_lock
, flags
);
328 /* Check for room in outstanding command list. */
329 handle
= req
->current_outstanding_cmd
;
330 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
332 if (handle
== req
->num_outstanding_cmds
)
334 if (!req
->outstanding_cmds
[handle
])
338 if (index
== req
->num_outstanding_cmds
) {
342 req_cnt
= qla24xx_calc_iocbs(vha
, tot_dsds
);
343 if (req
->cnt
< (req_cnt
+ 2)) {
344 cnt
= IS_SHADOW_REG_CAPABLE(ha
) ? *req
->out_ptr
:
345 RD_REG_DWORD_RELAXED(req
->req_q_out
);
347 if (req
->ring_index
< cnt
)
348 req
->cnt
= cnt
- req
->ring_index
;
350 req
->cnt
= req
->length
- (req
->ring_index
- cnt
);
352 if (req
->cnt
< (req_cnt
+ 2)){
358 if (unlikely(!fd
->sqid
)) {
359 struct nvme_fc_cmd_iu
*cmd
= fd
->cmdaddr
;
360 if (cmd
->sqe
.common
.opcode
== nvme_admin_async_event
) {
361 nvme
->u
.nvme
.aen_op
= 1;
362 atomic_inc(&vha
->nvme_active_aen_cnt
);
366 /* Build command packet. */
367 req
->current_outstanding_cmd
= handle
;
368 req
->outstanding_cmds
[handle
] = sp
;
372 cmd_pkt
= (struct cmd_nvme
*)req
->ring_ptr
;
373 cmd_pkt
->handle
= MAKE_HANDLE(req
->id
, handle
);
375 /* Zero out remaining portion of packet. */
376 clr_ptr
= (uint32_t *)cmd_pkt
+ 2;
377 memset(clr_ptr
, 0, REQUEST_ENTRY_SIZE
- 8);
379 cmd_pkt
->entry_status
= 0;
381 /* Update entry type to indicate Command NVME IOCB */
382 cmd_pkt
->entry_type
= COMMAND_NVME
;
384 /* No data transfer how do we check buffer len == 0?? */
385 if (fd
->io_dir
== NVMEFC_FCP_READ
) {
386 cmd_pkt
->control_flags
=
387 cpu_to_le16(CF_READ_DATA
| CF_NVME_ENABLE
);
388 vha
->qla_stats
.input_bytes
+= fd
->payload_length
;
389 vha
->qla_stats
.input_requests
++;
390 } else if (fd
->io_dir
== NVMEFC_FCP_WRITE
) {
391 cmd_pkt
->control_flags
=
392 cpu_to_le16(CF_WRITE_DATA
| CF_NVME_ENABLE
);
393 vha
->qla_stats
.output_bytes
+= fd
->payload_length
;
394 vha
->qla_stats
.output_requests
++;
395 } else if (fd
->io_dir
== 0) {
396 cmd_pkt
->control_flags
= cpu_to_le16(CF_NVME_ENABLE
);
400 cmd_pkt
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
401 cmd_pkt
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
402 cmd_pkt
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
403 cmd_pkt
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
404 cmd_pkt
->vp_index
= sp
->fcport
->vha
->vp_idx
;
407 cmd_pkt
->nvme_rsp_dsd_len
= cpu_to_le16(fd
->rsplen
);
408 cmd_pkt
->nvme_rsp_dseg_address
[0] = cpu_to_le32(LSD(fd
->rspdma
));
409 cmd_pkt
->nvme_rsp_dseg_address
[1] = cpu_to_le32(MSD(fd
->rspdma
));
412 cmd_pkt
->nvme_cmnd_dseg_len
= cpu_to_le16(fd
->cmdlen
);
413 cmd_pkt
->nvme_cmnd_dseg_address
[0] = cpu_to_le32(LSD(fd
->cmddma
));
414 cmd_pkt
->nvme_cmnd_dseg_address
[1] = cpu_to_le32(MSD(fd
->cmddma
));
416 cmd_pkt
->dseg_count
= cpu_to_le16(tot_dsds
);
417 cmd_pkt
->byte_count
= cpu_to_le32(fd
->payload_length
);
419 /* One DSD is available in the Command Type NVME IOCB */
421 cur_dsd
= (uint32_t *)&cmd_pkt
->nvme_data_dseg_address
[0];
424 /* Load data segments */
425 for_each_sg(sgl
, sg
, tot_dsds
, i
) {
427 cont_a64_entry_t
*cont_pkt
;
429 /* Allocate additional continuation packets? */
430 if (avail_dsds
== 0) {
432 * Five DSDs are available in the Continuation
436 /* Adjust ring index */
438 if (req
->ring_index
== req
->length
) {
440 req
->ring_ptr
= req
->ring
;
444 cont_pkt
= (cont_a64_entry_t
*)req
->ring_ptr
;
445 *((uint32_t *)(&cont_pkt
->entry_type
)) =
446 cpu_to_le32(CONTINUE_A64_TYPE
);
448 cur_dsd
= (uint32_t *)cont_pkt
->dseg_0_address
;
452 sle_dma
= sg_dma_address(sg
);
453 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
454 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
455 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
459 /* Set total entry count. */
460 cmd_pkt
->entry_count
= (uint8_t)req_cnt
;
463 /* Adjust ring index. */
465 if (req
->ring_index
== req
->length
) {
467 req
->ring_ptr
= req
->ring
;
472 /* Set chip new ring index. */
473 WRT_REG_DWORD(req
->req_q_in
, req
->ring_index
);
476 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
481 static int qla_nvme_post_cmd(struct nvme_fc_local_port
*lport
,
482 struct nvme_fc_remote_port
*rport
, void *hw_queue_handle
,
483 struct nvmefc_fcp_req
*fd
)
486 struct srb_iocb
*nvme
;
487 struct scsi_qla_host
*vha
;
488 int rval
= QLA_FUNCTION_FAILED
;
490 struct qla_qpair
*qpair
= (struct qla_qpair
*)hw_queue_handle
;
491 struct nvme_private
*priv
;
494 ql_log(ql_log_warn
, NULL
, 0x2134, "NO NVMe FCP request\n");
499 fcport
= (fc_port_t
*)rport
->private;
501 ql_log(ql_log_warn
, NULL
, 0x210e, "No fcport ptr\n");
506 if ((!qpair
) || (!(fcport
->nvme_flag
& NVME_FLAG_REGISTERED
)))
509 /* Alloc SRB structure */
510 sp
= qla2xxx_get_qpair_sp(qpair
, fcport
, GFP_ATOMIC
);
514 atomic_set(&sp
->ref_count
, 1);
515 init_waitqueue_head(&sp
->nvme_ls_waitQ
);
517 sp
->type
= SRB_NVME_CMD
;
518 sp
->name
= "nvme_cmd";
519 sp
->done
= qla_nvme_sp_done
;
521 nvme
= &sp
->u
.iocb_cmd
;
522 nvme
->u
.nvme
.desc
= fd
;
524 rval
= qla2x00_start_nvme_mq(sp
);
525 if (rval
!= QLA_SUCCESS
) {
526 ql_log(ql_log_warn
, vha
, 0x212d,
527 "qla2x00_start_nvme_mq failed = %d\n", rval
);
528 atomic_dec(&sp
->ref_count
);
529 wake_up(&sp
->nvme_ls_waitQ
);
536 static void qla_nvme_localport_delete(struct nvme_fc_local_port
*lport
)
538 struct scsi_qla_host
*vha
= lport
->private;
540 atomic_dec(&vha
->nvme_ref_count
);
541 wake_up_all(&vha
->nvme_waitQ
);
543 ql_log(ql_log_info
, vha
, 0x210f,
544 "localport delete of %p completed.\n", vha
->nvme_local_port
);
545 vha
->nvme_local_port
= NULL
;
548 static void qla_nvme_remoteport_delete(struct nvme_fc_remote_port
*rport
)
551 struct nvme_rport
*r_port
, *trport
;
553 fcport
= (fc_port_t
*)rport
->private;
554 fcport
->nvme_remote_port
= NULL
;
555 fcport
->nvme_flag
&= ~NVME_FLAG_REGISTERED
;
556 atomic_dec(&fcport
->nvme_ref_count
);
557 wake_up_all(&fcport
->nvme_waitQ
);
559 list_for_each_entry_safe(r_port
, trport
,
560 &fcport
->vha
->nvme_rport_list
, list
) {
561 if (r_port
->fcport
== fcport
) {
562 list_del(&r_port
->list
);
568 ql_log(ql_log_info
, fcport
->vha
, 0x2110,
569 "remoteport_delete of %p completed.\n", fcport
);
572 static struct nvme_fc_port_template qla_nvme_fc_transport
= {
573 .localport_delete
= qla_nvme_localport_delete
,
574 .remoteport_delete
= qla_nvme_remoteport_delete
,
575 .create_queue
= qla_nvme_alloc_queue
,
576 .delete_queue
= NULL
,
577 .ls_req
= qla_nvme_ls_req
,
578 .ls_abort
= qla_nvme_ls_abort
,
579 .fcp_io
= qla_nvme_post_cmd
,
580 .fcp_abort
= qla_nvme_fcp_abort
,
581 .poll_queue
= qla_nvme_poll
,
583 .max_sgl_segments
= 128,
584 .max_dif_sgl_segments
= 64,
585 .dma_boundary
= 0xFFFFFFFF,
588 .lsrqst_priv_sz
= sizeof(struct nvme_private
),
589 .fcprqst_priv_sz
= sizeof(struct nvme_private
),
592 #define NVME_ABORT_POLLING_PERIOD 2
593 static int qla_nvme_wait_on_command(srb_t
*sp
)
595 int ret
= QLA_SUCCESS
;
597 wait_event_timeout(sp
->nvme_ls_waitQ
, (atomic_read(&sp
->ref_count
) > 1),
598 NVME_ABORT_POLLING_PERIOD
*HZ
);
600 if (atomic_read(&sp
->ref_count
) > 1)
601 ret
= QLA_FUNCTION_FAILED
;
606 static int qla_nvme_wait_on_rport_del(fc_port_t
*fcport
)
608 int ret
= QLA_SUCCESS
;
610 wait_event_timeout(fcport
->nvme_waitQ
,
611 atomic_read(&fcport
->nvme_ref_count
),
612 NVME_ABORT_POLLING_PERIOD
*HZ
);
614 if (atomic_read(&fcport
->nvme_ref_count
)) {
615 ret
= QLA_FUNCTION_FAILED
;
616 ql_log(ql_log_info
, fcport
->vha
, 0x2111,
617 "timed out waiting for fcport=%p to delete\n", fcport
);
623 void qla_nvme_abort(struct qla_hw_data
*ha
, srb_t
*sp
)
627 rval
= ha
->isp_ops
->abort_command(sp
);
629 if (!qla_nvme_wait_on_command(sp
))
630 ql_log(ql_log_warn
, NULL
, 0x2112,
631 "nvme_wait_on_command timed out waiting on sp=%p\n",
636 static void qla_nvme_abort_all(fc_port_t
*fcport
)
641 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
644 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
645 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
646 req
= ha
->req_q_map
[que
];
649 if (!req
->outstanding_cmds
)
651 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++) {
652 sp
= req
->outstanding_cmds
[cnt
];
653 if ((sp
) && ((sp
->type
== SRB_NVME_CMD
) ||
654 (sp
->type
== SRB_NVME_LS
)) &&
655 (sp
->fcport
== fcport
)) {
656 atomic_inc(&sp
->ref_count
);
657 spin_unlock_irqrestore(&ha
->hardware_lock
,
659 qla_nvme_abort(ha
, sp
);
660 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
661 req
->outstanding_cmds
[cnt
] = NULL
;
666 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
669 static void qla_nvme_unregister_remote_port(struct work_struct
*work
)
671 struct fc_port
*fcport
= container_of(work
, struct fc_port
,
673 struct nvme_rport
*rport
, *trport
;
675 if (!IS_ENABLED(CONFIG_NVME_FC
))
678 list_for_each_entry_safe(rport
, trport
,
679 &fcport
->vha
->nvme_rport_list
, list
) {
680 if (rport
->fcport
== fcport
) {
681 ql_log(ql_log_info
, fcport
->vha
, 0x2113,
682 "%s: fcport=%p\n", __func__
, fcport
);
683 nvme_fc_unregister_remoteport(
684 fcport
->nvme_remote_port
);
689 void qla_nvme_delete(scsi_qla_host_t
*vha
)
691 struct nvme_rport
*rport
, *trport
;
695 if (!IS_ENABLED(CONFIG_NVME_FC
))
698 list_for_each_entry_safe(rport
, trport
, &vha
->nvme_rport_list
, list
) {
699 fcport
= rport
->fcport
;
701 ql_log(ql_log_info
, fcport
->vha
, 0x2114, "%s: fcport=%p\n",
704 nvme_fc_unregister_remoteport(fcport
->nvme_remote_port
);
705 qla_nvme_wait_on_rport_del(fcport
);
706 qla_nvme_abort_all(fcport
);
709 if (vha
->nvme_local_port
) {
710 nv_ret
= nvme_fc_unregister_localport(vha
->nvme_local_port
);
712 ql_log(ql_log_info
, vha
, 0x2116,
713 "unregistered localport=%p\n",
714 vha
->nvme_local_port
);
716 ql_log(ql_log_info
, vha
, 0x2115,
717 "Unregister of localport failed\n");
721 void qla_nvme_register_hba(scsi_qla_host_t
*vha
)
723 struct nvme_fc_port_template
*tmpl
;
724 struct qla_hw_data
*ha
;
725 struct nvme_fc_port_info pinfo
;
728 if (!IS_ENABLED(CONFIG_NVME_FC
))
732 tmpl
= &qla_nvme_fc_transport
;
734 WARN_ON(vha
->nvme_local_port
);
735 WARN_ON(ha
->max_req_queues
< 3);
737 qla_nvme_fc_transport
.max_hw_queues
=
738 min((uint8_t)(qla_nvme_fc_transport
.max_hw_queues
),
739 (uint8_t)(ha
->max_req_queues
- 2));
741 pinfo
.node_name
= wwn_to_u64(vha
->node_name
);
742 pinfo
.port_name
= wwn_to_u64(vha
->port_name
);
743 pinfo
.port_role
= FC_PORT_ROLE_NVME_INITIATOR
;
744 pinfo
.port_id
= vha
->d_id
.b24
;
746 ql_log(ql_log_info
, vha
, 0xffff,
747 "register_localport: host-traddr=pn-0x%llx:nn-0x%llx on portID:%x\n",
748 pinfo
.port_name
, pinfo
.node_name
, pinfo
.port_id
);
749 qla_nvme_fc_transport
.dma_boundary
= vha
->host
->dma_boundary
;
751 ret
= nvme_fc_register_localport(&pinfo
, tmpl
,
752 get_device(&ha
->pdev
->dev
), &vha
->nvme_local_port
);
754 ql_log(ql_log_warn
, vha
, 0xffff,
755 "register_localport failed: ret=%x\n", ret
);
758 atomic_set(&vha
->nvme_ref_count
, 1);
759 vha
->nvme_local_port
->private = vha
;
760 init_waitqueue_head(&vha
->nvme_waitQ
);