efx_channels.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  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. min(max(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(sizeof(*channel), GFP_KERNEL);
  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(sizeof(*channel), GFP_KERNEL);
  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. /* Restart special buffer allocation */
  603. efx->next_buffer_table = 0;
  604. /* Probe channels in reverse, so that any 'extra' channels
  605. * use the start of the buffer table. This allows the traffic
  606. * channels to be resized without moving them or wasting the
  607. * entries before them.
  608. */
  609. efx_for_each_channel_rev(channel, efx) {
  610. rc = efx_probe_channel(channel);
  611. if (rc) {
  612. netif_err(efx, probe, efx->net_dev,
  613. "failed to create channel %d\n",
  614. channel->channel);
  615. goto fail;
  616. }
  617. }
  618. efx_set_channel_names(efx);
  619. return 0;
  620. fail:
  621. efx_remove_channels(efx);
  622. return rc;
  623. }
  624. void efx_remove_channel(struct efx_channel *channel)
  625. {
  626. struct efx_tx_queue *tx_queue;
  627. struct efx_rx_queue *rx_queue;
  628. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  629. "destroy chan %d\n", channel->channel);
  630. efx_for_each_channel_rx_queue(rx_queue, channel)
  631. efx_remove_rx_queue(rx_queue);
  632. efx_for_each_channel_tx_queue(tx_queue, channel)
  633. efx_remove_tx_queue(tx_queue);
  634. efx_remove_eventq(channel);
  635. channel->type->post_remove(channel);
  636. }
  637. void efx_remove_channels(struct efx_nic *efx)
  638. {
  639. struct efx_channel *channel;
  640. efx_for_each_channel(channel, efx)
  641. efx_remove_channel(channel);
  642. kfree(efx->xdp_tx_queues);
  643. }
  644. static int efx_set_xdp_tx_queue(struct efx_nic *efx, int xdp_queue_number,
  645. struct efx_tx_queue *tx_queue)
  646. {
  647. if (xdp_queue_number >= efx->xdp_tx_queue_count)
  648. return -EINVAL;
  649. netif_dbg(efx, drv, efx->net_dev,
  650. "Channel %u TXQ %u is XDP %u, HW %u\n",
  651. tx_queue->channel->channel, tx_queue->label,
  652. xdp_queue_number, tx_queue->queue);
  653. efx->xdp_tx_queues[xdp_queue_number] = tx_queue;
  654. return 0;
  655. }
  656. static void efx_set_xdp_channels(struct efx_nic *efx)
  657. {
  658. struct efx_tx_queue *tx_queue;
  659. struct efx_channel *channel;
  660. unsigned int next_queue = 0;
  661. int xdp_queue_number = 0;
  662. int rc;
  663. /* We need to mark which channels really have RX and TX
  664. * queues, and adjust the TX queue numbers if we have separate
  665. * RX-only and TX-only channels.
  666. */
  667. efx_for_each_channel(channel, efx) {
  668. if (channel->channel < efx->tx_channel_offset)
  669. continue;
  670. if (efx_channel_is_xdp_tx(channel)) {
  671. efx_for_each_channel_tx_queue(tx_queue, channel) {
  672. tx_queue->queue = next_queue++;
  673. rc = efx_set_xdp_tx_queue(efx, xdp_queue_number,
  674. tx_queue);
  675. if (rc == 0)
  676. xdp_queue_number++;
  677. }
  678. } else {
  679. efx_for_each_channel_tx_queue(tx_queue, channel) {
  680. tx_queue->queue = next_queue++;
  681. netif_dbg(efx, drv, efx->net_dev,
  682. "Channel %u TXQ %u is HW %u\n",
  683. channel->channel, tx_queue->label,
  684. tx_queue->queue);
  685. }
  686. /* If XDP is borrowing queues from net stack, it must
  687. * use the queue with no csum offload, which is the
  688. * first one of the channel
  689. * (note: tx_queue_by_type is not initialized yet)
  690. */
  691. if (efx->xdp_txq_queues_mode ==
  692. EFX_XDP_TX_QUEUES_BORROWED) {
  693. tx_queue = &channel->tx_queue[0];
  694. rc = efx_set_xdp_tx_queue(efx, xdp_queue_number,
  695. tx_queue);
  696. if (rc == 0)
  697. xdp_queue_number++;
  698. }
  699. }
  700. }
  701. WARN_ON(efx->xdp_txq_queues_mode == EFX_XDP_TX_QUEUES_DEDICATED &&
  702. xdp_queue_number != efx->xdp_tx_queue_count);
  703. WARN_ON(efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_DEDICATED &&
  704. xdp_queue_number > efx->xdp_tx_queue_count);
  705. /* If we have more CPUs than assigned XDP TX queues, assign the already
  706. * existing queues to the exceeding CPUs
  707. */
  708. next_queue = 0;
  709. while (xdp_queue_number < efx->xdp_tx_queue_count) {
  710. tx_queue = efx->xdp_tx_queues[next_queue++];
  711. rc = efx_set_xdp_tx_queue(efx, xdp_queue_number, tx_queue);
  712. if (rc == 0)
  713. xdp_queue_number++;
  714. }
  715. }
  716. int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
  717. {
  718. struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel,
  719. *ptp_channel = efx_ptp_channel(efx);
  720. struct efx_ptp_data *ptp_data = efx->ptp_data;
  721. unsigned int i, next_buffer_table = 0;
  722. u32 old_rxq_entries, old_txq_entries;
  723. int rc, rc2;
  724. rc = efx_check_disabled(efx);
  725. if (rc)
  726. return rc;
  727. /* Not all channels should be reallocated. We must avoid
  728. * reallocating their buffer table entries.
  729. */
  730. efx_for_each_channel(channel, efx) {
  731. struct efx_rx_queue *rx_queue;
  732. struct efx_tx_queue *tx_queue;
  733. if (channel->type->copy)
  734. continue;
  735. next_buffer_table = max(next_buffer_table,
  736. channel->eventq.index +
  737. channel->eventq.entries);
  738. efx_for_each_channel_rx_queue(rx_queue, channel)
  739. next_buffer_table = max(next_buffer_table,
  740. rx_queue->rxd.index +
  741. rx_queue->rxd.entries);
  742. efx_for_each_channel_tx_queue(tx_queue, channel)
  743. next_buffer_table = max(next_buffer_table,
  744. tx_queue->txd.index +
  745. tx_queue->txd.entries);
  746. }
  747. efx_device_detach_sync(efx);
  748. efx_stop_all(efx);
  749. efx_soft_disable_interrupts(efx);
  750. /* Clone channels (where possible) */
  751. memset(other_channel, 0, sizeof(other_channel));
  752. for (i = 0; i < efx->n_channels; i++) {
  753. channel = efx->channel[i];
  754. if (channel->type->copy)
  755. channel = channel->type->copy(channel);
  756. if (!channel) {
  757. rc = -ENOMEM;
  758. goto out;
  759. }
  760. other_channel[i] = channel;
  761. }
  762. /* Swap entry counts and channel pointers */
  763. old_rxq_entries = efx->rxq_entries;
  764. old_txq_entries = efx->txq_entries;
  765. efx->rxq_entries = rxq_entries;
  766. efx->txq_entries = txq_entries;
  767. for (i = 0; i < efx->n_channels; i++)
  768. swap(efx->channel[i], other_channel[i]);
  769. /* Restart buffer table allocation */
  770. efx->next_buffer_table = next_buffer_table;
  771. for (i = 0; i < efx->n_channels; i++) {
  772. channel = efx->channel[i];
  773. if (!channel->type->copy)
  774. continue;
  775. rc = efx_probe_channel(channel);
  776. if (rc)
  777. goto rollback;
  778. efx_init_napi_channel(efx->channel[i]);
  779. }
  780. efx_set_xdp_channels(efx);
  781. out:
  782. efx->ptp_data = NULL;
  783. /* Destroy unused channel structures */
  784. for (i = 0; i < efx->n_channels; i++) {
  785. channel = other_channel[i];
  786. if (channel && channel->type->copy) {
  787. efx_fini_napi_channel(channel);
  788. efx_remove_channel(channel);
  789. kfree(channel);
  790. }
  791. }
  792. efx->ptp_data = ptp_data;
  793. rc2 = efx_soft_enable_interrupts(efx);
  794. if (rc2) {
  795. rc = rc ? rc : rc2;
  796. netif_err(efx, drv, efx->net_dev,
  797. "unable to restart interrupts on channel reallocation\n");
  798. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  799. } else {
  800. efx_start_all(efx);
  801. efx_device_attach_if_not_resetting(efx);
  802. }
  803. return rc;
  804. rollback:
  805. /* Swap back */
  806. efx->rxq_entries = old_rxq_entries;
  807. efx->txq_entries = old_txq_entries;
  808. for (i = 0; i < efx->n_channels; i++)
  809. swap(efx->channel[i], other_channel[i]);
  810. efx_ptp_update_channel(efx, ptp_channel);
  811. goto out;
  812. }
  813. int efx_set_channels(struct efx_nic *efx)
  814. {
  815. struct efx_channel *channel;
  816. int rc;
  817. if (efx->xdp_tx_queue_count) {
  818. EFX_WARN_ON_PARANOID(efx->xdp_tx_queues);
  819. /* Allocate array for XDP TX queue lookup. */
  820. efx->xdp_tx_queues = kcalloc(efx->xdp_tx_queue_count,
  821. sizeof(*efx->xdp_tx_queues),
  822. GFP_KERNEL);
  823. if (!efx->xdp_tx_queues)
  824. return -ENOMEM;
  825. }
  826. efx_for_each_channel(channel, efx) {
  827. if (channel->channel < efx->n_rx_channels)
  828. channel->rx_queue.core_index = channel->channel;
  829. else
  830. channel->rx_queue.core_index = -1;
  831. }
  832. efx_set_xdp_channels(efx);
  833. rc = netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
  834. if (rc)
  835. return rc;
  836. return netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
  837. }
  838. static bool efx_default_channel_want_txqs(struct efx_channel *channel)
  839. {
  840. return channel->channel - channel->efx->tx_channel_offset <
  841. channel->efx->n_tx_channels;
  842. }
  843. /*************
  844. * START/STOP
  845. *************/
  846. int efx_soft_enable_interrupts(struct efx_nic *efx)
  847. {
  848. struct efx_channel *channel, *end_channel;
  849. int rc;
  850. BUG_ON(efx->state == STATE_DISABLED);
  851. efx->irq_soft_enabled = true;
  852. smp_wmb();
  853. efx_for_each_channel(channel, efx) {
  854. if (!channel->type->keep_eventq) {
  855. rc = efx_init_eventq(channel);
  856. if (rc)
  857. goto fail;
  858. }
  859. efx_start_eventq(channel);
  860. }
  861. efx_mcdi_mode_event(efx);
  862. return 0;
  863. fail:
  864. end_channel = channel;
  865. efx_for_each_channel(channel, efx) {
  866. if (channel == end_channel)
  867. break;
  868. efx_stop_eventq(channel);
  869. if (!channel->type->keep_eventq)
  870. efx_fini_eventq(channel);
  871. }
  872. return rc;
  873. }
  874. void efx_soft_disable_interrupts(struct efx_nic *efx)
  875. {
  876. struct efx_channel *channel;
  877. if (efx->state == STATE_DISABLED)
  878. return;
  879. efx_mcdi_mode_poll(efx);
  880. efx->irq_soft_enabled = false;
  881. smp_wmb();
  882. if (efx->legacy_irq)
  883. synchronize_irq(efx->legacy_irq);
  884. efx_for_each_channel(channel, efx) {
  885. if (channel->irq)
  886. synchronize_irq(channel->irq);
  887. efx_stop_eventq(channel);
  888. if (!channel->type->keep_eventq)
  889. efx_fini_eventq(channel);
  890. }
  891. /* Flush the asynchronous MCDI request queue */
  892. efx_mcdi_flush_async(efx);
  893. }
  894. int efx_enable_interrupts(struct efx_nic *efx)
  895. {
  896. struct efx_channel *channel, *end_channel;
  897. int rc;
  898. /* TODO: Is this really a bug? */
  899. BUG_ON(efx->state == STATE_DISABLED);
  900. if (efx->eeh_disabled_legacy_irq) {
  901. enable_irq(efx->legacy_irq);
  902. efx->eeh_disabled_legacy_irq = false;
  903. }
  904. efx->type->irq_enable_master(efx);
  905. efx_for_each_channel(channel, efx) {
  906. if (channel->type->keep_eventq) {
  907. rc = efx_init_eventq(channel);
  908. if (rc)
  909. goto fail;
  910. }
  911. }
  912. rc = efx_soft_enable_interrupts(efx);
  913. if (rc)
  914. goto fail;
  915. return 0;
  916. fail:
  917. end_channel = channel;
  918. efx_for_each_channel(channel, efx) {
  919. if (channel == end_channel)
  920. break;
  921. if (channel->type->keep_eventq)
  922. efx_fini_eventq(channel);
  923. }
  924. efx->type->irq_disable_non_ev(efx);
  925. return rc;
  926. }
  927. void efx_disable_interrupts(struct efx_nic *efx)
  928. {
  929. struct efx_channel *channel;
  930. efx_soft_disable_interrupts(efx);
  931. efx_for_each_channel(channel, efx) {
  932. if (channel->type->keep_eventq)
  933. efx_fini_eventq(channel);
  934. }
  935. efx->type->irq_disable_non_ev(efx);
  936. }
  937. void efx_start_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. efx_for_each_channel_rev(channel, efx) {
  943. efx_for_each_channel_tx_queue(tx_queue, channel) {
  944. efx_init_tx_queue(tx_queue);
  945. atomic_inc(&efx->active_queues);
  946. }
  947. efx_for_each_channel_rx_queue(rx_queue, channel) {
  948. efx_init_rx_queue(rx_queue);
  949. atomic_inc(&efx->active_queues);
  950. efx_stop_eventq(channel);
  951. efx_fast_push_rx_descriptors(rx_queue, false);
  952. efx_start_eventq(channel);
  953. }
  954. WARN_ON(channel->rx_pkt_n_frags);
  955. }
  956. }
  957. void efx_stop_channels(struct efx_nic *efx)
  958. {
  959. struct efx_tx_queue *tx_queue;
  960. struct efx_rx_queue *rx_queue;
  961. struct efx_channel *channel;
  962. int rc = 0;
  963. /* Stop RX refill */
  964. efx_for_each_channel(channel, efx) {
  965. efx_for_each_channel_rx_queue(rx_queue, channel)
  966. rx_queue->refill_enabled = false;
  967. }
  968. efx_for_each_channel(channel, efx) {
  969. /* RX packet processing is pipelined, so wait for the
  970. * NAPI handler to complete. At least event queue 0
  971. * might be kept active by non-data events, so don't
  972. * use napi_synchronize() but actually disable NAPI
  973. * temporarily.
  974. */
  975. if (efx_channel_has_rx_queue(channel)) {
  976. efx_stop_eventq(channel);
  977. efx_start_eventq(channel);
  978. }
  979. }
  980. if (efx->type->fini_dmaq)
  981. rc = efx->type->fini_dmaq(efx);
  982. if (rc) {
  983. netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
  984. } else {
  985. netif_dbg(efx, drv, efx->net_dev,
  986. "successfully flushed all queues\n");
  987. }
  988. efx_for_each_channel(channel, efx) {
  989. efx_for_each_channel_rx_queue(rx_queue, channel)
  990. efx_fini_rx_queue(rx_queue);
  991. efx_for_each_channel_tx_queue(tx_queue, channel)
  992. efx_fini_tx_queue(tx_queue);
  993. }
  994. }
  995. /**************************************************************************
  996. *
  997. * NAPI interface
  998. *
  999. *************************************************************************/
  1000. /* Process channel's event queue
  1001. *
  1002. * This function is responsible for processing the event queue of a
  1003. * single channel. The caller must guarantee that this function will
  1004. * never be concurrently called more than once on the same channel,
  1005. * though different channels may be being processed concurrently.
  1006. */
  1007. static int efx_process_channel(struct efx_channel *channel, int budget)
  1008. {
  1009. struct efx_tx_queue *tx_queue;
  1010. struct list_head rx_list;
  1011. int spent;
  1012. if (unlikely(!channel->enabled))
  1013. return 0;
  1014. /* Prepare the batch receive list */
  1015. EFX_WARN_ON_PARANOID(channel->rx_list != NULL);
  1016. INIT_LIST_HEAD(&rx_list);
  1017. channel->rx_list = &rx_list;
  1018. efx_for_each_channel_tx_queue(tx_queue, channel) {
  1019. tx_queue->pkts_compl = 0;
  1020. tx_queue->bytes_compl = 0;
  1021. }
  1022. spent = efx_nic_process_eventq(channel, budget);
  1023. if (spent && efx_channel_has_rx_queue(channel)) {
  1024. struct efx_rx_queue *rx_queue =
  1025. efx_channel_get_rx_queue(channel);
  1026. efx_rx_flush_packet(channel);
  1027. efx_fast_push_rx_descriptors(rx_queue, true);
  1028. }
  1029. /* Update BQL */
  1030. efx_for_each_channel_tx_queue(tx_queue, channel) {
  1031. if (tx_queue->bytes_compl) {
  1032. netdev_tx_completed_queue(tx_queue->core_txq,
  1033. tx_queue->pkts_compl,
  1034. tx_queue->bytes_compl);
  1035. }
  1036. }
  1037. /* Receive any packets we queued up */
  1038. netif_receive_skb_list(channel->rx_list);
  1039. channel->rx_list = NULL;
  1040. return spent;
  1041. }
  1042. static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel)
  1043. {
  1044. int step = efx->irq_mod_step_us;
  1045. if (channel->irq_mod_score < irq_adapt_low_thresh) {
  1046. if (channel->irq_moderation_us > step) {
  1047. channel->irq_moderation_us -= step;
  1048. efx->type->push_irq_moderation(channel);
  1049. }
  1050. } else if (channel->irq_mod_score > irq_adapt_high_thresh) {
  1051. if (channel->irq_moderation_us <
  1052. efx->irq_rx_moderation_us) {
  1053. channel->irq_moderation_us += step;
  1054. efx->type->push_irq_moderation(channel);
  1055. }
  1056. }
  1057. channel->irq_count = 0;
  1058. channel->irq_mod_score = 0;
  1059. }
  1060. /* NAPI poll handler
  1061. *
  1062. * NAPI guarantees serialisation of polls of the same device, which
  1063. * provides the guarantee required by efx_process_channel().
  1064. */
  1065. static int efx_poll(struct napi_struct *napi, int budget)
  1066. {
  1067. struct efx_channel *channel =
  1068. container_of(napi, struct efx_channel, napi_str);
  1069. struct efx_nic *efx = channel->efx;
  1070. #ifdef CONFIG_RFS_ACCEL
  1071. unsigned int time;
  1072. #endif
  1073. int spent;
  1074. netif_vdbg(efx, intr, efx->net_dev,
  1075. "channel %d NAPI poll executing on CPU %d\n",
  1076. channel->channel, raw_smp_processor_id());
  1077. spent = efx_process_channel(channel, budget);
  1078. xdp_do_flush_map();
  1079. if (spent < budget) {
  1080. if (efx_channel_has_rx_queue(channel) &&
  1081. efx->irq_rx_adaptive &&
  1082. unlikely(++channel->irq_count == 1000)) {
  1083. efx_update_irq_mod(efx, channel);
  1084. }
  1085. #ifdef CONFIG_RFS_ACCEL
  1086. /* Perhaps expire some ARFS filters */
  1087. time = jiffies - channel->rfs_last_expiry;
  1088. /* Would our quota be >= 20? */
  1089. if (channel->rfs_filter_count * time >= 600 * HZ)
  1090. mod_delayed_work(system_wq, &channel->filter_work, 0);
  1091. #endif
  1092. /* There is no race here; although napi_disable() will
  1093. * only wait for napi_complete(), this isn't a problem
  1094. * since efx_nic_eventq_read_ack() will have no effect if
  1095. * interrupts have already been disabled.
  1096. */
  1097. if (napi_complete_done(napi, spent))
  1098. efx_nic_eventq_read_ack(channel);
  1099. }
  1100. return spent;
  1101. }
  1102. void efx_init_napi_channel(struct efx_channel *channel)
  1103. {
  1104. struct efx_nic *efx = channel->efx;
  1105. channel->napi_dev = efx->net_dev;
  1106. netif_napi_add(channel->napi_dev, &channel->napi_str, efx_poll);
  1107. }
  1108. void efx_init_napi(struct efx_nic *efx)
  1109. {
  1110. struct efx_channel *channel;
  1111. efx_for_each_channel(channel, efx)
  1112. efx_init_napi_channel(channel);
  1113. }
  1114. void efx_fini_napi_channel(struct efx_channel *channel)
  1115. {
  1116. if (channel->napi_dev)
  1117. netif_napi_del(&channel->napi_str);
  1118. channel->napi_dev = NULL;
  1119. }
  1120. void efx_fini_napi(struct efx_nic *efx)
  1121. {
  1122. struct efx_channel *channel;
  1123. efx_for_each_channel(channel, efx)
  1124. efx_fini_napi_channel(channel);
  1125. }
  1126. /***************
  1127. * Housekeeping
  1128. ***************/
  1129. static int efx_channel_dummy_op_int(struct efx_channel *channel)
  1130. {
  1131. return 0;
  1132. }
  1133. void efx_channel_dummy_op_void(struct efx_channel *channel)
  1134. {
  1135. }
  1136. static const struct efx_channel_type efx_default_channel_type = {
  1137. .pre_probe = efx_channel_dummy_op_int,
  1138. .post_remove = efx_channel_dummy_op_void,
  1139. .get_name = efx_get_channel_name,
  1140. .copy = efx_copy_channel,
  1141. .want_txqs = efx_default_channel_want_txqs,
  1142. .keep_eventq = false,
  1143. .want_pio = true,
  1144. };