Commit 508da426 authored by Bruce Allan's avatar Bruce Allan Committed by Jeff Kirsher

e1000e: re-factor ethtool get/set ring parameter

Make it more like how igb does it, with some additional error checking.
Signed-off-by: default avatarBruce Allan <bruce.w.allan@intel.com>
Tested-by: default avatarAaron Brown <aaron.f.brown@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent 55aa6985
...@@ -605,94 +605,112 @@ static void e1000_get_ringparam(struct net_device *netdev, ...@@ -605,94 +605,112 @@ static void e1000_get_ringparam(struct net_device *netdev,
struct ethtool_ringparam *ring) struct ethtool_ringparam *ring)
{ {
struct e1000_adapter *adapter = netdev_priv(netdev); struct e1000_adapter *adapter = netdev_priv(netdev);
struct e1000_ring *tx_ring = adapter->tx_ring;
struct e1000_ring *rx_ring = adapter->rx_ring;
ring->rx_max_pending = E1000_MAX_RXD; ring->rx_max_pending = E1000_MAX_RXD;
ring->tx_max_pending = E1000_MAX_TXD; ring->tx_max_pending = E1000_MAX_TXD;
ring->rx_pending = rx_ring->count; ring->rx_pending = adapter->rx_ring_count;
ring->tx_pending = tx_ring->count; ring->tx_pending = adapter->tx_ring_count;
} }
static int e1000_set_ringparam(struct net_device *netdev, static int e1000_set_ringparam(struct net_device *netdev,
struct ethtool_ringparam *ring) struct ethtool_ringparam *ring)
{ {
struct e1000_adapter *adapter = netdev_priv(netdev); struct e1000_adapter *adapter = netdev_priv(netdev);
struct e1000_ring *tx_ring, *tx_old; struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
struct e1000_ring *rx_ring, *rx_old; int err = 0, size = sizeof(struct e1000_ring);
int err; bool set_tx = false, set_rx = false;
u16 new_rx_count, new_tx_count;
if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
return -EINVAL; return -EINVAL;
while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
usleep_range(1000, 2000); E1000_MAX_RXD);
new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
if (netif_running(adapter->netdev)) new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
e1000e_down(adapter); E1000_MAX_TXD);
new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
tx_old = adapter->tx_ring; if ((new_tx_count == adapter->tx_ring_count) &&
rx_old = adapter->rx_ring; (new_rx_count == adapter->rx_ring_count))
/* nothing to do */
return 0;
err = -ENOMEM; while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL); usleep_range(1000, 2000);
if (!tx_ring)
goto err_alloc_tx;
rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL); if (!netif_running(adapter->netdev)) {
if (!rx_ring) /* Set counts now and allocate resources during open() */
goto err_alloc_rx; adapter->tx_ring->count = new_tx_count;
adapter->rx_ring->count = new_rx_count;
adapter->tx_ring_count = new_tx_count;
adapter->rx_ring_count = new_rx_count;
goto clear_reset;
}
adapter->tx_ring = tx_ring; set_tx = (new_tx_count != adapter->tx_ring_count);
adapter->rx_ring = rx_ring; set_rx = (new_rx_count != adapter->rx_ring_count);
rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD); /* Allocate temporary storage for ring updates */
rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD)); if (set_tx) {
rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE); temp_tx = vmalloc(size);
if (!temp_tx) {
err = -ENOMEM;
goto free_temp;
}
}
if (set_rx) {
temp_rx = vmalloc(size);
if (!temp_rx) {
err = -ENOMEM;
goto free_temp;
}
}
tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD); e1000e_down(adapter);
tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
if (netif_running(adapter->netdev)) { /*
/* Try to get new resources before deleting old */ * We can't just free everything and then setup again, because the
err = e1000e_setup_rx_resources(rx_ring); * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
* structs. First, attempt to allocate new resources...
*/
if (set_tx) {
memcpy(temp_tx, adapter->tx_ring, size);
temp_tx->count = new_tx_count;
err = e1000e_setup_tx_resources(temp_tx);
if (err) if (err)
goto err_setup_rx; goto err_setup;
err = e1000e_setup_tx_resources(tx_ring); }
if (set_rx) {
memcpy(temp_rx, adapter->rx_ring, size);
temp_rx->count = new_rx_count;
err = e1000e_setup_rx_resources(temp_rx);
if (err) if (err)
goto err_setup_tx; goto err_setup_rx;
}
/* /* ...then free the old resources and copy back any new ring data */
* restore the old in order to free it, if (set_tx) {
* then add in the new
*/
adapter->rx_ring = rx_old;
adapter->tx_ring = tx_old;
e1000e_free_rx_resources(adapter->rx_ring);
e1000e_free_tx_resources(adapter->tx_ring); e1000e_free_tx_resources(adapter->tx_ring);
kfree(tx_old); memcpy(adapter->tx_ring, temp_tx, size);
kfree(rx_old); adapter->tx_ring_count = new_tx_count;
adapter->rx_ring = rx_ring; }
adapter->tx_ring = tx_ring; if (set_rx) {
err = e1000e_up(adapter); e1000e_free_rx_resources(adapter->rx_ring);
if (err) memcpy(adapter->rx_ring, temp_rx, size);
goto err_setup; adapter->rx_ring_count = new_rx_count;
} }
clear_bit(__E1000_RESETTING, &adapter->state);
return 0;
err_setup_tx:
e1000e_free_rx_resources(rx_ring);
err_setup_rx: err_setup_rx:
adapter->rx_ring = rx_old; if (err && set_tx)
adapter->tx_ring = tx_old; e1000e_free_tx_resources(temp_tx);
kfree(rx_ring);
err_alloc_rx:
kfree(tx_ring);
err_alloc_tx:
e1000e_up(adapter);
err_setup: err_setup:
e1000e_up(adapter);
free_temp:
vfree(temp_tx);
vfree(temp_rx);
clear_reset:
clear_bit(__E1000_RESETTING, &adapter->state); clear_bit(__E1000_RESETTING, &adapter->state);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment