Skip to content

Commit e9117e5

Browse files
sf-hgkdavem330
authored andcommitted
sfc: Firmware-Assisted TSO version 2
Add support for FATSOv2 to the driver. FATSOv2 offloads far more of the task of TCP segmentation to the firmware, such that we now just pass a single super-packet to the NIC. This means TSO has a great deal in common with a normal DMA transmit, apart from adding a couple of option descriptors. NIC-specific checks have been moved off the fast path and in to initialisation where possible. This also moves FATSOv1/SWTSO to a new file (tx_tso.c). The end of transmit and some error handling is now outside TSO, since it is common with other code. Signed-off-by: Edward Cree <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e17705c commit e9117e5

File tree

11 files changed

+1035
-768
lines changed

11 files changed

+1035
-768
lines changed

drivers/net/ethernet/sfc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sfc-y += efx.o nic.o farch.o falcon.o siena.o ef10.o tx.o \
22
rx.o selftest.o ethtool.o qt202x_phy.o mdio_10g.o \
33
tenxpress.o txc43128_phy.o falcon_boards.o \
4-
mcdi.o mcdi_port.o mcdi_mon.o ptp.o
4+
mcdi.o mcdi_port.o mcdi_mon.o ptp.o tx_tso.o
55
sfc-$(CONFIG_SFC_MTD) += mtd.o
66
sfc-$(CONFIG_SFC_SRIOV) += sriov.o siena_sriov.o ef10_sriov.o
77

drivers/net/ethernet/sfc/ef10.c

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,78 @@ static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
20862086
ER_DZ_TX_DESC_UPD, tx_queue->queue);
20872087
}
20882088

