net/hinic: add VLAN filter and offload
authorXiaoyun Wang <cloud.wangxiaoyun@huawei.com>
Thu, 10 Oct 2019 14:51:48 +0000 (22:51 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 23 Oct 2019 14:43:08 +0000 (16:43 +0200)
This patch adds support for VLAN filter and VLAN offload.

Signed-off-by: Xiaoyun Wang <cloud.wangxiaoyun@huawei.com>
doc/guides/nics/features/hinic.ini
doc/guides/nics/hinic.rst
doc/guides/rel_notes/release_19_11.rst
drivers/net/hinic/base/hinic_pmd_cmd.h
drivers/net/hinic/base/hinic_pmd_niccfg.c
drivers/net/hinic/base/hinic_pmd_niccfg.h
drivers/net/hinic/hinic_pmd_ethdev.c
drivers/net/hinic/hinic_pmd_ethdev.h

index c858411..8b09509 100644 (file)
@@ -20,6 +20,8 @@ RSS key update       = Y
 RSS reta update      = Y
 Inner RSS            = Y
 SR-IOV               = Y
+VLAN filter          = Y
+VLAN offload         = Y
 CRC offload          = Y
 L3 checksum offload  = Y
 L4 checksum offload  = Y
index c3ce101..881075a 100644 (file)
@@ -25,6 +25,7 @@ Features
 - Link flow control
 - Scattered and gather for TX and RX
 - SR-IOV - Partially supported at this point, VFIO only
+- VLAN filter and VLAN offload
 
 Prerequisites
 -------------
index 4a918da..803a0ff 100644 (file)
@@ -116,6 +116,7 @@ New Features
   Updated the Huawei hinic driver with new features and improvements, including:
 
   * Enabled SR-IOV - Partially supported at this point, VFIO only.
+  * Supported VLAN filter and VLAN offload.
 
 * **Added Marvell NITROX symmetric crypto PMD.**
 
index c8750b8..5c38b5f 100644 (file)
@@ -140,6 +140,7 @@ enum hinic_port_cmd {
 
        HINIC_PORT_CMD_SET_VHD_CFG              = 0xF7,
        HINIC_PORT_CMD_SET_LINK_FOLLOW          = 0xF8,
+       HINIC_PORT_CMD_SET_VLAN_FILTER          = 0xFF
 };
 
 /* cmd of mgmt CPU message for HW module */
index 0a20ade..8bd7ed6 100644 (file)
@@ -289,6 +289,142 @@ int hinic_set_port_mtu(void *hwdev, u32 new_mtu)
        return 0;
 }
 
