Skip to content

Commit

Permalink
Merge branch 'lan743x-phylink'
Browse files Browse the repository at this point in the history
Raju Lakkaraju says:

====================
Add support to PHYLINK for LAN743x/PCI11x1x chips

This is the follow-up patch series of
https://lkml.iu.edu/hypermail/linux/kernel/2310.2/02078.html

Divide the PHYLINK adaptation and SFP modifications into two separate patch
series.

The current patch series focuses on transitioning the LAN743x driver's PHY
support from phylib to phylink.

Tested on PCI11010 Rev-1 Evaluation board

Change List:
============
V5 -> V6:
  - Remove the lan743x_find_max_speed( ) function. Not require
  - Add EEE enable check before calling lan743x_mac_eee_enable( ) function
V4 -> V5:
  - Remove the fixed_phy_unregister( ) function. Not require
  - Remove the "phydev->eee_enabled" check to update the MAC EEE
    enable/disable
  - Call lan743x_mac_eee_enable() with true after update tx_lpi_timer.
  - Add phy_support_eee() to initialize the EEE flags
V3 -> V4:
  - Add fixed-link patch along with this series.
    Note: Note: This code was developed by Mr.Russell King
    Ref:
    https://lore.kernel.org/netdev/LV8PR11MB8700C786F5F1C274C73036CC9F8E2@LV8PR11MB8700.namprd11.prod.outlook.com/T/#me943adf54f1ea082edf294aba448fa003a116815
  - Change phylink fixed-link function header's string from "Returns" to
    "Returns:"
  - Remove the EEE private variable from LAN743x adapter strcture and fix the
    EEE's set/get functions
  - set the individual caps (i.e. _RGMII, _RGMII_ID, _RGMII_RXID and
    __RGMII_TXID) replace with phy_interface_set_rgmii( ) function
  - Change lan743x_set_eee( ) to lan743x_mac_eee_enable( )

V2 -> V3:
  - Remove the unwanted parens in each of these if() sub-blocks
  - Replace "to_net_dev(config->dev)" with "netdev".
  - Add GMII_ID/RGMII_TXID/RGMII_RXID in supported_interfaces
  - Fix the lan743x_phy_handle_exists( ) return type

V1 -> V2:
  - Fix the Russell King's comments i.e. remove the speed, duplex update in
    lan743x_phylink_mac_config( )
  - pre-March 2020 legacy support has been removed

V0 -> V1:
  - Integrate with Synopsys DesignWare XPCS drivers
  - Based on external review comments,
  - Changes made to SGMII interface support only 1G/100M/10M bps speed
  - Changes made to 2500Base-X interface support only 2.5Gbps speed
  - Add check for not is_sgmii_en with is_sfp_support_en support
  - Change the "pci11x1x_strap_get_status" function return type from void to
    int
  - Add ethtool phylink wol, eee, pause get/set functions
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
davem330 committed Sep 11, 2024
2 parents f3b6129 + f95f28d commit bf73478
Show file tree
Hide file tree
Showing 6 changed files with 498 additions and 324 deletions.
5 changes: 3 additions & 2 deletions drivers/net/ethernet/microchip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ config LAN743X
tristate "LAN743x support"
depends on PCI
depends on PTP_1588_CLOCK_OPTIONAL
select PHYLIB
select FIXED_PHY
select CRC16
select CRC32
select PHYLINK
help
Support for the Microchip LAN743x PCI Express Gigabit Ethernet chip
Support for the Microchip LAN743x and PCI11x1x families of PCI
Express Ethernet devices

To compile this driver as a module, choose M here. The module will be
called lan743x.
Expand Down
123 changes: 44 additions & 79 deletions drivers/net/ethernet/microchip/lan743x_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,61 +1054,55 @@ static int lan743x_ethtool_get_eee(struct net_device *netdev,
struct ethtool_keee *eee)
{
struct lan743x_adapter *adapter = netdev_priv(netdev);
struct phy_device *phydev = netdev->phydev;
u32 buf;
int ret;

if (!phydev)
return -EIO;
if (!phydev->drv) {
netif_err(adapter, drv, adapter->netdev,
"Missing PHY Driver\n");
return -EIO;
}

ret = phy_ethtool_get_eee(phydev, eee);
if (ret < 0)
return ret;
eee->tx_lpi_timer = lan743x_csr_read(adapter,
MAC_EEE_TX_LPI_REQ_DLY_CNT);

buf = lan743x_csr_read(adapter, MAC_CR);
if (buf & MAC_CR_EEE_EN_) {
/* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */
buf = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT);
eee->tx_lpi_timer = buf;
} else {
eee->tx_lpi_timer = 0;
}

return 0;
return phylink_ethtool_get_eee(adapter->phylink, eee);
}

