Skip to content

Commit 0dfd9cb

Browse files
Justin Teemartinkpetersen
authored andcommitted
scsi: lpfc: Change nlp state statistic counters into atomic_t
There is no reason to use the shost_lock to synchronize an LLDD statistics counter. Convert all the nlp state statistic counters into atomic_t. Corresponding zeroing, increments, and reads are converted to atomic versions. Signed-off-by: Justin Tee <justin.tee@broadcom.com> Link: https://lore.kernel.org/r/20240131185112.149731-13-justintee8345@gmail.com Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 4be4ad6 commit 0dfd9cb

File tree

5 files changed

+50
-37
lines changed

5 files changed

+50
-37
lines changed

drivers/scsi/lpfc/lpfc.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,15 @@ struct lpfc_vport {
589589
struct list_head fc_nodes;
590590

591591
/* Keep counters for the number of entries in each list. */
592-
uint16_t fc_plogi_cnt;
593-
uint16_t fc_adisc_cnt;
594-
uint16_t fc_reglogin_cnt;
595-
uint16_t fc_prli_cnt;
596-
uint16_t fc_unmap_cnt;
597-
uint16_t fc_map_cnt;
598-
uint16_t fc_npr_cnt;
599-
uint16_t fc_unused_cnt;
592+
atomic_t fc_plogi_cnt;
593+
atomic_t fc_adisc_cnt;
594+
atomic_t fc_reglogin_cnt;
595+
atomic_t fc_prli_cnt;
596+
atomic_t fc_unmap_cnt;
597+
atomic_t fc_map_cnt;
598+
atomic_t fc_npr_cnt;
599+
atomic_t fc_unused_cnt;
600+
600601
struct serv_parm fc_sparam; /* buffer for our service parameters */
601602

602603
uint32_t fc_myDID; /* fibre channel S_ID */

drivers/scsi/lpfc/lpfc_attr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,8 @@ lpfc_num_discovered_ports_show(struct device *dev,
12601260
struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
12611261

12621262
return scnprintf(buf, PAGE_SIZE, "%d\n",
1263-
vport->fc_map_cnt + vport->fc_unmap_cnt);
1263+
atomic_read(&vport->fc_map_cnt) +
1264+
atomic_read(&vport->fc_unmap_cnt));
12641265
}
12651266

12661267
/**

drivers/scsi/lpfc/lpfc_els.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,8 @@ lpfc_more_plogi(struct lpfc_vport *vport)
16461646
lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
16471647
"0232 Continue discovery with %d PLOGIs to go "
16481648
"Data: x%x x%x x%x\n",
1649-
vport->num_disc_nodes, vport->fc_plogi_cnt,
1649+
vport->num_disc_nodes,
1650+
atomic_read(&vport->fc_plogi_cnt),
16501651
vport->fc_flag, vport->port_state);
16511652
/* Check to see if there are more PLOGIs to be sent */
16521653
if (vport->fc_flag & FC_NLP_MORE)
@@ -2692,7 +2693,7 @@ lpfc_rscn_disc(struct lpfc_vport *vport)
26922693

26932694
/* RSCN discovery */
26942695
/* go thru NPR nodes and issue ELS PLOGIs */
2695-
if (vport->fc_npr_cnt)
2696+
if (atomic_read(&vport->fc_npr_cnt))
26962697
if (lpfc_els_disc_plogi(vport))
26972698
return;
26982699

