Skip to content

Commit e39811b

Browse files
Justin Teemartinkpetersen
authored andcommitted
scsi: lpfc: Change lpfc_vport load_flag member into a bitmask
In attempt to reduce the amount of unnecessary shost_lock acquisitions in the lpfc driver, change load_flag into an unsigned long bitmask and use clear_bit/test_bit bitwise atomic APIs instead of reliance on shost_lock for synchronization. Also, correct the test for FC_UNLOADING in lpfc_ct_handle_mibreq, which incorrectly tests vport->fc_flag rather than vport->load_flag. Signed-off-by: Justin Tee <justin.tee@broadcom.com> Link: https://lore.kernel.org/r/20240131185112.149731-16-justintee8345@gmail.com Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent a645b8c commit e39811b

File tree

10 files changed

+108
-120
lines changed

10 files changed

+108
-120
lines changed

drivers/scsi/lpfc/lpfc.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ enum lpfc_fc_flag {
565565
FC_DISC_DELAYED, /* Delay NPort discovery */
566566
};
567567

568+
enum lpfc_load_flag {
569+
FC_LOADING, /* HBA in process of loading drvr */
570+
FC_UNLOADING, /* HBA in process of unloading drvr */
571+
FC_ALLOW_FDMI, /* port is ready for FDMI requests */
572+
FC_ALLOW_VMID, /* Allow VMID I/Os */
573+
FC_DEREGISTER_ALL_APP_ID /* Deregister all VMIDs */
574+
};
575+
568576
struct lpfc_vport {
569577
struct lpfc_hba *phba;
570578
struct list_head listentry;
@@ -647,12 +655,7 @@ struct lpfc_vport {
647655
struct timer_list els_tmofunc;
648656
struct timer_list delayed_disc_tmo;
649657

650-
uint8_t load_flag;
651-
#define FC_LOADING 0x1 /* HBA in process of loading drvr */
652-
#define FC_UNLOADING 0x2 /* HBA in process of unloading drvr */
653-
#define FC_ALLOW_FDMI 0x4 /* port is ready for FDMI requests */
654-
#define FC_ALLOW_VMID 0x8 /* Allow VMID I/Os */
655-
#define FC_DEREGISTER_ALL_APP_ID 0x10 /* Deregister all VMIDs */
658+
unsigned long load_flag;
656659
/* Vport Config Parameters */
657660
uint32_t cfg_scan_down;
658661
uint32_t cfg_lun_queue_depth;

drivers/scsi/lpfc/lpfc_ct.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ lpfc_ct_handle_mibreq(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocbq)
298298
}
299299

300300
/* Ignore traffic received during vport shutdown */
301-
if (test_bit(FC_UNLOADING, &vport->fc_flag))
301+
if (test_bit(FC_UNLOADING, &vport->load_flag))
302302
return;
303303

304304
ndlp = lpfc_findnode_did(vport, did);
@@ -943,7 +943,7 @@ lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
943943
}
944944

