mirror of https://gitee.com/openkylin/linux.git
e1000e: re-factor ethtool get/set ring parameter
Make it more like how igb does it, with some additional error checking. Signed-off-by: Bruce Allan <bruce.w.allan@intel.com> Tested-by: Aaron Brown <aaron.f.brown@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
This commit is contained in:
parent
55aa69854a
commit
508da4264a
|
@ -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;
|
||||||
|
|
||||||
|
new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
|
||||||
|
E1000_MAX_RXD);
|
||||||
|
new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
|
||||||
|
|
||||||
|
new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
|
||||||
|
E1000_MAX_TXD);
|
||||||
|
new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
|
||||||
|
|
||||||
|
if ((new_tx_count == adapter->tx_ring_count) &&
|
||||||
|
(new_rx_count == adapter->rx_ring_count))
|
||||||
|
/* nothing to do */
|
||||||
|
return 0;
|
||||||
|
|
||||||
while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
|
while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
|
||||||
usleep_range(1000, 2000);
|
usleep_range(1000, 2000);
|
||||||
|
|
||||||
if (netif_running(adapter->netdev))
|
if (!netif_running(adapter->netdev)) {
|
||||||
e1000e_down(adapter);
|
/* Set counts now and allocate resources during open() */
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
tx_old = adapter->tx_ring;
|
set_tx = (new_tx_count != adapter->tx_ring_count);
|
||||||
rx_old = adapter->rx_ring;
|
set_rx = (new_rx_count != adapter->rx_ring_count);
|
||||||
|
|
||||||
err = -ENOMEM;
|
/* Allocate temporary storage for ring updates */
|
||||||
tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL);
|
if (set_tx) {
|
||||||
if (!tx_ring)
|
temp_tx = vmalloc(size);
|
||||||
goto err_alloc_tx;
|
if (!temp_tx) {
|
||||||
|
err = -ENOMEM;
|
||||||
|
goto free_temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (set_rx) {
|
||||||
|
temp_rx = vmalloc(size);
|
||||||
|
if (!temp_rx) {
|
||||||
|
err = -ENOMEM;
|
||||||
|
goto free_temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL);
|
e1000e_down(adapter);
|
||||||
if (!rx_ring)
|
|
||||||
goto err_alloc_rx;
|
|
||||||
|
|
||||||
adapter->tx_ring = tx_ring;
|
/*
|
||||||
adapter->rx_ring = rx_ring;
|
* We can't just free everything and then setup again, because the
|
||||||
|
* ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
|
||||||
rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
|
* structs. First, attempt to allocate new resources...
|
||||||
rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
|
*/
|
||||||
rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
|
if (set_tx) {
|
||||||
|
memcpy(temp_tx, adapter->tx_ring, size);
|
||||||
tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
|
temp_tx->count = new_tx_count;
|
||||||
tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
|
err = e1000e_setup_tx_resources(temp_tx);
|
||||||
tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
|
|
||||||
|
|
||||||
if (netif_running(adapter->netdev)) {
|
|
||||||
/* Try to get new resources before deleting old */
|
|
||||||
err = e1000e_setup_rx_resources(rx_ring);
|
|
||||||
if (err)
|
|
||||||
goto err_setup_rx;
|
|
||||||
err = e1000e_setup_tx_resources(tx_ring);
|
|
||||||
if (err)
|
|
||||||
goto err_setup_tx;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* restore the old in order to free it,
|
|
||||||
* 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);
|
|
||||||
kfree(tx_old);
|
|
||||||
kfree(rx_old);
|
|
||||||
adapter->rx_ring = rx_ring;
|
|
||||||
adapter->tx_ring = tx_ring;
|
|
||||||
err = e1000e_up(adapter);
|
|
||||||
if (err)
|
if (err)
|
||||||
goto err_setup;
|
goto err_setup;
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
|
goto err_setup_rx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ...then free the old resources and copy back any new ring data */
|
||||||
|
if (set_tx) {
|
||||||
|
e1000e_free_tx_resources(adapter->tx_ring);
|
||||||
|
memcpy(adapter->tx_ring, temp_tx, size);
|
||||||
|
adapter->tx_ring_count = new_tx_count;
|
||||||
|
}
|
||||||
|
if (set_rx) {
|
||||||
|
e1000e_free_rx_resources(adapter->rx_ring);
|
||||||
|
memcpy(adapter->rx_ring, temp_rx, size);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue