Skip to content

Commit 3f8f9f1

Browse files
Justin Teemartinkpetersen
authored andcommitted
scsi: lpfc: Change lpfc_nodelist save_flags member into a bitmask
In attempt to reduce the amount of unnecessary ndlp->lock acquisitions in the lpfc driver, change save_flags into an unsigned long bitmask and use clear_bit/test_bit bitwise atomic APIs instead of reliance on ndlp->lock for synchronization. Signed-off-by: Justin Tee <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 06dbe31 commit 3f8f9f1

File tree

7 files changed

+33
-53
lines changed

7 files changed

+33
-53
lines changed

drivers/scsi/lpfc/lpfc_ct.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,14 +1646,12 @@ lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
16461646
/* If the caller wanted a synchronous DA_ID completion, signal the
16471647
* wait obj and clear flag to reset the vport.
16481648
*/
1649-
if (ndlp->save_flags & NLP_WAIT_FOR_DA_ID) {
1649+
if (test_bit(NLP_WAIT_FOR_DA_ID, &ndlp->save_flags)) {
16501650
if (ndlp->da_id_waitq)
16511651
wake_up(ndlp->da_id_waitq);
16521652
}
16531653

1654-
spin_lock_irq(&ndlp->lock);
1655-
ndlp->save_flags &= ~NLP_WAIT_FOR_DA_ID;
1656-
spin_unlock_irq(&ndlp->lock);
1654+
clear_bit(NLP_WAIT_FOR_DA_ID, &ndlp->save_flags);
16571655

16581656
lpfc_ct_free_iocb(phba, cmdiocb);
16591657
lpfc_nlp_put(ndlp);

drivers/scsi/lpfc/lpfc_disc.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ enum lpfc_fc4_xpt_flags {
8585
NLP_XPT_HAS_HH = 0x10
8686
};
8787

88-
enum lpfc_nlp_save_flags {
88+
enum lpfc_nlp_save_flags { /* mask bits */
8989
/* devloss occurred during recovery */
90-
NLP_IN_RECOV_POST_DEV_LOSS = 0x1,
90+
NLP_IN_RECOV_POST_DEV_LOSS,
9191
/* wait for outstanding LOGO to cmpl */
92-
NLP_WAIT_FOR_LOGO = 0x2,
92+
NLP_WAIT_FOR_LOGO,
9393
/* wait for outstanding DA_ID to finish */
94-
NLP_WAIT_FOR_DA_ID = 0x4
94+
NLP_WAIT_FOR_DA_ID
9595
};
9696

9797
struct lpfc_nodelist {
@@ -154,7 +154,7 @@ struct lpfc_nodelist {
154154
uint32_t fc4_prli_sent;
155155

156156
/* flags to keep ndlp alive until special conditions are met */
157-
enum lpfc_nlp_save_flags save_flags;
157+
unsigned long save_flags;
158158

159159
enum lpfc_fc4_xpt_flags fc4_xpt_flags;
160160

drivers/scsi/lpfc/lpfc_els.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,12 +2988,8 @@ lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
29882988
}
29892989

29902990
clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag);
2991-
spin_lock_irq(&ndlp->lock);
2992-
if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
2991+
if (test_and_clear_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags))
29932992
wake_up_waiter = 1;
2994-
ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
2995-
}
2996-
spin_unlock_irq(&ndlp->lock);
29972993

29982994
lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
29992995
"LOGO cmpl: status:x%x/x%x did:x%x",
@@ -11509,15 +11505,13 @@ lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1150911505
lpfc_can_disctmo(vport);
1151011506
}
1151111507

11512-
if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
11508+
if (test_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags)) {
1151311509
/* Wake up lpfc_vport_delete if waiting...*/
1151411510
if (ndlp->logo_waitq)
1151511511
wake_up(ndlp->logo_waitq);
1151611512
clear_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag);
1151711513
clear_bit(NLP_LOGO_SND, &ndlp->nlp_flag);
11518-
spin_lock_irq(&ndlp->lock);
11519-
ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
11520-
spin_unlock_irq(&ndlp->lock);
11514+
clear_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags);
1152111515
}
1152211516

1152311517
/* Safe to release resources now. */

