net: hns3: Add dcb netlink interface for the support of DCB feature
authorYunsheng Lin <linyunsheng@huawei.com>
Wed, 27 Sep 2017 01:45:30 +0000 (09:45 +0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 28 Sep 2017 17:35:12 +0000 (10:35 -0700)
This patch add dcb netlink interface by calling the interface from
hclge_dcb module.

This patch also update Makefile in order to build hns3_dcbnl module.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile
drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_dcbnl.c [new file with mode: 0644]
drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h

index 7023dc8780860b836c49cda53b4e54a1754a84d9..d2b20d01a58c5d1866e08a1679d9fe6952ddec55 100644 (file)
@@ -11,3 +11,5 @@ hclge-$(CONFIG_HNS3_DCB) += hclge_dcb.o
 
 obj-$(CONFIG_HNS3_ENET) += hns3.o
 hns3-objs = hns3_enet.o hns3_ethtool.o
+
+hns3-$(CONFIG_HNS3_DCB) += hns3_dcbnl.o
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_dcbnl.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_dcbnl.c
new file mode 100644 (file)
index 0000000..9832172
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2016-2017 Hisilicon Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include "hnae3.h"
+#include "hns3_enet.h"
+
+static
+int hns3_dcbnl_ieee_getets(struct net_device *ndev, struct ieee_ets *ets)
+{
+       struct hns3_nic_priv *priv = netdev_priv(ndev);
+       struct hnae3_handle *h = priv->ae_handle;
+
+       if (h->kinfo.dcb_ops->ieee_getets)
+               return h->kinfo.dcb_ops->ieee_getets(h, ets);
+
+       return -EOPNOTSUPP;
+}
+
+static
+int hns3_dcbnl_ieee_setets(struct net_device *ndev, struct ieee_ets *ets)
+{
+       struct hns3_nic_priv *priv = netdev_priv(ndev);
+       struct hnae3_handle *h = priv->ae_handle;
+
+       if (h->kinfo.dcb_ops->ieee_setets)
+               return h->kinfo.dcb_ops->ieee_setets(h, ets);
+
+       return -EOPNOTSUPP;
+}
+
+static
+int hns3_dcbnl_ieee_getpfc(struct net_device *ndev, struct ieee_pfc *pfc)
+{
+       struct hns3_nic_priv *priv = netdev_priv(ndev);
+       struct hnae3_handle *h = priv->ae_handle;
+
+       if (h->kinfo.dcb_ops->ieee_getpfc)
+               return h->kinfo.dcb_ops->ieee_getpfc(h, pfc);
+
+       return -EOPNOTSUPP;
+}
+
+static
+int hns3_dcbnl_ieee_setpfc(struct net_device *ndev, struct ieee_pfc *pfc)
+{
+       struct hns3_nic_priv *priv = netdev_priv(ndev);
+       struct hnae3_handle *h = priv->ae_handle;
+
+       if (h->kinfo.dcb_ops->ieee_setpfc)
+               return h->kinfo.dcb_ops->ieee_setpfc(h, pfc);
+
+       return -EOPNOTSUPP;
+}
+
+/* DCBX configuration */
+static u8 hns3_dcbnl_getdcbx(struct net_device *ndev)
+{
+       struct hns3_nic_priv *priv = netdev_priv(ndev);
+       struct hnae3_handle *h = priv->ae_handle;
+
+       if (h->kinfo.dcb_ops->getdcbx)
+               return h->kinfo.dcb_ops->getdcbx(h);
+
+       return 0;
+}
+
+/* return 0 if successful, otherwise fail */
+static u8 hns3_dcbnl_setdcbx(struct net_device *ndev, u8 mode)
+{
+       struct hns3_nic_priv *priv = netdev_priv(ndev);
+       struct hnae3_handle *h = priv->ae_handle;
+
+       if (h->kinfo.dcb_ops->setdcbx)
+               return h->kinfo.dcb_ops->setdcbx(h, mode);
+
+       return 1;
+}
+
+static const struct dcbnl_rtnl_ops hns3_dcbnl_ops = {
+       .ieee_getets    = hns3_dcbnl_ieee_getets,
+       .ieee_setets    = hns3_dcbnl_ieee_setets,
+       .ieee_getpfc    = hns3_dcbnl_ieee_getpfc,
+       .ieee_setpfc    = hns3_dcbnl_ieee_setpfc,
+       .getdcbx        = hns3_dcbnl_getdcbx,
+       .setdcbx        = hns3_dcbnl_setdcbx,
+};
+
+/* hclge_dcbnl_setup - DCBNL setup
+ * @handle: the corresponding vport handle
+ * Set up DCBNL
+ */
+void hns3_dcbnl_setup(struct hnae3_handle *handle)
+{
+       struct net_device *dev = handle->kinfo.netdev;
+
+       if (!handle->kinfo.dcb_ops)
+               return;
+
+       dev->dcbnl_ops = &hns3_dcbnl_ops;
+}
index 35369e1c8036f3abbade76b63eed2a103170b4c7..11dab26f35432c5cc2d60f3016be9ba37862af46 100644 (file)
@@ -2790,6 +2790,8 @@ static int hns3_client_init(struct hnae3_handle *handle)
                goto out_reg_netdev_fail;
        }
 
+       hns3_dcbnl_setup(handle);
+
        /* MTU range: (ETH_MIN_MTU(kernel default) - 9706) */
        netdev->max_mtu = HNS3_MAX_MTU - (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
 
index 7e87461897475e3589ee629e9c1ac7a57904ed7d..481eada73e2d8e4b6c712dc959c5e1def0f84403 100644 (file)
@@ -590,4 +590,11 @@ static inline void hns3_write_reg(void __iomem *base, u32 reg, u32 value)
 void hns3_ethtool_set_ops(struct net_device *netdev);
 
 int hns3_clean_tx_ring(struct hns3_enet_ring *ring, int budget);
+
+#ifdef CONFIG_HNS3_DCB
+void hns3_dcbnl_setup(struct hnae3_handle *handle);
+#else
+static inline void hns3_dcbnl_setup(struct hnae3_handle *handle) {}
+#endif
+
 #endif