+/**
+ * hinic_add_remove_vlan - Add or remove vlan id to vlan elb table.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param vlan_id
+ *   Vlan id.
+ * @param func_id
+ *   Global function id of NIC.
+ * @param add
+ *   Add or remove operation.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
+int hinic_add_remove_vlan(void *hwdev, u16 vlan_id, u16 func_id, bool add)
+{
+       struct hinic_vlan_config vlan_info;
+       u16 out_size = sizeof(vlan_info);
+       u8 cmd;
+       int err;
+
+       if (!hwdev) {
+               PMD_DRV_LOG(ERR, "Hwdev is NULL");
+               return -EINVAL;
+       }
+
+       cmd = add ? HINIC_PORT_CMD_ADD_VLAN : HINIC_PORT_CMD_DEL_VLAN;
+
+       memset(&vlan_info, 0, sizeof(vlan_info));
+       vlan_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+       vlan_info.func_id = func_id;
+       vlan_info.vlan_id = vlan_id;
+
+       err = l2nic_msg_to_mgmt_sync(hwdev, cmd, &vlan_info,
+                                    sizeof(vlan_info), &vlan_info,
+                                    &out_size);
+       if (err || !out_size || vlan_info.mgmt_msg_head.status) {
+               PMD_DRV_LOG(ERR,
+                       "Failed to %s vlan, err: %d, status: 0x%x, out size: 0x%x\n",
+                       add ? "add" : "remove", err,
+                       vlan_info.mgmt_msg_head.status, out_size);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+/**
+ * hinic_config_vlan_filter - Enable or Disable vlan filter.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param vlan_filter_ctrl
+ *   Enable or Disable.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
+int hinic_config_vlan_filter(void *hwdev, u32 vlan_filter_ctrl)
+{
+       struct hinic_hwdev *nic_hwdev = (struct hinic_hwdev *)hwdev;
+       struct hinic_vlan_filter vlan_filter;
+       u16 out_size = sizeof(vlan_filter);
+       int err;
+
+       if (!hwdev)
+               return -EINVAL;
+
+       memset(&vlan_filter, 0, sizeof(vlan_filter));
+       vlan_filter.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+       vlan_filter.func_id = hinic_global_func_id(nic_hwdev);
+       vlan_filter.vlan_filter_ctrl = vlan_filter_ctrl;
+
+       err = l2nic_msg_to_mgmt_sync(nic_hwdev, HINIC_PORT_CMD_SET_VLAN_FILTER,
+                                    &vlan_filter, sizeof(vlan_filter),
+                                    &vlan_filter, &out_size);
+       if (vlan_filter.mgmt_msg_head.status == HINIC_MGMT_CMD_UNSUPPORTED) {
+               err = HINIC_MGMT_CMD_UNSUPPORTED;
+       } else if ((err == HINIC_MBOX_VF_CMD_ERROR) &&
+               (HINIC_IS_VF(nic_hwdev))) {
+               err = HINIC_MGMT_CMD_UNSUPPORTED;
+       } else if (err || !out_size || vlan_filter.mgmt_msg_head.status) {
+               PMD_DRV_LOG(ERR,
+                       "Failed to config vlan filter, vlan_filter_ctrl: 0x%x, err: %d, status: 0x%x, out size: 0x%x\n",
+                       vlan_filter_ctrl, err,
+                       vlan_filter.mgmt_msg_head.status, out_size);
+               err = -EINVAL;
+       }
+
+       return err;
+}
+
+/**
+ * hinic_set_rx_vlan_offload - Enable or Disable vlan offload.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param en
+ *   Enable or Disable.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
+int hinic_set_rx_vlan_offload(void *hwdev, u8 en)
+{
+       struct hinic_vlan_offload vlan_cfg;
+       u16 out_size = sizeof(vlan_cfg);
+       int err;
+
+       if (!hwdev) {
+               PMD_DRV_LOG(ERR, "Hwdev is NULL");
+               return -EINVAL;
+       }
+
+       memset(&vlan_cfg, 0, sizeof(vlan_cfg));
+       vlan_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+       vlan_cfg.func_id = hinic_global_func_id(hwdev);
+       vlan_cfg.vlan_rx_offload = en;
+
+       err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RX_VLAN_OFFLOAD,
+                                       &vlan_cfg, sizeof(vlan_cfg),
+                                       &vlan_cfg, &out_size);
+       if (err || !out_size || vlan_cfg.mgmt_msg_head.status) {
+               PMD_DRV_LOG(ERR,
+                       "Failed to set rx vlan offload, err: %d, status: 0x%x, out size: 0x%x\n",
+                       err, vlan_cfg.mgmt_msg_head.status, out_size);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 /**
  * hinic_get_link_status - Get link status from hardware.
  *
index 94371bb..d19a834 100644 (file)
@@ -380,6 +380,29 @@ struct hinic_mtu {
        u32     mtu;
 };
 
+struct hinic_vlan_config {
+       struct hinic_mgmt_msg_head mgmt_msg_head;
+
+       u16     func_id;
+       u16     vlan_id;
+};
+
+struct hinic_vlan_filter {
+       struct hinic_mgmt_msg_head mgmt_msg_head;
+
+       u16     func_id;
+       u8      rsvd1[2];
+       u32     vlan_filter_ctrl;
+};
+
+struct hinic_vlan_offload {
+       struct hinic_mgmt_msg_head mgmt_msg_head;
+
+       u16     func_id;
+       u8      vlan_rx_offload;
+       u8      rsvd1[5];
+};
+
 struct hinic_get_link {
        struct hinic_mgmt_msg_head mgmt_msg_head;
 
@@ -597,6 +620,12 @@ int hinic_get_default_mac(void *hwdev, u8 *mac_addr);
 
 int hinic_set_port_mtu(void *hwdev, u32 new_mtu);
 
+int hinic_add_remove_vlan(void *hwdev, u16 vlan_id, u16 func_id, bool add);
+
+int hinic_config_vlan_filter(void *hwdev, u32 vlan_filter_ctrl);
+
+int hinic_set_rx_vlan_offload(void *hwdev, u8 en);
+
 int hinic_set_vport_enable(void *hwdev, bool enable);
 
 int hinic_set_port_enable(void *hwdev, bool enable);
index 2f413e3..4e2a69c 100644 (file)
@@ -10,6 +10,7 @@
 #include <rte_memcpy.h>
 #include <rte_mempool.h>
 #include <rte_errno.h>
+#include <rte_ether.h>
 
 #include "base/hinic_compat.h"
 #include "base/hinic_pmd_hwdev.h"
 #define HINIC_MIN_RX_BUF_SIZE          1024
 #define HINIC_MAX_MAC_ADDRS            1
 
+/*
+ * vlan_id is a 12 bit number.
+ * The VFTA array is actually a 4096 bit array, 128 of 32bit elements.
+ * 2^5 = 32. The val of lower 5 bits specifies the bit in the 32bit element.
+ * The higher 7 bit val specifies VFTA array index.
+ */
+#define HINIC_VFTA_BIT(vlan_id)    (1 << ((vlan_id) & 0x1F))
+#define HINIC_VFTA_IDX(vlan_id)    ((vlan_id) >> 5)
+
+#define HINIC_VLAN_FILTER_EN           (1U << 0)
+
 /* Driver-specific log messages type */
 int hinic_logtype;
 
