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