2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2017 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
8 #include <linux/scatterlist.h>
9 #include <linux/delay.h>
10 #include <linux/nvme.h>
11 #include <linux/nvme-fc.h>
13 static struct nvme_fc_port_template qla_nvme_fc_transport
;
15 static void qla_nvme_unregister_remote_port(struct work_struct
*);
17 int qla_nvme_register_remote(struct scsi_qla_host
*vha
, struct fc_port
*fcport
)
19 struct qla_nvme_rport
*rport
;
20 struct nvme_fc_port_info req
;
23 if (!IS_ENABLED(CONFIG_NVME_FC
))
26 if (!vha
->flags
.nvme_enabled
) {
27 ql_log(ql_log_info
, vha
, 0x2100,
28 "%s: Not registering target since Host NVME is not enabled\n",
33 if (!(fcport
->nvme_prli_service_param
&
34 (NVME_PRLI_SP_TARGET
| NVME_PRLI_SP_DISCOVERY
)) ||
35 (fcport
->nvme_flag
& NVME_FLAG_REGISTERED
))
38 INIT_WORK(&fcport
->nvme_del_work
, qla_nvme_unregister_remote_port
);
39 fcport
->nvme_flag
&= ~NVME_FLAG_RESETTING
;
41 memset(&req
, 0, sizeof(struct nvme_fc_port_info
));
42 req
.port_name
= wwn_to_u64(fcport
->port_name
);
43 req
.node_name
= wwn_to_u64(fcport
->node_name
);
45 req
.dev_loss_tmo
= NVME_FC_DEV_LOSS_TMO
;
47 if (fcport
->nvme_prli_service_param
& NVME_PRLI_SP_INITIATOR
)
48 req
.port_role
= FC_PORT_ROLE_NVME_INITIATOR
;
50 if (fcport
->nvme_prli_service_param
& NVME_PRLI_SP_TARGET
)
51 req
.port_role
|= FC_PORT_ROLE_NVME_TARGET
;
53 if (fcport
->nvme_prli_service_param
& NVME_PRLI_SP_DISCOVERY
)
54 req
.port_role
|= FC_PORT_ROLE_NVME_DISCOVERY
;
56 req
.port_id
= fcport
->d_id
.b24
;
58 ql_log(ql_log_info
, vha
, 0x2102,
59 "%s: traddr=nn-0x%016llx:pn-0x%016llx PortID:%06x\n",
60 __func__
, req
.node_name
, req
.port_name
,
63 ret
= nvme_fc_register_remoteport(vha
->nvme_local_port
, &req
,
64 &fcport
->nvme_remote_port
);
66 ql_log(ql_log_warn
, vha
, 0x212e,
67 "Failed to register remote port. Transport returned %d\n",
72 rport
= fcport
->nvme_remote_port
->private;
73 rport
->fcport
= fcport
;
74 list_add_tail(&rport
->list
, &vha
->nvme_rport_list
);
76 fcport
->nvme_flag
|= NVME_FLAG_REGISTERED
;
80 /* Allocate a queue for NVMe traffic */
81 static int qla_nvme_alloc_queue(struct nvme_fc_local_port
*lport
,
82 unsigned int qidx
, u16 qsize
, void **handle
)
84 struct scsi_qla_host
*vha
;
85 struct qla_hw_data
*ha
;
86 struct qla_qpair
*qpair
;
91 vha
= (struct scsi_qla_host
*)lport
->private;
94 ql_log(ql_log_info
, vha
, 0x2104,
95 "%s: handle %p, idx =%d, qsize %d\n",
96 __func__
, handle
, qidx
, qsize
);
98 if (qidx
> qla_nvme_fc_transport
.max_hw_queues
) {
99 ql_log(ql_log_warn
, vha
, 0x212f,
100 "%s: Illegal qidx=%d. Max=%d\n",
101 __func__
, qidx
, qla_nvme_fc_transport
.max_hw_queues
);
105 if (ha
->queue_pair_map
[qidx
]) {
106 *handle
= ha
->queue_pair_map
[qidx
];
107 ql_log(ql_log_info
, vha
, 0x2121,
108 "Returning existing qpair of %p for idx=%x\n",
113 qpair
= qla2xxx_create_qpair(vha
, 5, vha
->vp_idx
, true);
115 ql_log(ql_log_warn
, vha
, 0x2122,
116 "Failed to allocate qpair\n");
124 static void qla_nvme_sp_ls_done(void *ptr
, int res
)
127 struct srb_iocb
*nvme
;
128 struct nvmefc_ls_req
*fd
;
129 struct nvme_private
*priv
;
131 if (atomic_read(&sp
->ref_count
) == 0) {
132 ql_log(ql_log_warn
, sp
->fcport
->vha
, 0x2123,
133 "SP reference-count to ZERO on LS_done -- sp=%p.\n", sp
);
137 if (!atomic_dec_and_test(&sp
->ref_count
))
143 nvme
= &sp
->u
.iocb_cmd
;
144 fd
= nvme
->u
.nvme
.desc
;
146 priv
->comp_status
= res
;
147 schedule_work(&priv
->ls_work
);
148 /* work schedule doesn't need the sp */
152 static void qla_nvme_sp_done(void *ptr
, int res
)
155 struct srb_iocb
*nvme
;
156 struct nvmefc_fcp_req
*fd
;
158 nvme
= &sp
->u
.iocb_cmd
;
159 fd
= nvme
->u
.nvme
.desc
;
161 if (!atomic_dec_and_test(&sp
->ref_count
))
164 if (res
== QLA_SUCCESS
)
167 fd
->status
= NVME_SC_INTERNAL
;
169 fd
->rcv_rsplen
= nvme
->u
.nvme
.rsp_pyld_len
;
171 qla2xxx_rel_qpair_sp(sp
->qpair
, sp
);
176 static void qla_nvme_abort_work(struct work_struct
*work
)
178 struct nvme_private
*priv
=
179 container_of(work
, struct nvme_private
, abort_work
);
180 srb_t
*sp
= priv
->sp
;
181 fc_port_t
*fcport
= sp
->fcport
;
182 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
185 rval
= ha
->isp_ops
->abort_command(sp
);
187 ql_dbg(ql_dbg_io
, fcport
->vha
, 0x212b,
188 "%s: %s command for sp=%p, handle=%x on fcport=%p rval=%x\n",
189 __func__
, (rval
!= QLA_SUCCESS
) ? "Failed to abort" : "Aborted",
190 sp
, sp
->handle
, fcport
, rval
);
193 static void qla_nvme_ls_abort(struct nvme_fc_local_port
*lport
,
194 struct nvme_fc_remote_port
*rport
, struct nvmefc_ls_req
*fd
)
196 struct nvme_private
*priv
= fd
->private;
198 INIT_WORK(&priv
->abort_work
, qla_nvme_abort_work
);
199 schedule_work(&priv
->abort_work
);
202 static void qla_nvme_ls_complete(struct work_struct
*work
)
204 struct nvme_private
*priv
=
205 container_of(work
, struct nvme_private
, ls_work
);
206 struct nvmefc_ls_req
*fd
= priv
->fd
;
208 fd
->done(fd
, priv
->comp_status
);
211 static int qla_nvme_ls_req(struct nvme_fc_local_port
*lport
,
212 struct nvme_fc_remote_port
*rport
, struct nvmefc_ls_req
*fd
)
214 struct qla_nvme_rport
*qla_rport
= rport
->private;
215 fc_port_t
*fcport
= qla_rport
->fcport
;
216 struct srb_iocb
*nvme
;
217 struct nvme_private
*priv
= fd
->private;
218 struct scsi_qla_host
*vha
;
219 int rval
= QLA_FUNCTION_FAILED
;
220 struct qla_hw_data
*ha
;
225 /* Alloc SRB structure */
226 sp
= qla2x00_get_sp(vha
, fcport
, GFP_ATOMIC
);
230 sp
->type
= SRB_NVME_LS
;
231 sp
->name
= "nvme_ls";
232 sp
->done
= qla_nvme_sp_ls_done
;
233 atomic_set(&sp
->ref_count
, 1);
234 nvme
= &sp
->u
.iocb_cmd
;
237 INIT_WORK(&priv
->ls_work
, qla_nvme_ls_complete
);
238 nvme
->u
.nvme
.desc
= fd
;
239 nvme
->u
.nvme
.dir
= 0;
241 nvme
->u
.nvme
.cmd_len
= fd
->rqstlen
;
242 nvme
->u
.nvme
.rsp_len
= fd
->rsplen
;
243 nvme
->u
.nvme
.rsp_dma
= fd
->rspdma
;
244 nvme
->u
.nvme
.timeout_sec
= fd
->timeout
;
245 nvme
->u
.nvme
.cmd_dma
= dma_map_single(&ha
->pdev
->dev
, fd
->rqstaddr
,
246 fd
->rqstlen
, DMA_TO_DEVICE
);
247 dma_sync_single_for_device(&ha
->pdev
->dev
, nvme
->u
.nvme
.cmd_dma
,
248 fd
->rqstlen
, DMA_TO_DEVICE
);
250 rval
= qla2x00_start_sp(sp
);
251 if (rval
!= QLA_SUCCESS
) {
252 ql_log(ql_log_warn
, vha
, 0x700e,
253 "qla2x00_start_sp failed = %d\n", rval
);
254 atomic_dec(&sp
->ref_count
);
255 wake_up(&sp
->nvme_ls_waitq
);
262 static void qla_nvme_fcp_abort(struct nvme_fc_local_port
*lport
,
263 struct nvme_fc_remote_port
*rport
, void *hw_queue_handle
,
264 struct nvmefc_fcp_req
*fd
)
266 struct nvme_private
*priv
= fd
->private;
268 INIT_WORK(&priv
->abort_work
, qla_nvme_abort_work
);
269 schedule_work(&priv
->abort_work
);
272 static void qla_nvme_poll(struct nvme_fc_local_port
*lport
, void *hw_queue_handle
)
274 struct qla_qpair
*qpair
= hw_queue_handle
;
276 struct scsi_qla_host
*vha
= lport
->private;
278 spin_lock_irqsave(&qpair
->qp_lock
, flags
);
279 qla24xx_process_response_queue(vha
, qpair
->rsp
);
280 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
283 static inline int qla2x00_start_nvme_mq(srb_t
*sp
)
289 struct cmd_nvme
*cmd_pkt
;
295 struct req_que
*req
= NULL
;
296 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
297 struct qla_hw_data
*ha
= vha
->hw
;
298 struct qla_qpair
*qpair
= sp
->qpair
;
299 struct srb_iocb
*nvme
= &sp
->u
.iocb_cmd
;
300 struct scatterlist
*sgl
, *sg
;
301 struct nvmefc_fcp_req
*fd
= nvme
->u
.nvme
.desc
;
302 uint32_t rval
= QLA_SUCCESS
;
304 /* Setup qpair pointers */
306 tot_dsds
= fd
->sg_cnt
;
308 /* Acquire qpair specific lock */
309 spin_lock_irqsave(&qpair
->qp_lock
, flags
);
311 /* Check for room in outstanding command list. */
312 handle
= req
->current_outstanding_cmd
;
313 for (index
= 1; index
< req
->num_outstanding_cmds
; index
++) {
315 if (handle
== req
->num_outstanding_cmds
)
317 if (!req
->outstanding_cmds
[handle
])
321 if (index
== req
->num_outstanding_cmds
) {
325 req_cnt
= qla24xx_calc_iocbs(vha
, tot_dsds
);
326 if (req
->cnt
< (req_cnt
+ 2)) {
327 cnt
= IS_SHADOW_REG_CAPABLE(ha
) ? *req
->out_ptr
:
328 RD_REG_DWORD_RELAXED(req
->req_q_out
);
330 if (req
->ring_index
< cnt
)
331 req
->cnt
= cnt
- req
->ring_index
;
333 req
->cnt
= req
->length
- (req
->ring_index
- cnt
);
335 if (req
->cnt
< (req_cnt
+ 2)){
341 if (unlikely(!fd
->sqid
)) {
342 struct nvme_fc_cmd_iu
*cmd
= fd
->cmdaddr
;
343 if (cmd
->sqe
.common
.opcode
== nvme_admin_async_event
) {
344 nvme
->u
.nvme
.aen_op
= 1;
345 atomic_inc(&ha
->nvme_active_aen_cnt
);
349 /* Build command packet. */
350 req
->current_outstanding_cmd
= handle
;
351 req
->outstanding_cmds
[handle
] = sp
;
355 cmd_pkt
= (struct cmd_nvme
*)req
->ring_ptr
;
356 cmd_pkt
->handle
= MAKE_HANDLE(req
->id
, handle
);
358 /* Zero out remaining portion of packet. */
359 clr_ptr
= (uint32_t *)cmd_pkt
+ 2;
360 memset(clr_ptr
, 0, REQUEST_ENTRY_SIZE
- 8);
362 cmd_pkt
->entry_status
= 0;
364 /* Update entry type to indicate Command NVME IOCB */
365 cmd_pkt
->entry_type
= COMMAND_NVME
;
367 /* No data transfer how do we check buffer len == 0?? */
368 if (fd
->io_dir
== NVMEFC_FCP_READ
) {
369 cmd_pkt
->control_flags
=
370 cpu_to_le16(CF_READ_DATA
| CF_NVME_ENABLE
);
371 vha
->qla_stats
.input_bytes
+= fd
->payload_length
;
372 vha
->qla_stats
.input_requests
++;
373 } else if (fd
->io_dir
== NVMEFC_FCP_WRITE
) {
374 cmd_pkt
->control_flags
=
375 cpu_to_le16(CF_WRITE_DATA
| CF_NVME_ENABLE
);
376 vha
->qla_stats
.output_bytes
+= fd
->payload_length
;
377 vha
->qla_stats
.output_requests
++;
378 } else if (fd
->io_dir
== 0) {
379 cmd_pkt
->control_flags
= cpu_to_le16(CF_NVME_ENABLE
);
383 cmd_pkt
->nport_handle
= cpu_to_le16(sp
->fcport
->loop_id
);
384 cmd_pkt
->port_id
[0] = sp
->fcport
->d_id
.b
.al_pa
;
385 cmd_pkt
->port_id
[1] = sp
->fcport
->d_id
.b
.area
;
386 cmd_pkt
->port_id
[2] = sp
->fcport
->d_id
.b
.domain
;
387 cmd_pkt
->vp_index
= sp
->fcport
->vha
->vp_idx
;
390 cmd_pkt
->nvme_rsp_dsd_len
= cpu_to_le16(fd
->rsplen
);
391 cmd_pkt
->nvme_rsp_dseg_address
[0] = cpu_to_le32(LSD(fd
->rspdma
));
392 cmd_pkt
->nvme_rsp_dseg_address
[1] = cpu_to_le32(MSD(fd
->rspdma
));
395 cmd_pkt
->nvme_cmnd_dseg_len
= cpu_to_le16(fd
->cmdlen
);
396 cmd_pkt
->nvme_cmnd_dseg_address
[0] = cpu_to_le32(LSD(fd
->cmddma
));
397 cmd_pkt
->nvme_cmnd_dseg_address
[1] = cpu_to_le32(MSD(fd
->cmddma
));
399 cmd_pkt
->dseg_count
= cpu_to_le16(tot_dsds
);
400 cmd_pkt
->byte_count
= cpu_to_le32(fd
->payload_length
);
402 /* One DSD is available in the Command Type NVME IOCB */
404 cur_dsd
= (uint32_t *)&cmd_pkt
->nvme_data_dseg_address
[0];
407 /* Load data segments */
408 for_each_sg(sgl
, sg
, tot_dsds
, i
) {
410 cont_a64_entry_t
*cont_pkt
;
412 /* Allocate additional continuation packets? */
413 if (avail_dsds
== 0) {
415 * Five DSDs are available in the Continuation
419 /* Adjust ring index */
421 if (req
->ring_index
== req
->length
) {
423 req
->ring_ptr
= req
->ring
;
427 cont_pkt
= (cont_a64_entry_t
*)req
->ring_ptr
;
428 *((uint32_t *)(&cont_pkt
->entry_type
)) =
429 cpu_to_le32(CONTINUE_A64_TYPE
);
431 cur_dsd
= (uint32_t *)cont_pkt
->dseg_0_address
;
435 sle_dma
= sg_dma_address(sg
);
436 *cur_dsd
++ = cpu_to_le32(LSD(sle_dma
));
437 *cur_dsd
++ = cpu_to_le32(MSD(sle_dma
));
438 *cur_dsd
++ = cpu_to_le32(sg_dma_len(sg
));
442 /* Set total entry count. */
443 cmd_pkt
->entry_count
= (uint8_t)req_cnt
;
446 /* Adjust ring index. */
448 if (req
->ring_index
== req
->length
) {
450 req
->ring_ptr
= req
->ring
;
455 /* Set chip new ring index. */
456 WRT_REG_DWORD(req
->req_q_in
, req
->ring_index
);
459 spin_unlock_irqrestore(&qpair
->qp_lock
, flags
);
464 static int qla_nvme_post_cmd(struct nvme_fc_local_port
*lport
,
465 struct nvme_fc_remote_port
*rport
, void *hw_queue_handle
,
466 struct nvmefc_fcp_req
*fd
)
469 struct srb_iocb
*nvme
;
470 struct scsi_qla_host
*vha
;
473 struct qla_qpair
*qpair
= hw_queue_handle
;
474 struct nvme_private
*priv
;
475 struct qla_nvme_rport
*qla_rport
= rport
->private;
478 ql_log(ql_log_warn
, NULL
, 0x2134,
479 "NO NVMe request or Queue Handle\n");
484 fcport
= qla_rport
->fcport
;
486 ql_log(ql_log_warn
, NULL
, 0x210e, "No fcport ptr\n");
492 if (test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
))
496 * If we know the dev is going away while the transport is still sending
497 * IO's return busy back to stall the IO Q. This happens when the
498 * link goes away and fw hasn't notified us yet, but IO's are being
499 * returned. If the dev comes back quickly we won't exhaust the IO
500 * retry count at the core.
502 if (fcport
->nvme_flag
& NVME_FLAG_RESETTING
)
505 /* Alloc SRB structure */
506 sp
= qla2xxx_get_qpair_sp(qpair
, fcport
, GFP_ATOMIC
);
510 atomic_set(&sp
->ref_count
, 1);
511 init_waitqueue_head(&sp
->nvme_ls_waitq
);
513 sp
->type
= SRB_NVME_CMD
;
514 sp
->name
= "nvme_cmd";
515 sp
->done
= qla_nvme_sp_done
;
517 nvme
= &sp
->u
.iocb_cmd
;
518 nvme
->u
.nvme
.desc
= fd
;
520 rval
= qla2x00_start_nvme_mq(sp
);
521 if (rval
!= QLA_SUCCESS
) {
522 ql_log(ql_log_warn
, vha
, 0x212d,
523 "qla2x00_start_nvme_mq failed = %d\n", rval
);
524 atomic_dec(&sp
->ref_count
);
525 wake_up(&sp
->nvme_ls_waitq
);
531 static void qla_nvme_localport_delete(struct nvme_fc_local_port
*lport
)
533 struct scsi_qla_host
*vha
= lport
->private;
535 ql_log(ql_log_info
, vha
, 0x210f,
536 "localport delete of %p completed.\n", vha
->nvme_local_port
);
537 vha
->nvme_local_port
= NULL
;
538 complete(&vha
->nvme_del_done
);
541 static void qla_nvme_remoteport_delete(struct nvme_fc_remote_port
*rport
)
544 struct qla_nvme_rport
*qla_rport
= rport
->private, *trport
;
546 fcport
= qla_rport
->fcport
;
547 fcport
->nvme_remote_port
= NULL
;
548 fcport
->nvme_flag
&= ~NVME_FLAG_REGISTERED
;
550 list_for_each_entry_safe(qla_rport
, trport
,
551 &fcport
->vha
->nvme_rport_list
, list
) {
552 if (qla_rport
->fcport
== fcport
) {
553 list_del(&qla_rport
->list
);
557 complete(&fcport
->nvme_del_done
);
559 if (!test_bit(UNLOADING
, &fcport
->vha
->dpc_flags
)) {
560 INIT_WORK(&fcport
->free_work
, qlt_free_session_done
);
561 schedule_work(&fcport
->free_work
);
564 fcport
->nvme_flag
&= ~(NVME_FLAG_REGISTERED
| NVME_FLAG_DELETING
);
565 ql_log(ql_log_info
, fcport
->vha
, 0x2110,
566 "remoteport_delete of %p completed.\n", fcport
);
569 static struct nvme_fc_port_template qla_nvme_fc_transport
= {
570 .localport_delete
= qla_nvme_localport_delete
,
571 .remoteport_delete
= qla_nvme_remoteport_delete
,
572 .create_queue
= qla_nvme_alloc_queue
,
573 .delete_queue
= NULL
,
574 .ls_req
= qla_nvme_ls_req
,
575 .ls_abort
= qla_nvme_ls_abort
,
576 .fcp_io
= qla_nvme_post_cmd
,
577 .fcp_abort
= qla_nvme_fcp_abort
,
578 .poll_queue
= qla_nvme_poll
,
580 .max_sgl_segments
= 128,
581 .max_dif_sgl_segments
= 64,
582 .dma_boundary
= 0xFFFFFFFF,
584 .remote_priv_sz
= sizeof(struct qla_nvme_rport
),
585 .lsrqst_priv_sz
= sizeof(struct nvme_private
),
586 .fcprqst_priv_sz
= sizeof(struct nvme_private
),
589 #define NVME_ABORT_POLLING_PERIOD 2
590 static int qla_nvme_wait_on_command(srb_t
*sp
)
592 int ret
= QLA_SUCCESS
;
594 wait_event_timeout(sp
->nvme_ls_waitq
, (atomic_read(&sp
->ref_count
) > 1),
595 NVME_ABORT_POLLING_PERIOD
*HZ
);
597 if (atomic_read(&sp
->ref_count
) > 1)
598 ret
= QLA_FUNCTION_FAILED
;
603 void qla_nvme_abort(struct qla_hw_data
*ha
, struct srb
*sp
, int res
)
607 if (!test_bit(ABORT_ISP_ACTIVE
, &sp
->vha
->dpc_flags
)) {
608 rval
= ha
->isp_ops
->abort_command(sp
);
609 if (!rval
&& !qla_nvme_wait_on_command(sp
))
610 ql_log(ql_log_warn
, NULL
, 0x2112,
611 "timed out waiting on sp=%p\n", sp
);
617 static void qla_nvme_unregister_remote_port(struct work_struct
*work
)
619 struct fc_port
*fcport
= container_of(work
, struct fc_port
,
621 struct qla_nvme_rport
*qla_rport
, *trport
;
623 if (!IS_ENABLED(CONFIG_NVME_FC
))
626 ql_log(ql_log_warn
, NULL
, 0x2112,
627 "%s: unregister remoteport on %p\n",__func__
, fcport
);
629 list_for_each_entry_safe(qla_rport
, trport
,
630 &fcport
->vha
->nvme_rport_list
, list
) {
631 if (qla_rport
->fcport
== fcport
) {
632 ql_log(ql_log_info
, fcport
->vha
, 0x2113,
633 "%s: fcport=%p\n", __func__
, fcport
);
634 init_completion(&fcport
->nvme_del_done
);
635 nvme_fc_unregister_remoteport(
636 fcport
->nvme_remote_port
);
637 wait_for_completion(&fcport
->nvme_del_done
);
643 void qla_nvme_delete(struct scsi_qla_host
*vha
)
645 struct qla_nvme_rport
*qla_rport
, *trport
;
649 if (!IS_ENABLED(CONFIG_NVME_FC
))
652 list_for_each_entry_safe(qla_rport
, trport
,
653 &vha
->nvme_rport_list
, list
) {
654 fcport
= qla_rport
->fcport
;
656 ql_log(ql_log_info
, fcport
->vha
, 0x2114, "%s: fcport=%p\n",
659 nvme_fc_set_remoteport_devloss(fcport
->nvme_remote_port
, 0);
660 init_completion(&fcport
->nvme_del_done
);
661 nvme_fc_unregister_remoteport(fcport
->nvme_remote_port
);
662 wait_for_completion(&fcport
->nvme_del_done
);
665 if (vha
->nvme_local_port
) {
666 init_completion(&vha
->nvme_del_done
);
667 ql_log(ql_log_info
, vha
, 0x2116,
668 "unregister localport=%p\n",
669 vha
->nvme_local_port
);
670 nv_ret
= nvme_fc_unregister_localport(vha
->nvme_local_port
);
672 ql_log(ql_log_info
, vha
, 0x2115,
673 "Unregister of localport failed\n");
675 wait_for_completion(&vha
->nvme_del_done
);
679 void qla_nvme_register_hba(struct scsi_qla_host
*vha
)
681 struct nvme_fc_port_template
*tmpl
;
682 struct qla_hw_data
*ha
;
683 struct nvme_fc_port_info pinfo
;
686 if (!IS_ENABLED(CONFIG_NVME_FC
))
690 tmpl
= &qla_nvme_fc_transport
;
692 WARN_ON(vha
->nvme_local_port
);
693 WARN_ON(ha
->max_req_queues
< 3);
695 qla_nvme_fc_transport
.max_hw_queues
=
696 min((uint8_t)(qla_nvme_fc_transport
.max_hw_queues
),
697 (uint8_t)(ha
->max_req_queues
- 2));
699 pinfo
.node_name
= wwn_to_u64(vha
->node_name
);
700 pinfo
.port_name
= wwn_to_u64(vha
->port_name
);
701 pinfo
.port_role
= FC_PORT_ROLE_NVME_INITIATOR
;
702 pinfo
.port_id
= vha
->d_id
.b24
;
704 ql_log(ql_log_info
, vha
, 0xffff,
705 "register_localport: host-traddr=nn-0x%llx:pn-0x%llx on portID:%x\n",
706 pinfo
.node_name
, pinfo
.port_name
, pinfo
.port_id
);
707 qla_nvme_fc_transport
.dma_boundary
= vha
->host
->dma_boundary
;
709 ret
= nvme_fc_register_localport(&pinfo
, tmpl
,
710 get_device(&ha
->pdev
->dev
), &vha
->nvme_local_port
);
712 ql_log(ql_log_warn
, vha
, 0xffff,
713 "register_localport failed: ret=%x\n", ret
);
716 vha
->nvme_local_port
->private = vha
;