Skip to content

Commit

Permalink
net/mlx5: support adding MC address list operation
Browse files Browse the repository at this point in the history
Partial-bug: #1783471

Change-Id: Ia6ef99dcce6dd311ea312284eb28ab13f2908417
Signed-off-by: matan <matan@mellanox.com>
  • Loading branch information
Matan Azrad committed Jul 31, 2018
1 parent 03fca54 commit b8c3b05
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 19 deletions.
2 changes: 2 additions & 0 deletions drivers/net/mlx5/mlx5.c
Expand Up @@ -314,6 +314,7 @@ const struct eth_dev_ops mlx5_dev_ops = {
.mac_addr_remove = mlx5_mac_addr_remove,
.mac_addr_add = mlx5_mac_addr_add,
.mac_addr_set = mlx5_mac_addr_set,
.set_mc_addr_list = mlx5_set_mc_addr_list,
.mtu_set = mlx5_dev_set_mtu,
.vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
.vlan_offload_set = mlx5_vlan_offload_set,
Expand Down Expand Up @@ -365,6 +366,7 @@ const struct eth_dev_ops mlx5_dev_ops_isolate = {
.mac_addr_remove = mlx5_mac_addr_remove,
.mac_addr_add = mlx5_mac_addr_add,
.mac_addr_set = mlx5_mac_addr_set,
.set_mc_addr_list = mlx5_set_mc_addr_list,
.mtu_set = mlx5_dev_set_mtu,
.vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
.vlan_offload_set = mlx5_vlan_offload_set,
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/mlx5/mlx5.h
Expand Up @@ -212,6 +212,8 @@ void mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
int mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
uint32_t index, uint32_t vmdq);
void mlx5_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr);
int mlx5_set_mc_addr_list(struct rte_eth_dev *dev,
struct ether_addr *mc_addr_set, uint32_t nb_mc_addr);

/* mlx5_rss.c */

Expand Down
7 changes: 6 additions & 1 deletion drivers/net/mlx5/mlx5_defs.h
Expand Up @@ -41,8 +41,13 @@
/* Reported driver name. */
#define MLX5_DRIVER_NAME "net_mlx5"

/* Maximum number of simultaneous unicast MAC addresses. */
#define MLX5_MAX_UC_MAC_ADDRESSES 128
/* Maximum number of simultaneous Multicast MAC addresses. */
#define MLX5_MAX_MC_MAC_ADDRESSES 128
/* Maximum number of simultaneous MAC addresses. */
#define MLX5_MAX_MAC_ADDRESSES 128
#define MLX5_MAX_MAC_ADDRESSES \
(MLX5_MAX_UC_MAC_ADDRESSES + MLX5_MAX_MC_MAC_ADDRESSES)

/* Maximum number of simultaneous VLAN filters. */
#define MLX5_MAX_VLAN_IDS 128
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/mlx5/mlx5_ethdev.c
Expand Up @@ -424,7 +424,7 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
max = 65535;
info->max_rx_queues = max;
info->max_tx_queues = max;
info->max_mac_addrs = RTE_DIM(priv->mac);
info->max_mac_addrs = MLX5_MAX_UC_MAC_ADDRESSES;
info->rx_offload_capa =
(priv->hw_csum ?
(DEV_RX_OFFLOAD_IPV4_CKSUM |
Expand Down
122 changes: 105 additions & 17 deletions drivers/net/mlx5/mlx5_mac.c
Expand Up @@ -85,49 +85,49 @@ mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[ETHER_ADDR_LEN])
}

/**
* DPDK callback to remove a MAC address.
* Remove a MAC address from the internal array.
*
* @param dev
* Pointer to Ethernet device structure.
* @param index
* MAC address index.
*/
void
mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
static void
mlx5_internal_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
{
assert(index < MLX5_MAX_MAC_ADDRESSES);
if (is_zero_ether_addr(&dev->data->mac_addrs[index]))
return;
memset(&dev->data->mac_addrs[index], 0, sizeof(struct ether_addr));
if (!dev->data->promiscuous) {
int ret = mlx5_traffic_restart(dev);

if (ret)
DRV_LOG(ERR, "port %u cannot remove mac address: %s",
dev->data->port_id, strerror(rte_errno));
}
}

