efx_channels.c 35 KB

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