diff options
author | Alexandre Rames <arames@solarflare.com> | 2013-01-11 07:26:21 -0500 |
---|---|---|
committer | Ben Hutchings <bhutchings@solarflare.com> | 2013-03-07 15:21:57 -0500 |
commit | 97d48a10c670f87bba9e5b2241e32f2eccd3fef0 (patch) | |
tree | 49751747e27c3963e1bd1f788ea4005f9f5e964f | |
parent | 9230451af9efcf5e3d60ce7f4fec2468e8ce54b1 (diff) |
sfc: Remove rx_alloc_method SKB
[bwh: Remove more dead code, and make efx_ptp_rx() pull the data it
needs into the header area.]
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
-rw-r--r-- | drivers/net/ethernet/sfc/efx.c | 8 | ||||
-rw-r--r-- | drivers/net/ethernet/sfc/efx.h | 1 | ||||
-rw-r--r-- | drivers/net/ethernet/sfc/net_driver.h | 23 | ||||
-rw-r--r-- | drivers/net/ethernet/sfc/ptp.c | 4 | ||||
-rw-r--r-- | drivers/net/ethernet/sfc/rx.c | 330 |
5 files changed, 101 insertions, 265 deletions
diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c index 0bc00991d310..11a81084bec4 100644 --- a/drivers/net/ethernet/sfc/efx.c +++ b/drivers/net/ethernet/sfc/efx.c | |||
@@ -247,10 +247,8 @@ static int efx_process_channel(struct efx_channel *channel, int budget) | |||
247 | __efx_rx_packet(channel, channel->rx_pkt); | 247 | __efx_rx_packet(channel, channel->rx_pkt); |
248 | channel->rx_pkt = NULL; | 248 | channel->rx_pkt = NULL; |
249 | } | 249 | } |
250 | if (rx_queue->enabled) { | 250 | if (rx_queue->enabled) |
251 | efx_rx_strategy(channel); | ||
252 | efx_fast_push_rx_descriptors(rx_queue); | 251 | efx_fast_push_rx_descriptors(rx_queue); |
253 | } | ||
254 | } | 252 | } |
255 | 253 | ||
256 | return spent; | 254 | return spent; |
@@ -655,16 +653,12 @@ static void efx_start_datapath(struct efx_nic *efx) | |||
655 | efx_for_each_channel_tx_queue(tx_queue, channel) | 653 | efx_for_each_channel_tx_queue(tx_queue, channel) |
656 | efx_init_tx_queue(tx_queue); | 654 | efx_init_tx_queue(tx_queue); |
657 | 655 | ||
658 | /* The rx buffer allocation strategy is MTU dependent */ | ||
659 | efx_rx_strategy(channel); | ||
660 | |||
661 | efx_for_each_channel_rx_queue(rx_queue, channel) { | 656 | efx_for_each_channel_rx_queue(rx_queue, channel) { |
662 | efx_init_rx_queue(rx_queue); | 657 | efx_init_rx_queue(rx_queue); |
663 | efx_nic_generate_fill_event(rx_queue); | 658 | efx_nic_generate_fill_event(rx_queue); |
664 | } | 659 | } |
665 | 660 | ||
666 | WARN_ON(channel->rx_pkt != NULL); | 661 | WARN_ON(channel->rx_pkt != NULL); |
667 | efx_rx_strategy(channel); | ||
668 | } | 662 | } |
669 | 663 | ||
670 | if (netif_device_present(efx->net_dev)) | 664 | if (netif_device_present(efx->net_dev)) |
diff --git a/drivers/net/ethernet/sfc/efx.h b/drivers/net/ethernet/sfc/efx.h index d2f790df6dcb..64c555e493be 100644 --- a/drivers/net/ethernet/sfc/efx.h +++ b/drivers/net/ethernet/sfc/efx.h | |||
@@ -37,7 +37,6 @@ extern int efx_probe_rx_queue(struct efx_rx_queue *rx_queue); | |||
37 | extern void efx_remove_rx_queue(struct efx_rx_queue *rx_queue); | 37 | extern void efx_remove_rx_queue(struct efx_rx_queue *rx_queue); |
38 | extern void efx_init_rx_queue(struct efx_rx_queue *rx_queue); | 38 | extern void efx_init_rx_queue(struct efx_rx_queue *rx_queue); |
39 | extern void efx_fini_rx_queue(struct efx_rx_queue *rx_queue); | 39 | extern void efx_fini_rx_queue(struct efx_rx_queue *rx_queue); |
40 | extern void efx_rx_strategy(struct efx_channel *channel); | ||
41 | extern void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue); | 40 | extern void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue); |
42 | extern void efx_rx_slow_fill(unsigned long context); | 41 | extern void efx_rx_slow_fill(unsigned long context); |
43 | extern void __efx_rx_packet(struct efx_channel *channel, | 42 | extern void __efx_rx_packet(struct efx_channel *channel, |
diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index cdcf510311c3..c83fe090406d 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h | |||
@@ -206,25 +206,19 @@ struct efx_tx_queue { | |||
206 | /** | 206 | /** |
207 | * struct efx_rx_buffer - An Efx RX data buffer | 207 | * struct efx_rx_buffer - An Efx RX data buffer |
208 | * @dma_addr: DMA base address of the buffer | 208 | * @dma_addr: DMA base address of the buffer |
209 | * @skb: The associated socket buffer. Valid iff !(@flags & %EFX_RX_BUF_PAGE). | 209 | * @page: The associated page buffer. |
210 | * Will be %NULL if the buffer slot is currently free. | 210 | * Will be %NULL if the buffer slot is currently free. |
211 | * @page: The associated page buffer. Valif iff @flags & %EFX_RX_BUF_PAGE. | 211 | * @page_offset: Offset within page |
212 | * Will be %NULL if the buffer slot is currently free. | ||
213 | * @page_offset: Offset within page. Valid iff @flags & %EFX_RX_BUF_PAGE. | ||
214 | * @len: Buffer length, in bytes. | 212 | * @len: Buffer length, in bytes. |
215 | * @flags: Flags for buffer and packet state. | 213 | * @flags: Flags for buffer and packet state. |
216 | */ | 214 | */ |
217 | struct efx_rx_buffer { | 215 | struct efx_rx_buffer { |
218 | dma_addr_t dma_addr; | 216 | dma_addr_t dma_addr; |
219 | union { | 217 | struct page *page; |
220 | struct sk_buff *skb; | ||
221 | struct page *page; | ||
222 | } u; | ||
223 | u16 page_offset; | 218 | u16 page_offset; |
224 | u16 len; | 219 | u16 len; |
225 | u16 flags; | 220 | u16 flags; |
226 | }; | 221 | }; |
227 | #define EFX_RX_BUF_PAGE 0x0001 | ||
228 | #define EFX_RX_PKT_CSUMMED 0x0002 | 222 | #define EFX_RX_PKT_CSUMMED 0x0002 |
229 | #define EFX_RX_PKT_DISCARD 0x0004 | 223 | #define EFX_RX_PKT_DISCARD 0x0004 |
230 | 224 | ||
@@ -266,8 +260,6 @@ struct efx_rx_page_state { | |||
266 | * @min_fill: RX descriptor minimum non-zero fill level. | 260 | * @min_fill: RX descriptor minimum non-zero fill level. |
267 | * This records the minimum fill level observed when a ring | 261 | * This records the minimum fill level observed when a ring |
268 | * refill was triggered. | 262 | * refill was triggered. |
269 | * @alloc_page_count: RX allocation strategy counter. | ||
270 | * @alloc_skb_count: RX allocation strategy counter. | ||
271 | * @slow_fill: Timer used to defer efx_nic_generate_fill_event(). | 263 | * @slow_fill: Timer used to defer efx_nic_generate_fill_event(). |
272 | */ | 264 | */ |
273 | struct efx_rx_queue { | 265 | struct efx_rx_queue { |
@@ -286,8 +278,6 @@ struct efx_rx_queue { | |||
286 | unsigned int fast_fill_trigger; | 278 | unsigned int fast_fill_trigger; |
287 | unsigned int min_fill; | 279 | unsigned int min_fill; |
288 | unsigned int min_overfill; | 280 | unsigned int min_overfill; |
289 | unsigned int alloc_page_count; | ||
290 | unsigned int alloc_skb_count; | ||
291 | struct timer_list slow_fill; | 281 | struct timer_list slow_fill; |
292 | unsigned int slow_fill_count; | 282 | unsigned int slow_fill_count; |
293 | }; | 283 | }; |
@@ -336,10 +326,6 @@ enum efx_rx_alloc_method { | |||
336 | * @event_test_cpu: Last CPU to handle interrupt or test event for this channel | 326 | * @event_test_cpu: Last CPU to handle interrupt or test event for this channel |
337 | * @irq_count: Number of IRQs since last adaptive moderation decision | 327 | * @irq_count: Number of IRQs since last adaptive moderation decision |
338 | * @irq_mod_score: IRQ moderation score | 328 | * @irq_mod_score: IRQ moderation score |
339 | * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors | ||
340 | * and diagnostic counters | ||
341 | * @rx_alloc_push_pages: RX allocation method currently in use for pushing | ||
342 | * descriptors | ||
343 | * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors | 329 | * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors |
344 | * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors | 330 | * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors |
345 | * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors | 331 | * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors |
@@ -371,9 +357,6 @@ struct efx_channel { | |||
371 | unsigned int rfs_filters_added; | 357 | unsigned int rfs_filters_added; |
372 | #endif | 358 | #endif |
373 | 359 | ||
374 | int rx_alloc_level; | ||
375 | int rx_alloc_push_pages; | ||
376 | |||
377 | unsigned n_rx_tobe_disc; | 360 | unsigned n_rx_tobe_disc; |
378 | unsigned n_rx_ip_hdr_chksum_err; | 361 | unsigned n_rx_ip_hdr_chksum_err; |
379 | unsigned n_rx_tcp_udp_chksum_err; | 362 | unsigned n_rx_tcp_udp_chksum_err; |
diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c index d1858c0e0827..07f6baa15c0c 100644 --- a/drivers/net/ethernet/sfc/ptp.c +++ b/drivers/net/ethernet/sfc/ptp.c | |||
@@ -1000,7 +1000,7 @@ static bool efx_ptp_rx(struct efx_channel *channel, struct sk_buff *skb) | |||
1000 | 1000 | ||
1001 | /* Correct version? */ | 1001 | /* Correct version? */ |
1002 | if (ptp->mode == MC_CMD_PTP_MODE_V1) { | 1002 | if (ptp->mode == MC_CMD_PTP_MODE_V1) { |
1003 | if (skb->len < PTP_V1_MIN_LENGTH) { | 1003 | if (!pskb_may_pull(skb, PTP_V1_MIN_LENGTH)) { |
1004 | return false; | 1004 | return false; |
1005 | } | 1005 | } |
1006 | version = ntohs(*(__be16 *)&skb->data[PTP_V1_VERSION_OFFSET]); | 1006 | version = ntohs(*(__be16 *)&skb->data[PTP_V1_VERSION_OFFSET]); |
@@ -1014,7 +1014,7 @@ static bool efx_ptp_rx(struct efx_channel *channel, struct sk_buff *skb) | |||
1014 | match_data_012 = skb->data + PTP_V1_UUID_OFFSET; | 1014 | match_data_012 = skb->data + PTP_V1_UUID_OFFSET; |
1015 | match_data_345 = skb->data + PTP_V1_UUID_OFFSET + 3; | 1015 | match_data_345 = skb->data + PTP_V1_UUID_OFFSET + 3; |
1016 | } else { | 1016 | } else { |
1017 | if (skb->len < PTP_V2_MIN_LENGTH) { | 1017 | if (!pskb_may_pull(skb, PTP_V2_MIN_LENGTH)) { |
1018 | return false; | 1018 | return false; |
1019 | } | 1019 | } |
1020 | version = skb->data[PTP_V2_VERSION_OFFSET]; | 1020 | version = skb->data[PTP_V2_VERSION_OFFSET]; |
diff --git a/drivers/net/ethernet/sfc/rx.c b/drivers/net/ethernet/sfc/rx.c index f31c23ea2a07..e7aa28eb9327 100644 --- a/drivers/net/ethernet/sfc/rx.c +++ b/drivers/net/ethernet/sfc/rx.c | |||
@@ -33,46 +33,6 @@ | |||
33 | /* Size of buffer allocated for skb header area. */ | 33 | /* Size of buffer allocated for skb header area. */ |
34 | #define EFX_SKB_HEADERS 64u | 34 | #define EFX_SKB_HEADERS 64u |
35 | 35 | ||
36 | /* | ||
37 | * rx_alloc_method - RX buffer allocation method | ||
38 | * | ||
39 | * This driver supports two methods for allocating and using RX buffers: | ||
40 | * each RX buffer may be backed by an skb or by an order-n page. | ||
41 | * | ||
42 | * When GRO is in use then the second method has a lower overhead, | ||
43 | * since we don't have to allocate then free skbs on reassembled frames. | ||
44 | * | ||
45 | * Values: | ||
46 | * - RX_ALLOC_METHOD_AUTO = 0 | ||
47 | * - RX_ALLOC_METHOD_SKB = 1 | ||
48 | * - RX_ALLOC_METHOD_PAGE = 2 | ||
49 | * | ||
50 | * The heuristic for %RX_ALLOC_METHOD_AUTO is a simple hysteresis count | ||
51 | * controlled by the parameters below. | ||
52 | * | ||
53 | * - Since pushing and popping descriptors are separated by the rx_queue | ||
54 | * size, so the watermarks should be ~rxd_size. | ||
55 | * - The performance win by using page-based allocation for GRO is less | ||
56 | * than the performance hit of using page-based allocation of non-GRO, | ||
57 | * so the watermarks should reflect this. | ||
58 | * | ||
59 | * Per channel we maintain a single variable, updated by each channel: | ||
60 | * | ||
61 | * rx_alloc_level += (gro_performed ? RX_ALLOC_FACTOR_GRO : | ||
62 | * RX_ALLOC_FACTOR_SKB) | ||
63 | * Per NAPI poll interval, we constrain rx_alloc_level to 0..MAX (which | ||
64 | * limits the hysteresis), and update the allocation strategy: | ||
65 | * | ||
66 | * rx_alloc_method = (rx_alloc_level > RX_ALLOC_LEVEL_GRO ? | ||
67 | * RX_ALLOC_METHOD_PAGE : RX_ALLOC_METHOD_SKB) | ||
68 | */ | ||
69 | static int rx_alloc_method = RX_ALLOC_METHOD_AUTO; | ||
70 | |||
71 | #define RX_ALLOC_LEVEL_GRO 0x2000 | ||
72 | #define RX_ALLOC_LEVEL_MAX 0x3000 | ||
73 | #define RX_ALLOC_FACTOR_GRO 1 | ||
74 | #define RX_ALLOC_FACTOR_SKB (-2) | ||
75 | |||
76 | /* This is the percentage fill level below which new RX descriptors | 36 | /* This is the percentage fill level below which new RX descriptors |
77 | * will be added to the RX descriptor ring. | 37 | * will be added to the RX descriptor ring. |
78 | */ | 38 | */ |
@@ -99,10 +59,7 @@ static inline unsigned int efx_rx_buf_size(struct efx_nic *efx) | |||
99 | 59 | ||
100 | static u8 *efx_rx_buf_eh(struct efx_nic *efx, struct efx_rx_buffer *buf) | 60 | static u8 *efx_rx_buf_eh(struct efx_nic *efx, struct efx_rx_buffer *buf) |
101 | { | 61 | { |
102 | if (buf->flags & EFX_RX_BUF_PAGE) | 62 | return page_address(buf->page) + efx_rx_buf_offset(efx, buf); |
103 | return page_address(buf->u.page) + efx_rx_buf_offset(efx, buf); | ||
104 | else | ||
105 | return (u8 *)buf->u.skb->data + efx->type->rx_buffer_hash_size; | ||
106 | } | 63 | } |
107 | 64 | ||
108 | static inline u32 efx_rx_buf_hash(const u8 *eh) | 65 | static inline u32 efx_rx_buf_hash(const u8 *eh) |
@@ -120,56 +77,7 @@ static inline u32 efx_rx_buf_hash(const u8 *eh) | |||
120 | } | 77 | } |
121 | 78 | ||
122 | /** | 79 | /** |
123 | * efx_init_rx_buffers_skb - create EFX_RX_BATCH skb-based RX buffers | 80 | * efx_init_rx_buffers - create EFX_RX_BATCH page-based RX buffers |
124 | * | ||
125 | * @rx_queue: Efx RX queue | ||
126 | * | ||
127 | * This allocates EFX_RX_BATCH skbs, maps them for DMA, and populates a | ||
128 | * struct efx_rx_buffer for each one. Return a negative error code or 0 | ||
129 | * on success. May fail having only inserted fewer than EFX_RX_BATCH | ||
130 | * buffers. | ||
131 | */ | ||
132 | static int efx_init_rx_buffers_skb(struct efx_rx_queue *rx_queue) | ||
133 | { | ||
134 | struct efx_nic *efx = rx_queue->efx; | ||
135 | struct net_device *net_dev = efx->net_dev; | ||
136 | struct efx_rx_buffer *rx_buf; | ||
137 | struct sk_buff *skb; | ||
138 | int skb_len = efx->rx_buffer_len; | ||
139 | unsigned index, count; | ||
140 | |||
141 | for (count = 0; count < EFX_RX_BATCH; ++count) { | ||
142 | index = rx_queue->added_count & rx_queue->ptr_mask; | ||
143 | rx_buf = efx_rx_buffer(rx_queue, index); | ||
144 | |||
145 | rx_buf->u.skb = skb = netdev_alloc_skb(net_dev, skb_len); | ||
146 | if (unlikely(!skb)) | ||
147 | return -ENOMEM; | ||
148 | |||
149 | /* Adjust the SKB for padding */ | ||
150 | skb_reserve(skb, NET_IP_ALIGN); | ||
151 | rx_buf->len = skb_len - NET_IP_ALIGN; | ||
152 | rx_buf->flags = 0; | ||
153 | |||
154 | rx_buf->dma_addr = dma_map_single(&efx->pci_dev->dev, | ||
155 | skb->data, rx_buf->len, | ||
156 | DMA_FROM_DEVICE); | ||
157 | if (unlikely(dma_mapping_error(&efx->pci_dev->dev, | ||
158 | rx_buf->dma_addr))) { | ||
159 | dev_kfree_skb_any(skb); | ||
160 | rx_buf->u.skb = NULL; | ||
161 | return -EIO; | ||
162 | } | ||
163 | |||
164 | ++rx_queue->added_count; | ||
165 | ++rx_queue->alloc_skb_count; | ||
166 | } | ||
167 | |||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * efx_init_rx_buffers_page - create EFX_RX_BATCH page-based RX buffers | ||
173 | * | 81 | * |
174 | * @rx_queue: Efx RX queue | 82 | * @rx_queue: Efx RX queue |
175 | * | 83 | * |
@@ -178,7 +86,7 @@ static int efx_init_rx_buffers_skb(struct efx_rx_queue *rx_queue) | |||
178 | * code or 0 on success. If a single page can be split between two buffers, | 86 | * code or 0 on success. If a single page can be split between two buffers, |
179 | * then the page will either be inserted fully, or not at at all. | 87 | * then the page will either be inserted fully, or not at at all. |
180 | */ | 88 | */ |
181 | static int efx_init_rx_buffers_page(struct efx_rx_queue *rx_queue) | 89 | static int efx_init_rx_buffers(struct efx_rx_queue *rx_queue) |
182 | { | 90 | { |
183 | struct efx_nic *efx = rx_queue->efx; | 91 | struct efx_nic *efx = rx_queue->efx; |
184 | struct efx_rx_buffer *rx_buf; | 92 | struct efx_rx_buffer *rx_buf; |
@@ -214,12 +122,11 @@ static int efx_init_rx_buffers_page(struct efx_rx_queue *rx_queue) | |||
214 | index = rx_queue->added_count & rx_queue->ptr_mask; | 122 | index = rx_queue->added_count & rx_queue->ptr_mask; |
215 | rx_buf = efx_rx_buffer(rx_queue, index); | 123 | rx_buf = efx_rx_buffer(rx_queue, index); |
216 | rx_buf->dma_addr = dma_addr + EFX_PAGE_IP_ALIGN; | 124 | rx_buf->dma_addr = dma_addr + EFX_PAGE_IP_ALIGN; |
217 | rx_buf->u.page = page; | 125 | rx_buf->page = page; |
218 | rx_buf->page_offset = page_offset + EFX_PAGE_IP_ALIGN; | 126 | rx_buf->page_offset = page_offset + EFX_PAGE_IP_ALIGN; |
219 | rx_buf->len = efx->rx_buffer_len - EFX_PAGE_IP_ALIGN; | 127 | rx_buf->len = efx->rx_buffer_len - EFX_PAGE_IP_ALIGN; |
220 | rx_buf->flags = EFX_RX_BUF_PAGE; | 128 | rx_buf->flags = 0; |
221 | ++rx_queue->added_count; | 129 | ++rx_queue->added_count; |
222 | ++rx_queue->alloc_page_count; | ||
223 | ++state->refcnt; | 130 | ++state->refcnt; |
224 | 131 | ||
225 | if ((~count & 1) && (efx->rx_buffer_len <= EFX_RX_HALF_PAGE)) { | 132 | if ((~count & 1) && (efx->rx_buffer_len <= EFX_RX_HALF_PAGE)) { |
@@ -239,10 +146,10 @@ static void efx_unmap_rx_buffer(struct efx_nic *efx, | |||
239 | struct efx_rx_buffer *rx_buf, | 146 | struct efx_rx_buffer *rx_buf, |
240 | unsigned int used_len) | 147 | unsigned int used_len) |
241 | { | 148 | { |
242 | if ((rx_buf->flags & EFX_RX_BUF_PAGE) && rx_buf->u.page) { | 149 | if (rx_buf->page) { |
243 | struct efx_rx_page_state *state; | 150 | struct efx_rx_page_state *state; |
244 | 151 | ||
245 | state = page_address(rx_buf->u.page); | 152 | state = page_address(rx_buf->page); |
246 | if (--state->refcnt == 0) { | 153 | if (--state->refcnt == 0) { |
247 | dma_unmap_page(&efx->pci_dev->dev, | 154 | dma_unmap_page(&efx->pci_dev->dev, |
248 | state->dma_addr, | 155 | state->dma_addr, |
@@ -253,21 +160,15 @@ static void efx_unmap_rx_buffer(struct efx_nic *efx, | |||
253 | rx_buf->dma_addr, used_len, | 160 | rx_buf->dma_addr, used_len, |
254 | DMA_FROM_DEVICE); | 161 | DMA_FROM_DEVICE); |
255 | } | 162 | } |
256 | } else if (!(rx_buf->flags & EFX_RX_BUF_PAGE) && rx_buf->u.skb) { | ||
257 | dma_unmap_single(&efx->pci_dev->dev, rx_buf->dma_addr, | ||
258 | rx_buf->len, DMA_FROM_DEVICE); | ||
259 | } | 163 | } |
260 | } | 164 | } |
261 | 165 | ||
262 | static void efx_free_rx_buffer(struct efx_nic *efx, | 166 | static void efx_free_rx_buffer(struct efx_nic *efx, |
263 | struct efx_rx_buffer *rx_buf) | 167 | struct efx_rx_buffer *rx_buf) |
264 | { | 168 | { |
265 | if ((rx_buf->flags & EFX_RX_BUF_PAGE) && rx_buf->u.page) { | 169 | if (rx_buf->page) { |
266 | __free_pages(rx_buf->u.page, efx->rx_buffer_order); | 170 | __free_pages(rx_buf->page, efx->rx_buffer_order); |
267 | rx_buf->u.page = NULL; | 171 | rx_buf->page = NULL; |
268 | } else if (!(rx_buf->flags & EFX_RX_BUF_PAGE) && rx_buf->u.skb) { | ||
269 | dev_kfree_skb_any(rx_buf->u.skb); | ||
270 | rx_buf->u.skb = NULL; | ||
271 | } | 172 | } |
272 | } | 173 | } |
273 | 174 | ||
@@ -283,7 +184,7 @@ static void efx_fini_rx_buffer(struct efx_rx_queue *rx_queue, | |||
283 | static void efx_resurrect_rx_buffer(struct efx_rx_queue *rx_queue, | 184 | static void efx_resurrect_rx_buffer(struct efx_rx_queue *rx_queue, |
284 | struct efx_rx_buffer *rx_buf) | 185 | struct efx_rx_buffer *rx_buf) |
285 | { | 186 | { |
286 | struct efx_rx_page_state *state = page_address(rx_buf->u.page); | 187 | struct efx_rx_page_state *state = page_address(rx_buf->page); |
287 | struct efx_rx_buffer *new_buf; | 188 | struct efx_rx_buffer *new_buf; |
288 | unsigned fill_level, index; | 189 | unsigned fill_level, index; |
289 | 190 | ||
@@ -298,14 +199,13 @@ static void efx_resurrect_rx_buffer(struct efx_rx_queue *rx_queue, | |||
298 | } | 199 | } |
299 | 200 | ||
300 | ++state->refcnt; | 201 | ++state->refcnt; |
301 | get_page(rx_buf->u.page); | 202 | get_page(rx_buf->page); |
302 | 203 | ||
303 | index = rx_queue->added_count & rx_queue->ptr_mask; | 204 | index = rx_queue->added_count & rx_queue->ptr_mask; |
304 | new_buf = efx_rx_buffer(rx_queue, index); | 205 | new_buf = efx_rx_buffer(rx_queue, index); |
305 | new_buf->dma_addr = rx_buf->dma_addr ^ (PAGE_SIZE >> 1); | 206 | new_buf->dma_addr = rx_buf->dma_addr ^ (PAGE_SIZE >> 1); |
306 | new_buf->u.page = rx_buf->u.page; | 207 | new_buf->page = rx_buf->page; |
307 | new_buf->len = rx_buf->len; | 208 | new_buf->len = rx_buf->len; |
308 | new_buf->flags = EFX_RX_BUF_PAGE; | ||
309 | ++rx_queue->added_count; | 209 | ++rx_queue->added_count; |
310 | } | 210 | } |
311 | 211 | ||
@@ -319,18 +219,17 @@ static void efx_recycle_rx_buffer(struct efx_channel *channel, | |||
319 | struct efx_rx_buffer *new_buf; | 219 | struct efx_rx_buffer *new_buf; |
320 | unsigned index; | 220 | unsigned index; |
321 | 221 | ||
322 | rx_buf->flags &= EFX_RX_BUF_PAGE; | 222 | rx_buf->flags = 0; |
323 | 223 | ||
324 | if ((rx_buf->flags & EFX_RX_BUF_PAGE) && | 224 | if (efx->rx_buffer_len <= EFX_RX_HALF_PAGE && |
325 | efx->rx_buffer_len <= EFX_RX_HALF_PAGE && | 225 | page_count(rx_buf->page) == 1) |
326 | page_count(rx_buf->u.page) == 1) | ||
327 | efx_resurrect_rx_buffer(rx_queue, rx_buf); | 226 | efx_resurrect_rx_buffer(rx_queue, rx_buf); |
328 | 227 | ||
329 | index = rx_queue->added_count & rx_queue->ptr_mask; | 228 | index = rx_queue->added_count & rx_queue->ptr_mask; |
330 | new_buf = efx_rx_buffer(rx_queue, index); | 229 | new_buf = efx_rx_buffer(rx_queue, index); |
331 | 230 | ||
332 | memcpy(new_buf, rx_buf, sizeof(*new_buf)); | 231 | memcpy(new_buf, rx_buf, sizeof(*new_buf)); |
333 | rx_buf->u.page = NULL; | 232 | rx_buf->page = NULL; |
334 | ++rx_queue->added_count; | 233 | ++rx_queue->added_count; |
335 | } | 234 | } |
336 | 235 | ||
@@ -348,7 +247,6 @@ static void efx_recycle_rx_buffer(struct efx_channel *channel, | |||
348 | */ | 247 | */ |
349 | void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue) | 248 | void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue) |
350 | { | 249 | { |
351 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); | ||
352 | unsigned fill_level; | 250 | unsigned fill_level; |
353 | int space, rc = 0; | 251 | int space, rc = 0; |
354 | 252 | ||
@@ -369,16 +267,13 @@ void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue) | |||
369 | 267 | ||
370 | netif_vdbg(rx_queue->efx, rx_status, rx_queue->efx->net_dev, | 268 | netif_vdbg(rx_queue->efx, rx_status, rx_queue->efx->net_dev, |
371 | "RX queue %d fast-filling descriptor ring from" | 269 | "RX queue %d fast-filling descriptor ring from" |
372 | " level %d to level %d using %s allocation\n", | 270 | " level %d to level %d\n", |
373 | efx_rx_queue_index(rx_queue), fill_level, | 271 | efx_rx_queue_index(rx_queue), fill_level, |
374 | rx_queue->max_fill, | 272 | rx_queue->max_fill); |
375 | channel->rx_alloc_push_pages ? "page" : "skb"); | 273 | |
376 | 274 | ||
377 | do { | 275 | do { |
378 | if (channel->rx_alloc_push_pages) | 276 | rc = efx_init_rx_buffers(rx_queue); |
379 | rc = efx_init_rx_buffers_page(rx_queue); | ||
380 | else | ||
381 | rc = efx_init_rx_buffers_skb(rx_queue); | ||
382 | if (unlikely(rc)) { | 277 | if (unlikely(rc)) { |
383 | /* Ensure that we don't leave the rx queue empty */ | 278 | /* Ensure that we don't leave the rx queue empty */ |
384 | if (rx_queue->added_count == rx_queue->removed_count) | 279 | if (rx_queue->added_count == rx_queue->removed_count) |
@@ -408,7 +303,7 @@ void efx_rx_slow_fill(unsigned long context) | |||
408 | 303 | ||
409 | static void efx_rx_packet__check_len(struct efx_rx_queue *rx_queue, | 304 | static void efx_rx_packet__check_len(struct efx_rx_queue *rx_queue, |
410 | struct efx_rx_buffer *rx_buf, | 305 | struct efx_rx_buffer *rx_buf, |
411 | int len, bool *leak_packet) | 306 | int len) |
412 | { | 307 | { |
413 | struct efx_nic *efx = rx_queue->efx; | 308 | struct efx_nic *efx = rx_queue->efx; |
414 | unsigned max_len = rx_buf->len - efx->type->rx_buffer_padding; | 309 | unsigned max_len = rx_buf->len - efx->type->rx_buffer_padding; |
@@ -428,11 +323,6 @@ static void efx_rx_packet__check_len(struct efx_rx_queue *rx_queue, | |||
428 | "RX event (0x%x > 0x%x+0x%x). Leaking\n", | 323 | "RX event (0x%x > 0x%x+0x%x). Leaking\n", |
429 | efx_rx_queue_index(rx_queue), len, max_len, | 324 | efx_rx_queue_index(rx_queue), len, max_len, |
430 | efx->type->rx_buffer_padding); | 325 | efx->type->rx_buffer_padding); |
431 | /* If this buffer was skb-allocated, then the meta | ||
432 | * data at the end of the skb will be trashed. So | ||
433 | * we have no choice but to leak the fragment. | ||
434 | */ | ||
435 | *leak_packet = !(rx_buf->flags & EFX_RX_BUF_PAGE); | ||
436 | efx_schedule_reset(efx, RESET_TYPE_RX_RECOVERY); | 326 | efx_schedule_reset(efx, RESET_TYPE_RX_RECOVERY); |
437 | } else { | 327 | } else { |
438 | if (net_ratelimit()) | 328 | if (net_ratelimit()) |
@@ -454,51 +344,78 @@ static void efx_rx_packet_gro(struct efx_channel *channel, | |||
454 | { | 344 | { |
455 | struct napi_struct *napi = &channel->napi_str; | 345 | struct napi_struct *napi = &channel->napi_str; |
456 | gro_result_t gro_result; | 346 | gro_result_t gro_result; |
347 | struct efx_nic *efx = channel->efx; | ||
348 | struct page *page = rx_buf->page; | ||
349 | struct sk_buff *skb; | ||
457 | 350 | ||
458 | if (rx_buf->flags & EFX_RX_BUF_PAGE) { | 351 | rx_buf->page = NULL; |
459 | struct efx_nic *efx = channel->efx; | ||
460 | struct page *page = rx_buf->u.page; | ||
461 | struct sk_buff *skb; | ||
462 | |||
463 | rx_buf->u.page = NULL; | ||
464 | 352 | ||
465 | skb = napi_get_frags(napi); | 353 | skb = napi_get_frags(napi); |
466 | if (!skb) { | 354 | if (!skb) { |
467 | put_page(page); | 355 | put_page(page); |
468 | return; | 356 | return; |
469 | } | 357 | } |
470 | 358 | ||
471 | if (efx->net_dev->features & NETIF_F_RXHASH) | 359 | if (efx->net_dev->features & NETIF_F_RXHASH) |
472 | skb->rxhash = efx_rx_buf_hash(eh); | 360 | skb->rxhash = efx_rx_buf_hash(eh); |
473 | 361 | ||
474 | skb_fill_page_desc(skb, 0, page, | 362 | skb_fill_page_desc(skb, 0, page, |
475 | efx_rx_buf_offset(efx, rx_buf), rx_buf->len); | 363 | efx_rx_buf_offset(efx, rx_buf), rx_buf->len); |
476 | 364 | ||
477 | skb->len = rx_buf->len; | 365 | skb->len = rx_buf->len; |
478 | skb->data_len = rx_buf->len; | 366 | skb->data_len = rx_buf->len; |
479 | skb->truesize += rx_buf->len; | 367 | skb->truesize += rx_buf->len; |
480 | skb->ip_summed = ((rx_buf->flags & EFX_RX_PKT_CSUMMED) ? | 368 | skb->ip_summed = ((rx_buf->flags & EFX_RX_PKT_CSUMMED) ? |
481 | CHECKSUM_UNNECESSARY : CHECKSUM_NONE); | 369 | CHECKSUM_UNNECESSARY : CHECKSUM_NONE); |
482 | 370 | ||
483 | skb_record_rx_queue(skb, channel->rx_queue.core_index); | 371 | skb_record_rx_queue(skb, channel->rx_queue.core_index); |
484 | 372 | ||
485 | gro_result = napi_gro_frags(napi); | 373 | gro_result = napi_gro_frags(napi); |
486 | } else { | ||
487 | struct sk_buff *skb = rx_buf->u.skb; | ||
488 | 374 | ||
489 | EFX_BUG_ON_PARANOID(!(rx_buf->flags & EFX_RX_PKT_CSUMMED)); | 375 | if (gro_result != GRO_DROP) |
490 | rx_buf->u.skb = NULL; | 376 | channel->irq_mod_score += 2; |
491 | skb->ip_summed = CHECKSUM_UNNECESSARY; | 377 | } |
492 | 378 | ||
493 | gro_result = napi_gro_receive(napi, skb); | 379 | /* Allocate and construct an SKB around a struct page.*/ |
494 | } | 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; | ||
495 | 386 | ||
496 | if (gro_result == GRO_NORMAL) { | 387 | /* Allocate an SKB to store the headers */ |
497 | channel->rx_alloc_level += RX_ALLOC_FACTOR_SKB; | 388 | skb = netdev_alloc_skb(efx->net_dev, hdr_len + EFX_PAGE_SKB_ALIGN); |
498 | } else if (gro_result != GRO_DROP) { | 389 | if (unlikely(skb == NULL)) |
499 | channel->rx_alloc_level += RX_ALLOC_FACTOR_GRO; | 390 | return NULL; |
500 | channel->irq_mod_score += 2; | 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; | ||
501 | } | 410 | } |
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; | ||
502 | } | 419 | } |
503 | 420 | ||
504 | void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index, | 421 | void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index, |
@@ -507,7 +424,6 @@ void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index, | |||
507 | struct efx_nic *efx = rx_queue->efx; | 424 | struct efx_nic *efx = rx_queue->efx; |
508 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); | 425 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
509 | struct efx_rx_buffer *rx_buf; | 426 | struct efx_rx_buffer *rx_buf; |
510 | bool leak_packet = false; | ||
511 | 427 | ||
512 | rx_buf = efx_rx_buffer(rx_queue, index); | 428 | rx_buf = efx_rx_buffer(rx_queue, index); |
513 | rx_buf->flags |= flags; | 429 | rx_buf->flags |= flags; |
@@ -519,7 +435,7 @@ void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index, | |||
519 | rx_queue->removed_count++; | 435 | rx_queue->removed_count++; |
520 | 436 | ||
521 | /* Validate the length encoded in the event vs the descriptor pushed */ | 437 | /* Validate the length encoded in the event vs the descriptor pushed */ |
522 | efx_rx_packet__check_len(rx_queue, rx_buf, len, &leak_packet); | 438 | efx_rx_packet__check_len(rx_queue, rx_buf, len); |
523 | 439 | ||
524 | netif_vdbg(efx, rx_status, efx->net_dev, | 440 | netif_vdbg(efx, rx_status, efx->net_dev, |
525 | "RX queue %d received id %x at %llx+%x %s%s\n", | 441 | "RX queue %d received id %x at %llx+%x %s%s\n", |
@@ -530,10 +446,7 @@ void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index, | |||
530 | 446 | ||
531 | /* Discard packet, if instructed to do so */ | 447 | /* Discard packet, if instructed to do so */ |
532 | if (unlikely(rx_buf->flags & EFX_RX_PKT_DISCARD)) { | 448 | if (unlikely(rx_buf->flags & EFX_RX_PKT_DISCARD)) { |
533 | if (unlikely(leak_packet)) | 449 | efx_recycle_rx_buffer(channel, rx_buf); |
534 | channel->n_skbuff_leaks++; | ||
535 | else | ||
536 | efx_recycle_rx_buffer(channel, rx_buf); | ||
537 | 450 | ||
538 | /* Don't hold off the previous receive */ | 451 | /* Don't hold off the previous receive */ |
539 | rx_buf = NULL; | 452 | rx_buf = NULL; |
@@ -560,31 +473,28 @@ out: | |||
560 | channel->rx_pkt = rx_buf; | 473 | channel->rx_pkt = rx_buf; |
561 | } | 474 | } |
562 | 475 | ||
563 | static void efx_rx_deliver(struct efx_channel *channel, | 476 | static void efx_rx_deliver(struct efx_channel *channel, u8 *eh, |
564 | struct efx_rx_buffer *rx_buf) | 477 | struct efx_rx_buffer *rx_buf) |
565 | { | 478 | { |
566 | struct sk_buff *skb; | 479 | struct sk_buff *skb; |
480 | u16 hdr_len = min_t(u16, rx_buf->len, EFX_SKB_HEADERS); | ||
567 | 481 | ||
568 | /* We now own the SKB */ | 482 | skb = efx_rx_mk_skb(channel, rx_buf, eh, hdr_len); |
569 | skb = rx_buf->u.skb; | 483 | if (unlikely(skb == NULL)) { |
570 | rx_buf->u.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); | ||
571 | 488 | ||
572 | /* Set the SKB flags */ | 489 | /* Set the SKB flags */ |
573 | skb_checksum_none_assert(skb); | 490 | skb_checksum_none_assert(skb); |
574 | 491 | ||
575 | /* Record the rx_queue */ | ||
576 | skb_record_rx_queue(skb, channel->rx_queue.core_index); | ||
577 | |||
578 | if (channel->type->receive_skb) | 492 | if (channel->type->receive_skb) |
579 | if (channel->type->receive_skb(channel, skb)) | 493 | if (channel->type->receive_skb(channel, skb)) |
580 | goto handled; | 494 | return; |
581 | 495 | ||
582 | /* Pass the packet up */ | 496 | /* Pass the packet up */ |
583 | netif_receive_skb(skb); | 497 | netif_receive_skb(skb); |
584 | |||
585 | handled: | ||
586 | /* Update allocation strategy method */ | ||
587 | channel->rx_alloc_level += RX_ALLOC_FACTOR_SKB; | ||
588 | } | 498 | } |
589 | 499 | ||
590 | /* Handle a received packet. Second half: Touches packet payload. */ | 500 | /* Handle a received packet. Second half: Touches packet payload. */ |
@@ -602,60 +512,13 @@ void __efx_rx_packet(struct efx_channel *channel, struct efx_rx_buffer *rx_buf) | |||
602 | return; | 512 | return; |
603 | } | 513 | } |
604 | 514 | ||
605 | if (!(rx_buf->flags & EFX_RX_BUF_PAGE)) { | ||
606 | struct sk_buff *skb = rx_buf->u.skb; | ||
607 | |||
608 | prefetch(skb_shinfo(skb)); | ||
609 | |||
610 | skb_reserve(skb, efx->type->rx_buffer_hash_size); | ||
611 | skb_put(skb, rx_buf->len); | ||
612 | |||
613 | if (efx->net_dev->features & NETIF_F_RXHASH) | ||
614 | skb->rxhash = efx_rx_buf_hash(eh); | ||
615 | |||
616 | /* Move past the ethernet header. rx_buf->data still points | ||
617 | * at the ethernet header */ | ||
618 | skb->protocol = eth_type_trans(skb, efx->net_dev); | ||
619 | |||
620 | skb_record_rx_queue(skb, channel->rx_queue.core_index); | ||
621 | } | ||
622 | |||
623 | if (unlikely(!(efx->net_dev->features & NETIF_F_RXCSUM))) | 515 | if (unlikely(!(efx->net_dev->features & NETIF_F_RXCSUM))) |
624 | rx_buf->flags &= ~EFX_RX_PKT_CSUMMED; | 516 | rx_buf->flags &= ~EFX_RX_PKT_CSUMMED; |
625 | 517 | ||
626 | if (likely(rx_buf->flags & (EFX_RX_BUF_PAGE | EFX_RX_PKT_CSUMMED)) && | 518 | if (!channel->type->receive_skb) |
627 | !channel->type->receive_skb) | ||
628 | efx_rx_packet_gro(channel, rx_buf, eh); | 519 | efx_rx_packet_gro(channel, rx_buf, eh); |
629 | else | 520 | else |
630 | efx_rx_deliver(channel, rx_buf); | 521 | efx_rx_deliver(channel, eh, rx_buf); |
631 | } | ||
632 | |||
633 | void efx_rx_strategy(struct efx_channel *channel) | ||
634 | { | ||
635 | enum efx_rx_alloc_method method = rx_alloc_method; | ||
636 | |||
637 | if (channel->type->receive_skb) { | ||
638 | channel->rx_alloc_push_pages = false; | ||
639 | return; | ||
640 | } | ||
641 | |||
642 | /* Only makes sense to use page based allocation if GRO is enabled */ | ||
643 | if (!(channel->efx->net_dev->features & NETIF_F_GRO)) { | ||
644 | method = RX_ALLOC_METHOD_SKB; | ||
645 | } else if (method == RX_ALLOC_METHOD_AUTO) { | ||
646 | /* Constrain the rx_alloc_level */ | ||
647 | if (channel->rx_alloc_level < 0) | ||
648 | channel->rx_alloc_level = 0; | ||
649 | else if (channel->rx_alloc_level > RX_ALLOC_LEVEL_MAX) | ||
650 | channel->rx_alloc_level = RX_ALLOC_LEVEL_MAX; | ||
651 | |||
652 | /* Decide on the allocation method */ | ||
653 | method = ((channel->rx_alloc_level > RX_ALLOC_LEVEL_GRO) ? | ||
654 | RX_ALLOC_METHOD_PAGE : RX_ALLOC_METHOD_SKB); | ||
655 | } | ||
656 | |||
657 | /* Push the option */ | ||
658 | channel->rx_alloc_push_pages = (method == RX_ALLOC_METHOD_PAGE); | ||
659 | } | 522 | } |
660 | 523 | ||
661 | int efx_probe_rx_queue(struct efx_rx_queue *rx_queue) | 524 | int efx_probe_rx_queue(struct efx_rx_queue *rx_queue) |
@@ -756,9 +619,6 @@ void efx_remove_rx_queue(struct efx_rx_queue *rx_queue) | |||
756 | } | 619 | } |
757 | 620 | ||
758 | 621 | ||
759 | module_param(rx_alloc_method, int, 0644); | ||
760 | MODULE_PARM_DESC(rx_alloc_method, "Allocation method used for RX buffers"); | ||
761 | |||
762 | module_param(rx_refill_threshold, uint, 0444); | 622 | module_param(rx_refill_threshold, uint, 0444); |
763 | MODULE_PARM_DESC(rx_refill_threshold, | 623 | MODULE_PARM_DESC(rx_refill_threshold, |
764 | "RX descriptor ring refill threshold (%)"); | 624 | "RX descriptor ring refill threshold (%)"); |