945945
/* Skip processing response on pport if unloading */
946-
if (vport == phba->pport && vport->load_flag & FC_UNLOADING) {
946+
if (vport == phba->pport && test_bit(FC_UNLOADING, &vport->load_flag)) {
947947
if (test_bit(FC_RSCN_MODE, &vport->fc_flag))
948948
lpfc_els_flush_rscn(vport);
949949
goto out;
@@ -1159,7 +1159,7 @@ lpfc_cmpl_ct_cmd_gid_pt(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11591159
}
11601160

11611161
/* Skip processing response on pport if unloading */
1162-
if (vport == phba->pport && vport->load_flag & FC_UNLOADING) {
1162+
if (vport == phba->pport && test_bit(FC_UNLOADING, &vport->load_flag)) {
11631163
if (test_bit(FC_RSCN_MODE, &vport->fc_flag))
11641164
lpfc_els_flush_rscn(vport);
11651165
goto out;
@@ -3583,7 +3583,8 @@ lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
35833583
(ctrsp->Explanation != SLI_CT_APP_ID_NOT_AVAILABLE)) {
35843584
/* If DALLAPP_ID failed retry later */
35853585
if (cmd == SLI_CTAS_DALLAPP_ID)
3586-
vport->load_flag |= FC_DEREGISTER_ALL_APP_ID;
3586+
set_bit(FC_DEREGISTER_ALL_APP_ID,
3587+
&vport->load_flag);
35873588
goto free_res;
35883589
}
35893590
}
@@ -3639,7 +3640,7 @@ lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
36393640
if (!hash_empty(vport->hash_table))
36403641
hash_for_each(vport->hash_table, bucket, cur, hnode)
36413642
hash_del(&cur->hnode);
3642-
vport->load_flag |= FC_ALLOW_VMID;
3643+
set_bit(FC_ALLOW_VMID, &vport->load_flag);
36433644
break;
36443645
default:
36453646
lpfc_printf_vlog(vport, KERN_DEBUG, LOG_DISCOVERY,

drivers/scsi/lpfc/lpfc_els.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4964,7 +4964,7 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
49644964
retry = 0;
49654965
}
49664966

4967-
if ((vport->load_flag & FC_UNLOADING) != 0)
4967+
if (test_bit(FC_UNLOADING, &vport->load_flag))
49684968
retry = 0;
49694969

49704970
out_retry:
@@ -8232,7 +8232,7 @@ lpfc_els_handle_rscn(struct lpfc_vport *vport)
82328232
struct lpfc_hba *phba = vport->phba;
82338233

82348234
/* Ignore RSCN if the port is being torn down. */
8235-
if (vport->load_flag & FC_UNLOADING) {
8235+
if (test_bit(FC_UNLOADING, &vport->load_flag)) {
82368236
lpfc_els_flush_rscn(vport);
82378237
return 0;
82388238
}
@@ -9449,11 +9449,11 @@ lpfc_els_timeout(struct timer_list *t)
94499449

94509450
spin_lock_irqsave(&vport->work_port_lock, iflag);
94519451
tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
9452-
if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
9452+
if (!tmo_posted && !test_bit(FC_UNLOADING, &vport->load_flag))
94539453
vport->work_port_events |= WORKER_ELS_TMO;
94549454
spin_unlock_irqrestore(&vport->work_port_lock, iflag);
94559455

9456-
if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
9456+
if (!tmo_posted && !test_bit(FC_UNLOADING, &vport->load_flag))
94579457
lpfc_worker_wake_up(phba);
94589458
return;
94599459
}
@@ -9489,7 +9489,7 @@ lpfc_els_timeout_handler(struct lpfc_vport *vport)
94899489
if (unlikely(!pring))
94909490
return;
94919491

9492-
if (phba->pport->load_flag & FC_UNLOADING)
9492+
if (test_bit(FC_UNLOADING, &phba->pport->load_flag))
94939493
return;
94949494

94959495
spin_lock_irq(&phba->hbalock);
@@ -9565,7 +9565,7 @@ lpfc_els_timeout_handler(struct lpfc_vport *vport)
95659565
lpfc_issue_hb_tmo(phba);
95669566

95679567
if (!list_empty(&pring->txcmplq))
9568-
if (!(phba->pport->load_flag & FC_UNLOADING))
9568+
if (!test_bit(FC_UNLOADING, &phba->pport->load_flag))
95699569
mod_timer(&vport->els_tmofunc,
95709570
jiffies + msecs_to_jiffies(1000 * timeout));
95719571
}
@@ -10364,7 +10364,7 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1036410364
goto dropit;
1036510365

1036610366
/* Ignore traffic received during vport shutdown. */
10367-
if (vport->load_flag & FC_UNLOADING)
10367+
if (test_bit(FC_UNLOADING, &vport->load_flag))
1036810368
goto dropit;
1036910369

1037010370
/* If NPort discovery is delayed drop incoming ELS */
@@ -10785,7 +10785,7 @@ lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1078510785
return;
1078610786

1078710787
dropit:
10788-
if (vport && !(vport->load_flag & FC_UNLOADING))
10788+
if (vport && !test_bit(FC_UNLOADING, &vport->load_flag))
1078910789
lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1079010790
"0111 Dropping received ELS cmd "
1079110791
"Data: x%x x%x x%x x%x\n",
@@ -10981,8 +10981,8 @@ lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
1098110981
}
1098210982

1098310983
if ((phba->cfg_enable_SmartSAN ||
10984-
(phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
10985-
(vport->load_flag & FC_ALLOW_FDMI))
10984+
phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT) &&
10985+
test_bit(FC_ALLOW_FDMI, &vport->load_flag))
1098610986
lpfc_start_fdmi(vport);
1098710987
}
1098810988

