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
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.
11 Signed-off-by: Catalin Neacsu <valentin-catalin.neacsu@nxp.com>
12 Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
14 drivers/staging/fsl-dpaa2/mac/mac.c | 39 +++++++++++++++++++++++++++++++++++++
15 1 file changed, 39 insertions(+)
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;
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 */
32 +static int cmp_dpmac_ver(struct dpaa2_mac_priv *priv,
33 + u16 ver_major, u16 ver_minor)
35 + if (priv->dpmac_ver_major == ver_major)
36 + return priv->dpmac_ver_minor - ver_minor;
37 + return priv->dpmac_ver_major - ver_major;
40 static void dpaa2_mac_link_changed(struct net_device *netdev)
42 struct phy_device *phydev;
43 @@ -154,6 +164,18 @@ static netdev_tx_t dpaa2_mac_drop_frame(
47 +static void dpaa2_mac_get_drvinfo(struct net_device *net_dev,
48 + struct ethtool_drvinfo *drvinfo)
50 + struct dpaa2_mac_priv *priv = netdev_priv(net_dev);
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));
59 static int dpaa2_mac_get_link_ksettings(struct net_device *netdev,
60 struct ethtool_link_ksettings *ks)
62 @@ -323,6 +345,7 @@ static const struct net_device_ops dpaa2
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
74 + err = dpmac_get_api_version(mc_dev->mc_io, 0, &priv->dpmac_ver_major,
75 + &priv->dpmac_ver_minor);
77 + dev_err(dev, "dpmac_get_api_version failed\n");
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);
89 err = dpmac_get_attributes(mc_dev->mc_io, 0,
90 mc_dev->mc_handle, &priv->attr);
92 @@ -622,6 +660,7 @@ err_no_phy:
95 teardown_irqs(mc_dev);
98 dpmac_close(mc_dev->mc_io, 0, mc_dev->mc_handle);