Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-stmmac-yet-more-cleanups'

Russell King says:

====================
net: stmmac: yet more cleanups

Building on the previous cleanup series, this cleans up yet more stmmac
code.

- Move stmmac_bus_clks_config() into stmmac_platform() which is where
its onlny user is.

- Move the xpcs Clause 73 test into stmmac_init_phy(), resulting in
simpler code in __stmmac_open().

- Move "can't attach PHY" error message into stmmac_init_phy().

We then start moving stuff out of __stmac_open() into stmmac_open()
(and correspondingly __stmmac_release() into stmmac_release()) which
is not necessary when re-initialising the interface on e.g. MTU change.

- Move initialisation of tx_lpi_timer
- Move PHY attachment/detachment
- Move PHY error message into stmmac_init_phy()

Finally, simplfy the paths in stmmac_init_phy().
====================

Link: https://patch.msgid.link/aNKDqqI7aLsuDD52@shell.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+73 -71
-1
drivers/net/ethernet/stmicro/stmmac/stmmac.h
··· 404 404 struct stmmac_resources *res); 405 405 int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt); 406 406 int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size); 407 - int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled); 408 407 int stmmac_set_clk_tx_rate(void *bsp_priv, struct clk *clk_tx_i, 409 408 phy_interface_t interface, int speed); 410 409
+41 -70
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 147 147 148 148 #define STMMAC_COAL_TIMER(x) (ns_to_ktime((x) * NSEC_PER_USEC)) 149 149 150 - int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled) 151 - { 152 - struct plat_stmmacenet_data *plat_dat = priv->plat; 153 - int ret; 154 - 155 - if (enabled) { 156 - ret = clk_prepare_enable(plat_dat->stmmac_clk); 157 - if (ret) 158 - return ret; 159 - ret = clk_prepare_enable(plat_dat->pclk); 160 - if (ret) { 161 - clk_disable_unprepare(plat_dat->stmmac_clk); 162 - return ret; 163 - } 164 - if (plat_dat->clks_config) { 165 - ret = plat_dat->clks_config(plat_dat->bsp_priv, enabled); 166 - if (ret) { 167 - clk_disable_unprepare(plat_dat->stmmac_clk); 168 - clk_disable_unprepare(plat_dat->pclk); 169 - return ret; 170 - } 171 - } 172 - } else { 173 - clk_disable_unprepare(plat_dat->stmmac_clk); 174 - clk_disable_unprepare(plat_dat->pclk); 175 - if (plat_dat->clks_config) 176 - plat_dat->clks_config(plat_dat->bsp_priv, enabled); 177 - } 178 - 179 - return 0; 180 - } 181 - EXPORT_SYMBOL_GPL(stmmac_bus_clks_config); 182 - 183 150 /** 184 151 * stmmac_set_clk_tx_rate() - set the clock rate for the MAC transmit clock 185 152 * @bsp_priv: BSP private data structure (unused) ··· 1112 1145 static int stmmac_init_phy(struct net_device *dev) 1113 1146 { 1114 1147 struct stmmac_priv *priv = netdev_priv(dev); 1148 + int mode = priv->plat->phy_interface; 1115 1149 struct fwnode_handle *phy_fwnode; 1116 1150 struct fwnode_handle *fwnode; 1151 + struct ethtool_keee eee; 1117 1152 int ret; 1118 1153 1119 1154 if (!phylink_expects_phy(priv->phylink)) 1155 + return 0; 1156 + 1157 + if (priv->hw->xpcs && 1158 + xpcs_get_an_mode(priv->hw->xpcs, mode) == DW_AN_C73) 1120 1159 return 0; 1121 1160 1122 1161 fwnode = priv->plat->port_node; ··· 1158 1185 ret = phylink_fwnode_phy_connect(priv->phylink, fwnode, 0); 1159 1186 } 1160 1187 1161 - if (ret == 0) { 1162 - struct ethtool_keee eee; 1188 + if (ret) { 1189 + netdev_err(priv->dev, "cannot attach to PHY (error: %pe)\n", 1190 + ERR_PTR(ret)); 1191 + return ret; 1192 + } 1163 1193 1164 - /* Configure phylib's copy of the LPI timer. Normally, 1165 - * phylink_config.lpi_timer_default would do this, but there is 1166 - * a chance that userspace could change the eee_timer setting 1167 - * via sysfs before the first open. Thus, preserve existing 1168 - * behaviour. 1169 - */ 1170 - if (!phylink_ethtool_get_eee(priv->phylink, &eee)) { 1171 - eee.tx_lpi_timer = priv->tx_lpi_timer; 1172 - phylink_ethtool_set_eee(priv->phylink, &eee); 1173 - } 1194 + /* Configure phylib's copy of the LPI timer. Normally, 1195 + * phylink_config.lpi_timer_default would do this, but there is a 1196 + * chance that userspace could change the eee_timer setting via sysfs 1197 + * before the first open. Thus, preserve existing behaviour. 1198 + */ 1199 + if (!phylink_ethtool_get_eee(priv->phylink, &eee)) { 1200 + eee.tx_lpi_timer = priv->tx_lpi_timer; 1201 + phylink_ethtool_set_eee(priv->phylink, &eee); 1174 1202 } 1175 1203 1176 1204 if (!priv->plat->pmt) { ··· 1182 1208 device_set_wakeup_enable(priv->device, !!wol.wolopts); 1183 1209 } 1184 1210 1185 - return ret; 1211 + return 0; 1186 1212 } 1187 1213 1188 1214 static int stmmac_phy_setup(struct stmmac_priv *priv) ··· 3933 3959 struct stmmac_dma_conf *dma_conf) 3934 3960 { 3935 3961 struct stmmac_priv *priv = netdev_priv(dev); 3936 - int mode = priv->plat->phy_interface; 3937 3962 u32 chan; 3938 3963 int ret; 3939 - 3940 - /* Initialise the tx lpi timer, converting from msec to usec */ 3941 - if (!priv->tx_lpi_timer) 3942 - priv->tx_lpi_timer = eee_timer * 1000; 3943 - 3944 - if ((!priv->hw->xpcs || 3945 - xpcs_get_an_mode(priv->hw->xpcs, mode) != DW_AN_C73)) { 3946 - ret = stmmac_init_phy(dev); 3947 - if (ret) { 3948 - netdev_err(priv->dev, 3949 - "%s: Cannot attach to PHY (error: %d)\n", 3950 - __func__, ret); 3951 - return ret; 3952 - } 3953 - } 3954 3964 3955 3965 for (int i = 0; i < MTL_MAX_TX_QUEUES; i++) 3956 3966 if (priv->dma_conf.tx_queue[i].tbs & STMMAC_TBS_EN) ··· 3985 4027 3986 4028 stmmac_release_ptp(priv); 3987 4029 init_error: 3988 - phylink_disconnect_phy(priv->phylink); 3989 4030 return ret; 3990 4031 } 3991 4032 ··· 3994 4037 struct stmmac_dma_conf *dma_conf; 3995 4038 int ret; 3996 4039 4040 + /* Initialise the tx lpi timer, converting from msec to usec */ 4041 + if (!priv->tx_lpi_timer) 4042 + priv->tx_lpi_timer = eee_timer * 1000; 4043 + 3997 4044 dma_conf = stmmac_setup_dma_desc(priv, dev->mtu); 3998 4045 if (IS_ERR(dma_conf)) 3999 4046 return PTR_ERR(dma_conf); 4000 4047 4001 4048 ret = pm_runtime_resume_and_get(priv->device); 4002 4049 if (ret < 0) 4003 - goto err; 4050 + goto err_dma_resources; 4051 + 4052 + ret = stmmac_init_phy(dev); 4053 + if (ret) 4054 + goto err_runtime_pm; 4004 4055 4005 4056 ret = __stmmac_open(dev, dma_conf); 4006 - if (ret) { 4007 - pm_runtime_put(priv->device); 4008 - err: 4009 - free_dma_desc_resources(priv, dma_conf); 4010 - } 4057 + if (ret) 4058 + goto err_disconnect_phy; 4011 4059 4012 4060 kfree(dma_conf); 4013 4061 4062 + return ret; 4063 + 4064 + err_disconnect_phy: 4065 + phylink_disconnect_phy(priv->phylink); 4066 + err_runtime_pm: 4067 + pm_runtime_put(priv->device); 4068 + err_dma_resources: 4069 + free_dma_desc_resources(priv, dma_conf); 4070 + kfree(dma_conf); 4014 4071 return ret; 4015 4072 } 4016 4073 ··· 4042 4071 4043 4072 /* Stop and disconnect the PHY */ 4044 4073 phylink_stop(priv->phylink); 4045 - phylink_disconnect_phy(priv->phylink); 4046 4074 4047 4075 stmmac_disable_all_queues(priv); 4048 4076 ··· 4081 4111 4082 4112 __stmmac_release(dev); 4083 4113 4114 + phylink_disconnect_phy(priv->phylink); 4084 4115 pm_runtime_put(priv->device); 4085 4116 4086 4117 return 0;
+32
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
··· 911 911 } 912 912 EXPORT_SYMBOL_GPL(stmmac_pltfr_remove); 913 913 914 + static int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled) 915 + { 916 + struct plat_stmmacenet_data *plat_dat = priv->plat; 917 + int ret; 918 + 919 + if (enabled) { 920 + ret = clk_prepare_enable(plat_dat->stmmac_clk); 921 + if (ret) 922 + return ret; 923 + ret = clk_prepare_enable(plat_dat->pclk); 924 + if (ret) { 925 + clk_disable_unprepare(plat_dat->stmmac_clk); 926 + return ret; 927 + } 928 + if (plat_dat->clks_config) { 929 + ret = plat_dat->clks_config(plat_dat->bsp_priv, enabled); 930 + if (ret) { 931 + clk_disable_unprepare(plat_dat->stmmac_clk); 932 + clk_disable_unprepare(plat_dat->pclk); 933 + return ret; 934 + } 935 + } 936 + } else { 937 + clk_disable_unprepare(plat_dat->stmmac_clk); 938 + clk_disable_unprepare(plat_dat->pclk); 939 + if (plat_dat->clks_config) 940 + plat_dat->clks_config(plat_dat->bsp_priv, enabled); 941 + } 942 + 943 + return 0; 944 + } 945 + 914 946 static int __maybe_unused stmmac_runtime_suspend(struct device *dev) 915 947 { 916 948 struct net_device *ndev = dev_get_drvdata(dev);