efx_channels.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2018 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #include "net_driver.h"
  11. #include <linux/module.h>
  12. #include <linux/filter.h>
  13. #include "efx_channels.h"
  14. #include "efx.h"
  15. #include "efx_common.h"
  16. #include "tx_common.h"
  17. #include "rx_common.h"
  18. #include "nic.h"
  19. #include "sriov.h"
  20. #include "workarounds.h"
  21. /* This is the first interrupt mode to try out of:
  22. * 0 => MSI-X
  23. * 1 => MSI
  24. * 2 => legacy
  25. */
  26. unsigned int efx_interrupt_mode = EFX_INT_MODE_MSIX;
  27. /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
  28. * i.e. the number of CPUs among which we may distribute simultaneous
  29. * interrupt handling.
  30. *
  31. * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
  32. * The default (0) means to assign an interrupt to each core.
  33. */
  34. unsigned int rss_cpus;
  35. static unsigned int irq_adapt_low_thresh = 8000;
  36. module_param(irq_adapt_low_thresh, uint, 0644);
  37. MODULE_PARM_DESC(irq_adapt_low_thresh,
  38. "Threshold score for reducing IRQ moderation");
  39. static unsigned int irq_adapt_high_thresh = 16000;
  40. module_param(irq_adapt_high_thresh, uint, 0644);
  41. MODULE_PARM_DESC(irq_adapt_high_thresh,
  42. "Threshold score for increasing IRQ moderation");
  43. static const struct efx_channel_type efx_default_channel_type;
  44. /*************
  45. * INTERRUPTS
  46. *************/
  47. static unsigned int count_online_cores(struct efx_nic *efx, bool local_node)
  48. {
  49. cpumask_var_t filter_mask;
  50. unsigned int count;
  51. int cpu;
  52. if (unlikely(!zalloc_cpumask_var(&filter_mask, GFP_KERNEL))) {
  53. netif_warn(efx, probe, efx->net_dev,
  54. "RSS disabled due to allocation failure\n");
  55. return 1;
  56. }
  57. cpumask_copy(filter_mask, cpu_online_mask);
  58. if (local_node)
  59. cpumask_and(filter_mask, filter_mask,
  60. cpumask_of_pcibus(efx->pci_dev->bus));
  61. count = 0;
  62. for_each_cpu(cpu, filter_mask) {
  63. ++count;
  64. cpumask_andnot(filter_mask, filter_mask, topology_sibling_cpumask(cpu));
  65. }
  66. free_cpumask_var(filter_mask);
  67. return count;
  68. }
  69. static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
  70. {
  71. unsigned int count;
  72. if (rss_cpus) {
  73. count = rss_cpus;
  74. } else {
  75. count = count_online_cores(efx, true);
  76. /* If no online CPUs in local node, fallback to any online CPUs */
  77. if (count == 0)
  78. count = count_online_cores(efx, false);
  79. }
  80. if (count > EFX_MAX_RX_QUEUES) {
  81. netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn,
  82. "Reducing number of rx queues from %u to %u.\n",
  83. count, EFX_MAX_RX_QUEUES);
  84. count = EFX_MAX_RX_QUEUES;
  85. }
  86. /* If RSS is requested for the PF *and* VFs then we can't write RSS
  87. * table entries that are inaccessible to VFs
  88. */
  89. #ifdef CONFIG_SFC_SRIOV
  90. if (efx->type->sriov_wanted) {
  91. if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
  92. count > efx_vf_size(efx)) {
  93. netif_warn(efx, probe, efx->net_dev,
  94. "Reducing number of RSS channels from %u to %u for "
  95. "VF support. Increase vf-msix-limit to use more "
  96. "channels on the PF.\n",
  97. count, efx_vf_size(efx));
  98. count = efx_vf_size(efx);
  99. }
  100. }
  101. #endif
  102. return count;
  103. }
  104. static int efx_allocate_msix_channels(struct efx_nic *efx,
  105. unsigned int max_channels,
  106. unsigned int extra_channels,
  107. unsigned int parallelism)
  108. {
  109. unsigned int n_channels = parallelism;
  110. int vec_count;
  111. int tx_per_ev;
  112. int n_xdp_tx;
  113. int n_xdp_ev;
  114. if (efx_separate_tx_channels)
  115. n_channels *= 2;
  116. n_channels += extra_channels;
  117. /* To allow XDP transmit to happen from arbitrary NAPI contexts
  118. * we allocate a TX queue per CPU. We share event queues across
  119. * multiple tx queues, assuming tx and ev queues are both
  120. * maximum size.
  121. */
  122. tx_per_ev = EFX_MAX_EVQ_SIZE / EFX_TXQ_MAX_ENT(efx);
  123. tx_per_ev = min(tx_per_ev, EFX_MAX_TXQ_PER_CHANNEL);
  124. n_xdp_tx = num_possible_cpus();
  125. n_xdp_ev = DIV_ROUND_UP(n_xdp_tx, tx_per_ev);
  126. vec_count = pci_msix_vec_count(efx->pci_dev);
  127. if (vec_count < 0)
  128. return vec_count;
  129. max_channels = min_t(unsigned int, vec_count, max_channels);
  130. /* Check resources.
  131. * We need a channel per event queue, plus a VI per tx queue.
  132. * This may be more pessimistic than it needs to be.
  133. */
  134. if (n_channels >= max_channels) {
  135. efx->xdp_txq_queues_mode = EFX_XDP_TX_QUEUES_BORROWED;
  136. netif_warn(efx, drv, efx->net_dev,
  137. "Insufficient resources for %d XDP event queues (%d other channels, max %d)\n",
  138. n_xdp_ev, n_channels, max_channels);
  139. netif_warn(efx, drv, efx->net_dev,
  140. "XDP_TX and XDP_REDIRECT might decrease device's performance\n");
  141. } else if (n_channels + n_xdp_tx > efx->max_vis) {
  142. efx->xdp_txq_queues_mode = EFX_XDP_TX_QUEUES_BORROWED;
  143. netif_warn(efx, drv, efx->net_dev,
  144. "Insufficient resources for %d XDP TX queues (%d other channels, max VIs %d)\n",
  145. n_xdp_tx, n_channels, efx->max_vis);
  146. netif_warn(efx, drv, efx->net_dev,
  147. "XDP_TX and XDP_REDIRECT might decrease device's performance\n");
  148. } else if (n_channels + n_xdp_ev > max_channels) {
  149. efx->xdp_txq_queues_mode = EFX_XDP_TX_QUEUES_SHARED;
  150. netif_warn(efx, drv, efx->net_dev,
  151. "Insufficient resources for %d XDP event queues (%d other channels, max %d)\n",
  152. n_xdp_ev, n_channels, max_channels);
  153. n_xdp_ev = max_channels - n_channels;
  154. netif_warn(efx, drv, efx->net_dev,
  155. "XDP_TX and XDP_REDIRECT will work with reduced performance (%d cpus/tx_queue)\n",
  156. DIV_ROUND_UP(n_xdp_tx, tx_per_ev * n_xdp_ev));
  157. } else {
  158. efx->xdp_txq_queues_mode = EFX_XDP_TX_QUEUES_DEDICATED;
  159. }
  160. if (efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_BORROWED) {
  161. efx->n_xdp_channels = n_xdp_ev;
  162. efx->xdp_tx_per_channel = tx_per_ev;
  163. efx->xdp_tx_queue_count = n_xdp_tx;
  164. n_channels += n_xdp_ev;
  165. netif_dbg(efx, drv, efx->net_dev,
  166. "Allocating %d TX and %d event queues for XDP\n",
  167. n_xdp_ev * tx_per_ev, n_xdp_ev);
  168. } else {
  169. efx->n_xdp_channels = 0;
  170. efx->xdp_tx_per_channel = 0;
  171. efx->xdp_tx_queue_count = n_xdp_tx;
  172. }
  173. if (vec_count < n_channels) {
  174. netif_err(efx, drv, efx->net_dev,
  175. "WARNING: Insufficient MSI-X vectors available (%d < %u).\n",
  176. vec_count, n_channels);
  177. netif_err(efx, drv, efx->net_dev,
  178. "WARNING: Performance may be reduced.\n");
  179. n_channels = vec_count;
  180. }
  181. n_channels = min(n_channels, max_channels);
  182. efx->n_channels = n_channels;
  183. /* Ignore XDP tx channels when creating rx channels. */
  184. n_channels -= efx->n_xdp_channels;
  185. if (efx_separate_tx_channels) {
  186. efx->n_tx_channels =
  187. clamp(n_channels / 2, 1U,
  188. efx->max_tx_channels);
  189. efx->tx_channel_offset =
  190. n_channels - efx->n_tx_channels;
  191. efx->n_rx_channels =
  192. max(n_channels -
  193. efx->n_tx_channels, 1U);
  194. } else {
  195. efx->n_tx_channels = min(n_channels, efx->max_tx_channels);
  196. efx->tx_channel_offset = 0;
  197. efx->n_rx_channels = n_channels;
  198. }
  199. efx->n_rx_channels = min(efx->n_rx_channels, parallelism);
  200. efx->n_tx_channels = min(efx->n_tx_channels, parallelism);
  201. efx->xdp_channel_offset = n_channels;
  202. netif_dbg(efx, drv, efx->net_dev,
  203. "Allocating %u RX channels\n",
  204. efx->n_rx_channels);
  205. return efx->n_channels;
  206. }
  207. /* Probe the number and type of interrupts we are able to obtain, and
  208. * the resulting numbers of channels and RX queues.
  209. */
  210. int efx_probe_interrupts(struct efx_nic *efx)
  211. {
  212. unsigned int extra_channels = 0;
  213. unsigned int rss_spread;
  214. unsigned int i, j;
  215. int rc;
  216. for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
  217. if (efx->extra_channel_type[i])
  218. ++extra_channels;
  219. if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
  220. unsigned int parallelism = efx_wanted_parallelism(efx);
  221. struct msix_entry xentries[EFX_MAX_CHANNELS];
  222. unsigned int n_channels;
  223. rc = efx_allocate_msix_channels(efx, efx->max_channels,
  224. extra_channels, parallelism);
  225. if (rc >= 0) {
  226. n_channels = rc;
  227. for (i = 0; i < n_channels; i++)
  228. xentries[i].entry = i;
  229. rc = pci_enable_msix_range(efx->pci_dev, xentries, 1,
  230. n_channels);
  231. }
  232. if (rc < 0) {
  233. /* Fall back to single channel MSI */
  234. netif_err(efx, drv, efx->net_dev,
  235. "could not enable MSI-X\n");
  236. if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI)
  237. efx->interrupt_mode = EFX_INT_MODE_MSI;
  238. else
  239. return rc;
  240. } else if (rc < n_channels) {
  241. netif_err(efx, drv, efx->net_dev,
  242. "WARNING: Insufficient MSI-X vectors"
  243. " available (%d < %u).\n", rc, n_channels);
  244. netif_err(efx, drv, efx->net_dev,
  245. "WARNING: Performance may be reduced.\n");
  246. n_channels = rc;
  247. }
  248. if (rc > 0) {
  249. for (i = 0; i < efx->n_channels; i++)
  250. efx_get_channel(efx, i)->irq =
  251. xentries[i].vector;
  252. }
  253. }
  254. /* Try single interrupt MSI */
  255. if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
  256. efx->n_channels = 1;
  257. efx->n_rx_channels = 1;
  258. efx->n_tx_channels = 1;
  259. efx->tx_channel_offset = 0;
  260. efx->n_xdp_channels = 0;
  261. efx->xdp_channel_offset = efx->n_channels;
  262. efx->xdp_txq_queues_mode = EFX_XDP_TX_QUEUES_BORROWED;
  263. rc = pci_enable_msi(efx->pci_dev);
  264. if (rc == 0) {
  265. efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
  266. } else {
  267. netif_err(efx, drv, efx->net_dev,
  268. "could not enable MSI\n");
  269. if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY)
  270. efx->interrupt_mode = EFX_INT_MODE_LEGACY;
  271. else
  272. return rc;
  273. }
  274. }
  275. /* Assume legacy interrupts */
  276. if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
  277. efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0);
  278. efx->n_rx_channels = 1;
  279. efx->n_tx_channels = 1;
  280. efx->tx_channel_offset = efx_separate_tx_channels ? 1 : 0;
  281. efx->n_xdp_channels = 0;
  282. efx->xdp_channel_offset = efx->n_channels;
  283. efx->xdp_txq_queues_mode = EFX_XDP_TX_QUEUES_BORROWED;
  284. efx->legacy_irq = efx->pci_dev->irq;
  285. }
  286. /* Assign extra channels if possible, before XDP channels */
  287. efx->n_extra_tx_channels = 0;
  288. j = efx->xdp_channel_offset;
  289. for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
  290. if (!efx->extra_channel_type[i])
  291. continue;
  292. if (j <= efx->tx_channel_offset + efx->n_tx_channels) {
  293. efx->extra_channel_type[i]->handle_no_channel(efx);
  294. } else {
  295. --j;
  296. efx_get_channel(efx, j)->type =
  297. efx->extra_channel_type[i];
  298. if (efx_channel_has_tx_queues(efx_get_channel(efx, j)))
  299. efx->n_extra_tx_channels++;
  300. }
  301. }
  302. rss_spread = efx->n_rx_channels;
  303. /* RSS might be usable on VFs even if it is disabled on the PF */
  304. #ifdef CONFIG_SFC_SRIOV
  305. if (efx->type->sriov_wanted) {
  306. efx->rss_spread = ((rss_spread > 1 ||
  307. !efx->type->sriov_wanted(efx)) ?
  308. rss_spread : efx_vf_size(efx));
  309. return 0;
  310. }
  311. #endif
  312. efx->rss_spread = rss_spread;
  313. return 0;
  314. }
  315. #if defined(CONFIG_SMP)
  316. void efx_set_interrupt_affinity(struct efx_nic *efx)
  317. {
  318. const struct cpumask *numa_mask = cpumask_of_pcibus(efx->pci_dev->bus);
  319. struct efx_channel *channel;
  320. unsigned int cpu;
  321. /* If no online CPUs in local node, fallback to any online CPU */
  322. if (cpumask_first_and(cpu_online_mask, numa_mask) >= nr_cpu_ids)
  323. numa_mask = cpu_online_mask;
  324. cpu = -1;
  325. efx_for_each_channel(channel, efx) {
  326. cpu = cpumask_next_and(cpu, cpu_online_mask, numa_mask);
  327. if (cpu >= nr_cpu_ids)
  328. cpu = cpumask_first_and(cpu_online_mask, numa_mask);
  329. irq_set_affinity_hint(channel->irq, cpumask_of(cpu));
  330. }
  331. }
  332. void efx_clear_interrupt_affinity(struct efx_nic *efx)
  333. {
  334. struct efx_channel *channel;
  335. efx_for_each_channel(channel, efx)
  336. irq_set_affinity_hint(channel->irq, NULL);
  337. }
  338. #else
  339. void
  340. efx_set_interrupt_affinity(struct efx_nic *efx __attribute__ ((unused)))
  341. {
  342. }
  343. void
  344. efx_clear_interrupt_affinity(struct efx_nic *efx __attribute__ ((unused)))
  345. {
  346. }
  347. #endif /* CONFIG_SMP */
  348. void efx_remove_interrupts(struct efx_nic *efx)
  349. {
  350. struct efx_channel *channel;
  351. /* Remove MSI/MSI-X interrupts */
  352. efx_for_each_channel(channel, efx)
  353. channel->irq = 0;
  354. pci_disable_msi(efx->pci_dev);
  355. pci_disable_msix(efx->pci_dev);
  356. /* Remove legacy interrupt */
  357. efx->legacy_irq = 0;
  358. }
  359. /***************
  360. * EVENT QUEUES
  361. ***************/
  362. /* Create event queue
  363. * Event queue memory allocations are done only once. If the channel
  364. * is reset, the memory buffer will be reused; this guards against
  365. * errors during channel reset and also simplifies interrupt handling.
  366. */
  367. int efx_probe_eventq(struct efx_channel *channel)
  368. {
  369. struct efx_nic *efx = channel->efx;
  370. unsigned long entries;
  371. netif_dbg(efx, probe, efx->net_dev,
  372. "chan %d create event queue\n", channel->channel);
  373. /* Build an event queue with room for one event per tx and rx buffer,
  374. * plus some extra for link state events and MCDI completions.
  375. */
  376. entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
  377. EFX_WARN_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
  378. channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;
  379. return efx_nic_probe_eventq(channel);
  380. }
  381. /* Prepare channel's event queue */
  382. int efx_init_eventq(struct efx_channel *channel)
  383. {
  384. struct efx_nic *efx = channel->efx;
  385. int rc;
  386. EFX_WARN_ON_PARANOID(channel->eventq_init);
  387. netif_dbg(efx, drv, efx->net_dev,
  388. "chan %d init event queue\n", channel->channel);
  389. rc = efx_nic_init_eventq(channel);
  390. if (rc == 0) {
  391. efx->type->push_irq_moderation(channel);
  392. channel->eventq_read_ptr = 0;
  393. channel->eventq_init = true;
  394. }
  395. return rc;
  396. }
  397. /* Enable event queue processing and NAPI */
  398. void efx_start_eventq(struct efx_channel *channel)
  399. {
  400. netif_dbg(channel->efx, ifup, channel->efx->net_dev,
  401. "chan %d start event queue\n", channel->channel);
  402. /* Make sure the NAPI handler sees the enabled flag set */
  403. channel->enabled = true;
  404. smp_wmb();
  405. napi_enable(&channel->napi_str);
  406. efx_nic_eventq_read_ack(channel);
  407. }
  408. /* Disable event queue processing and NAPI */
  409. void efx_stop_eventq(struct efx_channel *channel)
  410. {
  411. if (!channel->enabled)
  412. return;
  413. napi_disable(&channel->napi_str);
  414. channel->enabled = false;
  415. }
  416. void efx_fini_eventq(struct efx_channel *channel)
  417. {
  418. if (!channel->eventq_init)
  419. return;
  420. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  421. "chan %d fini event queue\n", channel->channel);
  422. efx_nic_fini_eventq(channel);
  423. channel->eventq_init = false;
  424. }
  425. void efx_remove_eventq(struct efx_channel *channel)
  426. {
  427. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  428. "chan %d remove event queue\n", channel->channel);
  429. efx_nic_remove_eventq(channel);
  430. }
  431. /**************************************************************************
  432. *
  433. * Channel handling
  434. *
  435. *************************************************************************/
  436. #ifdef CONFIG_RFS_ACCEL
  437. static void efx_filter_rfs_expire(struct work_struct *data)
  438. {
  439. struct delayed_work *dwork = to_delayed_work(data);
  440. struct efx_channel *channel;
  441. unsigned int time, quota;
  442. channel = container_of(dwork, struct efx_channel, filter_work);
  443. time = jiffies - channel->rfs_last_expiry;
  444. quota = channel->rfs_filter_count * time / (30 * HZ);
  445. if (quota >= 20 && __efx_filter_rfs_expire(channel, min(channel->rfs_filter_count, quota)))
  446. channel->rfs_last_expiry += time;
  447. /* Ensure we do more work eventually even if NAPI poll is not happening */
  448. schedule_delayed_work(dwork, 30 * HZ);
  449. }
  450. #endif
  451. /* Allocate and initialise a channel structure. */
  452. static struct efx_channel *efx_alloc_channel(struct efx_nic *efx, int i)
  453. {
  454. struct efx_rx_queue *rx_queue;
  455. struct efx_tx_queue *tx_queue;
  456. struct efx_channel *channel;
  457. int j;
  458. channel = kzalloc_obj(*channel);
  459. if (!channel)
  460. return NULL;
  461. channel->efx = efx;
  462. channel->channel = i;
  463. channel->type = &efx_default_channel_type;
  464. for (j = 0; j < EFX_MAX_TXQ_PER_CHANNEL; j++) {
  465. tx_queue = &channel->tx_queue[j];
  466. tx_queue->efx = efx;
  467. tx_queue->queue = -1;
  468. tx_queue->label = j;
  469. tx_queue->channel = channel;
  470. }
  471. #ifdef CONFIG_RFS_ACCEL
  472. INIT_DELAYED_WORK(&channel->filter_work, efx_filter_rfs_expire);
  473. #endif
  474. rx_queue = &channel->rx_queue;
  475. rx_queue->efx = efx;
  476. timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
  477. return channel;
  478. }
  479. int efx_init_channels(struct efx_nic *efx)
  480. {
  481. unsigned int i;
  482. for (i = 0; i < EFX_MAX_CHANNELS; i++) {
  483. efx->channel[i] = efx_alloc_channel(efx, i);
  484. if (!efx->channel[i])
  485. return -ENOMEM;
  486. efx->msi_context[i].efx = efx;
  487. efx->msi_context[i].index = i;
  488. }
  489. /* Higher numbered interrupt modes are less capable! */
  490. efx->interrupt_mode = min(efx->type->min_interrupt_mode,
  491. efx_interrupt_mode);
  492. efx->max_channels = EFX_MAX_CHANNELS;
  493. efx->max_tx_channels = EFX_MAX_CHANNELS;
  494. return 0;
  495. }
  496. void efx_fini_channels(struct efx_nic *efx)
  497. {
  498. unsigned int i;
  499. for (i = 0; i < EFX_MAX_CHANNELS; i++)
  500. if (efx->channel[i]) {
  501. kfree(efx->channel[i]);
  502. efx->channel[i] = NULL;
  503. }
  504. }
  505. /* Allocate and initialise a channel structure, copying parameters
  506. * (but not resources) from an old channel structure.
  507. */
  508. struct efx_channel *efx_copy_channel(const struct efx_channel *old_channel)
  509. {
  510. struct efx_rx_queue *rx_queue;
  511. struct efx_tx_queue *tx_queue;
  512. struct efx_channel *channel;
  513. int j;
  514. channel = kmalloc_obj(*channel);
  515. if (!channel)
  516. return NULL;
  517. *channel = *old_channel;
  518. channel->napi_dev = NULL;
  519. INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
  520. channel->napi_str.napi_id = 0;
  521. channel->napi_str.state = 0;
  522. memset(&channel->eventq, 0, sizeof(channel->eventq));
  523. for (j = 0; j < EFX_MAX_TXQ_PER_CHANNEL; j++) {
  524. tx_queue = &channel->tx_queue[j];
  525. if (tx_queue->channel)
  526. tx_queue->channel = channel;
  527. tx_queue->buffer = NULL;
  528. tx_queue->cb_page = NULL;
  529. memset(&tx_queue->txd, 0, sizeof(tx_queue->txd));
  530. }
  531. rx_queue = &channel->rx_queue;
  532. rx_queue->buffer = NULL;
  533. memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
  534. timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
  535. #ifdef CONFIG_RFS_ACCEL
  536. INIT_DELAYED_WORK(&channel->filter_work, efx_filter_rfs_expire);
  537. #endif
  538. return channel;
  539. }
  540. static int efx_probe_channel(struct efx_channel *channel)
  541. {
  542. struct efx_tx_queue *tx_queue;
  543. struct efx_rx_queue *rx_queue;
  544. int rc;
  545. netif_dbg(channel->efx, probe, channel->efx->net_dev,
  546. "creating channel %d\n", channel->channel);
  547. rc = channel->type->pre_probe(channel);
  548. if (rc)
  549. goto fail;
  550. rc = efx_probe_eventq(channel);
  551. if (rc)
  552. goto fail;
  553. efx_for_each_channel_tx_queue(tx_queue, channel) {
  554. rc = efx_probe_tx_queue(tx_queue);
  555. if (rc)
  556. goto fail;
  557. }
  558. efx_for_each_channel_rx_queue(rx_queue, channel) {
  559. rc = efx_probe_rx_queue(rx_queue);
  560. if (rc)
  561. goto fail;
  562. }
  563. channel->rx_list = NULL;
  564. return 0;
  565. fail:
  566. efx_remove_channel(channel);
  567. return rc;
  568. }
  569. static void efx_get_channel_name(struct efx_channel *channel, char *buf,
  570. size_t len)
  571. {
  572. struct efx_nic *efx = channel->efx;
  573. const char *type;
  574. int number;
  575. number = channel->channel;
  576. if (number >= efx->xdp_channel_offset &&
  577. !WARN_ON_ONCE(!efx->n_xdp_channels)) {
  578. type = "-xdp";
  579. number -= efx->xdp_channel_offset;
  580. } else if (efx->tx_channel_offset == 0) {
  581. type = "";
  582. } else if (number < efx->tx_channel_offset) {
  583. type = "-rx";
  584. } else {
  585. type = "-tx";
  586. number -= efx->tx_channel_offset;
  587. }
  588. snprintf(buf, len, "%s%s-%d", efx->name, type, number);
  589. }
  590. void efx_set_channel_names(struct efx_nic *efx)
  591. {
  592. struct efx_channel *channel;
  593. efx_for_each_channel(channel, efx)
  594. channel->type->get_name(channel,
  595. efx->msi_context[channel->channel].name,
  596. sizeof(efx->msi_context[0].name));
  597. }
  598. int efx_probe_channels(struct efx_nic *efx)
  599. {
  600. struct efx_channel *channel;
  601. int rc;
  602. /* Probe channels in reverse, so that any 'extra' channels
  603. * use the start of the buffer table. This allows the traffic
  604. * channels to be resized without moving them or wasting the
  605. * entries before them.
  606. */
  607. efx_for_each_channel_rev(channel, efx) {
  608. rc = efx_probe_channel(channel);
  609. if (rc) {
  610. netif_err(efx, probe, efx->net_dev,
  611. "failed to create channel %d\n",
  612. channel->channel);
  613. goto fail;
  614. }
  615. }
  616. efx_set_channel_names(efx);
  617. return 0;
  618. fail:
  619. efx_remove_channels(efx);
  620. return rc;
  621. }
  622. void efx_remove_channel(struct efx_channel *channel)
  623. {
  624. struct efx_tx_queue *tx_queue;
  625. struct efx_rx_queue *rx_queue;
  626. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  627. "destroy chan %d\n", channel->channel);
  628. efx_for_each_channel_rx_queue(rx_queue, channel)
  629. efx_remove_rx_queue(rx_queue);
  630. efx_for_each_channel_tx_queue(tx_queue, channel)
  631. efx_remove_tx_queue(tx_queue);
  632. efx_remove_eventq(channel);
  633. channel->type->post_remove(channel);
  634. }
  635. void efx_remove_channels(struct efx_nic *efx)
  636. {
  637. struct efx_channel *channel;
  638. efx_for_each_channel(channel, efx)
  639. efx_remove_channel(channel);
  640. kfree(efx->xdp_tx_queues);
  641. }
  642. static int efx_set_xdp_tx_queue(struct efx_nic *efx, int xdp_queue_number,
  643. struct efx_tx_queue *tx_queue)
  644. {
  645. if (xdp_queue_number >= efx->xdp_tx_queue_count)
  646. return -EINVAL;
  647. netif_dbg(efx, drv, efx->net_dev,
  648. "Channel %u TXQ %u is XDP %u, HW %u\n",
  649. tx_queue->channel->channel, tx_queue->label,
  650. xdp_queue_number, tx_queue->queue);
  651. efx->xdp_tx_queues[xdp_queue_number] = tx_queue;
  652. return 0;
  653. }
  654. static void efx_set_xdp_channels(struct efx_nic *efx)
  655. {
  656. struct efx_tx_queue *tx_queue;
  657. struct efx_channel *channel;
  658. unsigned int next_queue = 0;
  659. int xdp_queue_number = 0;
  660. int rc;
  661. /* We need to mark which channels really have RX and TX
  662. * queues, and adjust the TX queue numbers if we have separate
  663. * RX-only and TX-only channels.
  664. */
  665. efx_for_each_channel(channel, efx) {
  666. if (channel->channel < efx->tx_channel_offset)
  667. continue;
  668. if (efx_channel_is_xdp_tx(channel)) {
  669. efx_for_each_channel_tx_queue(tx_queue, channel) {
  670. tx_queue->queue = next_queue++;
  671. rc = efx_set_xdp_tx_queue(efx, xdp_queue_number,
  672. tx_queue);
  673. if (rc == 0)
  674. xdp_queue_number++;
  675. }
  676. } else {
  677. efx_for_each_channel_tx_queue(tx_queue, channel) {
  678. tx_queue->queue = next_queue++;
  679. netif_dbg(efx, drv, efx->net_dev,
  680. "Channel %u TXQ %u is HW %u\n",
  681. channel->channel, tx_queue->label,
  682. tx_queue->queue);
  683. }
  684. /* If XDP is borrowing queues from net stack, it must
  685. * use the queue with no csum offload, which is the
  686. * first one of the channel
  687. * (note: tx_queue_by_type is not initialized yet)
  688. */
  689. if (efx->xdp_txq_queues_mode ==
  690. EFX_XDP_TX_QUEUES_BORROWED) {
  691. tx_queue = &channel->tx_queue[0];
  692. rc = efx_set_xdp_tx_queue(efx, xdp_queue_number,
  693. tx_queue);
  694. if (rc == 0)
  695. xdp_queue_number++;
  696. }
  697. }
  698. }
  699. WARN_ON(efx->xdp_txq_queues_mode == EFX_XDP_TX_QUEUES_DEDICATED &&
  700. xdp_queue_number != efx->xdp_tx_queue_count);
  701. WARN_ON(efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_DEDICATED &&
  702. xdp_queue_number > efx->xdp_tx_queue_count);
  703. /* If we have more CPUs than assigned XDP TX queues, assign the already
  704. * existing queues to the exceeding CPUs
  705. */
  706. next_queue = 0;
  707. while (xdp_queue_number < efx->xdp_tx_queue_count) {
  708. tx_queue = efx->xdp_tx_queues[next_queue++];
  709. rc = efx_set_xdp_tx_queue(efx, xdp_queue_number, tx_queue);
  710. if (rc == 0)
  711. xdp_queue_number++;
  712. }
  713. }
  714. int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
  715. {
  716. struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel,
  717. *ptp_channel = efx_ptp_channel(efx);
  718. struct efx_ptp_data *ptp_data = efx->ptp_data;
  719. u32 old_rxq_entries, old_txq_entries;
  720. unsigned int i;
  721. int rc, rc2;
  722. rc = efx_check_disabled(efx);
  723. if (rc)
  724. return rc;
  725. efx_device_detach_sync(efx);
  726. efx_stop_all(efx);
  727. efx_soft_disable_interrupts(efx);
  728. /* Clone channels (where possible) */
  729. memset(other_channel, 0, sizeof(other_channel));
  730. for (i = 0; i < efx->n_channels; i++) {
  731. channel = efx->channel[i];
  732. if (channel->type->copy)
  733. channel = channel->type->copy(channel);
  734. if (!channel) {
  735. rc = -ENOMEM;
  736. goto out;
  737. }
  738. other_channel[i] = channel;
  739. }
  740. /* Swap entry counts and channel pointers */
  741. old_rxq_entries = efx->rxq_entries;
  742. old_txq_entries = efx->txq_entries;
  743. efx->rxq_entries = rxq_entries;
  744. efx->txq_entries = txq_entries;
  745. for (i = 0; i < efx->n_channels; i++)
  746. swap(efx->channel[i], other_channel[i]);
  747. for (i = 0; i < efx->n_channels; i++) {
  748. channel = efx->channel[i];
  749. if (!channel->type->copy)
  750. continue;
  751. rc = efx_probe_channel(channel);
  752. if (rc)
  753. goto rollback;
  754. efx_init_napi_channel(efx->channel[i]);
  755. }
  756. efx_set_xdp_channels(efx);
  757. out:
  758. efx->ptp_data = NULL;
  759. /* Destroy unused channel structures */
  760. for (i = 0; i < efx->n_channels; i++) {
  761. channel = other_channel[i];
  762. if (channel && channel->type->copy) {
  763. efx_fini_napi_channel(channel);
  764. efx_remove_channel(channel);
  765. kfree(channel);
  766. }
  767. }
  768. efx->ptp_data = ptp_data;
  769. rc2 = efx_soft_enable_interrupts(efx);
  770. if (rc2) {
  771. rc = rc ? rc : rc2;
  772. netif_err(efx, drv, efx->net_dev,
  773. "unable to restart interrupts on channel reallocation\n");
  774. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  775. } else {
  776. efx_start_all(efx);
  777. efx_device_attach_if_not_resetting(efx);
  778. }
  779. return rc;
  780. rollback:
  781. /* Swap back */
  782. efx->rxq_entries = old_rxq_entries;
  783. efx->txq_entries = old_txq_entries;
  784. for (i = 0; i < efx->n_channels; i++)
  785. swap(efx->channel[i], other_channel[i]);
  786. efx_ptp_update_channel(efx, ptp_channel);
  787. goto out;
  788. }
  789. int efx_set_channels(struct efx_nic *efx)
  790. {
  791. struct efx_channel *channel;
  792. int rc;
  793. if (efx->xdp_tx_queue_count) {
  794. EFX_WARN_ON_PARANOID(efx->xdp_tx_queues);
  795. /* Allocate array for XDP TX queue lookup. */
  796. efx->xdp_tx_queues = kzalloc_objs(*efx->xdp_tx_queues,
  797. efx->xdp_tx_queue_count);
  798. if (!efx->xdp_tx_queues)
  799. return -ENOMEM;
  800. }
  801. efx_for_each_channel(channel, efx) {
  802. if (channel->channel < efx->n_rx_channels)
  803. channel->rx_queue.core_index = channel->channel;
  804. else
  805. channel->rx_queue.core_index = -1;
  806. }
  807. efx_set_xdp_channels(efx);
  808. rc = netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
  809. if (rc)
  810. return rc;
  811. return netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
  812. }
  813. static bool efx_default_channel_want_txqs(struct efx_channel *channel)
  814. {
  815. return channel->channel - channel->efx->tx_channel_offset <
  816. channel->efx->n_tx_channels;
  817. }
  818. /*************
  819. * START/STOP
  820. *************/
  821. int efx_soft_enable_interrupts(struct efx_nic *efx)
  822. {
  823. struct efx_channel *channel, *end_channel;
  824. int rc;
  825. BUG_ON(efx->state == STATE_DISABLED);
  826. efx->irq_soft_enabled = true;
  827. smp_wmb();
  828. efx_for_each_channel(channel, efx) {
  829. if (!channel->type->keep_eventq) {
  830. rc = efx_init_eventq(channel);
  831. if (rc)
  832. goto fail;
  833. }
  834. efx_start_eventq(channel);
  835. }
  836. efx_mcdi_mode_event(efx);
  837. return 0;
  838. fail:
  839. end_channel = channel;
  840. efx_for_each_channel(channel, efx) {
  841. if (channel == end_channel)
  842. break;
  843. efx_stop_eventq(channel);
  844. if (!channel->type->keep_eventq)
  845. efx_fini_eventq(channel);
  846. }
  847. return rc;
  848. }
  849. void efx_soft_disable_interrupts(struct efx_nic *efx)
  850. {
  851. struct efx_channel *channel;
  852. if (efx->state == STATE_DISABLED)
  853. return;
  854. efx_mcdi_mode_poll(efx);
  855. efx->irq_soft_enabled = false;
  856. smp_wmb();
  857. if (efx->legacy_irq)
  858. synchronize_irq(efx->legacy_irq);
  859. efx_for_each_channel(channel, efx) {
  860. if (channel->irq)
  861. synchronize_irq(channel->irq);
  862. efx_stop_eventq(channel);
  863. if (!channel->type->keep_eventq)
  864. efx_fini_eventq(channel);
  865. }
  866. /* Flush the asynchronous MCDI request queue */
  867. efx_mcdi_flush_async(efx);
  868. }
  869. int efx_enable_interrupts(struct efx_nic *efx)
  870. {
  871. struct efx_channel *channel, *end_channel;
  872. int rc;
  873. /* TODO: Is this really a bug? */
  874. BUG_ON(efx->state == STATE_DISABLED);
  875. if (efx->eeh_disabled_legacy_irq) {
  876. enable_irq(efx->legacy_irq);
  877. efx->eeh_disabled_legacy_irq = false;
  878. }
  879. efx->type->irq_enable_master(efx);
  880. efx_for_each_channel(channel, efx) {
  881. if (channel->type->keep_eventq) {
  882. rc = efx_init_eventq(channel);
  883. if (rc)
  884. goto fail;
  885. }
  886. }
  887. rc = efx_soft_enable_interrupts(efx);
  888. if (rc)
  889. goto fail;
  890. return 0;
  891. fail:
  892. end_channel = channel;
  893. efx_for_each_channel(channel, efx) {
  894. if (channel == end_channel)
  895. break;
  896. if (channel->type->keep_eventq)
  897. efx_fini_eventq(channel);
  898. }
  899. efx->type->irq_disable_non_ev(efx);
  900. return rc;
  901. }
  902. void efx_disable_interrupts(struct efx_nic *efx)
  903. {
  904. struct efx_channel *channel;
  905. efx_soft_disable_interrupts(efx);
  906. efx_for_each_channel(channel, efx) {
  907. if (channel->type->keep_eventq)
  908. efx_fini_eventq(channel);
  909. }
  910. efx->type->irq_disable_non_ev(efx);
  911. }
  912. void efx_start_channels(struct efx_nic *efx)
  913. {
  914. struct efx_tx_queue *tx_queue;
  915. struct efx_rx_queue *rx_queue;
  916. struct efx_channel *channel;
  917. efx_for_each_channel_rev(channel, efx) {
  918. if (channel->type->start)
  919. channel->type->start(channel);
  920. efx_for_each_channel_tx_queue(tx_queue, channel) {
  921. efx_init_tx_queue(tx_queue);
  922. atomic_inc(&efx->active_queues);
  923. }
  924. /* reset per-queue stats */
  925. channel->old_n_rx_hw_drops = efx_get_queue_stat_rx_hw_drops(channel);
  926. channel->old_n_rx_hw_drop_overruns = channel->n_rx_nodesc_trunc;
  927. efx_for_each_channel_rx_queue(rx_queue, channel) {
  928. efx_init_rx_queue(rx_queue);
  929. atomic_inc(&efx->active_queues);
  930. efx_stop_eventq(channel);
  931. efx_fast_push_rx_descriptors(rx_queue, false);
  932. efx_start_eventq(channel);
  933. }
  934. WARN_ON(channel->rx_pkt_n_frags);
  935. }
  936. }
  937. void efx_stop_channels(struct efx_nic *efx)
  938. {
  939. struct efx_tx_queue *tx_queue;
  940. struct efx_rx_queue *rx_queue;
  941. struct efx_channel *channel;
  942. int rc = 0;
  943. /* Stop special channels and RX refill.
  944. * The channel's stop has to be called first, since it might wait
  945. * for a sentinel RX to indicate the channel has fully drained.
  946. */
  947. efx_for_each_channel(channel, efx) {
  948. if (channel->type->stop)
  949. channel->type->stop(channel);
  950. efx_for_each_channel_rx_queue(rx_queue, channel)
  951. rx_queue->refill_enabled = false;
  952. }
  953. efx_for_each_channel(channel, efx) {
  954. /* RX packet processing is pipelined, so wait for the
  955. * NAPI handler to complete. At least event queue 0
  956. * might be kept active by non-data events, so don't
  957. * use napi_synchronize() but actually disable NAPI
  958. * temporarily.
  959. */
  960. if (efx_channel_has_rx_queue(channel)) {
  961. efx_stop_eventq(channel);
  962. efx_start_eventq(channel);
  963. }
  964. }
  965. if (efx->type->fini_dmaq)
  966. rc = efx->type->fini_dmaq(efx);
  967. if (rc) {
  968. netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
  969. } else {
  970. netif_dbg(efx, drv, efx->net_dev,
  971. "successfully flushed all queues\n");
  972. }
  973. efx_for_each_channel(channel, efx) {
  974. efx_for_each_channel_rx_queue(rx_queue, channel)
  975. efx_fini_rx_queue(rx_queue);
  976. efx_for_each_channel_tx_queue(tx_queue, channel)
  977. efx_fini_tx_queue(tx_queue);
  978. }
  979. }
  980. /**************************************************************************
  981. *
  982. * NAPI interface
  983. *
  984. *************************************************************************/
  985. /* Process channel's event queue
  986. *
  987. * This function is responsible for processing the event queue of a
  988. * single channel. The caller must guarantee that this function will
  989. * never be concurrently called more than once on the same channel,
  990. * though different channels may be being processed concurrently.
  991. */
  992. static int efx_process_channel(struct efx_channel *channel, int budget)
  993. {
  994. struct efx_tx_queue *tx_queue;
  995. struct list_head rx_list;
  996. int spent;
  997. if (unlikely(!channel->enabled))
  998. return 0;
  999. /* Prepare the batch receive list */
  1000. EFX_WARN_ON_PARANOID(channel->rx_list != NULL);
  1001. INIT_LIST_HEAD(&rx_list);
  1002. channel->rx_list = &rx_list;
  1003. efx_for_each_channel_tx_queue(tx_queue, channel) {
  1004. tx_queue->pkts_compl = 0;
  1005. tx_queue->bytes_compl = 0;
  1006. }
  1007. spent = efx_nic_process_eventq(channel, budget);
  1008. if (spent && efx_channel_has_rx_queue(channel)) {
  1009. struct efx_rx_queue *rx_queue =
  1010. efx_channel_get_rx_queue(channel);
  1011. efx_rx_flush_packet(channel);
  1012. efx_fast_push_rx_descriptors(rx_queue, true);
  1013. }
  1014. /* Update BQL */
  1015. efx_for_each_channel_tx_queue(tx_queue, channel) {
  1016. if (tx_queue->bytes_compl) {
  1017. netdev_tx_completed_queue(tx_queue->core_txq,
  1018. tx_queue->pkts_compl,
  1019. tx_queue->bytes_compl);
  1020. }
  1021. tx_queue->complete_packets += tx_queue->pkts_compl;
  1022. tx_queue->complete_bytes += tx_queue->bytes_compl;
  1023. }
  1024. /* Receive any packets we queued up */
  1025. netif_receive_skb_list(channel->rx_list);
  1026. channel->rx_list = NULL;
  1027. return spent;
  1028. }
  1029. static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel)
  1030. {
  1031. int step = efx->irq_mod_step_us;
  1032. if (channel->irq_mod_score < irq_adapt_low_thresh) {
  1033. if (channel->irq_moderation_us > step) {
  1034. channel->irq_moderation_us -= step;
  1035. efx->type->push_irq_moderation(channel);
  1036. }
  1037. } else if (channel->irq_mod_score > irq_adapt_high_thresh) {
  1038. if (channel->irq_moderation_us <
  1039. efx->irq_rx_moderation_us) {
  1040. channel->irq_moderation_us += step;
  1041. efx->type->push_irq_moderation(channel);
  1042. }
  1043. }
  1044. channel->irq_count = 0;
  1045. channel->irq_mod_score = 0;
  1046. }
  1047. /* NAPI poll handler
  1048. *
  1049. * NAPI guarantees serialisation of polls of the same device, which
  1050. * provides the guarantee required by efx_process_channel().
  1051. */
  1052. static int efx_poll(struct napi_struct *napi, int budget)
  1053. {
  1054. struct efx_channel *channel =
  1055. container_of(napi, struct efx_channel, napi_str);
  1056. struct efx_nic *efx = channel->efx;
  1057. #ifdef CONFIG_RFS_ACCEL
  1058. unsigned int time;
  1059. #endif
  1060. int spent;
  1061. netif_vdbg(efx, intr, efx->net_dev,
  1062. "channel %d NAPI poll executing on CPU %d\n",
  1063. channel->channel, raw_smp_processor_id());
  1064. spent = efx_process_channel(channel, budget);
  1065. if (budget)
  1066. xdp_do_flush();
  1067. if (spent < budget) {
  1068. if (efx_channel_has_rx_queue(channel) &&
  1069. efx->irq_rx_adaptive &&
  1070. unlikely(++channel->irq_count == 1000)) {
  1071. efx_update_irq_mod(efx, channel);
  1072. }
  1073. #ifdef CONFIG_RFS_ACCEL
  1074. /* Perhaps expire some ARFS filters */
  1075. time = jiffies - channel->rfs_last_expiry;
  1076. /* Would our quota be >= 20? */
  1077. if (channel->rfs_filter_count * time >= 600 * HZ)
  1078. mod_delayed_work(system_percpu_wq, &channel->filter_work, 0);
  1079. #endif
  1080. /* There is no race here; although napi_disable() will
  1081. * only wait for napi_complete(), this isn't a problem
  1082. * since efx_nic_eventq_read_ack() will have no effect if
  1083. * interrupts have already been disabled.
  1084. */
  1085. if (napi_complete_done(napi, spent))
  1086. efx_nic_eventq_read_ack(channel);
  1087. }
  1088. return spent;
  1089. }
  1090. void efx_init_napi_channel(struct efx_channel *channel)
  1091. {
  1092. struct efx_nic *efx = channel->efx;
  1093. channel->napi_dev = efx->net_dev;
  1094. netif_napi_add(channel->napi_dev, &channel->napi_str, efx_poll);
  1095. }
  1096. void efx_init_napi(struct efx_nic *efx)
  1097. {
  1098. struct efx_channel *channel;
  1099. efx_for_each_channel(channel, efx)
  1100. efx_init_napi_channel(channel);
  1101. }
  1102. void efx_fini_napi_channel(struct efx_channel *channel)
  1103. {
  1104. if (channel->napi_dev)
  1105. netif_napi_del(&channel->napi_str);
  1106. channel->napi_dev = NULL;
  1107. }
  1108. void efx_fini_napi(struct efx_nic *efx)
  1109. {
  1110. struct efx_channel *channel;
  1111. efx_for_each_channel(channel, efx)
  1112. efx_fini_napi_channel(channel);
  1113. }
  1114. /***************
  1115. * Housekeeping
  1116. ***************/
  1117. static int efx_channel_dummy_op_int(struct efx_channel *channel)
  1118. {
  1119. return 0;
  1120. }
  1121. void efx_channel_dummy_op_void(struct efx_channel *channel)
  1122. {
  1123. }
  1124. static const struct efx_channel_type efx_default_channel_type = {
  1125. .pre_probe = efx_channel_dummy_op_int,
  1126. .post_remove = efx_channel_dummy_op_void,
  1127. .get_name = efx_get_channel_name,
  1128. .copy = efx_copy_channel,
  1129. .want_txqs = efx_default_channel_want_txqs,
  1130. .keep_eventq = false,
  1131. .want_pio = true,
  1132. };