Skip to content

Commit c3880bd

Browse files
MariuszStachuraJeff Kirsher
authored andcommitted
i40e: link_down_on_close private flag support
This patch introduces new ethtool private flag used for forcing true link state. Function i40e_force_link_state that implements this functionality was added, it sets phy_type = 0 in order to work-around firmware's LESM. False positive error messages were suppressed. The ndo_open() should not succeed if there were issues with forcing link state to be UP. Added I40E_PHY_TYPES_BITMASK define with all phy types OR-ed together in one bitmask. Added after phy type definition, so it will be hard to forget to include new phy types to the bitmask. Signed-off-by: Mariusz Stachura <[email protected]> Signed-off-by: Mitch Williams <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 4869a14 commit c3880bd

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

drivers/net/ethernet/intel/i40e/i40e_adminq_cmd.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,43 @@ enum i40e_aq_phy_type {
19141914
I40E_PHY_TYPE_DEFAULT = 0xFF,
19151915
};
19161916

1917+
#define I40E_PHY_TYPES_BITMASK (BIT_ULL(I40E_PHY_TYPE_SGMII) | \
1918+
BIT_ULL(I40E_PHY_TYPE_1000BASE_KX) | \
1919+
BIT_ULL(I40E_PHY_TYPE_10GBASE_KX4) | \
1920+
BIT_ULL(I40E_PHY_TYPE_10GBASE_KR) | \
1921+
BIT_ULL(I40E_PHY_TYPE_40GBASE_KR4) | \
1922+
BIT_ULL(I40E_PHY_TYPE_XAUI) | \
1923+
BIT_ULL(I40E_PHY_TYPE_XFI) | \
1924+
BIT_ULL(I40E_PHY_TYPE_SFI) | \
1925+
BIT_ULL(I40E_PHY_TYPE_XLAUI) | \
1926+
BIT_ULL(I40E_PHY_TYPE_XLPPI) | \
1927+
BIT_ULL(I40E_PHY_TYPE_40GBASE_CR4_CU) | \
1928+
BIT_ULL(I40E_PHY_TYPE_10GBASE_CR1_CU) | \
1929+
BIT_ULL(I40E_PHY_TYPE_10GBASE_AOC) | \
1930+
BIT_ULL(I40E_PHY_TYPE_40GBASE_AOC) | \
1931+
BIT_ULL(I40E_PHY_TYPE_UNRECOGNIZED) | \
1932+
BIT_ULL(I40E_PHY_TYPE_UNSUPPORTED) | \
1933+
BIT_ULL(I40E_PHY_TYPE_100BASE_TX) | \
1934+
BIT_ULL(I40E_PHY_TYPE_1000BASE_T) | \
1935+
BIT_ULL(I40E_PHY_TYPE_10GBASE_T) | \
1936+
BIT_ULL(I40E_PHY_TYPE_10GBASE_SR) | \
1937+
BIT_ULL(I40E_PHY_TYPE_10GBASE_LR) | \
1938+
BIT_ULL(I40E_PHY_TYPE_10GBASE_SFPP_CU) | \
1939+
BIT_ULL(I40E_PHY_TYPE_10GBASE_CR1) | \
1940+
BIT_ULL(I40E_PHY_TYPE_40GBASE_CR4) | \
1941+
BIT_ULL(I40E_PHY_TYPE_40GBASE_SR4) | \
1942+
BIT_ULL(I40E_PHY_TYPE_40GBASE_LR4) | \
1943+
BIT_ULL(I40E_PHY_TYPE_1000BASE_SX) | \
1944+
BIT_ULL(I40E_PHY_TYPE_1000BASE_LX) | \
1945+
BIT_ULL(I40E_PHY_TYPE_1000BASE_T_OPTICAL) | \
1946+
BIT_ULL(I40E_PHY_TYPE_20GBASE_KR2) | \
1947+
BIT_ULL(I40E_PHY_TYPE_25GBASE_KR) | \
1948+
BIT_ULL(I40E_PHY_TYPE_25GBASE_CR) | \
1949+
BIT_ULL(I40E_PHY_TYPE_25GBASE_SR) | \
1950+
BIT_ULL(I40E_PHY_TYPE_25GBASE_LR) | \
1951+
BIT_ULL(I40E_PHY_TYPE_25GBASE_AOC) | \
1952+
BIT_ULL(I40E_PHY_TYPE_25GBASE_ACC))
1953+
19171954
#define I40E_LINK_SPEED_100MB_SHIFT 0x1
19181955
#define I40E_LINK_SPEED_1000MB_SHIFT 0x2
19191956
#define I40E_LINK_SPEED_10GB_SHIFT 0x3

