scsi: lpfc: Change nlp state statistic counters into atomic_t
authorJustin Tee <justin.tee@broadcom.com>
Wed, 31 Jan 2024 18:51:07 +0000 (10:51 -0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 6 Feb 2024 01:51:35 +0000 (20:51 -0500)
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>
drivers/scsi/lpfc/lpfc.h
drivers/scsi/lpfc/lpfc_attr.c
drivers/scsi/lpfc/lpfc_els.c
drivers/scsi/lpfc/lpfc_hbadisc.c
drivers/scsi/lpfc/lpfc_init.c

index 04d608ea91060ba32cba525323ccd30be340bc6b..8f3cac09a381527c2addab473500348ee48cbac6 100644 (file)
@@ -589,14 +589,15 @@ struct lpfc_vport {
        struct list_head fc_nodes;
 
        /* Keep counters for the number of entries in each list. */
-       uint16_t fc_plogi_cnt;
-       uint16_t fc_adisc_cnt;
-       uint16_t fc_reglogin_cnt;
-       uint16_t fc_prli_cnt;
-       uint16_t fc_unmap_cnt;
-       uint16_t fc_map_cnt;
-       uint16_t fc_npr_cnt;
-       uint16_t fc_unused_cnt;
+       atomic_t fc_plogi_cnt;
+       atomic_t fc_adisc_cnt;
+       atomic_t fc_reglogin_cnt;
+       atomic_t fc_prli_cnt;
+       atomic_t fc_unmap_cnt;
+       atomic_t fc_map_cnt;
+       atomic_t fc_npr_cnt;
+       atomic_t fc_unused_cnt;
+
        struct serv_parm fc_sparam;     /* buffer for our service parameters */
 
        uint32_t fc_myDID;      /* fibre channel S_ID */
index 1f9a529e09ffd48b8c21fb8e2c8a97e8a283f328..142c90eb210f2bd4a02cf7ceedc37be7b4e61c0f 100644 (file)
@@ -1260,7 +1260,8 @@ lpfc_num_discovered_ports_show(struct device *dev,
        struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
 
        return scnprintf(buf, PAGE_SIZE, "%d\n",
-                       vport->fc_map_cnt + vport->fc_unmap_cnt);
+                        atomic_read(&vport->fc_map_cnt) +
+                        atomic_read(&vport->fc_unmap_cnt));
 }
 
 /**
index 1ada8ba6cc2a557e44fc9c602c22ad2ace727a1b..e01583e2690bd41ade83fff85f66393da0680dba 100644 (file)
@@ -1646,7 +1646,8 @@ lpfc_more_plogi(struct lpfc_vport *vport)
        lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
                         "0232 Continue discovery with %d PLOGIs to go "
                         "Data: x%x x%x x%x\n",
-                        vport->num_disc_nodes, vport->fc_plogi_cnt,
+                        vport->num_disc_nodes,
+                        atomic_read(&vport->fc_plogi_cnt),
                         vport->fc_flag, vport->port_state);
        /* Check to see if there are more PLOGIs to be sent */
        if (vport->fc_flag & FC_NLP_MORE)
@@ -2692,7 +2693,7 @@ lpfc_rscn_disc(struct lpfc_vport *vport)
 
        /* RSCN discovery */
        /* go thru NPR nodes and issue ELS PLOGIs */
-       if (vport->fc_npr_cnt)
+       if (atomic_read(&vport->fc_npr_cnt))
                if (lpfc_els_disc_plogi(vport))
                        return;
 
@@ -2752,7 +2753,7 @@ lpfc_adisc_done(struct lpfc_vport *vport)
                if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
                        vport->num_disc_nodes = 0;
                        /* go thru NPR list, issue ELS PLOGIs */
-                       if (vport->fc_npr_cnt)
+                       if (atomic_read(&vport->fc_npr_cnt))
                                lpfc_els_disc_plogi(vport);
                        if (!vport->num_disc_nodes) {
                                spin_lock_irq(shost->host_lock);
@@ -2785,7 +2786,8 @@ lpfc_more_adisc(struct lpfc_vport *vport)
        lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
                         "0210 Continue discovery with %d ADISCs to go "
                         "Data: x%x x%x x%x\n",
-                        vport->num_disc_nodes, vport->fc_adisc_cnt,
+                        vport->num_disc_nodes,
+                        atomic_read(&vport->fc_adisc_cnt),
                         vport->fc_flag, vport->port_state);
        /* Check to see if there are more ADISCs to be sent */
        if (vport->fc_flag & FC_NLP_MORE) {
index 35ea67431239c71c723e02ecdebdcff5965c53c9..7c4356d8773087de80a021df03709fd011ba31ee 100644 (file)
@@ -4023,7 +4023,7 @@ lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
        spin_unlock_irq(shost->host_lock);
        vport->num_disc_nodes = 0;
        /* go thru NPR list and issue ELS PLOGIs */
-       if (vport->fc_npr_cnt)
+       if (atomic_read(&vport->fc_npr_cnt))
                lpfc_els_disc_plogi(vport);
 
        if (!vport->num_disc_nodes) {
@@ -4600,40 +4600,35 @@ lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
 static void
 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
 {
-       struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
-       unsigned long iflags;
-
-       spin_lock_irqsave(shost->host_lock, iflags);
        switch (state) {
        case NLP_STE_UNUSED_NODE:
-               vport->fc_unused_cnt += count;
+               atomic_add(count, &vport->fc_unused_cnt);
                break;
        case NLP_STE_PLOGI_ISSUE:
-               vport->fc_plogi_cnt += count;
+               atomic_add(count, &vport->fc_plogi_cnt);
                break;
        case NLP_STE_ADISC_ISSUE:
-               vport->fc_adisc_cnt += count;
+               atomic_add(count, &vport->fc_adisc_cnt);
                break;
        case NLP_STE_REG_LOGIN_ISSUE:
-               vport->fc_reglogin_cnt += count;
+               atomic_add(count, &vport->fc_reglogin_cnt);
                break;
        case NLP_STE_PRLI_ISSUE:
-               vport->fc_prli_cnt += count;
+               atomic_add(count, &vport->fc_prli_cnt);
                break;
        case NLP_STE_UNMAPPED_NODE:
-               vport->fc_unmap_cnt += count;
+               atomic_add(count, &vport->fc_unmap_cnt);
                break;
        case NLP_STE_MAPPED_NODE:
-               vport->fc_map_cnt += count;
+               atomic_add(count, &vport->fc_map_cnt);
                break;
        case NLP_STE_NPR_NODE:
-               if (vport->fc_npr_cnt == 0 && count == -1)
-                       vport->fc_npr_cnt = 0;
+               if (!atomic_read(&vport->fc_npr_cnt) && count == -1)
+                       atomic_set(&vport->fc_npr_cnt, 0);
                else
-                       vport->fc_npr_cnt += count;
+                       atomic_add(count, &vport->fc_npr_cnt);
                break;
        }
-       spin_unlock_irqrestore(shost->host_lock, iflags);
 }
 
 /* Register a node with backend if not already done */
@@ -5034,8 +5029,9 @@ lpfc_set_disctmo(struct lpfc_vport *vport)
                         "0247 Start Discovery Timer state x%x "
                         "Data: x%x x%lx x%x x%x\n",
                         vport->port_state, tmo,
-                        (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
-                        vport->fc_adisc_cnt);
+                        (unsigned long)&vport->fc_disctmo,
+                        atomic_read(&vport->fc_plogi_cnt),
+                        atomic_read(&vport->fc_adisc_cnt));
 
        return;
 }
@@ -5070,7 +5066,8 @@ lpfc_can_disctmo(struct lpfc_vport *vport)
                         "0248 Cancel Discovery Timer state x%x "
                         "Data: x%x x%x x%x\n",
                         vport->port_state, vport->fc_flag,
-                        vport->fc_plogi_cnt, vport->fc_adisc_cnt);
+                        atomic_read(&vport->fc_plogi_cnt),
+                        atomic_read(&vport->fc_adisc_cnt));
        return 0;
 }
 
