efx_channels.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  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. /* 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 = kcalloc(efx->xdp_tx_queue_count,
  797. sizeof(*efx->xdp_tx_queues),
  798. GFP_KERNEL);
  799. if (!efx->xdp_tx_queues)
  800. return -ENOMEM;
  801. }
  802. efx_for_each_channel(channel, efx) {
  803. if (channel->channel < efx->n_rx_channels)
  804. channel->rx_queue.core_index = channel->channel;
  805. else
  806. channel->rx_queue.core_index = -1;
  807. }
  808. efx_set_xdp_channels(efx);
  809. rc = netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
  810. if (rc)
  811. return rc;
  812. return netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
  813. }
  814. static bool efx_default_channel_want_txqs(struct efx_channel *channel)
  815. {
  816. return channel->channel - channel->efx->tx_channel_offset <
  817. channel->efx->n_tx_channels;
  818. }
  819. /*************
  820. * START/STOP
  821. *************/
  822. int efx_soft_enable_interrupts(struct efx_nic *efx)
  823. {
  824. struct efx_channel *channel, *end_channel;
  825. int rc;
  826. BUG_ON(efx->state == STATE_DISABLED);
  827. efx->irq_soft_enabled = true;
  828. smp_wmb();
  829. efx_for_each_channel(channel, efx) {
  830. if (!channel->type->keep_eventq) {
  831. rc = efx_init_eventq(channel);
  832. if (rc)
  833. goto fail;
  834. }
  835. efx_start_eventq(channel);
  836. }
  837. efx_mcdi_mode_event(efx);
  838. return 0;
  839. fail:
  840. end_channel = channel;
  841. efx_for_each_channel(channel, efx) {
  842. if (channel == end_channel)
  843. break;
  844. efx_stop_eventq(channel);
  845. if (!channel->type->keep_eventq)
  846. efx_fini_eventq(channel);
  847. }
  848. return rc;
  849. }
  850. void efx_soft_disable_interrupts(struct efx_nic *efx)
  851. {
  852. struct efx_channel *channel;
  853. if (efx->state == STATE_DISABLED)
  854. return;
  855. efx_mcdi_mode_poll(efx);
  856. efx->irq_soft_enabled = false;
  857. smp_wmb();
  858. if (efx->legacy_irq)
  859. synchronize_irq(efx->legacy_irq);
  860. efx_for_each_channel(channel, efx) {
  861. if (channel->irq)
  862. synchronize_irq(channel->irq);
  863. efx_stop_eventq(channel);
  864. if (!channel->type->keep_eventq)
  865. efx_fini_eventq(channel);
  866. }
  867. /* Flush the asynchronous MCDI request queue */
  868. efx_mcdi_flush_async(efx);
  869. }
  870. int efx_enable_interrupts(struct efx_nic *efx)
  871. {
  872. struct efx_channel *channel, *end_channel;
  873. int rc;
  874. /* TODO: Is this really a bug? */
  875. BUG_ON(efx->state == STATE_DISABLED);
  876. if (efx->eeh_disabled_legacy_irq) {
  877. enable_irq(efx->legacy_irq);
  878. efx->eeh_disabled_legacy_irq = false;
  879. }
  880. efx->type->irq_enable_master(efx);
  881. efx_for_each_channel(channel, efx) {
  882. if (channel->type->keep_eventq) {
  883. rc = efx_init_eventq(channel);
  884. if (rc)
  885. goto fail;
  886. }
  887. }
  888. rc = efx_soft_enable_interrupts(efx);
  889. if (rc)
  890. goto fail;
  891. return 0;
  892. fail:
  893. end_channel = channel;
  894. efx_for_each_channel(channel, efx) {
  895. if (channel == end_channel)
  896. break;
  897. if (channel->type->keep_eventq)
  898. efx_fini_eventq(channel);
  899. }
  900. efx->type->irq_disable_non_ev(efx);
  901. return rc;
  902. }
  903. void efx_disable_interrupts(struct efx_nic *efx)
  904. {
  905. struct efx_channel *channel;
  906. efx_soft_disable_interrupts(efx);
  907. efx_for_each_channel(channel, efx) {
  908. if (channel->type->keep_eventq)
  909. efx_fini_eventq(channel);
  910. }
  911. efx->type->irq_disable_non_ev(efx);
  912. }
  913. void efx_start_channels(struct efx_nic *efx)
  914. {
  915. struct efx_tx_queue *tx_queue;
  916. struct efx_rx_queue *rx_queue;
  917. struct efx_channel *channel;
  918. efx_for_each_channel_rev(channel, efx) {
  919. if (channel->type->start)
  920. channel->type->start(channel);
  921. efx_for_each_channel_tx_queue(tx_queue, channel) {
  922. efx_init_tx_queue(tx_queue);
  923. atomic_inc(&efx->active_queues);
  924. }
  925. efx_for_each_channel_rx_queue(rx_queue, channel) {
  926. efx_init_rx_queue(rx_queue);
  927. atomic_inc(&efx->active_queues);
  928. efx_stop_eventq(channel);
  929. efx_fast_push_rx_descriptors(rx_queue, false);
  930. efx_start_eventq(channel);
  931. }
  932. WARN_ON(channel->rx_pkt_n_frags);
  933. }
  934. }
  935. void efx_stop_channels(struct efx_nic *efx)
  936. {
  937. struct efx_tx_queue *tx_queue;
  938. struct efx_rx_queue *rx_queue;
  939. struct efx_channel *channel;
  940. int rc = 0;
  941. /* Stop special channels and RX refill.
  942. * The channel's stop has to be called first, since it might wait
  943. * for a sentinel RX to indicate the channel has fully drained.
  944. */
  945. efx_for_each_channel(channel, efx) {
  946. if (channel->type->stop)
  947. channel->type->stop(channel);
  948. efx_for_each_channel_rx_queue(rx_queue, channel)
  949. rx_queue->refill_enabled = false;
  950. }
  951. efx_for_each_channel(channel, efx) {
  952. /* RX packet processing is pipelined, so wait for the
  953. * NAPI handler to complete. At least event queue 0
  954. * might be kept active by non-data events, so don't
  955. * use napi_synchronize() but actually disable NAPI
  956. * temporarily.
  957. */
  958. if (efx_channel_has_rx_queue(channel)) {
  959. efx_stop_eventq(channel);
  960. efx_start_eventq(channel);
  961. }
  962. }
  963. if (efx->type->fini_dmaq)
  964. rc = efx->type->fini_dmaq(efx);
  965. if (rc) {
  966. netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
  967. } else {
  968. netif_dbg(efx, drv, efx->net_dev,
  969. "successfully flushed all queues\n");
  970. }
  971. efx_for_each_channel(channel, efx) {
  972. efx_for_each_channel_rx_queue(rx_queue, channel)
  973. efx_fini_rx_queue(rx_queue);
  974. efx_for_each_channel_tx_queue(tx_queue, channel)
  975. efx_fini_tx_queue(tx_queue);
  976. }
  977. }
  978. /**************************************************************************
  979. *
  980. * NAPI interface
  981. *
  982. *************************************************************************/
  983. /* Process channel's event queue
  984. *
  985. * This function is responsible for processing the event queue of a
  986. * single channel. The caller must guarantee that this function will
  987. * never be concurrently called more than once on the same channel,
  988. * though different channels may be being processed concurrently.
  989. */
  990. static int efx_process_channel(struct efx_channel *channel, int budget)
  991. {
  992. struct efx_tx_queue *tx_queue;
  993. struct list_head rx_list;
  994. int spent;
  995. if (unlikely(!channel->enabled))
  996. return 0;
  997. /* Prepare the batch receive list */
  998. EFX_WARN_ON_PARANOID(channel->rx_list != NULL);
  999. INIT_LIST_HEAD(&rx_list);
  1000. channel->rx_list = &rx_list;
  1001. efx_for_each_channel_tx_queue(tx_queue, channel) {
  1002. tx_queue->pkts_compl = 0;
  1003. tx_queue->bytes_compl = 0;
  1004. }
  1005. spent = efx_nic_process_eventq(channel, budget);
  1006. if (spent && efx_channel_has_rx_queue(channel)) {
  1007. struct efx_rx_queue *rx_queue =
  1008. efx_channel_get_rx_queue(channel);
  1009. efx_rx_flush_packet(channel);
  1010. efx_fast_push_rx_descriptors(rx_queue, true);
  1011. }
  1012. /* Update BQL */
  1013. efx_for_each_channel_tx_queue(tx_queue, channel) {
  1014. if (tx_queue->bytes_compl) {
  1015. netdev_tx_completed_queue(tx_queue->core_txq,
  1016. tx_queue->pkts_compl,
  1017. tx_queue->bytes_compl);
  1018. }
  1019. }
  1020. /* Receive any packets we queued up */
  1021. netif_receive_skb_list(channel->rx_list);
  1022. channel->rx_list = NULL;
  1023. return spent;
  1024. }
  1025. static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel)
  1026. {
  1027. int step = efx->irq_mod_step_us;
  1028. if (channel->irq_mod_score < irq_adapt_low_thresh) {
  1029. if (channel->irq_moderation_us > step) {
  1030. channel->irq_moderation_us -= step;
  1031. efx->type->push_irq_moderation(channel);
  1032. }
  1033. } else if (channel->irq_mod_score > irq_adapt_high_thresh) {
  1034. if (channel->irq_moderation_us <
  1035. efx->irq_rx_moderation_us) {
  1036. channel->irq_moderation_us += step;
  1037. efx->type->push_irq_moderation(channel);
  1038. }
  1039. }
  1040. channel->irq_count = 0;
  1041. channel->irq_mod_score = 0;
  1042. }
  1043. /* NAPI poll handler
  1044. *
  1045. * NAPI guarantees serialisation of polls of the same device, which
  1046. * provides the guarantee required by efx_process_channel().
  1047. */
  1048. static int efx_poll(struct napi_struct *napi, int budget)
  1049. {
  1050. struct efx_channel *channel =
  1051. container_of(napi, struct efx_channel, napi_str);
  1052. struct efx_nic *efx = channel->efx;
  1053. #ifdef CONFIG_RFS_ACCEL
  1054. unsigned int time;
  1055. #endif
  1056. int spent;
  1057. netif_vdbg(efx, intr, efx->net_dev,
  1058. "channel %d NAPI poll executing on CPU %d\n",
  1059. channel->channel, raw_smp_processor_id());
  1060. spent = efx_process_channel(channel, budget);
  1061. if (budget)
  1062. xdp_do_flush();
  1063. if (spent < budget) {
  1064. if (efx_channel_has_rx_queue(channel) &&
  1065. efx->irq_rx_adaptive &&
  1066. unlikely(++channel->irq_count == 1000)) {
  1067. efx_update_irq_mod(efx, channel);
  1068. }
  1069. #ifdef CONFIG_RFS_ACCEL
  1070. /* Perhaps expire some ARFS filters */
  1071. time = jiffies - channel->rfs_last_expiry;
  1072. /* Would our quota be >= 20? */
  1073. if (channel->rfs_filter_count * time >= 600 * HZ)
  1074. mod_delayed_work(system_wq, &channel->filter_work, 0);
  1075. #endif
  1076. /* There is no race here; although napi_disable() will
  1077. * only wait for napi_complete(), this isn't a problem
  1078. * since efx_nic_eventq_read_ack() will have no effect if
  1079. * interrupts have already been disabled.
  1080. */
  1081. if (napi_complete_done(napi, spent))
  1082. efx_nic_eventq_read_ack(channel);
  1083. }
  1084. return spent;
  1085. }
  1086. void efx_init_napi_channel(struct efx_channel *channel)
  1087. {
  1088. struct efx_nic *efx = channel->efx;
  1089. channel->napi_dev = efx->net_dev;
  1090. netif_napi_add(channel->napi_dev, &channel->napi_str, efx_poll);
  1091. }
  1092. void efx_init_napi(struct efx_nic *efx)
  1093. {
  1094. struct efx_channel *channel;
  1095. efx_for_each_channel(channel, efx)
  1096. efx_init_napi_channel(channel);
  1097. }
  1098. void efx_fini_napi_channel(struct efx_channel *channel)
  1099. {
  1100. if (channel->napi_dev)
  1101. netif_napi_del(&channel->napi_str);
  1102. channel->napi_dev = NULL;
  1103. }
  1104. void efx_fini_napi(struct efx_nic *efx)
  1105. {
  1106. struct efx_channel *channel;
  1107. efx_for_each_channel(channel, efx)
  1108. efx_fini_napi_channel(channel);
  1109. }
  1110. /***************
  1111. * Housekeeping
  1112. ***************/
  1113. static int efx_channel_dummy_op_int(struct efx_channel *channel)
  1114. {
  1115. return 0;
  1116. }
  1117. void efx_channel_dummy_op_void(struct efx_channel *channel)
  1118. {
  1119. }
  1120. static const struct efx_channel_type efx_default_channel_type = {
  1121. .pre_probe = efx_channel_dummy_op_int,
  1122. .post_remove = efx_channel_dummy_op_void,
  1123. .get_name = efx_get_channel_name,
  1124. .copy = efx_copy_channel,
  1125. .want_txqs = efx_default_channel_want_txqs,
  1126. .keep_eventq = false,
  1127. .want_pio = true,
  1128. };