r8169: add phylib support
Heiner Kallweit
maintainerv3 cover r8169: add phylib support
Now that all the basic refactoring has been done we can add phylib support. This patch series was successfully tested on:
RTL8168h
RTL8168evl
RTL8169sb
Changes in v2:
- return error in mdio ops if phyaddr > 0
- advertise pause modes
- added reviewed-by for several patches
Changes in v3:
- return ENODEV for unused phy addresses in mdio ops
- remove unneeded PHY suspend in patch 2
- use recently added phy_speed_down and phy_speed_up in patch 7
- other minor changes based on review comments
Heiner Kallweit (10):
r8169: add basic phylib support
r8169: use phy_resume/phy_suspend
r8169: replace open-coded PHY soft reset with genphy_soft_reset
r8169: use phy_ethtool_(g|s)et_link_ksettings
r8169: use phy_ethtool_nway_reset
r8169: use phy_mii_ioctl
r8169: use phy_speed_down / phy_speed_up
r8169: remove rtl8169_set_speed_xmii
r8169: remove mii_if_info member from struct rtl8169_private
r8169: don't read chip phy status register
drivers/net/ethernet/realtek/Kconfig | 2 +- drivers/net/ethernet/realtek/r8169.c | 465 +++++++++------------------ 2 files changed, 155 insertions(+), 312 deletions(-)
Signature · 1 line
2.18.0
Heiner Kallweit
maintainerPATCH v3 1/10 r8169: add basic phylib support
Add basic phylib support to r8169. All now unneeded old PHY handling code will be removed in subsequent patches.
---
v2:
- return error in mdio ops if phyaddr > 0
- advertise pause modes
v3:
- return ENODEV in mdio ops if phyaddr > 0
- consider other minor review comments
--- drivers/net/ethernet/realtek/Kconfig | 1 + drivers/net/ethernet/realtek/r8169.c | 159 +++++++++++++++++++++------ 2 files changed, 128 insertions(+), 32 deletions(-)
drivers/net/ethernet/realtek/Kconfig +1 -0
@@ -99,6 +99,7 @@ config R8169 depends on PCI select FW_LOADER select CRC32 + select PHYLIB select MII ---help--- Say Y here if you have a Realtek 8169 PCI Gigabit Ethernet adapter.
drivers/net/ethernet/realtek/r8169.c +127 -32
273 lines not on this page · raw message
Signature · 1 line
2.18.0
Heiner Kallweit
maintainerPATCH v3 2/10 r8169: use phy_resume/phy_suspend
In reply to Heiner KallweitUse phy_resume() / phy_suspend() instead of open coding this functionality. The chip version specific differences are handled by the respective PHY drivers.
The call to r8168_phy_power_down() in r8168_pll_power_down() can be removed because phylib takes care now. The relevant scenarios are:
- rtl8169_close(): phy_disconnect() powers down PHY
- suspend: mdio_bus_phy_suspend() takes care
- runtime-suspend: WoL is active, don't suspend PHY
- rtl_shutdown(): no need to power down PHY
---
v2:
- no changes
v3:
- remove unneeded call to r8168_phy_power_down()
--- drivers/net/ethernet/realtek/r8169.c | 50 ++++------------------------ 1 file changed, 6 insertions(+), 44 deletions(-)
drivers/net/ethernet/realtek/r8169.c +6 -44
@@ -4450,47 +4450,6 @@ static bool rtl_wol_pll_power_down(struct rtl8169_private *tp)return true; } -static void r8168_phy_power_up (struct rtl8169_private *tp) -{ -rtl_writephy (tp,0x1f ,0x0000 ); -switch (tp->mac_version) { -case RTL_GIGA_MAC_VER_11 : -case RTL_GIGA_MAC_VER_12 : - case RTL_GIGA_MAC_VER_17 ... RTL_GIGA_MAC_VER_28: -case RTL_GIGA_MAC_VER_31 : -rtl_writephy (tp,0x0e ,0x0000 ); -break ; -default : -break ; - } -rtl_writephy (tp,MII_BMCR ,BMCR_ANENABLE ); - -/* give MAC/PHY some time to resume */ -msleep (20 ); -} - -static void r8168_phy_power_down (struct rtl8169_private *tp) -{ -rtl_writephy (tp,0x1f ,0x0000 ); -switch (tp->mac_version) { -case RTL_GIGA_MAC_VER_32 : -case RTL_GIGA_MAC_VER_33 : -case RTL_GIGA_MAC_VER_40 : -case RTL_GIGA_MAC_VER_41 : -rtl_writephy (tp,MII_BMCR ,BMCR_ANENABLE |BMCR_PDOWN ); -break ; - -case RTL_GIGA_MAC_VER_11 : -case RTL_GIGA_MAC_VER_12 : - case RTL_GIGA_MAC_VER_17 ... RTL_GIGA_MAC_VER_28: -case RTL_GIGA_MAC_VER_31 : -rtl_writephy (tp,0x0e ,0x0200 ); -default : -rtl_writephy (tp,MII_BMCR ,BMCR_PDOWN ); -break ; - } -} -static void r8168_pll_power_down (struct rtl8169_private *tp) {if (r8168_check_dash (tp))
@@ -4503,8 +4462,6 @@ static void r8168_pll_power_down(struct rtl8169_private *tp)if (rtl_wol_pll_power_down (tp))return ; -r8168_phy_power_down (tp); -switch (tp->mac_version) { case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33:case RTL_GIGA_MAC_VER_37 :
@@ -4556,7 +4513,9 @@ static void r8168_pll_power_up(struct rtl8169_private *tp)break ; } -r8168_phy_power_up (tp); +phy_resume (tp->dev->phydev); +/* give MAC/PHY some time to resume */ +msleep (20 ); }static void rtl_pll_power_down (struct rtl8169_private *tp)
@@ -7470,6 +7429,9 @@ static int r8169_mdio_register(struct rtl8169_private *tp)return -ENODEV ; } +/* PHY will be woken up in rtl_open() */ +phy_suspend (phydev); + tp->mii_bus = new_bus;return 0 ;
Signature · 1 line
2.18.0
Heiner Kallweit
maintainerPATCH v3 3/10 r8169: replace open-coded PHY soft reset with genphy_soft_reset
In reply to Heiner KallweitUse genphy_soft_reset() instead of open-coding a PHY soft reset. We have to do an explicit PHY soft reset because some chips use the genphy driver which uses a no-op as soft_reset callback.
--- drivers/net/ethernet/realtek/r8169.c | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-)
drivers/net/ethernet/realtek/r8169.c +1 -26
@@ -1441,19 +1441,6 @@ static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp)RTL_R8 (tp, ChipCmd); } -static unsigned int rtl8169_xmii_reset_pending (struct rtl8169_private *tp) -{ -return rtl_readphy (tp,MII_BMCR ) &BMCR_RESET ; -} - -static void rtl8169_xmii_reset_enable (struct rtl8169_private *tp) -{ -unsigned int val; - - val =rtl_readphy (tp,MII_BMCR ) |BMCR_RESET ; -rtl_writephy (tp,MII_BMCR , val &0xffff ); -} -static void rtl_link_chg_patch (struct rtl8169_private *tp) {struct net_device *dev = tp->dev;
@@ -4252,18 +4239,6 @@ static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag)schedule_work (&tp->wk.work); } -DECLARE_RTL_COND (rtl_phy_reset_cond) -{ -return rtl8169_xmii_reset_pending (tp); -} - -static void rtl8169_phy_reset (struct net_device *dev, -struct rtl8169_private *tp) -{ -rtl8169_xmii_reset_enable (tp); -rtl_msleep_loop_wait_low (tp, &rtl_phy_reset_cond,1 ,100 ); -} -static bool rtl_tbi_enabled (struct rtl8169_private *tp) { return (tp->mac_version == RTL_GIGA_MAC_VER_01) &&
@@ -4294,7 +4269,7 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)rtl_writephy (tp,0x0b ,0x0000 );//w 0x0b 15 0 0 } -rtl8169_phy_reset (dev, tp); +genphy_soft_reset (dev->phydev); rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
Signature · 1 line
2.18.0
Heiner Kallweit
maintainerPATCH v3 4/10 r8169: use phy_ethtool_(g|s)et_link_ksettings
In reply to Heiner KallweitUse phy_ethtool_(g|s)et_link_ksettings() for the respective ethtool_ops callbacks.
--- drivers/net/ethernet/realtek/r8169.c | 35 +++------------------------- 1 file changed, 3 insertions(+), 32 deletions(-)
drivers/net/ethernet/realtek/r8169.c +3 -32
@@ -1809,35 +1809,6 @@ static void rtl8169_rx_vlan_tag(struct RxDesc *desc, struct sk_buff *skb)__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ),swab16 (opts2 &0xffff )); } -static int rtl8169_get_link_ksettings (struct net_device *dev, -struct ethtool_link_ksettings *cmd) -{ -struct rtl8169_private *tp =netdev_priv (dev); - -mii_ethtool_get_link_ksettings (&tp->mii, cmd); - -return 0 ; -} - -static int rtl8169_set_link_ksettings (struct net_device *dev, -const struct ethtool_link_ksettings *cmd) -{ -struct rtl8169_private *tp =netdev_priv (dev); -int rc; -u32 advertising; - -if (!ethtool_convert_link_mode_to_legacy_u32 (&advertising, - cmd->link_modes.advertising)) -return -EINVAL ; - -rtl_lock_work (tp); - rc =rtl8169_set_speed (dev, cmd->base.autoneg, cmd->base.speed, - cmd->base.duplex, advertising); -rtl_unlock_work (tp); - -return rc; -} -static void rtl8169_get_regs (struct net_device *dev,struct ethtool_regs *regs,void *p) {
@@ -2092,7 +2063,7 @@ static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev)const struct rtl_coalesce_info *ci;int rc; - rc =rtl8169_get_link_ksettings (dev, &ecmd); + rc =phy_ethtool_get_link_ksettings (dev, &ecmd);if (rc <0 )return ERR_PTR (rc);
@@ -2251,8 +2222,8 @@ static const struct ethtool_ops rtl8169_ethtool_ops = { .get_ethtool_stats = rtl8169_get_ethtool_stats, .get_ts_info = ethtool_op_get_ts_info, .nway_reset = rtl8169_nway_reset, - .get_link_ksettings = rtl8169_get_link_ksettings, - .set_link_ksettings = rtl8169_set_link_ksettings, + .get_link_ksettings = phy_ethtool_get_link_ksettings, + .set_link_ksettings = phy_ethtool_set_link_ksettings, }; static void rtl8169_get_mac_version(struct rtl8169_private *tp,
Signature · 1 line
2.18.0
Heiner Kallweit
maintainerPATCH v3 5/10 r8169: use phy_ethtool_nway_reset
In reply to Heiner KallweitSwitch to using phy_ethtool_nway_reset().
--- drivers/net/ethernet/realtek/Kconfig | 1 - drivers/net/ethernet/realtek/r8169.c | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-)
drivers/net/ethernet/realtek/Kconfig +0 -1
@@ -100,7 +100,6 @@ config R8169 select FW_LOADER select CRC32 select PHYLIB - select MII ---help--- Say Y here if you have a Realtek 8169 PCI Gigabit Ethernet adapter.
drivers/net/ethernet/realtek/r8169.c +1 -8
@@ -1984,13 +1984,6 @@ static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) } } -static int rtl8169_nway_reset (struct net_device *dev) -{ -struct rtl8169_private *tp =netdev_priv (dev); - -return mii_nway_restart (&tp->mii); -} -/* * Interrupt coalescing *
@@ -2221,7 +2214,7 @@ static const struct ethtool_ops rtl8169_ethtool_ops = { .get_sset_count = rtl8169_get_sset_count, .get_ethtool_stats = rtl8169_get_ethtool_stats, .get_ts_info = ethtool_op_get_ts_info, - .nway_reset = rtl8169_nway_reset, + .nway_reset = phy_ethtool_nway_reset, .get_link_ksettings = phy_ethtool_get_link_ksettings, .set_link_ksettings = phy_ethtool_set_link_ksettings, };
Signature · 1 line
2.18.0
Heiner Kallweit
maintainerPATCH v3 6/10 r8169: use phy_mii_ioctl
In reply to Heiner KallweitSwitch to using phy_mii_ioctl().
--- drivers/net/ethernet/realtek/r8169.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-)
drivers/net/ethernet/realtek/r8169.c +3 -22
@@ -4283,31 +4283,12 @@ static int rtl_set_mac_address(struct net_device *dev, void *p)return 0 ; } -static int rtl_xmii_ioctl (struct rtl8169_private *tp, -struct mii_ioctl_data *data,int cmd) -{ -switch (cmd) { -case SIOCGMIIPHY : - data->phy_id =32 ;/* Internal PHY */ -return 0 ; - -case SIOCGMIIREG : - data->val_out =rtl_readphy (tp, data->reg_num &0x1f ); -return 0 ; - -case SIOCSMIIREG : -rtl_writephy (tp, data->reg_num &0x1f , data->val_in); -return 0 ; - } -return -EOPNOTSUPP ; -} -static int rtl8169_ioctl (struct net_device *dev,struct ifreq *ifr,int cmd) { -struct rtl8169_private *tp =netdev_priv (dev); -struct mii_ioctl_data *data =if_mii (ifr); +if (!netif_running (dev)) +return -ENODEV ; -return netif_running (dev) ?rtl_xmii_ioctl (tp, data, cmd) : -ENODEV ; +return phy_mii_ioctl (dev->phydev, ifr, cmd); }static void rtl_init_mdio_ops (struct rtl8169_private *tp)
Signature · 1 line
2.18.0
Heiner Kallweit
maintainerPATCH v3 7/10 r8169: use phy_speed_down / phy_speed_up
In reply to Heiner KallweitUse new phylib functions phy_speed_down() and phy_speed_up().
--- drivers/net/ethernet/realtek/r8169.c | 29 ++++------------------------ 1 file changed, 4 insertions(+), 25 deletions(-)
drivers/net/ethernet/realtek/r8169.c +4 -25
@@ -4233,6 +4233,9 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)rtl_writephy (tp,0x0b ,0x0000 );//w 0x0b 15 0 0 } +/* We may have called phy_speed_down before */ +phy_speed_up (dev->phydev); +genphy_soft_reset (dev->phydev); rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL,
@@ -4316,30 +4319,6 @@ static void rtl_init_mdio_ops(struct rtl8169_private *tp) } } -static void rtl_speed_down (struct rtl8169_private *tp) -{ -u32 adv; -int lpa; - -rtl_writephy (tp,0x1f ,0x0000 ); - lpa =rtl_readphy (tp,MII_LPA ); - -if (lpa & (LPA_10HALF |LPA_10FULL )) - adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full; -else if (lpa & (LPA_100HALF |LPA_100FULL )) - adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | - ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; -else - adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | - ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | - (tp->mii.supports_gmii ? - ADVERTISED_1000baseT_Half | - ADVERTISED_1000baseT_Full :0 ); - -rtl8169_set_speed (tp->dev,AUTONEG_ENABLE ,SPEED_1000 ,DUPLEX_FULL , - adv); -} -static void rtl_wol_suspend_quirk (struct rtl8169_private *tp) {switch (tp->mac_version) {
@@ -4364,7 +4343,7 @@ static bool rtl_wol_pll_power_down(struct rtl8169_private *tp)if (!netif_running (tp->dev) || !__rtl8169_get_wol (tp))return false; -rtl_speed_down (tp); +phy_speed_down (tp->dev->phydev, false);rtl_wol_suspend_quirk (tp);return true;
Signature · 1 line
2.18.0
Heiner Kallweit
maintainerPATCH v3 8/10 r8169: remove rtl8169_set_speed_xmii
In reply to Heiner KallweitWe can remove rtl8169_set_speed_xmii() now that phylib handles all this.
--- drivers/net/ethernet/realtek/r8169.c | 90 ---------------------------- 1 file changed, 90 deletions(-)
drivers/net/ethernet/realtek/r8169.c +0 -90
@@ -1663,89 +1663,6 @@ static int rtl8169_get_regs_len(struct net_device *dev)return R8169_REGS_SIZE ; } -static int rtl8169_set_speed_xmii (struct net_device *dev, -u8 autoneg,u16 speed,u8 duplex,u32 adv) -{ -struct rtl8169_private *tp =netdev_priv (dev); -int giga_ctrl, bmcr; -int rc = -EINVAL ; - -rtl_writephy (tp,0x1f ,0x0000 ); - -if (autoneg ==AUTONEG_ENABLE ) { -int auto_nego; - - auto_nego =rtl_readphy (tp,MII_ADVERTISE ); - auto_nego &= ~(ADVERTISE_10HALF |ADVERTISE_10FULL | -ADVERTISE_100HALF |ADVERTISE_100FULL ); - -if (adv & ADVERTISED_10baseT_Half) - auto_nego |=ADVERTISE_10HALF ; -if (adv & ADVERTISED_10baseT_Full) - auto_nego |=ADVERTISE_10FULL ; -if (adv & ADVERTISED_100baseT_Half) - auto_nego |=ADVERTISE_100HALF ; -if (adv & ADVERTISED_100baseT_Full) - auto_nego |=ADVERTISE_100FULL ; - - auto_nego |=ADVERTISE_PAUSE_CAP |ADVERTISE_PAUSE_ASYM ; - - giga_ctrl =rtl_readphy (tp,MII_CTRL1000 ); - giga_ctrl &= ~(ADVERTISE_1000FULL |ADVERTISE_1000HALF ); - -/* The 8100e/8101e/8102e do Fast Ethernet only. */ -if (tp->mii.supports_gmii) { -if (adv & ADVERTISED_1000baseT_Half) - giga_ctrl |=ADVERTISE_1000HALF ; -if (adv & ADVERTISED_1000baseT_Full) - giga_ctrl |=ADVERTISE_1000FULL ; - }else if (adv & (ADVERTISED_1000baseT_Half | - ADVERTISED_1000baseT_Full)) { -netif_info (tp, link, dev, -"PHY does not support 1000Mbps\n" ); - goto out; - } - - bmcr =BMCR_ANENABLE |BMCR_ANRESTART ; - -rtl_writephy (tp,MII_ADVERTISE , auto_nego); -rtl_writephy (tp,MII_CTRL1000 , giga_ctrl); - }else { -if (speed ==SPEED_10 ) - bmcr =0 ; -else if (speed ==SPEED_100 ) - bmcr =BMCR_SPEED100 ; -else - goto out; - -if (duplex ==DUPLEX_FULL ) - bmcr |=BMCR_FULLDPLX ; - } - -rtl_writephy (tp,MII_BMCR , bmcr); - -if (tp->mac_version ==RTL_GIGA_MAC_VER_02 || - tp->mac_version ==RTL_GIGA_MAC_VER_03 ) { -if ((speed ==SPEED_100 ) && (autoneg !=AUTONEG_ENABLE )) { -rtl_writephy (tp,0x17 ,0x2138 ); -rtl_writephy (tp,0x0e ,0x0260 ); - }else { -rtl_writephy (tp,0x17 ,0x2108 ); -rtl_writephy (tp,0x0e ,0x0000 ); - } - } - - rc =0 ; -out: -return rc; -} - -static int rtl8169_set_speed (struct net_device *dev, -u8 autoneg,u16 speed,u8 duplex,u32 advertising) -{ -return rtl8169_set_speed_xmii (dev, autoneg, speed, duplex, advertising); -} -static netdev_features_t rtl8169_fix_features (struct net_device *dev,netdev_features_t features) {
@@ -4237,13 +4154,6 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)phy_speed_up (dev->phydev);genphy_soft_reset (dev->phydev); - -rtl8169_set_speed (dev,AUTONEG_ENABLE ,SPEED_1000 ,DUPLEX_FULL , - ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | - ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | - (tp->mii.supports_gmii ? - ADVERTISED_1000baseT_Half | - ADVERTISED_1000baseT_Full :0 )); }static void rtl_rar_set (struct rtl8169_private *tp,u8 *addr)
Signature · 1 line
2.18.0
Heiner Kallweit
maintainerPATCH v3 9/10 r8169: remove mii_if_info member from struct rtl8169_private
In reply to Heiner KallweitThe only remaining usage of the struct mii_if_info member is to store the information whether the chip is GMII-capable. So we can replace it with a simple flag.
--- drivers/net/ethernet/realtek/r8169.c | 38 +++++----------------------- 1 file changed, 7 insertions(+), 31 deletions(-)
drivers/net/ethernet/realtek/r8169.c +7 -31
@@ -15,7 +15,6 @@#include <linux/etherdevice.h> #include <linux/delay.h> #include <linux/ethtool.h> -#include <linux/mii.h> #include <linux/phy.h> #include <linux/if_vlan.h> #include <linux/crc32.h>
@@ -754,7 +753,7 @@ struct rtl8169_private {struct work_struct work; } wk; -struct mii_if_info mii; + unsigned supports_gmii:1;struct mii_bus *mii_bus;dma_addr_t counters_phys_addr;struct rtl8169_counters *counters;
@@ -1106,21 +1105,6 @@ static void rtl_w0w1_phy(struct rtl8169_private *tp, int reg_addr, int p, int m)rtl_writephy (tp, reg_addr, (val & ~m) | p); } -static void rtl_mdio_write (struct net_device *dev,int phy_id,int location, -int val) -{ -struct rtl8169_private *tp =netdev_priv (dev); - -rtl_writephy (tp, location, val); -} - -static int rtl_mdio_read (struct net_device *dev,int phy_id,int location) -{ -struct rtl8169_private *tp =netdev_priv (dev); - -return rtl_readphy (tp, location); -} -DECLARE_RTL_COND (rtl_ephyar_cond) {return RTL_R32 (tp,EPHYAR ) &EPHYAR_FLAG ;
@@ -2246,15 +2230,15 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp, "unknown MAC, using family default\n"); tp->mac_version = default_version; }else if (tp->mac_version ==RTL_GIGA_MAC_VER_42 ) { - tp->mac_version = tp->mii.supports_gmii ? + tp->mac_version = tp->supports_gmii ?RTL_GIGA_MAC_VER_42 :RTL_GIGA_MAC_VER_43 ; }else if (tp->mac_version ==RTL_GIGA_MAC_VER_45 ) { - tp->mac_version = tp->mii.supports_gmii ? + tp->mac_version = tp->supports_gmii ?RTL_GIGA_MAC_VER_45 :RTL_GIGA_MAC_VER_47 ; }else if (tp->mac_version ==RTL_GIGA_MAC_VER_46 ) { - tp->mac_version = tp->mii.supports_gmii ? + tp->mac_version = tp->supports_gmii ?RTL_GIGA_MAC_VER_46 :RTL_GIGA_MAC_VER_48 ; }
@@ -6686,7 +6670,7 @@ static int r8169_phy_connect(struct rtl8169_private *tp)phy_interface_t phy_mode;int ret; - phy_mode = tp->mii.supports_gmii ?PHY_INTERFACE_MODE_GMII : + phy_mode = tp->supports_gmii ?PHY_INTERFACE_MODE_GMII :PHY_INTERFACE_MODE_MII ; ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler,
@@ -6694,7 +6678,7 @@ static int r8169_phy_connect(struct rtl8169_private *tp)if (ret)return ret; -if (!tp->mii.supports_gmii) +if (!tp->supports_gmii)phy_set_max_speed (phydev,SPEED_100 );/* Ensure to advertise everything, incl. pause */
@@ -7303,7 +7287,6 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) {const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;struct rtl8169_private *tp; -struct mii_if_info *mii;struct net_device *dev;int chipset, region, i;int rc;
@@ -7323,14 +7306,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) tp->dev = dev; tp->pci_dev = pdev; tp->msg_enable =netif_msg_init (debug.msg_enable,R8169_MSG_DEFAULT ); - - mii = &tp->mii; - mii->dev = dev; - mii->mdio_read = rtl_mdio_read; - mii->mdio_write = rtl_mdio_write; - mii->phy_id_mask =0x1f ; - mii->reg_num_mask =0x1f ; - mii->supports_gmii = cfg->has_gmii; + tp->supports_gmii = cfg->has_gmii;/* enable device (incl. PCI PM wakeup and hotplug setup) */ rc =pcim_enable_device (pdev);
Signature · 1 line
2.18.0
Heiner Kallweit
maintainerPATCH v3 10/10 r8169: don't read chip phy status register
In reply to Heiner KallweitInstead of accessing the PHYstatus register we can use the information phylib stores in the phy_device structure.
--- drivers/net/ethernet/realtek/r8169.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/realtek/r8169.c +5 -4
@@ -1428,18 +1428,19 @@ static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp)static void rtl_link_chg_patch (struct rtl8169_private *tp) {struct net_device *dev = tp->dev; +struct phy_device *phydev = dev->phydev;if (!netif_running (dev))return ;if (tp->mac_version ==RTL_GIGA_MAC_VER_34 || tp->mac_version ==RTL_GIGA_MAC_VER_38 ) { -if (RTL_R8 (tp, PHYstatus) & _1000bpsF) { +if (phydev->speed ==SPEED_1000 ) {rtl_eri_write (tp,0x1bc ,ERIAR_MASK_1111 ,0x00000011 ,ERIAR_EXGMAC );rtl_eri_write (tp,0x1dc ,ERIAR_MASK_1111 ,0x00000005 ,ERIAR_EXGMAC ); - }else if (RTL_R8 (tp, PHYstatus) & _100bps) { + }else if (phydev->speed ==SPEED_100 ) {rtl_eri_write (tp,0x1bc ,ERIAR_MASK_1111 ,0x0000001f ,ERIAR_EXGMAC ); rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005,
@@ -1457,7 +1458,7 @@ static void rtl_link_chg_patch(struct rtl8169_private *tp) ERIAR_EXGMAC); }else if (tp->mac_version ==RTL_GIGA_MAC_VER_35 || tp->mac_version ==RTL_GIGA_MAC_VER_36 ) { -if (RTL_R8 (tp, PHYstatus) & _1000bpsF) { +if (phydev->speed ==SPEED_1000 ) {rtl_eri_write (tp,0x1bc ,ERIAR_MASK_1111 ,0x00000011 ,ERIAR_EXGMAC ); rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005,
@@ -1469,7 +1470,7 @@ static void rtl_link_chg_patch(struct rtl8169_private *tp) ERIAR_EXGMAC); } }else if (tp->mac_version ==RTL_GIGA_MAC_VER_37 ) { -if (RTL_R8 (tp, PHYstatus) & _10bps) { +if (phydev->speed ==SPEED_10 ) {rtl_eri_write (tp,0x1d0 ,ERIAR_MASK_0011 ,0x4d02 ,ERIAR_EXGMAC ); rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060,
Signature · 1 line
2.18.0
David Miller
maintainerFrom: Heiner Kallweit <[email protected]>
Date: Tue, 17 Jul 2018 22:42:40 +0200
Quoted 11 lines
Now that all the basic refactoring has been done we can add phylib support. This patch series was successfully tested on:
RTL8168h
RTL8168evl
RTL8169sbChanges in v2:
- return error in mdio ops if phyaddr > 0
- advertise pause modes
- added reviewed-by for several patches
Quoted 5 lines
Changes in v3:
- return ENODEV for unused phy addresses in mdio ops
- remove unneeded PHY suspend in patch 2
- use recently addedphy_speed_downandphy_speed_upin patch 7
- other minor changes based on review comments
This looks great, series applied, thanks!