Skip to content

Commit 5d93cfc

Browse files
sean-anderson-secodavem330
authored andcommitted
net: dpaa: Convert to phylink
This converts DPAA to phylink. All macs are converted. This should work with no device tree modifications (including those made in this series), except for QSGMII (as noted previously). The mEMAC configuration is one of the tricker areas. I have tried to capture all the restrictions across the various models. Most of the time, we assume that if the serdes supports a mode or the phy-interface-mode specifies it, then we support it. The only place we can't do this is (RG)MII, since there's no serdes. In that case, we rely on a (new) devicetree property. There are also several cases where half-duplex is broken. Unfortunately, only a single compatible is used for the MAC, so we have to use the board compatible instead. The 10GEC conversion is very straightforward, since it only supports XAUI. There is generally nothing to configure. The dTSEC conversion is broadly similar to mEMAC, but is simpler because we don't support configuring the SerDes (though this can be easily added) and we don't have multiple PCSs. From what I can tell, there's nothing different in the driver or documentation between SGMII and 1000BASE-X except for the advertising. Similarly, I couldn't find anything about 2500BASE-X. In both cases, I treat them like SGMII. These modes aren't used by any in-tree boards. Similarly, despite being mentioned in the driver, I couldn't find any documented SoCs which supported QSGMII. I have left it unimplemented for now. Signed-off-by: Sean Anderson <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a7c2a32 commit 5d93cfc

File tree

10 files changed

+612
-909
lines changed

10 files changed

+612
-909
lines changed

drivers/net/ethernet/freescale/dpaa/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
menuconfig FSL_DPAA_ETH
33
tristate "DPAA Ethernet"
44
depends on FSL_DPAA && FSL_FMAN
5-
select PHYLIB
6-
select FIXED_PHY
5+
select PHYLINK
6+
select PCS_LYNX
77
help
88
Data Path Acceleration Architecture Ethernet driver,
99
supporting the Freescale QorIQ chips.

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c

Lines changed: 26 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,27 @@ static int dpaa_netdev_init(struct net_device *net_dev,
264264
net_dev->needed_headroom = priv->tx_headroom;
265265
net_dev->watchdog_timeo = msecs_to_jiffies(tx_timeout);
266266

267-
mac_dev->net_dev = net_dev;
267+
/* The rest of the config is filled in by the mac device already */
268+
mac_dev->phylink_config.dev = &net_dev->dev;
269+
mac_dev->phylink_config.type = PHYLINK_NETDEV;
268270
mac_dev->update_speed = dpaa_eth_cgr_set_speed;
271+
mac_dev->phylink = phylink_create(&mac_dev->phylink_config,
272+
dev_fwnode(mac_dev->dev),
273+
mac_dev->phy_if,
274+
mac_dev->phylink_ops);
275+
if (IS_ERR(mac_dev->phylink)) {
276+
err = PTR_ERR(mac_dev->phylink);
277+
dev_err_probe(dev, err, "Could not create phylink\n");
278+
return err;
279+
}
269280

270281
/* start without the RUNNING flag, phylib controls it later */
271282
netif_carrier_off(net_dev);
272283

273284
err = register_netdev(net_dev);
274285
if (err < 0) {
275286
dev_err(dev, "register_netdev() = %d\n", err);
287+
phylink_destroy(mac_dev->phylink);
276288
return err;
277289
}
278290

@@ -294,8 +306,7 @@ static int dpaa_stop(struct net_device *net_dev)
294306
*/
295307
msleep(200);
296308

297-
if (mac_dev->phy_dev)
298-
phy_stop(mac_dev->phy_dev);
309+
phylink_stop(mac_dev->phylink);
299310
mac_dev->disable(mac_dev->fman_mac);
300311

301312
for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
@@ -304,8 +315,7 @@ static int dpaa_stop(struct net_device *net_dev)
304315
err = error;
305316
}
306317

307-
if (net_dev->phydev)
308-
phy_disconnect(net_dev->phydev);
318+
phylink_disconnect_phy(mac_dev->phylink);
309319
net_dev->phydev = NULL;
310320

