Skip to content

Commit 78e8847

Browse files
Saurav Kashyapmartinkpetersen
authored andcommitted
scsi: qedf: Wait for stag work during unload
If stag work is already scheduled and unload is called, it can lead to issues as unload cleans up the work element. Wait for stag work to get completed before cleanup during unload. Signed-off-by: Saurav Kashyap <[email protected]> Signed-off-by: Nilesh Javali <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 51071f0 commit 78e8847

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

drivers/scsi/qedf/qedf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ struct qedf_ctx {
363363
#define QEDF_IN_RECOVERY 5
364364
#define QEDF_DBG_STOP_IO 6
365365
#define QEDF_PROBING 8
366+
#define QEDF_STAG_IN_PROGRESS 9
366367
unsigned long flags; /* Miscellaneous state flags */
367368
int fipvlan_retries;
368369
u8 num_queues;

drivers/scsi/qedf/qedf_main.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,18 @@ static struct fc_seq *qedf_elsct_send(struct fc_lport *lport, u32 did,
318318
*/
319319
if (resp == fc_lport_flogi_resp) {
320320
qedf->flogi_cnt++;
321+
qedf->flogi_pending++;
322+
323+
if (test_bit(QEDF_UNLOADING, &qedf->flags)) {
324+
QEDF_ERR(&qedf->dbg_ctx, "Driver unloading\n");
325+
qedf->flogi_pending = 0;
326+
}
327+
321328
if (qedf->flogi_pending >= QEDF_FLOGI_RETRY_CNT) {
322329
schedule_delayed_work(&qedf->stag_work, 2);
323330
return NULL;
324331
}
325-
qedf->flogi_pending++;
332+
326333
return fc_elsct_send(lport, did, fp, op, qedf_flogi_resp,
327334
arg, timeout);
328335
}
@@ -912,13 +919,14 @@ void qedf_ctx_soft_reset(struct fc_lport *lport)
912919
struct qedf_ctx *qedf;
913920
struct qed_link_output if_link;
914921

922+
qedf = lport_priv(lport);
923+
915924
if (lport->vport) {
925+
clear_bit(QEDF_STAG_IN_PROGRESS, &qedf->flags);
916926
printk_ratelimited("Cannot issue host reset on NPIV port.\n");
917927
return;
918928
}
919929

920-
qedf = lport_priv(lport);
921-
922930
qedf->flogi_pending = 0;
923931
/* For host reset, essentially do a soft link up/down */
924932
atomic_set(&qedf->link_state, QEDF_LINK_DOWN);
@@ -938,6 +946,7 @@ void qedf_ctx_soft_reset(struct fc_lport *lport)
938946
if (!if_link.link_up) {
939947
QEDF_INFO(&qedf->dbg_ctx, QEDF_LOG_DISC,
940948
"Physical link is not up.\n");
949+
clear_bit(QEDF_STAG_IN_PROGRESS, &qedf->flags);
941950
return;
942951
}
943952
/* Flush and wait to make sure link down is processed */
@@ -950,6 +959,7 @@ void qedf_ctx_soft_reset(struct fc_lport *lport)
950959
"Queue link up work.\n");
951960
queue_delayed_work(qedf->link_update_wq, &qedf->link_update,
952961
0);
962+
clear_bit(QEDF_STAG_IN_PROGRESS, &qedf->flags);
953963
}
954964

955965
/* Reset the host by gracefully logging out and then logging back in */
@@ -3721,6 +3731,7 @@ static void __qedf_remove(struct pci_dev *pdev, int mode)
37213731
{
37223732
struct qedf_ctx *qedf;
37233733
int rc;
3734+
int cnt = 0;
37243735

37253736
if (!pdev) {
37263737
QEDF_ERR(NULL, "pdev is NULL.\n");
@@ -3738,6 +3749,17 @@ static void __qedf_remove(struct pci_dev *pdev, int mode)
37383749
return;
37393750
}
37403751

3752+
stag_in_prog:
3753+
if (test_bit(QEDF_STAG_IN_PROGRESS, &qedf->flags)) {
3754+
QEDF_ERR(&qedf->dbg_ctx, "Stag in progress, cnt=%d.\n", cnt);
3755+
cnt++;
3756+
3757+
if (cnt < 5) {
3758+
msleep(500);
3759+
goto stag_in_prog;
3760+
}
3761+
}
3762+
37413763
if (mode != QEDF_MODE_RECOVERY)
37423764
set_bit(QEDF_UNLOADING, &qedf->flags);
37433765

@@ -4013,6 +4035,8 @@ void qedf_stag_change_work(struct work_struct *work)
40134035
return;
40144036
}
40154037

4038+
set_bit(QEDF_STAG_IN_PROGRESS, &qedf->flags);
4039+
40164040
printk_ratelimited("[%s]:[%s:%d]:%d: Performing software context reset.",
40174041
dev_name(&qedf->pdev->dev), __func__, __LINE__,
40184042
qedf->dbg_ctx.host_no);

0 commit comments

Comments
 (0)