Skip to content

Commit a645b8c

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

File tree

11 files changed

+425
-590
lines changed

11 files changed

+425
-590
lines changed

drivers/scsi/lpfc/lpfc.h

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,36 @@ struct lpfc_cgn_acqe_stat {
535535
atomic64_t warn;
536536
};
537537

538+
enum lpfc_fc_flag {
539+
/* Several of these flags are HBA centric and should be moved to
540+
* phba->link_flag (e.g. FC_PTP, FC_PUBLIC_LOOP)
541+
*/
542+
FC_PT2PT, /* pt2pt with no fabric */
543+
FC_PT2PT_PLOGI, /* pt2pt initiate PLOGI */
544+
FC_DISC_TMO, /* Discovery timer running */
545+
FC_PUBLIC_LOOP, /* Public loop */
546+
FC_LBIT, /* LOGIN bit in loopinit set */
547+
FC_RSCN_MODE, /* RSCN cmd rcv'ed */
548+
FC_NLP_MORE, /* More node to process in node tbl */
549+
FC_OFFLINE_MODE, /* Interface is offline for diag */
550+
FC_FABRIC, /* We are fabric attached */
551+
FC_VPORT_LOGO_RCVD, /* LOGO received on vport */
552+
FC_RSCN_DISCOVERY, /* Auth all devices after RSCN */
553+
FC_LOGO_RCVD_DID_CHNG, /* FDISC on phys port detect DID chng */
554+
FC_PT2PT_NO_NVME, /* Don't send NVME PRLI */
555+
FC_SCSI_SCAN_TMO, /* scsi scan timer running */
556+
FC_ABORT_DISCOVERY, /* we want to abort discovery */
557+
FC_NDISC_ACTIVE, /* NPort discovery active */
558+
FC_BYPASSED_MODE, /* NPort is in bypassed mode */
559+
FC_VPORT_NEEDS_REG_VPI, /* Needs to have its vpi registered */
560+
FC_RSCN_DEFERRED, /* A deferred RSCN being processed */
561+
FC_VPORT_NEEDS_INIT_VPI, /* Need to INIT_VPI before FDISC */
562+
FC_VPORT_CVL_RCVD, /* VLink failed due to CVL */
563+
FC_VFI_REGISTERED, /* VFI is registered */
564+
FC_FDISC_COMPLETED, /* FDISC completed */
565+
FC_DISC_DELAYED, /* Delay NPort discovery */
566+
};
567+
538568
struct lpfc_vport {
539569
struct lpfc_hba *phba;
540570
struct list_head listentry;
@@ -549,34 +579,7 @@ struct lpfc_vport {
549579
uint8_t vpi_state;
550580
#define LPFC_VPI_REGISTERED 0x1
551581

552-
uint32_t fc_flag; /* FC flags */
553-
/* Several of these flags are HBA centric and should be moved to
554-
* phba->link_flag (e.g. FC_PTP, FC_PUBLIC_LOOP)
555-
*/
556-
#define FC_PT2PT 0x1 /* pt2pt with no fabric */
557-
#define FC_PT2PT_PLOGI 0x2 /* pt2pt initiate PLOGI */
558-
#define FC_DISC_TMO 0x4 /* Discovery timer running */
559-
#define FC_PUBLIC_LOOP 0x8 /* Public loop */
560-
#define FC_LBIT 0x10 /* LOGIN bit in loopinit set */
561-
#define FC_RSCN_MODE 0x20 /* RSCN cmd rcv'ed */
562-
#define FC_NLP_MORE 0x40 /* More node to process in node tbl */
563-
#define FC_OFFLINE_MODE 0x80 /* Interface is offline for diag */
564-
#define FC_FABRIC 0x100 /* We are fabric attached */
565-
#define FC_VPORT_LOGO_RCVD 0x200 /* LOGO received on vport */
566-
#define FC_RSCN_DISCOVERY 0x400 /* Auth all devices after RSCN */
567-
#define FC_LOGO_RCVD_DID_CHNG 0x800 /* FDISC on phys port detect DID chng*/
568-
#define FC_PT2PT_NO_NVME 0x1000 /* Don't send NVME PRLI */
569-
#define FC_SCSI_SCAN_TMO 0x4000 /* scsi scan timer running */
570-
#define FC_ABORT_DISCOVERY 0x8000 /* we want to abort discovery */
571-
#define FC_NDISC_ACTIVE 0x10000 /* NPort discovery active */
572-
#define FC_BYPASSED_MODE 0x20000 /* NPort is in bypassed mode */
573-
#define FC_VPORT_NEEDS_REG_VPI 0x80000 /* Needs to have its vpi registered */
574-
#define FC_RSCN_DEFERRED 0x100000 /* A deferred RSCN being processed */
575-
#define FC_VPORT_NEEDS_INIT_VPI 0x200000 /* Need to INIT_VPI before FDISC */
576-
#define FC_VPORT_CVL_RCVD 0x400000 /* VLink failed due to CVL */
577-
#define FC_VFI_REGISTERED 0x800000 /* VFI is registered */
578-
#define FC_FDISC_COMPLETED 0x1000000/* FDISC completed */
579-
#define FC_DISC_DELAYED 0x2000000/* Delay NPort discovery */
582+
unsigned long fc_flag; /* FC flags */
580583

581584
uint32_t ct_flags;
582585
#define FC_CT_RFF_ID 0x1 /* RFF_ID accepted by switch */

drivers/scsi/lpfc/lpfc_attr.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,14 +1092,14 @@ lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
10921092
break;
10931093
}
10941094
if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
1095-
if (vport->fc_flag & FC_PUBLIC_LOOP)
1095+
if (test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
10961096
len += scnprintf(buf + len, PAGE_SIZE-len,
10971097
" Public Loop\n");
10981098
else
10991099
len += scnprintf(buf + len, PAGE_SIZE-len,
11001100
" Private Loop\n");
11011101
} else {
1102-
if (vport->fc_flag & FC_FABRIC) {
1102+
if (test_bit(FC_FABRIC, &vport->fc_flag)) {
11031103
if (phba->sli_rev == LPFC_SLI_REV4 &&
11041104
vport->port_type == LPFC_PHYSICAL_PORT &&
11051105
phba->sli4_hba.fawwpn_flag &
@@ -1291,7 +1291,7 @@ lpfc_issue_lip(struct Scsi_Host *shost)
12911291
* If the link is offline, disabled or BLOCK_MGMT_IO
12921292
* it doesn't make any sense to allow issue_lip
12931293
*/
1294-
if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1294+
if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
12951295
(phba->hba_flag & LINK_DISABLED) ||
12961296
(phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
12971297
return -EPERM;
@@ -1305,8 +1305,8 @@ lpfc_issue_lip(struct Scsi_Host *shost)
13051305
pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
13061306
pmboxq->u.mb.mbxOwner = OWN_HOST;
13071307

1308-
if ((vport->fc_flag & FC_PT2PT) && (vport->fc_flag & FC_PT2PT_NO_NVME))
1309-
vport->fc_flag &= ~FC_PT2PT_NO_NVME;
1308+
if (test_bit(FC_PT2PT, &vport->fc_flag))
1309+
clear_bit(FC_PT2PT_NO_NVME, &vport->fc_flag);
13101310

13111311
mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
13121312

@@ -1496,7 +1496,8 @@ lpfc_reset_pci_bus(struct lpfc_hba *phba)
14961496
if (shost) {
14971497
phba_other =
14981498
((struct lpfc_vport *)shost->hostdata)->phba;
1499-
if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1499+
if (!test_bit(FC_OFFLINE_MODE,
1500+
&phba_other->pport->fc_flag)) {
15001501
lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
15011502
"8349 WWPN = 0x%02x%02x%02x%02x"
15021503
"%02x%02x%02x%02x is not "
@@ -1551,7 +1552,7 @@ lpfc_selective_reset(struct lpfc_hba *phba)
15511552
if (!phba->cfg_enable_hba_reset)
15521553
return -EACCES;
15531554

1554-
if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1555+
if (!test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag)) {
15551556
status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
15561557

15571558
if (status != 0)
@@ -1690,7 +1691,7 @@ lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
16901691
{
16911692
struct completion online_compl;
16921693
struct pci_dev *pdev = phba->pcidev;
1693-
uint32_t before_fc_flag;
1694+
unsigned long before_fc_flag;
16941695
uint32_t sriov_nr_virtfn;
16951696
uint32_t reg_val;
16961697
int status = 0, rc = 0;
@@ -1761,7 +1762,7 @@ lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
17611762
}
17621763

17631764
/* keep the original port state */
1764-
if (before_fc_flag & FC_OFFLINE_MODE) {
1765+
if (test_bit(FC_OFFLINE_MODE, &before_fc_flag)) {
17651766
if (phba->fw_dump_cmpl)
17661767
phba->fw_dump_cmpl = NULL;
17671768
goto out;
@@ -2099,7 +2100,7 @@ lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
20992100
*board_mode_str = '\0';
21002101
lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
21012102
"3097 Failed \"%s\", status(%d), "
2102-
"fc_flag(x%x)\n",
2103+
"fc_flag(x%lx)\n",
21032104
buf, status, phba->pport->fc_flag);
21042105
return status;
21052106
}
@@ -2158,7 +2159,7 @@ lpfc_get_hba_info(struct lpfc_hba *phba,
21582159
pmb->mbxOwner = OWN_HOST;
21592160
pmboxq->ctx_buf = NULL;
21602161

2161-
if (phba->pport->fc_flag & FC_OFFLINE_MODE)
2162+
if (test_bit(FC_OFFLINE_MODE, &phba->pport->fc_flag))
21622163
rc = MBX_NOT_FINISHED;
21632164
else
21642165
rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
@@ -6200,7 +6201,7 @@ sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
62006201
if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
62016202
return -EINVAL;
62026203

6203-
if (!(vport->fc_flag & FC_OFFLINE_MODE))
6204+
if (!test_bit(FC_OFFLINE_MODE, &vport->fc_flag))
62046205
return -EPERM;
62056206

62066207
spin_lock_irq(&phba->hbalock);
@@ -6433,12 +6434,12 @@ lpfc_get_host_port_type(struct Scsi_Host *shost)
64336434
fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
64346435
} else if (lpfc_is_link_up(phba)) {
64356436
if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6436-
if (vport->fc_flag & FC_PUBLIC_LOOP)
6437+
if (test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))
64376438
fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
64386439
else
64396440
fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
64406441
} else {
6441-
if (vport->fc_flag & FC_FABRIC)
6442+
if (test_bit(FC_FABRIC, &vport->fc_flag))
64426443
fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
64436444
else
64446445
fc_host_port_type(shost) = FC_PORTTYPE_PTP;
@@ -6457,7 +6458,7 @@ lpfc_get_host_port_state(struct Scsi_Host *shost)
64576458
struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
64586459
struct lpfc_hba *phba = vport->phba;
64596460

6460-
if (vport->fc_flag & FC_OFFLINE_MODE)
6461+
if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag))
64616462
fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
64626463
else {
64636464
switch (phba->link_state) {
@@ -6571,10 +6572,10 @@ lpfc_get_host_fabric_name (struct Scsi_Host *shost)
65716572
struct lpfc_hba *phba = vport->phba;
65726573
u64 node_name;
65736574

6574-
if ((vport->port_state > LPFC_FLOGI) &&
6575-
((vport->fc_flag & FC_FABRIC) ||
6576-
((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
6577-
(vport->fc_flag & FC_PUBLIC_LOOP))))
6575+
if (vport->port_state > LPFC_FLOGI &&
6576+
(test_bit(FC_FABRIC, &vport->fc_flag) ||
6577+
(phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
6578+
test_bit(FC_PUBLIC_LOOP, &vport->fc_flag))))
65786579
node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
65796580
else
65806581
/* fabric is local port if there is no F/FL_Port */
@@ -6630,7 +6631,7 @@ lpfc_get_stats(struct Scsi_Host *shost)
66306631
pmboxq->ctx_buf = NULL;
66316632
pmboxq->vport = vport;
66326633

6633-
if (vport->fc_flag & FC_OFFLINE_MODE) {
6634+
if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
66346635
rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
66356636
if (rc != MBX_SUCCESS) {
66366637
mempool_free(pmboxq, phba->mbox_mem_pool);
@@ -6683,7 +6684,7 @@ lpfc_get_stats(struct Scsi_Host *shost)
66836684
pmboxq->ctx_buf = NULL;
66846685
pmboxq->vport = vport;
66856686

6686-
if (vport->fc_flag & FC_OFFLINE_MODE) {
6687+
if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
66876688
rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
66886689
if (rc != MBX_SUCCESS) {
66896690
mempool_free(pmboxq, phba->mbox_mem_pool);
@@ -6770,8 +6771,8 @@ lpfc_reset_stats(struct Scsi_Host *shost)
67706771
pmboxq->ctx_buf = NULL;
67716772
pmboxq->vport = vport;
67726773

6773-
if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6774-
(!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6774+
if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
6775+
!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
67756776
rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
67766777
if (rc != MBX_SUCCESS) {
67776778
mempool_free(pmboxq, phba->mbox_mem_pool);
@@ -6792,8 +6793,8 @@ lpfc_reset_stats(struct Scsi_Host *shost)
67926793
pmboxq->ctx_buf = NULL;
67936794
pmboxq->vport = vport;
67946795

6795-
if ((vport->fc_flag & FC_OFFLINE_MODE) ||
6796-
(!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
6796+
if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
6797+
!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
67976798
rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
67986799
if (rc != MBX_SUCCESS) {
67996800
mempool_free(pmboxq, phba->mbox_mem_pool);

drivers/scsi/lpfc/lpfc_bsg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ lpfc_sli4_bsg_set_loopback_mode(struct lpfc_hba *phba, int mode,
19771977
static int
19781978
lpfc_sli4_diag_fcport_reg_setup(struct lpfc_hba *phba)
19791979
{
1980-
if (phba->pport->fc_flag & FC_VFI_REGISTERED) {
1980+
if (test_bit(FC_VFI_REGISTERED, &phba->pport->fc_flag)) {
19811981
lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
19821982
"3136 Port still had vfi registered: "
19831983
"mydid:x%x, fcfi:%d, vfi:%d, vpi:%d\n",
@@ -3448,7 +3448,7 @@ static int lpfc_bsg_check_cmd_access(struct lpfc_hba *phba,
34483448
case MBX_RUN_DIAGS:
34493449
case MBX_RESTART:
34503450
case MBX_SET_MASK:
3451-
if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3451+
if (!test_bit(FC_OFFLINE_MODE, &vport->fc_flag)) {
34523452
lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
34533453
"2743 Command 0x%x is illegal in on-line "
34543454
"state\n",
@@ -4886,7 +4886,7 @@ lpfc_bsg_issue_mbox(struct lpfc_hba *phba, struct bsg_job *job,
48864886
dd_data->context_un.mbox.outExtWLen = mbox_req->outExtWLen;
48874887
job->dd_data = dd_data;
48884888

4889-
if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4889+
if (test_bit(FC_OFFLINE_MODE, &vport->fc_flag) ||
48904890
(!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
48914891
rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
48924892
if (rc != MBX_SUCCESS) {

0 commit comments

Comments
 (0)