311321
msleep(200);
@@ -833,10 +843,10 @@ static int dpaa_eth_cgr_init(struct dpaa_priv *priv)
833843

834844
/* Set different thresholds based on the configured MAC speed.
835845
* This may turn suboptimal if the MAC is reconfigured at another
836-
* speed, so MACs must call dpaa_eth_cgr_set_speed in their adjust_link
846+
* speed, so MACs must call dpaa_eth_cgr_set_speed in their link_up
837847
* callback.
838848
*/
839-
if (priv->mac_dev->if_support & SUPPORTED_10000baseT_Full)
849+
if (priv->mac_dev->phylink_config.mac_capabilities & MAC_10000FD)
840850
cs_th = DPAA_CS_THRESHOLD_10G;
841851
else
842852
cs_th = DPAA_CS_THRESHOLD_1G;
@@ -865,7 +875,7 @@ static int dpaa_eth_cgr_init(struct dpaa_priv *priv)
865875

866876
static void dpaa_eth_cgr_set_speed(struct mac_device *mac_dev, int speed)
867877
{
868-
struct net_device *net_dev = mac_dev->net_dev;
878+
struct net_device *net_dev = to_net_dev(mac_dev->phylink_config.dev);
869879
struct dpaa_priv *priv = netdev_priv(net_dev);
870880
struct qm_mcc_initcgr opts = { };
871881
u32 cs_th;
@@ -2904,58 +2914,6 @@ static void dpaa_eth_napi_disable(struct dpaa_priv *priv)
29042914
}
29052915
}
29062916

2907-
static void dpaa_adjust_link(struct net_device *net_dev)
2908-
{
2909-
struct mac_device *mac_dev;
2910-
struct dpaa_priv *priv;
2911-
2912-
priv = netdev_priv(net_dev);
2913-
mac_dev = priv->mac_dev;
2914-
mac_dev->adjust_link(mac_dev);
2915-
}
2916-
2917-
/* The Aquantia PHYs are capable of performing rate adaptation */
2918-
#define PHY_VEND_AQUANTIA 0x03a1b400
2919-
#define PHY_VEND_AQUANTIA2 0x31c31c00
2920-
2921-
static int dpaa_phy_init(struct net_device *net_dev)
2922-
{
2923-
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
2924-
struct mac_device *mac_dev;
2925-
struct phy_device *phy_dev;
2926-
struct dpaa_priv *priv;
2927-
u32 phy_vendor;
2928-
2929-
priv = netdev_priv(net_dev);
2930-
mac_dev = priv->mac_dev;
2931-
2932-
phy_dev = of_phy_connect(net_dev, mac_dev->phy_node,
2933-
&dpaa_adjust_link, 0,
2934-
mac_dev->phy_if);
2935-
if (!phy_dev) {
2936-
netif_err(priv, ifup, net_dev, "init_phy() failed\n");
2937-
return -ENODEV;
2938-
}
2939-
2940-
phy_vendor = phy_dev->drv->phy_id & GENMASK(31, 10);
2941-
/* Unless the PHY is capable of rate adaptation */
2942-
if (mac_dev->phy_if != PHY_INTERFACE_MODE_XGMII ||
2943-
(phy_vendor != PHY_VEND_AQUANTIA &&
2944-
phy_vendor != PHY_VEND_AQUANTIA2)) {
2945-
/* remove any features not supported by the controller */
2946-
ethtool_convert_legacy_u32_to_link_mode(mask,
2947-
mac_dev->if_support);
2948-
linkmode_and(phy_dev->supported, phy_dev->supported, mask);
2949-
}
2950-
2951-
phy_support_asym_pause(phy_dev);
2952-
2953-
mac_dev->phy_dev = phy_dev;
2954-
net_dev->phydev = phy_dev;
2955-
2956-
return 0;
2957-
}
2958-
29592917
static int dpaa_open(struct net_device *net_dev)
29602918
{
29612919
struct mac_device *mac_dev;
@@ -2966,7 +2924,8 @@ static int dpaa_open(struct net_device *net_dev)
29662924
mac_dev = priv->mac_dev;
29672925
dpaa_eth_napi_enable(priv);
29682926

2969-
err = dpaa_phy_init(net_dev);
2927+
err = phylink_of_phy_connect(mac_dev->phylink,
2928+
mac_dev->dev->of_node, 0);
29702929
if (err)
29712930
goto phy_init_failed;
29722931

@@ -2981,7 +2940,7 @@ static int dpaa_open(struct net_device *net_dev)
29812940
netif_err(priv, ifup, net_dev, "mac_dev->enable() = %d\n", err);
29822941
goto mac_start_failed;
29832942
}
2984-
phy_start(priv->mac_dev->phy_dev);
2943+
phylink_start(mac_dev->phylink);
29852944