@@ -5951,8 +5948,10 @@ lpfc_disc_start(struct lpfc_vport *vport)
        lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
                         "0202 Start Discovery port state x%x "
                         "flg x%x Data: x%x x%x x%x\n",
-                        vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
-                        vport->fc_adisc_cnt, vport->fc_npr_cnt);
+                        vport->port_state, vport->fc_flag,
+                        atomic_read(&vport->fc_plogi_cnt),
+                        atomic_read(&vport->fc_adisc_cnt),
+                        atomic_read(&vport->fc_npr_cnt));
 
        /* First do ADISCs - if any */
        num_sent = lpfc_els_disc_adisc(vport);
@@ -5981,7 +5980,7 @@ lpfc_disc_start(struct lpfc_vport *vport)
                if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
                        vport->num_disc_nodes = 0;
                        /* go thru NPR nodes and issue ELS PLOGIs */
-                       if (vport->fc_npr_cnt)
+                       if (atomic_read(&vport->fc_npr_cnt))
                                lpfc_els_disc_plogi(vport);
 
                        if (!vport->num_disc_nodes) {
@@ -6077,7 +6076,8 @@ lpfc_disc_flush_list(struct lpfc_vport *vport)
        struct lpfc_nodelist *ndlp, *next_ndlp;
        struct lpfc_hba *phba = vport->phba;
 
-       if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
+       if (atomic_read(&vport->fc_plogi_cnt) ||
+           atomic_read(&vport->fc_adisc_cnt)) {
                list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
                                         nlp_listp) {
                        if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
index 8e84ba0f7721f67a4aff7f28c624af4314b87576..1285a7bbdcedda10fc8f75ef15d954e2bfb547e2 100644 (file)
@@ -4770,6 +4770,14 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
        vport->load_flag |= FC_LOADING;
        vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
        vport->fc_rscn_flush = 0;
+       atomic_set(&vport->fc_plogi_cnt, 0);
+       atomic_set(&vport->fc_adisc_cnt, 0);
+       atomic_set(&vport->fc_reglogin_cnt, 0);
+       atomic_set(&vport->fc_prli_cnt, 0);
+       atomic_set(&vport->fc_unmap_cnt, 0);
+       atomic_set(&vport->fc_map_cnt, 0);
+       atomic_set(&vport->fc_npr_cnt, 0);
+       atomic_set(&vport->fc_unused_cnt, 0);
        lpfc_get_vport_cfgparam(vport);
 
        /* Adjust value in vport */
@@ -4946,7 +4954,8 @@ int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
                goto finished;
        if (vport->num_disc_nodes || vport->fc_prli_sent)
                goto finished;
-       if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
+       if (!atomic_read(&vport->fc_map_cnt) &&
+           time < msecs_to_jiffies(2 * 1000))
                goto finished;
        if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
                goto finished;