@@ -230,6 +242,7 @@ static const struct rte_eth_desc_lim hinic_tx_desc_lim = {
        .nb_align = HINIC_TXD_ALIGN,
 };
 
+static int hinic_vlan_offload_set(struct rte_eth_dev *dev, int mask);
 
 /**
  * Interrupt handler triggered by NIC  for handling
@@ -313,6 +326,15 @@ static int hinic_dev_configure(struct rte_eth_dev *dev)
                return err;
        }
 
+       /* init vlan offoad */
+       err = hinic_vlan_offload_set(dev,
+                               ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK);
+       if (err) {
+               PMD_DRV_LOG(ERR, "Initialize vlan filter and strip failed\n");
+               (void)hinic_config_mq_mode(dev, FALSE);
+               return err;
+       }
+
        return HINIC_OK;
 }
 
@@ -695,7 +717,8 @@ hinic_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
        info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
                                DEV_RX_OFFLOAD_IPV4_CKSUM |
                                DEV_RX_OFFLOAD_UDP_CKSUM |
-                               DEV_RX_OFFLOAD_TCP_CKSUM;
+                               DEV_RX_OFFLOAD_TCP_CKSUM |
+                               DEV_RX_OFFLOAD_VLAN_FILTER;
 
        info->tx_queue_offload_capa = 0;
        info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
@@ -1353,6 +1376,170 @@ static void hinic_deinit_mac_addr(struct rte_eth_dev *eth_dev)
                            eth_dev->data->name);
 }
 