@@ -2752,7 +2753,7 @@ lpfc_adisc_done(struct lpfc_vport *vport)
27522753
if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
27532754
vport->num_disc_nodes = 0;
27542755
/* go thru NPR list, issue ELS PLOGIs */
2755-
if (vport->fc_npr_cnt)
2756+
if (atomic_read(&vport->fc_npr_cnt))
27562757
lpfc_els_disc_plogi(vport);
27572758
if (!vport->num_disc_nodes) {
27582759
spin_lock_irq(shost->host_lock);
@@ -2785,7 +2786,8 @@ lpfc_more_adisc(struct lpfc_vport *vport)
27852786
lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
27862787
"0210 Continue discovery with %d ADISCs to go "
27872788
"Data: x%x x%x x%x\n",
2788-
vport->num_disc_nodes, vport->fc_adisc_cnt,
2789+
vport->num_disc_nodes,
2790+
atomic_read(&vport->fc_adisc_cnt),
27892791
vport->fc_flag, vport->port_state);
27902792
/* Check to see if there are more ADISCs to be sent */
27912793
if (vport->fc_flag & FC_NLP_MORE) {

drivers/scsi/lpfc/lpfc_hbadisc.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4023,7 +4023,7 @@ lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
40234023
spin_unlock_irq(shost->host_lock);
40244024
vport->num_disc_nodes = 0;
40254025
/* go thru NPR list and issue ELS PLOGIs */
4026-
if (vport->fc_npr_cnt)
4026+
if (atomic_read(&vport->fc_npr_cnt))
40274027
lpfc_els_disc_plogi(vport);
40284028

40294029
if (!vport->num_disc_nodes) {
@@ -4600,40 +4600,35 @@ lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
46004600
static void
46014601
lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
46024602
{
4603-
struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4604-
unsigned long iflags;
4605-
4606-
spin_lock_irqsave(shost->host_lock, iflags);
46074603
switch (state) {
46084604
case NLP_STE_UNUSED_NODE:
4609-
vport->fc_unused_cnt += count;
4605+
atomic_add(count, &vport->fc_unused_cnt);
46104606
break;
46114607
case NLP_STE_PLOGI_ISSUE:
4612-
vport->fc_plogi_cnt += count;
4608+
atomic_add(count, &vport->fc_plogi_cnt);
46134609
break;
46144610
case NLP_STE_ADISC_ISSUE:
4615-
vport->fc_adisc_cnt += count;
4611+
atomic_add(count, &vport->fc_adisc_cnt);
46164612
break;
46174613
case NLP_STE_REG_LOGIN_ISSUE:
4618-
vport->fc_reglogin_cnt += count;
4614+
atomic_add(count, &vport->fc_reglogin_cnt);
46194615
break;
46204616
case NLP_STE_PRLI_ISSUE:
4621-
vport->fc_prli_cnt += count;
4617+
atomic_add(count, &vport->fc_prli_cnt);
46224618
break;
46234619
case NLP_STE_UNMAPPED_NODE:
4624-
vport->fc_unmap_cnt += count;
4620+
atomic_add(count, &vport->fc_unmap_cnt);
46254621
break;
46264622
case NLP_STE_MAPPED_NODE:
4627-
vport->fc_map_cnt += count;
4623+
atomic_add(count, &vport->fc_map_cnt);
46284624
break;
46294625
case NLP_STE_NPR_NODE:
4630-
if (vport->fc_npr_cnt == 0 && count == -1)
4631-
vport->fc_npr_cnt = 0;
4626+
if (!atomic_read(&vport->fc_npr_cnt) && count == -1)
4627+
atomic_set(&vport->fc_npr_cnt, 0);
46324628
else
4633-
vport->fc_npr_cnt += count;
4629+
atomic_add(count, &vport->fc_npr_cnt);
46344630
break;
46354631
}
4636-
spin_unlock_irqrestore(shost->host_lock, iflags);
46374632
}
46384633

46394634
/* Register a node with backend if not already done */
@@ -5034,8 +5029,9 @@ lpfc_set_disctmo(struct lpfc_vport *vport)
50345029
"0247 Start Discovery Timer state x%x "
50355030
"Data: x%x x%lx x%x x%x\n",
50365031
vport->port_state, tmo,
5037-
(unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
5038-
vport->fc_adisc_cnt);
5032+
(unsigned long)&vport->fc_disctmo,
5033+
atomic_read(&vport->fc_plogi_cnt),
5034+
atomic_read(&vport->fc_adisc_cnt));
50395035

50405036
return;
50415037
}
@@ -5070,7 +5066,8 @@ lpfc_can_disctmo(struct lpfc_vport *vport)
50705066
"0248 Cancel Discovery Timer state x%x "
50715067
"Data: x%x x%x x%x\n",
50725068
vport->port_state, vport->fc_flag,
5073-
vport->fc_plogi_cnt, vport->fc_adisc_cnt);
5069+
atomic_read(&vport->fc_plogi_cnt),
5070+
atomic_read(&vport->fc_adisc_cnt));
50745071
return 0;
50755072
}
50765073

@@ -5951,8 +5948,10 @@ lpfc_disc_start(struct lpfc_vport *vport)
59515948
lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
59525949
"0202 Start Discovery port state x%x "
59535950
"flg x%x Data: x%x x%x x%x\n",
5954-
vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5955-
vport->fc_adisc_cnt, vport->fc_npr_cnt);
5951+
vport->port_state, vport->fc_flag,
5952+
atomic_read(&vport->fc_plogi_cnt),
5953+
atomic_read(&vport->fc_adisc_cnt),
5954+
atomic_read(&vport->fc_npr_cnt));
59565955

59575956
/* First do ADISCs - if any */
59585957
num_sent = lpfc_els_disc_adisc(vport);
@@ -5981,7 +5980,7 @@ lpfc_disc_start(struct lpfc_vport *vport)
59815980
if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
59825981
vport->num_disc_nodes = 0;
59835982
/* go thru NPR nodes and issue ELS PLOGIs */
5984-
if (vport->fc_npr_cnt)
5983+
if (atomic_read(&vport->fc_npr_cnt))
59855984
lpfc_els_disc_plogi(vport);
59865985

59875986
if (!vport->num_disc_nodes) {
@@ -6077,7 +6076,8 @@ lpfc_disc_flush_list(struct lpfc_vport *vport)
60776076
struct lpfc_nodelist *ndlp, *next_ndlp;
60786077
struct lpfc_hba *phba = vport->phba;
60796078

6080-
if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
6079+
if (atomic_read(&vport->fc_plogi_cnt) ||
6080+
atomic_read(&vport->fc_adisc_cnt)) {
60816081
list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
60826082
nlp_listp) {
60836083
if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||

drivers/scsi/lpfc/lpfc_init.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4770,6 +4770,14 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
47704770
vport->load_flag |= FC_LOADING;
47714771
vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
47724772
vport->fc_rscn_flush = 0;
4773+
atomic_set(&vport->fc_plogi_cnt, 0);
4774+
atomic_set(&vport->fc_adisc_cnt, 0);
4775+
atomic_set(&vport->fc_reglogin_cnt, 0);
4776+
atomic_set(&vport->fc_prli_cnt, 0);
4777+
atomic_set(&vport->fc_unmap_cnt, 0);
4778+
atomic_set(&vport->fc_map_cnt, 0);
4779+
atomic_set(&vport->fc_npr_cnt, 0);
4780+
atomic_set(&vport->fc_unused_cnt, 0);
47734781
lpfc_get_vport_cfgparam(vport);
47744782

47754783
/* Adjust value in vport */
@@ -4946,7 +4954,8 @@ int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
49464954
goto finished;
49474955
if (vport->num_disc_nodes || vport->fc_prli_sent)
49484956
goto finished;
4949-
if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
4957+
if (!atomic_read(&vport->fc_map_cnt) &&
4958+
time < msecs_to_jiffies(2 * 1000))
49504959
goto finished;
49514960
if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
49524961
goto finished;

0 commit comments

Comments
 (0)