Skip to content

Commit 447a851

Browse files
committed
Merge branch 'sfc-TXQ-refactor'
Edward Cree says: ==================== sfc: TXQ refactor Refactor and unify partner-TXQ handling in the EF100 and legacy drivers. The main thrust of this series is to remove from the legacy (Siena/EF10) driver the assumption that a netdev TX queue has precisely two hardware TXQs (checksummed and unchecksummed) associated with it, so that in future we can have more (e.g. for handling inner-header checksums) or fewer (e.g. to free up hardware queues for XDP usage). Changes from v1: * better explain patch #1 in the commit message, and rename xmit_more_available to xmit_pending * add new patch #2 applying the same approach to ef100, for consistency ==================== Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 44a8c4f + 337792a commit 447a851

File tree

8 files changed

+104
-105
lines changed

8 files changed

+104
-105
lines changed

drivers/net/ethernet/sfc/ef10.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,7 @@ static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
23672367
unsigned int write_ptr;
23682368
efx_qword_t *txd;
23692369

2370-
tx_queue->xmit_more_available = false;
2370+
tx_queue->xmit_pending = false;
23712371
if (unlikely(tx_queue->write_count == tx_queue->insert_count))
23722372
return;
23732373

drivers/net/ethernet/sfc/ef100_tx.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ static efx_oword_t *ef100_tx_desc(struct efx_tx_queue *tx_queue, unsigned int in
117117
return NULL;
118118
}
119119

120-
void ef100_notify_tx_desc(struct efx_tx_queue *tx_queue)
120+
static void ef100_notify_tx_desc(struct efx_tx_queue *tx_queue)
121121
{
122122
unsigned int write_ptr;
123123
efx_dword_t reg;
124124

125+
tx_queue->xmit_pending = false;
126+
125127
if (unlikely(tx_queue->notify_count == tx_queue->write_count))
126128
return;
127129

@@ -131,7 +133,6 @@ void ef100_notify_tx_desc(struct efx_tx_queue *tx_queue)
131133
efx_writed_page(tx_queue->efx, &reg,
132134
ER_GZ_TX_RING_DOORBELL, tx_queue->queue);
133135
tx_queue->notify_count = tx_queue->write_count;
134-
tx_queue->xmit_more_available = false;
135136
}
136137

137138
static void ef100_tx_push_buffers(struct efx_tx_queue *tx_queue)
@@ -359,28 +360,31 @@ int ef100_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
359360
goto err;
360361
ef100_tx_make_descriptors(tx_queue, skb, segments);
361362

362-
fill_level = efx_channel_tx_fill_level(tx_queue->channel);
363+
fill_level = efx_channel_tx_old_fill_level(tx_queue->channel);
363364
if (fill_level > efx->txq_stop_thresh) {
365+
struct efx_tx_queue *txq2;
366+
364367
netif_tx_stop_queue(tx_queue->core_txq);
365368
/* Re-read after a memory barrier in case we've raced with
366369
* the completion path. Otherwise there's a danger we'll never
367370
* restart the queue if all completions have just happened.
368371
*/
369372
smp_mb();
370-
fill_level = efx_channel_tx_fill_level(tx_queue->channel);
373+
efx_for_each_channel_tx_queue(txq2, tx_queue->channel)
374+
txq2->old_read_count = READ_ONCE(txq2->read_count);
375+
fill_level = efx_channel_tx_old_fill_level(tx_queue->channel);
371376
if (fill_level < efx->txq_stop_thresh)
372377
netif_tx_start_queue(tx_queue->core_txq);
373378
}
374379

375-
if (__netdev_tx_sent_queue(tx_queue->core_txq, skb->len, xmit_more))
376-
tx_queue->xmit_more_available = false; /* push doorbell */
377-
else if (tx_queue->write_count - tx_queue->notify_count > 255)
378-
/* Ensure we never push more than 256 packets at once */
379-
tx_queue->xmit_more_available = false; /* push */
380-
else
381-
tx_queue->xmit_more_available = true; /* don't push yet */
380+
tx_queue->xmit_pending = true;
382381