+static void hinic_store_vlan_filter(struct hinic_nic_dev *nic_dev,
+                                       u16 vlan_id, bool on)
+{
+       u32 vid_idx, vid_bit;
+
+       vid_idx = HINIC_VFTA_IDX(vlan_id);
+       vid_bit = HINIC_VFTA_BIT(vlan_id);
+
+       if (on)
+               nic_dev->vfta[vid_idx] |= vid_bit;
+       else
+               nic_dev->vfta[vid_idx] &= ~vid_bit;
+}
+
+static bool hinic_find_vlan_filter(struct hinic_nic_dev *nic_dev,
+                               uint16_t vlan_id)
+{
+       u32 vid_idx, vid_bit;
+
+       vid_idx = HINIC_VFTA_IDX(vlan_id);
+       vid_bit = HINIC_VFTA_BIT(vlan_id);
+
+       return (nic_dev->vfta[vid_idx] & vid_bit) ? TRUE : FALSE;
+}
+
+/**
+ * DPDK callback to set vlan filter.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param vlan_id
+ *   vlan id is used to filter vlan packets
+ * @param enable
+ *   enable disable or enable vlan filter function
+ */
+static int hinic_vlan_filter_set(struct rte_eth_dev *dev,
+                               uint16_t vlan_id, int enable)
+{
+       struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+       int err = 0;
+       u16 func_id;
+
+       if (vlan_id > RTE_ETHER_MAX_VLAN_ID)
+               return -EINVAL;
+
+       func_id = hinic_global_func_id(nic_dev->hwdev);
+
+       if (enable) {
+               /* If vlanid is already set, just return */
+               if (hinic_find_vlan_filter(nic_dev, vlan_id)) {
+                       PMD_DRV_LOG(INFO, "Vlan %u has been added, device: %s",
+                                 vlan_id, nic_dev->proc_dev_name);
+                       return 0;
+               }
+
+               err = hinic_add_remove_vlan(nic_dev->hwdev, vlan_id,
+                                           func_id, TRUE);
+       } else {
+               /* If vlanid can't be found, just return */
+               if (!hinic_find_vlan_filter(nic_dev, vlan_id)) {
+                       PMD_DRV_LOG(INFO, "Vlan %u is not in the vlan filter list, device: %s",
+                                 vlan_id, nic_dev->proc_dev_name);
+                       return 0;
+               }
+
+               err = hinic_add_remove_vlan(nic_dev->hwdev, vlan_id,
+                                           func_id, FALSE);
+       }
+
+       if (err) {
+               PMD_DRV_LOG(ERR, "%s vlan failed, func_id: %d, vlan_id: %d, err: %d",
+                     enable ? "Add" : "Remove", func_id, vlan_id, err);
+               return err;
+       }
+
+       hinic_store_vlan_filter(nic_dev, vlan_id, enable);
+
+       PMD_DRV_LOG(INFO, "%s vlan %u succeed, device: %s",
+                 enable ? "Add" : "Remove", vlan_id, nic_dev->proc_dev_name);
+       return 0;
+}
+
+/**
+ * DPDK callback to enable or disable vlan offload.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param mask
+ *   Definitions used for VLAN setting
+ */
+static int hinic_vlan_offload_set(struct rte_eth_dev *dev, int mask)
+{
+       struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+       struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
+       bool on;
+       int err;
+
+       /* Enable or disable VLAN filter */
+       if (mask & ETH_VLAN_FILTER_MASK) {
+               on = (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER) ?
+                       TRUE : FALSE;
+               err = hinic_config_vlan_filter(nic_dev->hwdev, on);
+               if (err == HINIC_MGMT_CMD_UNSUPPORTED) {
+                       PMD_DRV_LOG(WARNING,
+                               "Current matching version does not support vlan filter configuration, device: %s, port_id: %d",
+                                 nic_dev->proc_dev_name, dev->data->port_id);
+               } else if (err) {
+                       PMD_DRV_LOG(ERR, "Failed to %s vlan filter, device: %s, port_id: %d, err: %d",
+                                 on ? "enable" : "disable",
+                                 nic_dev->proc_dev_name,
+                                 dev->data->port_id, err);
+                       return err;
+               }
+
+               PMD_DRV_LOG(INFO, "%s vlan filter succeed, device: %s, port_id: %d",
+                         on ? "Enable" : "Disable",
+                         nic_dev->proc_dev_name, dev->data->port_id);
+       }
+
+       /* Enable or disable VLAN stripping */
+       if (mask & ETH_VLAN_STRIP_MASK) {
+               on = (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) ?
+                       TRUE : FALSE;
+               err = hinic_set_rx_vlan_offload(nic_dev->hwdev, on);
+               if (err) {
+                       PMD_DRV_LOG(ERR, "Failed to %s vlan strip, device: %s, port_id: %d, err: %d",
+                                 on ? "enable" : "disable",
+                                 nic_dev->proc_dev_name,
+                                 dev->data->port_id, err);
+                       return err;
+               }
+
+               PMD_DRV_LOG(INFO, "%s vlan strip succeed, device: %s, port_id: %d",
+                         on ? "Enable" : "Disable",
+                         nic_dev->proc_dev_name, dev->data->port_id);
+       }
+
+       if (mask & ETH_VLAN_EXTEND_MASK) {
+               PMD_DRV_LOG(ERR, "Don't support vlan qinq, device: %s, port_id: %d",
+                         nic_dev->proc_dev_name, dev->data->port_id);
+               return -ENOTSUP;
+       }
+
+       return 0;
+}
+
+static void hinic_remove_all_vlanid(struct rte_eth_dev *eth_dev)
+{
+       struct hinic_nic_dev *nic_dev =
+               HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(eth_dev);
+       u16 func_id;
+       int i;
+
+       func_id = hinic_global_func_id(nic_dev->hwdev);
+       for (i = 0; i <= RTE_ETHER_MAX_VLAN_ID; i++) {
+               /* If can't find it, continue */
+               if (!hinic_find_vlan_filter(nic_dev, i))
+                       continue;
+
+               (void)hinic_add_remove_vlan(nic_dev->hwdev, i, func_id, FALSE);
+               hinic_store_vlan_filter(nic_dev, i, false);
+       }
+}
+
 /**
  * DPDK callback to enable promiscuous mode.
  *
@@ -2214,6 +2401,7 @@ static void hinic_dev_close(struct rte_eth_dev *dev)
 
        /* deinit mac vlan tbl */
        hinic_deinit_mac_addr(dev);
