1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2017 QLogic Corporation
7 #include <linux/scatterlist.h>
8 #include <linux/delay.h>
9 #include <linux/nvme.h>
10 #include <linux/nvme-fc.h>
12 static struct nvme_fc_port_template qla_nvme_fc_transport;
14 int qla_nvme_register_remote(struct scsi_qla_host *vha, struct fc_port *fcport)
16 struct qla_nvme_rport *rport;
17 struct nvme_fc_port_info req;
20 if (!IS_ENABLED(CONFIG_NVME_FC))
23 if (!vha->flags.nvme_enabled) {
24 ql_log(ql_log_info, vha, 0x2100,
25 "%s: Not registering target since Host NVME is not enabled\n",
30 if (!vha->nvme_local_port && qla_nvme_register_hba(vha))
33 if (!(fcport->nvme_prli_service_param &
34 (NVME_PRLI_SP_TARGET | NVME_PRLI_SP_DISCOVERY)) ||
35 (fcport->nvme_flag & NVME_FLAG_REGISTERED))
38 if (atomic_read(&fcport->state) == FCS_ONLINE)
41 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
43 fcport->nvme_flag &= ~NVME_FLAG_RESETTING;
45 memset(&req, 0, sizeof(struct nvme_fc_port_info));
46 req.port_name = wwn_to_u64(fcport->port_name);
47 req.node_name = wwn_to_u64(fcport->node_name);
51 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_INITIATOR)
52 req.port_role = FC_PORT_ROLE_NVME_INITIATOR;
54 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_TARGET)
55 req.port_role |= FC_PORT_ROLE_NVME_TARGET;
57 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_DISCOVERY)
58 req.port_role |= FC_PORT_ROLE_NVME_DISCOVERY;
60 req.port_id = fcport->d_id.b24;
62 ql_log(ql_log_info, vha, 0x2102,
63 "%s: traddr=nn-0x%016llx:pn-0x%016llx PortID:%06x\n",
64 __func__, req.node_name, req.port_name,
67 ret = nvme_fc_register_remoteport(vha->nvme_local_port, &req,
68 &fcport->nvme_remote_port);
70 ql_log(ql_log_warn, vha, 0x212e,
71 "Failed to register remote port. Transport returned %d\n",
76 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_SLER)
77 ql_log(ql_log_info, vha, 0x212a,
78 "PortID:%06x Supports SLER\n", req.port_id);
80 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_PI_CTRL)
81 ql_log(ql_log_info, vha, 0x212b,
82 "PortID:%06x Supports PI control\n", req.port_id);
84 rport = fcport->nvme_remote_port->private;
85 rport->fcport = fcport;
87 fcport->nvme_flag |= NVME_FLAG_REGISTERED;
91 /* Allocate a queue for NVMe traffic */
92 static int qla_nvme_alloc_queue(struct nvme_fc_local_port *lport,
93 unsigned int qidx, u16 qsize, void **handle)
95 struct scsi_qla_host *vha;
96 struct qla_hw_data *ha;
97 struct qla_qpair *qpair;
99 /* Map admin queue and 1st IO queue to index 0 */
103 vha = (struct scsi_qla_host *)lport->private;
106 ql_log(ql_log_info, vha, 0x2104,
107 "%s: handle %p, idx =%d, qsize %d\n",
108 __func__, handle, qidx, qsize);
110 if (qidx > qla_nvme_fc_transport.max_hw_queues) {
111 ql_log(ql_log_warn, vha, 0x212f,
112 "%s: Illegal qidx=%d. Max=%d\n",
113 __func__, qidx, qla_nvme_fc_transport.max_hw_queues);
117 /* Use base qpair if max_qpairs is 0 */
118 if (!ha->max_qpairs) {
119 qpair = ha->base_qpair;
121 if (ha->queue_pair_map[qidx]) {
122 *handle = ha->queue_pair_map[qidx];
123 ql_log(ql_log_info, vha, 0x2121,
124 "Returning existing qpair of %p for idx=%x\n",
129 qpair = qla2xxx_create_qpair(vha, 5, vha->vp_idx, true);
131 ql_log(ql_log_warn, vha, 0x2122,
132 "Failed to allocate qpair\n");
141 static void qla_nvme_release_fcp_cmd_kref(struct kref *kref)
143 struct srb *sp = container_of(kref, struct srb, cmd_kref);
144 struct nvme_private *priv = (struct nvme_private *)sp->priv;
145 struct nvmefc_fcp_req *fd;
146 struct srb_iocb *nvme;
152 nvme = &sp->u.iocb_cmd;
153 fd = nvme->u.nvme.desc;
155 spin_lock_irqsave(&priv->cmd_lock, flags);
158 if (priv->comp_status == QLA_SUCCESS) {
159 fd->rcv_rsplen = le16_to_cpu(nvme->u.nvme.rsp_pyld_len);
160 fd->status = NVME_SC_SUCCESS;
163 fd->transferred_length = 0;
164 fd->status = NVME_SC_INTERNAL;
166 spin_unlock_irqrestore(&priv->cmd_lock, flags);
170 qla2xxx_rel_qpair_sp(sp->qpair, sp);
173 static void qla_nvme_ls_unmap(struct srb *sp, struct nvmefc_ls_req *fd)
175 if (sp->flags & SRB_DMA_VALID) {
176 struct srb_iocb *nvme = &sp->u.iocb_cmd;
177 struct qla_hw_data *ha = sp->fcport->vha->hw;
179 dma_unmap_single(&ha->pdev->dev, nvme->u.nvme.cmd_dma,
180 fd->rqstlen, DMA_TO_DEVICE);
181 sp->flags &= ~SRB_DMA_VALID;
185 static void qla_nvme_release_ls_cmd_kref(struct kref *kref)
187 struct srb *sp = container_of(kref, struct srb, cmd_kref);
188 struct nvme_private *priv = (struct nvme_private *)sp->priv;
189 struct nvmefc_ls_req *fd;
195 spin_lock_irqsave(&priv->cmd_lock, flags);
198 spin_unlock_irqrestore(&priv->cmd_lock, flags);
202 qla_nvme_ls_unmap(sp, fd);
203 fd->done(fd, priv->comp_status);
208 static void qla_nvme_ls_complete(struct work_struct *work)
210 struct nvme_private *priv =
211 container_of(work, struct nvme_private, ls_work);
213 kref_put(&priv->sp->cmd_kref, qla_nvme_release_ls_cmd_kref);
216 static void qla_nvme_sp_ls_done(srb_t *sp, int res)
218 struct nvme_private *priv = sp->priv;
220 if (WARN_ON_ONCE(kref_read(&sp->cmd_kref) == 0))
226 priv->comp_status = res;
227 INIT_WORK(&priv->ls_work, qla_nvme_ls_complete);
228 schedule_work(&priv->ls_work);
231 /* it assumed that QPair lock is held. */
232 static void qla_nvme_sp_done(srb_t *sp, int res)
234 struct nvme_private *priv = sp->priv;
236 priv->comp_status = res;
237 kref_put(&sp->cmd_kref, qla_nvme_release_fcp_cmd_kref);
242 static void qla_nvme_abort_work(struct work_struct *work)
244 struct nvme_private *priv =
245 container_of(work, struct nvme_private, abort_work);
246 srb_t *sp = priv->sp;
247 fc_port_t *fcport = sp->fcport;
248 struct qla_hw_data *ha = fcport->vha->hw;
249 int rval, abts_done_called = 1;
250 bool io_wait_for_abort_done;
253 ql_dbg(ql_dbg_io, fcport->vha, 0xffff,
254 "%s called for sp=%p, hndl=%x on fcport=%p desc=%p deleted=%d\n",
255 __func__, sp, sp->handle, fcport, sp->u.iocb_cmd.u.nvme.desc, fcport->deleted);
257 if (!ha->flags.fw_started || fcport->deleted == QLA_SESS_DELETED)
260 if (ha->flags.host_shutting_down) {
261 ql_log(ql_log_info, sp->fcport->vha, 0xffff,
262 "%s Calling done on sp: %p, type: 0x%x\n",
263 __func__, sp, sp->type);
269 * sp may not be valid after abort_command if return code is either
270 * SUCCESS or ERR_FROM_FW codes, so cache the value here.
272 io_wait_for_abort_done = ql2xabts_wait_nvme &&
273 QLA_ABTS_WAIT_ENABLED(sp);
276 rval = ha->isp_ops->abort_command(sp);
278 ql_dbg(ql_dbg_io, fcport->vha, 0x212b,
279 "%s: %s command for sp=%p, handle=%x on fcport=%p rval=%x\n",
280 __func__, (rval != QLA_SUCCESS) ? "Failed to abort" : "Aborted",
281 sp, handle, fcport, rval);
284 * If async tmf is enabled, the abort callback is called only on
285 * return codes QLA_SUCCESS and QLA_ERR_FROM_FW.
287 if (ql2xasynctmfenable &&
288 rval != QLA_SUCCESS && rval != QLA_ERR_FROM_FW)
289 abts_done_called = 0;
292 * Returned before decreasing kref so that I/O requests
293 * are waited until ABTS complete. This kref is decreased
294 * at qla24xx_abort_sp_done function.
296 if (abts_done_called && io_wait_for_abort_done)
299 /* kref_get was done before work was schedule. */
300 kref_put(&sp->cmd_kref, sp->put_fn);
303 static void qla_nvme_ls_abort(struct nvme_fc_local_port *lport,
304 struct nvme_fc_remote_port *rport, struct nvmefc_ls_req *fd)
306 struct nvme_private *priv = fd->private;
309 spin_lock_irqsave(&priv->cmd_lock, flags);
311 spin_unlock_irqrestore(&priv->cmd_lock, flags);
315 if (!kref_get_unless_zero(&priv->sp->cmd_kref)) {
316 spin_unlock_irqrestore(&priv->cmd_lock, flags);
319 spin_unlock_irqrestore(&priv->cmd_lock, flags);
321 INIT_WORK(&priv->abort_work, qla_nvme_abort_work);
322 schedule_work(&priv->abort_work);
325 static int qla_nvme_ls_req(struct nvme_fc_local_port *lport,
326 struct nvme_fc_remote_port *rport, struct nvmefc_ls_req *fd)
328 struct qla_nvme_rport *qla_rport = rport->private;
329 fc_port_t *fcport = qla_rport->fcport;
330 struct srb_iocb *nvme;
331 struct nvme_private *priv = fd->private;
332 struct scsi_qla_host *vha;
333 int rval = QLA_FUNCTION_FAILED;
334 struct qla_hw_data *ha;
337 if (!fcport || fcport->deleted)
343 if (!ha->flags.fw_started)
346 /* Alloc SRB structure */
347 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
351 sp->type = SRB_NVME_LS;
352 sp->name = "nvme_ls";
353 sp->done = qla_nvme_sp_ls_done;
354 sp->put_fn = qla_nvme_release_ls_cmd_kref;
357 kref_init(&sp->cmd_kref);
358 spin_lock_init(&priv->cmd_lock);
359 nvme = &sp->u.iocb_cmd;
361 nvme->u.nvme.desc = fd;
362 nvme->u.nvme.dir = 0;
364 nvme->u.nvme.cmd_len = fd->rqstlen;
365 nvme->u.nvme.rsp_len = fd->rsplen;
366 nvme->u.nvme.rsp_dma = fd->rspdma;
367 nvme->u.nvme.timeout_sec = fd->timeout;
368 nvme->u.nvme.cmd_dma = dma_map_single(&ha->pdev->dev, fd->rqstaddr,
369 fd->rqstlen, DMA_TO_DEVICE);
370 dma_sync_single_for_device(&ha->pdev->dev, nvme->u.nvme.cmd_dma,
371 fd->rqstlen, DMA_TO_DEVICE);
373 sp->flags |= SRB_DMA_VALID;
375 rval = qla2x00_start_sp(sp);
376 if (rval != QLA_SUCCESS) {
377 ql_log(ql_log_warn, vha, 0x700e,
378 "qla2x00_start_sp failed = %d\n", rval);
379 wake_up(&sp->nvme_ls_waitq);
382 qla_nvme_ls_unmap(sp, fd);
390 static void qla_nvme_fcp_abort(struct nvme_fc_local_port *lport,
391 struct nvme_fc_remote_port *rport, void *hw_queue_handle,
392 struct nvmefc_fcp_req *fd)
394 struct nvme_private *priv = fd->private;
397 spin_lock_irqsave(&priv->cmd_lock, flags);
399 spin_unlock_irqrestore(&priv->cmd_lock, flags);
402 if (!kref_get_unless_zero(&priv->sp->cmd_kref)) {
403 spin_unlock_irqrestore(&priv->cmd_lock, flags);
406 spin_unlock_irqrestore(&priv->cmd_lock, flags);
408 INIT_WORK(&priv->abort_work, qla_nvme_abort_work);
409 schedule_work(&priv->abort_work);
412 static inline int qla2x00_start_nvme_mq(srb_t *sp)
417 struct cmd_nvme *cmd_pkt;
422 struct dsd64 *cur_dsd;
423 struct req_que *req = NULL;
424 struct scsi_qla_host *vha = sp->fcport->vha;
425 struct qla_hw_data *ha = vha->hw;
426 struct qla_qpair *qpair = sp->qpair;
427 struct srb_iocb *nvme = &sp->u.iocb_cmd;
428 struct scatterlist *sgl, *sg;
429 struct nvmefc_fcp_req *fd = nvme->u.nvme.desc;
430 struct nvme_fc_cmd_iu *cmd = fd->cmdaddr;
431 uint32_t rval = QLA_SUCCESS;
433 /* Setup qpair pointers */
435 tot_dsds = fd->sg_cnt;
437 /* Acquire qpair specific lock */
438 spin_lock_irqsave(&qpair->qp_lock, flags);
440 handle = qla2xxx_get_next_handle(req);
445 req_cnt = qla24xx_calc_iocbs(vha, tot_dsds);
446 if (req->cnt < (req_cnt + 2)) {
447 if (IS_SHADOW_REG_CAPABLE(ha)) {
450 cnt = rd_reg_dword_relaxed(req->req_q_out);
451 if (qla2x00_check_reg16_for_disconnect(vha, cnt))
455 if (req->ring_index < cnt)
456 req->cnt = cnt - req->ring_index;
458 req->cnt = req->length - (req->ring_index - cnt);
460 if (req->cnt < (req_cnt + 2)){
466 if (unlikely(!fd->sqid)) {
467 if (cmd->sqe.common.opcode == nvme_admin_async_event) {
468 nvme->u.nvme.aen_op = 1;
469 atomic_inc(&ha->nvme_active_aen_cnt);
473 /* Build command packet. */
474 req->current_outstanding_cmd = handle;
475 req->outstanding_cmds[handle] = sp;
479 cmd_pkt = (struct cmd_nvme *)req->ring_ptr;
480 cmd_pkt->handle = make_handle(req->id, handle);
482 /* Zero out remaining portion of packet. */
483 clr_ptr = (uint32_t *)cmd_pkt + 2;
484 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
486 cmd_pkt->entry_status = 0;
488 /* Update entry type to indicate Command NVME IOCB */
489 cmd_pkt->entry_type = COMMAND_NVME;
491 /* No data transfer how do we check buffer len == 0?? */
492 if (fd->io_dir == NVMEFC_FCP_READ) {
493 cmd_pkt->control_flags = cpu_to_le16(CF_READ_DATA);
494 qpair->counters.input_bytes += fd->payload_length;
495 qpair->counters.input_requests++;
496 } else if (fd->io_dir == NVMEFC_FCP_WRITE) {
497 cmd_pkt->control_flags = cpu_to_le16(CF_WRITE_DATA);
498 if ((vha->flags.nvme_first_burst) &&
499 (sp->fcport->nvme_prli_service_param &
500 NVME_PRLI_SP_FIRST_BURST)) {
501 if ((fd->payload_length <=
502 sp->fcport->nvme_first_burst_size) ||
503 (sp->fcport->nvme_first_burst_size == 0))
504 cmd_pkt->control_flags |=
505 cpu_to_le16(CF_NVME_FIRST_BURST_ENABLE);
507 qpair->counters.output_bytes += fd->payload_length;
508 qpair->counters.output_requests++;
509 } else if (fd->io_dir == 0) {
510 cmd_pkt->control_flags = 0;
513 if (sp->fcport->edif.enable && fd->io_dir != 0)
514 cmd_pkt->control_flags |= cpu_to_le16(CF_EN_EDIF);
516 /* Set BIT_13 of control flags for Async event */
517 if (vha->flags.nvme2_enabled &&
518 cmd->sqe.common.opcode == nvme_admin_async_event) {
519 cmd_pkt->control_flags |= cpu_to_le16(CF_ADMIN_ASYNC_EVENT);
523 cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
524 cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
525 cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
526 cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
527 cmd_pkt->vp_index = sp->fcport->vha->vp_idx;
530 cmd_pkt->nvme_rsp_dsd_len = cpu_to_le16(fd->rsplen);
531 put_unaligned_le64(fd->rspdma, &cmd_pkt->nvme_rsp_dseg_address);
534 cmd_pkt->nvme_cmnd_dseg_len = cpu_to_le16(fd->cmdlen);
535 cmd_pkt->nvme_cmnd_dseg_address = cpu_to_le64(fd->cmddma);
537 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
538 cmd_pkt->byte_count = cpu_to_le32(fd->payload_length);
540 /* One DSD is available in the Command Type NVME IOCB */
542 cur_dsd = &cmd_pkt->nvme_dsd;
545 /* Load data segments */
546 for_each_sg(sgl, sg, tot_dsds, i) {
547 cont_a64_entry_t *cont_pkt;
549 /* Allocate additional continuation packets? */
550 if (avail_dsds == 0) {
552 * Five DSDs are available in the Continuation
556 /* Adjust ring index */
558 if (req->ring_index == req->length) {
560 req->ring_ptr = req->ring;
564 cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
565 put_unaligned_le32(CONTINUE_A64_TYPE,
566 &cont_pkt->entry_type);
568 cur_dsd = cont_pkt->dsd;
569 avail_dsds = ARRAY_SIZE(cont_pkt->dsd);
572 append_dsd64(&cur_dsd, sg);
576 /* Set total entry count. */
577 cmd_pkt->entry_count = (uint8_t)req_cnt;
580 /* Adjust ring index. */
582 if (req->ring_index == req->length) {
584 req->ring_ptr = req->ring;
589 /* ignore nvme async cmd due to long timeout */
590 if (!nvme->u.nvme.aen_op)
591 sp->qpair->cmd_cnt++;
593 /* Set chip new ring index. */
594 wrt_reg_dword(req->req_q_in, req->ring_index);
597 spin_unlock_irqrestore(&qpair->qp_lock, flags);
603 static int qla_nvme_post_cmd(struct nvme_fc_local_port *lport,
604 struct nvme_fc_remote_port *rport, void *hw_queue_handle,
605 struct nvmefc_fcp_req *fd)
608 struct srb_iocb *nvme;
609 struct scsi_qla_host *vha;
612 struct qla_qpair *qpair = hw_queue_handle;
613 struct nvme_private *priv = fd->private;
614 struct qla_nvme_rport *qla_rport = rport->private;
617 /* nvme association has been torn down */
621 fcport = qla_rport->fcport;
623 if (unlikely(!qpair || !fcport || fcport->deleted))
626 if (!(fcport->nvme_flag & NVME_FLAG_REGISTERED))
631 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
635 * If we know the dev is going away while the transport is still sending
636 * IO's return busy back to stall the IO Q. This happens when the
637 * link goes away and fw hasn't notified us yet, but IO's are being
638 * returned. If the dev comes back quickly we won't exhaust the IO
639 * retry count at the core.
641 if (fcport->nvme_flag & NVME_FLAG_RESETTING)
644 /* Alloc SRB structure */
645 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
649 init_waitqueue_head(&sp->nvme_ls_waitq);
650 kref_init(&sp->cmd_kref);
651 spin_lock_init(&priv->cmd_lock);
654 sp->type = SRB_NVME_CMD;
655 sp->name = "nvme_cmd";
656 sp->done = qla_nvme_sp_done;
657 sp->put_fn = qla_nvme_release_fcp_cmd_kref;
661 nvme = &sp->u.iocb_cmd;
662 nvme->u.nvme.desc = fd;
664 rval = qla2x00_start_nvme_mq(sp);
665 if (rval != QLA_SUCCESS) {
666 ql_log(ql_log_warn, vha, 0x212d,
667 "qla2x00_start_nvme_mq failed = %d\n", rval);
668 wake_up(&sp->nvme_ls_waitq);
671 qla2xxx_rel_qpair_sp(sp->qpair, sp);
677 static void qla_nvme_localport_delete(struct nvme_fc_local_port *lport)
679 struct scsi_qla_host *vha = lport->private;
681 ql_log(ql_log_info, vha, 0x210f,
682 "localport delete of %p completed.\n", vha->nvme_local_port);
683 vha->nvme_local_port = NULL;
684 complete(&vha->nvme_del_done);
687 static void qla_nvme_remoteport_delete(struct nvme_fc_remote_port *rport)
690 struct qla_nvme_rport *qla_rport = rport->private;
692 fcport = qla_rport->fcport;
693 fcport->nvme_remote_port = NULL;
694 fcport->nvme_flag &= ~NVME_FLAG_REGISTERED;
695 fcport->nvme_flag &= ~NVME_FLAG_DELETING;
696 ql_log(ql_log_info, fcport->vha, 0x2110,
697 "remoteport_delete of %p %8phN completed.\n",
698 fcport, fcport->port_name);
699 complete(&fcport->nvme_del_done);
702 static struct nvme_fc_port_template qla_nvme_fc_transport = {
703 .localport_delete = qla_nvme_localport_delete,
704 .remoteport_delete = qla_nvme_remoteport_delete,
705 .create_queue = qla_nvme_alloc_queue,
706 .delete_queue = NULL,
707 .ls_req = qla_nvme_ls_req,
708 .ls_abort = qla_nvme_ls_abort,
709 .fcp_io = qla_nvme_post_cmd,
710 .fcp_abort = qla_nvme_fcp_abort,
712 .max_sgl_segments = 1024,
713 .max_dif_sgl_segments = 64,
714 .dma_boundary = 0xFFFFFFFF,
716 .remote_priv_sz = sizeof(struct qla_nvme_rport),
717 .lsrqst_priv_sz = sizeof(struct nvme_private),
718 .fcprqst_priv_sz = sizeof(struct nvme_private),
721 void qla_nvme_unregister_remote_port(struct fc_port *fcport)
725 if (!IS_ENABLED(CONFIG_NVME_FC))
728 ql_log(ql_log_warn, fcport->vha, 0x2112,
729 "%s: unregister remoteport on %p %8phN\n",
730 __func__, fcport, fcport->port_name);
732 if (test_bit(PFLG_DRIVER_REMOVING, &fcport->vha->pci_flags))
733 nvme_fc_set_remoteport_devloss(fcport->nvme_remote_port, 0);
735 init_completion(&fcport->nvme_del_done);
736 ret = nvme_fc_unregister_remoteport(fcport->nvme_remote_port);
738 ql_log(ql_log_info, fcport->vha, 0x2114,
739 "%s: Failed to unregister nvme_remote_port (%d)\n",
741 wait_for_completion(&fcport->nvme_del_done);
744 void qla_nvme_delete(struct scsi_qla_host *vha)
748 if (!IS_ENABLED(CONFIG_NVME_FC))
751 if (vha->nvme_local_port) {
752 init_completion(&vha->nvme_del_done);
753 ql_log(ql_log_info, vha, 0x2116,
754 "unregister localport=%p\n",
755 vha->nvme_local_port);
756 nv_ret = nvme_fc_unregister_localport(vha->nvme_local_port);
758 ql_log(ql_log_info, vha, 0x2115,
759 "Unregister of localport failed\n");
761 wait_for_completion(&vha->nvme_del_done);
765 int qla_nvme_register_hba(struct scsi_qla_host *vha)
767 struct nvme_fc_port_template *tmpl;
768 struct qla_hw_data *ha;
769 struct nvme_fc_port_info pinfo;
772 if (!IS_ENABLED(CONFIG_NVME_FC))
776 tmpl = &qla_nvme_fc_transport;
779 qla_nvme_fc_transport.max_hw_queues =
780 min((uint8_t)(qla_nvme_fc_transport.max_hw_queues),
781 (uint8_t)(ha->max_qpairs ? ha->max_qpairs : 1));
783 pinfo.node_name = wwn_to_u64(vha->node_name);
784 pinfo.port_name = wwn_to_u64(vha->port_name);
785 pinfo.port_role = FC_PORT_ROLE_NVME_INITIATOR;
786 pinfo.port_id = vha->d_id.b24;
788 mutex_lock(&ha->vport_lock);
790 * Check again for nvme_local_port to see if any other thread raced
791 * with this one and finished registration.
793 if (!vha->nvme_local_port) {
794 ql_log(ql_log_info, vha, 0xffff,
795 "register_localport: host-traddr=nn-0x%llx:pn-0x%llx on portID:%x\n",
796 pinfo.node_name, pinfo.port_name, pinfo.port_id);
797 qla_nvme_fc_transport.dma_boundary = vha->host->dma_boundary;
799 ret = nvme_fc_register_localport(&pinfo, tmpl,
800 get_device(&ha->pdev->dev),
801 &vha->nvme_local_port);
802 mutex_unlock(&ha->vport_lock);
804 mutex_unlock(&ha->vport_lock);
808 ql_log(ql_log_warn, vha, 0xffff,
809 "register_localport failed: ret=%x\n", ret);
811 vha->nvme_local_port->private = vha;
817 void qla_nvme_abort_set_option(struct abort_entry_24xx *abt, srb_t *orig_sp)
819 struct qla_hw_data *ha;
821 if (!(ql2xabts_wait_nvme && QLA_ABTS_WAIT_ENABLED(orig_sp)))
824 ha = orig_sp->fcport->vha->hw;
826 WARN_ON_ONCE(abt->options & cpu_to_le16(BIT_0));
827 /* Use Driver Specified Retry Count */
828 abt->options |= cpu_to_le16(AOF_ABTS_RTY_CNT);
829 abt->drv.abts_rty_cnt = cpu_to_le16(2);
830 /* Use specified response timeout */
831 abt->options |= cpu_to_le16(AOF_RSP_TIMEOUT);
832 /* set it to 2 * r_a_tov in secs */
833 abt->drv.rsp_timeout = cpu_to_le16(2 * (ha->r_a_tov / 10));
836 void qla_nvme_abort_process_comp_status(struct abort_entry_24xx *abt, srb_t *orig_sp)
839 struct scsi_qla_host *vha;
841 if (!(ql2xabts_wait_nvme && QLA_ABTS_WAIT_ENABLED(orig_sp)))
844 vha = orig_sp->fcport->vha;
846 comp_status = le16_to_cpu(abt->comp_status);
847 switch (comp_status) {
848 case CS_RESET: /* reset event aborted */
849 case CS_ABORTED: /* IOCB was cleaned */
850 /* N_Port handle is not currently logged in */
852 /* N_Port handle was logged out while waiting for ABTS to complete */
853 case CS_PORT_UNAVAILABLE:
854 /* Firmware found that the port name changed */
855 case CS_PORT_LOGGED_OUT:
856 /* BA_RJT was received for the ABTS */
857 case CS_PORT_CONFIG_CHG:
858 ql_dbg(ql_dbg_async, vha, 0xf09d,
859 "Abort I/O IOCB completed with error, comp_status=%x\n",
863 /* BA_RJT was received for the ABTS */
864 case CS_REJECT_RECEIVED:
865 ql_dbg(ql_dbg_async, vha, 0xf09e,
866 "BA_RJT was received for the ABTS rjt_vendorUnique = %u",
867 abt->fw.ba_rjt_vendorUnique);
868 ql_dbg(ql_dbg_async + ql_dbg_mbx, vha, 0xf09e,
869 "ba_rjt_reasonCodeExpl = %u, ba_rjt_reasonCode = %u\n",
870 abt->fw.ba_rjt_reasonCodeExpl, abt->fw.ba_rjt_reasonCode);
874 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0xf09f,
875 "IOCB request is completed successfully comp_status=%x\n",
880 ql_dbg(ql_dbg_async, vha, 0xf0a0,
881 "IOCB request is failed, comp_status=%x\n", comp_status);
885 ql_dbg(ql_dbg_async, vha, 0xf0a1,
886 "Invalid Abort IO IOCB Completion Status %x\n",
892 inline void qla_wait_nvme_release_cmd_kref(srb_t *orig_sp)
894 if (!(ql2xabts_wait_nvme && QLA_ABTS_WAIT_ENABLED(orig_sp)))
896 kref_put(&orig_sp->cmd_kref, orig_sp->put_fn);