383-
if (!tx_queue->xmit_more_available)
382+
/* If xmit_more then we don't need to push the doorbell, unless there
383+
* are 256 descriptors already queued in which case we have to push to
384+
* ensure we never push more than 256 at once.
385+
*/
386+
if (__netdev_tx_sent_queue(tx_queue->core_txq, skb->len, xmit_more) ||
387+
tx_queue->write_count - tx_queue->notify_count > 255)
384388
ef100_tx_push_buffers(tx_queue);
385389

386390
if (segments) {
@@ -399,10 +403,10 @@ int ef100_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
399403

400404
/* If we're not expecting another transmit and we had something to push
401405
* on this queue then we need to push here to get the previous packets
402-
* out. We only enter this branch from before the 'Update BQL' section
403-
* above, so xmit_more_available still refers to the old state.
406+
* out. We only enter this branch from before the xmit_more handling
407+
* above, so xmit_pending still refers to the old state.
404408
*/
405-
if (tx_queue->xmit_more_available && !xmit_more)
409+
if (tx_queue->xmit_pending && !xmit_more)
406410
ef100_tx_push_buffers(tx_queue);
407411
return rc;
408412
}

drivers/net/ethernet/sfc/ef100_tx.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
int ef100_tx_probe(struct efx_tx_queue *tx_queue);
1818
void ef100_tx_init(struct efx_tx_queue *tx_queue);
1919
void ef100_tx_write(struct efx_tx_queue *tx_queue);
20-
void ef100_notify_tx_desc(struct efx_tx_queue *tx_queue);
2120
unsigned int ef100_tx_max_skb_descs(struct efx_nic *efx);
2221

2322
void ef100_ev_tx(struct efx_channel *channel, const efx_qword_t *p_event);

drivers/net/ethernet/sfc/farch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void efx_farch_tx_write(struct efx_tx_queue *tx_queue)
320320
unsigned write_ptr;
321321
unsigned old_write_count = tx_queue->write_count;
322322

323-
tx_queue->xmit_more_available = false;
323+
tx_queue->xmit_pending = false;
324324
if (unlikely(tx_queue->write_count == tx_queue->insert_count))
325325
return;
326326

