hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/scsi/qedf/qedf_els.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * QLogic FCoE Offload Driver
34 * Copyright (c) 2016-2018 Cavium Inc.
4
- *
5
- * This software is available under the terms of the GNU General Public License
6
- * (GPL) Version 2, available from the file COPYING in the main directory of
7
- * this source tree.
85 */
96 #include "qedf.h"
107
....@@ -127,7 +124,7 @@
127124 task = qedf_get_task_mem(&qedf->tasks, xid);
128125 qedf_init_mp_task(els_req, task, sqe);
129126
130
- /* Put timer on original I/O request */
127
+ /* Put timer on els request */
131128 if (timer_msec)
132129 qedf_cmd_timer_set(qedf, els_req, timer_msec);
133130
....@@ -135,6 +132,8 @@
135132 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Ringing doorbell for ELS "
136133 "req\n");
137134 qedf_ring_doorbell(fcport);
135
+ set_bit(QEDF_CMD_OUTSTANDING, &els_req->flags);
136
+
138137 spin_unlock_irqrestore(&fcport->rport_lock, flags);
139138 els_err:
140139 return rc;
....@@ -143,20 +142,38 @@
143142 void qedf_process_els_compl(struct qedf_ctx *qedf, struct fcoe_cqe *cqe,
144143 struct qedf_ioreq *els_req)
145144 {
146
- struct fcoe_task_context *task_ctx;
147
- struct scsi_cmnd *sc_cmd;
148
- uint16_t xid;
149145 struct fcoe_cqe_midpath_info *mp_info;
146
+ struct qedf_rport *fcport;
150147
151148 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Entered with xid = 0x%x"
152149 " cmd_type = %d.\n", els_req->xid, els_req->cmd_type);
153150
151
+ if ((els_req->event == QEDF_IOREQ_EV_ELS_FLUSH)
152
+ || (els_req->event == QEDF_IOREQ_EV_CLEANUP_SUCCESS)
153
+ || (els_req->event == QEDF_IOREQ_EV_CLEANUP_FAILED)) {
154
+ QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO,
155
+ "ELS completion xid=0x%x after flush event=0x%x",
156
+ els_req->xid, els_req->event);
157
+ return;
158
+ }
159
+
160
+ fcport = els_req->fcport;
161
+
162
+ /* When flush is active,
163
+ * let the cmds be completed from the cleanup context
164
+ */
165
+ if (test_bit(QEDF_RPORT_IN_TARGET_RESET, &fcport->flags) ||
166
+ test_bit(QEDF_RPORT_IN_LUN_RESET, &fcport->flags)) {
167
+ QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_IO,
168
+ "Dropping ELS completion xid=0x%x as fcport is flushing",
169
+ els_req->xid);
170
+ return;
171
+ }
172
+
173
+ clear_bit(QEDF_CMD_OUTSTANDING, &els_req->flags);
174
+
154175 /* Kill the ELS timer */
155176 cancel_delayed_work(&els_req->timeout_work);
156
-
157
- xid = els_req->xid;
158
- task_ctx = qedf_get_task_mem(&qedf->tasks, xid);
159
- sc_cmd = els_req->sc_cmd;
160177
161178 /* Get ELS response length from CQE */
162179 mp_info = &cqe->cqe_info.midpath_info;
....@@ -185,20 +202,23 @@
185202
186203 orig_io_req = cb_arg->aborted_io_req;
187204
188
- if (!orig_io_req)
205
+ if (!orig_io_req) {
206
+ QEDF_ERR(&qedf->dbg_ctx,
207
+ "Original io_req is NULL, rrq_req = %p.\n", rrq_req);
189208 goto out_free;
190
-
191
- if (rrq_req->event != QEDF_IOREQ_EV_ELS_TMO &&
192
- rrq_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
193
- cancel_delayed_work_sync(&orig_io_req->timeout_work);
209
+ }
194210
195211 refcount = kref_read(&orig_io_req->refcount);
196212 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "rrq_compl: orig io = %p,"
197213 " orig xid = 0x%x, rrq_xid = 0x%x, refcount=%d\n",
198214 orig_io_req, orig_io_req->xid, rrq_req->xid, refcount);
199215
200
- /* This should return the aborted io_req to the command pool */
201
- if (orig_io_req)
216
+ /*
217
+ * This should return the aborted io_req to the command pool. Note that
218
+ * we need to check the refcound in case the original request was
219
+ * flushed but we get a completion on this xid.
220
+ */
221
+ if (orig_io_req && refcount > 0)
202222 kref_put(&orig_io_req->refcount, qedf_release_cmd);
203223
204224 out_free:
....@@ -225,6 +245,7 @@
225245 uint32_t sid;
226246 uint32_t r_a_tov;
227247 int rc;
248
+ int refcount;
228249
229250 if (!aborted_io_req) {
230251 QEDF_ERR(NULL, "abort_io_req is NULL.\n");
....@@ -232,6 +253,15 @@
232253 }
233254
234255 fcport = aborted_io_req->fcport;
256
+
257
+ if (!fcport) {
258
+ refcount = kref_read(&aborted_io_req->refcount);
259
+ QEDF_ERR(NULL,
260
+ "RRQ work was queued prior to a flush xid=0x%x, refcount=%d.\n",
261
+ aborted_io_req->xid, refcount);
262
+ kref_put(&aborted_io_req->refcount, qedf_release_cmd);
263
+ return -EINVAL;
264
+ }
235265
236266 /* Check that fcport is still offloaded */
237267 if (!test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags)) {
....@@ -245,6 +275,19 @@
245275 }
246276
247277 qedf = fcport->qedf;
278
+
279
+ /*
280
+ * Sanity check that we can send a RRQ to make sure that refcount isn't
281
+ * 0
282
+ */
283
+ refcount = kref_read(&aborted_io_req->refcount);
284
+ if (refcount != 1) {
285
+ QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_ELS,
286
+ "refcount for xid=%x io_req=%p refcount=%d is not 1.\n",
287
+ aborted_io_req->xid, aborted_io_req, refcount);
288
+ return -EINVAL;
289
+ }
290
+
248291 lport = qedf->lport;
249292 sid = fcport->sid;
250293 r_a_tov = lport->r_a_tov;
....@@ -327,32 +370,47 @@
327370 struct fc_lport *lport;
328371 struct fc_rport_priv *rdata;
329372 u32 port_id;
373
+ unsigned long flags;
330374
331
- if (!fcport)
375
+ if (!fcport) {
376
+ QEDF_ERR(NULL, "fcport is NULL.\n");
332377 return;
378
+ }
333379
380
+ spin_lock_irqsave(&fcport->rport_lock, flags);
334381 if (test_bit(QEDF_RPORT_IN_RESET, &fcport->flags) ||
335382 !test_bit(QEDF_RPORT_SESSION_READY, &fcport->flags) ||
336383 test_bit(QEDF_RPORT_UPLOADING_CONNECTION, &fcport->flags)) {
337384 QEDF_ERR(&(fcport->qedf->dbg_ctx), "fcport %p already in reset or not offloaded.\n",
338385 fcport);
386
+ spin_unlock_irqrestore(&fcport->rport_lock, flags);
339387 return;
340388 }
341389
342390 /* Set that we are now in reset */
343391 set_bit(QEDF_RPORT_IN_RESET, &fcport->flags);
392
+ spin_unlock_irqrestore(&fcport->rport_lock, flags);
344393
345394 rdata = fcport->rdata;
346
- if (rdata) {
395
+ if (rdata && !kref_get_unless_zero(&rdata->kref)) {
396
+ fcport->rdata = NULL;
397
+ rdata = NULL;
398
+ }
399
+
400
+ if (rdata && rdata->rp_state == RPORT_ST_READY) {
347401 lport = fcport->qedf->lport;
348402 port_id = rdata->ids.port_id;
349403 QEDF_ERR(&(fcport->qedf->dbg_ctx),
350404 "LOGO port_id=%x.\n", port_id);
351405 fc_rport_logoff(rdata);
406
+ kref_put(&rdata->kref, fc_rport_destroy);
407
+ mutex_lock(&lport->disc.disc_mutex);
352408 /* Recreate the rport and log back in */
353409 rdata = fc_rport_create(lport, port_id);
410
+ mutex_unlock(&lport->disc.disc_mutex);
354411 if (rdata)
355412 fc_rport_login(rdata);
413
+ fcport->rdata = rdata;
356414 }
357415 clear_bit(QEDF_RPORT_IN_RESET, &fcport->flags);
358416 }
....@@ -380,8 +438,11 @@
380438 * If we are flushing the command just free the cb_arg as none of the
381439 * response data will be valid.
382440 */
383
- if (els_req->event == QEDF_IOREQ_EV_ELS_FLUSH)
441
+ if (els_req->event == QEDF_IOREQ_EV_ELS_FLUSH) {
442
+ QEDF_ERR(NULL, "els_req xid=0x%x event is flush.\n",
443
+ els_req->xid);
384444 goto free_arg;
445
+ }
385446
386447 fcport = els_req->fcport;
387448 mp_req = &(els_req->mp_req);
....@@ -494,8 +555,10 @@
494555
495556 orig_io_req = cb_arg->aborted_io_req;
496557
497
- if (!orig_io_req)
558
+ if (!orig_io_req) {
559
+ QEDF_ERR(NULL, "orig_io_req is NULL.\n");
498560 goto out_free;
561
+ }
499562
500563 clear_bit(QEDF_CMD_SRR_SENT, &orig_io_req->flags);
501564
....@@ -509,8 +572,11 @@
509572 orig_io_req, orig_io_req->xid, srr_req->xid, refcount);
510573
511574 /* If a SRR times out, simply free resources */
512
- if (srr_req->event == QEDF_IOREQ_EV_ELS_TMO)
575
+ if (srr_req->event == QEDF_IOREQ_EV_ELS_TMO) {
576
+ QEDF_ERR(&qedf->dbg_ctx,
577
+ "ELS timeout rec_xid=0x%x.\n", srr_req->xid);
513578 goto out_put;
579
+ }
514580
515581 /* Normalize response data into struct fc_frame */
516582 mp_req = &(srr_req->mp_req);
....@@ -561,7 +627,7 @@
561627 struct qedf_rport *fcport;
562628 struct fc_lport *lport;
563629 struct qedf_els_cb_arg *cb_arg = NULL;
564
- u32 sid, r_a_tov;
630
+ u32 r_a_tov;
565631 int rc;
566632
567633 if (!orig_io_req) {
....@@ -587,7 +653,6 @@
587653
588654 qedf = fcport->qedf;
589655 lport = qedf->lport;
590
- sid = fcport->sid;
591656 r_a_tov = lport->r_a_tov;
592657
593658 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS, "Sending SRR orig_io=%p, "
....@@ -684,8 +749,11 @@
684749 cb_arg = io_req->cb_arg;
685750
686751 /* If we timed out just free resources */
687
- if (io_req->event == QEDF_IOREQ_EV_ELS_TMO || !cqe)
752
+ if (io_req->event == QEDF_IOREQ_EV_ELS_TMO || !cqe) {
753
+ QEDF_ERR(&qedf->dbg_ctx,
754
+ "cqe is NULL or timeout event (0x%x)", io_req->event);
688755 goto free;
756
+ }
689757
690758 /* Kill the timer we put on the request */
691759 cancel_delayed_work_sync(&io_req->timeout_work);
....@@ -788,8 +856,10 @@
788856
789857 orig_io_req = cb_arg->aborted_io_req;
790858
791
- if (!orig_io_req)
859
+ if (!orig_io_req) {
860
+ QEDF_ERR(NULL, "orig_io_req is NULL.\n");
792861 goto out_free;
862
+ }
793863
794864 if (rec_req->event != QEDF_IOREQ_EV_ELS_TMO &&
795865 rec_req->event != QEDF_IOREQ_EV_ELS_ERR_DETECT)
....@@ -801,8 +871,12 @@
801871 orig_io_req, orig_io_req->xid, rec_req->xid, refcount);
802872
803873 /* If a REC times out, free resources */
804
- if (rec_req->event == QEDF_IOREQ_EV_ELS_TMO)
874
+ if (rec_req->event == QEDF_IOREQ_EV_ELS_TMO) {
875
+ QEDF_ERR(&qedf->dbg_ctx,
876
+ "Got TMO event, orig_io_req %p orig_io_xid=0x%x.\n",
877
+ orig_io_req, orig_io_req->xid);
805878 goto out_put;
879
+ }
806880
807881 /* Normalize response data into struct fc_frame */
808882 mp_req = &(rec_req->mp_req);
....@@ -828,6 +902,11 @@
828902 opcode = fc_frame_payload_op(fp);
829903 if (opcode == ELS_LS_RJT) {
830904 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
905
+ if (!rjt) {
906
+ QEDF_ERR(&qedf->dbg_ctx, "payload get failed");
907
+ goto out_free_frame;
908
+ }
909
+
831910 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_ELS,
832911 "Received LS_RJT for REC: er_reason=0x%x, "
833912 "er_explan=0x%x.\n", rjt->er_reason, rjt->er_explan);