aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/sfc/efx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/sfc/efx.c')
-rw-r--r--drivers/net/sfc/efx.c142
1 files changed, 76 insertions, 66 deletions
diff --git a/drivers/net/sfc/efx.c b/drivers/net/sfc/efx.c
index 88f2fb193abe..156460527231 100644
--- a/drivers/net/sfc/efx.c
+++ b/drivers/net/sfc/efx.c
@@ -20,6 +20,7 @@
20#include <linux/crc32.h> 20#include <linux/crc32.h>
21#include <linux/ethtool.h> 21#include <linux/ethtool.h>
22#include <linux/topology.h> 22#include <linux/topology.h>
23#include <linux/gfp.h>
23#include "net_driver.h" 24#include "net_driver.h"
24#include "efx.h" 25#include "efx.h"
25#include "mdio_10g.h" 26#include "mdio_10g.h"
@@ -224,17 +225,17 @@ static void efx_fini_channels(struct efx_nic *efx);
224 * never be concurrently called more than once on the same channel, 225 * never be concurrently called more than once on the same channel,
225 * though different channels may be being processed concurrently. 226 * though different channels may be being processed concurrently.
226 */ 227 */
227static int efx_process_channel(struct efx_channel *channel, int rx_quota) 228static int efx_process_channel(struct efx_channel *channel, int budget)
228{ 229{
229 struct efx_nic *efx = channel->efx; 230 struct efx_nic *efx = channel->efx;
230 int rx_packets; 231 int spent;
231 232
232 if (unlikely(efx->reset_pending != RESET_TYPE_NONE || 233 if (unlikely(efx->reset_pending != RESET_TYPE_NONE ||
233 !channel->enabled)) 234 !channel->enabled))
234 return 0; 235 return 0;
235 236
236 rx_packets = efx_nic_process_eventq(channel, rx_quota); 237 spent = efx_nic_process_eventq(channel, budget);
237 if (rx_packets == 0) 238 if (spent == 0)
238 return 0; 239 return 0;
239 240
240 /* Deliver last RX packet. */ 241 /* Deliver last RX packet. */
@@ -248,7 +249,7 @@ static int efx_process_channel(struct efx_channel *channel, int rx_quota)
248 249
249 efx_fast_push_rx_descriptors(&efx->rx_queue[channel->channel]); 250 efx_fast_push_rx_descriptors(&efx->rx_queue[channel->channel]);
250 251
251 return rx_packets; 252 return spent;
252} 253}
253 254
254/* Mark channel as finished processing 255/* Mark channel as finished processing
@@ -277,17 +278,17 @@ static int efx_poll(struct napi_struct *napi, int budget)
277{ 278{
278 struct efx_channel *channel = 279 struct efx_channel *channel =
279 container_of(napi, struct efx_channel, napi_str); 280 container_of(napi, struct efx_channel, napi_str);
280 int rx_packets; 281 int spent;
281 282
282 EFX_TRACE(channel->efx, "channel %d NAPI poll executing on CPU %d\n", 283 EFX_TRACE(channel->efx, "channel %d NAPI poll executing on CPU %d\n",
283 channel->channel, raw_smp_processor_id()); 284 channel->channel, raw_smp_processor_id());
284 285
285 rx_packets = efx_process_channel(channel, budget); 286 spent = efx_process_channel(channel, budget);
286 287
287 if (rx_packets < budget) { 288 if (spent < budget) {
288 struct efx_nic *efx = channel->efx; 289 struct efx_nic *efx = channel->efx;
289 290
290 if (channel->used_flags & EFX_USED_BY_RX && 291 if (channel->channel < efx->n_rx_channels &&
291 efx->irq_rx_adaptive && 292 efx->irq_rx_adaptive &&
292 unlikely(++channel->irq_count == 1000)) { 293 unlikely(++channel->irq_count == 1000)) {
293 if (unlikely(channel->irq_mod_score < 294 if (unlikely(channel->irq_mod_score <
@@ -317,7 +318,7 @@ static int efx_poll(struct napi_struct *napi, int budget)
317 efx_channel_processed(channel); 318 efx_channel_processed(channel);
318 } 319 }
319 320
320 return rx_packets; 321 return spent;
321} 322}
322 323
323/* Process the eventq of the specified channel immediately on this CPU 324/* Process the eventq of the specified channel immediately on this CPU
@@ -332,7 +333,6 @@ void efx_process_channel_now(struct efx_channel *channel)
332{ 333{
333 struct efx_nic *efx = channel->efx; 334 struct efx_nic *efx = channel->efx;
334 335
335 BUG_ON(!channel->used_flags);
336 BUG_ON(!channel->enabled); 336 BUG_ON(!channel->enabled);
337 337
338 /* Disable interrupts and wait for ISRs to complete */ 338 /* Disable interrupts and wait for ISRs to complete */
@@ -445,12 +445,12 @@ static void efx_set_channel_names(struct efx_nic *efx)
445 445
446 efx_for_each_channel(channel, efx) { 446 efx_for_each_channel(channel, efx) {
447 number = channel->channel; 447 number = channel->channel;
448 if (efx->n_channels > efx->n_rx_queues) { 448 if (efx->n_channels > efx->n_rx_channels) {
449 if (channel->channel < efx->n_rx_queues) { 449 if (channel->channel < efx->n_rx_channels) {
450 type = "-rx"; 450 type = "-rx";
451 } else { 451 } else {
452 type = "-tx"; 452 type = "-tx";
453 number -= efx->n_rx_queues; 453 number -= efx->n_rx_channels;
454 } 454 }
455 } 455 }
456 snprintf(channel->name, sizeof(channel->name), 456 snprintf(channel->name, sizeof(channel->name),
@@ -584,8 +584,6 @@ static void efx_remove_channel(struct efx_channel *channel)
584 efx_for_each_channel_tx_queue(tx_queue, channel) 584 efx_for_each_channel_tx_queue(tx_queue, channel)
585 efx_remove_tx_queue(tx_queue); 585 efx_remove_tx_queue(tx_queue);
586 efx_remove_eventq(channel); 586 efx_remove_eventq(channel);
587
588 channel->used_flags = 0;
589} 587}
590 588
591void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue, int delay) 589void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue, int delay)
@@ -955,10 +953,9 @@ static void efx_fini_io(struct efx_nic *efx)
955 pci_disable_device(efx->pci_dev); 953 pci_disable_device(efx->pci_dev);
956} 954}
957 955
958/* Get number of RX queues wanted. Return number of online CPU 956/* Get number of channels wanted. Each channel will have its own IRQ,
959 * packages in the expectation that an IRQ balancer will spread 957 * 1 RX queue and/or 2 TX queues. */
960 * interrupts across them. */ 958static int efx_wanted_channels(void)
961static int efx_wanted_rx_queues(void)
962{ 959{
963 cpumask_var_t core_mask; 960 cpumask_var_t core_mask;
964 int count; 961 int count;
@@ -994,34 +991,39 @@ static void efx_probe_interrupts(struct efx_nic *efx)
994 991
995 if (efx->interrupt_mode == EFX_INT_MODE_MSIX) { 992 if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
996 struct msix_entry xentries[EFX_MAX_CHANNELS]; 993 struct msix_entry xentries[EFX_MAX_CHANNELS];
997 int wanted_ints; 994 int n_channels;
998 int rx_queues;
999 995
1000 /* We want one RX queue and interrupt per CPU package 996 n_channels = efx_wanted_channels();
1001 * (or as specified by the rss_cpus module parameter). 997 if (separate_tx_channels)
1002 * We will need one channel per interrupt. 998 n_channels *= 2;
1003 */ 999 n_channels = min(n_channels, max_channels);
1004 rx_queues = rss_cpus ? rss_cpus : efx_wanted_rx_queues();
1005 wanted_ints = rx_queues + (separate_tx_channels ? 1 : 0);
1006 wanted_ints = min(wanted_ints, max_channels);
1007 1000
1008 for (i = 0; i < wanted_ints; i++) 1001 for (i = 0; i < n_channels; i++)
1009 xentries[i].entry = i; 1002 xentries[i].entry = i;
1010 rc = pci_enable_msix(efx->pci_dev, xentries, wanted_ints); 1003 rc = pci_enable_msix(efx->pci_dev, xentries, n_channels);
1011 if (rc > 0) { 1004 if (rc > 0) {
1012 EFX_ERR(efx, "WARNING: Insufficient MSI-X vectors" 1005 EFX_ERR(efx, "WARNING: Insufficient MSI-X vectors"
1013 " available (%d < %d).\n", rc, wanted_ints); 1006 " available (%d < %d).\n", rc, n_channels);
1014 EFX_ERR(efx, "WARNING: Performance may be reduced.\n"); 1007 EFX_ERR(efx, "WARNING: Performance may be reduced.\n");
1015 EFX_BUG_ON_PARANOID(rc >= wanted_ints); 1008 EFX_BUG_ON_PARANOID(rc >= n_channels);
1016 wanted_ints = rc; 1009 n_channels = rc;
1017 rc = pci_enable_msix(efx->pci_dev, xentries, 1010 rc = pci_enable_msix(efx->pci_dev, xentries,
1018 wanted_ints); 1011 n_channels);
1019 } 1012 }
1020 1013
1021 if (rc == 0) { 1014 if (rc == 0) {
1022 efx->n_rx_queues = min(rx_queues, wanted_ints); 1015 efx->n_channels = n_channels;
1023 efx->n_channels = wanted_ints; 1016 if (separate_tx_channels) {
1024 for (i = 0; i < wanted_ints; i++) 1017 efx->n_tx_channels =
1018 max(efx->n_channels / 2, 1U);
1019 efx->n_rx_channels =
1020 max(efx->n_channels -
1021 efx->n_tx_channels, 1U);
1022 } else {
1023 efx->n_tx_channels = efx->n_channels;
1024 efx->n_rx_channels = efx->n_channels;
1025 }
1026 for (i = 0; i < n_channels; i++)
1025 efx->channel[i].irq = xentries[i].vector; 1027 efx->channel[i].irq = xentries[i].vector;
1026 } else { 1028 } else {
1027 /* Fall back to single channel MSI */ 1029 /* Fall back to single channel MSI */
@@ -1032,8 +1034,9 @@ static void efx_probe_interrupts(struct efx_nic *efx)
1032 1034
1033 /* Try single interrupt MSI */ 1035 /* Try single interrupt MSI */
1034 if (efx->interrupt_mode == EFX_INT_MODE_MSI) { 1036 if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
1035 efx->n_rx_queues = 1;
1036 efx->n_channels = 1; 1037 efx->n_channels = 1;
1038 efx->n_rx_channels = 1;
1039 efx->n_tx_channels = 1;
1037 rc = pci_enable_msi(efx->pci_dev); 1040 rc = pci_enable_msi(efx->pci_dev);
1038 if (rc == 0) { 1041 if (rc == 0) {
1039 efx->channel[0].irq = efx->pci_dev->irq; 1042 efx->channel[0].irq = efx->pci_dev->irq;
@@ -1045,8 +1048,9 @@ static void efx_probe_interrupts(struct efx_nic *efx)
1045 1048
1046 /* Assume legacy interrupts */ 1049 /* Assume legacy interrupts */
1047 if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) { 1050 if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
1048 efx->n_rx_queues = 1;
1049 efx->n_channels = 1 + (separate_tx_channels ? 1 : 0); 1051 efx->n_channels = 1 + (separate_tx_channels ? 1 : 0);
1052 efx->n_rx_channels = 1;
1053 efx->n_tx_channels = 1;
1050 efx->legacy_irq = efx->pci_dev->irq; 1054 efx->legacy_irq = efx->pci_dev->irq;
1051 } 1055 }
1052} 1056}
@@ -1067,21 +1071,24 @@ static void efx_remove_interrupts(struct efx_nic *efx)
1067 1071
1068static void efx_set_channels(struct efx_nic *efx) 1072static void efx_set_channels(struct efx_nic *efx)
1069{ 1073{
1074 struct efx_channel *channel;
1070 struct efx_tx_queue *tx_queue; 1075 struct efx_tx_queue *tx_queue;
1071 struct efx_rx_queue *rx_queue; 1076 struct efx_rx_queue *rx_queue;
1077 unsigned tx_channel_offset =
1078 separate_tx_channels ? efx->n_channels - efx->n_tx_channels : 0;
1072 1079
1073 efx_for_each_tx_queue(tx_queue, efx) { 1080 efx_for_each_channel(channel, efx) {
1074 if (separate_tx_channels) 1081 if (channel->channel - tx_channel_offset < efx->n_tx_channels) {
1075 tx_queue->channel = &efx->channel[efx->n_channels-1]; 1082 channel->tx_queue = &efx->tx_queue[
1076 else 1083 (channel->channel - tx_channel_offset) *
1077 tx_queue->channel = &efx->channel[0]; 1084 EFX_TXQ_TYPES];
1078 tx_queue->channel->used_flags |= EFX_USED_BY_TX; 1085 efx_for_each_channel_tx_queue(tx_queue, channel)
1086 tx_queue->channel = channel;
1087 }
1079 } 1088 }
1080 1089
1081 efx_for_each_rx_queue(rx_queue, efx) { 1090 efx_for_each_rx_queue(rx_queue, efx)
1082 rx_queue->channel = &efx->channel[rx_queue->queue]; 1091 rx_queue->channel = &efx->channel[rx_queue->queue];
1083 rx_queue->channel->used_flags |= EFX_USED_BY_RX;
1084 }
1085} 1092}
1086 1093
1087static int efx_probe_nic(struct efx_nic *efx) 1094static int efx_probe_nic(struct efx_nic *efx)
@@ -1095,11 +1102,12 @@ static int efx_probe_nic(struct efx_nic *efx)
1095 if (rc) 1102 if (rc)
1096 return rc; 1103 return rc;
1097 1104
1098 /* Determine the number of channels and RX queues by trying to hook 1105 /* Determine the number of channels and queues by trying to hook
1099 * in MSI-X interrupts. */ 1106 * in MSI-X interrupts. */
1100 efx_probe_interrupts(efx); 1107 efx_probe_interrupts(efx);
1101 1108
1102 efx_set_channels(efx); 1109 efx_set_channels(efx);
1110 efx->net_dev->real_num_tx_queues = efx->n_tx_channels;
1103 1111
1104 /* Initialise the interrupt moderation settings */ 1112 /* Initialise the interrupt moderation settings */
1105 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true); 1113 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true);
@@ -1186,11 +1194,12 @@ static void efx_start_all(struct efx_nic *efx)
1186 /* Mark the port as enabled so port reconfigurations can start, then 1194 /* Mark the port as enabled so port reconfigurations can start, then
1187 * restart the transmit interface early so the watchdog timer stops */ 1195 * restart the transmit interface early so the watchdog timer stops */
1188 efx_start_port(efx); 1196 efx_start_port(efx);
1189 if (efx_dev_registered(efx))
1190 efx_wake_queue(efx);
1191 1197
1192 efx_for_each_channel(channel, efx) 1198 efx_for_each_channel(channel, efx) {
1199 if (efx_dev_registered(efx))
1200 efx_wake_queue(channel);
1193 efx_start_channel(channel); 1201 efx_start_channel(channel);
1202 }
1194 1203
1195 efx_nic_enable_interrupts(efx); 1204 efx_nic_enable_interrupts(efx);
1196 1205
@@ -1281,7 +1290,9 @@ static void efx_stop_all(struct efx_nic *efx)
1281 /* Stop the kernel transmit interface late, so the watchdog 1290 /* Stop the kernel transmit interface late, so the watchdog
1282 * timer isn't ticking over the flush */ 1291 * timer isn't ticking over the flush */
1283 if (efx_dev_registered(efx)) { 1292 if (efx_dev_registered(efx)) {
1284 efx_stop_queue(efx); 1293 struct efx_channel *channel;
1294 efx_for_each_channel(channel, efx)
1295 efx_stop_queue(channel);
1285 netif_tx_lock_bh(efx->net_dev); 1296 netif_tx_lock_bh(efx->net_dev);
1286 netif_tx_unlock_bh(efx->net_dev); 1297 netif_tx_unlock_bh(efx->net_dev);
1287 } 1298 }
@@ -1536,9 +1547,8 @@ static void efx_watchdog(struct net_device *net_dev)
1536{ 1547{
1537 struct efx_nic *efx = netdev_priv(net_dev); 1548 struct efx_nic *efx = netdev_priv(net_dev);
1538 1549
1539 EFX_ERR(efx, "TX stuck with stop_count=%d port_enabled=%d:" 1550 EFX_ERR(efx, "TX stuck with port_enabled=%d: resetting channels\n",
1540 " resetting channels\n", 1551 efx->port_enabled);
1541 atomic_read(&efx->netif_stop_count), efx->port_enabled);
1542 1552
1543 efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG); 1553 efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
1544} 1554}
@@ -1602,7 +1612,7 @@ static int efx_set_mac_address(struct net_device *net_dev, void *data)
1602static void efx_set_multicast_list(struct net_device *net_dev) 1612static void efx_set_multicast_list(struct net_device *net_dev)
1603{ 1613{
1604 struct efx_nic *efx = netdev_priv(net_dev); 1614 struct efx_nic *efx = netdev_priv(net_dev);
1605 struct dev_mc_list *mc_list; 1615 struct netdev_hw_addr *ha;
1606 union efx_multicast_hash *mc_hash = &efx->multicast_hash; 1616 union efx_multicast_hash *mc_hash = &efx->multicast_hash;
1607 u32 crc; 1617 u32 crc;
1608 int bit; 1618 int bit;
@@ -1614,8 +1624,8 @@ static void efx_set_multicast_list(struct net_device *net_dev)
1614 memset(mc_hash, 0xff, sizeof(*mc_hash)); 1624 memset(mc_hash, 0xff, sizeof(*mc_hash));
1615 } else { 1625 } else {
1616 memset(mc_hash, 0x00, sizeof(*mc_hash)); 1626 memset(mc_hash, 0x00, sizeof(*mc_hash));
1617 netdev_for_each_mc_addr(mc_list, net_dev) { 1627 netdev_for_each_mc_addr(ha, net_dev) {
1618 crc = ether_crc_le(ETH_ALEN, mc_list->dmi_addr); 1628 crc = ether_crc_le(ETH_ALEN, ha->addr);
1619 bit = crc & (EFX_MCAST_HASH_ENTRIES - 1); 1629 bit = crc & (EFX_MCAST_HASH_ENTRIES - 1);
1620 set_bit_le(bit, mc_hash->byte); 1630 set_bit_le(bit, mc_hash->byte);
1621 } 1631 }
@@ -1860,6 +1870,7 @@ out:
1860 } 1870 }
1861 1871
1862 if (disabled) { 1872 if (disabled) {
1873 dev_close(efx->net_dev);
1863 EFX_ERR(efx, "has been disabled\n"); 1874 EFX_ERR(efx, "has been disabled\n");
1864 efx->state = STATE_DISABLED; 1875 efx->state = STATE_DISABLED;
1865 } else { 1876 } else {
@@ -1883,8 +1894,7 @@ static void efx_reset_work(struct work_struct *data)
1883 } 1894 }
1884 1895
1885 rtnl_lock(); 1896 rtnl_lock();
1886 if (efx_reset(efx, efx->reset_pending)) 1897 (void)efx_reset(efx, efx->reset_pending);
1887 dev_close(efx->net_dev);
1888 rtnl_unlock(); 1898 rtnl_unlock();
1889} 1899}
1890 1900
@@ -2013,22 +2023,22 @@ static int efx_init_struct(struct efx_nic *efx, struct efx_nic_type *type,
2013 2023
2014 efx->net_dev = net_dev; 2024 efx->net_dev = net_dev;
2015 efx->rx_checksum_enabled = true; 2025 efx->rx_checksum_enabled = true;
2016 spin_lock_init(&efx->netif_stop_lock);
2017 spin_lock_init(&efx->stats_lock); 2026 spin_lock_init(&efx->stats_lock);
2018 mutex_init(&efx->mac_lock); 2027 mutex_init(&efx->mac_lock);
2019 efx->mac_op = type->default_mac_ops; 2028 efx->mac_op = type->default_mac_ops;
2020 efx->phy_op = &efx_dummy_phy_operations; 2029 efx->phy_op = &efx_dummy_phy_operations;
2021 efx->mdio.dev = net_dev; 2030 efx->mdio.dev = net_dev;
2022 INIT_WORK(&efx->mac_work, efx_mac_work); 2031 INIT_WORK(&efx->mac_work, efx_mac_work);
2023 atomic_set(&efx->netif_stop_count, 1);
2024 2032
2025 for (i = 0; i < EFX_MAX_CHANNELS; i++) { 2033 for (i = 0; i < EFX_MAX_CHANNELS; i++) {
2026 channel = &efx->channel[i]; 2034 channel = &efx->channel[i];
2027 channel->efx = efx; 2035 channel->efx = efx;
2028 channel->channel = i; 2036 channel->channel = i;
2029 channel->work_pending = false; 2037 channel->work_pending = false;
2038 spin_lock_init(&channel->tx_stop_lock);
2039 atomic_set(&channel->tx_stop_count, 1);
2030 } 2040 }
2031 for (i = 0; i < EFX_TX_QUEUE_COUNT; i++) { 2041 for (i = 0; i < EFX_MAX_TX_QUEUES; i++) {
2032 tx_queue = &efx->tx_queue[i]; 2042 tx_queue = &efx->tx_queue[i];
2033 tx_queue->efx = efx; 2043 tx_queue->efx = efx;
2034 tx_queue->queue = i; 2044 tx_queue->queue = i;
@@ -2200,7 +2210,7 @@ static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
2200 int i, rc; 2210 int i, rc;
2201 2211
2202 /* Allocate and initialise a struct net_device and struct efx_nic */ 2212 /* Allocate and initialise a struct net_device and struct efx_nic */
2203 net_dev = alloc_etherdev(sizeof(*efx)); 2213 net_dev = alloc_etherdev_mq(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES);
2204 if (!net_dev) 2214 if (!net_dev)
2205 return -ENOMEM; 2215 return -ENOMEM;
2206 net_dev->features |= (type->offload_features | NETIF_F_SG | 2216 net_dev->features |= (type->offload_features | NETIF_F_SG |