Skip to content

Commit

Permalink
ethtool: Change ethtool_op_set_flags to validate flags
Browse files Browse the repository at this point in the history
ethtool_op_set_flags() does not check for unsupported flags, and has
no way of doing so.  This means it is not suitable for use as a
default implementation of ethtool_ops::set_flags.

Add a 'supported' parameter specifying the flags that the driver and
hardware support, validate the requested flags against this, and
change all current callers to pass this parameter.

Change some other trivial implementations of ethtool_ops::set_flags to
call ethtool_op_set_flags().

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Reviewed-by: Stanislaw Gruszka <sgruszka@redhat.com>
Acked-by: Jeff Garzik <jgarzik@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ben Hutchings authored and David S. Miller committed Jun 30, 2010
1 parent b3003be commit 1437ce3
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 60 deletions.
9 changes: 1 addition & 8 deletions drivers/net/cxgb4/cxgb4_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1799,14 +1799,7 @@ static int set_tso(struct net_device *dev, u32 value)

static int set_flags(struct net_device *dev, u32 flags)
{
if (flags & ~ETH_FLAG_RXHASH)
return -EOPNOTSUPP;

if (flags & ETH_FLAG_RXHASH)
dev->features |= NETIF_F_RXHASH;
else
dev->features &= ~NETIF_F_RXHASH;
return 0;
return ethtool_op_set_flags(dev, flags, ETH_FLAG_RXHASH);
}

