layerscape: add patches-5.4
[openwrt/staging/mkresin.git] / target / linux / layerscape / patches-5.4 / 701-net-0171-staging-fsl-dpaa2-mac-Check-DPMAC-version.patch
1 From 2dc96021dc08d24eed822f66cb8fb5a454fee236 Mon Sep 17 00:00:00 2001
2 From: Ioana Radulescu <ruxandra.radulescu@nxp.com>
3 Date: Fri, 19 Oct 2018 16:20:07 +0300
4 Subject: [PATCH] staging: fsl-dpaa2/mac: Check DPMAC version
5
6 Read the current API version exposed by the DPMAC object.
7 Add a check at probe time to make sure it is compatible with
8 the set of MC commands we intend to use on it.
9 Also, print the version number through ethtool driver info.
10
11 Signed-off-by: Catalin Neacsu <valentin-catalin.neacsu@nxp.com>
12 Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
13 ---
14 drivers/staging/fsl-dpaa2/mac/mac.c | 39 +++++++++++++++++++++++++++++++++++++
15 1 file changed, 39 insertions(+)
16
17 --- a/drivers/staging/fsl-dpaa2/mac/mac.c
18 +++ b/drivers/staging/fsl-dpaa2/mac/mac.c
19 @@ -56,6 +56,8 @@ struct dpaa2_mac_priv {
20 struct fsl_mc_device *mc_dev;
21 struct dpmac_attr attr;
22 struct dpmac_link_state old_state;
23 + u16 dpmac_ver_major;
24 + u16 dpmac_ver_minor;
25 };
26
27 /* TODO: fix the 10G modes, mapping can't be right:
28 @@ -81,6 +83,14 @@ static phy_interface_t dpaa2_mac_iface_m
29 PHY_INTERFACE_MODE_XGMII, /* DPMAC_ETH_IF_USXGMII */
30 };
31
32 +static int cmp_dpmac_ver(struct dpaa2_mac_priv *priv,
33 + u16 ver_major, u16 ver_minor)
34 +{
35 + if (priv->dpmac_ver_major == ver_major)
36 + return priv->dpmac_ver_minor - ver_minor;
37 + return priv->dpmac_ver_major - ver_major;
38 +}
39 +
40 static void dpaa2_mac_link_changed(struct net_device *netdev)
41 {
42 struct phy_device *phydev;
43 @@ -154,6 +164,18 @@ static netdev_tx_t dpaa2_mac_drop_frame(
44 return NETDEV_TX_OK;
45 }
46
47 +static void dpaa2_mac_get_drvinfo(struct net_device *net_dev,
48 + struct ethtool_drvinfo *drvinfo)
49 +{
50 + struct dpaa2_mac_priv *priv = netdev_priv(net_dev);
51 +
52 + strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
53 + snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
54 + "%u.%u", priv->dpmac_ver_major, priv->dpmac_ver_minor);
55 + strlcpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent),
56 + sizeof(drvinfo->bus_info));
57 +}
58 +
59 static int dpaa2_mac_get_link_ksettings(struct net_device *netdev,
60 struct ethtool_link_ksettings *ks)
61 {
62 @@ -323,6 +345,7 @@ static const struct net_device_ops dpaa2
63 };
64
65 static const struct ethtool_ops dpaa2_mac_ethtool_ops = {
66 + .get_drvinfo = &dpaa2_mac_get_drvinfo,
67 .get_link_ksettings = &dpaa2_mac_get_link_ksettings,
68 .set_link_ksettings = &dpaa2_mac_set_link_ksettings,
69 .get_strings = &dpaa2_mac_get_strings,
70 @@ -510,6 +533,21 @@ static int dpaa2_mac_probe(struct fsl_mc
71 goto err_free_mcp;
72 }
73
74 + err = dpmac_get_api_version(mc_dev->mc_io, 0, &priv->dpmac_ver_major,
75 + &priv->dpmac_ver_minor);
76 + if (err) {
77 + dev_err(dev, "dpmac_get_api_version failed\n");
78 + goto err_version;
79 + }
80 +
81 + if (cmp_dpmac_ver(priv, DPMAC_VER_MAJOR, DPMAC_VER_MINOR) < 0) {
82 + dev_err(dev, "DPMAC version %u.%u lower than supported %u.%u\n",
83 + priv->dpmac_ver_major, priv->dpmac_ver_minor,
84 + DPMAC_VER_MAJOR, DPMAC_VER_MINOR);
85 + err = -ENOTSUPP;
86 + goto err_version;
87 + }
88 +
89 err = dpmac_get_attributes(mc_dev->mc_io, 0,
90 mc_dev->mc_handle, &priv->attr);
91 if (err) {
92 @@ -622,6 +660,7 @@ err_no_phy:
93 err_free_irq:
94 #endif
95 teardown_irqs(mc_dev);
96 +err_version:
97 err_close:
98 dpmac_close(mc_dev->mc_io, 0, mc_dev->mc_handle);
99 err_free_mcp: