git: 8c711d0aa2d9 - stable/13 - cxgbe(4): Handle FORCE_FEC in pcaps correctly.

From: Navdeep Parhar <np_at_FreeBSD.org>
Date: Sat, 02 Apr 2022 01:50:09 UTC
The branch stable/13 has been updated by np:

URL: https://cgit.FreeBSD.org/src/commit/?id=8c711d0aa2d9d3369bb2cfdd5b7a27e2cd521ccc

commit 8c711d0aa2d9d3369bb2cfdd5b7a27e2cd521ccc
Author:     Navdeep Parhar <np@FreeBSD.org>
AuthorDate: 2022-03-25 07:34:54 +0000
Commit:     Navdeep Parhar <np@FreeBSD.org>
CommitDate: 2022-04-02 01:49:43 +0000

    cxgbe(4): Handle FORCE_FEC in pcaps correctly.
    
    The firmware doesn't report FORCE_FEC in pcaps if the transceiver
    plugged in at that time does not support a speed that may use FEC.  It
    is incorrect for the driver to assume that the FORCE_FEC value it read
    during attach (in init_link_config) is permanent.  Instead, it should
    check pcaps just before issuing the L1CFG command.
    
    Sponsored by:   Chelsio Communications
    
    (cherry picked from commit 231f2112403229a1382be3f5f6ed50bffe3497e8)
---
 sys/dev/cxgbe/common/t4_hw.c | 15 +++++++++------
 sys/dev/cxgbe/t4_main.c      | 14 ++++++--------
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/sys/dev/cxgbe/common/t4_hw.c b/sys/dev/cxgbe/common/t4_hw.c
index c32dab915ee6..0176eb3e2b0d 100644
--- a/sys/dev/cxgbe/common/t4_hw.c
+++ b/sys/dev/cxgbe/common/t4_hw.c
@@ -3908,13 +3908,16 @@ int t4_link_l1cfg(struct adapter *adap, unsigned int mbox, unsigned int port,
 		speed = fwcap_top_speed(lc->pcaps);
 
 	fec = 0;
-#ifdef INVARIANTS
-	if (lc->force_fec != 0)
-		MPASS(lc->pcaps & FW_PORT_CAP32_FORCE_FEC);
-#endif
 	if (fec_supported(speed)) {
+		int force_fec;
+
+		if (lc->pcaps & FW_PORT_CAP32_FORCE_FEC)
+			force_fec = lc->force_fec;
+		else
+			force_fec = 0;
+
 		if (lc->requested_fec == FEC_AUTO) {
-			if (lc->force_fec > 0) {
+			if (force_fec > 0) {
 				/*
 				 * Must use FORCE_FEC even though requested FEC
 				 * is AUTO. Set all the FEC bits valid for the
@@ -3960,7 +3963,7 @@ int t4_link_l1cfg(struct adapter *adap, unsigned int mbox, unsigned int port,
 			 * User has explicitly requested some FEC(s). Set
 			 * FORCE_FEC unless prohibited from using it.
 			 */
-			if (lc->force_fec != 0)
+			if (force_fec != 0)
 				fec |= FW_PORT_CAP32_FORCE_FEC;
 			fec |= fec_to_fwcap(lc->requested_fec &
 			    M_FW_PORT_CAP32_FEC);
diff --git a/sys/dev/cxgbe/t4_main.c b/sys/dev/cxgbe/t4_main.c
index 703335d9bc87..a113a1c662c8 100644
--- a/sys/dev/cxgbe/t4_main.c
+++ b/sys/dev/cxgbe/t4_main.c
@@ -5848,7 +5848,6 @@ init_link_config(struct port_info *pi)
 	struct link_config *lc = &pi->link_cfg;
 
 	PORT_LOCK_ASSERT_OWNED(pi);
-	MPASS(lc->pcaps != 0);
 
 	lc->requested_caps = 0;
 	lc->requested_speed = 0;
@@ -5874,13 +5873,12 @@ init_link_config(struct port_info *pi)
 		if (lc->requested_fec == 0)
 			lc->requested_fec = FEC_AUTO;
 	}
-	lc->force_fec = 0;
-	if (lc->pcaps & FW_PORT_CAP32_FORCE_FEC) {
-		if (t4_force_fec < 0)
-			lc->force_fec = -1;
-		else if (t4_force_fec > 0)
-			lc->force_fec = 1;
-	}
+	if (t4_force_fec < 0)
+		lc->force_fec = -1;
+	else if (t4_force_fec > 0)
+		lc->force_fec = 1;
+	else
+		lc->force_fec = 0;
 }
 
 /*