Skip to content

Commit

Permalink
ethdev: change promiscuous callbacks to return status
Browse files Browse the repository at this point in the history
Enabling/disabling of promiscuous mode is not always successful and
it should be taken into account to be able to handle it properly.

When correct return status is unclear from driver code, -EAGAIN is used.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Acked-by: Matan Azrad <matan@mellanox.com>
Acked-by: Hyong Youb Kim <hyonkim@cisco.com>
  • Loading branch information
arybchenko authored and Ferruh Yigit committed Oct 7, 2019
1 parent ae9f487 commit 9039c81
Show file tree
Hide file tree
Showing 55 changed files with 692 additions and 265 deletions.
12 changes: 8 additions & 4 deletions app/test/virtual_pmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,17 @@ virtual_ethdev_stats_reset(struct rte_eth_dev *dev)
memset(&dev_private->eth_stats, 0, sizeof(dev_private->eth_stats));
}

static void
static int
virtual_ethdev_promiscuous_mode_enable(struct rte_eth_dev *dev __rte_unused)
{}
{
return 0;
}

static void
static int
virtual_ethdev_promiscuous_mode_disable(struct rte_eth_dev *dev __rte_unused)
{}
{
return 0;
}

static int
virtual_ethdev_mac_address_set(__rte_unused struct rte_eth_dev *dev,
Expand Down
22 changes: 14 additions & 8 deletions drivers/net/af_packet/rte_eth_af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,41 +458,47 @@ eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
return 0;
}

static void
static int
eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask)
{
struct ifreq ifr;
int ret = 0;
int s;

s = socket(PF_INET, SOCK_DGRAM, 0);
if (s < 0)
return;
return -errno;

strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) {
ret = -errno;
goto out;
}
ifr.ifr_flags &= mask;
ifr.ifr_flags |= flags;
if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0)
if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0) {
ret = -errno;
goto out;
}
out:
close(s);
return ret;
}

static void
static int
eth_dev_promiscuous_enable(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = dev->data->dev_private;

eth_dev_change_flags(internals->if_name, IFF_PROMISC, ~0);
return eth_dev_change_flags(internals->if_name, IFF_PROMISC, ~0);
}

static void
static int
eth_dev_promiscuous_disable(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = dev->data->dev_private;

eth_dev_change_flags(internals->if_name, 0, ~IFF_PROMISC);
return eth_dev_change_flags(internals->if_name, 0, ~IFF_PROMISC);
}

static const struct eth_dev_ops ops = {
Expand Down
22 changes: 14 additions & 8 deletions drivers/net/af_xdp/rte_eth_af_xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,41 +746,47 @@ eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
return (ret < 0) ? -errno : 0;
}

static void
static int
eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask)
{
struct ifreq ifr;
int ret = 0;
int s;

s = socket(PF_INET, SOCK_DGRAM, 0);
if (s < 0)
return;
return -errno;

strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) {
ret = -errno;
goto out;
}
ifr.ifr_flags &= mask;
ifr.ifr_flags |= flags;
if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0)
if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0) {
ret = -errno;
goto out;
}
out:
close(s);
return ret;
}

static void
static int
eth_dev_promiscuous_enable(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = dev->data->dev_private;

eth_dev_change_flags(internals->if_name, IFF_PROMISC, ~0);
return eth_dev_change_flags(internals->if_name, IFF_PROMISC, ~0);
}

static void
static int
eth_dev_promiscuous_disable(struct rte_eth_dev *dev)
{
struct pmd_internals *internals = dev->data->dev_private;

eth_dev_change_flags(internals->if_name, 0, ~IFF_PROMISC);
return eth_dev_change_flags(internals->if_name, 0, ~IFF_PROMISC);
}

static const struct eth_dev_ops ops = {
Expand Down
12 changes: 8 additions & 4 deletions drivers/net/atlantic/atl_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ static int atl_dev_set_link_up(struct rte_eth_dev *dev);
static int atl_dev_set_link_down(struct rte_eth_dev *dev);
static void atl_dev_close(struct rte_eth_dev *dev);
static int atl_dev_reset(struct rte_eth_dev *dev);
static void atl_dev_promiscuous_enable(struct rte_eth_dev *dev);
static void atl_dev_promiscuous_disable(struct rte_eth_dev *dev);
static int atl_dev_promiscuous_enable(struct rte_eth_dev *dev);
static int atl_dev_promiscuous_disable(struct rte_eth_dev *dev);
static void atl_dev_allmulticast_enable(struct rte_eth_dev *dev);
static void atl_dev_allmulticast_disable(struct rte_eth_dev *dev);
static int atl_dev_link_update(struct rte_eth_dev *dev, int wait);
Expand Down Expand Up @@ -1207,20 +1207,24 @@ atl_dev_link_update(struct rte_eth_dev *dev, int wait __rte_unused)
return 0;
}

