From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 90C1BA0613 for ; Wed, 25 Sep 2019 16:16:15 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 492C01BEAA; Wed, 25 Sep 2019 16:16:06 +0200 (CEST) Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by dpdk.org (Postfix) with ESMTP id 6390E1BEA1 for ; Wed, 25 Sep 2019 16:16:02 +0200 (CEST) Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 5B8FBF06273D53240CC1 for ; Wed, 25 Sep 2019 22:16:01 +0800 (CST) Received: from tester.localdomain (10.175.119.39) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Wed, 25 Sep 2019 22:15:53 +0800 From: Xiaoyun wang To: CC: , , , , , , , Xiaoyun wang Date: Wed, 25 Sep 2019 22:30:32 +0800 Message-ID: <894361a753893a1710755cbe2072fcf3cfbec725.1569421287.git.cloud.wangxiaoyun@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.119.39] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v2 04/17] net/hinic: add VLAN filter and offload X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds support for VLAN filter and VLAN offload. Signed-off-by: Xiaoyun wang --- drivers/net/hinic/base/hinic_pmd_cmd.h | 1 + drivers/net/hinic/base/hinic_pmd_niccfg.c | 136 +++++++++++++++++++++ drivers/net/hinic/base/hinic_pmd_niccfg.h | 29 +++++ drivers/net/hinic/hinic_pmd_ethdev.c | 194 +++++++++++++++++++++++++++++- drivers/net/hinic/hinic_pmd_ethdev.h | 15 ++- 5 files changed, 369 insertions(+), 6 deletions(-) diff --git a/drivers/net/hinic/base/hinic_pmd_cmd.h b/drivers/net/hinic/base/hinic_pmd_cmd.h index c8750b8..5c38b5f 100644 --- a/drivers/net/hinic/base/hinic_pmd_cmd.h +++ b/drivers/net/hinic/base/hinic_pmd_cmd.h @@ -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 */ diff --git a/drivers/net/hinic/base/hinic_pmd_niccfg.c b/drivers/net/hinic/base/hinic_pmd_niccfg.c index 0a20ade..8bd7ed6 100644 --- a/drivers/net/hinic/base/hinic_pmd_niccfg.c +++ b/drivers/net/hinic/base/hinic_pmd_niccfg.c @@ -290,6 +290,142 @@ int hinic_set_port_mtu(void *hwdev, u32 new_mtu) } /** + * 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. * * @param hwdev diff --git a/drivers/net/hinic/base/hinic_pmd_niccfg.h b/drivers/net/hinic/base/hinic_pmd_niccfg.h index 94371bb..d19a834 100644 --- a/drivers/net/hinic/base/hinic_pmd_niccfg.h +++ b/drivers/net/hinic/base/hinic_pmd_niccfg.h @@ -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_update_mac(void *hwdev, u8 *old_mac, u8 *new_mac, u16 vlan_id, 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); diff --git a/drivers/net/hinic/hinic_pmd_ethdev.c b/drivers/net/hinic/hinic_pmd_ethdev.c index 2f413e3..4e2a69c 100644 --- a/drivers/net/hinic/hinic_pmd_ethdev.c +++ b/drivers/net/hinic/hinic_pmd_ethdev.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "base/hinic_compat.h" #include "base/hinic_pmd_hwdev.h" @@ -52,6 +53,17 @@ #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 int hinic_xstats_calc_num(struct hinic_nic_dev *nic_dev) .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 @@ static void hinic_get_speed_capa(struct rte_eth_dev *dev, uint32_t *speed_capa) 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 void hinic_dev_close(struct rte_eth_dev *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, @@ -2257,6 +2447,8 @@ static void hinic_dev_close(struct rte_eth_dev *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, .rss_hash_update = hinic_rss_hash_update, .rss_hash_conf_get = hinic_rss_conf_get, .reta_update = hinic_rss_indirtbl_update, diff --git a/drivers/net/hinic/hinic_pmd_ethdev.h b/drivers/net/hinic/hinic_pmd_ethdev.h index 4aeddc2..66eaf20 100644 --- a/drivers/net/hinic/hinic_pmd_ethdev.h +++ b/drivers/net/hinic/hinic_pmd_ethdev.h @@ -11,12 +11,12 @@ #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 */ -- 1.8.3.1