sfc: Support only two rx buffers per page
[firefly-linux-kernel-4.4.55.git] / drivers / net / sfc / rx.c
1 /****************************************************************************
2  * Driver for Solarflare Solarstorm network controllers and boards
3  * Copyright 2005-2006 Fen Systems Ltd.
4  * Copyright 2005-2009 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
11 #include <linux/socket.h>
12 #include <linux/in.h>
13 #include <linux/slab.h>
14 #include <linux/ip.h>
15 #include <linux/tcp.h>
16 #include <linux/udp.h>
17 #include <net/ip.h>
18 #include <net/checksum.h>
19 #include "net_driver.h"
20 #include "efx.h"
21 #include "nic.h"
22 #include "selftest.h"
23 #include "workarounds.h"
24
25 /* Number of RX descriptors pushed at once. */
26 #define EFX_RX_BATCH  8
27
28 /* Size of buffer allocated for skb header area. */
29 #define EFX_SKB_HEADERS  64u
30
31 /*
32  * rx_alloc_method - RX buffer allocation method
33  *
34  * This driver supports two methods for allocating and using RX buffers:
35  * each RX buffer may be backed by an skb or by an order-n page.
36  *
37  * When LRO is in use then the second method has a lower overhead,
38  * since we don't have to allocate then free skbs on reassembled frames.
39  *
40  * Values:
41  *   - RX_ALLOC_METHOD_AUTO = 0
42  *   - RX_ALLOC_METHOD_SKB  = 1
43  *   - RX_ALLOC_METHOD_PAGE = 2
44  *
45  * The heuristic for %RX_ALLOC_METHOD_AUTO is a simple hysteresis count
46  * controlled by the parameters below.
47  *
48  *   - Since pushing and popping descriptors are separated by the rx_queue
49  *     size, so the watermarks should be ~rxd_size.
50  *   - The performance win by using page-based allocation for LRO is less
51  *     than the performance hit of using page-based allocation of non-LRO,
52  *     so the watermarks should reflect this.
53  *
54  * Per channel we maintain a single variable, updated by each channel:
55  *
56  *   rx_alloc_level += (lro_performed ? RX_ALLOC_FACTOR_LRO :
57  *                      RX_ALLOC_FACTOR_SKB)
58  * Per NAPI poll interval, we constrain rx_alloc_level to 0..MAX (which
59  * limits the hysteresis), and update the allocation strategy:
60  *
61  *   rx_alloc_method = (rx_alloc_level > RX_ALLOC_LEVEL_LRO ?
62  *                      RX_ALLOC_METHOD_PAGE : RX_ALLOC_METHOD_SKB)
63  */
64 static int rx_alloc_method = RX_ALLOC_METHOD_AUTO;
65
66 #define RX_ALLOC_LEVEL_LRO 0x2000
67 #define RX_ALLOC_LEVEL_MAX 0x3000
68 #define RX_ALLOC_FACTOR_LRO 1
69 #define RX_ALLOC_FACTOR_SKB (-2)
70
71 /* This is the percentage fill level below which new RX descriptors
72  * will be added to the RX descriptor ring.
73  */
74 static unsigned int rx_refill_threshold = 90;
75
76 /* This is the percentage fill level to which an RX queue will be refilled
77  * when the "RX refill threshold" is reached.
78  */
79 static unsigned int rx_refill_limit = 95;
80
81 /*
82  * RX maximum head room required.
83  *
84  * This must be at least 1 to prevent overflow and at least 2 to allow
85  * pipelined receives.
86  */
87 #define EFX_RXD_HEAD_ROOM 2
88
89 static inline unsigned int efx_rx_buf_offset(struct efx_rx_buffer *buf)
90 {
91         /* Offset is always within one page, so we don't need to consider
92          * the page order.
93          */
94         return (__force unsigned long) buf->data & (PAGE_SIZE - 1);
95 }
96 static inline unsigned int efx_rx_buf_size(struct efx_nic *efx)
97 {
98         return PAGE_SIZE << efx->rx_buffer_order;
99 }
100
101 /**
102  * efx_init_rx_buffers_skb - create EFX_RX_BATCH skb-based RX buffers
103  *
104  * @rx_queue:           Efx RX queue
105  *
106  * This allocates EFX_RX_BATCH skbs, maps them for DMA, and populates a
107  * struct efx_rx_buffer for each one. Return a negative error code or 0
108  * on success. May fail having only inserted fewer than EFX_RX_BATCH
109  * buffers.
110  */
111 static int efx_init_rx_buffers_skb(struct efx_rx_queue *rx_queue)
112 {
113         struct efx_nic *efx = rx_queue->efx;
114         struct net_device *net_dev = efx->net_dev;
115         struct efx_rx_buffer *rx_buf;
116         int skb_len = efx->rx_buffer_len;
117         unsigned index, count;
118
119         for (count = 0; count < EFX_RX_BATCH; ++count) {
120                 index = rx_queue->added_count & EFX_RXQ_MASK;
121                 rx_buf = efx_rx_buffer(rx_queue, index);
122
123                 rx_buf->skb = netdev_alloc_skb(net_dev, skb_len);
124                 if (unlikely(!rx_buf->skb))
125                         return -ENOMEM;
126                 rx_buf->page = NULL;
127
128                 /* Adjust the SKB for padding and checksum */
129                 skb_reserve(rx_buf->skb, NET_IP_ALIGN);
130                 rx_buf->len = skb_len - NET_IP_ALIGN;
131                 rx_buf->data = (char *)rx_buf->skb->data;
132                 rx_buf->skb->ip_summed = CHECKSUM_UNNECESSARY;
133
134                 rx_buf->dma_addr = pci_map_single(efx->pci_dev,
135                                                   rx_buf->data, rx_buf->len,
136                                                   PCI_DMA_FROMDEVICE);
137                 if (unlikely(pci_dma_mapping_error(efx->pci_dev,
138                                                    rx_buf->dma_addr))) {
139                         dev_kfree_skb_any(rx_buf->skb);
140                         rx_buf->skb = NULL;
141                         return -EIO;
142                 }
143
144                 ++rx_queue->added_count;
145                 ++rx_queue->alloc_skb_count;
146         }
147
148         return 0;
149 }
150
151 /**
152  * efx_init_rx_buffers_page - create EFX_RX_BATCH page-based RX buffers
153  *
154  * @rx_queue:           Efx RX queue
155  *
156  * This allocates memory for EFX_RX_BATCH receive buffers, maps them for DMA,
157  * and populates struct efx_rx_buffers for each one. Return a negative error
158  * code or 0 on success. If a single page can be split between two buffers,
159  * then the page will either be inserted fully, or not at at all.
160  */
161 static int efx_init_rx_buffers_page(struct efx_rx_queue *rx_queue)
162 {
163         struct efx_nic *efx = rx_queue->efx;
164         struct efx_rx_buffer *rx_buf;
165         struct page *page;
166         char *page_addr;
167         dma_addr_t dma_addr;
168         unsigned index, count;
169
170         /* We can split a page between two buffers */
171         BUILD_BUG_ON(EFX_RX_BATCH & 1);
172
173         for (count = 0; count < EFX_RX_BATCH; ++count) {
174                 page = alloc_pages(__GFP_COLD | __GFP_COMP | GFP_ATOMIC,
175                                    efx->rx_buffer_order);
176                 if (unlikely(page == NULL))
177                         return -ENOMEM;
178                 dma_addr = pci_map_page(efx->pci_dev, page, 0,
179                                         efx_rx_buf_size(efx),
180                                         PCI_DMA_FROMDEVICE);
181                 if (unlikely(pci_dma_mapping_error(efx->pci_dev, dma_addr))) {
182                         __free_pages(page, efx->rx_buffer_order);
183                         return -EIO;
184                 }
185                 EFX_BUG_ON_PARANOID(dma_addr & (PAGE_SIZE - 1));
186                 page_addr = page_address(page) + EFX_PAGE_IP_ALIGN;
187                 dma_addr += EFX_PAGE_IP_ALIGN;
188
189         split:
190                 index = rx_queue->added_count & EFX_RXQ_MASK;
191                 rx_buf = efx_rx_buffer(rx_queue, index);
192                 rx_buf->dma_addr = dma_addr;
193                 rx_buf->skb = NULL;
194                 rx_buf->page = page;
195                 rx_buf->data = page_addr;
196                 rx_buf->len = efx->rx_buffer_len - EFX_PAGE_IP_ALIGN;
197                 ++rx_queue->added_count;
198                 ++rx_queue->alloc_page_count;
199
200                 if ((~count & 1) && (efx->rx_buffer_len < (PAGE_SIZE >> 1))) {
201                         /* Use the second half of the page */
202                         get_page(page);
203                         dma_addr += (PAGE_SIZE >> 1);
204                         page_addr += (PAGE_SIZE >> 1);
205                         ++count;
206                         goto split;
207                 }
208         }
209
210         return 0;
211 }
212
213 static void efx_unmap_rx_buffer(struct efx_nic *efx,
214                                 struct efx_rx_buffer *rx_buf)
215 {
216         if (rx_buf->page) {
217                 EFX_BUG_ON_PARANOID(rx_buf->skb);
218
219                 /* Unmap the buffer if there's only one buffer per page(s),
220                  * or this is the second half of a two buffer page. */
221                 if (efx->rx_buffer_order != 0 ||
222                     (efx_rx_buf_offset(rx_buf) & (PAGE_SIZE >> 1)) != 0) {
223                         pci_unmap_page(efx->pci_dev,
224                                        rx_buf->dma_addr & ~(PAGE_SIZE - 1),
225                                        efx_rx_buf_size(efx),
226                                        PCI_DMA_FROMDEVICE);
227                 }
228         } else if (likely(rx_buf->skb)) {
229                 pci_unmap_single(efx->pci_dev, rx_buf->dma_addr,
230                                  rx_buf->len, PCI_DMA_FROMDEVICE);
231         }
232 }
233
234 static void efx_free_rx_buffer(struct efx_nic *efx,
235                                struct efx_rx_buffer *rx_buf)
236 {
237         if (rx_buf->page) {
238                 __free_pages(rx_buf->page, efx->rx_buffer_order);
239                 rx_buf->page = NULL;
240         } else if (likely(rx_buf->skb)) {
241                 dev_kfree_skb_any(rx_buf->skb);
242                 rx_buf->skb = NULL;
243         }
244 }
245
246 static void efx_fini_rx_buffer(struct efx_rx_queue *rx_queue,
247                                struct efx_rx_buffer *rx_buf)
248 {
249         efx_unmap_rx_buffer(rx_queue->efx, rx_buf);
250         efx_free_rx_buffer(rx_queue->efx, rx_buf);
251 }
252
253 /**
254  * efx_fast_push_rx_descriptors - push new RX descriptors quickly
255  * @rx_queue:           RX descriptor queue
256  * This will aim to fill the RX descriptor queue up to
257  * @rx_queue->@fast_fill_limit. If there is insufficient atomic
258  * memory to do so, a slow fill will be scheduled.
259  *
260  * The caller must provide serialisation (none is used here). In practise,
261  * this means this function must run from the NAPI handler, or be called
262  * when NAPI is disabled.
263  */
264 void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue)
265 {
266         struct efx_channel *channel = rx_queue->channel;
267         unsigned fill_level;
268         int space, rc = 0;
269
270         /* Calculate current fill level, and exit if we don't need to fill */
271         fill_level = (rx_queue->added_count - rx_queue->removed_count);
272         EFX_BUG_ON_PARANOID(fill_level > EFX_RXQ_SIZE);
273         if (fill_level >= rx_queue->fast_fill_trigger)
274                 return;
275
276         /* Record minimum fill level */
277         if (unlikely(fill_level < rx_queue->min_fill)) {
278                 if (fill_level)
279                         rx_queue->min_fill = fill_level;
280         }
281
282         space = rx_queue->fast_fill_limit - fill_level;
283         if (space < EFX_RX_BATCH)
284                 return;
285
286         EFX_TRACE(rx_queue->efx, "RX queue %d fast-filling descriptor ring from"
287                   " level %d to level %d using %s allocation\n",
288                   rx_queue->queue, fill_level, rx_queue->fast_fill_limit,
289                   channel->rx_alloc_push_pages ? "page" : "skb");
290
291         do {
292                 if (channel->rx_alloc_push_pages)
293                         rc = efx_init_rx_buffers_page(rx_queue);
294                 else
295                         rc = efx_init_rx_buffers_skb(rx_queue);
296                 if (unlikely(rc)) {
297                         /* Ensure that we don't leave the rx queue empty */
298                         if (rx_queue->added_count == rx_queue->removed_count)
299                                 efx_schedule_slow_fill(rx_queue);
300                         goto out;
301                 }
302         } while ((space -= EFX_RX_BATCH) >= EFX_RX_BATCH);
303
304         EFX_TRACE(rx_queue->efx, "RX queue %d fast-filled descriptor ring "
305                   "to level %d\n", rx_queue->queue,
306                   rx_queue->added_count - rx_queue->removed_count);
307
308  out:
309         /* Send write pointer to card. */
310         efx_nic_notify_rx_desc(rx_queue);
311 }
312
313 void efx_rx_slow_fill(unsigned long context)
314 {
315         struct efx_rx_queue *rx_queue = (struct efx_rx_queue *)context;
316         struct efx_channel *channel = rx_queue->channel;
317
318         /* Post an event to cause NAPI to run and refill the queue */
319         efx_nic_generate_fill_event(channel);
320         ++rx_queue->slow_fill_count;
321 }
322
323 static void efx_rx_packet__check_len(struct efx_rx_queue *rx_queue,
324                                      struct efx_rx_buffer *rx_buf,
325                                      int len, bool *discard,
326                                      bool *leak_packet)
327 {
328         struct efx_nic *efx = rx_queue->efx;
329         unsigned max_len = rx_buf->len - efx->type->rx_buffer_padding;
330
331         if (likely(len <= max_len))
332                 return;
333
334         /* The packet must be discarded, but this is only a fatal error
335          * if the caller indicated it was
336          */
337         *discard = true;
338
339         if ((len > rx_buf->len) && EFX_WORKAROUND_8071(efx)) {
340                 EFX_ERR_RL(efx, " RX queue %d seriously overlength "
341                            "RX event (0x%x > 0x%x+0x%x). Leaking\n",
342                            rx_queue->queue, len, max_len,
343                            efx->type->rx_buffer_padding);
344                 /* If this buffer was skb-allocated, then the meta
345                  * data at the end of the skb will be trashed. So
346                  * we have no choice but to leak the fragment.
347                  */
348                 *leak_packet = (rx_buf->skb != NULL);
349                 efx_schedule_reset(efx, RESET_TYPE_RX_RECOVERY);
350         } else {
351                 EFX_ERR_RL(efx, " RX queue %d overlength RX event "
352                            "(0x%x > 0x%x)\n", rx_queue->queue, len, max_len);
353         }
354
355         rx_queue->channel->n_rx_overlength++;
356 }
357
358 /* Pass a received packet up through the generic LRO stack
359  *
360  * Handles driverlink veto, and passes the fragment up via
361  * the appropriate LRO method
362  */
363 static void efx_rx_packet_lro(struct efx_channel *channel,
364                               struct efx_rx_buffer *rx_buf,
365                               bool checksummed)
366 {
367         struct napi_struct *napi = &channel->napi_str;
368         gro_result_t gro_result;
369
370         /* Pass the skb/page into the LRO engine */
371         if (rx_buf->page) {
372                 struct page *page = rx_buf->page;
373                 struct sk_buff *skb;
374
375                 EFX_BUG_ON_PARANOID(rx_buf->skb);
376                 rx_buf->page = NULL;
377
378                 skb = napi_get_frags(napi);
379                 if (!skb) {
380                         put_page(page);
381                         return;
382                 }
383
384                 skb_shinfo(skb)->frags[0].page = page;
385                 skb_shinfo(skb)->frags[0].page_offset =
386                         efx_rx_buf_offset(rx_buf);
387                 skb_shinfo(skb)->frags[0].size = rx_buf->len;
388                 skb_shinfo(skb)->nr_frags = 1;
389
390                 skb->len = rx_buf->len;
391                 skb->data_len = rx_buf->len;
392                 skb->truesize += rx_buf->len;
393                 skb->ip_summed =
394                         checksummed ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE;
395
396                 skb_record_rx_queue(skb, channel->channel);
397
398                 gro_result = napi_gro_frags(napi);
399         } else {
400                 struct sk_buff *skb = rx_buf->skb;
401
402                 EFX_BUG_ON_PARANOID(!skb);
403                 EFX_BUG_ON_PARANOID(!checksummed);
404                 rx_buf->skb = NULL;
405
406                 gro_result = napi_gro_receive(napi, skb);
407         }
408
409         if (gro_result == GRO_NORMAL) {
410                 channel->rx_alloc_level += RX_ALLOC_FACTOR_SKB;
411         } else if (gro_result != GRO_DROP) {
412                 channel->rx_alloc_level += RX_ALLOC_FACTOR_LRO;
413                 channel->irq_mod_score += 2;
414         }
415 }
416
417 void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
418                    unsigned int len, bool checksummed, bool discard)
419 {
420         struct efx_nic *efx = rx_queue->efx;
421         struct efx_rx_buffer *rx_buf;
422         bool leak_packet = false;
423
424         rx_buf = efx_rx_buffer(rx_queue, index);
425         EFX_BUG_ON_PARANOID(!rx_buf->data);
426         EFX_BUG_ON_PARANOID(rx_buf->skb && rx_buf->page);
427         EFX_BUG_ON_PARANOID(!(rx_buf->skb || rx_buf->page));
428
429         /* This allows the refill path to post another buffer.
430          * EFX_RXD_HEAD_ROOM ensures that the slot we are using
431          * isn't overwritten yet.
432          */
433         rx_queue->removed_count++;
434
435         /* Validate the length encoded in the event vs the descriptor pushed */
436         efx_rx_packet__check_len(rx_queue, rx_buf, len,
437                                  &discard, &leak_packet);
438
439         EFX_TRACE(efx, "RX queue %d received id %x at %llx+%x %s%s\n",
440                   rx_queue->queue, index,
441                   (unsigned long long)rx_buf->dma_addr, len,
442                   (checksummed ? " [SUMMED]" : ""),
443                   (discard ? " [DISCARD]" : ""));
444
445         /* Discard packet, if instructed to do so */
446         if (unlikely(discard)) {
447                 if (unlikely(leak_packet))
448                         rx_queue->channel->n_skbuff_leaks++;
449                 else
450                         /* We haven't called efx_unmap_rx_buffer yet,
451                          * so fini the entire rx_buffer here */
452                         efx_fini_rx_buffer(rx_queue, rx_buf);
453                 return;
454         }
455
456         /* Release card resources - assumes all RX buffers consumed in-order
457          * per RX queue
458          */
459         efx_unmap_rx_buffer(efx, rx_buf);
460
461         /* Prefetch nice and early so data will (hopefully) be in cache by
462          * the time we look at it.
463          */
464         prefetch(rx_buf->data);
465
466         /* Pipeline receives so that we give time for packet headers to be
467          * prefetched into cache.
468          */
469         rx_buf->len = len;
470         if (rx_queue->channel->rx_pkt)
471                 __efx_rx_packet(rx_queue->channel,
472                                 rx_queue->channel->rx_pkt,
473                                 rx_queue->channel->rx_pkt_csummed);
474         rx_queue->channel->rx_pkt = rx_buf;
475         rx_queue->channel->rx_pkt_csummed = checksummed;
476 }
477
478 /* Handle a received packet.  Second half: Touches packet payload. */
479 void __efx_rx_packet(struct efx_channel *channel,
480                      struct efx_rx_buffer *rx_buf, bool checksummed)
481 {
482         struct efx_nic *efx = channel->efx;
483         struct sk_buff *skb;
484
485         /* If we're in loopback test, then pass the packet directly to the
486          * loopback layer, and free the rx_buf here
487          */
488         if (unlikely(efx->loopback_selftest)) {
489                 efx_loopback_rx_packet(efx, rx_buf->data, rx_buf->len);
490                 efx_free_rx_buffer(efx, rx_buf);
491                 return;
492         }
493
494         if (rx_buf->skb) {
495                 prefetch(skb_shinfo(rx_buf->skb));
496
497                 skb_put(rx_buf->skb, rx_buf->len);
498
499                 /* Move past the ethernet header. rx_buf->data still points
500                  * at the ethernet header */
501                 rx_buf->skb->protocol = eth_type_trans(rx_buf->skb,
502                                                        efx->net_dev);
503
504                 skb_record_rx_queue(rx_buf->skb, channel->channel);
505         }
506
507         if (likely(checksummed || rx_buf->page)) {
508                 efx_rx_packet_lro(channel, rx_buf, checksummed);
509                 return;
510         }
511
512         /* We now own the SKB */
513         skb = rx_buf->skb;
514         rx_buf->skb = NULL;
515         EFX_BUG_ON_PARANOID(!skb);
516
517         /* Set the SKB flags */
518         skb->ip_summed = CHECKSUM_NONE;
519
520         /* Pass the packet up */
521         netif_receive_skb(skb);
522
523         /* Update allocation strategy method */
524         channel->rx_alloc_level += RX_ALLOC_FACTOR_SKB;
525 }
526
527 void efx_rx_strategy(struct efx_channel *channel)
528 {
529         enum efx_rx_alloc_method method = rx_alloc_method;
530
531         /* Only makes sense to use page based allocation if LRO is enabled */
532         if (!(channel->efx->net_dev->features & NETIF_F_GRO)) {
533                 method = RX_ALLOC_METHOD_SKB;
534         } else if (method == RX_ALLOC_METHOD_AUTO) {
535                 /* Constrain the rx_alloc_level */
536                 if (channel->rx_alloc_level < 0)
537                         channel->rx_alloc_level = 0;
538                 else if (channel->rx_alloc_level > RX_ALLOC_LEVEL_MAX)
539                         channel->rx_alloc_level = RX_ALLOC_LEVEL_MAX;
540
541                 /* Decide on the allocation method */
542                 method = ((channel->rx_alloc_level > RX_ALLOC_LEVEL_LRO) ?
543                           RX_ALLOC_METHOD_PAGE : RX_ALLOC_METHOD_SKB);
544         }
545
546         /* Push the option */
547         channel->rx_alloc_push_pages = (method == RX_ALLOC_METHOD_PAGE);
548 }
549
550 int efx_probe_rx_queue(struct efx_rx_queue *rx_queue)
551 {
552         struct efx_nic *efx = rx_queue->efx;
553         unsigned int rxq_size;
554         int rc;
555
556         EFX_LOG(efx, "creating RX queue %d\n", rx_queue->queue);
557
558         /* Allocate RX buffers */
559         rxq_size = EFX_RXQ_SIZE * sizeof(*rx_queue->buffer);
560         rx_queue->buffer = kzalloc(rxq_size, GFP_KERNEL);
561         if (!rx_queue->buffer)
562                 return -ENOMEM;
563
564         rc = efx_nic_probe_rx(rx_queue);
565         if (rc) {
566                 kfree(rx_queue->buffer);
567                 rx_queue->buffer = NULL;
568         }
569         return rc;
570 }
571
572 void efx_init_rx_queue(struct efx_rx_queue *rx_queue)
573 {
574         unsigned int max_fill, trigger, limit;
575
576         EFX_LOG(rx_queue->efx, "initialising RX queue %d\n", rx_queue->queue);
577
578         /* Initialise ptr fields */
579         rx_queue->added_count = 0;
580         rx_queue->notified_count = 0;
581         rx_queue->removed_count = 0;
582         rx_queue->min_fill = -1U;
583         rx_queue->min_overfill = -1U;
584
585         /* Initialise limit fields */
586         max_fill = EFX_RXQ_SIZE - EFX_RXD_HEAD_ROOM;
587         trigger = max_fill * min(rx_refill_threshold, 100U) / 100U;
588         limit = max_fill * min(rx_refill_limit, 100U) / 100U;
589
590         rx_queue->max_fill = max_fill;
591         rx_queue->fast_fill_trigger = trigger;
592         rx_queue->fast_fill_limit = limit;
593
594         /* Set up RX descriptor ring */
595         efx_nic_init_rx(rx_queue);
596 }
597
598 void efx_fini_rx_queue(struct efx_rx_queue *rx_queue)
599 {
600         int i;
601         struct efx_rx_buffer *rx_buf;
602
603         EFX_LOG(rx_queue->efx, "shutting down RX queue %d\n", rx_queue->queue);
604
605         del_timer_sync(&rx_queue->slow_fill);
606         efx_nic_fini_rx(rx_queue);
607
608         /* Release RX buffers NB start at index 0 not current HW ptr */
609         if (rx_queue->buffer) {
610                 for (i = 0; i <= EFX_RXQ_MASK; i++) {
611                         rx_buf = efx_rx_buffer(rx_queue, i);
612                         efx_fini_rx_buffer(rx_queue, rx_buf);
613                 }
614         }
615 }
616
617 void efx_remove_rx_queue(struct efx_rx_queue *rx_queue)
618 {
619         EFX_LOG(rx_queue->efx, "destroying RX queue %d\n", rx_queue->queue);
620
621         efx_nic_remove_rx(rx_queue);
622
623         kfree(rx_queue->buffer);
624         rx_queue->buffer = NULL;
625 }
626
627
628 module_param(rx_alloc_method, int, 0644);
629 MODULE_PARM_DESC(rx_alloc_method, "Allocation method used for RX buffers");
630
631 module_param(rx_refill_threshold, uint, 0444);
632 MODULE_PARM_DESC(rx_refill_threshold,
633                  "RX descriptor ring fast/slow fill threshold (%)");
634