@@ -12014,7 +12014,7 @@ lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
1201412014
* node and the vport is unloading, the xri aborted wcqe
1201512015
* likely isn't coming back. Just release the sgl.
1201612016
*/
12017-
if ((vport->load_flag & FC_UNLOADING) &&
12017+
if (test_bit(FC_UNLOADING, &vport->load_flag) &&
1201812018
ndlp->nlp_DID == Fabric_DID) {
1201912019
list_del(&sglq_entry->list);
1202012020
sglq_entry->state = SGL_FREED;

drivers/scsi/lpfc/lpfc_hbadisc.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
169169

170170
lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
171171
"3181 dev_loss_callbk x%06x, rport x%px flg x%x "
172-
"load_flag x%x refcnt %u state %d xpt x%x\n",
172+
"load_flag x%lx refcnt %u state %d xpt x%x\n",
173173
ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag,
174174
vport->load_flag, kref_read(&ndlp->kref),
175175
ndlp->nlp_state, ndlp->fc4_xpt_flags);
176176

177177
/* Don't schedule a worker thread event if the vport is going down. */
178-
if (vport->load_flag & FC_UNLOADING) {
178+
if (test_bit(FC_UNLOADING, &vport->load_flag)) {
179179
spin_lock_irqsave(&ndlp->lock, iflags);
180180
ndlp->rport = NULL;
181181

@@ -263,7 +263,7 @@ lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
263263
} else {
264264
lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
265265
"3188 worker thread is stopped %s x%06x, "
266-
" rport x%px flg x%x load_flag x%x refcnt "
266+
" rport x%px flg x%x load_flag x%lx refcnt "
267267
"%d\n", __func__, ndlp->nlp_DID,
268268
ndlp->rport, ndlp->nlp_flag,
269269
vport->load_flag, kref_read(&ndlp->kref));
@@ -911,7 +911,7 @@ lpfc_work_list_done(struct lpfc_hba *phba)
911911
free_evt = 0;
912912
break;
913913
case LPFC_EVT_RESET_HBA:
914-
if (!(phba->pport->load_flag & FC_UNLOADING))
914+
if (!test_bit(FC_UNLOADING, &phba->pport->load_flag))
915915
lpfc_reset_hba(phba);
916916
break;
917917
}
@@ -1358,7 +1358,7 @@ lpfc_linkup_port(struct lpfc_vport *vport)
13581358
struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
13591359
struct lpfc_hba *phba = vport->phba;
13601360

1361-
if ((vport->load_flag & FC_UNLOADING) != 0)
1361+
if (test_bit(FC_UNLOADING, &vport->load_flag))
13621362
return;
13631363

13641364
lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
@@ -3924,7 +3924,7 @@ lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
39243924
lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
39253925
"2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
39263926
vport->vpi, mb->mbxStatus);
3927-
if (!(phba->pport->load_flag & FC_UNLOADING))
3927+
if (!test_bit(FC_UNLOADING, &phba->pport->load_flag))
39283928
lpfc_workq_post_event(phba, NULL, NULL,
39293929
LPFC_EVT_RESET_HBA);
39303930
}
@@ -3939,7 +3939,7 @@ lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
39393939
* This shost reference might have been taken at the beginning of
39403940
* lpfc_vport_delete()
39413941
*/
3942-
if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3942+
if (test_bit(FC_UNLOADING, &vport->load_flag) && vport != phba->pport)
39433943
scsi_host_put(shost);
39443944
}
39453945

@@ -4490,7 +4490,7 @@ lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
44904490
ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
44914491

44924492
/* Don't add the remote port if unloading. */
4493-
if (vport->load_flag & FC_UNLOADING)
4493+
if (test_bit(FC_UNLOADING, &vport->load_flag))
44944494
return;
44954495

44964496
ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
@@ -5235,13 +5235,13 @@ lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
52355235
mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
52365236

52375237
} else if (phba->sli_rev == LPFC_SLI_REV4 &&
5238-
(!(vport->load_flag & FC_UNLOADING)) &&
5238+
!test_bit(FC_UNLOADING, &vport->load_flag) &&
52395239
(bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
52405240
LPFC_SLI_INTF_IF_TYPE_2) &&
52415241
(kref_read(&ndlp->kref) > 0)) {
52425242
mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
52435243
} else {
5244-
if (vport->load_flag & FC_UNLOADING) {
5244+
if (test_bit(FC_UNLOADING, &vport->load_flag)) {
52455245
if (phba->sli_rev == LPFC_SLI_REV4) {
52465246
spin_lock_irqsave(&ndlp->lock, iflags);
52475247
ndlp->nlp_flag |= NLP_RELEASE_RPI;
@@ -5349,7 +5349,7 @@ lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
53495349
* will issue a LOGO here and keep the rpi alive if
53505350
* not unloading.
53515351
*/
5352-
if (!(vport->load_flag & FC_UNLOADING)) {
5352+
if (!test_bit(FC_UNLOADING, &vport->load_flag)) {
53535353
ndlp->nlp_flag &= ~NLP_UNREG_INP;
53545354
lpfc_issue_els_logo(vport, ndlp, 0);
53555355
ndlp->nlp_prev_state = ndlp->nlp_state;
@@ -6925,8 +6925,8 @@ lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
69256925
* If driver is not unloading, check if there is any other
69266926
* FCF record that can be used for discovery.
69276927
*/
6928-
if ((phba->pport->load_flag & FC_UNLOADING) ||
6929-
(phba->link_state < LPFC_LINK_UP))
6928+
if (test_bit(FC_UNLOADING, &phba->pport->load_flag) ||
6929+
phba->link_state < LPFC_LINK_UP)
69306930
return;
69316931

69326932
/* This is considered as the initial FCF discovery scan */

0 commit comments

Comments
 (0)