/**
* DPDK callback to add a MAC address.
* Adds a MAC address to the internal array.
*
* @param dev
* Pointer to Ethernet device structure.
* @param mac_addr
* MAC address to register.
* @param index
* MAC address index.
* @param vmdq
* VMDq pool index to associate address with (ignored).
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
int
mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
uint32_t index, uint32_t vmdq __rte_unused)
static int
mlx5_internal_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
uint32_t index)
{
unsigned int i;

assert(index < MLX5_MAX_MAC_ADDRESSES);
if (index >= MLX5_MAX_MAC_ADDRESSES) {
rte_errno = EINVAL;
return -rte_errno;
}
if (is_zero_ether_addr(mac)) {
rte_errno = EINVAL;
return -rte_errno;
}
/* First, make sure this address isn't already configured. */
for (i = 0; (i != MLX5_MAX_MAC_ADDRESSES); ++i) {
/* Skip this index, it's going to be reconfigured. */
Expand All @@ -140,6 +140,61 @@ mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
return -rte_errno;
}
dev->data->mac_addrs[index] = *mac;
return 0;
}

/**
* DPDK callback to remove a MAC address.
*
* @param dev
* Pointer to Ethernet device structure.
* @param index
* MAC address index.
*/
void
mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
{
int ret;

if (index >= MLX5_MAX_UC_MAC_ADDRESSES)
return;
mlx5_internal_mac_addr_remove(dev, index);
if (!dev->data->promiscuous) {
ret = mlx5_traffic_restart(dev);
if (ret)
DRV_LOG(ERR, "port %u cannot restart traffic: %s",
dev->data->port_id, strerror(rte_errno));
}
}

/**
* DPDK callback to add a MAC address.
*
* @param dev
* Pointer to Ethernet device structure.
* @param mac_addr
* MAC address to register.
* @param index
* MAC address index.
* @param vmdq
* VMDq pool index to associate address with (ignored).
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
int
mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
uint32_t index, uint32_t vmdq __rte_unused)
{
int ret;

if (index >= MLX5_MAX_UC_MAC_ADDRESSES) {
rte_errno = EINVAL;
return -rte_errno;
}
ret = mlx5_internal_mac_addr_add(dev, mac, index);
if (ret < 0)
return ret;
if (!dev->data->promiscuous)
return mlx5_traffic_restart(dev);
return 0;
Expand All @@ -166,3 +221,36 @@ mlx5_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
DRV_LOG(ERR, "port %u cannot set mac address: %s",
dev->data->port_id, strerror(rte_errno));
}

/**
* DPDK callback to set multicast addresses list.
*
* @param dev
* Pointer to Ethernet device structure.
* @param mac_addr_set
* Multicast MAC address pointer array.
* @param nb_mac_addr
* Number of entries in the array.
*
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
int
mlx5_set_mc_addr_list(struct rte_eth_dev *dev,
struct ether_addr *mc_addr_set, uint32_t nb_mc_addr)
{
uint32_t i;
int ret;

for (i = MLX5_MAX_UC_MAC_ADDRESSES; i != MLX5_MAX_MAC_ADDRESSES; ++i)
mlx5_internal_mac_addr_remove(dev, i);
i = MLX5_MAX_UC_MAC_ADDRESSES;
while (nb_mc_addr--) {
ret = mlx5_internal_mac_addr_add(dev, mc_addr_set++, i++);
if (ret)
return ret;
}
if (!dev->data->promiscuous)
return mlx5_traffic_restart(dev);
return 0;
}

0 comments on commit b8c3b05

Please sign in to comment.