igc: Add initial EEE support
Subsystems (2)
PATCH 1/1 igc: Add initial EEE support
IEEE802.3az-2010 Energy Efficient Ethernet has been approved as standard (September 2010) and the driver can enable and disable it via ethtool.
Disable the feature by default on parts which support it. Add enable/disable eee options.
tx-lpi, tx-timer and advertise not supported yet.
--- drivers/net/ethernet/intel/igc/igc.h | 4 ++ drivers/net/ethernet/intel/igc/igc_defines.h | 10 +++ drivers/net/ethernet/intel/igc/igc_ethtool.c | 104 +++++++++++++++++++++++++++ drivers/net/ethernet/intel/igc/igc_hw.h | 1 + drivers/net/ethernet/intel/igc/igc_i225.c | 61 ++++++++++++++++ drivers/net/ethernet/intel/igc/igc_i225.h | 2 + drivers/net/ethernet/intel/igc/igc_main.c | 17 +++++ drivers/net/ethernet/intel/igc/igc_regs.h | 5 ++ 8 files changed, 204 insertions(+)
drivers/net/ethernet/intel/igc/igc.h +4 -0
@@ -117,6 +117,9 @@ struct igc_ring {struct igc_adapter {struct net_device *netdev; +struct ethtool_eee eee; +u16 eee_advert; +unsigned long state;unsigned int flags;unsigned int num_q_vectors;
@@ -256,6 +259,7 @@ extern char igc_driver_version[];#define IGC_FLAG_MEDIA_RESET BIT(10)#define IGC_FLAG_MAS_ENABLE BIT(12)#define IGC_FLAG_HAS_MSIX BIT(13) +#define IGC_FLAG_EEE BIT(14)#define IGC_FLAG_VLAN_PROMISC BIT(15)#define IGC_FLAG_RX_LEGACY BIT(16)#define IGC_FLAG_TSN_QBV_ENABLED BIT(17)
drivers/net/ethernet/intel/igc/igc_defines.h +10 -0
@@ -512,4 +512,14 @@/* Maximum size of the MTA register table in all supported adapters */ #define MAX_MTA_REG 128 +/* EEE defines */ +#define IGC_IPCNFG_EEE_2_5G_AN 0x00000010/* IPCNFG EEE Ena 2.5G AN */ +#define IGC_IPCNFG_EEE_1G_AN 0x00000008/* IPCNFG EEE Ena 1G AN */ +#define IGC_IPCNFG_EEE_100M_AN 0x00000004/* IPCNFG EEE Ena 100M AN */ +#define IGC_EEER_EEE_NEG 0x20000000/* EEE capability nego */ +#define IGC_EEER_TX_LPI_EN 0x00010000/* EEER Tx LPI Enable */ +#define IGC_EEER_RX_LPI_EN 0x00020000/* EEER Rx LPI Enable */ +#define IGC_EEER_LPI_FC 0x00040000/* EEER Ena on Flow Cntrl */ +#define IGC_EEE_SU_LPI_CLK_STP 0x00800000/* EEE LPI Clock Stop */ +#endif /* _IGC_DEFINES_H_ */
drivers/net/ethernet/intel/igc/igc_ethtool.c +104 -0
122 lines not on this page · raw message
drivers/net/ethernet/intel/igc/igc_hw.h +1 -0
@@ -191,6 +191,7 @@ struct igc_fc_info {struct igc_dev_spec_base {bool clear_semaphore_once; +bool eee_disable; };struct igc_hw {
drivers/net/ethernet/intel/igc/igc_i225.c +61 -0
64 lines not on this page · raw message
drivers/net/ethernet/intel/igc/igc_i225.h +2 -0
@@ -9,5 +9,7 @@ void igc_release_swfw_sync_i225(struct igc_hw *hw, u16 mask);s32 igc_init_nvm_params_i225 (struct igc_hw *hw);bool igc_get_flash_presence_i225 (struct igc_hw *hw); +s32 igc_set_eee_i225 (struct igc_hw *hw,bool adv2p5G,bool adv1G, +bool adv100M);#endif
drivers/net/ethernet/intel/igc/igc_main.c +17 -0
@@ -105,6 +105,10 @@ void igc_reset(struct igc_adapter *adapter)if (hw->mac.ops.init_hw (hw))netdev_err (dev,"Error on hardware initialization" ); +/* Re-establish EEE setting */ +if (hw->phy.media_type == igc_media_type_copper) +igc_set_eee_i225 (hw, true, true, true); +if (!netif_running (adapter->netdev))igc_power_down_link (adapter);
@@ -4259,6 +4263,15 @@ static void igc_watchdog_task(struct work_struct *work) (ctrl &IGC_CTRL_RFCE ) ?"RX" : (ctrl & IGC_CTRL_TFCE) ? "TX" : "None"); +/* disable EEE if enabled */ +if ((adapter->flags &IGC_FLAG_EEE ) && + adapter->link_duplex ==HALF_DUPLEX ) { +netdev_info (netdev, +"EEE Disabled: unsupported at half duplex. Re-enable using ethtool when at full duplex\n" ); + adapter->hw.dev_spec._base.eee_disable = true; + adapter->flags &= ~IGC_FLAG_EEE ; + } +/* check if SmartSpeed worked */ igc_check_downshift (hw);if (phy->speed_downgraded)
@@ -5190,6 +5203,10 @@ static int igc_probe(struct pci_dev *pdev,netdev_info (netdev,"MAC: %pM" , netdev->dev_addr);dev_pm_set_driver_flags (&pdev->dev,DPM_FLAG_NEVER_SKIP ); +/* Disable EEE for internal copper PHY devices */ + hw->dev_spec._base.eee_disable = true; + adapter->flags &= ~IGC_FLAG_EEE ; +igc_set_eee_i225 (hw, false, false, false);pm_runtime_put_noidle (&pdev->dev);
drivers/net/ethernet/intel/igc/igc_regs.h +5 -0
@@ -249,6 +249,11 @@/* Wake Up packet memory */ #define IGC_WUPM_REG (_i) (0x05A00 + ((_i) * 4)) +/* Energy Efficient Ethernet "EEE" registers */ +#define IGC_EEER 0x0E30/* Energy Efficient Ethernet "EEE"*/ +#define IGC_IPCNFG 0x0E38/* Internal PHY Configuration */ +#define IGC_EEE_SU 0x0E34/* EEE Setup */ +/* forward declaration */ struct igc_hw ;u32 igc_rd32 (struct igc_hw *hw,u32 reg);
Signature · 1 line
2.11.0
PATCH 1/1 igc: Add initial EEE support
Hi Sasha,
drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) · line 1565
Quoted 13 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +13
-0+static int igc_ethtool_get_eee (struct net_device *netdev, +struct ethtool_eee *edata) +{ +struct igc_adapter *adapter =netdev_priv (netdev); +struct igc_hw *hw = &adapter->hw; +u32 eeer; + +if (!hw->dev_spec._base.eee_disable) + edata->advertised = +mmd_eee_adv_to_ethtool_adv_t (adapter->eee_advert); + + *edata = adapter->eee; + edata->supported = (SUPPORTED_Autoneg);
Nitpicking: The surrounding parentheses here looks pointless.
drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) · line 1567
Quoted 2 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +2
-0+netdev_info (netdev, +"Supported EEE link modes: 100baseT/Full, 1000baseT/Full, 2500baseT/Full" );
Although the '\n' is automatically added to this message, from the discussion in [1], the preference is that we keep putting it at the end of our logging messages.
This comment applies to all other log messages in this patch.
drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) · line 1605
Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +10
-0+static int igc_ethtool_set_eee (struct net_device *netdev, +struct ethtool_eee *edata) +{ +struct igc_adapter *adapter =netdev_priv (netdev); +struct igc_hw *hw = &adapter->hw; +struct ethtool_eee eee_curr; +s32 ret_val; + +if (hw->phy.media_type != igc_media_type_copper) +return -EOPNOTSUPP ;
It looks 'igc_media_type_copper' is the only media_type supported by the driver, at least up till now. I'm wondering if we could get rid of it and simplify the code.
Quoted 11 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +11
-0+ +memset (&eee_curr,0 ,sizeof (struct ethtool_eee )); + + ret_val =igc_ethtool_get_eee (netdev, &eee_curr); +if (ret_val) +return ret_val; + +if (eee_curr.eee_enabled) { +if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) { +netdev_err (netdev, +"Setting EEE tx-lpi is not supported" );
drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) · line 1626
Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +10
-0+return -EINVAL ; + } + +/* Tx LPI timer is not implemented currently */ +if (edata->tx_lpi_timer) { +netdev_err (netdev, +"Setting EEE Tx LPI timer is not supported" ); +return -EINVAL ; + } +
It seems we have an empty line here by mistake.
drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) · line 1634
Quoted 8 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +8
-0+ }else if (!edata->eee_enabled) { +netdev_err (netdev, +"Setting EEE options are not supported with EEE disabled" ); +return -EINVAL ; + } + + adapter->eee_advert =ethtool_adv_to_mmd_eee_adv_t (edata->advertised); +if (hw->dev_spec._base.eee_disable != !edata->eee_enabled) {
In every occurrence of _base.eee_disable we use the '!' operator like in the line above. I think the code would be more readable if we inverted the logic and had _base.eee_enable instead.
drivers/net/ethernet/intel/igc/igc_i225.c s32 igc_init_nvm_params_i225(struct igc_hw *hw) · line 508
Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_i225.c +7
-0+s32 igc_set_eee_i225 (struct igc_hw *hw,bool adv2p5G,bool adv1G, +bool adv100M) +{ +u32 ipcnfg, eeer; + +if (hw->mac.type != igc_i225 || + hw->phy.media_type != igc_media_type_copper)
The same comment I made above about checking for 'igc_media_type_copper' applies here too.
It looks 'igc_i225' is the only hw->mac.type supported by the driver, at least up till now. I'm wondering if we could get rid of it and simplify the code.
Regards,
Andre
[1] https://lore.kernel.org/netdev/20200421.153221.2089591404052111123.davem at davemloft.net/
Neftin
PATCH 1/1 igc: Add initial EEE support
Quoted 18 lines · Andre Guedes
Hi Sasha,
drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) · line 1565
Quoted 13 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +13
-0+static int igc_ethtool_get_eee (struct net_device *netdev, +struct ethtool_eee *edata) +{ +struct igc_adapter *adapter =netdev_priv (netdev); +struct igc_hw *hw = &adapter->hw; +u32 eeer; + +if (!hw->dev_spec._base.eee_disable) + edata->advertised = +mmd_eee_adv_to_ethtool_adv_t (adapter->eee_advert); + + *edata = adapter->eee; + edata->supported = (SUPPORTED_Autoneg);Nitpicking: The surrounding parentheses here looks pointless.
I will fix it in v2
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) · line 1567
Quoted 2 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +2
-0+netdev_info (netdev, +"Supported EEE link modes: 100baseT/Full, 1000baseT/Full, 2500baseT/Full" );Although the '\n' is automatically added to this message, from the discussion in [1], the preference is that we keep putting it at the end of our logging messages.
This comment applies to all other log messages in this patch.
yeah... we will need do that for all rest code where we removed "\n". I will take care for code relvant to this patch only. Other netdev_* should be changed too.
Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +6
-0+static int igc_ethtool_set_eee (struct net_device *netdev, +struct ethtool_eee *edata) +{ +struct igc_adapter *adapter =netdev_priv (netdev); +struct igc_hw *hw = &adapter->hw; +struct ethtool_eee eee_curr;
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) · line 1605
Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +4
-0+s32 ret_val; + +if (hw->phy.media_type != igc_media_type_copper) +return -EOPNOTSUPP ;It looks '
igc_media_type_copper' is the onlymedia_typesupported by the driver, at least up till now. I'm wondering if we could get rid of it and simplify the code.
Will fix in v2.
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +15
-0+ +memset (&eee_curr,0 ,sizeof (struct ethtool_eee )); + + ret_val =igc_ethtool_get_eee (netdev, &eee_curr); +if (ret_val) +return ret_val; + +if (eee_curr.eee_enabled) { +if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) { +netdev_err (netdev, +"Setting EEE tx-lpi is not supported" ); +return -EINVAL ; + } + +/* Tx LPI timer is not implemented currently */
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) · line 1626
Quoted 6 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +6
-0+if (edata->tx_lpi_timer) { +netdev_err (netdev, +"Setting EEE Tx LPI timer is not supported" ); +return -EINVAL ; + } +It seems we have an empty line here by mistake.
Will fix in v2.
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) · line 1634
Quoted 8 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +8
-0+ }else if (!edata->eee_enabled) { +netdev_err (netdev, +"Setting EEE options are not supported with EEE disabled" ); +return -EINVAL ; + } + + adapter->eee_advert =ethtool_adv_to_mmd_eee_adv_t (edata->advertised); +if (hw->dev_spec._base.eee_disable != !edata->eee_enabled) {
Quoted 4 lines
In every occurrence of _base.eee_disable we use the '!' operator like in the line above. I think the code would be more readable if we inverted the logic and had _base.eee_enable instead.
I agree. Actually all Intel drivers used inverted logic. Indeed will be more readable. Will fix in v2.
Quoted 11 lines
drivers/net/ethernet/intel/igc/igc_i225.c s32 igc_init_nvm_params_i225(struct igc_hw *hw) · line 508
Quoted 7 lines
drivers/net/ethernet/intel/igc/igc_i225.c +7
-0+s32 igc_set_eee_i225 (struct igc_hw *hw,bool adv2p5G,bool adv1G, +bool adv100M) +{ +u32 ipcnfg, eeer; + +if (hw->mac.type != igc_i225 || + hw->phy.media_type != igc_media_type_copper)The same comment I made above about checking for '
igc_media_type_copper' applies here too.
Will fix in v2.
Quoted 3 lines
It looks '
igc_i225' is the onlyhw->mac.typesupported by the driver, at least up till now. I'm wondering if we could get rid of it and simplify the code.
Right, mac_type and media_type is only one for i225 part. I think we will clean up it in separated patches.
Quoted 6 lines
Regards,
Andre
[1] https://lore.kernel.org/netdev/20200421.153221.2089591404052111123.davem at davemloft.net/
Hello Andre, thanks for review