diff options
Diffstat (limited to 'drivers/net/sfc/tx.c')
-rw-r--r-- | drivers/net/sfc/tx.c | 189 |
1 files changed, 101 insertions, 88 deletions
diff --git a/drivers/net/sfc/tx.c b/drivers/net/sfc/tx.c index 489c4de31447..be0e110a1f73 100644 --- a/drivers/net/sfc/tx.c +++ b/drivers/net/sfc/tx.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | * Driver for Solarflare Solarstorm network controllers and boards | 2 | * Driver for Solarflare Solarstorm network controllers and boards |
3 | * Copyright 2005-2006 Fen Systems Ltd. | 3 | * Copyright 2005-2006 Fen Systems Ltd. |
4 | * Copyright 2005-2008 Solarflare Communications Inc. | 4 | * Copyright 2005-2009 Solarflare Communications Inc. |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | 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 | 7 | * under the terms of the GNU General Public License version 2 as published |
@@ -12,12 +12,14 @@ | |||
12 | #include <linux/tcp.h> | 12 | #include <linux/tcp.h> |
13 | #include <linux/ip.h> | 13 | #include <linux/ip.h> |
14 | #include <linux/in.h> | 14 | #include <linux/in.h> |
15 | #include <linux/ipv6.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <net/ipv6.h> | ||
15 | #include <linux/if_ether.h> | 18 | #include <linux/if_ether.h> |
16 | #include <linux/highmem.h> | 19 | #include <linux/highmem.h> |
17 | #include "net_driver.h" | 20 | #include "net_driver.h" |
18 | #include "tx.h" | ||
19 | #include "efx.h" | 21 | #include "efx.h" |
20 | #include "falcon.h" | 22 | #include "nic.h" |
21 | #include "workarounds.h" | 23 | #include "workarounds.h" |
22 | 24 | ||
23 | /* | 25 | /* |
@@ -26,8 +28,7 @@ | |||
26 | * The tx_queue descriptor ring fill-level must fall below this value | 28 | * The tx_queue descriptor ring fill-level must fall below this value |
27 | * before we restart the netif queue | 29 | * before we restart the netif queue |
28 | */ | 30 | */ |
29 | #define EFX_NETDEV_TX_THRESHOLD(_tx_queue) \ | 31 | #define EFX_TXQ_THRESHOLD (EFX_TXQ_MASK / 2u) |
30 | (_tx_queue->efx->type->txd_ring_mask / 2u) | ||
31 | 32 | ||
32 | /* We want to be able to nest calls to netif_stop_queue(), since each | 33 | /* We want to be able to nest calls to netif_stop_queue(), since each |
33 | * channel can have an individual stop on the queue. | 34 | * channel can have an individual stop on the queue. |
@@ -125,6 +126,24 @@ static void efx_tsoh_free(struct efx_tx_queue *tx_queue, | |||
125 | } | 126 | } |
126 | 127 | ||
127 | 128 | ||
129 | static inline unsigned | ||
130 | efx_max_tx_len(struct efx_nic *efx, dma_addr_t dma_addr) | ||
131 | { | ||
132 | /* Depending on the NIC revision, we can use descriptor | ||
133 | * lengths up to 8K or 8K-1. However, since PCI Express | ||
134 | * devices must split read requests at 4K boundaries, there is | ||
135 | * little benefit from using descriptors that cross those | ||
136 | * boundaries and we keep things simple by not doing so. | ||
137 | */ | ||
138 | unsigned len = (~dma_addr & 0xfff) + 1; | ||
139 | |||
140 | /* Work around hardware bug for unaligned buffers. */ | ||
141 | if (EFX_WORKAROUND_5391(efx) && (dma_addr & 0xf)) | ||
142 | len = min_t(unsigned, len, 512 - (dma_addr & 0xf)); | ||
143 | |||
144 | return len; | ||
145 | } | ||
146 | |||
128 | /* | 147 | /* |
129 | * Add a socket buffer to a TX queue | 148 | * Add a socket buffer to a TX queue |
130 | * | 149 | * |
@@ -135,11 +154,13 @@ static void efx_tsoh_free(struct efx_tx_queue *tx_queue, | |||
135 | * If any DMA mapping fails, any mapped fragments will be unmapped, | 154 | * If any DMA mapping fails, any mapped fragments will be unmapped, |
136 | * the queue's insert pointer will be restored to its original value. | 155 | * the queue's insert pointer will be restored to its original value. |
137 | * | 156 | * |
157 | * This function is split out from efx_hard_start_xmit to allow the | ||
158 | * loopback test to direct packets via specific TX queues. | ||
159 | * | ||
138 | * Returns NETDEV_TX_OK or NETDEV_TX_BUSY | 160 | * Returns NETDEV_TX_OK or NETDEV_TX_BUSY |
139 | * You must hold netif_tx_lock() to call this function. | 161 | * You must hold netif_tx_lock() to call this function. |
140 | */ | 162 | */ |
141 | static netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, | 163 | netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb) |
142 | struct sk_buff *skb) | ||
143 | { | 164 | { |
144 | struct efx_nic *efx = tx_queue->efx; | 165 | struct efx_nic *efx = tx_queue->efx; |
145 | struct pci_dev *pci_dev = efx->pci_dev; | 166 | struct pci_dev *pci_dev = efx->pci_dev; |
@@ -147,7 +168,7 @@ static netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, | |||
147 | skb_frag_t *fragment; | 168 | skb_frag_t *fragment; |
148 | struct page *page; | 169 | struct page *page; |
149 | int page_offset; | 170 | int page_offset; |
150 | unsigned int len, unmap_len = 0, fill_level, insert_ptr, misalign; | 171 | unsigned int len, unmap_len = 0, fill_level, insert_ptr; |
151 | dma_addr_t dma_addr, unmap_addr = 0; | 172 | dma_addr_t dma_addr, unmap_addr = 0; |
152 | unsigned int dma_len; | 173 | unsigned int dma_len; |
153 | bool unmap_single; | 174 | bool unmap_single; |
@@ -156,7 +177,7 @@ static netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, | |||
156 | 177 | ||
157 | EFX_BUG_ON_PARANOID(tx_queue->write_count != tx_queue->insert_count); | 178 | EFX_BUG_ON_PARANOID(tx_queue->write_count != tx_queue->insert_count); |
158 | 179 | ||
159 | if (skb_shinfo((struct sk_buff *)skb)->gso_size) | 180 | if (skb_shinfo(skb)->gso_size) |
160 | return efx_enqueue_skb_tso(tx_queue, skb); | 181 | return efx_enqueue_skb_tso(tx_queue, skb); |
161 | 182 | ||
162 | /* Get size of the initial fragment */ | 183 | /* Get size of the initial fragment */ |
@@ -171,7 +192,7 @@ static netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, | |||
171 | } | 192 | } |
172 | 193 | ||
173 | fill_level = tx_queue->insert_count - tx_queue->old_read_count; | 194 | fill_level = tx_queue->insert_count - tx_queue->old_read_count; |
174 | q_space = efx->type->txd_ring_mask - 1 - fill_level; | 195 | q_space = EFX_TXQ_MASK - 1 - fill_level; |
175 | 196 | ||
176 | /* Map for DMA. Use pci_map_single rather than pci_map_page | 197 | /* Map for DMA. Use pci_map_single rather than pci_map_page |
177 | * since this is more efficient on machines with sparse | 198 | * since this is more efficient on machines with sparse |
@@ -208,16 +229,14 @@ static netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, | |||
208 | &tx_queue->read_count; | 229 | &tx_queue->read_count; |
209 | fill_level = (tx_queue->insert_count | 230 | fill_level = (tx_queue->insert_count |
210 | - tx_queue->old_read_count); | 231 | - tx_queue->old_read_count); |
211 | q_space = (efx->type->txd_ring_mask - 1 - | 232 | q_space = EFX_TXQ_MASK - 1 - fill_level; |
212 | fill_level); | ||
213 | if (unlikely(q_space-- <= 0)) | 233 | if (unlikely(q_space-- <= 0)) |
214 | goto stop; | 234 | goto stop; |
215 | smp_mb(); | 235 | smp_mb(); |
216 | --tx_queue->stopped; | 236 | --tx_queue->stopped; |
217 | } | 237 | } |
218 | 238 | ||
219 | insert_ptr = (tx_queue->insert_count & | 239 | insert_ptr = tx_queue->insert_count & EFX_TXQ_MASK; |
220 | efx->type->txd_ring_mask); | ||
221 | buffer = &tx_queue->buffer[insert_ptr]; | 240 | buffer = &tx_queue->buffer[insert_ptr]; |
222 | efx_tsoh_free(tx_queue, buffer); | 241 | efx_tsoh_free(tx_queue, buffer); |
223 | EFX_BUG_ON_PARANOID(buffer->tsoh); | 242 | EFX_BUG_ON_PARANOID(buffer->tsoh); |
@@ -226,14 +245,10 @@ static netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, | |||
226 | EFX_BUG_ON_PARANOID(!buffer->continuation); | 245 | EFX_BUG_ON_PARANOID(!buffer->continuation); |
227 | EFX_BUG_ON_PARANOID(buffer->unmap_len); | 246 | EFX_BUG_ON_PARANOID(buffer->unmap_len); |
228 | 247 | ||
229 | dma_len = (((~dma_addr) & efx->type->tx_dma_mask) + 1); | 248 | dma_len = efx_max_tx_len(efx, dma_addr); |
230 | if (likely(dma_len > len)) | 249 | if (likely(dma_len >= len)) |
231 | dma_len = len; | 250 | dma_len = len; |
232 | 251 | ||
233 | misalign = (unsigned)dma_addr & efx->type->bug5391_mask; | ||
234 | if (misalign && dma_len + misalign > 512) | ||
235 | dma_len = 512 - misalign; | ||
236 | |||
237 | /* Fill out per descriptor fields */ | 252 | /* Fill out per descriptor fields */ |
238 | buffer->len = dma_len; | 253 | buffer->len = dma_len; |
239 | buffer->dma_addr = dma_addr; | 254 | buffer->dma_addr = dma_addr; |
@@ -266,7 +281,7 @@ static netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, | |||
266 | buffer->continuation = false; | 281 | buffer->continuation = false; |
267 | 282 | ||
268 | /* Pass off to hardware */ | 283 | /* Pass off to hardware */ |
269 | falcon_push_buffers(tx_queue); | 284 | efx_nic_push_buffers(tx_queue); |
270 | 285 | ||
271 | return NETDEV_TX_OK; | 286 | return NETDEV_TX_OK; |
272 | 287 | ||
@@ -276,7 +291,7 @@ static netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, | |||
276 | skb_shinfo(skb)->nr_frags + 1); | 291 | skb_shinfo(skb)->nr_frags + 1); |
277 | 292 | ||
278 | /* Mark the packet as transmitted, and free the SKB ourselves */ | 293 | /* Mark the packet as transmitted, and free the SKB ourselves */ |
279 | dev_kfree_skb_any((struct sk_buff *)skb); | 294 | dev_kfree_skb_any(skb); |
280 | goto unwind; | 295 | goto unwind; |
281 | 296 | ||
282 | stop: | 297 | stop: |
@@ -289,7 +304,7 @@ static netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, | |||
289 | /* Work backwards until we hit the original insert pointer value */ | 304 | /* Work backwards until we hit the original insert pointer value */ |
290 | while (tx_queue->insert_count != tx_queue->write_count) { | 305 | while (tx_queue->insert_count != tx_queue->write_count) { |
291 | --tx_queue->insert_count; | 306 | --tx_queue->insert_count; |
292 | insert_ptr = tx_queue->insert_count & efx->type->txd_ring_mask; | 307 | insert_ptr = tx_queue->insert_count & EFX_TXQ_MASK; |
293 | buffer = &tx_queue->buffer[insert_ptr]; | 308 | buffer = &tx_queue->buffer[insert_ptr]; |
294 | efx_dequeue_buffer(tx_queue, buffer); | 309 | efx_dequeue_buffer(tx_queue, buffer); |
295 | buffer->len = 0; | 310 | buffer->len = 0; |
@@ -318,10 +333,9 @@ static void efx_dequeue_buffers(struct efx_tx_queue *tx_queue, | |||
318 | { | 333 | { |
319 | struct efx_nic *efx = tx_queue->efx; | 334 | struct efx_nic *efx = tx_queue->efx; |
320 | unsigned int stop_index, read_ptr; | 335 | unsigned int stop_index, read_ptr; |
321 | unsigned int mask = tx_queue->efx->type->txd_ring_mask; | ||
322 | 336 | ||
323 | stop_index = (index + 1) & mask; | 337 | stop_index = (index + 1) & EFX_TXQ_MASK; |
324 | read_ptr = tx_queue->read_count & mask; | 338 | read_ptr = tx_queue->read_count & EFX_TXQ_MASK; |
325 | 339 | ||
326 | while (read_ptr != stop_index) { | 340 | while (read_ptr != stop_index) { |
327 | struct efx_tx_buffer *buffer = &tx_queue->buffer[read_ptr]; | 341 | struct efx_tx_buffer *buffer = &tx_queue->buffer[read_ptr]; |
@@ -338,28 +352,10 @@ static void efx_dequeue_buffers(struct efx_tx_queue *tx_queue, | |||
338 | buffer->len = 0; | 352 | buffer->len = 0; |
339 | 353 | ||
340 | ++tx_queue->read_count; | 354 | ++tx_queue->read_count; |
341 | read_ptr = tx_queue->read_count & mask; | 355 | read_ptr = tx_queue->read_count & EFX_TXQ_MASK; |
342 | } | 356 | } |
343 | } | 357 | } |
344 | 358 | ||
345 | /* Initiate a packet transmission on the specified TX queue. | ||
346 | * Note that returning anything other than NETDEV_TX_OK will cause the | ||
347 | * OS to free the skb. | ||
348 | * | ||
349 | * This function is split out from efx_hard_start_xmit to allow the | ||
350 | * loopback test to direct packets via specific TX queues. It is | ||
351 | * therefore a non-static inline, so as not to penalise performance | ||
352 | * for non-loopback transmissions. | ||
353 | * | ||
354 | * Context: netif_tx_lock held | ||
355 | */ | ||
356 | inline netdev_tx_t efx_xmit(struct efx_nic *efx, | ||
357 | struct efx_tx_queue *tx_queue, struct sk_buff *skb) | ||
358 | { | ||
359 | /* Map fragments for DMA and add to TX queue */ | ||
360 | return efx_enqueue_skb(tx_queue, skb); | ||
361 | } | ||
362 | |||
363 | /* Initiate a packet transmission. We use one channel per CPU | 359 | /* Initiate a packet transmission. We use one channel per CPU |
364 | * (sharing when we have more CPUs than channels). On Falcon, the TX | 360 | * (sharing when we have more CPUs than channels). On Falcon, the TX |
365 | * completion events will be directed back to the CPU that transmitted | 361 | * completion events will be directed back to the CPU that transmitted |
@@ -383,7 +379,7 @@ netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb, | |||
383 | else | 379 | else |
384 | tx_queue = &efx->tx_queue[EFX_TX_QUEUE_NO_CSUM]; | 380 | tx_queue = &efx->tx_queue[EFX_TX_QUEUE_NO_CSUM]; |
385 | 381 | ||
386 | return efx_xmit(efx, tx_queue, skb); | 382 | return efx_enqueue_skb(tx_queue, skb); |
387 | } | 383 | } |
388 | 384 | ||
389 | void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index) | 385 | void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index) |
@@ -391,7 +387,7 @@ void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index) | |||
391 | unsigned fill_level; | 387 | unsigned fill_level; |
392 | struct efx_nic *efx = tx_queue->efx; | 388 | struct efx_nic *efx = tx_queue->efx; |
393 | 389 | ||
394 | EFX_BUG_ON_PARANOID(index > efx->type->txd_ring_mask); | 390 | EFX_BUG_ON_PARANOID(index > EFX_TXQ_MASK); |
395 | 391 | ||
396 | efx_dequeue_buffers(tx_queue, index); | 392 | efx_dequeue_buffers(tx_queue, index); |
397 | 393 | ||
@@ -401,7 +397,7 @@ void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index) | |||
401 | smp_mb(); | 397 | smp_mb(); |
402 | if (unlikely(tx_queue->stopped) && likely(efx->port_enabled)) { | 398 | if (unlikely(tx_queue->stopped) && likely(efx->port_enabled)) { |
403 | fill_level = tx_queue->insert_count - tx_queue->read_count; | 399 | fill_level = tx_queue->insert_count - tx_queue->read_count; |
404 | if (fill_level < EFX_NETDEV_TX_THRESHOLD(tx_queue)) { | 400 | if (fill_level < EFX_TXQ_THRESHOLD) { |
405 | EFX_BUG_ON_PARANOID(!efx_dev_registered(efx)); | 401 | EFX_BUG_ON_PARANOID(!efx_dev_registered(efx)); |
406 | 402 | ||
407 | /* Do this under netif_tx_lock(), to avoid racing | 403 | /* Do this under netif_tx_lock(), to avoid racing |
@@ -425,15 +421,15 @@ int efx_probe_tx_queue(struct efx_tx_queue *tx_queue) | |||
425 | EFX_LOG(efx, "creating TX queue %d\n", tx_queue->queue); | 421 | EFX_LOG(efx, "creating TX queue %d\n", tx_queue->queue); |
426 | 422 | ||
427 | /* Allocate software ring */ | 423 | /* Allocate software ring */ |
428 | txq_size = (efx->type->txd_ring_mask + 1) * sizeof(*tx_queue->buffer); | 424 | txq_size = EFX_TXQ_SIZE * sizeof(*tx_queue->buffer); |
429 | tx_queue->buffer = kzalloc(txq_size, GFP_KERNEL); | 425 | tx_queue->buffer = kzalloc(txq_size, GFP_KERNEL); |
430 | if (!tx_queue->buffer) | 426 | if (!tx_queue->buffer) |
431 | return -ENOMEM; | 427 | return -ENOMEM; |
432 | for (i = 0; i <= efx->type->txd_ring_mask; ++i) | 428 | for (i = 0; i <= EFX_TXQ_MASK; ++i) |
433 | tx_queue->buffer[i].continuation = true; | 429 | tx_queue->buffer[i].continuation = true; |
434 | 430 | ||
435 | /* Allocate hardware ring */ | 431 | /* Allocate hardware ring */ |
436 | rc = falcon_probe_tx(tx_queue); | 432 | rc = efx_nic_probe_tx(tx_queue); |
437 | if (rc) | 433 | if (rc) |
438 | goto fail; | 434 | goto fail; |
439 | 435 | ||
@@ -456,7 +452,7 @@ void efx_init_tx_queue(struct efx_tx_queue *tx_queue) | |||
456 | BUG_ON(tx_queue->stopped); | 452 | BUG_ON(tx_queue->stopped); |
457 | 453 | ||
458 | /* Set up TX descriptor ring */ | 454 | /* Set up TX descriptor ring */ |
459 | falcon_init_tx(tx_queue); | 455 | efx_nic_init_tx(tx_queue); |
460 | } | 456 | } |
461 | 457 | ||
462 | void efx_release_tx_buffers(struct efx_tx_queue *tx_queue) | 458 | void efx_release_tx_buffers(struct efx_tx_queue *tx_queue) |
@@ -468,8 +464,7 @@ void efx_release_tx_buffers(struct efx_tx_queue *tx_queue) | |||
468 | 464 | ||
469 | /* Free any buffers left in the ring */ | 465 | /* Free any buffers left in the ring */ |
470 | while (tx_queue->read_count != tx_queue->write_count) { | 466 | while (tx_queue->read_count != tx_queue->write_count) { |
471 | buffer = &tx_queue->buffer[tx_queue->read_count & | 467 | buffer = &tx_queue->buffer[tx_queue->read_count & EFX_TXQ_MASK]; |
472 | tx_queue->efx->type->txd_ring_mask]; | ||
473 | efx_dequeue_buffer(tx_queue, buffer); | 468 | efx_dequeue_buffer(tx_queue, buffer); |
474 | buffer->continuation = true; | 469 | buffer->continuation = true; |
475 | buffer->len = 0; | 470 | buffer->len = 0; |
@@ -483,7 +478,7 @@ void efx_fini_tx_queue(struct efx_tx_queue *tx_queue) | |||
483 | EFX_LOG(tx_queue->efx, "shutting down TX queue %d\n", tx_queue->queue); | 478 | EFX_LOG(tx_queue->efx, "shutting down TX queue %d\n", tx_queue->queue); |
484 | 479 | ||
485 | /* Flush TX queue, remove descriptor ring */ | 480 | /* Flush TX queue, remove descriptor ring */ |
486 | falcon_fini_tx(tx_queue); | 481 | efx_nic_fini_tx(tx_queue); |
487 | 482 | ||
488 | efx_release_tx_buffers(tx_queue); | 483 | efx_release_tx_buffers(tx_queue); |
489 | 484 | ||
@@ -500,7 +495,7 @@ void efx_fini_tx_queue(struct efx_tx_queue *tx_queue) | |||
500 | void efx_remove_tx_queue(struct efx_tx_queue *tx_queue) | 495 | void efx_remove_tx_queue(struct efx_tx_queue *tx_queue) |
501 | { | 496 | { |
502 | EFX_LOG(tx_queue->efx, "destroying TX queue %d\n", tx_queue->queue); | 497 | EFX_LOG(tx_queue->efx, "destroying TX queue %d\n", tx_queue->queue); |
503 | falcon_remove_tx(tx_queue); | 498 | efx_nic_remove_tx(tx_queue); |
504 | 499 | ||
505 | kfree(tx_queue->buffer); | 500 | kfree(tx_queue->buffer); |
506 | tx_queue->buffer = NULL; | 501 | tx_queue->buffer = NULL; |
@@ -539,6 +534,7 @@ void efx_remove_tx_queue(struct efx_tx_queue *tx_queue) | |||
539 | #define ETH_HDR_LEN(skb) (skb_network_header(skb) - (skb)->data) | 534 | #define ETH_HDR_LEN(skb) (skb_network_header(skb) - (skb)->data) |
540 | #define SKB_TCP_OFF(skb) PTR_DIFF(tcp_hdr(skb), (skb)->data) | 535 | #define SKB_TCP_OFF(skb) PTR_DIFF(tcp_hdr(skb), (skb)->data) |
541 | #define SKB_IPV4_OFF(skb) PTR_DIFF(ip_hdr(skb), (skb)->data) | 536 | #define SKB_IPV4_OFF(skb) PTR_DIFF(ip_hdr(skb), (skb)->data) |
537 | #define SKB_IPV6_OFF(skb) PTR_DIFF(ipv6_hdr(skb), (skb)->data) | ||
542 | 538 | ||
543 | /** | 539 | /** |
544 | * struct tso_state - TSO state for an SKB | 540 | * struct tso_state - TSO state for an SKB |
@@ -551,6 +547,7 @@ void efx_remove_tx_queue(struct efx_tx_queue *tx_queue) | |||
551 | * @unmap_len: Length of SKB fragment | 547 | * @unmap_len: Length of SKB fragment |
552 | * @unmap_addr: DMA address of SKB fragment | 548 | * @unmap_addr: DMA address of SKB fragment |
553 | * @unmap_single: DMA single vs page mapping flag | 549 | * @unmap_single: DMA single vs page mapping flag |
550 | * @protocol: Network protocol (after any VLAN header) | ||
554 | * @header_len: Number of bytes of header | 551 | * @header_len: Number of bytes of header |
555 | * @full_packet_size: Number of bytes to put in each outgoing segment | 552 | * @full_packet_size: Number of bytes to put in each outgoing segment |
556 | * | 553 | * |
@@ -571,6 +568,7 @@ struct tso_state { | |||
571 | dma_addr_t unmap_addr; | 568 | dma_addr_t unmap_addr; |
572 | bool unmap_single; | 569 | bool unmap_single; |
573 | 570 | ||
571 | __be16 protocol; | ||
574 | unsigned header_len; | 572 | unsigned header_len; |
575 | int full_packet_size; | 573 | int full_packet_size; |
576 | }; | 574 | }; |
@@ -578,9 +576,9 @@ struct tso_state { | |||
578 | 576 | ||
579 | /* | 577 | /* |
580 | * Verify that our various assumptions about sk_buffs and the conditions | 578 | * Verify that our various assumptions about sk_buffs and the conditions |
581 | * under which TSO will be attempted hold true. | 579 | * under which TSO will be attempted hold true. Return the protocol number. |
582 | */ | 580 | */ |
583 | static void efx_tso_check_safe(struct sk_buff *skb) | 581 | static __be16 efx_tso_check_protocol(struct sk_buff *skb) |
584 | { | 582 | { |
585 | __be16 protocol = skb->protocol; | 583 | __be16 protocol = skb->protocol; |
586 | 584 | ||
@@ -595,13 +593,22 @@ static void efx_tso_check_safe(struct sk_buff *skb) | |||
595 | if (protocol == htons(ETH_P_IP)) | 593 | if (protocol == htons(ETH_P_IP)) |
596 | skb_set_transport_header(skb, sizeof(*veh) + | 594 | skb_set_transport_header(skb, sizeof(*veh) + |
597 | 4 * ip_hdr(skb)->ihl); | 595 | 4 * ip_hdr(skb)->ihl); |
596 | else if (protocol == htons(ETH_P_IPV6)) | ||
597 | skb_set_transport_header(skb, sizeof(*veh) + | ||
598 | sizeof(struct ipv6hdr)); | ||
598 | } | 599 | } |
599 | 600 | ||
600 | EFX_BUG_ON_PARANOID(protocol != htons(ETH_P_IP)); | 601 | if (protocol == htons(ETH_P_IP)) { |
601 | EFX_BUG_ON_PARANOID(ip_hdr(skb)->protocol != IPPROTO_TCP); | 602 | EFX_BUG_ON_PARANOID(ip_hdr(skb)->protocol != IPPROTO_TCP); |
603 | } else { | ||
604 | EFX_BUG_ON_PARANOID(protocol != htons(ETH_P_IPV6)); | ||
605 | EFX_BUG_ON_PARANOID(ipv6_hdr(skb)->nexthdr != NEXTHDR_TCP); | ||
606 | } | ||
602 | EFX_BUG_ON_PARANOID((PTR_DIFF(tcp_hdr(skb), skb->data) | 607 | EFX_BUG_ON_PARANOID((PTR_DIFF(tcp_hdr(skb), skb->data) |
603 | + (tcp_hdr(skb)->doff << 2u)) > | 608 | + (tcp_hdr(skb)->doff << 2u)) > |
604 | skb_headlen(skb)); | 609 | skb_headlen(skb)); |
610 | |||
611 | return protocol; | ||
605 | } | 612 | } |
606 | 613 | ||
607 | 614 | ||
@@ -708,14 +715,14 @@ static int efx_tx_queue_insert(struct efx_tx_queue *tx_queue, | |||
708 | { | 715 | { |
709 | struct efx_tx_buffer *buffer; | 716 | struct efx_tx_buffer *buffer; |
710 | struct efx_nic *efx = tx_queue->efx; | 717 | struct efx_nic *efx = tx_queue->efx; |
711 | unsigned dma_len, fill_level, insert_ptr, misalign; | 718 | unsigned dma_len, fill_level, insert_ptr; |
712 | int q_space; | 719 | int q_space; |
713 | 720 | ||
714 | EFX_BUG_ON_PARANOID(len <= 0); | 721 | EFX_BUG_ON_PARANOID(len <= 0); |
715 | 722 | ||
716 | fill_level = tx_queue->insert_count - tx_queue->old_read_count; | 723 | fill_level = tx_queue->insert_count - tx_queue->old_read_count; |
717 | /* -1 as there is no way to represent all descriptors used */ | 724 | /* -1 as there is no way to represent all descriptors used */ |
718 | q_space = efx->type->txd_ring_mask - 1 - fill_level; | 725 | q_space = EFX_TXQ_MASK - 1 - fill_level; |
719 | 726 | ||
720 | while (1) { | 727 | while (1) { |
721 | if (unlikely(q_space-- <= 0)) { | 728 | if (unlikely(q_space-- <= 0)) { |
@@ -731,7 +738,7 @@ static int efx_tx_queue_insert(struct efx_tx_queue *tx_queue, | |||
731 | *(volatile unsigned *)&tx_queue->read_count; | 738 | *(volatile unsigned *)&tx_queue->read_count; |
732 | fill_level = (tx_queue->insert_count | 739 | fill_level = (tx_queue->insert_count |
733 | - tx_queue->old_read_count); | 740 | - tx_queue->old_read_count); |
734 | q_space = efx->type->txd_ring_mask - 1 - fill_level; | 741 | q_space = EFX_TXQ_MASK - 1 - fill_level; |
735 | if (unlikely(q_space-- <= 0)) { | 742 | if (unlikely(q_space-- <= 0)) { |
736 | *final_buffer = NULL; | 743 | *final_buffer = NULL; |
737 | return 1; | 744 | return 1; |
@@ -740,13 +747,13 @@ static int efx_tx_queue_insert(struct efx_tx_queue *tx_queue, | |||
740 | --tx_queue->stopped; | 747 | --tx_queue->stopped; |
741 | } | 748 | } |
742 | 749 | ||
743 | insert_ptr = tx_queue->insert_count & efx->type->txd_ring_mask; | 750 | insert_ptr = tx_queue->insert_count & EFX_TXQ_MASK; |
744 | buffer = &tx_queue->buffer[insert_ptr]; | 751 | buffer = &tx_queue->buffer[insert_ptr]; |
745 | ++tx_queue->insert_count; | 752 | ++tx_queue->insert_count; |
746 | 753 | ||
747 | EFX_BUG_ON_PARANOID(tx_queue->insert_count - | 754 | EFX_BUG_ON_PARANOID(tx_queue->insert_count - |
748 | tx_queue->read_count > | 755 | tx_queue->read_count > |
749 | efx->type->txd_ring_mask); | 756 | EFX_TXQ_MASK); |
750 | 757 | ||
751 | efx_tsoh_free(tx_queue, buffer); | 758 | efx_tsoh_free(tx_queue, buffer); |
752 | EFX_BUG_ON_PARANOID(buffer->len); | 759 | EFX_BUG_ON_PARANOID(buffer->len); |
@@ -757,12 +764,7 @@ static int efx_tx_queue_insert(struct efx_tx_queue *tx_queue, | |||
757 | 764 | ||
758 | buffer->dma_addr = dma_addr; | 765 | buffer->dma_addr = dma_addr; |
759 | 766 | ||
760 | /* Ensure we do not cross a boundary unsupported by H/W */ | 767 | dma_len = efx_max_tx_len(efx, dma_addr); |
761 | dma_len = (~dma_addr & efx->type->tx_dma_mask) + 1; | ||
762 | |||
763 | misalign = (unsigned)dma_addr & efx->type->bug5391_mask; | ||
764 | if (misalign && dma_len + misalign > 512) | ||
765 | dma_len = 512 - misalign; | ||
766 | 768 | ||
767 | /* If there is enough space to send then do so */ | 769 | /* If there is enough space to send then do so */ |
768 | if (dma_len >= len) | 770 | if (dma_len >= len) |
@@ -792,8 +794,7 @@ static void efx_tso_put_header(struct efx_tx_queue *tx_queue, | |||
792 | { | 794 | { |
793 | struct efx_tx_buffer *buffer; | 795 | struct efx_tx_buffer *buffer; |
794 | 796 | ||
795 | buffer = &tx_queue->buffer[tx_queue->insert_count & | 797 | buffer = &tx_queue->buffer[tx_queue->insert_count & EFX_TXQ_MASK]; |
796 | tx_queue->efx->type->txd_ring_mask]; | ||
797 | efx_tsoh_free(tx_queue, buffer); | 798 | efx_tsoh_free(tx_queue, buffer); |
798 | EFX_BUG_ON_PARANOID(buffer->len); | 799 | EFX_BUG_ON_PARANOID(buffer->len); |
799 | EFX_BUG_ON_PARANOID(buffer->unmap_len); | 800 | EFX_BUG_ON_PARANOID(buffer->unmap_len); |
@@ -818,11 +819,9 @@ static void efx_enqueue_unwind(struct efx_tx_queue *tx_queue) | |||
818 | while (tx_queue->insert_count != tx_queue->write_count) { | 819 | while (tx_queue->insert_count != tx_queue->write_count) { |
819 | --tx_queue->insert_count; | 820 | --tx_queue->insert_count; |
820 | buffer = &tx_queue->buffer[tx_queue->insert_count & | 821 | buffer = &tx_queue->buffer[tx_queue->insert_count & |
821 | tx_queue->efx->type->txd_ring_mask]; | 822 | EFX_TXQ_MASK]; |
822 | efx_tsoh_free(tx_queue, buffer); | 823 | efx_tsoh_free(tx_queue, buffer); |
823 | EFX_BUG_ON_PARANOID(buffer->skb); | 824 | EFX_BUG_ON_PARANOID(buffer->skb); |
824 | buffer->len = 0; | ||
825 | buffer->continuation = true; | ||
826 | if (buffer->unmap_len) { | 825 | if (buffer->unmap_len) { |
827 | unmap_addr = (buffer->dma_addr + buffer->len - | 826 | unmap_addr = (buffer->dma_addr + buffer->len - |
828 | buffer->unmap_len); | 827 | buffer->unmap_len); |
@@ -836,6 +835,8 @@ static void efx_enqueue_unwind(struct efx_tx_queue *tx_queue) | |||
836 | PCI_DMA_TODEVICE); | 835 | PCI_DMA_TODEVICE); |
837 | buffer->unmap_len = 0; | 836 | buffer->unmap_len = 0; |
838 | } | 837 | } |
838 | buffer->len = 0; | ||
839 | buffer->continuation = true; | ||
839 | } | 840 | } |
840 | } | 841 | } |
841 | 842 | ||
@@ -850,7 +851,10 @@ static void tso_start(struct tso_state *st, const struct sk_buff *skb) | |||
850 | + PTR_DIFF(tcp_hdr(skb), skb->data)); | 851 | + PTR_DIFF(tcp_hdr(skb), skb->data)); |
851 | st->full_packet_size = st->header_len + skb_shinfo(skb)->gso_size; | 852 | st->full_packet_size = st->header_len + skb_shinfo(skb)->gso_size; |
852 | 853 | ||
853 | st->ipv4_id = ntohs(ip_hdr(skb)->id); | 854 | if (st->protocol == htons(ETH_P_IP)) |
855 | st->ipv4_id = ntohs(ip_hdr(skb)->id); | ||
856 | else | ||
857 | st->ipv4_id = 0; | ||
854 | st->seqnum = ntohl(tcp_hdr(skb)->seq); | 858 | st->seqnum = ntohl(tcp_hdr(skb)->seq); |
855 | 859 | ||
856 | EFX_BUG_ON_PARANOID(tcp_hdr(skb)->urg); | 860 | EFX_BUG_ON_PARANOID(tcp_hdr(skb)->urg); |
@@ -965,7 +969,6 @@ static int tso_start_new_packet(struct efx_tx_queue *tx_queue, | |||
965 | struct tso_state *st) | 969 | struct tso_state *st) |
966 | { | 970 | { |
967 | struct efx_tso_header *tsoh; | 971 | struct efx_tso_header *tsoh; |
968 | struct iphdr *tsoh_iph; | ||
969 | struct tcphdr *tsoh_th; | 972 | struct tcphdr *tsoh_th; |
970 | unsigned ip_length; | 973 | unsigned ip_length; |
971 | u8 *header; | 974 | u8 *header; |
@@ -989,7 +992,6 @@ static int tso_start_new_packet(struct efx_tx_queue *tx_queue, | |||
989 | 992 | ||
990 | header = TSOH_BUFFER(tsoh); | 993 | header = TSOH_BUFFER(tsoh); |
991 | tsoh_th = (struct tcphdr *)(header + SKB_TCP_OFF(skb)); | 994 | tsoh_th = (struct tcphdr *)(header + SKB_TCP_OFF(skb)); |
992 | tsoh_iph = (struct iphdr *)(header + SKB_IPV4_OFF(skb)); | ||
993 | 995 | ||
994 | /* Copy and update the headers. */ | 996 | /* Copy and update the headers. */ |
995 | memcpy(header, skb->data, st->header_len); | 997 | memcpy(header, skb->data, st->header_len); |
@@ -1007,11 +1009,22 @@ static int tso_start_new_packet(struct efx_tx_queue *tx_queue, | |||
1007 | tsoh_th->fin = tcp_hdr(skb)->fin; | 1009 | tsoh_th->fin = tcp_hdr(skb)->fin; |
1008 | tsoh_th->psh = tcp_hdr(skb)->psh; | 1010 | tsoh_th->psh = tcp_hdr(skb)->psh; |
1009 | } | 1011 | } |
1010 | tsoh_iph->tot_len = htons(ip_length); | ||
1011 | 1012 | ||
1012 | /* Linux leaves suitable gaps in the IP ID space for us to fill. */ | 1013 | if (st->protocol == htons(ETH_P_IP)) { |
1013 | tsoh_iph->id = htons(st->ipv4_id); | 1014 | struct iphdr *tsoh_iph = |
1014 | st->ipv4_id++; | 1015 | (struct iphdr *)(header + SKB_IPV4_OFF(skb)); |
1016 | |||
1017 | tsoh_iph->tot_len = htons(ip_length); | ||
1018 | |||
1019 | /* Linux leaves suitable gaps in the IP ID space for us to fill. */ | ||
1020 | tsoh_iph->id = htons(st->ipv4_id); | ||
1021 | st->ipv4_id++; | ||
1022 | } else { | ||
1023 | struct ipv6hdr *tsoh_iph = | ||
1024 | (struct ipv6hdr *)(header + SKB_IPV6_OFF(skb)); | ||
1025 | |||
1026 | tsoh_iph->payload_len = htons(ip_length - sizeof(*tsoh_iph)); | ||
1027 | } | ||
1015 | 1028 | ||
1016 | st->packet_space = skb_shinfo(skb)->gso_size; | 1029 | st->packet_space = skb_shinfo(skb)->gso_size; |
1017 | ++tx_queue->tso_packets; | 1030 | ++tx_queue->tso_packets; |
@@ -1041,8 +1054,8 @@ static int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue, | |||
1041 | int frag_i, rc, rc2 = NETDEV_TX_OK; | 1054 | int frag_i, rc, rc2 = NETDEV_TX_OK; |
1042 | struct tso_state state; | 1055 | struct tso_state state; |
1043 | 1056 | ||
1044 | /* Verify TSO is safe - these checks should never fail. */ | 1057 | /* Find the packet protocol and sanity-check it */ |
1045 | efx_tso_check_safe(skb); | 1058 | state.protocol = efx_tso_check_protocol(skb); |
1046 | 1059 | ||
1047 | EFX_BUG_ON_PARANOID(tx_queue->write_count != tx_queue->insert_count); | 1060 | EFX_BUG_ON_PARANOID(tx_queue->write_count != tx_queue->insert_count); |
1048 | 1061 | ||
@@ -1092,14 +1105,14 @@ static int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue, | |||
1092 | } | 1105 | } |
1093 | 1106 | ||
1094 | /* Pass off to hardware */ | 1107 | /* Pass off to hardware */ |
1095 | falcon_push_buffers(tx_queue); | 1108 | efx_nic_push_buffers(tx_queue); |
1096 | 1109 | ||
1097 | tx_queue->tso_bursts++; | 1110 | tx_queue->tso_bursts++; |
1098 | return NETDEV_TX_OK; | 1111 | return NETDEV_TX_OK; |
1099 | 1112 | ||
1100 | mem_err: | 1113 | mem_err: |
1101 | EFX_ERR(efx, "Out of memory for TSO headers, or PCI mapping error\n"); | 1114 | EFX_ERR(efx, "Out of memory for TSO headers, or PCI mapping error\n"); |
1102 | dev_kfree_skb_any((struct sk_buff *)skb); | 1115 | dev_kfree_skb_any(skb); |
1103 | goto unwind; | 1116 | goto unwind; |
1104 | 1117 | ||
1105 | stop: | 1118 | stop: |
@@ -1135,7 +1148,7 @@ static void efx_fini_tso(struct efx_tx_queue *tx_queue) | |||
1135 | unsigned i; | 1148 | unsigned i; |
1136 | 1149 | ||
1137 | if (tx_queue->buffer) { | 1150 | if (tx_queue->buffer) { |
1138 | for (i = 0; i <= tx_queue->efx->type->txd_ring_mask; ++i) | 1151 | for (i = 0; i <= EFX_TXQ_MASK; ++i) |
1139 | efx_tsoh_free(tx_queue, &tx_queue->buffer[i]); | 1152 | efx_tsoh_free(tx_queue, &tx_queue->buffer[i]); |
1140 | } | 1153 | } |
1141 | 1154 | ||