Skip to content

Commit 57ccaed

Browse files
Ganesh Goudardavem330
authored andcommitted
cxgb4/cxgb4vf: link management changes for new SFP
newer SFPs like SFP28 and QSFP28 Transceiver Modules present several new possibilities which we haven't faced before. Fix the assumptions in the code reflecting the more limited capabilities of previous Transceiver Module systems Original work by Casey Leedom <leedom@chelsio.com> Signed-off-by: Ganesh Goudar <ganeshgr@chelsio.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b526e56 commit 57ccaed

3 files changed

Lines changed: 85 additions & 18 deletions

File tree

‎drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -800,24 +800,20 @@ static int set_link_ksettings(struct net_device *dev,
800800
if (base->duplex != DUPLEX_FULL)
801801
return -EINVAL;
802802

803-
if (!(lc->pcaps & FW_PORT_CAP32_ANEG)) {
804-
/* PHY offers a single speed. See if that's what's
805-
* being requested.
806-
*/
807-
if (base->autoneg == AUTONEG_DISABLE &&
808-
(lc->pcaps & speed_to_fw_caps(base->speed)))
809-
return 0;
810-
return -EINVAL;
811-
}
812-
813803
old_lc = *lc;
814-
if (base->autoneg == AUTONEG_DISABLE) {
804+
if (!(lc->pcaps & FW_PORT_CAP32_ANEG) ||
805+
base->autoneg == AUTONEG_DISABLE) {
815806
fw_caps = speed_to_fw_caps(base->speed);
816807

817-
if (!(lc->pcaps & fw_caps))
808+
/* Must only specify a single speed which must be supported
809+
* as part of the Physical Port Capabilities.
810+
*/
811+
if ((fw_caps & (fw_caps - 1)) != 0 ||
812+
!(lc->pcaps & fw_caps))
818813
return -EINVAL;
814+
819815
lc->speed_caps = fw_caps;
820-
lc->acaps = 0;
816+
lc->acaps = fw_caps;
821817
} else {
822818
fw_caps =
823819
lmm_to_fw_caps(link_ksettings->link_modes.advertising);

‎drivers/net/ethernet/chelsio/cxgb4/t4_hw.c‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4066,6 +4066,7 @@ int t4_link_l1cfg_core(struct adapter *adapter, unsigned int mbox,
40664066
fw_port_cap32_t fw_fc, cc_fec, fw_fec, rcap;
40674067
struct fw_port_cmd cmd;
40684068
unsigned int fw_mdi;
4069+
int ret;
40694070

40704071
fw_mdi = (FW_PORT_CAP32_MDI_V(FW_PORT_CAP32_MDI_AUTO) & lc->pcaps);
40714072
/* Convert driver coding of Pause Frame Flow Control settings into the
@@ -4100,6 +4101,13 @@ int t4_link_l1cfg_core(struct adapter *adapter, unsigned int mbox,
41004101
rcap = lc->acaps | fw_fc | fw_fec | fw_mdi;
41014102
}
41024103

4104+
if (rcap & ~lc->pcaps) {
4105+
dev_err(adapter->pdev_dev,
4106+
"Requested Port Capabilities %#x exceed Physical Port Capabilities %#x\n",
4107+
rcap, lc->pcaps);
4108+
return -EINVAL;
4109+
}
4110+
41034111
/* And send that on to the Firmware ...
41044112
*/
41054113
memset(&cmd, 0, sizeof(cmd));
@@ -4110,13 +4118,21 @@ int t4_link_l1cfg_core(struct adapter *adapter, unsigned int mbox,
41104118
cpu_to_be32(FW_PORT_CMD_ACTION_V(fw_caps == FW_CAPS16
41114119
? FW_PORT_ACTION_L1_CFG
41124120
: FW_PORT_ACTION_L1_CFG32) |
4113-
FW_LEN16(cmd));
4121+
FW_LEN16(cmd));
41144122
if (fw_caps == FW_CAPS16)
41154123
cmd.u.l1cfg.rcap = cpu_to_be32(fwcaps32_to_caps16(rcap));
41164124
else
41174125
cmd.u.l1cfg32.rcap32 = cpu_to_be32(rcap);
4118-
return t4_wr_mbox_meat_timeout(adapter, mbox, &cmd, sizeof(cmd), NULL,
4119-
sleep_ok, timeout);
4126+
4127+
ret = t4_wr_mbox_meat_timeout(adapter, mbox, &cmd, sizeof(cmd), NULL,
4128+
sleep_ok, timeout);
4129+
if (ret) {
4130+
dev_err(adapter->pdev_dev,
4131+
"Requested Port Capabilities %#x rejected, error %d\n",
4132+
rcap, -ret);
4133+
return ret;
4134+
}
4135+
return ret;
41204136
}
41214137

41224138
/**
@@ -8395,7 +8411,9 @@ void t4_handle_get_port_info(struct port_info *pi, const __be64 *rpl)
83958411
lc->lpacaps = lpacaps;
83968412
lc->acaps = acaps & ADVERT_MASK;
83978413

8398-
if (lc->acaps & FW_PORT_CAP32_ANEG) {
8414+
if (!(lc->acaps & FW_PORT_CAP32_ANEG)) {
8415+
lc->autoneg = AUTONEG_DISABLE;
8416+
} else if (lc->acaps & FW_PORT_CAP32_ANEG) {
83998417
lc->autoneg = AUTONEG_ENABLE;
84008418
} else {
84018419
/* When Autoneg is disabled, user needs to set
@@ -8600,13 +8618,21 @@ static void init_link_config(struct link_config *lc, fw_port_cap32_t pcaps,
86008618
lc->requested_fec = FEC_AUTO;
86018619
lc->fec = fwcap_to_cc_fec(lc->def_acaps);
86028620

8621+
/* If the Port is capable of Auto-Negtotiation, initialize it as
8622+
* "enabled" and copy over all of the Physical Port Capabilities
8623+
* to the Advertised Port Capabilities. Otherwise mark it as
8624+
* Auto-Negotiate disabled and select the highest supported speed
8625+
* for the link. Note parallel structure in t4_link_l1cfg_core()
8626+
* and t4_handle_get_port_info().
8627+
*/
86038628
if (lc->pcaps & FW_PORT_CAP32_ANEG) {
86048629
lc->acaps = lc->pcaps & ADVERT_MASK;
86058630
lc->autoneg = AUTONEG_ENABLE;
86068631
lc->requested_fc |= PAUSE_AUTONEG;
86078632
} else {
86088633
lc->acaps = 0;
86098634
lc->autoneg = AUTONEG_DISABLE;
8635+
lc->speed_caps = fwcap_to_fwspeed(acaps);
86108636
}
86118637
}
86128638

‎drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,36 @@ static unsigned int fwcap_to_speed(fw_port_cap32_t caps)
405405
return 0;
406406
}
407407

408+
/**
409+
* fwcap_to_fwspeed - return highest speed in Port Capabilities
410+
* @acaps: advertised Port Capabilities
411+
*
412+
* Get the highest speed for the port from the advertised Port
413+
* Capabilities. It will be either the highest speed from the list of
414+
* speeds or whatever user has set using ethtool.
415+
*/
416+
static fw_port_cap32_t fwcap_to_fwspeed(fw_port_cap32_t acaps)
417+
{
418+
#define TEST_SPEED_RETURN(__caps_speed) \
419+
do { \
420+
if (acaps & FW_PORT_CAP32_SPEED_##__caps_speed) \
421+
return FW_PORT_CAP32_SPEED_##__caps_speed; \
422+
} while (0)
423+
424+
TEST_SPEED_RETURN(400G);
425+
TEST_SPEED_RETURN(200G);
426+
TEST_SPEED_RETURN(100G);
427+
TEST_SPEED_RETURN(50G);
428+
TEST_SPEED_RETURN(40G);
429+
TEST_SPEED_RETURN(25G);
430+
TEST_SPEED_RETURN(10G);
431+
TEST_SPEED_RETURN(1G);
432+
TEST_SPEED_RETURN(100M);
433+
434+
#undef TEST_SPEED_RETURN
435+
return 0;
436+
}
437+
408438
/*
409439
* init_link_config - initialize a link's SW state
410440
* @lc: structure holding the link state
@@ -431,13 +461,21 @@ static void init_link_config(struct link_config *lc,
431461
lc->requested_fec = FEC_AUTO;
432462
lc->fec = lc->auto_fec;
433463

464+
/* If the Port is capable of Auto-Negtotiation, initialize it as
465+
* "enabled" and copy over all of the Physical Port Capabilities
466+
* to the Advertised Port Capabilities. Otherwise mark it as
467+
* Auto-Negotiate disabled and select the highest supported speed
468+
* for the link. Note parallel structure in t4_link_l1cfg_core()
469+
* and t4_handle_get_port_info().
470+
*/
434471
if (lc->pcaps & FW_PORT_CAP32_ANEG) {
435472
lc->acaps = acaps & ADVERT_MASK;
436473
lc->autoneg = AUTONEG_ENABLE;
437474
lc->requested_fc |= PAUSE_AUTONEG;
438475
} else {
439476
lc->acaps = 0;
440477
lc->autoneg = AUTONEG_DISABLE;
478+
lc->speed_caps = fwcap_to_fwspeed(acaps);
441479
}
442480
}
443481

@@ -1955,7 +1993,14 @@ static void t4vf_handle_get_port_info(struct port_info *pi,
19551993
lc->lpacaps = lpacaps;
19561994
lc->acaps = acaps & ADVERT_MASK;
19571995

1958-
if (lc->acaps & FW_PORT_CAP32_ANEG) {
1996+
/* If we're not physically capable of Auto-Negotiation, note
1997+
* this as Auto-Negotiation disabled. Otherwise, we track
1998+
* what Auto-Negotiation settings we have. Note parallel
1999+
* structure in init_link_config().
2000+
*/
2001+
if (!(lc->pcaps & FW_PORT_CAP32_ANEG)) {
2002+
lc->autoneg = AUTONEG_DISABLE;
2003+
} else if (lc->acaps & FW_PORT_CAP32_ANEG) {
19592004
lc->autoneg = AUTONEG_ENABLE;
19602005
} else {
19612006
/* When Autoneg is disabled, user needs to set

0 commit comments

Comments
 (0)