29862945
netif_tx_start_all_queues(net_dev);
29872946

@@ -2990,6 +2949,7 @@ static int dpaa_open(struct net_device *net_dev)
29902949
mac_start_failed:
29912950
for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++)
29922951
fman_port_disable(mac_dev->port[i]);
2952+
phylink_disconnect_phy(mac_dev->phylink);
29932953

29942954
phy_init_failed:
29952955
dpaa_eth_napi_disable(priv);
@@ -3145,10 +3105,12 @@ static int dpaa_ts_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
31453105
static int dpaa_ioctl(struct net_device *net_dev, struct ifreq *rq, int cmd)
31463106
{
31473107
int ret = -EINVAL;
3108+
struct dpaa_priv *priv = netdev_priv(net_dev);
31483109

31493110
if (cmd == SIOCGMIIREG) {
31503111
if (net_dev->phydev)
3151-
return phy_mii_ioctl(net_dev->phydev, rq, cmd);
3112+
return phylink_mii_ioctl(priv->mac_dev->phylink, rq,
3113+
cmd);
31523114
}
31533115

31543116
if (cmd == SIOCSHWTSTAMP)
@@ -3551,6 +3513,7 @@ static int dpaa_remove(struct platform_device *pdev)
35513513

35523514
dev_set_drvdata(dev, NULL);
35533515
unregister_netdev(net_dev);
3516+
phylink_destroy(priv->mac_dev->phylink);
35543517

35553518
err = dpaa_fq_free(dev, &priv->dpaa_fq_list);
35563519

drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c

Lines changed: 15 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,19 @@ static char dpaa_stats_global[][ETH_GSTRING_LEN] = {
5454
static int dpaa_get_link_ksettings(struct net_device *net_dev,
5555
struct ethtool_link_ksettings *cmd)
5656
{
57-
if (!net_dev->phydev)
58-
return 0;
57+
struct dpaa_priv *priv = netdev_priv(net_dev);
58+
struct mac_device *mac_dev = priv->mac_dev;
5959

60-
phy_ethtool_ksettings_get(net_dev->phydev, cmd);
61-
62-
return 0;
60+
return phylink_ethtool_ksettings_get(mac_dev->phylink, cmd);
6361
}
6462

6563
static int dpaa_set_link_ksettings(struct net_device *net_dev,
6664
const struct ethtool_link_ksettings *cmd)
6765
{
68-
int err;
69-
70-
if (!net_dev->phydev)
71-
return -ENODEV;
72-
73-
err = phy_ethtool_ksettings_set(net_dev->phydev, cmd);
74-
if (err < 0)
75-
netdev_err(net_dev, "phy_ethtool_ksettings_set() = %d\n", err);
66+
struct dpaa_priv *priv = netdev_priv(net_dev);
67+
struct mac_device *mac_dev = priv->mac_dev;
7668

77-
return err;
69+
return phylink_ethtool_ksettings_set(mac_dev->phylink, cmd);
7870
}
7971

8072
static void dpaa_get_drvinfo(struct net_device *net_dev,
@@ -99,80 +91,28 @@ static void dpaa_set_msglevel(struct net_device *net_dev,
9991

10092
static int dpaa_nway_reset(struct net_device *net_dev)
10193
{
102-
int err;
103-
104-
if (!net_dev->phydev)
105-
return -ENODEV;
106-
107-
err = 0;
108-
if (net_dev->phydev->autoneg) {
109-
err = phy_start_aneg(net_dev->phydev);
110-
if (err < 0)
111-
netdev_err(net_dev, "phy_start_aneg() = %d\n",
112-
err);
113-
}
94+
struct dpaa_priv *priv = netdev_priv(net_dev);
95+
struct mac_device *mac_dev = priv->mac_dev;
11496

115-
return err;
97+
return phylink_ethtool_nway_reset(mac_dev->phylink);
11698
}
11799

118100
static void dpaa_get_pauseparam(struct net_device *net_dev,
119101
struct ethtool_pauseparam *epause)
120102
{
121-
struct mac_device *mac_dev;
122-
struct dpaa_priv *priv;
123-
124-
priv = netdev_priv(net_dev);
125-
mac_dev = priv->mac_dev;
126-
127-
if (!net_dev->phydev)
128-
return;
103+
struct dpaa_priv *priv = netdev_priv(net_dev);
104+
struct mac_device *mac_dev = priv->mac_dev;
129105

130-
epause->autoneg = mac_dev->autoneg_pause;
131-
epause->rx_pause = mac_dev->rx_pause_active;
132-
epause->tx_pause = mac_dev->tx_pause_active;
106+
phylink_ethtool_get_pauseparam(mac_dev->phylink, epause);
133107
}
134108

135109
static int dpaa_set_pauseparam(struct net_device *net_dev,
136110
struct ethtool_pauseparam *epause)
137111
{
138-
struct mac_device *mac_dev;
139-
struct phy_device *phydev;
140-
bool rx_pause, tx_pause;
141-
struct dpaa_priv *priv;
142-
int err;
143-
144-
priv = netdev_priv(net_dev);
145-
mac_dev = priv->mac_dev;
146-
147-
phydev = net_dev->phydev;
148-
if (!phydev) {
149-
netdev_err(net_dev, "phy device not initialized\n");
150-
return -ENODEV;
151-
}
152-
153-
if (!phy_validate_pause(phydev, epause))
154-
return -EINVAL;
155-
156-
/* The MAC should know how to handle PAUSE frame autonegotiation before
157-
* adjust_link is triggered by a forced renegotiation of sym/asym PAUSE
158-
* settings.
159-
*/
160-
mac_dev->autoneg_pause = !!epause->autoneg;
161-
mac_dev->rx_pause_req = !!epause->rx_pause;
162-
mac_dev->tx_pause_req = !!epause->tx_pause;
163-
164-
/* Determine the sym/asym advertised PAUSE capabilities from the desired
165-
* rx/tx pause settings.
166-
*/
167-
168-
phy_set_asym_pause(phydev, epause->rx_pause, epause->tx_pause);
169-
170-
fman_get_pause_cfg(mac_dev, &rx_pause, &tx_pause);
171-
err = fman_set_mac_active_pause(mac_dev, rx_pause, tx_pause);
172-
if (err < 0)
173-
netdev_err(net_dev, "set_mac_active_pause() = %d\n", err);
112+
struct dpaa_priv *priv = netdev_priv(net_dev);
113+
struct mac_device *mac_dev = priv->mac_dev;
174114

175-
return err;
115+
return phylink_ethtool_set_pauseparam(mac_dev->phylink, epause);
176116
}
177117

178118
static int dpaa_get_sset_count(struct net_device *net_dev, int type)

drivers/net/ethernet/freescale/fman/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ config FSL_FMAN
33
tristate "FMan support"
44
depends on FSL_SOC || ARCH_LAYERSCAPE || COMPILE_TEST
55
select GENERIC_ALLOCATOR
6-
select PHYLIB
76
select PHYLINK
87
select PCS
98
select PCS_LYNX

0 commit comments

Comments
 (0)