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