aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/sfc/rx.c
diff options
context:
space:
mode:
authorSteve Hodgson <shodgson@solarflare.com>2010-06-01 07:20:34 -0400
committerDavid S. Miller <davem@davemloft.net>2010-06-02 05:21:09 -0400
commit244558006cf02f0096fb247f3a54dc7e7d81a256 (patch)
treed56b996063fa685cdaf49720a9370910913db837 /drivers/net/sfc/rx.c
parentf7d6f379db61233a1740cb2c6818b9c97531771f (diff)
sfc: Recycle discarded rx buffers back onto the queue
The cut-through design of the receive path means that packets that fail to match the appropriate MAC filter are not discarded at the MAC but are flagged in the completion event as 'to be discarded'. On networks with heavy multicast traffic, this can account for a significant proportion of received packets, so it is worthwhile to recycle the buffer immediately in this case rather than freeing it and then reallocating it shortly after. The only complication here is dealing with a page shared between two receive buffers. In that case, we need to be careful to free the dma mapping when both buffers have been free'd by the kernel. This means that we can only recycle such a page if both receive buffers are discarded. Unfortunately, in an environment with 1500mtu, rx_alloc_method=PAGE, and a mixture of discarded and not-discarded frames hitting the same receive queue, buffer recycling won't always be possible. Signed-off-by: Ben Hutchings <bhutchings@solarflare.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/sfc/rx.c')
-rw-r--r--drivers/net/sfc/rx.c90
1 files changed, 79 insertions, 11 deletions
diff --git a/drivers/net/sfc/rx.c b/drivers/net/sfc/rx.c
index 615a1fcd6644..dfebd73cf863 100644
--- a/drivers/net/sfc/rx.c
+++ b/drivers/net/sfc/rx.c
@@ -82,9 +82,10 @@ static unsigned int rx_refill_limit = 95;
82 * RX maximum head room required. 82 * RX maximum head room required.
83 * 83 *
84 * This must be at least 1 to prevent overflow and at least 2 to allow 84 * This must be at least 1 to prevent overflow and at least 2 to allow
85 * pipelined receives. 85 * pipelined receives. Then a further 1 because efx_recycle_rx_buffer()
86 * might insert two buffers.
86 */ 87 */
87#define EFX_RXD_HEAD_ROOM 2 88#define EFX_RXD_HEAD_ROOM 3
88 89
89static inline unsigned int efx_rx_buf_offset(struct efx_rx_buffer *buf) 90static inline unsigned int efx_rx_buf_offset(struct efx_rx_buffer *buf)
90{ 91{
@@ -250,6 +251,70 @@ static void efx_fini_rx_buffer(struct efx_rx_queue *rx_queue,
250 efx_free_rx_buffer(rx_queue->efx, rx_buf); 251 efx_free_rx_buffer(rx_queue->efx, rx_buf);
251} 252}
252 253
254/* Attempt to resurrect the other receive buffer that used to share this page,
255 * which had previously been passed up to the kernel and freed. */
256static void efx_resurrect_rx_buffer(struct efx_rx_queue *rx_queue,
257 struct efx_rx_buffer *rx_buf)
258{
259 struct efx_rx_buffer *new_buf;
260 unsigned index;
261
262 /* We could have recycled the 1st half, then refilled
263 * the queue, and now recycle the 2nd half.
264 * EFX_RXD_HEAD_ROOM ensures that there is always room
265 * to reinsert two buffers (once). */
266 get_page(rx_buf->page);
267
268 index = rx_queue->added_count & EFX_RXQ_MASK;
269 new_buf = efx_rx_buffer(rx_queue, index);
270 new_buf->dma_addr = rx_buf->dma_addr - (PAGE_SIZE >> 1);
271 new_buf->skb = NULL;
272 new_buf->page = rx_buf->page;
273 new_buf->data = rx_buf->data - (PAGE_SIZE >> 1);
274 new_buf->len = rx_buf->len;
275 ++rx_queue->added_count;
276}
277
278/* Recycle the given rx buffer directly back into the rx_queue. There is
279 * always room to add this buffer, because we've just popped a buffer. */
280static void efx_recycle_rx_buffer(struct efx_channel *channel,
281 struct efx_rx_buffer *rx_buf)
282{
283 struct efx_nic *efx = channel->efx;
284 struct efx_rx_queue *rx_queue = &efx->rx_queue[channel->channel];
285 struct efx_rx_buffer *new_buf;
286 unsigned index;
287
288 if (rx_buf->page != NULL && efx->rx_buffer_len < (PAGE_SIZE >> 1)) {
289 if (efx_rx_buf_offset(rx_buf) & (PAGE_SIZE >> 1)) {
290 /* This is the 2nd half of a page split between two
291 * buffers, If page_count() is > 1 then the kernel
292 * is holding onto the previous buffer */
293 if (page_count(rx_buf->page) != 1) {
294 efx_fini_rx_buffer(rx_queue, rx_buf);
295 return;
296 }
297
298 efx_resurrect_rx_buffer(rx_queue, rx_buf);
299 } else {
300 /* Free the 1st buffer's reference on the page. If the
301 * 2nd buffer is also discarded, this buffer will be
302 * resurrected above */
303 put_page(rx_buf->page);
304 rx_buf->page = NULL;
305 return;
306 }
307 }
308
309 index = rx_queue->added_count & EFX_RXQ_MASK;
310 new_buf = efx_rx_buffer(rx_queue, index);
311
312 memcpy(new_buf, rx_buf, sizeof(*new_buf));
313 rx_buf->page = NULL;
314 rx_buf->skb = NULL;
315 ++rx_queue->added_count;
316}
317
253/** 318/**
254 * efx_fast_push_rx_descriptors - push new RX descriptors quickly 319 * efx_fast_push_rx_descriptors - push new RX descriptors quickly
255 * @rx_queue: RX descriptor queue 320 * @rx_queue: RX descriptor queue
@@ -271,7 +336,7 @@ void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue)
271 fill_level = (rx_queue->added_count - rx_queue->removed_count); 336 fill_level = (rx_queue->added_count - rx_queue->removed_count);
272 EFX_BUG_ON_PARANOID(fill_level > EFX_RXQ_SIZE); 337 EFX_BUG_ON_PARANOID(fill_level > EFX_RXQ_SIZE);
273 if (fill_level >= rx_queue->fast_fill_trigger) 338 if (fill_level >= rx_queue->fast_fill_trigger)
274 return; 339 goto out;
275 340
276 /* Record minimum fill level */ 341 /* Record minimum fill level */
277 if (unlikely(fill_level < rx_queue->min_fill)) { 342 if (unlikely(fill_level < rx_queue->min_fill)) {
@@ -281,7 +346,7 @@ void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue)
281 346
282 space = rx_queue->fast_fill_limit - fill_level; 347 space = rx_queue->fast_fill_limit - fill_level;
283 if (space < EFX_RX_BATCH) 348 if (space < EFX_RX_BATCH)
284 return; 349 goto out;
285 350
286 EFX_TRACE(rx_queue->efx, "RX queue %d fast-filling descriptor ring from" 351 EFX_TRACE(rx_queue->efx, "RX queue %d fast-filling descriptor ring from"
287 " level %d to level %d using %s allocation\n", 352 " level %d to level %d using %s allocation\n",
@@ -306,8 +371,8 @@ void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue)
306 rx_queue->added_count - rx_queue->removed_count); 371 rx_queue->added_count - rx_queue->removed_count);
307 372
308 out: 373 out:
309 /* Send write pointer to card. */ 374 if (rx_queue->notified_count != rx_queue->added_count)
310 efx_nic_notify_rx_desc(rx_queue); 375 efx_nic_notify_rx_desc(rx_queue);
311} 376}
312 377
313void efx_rx_slow_fill(unsigned long context) 378void efx_rx_slow_fill(unsigned long context)
@@ -418,6 +483,7 @@ void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
418 unsigned int len, bool checksummed, bool discard) 483 unsigned int len, bool checksummed, bool discard)
419{ 484{
420 struct efx_nic *efx = rx_queue->efx; 485 struct efx_nic *efx = rx_queue->efx;
486 struct efx_channel *channel = rx_queue->channel;
421 struct efx_rx_buffer *rx_buf; 487 struct efx_rx_buffer *rx_buf;
422 bool leak_packet = false; 488 bool leak_packet = false;
423 489
@@ -445,12 +511,13 @@ void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
445 /* Discard packet, if instructed to do so */ 511 /* Discard packet, if instructed to do so */
446 if (unlikely(discard)) { 512 if (unlikely(discard)) {
447 if (unlikely(leak_packet)) 513 if (unlikely(leak_packet))
448 rx_queue->channel->n_skbuff_leaks++; 514 channel->n_skbuff_leaks++;
449 else 515 else
450 /* We haven't called efx_unmap_rx_buffer yet, 516 efx_recycle_rx_buffer(channel, rx_buf);
451 * so fini the entire rx_buffer here */ 517
452 efx_fini_rx_buffer(rx_queue, rx_buf); 518 /* Don't hold off the previous receive */
453 return; 519 rx_buf = NULL;
520 goto out;
454 } 521 }
455 522
456 /* Release card resources - assumes all RX buffers consumed in-order 523 /* Release card resources - assumes all RX buffers consumed in-order
@@ -467,6 +534,7 @@ void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
467 * prefetched into cache. 534 * prefetched into cache.
468 */ 535 */
469 rx_buf->len = len; 536 rx_buf->len = len;
537out:
470 if (rx_queue->channel->rx_pkt) 538 if (rx_queue->channel->rx_pkt)
471 __efx_rx_packet(rx_queue->channel, 539 __efx_rx_packet(rx_queue->channel,
472 rx_queue->channel->rx_pkt, 540 rx_queue->channel->rx_pkt,