rx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2005-2011 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 <linux/socket.h>
  11. #include <linux/in.h>
  12. #include <linux/slab.h>
  13. #include <linux/ip.h>
  14. #include <linux/tcp.h>
  15. #include <linux/udp.h>
  16. #include <linux/prefetch.h>
  17. #include <linux/moduleparam.h>
  18. #include <net/ip.h>
  19. #include <net/checksum.h>
  20. #include "net_driver.h"
  21. #include "efx.h"
  22. #include "nic.h"
  23. #include "selftest.h"
  24. #include "workarounds.h"
  25. /* Number of RX descriptors pushed at once. */
  26. #define EFX_RX_BATCH 8
  27. /* Maximum size of a buffer sharing a page */
  28. #define EFX_RX_HALF_PAGE ((PAGE_SIZE >> 1) - sizeof(struct efx_rx_page_state))
  29. /* Size of buffer allocated for skb header area. */
  30. #define EFX_SKB_HEADERS 64u
  31. /* This is the percentage fill level below which new RX descriptors
  32. * will be added to the RX descriptor ring.
  33. */
  34. static unsigned int rx_refill_threshold;
  35. /*
  36. * RX maximum head room required.
  37. *
  38. * This must be at least 1 to prevent overflow and at least 2 to allow
  39. * pipelined receives.
  40. */
  41. #define EFX_RXD_HEAD_ROOM 2
  42. /* Offset of ethernet header within page */
  43. static inline unsigned int efx_rx_buf_offset(struct efx_nic *efx,
  44. struct efx_rx_buffer *buf)
  45. {
  46. return buf->page_offset + efx->type->rx_buffer_hash_size;
  47. }
  48. static inline unsigned int efx_rx_buf_size(struct efx_nic *efx)
  49. {
  50. return PAGE_SIZE << efx->rx_buffer_order;
  51. }
  52. static u8 *efx_rx_buf_eh(struct efx_nic *efx, struct efx_rx_buffer *buf)
  53. {
  54. return page_address(buf->page) + efx_rx_buf_offset(efx, buf);
  55. }
  56. static inline u32 efx_rx_buf_hash(const u8 *eh)
  57. {
  58. /* The ethernet header is always directly after any hash. */
  59. #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) || NET_IP_ALIGN % 4 == 0
  60. return __le32_to_cpup((const __le32 *)(eh - 4));
  61. #else
  62. const u8 *data = eh - 4;
  63. return (u32)data[0] |
  64. (u32)data[1] << 8 |
  65. (u32)data[2] << 16 |
  66. (u32)data[3] << 24;
  67. #endif
  68. }
  69. /**
  70. * efx_init_rx_buffers - create EFX_RX_BATCH page-based RX buffers
  71. *
  72. * @rx_queue: Efx RX queue
  73. *
  74. * This allocates memory for EFX_RX_BATCH receive buffers, maps them for DMA,
  75. * and populates struct efx_rx_buffers for each one. Return a negative error
  76. * code or 0 on success. If a single page can be split between two buffers,
  77. * then the page will either be inserted fully, or not at at all.
  78. */
  79. static int efx_init_rx_buffers(struct efx_rx_queue *rx_queue)
  80. {
  81. struct efx_nic *efx = rx_queue->efx;
  82. struct efx_rx_buffer *rx_buf;
  83. struct page *page;
  84. unsigned int page_offset;
  85. struct efx_rx_page_state *state;
  86. dma_addr_t dma_addr;
  87. unsigned index, count;
  88. /* We can split a page between two buffers */
  89. BUILD_BUG_ON(EFX_RX_BATCH & 1);
  90. for (count = 0; count < EFX_RX_BATCH; ++count) {
  91. page = alloc_pages(__GFP_COLD | __GFP_COMP | GFP_ATOMIC,
  92. efx->rx_buffer_order);
  93. if (unlikely(page == NULL))
  94. return -ENOMEM;
  95. dma_addr = dma_map_page(&efx->pci_dev->dev, page, 0,
  96. efx_rx_buf_size(efx),
  97. DMA_FROM_DEVICE);
  98. if (unlikely(dma_mapping_error(&efx->pci_dev->dev, dma_addr))) {
  99. __free_pages(page, efx->rx_buffer_order);
  100. return -EIO;
  101. }
  102. state = page_address(page);
  103. state->refcnt = 0;
  104. state->dma_addr = dma_addr;
  105. dma_addr += sizeof(struct efx_rx_page_state);
  106. page_offset = sizeof(struct efx_rx_page_state);
  107. split:
  108. index = rx_queue->added_count & rx_queue->ptr_mask;
  109. rx_buf = efx_rx_buffer(rx_queue, index);
  110. rx_buf->dma_addr = dma_addr + EFX_PAGE_IP_ALIGN;
  111. rx_buf->page = page;
  112. rx_buf->page_offset = page_offset + EFX_PAGE_IP_ALIGN;
  113. rx_buf->len = efx->rx_buffer_len - EFX_PAGE_IP_ALIGN;
  114. rx_buf->flags = 0;
  115. ++rx_queue->added_count;
  116. ++state->refcnt;
  117. if ((~count & 1) && (efx->rx_buffer_len <= EFX_RX_HALF_PAGE)) {
  118. /* Use the second half of the page */
  119. get_page(page);
  120. dma_addr += (PAGE_SIZE >> 1);
  121. page_offset += (PAGE_SIZE >> 1);
  122. ++count;
  123. goto split;
  124. }
  125. }
  126. return 0;
  127. }
  128. static void efx_unmap_rx_buffer(struct efx_nic *efx,
  129. struct efx_rx_buffer *rx_buf,
  130. unsigned int used_len)
  131. {
  132. if (rx_buf->page) {
  133. struct efx_rx_page_state *state;
  134. state = page_address(rx_buf->page);
  135. if (--state->refcnt == 0) {
  136. dma_unmap_page(&efx->pci_dev->dev,
  137. state->dma_addr,
  138. efx_rx_buf_size(efx),
  139. DMA_FROM_DEVICE);
  140. } else if (used_len) {
  141. dma_sync_single_for_cpu(&efx->pci_dev->dev,
  142. rx_buf->dma_addr, used_len,
  143. DMA_FROM_DEVICE);
  144. }
  145. }
  146. }
  147. static void efx_free_rx_buffer(struct efx_nic *efx,
  148. struct efx_rx_buffer *rx_buf)
  149. {
  150. if (rx_buf->page) {
  151. __free_pages(rx_buf->page, efx->rx_buffer_order);
  152. rx_buf->page = NULL;
  153. }
  154. }
  155. static void efx_fini_rx_buffer(struct efx_rx_queue *rx_queue,
  156. struct efx_rx_buffer *rx_buf)
  157. {
  158. efx_unmap_rx_buffer(rx_queue->efx, rx_buf, 0);
  159. efx_free_rx_buffer(rx_queue->efx, rx_buf);
  160. }
  161. /* Attempt to resurrect the other receive buffer that used to share this page,
  162. * which had previously been passed up to the kernel and freed. */
  163. static void efx_resurrect_rx_buffer(struct efx_rx_queue *rx_queue,
  164. struct efx_rx_buffer *rx_buf)
  165. {
  166. struct efx_rx_page_state *state = page_address(rx_buf->page);
  167. struct efx_rx_buffer *new_buf;
  168. unsigned fill_level, index;
  169. /* +1 because efx_rx_packet() incremented removed_count. +1 because
  170. * we'd like to insert an additional descriptor whilst leaving
  171. * EFX_RXD_HEAD_ROOM for the non-recycle path */
  172. fill_level = (rx_queue->added_count - rx_queue->removed_count + 2);
  173. if (unlikely(fill_level > rx_queue->max_fill)) {
  174. /* We could place "state" on a list, and drain the list in
  175. * efx_fast_push_rx_descriptors(). For now, this will do. */
  176. return;
  177. }
  178. ++state->refcnt;
  179. get_page(rx_buf->page);
  180. index = rx_queue->added_count & rx_queue->ptr_mask;
  181. new_buf = efx_rx_buffer(rx_queue, index);
  182. new_buf->dma_addr = rx_buf->dma_addr ^ (PAGE_SIZE >> 1);
  183. new_buf->page = rx_buf->page;
  184. new_buf->len = rx_buf->len;
  185. ++rx_queue->added_count;
  186. }
  187. /* Recycle the given rx buffer directly back into the rx_queue. There is
  188. * always room to add this buffer, because we've just popped a buffer. */
  189. static void efx_recycle_rx_buffer(struct efx_channel *channel,
  190. struct efx_rx_buffer *rx_buf)
  191. {
  192. struct efx_nic *efx = channel->efx;
  193. struct efx_rx_queue *rx_queue = efx_channel_get_rx_queue(channel);
  194. struct efx_rx_buffer *new_buf;
  195. unsigned index;
  196. rx_buf->flags = 0;
  197. if (efx->rx_buffer_len <= EFX_RX_HALF_PAGE &&
  198. page_count(rx_buf->page) == 1)
  199. efx_resurrect_rx_buffer(rx_queue, rx_buf);
  200. index = rx_queue->added_count & rx_queue->ptr_mask;
  201. new_buf = efx_rx_buffer(rx_queue, index);
  202. memcpy(new_buf, rx_buf, sizeof(*new_buf));
  203. rx_buf->page = NULL;
  204. ++rx_queue->added_count;
  205. }
  206. /**
  207. * efx_fast_push_rx_descriptors - push new RX descriptors quickly
  208. * @rx_queue: RX descriptor queue
  209. *
  210. * This will aim to fill the RX descriptor queue up to
  211. * @rx_queue->@max_fill. If there is insufficient atomic
  212. * memory to do so, a slow fill will be scheduled.
  213. *
  214. * The caller must provide serialisation (none is used here). In practise,
  215. * this means this function must run from the NAPI handler, or be called
  216. * when NAPI is disabled.
  217. */
  218. void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue)
  219. {
  220. unsigned fill_level;
  221. int space, rc = 0;
  222. /* Calculate current fill level, and exit if we don't need to fill */
  223. fill_level = (rx_queue->added_count - rx_queue->removed_count);
  224. EFX_BUG_ON_PARANOID(fill_level > rx_queue->efx->rxq_entries);
  225. if (fill_level >= rx_queue->fast_fill_trigger)
  226. goto out;
  227. /* Record minimum fill level */
  228. if (unlikely(fill_level < rx_queue->min_fill)) {
  229. if (fill_level)
  230. rx_queue->min_fill = fill_level;
  231. }
  232. space = rx_queue->max_fill - fill_level;
  233. EFX_BUG_ON_PARANOID(space < EFX_RX_BATCH);
  234. netif_vdbg(rx_queue->efx, rx_status, rx_queue->efx->net_dev,
  235. "RX queue %d fast-filling descriptor ring from"
  236. " level %d to level %d\n",
  237. efx_rx_queue_index(rx_queue), fill_level,
  238. rx_queue->max_fill);
  239. do {
  240. rc = efx_init_rx_buffers(rx_queue);
  241. if (unlikely(rc)) {
  242. /* Ensure that we don't leave the rx queue empty */
  243. if (rx_queue->added_count == rx_queue->removed_count)
  244. efx_schedule_slow_fill(rx_queue);
  245. goto out;
  246. }
  247. } while ((space -= EFX_RX_BATCH) >= EFX_RX_BATCH);
  248. netif_vdbg(rx_queue->efx, rx_status, rx_queue->efx->net_dev,
  249. "RX queue %d fast-filled descriptor ring "
  250. "to level %d\n", efx_rx_queue_index(rx_queue),
  251. rx_queue->added_count - rx_queue->removed_count);
  252. out:
  253. if (rx_queue->notified_count != rx_queue->added_count)
  254. efx_nic_notify_rx_desc(rx_queue);
  255. }
  256. void efx_rx_slow_fill(unsigned long context)
  257. {
  258. struct efx_rx_queue *rx_queue = (struct efx_rx_queue *)context;
  259. /* Post an event to cause NAPI to run and refill the queue */
  260. efx_nic_generate_fill_event(rx_queue);
  261. ++rx_queue->slow_fill_count;
  262. }
  263. static void efx_rx_packet__check_len(struct efx_rx_queue *rx_queue,
  264. struct efx_rx_buffer *rx_buf,
  265. int len)
  266. {
  267. struct efx_nic *efx = rx_queue->efx;
  268. unsigned max_len = rx_buf->len - efx->type->rx_buffer_padding;
  269. if (likely(len <= max_len))
  270. return;
  271. /* The packet must be discarded, but this is only a fatal error
  272. * if the caller indicated it was
  273. */
  274. rx_buf->flags |= EFX_RX_PKT_DISCARD;
  275. if ((len > rx_buf->len) && EFX_WORKAROUND_8071(efx)) {
  276. if (net_ratelimit())
  277. netif_err(efx, rx_err, efx->net_dev,
  278. " RX queue %d seriously overlength "
  279. "RX event (0x%x > 0x%x+0x%x). Leaking\n",
  280. efx_rx_queue_index(rx_queue), len, max_len,
  281. efx->type->rx_buffer_padding);
  282. efx_schedule_reset(efx, RESET_TYPE_RX_RECOVERY);
  283. } else {
  284. if (net_ratelimit())
  285. netif_err(efx, rx_err, efx->net_dev,
  286. " RX queue %d overlength RX event "
  287. "(0x%x > 0x%x)\n",
  288. efx_rx_queue_index(rx_queue), len, max_len);
  289. }
  290. efx_rx_queue_channel(rx_queue)->n_rx_overlength++;
  291. }
  292. /* Pass a received packet up through GRO. GRO can handle pages
  293. * regardless of checksum state and skbs with a good checksum.
  294. */
  295. static void efx_rx_packet_gro(struct efx_channel *channel,
  296. struct efx_rx_buffer *rx_buf,
  297. const u8 *eh)
  298. {
  299. struct napi_struct *napi = &channel->napi_str;
  300. gro_result_t gro_result;
  301. struct efx_nic *efx = channel->efx;
  302. struct page *page = rx_buf->page;
  303. struct sk_buff *skb;
  304. rx_buf->page = NULL;
  305. skb = napi_get_frags(napi);
  306. if (!skb) {
  307. put_page(page);
  308. return;
  309. }
  310. if (efx->net_dev->features & NETIF_F_RXHASH)
  311. skb->rxhash = efx_rx_buf_hash(eh);
  312. skb_fill_page_desc(skb, 0, page,
  313. efx_rx_buf_offset(efx, rx_buf), rx_buf->len);
  314. skb->len = rx_buf->len;
  315. skb->data_len = rx_buf->len;
  316. skb->truesize += rx_buf->len;
  317. skb->ip_summed = ((rx_buf->flags & EFX_RX_PKT_CSUMMED) ?
  318. CHECKSUM_UNNECESSARY : CHECKSUM_NONE);
  319. skb_record_rx_queue(skb, channel->rx_queue.core_index);
  320. gro_result = napi_gro_frags(napi);
  321. if (gro_result != GRO_DROP)
  322. channel->irq_mod_score += 2;
  323. }
  324. /* Allocate and construct an SKB around a struct page.*/
  325. static struct sk_buff *efx_rx_mk_skb(struct efx_channel *channel,
  326. struct efx_rx_buffer *rx_buf,
  327. u8 *eh, int hdr_len)
  328. {
  329. struct efx_nic *efx = channel->efx;
  330. struct sk_buff *skb;
  331. /* Allocate an SKB to store the headers */
  332. skb = netdev_alloc_skb(efx->net_dev, hdr_len + EFX_PAGE_SKB_ALIGN);
  333. if (unlikely(skb == NULL))
  334. return NULL;
  335. EFX_BUG_ON_PARANOID(rx_buf->len < hdr_len);
  336. skb_reserve(skb, EFX_PAGE_SKB_ALIGN);
  337. skb->len = rx_buf->len;
  338. skb->truesize = rx_buf->len + sizeof(struct sk_buff);
  339. memcpy(skb->data, eh, hdr_len);
  340. skb->tail += hdr_len;
  341. /* Append the remaining page onto the frag list */
  342. if (rx_buf->len > hdr_len) {
  343. skb->data_len = skb->len - hdr_len;
  344. skb_fill_page_desc(skb, 0, rx_buf->page,
  345. efx_rx_buf_offset(efx, rx_buf) + hdr_len,
  346. skb->data_len);
  347. } else {
  348. __free_pages(rx_buf->page, efx->rx_buffer_order);
  349. skb->data_len = 0;
  350. }
  351. /* Ownership has transferred from the rx_buf to skb */
  352. rx_buf->page = NULL;
  353. /* Move past the ethernet header */
  354. skb->protocol = eth_type_trans(skb, efx->net_dev);
  355. return skb;
  356. }
  357. void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
  358. unsigned int len, u16 flags)
  359. {
  360. struct efx_nic *efx = rx_queue->efx;
  361. struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
  362. struct efx_rx_buffer *rx_buf;
  363. rx_buf = efx_rx_buffer(rx_queue, index);
  364. rx_buf->flags |= flags;
  365. /* This allows the refill path to post another buffer.
  366. * EFX_RXD_HEAD_ROOM ensures that the slot we are using
  367. * isn't overwritten yet.
  368. */
  369. rx_queue->removed_count++;
  370. /* Validate the length encoded in the event vs the descriptor pushed */
  371. efx_rx_packet__check_len(rx_queue, rx_buf, len);
  372. netif_vdbg(efx, rx_status, efx->net_dev,
  373. "RX queue %d received id %x at %llx+%x %s%s\n",
  374. efx_rx_queue_index(rx_queue), index,
  375. (unsigned long long)rx_buf->dma_addr, len,
  376. (rx_buf->flags & EFX_RX_PKT_CSUMMED) ? " [SUMMED]" : "",
  377. (rx_buf->flags & EFX_RX_PKT_DISCARD) ? " [DISCARD]" : "");
  378. /* Discard packet, if instructed to do so */
  379. if (unlikely(rx_buf->flags & EFX_RX_PKT_DISCARD)) {
  380. efx_recycle_rx_buffer(channel, rx_buf);
  381. /* Don't hold off the previous receive */
  382. rx_buf = NULL;
  383. goto out;
  384. }
  385. /* Release and/or sync DMA mapping - assumes all RX buffers
  386. * consumed in-order per RX queue
  387. */
  388. efx_unmap_rx_buffer(efx, rx_buf, len);
  389. /* Prefetch nice and early so data will (hopefully) be in cache by
  390. * the time we look at it.
  391. */
  392. prefetch(efx_rx_buf_eh(efx, rx_buf));
  393. /* Pipeline receives so that we give time for packet headers to be
  394. * prefetched into cache.
  395. */
  396. rx_buf->len = len - efx->type->rx_buffer_hash_size;
  397. out:
  398. if (channel->rx_pkt)
  399. __efx_rx_packet(channel, channel->rx_pkt);
  400. channel->rx_pkt = rx_buf;
  401. }
  402. static void efx_rx_deliver(struct efx_channel *channel, u8 *eh,
  403. struct efx_rx_buffer *rx_buf)
  404. {
  405. struct sk_buff *skb;
  406. u16 hdr_len = min_t(u16, rx_buf->len, EFX_SKB_HEADERS);
  407. skb = efx_rx_mk_skb(channel, rx_buf, eh, hdr_len);
  408. if (unlikely(skb == NULL)) {
  409. efx_free_rx_buffer(channel->efx, rx_buf);
  410. return;
  411. }
  412. skb_record_rx_queue(skb, channel->rx_queue.core_index);
  413. /* Set the SKB flags */
  414. skb_checksum_none_assert(skb);
  415. if (channel->type->receive_skb)
  416. if (channel->type->receive_skb(channel, skb))
  417. return;
  418. /* Pass the packet up */
  419. netif_receive_skb(skb);
  420. }
  421. /* Handle a received packet. Second half: Touches packet payload. */
  422. void __efx_rx_packet(struct efx_channel *channel, struct efx_rx_buffer *rx_buf)
  423. {
  424. struct efx_nic *efx = channel->efx;
  425. u8 *eh = efx_rx_buf_eh(efx, rx_buf);
  426. /* If we're in loopback test, then pass the packet directly to the
  427. * loopback layer, and free the rx_buf here
  428. */
  429. if (unlikely(efx->loopback_selftest)) {
  430. efx_loopback_rx_packet(efx, eh, rx_buf->len);
  431. efx_free_rx_buffer(efx, rx_buf);
  432. return;
  433. }
  434. if (unlikely(!(efx->net_dev->features & NETIF_F_RXCSUM)))
  435. rx_buf->flags &= ~EFX_RX_PKT_CSUMMED;
  436. if (!channel->type->receive_skb)
  437. efx_rx_packet_gro(channel, rx_buf, eh);
  438. else
  439. efx_rx_deliver(channel, eh, rx_buf);
  440. }
  441. int efx_probe_rx_queue(struct efx_rx_queue *rx_queue)
  442. {
  443. struct efx_nic *efx = rx_queue->efx;
  444. unsigned int entries;
  445. int rc;
  446. /* Create the smallest power-of-two aligned ring */
  447. entries = max(roundup_pow_of_two(efx->rxq_entries), EFX_MIN_DMAQ_SIZE);
  448. EFX_BUG_ON_PARANOID(entries > EFX_MAX_DMAQ_SIZE);
  449. rx_queue->ptr_mask = entries - 1;
  450. netif_dbg(efx, probe, efx->net_dev,
  451. "creating RX queue %d size %#x mask %#x\n",
  452. efx_rx_queue_index(rx_queue), efx->rxq_entries,
  453. rx_queue->ptr_mask);
  454. /* Allocate RX buffers */
  455. rx_queue->buffer = kcalloc(entries, sizeof(*rx_queue->buffer),
  456. GFP_KERNEL);
  457. if (!rx_queue->buffer)
  458. return -ENOMEM;
  459. rc = efx_nic_probe_rx(rx_queue);
  460. if (rc) {
  461. kfree(rx_queue->buffer);
  462. rx_queue->buffer = NULL;
  463. }
  464. return rc;
  465. }
  466. void efx_init_rx_queue(struct efx_rx_queue *rx_queue)
  467. {
  468. struct efx_nic *efx = rx_queue->efx;
  469. unsigned int max_fill, trigger, max_trigger;
  470. netif_dbg(rx_queue->efx, drv, rx_queue->efx->net_dev,
  471. "initialising RX queue %d\n", efx_rx_queue_index(rx_queue));
  472. /* Initialise ptr fields */
  473. rx_queue->added_count = 0;
  474. rx_queue->notified_count = 0;
  475. rx_queue->removed_count = 0;
  476. rx_queue->min_fill = -1U;
  477. /* Initialise limit fields */
  478. max_fill = efx->rxq_entries - EFX_RXD_HEAD_ROOM;
  479. max_trigger = max_fill - EFX_RX_BATCH;
  480. if (rx_refill_threshold != 0) {
  481. trigger = max_fill * min(rx_refill_threshold, 100U) / 100U;
  482. if (trigger > max_trigger)
  483. trigger = max_trigger;
  484. } else {
  485. trigger = max_trigger;
  486. }
  487. rx_queue->max_fill = max_fill;
  488. rx_queue->fast_fill_trigger = trigger;
  489. /* Set up RX descriptor ring */
  490. rx_queue->enabled = true;
  491. efx_nic_init_rx(rx_queue);
  492. }
  493. void efx_fini_rx_queue(struct efx_rx_queue *rx_queue)
  494. {
  495. int i;
  496. struct efx_rx_buffer *rx_buf;
  497. netif_dbg(rx_queue->efx, drv, rx_queue->efx->net_dev,
  498. "shutting down RX queue %d\n", efx_rx_queue_index(rx_queue));
  499. /* A flush failure might have left rx_queue->enabled */
  500. rx_queue->enabled = false;
  501. del_timer_sync(&rx_queue->slow_fill);
  502. efx_nic_fini_rx(rx_queue);
  503. /* Release RX buffers NB start at index 0 not current HW ptr */
  504. if (rx_queue->buffer) {
  505. for (i = 0; i <= rx_queue->ptr_mask; i++) {
  506. rx_buf = efx_rx_buffer(rx_queue, i);
  507. efx_fini_rx_buffer(rx_queue, rx_buf);
  508. }
  509. }
  510. }
  511. void efx_remove_rx_queue(struct efx_rx_queue *rx_queue)
  512. {
  513. netif_dbg(rx_queue->efx, drv, rx_queue->efx->net_dev,
  514. "destroying RX queue %d\n", efx_rx_queue_index(rx_queue));
  515. efx_nic_remove_rx(rx_queue);
  516. kfree(rx_queue->buffer);
  517. rx_queue->buffer = NULL;
  518. }
  519. module_param(rx_refill_threshold, uint, 0444);
  520. MODULE_PARM_DESC(rx_refill_threshold,
  521. "RX descriptor ring refill threshold (%)");