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>
11 #include <linux/blk-mq-pci.h>
12 #include <linux/blk-mq.h>
14 static struct nvme_fc_port_template qla_nvme_fc_transport;
16 int qla_nvme_register_remote(struct scsi_qla_host *vha, struct fc_port *fcport)
18 struct qla_nvme_rport *rport;
19 struct nvme_fc_port_info req;
22 if (!IS_ENABLED(CONFIG_NVME_FC))
25 if (!vha->flags.nvme_enabled) {
26 ql_log(ql_log_info, vha, 0x2100,
27 "%s: Not registering target since Host NVME is not enabled\n",
32 if (!vha->nvme_local_port && qla_nvme_register_hba(vha))
35 if (!(fcport->nvme_prli_service_param &
36 (NVME_PRLI_SP_TARGET | NVME_PRLI_SP_DISCOVERY)) ||
37 (fcport->nvme_flag & NVME_FLAG_REGISTERED))
40 fcport->nvme_flag &= ~NVME_FLAG_RESETTING;
42 memset(&req, 0, sizeof(struct nvme_fc_port_info));
43 req.port_name = wwn_to_u64(fcport->port_name);
44 req.node_name = wwn_to_u64(fcport->node_name);
48 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_INITIATOR)
49 req.port_role = FC_PORT_ROLE_NVME_INITIATOR;
51 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_TARGET)
52 req.port_role |= FC_PORT_ROLE_NVME_TARGET;
54 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_DISCOVERY)
55 req.port_role |= FC_PORT_ROLE_NVME_DISCOVERY;
57 req.port_id = fcport->d_id.b24;
59 ql_log(ql_log_info, vha, 0x2102,
60 "%s: traddr=nn-0x%016llx:pn-0x%016llx PortID:%06x\n",
61 __func__, req.node_name, req.port_name,
64 ret = nvme_fc_register_remoteport(vha->nvme_local_port, &req,
65 &fcport->nvme_remote_port);
67 ql_log(ql_log_warn, vha, 0x212e,
68 "Failed to register remote port. Transport returned %d\n",
73 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_SLER)
74 ql_log(ql_log_info, vha, 0x212a,
75 "PortID:%06x Supports SLER\n", req.port_id);
77 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_PI_CTRL)
78 ql_log(ql_log_info, vha, 0x212b,
79 "PortID:%06x Supports PI control\n", req.port_id);
81 rport = fcport->nvme_remote_port->private;
82 rport->fcport = fcport;
84 fcport->nvme_flag |= NVME_FLAG_REGISTERED;
88 /* Allocate a queue for NVMe traffic */
89 static int qla_nvme_alloc_queue(struct nvme_fc_local_port *lport,
90 unsigned int qidx, u16 qsize, void **handle)
92 struct scsi_qla_host *vha;
93 struct qla_hw_data *ha;
94 struct qla_qpair *qpair;
96 /* Map admin queue and 1st IO queue to index 0 */
100 vha = (struct scsi_qla_host *)lport->private;
103 ql_log(ql_log_info, vha, 0x2104,
104 "%s: handle %p, idx =%d, qsize %d\n",
105 __func__, handle, qidx, qsize);
107 if (qidx > qla_nvme_fc_transport.max_hw_queues) {
108 ql_log(ql_log_warn, vha, 0x212f,
109 "%s: Illegal qidx=%d. Max=%d\n",
110 __func__, qidx, qla_nvme_fc_transport.max_hw_queues);
114 /* Use base qpair if max_qpairs is 0 */
115 if (!ha->max_qpairs) {
116 qpair = ha->base_qpair;
118 if (ha->queue_pair_map[qidx]) {
119 *handle = ha->queue_pair_map[qidx];
120 ql_log(ql_log_info, vha, 0x2121,
121 "Returning existing qpair of %p for idx=%x\n",
126 qpair = qla2xxx_create_qpair(vha, 5, vha->vp_idx, true);
128 ql_log(ql_log_warn, vha, 0x2122,
129 "Failed to allocate qpair\n");
138 static void qla_nvme_release_fcp_cmd_kref(struct kref *kref)
140 struct srb *sp = container_of(kref, struct srb, cmd_kref);
141 struct nvme_private *priv = (struct nvme_private *)sp->priv;
142 struct nvmefc_fcp_req *fd;
143 struct srb_iocb *nvme;
149 nvme = &sp->u.iocb_cmd;
150 fd = nvme->u.nvme.desc;
152 spin_lock_irqsave(&priv->cmd_lock, flags);
155 if (priv->comp_status == QLA_SUCCESS) {
156 fd->rcv_rsplen = le16_to_cpu(nvme->u.nvme.rsp_pyld_len);
157 fd->status = NVME_SC_SUCCESS;
160 fd->transferred_length = 0;
161 fd->status = NVME_SC_INTERNAL;
163 spin_unlock_irqrestore(&priv->cmd_lock, flags);
167 qla2xxx_rel_qpair_sp(sp->qpair, sp);
170 static void qla_nvme_release_ls_cmd_kref(struct kref *kref)
172 struct srb *sp = container_of(kref, struct srb, cmd_kref);
173 struct nvme_private *priv = (struct nvme_private *)sp->priv;
174 struct nvmefc_ls_req *fd;
180 spin_lock_irqsave(&priv->cmd_lock, flags);
183 spin_unlock_irqrestore(&priv->cmd_lock, flags);
186 fd->done(fd, priv->comp_status);
191 static void qla_nvme_ls_complete(struct work_struct *work)
193 struct nvme_private *priv =
194 container_of(work, struct nvme_private, ls_work);
196 kref_put(&priv->sp->cmd_kref, qla_nvme_release_ls_cmd_kref);
199 static void qla_nvme_sp_ls_done(srb_t *sp, int res)
201 struct nvme_private *priv = sp->priv;
203 if (WARN_ON_ONCE(kref_read(&sp->cmd_kref) == 0))
209 priv->comp_status = res;
210 INIT_WORK(&priv->ls_work, qla_nvme_ls_complete);
211 schedule_work(&priv->ls_work);
214 /* it assumed that QPair lock is held. */
215 static void qla_nvme_sp_done(srb_t *sp, int res)
217 struct nvme_private *priv = sp->priv;
219 priv->comp_status = res;
220 kref_put(&sp->cmd_kref, qla_nvme_release_fcp_cmd_kref);
225 static void qla_nvme_abort_work(struct work_struct *work)
227 struct nvme_private *priv =
228 container_of(work, struct nvme_private, abort_work);
229 srb_t *sp = priv->sp;
230 fc_port_t *fcport = sp->fcport;
231 struct qla_hw_data *ha = fcport->vha->hw;
232 int rval, abts_done_called = 1;
233 bool io_wait_for_abort_done;
236 ql_dbg(ql_dbg_io, fcport->vha, 0xffff,
237 "%s called for sp=%p, hndl=%x on fcport=%p desc=%p deleted=%d\n",
238 __func__, sp, sp->handle, fcport, sp->u.iocb_cmd.u.nvme.desc, fcport->deleted);
240 if (!ha->flags.fw_started || fcport->deleted == QLA_SESS_DELETED)
243 if (ha->flags.host_shutting_down) {
244 ql_log(ql_log_info, sp->fcport->vha, 0xffff,
245 "%s Calling done on sp: %p, type: 0x%x\n",
246 __func__, sp, sp->type);
252 * sp may not be valid after abort_command if return code is either
253 * SUCCESS or ERR_FROM_FW codes, so cache the value here.
255 io_wait_for_abort_done = ql2xabts_wait_nvme &&
256 QLA_ABTS_WAIT_ENABLED(sp);
259 rval = ha->isp_ops->abort_command(sp);
261 ql_dbg(ql_dbg_io, fcport->vha, 0x212b,
262 "%s: %s command for sp=%p, handle=%x on fcport=%p rval=%x\n",
263 __func__, (rval != QLA_SUCCESS) ? "Failed to abort" : "Aborted",
264 sp, handle, fcport, rval);
267 * If async tmf is enabled, the abort callback is called only on
268 * return codes QLA_SUCCESS and QLA_ERR_FROM_FW.
270 if (ql2xasynctmfenable &&
271 rval != QLA_SUCCESS && rval != QLA_ERR_FROM_FW)
272 abts_done_called = 0;
275 * Returned before decreasing kref so that I/O requests
276 * are waited until ABTS complete. This kref is decreased
277 * at qla24xx_abort_sp_done function.
279 if (abts_done_called && io_wait_for_abort_done)
282 /* kref_get was done before work was schedule. */
283 kref_put(&sp->cmd_kref, sp->put_fn);
286 static void qla_nvme_ls_abort(struct nvme_fc_local_port *lport,
287 struct nvme_fc_remote_port *rport, struct nvmefc_ls_req *fd)
289 struct nvme_private *priv = fd->private;
292 spin_lock_irqsave(&priv->cmd_lock, flags);
294 spin_unlock_irqrestore(&priv->cmd_lock, flags);
298 if (!kref_get_unless_zero(&priv->sp->cmd_kref)) {
299 spin_unlock_irqrestore(&priv->cmd_lock, flags);
302 spin_unlock_irqrestore(&priv->cmd_lock, flags);
304 INIT_WORK(&priv->abort_work, qla_nvme_abort_work);
305 schedule_work(&priv->abort_work);
308 static int qla_nvme_ls_req(struct nvme_fc_local_port *lport,
309 struct nvme_fc_remote_port *rport, struct nvmefc_ls_req *fd)
311 struct qla_nvme_rport *qla_rport = rport->private;
312 fc_port_t *fcport = qla_rport->fcport;
313 struct srb_iocb *nvme;
314 struct nvme_private *priv = fd->private;
315 struct scsi_qla_host *vha;
316 int rval = QLA_FUNCTION_FAILED;
317 struct qla_hw_data *ha;
320 if (!fcport || fcport->deleted)
326 if (!ha->flags.fw_started)
329 /* Alloc SRB structure */
330 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
334 sp->type = SRB_NVME_LS;
335 sp->name = "nvme_ls";
336 sp->done = qla_nvme_sp_ls_done;
337 sp->put_fn = qla_nvme_release_ls_cmd_kref;
340 kref_init(&sp->cmd_kref);
341 spin_lock_init(&priv->cmd_lock);
342 nvme = &sp->u.iocb_cmd;
344 nvme->u.nvme.desc = fd;
345 nvme->u.nvme.dir = 0;
347 nvme->u.nvme.cmd_len = fd->rqstlen;
348 nvme->u.nvme.rsp_len = fd->rsplen;
349 nvme->u.nvme.rsp_dma = fd->rspdma;
350 nvme->u.nvme.timeout_sec = fd->timeout;
351 nvme->u.nvme.cmd_dma = dma_map_single(&ha->pdev->dev, fd->rqstaddr,
352 fd->rqstlen, DMA_TO_DEVICE);
353 dma_sync_single_for_device(&ha->pdev->dev, nvme->u.nvme.cmd_dma,
354 fd->rqstlen, DMA_TO_DEVICE);
356 rval = qla2x00_start_sp(sp);
357 if (rval != QLA_SUCCESS) {
358 ql_log(ql_log_warn, vha, 0x700e,
359 "qla2x00_start_sp failed = %d\n", rval);
360 wake_up(&sp->nvme_ls_waitq);
370 static void qla_nvme_fcp_abort(struct nvme_fc_local_port *lport,
371 struct nvme_fc_remote_port *rport, void *hw_queue_handle,
372 struct nvmefc_fcp_req *fd)
374 struct nvme_private *priv = fd->private;
377 spin_lock_irqsave(&priv->cmd_lock, flags);
379 spin_unlock_irqrestore(&priv->cmd_lock, flags);
382 if (!kref_get_unless_zero(&priv->sp->cmd_kref)) {
383 spin_unlock_irqrestore(&priv->cmd_lock, flags);
386 spin_unlock_irqrestore(&priv->cmd_lock, flags);
388 INIT_WORK(&priv->abort_work, qla_nvme_abort_work);
389 schedule_work(&priv->abort_work);
392 static inline int qla2x00_start_nvme_mq(srb_t *sp)
397 struct cmd_nvme *cmd_pkt;
402 struct dsd64 *cur_dsd;
403 struct req_que *req = NULL;
404 struct rsp_que *rsp = NULL;
405 struct scsi_qla_host *vha = sp->fcport->vha;
406 struct qla_hw_data *ha = vha->hw;
407 struct qla_qpair *qpair = sp->qpair;
408 struct srb_iocb *nvme = &sp->u.iocb_cmd;
409 struct scatterlist *sgl, *sg;
410 struct nvmefc_fcp_req *fd = nvme->u.nvme.desc;
411 struct nvme_fc_cmd_iu *cmd = fd->cmdaddr;
412 uint32_t rval = QLA_SUCCESS;
414 /* Setup qpair pointers */
417 tot_dsds = fd->sg_cnt;
419 /* Acquire qpair specific lock */
420 spin_lock_irqsave(&qpair->qp_lock, flags);
422 handle = qla2xxx_get_next_handle(req);
427 req_cnt = qla24xx_calc_iocbs(vha, tot_dsds);
428 if (req->cnt < (req_cnt + 2)) {
429 if (IS_SHADOW_REG_CAPABLE(ha)) {
432 cnt = rd_reg_dword_relaxed(req->req_q_out);
433 if (qla2x00_check_reg16_for_disconnect(vha, cnt))
437 if (req->ring_index < cnt)
438 req->cnt = cnt - req->ring_index;
440 req->cnt = req->length - (req->ring_index - cnt);
442 if (req->cnt < (req_cnt + 2)){
448 if (unlikely(!fd->sqid)) {
449 if (cmd->sqe.common.opcode == nvme_admin_async_event) {
450 nvme->u.nvme.aen_op = 1;
451 atomic_inc(&ha->nvme_active_aen_cnt);
455 /* Build command packet. */
456 req->current_outstanding_cmd = handle;
457 req->outstanding_cmds[handle] = sp;
461 cmd_pkt = (struct cmd_nvme *)req->ring_ptr;
462 cmd_pkt->handle = make_handle(req->id, handle);
464 /* Zero out remaining portion of packet. */
465 clr_ptr = (uint32_t *)cmd_pkt + 2;
466 memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
468 cmd_pkt->entry_status = 0;
470 /* Update entry type to indicate Command NVME IOCB */
471 cmd_pkt->entry_type = COMMAND_NVME;
473 /* No data transfer how do we check buffer len == 0?? */
474 if (fd->io_dir == NVMEFC_FCP_READ) {
475 cmd_pkt->control_flags = cpu_to_le16(CF_READ_DATA);
476 qpair->counters.input_bytes += fd->payload_length;
477 qpair->counters.input_requests++;
478 } else if (fd->io_dir == NVMEFC_FCP_WRITE) {
479 cmd_pkt->control_flags = cpu_to_le16(CF_WRITE_DATA);
480 if ((vha->flags.nvme_first_burst) &&
481 (sp->fcport->nvme_prli_service_param &
482 NVME_PRLI_SP_FIRST_BURST)) {
483 if ((fd->payload_length <=
484 sp->fcport->nvme_first_burst_size) ||
485 (sp->fcport->nvme_first_burst_size == 0))
486 cmd_pkt->control_flags |=
487 cpu_to_le16(CF_NVME_FIRST_BURST_ENABLE);
489 qpair->counters.output_bytes += fd->payload_length;
490 qpair->counters.output_requests++;
491 } else if (fd->io_dir == 0) {
492 cmd_pkt->control_flags = 0;
495 if (sp->fcport->edif.enable && fd->io_dir != 0)
496 cmd_pkt->control_flags |= cpu_to_le16(CF_EN_EDIF);
498 /* Set BIT_13 of control flags for Async event */
499 if (vha->flags.nvme2_enabled &&
500 cmd->sqe.common.opcode == nvme_admin_async_event) {
501 cmd_pkt->control_flags |= cpu_to_le16(CF_ADMIN_ASYNC_EVENT);
505 cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
506 cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
507 cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
508 cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
509 cmd_pkt->vp_index = sp->fcport->vha->vp_idx;
512 cmd_pkt->nvme_rsp_dsd_len = cpu_to_le16(fd->rsplen);
513 put_unaligned_le64(fd->rspdma, &cmd_pkt->nvme_rsp_dseg_address);
516 cmd_pkt->nvme_cmnd_dseg_len = cpu_to_le16(fd->cmdlen);
517 cmd_pkt->nvme_cmnd_dseg_address = cpu_to_le64(fd->cmddma);
519 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
520 cmd_pkt->byte_count = cpu_to_le32(fd->payload_length);
522 /* One DSD is available in the Command Type NVME IOCB */
524 cur_dsd = &cmd_pkt->nvme_dsd;
527 /* Load data segments */
528 for_each_sg(sgl, sg, tot_dsds, i) {
529 cont_a64_entry_t *cont_pkt;
531 /* Allocate additional continuation packets? */
532 if (avail_dsds == 0) {
534 * Five DSDs are available in the Continuation
538 /* Adjust ring index */
540 if (req->ring_index == req->length) {
542 req->ring_ptr = req->ring;
546 cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
547 put_unaligned_le32(CONTINUE_A64_TYPE,
548 &cont_pkt->entry_type);
550 cur_dsd = cont_pkt->dsd;
551 avail_dsds = ARRAY_SIZE(cont_pkt->dsd);
554 append_dsd64(&cur_dsd, sg);
558 /* Set total entry count. */
559 cmd_pkt->entry_count = (uint8_t)req_cnt;
562 /* Adjust ring index. */
564 if (req->ring_index == req->length) {
566 req->ring_ptr = req->ring;
571 /* ignore nvme async cmd due to long timeout */
572 if (!nvme->u.nvme.aen_op)
573 sp->qpair->cmd_cnt++;
575 /* Set chip new ring index. */
576 wrt_reg_dword(req->req_q_in, req->ring_index);
578 if (vha->flags.process_response_queue &&
579 rsp->ring_ptr->signature != RESPONSE_PROCESSED)
580 qla24xx_process_response_queue(vha, rsp);
583 spin_unlock_irqrestore(&qpair->qp_lock, flags);
589 static int qla_nvme_post_cmd(struct nvme_fc_local_port *lport,
590 struct nvme_fc_remote_port *rport, void *hw_queue_handle,
591 struct nvmefc_fcp_req *fd)
594 struct srb_iocb *nvme;
595 struct scsi_qla_host *vha;
598 struct qla_qpair *qpair = hw_queue_handle;
599 struct nvme_private *priv = fd->private;
600 struct qla_nvme_rport *qla_rport = rport->private;
603 /* nvme association has been torn down */
607 fcport = qla_rport->fcport;
609 if (unlikely(!qpair || !fcport || fcport->deleted))
612 if (!(fcport->nvme_flag & NVME_FLAG_REGISTERED))
617 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
621 * If we know the dev is going away while the transport is still sending
622 * IO's return busy back to stall the IO Q. This happens when the
623 * link goes away and fw hasn't notified us yet, but IO's are being
624 * returned. If the dev comes back quickly we won't exhaust the IO
625 * retry count at the core.
627 if (fcport->nvme_flag & NVME_FLAG_RESETTING)
630 /* Alloc SRB structure */
631 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
635 init_waitqueue_head(&sp->nvme_ls_waitq);
636 kref_init(&sp->cmd_kref);
637 spin_lock_init(&priv->cmd_lock);
640 sp->type = SRB_NVME_CMD;
641 sp->name = "nvme_cmd";
642 sp->done = qla_nvme_sp_done;
643 sp->put_fn = qla_nvme_release_fcp_cmd_kref;
647 nvme = &sp->u.iocb_cmd;
648 nvme->u.nvme.desc = fd;
650 rval = qla2x00_start_nvme_mq(sp);
651 if (rval != QLA_SUCCESS) {
652 ql_log(ql_log_warn, vha, 0x212d,
653 "qla2x00_start_nvme_mq failed = %d\n", rval);
654 wake_up(&sp->nvme_ls_waitq);
657 qla2xxx_rel_qpair_sp(sp->qpair, sp);
663 static void qla_nvme_map_queues(struct nvme_fc_local_port *lport,
664 struct blk_mq_queue_map *map)
666 struct scsi_qla_host *vha = lport->private;
669 rc = blk_mq_pci_map_queues(map, vha->hw->pdev, vha->irq_offset);
671 ql_log(ql_log_warn, vha, 0x21de,
672 "pci map queue failed 0x%x", rc);
675 static void qla_nvme_localport_delete(struct nvme_fc_local_port *lport)
677 struct scsi_qla_host *vha = lport->private;
679 ql_log(ql_log_info, vha, 0x210f,
680 "localport delete of %p completed.\n", vha->nvme_local_port);
681 vha->nvme_local_port = NULL;
682 complete(&vha->nvme_del_done);
685 static void qla_nvme_remoteport_delete(struct nvme_fc_remote_port *rport)
688 struct qla_nvme_rport *qla_rport = rport->private;
690 fcport = qla_rport->fcport;
691 fcport->nvme_remote_port = NULL;
692 fcport->nvme_flag &= ~NVME_FLAG_REGISTERED;
693 fcport->nvme_flag &= ~NVME_FLAG_DELETING;
694 ql_log(ql_log_info, fcport->vha, 0x2110,
695 "remoteport_delete of %p %8phN completed.\n",
696 fcport, fcport->port_name);
697 complete(&fcport->nvme_del_done);
700 static struct nvme_fc_port_template qla_nvme_fc_transport = {
701 .localport_delete = qla_nvme_localport_delete,
702 .remoteport_delete = qla_nvme_remoteport_delete,
703 .create_queue = qla_nvme_alloc_queue,
704 .delete_queue = NULL,
705 .ls_req = qla_nvme_ls_req,
706 .ls_abort = qla_nvme_ls_abort,
707 .fcp_io = qla_nvme_post_cmd,
708 .fcp_abort = qla_nvme_fcp_abort,
709 .map_queues = qla_nvme_map_queues,
711 .max_sgl_segments = 1024,
712 .max_dif_sgl_segments = 64,
713 .dma_boundary = 0xFFFFFFFF,
715 .remote_priv_sz = sizeof(struct qla_nvme_rport),
716 .lsrqst_priv_sz = sizeof(struct nvme_private),
717 .fcprqst_priv_sz = sizeof(struct nvme_private),
720 void qla_nvme_unregister_remote_port(struct fc_port *fcport)
724 if (!IS_ENABLED(CONFIG_NVME_FC))
727 ql_log(ql_log_warn, fcport->vha, 0x2112,
728 "%s: unregister remoteport on %p %8phN\n",
729 __func__, fcport, fcport->port_name);
731 if (test_bit(PFLG_DRIVER_REMOVING, &fcport->vha->pci_flags))
732 nvme_fc_set_remoteport_devloss(fcport->nvme_remote_port, 0);
734 init_completion(&fcport->nvme_del_done);
735 ret = nvme_fc_unregister_remoteport(fcport->nvme_remote_port);
737 ql_log(ql_log_info, fcport->vha, 0x2114,
738 "%s: Failed to unregister nvme_remote_port (%d)\n",
740 wait_for_completion(&fcport->nvme_del_done);
743 void qla_nvme_delete(struct scsi_qla_host *vha)
747 if (!IS_ENABLED(CONFIG_NVME_FC))
750 if (vha->nvme_local_port) {
751 init_completion(&vha->nvme_del_done);
752 ql_log(ql_log_info, vha, 0x2116,
753 "unregister localport=%p\n",
754 vha->nvme_local_port);
755 nv_ret = nvme_fc_unregister_localport(vha->nvme_local_port);
757 ql_log(ql_log_info, vha, 0x2115,
758 "Unregister of localport failed\n");
760 wait_for_completion(&vha->nvme_del_done);
764 int qla_nvme_register_hba(struct scsi_qla_host *vha)
766 struct nvme_fc_port_template *tmpl;
767 struct qla_hw_data *ha;
768 struct nvme_fc_port_info pinfo;
771 if (!IS_ENABLED(CONFIG_NVME_FC))
775 tmpl = &qla_nvme_fc_transport;
777 WARN_ON(vha->nvme_local_port);
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 ql_log(ql_log_info, vha, 0xffff,
789 "register_localport: host-traddr=nn-0x%llx:pn-0x%llx on portID:%x\n",
790 pinfo.node_name, pinfo.port_name, pinfo.port_id);
791 qla_nvme_fc_transport.dma_boundary = vha->host->dma_boundary;
793 ret = nvme_fc_register_localport(&pinfo, tmpl,
794 get_device(&ha->pdev->dev), &vha->nvme_local_port);
796 ql_log(ql_log_warn, vha, 0xffff,
797 "register_localport failed: ret=%x\n", ret);
799 vha->nvme_local_port->private = vha;
805 void qla_nvme_abort_set_option(struct abort_entry_24xx *abt, srb_t *orig_sp)
807 struct qla_hw_data *ha;
809 if (!(ql2xabts_wait_nvme && QLA_ABTS_WAIT_ENABLED(orig_sp)))
812 ha = orig_sp->fcport->vha->hw;
814 WARN_ON_ONCE(abt->options & cpu_to_le16(BIT_0));
815 /* Use Driver Specified Retry Count */
816 abt->options |= cpu_to_le16(AOF_ABTS_RTY_CNT);
817 abt->drv.abts_rty_cnt = cpu_to_le16(2);
818 /* Use specified response timeout */
819 abt->options |= cpu_to_le16(AOF_RSP_TIMEOUT);
820 /* set it to 2 * r_a_tov in secs */
821 abt->drv.rsp_timeout = cpu_to_le16(2 * (ha->r_a_tov / 10));
824 void qla_nvme_abort_process_comp_status(struct abort_entry_24xx *abt, srb_t *orig_sp)
827 struct scsi_qla_host *vha;
829 if (!(ql2xabts_wait_nvme && QLA_ABTS_WAIT_ENABLED(orig_sp)))
832 vha = orig_sp->fcport->vha;
834 comp_status = le16_to_cpu(abt->comp_status);
835 switch (comp_status) {
836 case CS_RESET: /* reset event aborted */
837 case CS_ABORTED: /* IOCB was cleaned */
838 /* N_Port handle is not currently logged in */
840 /* N_Port handle was logged out while waiting for ABTS to complete */
841 case CS_PORT_UNAVAILABLE:
842 /* Firmware found that the port name changed */
843 case CS_PORT_LOGGED_OUT:
844 /* BA_RJT was received for the ABTS */
845 case CS_PORT_CONFIG_CHG:
846 ql_dbg(ql_dbg_async, vha, 0xf09d,
847 "Abort I/O IOCB completed with error, comp_status=%x\n",
851 /* BA_RJT was received for the ABTS */
852 case CS_REJECT_RECEIVED:
853 ql_dbg(ql_dbg_async, vha, 0xf09e,
854 "BA_RJT was received for the ABTS rjt_vendorUnique = %u",
855 abt->fw.ba_rjt_vendorUnique);
856 ql_dbg(ql_dbg_async + ql_dbg_mbx, vha, 0xf09e,
857 "ba_rjt_reasonCodeExpl = %u, ba_rjt_reasonCode = %u\n",
858 abt->fw.ba_rjt_reasonCodeExpl, abt->fw.ba_rjt_reasonCode);
862 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0xf09f,
863 "IOCB request is completed successfully comp_status=%x\n",
868 ql_dbg(ql_dbg_async, vha, 0xf0a0,
869 "IOCB request is failed, comp_status=%x\n", comp_status);
873 ql_dbg(ql_dbg_async, vha, 0xf0a1,
874 "Invalid Abort IO IOCB Completion Status %x\n",
880 inline void qla_wait_nvme_release_cmd_kref(srb_t *orig_sp)
882 if (!(ql2xabts_wait_nvme && QLA_ABTS_WAIT_ENABLED(orig_sp)))
884 kref_put(&orig_sp->cmd_kref, orig_sp->put_fn);