Skip to content

Commit 6b5525c

Browse files
committed
Merge branch 'sfc-encap-offloads-on-EF10'
Edward Cree says: ==================== sfc: encap offloads on EF10 EF10 NICs from the 8000 series onwards support TX offloads (checksumming, TSO) on VXLAN- and NVGRE-encapsulated packets. This series adds driver support for these offloads. Changes from v1: * Fix 'no TXQ of type' error handling in patch #1 (and clear up the misleading comment that inspired the wrong version) * Add comment in patch #5 explaining what the deal with TSOv3 is ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 4a681bf + 24b2c37 commit 6b5525c

18 files changed

+318
-106
lines changed

drivers/net/ethernet/sfc/ef10.c

Lines changed: 85 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,14 @@ static int efx_ef10_probe(struct efx_nic *efx)
601601
efx_ef10_read_licensed_features(efx);
602602

603603
/* We can have one VI for each vi_stride-byte region.
604-
* However, until we use TX option descriptors we need two TX queues
605-
* per channel.
604+
* However, until we use TX option descriptors we need up to four
605+
* TX queues per channel for different checksumming combinations.
606606
*/
607-
efx->tx_queues_per_channel = 2;
607+
if (nic_data->datapath_caps &
608+
(1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
609+
efx->tx_queues_per_channel = 4;
610+
else
611+
efx->tx_queues_per_channel = 2;
608612
efx->max_vis = efx_ef10_mem_map_size(efx) / efx->vi_stride;
609613
if (!efx->max_vis) {
610614
netif_err(efx, drv, efx->net_dev, "error determining max VIs\n");
@@ -1300,6 +1304,7 @@ static void efx_ef10_fini_nic(struct efx_nic *efx)
13001304
static int efx_ef10_init_nic(struct efx_nic *efx)
13011305
{
13021306
struct efx_ef10_nic_data *nic_data = efx->nic_data;
1307+
netdev_features_t hw_enc_features = 0;
13031308
int rc;
13041309

13051310
if (nic_data->must_check_datapath_caps) {
@@ -1344,6 +1349,21 @@ static int efx_ef10_init_nic(struct efx_nic *efx)
13441349
nic_data->must_restore_piobufs = false;
13451350
}
13461351

1352+
/* add encapsulated checksum offload features */
1353+
if (efx_has_cap(efx, VXLAN_NVGRE) && !efx_ef10_is_vf(efx))
1354+
hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
1355+
/* add encapsulated TSO features */
1356+
if (efx_has_cap(efx, TX_TSO_V2_ENCAP)) {
1357+
netdev_features_t encap_tso_features;
1358+
1359+
encap_tso_features = NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
1360+
NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM;
1361+
1362+
hw_enc_features |= encap_tso_features | NETIF_F_TSO;
1363+
efx->net_dev->features |= encap_tso_features;
1364+
}
1365+
efx->net_dev->hw_enc_features = hw_enc_features;
1366+
13471367
/* don't fail init if RSS setup doesn't work */
13481368
rc = efx->type->rx_push_rss_config(efx, false,
13491369
efx->rss_context.rx_indir_table, NULL);
@@ -2146,6 +2166,9 @@ static int efx_ef10_irq_test_generate(struct efx_nic *efx)
21462166

21472167
static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
21482168
{
2169+
/* low two bits of label are what we want for type */
2170+
BUILD_BUG_ON((EFX_TXQ_TYPE_OUTER_CSUM | EFX_TXQ_TYPE_INNER_CSUM) != 3);
2171+
tx_queue->type = tx_queue->label & 3;
21492172
return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
21502173
(tx_queue->ptr_mask + 1) *
21512174
sizeof(efx_qword_t),
@@ -2168,15 +2191,15 @@ static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
21682191

21692192
/* Add Firmware-Assisted TSO v2 option descriptors to a queue.
21702193
*/
2171-
static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2172-
struct sk_buff *skb,
2173-
bool *data_mapped)
2194+
int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue, struct sk_buff *skb,
2195+
bool *data_mapped)
21742196
{
21752197
struct efx_tx_buffer *buffer;
2198+
u16 inner_ipv4_id = 0;
2199+
u16 outer_ipv4_id = 0;
21762200
struct tcphdr *tcp;
21772201
struct iphdr *ip;
2178-
2179-
u16 ipv4_id;
2202+
u16 ip_tot_len;
21802203
u32 seqnum;
21812204
u32 mss;
21822205

@@ -2189,21 +2212,43 @@ static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
21892212
return -EINVAL;
21902213
}
21912214

2192-
ip = ip_hdr(skb);
2215+
if (skb->encapsulation) {
2216+
if (!tx_queue->tso_encap)
2217+
return -EINVAL;
2218+
ip = ip_hdr(skb);
2219+
if (ip->version == 4)
2220+
outer_ipv4_id = ntohs(ip->id);
2221+
2222+
ip = inner_ip_hdr(skb);
2223+
tcp = inner_tcp_hdr(skb);
2224+
} else {
2225+
ip = ip_hdr(skb);
2226+
tcp = tcp_hdr(skb);
2227+
}
2228+
2229+
/* 8000-series EF10 hardware requires that IP Total Length be
2230+
* greater than or equal to the value it will have in each segment
2231+
* (which is at most mss + 208 + TCP header length), but also less
2232+
* than (0x10000 - inner_network_header). Otherwise the TCP
2233+
* checksum calculation will be broken for encapsulated packets.
2234+
* We fill in ip->tot_len with 0xff30, which should satisfy the
2235+
* first requirement unless the MSS is ridiculously large (which
2236+
* should be impossible as the driver max MTU is 9216); it is
2237+
* guaranteed to satisfy the second as we only attempt TSO if
2238+
* inner_network_header <= 208.
2239+
*/
2240+
ip_tot_len = -EFX_TSO2_MAX_HDRLEN;
2241+
EFX_WARN_ON_ONCE_PARANOID(mss + EFX_TSO2_MAX_HDRLEN +
2242+
(tcp->doff << 2u) > ip_tot_len);
2243+
21932244
if (ip->version == 4) {
2194-
/* Modify IPv4 header if needed. */
2195-
ip->tot_len = 0;
2245+
ip->tot_len = htons(ip_tot_len);
21962246
ip->check = 0;
2197-
ipv4_id = ntohs(ip->id);
2247+
inner_ipv4_id = ntohs(ip->id);
21982248
} else {
2199-
/* Modify IPv6 header if needed. */
2200-
struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2201-
2202-
ipv6->payload_len = 0;
2203-
ipv4_id = 0;
2249+
((struct ipv6hdr *)ip)->payload_len = htons(ip_tot_len);
22042250
}
22052251

2206-
tcp = tcp_hdr(skb);
22072252
seqnum = ntohl(tcp->seq);
22082253

22092254
buffer = efx_tx_queue_get_insert_buffer(tx_queue);
@@ -2216,7 +2261,7 @@ static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
22162261
ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
22172262
ESF_DZ_TX_TSO_OPTION_TYPE,
22182263
ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2219-
ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2264+
ESF_DZ_TX_TSO_IP_ID, inner_ipv4_id,
22202265
ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
22212266
);
22222267
++tx_queue->insert_count;
@@ -2226,11 +2271,12 @@ static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
22262271
buffer->flags = EFX_TX_BUF_OPTION;
22272272
buffer->len = 0;
22282273
buffer->unmap_len = 0;
2229-
EFX_POPULATE_QWORD_4(buffer->option,
2274+
EFX_POPULATE_QWORD_5(buffer->option,
22302275
ESF_DZ_TX_DESC_IS_OPT, 1,
22312276
ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
22322277
ESF_DZ_TX_TSO_OPTION_TYPE,
22332278
ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2279+
ESF_DZ_TX_TSO_OUTER_IPID, outer_ipv4_id,
22342280
ESF_DZ_TX_TSO_TCP_MSS, mss
22352281
);
22362282
++tx_queue->insert_count;
@@ -2254,11 +2300,11 @@ static u32 efx_ef10_tso_versions(struct efx_nic *efx)
22542300

22552301
static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
22562302
{
2257-
bool csum_offload = tx_queue->label & EFX_TXQ_TYPE_OFFLOAD;
2303+
bool csum_offload = tx_queue->type & EFX_TXQ_TYPE_OUTER_CSUM;
2304+
bool inner_csum = tx_queue->type & EFX_TXQ_TYPE_INNER_CSUM;
22582305
struct efx_channel *channel = tx_queue->channel;
22592306
struct efx_nic *efx = tx_queue->efx;
22602307
struct efx_ef10_nic_data *nic_data;
2261-
bool tso_v2 = false;
22622308
efx_qword_t *txd;
22632309
int rc;
22642310

@@ -2281,15 +2327,18 @@ static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
22812327
* TSOv2 cannot be used with Hardware timestamping, and is never needed
22822328
* for XDP tx.
22832329
*/
2284-
if (csum_offload && (nic_data->datapath_caps2 &
2285-
(1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN)) &&
2286-
!tx_queue->timestamping && !tx_queue->xdp_tx) {
2287-
tso_v2 = true;
2288-
netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2289-
channel->channel);
2330+
if (efx_has_cap(efx, TX_TSO_V2)) {
2331+
if ((csum_offload || inner_csum) &&
2332+
!tx_queue->timestamping && !tx_queue->xdp_tx) {
2333+
tx_queue->tso_version = 2;
2334+
netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2335+
channel->channel);
2336+
}
2337+
} else if (efx_has_cap(efx, TX_TSO)) {
2338+
tx_queue->tso_version = 1;
22902339
}
22912340

2292-
rc = efx_mcdi_tx_init(tx_queue, tso_v2);
2341+
rc = efx_mcdi_tx_init(tx_queue);
22932342
if (rc)
22942343
goto fail;
22952344

@@ -2302,22 +2351,19 @@ static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
23022351
tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
23032352
tx_queue->insert_count = 1;
23042353
txd = efx_tx_desc(tx_queue, 0);
2305-
EFX_POPULATE_QWORD_5(*txd,
2354+
EFX_POPULATE_QWORD_7(*txd,
23062355
ESF_DZ_TX_DESC_IS_OPT, true,
23072356
ESF_DZ_TX_OPTION_TYPE,
23082357
ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
23092358
ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
2310-
ESF_DZ_TX_OPTION_IP_CSUM, csum_offload,
2359+
ESF_DZ_TX_OPTION_IP_CSUM, csum_offload && tx_queue->tso_version != 2,
2360+
ESF_DZ_TX_OPTION_INNER_UDP_TCP_CSUM, inner_csum,
2361+
ESF_DZ_TX_OPTION_INNER_IP_CSUM, inner_csum && tx_queue->tso_version != 2,
23112362
ESF_DZ_TX_TIMESTAMP, tx_queue->timestamping);
23122363
tx_queue->write_count = 1;
23132364

2314-
if (tso_v2) {
2315-
tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2316-
tx_queue->tso_version = 2;
2317-
} else if (nic_data->datapath_caps &
2318-
(1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
2319-
tx_queue->tso_version = 1;
2320-
}
2365+
if (tx_queue->tso_version == 2 && efx_has_cap(efx, TX_TSO_V2_ENCAP))
2366+
tx_queue->tso_encap = true;
23212367

23222368
wmb();
23232369
efx_ef10_push_tx_desc(tx_queue, txd);
@@ -2880,7 +2926,7 @@ efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
28802926
/* Get the transmit queue */
28812927
tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
28822928
tx_queue = efx_channel_get_tx_queue(channel,
2883-
tx_ev_q_label % EFX_TXQ_TYPES);
2929+
tx_ev_q_label % EFX_MAX_TXQ_PER_CHANNEL);
28842930

28852931
if (!tx_queue->timestamping) {
28862932
/* Transmit completion */

drivers/net/ethernet/sfc/ef100_tx.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ void ef100_tx_init(struct efx_tx_queue *tx_queue)
3737
tx_queue->channel->channel -
3838
tx_queue->efx->tx_channel_offset);
3939

40-
if (efx_mcdi_tx_init(tx_queue, false))
40+
/* This value is purely documentational; as EF100 never passes through
41+
* the switch statement in tx.c:__efx_enqueue_skb(), that switch does
42+
* not handle case 3. EF100's TSOv3 descriptors are generated by
43+
* ef100_make_tso_desc().
44+
* Meanwhile, all efx_mcdi_tx_init() cares about is that it's not 2.
45+
*/
46+
tx_queue->tso_version = 3;
47+
if (efx_mcdi_tx_init(tx_queue))
4148
netdev_WARN(tx_queue->efx->net_dev,
4249
"failed to initialise TXQ %d\n", tx_queue->queue);
4350
}

drivers/net/ethernet/sfc/efx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ static const struct net_device_ops efx_netdev_ops = {
596596
.ndo_set_mac_address = efx_set_mac_address,
597597
.ndo_set_rx_mode = efx_set_rx_mode,
598598
.ndo_set_features = efx_set_features,
599+
.ndo_features_check = efx_features_check,
599600
.ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid,
600601
.ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid,
601602
#ifdef CONFIG_SFC_SRIOV

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
*/

0 commit comments

Comments
 (0)