From: Shaopeng He Date: Thu, 18 Jun 2015 07:21:19 +0000 (+0800) Subject: fm10k: update mac table with vlan filtering X-Git-Tag: spdx-start~9019 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=2e58464ca9be0b56e81a3f5b4155e691e9634c39;p=dpdk.git fm10k: update mac table with vlan filtering VLAN filter was updated to add/delete one static entry in MAC table for each combination of VLAN and MAC address. More sanity checks were added. Signed-off-by: Shaopeng He Acked-by: Jing Chen --- diff --git a/drivers/net/fm10k/fm10k.h b/drivers/net/fm10k/fm10k.h index ad7a7d13f5..876aa81214 100644 --- a/drivers/net/fm10k/fm10k.h +++ b/drivers/net/fm10k/fm10k.h @@ -109,11 +109,31 @@ #define FM10K_VLAN_TAG_SIZE 4 +/* Maximum number of MAC addresses per PF/VF */ +#define FM10K_MAX_MACADDR_NUM 1 + +#define FM10K_UINT32_BIT_SIZE (CHAR_BIT * sizeof(uint32_t)) +#define FM10K_VFTA_SIZE (4096 / FM10K_UINT32_BIT_SIZE) + +/* 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 FM10K_VFTA_BIT(vlan_id) (1 << ((vlan_id) & 0x1F)) +#define FM10K_VFTA_IDX(vlan_id) ((vlan_id) >> 5) + +struct fm10k_macvlan_filter_info { + uint16_t vlan_num; /* Total VLAN number */ + uint32_t vfta[FM10K_VFTA_SIZE]; /* VLAN bitmap */ +}; + struct fm10k_dev_info { volatile uint32_t enable; volatile uint32_t glort; /* Protect the mailbox to avoid race condition */ rte_spinlock_t mbx_lock; + struct fm10k_macvlan_filter_info macvlan; }; /* @@ -137,6 +157,9 @@ struct fm10k_adapter { #define FM10K_DEV_PRIVATE_TO_MBXLOCK(adapter) \ (&(((struct fm10k_adapter *)adapter)->info.mbx_lock)) +#define FM10K_DEV_PRIVATE_TO_MACVLAN(adapter) \ + (&(((struct fm10k_adapter *)adapter)->info.macvlan)) + struct fm10k_rx_queue { struct rte_mempool *mp; struct rte_mbuf **sw_ring; diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c index 19d821e94a..61401769ee 100644 --- a/drivers/net/fm10k/fm10k_ethdev.c +++ b/drivers/net/fm10k/fm10k_ethdev.c @@ -937,15 +937,69 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev, static int fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on) { - struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private); + s32 result; + uint32_t vid_idx, vid_bit, mac_index; + struct fm10k_hw *hw; + struct fm10k_macvlan_filter_info *macvlan; + struct rte_eth_dev_data *data = dev->data; - PMD_INIT_FUNC_TRACE(); + hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private); + macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private); /* @todo - add support for the VF */ - if (hw->mac.type != fm10k_mac_pf) + if (hw->mac.type != fm10k_mac_pf) { + PMD_INIT_LOG(ERR, "VLAN filter not available on VF"); return -ENOTSUP; + } + + if (vlan_id > ETH_VLAN_ID_MAX) { + PMD_INIT_LOG(ERR, "Invalid vlan_id: must be < 4096"); + return (-EINVAL); + } + + vid_idx = FM10K_VFTA_IDX(vlan_id); + vid_bit = FM10K_VFTA_BIT(vlan_id); + /* this VLAN ID is already in the VLAN filter table, return SUCCESS */ + if (on && (macvlan->vfta[vid_idx] & vid_bit)) + return 0; + /* this VLAN ID is NOT in the VLAN filter table, cannot remove */ + if (!on && !(macvlan->vfta[vid_idx] & vid_bit)) { + PMD_INIT_LOG(ERR, "Invalid vlan_id: not existing " + "in the VLAN filter table"); + return (-EINVAL); + } - return fm10k_update_vlan(hw, vlan_id, 0, on); + fm10k_mbx_lock(hw); + result = fm10k_update_vlan(hw, vlan_id, 0, on); + fm10k_mbx_unlock(hw); + if (result != FM10K_SUCCESS) { + PMD_INIT_LOG(ERR, "VLAN update failed: %d", result); + return (-EIO); + } + + for (mac_index = 0; (mac_index < FM10K_MAX_MACADDR_NUM) && + (result == FM10K_SUCCESS); mac_index++) { + if (is_zero_ether_addr(&data->mac_addrs[mac_index])) + continue; + fm10k_mbx_lock(hw); + result = fm10k_update_uc_addr(hw, hw->mac.dglort_map, + data->mac_addrs[mac_index].addr_bytes, + vlan_id, on, 0); + fm10k_mbx_unlock(hw); + } + if (result != FM10K_SUCCESS) { + PMD_INIT_LOG(ERR, "MAC address update failed: %d", result); + return (-EIO); + } + + if (on) { + macvlan->vlan_num++; + macvlan->vfta[vid_idx] |= vid_bit; + } else { + macvlan->vlan_num--; + macvlan->vfta[vid_idx] &= ~vid_bit; + } + return 0; } static inline int @@ -1818,6 +1872,7 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev) { struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private); int diag; + struct fm10k_macvlan_filter_info *macvlan; PMD_INIT_FUNC_TRACE(); @@ -1832,6 +1887,8 @@ eth_fm10k_dev_init(struct rte_eth_dev *dev) if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; + macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private); + memset(macvlan, 0, sizeof(*macvlan)); /* Vendor and Device ID need to be set before init of shared code */ memset(hw, 0, sizeof(*hw)); hw->device_id = dev->pci_dev->id.device_id;