drivers/net/ethernet/intel/i40e/i40e_ethtool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
230230
I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
231231
I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
232232
I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
233+
I40E_PRIV_FLAG("link-down-on-close",
234+
I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED, 0),
233235
I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
234236
I40E_PRIV_FLAG("disable-source-pruning",
235237
I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),

drivers/net/ethernet/intel/i40e/i40e_main.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6546,6 +6546,75 @@ int i40e_up(struct i40e_vsi *vsi)
65466546
return err;
65476547
}
65486548

6549+
/**
6550+
* i40e_force_link_state - Force the link status
6551+
* @pf: board private structure
6552+
* @is_up: whether the link state should be forced up or down
6553+
**/
6554+
static i40e_status i40e_force_link_state(struct i40e_pf *pf, bool is_up)
6555+
{
6556+
struct i40e_aq_get_phy_abilities_resp abilities;
6557+
struct i40e_aq_set_phy_config config = {0};
6558+
struct i40e_hw *hw = &pf->hw;
6559+
i40e_status err;
6560+
u64 mask;
6561+
6562+
/* Get the current phy config */
6563+
err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
6564+
NULL);
6565+
if (err) {
6566+
dev_err(&pf->pdev->dev,
6567+
"failed to get phy cap., ret = %s last_status = %s\n",
6568+
i40e_stat_str(hw, err),
6569+
i40e_aq_str(hw, hw->aq.asq_last_status));
6570+
return err;
6571+
}
6572+
6573+
/* If link needs to go up, but was not forced to go down,
6574+
* no need for a flap
6575+
*/
6576+
if (is_up && abilities.phy_type != 0)
6577+
return I40E_SUCCESS;
6578+
6579+
/* To force link we need to set bits for all supported PHY types,
6580+
* but there are now more than 32, so we need to split the bitmap
6581+
* across two fields.
6582+
*/
6583+
mask = I40E_PHY_TYPES_BITMASK;
6584+
config.phy_type = is_up ? cpu_to_le32((u32)(mask & 0xffffffff)) : 0;
6585+
config.phy_type_ext = is_up ? (u8)((mask >> 32) & 0xff) : 0;
6586+
/* Copy the old settings, except of phy_type */
6587+
config.abilities = abilities.abilities;
6588+
config.link_speed = abilities.link_speed;
6589+
config.eee_capability = abilities.eee_capability;
6590+
config.eeer = abilities.eeer_val;
6591+
config.low_power_ctrl = abilities.d3_lpan;
6592+
err = i40e_aq_set_phy_config(hw, &config, NULL);
6593+
6594+
if (err) {
6595+
dev_err(&pf->pdev->dev,
6596+
"set phy config ret = %s last_status = %s\n",
6597+
i40e_stat_str(&pf->hw, err),
6598+
i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
6599+
return err;
6600+
}
6601+
6602+
/* Update the link info */
6603+
err = i40e_update_link_info(hw);
6604+
if (err) {
6605+
/* Wait a little bit (on 40G cards it sometimes takes a really
6606+
* long time for link to come back from the atomic reset)
6607+
* and try once more
6608+
*/
6609+
msleep(1000);
6610+
i40e_update_link_info(hw);
6611+
}
6612+
6613+
i40e_aq_set_link_restart_an(hw, true, NULL);
6614+
6615+
return I40E_SUCCESS;
6616+
}
6617+
65496618
/**
65506619
* i40e_down - Shutdown the connection processing
65516620
* @vsi: the VSI being stopped
@@ -6563,6 +6632,9 @@ void i40e_down(struct i40e_vsi *vsi)
65636632
}
65646633
i40e_vsi_disable_irq(vsi);
65656634
i40e_vsi_stop_rings(vsi);
6635+
if (vsi->type == I40E_VSI_MAIN &&
6636+
vsi->back->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED)
6637+
i40e_force_link_state(vsi->back, false);
65666638
i40e_napi_disable_all(vsi);
65676639

65686640
for (i = 0; i < vsi->num_queue_pairs; i++) {
@@ -7524,6 +7596,9 @@ int i40e_open(struct net_device *netdev)
75247596

75257597
netif_carrier_off(netdev);
75267598

7599+
if (i40e_force_link_state(pf, true))
7600+
return -EAGAIN;
7601+
75277602
err = i40e_vsi_open(vsi);
75287603
if (err)
75297604
return err;

0 commit comments

Comments
 (0)