]> git.baikalelectronics.ru Git - kernel.git/commitdiff
dpaa2-eth: add basic devlink support
authorIoana Ciornei <ioana.ciornei@nxp.com>
Thu, 1 Oct 2020 15:11:47 +0000 (18:11 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 2 Oct 2020 23:31:56 +0000 (16:31 -0700)
Add basic support in dpaa2-eth for devlink. For the moment, just
register the device with devlink, add the corresponding devlink port and
implement the .info_get() callback.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/freescale/dpaa2/Makefile
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c [new file with mode: 0644]
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h

index 6e7f33c956bf43f0e1a33bbe37e28f7f4f87ea0a..146cb3540e6134befdae79c8e930d2c6ac893dc7 100644 (file)
@@ -6,7 +6,7 @@
 obj-$(CONFIG_FSL_DPAA2_ETH)            += fsl-dpaa2-eth.o
 obj-$(CONFIG_FSL_DPAA2_PTP_CLOCK)      += fsl-dpaa2-ptp.o
 
-fsl-dpaa2-eth-objs     := dpaa2-eth.o dpaa2-ethtool.o dpni.o dpaa2-mac.o dpmac.o
+fsl-dpaa2-eth-objs     := dpaa2-eth.o dpaa2-ethtool.o dpni.o dpaa2-mac.o dpmac.o dpaa2-eth-devlink.o
 fsl-dpaa2-eth-${CONFIG_FSL_DPAA2_ETH_DCB} += dpaa2-eth-dcb.o
 fsl-dpaa2-eth-${CONFIG_DEBUG_FS} += dpaa2-eth-debugfs.o
 fsl-dpaa2-ptp-objs     := dpaa2-ptp.o dprtc.o
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c
new file mode 100644 (file)
index 0000000..3691981
--- /dev/null
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
+#include "dpaa2-eth.h"
+/* Copyright 2020 NXP
+ */
+
+static int dpaa2_eth_dl_info_get(struct devlink *devlink,
+                                struct devlink_info_req *req,
+                                struct netlink_ext_ack *extack)
+{
+       struct dpaa2_eth_devlink_priv *dl_priv = devlink_priv(devlink);
+       struct dpaa2_eth_priv *priv = dl_priv->dpaa2_priv;
+       char buf[10];
+       int err;
+
+       err = devlink_info_driver_name_put(req, KBUILD_MODNAME);
+       if (err)
+               return err;
+
+       scnprintf(buf, 10, "%d.%d", priv->dpni_ver_major, priv->dpni_ver_minor);
+       err = devlink_info_version_running_put(req, "dpni", buf);
+       if (err)
+               return err;
+
+       return 0;
+}
+
+static const struct devlink_ops dpaa2_eth_devlink_ops = {
+       .info_get = dpaa2_eth_dl_info_get,
+};
+
+int dpaa2_eth_dl_register(struct dpaa2_eth_priv *priv)
+{
+       struct net_device *net_dev = priv->net_dev;
+       struct device *dev = net_dev->dev.parent;
+       struct dpaa2_eth_devlink_priv *dl_priv;
+       int err;
+
+       priv->devlink = devlink_alloc(&dpaa2_eth_devlink_ops, sizeof(*dl_priv));
+       if (!priv->devlink) {
+               dev_err(dev, "devlink_alloc failed\n");
+               return -ENOMEM;
+       }
+       dl_priv = devlink_priv(priv->devlink);
+       dl_priv->dpaa2_priv = priv;
+
+       err = devlink_register(priv->devlink, dev);
+       if (err) {
+               dev_err(dev, "devlink_register() = %d\n", err);
+               goto devlink_free;
+       }
+
+       return 0;
+
+devlink_free:
+       devlink_free(priv->devlink);
+
+       return err;
+}
+
+void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv)
+{
+       devlink_unregister(priv->devlink);
+       devlink_free(priv->devlink);
+}
+
+int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv)
+{
+       struct devlink_port *devlink_port = &priv->devlink_port;
+       struct devlink_port_attrs attrs = {};
+       int err;
+
+       attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
+       devlink_port_attrs_set(devlink_port, &attrs);
+
+       err = devlink_port_register(priv->devlink, devlink_port, 0);
+       if (err)
+               return err;
+
+       devlink_port_type_eth_set(devlink_port, priv->net_dev);
+
+       return 0;
+}
+
+void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv)
+{
+       struct devlink_port *devlink_port = &priv->devlink_port;
+
+       devlink_port_type_clear(devlink_port);
+       devlink_port_unregister(devlink_port);
+}
index fe4caf7aad7ca635a4874d3e233af6afe6ce0381..29c1c9263422d3b47e09d21ce5233d694b82ee06 100644 (file)
@@ -4223,6 +4223,14 @@ static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev)
        if (err)
                goto err_connect_mac;
 
+       err = dpaa2_eth_dl_register(priv);
+       if (err)
+               goto err_dl_register;
+
+       err = dpaa2_eth_dl_port_add(priv);
+       if (err)
+               goto err_dl_port_add;
+
        err = register_netdev(net_dev);
        if (err < 0) {
                dev_err(dev, "register_netdev() failed\n");
@@ -4237,6 +4245,10 @@ static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev)
        return 0;
 
 err_netdev_reg:
+       dpaa2_eth_dl_port_del(priv);
+err_dl_port_add:
+       dpaa2_eth_dl_unregister(priv);
+err_dl_register:
        dpaa2_eth_disconnect_mac(priv);
 err_connect_mac:
        if (priv->do_link_poll)
@@ -4291,6 +4303,9 @@ static int dpaa2_eth_remove(struct fsl_mc_device *ls_dev)
 
        unregister_netdev(net_dev);
 
+       dpaa2_eth_dl_port_del(priv);
+       dpaa2_eth_dl_unregister(priv);
+
        if (priv->do_link_poll)
                kthread_stop(priv->poll_thread);
        else
index 6436fa3b25cbdf8dc52db5acfdde56c450838a76..9da6fac7cfef4cd194ae67be8252aff1e7917b6d 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/if_vlan.h>
 #include <linux/fsl/mc.h>
 #include <linux/net_tstamp.h>
+#include <net/devlink.h>
 
 #include <soc/fsl/dpaa2-io.h>
 #include <soc/fsl/dpaa2-fd.h>
@@ -503,6 +504,12 @@ struct dpaa2_eth_priv {
         * queue before transmit current packet.
         */
        struct mutex            onestep_tstamp_lock;
+       struct devlink *devlink;
+       struct devlink_port devlink_port;
+};
+
+struct dpaa2_eth_devlink_priv {
+       struct dpaa2_eth_priv *dpaa2_priv;
 };
 
 #define TX_TSTAMP              0x1
@@ -636,4 +643,10 @@ void dpaa2_eth_set_rx_taildrop(struct dpaa2_eth_priv *priv,
 
 extern const struct dcbnl_rtnl_ops dpaa2_eth_dcbnl_ops;
 
+int dpaa2_eth_dl_register(struct dpaa2_eth_priv *priv);
+void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv);
+
+int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv);
+void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv);
+
 #endif /* __DPAA2_H */