static void
static int
atl_dev_promiscuous_enable(struct rte_eth_dev *dev)
{
struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);

hw_atl_rpfl2promiscuous_mode_en_set(hw, true);

return 0;
}

static void
static int
atl_dev_promiscuous_disable(struct rte_eth_dev *dev)
{
struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);

hw_atl_rpfl2promiscuous_mode_en_set(hw, false);

return 0;
}

static void
Expand Down
12 changes: 8 additions & 4 deletions drivers/net/avp/avp_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ static int avp_dev_info_get(struct rte_eth_dev *dev,
struct rte_eth_dev_info *dev_info);
static int avp_vlan_offload_set(struct rte_eth_dev *dev, int mask);
static int avp_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete);
static void avp_dev_promiscuous_enable(struct rte_eth_dev *dev);
static void avp_dev_promiscuous_disable(struct rte_eth_dev *dev);
static int avp_dev_promiscuous_enable(struct rte_eth_dev *dev);
static int avp_dev_promiscuous_disable(struct rte_eth_dev *dev);

static int avp_dev_rx_queue_setup(struct rte_eth_dev *dev,
uint16_t rx_queue_id,
Expand Down Expand Up @@ -2157,7 +2157,7 @@ avp_dev_link_update(struct rte_eth_dev *eth_dev,
return -1;
}

static void
static int
avp_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
{
struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
Expand All @@ -2169,9 +2169,11 @@ avp_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
eth_dev->data->port_id);
}
rte_spinlock_unlock(&avp->lock);

return 0;
}

static void
static int
avp_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
{
struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
Expand All @@ -2183,6 +2185,8 @@ avp_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
eth_dev->data->port_id);
}
rte_spinlock_unlock(&avp->lock);

return 0;
}

static int
Expand Down
12 changes: 8 additions & 4 deletions drivers/net/axgbe/axgbe_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ static int axgbe_dev_start(struct rte_eth_dev *dev);
static void axgbe_dev_stop(struct rte_eth_dev *dev);
static void axgbe_dev_interrupt_handler(void *param);
static void axgbe_dev_close(struct rte_eth_dev *dev);
static void axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
static void axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
static int axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
static int axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
static void axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
static void axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev);
static int axgbe_dev_link_update(struct rte_eth_dev *dev,
Expand Down Expand Up @@ -236,24 +236,28 @@ axgbe_dev_close(struct rte_eth_dev *dev)
axgbe_dev_clear_queues(dev);
}

static void
static int
axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
{
struct axgbe_port *pdata = dev->data->dev_private;

PMD_INIT_FUNC_TRACE();

AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 1);

return 0;
}

static void
static int
axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
{
struct axgbe_port *pdata = dev->data->dev_private;

PMD_INIT_FUNC_TRACE();

AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 0);

return 0;
}

static void
Expand Down
8 changes: 6 additions & 2 deletions drivers/net/bnx2x/bnx2x_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ bnx2x_dev_close(struct rte_eth_dev *dev)
bnx2x_free_ilt_mem(sc);
}

static void
static int
bnx2x_promisc_enable(struct rte_eth_dev *dev)
{
struct bnx2x_softc *sc = dev->data->dev_private;
Expand All @@ -302,9 +302,11 @@ bnx2x_promisc_enable(struct rte_eth_dev *dev)
if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
bnx2x_set_rx_mode(sc);

return 0;
}

static void
static int
bnx2x_promisc_disable(struct rte_eth_dev *dev)
{
struct bnx2x_softc *sc = dev->data->dev_private;
Expand All @@ -314,6 +316,8 @@ bnx2x_promisc_disable(struct rte_eth_dev *dev)
if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
bnx2x_set_rx_mode(sc);

return 0;
}

static void
Expand Down
26 changes: 20 additions & 6 deletions drivers/net/bnxt/bnxt_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,32 +1006,46 @@ int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete)
return rc;
}

static void bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
static int bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
{
struct bnxt *bp = eth_dev->data->dev_private;
struct bnxt_vnic_info *vnic;
uint32_t old_flags;
int rc;

if (bp->vnic_info == NULL)
return;
return 0;

vnic = &bp->vnic_info[0];

old_flags = vnic->flags;
vnic->flags |= BNXT_VNIC_INFO_PROMISC;
bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
if (rc != 0)
vnic->flags = old_flags;

return rc;
}

static void bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
static int bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
{
struct bnxt *bp = eth_dev->data->dev_private;
struct bnxt_vnic_info *vnic;
uint32_t old_flags;
int rc;

if (bp->vnic_info == NULL)
return;
return 0;

vnic = &bp->vnic_info[0];

old_flags = vnic->flags;
vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
if (rc != 0)
vnic->flags = old_flags;

return rc;
}

static void bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
Expand Down
Loading

0 comments on commit 9039c81

Please sign in to comment.