drivers/scsi/lpfc/lpfc_hbadisc.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -414,22 +414,15 @@ void
414414
lpfc_check_nlp_post_devloss(struct lpfc_vport *vport,
415415
struct lpfc_nodelist *ndlp)
416416
{
417-
unsigned long iflags;
418-
419-
spin_lock_irqsave(&ndlp->lock, iflags);
420-
if (ndlp->save_flags & NLP_IN_RECOV_POST_DEV_LOSS) {
421-
ndlp->save_flags &= ~NLP_IN_RECOV_POST_DEV_LOSS;
422-
spin_unlock_irqrestore(&ndlp->lock, iflags);
417+
if (test_and_clear_bit(NLP_IN_RECOV_POST_DEV_LOSS, &ndlp->save_flags)) {
423418
lpfc_nlp_get(ndlp);
424419
lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY | LOG_NODE,
425420
"8438 Devloss timeout reversed on DID x%x "
426421
"refcnt %d ndlp %p flag x%lx "
427422
"port_state = x%x\n",
428423
ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp,
429424
ndlp->nlp_flag, vport->port_state);
430-
return;
431425
}
432-
spin_unlock_irqrestore(&ndlp->lock, iflags);
433426
}
434427

435428
/**
@@ -546,9 +539,7 @@ lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
546539
ndlp->nlp_DID, kref_read(&ndlp->kref),
547540
ndlp, ndlp->nlp_flag,
548541
vport->port_state);
549-
spin_lock_irqsave(&ndlp->lock, iflags);
550-
ndlp->save_flags |= NLP_IN_RECOV_POST_DEV_LOSS;
551-
spin_unlock_irqrestore(&ndlp->lock, iflags);
542+
set_bit(NLP_IN_RECOV_POST_DEV_LOSS, &ndlp->save_flags);
552543
return fcf_inuse;
553544
} else if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
554545
/* Fabric node fully recovered before this dev_loss_tmo

drivers/scsi/lpfc/lpfc_init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,8 +3847,8 @@ lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
38473847
* Otherwise, let dev_loss take care of
38483848
* the node.
38493849
*/
3850-
if (!(ndlp->save_flags &
3851-
NLP_IN_RECOV_POST_DEV_LOSS) &&
3850+
if (!test_bit(NLP_IN_RECOV_POST_DEV_LOSS,
3851+
&ndlp->save_flags) &&
38523852
!(ndlp->fc4_xpt_flags &
38533853
(NVME_XPT_REGD | SCSI_XPT_REGD)))
38543854
lpfc_disc_state_machine

drivers/scsi/lpfc/lpfc_scsi.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6120,31 +6120,28 @@ lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
61206120

61216121
/* Issue LOGO, if no LOGO is outstanding */
61226122
spin_lock_irqsave(&pnode->lock, flags);
6123-
if (!(pnode->save_flags & NLP_WAIT_FOR_LOGO) &&
6123+
if (!test_bit(NLP_WAIT_FOR_LOGO, &pnode->save_flags) &&
61246124
!pnode->logo_waitq) {
61256125
pnode->logo_waitq = &waitq;
61266126
pnode->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
6127-
set_bit(NLP_ISSUE_LOGO, &pnode->nlp_flag);
6128-
pnode->save_flags |= NLP_WAIT_FOR_LOGO;
61296127
spin_unlock_irqrestore(&pnode->lock, flags);
6128+
set_bit(NLP_ISSUE_LOGO, &pnode->nlp_flag);
6129+
set_bit(NLP_WAIT_FOR_LOGO, &pnode->save_flags);
61306130
lpfc_unreg_rpi(vport, pnode);
61316131
wait_event_timeout(waitq,
6132-
(!(pnode->save_flags &
6133-
NLP_WAIT_FOR_LOGO)),
6132+
!test_bit(NLP_WAIT_FOR_LOGO,
6133+
&pnode->save_flags),
61346134
msecs_to_jiffies(dev_loss_tmo *
61356135
1000));
61366136

6137-
if (pnode->save_flags & NLP_WAIT_FOR_LOGO) {
6137+
if (test_and_clear_bit(NLP_WAIT_FOR_LOGO,
6138+
&pnode->save_flags))
61386139
lpfc_printf_vlog(vport, KERN_ERR, logit,
61396140
"0725 SCSI layer TGTRST "
61406141
"failed & LOGO TMO (%d, %llu) "
61416142
"return x%x\n",
61426143
tgt_id, lun_id, status);
6143-
spin_lock_irqsave(&pnode->lock, flags);
6144-
pnode->save_flags &= ~NLP_WAIT_FOR_LOGO;
6145-
} else {
6146-
spin_lock_irqsave(&pnode->lock, flags);
6147-
}
6144+
spin_lock_irqsave(&pnode->lock, flags);
61486145
pnode->logo_waitq = NULL;
61496146
spin_unlock_irqrestore(&pnode->lock, flags);
61506147
status = SUCCESS;

drivers/scsi/lpfc/lpfc_vport.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -492,21 +492,22 @@ lpfc_send_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
492492
DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
493493

494494
spin_lock_irq(&ndlp->lock);
495-
if (!(ndlp->save_flags & NLP_WAIT_FOR_LOGO) &&
495+
if (!test_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags) &&
496496
!ndlp->logo_waitq) {
497497
ndlp->logo_waitq = &waitq;
498498
ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
499499
set_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag);
500-
ndlp->save_flags |= NLP_WAIT_FOR_LOGO;
500+
set_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags);
501501
}
502502
spin_unlock_irq(&ndlp->lock);
503503
rc = lpfc_issue_els_npiv_logo(vport, ndlp);
504504
if (!rc) {
505505
wait_event_timeout(waitq,
506-
(!(ndlp->save_flags & NLP_WAIT_FOR_LOGO)),
506+
!test_bit(NLP_WAIT_FOR_LOGO,
507+
&ndlp->save_flags),
507508
msecs_to_jiffies(phba->fc_ratov * 2000));
508509

509-
if (!(ndlp->save_flags & NLP_WAIT_FOR_LOGO))
510+
if (!test_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags))
510511
goto logo_cmpl;
511512
/* LOGO wait failed. Correct status. */
512513
rc = -EINTR;
@@ -516,9 +517,7 @@ lpfc_send_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
516517

517518
/* Error - clean up node flags. */
518519
clear_bit(NLP_ISSUE_LOGO, &ndlp->nlp_flag);
519-
spin_lock_irq(&ndlp->lock);
520-
ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
521-
spin_unlock_irq(&ndlp->lock);
520+
clear_bit(NLP_WAIT_FOR_LOGO, &ndlp->save_flags);
522521

523522
logo_cmpl:
524523
lpfc_printf_vlog(vport, KERN_INFO, LOG_VPORT,
@@ -696,19 +695,20 @@ lpfc_vport_delete(struct fc_vport *fc_vport)
696695

697696
spin_lock_irq(&ndlp->lock);
698697
ndlp->da_id_waitq = &waitq;
699-
ndlp->save_flags |= NLP_WAIT_FOR_DA_ID;
700698
spin_unlock_irq(&ndlp->lock);
699+
set_bit(NLP_WAIT_FOR_DA_ID, &ndlp->save_flags);
701700

702701
rc = lpfc_ns_cmd(vport, SLI_CTNS_DA_ID, 0, 0);
703702
if (!rc) {
704703
wait_event_timeout(waitq,
705-
!(ndlp->save_flags & NLP_WAIT_FOR_DA_ID),
704+
!test_bit(NLP_WAIT_FOR_DA_ID,
705+
&ndlp->save_flags),
706706
msecs_to_jiffies(phba->fc_ratov * 2000));
707707
}
708708

709709
lpfc_printf_vlog(vport, KERN_INFO, LOG_VPORT | LOG_ELS,
710710
"1829 DA_ID issue status %d. "
711-
"SFlag x%x NState x%x, NFlag x%lx "
711+
"SFlag x%lx NState x%x, NFlag x%lx "
712712
"Rpi x%x\n",
713713
rc, ndlp->save_flags, ndlp->nlp_state,
714714
ndlp->nlp_flag, ndlp->nlp_rpi);
@@ -718,8 +718,8 @@ lpfc_vport_delete(struct fc_vport *fc_vport)
718718
*/
719719
spin_lock_irq(&ndlp->lock);
720720
ndlp->da_id_waitq = NULL;
721-
ndlp->save_flags &= ~NLP_WAIT_FOR_DA_ID;
722721
spin_unlock_irq(&ndlp->lock);
722+
clear_bit(NLP_WAIT_FOR_DA_ID, &ndlp->save_flags);
723723
}
724724

725725
issue_logo:

0 commit comments

Comments
 (0)