Skip to content

Commit 1280479

Browse files
ecree-solarflaredavem330
authored andcommitted
sfc: decouple TXQ type from label
Make it possible to have an arbitrary mapping from types to labels, because when we add inner-csum-offload TXQs there will no longer be a convenient nesting hierarchy of NIC types (EF10 will have inner-csum TXQs, while Siena will have HIGHPRI). Correct a misleading comment on efx_hard_start_xmit(). Signed-off-by: Edward Cree <ecree@solarflare.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4a681bf commit 1280479

File tree

11 files changed

+64
-43
lines changed

11 files changed

+64
-43
lines changed

drivers/net/ethernet/sfc/ef10.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,7 @@ static int efx_ef10_irq_test_generate(struct efx_nic *efx)
21462146

21472147
static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
21482148
{
2149+
tx_queue->type = tx_queue->label & EFX_TXQ_TYPE_OFFLOAD;
21492150
return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
21502151
(tx_queue->ptr_mask + 1) *
21512152
sizeof(efx_qword_t),
@@ -2254,7 +2255,7 @@ static u32 efx_ef10_tso_versions(struct efx_nic *efx)
22542255

22552256
static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
22562257
{
2257-
bool csum_offload = tx_queue->label & EFX_TXQ_TYPE_OFFLOAD;
2258+
bool csum_offload = tx_queue->type & EFX_TXQ_TYPE_OFFLOAD;
22582259
struct efx_channel *channel = tx_queue->channel;
22592260
struct efx_nic *efx = tx_queue->efx;
22602261
struct efx_ef10_nic_data *nic_data;
@@ -2880,7 +2881,7 @@ efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
28802881
/* Get the transmit queue */
28812882
tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
28822883
tx_queue = efx_channel_get_tx_queue(channel,
2883-
tx_ev_q_label % EFX_TXQ_TYPES);
2884+
tx_ev_q_label % EFX_MAX_TXQ_PER_CHANNEL);
28842885

28852886
if (!tx_queue->timestamping) {
28862887
/* Transmit completion */

drivers/net/ethernet/sfc/efx_channels.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int efx_allocate_msix_channels(struct efx_nic *efx,
151151
*/
152152

153153
n_xdp_tx = num_possible_cpus();
154-
n_xdp_ev = DIV_ROUND_UP(n_xdp_tx, EFX_TXQ_TYPES);
154+
n_xdp_ev = DIV_ROUND_UP(n_xdp_tx, EFX_MAX_TXQ_PER_CHANNEL);
155155

156156
vec_count = pci_msix_vec_count(efx->pci_dev);
157157
if (vec_count < 0)
@@ -179,7 +179,7 @@ static int efx_allocate_msix_channels(struct efx_nic *efx,
179179
efx->xdp_tx_queue_count = 0;
180180
} else {
181181
efx->n_xdp_channels = n_xdp_ev;
182-
efx->xdp_tx_per_channel = EFX_TXQ_TYPES;
182+
efx->xdp_tx_per_channel = EFX_MAX_TXQ_PER_CHANNEL;
183183
efx->xdp_tx_queue_count = n_xdp_tx;
184184
n_channels += n_xdp_ev;
185185
netif_dbg(efx, drv, efx->net_dev,
@@ -520,7 +520,7 @@ static struct efx_channel *efx_alloc_channel(struct efx_nic *efx, int i)
520520
channel->channel = i;
521521
channel->type = &efx_default_channel_type;
522522

523-
for (j = 0; j < EFX_TXQ_TYPES; j++) {
523+
for (j = 0; j < EFX_MAX_TXQ_PER_CHANNEL; j++) {
524524
tx_queue = &channel->tx_queue[j];
525525
tx_queue->efx = efx;
526526
tx_queue->queue = -1;
@@ -594,7 +594,7 @@ struct efx_channel *efx_copy_channel(const struct efx_channel *old_channel)
594594
channel->napi_str.state = 0;
595595
memset(&channel->eventq, 0, sizeof(channel->eventq));
596596

597-
for (j = 0; j < EFX_TXQ_TYPES; j++) {
597+
for (j = 0; j < EFX_MAX_TXQ_PER_CHANNEL; j++) {
598598
tx_queue = &channel->tx_queue[j];
599599
if (tx_queue->channel)
600600
tx_queue->channel = channel;
@@ -894,7 +894,7 @@ int efx_set_channels(struct efx_nic *efx)
894894
xdp_queue_number, tx_queue->queue);
895895
/* We may have a few left-over XDP TX
896896
* queues owing to xdp_tx_queue_count
897-
* not dividing evenly by EFX_TXQ_TYPES.
897+
* not dividing evenly by EFX_MAX_TXQ_PER_CHANNEL.
898898
* We still allocate and probe those
899899
* TXQs, but never use them.
900900
*/

drivers/net/ethernet/sfc/ethtool_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
407407
snprintf(strings, ETH_GSTRING_LEN,
408408
"tx-%u.tx_packets",
409409
channel->tx_queue[0].queue /
410-
EFX_TXQ_TYPES);
410+
EFX_MAX_TXQ_PER_CHANNEL);
411411

412412
strings += ETH_GSTRING_LEN;
413413
}

drivers/net/ethernet/sfc/farch.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,16 @@ int efx_farch_tx_probe(struct efx_tx_queue *tx_queue)
372372
struct efx_nic *efx = tx_queue->efx;
373373
unsigned entries;
374374

375+
tx_queue->type = ((tx_queue->label & 1) ? EFX_TXQ_TYPE_OFFLOAD : 0) |
376+
((tx_queue->label & 2) ? EFX_TXQ_TYPE_HIGHPRI : 0);
375377
entries = tx_queue->ptr_mask + 1;
376378
return efx_alloc_special_buffer(efx, &tx_queue->txd,
377379
entries * sizeof(efx_qword_t));
378380
}
379381

380382
void efx_farch_tx_init(struct efx_tx_queue *tx_queue)
381383
{
382-
int csum = tx_queue->label & EFX_TXQ_TYPE_OFFLOAD;
384+
int csum = tx_queue->type & EFX_TXQ_TYPE_OFFLOAD;
383385
struct efx_nic *efx = tx_queue->efx;
384386
efx_oword_t reg;
385387

@@ -409,7 +411,7 @@ void efx_farch_tx_init(struct efx_tx_queue *tx_queue)
409411

410412
EFX_POPULATE_OWORD_1(reg,
411413
FRF_BZ_TX_PACE,
412-
(tx_queue->label & EFX_TXQ_TYPE_HIGHPRI) ?
414+
(tx_queue->type & EFX_TXQ_TYPE_HIGHPRI) ?
413415
FFE_BZ_TX_PACE_OFF :
414416
FFE_BZ_TX_PACE_RESERVED);
415417
efx_writeo_table(efx, &reg, FR_BZ_TX_PACE_TBL, tx_queue->queue);
@@ -832,13 +834,13 @@ efx_farch_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
832834
tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_DESC_PTR);
833835
tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
834836
tx_queue = efx_channel_get_tx_queue(
835-
channel, tx_ev_q_label % EFX_TXQ_TYPES);
837+
channel, tx_ev_q_label % EFX_MAX_TXQ_PER_CHANNEL);
836838
efx_xmit_done(tx_queue, tx_ev_desc_ptr);
837839
} else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_WQ_FF_FULL)) {
838840
/* Rewrite the FIFO write pointer */
839841
tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
840842
tx_queue = efx_channel_get_tx_queue(
841-
channel, tx_ev_q_label % EFX_TXQ_TYPES);
843+
channel, tx_ev_q_label % EFX_MAX_TXQ_PER_CHANNEL);
842844

843845
netif_tx_lock(efx->net_dev);
844846
efx_farch_notify_tx_desc(tx_queue);
@@ -1080,9 +1082,9 @@ efx_farch_handle_tx_flush_done(struct efx_nic *efx, efx_qword_t *event)
10801082
int qid;
10811083

10821084
qid = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
1083-
if (qid < EFX_TXQ_TYPES * (efx->n_tx_channels + efx->n_extra_tx_channels)) {
1084-
tx_queue = efx_get_tx_queue(efx, qid / EFX_TXQ_TYPES,
1085-
qid % EFX_TXQ_TYPES);
1085+
if (qid < EFX_MAX_TXQ_PER_CHANNEL * (efx->n_tx_channels + efx->n_extra_tx_channels)) {
1086+
tx_queue = efx_get_tx_queue(efx, qid / EFX_MAX_TXQ_PER_CHANNEL,
1087+
qid % EFX_MAX_TXQ_PER_CHANNEL);
10861088
if (atomic_cmpxchg(&tx_queue->flush_outstanding, 1, 0)) {
10871089
efx_farch_magic_event(tx_queue->channel,
10881090
EFX_CHANNEL_MAGIC_TX_DRAIN(tx_queue));
@@ -1675,10 +1677,10 @@ void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw)
16751677
* and the descriptor caches for those channels.
16761678
*/
16771679
buftbl_min = ((efx->n_rx_channels * EFX_MAX_DMAQ_SIZE +
1678-
total_tx_channels * EFX_TXQ_TYPES * EFX_MAX_DMAQ_SIZE +
1680+
total_tx_channels * EFX_MAX_TXQ_PER_CHANNEL * EFX_MAX_DMAQ_SIZE +
16791681
efx->n_channels * EFX_MAX_EVQ_SIZE)
16801682
* sizeof(efx_qword_t) / EFX_BUF_SIZE);
1681-
vi_count = max(efx->n_channels, total_tx_channels * EFX_TXQ_TYPES);
1683+
vi_count = max(efx->n_channels, total_tx_channels * EFX_MAX_TXQ_PER_CHANNEL);
16821684

16831685
#ifdef CONFIG_SFC_SRIOV
16841686
if (efx->type->sriov_wanted) {

drivers/net/ethernet/sfc/mcdi_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int efx_mcdi_tx_init(struct efx_tx_queue *tx_queue, bool tso_v2)
164164
{
165165
MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
166166
EFX_BUF_SIZE));
167-
bool csum_offload = tx_queue->label & EFX_TXQ_TYPE_OFFLOAD;
167+
bool csum_offload = tx_queue->type & EFX_TXQ_TYPE_OFFLOAD;
168168
size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
169169
struct efx_channel *channel = tx_queue->channel;
170170
struct efx_nic *efx = tx_queue->efx;

drivers/net/ethernet/sfc/net_driver.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
#define EFX_TXQ_TYPE_OFFLOAD 1 /* flag */
6767
#define EFX_TXQ_TYPE_HIGHPRI 2 /* flag */
6868
#define EFX_TXQ_TYPES 4
69-
#define EFX_MAX_TX_QUEUES (EFX_TXQ_TYPES * EFX_MAX_CHANNELS)
69+
#define EFX_MAX_TXQ_PER_CHANNEL 4
70+
#define EFX_MAX_TX_QUEUES (EFX_MAX_TXQ_PER_CHANNEL * EFX_MAX_CHANNELS)
7071

7172
/* Maximum possible MTU the driver supports */
7273
#define EFX_MAX_MTU (9 * 1024)
@@ -190,6 +191,7 @@ struct efx_tx_buffer {
190191
* @queue: DMA queue number
191192
* @label: Label for TX completion events.
192193
* Is our index within @channel->tx_queue array.
194+
* @type: configuration type of this TX queue. A bitmask of %EFX_TXQ_TYPE_* flags.
193195
* @tso_version: Version of TSO in use for this queue.
194196
* @channel: The associated channel
195197
* @core_txq: The networking core TX queue structure
@@ -254,6 +256,7 @@ struct efx_tx_queue {
254256
struct efx_nic *efx ____cacheline_aligned_in_smp;
255257
unsigned int queue;
256258
unsigned int label;
259+
unsigned int type;
257260
unsigned int tso_version;
258261
struct efx_channel *channel;
259262
struct netdev_queue *core_txq;
@@ -479,6 +482,7 @@ enum efx_sync_events_state {
479482
* @rx_list: list of SKBs from current RX, awaiting processing
480483
* @rx_queue: RX queue for this channel
481484
* @tx_queue: TX queues for this channel
485+
* @tx_queue_by_type: pointers into @tx_queue, or %NULL, indexed by txq type
482486
* @sync_events_state: Current state of sync events on this channel
483487
* @sync_timestamp_major: Major part of the last ptp sync event
484488
* @sync_timestamp_minor: Minor part of the last ptp sync event
@@ -540,7 +544,8 @@ struct efx_channel {
540544
struct list_head *rx_list;
541545

542546
struct efx_rx_queue rx_queue;
543-
struct efx_tx_queue tx_queue[EFX_TXQ_TYPES];
547+
struct efx_tx_queue tx_queue[EFX_MAX_TXQ_PER_CHANNEL];
548+
struct efx_tx_queue *tx_queue_by_type[EFX_TXQ_TYPES];
544549

545550
enum efx_sync_events_state sync_events_state;
546551
u32 sync_timestamp_major;
@@ -1200,7 +1205,7 @@ struct efx_udp_tunnel {
12001205
* a pointer to the &struct efx_msi_context for the channel.
12011206
* @irq_handle_legacy: Handle legacy interrupt. The @dev_id argument
12021207
* is a pointer to the &struct efx_nic.
1203-
* @tx_probe: Allocate resources for TX queue
1208+
* @tx_probe: Allocate resources for TX queue (and select TXQ type)
12041209
* @tx_init: Initialise TX queue on the NIC
12051210
* @tx_remove: Free resources for TX queue
12061211
* @tx_write: Write TX descriptors and doorbell
@@ -1495,14 +1500,6 @@ efx_get_tx_channel(struct efx_nic *efx, unsigned int index)
14951500
return efx->channel[efx->tx_channel_offset + index];
14961501
}
14971502

1498-
static inline struct efx_tx_queue *
1499-
efx_get_tx_queue(struct efx_nic *efx, unsigned index, unsigned type)
1500-
{
1501-
EFX_WARN_ON_ONCE_PARANOID(index >= efx->n_tx_channels ||
1502-
type >= efx->tx_queues_per_channel);
1503-
return &efx->channel[efx->tx_channel_offset + index]->tx_queue[type];
1504-
}
1505-
15061503
static inline struct efx_channel *
15071504
efx_get_xdp_channel(struct efx_nic *efx, unsigned int index)
15081505
{
@@ -1529,10 +1526,18 @@ static inline unsigned int efx_channel_num_tx_queues(struct efx_channel *channel
15291526
}
15301527

15311528
static inline struct efx_tx_queue *
1532-
efx_channel_get_tx_queue(struct efx_channel *channel, unsigned type)
1529+
efx_channel_get_tx_queue(struct efx_channel *channel, unsigned int type)
15331530
{
1534-
EFX_WARN_ON_ONCE_PARANOID(type >= efx_channel_num_tx_queues(channel));
1535-
return &channel->tx_queue[type];
1531+
EFX_WARN_ON_ONCE_PARANOID(type >= EFX_TXQ_TYPES);
1532+
return channel->tx_queue_by_type[type];
1533+
}
1534+
1535+
static inline struct efx_tx_queue *
1536+
efx_get_tx_queue(struct efx_nic *efx, unsigned int index, unsigned int type)
1537+
{
1538+
struct efx_channel *channel = efx_get_tx_channel(efx, index);
1539+
1540+
return efx_channel_get_tx_queue(channel, type);
15361541
}
15371542

15381543
/* Iterate over all TX queues belonging to a channel */

drivers/net/ethernet/sfc/ptp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ static void efx_ptp_xmit_skb_queue(struct efx_nic *efx, struct sk_buff *skb)
10851085
struct efx_tx_queue *tx_queue;
10861086
u8 type = skb->ip_summed == CHECKSUM_PARTIAL ? EFX_TXQ_TYPE_OFFLOAD : 0;
10871087

1088-
tx_queue = &ptp_data->channel->tx_queue[type];
1088+
tx_queue = efx_channel_get_tx_queue(ptp_data->channel, type);
10891089
if (tx_queue && tx_queue->timestamping) {
10901090
efx_enqueue_skb(tx_queue, skb);
10911091
} else {

drivers/net/ethernet/sfc/selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ static int efx_test_loopbacks(struct efx_nic *efx, struct efx_self_tests *tests,
656656

657657
/* Test all enabled types of TX queue */
658658
efx_for_each_channel_tx_queue(tx_queue, channel) {
659-
state->offload_csum = (tx_queue->label &
659+
state->offload_csum = (tx_queue->type &
660660
EFX_TXQ_TYPE_OFFLOAD);
661661
rc = efx_test_loopback(tx_queue,
662662
&tests->loopback[mode]);

drivers/net/ethernet/sfc/selftest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616

1717
struct efx_loopback_self_tests {
18-
int tx_sent[EFX_TXQ_TYPES];
19-
int tx_done[EFX_TXQ_TYPES];
18+
int tx_sent[EFX_MAX_TXQ_PER_CHANNEL];
19+
int tx_done[EFX_MAX_TXQ_PER_CHANNEL];
2020
int rx_good;
2121
int rx_bad;
2222
};

drivers/net/ethernet/sfc/tx.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,10 @@ int efx_xdp_tx_buffers(struct efx_nic *efx, int n, struct xdp_frame **xdpfs,
491491
}
492492

493493
/* Initiate a packet transmission. We use one channel per CPU
494-
* (sharing when we have more CPUs than channels). On Falcon, the TX
495-
* completion events will be directed back to the CPU that transmitted
496-
* the packet, which should be cache-efficient.
494+
* (sharing when we have more CPUs than channels).
497495
*
498496
* Context: non-blocking.
499-
* Note that returning anything other than NETDEV_TX_OK will cause the
500-
* OS to free the skb.
497+
* Should always return NETDEV_TX_OK and consume the skb.
501498
*/
502499
netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb,
503500
struct net_device *net_dev)
@@ -527,6 +524,20 @@ netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb,
527524
}
528525

529526
tx_queue = efx_get_tx_queue(efx, index, type);
527+
if (WARN_ON_ONCE(!tx_queue)) {
528+
/* We don't have a TXQ of the right type.
529+
* This should never happen, as we don't advertise offload
530+
* features unless we can support them.
531+
*/
532+
dev_kfree_skb_any(skb);
533+
/* If we're not expecting another transmit and we had something to push
534+
* on this queue or a partner queue then we need to push here to get the
535+
* previous packets out.
536+
*/
537+
if (!netdev_xmit_more())
538+
efx_tx_send_pending(tx_queue->channel);
539+
return NETDEV_TX_OK;
540+
}
530541

531542
return __efx_enqueue_skb(tx_queue, skb);
532543
}
@@ -577,7 +588,7 @@ void efx_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue)
577588
tx_queue->core_txq =
578589
netdev_get_tx_queue(efx->net_dev,
579590
tx_queue->channel->channel +
580-
((tx_queue->label & EFX_TXQ_TYPE_HIGHPRI) ?
591+
((tx_queue->type & EFX_TXQ_TYPE_HIGHPRI) ?
581592
efx->n_tx_channels : 0));
582593
}
583594

0 commit comments

Comments
 (0)