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