25a9e90fbfb646edead34bdd90f08d9697c42503
[openwrt/openwrt.git] /
1 From 0a5243abf168351ea8409caf329448a3e18ab62f Mon Sep 17 00:00:00 2001
2 From: Ioana Radulescu <ruxandra.radulescu@nxp.com>
3 Date: Tue, 24 Sep 2019 13:24:40 +0300
4 Subject: [PATCH] dpaa2-eth: Re-add get_link_ksettings ethtool op
5
6 Which was removed from upstream driver since without a MAC driver
7 we have no support for changing link parameters there.
8
9 Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
10 ---
11 .../net/ethernet/freescale/dpaa2/dpaa2-ethtool.c | 47 +++++++++++++++++++++-
12 1 file changed, 46 insertions(+), 1 deletion(-)
13
14 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c
15 +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c
16 @@ -85,7 +85,8 @@ dpaa2_eth_get_link_ksettings(struct net_
17 {
18 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
19
20 - link_settings->base.autoneg = AUTONEG_DISABLE;
21 + if (priv->link_state.options & DPNI_LINK_OPT_AUTONEG)
22 + link_settings->base.autoneg = AUTONEG_ENABLE;
23 if (!(priv->link_state.options & DPNI_LINK_OPT_HALF_DUPLEX))
24 link_settings->base.duplex = DUPLEX_FULL;
25 link_settings->base.speed = priv->link_state.rate;
26 @@ -93,6 +94,49 @@ dpaa2_eth_get_link_ksettings(struct net_
27 return 0;
28 }
29
30 +#define DPNI_DYNAMIC_LINK_SET_VER_MAJOR 7
31 +#define DPNI_DYNAMIC_LINK_SET_VER_MINOR 1
32 +static int
33 +dpaa2_eth_set_link_ksettings(struct net_device *net_dev,
34 + const struct ethtool_link_ksettings *link_settings)
35 +{
36 + struct dpni_link_cfg cfg = {0};
37 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
38 + int err = 0;
39 +
40 + /* If using an older MC version, the DPNI must be down
41 + * in order to be able to change link settings. Taking steps to let
42 + * the user know that.
43 + */
44 + if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_DYNAMIC_LINK_SET_VER_MAJOR,
45 + DPNI_DYNAMIC_LINK_SET_VER_MINOR) < 0) {
46 + if (netif_running(net_dev)) {
47 + netdev_info(net_dev, "Interface must be brought down first.\n");
48 + return -EACCES;
49 + }
50 + }
51 +
52 + cfg.rate = link_settings->base.speed;
53 + cfg.options = priv->link_state.options;
54 + if (link_settings->base.autoneg == AUTONEG_ENABLE)
55 + cfg.options |= DPNI_LINK_OPT_AUTONEG;
56 + else
57 + cfg.options &= ~DPNI_LINK_OPT_AUTONEG;
58 + if (link_settings->base.duplex == DUPLEX_HALF)
59 + cfg.options |= DPNI_LINK_OPT_HALF_DUPLEX;
60 + else
61 + cfg.options &= ~DPNI_LINK_OPT_HALF_DUPLEX;
62 +
63 + err = dpni_set_link_cfg(priv->mc_io, 0, priv->mc_token, &cfg);
64 + if (err)
65 + /* ethtool will be loud enough if we return an error; no point
66 + * in putting our own error message on the console by default
67 + */
68 + netdev_dbg(net_dev, "ERROR %d setting link cfg\n", err);
69 +
70 + return err;
71 +}
72 +
73 static void dpaa2_eth_get_pauseparam(struct net_device *net_dev,
74 struct ethtool_pauseparam *pause)
75 {
76 @@ -734,6 +778,7 @@ const struct ethtool_ops dpaa2_ethtool_o
77 .get_drvinfo = dpaa2_eth_get_drvinfo,
78 .get_link = ethtool_op_get_link,
79 .get_link_ksettings = dpaa2_eth_get_link_ksettings,
80 + .set_link_ksettings = dpaa2_eth_set_link_ksettings,
81 .get_pauseparam = dpaa2_eth_get_pauseparam,
82 .set_pauseparam = dpaa2_eth_set_pauseparam,
83 .get_sset_count = dpaa2_eth_get_sset_count,