forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/scsi/qla2xxx/qla_nvme.c
....@@ -1,8 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * QLogic Fibre Channel HBA Driver
34 * Copyright (c) 2003-2017 QLogic Corporation
4
- *
5
- * See LICENSE.qla2xxx for copyright and licensing details.
65 */
76 #include "qla_nvme.h"
87 #include <linux/scatterlist.h>
....@@ -11,8 +10,6 @@
1110 #include <linux/nvme-fc.h>
1211
1312 static struct nvme_fc_port_template qla_nvme_fc_transport;
14
-
15
-static void qla_nvme_unregister_remote_port(struct work_struct *);
1613
1714 int qla_nvme_register_remote(struct scsi_qla_host *vha, struct fc_port *fcport)
1815 {
....@@ -38,14 +35,13 @@
3835 (fcport->nvme_flag & NVME_FLAG_REGISTERED))
3936 return 0;
4037
41
- INIT_WORK(&fcport->nvme_del_work, qla_nvme_unregister_remote_port);
4238 fcport->nvme_flag &= ~NVME_FLAG_RESETTING;
4339
4440 memset(&req, 0, sizeof(struct nvme_fc_port_info));
4541 req.port_name = wwn_to_u64(fcport->port_name);
4642 req.node_name = wwn_to_u64(fcport->node_name);
4743 req.port_role = 0;
48
- req.dev_loss_tmo = NVME_FC_DEV_LOSS_TMO;
44
+ req.dev_loss_tmo = 0;
4945
5046 if (fcport->nvme_prli_service_param & NVME_PRLI_SP_INITIATOR)
5147 req.port_role = FC_PORT_ROLE_NVME_INITIATOR;
....@@ -72,9 +68,16 @@
7268 return ret;
7369 }
7470
71
+ if (fcport->nvme_prli_service_param & NVME_PRLI_SP_SLER)
72
+ ql_log(ql_log_info, vha, 0x212a,
73
+ "PortID:%06x Supports SLER\n", req.port_id);
74
+
75
+ if (fcport->nvme_prli_service_param & NVME_PRLI_SP_PI_CTRL)
76
+ ql_log(ql_log_info, vha, 0x212b,
77
+ "PortID:%06x Supports PI control\n", req.port_id);
78
+
7579 rport = fcport->nvme_remote_port->private;
7680 rport->fcport = fcport;
77
- list_add_tail(&rport->list, &vha->nvme_rport_list);
7881
7982 fcport->nvme_flag |= NVME_FLAG_REGISTERED;
8083 return 0;
....@@ -106,73 +109,127 @@
106109 return -EINVAL;
107110 }
108111
109
- if (ha->queue_pair_map[qidx]) {
110
- *handle = ha->queue_pair_map[qidx];
111
- ql_log(ql_log_info, vha, 0x2121,
112
- "Returning existing qpair of %p for idx=%x\n",
113
- *handle, qidx);
114
- return 0;
115
- }
112
+ /* Use base qpair if max_qpairs is 0 */
113
+ if (!ha->max_qpairs) {
114
+ qpair = ha->base_qpair;
115
+ } else {
116
+ if (ha->queue_pair_map[qidx]) {
117
+ *handle = ha->queue_pair_map[qidx];
118
+ ql_log(ql_log_info, vha, 0x2121,
119
+ "Returning existing qpair of %p for idx=%x\n",
120
+ *handle, qidx);
121
+ return 0;
122
+ }
116123
117
- qpair = qla2xxx_create_qpair(vha, 5, vha->vp_idx, true);
118
- if (qpair == NULL) {
119
- ql_log(ql_log_warn, vha, 0x2122,
120
- "Failed to allocate qpair\n");
121
- return -EINVAL;
124
+ qpair = qla2xxx_create_qpair(vha, 5, vha->vp_idx, true);
125
+ if (!qpair) {
126
+ ql_log(ql_log_warn, vha, 0x2122,
127
+ "Failed to allocate qpair\n");
128
+ return -EINVAL;
129
+ }
122130 }
123131 *handle = qpair;
124132
125133 return 0;
126134 }
127135
128
-static void qla_nvme_sp_ls_done(void *ptr, int res)
136
+static void qla_nvme_release_fcp_cmd_kref(struct kref *kref)
129137 {
130
- srb_t *sp = ptr;
138
+ struct srb *sp = container_of(kref, struct srb, cmd_kref);
139
+ struct nvme_private *priv = (struct nvme_private *)sp->priv;
140
+ struct nvmefc_fcp_req *fd;
131141 struct srb_iocb *nvme;
132
- struct nvmefc_ls_req *fd;
133
- struct nvme_private *priv;
142
+ unsigned long flags;
134143
135
- if (atomic_read(&sp->ref_count) == 0) {
136
- ql_log(ql_log_warn, sp->fcport->vha, 0x2123,
137
- "SP reference-count to ZERO on LS_done -- sp=%p.\n", sp);
138
- return;
144
+ if (!priv)
145
+ goto out;
146
+
147
+ nvme = &sp->u.iocb_cmd;
148
+ fd = nvme->u.nvme.desc;
149
+
150
+ spin_lock_irqsave(&priv->cmd_lock, flags);
151
+ priv->sp = NULL;
152
+ sp->priv = NULL;
153
+ if (priv->comp_status == QLA_SUCCESS) {
154
+ fd->rcv_rsplen = le16_to_cpu(nvme->u.nvme.rsp_pyld_len);
155
+ fd->status = NVME_SC_SUCCESS;
156
+ } else {
157
+ fd->rcv_rsplen = 0;
158
+ fd->transferred_length = 0;
159
+ fd->status = NVME_SC_INTERNAL;
139160 }
161
+ spin_unlock_irqrestore(&priv->cmd_lock, flags);
140162
141
- if (!atomic_dec_and_test(&sp->ref_count))
163
+ fd->done(fd);
164
+out:
165
+ qla2xxx_rel_qpair_sp(sp->qpair, sp);
166
+}
167
+
168
+static void qla_nvme_ls_unmap(struct srb *sp, struct nvmefc_ls_req *fd)
169
+{
170
+ if (sp->flags & SRB_DMA_VALID) {
171
+ struct srb_iocb *nvme = &sp->u.iocb_cmd;
172
+ struct qla_hw_data *ha = sp->fcport->vha->hw;
173
+
174
+ dma_unmap_single(&ha->pdev->dev, nvme->u.nvme.cmd_dma,
175
+ fd->rqstlen, DMA_TO_DEVICE);
176
+ sp->flags &= ~SRB_DMA_VALID;
177
+ }
178
+}
179
+
180
+static void qla_nvme_release_ls_cmd_kref(struct kref *kref)
181
+{
182
+ struct srb *sp = container_of(kref, struct srb, cmd_kref);
183
+ struct nvme_private *priv = (struct nvme_private *)sp->priv;
184
+ struct nvmefc_ls_req *fd;
185
+ unsigned long flags;
186
+
187
+ if (!priv)
188
+ goto out;
189
+
190
+ spin_lock_irqsave(&priv->cmd_lock, flags);
191
+ priv->sp = NULL;
192
+ sp->priv = NULL;
193
+ spin_unlock_irqrestore(&priv->cmd_lock, flags);
194
+
195
+ fd = priv->fd;
196
+
197
+ qla_nvme_ls_unmap(sp, fd);
198
+ fd->done(fd, priv->comp_status);
199
+out:
200
+ qla2x00_rel_sp(sp);
201
+}
202
+
203
+static void qla_nvme_ls_complete(struct work_struct *work)
204
+{
205
+ struct nvme_private *priv =
206
+ container_of(work, struct nvme_private, ls_work);
207
+
208
+ kref_put(&priv->sp->cmd_kref, qla_nvme_release_ls_cmd_kref);
209
+}
210
+
211
+static void qla_nvme_sp_ls_done(srb_t *sp, int res)
212
+{
213
+ struct nvme_private *priv = sp->priv;
214
+
215
+ if (WARN_ON_ONCE(kref_read(&sp->cmd_kref) == 0))
142216 return;
143217
144218 if (res)
145219 res = -EINVAL;
146220
147
- nvme = &sp->u.iocb_cmd;
148
- fd = nvme->u.nvme.desc;
149
- priv = fd->private;
150221 priv->comp_status = res;
222
+ INIT_WORK(&priv->ls_work, qla_nvme_ls_complete);
151223 schedule_work(&priv->ls_work);
152
- /* work schedule doesn't need the sp */
153
- qla2x00_rel_sp(sp);
154224 }
155225
156
-static void qla_nvme_sp_done(void *ptr, int res)
226
+/* it assumed that QPair lock is held. */
227
+static void qla_nvme_sp_done(srb_t *sp, int res)
157228 {
158
- srb_t *sp = ptr;
159
- struct srb_iocb *nvme;
160
- struct nvmefc_fcp_req *fd;
229
+ struct nvme_private *priv = sp->priv;
161230
162
- nvme = &sp->u.iocb_cmd;
163
- fd = nvme->u.nvme.desc;
164
-
165
- if (!atomic_dec_and_test(&sp->ref_count))
166
- return;
167
-
168
- if (res == QLA_SUCCESS)
169
- fd->status = 0;
170
- else
171
- fd->status = NVME_SC_INTERNAL;
172
-
173
- fd->rcv_rsplen = nvme->u.nvme.rsp_pyld_len;
174
- fd->done(fd);
175
- qla2xxx_rel_qpair_sp(sp->qpair, sp);
231
+ priv->comp_status = res;
232
+ kref_put(&sp->cmd_kref, qla_nvme_release_fcp_cmd_kref);
176233
177234 return;
178235 }
....@@ -186,30 +243,53 @@
186243 struct qla_hw_data *ha = fcport->vha->hw;
187244 int rval;
188245
246
+ ql_dbg(ql_dbg_io, fcport->vha, 0xffff,
247
+ "%s called for sp=%p, hndl=%x on fcport=%p deleted=%d\n",
248
+ __func__, sp, sp->handle, fcport, fcport->deleted);
249
+
250
+ if (!ha->flags.fw_started && fcport->deleted)
251
+ goto out;
252
+
253
+ if (ha->flags.host_shutting_down) {
254
+ ql_log(ql_log_info, sp->fcport->vha, 0xffff,
255
+ "%s Calling done on sp: %p, type: 0x%x\n",
256
+ __func__, sp, sp->type);
257
+ sp->done(sp, 0);
258
+ goto out;
259
+ }
260
+
189261 rval = ha->isp_ops->abort_command(sp);
190262
191263 ql_dbg(ql_dbg_io, fcport->vha, 0x212b,
192264 "%s: %s command for sp=%p, handle=%x on fcport=%p rval=%x\n",
193265 __func__, (rval != QLA_SUCCESS) ? "Failed to abort" : "Aborted",
194266 sp, sp->handle, fcport, rval);
267
+
268
+out:
269
+ /* kref_get was done before work was schedule. */
270
+ kref_put(&sp->cmd_kref, sp->put_fn);
195271 }
196272
197273 static void qla_nvme_ls_abort(struct nvme_fc_local_port *lport,
198274 struct nvme_fc_remote_port *rport, struct nvmefc_ls_req *fd)
199275 {
200276 struct nvme_private *priv = fd->private;
277
+ unsigned long flags;
278
+
279
+ spin_lock_irqsave(&priv->cmd_lock, flags);
280
+ if (!priv->sp) {
281
+ spin_unlock_irqrestore(&priv->cmd_lock, flags);
282
+ return;
283
+ }
284
+
285
+ if (!kref_get_unless_zero(&priv->sp->cmd_kref)) {
286
+ spin_unlock_irqrestore(&priv->cmd_lock, flags);
287
+ return;
288
+ }
289
+ spin_unlock_irqrestore(&priv->cmd_lock, flags);
201290
202291 INIT_WORK(&priv->abort_work, qla_nvme_abort_work);
203292 schedule_work(&priv->abort_work);
204
-}
205
-
206
-static void qla_nvme_ls_complete(struct work_struct *work)
207
-{
208
- struct nvme_private *priv =
209
- container_of(work, struct nvme_private, ls_work);
210
- struct nvmefc_ls_req *fd = priv->fd;
211
-
212
- fd->done(fd, priv->comp_status);
213293 }
214294
215295 static int qla_nvme_ls_req(struct nvme_fc_local_port *lport,
....@@ -224,8 +304,16 @@
224304 struct qla_hw_data *ha;
225305 srb_t *sp;
226306
307
+
308
+ if (!fcport || (fcport && fcport->deleted))
309
+ return rval;
310
+
227311 vha = fcport->vha;
228312 ha = vha->hw;
313
+
314
+ if (!ha->flags.fw_started)
315
+ return rval;
316
+
229317 /* Alloc SRB structure */
230318 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
231319 if (!sp)
....@@ -234,11 +322,13 @@
234322 sp->type = SRB_NVME_LS;
235323 sp->name = "nvme_ls";
236324 sp->done = qla_nvme_sp_ls_done;
237
- atomic_set(&sp->ref_count, 1);
238
- nvme = &sp->u.iocb_cmd;
325
+ sp->put_fn = qla_nvme_release_ls_cmd_kref;
326
+ sp->priv = priv;
239327 priv->sp = sp;
328
+ kref_init(&sp->cmd_kref);
329
+ spin_lock_init(&priv->cmd_lock);
330
+ nvme = &sp->u.iocb_cmd;
240331 priv->fd = fd;
241
- INIT_WORK(&priv->ls_work, qla_nvme_ls_complete);
242332 nvme->u.nvme.desc = fd;
243333 nvme->u.nvme.dir = 0;
244334 nvme->u.nvme.dl = 0;
....@@ -251,12 +341,17 @@
251341 dma_sync_single_for_device(&ha->pdev->dev, nvme->u.nvme.cmd_dma,
252342 fd->rqstlen, DMA_TO_DEVICE);
253343
344
+ sp->flags |= SRB_DMA_VALID;
345
+
254346 rval = qla2x00_start_sp(sp);
255347 if (rval != QLA_SUCCESS) {
256348 ql_log(ql_log_warn, vha, 0x700e,
257349 "qla2x00_start_sp failed = %d\n", rval);
258
- atomic_dec(&sp->ref_count);
259350 wake_up(&sp->nvme_ls_waitq);
351
+ sp->priv = NULL;
352
+ priv->sp = NULL;
353
+ qla_nvme_ls_unmap(sp, fd);
354
+ qla2x00_rel_sp(sp);
260355 return rval;
261356 }
262357
....@@ -268,34 +363,34 @@
268363 struct nvmefc_fcp_req *fd)
269364 {
270365 struct nvme_private *priv = fd->private;
366
+ unsigned long flags;
367
+
368
+ spin_lock_irqsave(&priv->cmd_lock, flags);
369
+ if (!priv->sp) {
370
+ spin_unlock_irqrestore(&priv->cmd_lock, flags);
371
+ return;
372
+ }
373
+ if (!kref_get_unless_zero(&priv->sp->cmd_kref)) {
374
+ spin_unlock_irqrestore(&priv->cmd_lock, flags);
375
+ return;
376
+ }
377
+ spin_unlock_irqrestore(&priv->cmd_lock, flags);
271378
272379 INIT_WORK(&priv->abort_work, qla_nvme_abort_work);
273380 schedule_work(&priv->abort_work);
274
-}
275
-
276
-static void qla_nvme_poll(struct nvme_fc_local_port *lport, void *hw_queue_handle)
277
-{
278
- struct qla_qpair *qpair = hw_queue_handle;
279
- unsigned long flags;
280
- struct scsi_qla_host *vha = lport->private;
281
-
282
- spin_lock_irqsave(&qpair->qp_lock, flags);
283
- qla24xx_process_response_queue(vha, qpair->rsp);
284
- spin_unlock_irqrestore(&qpair->qp_lock, flags);
285381 }
286382
287383 static inline int qla2x00_start_nvme_mq(srb_t *sp)
288384 {
289385 unsigned long flags;
290386 uint32_t *clr_ptr;
291
- uint32_t index;
292387 uint32_t handle;
293388 struct cmd_nvme *cmd_pkt;
294389 uint16_t cnt, i;
295390 uint16_t req_cnt;
296391 uint16_t tot_dsds;
297392 uint16_t avail_dsds;
298
- uint32_t *cur_dsd;
393
+ struct dsd64 *cur_dsd;
299394 struct req_que *req = NULL;
300395 struct scsi_qla_host *vha = sp->fcport->vha;
301396 struct qla_hw_data *ha = vha->hw;
....@@ -303,6 +398,7 @@
303398 struct srb_iocb *nvme = &sp->u.iocb_cmd;
304399 struct scatterlist *sgl, *sg;
305400 struct nvmefc_fcp_req *fd = nvme->u.nvme.desc;
401
+ struct nvme_fc_cmd_iu *cmd = fd->cmdaddr;
306402 uint32_t rval = QLA_SUCCESS;
307403
308404 /* Setup qpair pointers */
....@@ -312,24 +408,15 @@
312408 /* Acquire qpair specific lock */
313409 spin_lock_irqsave(&qpair->qp_lock, flags);
314410
315
- /* Check for room in outstanding command list. */
316
- handle = req->current_outstanding_cmd;
317
- for (index = 1; index < req->num_outstanding_cmds; index++) {
318
- handle++;
319
- if (handle == req->num_outstanding_cmds)
320
- handle = 1;
321
- if (!req->outstanding_cmds[handle])
322
- break;
323
- }
324
-
325
- if (index == req->num_outstanding_cmds) {
411
+ handle = qla2xxx_get_next_handle(req);
412
+ if (handle == 0) {
326413 rval = -EBUSY;
327414 goto queuing_error;
328415 }
329416 req_cnt = qla24xx_calc_iocbs(vha, tot_dsds);
330417 if (req->cnt < (req_cnt + 2)) {
331418 cnt = IS_SHADOW_REG_CAPABLE(ha) ? *req->out_ptr :
332
- RD_REG_DWORD_RELAXED(req->req_q_out);
419
+ rd_reg_dword_relaxed(req->req_q_out);
333420
334421 if (req->ring_index < cnt)
335422 req->cnt = cnt - req->ring_index;
....@@ -343,7 +430,6 @@
343430 }
344431
345432 if (unlikely(!fd->sqid)) {
346
- struct nvme_fc_cmd_iu *cmd = fd->cmdaddr;
347433 if (cmd->sqe.common.opcode == nvme_admin_async_event) {
348434 nvme->u.nvme.aen_op = 1;
349435 atomic_inc(&ha->nvme_active_aen_cnt);
....@@ -357,7 +443,7 @@
357443 req->cnt -= req_cnt;
358444
359445 cmd_pkt = (struct cmd_nvme *)req->ring_ptr;
360
- cmd_pkt->handle = MAKE_HANDLE(req->id, handle);
446
+ cmd_pkt->handle = make_handle(req->id, handle);
361447
362448 /* Zero out remaining portion of packet. */
363449 clr_ptr = (uint32_t *)cmd_pkt + 2;
....@@ -370,17 +456,29 @@
370456
371457 /* No data transfer how do we check buffer len == 0?? */
372458 if (fd->io_dir == NVMEFC_FCP_READ) {
373
- cmd_pkt->control_flags =
374
- cpu_to_le16(CF_READ_DATA | CF_NVME_ENABLE);
375
- vha->qla_stats.input_bytes += fd->payload_length;
376
- vha->qla_stats.input_requests++;
459
+ cmd_pkt->control_flags = cpu_to_le16(CF_READ_DATA);
460
+ qpair->counters.input_bytes += fd->payload_length;
461
+ qpair->counters.input_requests++;
377462 } else if (fd->io_dir == NVMEFC_FCP_WRITE) {
378
- cmd_pkt->control_flags =
379
- cpu_to_le16(CF_WRITE_DATA | CF_NVME_ENABLE);
380
- vha->qla_stats.output_bytes += fd->payload_length;
381
- vha->qla_stats.output_requests++;
463
+ cmd_pkt->control_flags = cpu_to_le16(CF_WRITE_DATA);
464
+ if ((vha->flags.nvme_first_burst) &&
465
+ (sp->fcport->nvme_prli_service_param &
466
+ NVME_PRLI_SP_FIRST_BURST)) {
467
+ if ((fd->payload_length <=
468
+ sp->fcport->nvme_first_burst_size) ||
469
+ (sp->fcport->nvme_first_burst_size == 0))
470
+ cmd_pkt->control_flags |=
471
+ cpu_to_le16(CF_NVME_FIRST_BURST_ENABLE);
472
+ }
473
+ qpair->counters.output_bytes += fd->payload_length;
474
+ qpair->counters.output_requests++;
382475 } else if (fd->io_dir == 0) {
383
- cmd_pkt->control_flags = cpu_to_le16(CF_NVME_ENABLE);
476
+ cmd_pkt->control_flags = 0;
477
+ }
478
+ /* Set BIT_13 of control flags for Async event */
479
+ if (vha->flags.nvme2_enabled &&
480
+ cmd->sqe.common.opcode == nvme_admin_async_event) {
481
+ cmd_pkt->control_flags |= cpu_to_le16(CF_ADMIN_ASYNC_EVENT);
384482 }
385483
386484 /* Set NPORT-ID */
....@@ -392,25 +490,22 @@
392490
393491 /* NVME RSP IU */
394492 cmd_pkt->nvme_rsp_dsd_len = cpu_to_le16(fd->rsplen);
395
- cmd_pkt->nvme_rsp_dseg_address[0] = cpu_to_le32(LSD(fd->rspdma));
396
- cmd_pkt->nvme_rsp_dseg_address[1] = cpu_to_le32(MSD(fd->rspdma));
493
+ put_unaligned_le64(fd->rspdma, &cmd_pkt->nvme_rsp_dseg_address);
397494
398495 /* NVME CNMD IU */
399496 cmd_pkt->nvme_cmnd_dseg_len = cpu_to_le16(fd->cmdlen);
400
- cmd_pkt->nvme_cmnd_dseg_address[0] = cpu_to_le32(LSD(fd->cmddma));
401
- cmd_pkt->nvme_cmnd_dseg_address[1] = cpu_to_le32(MSD(fd->cmddma));
497
+ cmd_pkt->nvme_cmnd_dseg_address = cpu_to_le64(fd->cmddma);
402498
403499 cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
404500 cmd_pkt->byte_count = cpu_to_le32(fd->payload_length);
405501
406502 /* One DSD is available in the Command Type NVME IOCB */
407503 avail_dsds = 1;
408
- cur_dsd = (uint32_t *)&cmd_pkt->nvme_data_dseg_address[0];
504
+ cur_dsd = &cmd_pkt->nvme_dsd;
409505 sgl = fd->first_sgl;
410506
411507 /* Load data segments */
412508 for_each_sg(sgl, sg, tot_dsds, i) {
413
- dma_addr_t sle_dma;
414509 cont_a64_entry_t *cont_pkt;
415510
416511 /* Allocate additional continuation packets? */
....@@ -429,17 +524,14 @@
429524 req->ring_ptr++;
430525 }
431526 cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
432
- *((uint32_t *)(&cont_pkt->entry_type)) =
433
- cpu_to_le32(CONTINUE_A64_TYPE);
527
+ put_unaligned_le32(CONTINUE_A64_TYPE,
528
+ &cont_pkt->entry_type);
434529
435
- cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
436
- avail_dsds = 5;
530
+ cur_dsd = cont_pkt->dsd;
531
+ avail_dsds = ARRAY_SIZE(cont_pkt->dsd);
437532 }
438533
439
- sle_dma = sg_dma_address(sg);
440
- *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
441
- *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
442
- *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
534
+ append_dsd64(&cur_dsd, sg);
443535 avail_dsds--;
444536 }
445537
....@@ -457,7 +549,7 @@
457549 }
458550
459551 /* Set chip new ring index. */
460
- WRT_REG_DWORD(req->req_q_in, req->ring_index);
552
+ wrt_reg_dword(req->req_q_in, req->ring_index);
461553
462554 queuing_error:
463555 spin_unlock_irqrestore(&qpair->qp_lock, flags);
....@@ -472,7 +564,7 @@
472564 fc_port_t *fcport;
473565 struct srb_iocb *nvme;
474566 struct scsi_qla_host *vha;
475
- int rval = -ENODEV;
567
+ int rval;
476568 srb_t *sp;
477569 struct qla_qpair *qpair = hw_queue_handle;
478570 struct nvme_private *priv = fd->private;
....@@ -480,15 +572,25 @@
480572
481573 if (!priv) {
482574 /* nvme association has been torn down */
483
- return rval;
575
+ return -ENODEV;
484576 }
485577
486578 fcport = qla_rport->fcport;
487579
580
+ if (!qpair || !fcport)
581
+ return -ENODEV;
582
+
583
+ if (!qpair->fw_started || fcport->deleted)
584
+ return -EBUSY;
585
+
488586 vha = fcport->vha;
489587
490
- if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
491
- return rval;
588
+ if (!(fcport->nvme_flag & NVME_FLAG_REGISTERED))
589
+ return -ENODEV;
590
+
591
+ if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
592
+ (qpair && !qpair->fw_started) || fcport->deleted)
593
+ return -EBUSY;
492594
493595 /*
494596 * If we know the dev is going away while the transport is still sending
....@@ -501,16 +603,19 @@
501603 return -EBUSY;
502604
503605 /* Alloc SRB structure */
504
- sp = qla2xxx_get_qpair_sp(qpair, fcport, GFP_ATOMIC);
606
+ sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
505607 if (!sp)
506608 return -EBUSY;
507609
508
- atomic_set(&sp->ref_count, 1);
509610 init_waitqueue_head(&sp->nvme_ls_waitq);
611
+ kref_init(&sp->cmd_kref);
612
+ spin_lock_init(&priv->cmd_lock);
613
+ sp->priv = priv;
510614 priv->sp = sp;
511615 sp->type = SRB_NVME_CMD;
512616 sp->name = "nvme_cmd";
513617 sp->done = qla_nvme_sp_done;
618
+ sp->put_fn = qla_nvme_release_fcp_cmd_kref;
514619 sp->qpair = qpair;
515620 sp->vha = vha;
516621 nvme = &sp->u.iocb_cmd;
....@@ -520,8 +625,10 @@
520625 if (rval != QLA_SUCCESS) {
521626 ql_log(ql_log_warn, vha, 0x212d,
522627 "qla2x00_start_nvme_mq failed = %d\n", rval);
523
- atomic_dec(&sp->ref_count);
524628 wake_up(&sp->nvme_ls_waitq);
629
+ sp->priv = NULL;
630
+ priv->sp = NULL;
631
+ qla2xxx_rel_qpair_sp(sp->qpair, sp);
525632 }
526633
527634 return rval;
....@@ -540,29 +647,16 @@
540647 static void qla_nvme_remoteport_delete(struct nvme_fc_remote_port *rport)
541648 {
542649 fc_port_t *fcport;
543
- struct qla_nvme_rport *qla_rport = rport->private, *trport;
650
+ struct qla_nvme_rport *qla_rport = rport->private;
544651
545652 fcport = qla_rport->fcport;
546653 fcport->nvme_remote_port = NULL;
547654 fcport->nvme_flag &= ~NVME_FLAG_REGISTERED;
548
-
549
- list_for_each_entry_safe(qla_rport, trport,
550
- &fcport->vha->nvme_rport_list, list) {
551
- if (qla_rport->fcport == fcport) {
552
- list_del(&qla_rport->list);
553
- break;
554
- }
555
- }
556
- complete(&fcport->nvme_del_done);
557
-
558
- if (!test_bit(UNLOADING, &fcport->vha->dpc_flags)) {
559
- INIT_WORK(&fcport->free_work, qlt_free_session_done);
560
- schedule_work(&fcport->free_work);
561
- }
562
-
563655 fcport->nvme_flag &= ~NVME_FLAG_DELETING;
564656 ql_log(ql_log_info, fcport->vha, 0x2110,
565
- "remoteport_delete of %p completed.\n", fcport);
657
+ "remoteport_delete of %p %8phN completed.\n",
658
+ fcport, fcport->port_name);
659
+ complete(&fcport->nvme_del_done);
566660 }
567661
568662 static struct nvme_fc_port_template qla_nvme_fc_transport = {
....@@ -574,9 +668,8 @@
574668 .ls_abort = qla_nvme_ls_abort,
575669 .fcp_io = qla_nvme_post_cmd,
576670 .fcp_abort = qla_nvme_fcp_abort,
577
- .poll_queue = qla_nvme_poll,
578671 .max_hw_queues = 8,
579
- .max_sgl_segments = 128,
672
+ .max_sgl_segments = 1024,
580673 .max_dif_sgl_segments = 64,
581674 .dma_boundary = 0xFFFFFFFF,
582675 .local_priv_sz = 8,
....@@ -585,78 +678,35 @@
585678 .fcprqst_priv_sz = sizeof(struct nvme_private),
586679 };
587680
588
-#define NVME_ABORT_POLLING_PERIOD 2
589
-static int qla_nvme_wait_on_command(srb_t *sp)
681
+void qla_nvme_unregister_remote_port(struct fc_port *fcport)
590682 {
591
- int ret = QLA_SUCCESS;
592
-
593
- wait_event_timeout(sp->nvme_ls_waitq, (atomic_read(&sp->ref_count) > 1),
594
- NVME_ABORT_POLLING_PERIOD*HZ);
595
-
596
- if (atomic_read(&sp->ref_count) > 1)
597
- ret = QLA_FUNCTION_FAILED;
598
-
599
- return ret;
600
-}
601
-
602
-void qla_nvme_abort(struct qla_hw_data *ha, struct srb *sp, int res)
603
-{
604
- int rval;
605
-
606
- if (ha->flags.fw_started) {
607
- rval = ha->isp_ops->abort_command(sp);
608
- if (!rval && !qla_nvme_wait_on_command(sp))
609
- ql_log(ql_log_warn, NULL, 0x2112,
610
- "timed out waiting on sp=%p\n", sp);
611
- } else {
612
- sp->done(sp, res);
613
- }
614
-}
615
-
616
-static void qla_nvme_unregister_remote_port(struct work_struct *work)
617
-{
618
- struct fc_port *fcport = container_of(work, struct fc_port,
619
- nvme_del_work);
620
- struct qla_nvme_rport *qla_rport, *trport;
683
+ int ret;
621684
622685 if (!IS_ENABLED(CONFIG_NVME_FC))
623686 return;
624687
625688 ql_log(ql_log_warn, NULL, 0x2112,
626
- "%s: unregister remoteport on %p\n",__func__, fcport);
689
+ "%s: unregister remoteport on %p %8phN\n",
690
+ __func__, fcport, fcport->port_name);
627691
628
- list_for_each_entry_safe(qla_rport, trport,
629
- &fcport->vha->nvme_rport_list, list) {
630
- if (qla_rport->fcport == fcport) {
631
- ql_log(ql_log_info, fcport->vha, 0x2113,
632
- "%s: fcport=%p\n", __func__, fcport);
633
- init_completion(&fcport->nvme_del_done);
634
- nvme_fc_unregister_remoteport(
635
- fcport->nvme_remote_port);
636
- wait_for_completion(&fcport->nvme_del_done);
637
- break;
638
- }
639
- }
692
+ if (test_bit(PFLG_DRIVER_REMOVING, &fcport->vha->pci_flags))
693
+ nvme_fc_set_remoteport_devloss(fcport->nvme_remote_port, 0);
694
+
695
+ init_completion(&fcport->nvme_del_done);
696
+ ret = nvme_fc_unregister_remoteport(fcport->nvme_remote_port);
697
+ if (ret)
698
+ ql_log(ql_log_info, fcport->vha, 0x2114,
699
+ "%s: Failed to unregister nvme_remote_port (%d)\n",
700
+ __func__, ret);
701
+ wait_for_completion(&fcport->nvme_del_done);
640702 }
641703
642704 void qla_nvme_delete(struct scsi_qla_host *vha)
643705 {
644
- struct qla_nvme_rport *qla_rport, *trport;
645
- fc_port_t *fcport;
646706 int nv_ret;
647707
648708 if (!IS_ENABLED(CONFIG_NVME_FC))
649709 return;
650
-
651
- list_for_each_entry_safe(qla_rport, trport,
652
- &vha->nvme_rport_list, list) {
653
- fcport = qla_rport->fcport;
654
-
655
- ql_log(ql_log_info, fcport->vha, 0x2114, "%s: fcport=%p\n",
656
- __func__, fcport);
657
-
658
- nvme_fc_set_remoteport_devloss(fcport->nvme_remote_port, 0);
659
- }
660710
661711 if (vha->nvme_local_port) {
662712 init_completion(&vha->nvme_del_done);
....@@ -686,11 +736,10 @@
686736 tmpl = &qla_nvme_fc_transport;
687737
688738 WARN_ON(vha->nvme_local_port);
689
- WARN_ON(ha->max_req_queues < 3);
690739
691740 qla_nvme_fc_transport.max_hw_queues =
692741 min((uint8_t)(qla_nvme_fc_transport.max_hw_queues),
693
- (uint8_t)(ha->max_req_queues - 2));
742
+ (uint8_t)(ha->max_qpairs ? ha->max_qpairs : 1));
694743
695744 pinfo.node_name = wwn_to_u64(vha->node_name);
696745 pinfo.port_name = wwn_to_u64(vha->port_name);