Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * QLogic Fibre Channel HBA Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c)  2003-2017 QLogic Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include "qla_nvme.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/nvme.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/nvme-fc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) static struct nvme_fc_port_template qla_nvme_fc_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) int qla_nvme_register_remote(struct scsi_qla_host *vha, struct fc_port *fcport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	struct qla_nvme_rport *rport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct nvme_fc_port_info req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	if (!IS_ENABLED(CONFIG_NVME_FC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	if (!vha->flags.nvme_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		ql_log(ql_log_info, vha, 0x2100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		    "%s: Not registering target since Host NVME is not enabled\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		    __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	if (!vha->nvme_local_port && qla_nvme_register_hba(vha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	if (!(fcport->nvme_prli_service_param &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	    (NVME_PRLI_SP_TARGET | NVME_PRLI_SP_DISCOVERY)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		(fcport->nvme_flag & NVME_FLAG_REGISTERED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (atomic_read(&fcport->state) == FCS_ONLINE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	qla2x00_set_fcport_state(fcport, FCS_ONLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	fcport->nvme_flag &= ~NVME_FLAG_RESETTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	memset(&req, 0, sizeof(struct nvme_fc_port_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	req.port_name = wwn_to_u64(fcport->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	req.node_name = wwn_to_u64(fcport->node_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	req.port_role = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	req.dev_loss_tmo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (fcport->nvme_prli_service_param & NVME_PRLI_SP_INITIATOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		req.port_role = FC_PORT_ROLE_NVME_INITIATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (fcport->nvme_prli_service_param & NVME_PRLI_SP_TARGET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		req.port_role |= FC_PORT_ROLE_NVME_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (fcport->nvme_prli_service_param & NVME_PRLI_SP_DISCOVERY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		req.port_role |= FC_PORT_ROLE_NVME_DISCOVERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	req.port_id = fcport->d_id.b24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	ql_log(ql_log_info, vha, 0x2102,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	    "%s: traddr=nn-0x%016llx:pn-0x%016llx PortID:%06x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	    __func__, req.node_name, req.port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	    req.port_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	ret = nvme_fc_register_remoteport(vha->nvme_local_port, &req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	    &fcport->nvme_remote_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		ql_log(ql_log_warn, vha, 0x212e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		    "Failed to register remote port. Transport returned %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		    ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (fcport->nvme_prli_service_param & NVME_PRLI_SP_SLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		ql_log(ql_log_info, vha, 0x212a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		       "PortID:%06x Supports SLER\n", req.port_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (fcport->nvme_prli_service_param & NVME_PRLI_SP_PI_CTRL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		ql_log(ql_log_info, vha, 0x212b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		       "PortID:%06x Supports PI control\n", req.port_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	rport = fcport->nvme_remote_port->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	rport->fcport = fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	fcport->nvme_flag |= NVME_FLAG_REGISTERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) /* Allocate a queue for NVMe traffic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static int qla_nvme_alloc_queue(struct nvme_fc_local_port *lport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)     unsigned int qidx, u16 qsize, void **handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct scsi_qla_host *vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct qla_hw_data *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct qla_qpair *qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/* Map admin queue and 1st IO queue to index 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (qidx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		qidx--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	vha = (struct scsi_qla_host *)lport->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	ql_log(ql_log_info, vha, 0x2104,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	    "%s: handle %p, idx =%d, qsize %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	    __func__, handle, qidx, qsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (qidx > qla_nvme_fc_transport.max_hw_queues) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		ql_log(ql_log_warn, vha, 0x212f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		    "%s: Illegal qidx=%d. Max=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		    __func__, qidx, qla_nvme_fc_transport.max_hw_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/* Use base qpair if max_qpairs is 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (!ha->max_qpairs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		qpair = ha->base_qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		if (ha->queue_pair_map[qidx]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			*handle = ha->queue_pair_map[qidx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			ql_log(ql_log_info, vha, 0x2121,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			       "Returning existing qpair of %p for idx=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			       *handle, qidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		qpair = qla2xxx_create_qpair(vha, 5, vha->vp_idx, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (!qpair) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			ql_log(ql_log_warn, vha, 0x2122,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			       "Failed to allocate qpair\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	*handle = qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static void qla_nvme_release_fcp_cmd_kref(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct srb *sp = container_of(kref, struct srb, cmd_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct nvme_private *priv = (struct nvme_private *)sp->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct nvmefc_fcp_req *fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct srb_iocb *nvme;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	nvme = &sp->u.iocb_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	fd = nvme->u.nvme.desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	spin_lock_irqsave(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	priv->sp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	sp->priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (priv->comp_status == QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		fd->rcv_rsplen = le16_to_cpu(nvme->u.nvme.rsp_pyld_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		fd->status = NVME_SC_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		fd->rcv_rsplen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		fd->transferred_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		fd->status = NVME_SC_INTERNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	spin_unlock_irqrestore(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	fd->done(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	qla2xxx_rel_qpair_sp(sp->qpair, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static void qla_nvme_ls_unmap(struct srb *sp, struct nvmefc_ls_req *fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (sp->flags & SRB_DMA_VALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		struct srb_iocb *nvme = &sp->u.iocb_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		struct qla_hw_data *ha = sp->fcport->vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		dma_unmap_single(&ha->pdev->dev, nvme->u.nvme.cmd_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				 fd->rqstlen, DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		sp->flags &= ~SRB_DMA_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static void qla_nvme_release_ls_cmd_kref(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct srb *sp = container_of(kref, struct srb, cmd_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct nvme_private *priv = (struct nvme_private *)sp->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct nvmefc_ls_req *fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	spin_lock_irqsave(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	priv->sp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	sp->priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	spin_unlock_irqrestore(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	fd = priv->fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	qla_nvme_ls_unmap(sp, fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	fd->done(fd, priv->comp_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	qla2x00_rel_sp(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static void qla_nvme_ls_complete(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct nvme_private *priv =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		container_of(work, struct nvme_private, ls_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	kref_put(&priv->sp->cmd_kref, qla_nvme_release_ls_cmd_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static void qla_nvme_sp_ls_done(srb_t *sp, int res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct nvme_private *priv = sp->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (WARN_ON_ONCE(kref_read(&sp->cmd_kref) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		res = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	priv->comp_status = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	INIT_WORK(&priv->ls_work, qla_nvme_ls_complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	schedule_work(&priv->ls_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* it assumed that QPair lock is held. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static void qla_nvme_sp_done(srb_t *sp, int res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct nvme_private *priv = sp->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	priv->comp_status = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	kref_put(&sp->cmd_kref, qla_nvme_release_fcp_cmd_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static void qla_nvme_abort_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct nvme_private *priv =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		container_of(work, struct nvme_private, abort_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	srb_t *sp = priv->sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	fc_port_t *fcport = sp->fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct qla_hw_data *ha = fcport->vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	int rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	ql_dbg(ql_dbg_io, fcport->vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	       "%s called for sp=%p, hndl=%x on fcport=%p deleted=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	       __func__, sp, sp->handle, fcport, fcport->deleted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (!ha->flags.fw_started && fcport->deleted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (ha->flags.host_shutting_down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		ql_log(ql_log_info, sp->fcport->vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		    "%s Calling done on sp: %p, type: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		    __func__, sp, sp->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		sp->done(sp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	rval = ha->isp_ops->abort_command(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	ql_dbg(ql_dbg_io, fcport->vha, 0x212b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	    "%s: %s command for sp=%p, handle=%x on fcport=%p rval=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	    __func__, (rval != QLA_SUCCESS) ? "Failed to abort" : "Aborted",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	    sp, sp->handle, fcport, rval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	/* kref_get was done before work was schedule. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	kref_put(&sp->cmd_kref, sp->put_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static void qla_nvme_ls_abort(struct nvme_fc_local_port *lport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)     struct nvme_fc_remote_port *rport, struct nvmefc_ls_req *fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	struct nvme_private *priv = fd->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	spin_lock_irqsave(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (!priv->sp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		spin_unlock_irqrestore(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (!kref_get_unless_zero(&priv->sp->cmd_kref)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		spin_unlock_irqrestore(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	spin_unlock_irqrestore(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	INIT_WORK(&priv->abort_work, qla_nvme_abort_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	schedule_work(&priv->abort_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static int qla_nvme_ls_req(struct nvme_fc_local_port *lport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)     struct nvme_fc_remote_port *rport, struct nvmefc_ls_req *fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	struct qla_nvme_rport *qla_rport = rport->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	fc_port_t *fcport = qla_rport->fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	struct srb_iocb   *nvme;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	struct nvme_private *priv = fd->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct scsi_qla_host *vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	int     rval = QLA_FUNCTION_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct qla_hw_data *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	srb_t           *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (!fcport || (fcport && fcport->deleted))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	vha = fcport->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (!ha->flags.fw_started)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	/* Alloc SRB structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (!sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	sp->type = SRB_NVME_LS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	sp->name = "nvme_ls";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	sp->done = qla_nvme_sp_ls_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	sp->put_fn = qla_nvme_release_ls_cmd_kref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	sp->priv = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	priv->sp = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	kref_init(&sp->cmd_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	spin_lock_init(&priv->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	nvme = &sp->u.iocb_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	priv->fd = fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	nvme->u.nvme.desc = fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	nvme->u.nvme.dir = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	nvme->u.nvme.dl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	nvme->u.nvme.cmd_len = fd->rqstlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	nvme->u.nvme.rsp_len = fd->rsplen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	nvme->u.nvme.rsp_dma = fd->rspdma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	nvme->u.nvme.timeout_sec = fd->timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	nvme->u.nvme.cmd_dma = dma_map_single(&ha->pdev->dev, fd->rqstaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	    fd->rqstlen, DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	dma_sync_single_for_device(&ha->pdev->dev, nvme->u.nvme.cmd_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	    fd->rqstlen, DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	sp->flags |= SRB_DMA_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	rval = qla2x00_start_sp(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		ql_log(ql_log_warn, vha, 0x700e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		    "qla2x00_start_sp failed = %d\n", rval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		wake_up(&sp->nvme_ls_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		sp->priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		priv->sp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		qla_nvme_ls_unmap(sp, fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		qla2x00_rel_sp(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static void qla_nvme_fcp_abort(struct nvme_fc_local_port *lport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)     struct nvme_fc_remote_port *rport, void *hw_queue_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)     struct nvmefc_fcp_req *fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	struct nvme_private *priv = fd->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	spin_lock_irqsave(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	if (!priv->sp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		spin_unlock_irqrestore(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (!kref_get_unless_zero(&priv->sp->cmd_kref)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		spin_unlock_irqrestore(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	spin_unlock_irqrestore(&priv->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	INIT_WORK(&priv->abort_work, qla_nvme_abort_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	schedule_work(&priv->abort_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static inline int qla2x00_start_nvme_mq(srb_t *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	unsigned long   flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	uint32_t        *clr_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	uint32_t        handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	struct cmd_nvme *cmd_pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	uint16_t        cnt, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	uint16_t        req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	uint16_t        tot_dsds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	uint16_t	avail_dsds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct dsd64	*cur_dsd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct req_que *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	struct scsi_qla_host *vha = sp->fcport->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	struct qla_qpair *qpair = sp->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct srb_iocb *nvme = &sp->u.iocb_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	struct scatterlist *sgl, *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct nvmefc_fcp_req *fd = nvme->u.nvme.desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	struct nvme_fc_cmd_iu *cmd = fd->cmdaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	uint32_t        rval = QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	/* Setup qpair pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	req = qpair->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	tot_dsds = fd->sg_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	/* Acquire qpair specific lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	spin_lock_irqsave(&qpair->qp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	handle = qla2xxx_get_next_handle(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	if (handle == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		goto queuing_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	req_cnt = qla24xx_calc_iocbs(vha, tot_dsds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (req->cnt < (req_cnt + 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		cnt = IS_SHADOW_REG_CAPABLE(ha) ? *req->out_ptr :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		    rd_reg_dword_relaxed(req->req_q_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		if (req->ring_index < cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 			req->cnt = cnt - req->ring_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			req->cnt = req->length - (req->ring_index - cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		if (req->cnt < (req_cnt + 2)){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			rval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			goto queuing_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	if (unlikely(!fd->sqid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		if (cmd->sqe.common.opcode == nvme_admin_async_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			nvme->u.nvme.aen_op = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			atomic_inc(&ha->nvme_active_aen_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	/* Build command packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	req->current_outstanding_cmd = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	req->outstanding_cmds[handle] = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	sp->handle = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	req->cnt -= req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	cmd_pkt = (struct cmd_nvme *)req->ring_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	cmd_pkt->handle = make_handle(req->id, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	/* Zero out remaining portion of packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	clr_ptr = (uint32_t *)cmd_pkt + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	cmd_pkt->entry_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	/* Update entry type to indicate Command NVME IOCB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	cmd_pkt->entry_type = COMMAND_NVME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	/* No data transfer how do we check buffer len == 0?? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	if (fd->io_dir == NVMEFC_FCP_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		cmd_pkt->control_flags = cpu_to_le16(CF_READ_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		qpair->counters.input_bytes += fd->payload_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		qpair->counters.input_requests++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	} else if (fd->io_dir == NVMEFC_FCP_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		cmd_pkt->control_flags = cpu_to_le16(CF_WRITE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		if ((vha->flags.nvme_first_burst) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		    (sp->fcport->nvme_prli_service_param &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			NVME_PRLI_SP_FIRST_BURST)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			if ((fd->payload_length <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 			    sp->fcport->nvme_first_burst_size) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 				(sp->fcport->nvme_first_burst_size == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 				cmd_pkt->control_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 					cpu_to_le16(CF_NVME_FIRST_BURST_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		qpair->counters.output_bytes += fd->payload_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		qpair->counters.output_requests++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	} else if (fd->io_dir == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		cmd_pkt->control_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	/* Set BIT_13 of control flags for Async event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (vha->flags.nvme2_enabled &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	    cmd->sqe.common.opcode == nvme_admin_async_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		cmd_pkt->control_flags |= cpu_to_le16(CF_ADMIN_ASYNC_EVENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	/* Set NPORT-ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	cmd_pkt->vp_index = sp->fcport->vha->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	/* NVME RSP IU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	cmd_pkt->nvme_rsp_dsd_len = cpu_to_le16(fd->rsplen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	put_unaligned_le64(fd->rspdma, &cmd_pkt->nvme_rsp_dseg_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	/* NVME CNMD IU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	cmd_pkt->nvme_cmnd_dseg_len = cpu_to_le16(fd->cmdlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	cmd_pkt->nvme_cmnd_dseg_address = cpu_to_le64(fd->cmddma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	cmd_pkt->byte_count = cpu_to_le32(fd->payload_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	/* One DSD is available in the Command Type NVME IOCB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	avail_dsds = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	cur_dsd = &cmd_pkt->nvme_dsd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	sgl = fd->first_sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	/* Load data segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	for_each_sg(sgl, sg, tot_dsds, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		cont_a64_entry_t *cont_pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		/* Allocate additional continuation packets? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		if (avail_dsds == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 			 * Five DSDs are available in the Continuation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 			 * Type 1 IOCB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 			/* Adjust ring index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 			req->ring_index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			if (req->ring_index == req->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 				req->ring_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 				req->ring_ptr = req->ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 				req->ring_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 			cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			put_unaligned_le32(CONTINUE_A64_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 					   &cont_pkt->entry_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 			cur_dsd = cont_pkt->dsd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 			avail_dsds = ARRAY_SIZE(cont_pkt->dsd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		append_dsd64(&cur_dsd, sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		avail_dsds--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	/* Set total entry count. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	cmd_pkt->entry_count = (uint8_t)req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	/* Adjust ring index. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	req->ring_index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	if (req->ring_index == req->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		req->ring_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		req->ring_ptr = req->ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		req->ring_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	/* Set chip new ring index. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	wrt_reg_dword(req->req_q_in, req->ring_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) queuing_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	spin_unlock_irqrestore(&qpair->qp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /* Post a command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static int qla_nvme_post_cmd(struct nvme_fc_local_port *lport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)     struct nvme_fc_remote_port *rport, void *hw_queue_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)     struct nvmefc_fcp_req *fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	fc_port_t *fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	struct srb_iocb *nvme;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	struct scsi_qla_host *vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	int rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	srb_t *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	struct qla_qpair *qpair = hw_queue_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	struct nvme_private *priv = fd->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	struct qla_nvme_rport *qla_rport = rport->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	if (!priv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		/* nvme association has been torn down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	fcport = qla_rport->fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	if (!qpair || !fcport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	if (!qpair->fw_started || fcport->deleted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	vha = fcport->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	if (!(fcport->nvme_flag & NVME_FLAG_REGISTERED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	    (qpair && !qpair->fw_started) || fcport->deleted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	 * If we know the dev is going away while the transport is still sending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	 * IO's return busy back to stall the IO Q.  This happens when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	 * link goes away and fw hasn't notified us yet, but IO's are being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	 * returned. If the dev comes back quickly we won't exhaust the IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	 * retry count at the core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	if (fcport->nvme_flag & NVME_FLAG_RESETTING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	/* Alloc SRB structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	if (!sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	init_waitqueue_head(&sp->nvme_ls_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	kref_init(&sp->cmd_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	spin_lock_init(&priv->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	sp->priv = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	priv->sp = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	sp->type = SRB_NVME_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	sp->name = "nvme_cmd";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	sp->done = qla_nvme_sp_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	sp->put_fn = qla_nvme_release_fcp_cmd_kref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	sp->qpair = qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	sp->vha = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	nvme = &sp->u.iocb_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	nvme->u.nvme.desc = fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	rval = qla2x00_start_nvme_mq(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	if (rval != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		ql_log(ql_log_warn, vha, 0x212d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		    "qla2x00_start_nvme_mq failed = %d\n", rval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		wake_up(&sp->nvme_ls_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		sp->priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		priv->sp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 		qla2xxx_rel_qpair_sp(sp->qpair, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) static void qla_nvme_localport_delete(struct nvme_fc_local_port *lport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	struct scsi_qla_host *vha = lport->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	ql_log(ql_log_info, vha, 0x210f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	    "localport delete of %p completed.\n", vha->nvme_local_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	vha->nvme_local_port = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	complete(&vha->nvme_del_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static void qla_nvme_remoteport_delete(struct nvme_fc_remote_port *rport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	fc_port_t *fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	struct qla_nvme_rport *qla_rport = rport->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	fcport = qla_rport->fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	fcport->nvme_remote_port = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	fcport->nvme_flag &= ~NVME_FLAG_REGISTERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	fcport->nvme_flag &= ~NVME_FLAG_DELETING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	ql_log(ql_log_info, fcport->vha, 0x2110,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	    "remoteport_delete of %p %8phN completed.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	    fcport, fcport->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	complete(&fcport->nvme_del_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) static struct nvme_fc_port_template qla_nvme_fc_transport = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	.localport_delete = qla_nvme_localport_delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	.remoteport_delete = qla_nvme_remoteport_delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	.create_queue   = qla_nvme_alloc_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	.delete_queue 	= NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	.ls_req		= qla_nvme_ls_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	.ls_abort	= qla_nvme_ls_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	.fcp_io		= qla_nvme_post_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	.fcp_abort	= qla_nvme_fcp_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	.max_hw_queues  = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	.max_sgl_segments = 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	.max_dif_sgl_segments = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	.dma_boundary = 0xFFFFFFFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	.local_priv_sz  = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	.remote_priv_sz = sizeof(struct qla_nvme_rport),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	.lsrqst_priv_sz = sizeof(struct nvme_private),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	.fcprqst_priv_sz = sizeof(struct nvme_private),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) void qla_nvme_unregister_remote_port(struct fc_port *fcport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	if (!IS_ENABLED(CONFIG_NVME_FC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	ql_log(ql_log_warn, NULL, 0x2112,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	    "%s: unregister remoteport on %p %8phN\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	    __func__, fcport, fcport->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	if (test_bit(PFLG_DRIVER_REMOVING, &fcport->vha->pci_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 		nvme_fc_set_remoteport_devloss(fcport->nvme_remote_port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	init_completion(&fcport->nvme_del_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	ret = nvme_fc_unregister_remoteport(fcport->nvme_remote_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		ql_log(ql_log_info, fcport->vha, 0x2114,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 			"%s: Failed to unregister nvme_remote_port (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 			    __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	wait_for_completion(&fcport->nvme_del_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) void qla_nvme_delete(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	int nv_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	if (!IS_ENABLED(CONFIG_NVME_FC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	if (vha->nvme_local_port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 		init_completion(&vha->nvme_del_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 		ql_log(ql_log_info, vha, 0x2116,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 			"unregister localport=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 			vha->nvme_local_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 		nv_ret = nvme_fc_unregister_localport(vha->nvme_local_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 		if (nv_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 			ql_log(ql_log_info, vha, 0x2115,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 			    "Unregister of localport failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 			wait_for_completion(&vha->nvme_del_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) int qla_nvme_register_hba(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	struct nvme_fc_port_template *tmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	struct qla_hw_data *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	struct nvme_fc_port_info pinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	if (!IS_ENABLED(CONFIG_NVME_FC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	tmpl = &qla_nvme_fc_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	WARN_ON(vha->nvme_local_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	qla_nvme_fc_transport.max_hw_queues =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	    min((uint8_t)(qla_nvme_fc_transport.max_hw_queues),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 		(uint8_t)(ha->max_qpairs ? ha->max_qpairs : 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	pinfo.node_name = wwn_to_u64(vha->node_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	pinfo.port_name = wwn_to_u64(vha->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	pinfo.port_role = FC_PORT_ROLE_NVME_INITIATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	pinfo.port_id = vha->d_id.b24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	ql_log(ql_log_info, vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	    "register_localport: host-traddr=nn-0x%llx:pn-0x%llx on portID:%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	    pinfo.node_name, pinfo.port_name, pinfo.port_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	qla_nvme_fc_transport.dma_boundary = vha->host->dma_boundary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	ret = nvme_fc_register_localport(&pinfo, tmpl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	    get_device(&ha->pdev->dev), &vha->nvme_local_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 		ql_log(ql_log_warn, vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 		    "register_localport failed: ret=%x\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 		vha->nvme_local_port->private = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }