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.
*
#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;
.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
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;
}
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 |
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.
*
/* deinit mac vlan tbl */
hinic_deinit_mac_addr(dev);
+ hinic_remove_all_vlanid(dev);
/* disable hardware and uio interrupt */
hinic_disable_interrupt(dev);
.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,
.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,