1768fd266SAlex Maftei (amaftei) // SPDX-License-Identifier: GPL-2.0-only 2768fd266SAlex Maftei (amaftei) /**************************************************************************** 3768fd266SAlex Maftei (amaftei) * Driver for Solarflare network controllers and boards 4768fd266SAlex Maftei (amaftei) * Copyright 2018 Solarflare Communications Inc. 5768fd266SAlex Maftei (amaftei) * 6768fd266SAlex Maftei (amaftei) * This program is free software; you can redistribute it and/or modify it 7768fd266SAlex Maftei (amaftei) * under the terms of the GNU General Public License version 2 as published 8768fd266SAlex Maftei (amaftei) * by the Free Software Foundation, incorporated herein by reference. 9768fd266SAlex Maftei (amaftei) */ 10768fd266SAlex Maftei (amaftei) 11768fd266SAlex Maftei (amaftei) #include "net_driver.h" 12768fd266SAlex Maftei (amaftei) #include <linux/module.h> 13768fd266SAlex Maftei (amaftei) #include "efx_channels.h" 14768fd266SAlex Maftei (amaftei) #include "efx.h" 15768fd266SAlex Maftei (amaftei) #include "efx_common.h" 16768fd266SAlex Maftei (amaftei) #include "tx_common.h" 17768fd266SAlex Maftei (amaftei) #include "rx_common.h" 18768fd266SAlex Maftei (amaftei) #include "nic.h" 19768fd266SAlex Maftei (amaftei) #include "sriov.h" 20768fd266SAlex Maftei (amaftei) 2183975485SAlex Maftei (amaftei) /* This is the first interrupt mode to try out of: 2283975485SAlex Maftei (amaftei) * 0 => MSI-X 2383975485SAlex Maftei (amaftei) * 1 => MSI 2483975485SAlex Maftei (amaftei) * 2 => legacy 2583975485SAlex Maftei (amaftei) */ 26e4ff3232SEdward Cree unsigned int efx_interrupt_mode = EFX_INT_MODE_MSIX; 2783975485SAlex Maftei (amaftei) 2837c45a4eSAlex Maftei (amaftei) /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS), 2937c45a4eSAlex Maftei (amaftei) * i.e. the number of CPUs among which we may distribute simultaneous 3037c45a4eSAlex Maftei (amaftei) * interrupt handling. 3137c45a4eSAlex Maftei (amaftei) * 3237c45a4eSAlex Maftei (amaftei) * Cards without MSI-X will only target one CPU via legacy or MSI interrupt. 3337c45a4eSAlex Maftei (amaftei) * The default (0) means to assign an interrupt to each core. 3437c45a4eSAlex Maftei (amaftei) */ 3567e6398eSEdward Cree unsigned int rss_cpus; 3637c45a4eSAlex Maftei (amaftei) 37768fd266SAlex Maftei (amaftei) static unsigned int irq_adapt_low_thresh = 8000; 38768fd266SAlex Maftei (amaftei) module_param(irq_adapt_low_thresh, uint, 0644); 39768fd266SAlex Maftei (amaftei) MODULE_PARM_DESC(irq_adapt_low_thresh, 40768fd266SAlex Maftei (amaftei) "Threshold score for reducing IRQ moderation"); 41768fd266SAlex Maftei (amaftei) 42768fd266SAlex Maftei (amaftei) static unsigned int irq_adapt_high_thresh = 16000; 43768fd266SAlex Maftei (amaftei) module_param(irq_adapt_high_thresh, uint, 0644); 44768fd266SAlex Maftei (amaftei) MODULE_PARM_DESC(irq_adapt_high_thresh, 45768fd266SAlex Maftei (amaftei) "Threshold score for increasing IRQ moderation"); 46768fd266SAlex Maftei (amaftei) 47768fd266SAlex Maftei (amaftei) /* This is the weight assigned to each of the (per-channel) virtual 48768fd266SAlex Maftei (amaftei) * NAPI devices. 49768fd266SAlex Maftei (amaftei) */ 50768fd266SAlex Maftei (amaftei) static int napi_weight = 64; 51768fd266SAlex Maftei (amaftei) 5283975485SAlex Maftei (amaftei) /*************** 5383975485SAlex Maftei (amaftei) * Housekeeping 5483975485SAlex Maftei (amaftei) ***************/ 5583975485SAlex Maftei (amaftei) 5683975485SAlex Maftei (amaftei) int efx_channel_dummy_op_int(struct efx_channel *channel) 5783975485SAlex Maftei (amaftei) { 5883975485SAlex Maftei (amaftei) return 0; 5983975485SAlex Maftei (amaftei) } 6083975485SAlex Maftei (amaftei) 6183975485SAlex Maftei (amaftei) void efx_channel_dummy_op_void(struct efx_channel *channel) 6283975485SAlex Maftei (amaftei) { 6383975485SAlex Maftei (amaftei) } 6483975485SAlex Maftei (amaftei) 6583975485SAlex Maftei (amaftei) static const struct efx_channel_type efx_default_channel_type = { 6683975485SAlex Maftei (amaftei) .pre_probe = efx_channel_dummy_op_int, 6783975485SAlex Maftei (amaftei) .post_remove = efx_channel_dummy_op_void, 6883975485SAlex Maftei (amaftei) .get_name = efx_get_channel_name, 6983975485SAlex Maftei (amaftei) .copy = efx_copy_channel, 7083975485SAlex Maftei (amaftei) .want_txqs = efx_default_channel_want_txqs, 7183975485SAlex Maftei (amaftei) .keep_eventq = false, 7283975485SAlex Maftei (amaftei) .want_pio = true, 7383975485SAlex Maftei (amaftei) }; 7483975485SAlex Maftei (amaftei) 7537c45a4eSAlex Maftei (amaftei) /************* 7637c45a4eSAlex Maftei (amaftei) * INTERRUPTS 7737c45a4eSAlex Maftei (amaftei) *************/ 7837c45a4eSAlex Maftei (amaftei) 7937c45a4eSAlex Maftei (amaftei) static unsigned int efx_wanted_parallelism(struct efx_nic *efx) 8037c45a4eSAlex Maftei (amaftei) { 8137c45a4eSAlex Maftei (amaftei) cpumask_var_t thread_mask; 8237c45a4eSAlex Maftei (amaftei) unsigned int count; 8337c45a4eSAlex Maftei (amaftei) int cpu; 8437c45a4eSAlex Maftei (amaftei) 8537c45a4eSAlex Maftei (amaftei) if (rss_cpus) { 8637c45a4eSAlex Maftei (amaftei) count = rss_cpus; 8737c45a4eSAlex Maftei (amaftei) } else { 8837c45a4eSAlex Maftei (amaftei) if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) { 8937c45a4eSAlex Maftei (amaftei) netif_warn(efx, probe, efx->net_dev, 9037c45a4eSAlex Maftei (amaftei) "RSS disabled due to allocation failure\n"); 9137c45a4eSAlex Maftei (amaftei) return 1; 9237c45a4eSAlex Maftei (amaftei) } 9337c45a4eSAlex Maftei (amaftei) 9437c45a4eSAlex Maftei (amaftei) count = 0; 9537c45a4eSAlex Maftei (amaftei) for_each_online_cpu(cpu) { 9637c45a4eSAlex Maftei (amaftei) if (!cpumask_test_cpu(cpu, thread_mask)) { 9737c45a4eSAlex Maftei (amaftei) ++count; 9837c45a4eSAlex Maftei (amaftei) cpumask_or(thread_mask, thread_mask, 9937c45a4eSAlex Maftei (amaftei) topology_sibling_cpumask(cpu)); 10037c45a4eSAlex Maftei (amaftei) } 10137c45a4eSAlex Maftei (amaftei) } 10237c45a4eSAlex Maftei (amaftei) 10337c45a4eSAlex Maftei (amaftei) free_cpumask_var(thread_mask); 10437c45a4eSAlex Maftei (amaftei) } 10537c45a4eSAlex Maftei (amaftei) 10637c45a4eSAlex Maftei (amaftei) if (count > EFX_MAX_RX_QUEUES) { 10737c45a4eSAlex Maftei (amaftei) netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn, 10837c45a4eSAlex Maftei (amaftei) "Reducing number of rx queues from %u to %u.\n", 10937c45a4eSAlex Maftei (amaftei) count, EFX_MAX_RX_QUEUES); 11037c45a4eSAlex Maftei (amaftei) count = EFX_MAX_RX_QUEUES; 11137c45a4eSAlex Maftei (amaftei) } 11237c45a4eSAlex Maftei (amaftei) 11337c45a4eSAlex Maftei (amaftei) /* If RSS is requested for the PF *and* VFs then we can't write RSS 11437c45a4eSAlex Maftei (amaftei) * table entries that are inaccessible to VFs 11537c45a4eSAlex Maftei (amaftei) */ 11637c45a4eSAlex Maftei (amaftei) #ifdef CONFIG_SFC_SRIOV 11737c45a4eSAlex Maftei (amaftei) if (efx->type->sriov_wanted) { 11837c45a4eSAlex Maftei (amaftei) if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 && 11937c45a4eSAlex Maftei (amaftei) count > efx_vf_size(efx)) { 12037c45a4eSAlex Maftei (amaftei) netif_warn(efx, probe, efx->net_dev, 12137c45a4eSAlex Maftei (amaftei) "Reducing number of RSS channels from %u to %u for " 12237c45a4eSAlex Maftei (amaftei) "VF support. Increase vf-msix-limit to use more " 12337c45a4eSAlex Maftei (amaftei) "channels on the PF.\n", 12437c45a4eSAlex Maftei (amaftei) count, efx_vf_size(efx)); 12537c45a4eSAlex Maftei (amaftei) count = efx_vf_size(efx); 12637c45a4eSAlex Maftei (amaftei) } 12737c45a4eSAlex Maftei (amaftei) } 12837c45a4eSAlex Maftei (amaftei) #endif 12937c45a4eSAlex Maftei (amaftei) 13037c45a4eSAlex Maftei (amaftei) return count; 13137c45a4eSAlex Maftei (amaftei) } 13237c45a4eSAlex Maftei (amaftei) 13337c45a4eSAlex Maftei (amaftei) static int efx_allocate_msix_channels(struct efx_nic *efx, 13437c45a4eSAlex Maftei (amaftei) unsigned int max_channels, 13537c45a4eSAlex Maftei (amaftei) unsigned int extra_channels, 13637c45a4eSAlex Maftei (amaftei) unsigned int parallelism) 13737c45a4eSAlex Maftei (amaftei) { 13837c45a4eSAlex Maftei (amaftei) unsigned int n_channels = parallelism; 13937c45a4eSAlex Maftei (amaftei) int vec_count; 14037c45a4eSAlex Maftei (amaftei) int n_xdp_tx; 14137c45a4eSAlex Maftei (amaftei) int n_xdp_ev; 14237c45a4eSAlex Maftei (amaftei) 14337c45a4eSAlex Maftei (amaftei) if (efx_separate_tx_channels) 14437c45a4eSAlex Maftei (amaftei) n_channels *= 2; 14537c45a4eSAlex Maftei (amaftei) n_channels += extra_channels; 14637c45a4eSAlex Maftei (amaftei) 14737c45a4eSAlex Maftei (amaftei) /* To allow XDP transmit to happen from arbitrary NAPI contexts 14837c45a4eSAlex Maftei (amaftei) * we allocate a TX queue per CPU. We share event queues across 14937c45a4eSAlex Maftei (amaftei) * multiple tx queues, assuming tx and ev queues are both 15037c45a4eSAlex Maftei (amaftei) * maximum size. 15137c45a4eSAlex Maftei (amaftei) */ 15237c45a4eSAlex Maftei (amaftei) 15337c45a4eSAlex Maftei (amaftei) n_xdp_tx = num_possible_cpus(); 15437c45a4eSAlex Maftei (amaftei) n_xdp_ev = DIV_ROUND_UP(n_xdp_tx, EFX_TXQ_TYPES); 15537c45a4eSAlex Maftei (amaftei) 15637c45a4eSAlex Maftei (amaftei) vec_count = pci_msix_vec_count(efx->pci_dev); 15737c45a4eSAlex Maftei (amaftei) if (vec_count < 0) 15837c45a4eSAlex Maftei (amaftei) return vec_count; 15937c45a4eSAlex Maftei (amaftei) 16037c45a4eSAlex Maftei (amaftei) max_channels = min_t(unsigned int, vec_count, max_channels); 16137c45a4eSAlex Maftei (amaftei) 16237c45a4eSAlex Maftei (amaftei) /* Check resources. 16337c45a4eSAlex Maftei (amaftei) * We need a channel per event queue, plus a VI per tx queue. 16437c45a4eSAlex Maftei (amaftei) * This may be more pessimistic than it needs to be. 16537c45a4eSAlex Maftei (amaftei) */ 16637c45a4eSAlex Maftei (amaftei) if (n_channels + n_xdp_ev > max_channels) { 16737c45a4eSAlex Maftei (amaftei) netif_err(efx, drv, efx->net_dev, 16837c45a4eSAlex Maftei (amaftei) "Insufficient resources for %d XDP event queues (%d other channels, max %d)\n", 16937c45a4eSAlex Maftei (amaftei) n_xdp_ev, n_channels, max_channels); 17037c45a4eSAlex Maftei (amaftei) efx->n_xdp_channels = 0; 17137c45a4eSAlex Maftei (amaftei) efx->xdp_tx_per_channel = 0; 17237c45a4eSAlex Maftei (amaftei) efx->xdp_tx_queue_count = 0; 173de5f32e2SEdward Cree } else if (n_channels + n_xdp_tx > efx->max_vis) { 174de5f32e2SEdward Cree netif_err(efx, drv, efx->net_dev, 175de5f32e2SEdward Cree "Insufficient resources for %d XDP TX queues (%d other channels, max VIs %d)\n", 176de5f32e2SEdward Cree n_xdp_tx, n_channels, efx->max_vis); 177de5f32e2SEdward Cree efx->n_xdp_channels = 0; 178de5f32e2SEdward Cree efx->xdp_tx_per_channel = 0; 179de5f32e2SEdward Cree efx->xdp_tx_queue_count = 0; 18037c45a4eSAlex Maftei (amaftei) } else { 18137c45a4eSAlex Maftei (amaftei) efx->n_xdp_channels = n_xdp_ev; 18237c45a4eSAlex Maftei (amaftei) efx->xdp_tx_per_channel = EFX_TXQ_TYPES; 18337c45a4eSAlex Maftei (amaftei) efx->xdp_tx_queue_count = n_xdp_tx; 18437c45a4eSAlex Maftei (amaftei) n_channels += n_xdp_ev; 18537c45a4eSAlex Maftei (amaftei) netif_dbg(efx, drv, efx->net_dev, 18637c45a4eSAlex Maftei (amaftei) "Allocating %d TX and %d event queues for XDP\n", 18737c45a4eSAlex Maftei (amaftei) n_xdp_tx, n_xdp_ev); 18837c45a4eSAlex Maftei (amaftei) } 18937c45a4eSAlex Maftei (amaftei) 19037c45a4eSAlex Maftei (amaftei) if (vec_count < n_channels) { 19137c45a4eSAlex Maftei (amaftei) netif_err(efx, drv, efx->net_dev, 19237c45a4eSAlex Maftei (amaftei) "WARNING: Insufficient MSI-X vectors available (%d < %u).\n", 19337c45a4eSAlex Maftei (amaftei) vec_count, n_channels); 19437c45a4eSAlex Maftei (amaftei) netif_err(efx, drv, efx->net_dev, 19537c45a4eSAlex Maftei (amaftei) "WARNING: Performance may be reduced.\n"); 19637c45a4eSAlex Maftei (amaftei) n_channels = vec_count; 19737c45a4eSAlex Maftei (amaftei) } 19837c45a4eSAlex Maftei (amaftei) 19937c45a4eSAlex Maftei (amaftei) n_channels = min(n_channels, max_channels); 20037c45a4eSAlex Maftei (amaftei) 20137c45a4eSAlex Maftei (amaftei) efx->n_channels = n_channels; 20237c45a4eSAlex Maftei (amaftei) 20337c45a4eSAlex Maftei (amaftei) /* Ignore XDP tx channels when creating rx channels. */ 20437c45a4eSAlex Maftei (amaftei) n_channels -= efx->n_xdp_channels; 20537c45a4eSAlex Maftei (amaftei) 20637c45a4eSAlex Maftei (amaftei) if (efx_separate_tx_channels) { 20737c45a4eSAlex Maftei (amaftei) efx->n_tx_channels = 20837c45a4eSAlex Maftei (amaftei) min(max(n_channels / 2, 1U), 20937c45a4eSAlex Maftei (amaftei) efx->max_tx_channels); 21037c45a4eSAlex Maftei (amaftei) efx->tx_channel_offset = 21137c45a4eSAlex Maftei (amaftei) n_channels - efx->n_tx_channels; 21237c45a4eSAlex Maftei (amaftei) efx->n_rx_channels = 21337c45a4eSAlex Maftei (amaftei) max(n_channels - 21437c45a4eSAlex Maftei (amaftei) efx->n_tx_channels, 1U); 21537c45a4eSAlex Maftei (amaftei) } else { 21637c45a4eSAlex Maftei (amaftei) efx->n_tx_channels = min(n_channels, efx->max_tx_channels); 21737c45a4eSAlex Maftei (amaftei) efx->tx_channel_offset = 0; 21837c45a4eSAlex Maftei (amaftei) efx->n_rx_channels = n_channels; 21937c45a4eSAlex Maftei (amaftei) } 22037c45a4eSAlex Maftei (amaftei) 22137c45a4eSAlex Maftei (amaftei) efx->n_rx_channels = min(efx->n_rx_channels, parallelism); 22237c45a4eSAlex Maftei (amaftei) efx->n_tx_channels = min(efx->n_tx_channels, parallelism); 22337c45a4eSAlex Maftei (amaftei) 22437c45a4eSAlex Maftei (amaftei) efx->xdp_channel_offset = n_channels; 22537c45a4eSAlex Maftei (amaftei) 22637c45a4eSAlex Maftei (amaftei) netif_dbg(efx, drv, efx->net_dev, 22737c45a4eSAlex Maftei (amaftei) "Allocating %u RX channels\n", 22837c45a4eSAlex Maftei (amaftei) efx->n_rx_channels); 22937c45a4eSAlex Maftei (amaftei) 23037c45a4eSAlex Maftei (amaftei) return efx->n_channels; 23137c45a4eSAlex Maftei (amaftei) } 23237c45a4eSAlex Maftei (amaftei) 23337c45a4eSAlex Maftei (amaftei) /* Probe the number and type of interrupts we are able to obtain, and 23437c45a4eSAlex Maftei (amaftei) * the resulting numbers of channels and RX queues. 23537c45a4eSAlex Maftei (amaftei) */ 23637c45a4eSAlex Maftei (amaftei) int efx_probe_interrupts(struct efx_nic *efx) 23737c45a4eSAlex Maftei (amaftei) { 23837c45a4eSAlex Maftei (amaftei) unsigned int extra_channels = 0; 23937c45a4eSAlex Maftei (amaftei) unsigned int rss_spread; 24037c45a4eSAlex Maftei (amaftei) unsigned int i, j; 24137c45a4eSAlex Maftei (amaftei) int rc; 24237c45a4eSAlex Maftei (amaftei) 24337c45a4eSAlex Maftei (amaftei) for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) 24437c45a4eSAlex Maftei (amaftei) if (efx->extra_channel_type[i]) 24537c45a4eSAlex Maftei (amaftei) ++extra_channels; 24637c45a4eSAlex Maftei (amaftei) 24737c45a4eSAlex Maftei (amaftei) if (efx->interrupt_mode == EFX_INT_MODE_MSIX) { 24837c45a4eSAlex Maftei (amaftei) unsigned int parallelism = efx_wanted_parallelism(efx); 24937c45a4eSAlex Maftei (amaftei) struct msix_entry xentries[EFX_MAX_CHANNELS]; 25037c45a4eSAlex Maftei (amaftei) unsigned int n_channels; 25137c45a4eSAlex Maftei (amaftei) 25237c45a4eSAlex Maftei (amaftei) rc = efx_allocate_msix_channels(efx, efx->max_channels, 25337c45a4eSAlex Maftei (amaftei) extra_channels, parallelism); 25437c45a4eSAlex Maftei (amaftei) if (rc >= 0) { 25537c45a4eSAlex Maftei (amaftei) n_channels = rc; 25637c45a4eSAlex Maftei (amaftei) for (i = 0; i < n_channels; i++) 25737c45a4eSAlex Maftei (amaftei) xentries[i].entry = i; 25837c45a4eSAlex Maftei (amaftei) rc = pci_enable_msix_range(efx->pci_dev, xentries, 1, 25937c45a4eSAlex Maftei (amaftei) n_channels); 26037c45a4eSAlex Maftei (amaftei) } 26137c45a4eSAlex Maftei (amaftei) if (rc < 0) { 26237c45a4eSAlex Maftei (amaftei) /* Fall back to single channel MSI */ 26337c45a4eSAlex Maftei (amaftei) netif_err(efx, drv, efx->net_dev, 26437c45a4eSAlex Maftei (amaftei) "could not enable MSI-X\n"); 26537c45a4eSAlex Maftei (amaftei) if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI) 26637c45a4eSAlex Maftei (amaftei) efx->interrupt_mode = EFX_INT_MODE_MSI; 26737c45a4eSAlex Maftei (amaftei) else 26837c45a4eSAlex Maftei (amaftei) return rc; 26937c45a4eSAlex Maftei (amaftei) } else if (rc < n_channels) { 27037c45a4eSAlex Maftei (amaftei) netif_err(efx, drv, efx->net_dev, 27137c45a4eSAlex Maftei (amaftei) "WARNING: Insufficient MSI-X vectors" 27237c45a4eSAlex Maftei (amaftei) " available (%d < %u).\n", rc, n_channels); 27337c45a4eSAlex Maftei (amaftei) netif_err(efx, drv, efx->net_dev, 27437c45a4eSAlex Maftei (amaftei) "WARNING: Performance may be reduced.\n"); 27537c45a4eSAlex Maftei (amaftei) n_channels = rc; 27637c45a4eSAlex Maftei (amaftei) } 27737c45a4eSAlex Maftei (amaftei) 27837c45a4eSAlex Maftei (amaftei) if (rc > 0) { 27937c45a4eSAlex Maftei (amaftei) for (i = 0; i < efx->n_channels; i++) 28037c45a4eSAlex Maftei (amaftei) efx_get_channel(efx, i)->irq = 28137c45a4eSAlex Maftei (amaftei) xentries[i].vector; 28237c45a4eSAlex Maftei (amaftei) } 28337c45a4eSAlex Maftei (amaftei) } 28437c45a4eSAlex Maftei (amaftei) 28537c45a4eSAlex Maftei (amaftei) /* Try single interrupt MSI */ 28637c45a4eSAlex Maftei (amaftei) if (efx->interrupt_mode == EFX_INT_MODE_MSI) { 28737c45a4eSAlex Maftei (amaftei) efx->n_channels = 1; 28837c45a4eSAlex Maftei (amaftei) efx->n_rx_channels = 1; 28937c45a4eSAlex Maftei (amaftei) efx->n_tx_channels = 1; 29037c45a4eSAlex Maftei (amaftei) efx->n_xdp_channels = 0; 29137c45a4eSAlex Maftei (amaftei) efx->xdp_channel_offset = efx->n_channels; 29237c45a4eSAlex Maftei (amaftei) rc = pci_enable_msi(efx->pci_dev); 29337c45a4eSAlex Maftei (amaftei) if (rc == 0) { 29437c45a4eSAlex Maftei (amaftei) efx_get_channel(efx, 0)->irq = efx->pci_dev->irq; 29537c45a4eSAlex Maftei (amaftei) } else { 29637c45a4eSAlex Maftei (amaftei) netif_err(efx, drv, efx->net_dev, 29737c45a4eSAlex Maftei (amaftei) "could not enable MSI\n"); 29837c45a4eSAlex Maftei (amaftei) if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY) 29937c45a4eSAlex Maftei (amaftei) efx->interrupt_mode = EFX_INT_MODE_LEGACY; 30037c45a4eSAlex Maftei (amaftei) else 30137c45a4eSAlex Maftei (amaftei) return rc; 30237c45a4eSAlex Maftei (amaftei) } 30337c45a4eSAlex Maftei (amaftei) } 30437c45a4eSAlex Maftei (amaftei) 30537c45a4eSAlex Maftei (amaftei) /* Assume legacy interrupts */ 30637c45a4eSAlex Maftei (amaftei) if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) { 30737c45a4eSAlex Maftei (amaftei) efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0); 30837c45a4eSAlex Maftei (amaftei) efx->n_rx_channels = 1; 30937c45a4eSAlex Maftei (amaftei) efx->n_tx_channels = 1; 31037c45a4eSAlex Maftei (amaftei) efx->n_xdp_channels = 0; 31137c45a4eSAlex Maftei (amaftei) efx->xdp_channel_offset = efx->n_channels; 31237c45a4eSAlex Maftei (amaftei) efx->legacy_irq = efx->pci_dev->irq; 31337c45a4eSAlex Maftei (amaftei) } 31437c45a4eSAlex Maftei (amaftei) 31537c45a4eSAlex Maftei (amaftei) /* Assign extra channels if possible, before XDP channels */ 31637c45a4eSAlex Maftei (amaftei) efx->n_extra_tx_channels = 0; 31737c45a4eSAlex Maftei (amaftei) j = efx->xdp_channel_offset; 31837c45a4eSAlex Maftei (amaftei) for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) { 31937c45a4eSAlex Maftei (amaftei) if (!efx->extra_channel_type[i]) 32037c45a4eSAlex Maftei (amaftei) continue; 32137c45a4eSAlex Maftei (amaftei) if (j <= efx->tx_channel_offset + efx->n_tx_channels) { 32237c45a4eSAlex Maftei (amaftei) efx->extra_channel_type[i]->handle_no_channel(efx); 32337c45a4eSAlex Maftei (amaftei) } else { 32437c45a4eSAlex Maftei (amaftei) --j; 32537c45a4eSAlex Maftei (amaftei) efx_get_channel(efx, j)->type = 32637c45a4eSAlex Maftei (amaftei) efx->extra_channel_type[i]; 32737c45a4eSAlex Maftei (amaftei) if (efx_channel_has_tx_queues(efx_get_channel(efx, j))) 32837c45a4eSAlex Maftei (amaftei) efx->n_extra_tx_channels++; 32937c45a4eSAlex Maftei (amaftei) } 33037c45a4eSAlex Maftei (amaftei) } 33137c45a4eSAlex Maftei (amaftei) 33237c45a4eSAlex Maftei (amaftei) rss_spread = efx->n_rx_channels; 33337c45a4eSAlex Maftei (amaftei) /* RSS might be usable on VFs even if it is disabled on the PF */ 33437c45a4eSAlex Maftei (amaftei) #ifdef CONFIG_SFC_SRIOV 33537c45a4eSAlex Maftei (amaftei) if (efx->type->sriov_wanted) { 33637c45a4eSAlex Maftei (amaftei) efx->rss_spread = ((rss_spread > 1 || 33737c45a4eSAlex Maftei (amaftei) !efx->type->sriov_wanted(efx)) ? 33837c45a4eSAlex Maftei (amaftei) rss_spread : efx_vf_size(efx)); 33937c45a4eSAlex Maftei (amaftei) return 0; 34037c45a4eSAlex Maftei (amaftei) } 34137c45a4eSAlex Maftei (amaftei) #endif 34237c45a4eSAlex Maftei (amaftei) efx->rss_spread = rss_spread; 34337c45a4eSAlex Maftei (amaftei) 34437c45a4eSAlex Maftei (amaftei) return 0; 34537c45a4eSAlex Maftei (amaftei) } 34637c45a4eSAlex Maftei (amaftei) 34737c45a4eSAlex Maftei (amaftei) #if defined(CONFIG_SMP) 34837c45a4eSAlex Maftei (amaftei) void efx_set_interrupt_affinity(struct efx_nic *efx) 34937c45a4eSAlex Maftei (amaftei) { 35037c45a4eSAlex Maftei (amaftei) struct efx_channel *channel; 35137c45a4eSAlex Maftei (amaftei) unsigned int cpu; 35237c45a4eSAlex Maftei (amaftei) 35337c45a4eSAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 35437c45a4eSAlex Maftei (amaftei) cpu = cpumask_local_spread(channel->channel, 35537c45a4eSAlex Maftei (amaftei) pcibus_to_node(efx->pci_dev->bus)); 35637c45a4eSAlex Maftei (amaftei) irq_set_affinity_hint(channel->irq, cpumask_of(cpu)); 35737c45a4eSAlex Maftei (amaftei) } 35837c45a4eSAlex Maftei (amaftei) } 35937c45a4eSAlex Maftei (amaftei) 36037c45a4eSAlex Maftei (amaftei) void efx_clear_interrupt_affinity(struct efx_nic *efx) 36137c45a4eSAlex Maftei (amaftei) { 36237c45a4eSAlex Maftei (amaftei) struct efx_channel *channel; 36337c45a4eSAlex Maftei (amaftei) 36437c45a4eSAlex Maftei (amaftei) efx_for_each_channel(channel, efx) 36537c45a4eSAlex Maftei (amaftei) irq_set_affinity_hint(channel->irq, NULL); 36637c45a4eSAlex Maftei (amaftei) } 36737c45a4eSAlex Maftei (amaftei) #else 36837c45a4eSAlex Maftei (amaftei) void 36937c45a4eSAlex Maftei (amaftei) efx_set_interrupt_affinity(struct efx_nic *efx __attribute__ ((unused))) 37037c45a4eSAlex Maftei (amaftei) { 37137c45a4eSAlex Maftei (amaftei) } 37237c45a4eSAlex Maftei (amaftei) 37337c45a4eSAlex Maftei (amaftei) void 37437c45a4eSAlex Maftei (amaftei) efx_clear_interrupt_affinity(struct efx_nic *efx __attribute__ ((unused))) 37537c45a4eSAlex Maftei (amaftei) { 37637c45a4eSAlex Maftei (amaftei) } 37737c45a4eSAlex Maftei (amaftei) #endif /* CONFIG_SMP */ 37837c45a4eSAlex Maftei (amaftei) 37937c45a4eSAlex Maftei (amaftei) void efx_remove_interrupts(struct efx_nic *efx) 38037c45a4eSAlex Maftei (amaftei) { 38137c45a4eSAlex Maftei (amaftei) struct efx_channel *channel; 38237c45a4eSAlex Maftei (amaftei) 38337c45a4eSAlex Maftei (amaftei) /* Remove MSI/MSI-X interrupts */ 38437c45a4eSAlex Maftei (amaftei) efx_for_each_channel(channel, efx) 38537c45a4eSAlex Maftei (amaftei) channel->irq = 0; 38637c45a4eSAlex Maftei (amaftei) pci_disable_msi(efx->pci_dev); 38737c45a4eSAlex Maftei (amaftei) pci_disable_msix(efx->pci_dev); 38837c45a4eSAlex Maftei (amaftei) 38937c45a4eSAlex Maftei (amaftei) /* Remove legacy interrupt */ 39037c45a4eSAlex Maftei (amaftei) efx->legacy_irq = 0; 39137c45a4eSAlex Maftei (amaftei) } 39237c45a4eSAlex Maftei (amaftei) 3935f999256SAlex Maftei (amaftei) /*************** 3945f999256SAlex Maftei (amaftei) * EVENT QUEUES 3955f999256SAlex Maftei (amaftei) ***************/ 3965f999256SAlex Maftei (amaftei) 3975f999256SAlex Maftei (amaftei) /* Create event queue 3985f999256SAlex Maftei (amaftei) * Event queue memory allocations are done only once. If the channel 3995f999256SAlex Maftei (amaftei) * is reset, the memory buffer will be reused; this guards against 4005f999256SAlex Maftei (amaftei) * errors during channel reset and also simplifies interrupt handling. 4015f999256SAlex Maftei (amaftei) */ 4025f999256SAlex Maftei (amaftei) int efx_probe_eventq(struct efx_channel *channel) 4035f999256SAlex Maftei (amaftei) { 4045f999256SAlex Maftei (amaftei) struct efx_nic *efx = channel->efx; 4055f999256SAlex Maftei (amaftei) unsigned long entries; 4065f999256SAlex Maftei (amaftei) 4075f999256SAlex Maftei (amaftei) netif_dbg(efx, probe, efx->net_dev, 4085f999256SAlex Maftei (amaftei) "chan %d create event queue\n", channel->channel); 4095f999256SAlex Maftei (amaftei) 4105f999256SAlex Maftei (amaftei) /* Build an event queue with room for one event per tx and rx buffer, 4115f999256SAlex Maftei (amaftei) * plus some extra for link state events and MCDI completions. 4125f999256SAlex Maftei (amaftei) */ 4135f999256SAlex Maftei (amaftei) entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128); 4145f999256SAlex Maftei (amaftei) EFX_WARN_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE); 4155f999256SAlex Maftei (amaftei) channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1; 4165f999256SAlex Maftei (amaftei) 4175f999256SAlex Maftei (amaftei) return efx_nic_probe_eventq(channel); 4185f999256SAlex Maftei (amaftei) } 4195f999256SAlex Maftei (amaftei) 4205f999256SAlex Maftei (amaftei) /* Prepare channel's event queue */ 4215f999256SAlex Maftei (amaftei) int efx_init_eventq(struct efx_channel *channel) 4225f999256SAlex Maftei (amaftei) { 4235f999256SAlex Maftei (amaftei) struct efx_nic *efx = channel->efx; 4245f999256SAlex Maftei (amaftei) int rc; 4255f999256SAlex Maftei (amaftei) 4265f999256SAlex Maftei (amaftei) EFX_WARN_ON_PARANOID(channel->eventq_init); 4275f999256SAlex Maftei (amaftei) 4285f999256SAlex Maftei (amaftei) netif_dbg(efx, drv, efx->net_dev, 4295f999256SAlex Maftei (amaftei) "chan %d init event queue\n", channel->channel); 4305f999256SAlex Maftei (amaftei) 4315f999256SAlex Maftei (amaftei) rc = efx_nic_init_eventq(channel); 4325f999256SAlex Maftei (amaftei) if (rc == 0) { 4335f999256SAlex Maftei (amaftei) efx->type->push_irq_moderation(channel); 4345f999256SAlex Maftei (amaftei) channel->eventq_read_ptr = 0; 4355f999256SAlex Maftei (amaftei) channel->eventq_init = true; 4365f999256SAlex Maftei (amaftei) } 4375f999256SAlex Maftei (amaftei) return rc; 4385f999256SAlex Maftei (amaftei) } 4395f999256SAlex Maftei (amaftei) 4405f999256SAlex Maftei (amaftei) /* Enable event queue processing and NAPI */ 4415f999256SAlex Maftei (amaftei) void efx_start_eventq(struct efx_channel *channel) 4425f999256SAlex Maftei (amaftei) { 4435f999256SAlex Maftei (amaftei) netif_dbg(channel->efx, ifup, channel->efx->net_dev, 4445f999256SAlex Maftei (amaftei) "chan %d start event queue\n", channel->channel); 4455f999256SAlex Maftei (amaftei) 4465f999256SAlex Maftei (amaftei) /* Make sure the NAPI handler sees the enabled flag set */ 4475f999256SAlex Maftei (amaftei) channel->enabled = true; 4485f999256SAlex Maftei (amaftei) smp_wmb(); 4495f999256SAlex Maftei (amaftei) 4505f999256SAlex Maftei (amaftei) napi_enable(&channel->napi_str); 4515f999256SAlex Maftei (amaftei) efx_nic_eventq_read_ack(channel); 4525f999256SAlex Maftei (amaftei) } 4535f999256SAlex Maftei (amaftei) 4545f999256SAlex Maftei (amaftei) /* Disable event queue processing and NAPI */ 4555f999256SAlex Maftei (amaftei) void efx_stop_eventq(struct efx_channel *channel) 4565f999256SAlex Maftei (amaftei) { 4575f999256SAlex Maftei (amaftei) if (!channel->enabled) 4585f999256SAlex Maftei (amaftei) return; 4595f999256SAlex Maftei (amaftei) 4605f999256SAlex Maftei (amaftei) napi_disable(&channel->napi_str); 4615f999256SAlex Maftei (amaftei) channel->enabled = false; 4625f999256SAlex Maftei (amaftei) } 4635f999256SAlex Maftei (amaftei) 4645f999256SAlex Maftei (amaftei) void efx_fini_eventq(struct efx_channel *channel) 4655f999256SAlex Maftei (amaftei) { 4665f999256SAlex Maftei (amaftei) if (!channel->eventq_init) 4675f999256SAlex Maftei (amaftei) return; 4685f999256SAlex Maftei (amaftei) 4695f999256SAlex Maftei (amaftei) netif_dbg(channel->efx, drv, channel->efx->net_dev, 4705f999256SAlex Maftei (amaftei) "chan %d fini event queue\n", channel->channel); 4715f999256SAlex Maftei (amaftei) 4725f999256SAlex Maftei (amaftei) efx_nic_fini_eventq(channel); 4735f999256SAlex Maftei (amaftei) channel->eventq_init = false; 4745f999256SAlex Maftei (amaftei) } 4755f999256SAlex Maftei (amaftei) 4765f999256SAlex Maftei (amaftei) void efx_remove_eventq(struct efx_channel *channel) 4775f999256SAlex Maftei (amaftei) { 4785f999256SAlex Maftei (amaftei) netif_dbg(channel->efx, drv, channel->efx->net_dev, 4795f999256SAlex Maftei (amaftei) "chan %d remove event queue\n", channel->channel); 4805f999256SAlex Maftei (amaftei) 4815f999256SAlex Maftei (amaftei) efx_nic_remove_eventq(channel); 4825f999256SAlex Maftei (amaftei) } 4835f999256SAlex Maftei (amaftei) 48483975485SAlex Maftei (amaftei) /************************************************************************** 48583975485SAlex Maftei (amaftei) * 48683975485SAlex Maftei (amaftei) * Channel handling 48783975485SAlex Maftei (amaftei) * 48883975485SAlex Maftei (amaftei) *************************************************************************/ 48983975485SAlex Maftei (amaftei) 490025c5a0bSEdward Cree #ifdef CONFIG_RFS_ACCEL 491025c5a0bSEdward Cree static void efx_filter_rfs_expire(struct work_struct *data) 492025c5a0bSEdward Cree { 493025c5a0bSEdward Cree struct delayed_work *dwork = to_delayed_work(data); 494025c5a0bSEdward Cree struct efx_channel *channel; 495025c5a0bSEdward Cree unsigned int time, quota; 496025c5a0bSEdward Cree 497025c5a0bSEdward Cree channel = container_of(dwork, struct efx_channel, filter_work); 498025c5a0bSEdward Cree time = jiffies - channel->rfs_last_expiry; 499025c5a0bSEdward Cree quota = channel->rfs_filter_count * time / (30 * HZ); 500025c5a0bSEdward Cree if (quota >= 20 && __efx_filter_rfs_expire(channel, min(channel->rfs_filter_count, quota))) 501025c5a0bSEdward Cree channel->rfs_last_expiry += time; 502025c5a0bSEdward Cree /* Ensure we do more work eventually even if NAPI poll is not happening */ 503025c5a0bSEdward Cree schedule_delayed_work(dwork, 30 * HZ); 504025c5a0bSEdward Cree } 505025c5a0bSEdward Cree #endif 506025c5a0bSEdward Cree 50783975485SAlex Maftei (amaftei) /* Allocate and initialise a channel structure. */ 5084da24fa6SEdward Cree static struct efx_channel *efx_alloc_channel(struct efx_nic *efx, int i) 50983975485SAlex Maftei (amaftei) { 51083975485SAlex Maftei (amaftei) struct efx_rx_queue *rx_queue; 51183975485SAlex Maftei (amaftei) struct efx_tx_queue *tx_queue; 51283975485SAlex Maftei (amaftei) struct efx_channel *channel; 51383975485SAlex Maftei (amaftei) int j; 51483975485SAlex Maftei (amaftei) 51583975485SAlex Maftei (amaftei) channel = kzalloc(sizeof(*channel), GFP_KERNEL); 51683975485SAlex Maftei (amaftei) if (!channel) 51783975485SAlex Maftei (amaftei) return NULL; 51883975485SAlex Maftei (amaftei) 51983975485SAlex Maftei (amaftei) channel->efx = efx; 52083975485SAlex Maftei (amaftei) channel->channel = i; 52183975485SAlex Maftei (amaftei) channel->type = &efx_default_channel_type; 52283975485SAlex Maftei (amaftei) 52383975485SAlex Maftei (amaftei) for (j = 0; j < EFX_TXQ_TYPES; j++) { 52483975485SAlex Maftei (amaftei) tx_queue = &channel->tx_queue[j]; 52583975485SAlex Maftei (amaftei) tx_queue->efx = efx; 526a81dcd85SEdward Cree tx_queue->queue = -1; 527a81dcd85SEdward Cree tx_queue->label = j; 52883975485SAlex Maftei (amaftei) tx_queue->channel = channel; 52983975485SAlex Maftei (amaftei) } 53083975485SAlex Maftei (amaftei) 53183975485SAlex Maftei (amaftei) #ifdef CONFIG_RFS_ACCEL 53283975485SAlex Maftei (amaftei) INIT_DELAYED_WORK(&channel->filter_work, efx_filter_rfs_expire); 53383975485SAlex Maftei (amaftei) #endif 53483975485SAlex Maftei (amaftei) 53583975485SAlex Maftei (amaftei) rx_queue = &channel->rx_queue; 53683975485SAlex Maftei (amaftei) rx_queue->efx = efx; 53783975485SAlex Maftei (amaftei) timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0); 53883975485SAlex Maftei (amaftei) 53983975485SAlex Maftei (amaftei) return channel; 54083975485SAlex Maftei (amaftei) } 54183975485SAlex Maftei (amaftei) 54283975485SAlex Maftei (amaftei) int efx_init_channels(struct efx_nic *efx) 54383975485SAlex Maftei (amaftei) { 54483975485SAlex Maftei (amaftei) unsigned int i; 54583975485SAlex Maftei (amaftei) 54683975485SAlex Maftei (amaftei) for (i = 0; i < EFX_MAX_CHANNELS; i++) { 5474da24fa6SEdward Cree efx->channel[i] = efx_alloc_channel(efx, i); 54883975485SAlex Maftei (amaftei) if (!efx->channel[i]) 54983975485SAlex Maftei (amaftei) return -ENOMEM; 55083975485SAlex Maftei (amaftei) efx->msi_context[i].efx = efx; 55183975485SAlex Maftei (amaftei) efx->msi_context[i].index = i; 55283975485SAlex Maftei (amaftei) } 55383975485SAlex Maftei (amaftei) 55483975485SAlex Maftei (amaftei) /* Higher numbered interrupt modes are less capable! */ 55583975485SAlex Maftei (amaftei) efx->interrupt_mode = min(efx->type->min_interrupt_mode, 556e4ff3232SEdward Cree efx_interrupt_mode); 55783975485SAlex Maftei (amaftei) 558937aa3aeSEdward Cree efx->max_channels = EFX_MAX_CHANNELS; 559937aa3aeSEdward Cree efx->max_tx_channels = EFX_MAX_CHANNELS; 560937aa3aeSEdward Cree 56183975485SAlex Maftei (amaftei) return 0; 56283975485SAlex Maftei (amaftei) } 56383975485SAlex Maftei (amaftei) 56483975485SAlex Maftei (amaftei) void efx_fini_channels(struct efx_nic *efx) 56583975485SAlex Maftei (amaftei) { 56683975485SAlex Maftei (amaftei) unsigned int i; 56783975485SAlex Maftei (amaftei) 56883975485SAlex Maftei (amaftei) for (i = 0; i < EFX_MAX_CHANNELS; i++) 56983975485SAlex Maftei (amaftei) if (efx->channel[i]) { 57083975485SAlex Maftei (amaftei) kfree(efx->channel[i]); 57183975485SAlex Maftei (amaftei) efx->channel[i] = NULL; 57283975485SAlex Maftei (amaftei) } 57383975485SAlex Maftei (amaftei) } 57483975485SAlex Maftei (amaftei) 57583975485SAlex Maftei (amaftei) /* Allocate and initialise a channel structure, copying parameters 57683975485SAlex Maftei (amaftei) * (but not resources) from an old channel structure. 57783975485SAlex Maftei (amaftei) */ 57883975485SAlex Maftei (amaftei) struct efx_channel *efx_copy_channel(const struct efx_channel *old_channel) 57983975485SAlex Maftei (amaftei) { 58083975485SAlex Maftei (amaftei) struct efx_rx_queue *rx_queue; 58183975485SAlex Maftei (amaftei) struct efx_tx_queue *tx_queue; 58283975485SAlex Maftei (amaftei) struct efx_channel *channel; 58383975485SAlex Maftei (amaftei) int j; 58483975485SAlex Maftei (amaftei) 58583975485SAlex Maftei (amaftei) channel = kmalloc(sizeof(*channel), GFP_KERNEL); 58683975485SAlex Maftei (amaftei) if (!channel) 58783975485SAlex Maftei (amaftei) return NULL; 58883975485SAlex Maftei (amaftei) 58983975485SAlex Maftei (amaftei) *channel = *old_channel; 59083975485SAlex Maftei (amaftei) 59183975485SAlex Maftei (amaftei) channel->napi_dev = NULL; 59283975485SAlex Maftei (amaftei) INIT_HLIST_NODE(&channel->napi_str.napi_hash_node); 59383975485SAlex Maftei (amaftei) channel->napi_str.napi_id = 0; 59483975485SAlex Maftei (amaftei) channel->napi_str.state = 0; 59583975485SAlex Maftei (amaftei) memset(&channel->eventq, 0, sizeof(channel->eventq)); 59683975485SAlex Maftei (amaftei) 59783975485SAlex Maftei (amaftei) for (j = 0; j < EFX_TXQ_TYPES; j++) { 59883975485SAlex Maftei (amaftei) tx_queue = &channel->tx_queue[j]; 59983975485SAlex Maftei (amaftei) if (tx_queue->channel) 60083975485SAlex Maftei (amaftei) tx_queue->channel = channel; 60183975485SAlex Maftei (amaftei) tx_queue->buffer = NULL; 6024b1bd9dbSEdward Cree tx_queue->cb_page = NULL; 60383975485SAlex Maftei (amaftei) memset(&tx_queue->txd, 0, sizeof(tx_queue->txd)); 60483975485SAlex Maftei (amaftei) } 60583975485SAlex Maftei (amaftei) 60683975485SAlex Maftei (amaftei) rx_queue = &channel->rx_queue; 60783975485SAlex Maftei (amaftei) rx_queue->buffer = NULL; 60883975485SAlex Maftei (amaftei) memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd)); 60983975485SAlex Maftei (amaftei) timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0); 61083975485SAlex Maftei (amaftei) #ifdef CONFIG_RFS_ACCEL 61183975485SAlex Maftei (amaftei) INIT_DELAYED_WORK(&channel->filter_work, efx_filter_rfs_expire); 61283975485SAlex Maftei (amaftei) #endif 61383975485SAlex Maftei (amaftei) 61483975485SAlex Maftei (amaftei) return channel; 61583975485SAlex Maftei (amaftei) } 61683975485SAlex Maftei (amaftei) 61783975485SAlex Maftei (amaftei) static int efx_probe_channel(struct efx_channel *channel) 61883975485SAlex Maftei (amaftei) { 61983975485SAlex Maftei (amaftei) struct efx_tx_queue *tx_queue; 62083975485SAlex Maftei (amaftei) struct efx_rx_queue *rx_queue; 62183975485SAlex Maftei (amaftei) int rc; 62283975485SAlex Maftei (amaftei) 62383975485SAlex Maftei (amaftei) netif_dbg(channel->efx, probe, channel->efx->net_dev, 62483975485SAlex Maftei (amaftei) "creating channel %d\n", channel->channel); 62583975485SAlex Maftei (amaftei) 62683975485SAlex Maftei (amaftei) rc = channel->type->pre_probe(channel); 62783975485SAlex Maftei (amaftei) if (rc) 62883975485SAlex Maftei (amaftei) goto fail; 62983975485SAlex Maftei (amaftei) 63083975485SAlex Maftei (amaftei) rc = efx_probe_eventq(channel); 63183975485SAlex Maftei (amaftei) if (rc) 63283975485SAlex Maftei (amaftei) goto fail; 63383975485SAlex Maftei (amaftei) 63483975485SAlex Maftei (amaftei) efx_for_each_channel_tx_queue(tx_queue, channel) { 63583975485SAlex Maftei (amaftei) rc = efx_probe_tx_queue(tx_queue); 63683975485SAlex Maftei (amaftei) if (rc) 63783975485SAlex Maftei (amaftei) goto fail; 63883975485SAlex Maftei (amaftei) } 63983975485SAlex Maftei (amaftei) 64083975485SAlex Maftei (amaftei) efx_for_each_channel_rx_queue(rx_queue, channel) { 64183975485SAlex Maftei (amaftei) rc = efx_probe_rx_queue(rx_queue); 64283975485SAlex Maftei (amaftei) if (rc) 64383975485SAlex Maftei (amaftei) goto fail; 64483975485SAlex Maftei (amaftei) } 64583975485SAlex Maftei (amaftei) 64683975485SAlex Maftei (amaftei) channel->rx_list = NULL; 64783975485SAlex Maftei (amaftei) 64883975485SAlex Maftei (amaftei) return 0; 64983975485SAlex Maftei (amaftei) 65083975485SAlex Maftei (amaftei) fail: 65183975485SAlex Maftei (amaftei) efx_remove_channel(channel); 65283975485SAlex Maftei (amaftei) return rc; 65383975485SAlex Maftei (amaftei) } 65483975485SAlex Maftei (amaftei) 65583975485SAlex Maftei (amaftei) void efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len) 65683975485SAlex Maftei (amaftei) { 65783975485SAlex Maftei (amaftei) struct efx_nic *efx = channel->efx; 65883975485SAlex Maftei (amaftei) const char *type; 65983975485SAlex Maftei (amaftei) int number; 66083975485SAlex Maftei (amaftei) 66183975485SAlex Maftei (amaftei) number = channel->channel; 66283975485SAlex Maftei (amaftei) 66383975485SAlex Maftei (amaftei) if (number >= efx->xdp_channel_offset && 66483975485SAlex Maftei (amaftei) !WARN_ON_ONCE(!efx->n_xdp_channels)) { 66583975485SAlex Maftei (amaftei) type = "-xdp"; 66683975485SAlex Maftei (amaftei) number -= efx->xdp_channel_offset; 66783975485SAlex Maftei (amaftei) } else if (efx->tx_channel_offset == 0) { 66883975485SAlex Maftei (amaftei) type = ""; 66983975485SAlex Maftei (amaftei) } else if (number < efx->tx_channel_offset) { 67083975485SAlex Maftei (amaftei) type = "-rx"; 67183975485SAlex Maftei (amaftei) } else { 67283975485SAlex Maftei (amaftei) type = "-tx"; 67383975485SAlex Maftei (amaftei) number -= efx->tx_channel_offset; 67483975485SAlex Maftei (amaftei) } 67583975485SAlex Maftei (amaftei) snprintf(buf, len, "%s%s-%d", efx->name, type, number); 67683975485SAlex Maftei (amaftei) } 67783975485SAlex Maftei (amaftei) 67883975485SAlex Maftei (amaftei) void efx_set_channel_names(struct efx_nic *efx) 67983975485SAlex Maftei (amaftei) { 68083975485SAlex Maftei (amaftei) struct efx_channel *channel; 68183975485SAlex Maftei (amaftei) 68283975485SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) 68383975485SAlex Maftei (amaftei) channel->type->get_name(channel, 68483975485SAlex Maftei (amaftei) efx->msi_context[channel->channel].name, 68583975485SAlex Maftei (amaftei) sizeof(efx->msi_context[0].name)); 68683975485SAlex Maftei (amaftei) } 68783975485SAlex Maftei (amaftei) 68883975485SAlex Maftei (amaftei) int efx_probe_channels(struct efx_nic *efx) 68983975485SAlex Maftei (amaftei) { 69083975485SAlex Maftei (amaftei) struct efx_channel *channel; 69183975485SAlex Maftei (amaftei) int rc; 69283975485SAlex Maftei (amaftei) 69383975485SAlex Maftei (amaftei) /* Restart special buffer allocation */ 69483975485SAlex Maftei (amaftei) efx->next_buffer_table = 0; 69583975485SAlex Maftei (amaftei) 69683975485SAlex Maftei (amaftei) /* Probe channels in reverse, so that any 'extra' channels 69783975485SAlex Maftei (amaftei) * use the start of the buffer table. This allows the traffic 69883975485SAlex Maftei (amaftei) * channels to be resized without moving them or wasting the 69983975485SAlex Maftei (amaftei) * entries before them. 70083975485SAlex Maftei (amaftei) */ 70183975485SAlex Maftei (amaftei) efx_for_each_channel_rev(channel, efx) { 70283975485SAlex Maftei (amaftei) rc = efx_probe_channel(channel); 70383975485SAlex Maftei (amaftei) if (rc) { 70483975485SAlex Maftei (amaftei) netif_err(efx, probe, efx->net_dev, 70583975485SAlex Maftei (amaftei) "failed to create channel %d\n", 70683975485SAlex Maftei (amaftei) channel->channel); 70783975485SAlex Maftei (amaftei) goto fail; 70883975485SAlex Maftei (amaftei) } 70983975485SAlex Maftei (amaftei) } 71083975485SAlex Maftei (amaftei) efx_set_channel_names(efx); 71183975485SAlex Maftei (amaftei) 71283975485SAlex Maftei (amaftei) return 0; 71383975485SAlex Maftei (amaftei) 71483975485SAlex Maftei (amaftei) fail: 71583975485SAlex Maftei (amaftei) efx_remove_channels(efx); 71683975485SAlex Maftei (amaftei) return rc; 71783975485SAlex Maftei (amaftei) } 71883975485SAlex Maftei (amaftei) 71983975485SAlex Maftei (amaftei) void efx_remove_channel(struct efx_channel *channel) 72083975485SAlex Maftei (amaftei) { 72183975485SAlex Maftei (amaftei) struct efx_tx_queue *tx_queue; 72283975485SAlex Maftei (amaftei) struct efx_rx_queue *rx_queue; 72383975485SAlex Maftei (amaftei) 72483975485SAlex Maftei (amaftei) netif_dbg(channel->efx, drv, channel->efx->net_dev, 72583975485SAlex Maftei (amaftei) "destroy chan %d\n", channel->channel); 72683975485SAlex Maftei (amaftei) 72783975485SAlex Maftei (amaftei) efx_for_each_channel_rx_queue(rx_queue, channel) 72883975485SAlex Maftei (amaftei) efx_remove_rx_queue(rx_queue); 729f9cac93eSEdward Cree efx_for_each_channel_tx_queue(tx_queue, channel) 73083975485SAlex Maftei (amaftei) efx_remove_tx_queue(tx_queue); 73183975485SAlex Maftei (amaftei) efx_remove_eventq(channel); 73283975485SAlex Maftei (amaftei) channel->type->post_remove(channel); 73383975485SAlex Maftei (amaftei) } 73483975485SAlex Maftei (amaftei) 73583975485SAlex Maftei (amaftei) void efx_remove_channels(struct efx_nic *efx) 73683975485SAlex Maftei (amaftei) { 73783975485SAlex Maftei (amaftei) struct efx_channel *channel; 73883975485SAlex Maftei (amaftei) 73983975485SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) 74083975485SAlex Maftei (amaftei) efx_remove_channel(channel); 74183975485SAlex Maftei (amaftei) 74283975485SAlex Maftei (amaftei) kfree(efx->xdp_tx_queues); 74383975485SAlex Maftei (amaftei) } 74483975485SAlex Maftei (amaftei) 74583975485SAlex Maftei (amaftei) int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries) 74683975485SAlex Maftei (amaftei) { 74783975485SAlex Maftei (amaftei) struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel; 74883975485SAlex Maftei (amaftei) unsigned int i, next_buffer_table = 0; 74983975485SAlex Maftei (amaftei) u32 old_rxq_entries, old_txq_entries; 75083975485SAlex Maftei (amaftei) int rc, rc2; 75183975485SAlex Maftei (amaftei) 75283975485SAlex Maftei (amaftei) rc = efx_check_disabled(efx); 75383975485SAlex Maftei (amaftei) if (rc) 75483975485SAlex Maftei (amaftei) return rc; 75583975485SAlex Maftei (amaftei) 75683975485SAlex Maftei (amaftei) /* Not all channels should be reallocated. We must avoid 75783975485SAlex Maftei (amaftei) * reallocating their buffer table entries. 75883975485SAlex Maftei (amaftei) */ 75983975485SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 76083975485SAlex Maftei (amaftei) struct efx_rx_queue *rx_queue; 76183975485SAlex Maftei (amaftei) struct efx_tx_queue *tx_queue; 76283975485SAlex Maftei (amaftei) 76383975485SAlex Maftei (amaftei) if (channel->type->copy) 76483975485SAlex Maftei (amaftei) continue; 76583975485SAlex Maftei (amaftei) next_buffer_table = max(next_buffer_table, 76683975485SAlex Maftei (amaftei) channel->eventq.index + 76783975485SAlex Maftei (amaftei) channel->eventq.entries); 76883975485SAlex Maftei (amaftei) efx_for_each_channel_rx_queue(rx_queue, channel) 76983975485SAlex Maftei (amaftei) next_buffer_table = max(next_buffer_table, 77083975485SAlex Maftei (amaftei) rx_queue->rxd.index + 77183975485SAlex Maftei (amaftei) rx_queue->rxd.entries); 77283975485SAlex Maftei (amaftei) efx_for_each_channel_tx_queue(tx_queue, channel) 77383975485SAlex Maftei (amaftei) next_buffer_table = max(next_buffer_table, 77483975485SAlex Maftei (amaftei) tx_queue->txd.index + 77583975485SAlex Maftei (amaftei) tx_queue->txd.entries); 77683975485SAlex Maftei (amaftei) } 77783975485SAlex Maftei (amaftei) 77883975485SAlex Maftei (amaftei) efx_device_detach_sync(efx); 77983975485SAlex Maftei (amaftei) efx_stop_all(efx); 78083975485SAlex Maftei (amaftei) efx_soft_disable_interrupts(efx); 78183975485SAlex Maftei (amaftei) 78283975485SAlex Maftei (amaftei) /* Clone channels (where possible) */ 78383975485SAlex Maftei (amaftei) memset(other_channel, 0, sizeof(other_channel)); 78483975485SAlex Maftei (amaftei) for (i = 0; i < efx->n_channels; i++) { 78583975485SAlex Maftei (amaftei) channel = efx->channel[i]; 78683975485SAlex Maftei (amaftei) if (channel->type->copy) 78783975485SAlex Maftei (amaftei) channel = channel->type->copy(channel); 78883975485SAlex Maftei (amaftei) if (!channel) { 78983975485SAlex Maftei (amaftei) rc = -ENOMEM; 79083975485SAlex Maftei (amaftei) goto out; 79183975485SAlex Maftei (amaftei) } 79283975485SAlex Maftei (amaftei) other_channel[i] = channel; 79383975485SAlex Maftei (amaftei) } 79483975485SAlex Maftei (amaftei) 79583975485SAlex Maftei (amaftei) /* Swap entry counts and channel pointers */ 79683975485SAlex Maftei (amaftei) old_rxq_entries = efx->rxq_entries; 79783975485SAlex Maftei (amaftei) old_txq_entries = efx->txq_entries; 79883975485SAlex Maftei (amaftei) efx->rxq_entries = rxq_entries; 79983975485SAlex Maftei (amaftei) efx->txq_entries = txq_entries; 80083975485SAlex Maftei (amaftei) for (i = 0; i < efx->n_channels; i++) { 80183975485SAlex Maftei (amaftei) channel = efx->channel[i]; 80283975485SAlex Maftei (amaftei) efx->channel[i] = other_channel[i]; 80383975485SAlex Maftei (amaftei) other_channel[i] = channel; 80483975485SAlex Maftei (amaftei) } 80583975485SAlex Maftei (amaftei) 80683975485SAlex Maftei (amaftei) /* Restart buffer table allocation */ 80783975485SAlex Maftei (amaftei) efx->next_buffer_table = next_buffer_table; 80883975485SAlex Maftei (amaftei) 80983975485SAlex Maftei (amaftei) for (i = 0; i < efx->n_channels; i++) { 81083975485SAlex Maftei (amaftei) channel = efx->channel[i]; 81183975485SAlex Maftei (amaftei) if (!channel->type->copy) 81283975485SAlex Maftei (amaftei) continue; 81383975485SAlex Maftei (amaftei) rc = efx_probe_channel(channel); 81483975485SAlex Maftei (amaftei) if (rc) 81583975485SAlex Maftei (amaftei) goto rollback; 81683975485SAlex Maftei (amaftei) efx_init_napi_channel(efx->channel[i]); 81783975485SAlex Maftei (amaftei) } 81883975485SAlex Maftei (amaftei) 81983975485SAlex Maftei (amaftei) out: 82083975485SAlex Maftei (amaftei) /* Destroy unused channel structures */ 82183975485SAlex Maftei (amaftei) for (i = 0; i < efx->n_channels; i++) { 82283975485SAlex Maftei (amaftei) channel = other_channel[i]; 82383975485SAlex Maftei (amaftei) if (channel && channel->type->copy) { 82483975485SAlex Maftei (amaftei) efx_fini_napi_channel(channel); 82583975485SAlex Maftei (amaftei) efx_remove_channel(channel); 82683975485SAlex Maftei (amaftei) kfree(channel); 82783975485SAlex Maftei (amaftei) } 82883975485SAlex Maftei (amaftei) } 82983975485SAlex Maftei (amaftei) 83083975485SAlex Maftei (amaftei) rc2 = efx_soft_enable_interrupts(efx); 83183975485SAlex Maftei (amaftei) if (rc2) { 83283975485SAlex Maftei (amaftei) rc = rc ? rc : rc2; 83383975485SAlex Maftei (amaftei) netif_err(efx, drv, efx->net_dev, 83483975485SAlex Maftei (amaftei) "unable to restart interrupts on channel reallocation\n"); 83583975485SAlex Maftei (amaftei) efx_schedule_reset(efx, RESET_TYPE_DISABLE); 83683975485SAlex Maftei (amaftei) } else { 83783975485SAlex Maftei (amaftei) efx_start_all(efx); 83883975485SAlex Maftei (amaftei) efx_device_attach_if_not_resetting(efx); 83983975485SAlex Maftei (amaftei) } 84083975485SAlex Maftei (amaftei) return rc; 84183975485SAlex Maftei (amaftei) 84283975485SAlex Maftei (amaftei) rollback: 84383975485SAlex Maftei (amaftei) /* Swap back */ 84483975485SAlex Maftei (amaftei) efx->rxq_entries = old_rxq_entries; 84583975485SAlex Maftei (amaftei) efx->txq_entries = old_txq_entries; 84683975485SAlex Maftei (amaftei) for (i = 0; i < efx->n_channels; i++) { 84783975485SAlex Maftei (amaftei) channel = efx->channel[i]; 84883975485SAlex Maftei (amaftei) efx->channel[i] = other_channel[i]; 84983975485SAlex Maftei (amaftei) other_channel[i] = channel; 85083975485SAlex Maftei (amaftei) } 85183975485SAlex Maftei (amaftei) goto out; 85283975485SAlex Maftei (amaftei) } 85383975485SAlex Maftei (amaftei) 85483975485SAlex Maftei (amaftei) int efx_set_channels(struct efx_nic *efx) 85583975485SAlex Maftei (amaftei) { 85683975485SAlex Maftei (amaftei) struct efx_tx_queue *tx_queue; 857a81dcd85SEdward Cree struct efx_channel *channel; 858a81dcd85SEdward Cree unsigned int next_queue = 0; 85983975485SAlex Maftei (amaftei) int xdp_queue_number; 86069a70496SEdward Cree int rc; 86183975485SAlex Maftei (amaftei) 86283975485SAlex Maftei (amaftei) efx->tx_channel_offset = 86383975485SAlex Maftei (amaftei) efx_separate_tx_channels ? 86483975485SAlex Maftei (amaftei) efx->n_channels - efx->n_tx_channels : 0; 86583975485SAlex Maftei (amaftei) 86683975485SAlex Maftei (amaftei) if (efx->xdp_tx_queue_count) { 86783975485SAlex Maftei (amaftei) EFX_WARN_ON_PARANOID(efx->xdp_tx_queues); 86883975485SAlex Maftei (amaftei) 86983975485SAlex Maftei (amaftei) /* Allocate array for XDP TX queue lookup. */ 87083975485SAlex Maftei (amaftei) efx->xdp_tx_queues = kcalloc(efx->xdp_tx_queue_count, 87183975485SAlex Maftei (amaftei) sizeof(*efx->xdp_tx_queues), 87283975485SAlex Maftei (amaftei) GFP_KERNEL); 87383975485SAlex Maftei (amaftei) if (!efx->xdp_tx_queues) 87483975485SAlex Maftei (amaftei) return -ENOMEM; 87583975485SAlex Maftei (amaftei) } 87683975485SAlex Maftei (amaftei) 87783975485SAlex Maftei (amaftei) /* We need to mark which channels really have RX and TX 87883975485SAlex Maftei (amaftei) * queues, and adjust the TX queue numbers if we have separate 87983975485SAlex Maftei (amaftei) * RX-only and TX-only channels. 88083975485SAlex Maftei (amaftei) */ 88183975485SAlex Maftei (amaftei) xdp_queue_number = 0; 88283975485SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 88383975485SAlex Maftei (amaftei) if (channel->channel < efx->n_rx_channels) 88483975485SAlex Maftei (amaftei) channel->rx_queue.core_index = channel->channel; 88583975485SAlex Maftei (amaftei) else 88683975485SAlex Maftei (amaftei) channel->rx_queue.core_index = -1; 88783975485SAlex Maftei (amaftei) 888a81dcd85SEdward Cree if (channel->channel >= efx->tx_channel_offset) { 889a81dcd85SEdward Cree if (efx_channel_is_xdp_tx(channel)) { 89083975485SAlex Maftei (amaftei) efx_for_each_channel_tx_queue(tx_queue, channel) { 891a81dcd85SEdward Cree tx_queue->queue = next_queue++; 892a81dcd85SEdward Cree netif_dbg(efx, drv, efx->net_dev, "Channel %u TXQ %u is XDP %u, HW %u\n", 893a81dcd85SEdward Cree channel->channel, tx_queue->label, 894a81dcd85SEdward Cree xdp_queue_number, tx_queue->queue); 895a81dcd85SEdward Cree /* We may have a few left-over XDP TX 896a81dcd85SEdward Cree * queues owing to xdp_tx_queue_count 897a81dcd85SEdward Cree * not dividing evenly by EFX_TXQ_TYPES. 898a81dcd85SEdward Cree * We still allocate and probe those 899a81dcd85SEdward Cree * TXQs, but never use them. 900a81dcd85SEdward Cree */ 901a81dcd85SEdward Cree if (xdp_queue_number < efx->xdp_tx_queue_count) 90283975485SAlex Maftei (amaftei) efx->xdp_tx_queues[xdp_queue_number] = tx_queue; 90383975485SAlex Maftei (amaftei) xdp_queue_number++; 90483975485SAlex Maftei (amaftei) } 905a81dcd85SEdward Cree } else { 906a81dcd85SEdward Cree efx_for_each_channel_tx_queue(tx_queue, channel) { 907a81dcd85SEdward Cree tx_queue->queue = next_queue++; 908a81dcd85SEdward Cree netif_dbg(efx, drv, efx->net_dev, "Channel %u TXQ %u is HW %u\n", 909a81dcd85SEdward Cree channel->channel, tx_queue->label, 910a81dcd85SEdward Cree tx_queue->queue); 911a81dcd85SEdward Cree } 912a81dcd85SEdward Cree } 91383975485SAlex Maftei (amaftei) } 91483975485SAlex Maftei (amaftei) } 91569a70496SEdward Cree 91669a70496SEdward Cree rc = netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels); 91769a70496SEdward Cree if (rc) 91869a70496SEdward Cree return rc; 91969a70496SEdward Cree return netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels); 92083975485SAlex Maftei (amaftei) } 92183975485SAlex Maftei (amaftei) 92283975485SAlex Maftei (amaftei) bool efx_default_channel_want_txqs(struct efx_channel *channel) 92383975485SAlex Maftei (amaftei) { 92483975485SAlex Maftei (amaftei) return channel->channel - channel->efx->tx_channel_offset < 92583975485SAlex Maftei (amaftei) channel->efx->n_tx_channels; 92683975485SAlex Maftei (amaftei) } 92783975485SAlex Maftei (amaftei) 928e20ba5b1SAlex Maftei (amaftei) /************* 929e20ba5b1SAlex Maftei (amaftei) * START/STOP 930e20ba5b1SAlex Maftei (amaftei) *************/ 931e20ba5b1SAlex Maftei (amaftei) 932e20ba5b1SAlex Maftei (amaftei) int efx_soft_enable_interrupts(struct efx_nic *efx) 933e20ba5b1SAlex Maftei (amaftei) { 934e20ba5b1SAlex Maftei (amaftei) struct efx_channel *channel, *end_channel; 935e20ba5b1SAlex Maftei (amaftei) int rc; 936e20ba5b1SAlex Maftei (amaftei) 937e20ba5b1SAlex Maftei (amaftei) BUG_ON(efx->state == STATE_DISABLED); 938e20ba5b1SAlex Maftei (amaftei) 939e20ba5b1SAlex Maftei (amaftei) efx->irq_soft_enabled = true; 940e20ba5b1SAlex Maftei (amaftei) smp_wmb(); 941e20ba5b1SAlex Maftei (amaftei) 942e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 943e20ba5b1SAlex Maftei (amaftei) if (!channel->type->keep_eventq) { 944e20ba5b1SAlex Maftei (amaftei) rc = efx_init_eventq(channel); 945e20ba5b1SAlex Maftei (amaftei) if (rc) 946e20ba5b1SAlex Maftei (amaftei) goto fail; 947e20ba5b1SAlex Maftei (amaftei) } 948e20ba5b1SAlex Maftei (amaftei) efx_start_eventq(channel); 949e20ba5b1SAlex Maftei (amaftei) } 950e20ba5b1SAlex Maftei (amaftei) 951e20ba5b1SAlex Maftei (amaftei) efx_mcdi_mode_event(efx); 952e20ba5b1SAlex Maftei (amaftei) 953e20ba5b1SAlex Maftei (amaftei) return 0; 954e20ba5b1SAlex Maftei (amaftei) fail: 955e20ba5b1SAlex Maftei (amaftei) end_channel = channel; 956e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 957e20ba5b1SAlex Maftei (amaftei) if (channel == end_channel) 958e20ba5b1SAlex Maftei (amaftei) break; 959e20ba5b1SAlex Maftei (amaftei) efx_stop_eventq(channel); 960e20ba5b1SAlex Maftei (amaftei) if (!channel->type->keep_eventq) 961e20ba5b1SAlex Maftei (amaftei) efx_fini_eventq(channel); 962e20ba5b1SAlex Maftei (amaftei) } 963e20ba5b1SAlex Maftei (amaftei) 964e20ba5b1SAlex Maftei (amaftei) return rc; 965e20ba5b1SAlex Maftei (amaftei) } 966e20ba5b1SAlex Maftei (amaftei) 967e20ba5b1SAlex Maftei (amaftei) void efx_soft_disable_interrupts(struct efx_nic *efx) 968e20ba5b1SAlex Maftei (amaftei) { 969e20ba5b1SAlex Maftei (amaftei) struct efx_channel *channel; 970e20ba5b1SAlex Maftei (amaftei) 971e20ba5b1SAlex Maftei (amaftei) if (efx->state == STATE_DISABLED) 972e20ba5b1SAlex Maftei (amaftei) return; 973e20ba5b1SAlex Maftei (amaftei) 974e20ba5b1SAlex Maftei (amaftei) efx_mcdi_mode_poll(efx); 975e20ba5b1SAlex Maftei (amaftei) 976e20ba5b1SAlex Maftei (amaftei) efx->irq_soft_enabled = false; 977e20ba5b1SAlex Maftei (amaftei) smp_wmb(); 978e20ba5b1SAlex Maftei (amaftei) 979e20ba5b1SAlex Maftei (amaftei) if (efx->legacy_irq) 980e20ba5b1SAlex Maftei (amaftei) synchronize_irq(efx->legacy_irq); 981e20ba5b1SAlex Maftei (amaftei) 982e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 983e20ba5b1SAlex Maftei (amaftei) if (channel->irq) 984e20ba5b1SAlex Maftei (amaftei) synchronize_irq(channel->irq); 985e20ba5b1SAlex Maftei (amaftei) 986e20ba5b1SAlex Maftei (amaftei) efx_stop_eventq(channel); 987e20ba5b1SAlex Maftei (amaftei) if (!channel->type->keep_eventq) 988e20ba5b1SAlex Maftei (amaftei) efx_fini_eventq(channel); 989e20ba5b1SAlex Maftei (amaftei) } 990e20ba5b1SAlex Maftei (amaftei) 991e20ba5b1SAlex Maftei (amaftei) /* Flush the asynchronous MCDI request queue */ 992e20ba5b1SAlex Maftei (amaftei) efx_mcdi_flush_async(efx); 993e20ba5b1SAlex Maftei (amaftei) } 994e20ba5b1SAlex Maftei (amaftei) 995e20ba5b1SAlex Maftei (amaftei) int efx_enable_interrupts(struct efx_nic *efx) 996e20ba5b1SAlex Maftei (amaftei) { 997e20ba5b1SAlex Maftei (amaftei) struct efx_channel *channel, *end_channel; 998e20ba5b1SAlex Maftei (amaftei) int rc; 999e20ba5b1SAlex Maftei (amaftei) 1000e20ba5b1SAlex Maftei (amaftei) /* TODO: Is this really a bug? */ 1001e20ba5b1SAlex Maftei (amaftei) BUG_ON(efx->state == STATE_DISABLED); 1002e20ba5b1SAlex Maftei (amaftei) 1003e20ba5b1SAlex Maftei (amaftei) if (efx->eeh_disabled_legacy_irq) { 1004e20ba5b1SAlex Maftei (amaftei) enable_irq(efx->legacy_irq); 1005e20ba5b1SAlex Maftei (amaftei) efx->eeh_disabled_legacy_irq = false; 1006e20ba5b1SAlex Maftei (amaftei) } 1007e20ba5b1SAlex Maftei (amaftei) 1008e20ba5b1SAlex Maftei (amaftei) efx->type->irq_enable_master(efx); 1009e20ba5b1SAlex Maftei (amaftei) 1010e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 1011e20ba5b1SAlex Maftei (amaftei) if (channel->type->keep_eventq) { 1012e20ba5b1SAlex Maftei (amaftei) rc = efx_init_eventq(channel); 1013e20ba5b1SAlex Maftei (amaftei) if (rc) 1014e20ba5b1SAlex Maftei (amaftei) goto fail; 1015e20ba5b1SAlex Maftei (amaftei) } 1016e20ba5b1SAlex Maftei (amaftei) } 1017e20ba5b1SAlex Maftei (amaftei) 1018e20ba5b1SAlex Maftei (amaftei) rc = efx_soft_enable_interrupts(efx); 1019e20ba5b1SAlex Maftei (amaftei) if (rc) 1020e20ba5b1SAlex Maftei (amaftei) goto fail; 1021e20ba5b1SAlex Maftei (amaftei) 1022e20ba5b1SAlex Maftei (amaftei) return 0; 1023e20ba5b1SAlex Maftei (amaftei) 1024e20ba5b1SAlex Maftei (amaftei) fail: 1025e20ba5b1SAlex Maftei (amaftei) end_channel = channel; 1026e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 1027e20ba5b1SAlex Maftei (amaftei) if (channel == end_channel) 1028e20ba5b1SAlex Maftei (amaftei) break; 1029e20ba5b1SAlex Maftei (amaftei) if (channel->type->keep_eventq) 1030e20ba5b1SAlex Maftei (amaftei) efx_fini_eventq(channel); 1031e20ba5b1SAlex Maftei (amaftei) } 1032e20ba5b1SAlex Maftei (amaftei) 1033e20ba5b1SAlex Maftei (amaftei) efx->type->irq_disable_non_ev(efx); 1034e20ba5b1SAlex Maftei (amaftei) 1035e20ba5b1SAlex Maftei (amaftei) return rc; 1036e20ba5b1SAlex Maftei (amaftei) } 1037e20ba5b1SAlex Maftei (amaftei) 1038e20ba5b1SAlex Maftei (amaftei) void efx_disable_interrupts(struct efx_nic *efx) 1039e20ba5b1SAlex Maftei (amaftei) { 1040e20ba5b1SAlex Maftei (amaftei) struct efx_channel *channel; 1041e20ba5b1SAlex Maftei (amaftei) 1042e20ba5b1SAlex Maftei (amaftei) efx_soft_disable_interrupts(efx); 1043e20ba5b1SAlex Maftei (amaftei) 1044e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 1045e20ba5b1SAlex Maftei (amaftei) if (channel->type->keep_eventq) 1046e20ba5b1SAlex Maftei (amaftei) efx_fini_eventq(channel); 1047e20ba5b1SAlex Maftei (amaftei) } 1048e20ba5b1SAlex Maftei (amaftei) 1049e20ba5b1SAlex Maftei (amaftei) efx->type->irq_disable_non_ev(efx); 1050e20ba5b1SAlex Maftei (amaftei) } 1051e20ba5b1SAlex Maftei (amaftei) 1052e20ba5b1SAlex Maftei (amaftei) void efx_start_channels(struct efx_nic *efx) 1053e20ba5b1SAlex Maftei (amaftei) { 1054e20ba5b1SAlex Maftei (amaftei) struct efx_tx_queue *tx_queue; 1055e20ba5b1SAlex Maftei (amaftei) struct efx_rx_queue *rx_queue; 1056e20ba5b1SAlex Maftei (amaftei) struct efx_channel *channel; 1057e20ba5b1SAlex Maftei (amaftei) 1058e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 1059e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel_tx_queue(tx_queue, channel) { 1060e20ba5b1SAlex Maftei (amaftei) efx_init_tx_queue(tx_queue); 1061e20ba5b1SAlex Maftei (amaftei) atomic_inc(&efx->active_queues); 1062e20ba5b1SAlex Maftei (amaftei) } 1063e20ba5b1SAlex Maftei (amaftei) 1064e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel_rx_queue(rx_queue, channel) { 1065e20ba5b1SAlex Maftei (amaftei) efx_init_rx_queue(rx_queue); 1066e20ba5b1SAlex Maftei (amaftei) atomic_inc(&efx->active_queues); 1067e20ba5b1SAlex Maftei (amaftei) efx_stop_eventq(channel); 1068e20ba5b1SAlex Maftei (amaftei) efx_fast_push_rx_descriptors(rx_queue, false); 1069e20ba5b1SAlex Maftei (amaftei) efx_start_eventq(channel); 1070e20ba5b1SAlex Maftei (amaftei) } 1071e20ba5b1SAlex Maftei (amaftei) 1072e20ba5b1SAlex Maftei (amaftei) WARN_ON(channel->rx_pkt_n_frags); 1073e20ba5b1SAlex Maftei (amaftei) } 1074e20ba5b1SAlex Maftei (amaftei) } 1075e20ba5b1SAlex Maftei (amaftei) 1076e20ba5b1SAlex Maftei (amaftei) void efx_stop_channels(struct efx_nic *efx) 1077e20ba5b1SAlex Maftei (amaftei) { 1078e20ba5b1SAlex Maftei (amaftei) struct efx_tx_queue *tx_queue; 1079e20ba5b1SAlex Maftei (amaftei) struct efx_rx_queue *rx_queue; 1080e20ba5b1SAlex Maftei (amaftei) struct efx_channel *channel; 1081b5775b47SAlex Maftei (amaftei) int rc = 0; 1082e20ba5b1SAlex Maftei (amaftei) 1083e20ba5b1SAlex Maftei (amaftei) /* Stop RX refill */ 1084e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 1085e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel_rx_queue(rx_queue, channel) 1086e20ba5b1SAlex Maftei (amaftei) rx_queue->refill_enabled = false; 1087e20ba5b1SAlex Maftei (amaftei) } 1088e20ba5b1SAlex Maftei (amaftei) 1089e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 1090e20ba5b1SAlex Maftei (amaftei) /* RX packet processing is pipelined, so wait for the 1091e20ba5b1SAlex Maftei (amaftei) * NAPI handler to complete. At least event queue 0 1092e20ba5b1SAlex Maftei (amaftei) * might be kept active by non-data events, so don't 1093e20ba5b1SAlex Maftei (amaftei) * use napi_synchronize() but actually disable NAPI 1094e20ba5b1SAlex Maftei (amaftei) * temporarily. 1095e20ba5b1SAlex Maftei (amaftei) */ 1096e20ba5b1SAlex Maftei (amaftei) if (efx_channel_has_rx_queue(channel)) { 1097e20ba5b1SAlex Maftei (amaftei) efx_stop_eventq(channel); 1098e20ba5b1SAlex Maftei (amaftei) efx_start_eventq(channel); 1099e20ba5b1SAlex Maftei (amaftei) } 1100e20ba5b1SAlex Maftei (amaftei) } 1101e20ba5b1SAlex Maftei (amaftei) 1102b5775b47SAlex Maftei (amaftei) if (efx->type->fini_dmaq) 1103e20ba5b1SAlex Maftei (amaftei) rc = efx->type->fini_dmaq(efx); 1104b5775b47SAlex Maftei (amaftei) 1105e20ba5b1SAlex Maftei (amaftei) if (rc) { 1106e20ba5b1SAlex Maftei (amaftei) netif_err(efx, drv, efx->net_dev, "failed to flush queues\n"); 1107e20ba5b1SAlex Maftei (amaftei) } else { 1108e20ba5b1SAlex Maftei (amaftei) netif_dbg(efx, drv, efx->net_dev, 1109e20ba5b1SAlex Maftei (amaftei) "successfully flushed all queues\n"); 1110e20ba5b1SAlex Maftei (amaftei) } 1111e20ba5b1SAlex Maftei (amaftei) 1112e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) { 1113e20ba5b1SAlex Maftei (amaftei) efx_for_each_channel_rx_queue(rx_queue, channel) 1114e20ba5b1SAlex Maftei (amaftei) efx_fini_rx_queue(rx_queue); 1115f9cac93eSEdward Cree efx_for_each_channel_tx_queue(tx_queue, channel) 1116e20ba5b1SAlex Maftei (amaftei) efx_fini_tx_queue(tx_queue); 1117e20ba5b1SAlex Maftei (amaftei) } 1118e20ba5b1SAlex Maftei (amaftei) } 1119e20ba5b1SAlex Maftei (amaftei) 1120768fd266SAlex Maftei (amaftei) /************************************************************************** 1121768fd266SAlex Maftei (amaftei) * 1122768fd266SAlex Maftei (amaftei) * NAPI interface 1123768fd266SAlex Maftei (amaftei) * 1124768fd266SAlex Maftei (amaftei) *************************************************************************/ 1125768fd266SAlex Maftei (amaftei) 1126768fd266SAlex Maftei (amaftei) /* Process channel's event queue 1127768fd266SAlex Maftei (amaftei) * 1128768fd266SAlex Maftei (amaftei) * This function is responsible for processing the event queue of a 1129768fd266SAlex Maftei (amaftei) * single channel. The caller must guarantee that this function will 1130768fd266SAlex Maftei (amaftei) * never be concurrently called more than once on the same channel, 1131768fd266SAlex Maftei (amaftei) * though different channels may be being processed concurrently. 1132768fd266SAlex Maftei (amaftei) */ 1133768fd266SAlex Maftei (amaftei) static int efx_process_channel(struct efx_channel *channel, int budget) 1134768fd266SAlex Maftei (amaftei) { 1135768fd266SAlex Maftei (amaftei) struct efx_tx_queue *tx_queue; 1136768fd266SAlex Maftei (amaftei) struct list_head rx_list; 1137768fd266SAlex Maftei (amaftei) int spent; 1138768fd266SAlex Maftei (amaftei) 1139768fd266SAlex Maftei (amaftei) if (unlikely(!channel->enabled)) 1140768fd266SAlex Maftei (amaftei) return 0; 1141768fd266SAlex Maftei (amaftei) 1142768fd266SAlex Maftei (amaftei) /* Prepare the batch receive list */ 1143768fd266SAlex Maftei (amaftei) EFX_WARN_ON_PARANOID(channel->rx_list != NULL); 1144768fd266SAlex Maftei (amaftei) INIT_LIST_HEAD(&rx_list); 1145768fd266SAlex Maftei (amaftei) channel->rx_list = &rx_list; 1146768fd266SAlex Maftei (amaftei) 1147768fd266SAlex Maftei (amaftei) efx_for_each_channel_tx_queue(tx_queue, channel) { 1148768fd266SAlex Maftei (amaftei) tx_queue->pkts_compl = 0; 1149768fd266SAlex Maftei (amaftei) tx_queue->bytes_compl = 0; 1150768fd266SAlex Maftei (amaftei) } 1151768fd266SAlex Maftei (amaftei) 1152768fd266SAlex Maftei (amaftei) spent = efx_nic_process_eventq(channel, budget); 1153768fd266SAlex Maftei (amaftei) if (spent && efx_channel_has_rx_queue(channel)) { 1154768fd266SAlex Maftei (amaftei) struct efx_rx_queue *rx_queue = 1155768fd266SAlex Maftei (amaftei) efx_channel_get_rx_queue(channel); 1156768fd266SAlex Maftei (amaftei) 1157768fd266SAlex Maftei (amaftei) efx_rx_flush_packet(channel); 1158768fd266SAlex Maftei (amaftei) efx_fast_push_rx_descriptors(rx_queue, true); 1159768fd266SAlex Maftei (amaftei) } 1160768fd266SAlex Maftei (amaftei) 1161768fd266SAlex Maftei (amaftei) /* Update BQL */ 1162768fd266SAlex Maftei (amaftei) efx_for_each_channel_tx_queue(tx_queue, channel) { 1163768fd266SAlex Maftei (amaftei) if (tx_queue->bytes_compl) { 1164768fd266SAlex Maftei (amaftei) netdev_tx_completed_queue(tx_queue->core_txq, 1165768fd266SAlex Maftei (amaftei) tx_queue->pkts_compl, 1166768fd266SAlex Maftei (amaftei) tx_queue->bytes_compl); 1167768fd266SAlex Maftei (amaftei) } 1168768fd266SAlex Maftei (amaftei) } 1169768fd266SAlex Maftei (amaftei) 1170768fd266SAlex Maftei (amaftei) /* Receive any packets we queued up */ 1171768fd266SAlex Maftei (amaftei) netif_receive_skb_list(channel->rx_list); 1172768fd266SAlex Maftei (amaftei) channel->rx_list = NULL; 1173768fd266SAlex Maftei (amaftei) 1174768fd266SAlex Maftei (amaftei) return spent; 1175768fd266SAlex Maftei (amaftei) } 1176768fd266SAlex Maftei (amaftei) 1177768fd266SAlex Maftei (amaftei) static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel) 1178768fd266SAlex Maftei (amaftei) { 1179768fd266SAlex Maftei (amaftei) int step = efx->irq_mod_step_us; 1180768fd266SAlex Maftei (amaftei) 1181768fd266SAlex Maftei (amaftei) if (channel->irq_mod_score < irq_adapt_low_thresh) { 1182768fd266SAlex Maftei (amaftei) if (channel->irq_moderation_us > step) { 1183768fd266SAlex Maftei (amaftei) channel->irq_moderation_us -= step; 1184768fd266SAlex Maftei (amaftei) efx->type->push_irq_moderation(channel); 1185768fd266SAlex Maftei (amaftei) } 1186768fd266SAlex Maftei (amaftei) } else if (channel->irq_mod_score > irq_adapt_high_thresh) { 1187768fd266SAlex Maftei (amaftei) if (channel->irq_moderation_us < 1188768fd266SAlex Maftei (amaftei) efx->irq_rx_moderation_us) { 1189768fd266SAlex Maftei (amaftei) channel->irq_moderation_us += step; 1190768fd266SAlex Maftei (amaftei) efx->type->push_irq_moderation(channel); 1191768fd266SAlex Maftei (amaftei) } 1192768fd266SAlex Maftei (amaftei) } 1193768fd266SAlex Maftei (amaftei) 1194768fd266SAlex Maftei (amaftei) channel->irq_count = 0; 1195768fd266SAlex Maftei (amaftei) channel->irq_mod_score = 0; 1196768fd266SAlex Maftei (amaftei) } 1197768fd266SAlex Maftei (amaftei) 1198768fd266SAlex Maftei (amaftei) /* NAPI poll handler 1199768fd266SAlex Maftei (amaftei) * 1200768fd266SAlex Maftei (amaftei) * NAPI guarantees serialisation of polls of the same device, which 1201768fd266SAlex Maftei (amaftei) * provides the guarantee required by efx_process_channel(). 1202768fd266SAlex Maftei (amaftei) */ 1203768fd266SAlex Maftei (amaftei) static int efx_poll(struct napi_struct *napi, int budget) 1204768fd266SAlex Maftei (amaftei) { 1205768fd266SAlex Maftei (amaftei) struct efx_channel *channel = 1206768fd266SAlex Maftei (amaftei) container_of(napi, struct efx_channel, napi_str); 1207768fd266SAlex Maftei (amaftei) struct efx_nic *efx = channel->efx; 1208b7683155SEdward Cree #ifdef CONFIG_RFS_ACCEL 1209b7683155SEdward Cree unsigned int time; 1210b7683155SEdward Cree #endif 1211768fd266SAlex Maftei (amaftei) int spent; 1212768fd266SAlex Maftei (amaftei) 1213768fd266SAlex Maftei (amaftei) netif_vdbg(efx, intr, efx->net_dev, 1214768fd266SAlex Maftei (amaftei) "channel %d NAPI poll executing on CPU %d\n", 1215768fd266SAlex Maftei (amaftei) channel->channel, raw_smp_processor_id()); 1216768fd266SAlex Maftei (amaftei) 1217768fd266SAlex Maftei (amaftei) spent = efx_process_channel(channel, budget); 1218768fd266SAlex Maftei (amaftei) 1219768fd266SAlex Maftei (amaftei) xdp_do_flush_map(); 1220768fd266SAlex Maftei (amaftei) 1221768fd266SAlex Maftei (amaftei) if (spent < budget) { 1222768fd266SAlex Maftei (amaftei) if (efx_channel_has_rx_queue(channel) && 1223768fd266SAlex Maftei (amaftei) efx->irq_rx_adaptive && 1224768fd266SAlex Maftei (amaftei) unlikely(++channel->irq_count == 1000)) { 1225768fd266SAlex Maftei (amaftei) efx_update_irq_mod(efx, channel); 1226768fd266SAlex Maftei (amaftei) } 1227768fd266SAlex Maftei (amaftei) 1228768fd266SAlex Maftei (amaftei) #ifdef CONFIG_RFS_ACCEL 1229768fd266SAlex Maftei (amaftei) /* Perhaps expire some ARFS filters */ 1230b7683155SEdward Cree time = jiffies - channel->rfs_last_expiry; 1231b7683155SEdward Cree /* Would our quota be >= 20? */ 1232b7683155SEdward Cree if (channel->rfs_filter_count * time >= 600 * HZ) 1233768fd266SAlex Maftei (amaftei) mod_delayed_work(system_wq, &channel->filter_work, 0); 1234768fd266SAlex Maftei (amaftei) #endif 1235768fd266SAlex Maftei (amaftei) 1236768fd266SAlex Maftei (amaftei) /* There is no race here; although napi_disable() will 1237768fd266SAlex Maftei (amaftei) * only wait for napi_complete(), this isn't a problem 1238768fd266SAlex Maftei (amaftei) * since efx_nic_eventq_read_ack() will have no effect if 1239768fd266SAlex Maftei (amaftei) * interrupts have already been disabled. 1240768fd266SAlex Maftei (amaftei) */ 1241768fd266SAlex Maftei (amaftei) if (napi_complete_done(napi, spent)) 1242768fd266SAlex Maftei (amaftei) efx_nic_eventq_read_ack(channel); 1243768fd266SAlex Maftei (amaftei) } 1244768fd266SAlex Maftei (amaftei) 1245768fd266SAlex Maftei (amaftei) return spent; 1246768fd266SAlex Maftei (amaftei) } 1247768fd266SAlex Maftei (amaftei) 1248768fd266SAlex Maftei (amaftei) void efx_init_napi_channel(struct efx_channel *channel) 1249768fd266SAlex Maftei (amaftei) { 1250768fd266SAlex Maftei (amaftei) struct efx_nic *efx = channel->efx; 1251768fd266SAlex Maftei (amaftei) 1252768fd266SAlex Maftei (amaftei) channel->napi_dev = efx->net_dev; 1253768fd266SAlex Maftei (amaftei) netif_napi_add(channel->napi_dev, &channel->napi_str, 1254768fd266SAlex Maftei (amaftei) efx_poll, napi_weight); 1255768fd266SAlex Maftei (amaftei) } 1256768fd266SAlex Maftei (amaftei) 1257768fd266SAlex Maftei (amaftei) void efx_init_napi(struct efx_nic *efx) 1258768fd266SAlex Maftei (amaftei) { 1259768fd266SAlex Maftei (amaftei) struct efx_channel *channel; 1260768fd266SAlex Maftei (amaftei) 1261768fd266SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) 1262768fd266SAlex Maftei (amaftei) efx_init_napi_channel(channel); 1263768fd266SAlex Maftei (amaftei) } 1264768fd266SAlex Maftei (amaftei) 1265768fd266SAlex Maftei (amaftei) void efx_fini_napi_channel(struct efx_channel *channel) 1266768fd266SAlex Maftei (amaftei) { 1267768fd266SAlex Maftei (amaftei) if (channel->napi_dev) 1268768fd266SAlex Maftei (amaftei) netif_napi_del(&channel->napi_str); 1269768fd266SAlex Maftei (amaftei) 1270768fd266SAlex Maftei (amaftei) channel->napi_dev = NULL; 1271768fd266SAlex Maftei (amaftei) } 1272768fd266SAlex Maftei (amaftei) 1273768fd266SAlex Maftei (amaftei) void efx_fini_napi(struct efx_nic *efx) 1274768fd266SAlex Maftei (amaftei) { 1275768fd266SAlex Maftei (amaftei) struct efx_channel *channel; 1276768fd266SAlex Maftei (amaftei) 1277768fd266SAlex Maftei (amaftei) efx_for_each_channel(channel, efx) 1278768fd266SAlex Maftei (amaftei) efx_fini_napi_channel(channel); 1279768fd266SAlex Maftei (amaftei) } 1280