diff options
Diffstat (limited to 'drivers/net/sfc/tx.c')
-rw-r--r-- | drivers/net/sfc/tx.c | 276 |
1 files changed, 155 insertions, 121 deletions
diff --git a/drivers/net/sfc/tx.c b/drivers/net/sfc/tx.c index c6942da2c99a..84eb99e0f8d2 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-2009 Solarflare Communications Inc. | 4 | * Copyright 2005-2010 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 |
@@ -28,51 +28,7 @@ | |||
28 | * 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 |
29 | * before we restart the netif queue | 29 | * before we restart the netif queue |
30 | */ | 30 | */ |
31 | #define EFX_TXQ_THRESHOLD (EFX_TXQ_MASK / 2u) | 31 | #define EFX_TXQ_THRESHOLD(_efx) ((_efx)->txq_entries / 2u) |
32 | |||
33 | /* We need to be able to nest calls to netif_tx_stop_queue(), partly | ||
34 | * because of the 2 hardware queues associated with each core queue, | ||
35 | * but also so that we can inhibit TX for reasons other than a full | ||
36 | * hardware queue. */ | ||
37 | void efx_stop_queue(struct efx_channel *channel) | ||
38 | { | ||
39 | struct efx_nic *efx = channel->efx; | ||
40 | |||
41 | if (!channel->tx_queue) | ||
42 | return; | ||
43 | |||
44 | spin_lock_bh(&channel->tx_stop_lock); | ||
45 | netif_vdbg(efx, tx_queued, efx->net_dev, "stop TX queue\n"); | ||
46 | |||
47 | atomic_inc(&channel->tx_stop_count); | ||
48 | netif_tx_stop_queue( | ||
49 | netdev_get_tx_queue( | ||
50 | efx->net_dev, | ||
51 | channel->tx_queue->queue / EFX_TXQ_TYPES)); | ||
52 | |||
53 | spin_unlock_bh(&channel->tx_stop_lock); | ||
54 | } | ||
55 | |||
56 | /* Decrement core TX queue stop count and wake it if the count is 0 */ | ||
57 | void efx_wake_queue(struct efx_channel *channel) | ||
58 | { | ||
59 | struct efx_nic *efx = channel->efx; | ||
60 | |||
61 | if (!channel->tx_queue) | ||
62 | return; | ||
63 | |||
64 | local_bh_disable(); | ||
65 | if (atomic_dec_and_lock(&channel->tx_stop_count, | ||
66 | &channel->tx_stop_lock)) { | ||
67 | netif_vdbg(efx, tx_queued, efx->net_dev, "waking TX queue\n"); | ||
68 | netif_tx_wake_queue( | ||
69 | netdev_get_tx_queue( | ||
70 | efx->net_dev, | ||
71 | channel->tx_queue->queue / EFX_TXQ_TYPES)); | ||
72 | spin_unlock(&channel->tx_stop_lock); | ||
73 | } | ||
74 | local_bh_enable(); | ||
75 | } | ||
76 | 32 | ||
77 | static void efx_dequeue_buffer(struct efx_tx_queue *tx_queue, | 33 | static void efx_dequeue_buffer(struct efx_tx_queue *tx_queue, |
78 | struct efx_tx_buffer *buffer) | 34 | struct efx_tx_buffer *buffer) |
@@ -207,7 +163,7 @@ netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb) | |||
207 | } | 163 | } |
208 | 164 | ||
209 | fill_level = tx_queue->insert_count - tx_queue->old_read_count; | 165 | fill_level = tx_queue->insert_count - tx_queue->old_read_count; |
210 | q_space = EFX_TXQ_MASK - 1 - fill_level; | 166 | q_space = efx->txq_entries - 1 - fill_level; |
211 | 167 | ||
212 | /* Map for DMA. Use pci_map_single rather than pci_map_page | 168 | /* Map for DMA. Use pci_map_single rather than pci_map_page |
213 | * since this is more efficient on machines with sparse | 169 | * since this is more efficient on machines with sparse |
@@ -234,24 +190,27 @@ netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb) | |||
234 | * checked. Update the xmit path's | 190 | * checked. Update the xmit path's |
235 | * copy of read_count. | 191 | * copy of read_count. |
236 | */ | 192 | */ |
237 | ++tx_queue->stopped; | 193 | netif_tx_stop_queue(tx_queue->core_txq); |
238 | /* This memory barrier protects the | 194 | /* This memory barrier protects the |
239 | * change of stopped from the access | 195 | * change of queue state from the access |
240 | * of read_count. */ | 196 | * of read_count. */ |
241 | smp_mb(); | 197 | smp_mb(); |
242 | tx_queue->old_read_count = | 198 | tx_queue->old_read_count = |
243 | *(volatile unsigned *) | 199 | ACCESS_ONCE(tx_queue->read_count); |
244 | &tx_queue->read_count; | ||
245 | fill_level = (tx_queue->insert_count | 200 | fill_level = (tx_queue->insert_count |
246 | - tx_queue->old_read_count); | 201 | - tx_queue->old_read_count); |
247 | q_space = EFX_TXQ_MASK - 1 - fill_level; | 202 | q_space = efx->txq_entries - 1 - fill_level; |
248 | if (unlikely(q_space-- <= 0)) | 203 | if (unlikely(q_space-- <= 0)) { |
249 | goto stop; | 204 | rc = NETDEV_TX_BUSY; |
205 | goto unwind; | ||
206 | } | ||
250 | smp_mb(); | 207 | smp_mb(); |
251 | --tx_queue->stopped; | 208 | if (likely(!efx->loopback_selftest)) |
209 | netif_tx_start_queue( | ||
210 | tx_queue->core_txq); | ||
252 | } | 211 | } |
253 | 212 | ||
254 | insert_ptr = tx_queue->insert_count & EFX_TXQ_MASK; | 213 | insert_ptr = tx_queue->insert_count & tx_queue->ptr_mask; |
255 | buffer = &tx_queue->buffer[insert_ptr]; | 214 | buffer = &tx_queue->buffer[insert_ptr]; |
256 | efx_tsoh_free(tx_queue, buffer); | 215 | efx_tsoh_free(tx_queue, buffer); |
257 | EFX_BUG_ON_PARANOID(buffer->tsoh); | 216 | EFX_BUG_ON_PARANOID(buffer->tsoh); |
@@ -308,19 +267,12 @@ netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb) | |||
308 | 267 | ||
309 | /* Mark the packet as transmitted, and free the SKB ourselves */ | 268 | /* Mark the packet as transmitted, and free the SKB ourselves */ |
310 | dev_kfree_skb_any(skb); | 269 | dev_kfree_skb_any(skb); |
311 | goto unwind; | ||
312 | |||
313 | stop: | ||
314 | rc = NETDEV_TX_BUSY; | ||
315 | |||
316 | if (tx_queue->stopped == 1) | ||
317 | efx_stop_queue(tx_queue->channel); | ||
318 | 270 | ||
319 | unwind: | 271 | unwind: |
320 | /* Work backwards until we hit the original insert pointer value */ | 272 | /* Work backwards until we hit the original insert pointer value */ |
321 | while (tx_queue->insert_count != tx_queue->write_count) { | 273 | while (tx_queue->insert_count != tx_queue->write_count) { |
322 | --tx_queue->insert_count; | 274 | --tx_queue->insert_count; |
323 | insert_ptr = tx_queue->insert_count & EFX_TXQ_MASK; | 275 | insert_ptr = tx_queue->insert_count & tx_queue->ptr_mask; |
324 | buffer = &tx_queue->buffer[insert_ptr]; | 276 | buffer = &tx_queue->buffer[insert_ptr]; |
325 | efx_dequeue_buffer(tx_queue, buffer); | 277 | efx_dequeue_buffer(tx_queue, buffer); |
326 | buffer->len = 0; | 278 | buffer->len = 0; |
@@ -350,8 +302,8 @@ static void efx_dequeue_buffers(struct efx_tx_queue *tx_queue, | |||
350 | struct efx_nic *efx = tx_queue->efx; | 302 | struct efx_nic *efx = tx_queue->efx; |
351 | unsigned int stop_index, read_ptr; | 303 | unsigned int stop_index, read_ptr; |
352 | 304 | ||
353 | stop_index = (index + 1) & EFX_TXQ_MASK; | 305 | stop_index = (index + 1) & tx_queue->ptr_mask; |
354 | read_ptr = tx_queue->read_count & EFX_TXQ_MASK; | 306 | read_ptr = tx_queue->read_count & tx_queue->ptr_mask; |
355 | 307 | ||
356 | while (read_ptr != stop_index) { | 308 | while (read_ptr != stop_index) { |
357 | struct efx_tx_buffer *buffer = &tx_queue->buffer[read_ptr]; | 309 | struct efx_tx_buffer *buffer = &tx_queue->buffer[read_ptr]; |
@@ -368,7 +320,7 @@ static void efx_dequeue_buffers(struct efx_tx_queue *tx_queue, | |||
368 | buffer->len = 0; | 320 | buffer->len = 0; |
369 | 321 | ||
370 | ++tx_queue->read_count; | 322 | ++tx_queue->read_count; |
371 | read_ptr = tx_queue->read_count & EFX_TXQ_MASK; | 323 | read_ptr = tx_queue->read_count & tx_queue->ptr_mask; |
372 | } | 324 | } |
373 | } | 325 | } |
374 | 326 | ||
@@ -386,43 +338,120 @@ netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb, | |||
386 | { | 338 | { |
387 | struct efx_nic *efx = netdev_priv(net_dev); | 339 | struct efx_nic *efx = netdev_priv(net_dev); |
388 | struct efx_tx_queue *tx_queue; | 340 | struct efx_tx_queue *tx_queue; |
341 | unsigned index, type; | ||
389 | 342 | ||
390 | if (unlikely(efx->port_inhibited)) | 343 | EFX_WARN_ON_PARANOID(!netif_device_present(net_dev)); |
391 | return NETDEV_TX_BUSY; | ||
392 | 344 | ||
393 | tx_queue = &efx->tx_queue[EFX_TXQ_TYPES * skb_get_queue_mapping(skb)]; | 345 | index = skb_get_queue_mapping(skb); |
394 | if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) | 346 | type = skb->ip_summed == CHECKSUM_PARTIAL ? EFX_TXQ_TYPE_OFFLOAD : 0; |
395 | tx_queue += EFX_TXQ_TYPE_OFFLOAD; | 347 | if (index >= efx->n_tx_channels) { |
348 | index -= efx->n_tx_channels; | ||
349 | type |= EFX_TXQ_TYPE_HIGHPRI; | ||
350 | } | ||
351 | tx_queue = efx_get_tx_queue(efx, index, type); | ||
396 | 352 | ||
397 | return efx_enqueue_skb(tx_queue, skb); | 353 | return efx_enqueue_skb(tx_queue, skb); |
398 | } | 354 | } |
399 | 355 | ||
356 | void efx_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue) | ||
357 | { | ||
358 | struct efx_nic *efx = tx_queue->efx; | ||
359 | |||
360 | /* Must be inverse of queue lookup in efx_hard_start_xmit() */ | ||
361 | tx_queue->core_txq = | ||
362 | netdev_get_tx_queue(efx->net_dev, | ||
363 | tx_queue->queue / EFX_TXQ_TYPES + | ||
364 | ((tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI) ? | ||
365 | efx->n_tx_channels : 0)); | ||
366 | } | ||
367 | |||
368 | int efx_setup_tc(struct net_device *net_dev, u8 num_tc) | ||
369 | { | ||
370 | struct efx_nic *efx = netdev_priv(net_dev); | ||
371 | struct efx_channel *channel; | ||
372 | struct efx_tx_queue *tx_queue; | ||
373 | unsigned tc; | ||
374 | int rc; | ||
375 | |||
376 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0 || num_tc > EFX_MAX_TX_TC) | ||
377 | return -EINVAL; | ||
378 | |||
379 | if (num_tc == net_dev->num_tc) | ||
380 | return 0; | ||
381 | |||
382 | for (tc = 0; tc < num_tc; tc++) { | ||
383 | net_dev->tc_to_txq[tc].offset = tc * efx->n_tx_channels; | ||
384 | net_dev->tc_to_txq[tc].count = efx->n_tx_channels; | ||
385 | } | ||
386 | |||
387 | if (num_tc > net_dev->num_tc) { | ||
388 | /* Initialise high-priority queues as necessary */ | ||
389 | efx_for_each_channel(channel, efx) { | ||
390 | efx_for_each_possible_channel_tx_queue(tx_queue, | ||
391 | channel) { | ||
392 | if (!(tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI)) | ||
393 | continue; | ||
394 | if (!tx_queue->buffer) { | ||
395 | rc = efx_probe_tx_queue(tx_queue); | ||
396 | if (rc) | ||
397 | return rc; | ||
398 | } | ||
399 | if (!tx_queue->initialised) | ||
400 | efx_init_tx_queue(tx_queue); | ||
401 | efx_init_tx_queue_core_txq(tx_queue); | ||
402 | } | ||
403 | } | ||
404 | } else { | ||
405 | /* Reduce number of classes before number of queues */ | ||
406 | net_dev->num_tc = num_tc; | ||
407 | } | ||
408 | |||
409 | rc = netif_set_real_num_tx_queues(net_dev, | ||
410 | max_t(int, num_tc, 1) * | ||
411 | efx->n_tx_channels); | ||
412 | if (rc) | ||
413 | return rc; | ||
414 | |||
415 | /* Do not destroy high-priority queues when they become | ||
416 | * unused. We would have to flush them first, and it is | ||
417 | * fairly difficult to flush a subset of TX queues. Leave | ||
418 | * it to efx_fini_channels(). | ||
419 | */ | ||
420 | |||
421 | net_dev->num_tc = num_tc; | ||
422 | return 0; | ||
423 | } | ||
424 | |||
400 | void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index) | 425 | void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index) |
401 | { | 426 | { |
402 | unsigned fill_level; | 427 | unsigned fill_level; |
403 | struct efx_nic *efx = tx_queue->efx; | 428 | struct efx_nic *efx = tx_queue->efx; |
404 | 429 | ||
405 | EFX_BUG_ON_PARANOID(index > EFX_TXQ_MASK); | 430 | EFX_BUG_ON_PARANOID(index > tx_queue->ptr_mask); |
406 | 431 | ||
407 | efx_dequeue_buffers(tx_queue, index); | 432 | efx_dequeue_buffers(tx_queue, index); |
408 | 433 | ||
409 | /* See if we need to restart the netif queue. This barrier | 434 | /* See if we need to restart the netif queue. This barrier |
410 | * separates the update of read_count from the test of | 435 | * separates the update of read_count from the test of the |
411 | * stopped. */ | 436 | * queue state. */ |
412 | smp_mb(); | 437 | smp_mb(); |
413 | if (unlikely(tx_queue->stopped) && likely(efx->port_enabled)) { | 438 | if (unlikely(netif_tx_queue_stopped(tx_queue->core_txq)) && |
439 | likely(efx->port_enabled) && | ||
440 | likely(netif_device_present(efx->net_dev))) { | ||
414 | fill_level = tx_queue->insert_count - tx_queue->read_count; | 441 | fill_level = tx_queue->insert_count - tx_queue->read_count; |
415 | if (fill_level < EFX_TXQ_THRESHOLD) { | 442 | if (fill_level < EFX_TXQ_THRESHOLD(efx)) { |
416 | EFX_BUG_ON_PARANOID(!efx_dev_registered(efx)); | 443 | EFX_BUG_ON_PARANOID(!efx_dev_registered(efx)); |
444 | netif_tx_wake_queue(tx_queue->core_txq); | ||
445 | } | ||
446 | } | ||
417 | 447 | ||
418 | /* Do this under netif_tx_lock(), to avoid racing | 448 | /* Check whether the hardware queue is now empty */ |
419 | * with efx_xmit(). */ | 449 | if ((int)(tx_queue->read_count - tx_queue->old_write_count) >= 0) { |
420 | netif_tx_lock(efx->net_dev); | 450 | tx_queue->old_write_count = ACCESS_ONCE(tx_queue->write_count); |
421 | if (tx_queue->stopped) { | 451 | if (tx_queue->read_count == tx_queue->old_write_count) { |
422 | tx_queue->stopped = 0; | 452 | smp_mb(); |
423 | efx_wake_queue(tx_queue->channel); | 453 | tx_queue->empty_read_count = |
424 | } | 454 | tx_queue->read_count | EFX_EMPTY_COUNT_VALID; |
425 | netif_tx_unlock(efx->net_dev); | ||
426 | } | 455 | } |
427 | } | 456 | } |
428 | } | 457 | } |
@@ -430,18 +459,24 @@ void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index) | |||
430 | int efx_probe_tx_queue(struct efx_tx_queue *tx_queue) | 459 | int efx_probe_tx_queue(struct efx_tx_queue *tx_queue) |
431 | { | 460 | { |
432 | struct efx_nic *efx = tx_queue->efx; | 461 | struct efx_nic *efx = tx_queue->efx; |
433 | unsigned int txq_size; | 462 | unsigned int entries; |
434 | int i, rc; | 463 | int i, rc; |
435 | 464 | ||
436 | netif_dbg(efx, probe, efx->net_dev, "creating TX queue %d\n", | 465 | /* Create the smallest power-of-two aligned ring */ |
437 | tx_queue->queue); | 466 | entries = max(roundup_pow_of_two(efx->txq_entries), EFX_MIN_DMAQ_SIZE); |
467 | EFX_BUG_ON_PARANOID(entries > EFX_MAX_DMAQ_SIZE); | ||
468 | tx_queue->ptr_mask = entries - 1; | ||
469 | |||
470 | netif_dbg(efx, probe, efx->net_dev, | ||
471 | "creating TX queue %d size %#x mask %#x\n", | ||
472 | tx_queue->queue, efx->txq_entries, tx_queue->ptr_mask); | ||
438 | 473 | ||
439 | /* Allocate software ring */ | 474 | /* Allocate software ring */ |
440 | txq_size = EFX_TXQ_SIZE * sizeof(*tx_queue->buffer); | 475 | tx_queue->buffer = kzalloc(entries * sizeof(*tx_queue->buffer), |
441 | tx_queue->buffer = kzalloc(txq_size, GFP_KERNEL); | 476 | GFP_KERNEL); |
442 | if (!tx_queue->buffer) | 477 | if (!tx_queue->buffer) |
443 | return -ENOMEM; | 478 | return -ENOMEM; |
444 | for (i = 0; i <= EFX_TXQ_MASK; ++i) | 479 | for (i = 0; i <= tx_queue->ptr_mask; ++i) |
445 | tx_queue->buffer[i].continuation = true; | 480 | tx_queue->buffer[i].continuation = true; |
446 | 481 | ||
447 | /* Allocate hardware ring */ | 482 | /* Allocate hardware ring */ |
@@ -464,12 +499,15 @@ void efx_init_tx_queue(struct efx_tx_queue *tx_queue) | |||
464 | 499 | ||
465 | tx_queue->insert_count = 0; | 500 | tx_queue->insert_count = 0; |
466 | tx_queue->write_count = 0; | 501 | tx_queue->write_count = 0; |
502 | tx_queue->old_write_count = 0; | ||
467 | tx_queue->read_count = 0; | 503 | tx_queue->read_count = 0; |
468 | tx_queue->old_read_count = 0; | 504 | tx_queue->old_read_count = 0; |
469 | BUG_ON(tx_queue->stopped); | 505 | tx_queue->empty_read_count = 0 | EFX_EMPTY_COUNT_VALID; |
470 | 506 | ||
471 | /* Set up TX descriptor ring */ | 507 | /* Set up TX descriptor ring */ |
472 | efx_nic_init_tx(tx_queue); | 508 | efx_nic_init_tx(tx_queue); |
509 | |||
510 | tx_queue->initialised = true; | ||
473 | } | 511 | } |
474 | 512 | ||
475 | void efx_release_tx_buffers(struct efx_tx_queue *tx_queue) | 513 | void efx_release_tx_buffers(struct efx_tx_queue *tx_queue) |
@@ -481,7 +519,7 @@ void efx_release_tx_buffers(struct efx_tx_queue *tx_queue) | |||
481 | 519 | ||
482 | /* Free any buffers left in the ring */ | 520 | /* Free any buffers left in the ring */ |
483 | while (tx_queue->read_count != tx_queue->write_count) { | 521 | while (tx_queue->read_count != tx_queue->write_count) { |
484 | buffer = &tx_queue->buffer[tx_queue->read_count & EFX_TXQ_MASK]; | 522 | buffer = &tx_queue->buffer[tx_queue->read_count & tx_queue->ptr_mask]; |
485 | efx_dequeue_buffer(tx_queue, buffer); | 523 | efx_dequeue_buffer(tx_queue, buffer); |
486 | buffer->continuation = true; | 524 | buffer->continuation = true; |
487 | buffer->len = 0; | 525 | buffer->len = 0; |
@@ -492,9 +530,14 @@ void efx_release_tx_buffers(struct efx_tx_queue *tx_queue) | |||
492 | 530 | ||
493 | void efx_fini_tx_queue(struct efx_tx_queue *tx_queue) | 531 | void efx_fini_tx_queue(struct efx_tx_queue *tx_queue) |
494 | { | 532 | { |
533 | if (!tx_queue->initialised) | ||
534 | return; | ||
535 | |||
495 | netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev, | 536 | netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev, |
496 | "shutting down TX queue %d\n", tx_queue->queue); | 537 | "shutting down TX queue %d\n", tx_queue->queue); |
497 | 538 | ||
539 | tx_queue->initialised = false; | ||
540 | |||
498 | /* Flush TX queue, remove descriptor ring */ | 541 | /* Flush TX queue, remove descriptor ring */ |
499 | efx_nic_fini_tx(tx_queue); | 542 | efx_nic_fini_tx(tx_queue); |
500 | 543 | ||
@@ -502,16 +545,13 @@ void efx_fini_tx_queue(struct efx_tx_queue *tx_queue) | |||
502 | 545 | ||
503 | /* Free up TSO header cache */ | 546 | /* Free up TSO header cache */ |
504 | efx_fini_tso(tx_queue); | 547 | efx_fini_tso(tx_queue); |
505 | |||
506 | /* Release queue's stop on port, if any */ | ||
507 | if (tx_queue->stopped) { | ||
508 | tx_queue->stopped = 0; | ||
509 | efx_wake_queue(tx_queue->channel); | ||
510 | } | ||
511 | } | 548 | } |
512 | 549 | ||
513 | void efx_remove_tx_queue(struct efx_tx_queue *tx_queue) | 550 | void efx_remove_tx_queue(struct efx_tx_queue *tx_queue) |
514 | { | 551 | { |
552 | if (!tx_queue->buffer) | ||
553 | return; | ||
554 | |||
515 | netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev, | 555 | netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev, |
516 | "destroying TX queue %d\n", tx_queue->queue); | 556 | "destroying TX queue %d\n", tx_queue->queue); |
517 | efx_nic_remove_tx(tx_queue); | 557 | efx_nic_remove_tx(tx_queue); |
@@ -741,7 +781,7 @@ static int efx_tx_queue_insert(struct efx_tx_queue *tx_queue, | |||
741 | 781 | ||
742 | fill_level = tx_queue->insert_count - tx_queue->old_read_count; | 782 | fill_level = tx_queue->insert_count - tx_queue->old_read_count; |
743 | /* -1 as there is no way to represent all descriptors used */ | 783 | /* -1 as there is no way to represent all descriptors used */ |
744 | q_space = EFX_TXQ_MASK - 1 - fill_level; | 784 | q_space = efx->txq_entries - 1 - fill_level; |
745 | 785 | ||
746 | while (1) { | 786 | while (1) { |
747 | if (unlikely(q_space-- <= 0)) { | 787 | if (unlikely(q_space-- <= 0)) { |
@@ -749,30 +789,30 @@ static int efx_tx_queue_insert(struct efx_tx_queue *tx_queue, | |||
749 | * since the xmit path last checked. Update | 789 | * since the xmit path last checked. Update |
750 | * the xmit path's copy of read_count. | 790 | * the xmit path's copy of read_count. |
751 | */ | 791 | */ |
752 | ++tx_queue->stopped; | 792 | netif_tx_stop_queue(tx_queue->core_txq); |
753 | /* This memory barrier protects the change of | 793 | /* This memory barrier protects the change of |
754 | * stopped from the access of read_count. */ | 794 | * queue state from the access of read_count. */ |
755 | smp_mb(); | 795 | smp_mb(); |
756 | tx_queue->old_read_count = | 796 | tx_queue->old_read_count = |
757 | *(volatile unsigned *)&tx_queue->read_count; | 797 | ACCESS_ONCE(tx_queue->read_count); |
758 | fill_level = (tx_queue->insert_count | 798 | fill_level = (tx_queue->insert_count |
759 | - tx_queue->old_read_count); | 799 | - tx_queue->old_read_count); |
760 | q_space = EFX_TXQ_MASK - 1 - fill_level; | 800 | q_space = efx->txq_entries - 1 - fill_level; |
761 | if (unlikely(q_space-- <= 0)) { | 801 | if (unlikely(q_space-- <= 0)) { |
762 | *final_buffer = NULL; | 802 | *final_buffer = NULL; |
763 | return 1; | 803 | return 1; |
764 | } | 804 | } |
765 | smp_mb(); | 805 | smp_mb(); |
766 | --tx_queue->stopped; | 806 | netif_tx_start_queue(tx_queue->core_txq); |
767 | } | 807 | } |
768 | 808 | ||
769 | insert_ptr = tx_queue->insert_count & EFX_TXQ_MASK; | 809 | insert_ptr = tx_queue->insert_count & tx_queue->ptr_mask; |
770 | buffer = &tx_queue->buffer[insert_ptr]; | 810 | buffer = &tx_queue->buffer[insert_ptr]; |
771 | ++tx_queue->insert_count; | 811 | ++tx_queue->insert_count; |
772 | 812 | ||
773 | EFX_BUG_ON_PARANOID(tx_queue->insert_count - | 813 | EFX_BUG_ON_PARANOID(tx_queue->insert_count - |
774 | tx_queue->read_count > | 814 | tx_queue->read_count >= |
775 | EFX_TXQ_MASK); | 815 | efx->txq_entries); |
776 | 816 | ||
777 | efx_tsoh_free(tx_queue, buffer); | 817 | efx_tsoh_free(tx_queue, buffer); |
778 | EFX_BUG_ON_PARANOID(buffer->len); | 818 | EFX_BUG_ON_PARANOID(buffer->len); |
@@ -813,7 +853,7 @@ static void efx_tso_put_header(struct efx_tx_queue *tx_queue, | |||
813 | { | 853 | { |
814 | struct efx_tx_buffer *buffer; | 854 | struct efx_tx_buffer *buffer; |
815 | 855 | ||
816 | buffer = &tx_queue->buffer[tx_queue->insert_count & EFX_TXQ_MASK]; | 856 | buffer = &tx_queue->buffer[tx_queue->insert_count & tx_queue->ptr_mask]; |
817 | efx_tsoh_free(tx_queue, buffer); | 857 | efx_tsoh_free(tx_queue, buffer); |
818 | EFX_BUG_ON_PARANOID(buffer->len); | 858 | EFX_BUG_ON_PARANOID(buffer->len); |
819 | EFX_BUG_ON_PARANOID(buffer->unmap_len); | 859 | EFX_BUG_ON_PARANOID(buffer->unmap_len); |
@@ -838,7 +878,7 @@ static void efx_enqueue_unwind(struct efx_tx_queue *tx_queue) | |||
838 | while (tx_queue->insert_count != tx_queue->write_count) { | 878 | while (tx_queue->insert_count != tx_queue->write_count) { |
839 | --tx_queue->insert_count; | 879 | --tx_queue->insert_count; |
840 | buffer = &tx_queue->buffer[tx_queue->insert_count & | 880 | buffer = &tx_queue->buffer[tx_queue->insert_count & |
841 | EFX_TXQ_MASK]; | 881 | tx_queue->ptr_mask]; |
842 | efx_tsoh_free(tx_queue, buffer); | 882 | efx_tsoh_free(tx_queue, buffer); |
843 | EFX_BUG_ON_PARANOID(buffer->skb); | 883 | EFX_BUG_ON_PARANOID(buffer->skb); |
844 | if (buffer->unmap_len) { | 884 | if (buffer->unmap_len) { |
@@ -1103,8 +1143,10 @@ static int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue, | |||
1103 | 1143 | ||
1104 | while (1) { | 1144 | while (1) { |
1105 | rc = tso_fill_packet_with_fragment(tx_queue, skb, &state); | 1145 | rc = tso_fill_packet_with_fragment(tx_queue, skb, &state); |
1106 | if (unlikely(rc)) | 1146 | if (unlikely(rc)) { |
1107 | goto stop; | 1147 | rc2 = NETDEV_TX_BUSY; |
1148 | goto unwind; | ||
1149 | } | ||
1108 | 1150 | ||
1109 | /* Move onto the next fragment? */ | 1151 | /* Move onto the next fragment? */ |
1110 | if (state.in_len == 0) { | 1152 | if (state.in_len == 0) { |
@@ -1133,14 +1175,6 @@ static int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue, | |||
1133 | netif_err(efx, tx_err, efx->net_dev, | 1175 | netif_err(efx, tx_err, efx->net_dev, |
1134 | "Out of memory for TSO headers, or PCI mapping error\n"); | 1176 | "Out of memory for TSO headers, or PCI mapping error\n"); |
1135 | dev_kfree_skb_any(skb); | 1177 | dev_kfree_skb_any(skb); |
1136 | goto unwind; | ||
1137 | |||
1138 | stop: | ||
1139 | rc2 = NETDEV_TX_BUSY; | ||
1140 | |||
1141 | /* Stop the queue if it wasn't stopped before. */ | ||
1142 | if (tx_queue->stopped == 1) | ||
1143 | efx_stop_queue(tx_queue->channel); | ||
1144 | 1178 | ||
1145 | unwind: | 1179 | unwind: |
1146 | /* Free the DMA mapping we were in the process of writing out */ | 1180 | /* Free the DMA mapping we were in the process of writing out */ |
@@ -1168,7 +1202,7 @@ static void efx_fini_tso(struct efx_tx_queue *tx_queue) | |||
1168 | unsigned i; | 1202 | unsigned i; |
1169 | 1203 | ||
1170 | if (tx_queue->buffer) { | 1204 | if (tx_queue->buffer) { |
1171 | for (i = 0; i <= EFX_TXQ_MASK; ++i) | 1205 | for (i = 0; i <= tx_queue->ptr_mask; ++i) |
1172 | efx_tsoh_free(tx_queue, &tx_queue->buffer[i]); | 1206 | efx_tsoh_free(tx_queue, &tx_queue->buffer[i]); |
1173 | } | 1207 | } |
1174 | 1208 | ||