drivers/net/ethernet/sfc/net_driver.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ struct efx_tx_buffer {
244244
* @tso_fallbacks: Number of times TSO fallback used
245245
* @pushes: Number of times the TX push feature has been used
246246
* @pio_packets: Number of times the TX PIO feature has been used
247-
* @xmit_more_available: Are any packets waiting to be pushed to the NIC
247+
* @xmit_pending: Are any packets waiting to be pushed to the NIC
248248
* @cb_packets: Number of times the TX copybreak feature has been used
249249
* @notify_count: Count of notified descriptors to the NIC
250250
* @empty_read_count: If the completion path has seen the queue as empty
@@ -292,7 +292,7 @@ struct efx_tx_queue {
292292
unsigned int tso_fallbacks;
293293
unsigned int pushes;
294294
unsigned int pio_packets;
295-
bool xmit_more_available;
295+
bool xmit_pending;
296296
unsigned int cb_packets;
297297
unsigned int notify_count;
298298
/* Statistics to supplement MAC stats */
@@ -1681,17 +1681,27 @@ efx_channel_tx_fill_level(struct efx_channel *channel)
16811681
struct efx_tx_queue *tx_queue;
16821682
unsigned int fill_level = 0;
16831683

1684-
/* This function is currently only used by EF100, which maybe
1685-
* could do something simpler and just compute the fill level
1686-
* of the single TXQ that's really in use.
1687-
*/
16881684
efx_for_each_channel_tx_queue(tx_queue, channel)
16891685
fill_level = max(fill_level,
16901686
tx_queue->insert_count - tx_queue->read_count);
16911687

16921688
return fill_level;
16931689
}
16941690

1691+
/* Conservative approximation of efx_channel_tx_fill_level using cached value */
1692+
static inline unsigned int
1693+
efx_channel_tx_old_fill_level(struct efx_channel *channel)
1694+
{
1695+
struct efx_tx_queue *tx_queue;
1696+
unsigned int fill_level = 0;
1697+
1698+
efx_for_each_channel_tx_queue(tx_queue, channel)
1699+
fill_level = max(fill_level,
1700+
tx_queue->insert_count - tx_queue->old_read_count);
1701+
1702+
return fill_level;
1703+
}
1704+
16951705
/* Get all supported features.
16961706
* If a feature is not fixed, it is present in hw_features.
16971707
* If a feature is fixed, it does not present in hw_features, but

drivers/net/ethernet/sfc/nic_common.h

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index)
6565
/* Report whether this TX queue would be empty for the given write_count.
6666
* May return false negative.
6767
*/
68-
static inline bool __efx_nic_tx_is_empty(struct efx_tx_queue *tx_queue,
69-
unsigned int write_count)
68+
static inline bool efx_nic_tx_is_empty(struct efx_tx_queue *tx_queue, unsigned int write_count)
7069
{
7170
unsigned int empty_read_count = READ_ONCE(tx_queue->empty_read_count);
7271

@@ -76,41 +75,6 @@ static inline bool __efx_nic_tx_is_empty(struct efx_tx_queue *tx_queue,
7675
return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0;
7776
}
7877

79-
/* Report whether the NIC considers this TX queue empty, using
80-
* packet_write_count (the write count recorded for the last completable
81-
* doorbell push). May return false negative. EF10 only, which is OK
82-
* because only EF10 supports PIO.
83-
*/
84-
static inline bool efx_nic_tx_is_empty(struct efx_tx_queue *tx_queue)
85-
{
86-
EFX_WARN_ON_ONCE_PARANOID(!tx_queue->efx->type->option_descriptors);
87-
return __efx_nic_tx_is_empty(tx_queue, tx_queue->packet_write_count);
88-
}
89-
90-
/* Get partner of a TX queue, seen as part of the same net core queue */
91-
/* XXX is this a thing on EF100? */
92-
static inline struct efx_tx_queue *efx_tx_queue_partner(struct efx_tx_queue *tx_queue)
93-
{
94-
if (tx_queue->label & EFX_TXQ_TYPE_OFFLOAD)
95-
return tx_queue - EFX_TXQ_TYPE_OFFLOAD;
96-
else
97-
return tx_queue + EFX_TXQ_TYPE_OFFLOAD;
98-
}
99-
100-
/* Decide whether we can use TX PIO, ie. write packet data directly into
101-
* a buffer on the device. This can reduce latency at the expense of
102-
* throughput, so we only do this if both hardware and software TX rings
103-
* are empty. This also ensures that only one packet at a time can be
104-
* using the PIO buffer.
105-
*/
106-
static inline bool efx_nic_may_tx_pio(struct efx_tx_queue *tx_queue)
107-
{
108-
struct efx_tx_queue *partner = efx_tx_queue_partner(tx_queue);
109-
110-
return tx_queue->piobuf && efx_nic_tx_is_empty(tx_queue) &&
111-
efx_nic_tx_is_empty(partner);
112-
}
113-
11478
int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue, struct sk_buff *skb,
11579
bool *data_mapped);
11680

@@ -125,7 +89,7 @@ int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue, struct sk_buff *skb,
12589
static inline bool efx_nic_may_push_tx_desc(struct efx_tx_queue *tx_queue,
12690
unsigned int write_count)
12791
{
128-
bool was_empty = __efx_nic_tx_is_empty(tx_queue, write_count);
92+
bool was_empty = efx_nic_tx_is_empty(tx_queue, write_count);
12993

13094
tx_queue->empty_read_count = 0;
13195
return was_empty && tx_queue->write_count - write_count == 1;

drivers/net/ethernet/sfc/tx.c

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ u8 *efx_tx_get_copy_buffer_limited(struct efx_tx_queue *tx_queue,
5959

6060
static void efx_tx_maybe_stop_queue(struct efx_tx_queue *txq1)
6161
{
62-
/* We need to consider both queues that the net core sees as one */
63-
struct efx_tx_queue *txq2 = efx_tx_queue_partner(txq1);
62+
/* We need to consider all queues that the net core sees as one */
6463
struct efx_nic *efx = txq1->efx;
64+
struct efx_tx_queue *txq2;
6565
unsigned int fill_level;
6666

67-
fill_level = max(txq1->insert_count - txq1->old_read_count,
68-
txq2->insert_count - txq2->old_read_count);
67+
fill_level = efx_channel_tx_old_fill_level(txq1->channel);
6968
if (likely(fill_level < efx->txq_stop_thresh))
7069
return;
7170

@@ -85,11 +84,10 @@ static void efx_tx_maybe_stop_queue(struct efx_tx_queue *txq1)
8584
*/
8685
netif_tx_stop_queue(txq1->core_txq);
8786
smp_mb();
88-
txq1->old_read_count = READ_ONCE(txq1->read_count);
89-
txq2->old_read_count = READ_ONCE(txq2->read_count);
87+
efx_for_each_channel_tx_queue(txq2, txq1->channel)
88+
txq2->old_read_count = READ_ONCE(txq2->read_count);
9089

91-
fill_level = max(txq1->insert_count - txq1->old_read_count,
92-
txq2->insert_count - txq2->old_read_count);
90+
fill_level = efx_channel_tx_old_fill_level(txq1->channel);
9391
EFX_WARN_ON_ONCE_PARANOID(fill_level >= efx->txq_entries);
9492
if (likely(fill_level < efx->txq_stop_thresh)) {
9593
smp_mb();
@@ -266,8 +264,45 @@ static int efx_enqueue_skb_pio(struct efx_tx_queue *tx_queue,
266264
++tx_queue->insert_count;
267265
return 0;
268266
}
267+
268+
/* Decide whether we can use TX PIO, ie. write packet data directly into
269+
* a buffer on the device. This can reduce latency at the expense of
270+
* throughput, so we only do this if both hardware and software TX rings
271+
* are empty, including all queues for the channel. This also ensures that
272+
* only one packet at a time can be using the PIO buffer. If the xmit_more
273+
* flag is set then we don't use this - there'll be another packet along
274+
* shortly and we want to hold off the doorbell.
275+
*/
276+
static bool efx_tx_may_pio(struct efx_tx_queue *tx_queue)
277+
{
278+
struct efx_channel *channel = tx_queue->channel;
279+
280+
if (!tx_queue->piobuf)
281+
return false;
282+
283+
EFX_WARN_ON_ONCE_PARANOID(!channel->efx->type->option_descriptors);
284+
285+
efx_for_each_channel_tx_queue(tx_queue, channel)
286+
if (!efx_nic_tx_is_empty(tx_queue, tx_queue->packet_write_count))
287+
return false;
288+
289+
return true;
290+
}
269291
#endif /* EFX_USE_PIO */
270292

293+
/* Send any pending traffic for a channel. xmit_more is shared across all
294+
* queues for a channel, so we must check all of them.
295+
*/
296+
static void efx_tx_send_pending(struct efx_channel *channel)
297+
{
298+
struct efx_tx_queue *q;
299+
300+
efx_for_each_channel_tx_queue(q, channel) {
301+
if (q->xmit_pending)
302+
efx_nic_push_buffers(q);
303+
}
304+
}
305+
271306
/*
272307
* Add a socket buffer to a TX queue
273308
*
@@ -315,7 +350,7 @@ netdev_tx_t __efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb
315350
goto err;
316351
#ifdef EFX_USE_PIO
317352
} else if (skb_len <= efx_piobuf_size && !xmit_more &&
318-
efx_nic_may_tx_pio(tx_queue)) {
353+
efx_tx_may_pio(tx_queue)) {
319354
/* Use PIO for short packets with an empty queue. */
320355
if (efx_enqueue_skb_pio(tx_queue, skb))
321356
goto err;
@@ -336,21 +371,11 @@ netdev_tx_t __efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb
336371

337372
efx_tx_maybe_stop_queue(tx_queue);
338373

339-
/* Pass off to hardware */
340-
if (__netdev_tx_sent_queue(tx_queue->core_txq, skb_len, xmit_more)) {
341-
struct efx_tx_queue *txq2 = efx_tx_queue_partner(tx_queue);
342-
343-
/* There could be packets left on the partner queue if
344-
* xmit_more was set. If we do not push those they
345-
* could be left for a long time and cause a netdev watchdog.
346-
*/
347-
if (txq2->xmit_more_available)
348-
efx_nic_push_buffers(txq2);
374+
tx_queue->xmit_pending = true;
349375

350-
efx_nic_push_buffers(tx_queue);
351-
} else {
352-
tx_queue->xmit_more_available = xmit_more;
353-
}
376+
/* Pass off to hardware */
377+
if (__netdev_tx_sent_queue(tx_queue->core_txq, skb_len, xmit_more))
378+
efx_tx_send_pending(tx_queue->channel);
354379

355380
if (segments) {
356381
tx_queue->tso_bursts++;
@@ -371,14 +396,8 @@ netdev_tx_t __efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb
371396
* on this queue or a partner queue then we need to push here to get the
372397
* previous packets out.
373398
*/
374-
if (!xmit_more) {
375-
struct efx_tx_queue *txq2 = efx_tx_queue_partner(tx_queue);
376-
377-
if (txq2->xmit_more_available)
378-
efx_nic_push_buffers(txq2);
379-
380-
efx_nic_push_buffers(tx_queue);
381-
}
399+
if (!xmit_more)
400+
efx_tx_send_pending(tx_queue->channel);
382401

383402
return NETDEV_TX_OK;
384403
}
@@ -489,18 +508,24 @@ netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb,
489508

490509
EFX_WARN_ON_PARANOID(!netif_device_present(net_dev));
491510

492-
/* PTP "event" packet */
493-
if (unlikely(efx_xmit_with_hwtstamp(skb)) &&
494-
unlikely(efx_ptp_is_ptp_tx(efx, skb))) {
495-
return efx_ptp_tx(efx, skb);
496-
}
497-
498511
index = skb_get_queue_mapping(skb);
499512
type = skb->ip_summed == CHECKSUM_PARTIAL ? EFX_TXQ_TYPE_OFFLOAD : 0;
500513
if (index >= efx->n_tx_channels) {
501514
index -= efx->n_tx_channels;
502515
type |= EFX_TXQ_TYPE_HIGHPRI;
503516
}
517+
518+
/* PTP "event" packet */
519+
if (unlikely(efx_xmit_with_hwtstamp(skb)) &&
520+
unlikely(efx_ptp_is_ptp_tx(efx, skb))) {
521+
/* There may be existing transmits on the channel that are
522+
* waiting for this packet to trigger the doorbell write.
523+
* We need to send the packets at this point.
524+
*/
525+
efx_tx_send_pending(efx_get_tx_channel(efx, index));
526+
return efx_ptp_tx(efx, skb);
527+
}
528+
504529
tx_queue = efx_get_tx_queue(efx, index, type);
505530

506531
return __efx_enqueue_skb(tx_queue, skb);

0 commit comments

Comments
 (0)