+       hinic_remove_all_vlanid(dev);
 
        /* disable hardware and uio interrupt */
        hinic_disable_interrupt(dev);
@@ -2233,6 +2421,8 @@ static const struct eth_dev_ops hinic_pmd_ops = {
        .tx_queue_release              = hinic_tx_queue_release,
        .dev_stop                      = hinic_dev_stop,
        .dev_close                     = hinic_dev_close,
+       .vlan_filter_set               = hinic_vlan_filter_set,
+       .vlan_offload_set              = hinic_vlan_offload_set,
        .promiscuous_enable            = hinic_dev_promiscuous_enable,
        .promiscuous_disable           = hinic_dev_promiscuous_disable,
        .rss_hash_update               = hinic_rss_hash_update,
@@ -2257,6 +2447,8 @@ static const struct eth_dev_ops hinic_pmd_vf_ops = {
        .tx_queue_release              = hinic_tx_queue_release,
        .dev_stop                      = hinic_dev_stop,
        .dev_close                     = hinic_dev_close,
+       .vlan_filter_set               = hinic_vlan_filter_set,
+       .vlan_offload_set              = hinic_vlan_offload_set,
        .rss_hash_update               = hinic_rss_hash_update,
        .rss_hash_conf_get             = hinic_rss_conf_get,
        .reta_update                   = hinic_rss_indirtbl_update,
index 4aeddc2..66eaf20 100644 (file)
 #include "base/hinic_compat.h"
 #include "base/hinic_pmd_cfg.h"
 
-#define HINIC_DEV_NAME_LEN     (32)
-#define HINIC_MAX_RX_QUEUES    (64)
+#define HINIC_DEV_NAME_LEN     32
+#define HINIC_MAX_RX_QUEUES    64
 
 /* mbuf pool for copy invalid mbuf segs */
-#define HINIC_COPY_MEMPOOL_DEPTH (128)
-#define HINIC_COPY_MBUF_SIZE     (4096)
+#define HINIC_COPY_MEMPOOL_DEPTH       128
+#define HINIC_COPY_MBUF_SIZE           4096
 
 #define SIZE_8BYTES(size)      (ALIGN((u32)(size), 8) >> 3)
 
@@ -31,6 +31,9 @@
 #define HINIC_TXD_ALIGN                 1
 #define HINIC_RXD_ALIGN                 1
 
+#define HINIC_UINT32_BIT_SIZE      (CHAR_BIT * sizeof(uint32_t))
+#define HINIC_VFTA_SIZE            (4096 / HINIC_UINT32_BIT_SIZE)
+
 enum hinic_dev_status {
        HINIC_DEV_INIT,
        HINIC_DEV_CLOSE,
@@ -54,10 +57,12 @@ struct hinic_nic_dev {
        u8 num_rss;
        u8 rx_queue_list[HINIC_MAX_RX_QUEUES];
 
+       u32 vfta[HINIC_VFTA_SIZE];      /* VLAN bitmap */
+
        /* info */
        unsigned int flags;
        struct nic_service_cap nic_cap;
-       u32 rx_mode_status;     /* promisc allmulticast */
+       u32 rx_mode_status;     /* promisc or allmulticast */
        unsigned long dev_status;
 
        /* dpdk only */