static int lan743x_ethtool_set_eee(struct net_device *netdev,
struct ethtool_keee *eee)
{
struct lan743x_adapter *adapter;
struct phy_device *phydev;
u32 buf = 0;
struct lan743x_adapter *adapter = netdev_priv(netdev);
u32 tx_lpi_timer;

if (!netdev)
return -EINVAL;
adapter = netdev_priv(netdev);
if (!adapter)
return -EINVAL;
phydev = netdev->phydev;
if (!phydev)
return -EIO;
if (!phydev->drv) {
netif_err(adapter, drv, adapter->netdev,
"Missing PHY Driver\n");
return -EIO;
}
tx_lpi_timer = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT);
if (tx_lpi_timer != eee->tx_lpi_timer) {
u32 mac_cr = lan743x_csr_read(adapter, MAC_CR);

/* Software should only change this field when Energy Efficient
* Ethernet Enable (EEEEN) is cleared.
* This function will trigger an autonegotiation restart and
* eee will be reenabled during link up if eee was negotiated.
*/
lan743x_mac_eee_enable(adapter, false);
lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT,
eee->tx_lpi_timer);

if (eee->eee_enabled) {
buf = (u32)eee->tx_lpi_timer;
lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, buf);
if (mac_cr & MAC_CR_EEE_EN_)
lan743x_mac_eee_enable(adapter, true);
}

return phy_ethtool_set_eee(phydev, eee);
return phylink_ethtool_set_eee(adapter->phylink, eee);
}

static int
lan743x_ethtool_set_link_ksettings(struct net_device *netdev,
const struct ethtool_link_ksettings *cmd)
{
struct lan743x_adapter *adapter = netdev_priv(netdev);

return phylink_ethtool_ksettings_set(adapter->phylink, cmd);
}

static int
lan743x_ethtool_get_link_ksettings(struct net_device *netdev,
struct ethtool_link_ksettings *cmd)
{
struct lan743x_adapter *adapter = netdev_priv(netdev);

return phylink_ethtool_ksettings_get(adapter->phylink, cmd);
}

#ifdef CONFIG_PM
Expand All @@ -1120,8 +1114,7 @@ static void lan743x_ethtool_get_wol(struct net_device *netdev,
wol->supported = 0;
wol->wolopts = 0;

if (netdev->phydev)
phy_ethtool_get_wol(netdev->phydev, wol);
phylink_ethtool_get_wol(adapter->phylink, wol);

if (wol->supported != adapter->phy_wol_supported)
netif_warn(adapter, drv, adapter->netdev,
Expand Down Expand Up @@ -1162,7 +1155,7 @@ static int lan743x_ethtool_set_wol(struct net_device *netdev,
!(adapter->phy_wol_supported & WAKE_MAGICSECURE))
phy_wol.wolopts &= ~WAKE_MAGIC;

ret = phy_ethtool_set_wol(netdev->phydev, &phy_wol);
ret = phylink_ethtool_set_wol(adapter->phylink, wol);
if (ret && (ret != -EOPNOTSUPP))
return ret;

Expand Down Expand Up @@ -1351,44 +1344,16 @@ static void lan743x_get_pauseparam(struct net_device *dev,
struct ethtool_pauseparam *pause)
{
struct lan743x_adapter *adapter = netdev_priv(dev);
struct lan743x_phy *phy = &adapter->phy;

if (phy->fc_request_control & FLOW_CTRL_TX)
pause->tx_pause = 1;
if (phy->fc_request_control & FLOW_CTRL_RX)
pause->rx_pause = 1;
pause->autoneg = phy->fc_autoneg;
phylink_ethtool_get_pauseparam(adapter->phylink, pause);
}

static int lan743x_set_pauseparam(struct net_device *dev,
struct ethtool_pauseparam *pause)
{
struct lan743x_adapter *adapter = netdev_priv(dev);
struct phy_device *phydev = dev->phydev;
struct lan743x_phy *phy = &adapter->phy;

if (!phydev)
return -ENODEV;

if (!phy_validate_pause(phydev, pause))
return -EINVAL;

phy->fc_request_control = 0;
if (pause->rx_pause)
phy->fc_request_control |= FLOW_CTRL_RX;

if (pause->tx_pause)
phy->fc_request_control |= FLOW_CTRL_TX;

phy->fc_autoneg = pause->autoneg;

if (pause->autoneg == AUTONEG_DISABLE)
lan743x_mac_flow_ctrl_set_enables(adapter, pause->tx_pause,
pause->rx_pause);
else
phy_set_asym_pause(phydev, pause->rx_pause, pause->tx_pause);

return 0;
return phylink_ethtool_set_pauseparam(adapter->phylink, pause);
}

const struct ethtool_ops lan743x_ethtool_ops = {
Expand All @@ -1413,8 +1378,8 @@ const struct ethtool_ops lan743x_ethtool_ops = {
.get_ts_info = lan743x_ethtool_get_ts_info,
.get_eee = lan743x_ethtool_get_eee,
.set_eee = lan743x_ethtool_set_eee,
.get_link_ksettings = phy_ethtool_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings,
.get_link_ksettings = lan743x_ethtool_get_link_ksettings,
.set_link_ksettings = lan743x_ethtool_set_link_ksettings,
.get_regs_len = lan743x_get_regs_len,
.get_regs = lan743x_get_regs,
.get_pauseparam = lan743x_get_pauseparam,
Expand Down
Loading

0 comments on commit bf73478

Please sign in to comment.