Skip to content

Commit 94ae899

Browse files
IoanaCiorneidavem330
authored andcommitted
dpaa2-mac: add PCS support through the Lynx module
Include PCS support in the dpaa2-eth driver by integrating it with the new Lynx PCS module. There is not much to talk about in terms of changes needed in the dpaa2-eth driver since the only steps necessary are to find the MDIO device representing the PCS, register it to the Lynx PCS module and then let phylink know if its existence also. After this, the PCS callbacks will be treated directly by Lynx, without interraction from dpaa2-eth's part. Signed-off-by: Ioana Ciornei <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b5b6775 commit 94ae899

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

drivers/net/ethernet/freescale/dpaa2/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ config FSL_DPAA2_ETH
33
tristate "Freescale DPAA2 Ethernet"
44
depends on FSL_MC_BUS && FSL_MC_DPIO
55
select PHYLINK
6+
select PCS_LYNX
67
help
78
This is the DPAA2 Ethernet driver supporting Freescale SoCs
89
with DPAA2 (DataPath Acceleration Architecture v2).

drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode)
1515
case DPMAC_ETH_IF_RGMII:
1616
*if_mode = PHY_INTERFACE_MODE_RGMII;
1717
break;
18+
case DPMAC_ETH_IF_USXGMII:
19+
*if_mode = PHY_INTERFACE_MODE_USXGMII;
20+
break;
21+
case DPMAC_ETH_IF_QSGMII:
22+
*if_mode = PHY_INTERFACE_MODE_QSGMII;
23+
break;
24+
case DPMAC_ETH_IF_SGMII:
25+
*if_mode = PHY_INTERFACE_MODE_SGMII;
26+
break;
27+
case DPMAC_ETH_IF_XFI:
28+
*if_mode = PHY_INTERFACE_MODE_10GBASER;
29+
break;
1830
default:
1931
return -EINVAL;
2032
}
@@ -67,6 +79,10 @@ static bool dpaa2_mac_phy_mode_mismatch(struct dpaa2_mac *mac,
6779
phy_interface_t interface)
6880
{
6981
switch (interface) {
82+
case PHY_INTERFACE_MODE_10GBASER:
83+
case PHY_INTERFACE_MODE_USXGMII:
84+
case PHY_INTERFACE_MODE_QSGMII:
85+
case PHY_INTERFACE_MODE_SGMII:
7086
case PHY_INTERFACE_MODE_RGMII:
7187
case PHY_INTERFACE_MODE_RGMII_ID:
7288
case PHY_INTERFACE_MODE_RGMII_RXID:
@@ -95,6 +111,17 @@ static void dpaa2_mac_validate(struct phylink_config *config,
95111
phylink_set(mask, Asym_Pause);
96112

97113
switch (state->interface) {
114+
case PHY_INTERFACE_MODE_NA:
115+
case PHY_INTERFACE_MODE_10GBASER:
116+
case PHY_INTERFACE_MODE_USXGMII:
117+
phylink_set(mask, 10000baseT_Full);
118+
if (state->interface == PHY_INTERFACE_MODE_10GBASER)
119+
break;
120+
phylink_set(mask, 5000baseT_Full);
121+
phylink_set(mask, 2500baseT_Full);
122+
fallthrough;
123+
case PHY_INTERFACE_MODE_SGMII:
124+
case PHY_INTERFACE_MODE_QSGMII:
98125
case PHY_INTERFACE_MODE_RGMII:
99126
case PHY_INTERFACE_MODE_RGMII_ID:
100127
case PHY_INTERFACE_MODE_RGMII_RXID:
@@ -227,6 +254,52 @@ bool dpaa2_mac_is_type_fixed(struct fsl_mc_device *dpmac_dev,
227254
return fixed;
228255
}
229256

257+
static int dpaa2_pcs_create(struct dpaa2_mac *mac,
258+
struct device_node *dpmac_node, int id)
259+
{
260+
struct mdio_device *mdiodev;
261+
struct device_node *node;
262+
263+
node = of_parse_phandle(dpmac_node, "pcs-handle", 0);
264+
if (!node) {
265+
/* do not error out on old DTS files */
266+
netdev_warn(mac->net_dev, "pcs-handle node not found\n");
267+
return 0;
268+
}
269+
270+
if (!of_device_is_available(node) ||
271+
!of_device_is_available(node->parent)) {
272+
netdev_err(mac->net_dev, "pcs-handle node not available\n");
273+
return -ENODEV;
274+
}
275+
276+
mdiodev = of_mdio_find_device(node);
277+
of_node_put(node);
278+
if (!mdiodev)
279+
return -EPROBE_DEFER;
280+
281+
mac->pcs = lynx_pcs_create(mdiodev);
282+
if (!mac->pcs) {
283+
netdev_err(mac->net_dev, "lynx_pcs_create() failed\n");
284+
put_device(&mdiodev->dev);
285+
return -ENOMEM;
286+
}
287+
288+
return 0;
289+
}
290+
291+
static void dpaa2_pcs_destroy(struct dpaa2_mac *mac)
292+
{
293+
struct lynx_pcs *pcs = mac->pcs;
294+
struct device *dev = &pcs->mdio->dev;
295+
296+
if (pcs) {
297+
lynx_pcs_destroy(pcs);
298+
put_device(dev);
299+
mac->pcs = NULL;
300+
}
301+
}
302+
230303
int dpaa2_mac_connect(struct dpaa2_mac *mac)
231304
{
232305
struct fsl_mc_device *dpmac_dev = mac->mc_dev;
@@ -278,6 +351,13 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
278351
goto err_put_node;
279352
}
280353

354+
if (attr.link_type == DPMAC_LINK_TYPE_PHY &&
355+
attr.eth_if != DPMAC_ETH_IF_RGMII) {
356+
err = dpaa2_pcs_create(mac, dpmac_node, attr.id);
357+
if (err)
358+
goto err_put_node;
359+
}
360+
281361
mac->phylink_config.dev = &net_dev->dev;
282362
mac->phylink_config.type = PHYLINK_NETDEV;
283363

@@ -286,10 +366,13 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
286366
&dpaa2_mac_phylink_ops);
287367
if (IS_ERR(phylink)) {
288368
err = PTR_ERR(phylink);
289-
goto err_put_node;
369+
goto err_pcs_destroy;
290370
}
291371
mac->phylink = phylink;
292372

373+
if (mac->pcs)
374+
phylink_set_pcs(mac->phylink, &mac->pcs->pcs);
375+
293376
err = phylink_of_phy_connect(mac->phylink, dpmac_node, 0);
294377
if (err) {
295378
netdev_err(net_dev, "phylink_of_phy_connect() = %d\n", err);
@@ -302,6 +385,8 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
302385

303386
err_phylink_destroy:
304387
phylink_destroy(mac->phylink);
388+
err_pcs_destroy:
389+
dpaa2_pcs_destroy(mac);
305390
err_put_node:
306391
of_node_put(dpmac_node);
307392
err_close_dpmac:
@@ -316,6 +401,8 @@ void dpaa2_mac_disconnect(struct dpaa2_mac *mac)
316401

317402
phylink_disconnect_phy(mac->phylink);
318403
phylink_destroy(mac->phylink);
404+
dpaa2_pcs_destroy(mac);
405+
319406
dpmac_close(mac->mc_io, 0, mac->mc_dev->mc_handle);
320407
}
321408

drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/of_mdio.h>
88
#include <linux/of_net.h>
99
#include <linux/phylink.h>
10+
#include <linux/pcs-lynx.h>
1011

1112
#include "dpmac.h"
1213
#include "dpmac-cmd.h"
@@ -21,6 +22,7 @@ struct dpaa2_mac {
2122
struct phylink *phylink;
2223
phy_interface_t if_mode;
2324
enum dpmac_link_type if_link_type;
25+
struct lynx_pcs *pcs;
2426
};
2527

2628
bool dpaa2_mac_is_type_fixed(struct fsl_mc_device *dpmac_dev,

0 commit comments

Comments
 (0)