2089+
/* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2090+
*/
2091+
static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2092+
struct sk_buff *skb,
2093+
bool *data_mapped)
2094+
{
2095+
struct efx_tx_buffer *buffer;
2096+
struct tcphdr *tcp;
2097+
struct iphdr *ip;
2098+
2099+
u16 ipv4_id;
2100+
u32 seqnum;
2101+
u32 mss;
2102+
2103+
EFX_BUG_ON_PARANOID(tx_queue->tso_version != 2);
2104+
2105+
mss = skb_shinfo(skb)->gso_size;
2106+
2107+
if (unlikely(mss < 4)) {
2108+
WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2109+
return -EINVAL;
2110+
}
2111+
2112+
ip = ip_hdr(skb);
2113+
if (ip->version == 4) {
2114+
/* Modify IPv4 header if needed. */
2115+
ip->tot_len = 0;
2116+
ip->check = 0;
2117+
ipv4_id = ip->id;
2118+
} else {
2119+
/* Modify IPv6 header if needed. */
2120+
struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2121+
2122+
ipv6->payload_len = 0;
2123+
ipv4_id = 0;
2124+
}
2125+
2126+
tcp = tcp_hdr(skb);
2127+
seqnum = ntohl(tcp->seq);
2128+
2129+
buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2130+
2131+
buffer->flags = EFX_TX_BUF_OPTION;
2132+
buffer->len = 0;
2133+
buffer->unmap_len = 0;
2134+
EFX_POPULATE_QWORD_5(buffer->option,
2135+
ESF_DZ_TX_DESC_IS_OPT, 1,
2136+
ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2137+
ESF_DZ_TX_TSO_OPTION_TYPE,
2138+
ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2139+
ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2140+
ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2141+
);
2142+
++tx_queue->insert_count;
2143+
2144+
buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2145+
2146+
buffer->flags = EFX_TX_BUF_OPTION;
2147+
buffer->len = 0;
2148+
buffer->unmap_len = 0;
2149+
EFX_POPULATE_QWORD_4(buffer->option,
2150+
ESF_DZ_TX_DESC_IS_OPT, 1,
2151+
ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2152+
ESF_DZ_TX_TSO_OPTION_TYPE,
2153+
ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2154+
ESF_DZ_TX_TSO_TCP_MSS, mss
2155+
);
2156+
++tx_queue->insert_count;
2157+
2158+
return 0;
2159+
}
2160+
20892161
static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
20902162
{
20912163
MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
@@ -2095,20 +2167,41 @@ static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
20952167
struct efx_channel *channel = tx_queue->channel;
20962168
struct efx_nic *efx = tx_queue->efx;
20972169
struct efx_ef10_nic_data *nic_data = efx->nic_data;
2170+
bool tso_v2 = false;
20982171
size_t inlen;
20992172
dma_addr_t dma_addr;
21002173
efx_qword_t *txd;
21012174
int rc;
21022175
int i;
21032176
BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
21042177

2178+
/* TSOv2 is a limited resource that can only be configured on a limited
2179+
* number of queues. TSO without checksum offload is not really a thing,
2180+
* so we only enable it for those queues.
2181+
*
2182+
* TODO: handle failure to allocate this in the case where we've used
2183+
* all the queues.
2184+
*/
2185+
if (csum_offload && (nic_data->datapath_caps2 &
2186+
(1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
2187+
tso_v2 = true;
2188+
netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2189+
channel->channel);
2190+
}
2191+
21052192
MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
21062193
MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
21072194
MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
21082195
MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
2109-
MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
2196+
MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
2197+
/* This flag was removed from mcdi_pcol.h for
2198+
* the non-_EXT version of INIT_TXQ. However,
2199+
* firmware still honours it.
2200+
*/
2201+
INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
21102202
INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
21112203
INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
2204+
21122205
MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
21132206
MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
21142207

@@ -2146,8 +2239,11 @@ static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
21462239
ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
21472240
tx_queue->write_count = 1;
21482241

2149-
if (nic_data->datapath_caps &
2150-
(1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
2242+
if (tso_v2) {
2243+
tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2244+
tx_queue->tso_version = 2;
2245+
} else if (nic_data->datapath_caps &
2246+
(1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
21512247
tx_queue->tso_version = 1;
21522248
}
21532249

@@ -2202,6 +2298,25 @@ static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
22022298
ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
22032299
}
22042300

2301+
#define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2302+
2303+
static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2304+
dma_addr_t dma_addr, unsigned int len)
2305+
{
2306+
if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2307+
/* If we need to break across multiple descriptors we should
2308+
* stop at a page boundary. This assumes the length limit is
2309+
* greater than the page size.
2310+
*/
2311+
dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2312+
2313+
BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2314+
len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2315+
}
2316+
2317+
return len;
2318+
}
2319+
22052320
static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
22062321
{
22072322
unsigned int old_write_count = tx_queue->write_count;
@@ -5469,6 +5584,7 @@ const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
54695584
.tx_init = efx_ef10_tx_init,
54705585
.tx_remove = efx_ef10_tx_remove,
54715586
.tx_write = efx_ef10_tx_write,
5587+
.tx_limit_len = efx_ef10_tx_limit_len,
54725588
.rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
54735589
.rx_probe = efx_ef10_rx_probe,
54745590
.rx_init = efx_ef10_rx_init,
@@ -5575,6 +5691,7 @@ const struct efx_nic_type efx_hunt_a0_nic_type = {
55755691
.tx_init = efx_ef10_tx_init,
55765692
.tx_remove = efx_ef10_tx_remove,
55775693
.tx_write = efx_ef10_tx_write,
5694+
.tx_limit_len = efx_ef10_tx_limit_len,
55785695
.rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
55795696
.rx_probe = efx_ef10_rx_probe,
55805697
.rx_init = efx_ef10_rx_init,

drivers/net/ethernet/sfc/ethtool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static const struct efx_sw_stat_desc efx_sw_stat_desc[] = {
7171
EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
7272
EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
7373
EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets),
74+
EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets),
7475
EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
7576
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
7677
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),

drivers/net/ethernet/sfc/falcon.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,6 +2750,7 @@ const struct efx_nic_type falcon_a1_nic_type = {
27502750
.tx_init = efx_farch_tx_init,
27512751
.tx_remove = efx_farch_tx_remove,
27522752
.tx_write = efx_farch_tx_write,
2753+
.tx_limit_len = efx_farch_tx_limit_len,
27532754
.rx_push_rss_config = dummy_rx_push_rss_config,
27542755
.rx_probe = efx_farch_rx_probe,
27552756
.rx_init = efx_farch_rx_init,
@@ -2849,6 +2850,7 @@ const struct efx_nic_type falcon_b0_nic_type = {
28492850
.tx_init = efx_farch_tx_init,
28502851
.tx_remove = efx_farch_tx_remove,
28512852
.tx_write = efx_farch_tx_write,
2853+
.tx_limit_len = efx_farch_tx_limit_len,
28522854
.rx_push_rss_config = falcon_b0_rx_push_rss_config,
28532855
.rx_probe = efx_farch_rx_probe,
28542856
.rx_init = efx_farch_rx_init,

drivers/net/ethernet/sfc/farch.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,21 @@ void efx_farch_tx_write(struct efx_tx_queue *tx_queue)
356356
}
357357
}
358358

359+
unsigned int efx_farch_tx_limit_len(struct efx_tx_queue *tx_queue,
360+
dma_addr_t dma_addr, unsigned int len)
361+
{
362+
/* Don't cross 4K boundaries with descriptors. */
363+
unsigned int limit = (~dma_addr & (EFX_PAGE_SIZE - 1)) + 1;
364+
365+
len = min(limit, len);
366+
367+
if (EFX_WORKAROUND_5391(tx_queue->efx) && (dma_addr & 0xf))
368+
len = min_t(unsigned int, len, 512 - (dma_addr & 0xf));
369+
370+
return len;
371+
}
372+
373+
359374
/* Allocate hardware resources for a TX queue */
360375
int efx_farch_tx_probe(struct efx_tx_queue *tx_queue)
361376
{

drivers/net/ethernet/sfc/net_driver.h

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,17 @@ struct efx_tx_buffer {
189189
* @channel: The associated channel
190190
* @core_txq: The networking core TX queue structure
191191
* @buffer: The software buffer ring
192-
* @tsoh_page: Array of pages of TSO header buffers
192+
* @cb_page: Array of pages of copy buffers. Carved up according to
193+
* %EFX_TX_CB_ORDER into %EFX_TX_CB_SIZE-sized chunks.
193194
* @txd: The hardware descriptor ring
194195
* @ptr_mask: The size of the ring minus 1.
195196
* @piobuf: PIO buffer region for this TX queue (shared with its partner).
196197
* Size of the region is efx_piobuf_size.
197198
* @piobuf_offset: Buffer offset to be specified in PIO descriptors
198199
* @initialised: Has hardware queue been initialised?
200+
* @tx_min_size: Minimum transmit size for this queue. Depends on HW.
201+
* @handle_tso: TSO xmit preparation handler. Sets up the TSO metadata and
202+
* may also map tx data, depending on the nature of the TSO implementation.
199203
* @read_count: Current read pointer.
200204
* This is the number of buffers that have been removed from both rings.
201205
* @old_write_count: The value of @write_count when last checked.
@@ -224,6 +228,7 @@ struct efx_tx_buffer {
224228
* @pushes: Number of times the TX push feature has been used
225229
* @pio_packets: Number of times the TX PIO feature has been used
226230
* @xmit_more_available: Are any packets waiting to be pushed to the NIC
231+
* @cb_packets: Number of times the TX copybreak feature has been used
227232
* @empty_read_count: If the completion path has seen the queue as empty
228233
* and the transmission path has not yet checked this, the value of
229234
* @read_count bitwise-added to %EFX_EMPTY_COUNT_VALID; otherwise 0.
@@ -236,12 +241,16 @@ struct efx_tx_queue {
236241
struct efx_channel *channel;
237242
struct netdev_queue *core_txq;
238243
struct efx_tx_buffer *buffer;
239-
struct efx_buffer *tsoh_page;
244+
struct efx_buffer *cb_page;
240245
struct efx_special_buffer txd;
241246
unsigned int ptr_mask;
242247
void __iomem *piobuf;
243248
unsigned int piobuf_offset;
244249
bool initialised;
250+
unsigned int tx_min_size;
251+
252+
/* Function pointers used in the fast path. */
253+
int (*handle_tso)(struct efx_tx_queue*, struct sk_buff*, bool *);
245254

246255
/* Members used mainly on the completion path */
247256
unsigned int read_count ____cacheline_aligned_in_smp;
@@ -260,6 +269,7 @@ struct efx_tx_queue {
260269
unsigned int pushes;
261270
unsigned int pio_packets;
262271
bool xmit_more_available;
272+
unsigned int cb_packets;
263273
/* Statistics to supplement MAC stats */
264274
unsigned long tx_packets;
265275

@@ -269,6 +279,9 @@ struct efx_tx_queue {
269279
atomic_t flush_outstanding;
270280
};
271281

282+
#define EFX_TX_CB_ORDER 7
283+
#define EFX_TX_CB_SIZE (1 << EFX_TX_CB_ORDER) - NET_IP_ALIGN
284+
272285
/**
273286
* struct efx_rx_buffer - An Efx RX data buffer
274287
* @dma_addr: DMA base address of the buffer
@@ -1288,6 +1301,8 @@ struct efx_nic_type {
12881301
void (*tx_init)(struct efx_tx_queue *tx_queue);
12891302
void (*tx_remove)(struct efx_tx_queue *tx_queue);
12901303
void (*tx_write)(struct efx_tx_queue *tx_queue);
1304+
unsigned int (*tx_limit_len)(struct efx_tx_queue *tx_queue,
1305+
dma_addr_t dma_addr, unsigned int len);
12911306
int (*rx_push_rss_config)(struct efx_nic *efx, bool user,
12921307
const u32 *rx_indir_table);
12931308
int (*rx_probe)(struct efx_rx_queue *rx_queue);
@@ -1545,4 +1560,32 @@ static inline netdev_features_t efx_supported_features(const struct efx_nic *efx
15451560
return net_dev->features | net_dev->hw_features;
15461561
}
15471562

1563+
/* Get the current TX queue insert index. */
1564+
static inline unsigned int
1565+
efx_tx_queue_get_insert_index(const struct efx_tx_queue *tx_queue)
1566+
{
1567+
return tx_queue->insert_count & tx_queue->ptr_mask;
1568+
}
1569+
1570+
/* Get a TX buffer. */
1571+
static inline struct efx_tx_buffer *
1572+
__efx_tx_queue_get_insert_buffer(const struct efx_tx_queue *tx_queue)
1573+
{
1574+
return &tx_queue->buffer[efx_tx_queue_get_insert_index(tx_queue)];
1575+
}
1576+
1577+
/* Get a TX buffer, checking it's not currently in use. */
1578+
static inline struct efx_tx_buffer *
1579+
efx_tx_queue_get_insert_buffer(const struct efx_tx_queue *tx_queue)
1580+
{
1581+
struct efx_tx_buffer *buffer =
1582+
__efx_tx_queue_get_insert_buffer(tx_queue);
1583+
1584+
EFX_BUG_ON_PARANOID(buffer->len);
1585+
EFX_BUG_ON_PARANOID(buffer->flags);
1586+
EFX_BUG_ON_PARANOID(buffer->unmap_len);
1587+
1588+
return buffer;
1589+
}
1590+
15481591
#endif /* EFX_NET_DRIVER_H */

drivers/net/ethernet/sfc/nic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ void efx_farch_tx_init(struct efx_tx_queue *tx_queue);
681681
void efx_farch_tx_fini(struct efx_tx_queue *tx_queue);
682682
void efx_farch_tx_remove(struct efx_tx_queue *tx_queue);
683683
void efx_farch_tx_write(struct efx_tx_queue *tx_queue);
684+
unsigned int efx_farch_tx_limit_len(struct efx_tx_queue *tx_queue,
685+
dma_addr_t dma_addr, unsigned int len);
684686
int efx_farch_rx_probe(struct efx_rx_queue *rx_queue);
685687
void efx_farch_rx_init(struct efx_rx_queue *rx_queue);
686688
void efx_farch_rx_fini(struct efx_rx_queue *rx_queue);

drivers/net/ethernet/sfc/siena.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ const struct efx_nic_type siena_a0_nic_type = {
977977
.tx_init = efx_farch_tx_init,
978978
.tx_remove = efx_farch_tx_remove,
979979
.tx_write = efx_farch_tx_write,
980+
.tx_limit_len = efx_farch_tx_limit_len,
980981
.rx_push_rss_config = siena_rx_push_rss_config,
981982
.rx_probe = efx_farch_rx_probe,
982983
.rx_init = efx_farch_rx_init,

0 commit comments

Comments
 (0)