Skip to content

Commit 3c38ec6

Browse files
madalinbucurdavem330
authored andcommitted
dpaa_eth: move of_phy_connect() to the eth driver
Signed-off-by: Madalin Bucur <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 48167c9 commit 3c38ec6

File tree

3 files changed

+66
-84
lines changed

3 files changed

+66
-84
lines changed

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

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,48 @@ static void dpaa_eth_napi_disable(struct dpaa_priv *priv)
24352435
}
24362436
}
24372437

2438+
static void dpaa_adjust_link(struct net_device *net_dev)
2439+
{
2440+
struct mac_device *mac_dev;
2441+
struct dpaa_priv *priv;
2442+
2443+
priv = netdev_priv(net_dev);
2444+
mac_dev = priv->mac_dev;
2445+
mac_dev->adjust_link(mac_dev);
2446+
}
2447+
2448+
static int dpaa_phy_init(struct net_device *net_dev)
2449+
{
2450+
struct mac_device *mac_dev;
2451+
struct phy_device *phy_dev;
2452+
struct dpaa_priv *priv;
2453+
2454+
priv = netdev_priv(net_dev);
2455+
mac_dev = priv->mac_dev;
2456+
2457+
phy_dev = of_phy_connect(net_dev, mac_dev->phy_node,
2458+
&dpaa_adjust_link, 0,
2459+
mac_dev->phy_if);
2460+
if (!phy_dev) {
2461+
netif_err(priv, ifup, net_dev, "init_phy() failed\n");
2462+
return -ENODEV;
2463+
}
2464+
2465+
/* Remove any features not supported by the controller */
2466+
phy_dev->supported &= mac_dev->if_support;
2467+
2468+
/* Enable the symmetric and asymmetric PAUSE frame advertisements,
2469+
* as most of the PHY drivers do not enable them by default.
2470+
*/
2471+
phy_dev->supported |= (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
2472+
phy_dev->advertising = phy_dev->supported;
2473+
2474+
mac_dev->phy_dev = phy_dev;
2475+
net_dev->phydev = phy_dev;
2476+
2477+
return 0;
2478+
}
2479+
24382480
static int dpaa_open(struct net_device *net_dev)
24392481
{
24402482
struct mac_device *mac_dev;
@@ -2445,12 +2487,8 @@ static int dpaa_open(struct net_device *net_dev)
24452487
mac_dev = priv->mac_dev;
24462488
dpaa_eth_napi_enable(priv);
24472489

2448-
net_dev->phydev = mac_dev->init_phy(net_dev, priv->mac_dev);
2449-
if (!net_dev->phydev) {
2450-
netif_err(priv, ifup, net_dev, "init_phy() failed\n");
2451-
err = -ENODEV;
2490+
if (dpaa_phy_init(net_dev))
24522491
goto phy_init_failed;
2453-
}
24542492

24552493
for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
24562494
err = fman_port_enable(mac_dev->port[i]);

drivers/net/ethernet/freescale/fman/mac.c

Lines changed: 20 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ struct mac_priv_s {
5757
struct device *dev;
5858
void __iomem *vaddr;
5959
u8 cell_index;
60-
phy_interface_t phy_if;
6160
struct fman *fman;
62-
struct device_node *phy_node;
6361
struct device_node *internal_phy_node;
6462
/* List of multicast addresses */
6563
struct list_head mc_addr_list;
@@ -106,7 +104,7 @@ static void set_fman_mac_params(struct mac_device *mac_dev,
106104
resource_size(mac_dev->res));
107105
memcpy(&params->addr, mac_dev->addr, sizeof(mac_dev->addr));
108106
params->max_speed = priv->max_speed;
109-
params->phy_if = priv->phy_if;
107+
params->phy_if = mac_dev->phy_if;
110108
params->basex_if = false;
111109
params->mac_id = priv->cell_index;
112110
params->fm = (void *)priv->fman;
@@ -419,15 +417,12 @@ void fman_get_pause_cfg(struct mac_device *mac_dev, bool *rx_pause,
419417
}
420418
EXPORT_SYMBOL(fman_get_pause_cfg);
421419

422-
static void adjust_link_void(struct net_device *net_dev)
420+
static void adjust_link_void(struct mac_device *mac_dev)
423421
{
424422
}
425423

426-
static void adjust_link_dtsec(struct net_device *net_dev)
424+
static void adjust_link_dtsec(struct mac_device *mac_dev)
427425
{
428-
struct device *dev = net_dev->dev.parent;
429-
struct dpaa_eth_data *eth_data = dev->platform_data;
430-
struct mac_device *mac_dev = eth_data->mac_dev;
431426
struct phy_device *phy_dev = mac_dev->phy_dev;
432427
struct fman_mac *fman_mac;
433428
bool rx_pause, tx_pause;
@@ -444,14 +439,12 @@ static void adjust_link_dtsec(struct net_device *net_dev)
444439
fman_get_pause_cfg(mac_dev, &rx_pause, &tx_pause);
445440
err = fman_set_mac_active_pause(mac_dev, rx_pause, tx_pause);
446441
if (err < 0)
447-
netdev_err(net_dev, "fman_set_mac_active_pause() = %d\n", err);
442+
dev_err(mac_dev->priv->dev, "fman_set_mac_active_pause() = %d\n",
443+
err);
448444
}
449445

450-
static void adjust_link_memac(struct net_device *net_dev)
446+
static void adjust_link_memac(struct mac_device *mac_dev)
451447
{
452-
struct device *dev = net_dev->dev.parent;
453-
struct dpaa_eth_data *eth_data = dev->platform_data;
454-
struct mac_device *mac_dev = eth_data->mac_dev;
455448
struct phy_device *phy_dev = mac_dev->phy_dev;
456449
struct fman_mac *fman_mac;
457450
bool rx_pause, tx_pause;
@@ -463,60 +456,12 @@ static void adjust_link_memac(struct net_device *net_dev)
463456
fman_get_pause_cfg(mac_dev, &rx_pause, &tx_pause);
464457
err = fman_set_mac_active_pause(mac_dev, rx_pause, tx_pause);
465458
if (err < 0)
466-
netdev_err(net_dev, "fman_set_mac_active_pause() = %d\n", err);
467-
}
468-
469-
/* Initializes driver's PHY state, and attaches to the PHY.
470-
* Returns 0 on success.
471-
*/
472-
static struct phy_device *init_phy(struct net_device *net_dev,
473-
struct mac_device *mac_dev,
474-
void (*adj_lnk)(struct net_device *))
475-
{
476-
struct phy_device *phy_dev;
477-
struct mac_priv_s *priv = mac_dev->priv;
478-
479-
phy_dev = of_phy_connect(net_dev, priv->phy_node, adj_lnk, 0,
480-
priv->phy_if);
481-
if (!phy_dev) {
482-
netdev_err(net_dev, "Could not connect to PHY\n");
483-
return NULL;
484-
}
485-
486-
/* Remove any features not supported by the controller */
487-
phy_dev->supported &= mac_dev->if_support;
488-
/* Enable the symmetric and asymmetric PAUSE frame advertisements,
489-
* as most of the PHY drivers do not enable them by default.
490-
*/
491-
phy_dev->supported |= (SUPPORTED_Pause | SUPPORTED_Asym_Pause);
492-
phy_dev->advertising = phy_dev->supported;
493-
494-
mac_dev->phy_dev = phy_dev;
495-
496-
return phy_dev;
497-
}
498-
499-
static struct phy_device *dtsec_init_phy(struct net_device *net_dev,
500-
struct mac_device *mac_dev)
501-
{
502-
return init_phy(net_dev, mac_dev, &adjust_link_dtsec);
503-
}
504-
505-
static struct phy_device *tgec_init_phy(struct net_device *net_dev,
506-
struct mac_device *mac_dev)
507-
{
508-
return init_phy(net_dev, mac_dev, adjust_link_void);
509-
}
510-
511-
static struct phy_device *memac_init_phy(struct net_device *net_dev,
512-
struct mac_device *mac_dev)
513-
{
514-
return init_phy(net_dev, mac_dev, &adjust_link_memac);
459+
dev_err(mac_dev->priv->dev, "fman_set_mac_active_pause() = %d\n",
460+
err);
515461
}
516462

517463
static void setup_dtsec(struct mac_device *mac_dev)
518464
{
519-
mac_dev->init_phy = dtsec_init_phy;
520465
mac_dev->init = dtsec_initialization;
521466
mac_dev->set_promisc = dtsec_set_promiscuous;
522467
mac_dev->change_addr = dtsec_modify_mac_address;
@@ -528,14 +473,13 @@ static void setup_dtsec(struct mac_device *mac_dev)
528473
mac_dev->set_multi = set_multi;
529474
mac_dev->start = start;
530475
mac_dev->stop = stop;
531-
476+
mac_dev->adjust_link = adjust_link_dtsec;
532477
mac_dev->priv->enable = dtsec_enable;
533478
mac_dev->priv->disable = dtsec_disable;
534479
}
535480

536481
static void setup_tgec(struct mac_device *mac_dev)
537482
{
538-
mac_dev->init_phy = tgec_init_phy;
539483
mac_dev->init = tgec_initialization;
540484
mac_dev->set_promisc = tgec_set_promiscuous;
541485
mac_dev->change_addr = tgec_modify_mac_address;
@@ -547,14 +491,13 @@ static void setup_tgec(struct mac_device *mac_dev)
547491
mac_dev->set_multi = set_multi;
548492
mac_dev->start = start;
549493
mac_dev->stop = stop;
550-
494+
mac_dev->adjust_link = adjust_link_void;
551495
mac_dev->priv->enable = tgec_enable;
552496
mac_dev->priv->disable = tgec_disable;
553497
}
554498

555499
static void setup_memac(struct mac_device *mac_dev)
556500
{
557-
mac_dev->init_phy = memac_init_phy;
558501
mac_dev->init = memac_initialization;
559502
mac_dev->set_promisc = memac_set_promiscuous;
560503
mac_dev->change_addr = memac_modify_mac_address;
@@ -566,7 +509,7 @@ static void setup_memac(struct mac_device *mac_dev)
566509
mac_dev->set_multi = set_multi;
567510
mac_dev->start = start;
568511
mac_dev->stop = stop;
569-
512+
mac_dev->adjust_link = adjust_link_memac;
570513
mac_dev->priv->enable = memac_enable;
571514
mac_dev->priv->disable = memac_disable;
572515
}
@@ -850,13 +793,13 @@ static int mac_probe(struct platform_device *_of_dev)
850793
mac_node);
851794
phy_if = PHY_INTERFACE_MODE_SGMII;
852795
}
853-
priv->phy_if = phy_if;
796+
mac_dev->phy_if = phy_if;
854797

855-
priv->speed = phy2speed[priv->phy_if];
798+
priv->speed = phy2speed[mac_dev->phy_if];
856799
priv->max_speed = priv->speed;
857800
mac_dev->if_support = DTSEC_SUPPORTED;
858801
/* We don't support half-duplex in SGMII mode */
859-
if (priv->phy_if == PHY_INTERFACE_MODE_SGMII)
802+
if (mac_dev->phy_if == PHY_INTERFACE_MODE_SGMII)
860803
mac_dev->if_support &= ~(SUPPORTED_10baseT_Half |
861804
SUPPORTED_100baseT_Half);
862805

@@ -865,12 +808,12 @@ static int mac_probe(struct platform_device *_of_dev)
865808
mac_dev->if_support |= SUPPORTED_1000baseT_Full;
866809

867810
/* The 10G interface only supports one mode */
868-
if (priv->phy_if == PHY_INTERFACE_MODE_XGMII)
811+
if (mac_dev->phy_if == PHY_INTERFACE_MODE_XGMII)
869812
mac_dev->if_support = SUPPORTED_10000baseT_Full;
870813

871814
/* Get the rest of the PHY information */
872-
priv->phy_node = of_parse_phandle(mac_node, "phy-handle", 0);
873-
if (!priv->phy_node && of_phy_is_fixed_link(mac_node)) {
815+
mac_dev->phy_node = of_parse_phandle(mac_node, "phy-handle", 0);
816+
if (!mac_dev->phy_node && of_phy_is_fixed_link(mac_node)) {
874817
struct phy_device *phy;
875818

876819
err = of_phy_register_fixed_link(mac_node);
@@ -884,8 +827,8 @@ static int mac_probe(struct platform_device *_of_dev)
884827
goto _return_dev_set_drvdata;
885828
}
886829

887-
priv->phy_node = of_node_get(mac_node);
888-
phy = of_phy_find_device(priv->phy_node);
830+
mac_dev->phy_node = of_node_get(mac_node);
831+
phy = of_phy_find_device(mac_dev->phy_node);
889832
if (!phy) {
890833
err = -EINVAL;
891834
goto _return_dev_set_drvdata;
@@ -903,7 +846,7 @@ static int mac_probe(struct platform_device *_of_dev)
903846
err = mac_dev->init(mac_dev);
904847
if (err < 0) {
905848
dev_err(dev, "mac_dev->init() = %d\n", err);
906-
of_node_put(priv->phy_node);
849+
of_node_put(mac_dev->phy_node);
907850
goto _return_dev_set_drvdata;
908851
}
909852

drivers/net/ethernet/freescale/fman/mac.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ struct mac_device {
5050
struct fman_port *port[2];
5151
u32 if_support;
5252
struct phy_device *phy_dev;
53+
phy_interface_t phy_if;
54+
struct device_node *phy_node;
5355

5456
bool autoneg_pause;
5557
bool rx_pause_req;
@@ -58,11 +60,10 @@ struct mac_device {
5860
bool tx_pause_active;
5961
bool promisc;
6062

61-
struct phy_device *(*init_phy)(struct net_device *net_dev,
62-
struct mac_device *mac_dev);
6363
int (*init)(struct mac_device *mac_dev);
6464
int (*start)(struct mac_device *mac_dev);
6565
int (*stop)(struct mac_device *mac_dev);
66+
void (*adjust_link)(struct mac_device *mac_dev);
6667
int (*set_promisc)(struct fman_mac *mac_dev, bool enable);
6768
int (*change_addr)(struct fman_mac *mac_dev, enet_addr_t *enet_addr);
6869
int (*set_multi)(struct net_device *net_dev,

0 commit comments

Comments
 (0)