static struct ethtool_ops cxgb_ethtool_ops = {
Expand Down
1 change: 0 additions & 1 deletion drivers/net/enic/enic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ static const struct ethtool_ops enic_ethtool_ops = {
.get_coalesce = enic_get_coalesce,
.set_coalesce = enic_set_coalesce,
.get_flags = ethtool_op_get_flags,
.set_flags = ethtool_op_set_flags,
};

static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
Expand Down
5 changes: 4 additions & 1 deletion drivers/net/ixgbe/ixgbe_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2205,8 +2205,11 @@ static int ixgbe_set_flags(struct net_device *netdev, u32 data)
{
struct ixgbe_adapter *adapter = netdev_priv(netdev);
bool need_reset = false;
int rc;

ethtool_op_set_flags(netdev, data);
rc = ethtool_op_set_flags(netdev, data, ETH_FLAG_LRO | ETH_FLAG_NTUPLE);
if (rc)
return rc;

/* if state changes we need to update adapter->flags and reset */
if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) {
Expand Down
7 changes: 6 additions & 1 deletion drivers/net/mv643xx_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,11 @@ static void mv643xx_eth_get_ethtool_stats(struct net_device *dev,
}
}

static int mv643xx_eth_set_flags(struct net_device *dev, u32 data)
{
return ethtool_op_set_flags(dev, data, ETH_FLAG_LRO);
}

static int mv643xx_eth_get_sset_count(struct net_device *dev, int sset)
{
if (sset == ETH_SS_STATS)
Expand All @@ -1661,7 +1666,7 @@ static const struct ethtool_ops mv643xx_eth_ethtool_ops = {
.get_strings = mv643xx_eth_get_strings,
.get_ethtool_stats = mv643xx_eth_get_ethtool_stats,
.get_flags = ethtool_op_get_flags,
.set_flags = ethtool_op_set_flags,
.set_flags = mv643xx_eth_set_flags,
.get_sset_count = mv643xx_eth_get_sset_count,
};

Expand Down
10 changes: 7 additions & 3 deletions drivers/net/myri10ge/myri10ge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1730,8 +1730,7 @@ static int myri10ge_set_rx_csum(struct net_device *netdev, u32 csum_enabled)
if (csum_enabled)
mgp->csum_flag = MXGEFW_FLAGS_CKSUM;
else {
u32 flags = ethtool_op_get_flags(netdev);
err = ethtool_op_set_flags(netdev, (flags & ~ETH_FLAG_LRO));
netdev->features &= ~NETIF_F_LRO;
mgp->csum_flag = 0;

}
Expand Down Expand Up @@ -1900,6 +1899,11 @@ static u32 myri10ge_get_msglevel(struct net_device *netdev)
return mgp->msg_enable;
}

static int myri10ge_set_flags(struct net_device *netdev, u32 value)
{
return ethtool_op_set_flags(netdev, value, ETH_FLAG_LRO);
}

static const struct ethtool_ops myri10ge_ethtool_ops = {
.get_settings = myri10ge_get_settings,
.get_drvinfo = myri10ge_get_drvinfo,
Expand All @@ -1920,7 +1924,7 @@ static const struct ethtool_ops myri10ge_ethtool_ops = {
.set_msglevel = myri10ge_set_msglevel,
.get_msglevel = myri10ge_get_msglevel,
.get_flags = ethtool_op_get_flags,
.set_flags = ethtool_op_set_flags
.set_flags = myri10ge_set_flags
};

static int myri10ge_allocate_rings(struct myri10ge_slice_state *ss)
Expand Down
9 changes: 1 addition & 8 deletions drivers/net/niu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7920,14 +7920,7 @@ static int niu_phys_id(struct net_device *dev, u32 data)

static int niu_set_flags(struct net_device *dev, u32 data)
{
if (data & (ETH_FLAG_LRO | ETH_FLAG_NTUPLE))
return -EOPNOTSUPP;

if (data & ETH_FLAG_RXHASH)
dev->features |= NETIF_F_RXHASH;
else
dev->features &= ~NETIF_F_RXHASH;
return 0;
return ethtool_op_set_flags(dev, data, ETH_FLAG_RXHASH);
}

static const struct ethtool_ops niu_ethtool_ops = {
Expand Down
5 changes: 1 addition & 4 deletions drivers/net/sfc/ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,7 @@ static int efx_ethtool_set_flags(struct net_device *net_dev, u32 data)
struct efx_nic *efx = netdev_priv(net_dev);
u32 supported = efx->type->offload_features & ETH_FLAG_RXHASH;

if (data & ~supported)
return -EOPNOTSUPP;

return ethtool_op_set_flags(net_dev, data);
return ethtool_op_set_flags(net_dev, data, supported);
}

static void efx_ethtool_self_test(struct net_device *net_dev,
Expand Down
16 changes: 6 additions & 10 deletions drivers/net/sky2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4188,17 +4188,13 @@ static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom
static int sky2_set_flags(struct net_device *dev, u32 data)
{
struct sky2_port *sky2 = netdev_priv(dev);
u32 supported =
(sky2->hw->flags & SKY2_HW_RSS_BROKEN) ? 0 : ETH_FLAG_RXHASH;
int rc;

if (data & ~ETH_FLAG_RXHASH)
return -EOPNOTSUPP;

if (data & ETH_FLAG_RXHASH) {
if (sky2->hw->flags & SKY2_HW_RSS_BROKEN)
return -EINVAL;

dev->features |= NETIF_F_RXHASH;
} else
dev->features &= ~NETIF_F_RXHASH;
rc = ethtool_op_set_flags(dev, data, supported);
if (rc)
return rc;

rx_set_rss(dev);

Expand Down
2 changes: 1 addition & 1 deletion include/linux/ethtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ int ethtool_op_set_tso(struct net_device *dev, u32 data);
u32 ethtool_op_get_ufo(struct net_device *dev);
int ethtool_op_set_ufo(struct net_device *dev, u32 data);
u32 ethtool_op_get_flags(struct net_device *dev);
int ethtool_op_set_flags(struct net_device *dev, u32 data);
int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported);
void ethtool_ntuple_flush(struct net_device *dev);

/**
Expand Down
28 changes: 5 additions & 23 deletions net/core/ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,31 +144,13 @@ u32 ethtool_op_get_flags(struct net_device *dev)
}
EXPORT_SYMBOL(ethtool_op_get_flags);

int ethtool_op_set_flags(struct net_device *dev, u32 data)
int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported)
{
const struct ethtool_ops *ops = dev->ethtool_ops;
unsigned long features = dev->features;

if (data & ETH_FLAG_LRO)
features |= NETIF_F_LRO;
else
features &= ~NETIF_F_LRO;

if (data & ETH_FLAG_NTUPLE) {
if (!ops->set_rx_ntuple)
return -EOPNOTSUPP;
features |= NETIF_F_NTUPLE;
} else {
/* safe to clear regardless */
features &= ~NETIF_F_NTUPLE;
}

if (data & ETH_FLAG_RXHASH)
features |= NETIF_F_RXHASH;
else
features &= ~NETIF_F_RXHASH;
if (data & ~supported)
return -EINVAL;

dev->features = features;
dev->features = ((dev->features & ~flags_dup_features) |
(data & flags_dup_features));
return 0;
}
EXPORT_SYMBOL(ethtool_op_set_flags);
Expand Down

0 comments on commit 1437ce3

Please sign in to comment.