Skip to content

Commit 79a495a

Browse files
dmarionflorincoras
authored andcommitted
atlantic: add tcp segmentation offload
Advertise tcp_gso and segment GSO buffers in hardware. The context descriptor carries the header lengths and the mss, and all data descriptors of the packet have the large send offload and context enable bits set, with the payload length not including the headers. A packet with the GSO flag may use up to 32 buffers instead of 8. Type: feature Change-Id: I6183814610bb9d8d2f0099d2fab09f2a23cf1c7e Signed-off-by: Damjan Marion <dmarion@0xa5.net>
1 parent aa19c81 commit 79a495a

4 files changed

Lines changed: 83 additions & 19 deletions

File tree

‎src/drivers/net/atlantic/atlantic.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ atl_init (vlib_main_t *vm, vnet_dev_t *dev)
266266
.ip4_cksum = 1,
267267
.tcp_cksum = 1,
268268
.udp_cksum = 1,
269+
.tcp_gso = 1,
269270
},
270271
},
271272
.ops = {

‎src/drivers/net/atlantic/atlantic.h‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,30 @@ typedef union
113113
u64 qwords[2];
114114
struct
115115
{
116-
u32 _reserved0;
117-
u32 len;
116+
u64 _reserved_0_63;
118117
union
119118
{
120119
u32 ctl;
121120
struct
122121
{
123122
u32 type_txd : 1;
124123
u32 type_txc : 1;
125-
u32 tcp : 1;
126-
u32 _reserved_3_20 : 18;
124+
u32 _reserved_2_20 : 19;
127125
u32 ipv6 : 1;
128-
u32 _reserved_22_30 : 9;
129-
u32 cmd : 1;
126+
u32 tcp : 1;
127+
u32 _reserved_23 : 1;
128+
u32 l2_len : 7;
129+
u32 l3_len_lo : 1;
130130
};
131131
};
132132
union
133133
{
134134
u32 len2;
135135
struct
136136
{
137-
u32 l2_len : 7;
138-
u32 l3_len : 9;
137+
u32 l3_len_hi : 8;
139138
u32 l4_len : 8;
140-
u32 mss : 8;
139+
u32 mss : 16;
141140
};
142141
};
143142
};

‎src/drivers/net/atlantic/format.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,21 @@ format_atl_tx_desc (u8 *s, va_list *args)
777777

778778
#define _(b) ((b) ? '+' : '-')
779779

780+
if (d->type_txc)
781+
{
782+
const atl_tx_ctx_desc_t *c = (const void *) d;
783+
784+
return format (s, "context l2_len %u l3_len %u l4_len %u mss %u ipv6%c tcp%c", c->l2_len,
785+
c->l3_len_hi << 1 | c->l3_len_lo, c->l4_len, c->mss, _ (c->ipv6), _ (c->tcp));
786+
}
787+
780788
s = format (s, "addr 0x%016llx len %u ctx_en %u", d->addr, d->len, d->ctx_en);
781-
s = format (s,
782-
"\n%Uflags type_txd%c type_txc%c dd%c eop%c vlan%c fcs%c "
783-
"ip4csum%c l4csum%c wb%c blen %u",
784-
format_white_space, indent, _ (d->type_txd), _ (d->type_txc), _ (d->dd), _ (d->eop),
785-
_ (d->vlan), _ (d->fcs), _ (d->ip4csum), _ (d->l4csum), _ (d->wb), d->blen);
789+
s =
790+
format (s,
791+
"\n%Uflags type_txd%c type_txc%c dd%c eop%c vlan%c fcs%c "
792+
"ip4csum%c l4csum%c lso%c wb%c blen %u",
793+
format_white_space, indent, _ (d->type_txd), _ (d->type_txc), _ (d->dd), _ (d->eop),
794+
_ (d->vlan), _ (d->fcs), _ (d->ip4csum), _ (d->l4csum), _ (d->lso), _ (d->wb), d->blen);
786795

787796
#undef _
788797

‎src/drivers/net/atlantic/tx_node.c‎

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,47 @@
77
#include <vnet/ip/ip4_packet.h>
88
#include <atlantic.h>
99

10+
#include <vnet/ip/ip6_packet.h>
11+
#include <vnet/tcp/tcp_packet.h>
12+
1013
#define ATL_TX_CSO_IP4 1
1114
#define ATL_TX_CSO_L4 2
15+
#define ATL_TX_GSO 4
16+
17+
#define ATL_TX_MAX_SEGS 8
18+
#define ATL_TX_MAX_GSO_SEGS 32
1219

1320
static_always_inline u32
14-
atl_tx_prepare_offload (vlib_buffer_t *b)
21+
atl_tx_prepare_offload (vlib_buffer_t *b, atl_tx_ctx_desc_t *ctx)
1522
{
1623
vnet_buffer_oflags_t oflags = vnet_buffer (b)->oflags;
1724
u32 cso = 0;
1825

26+
if (PREDICT_FALSE (b->flags & VNET_BUFFER_F_GSO))
27+
{
28+
i16 l3_hdr_offset = vnet_buffer (b)->l3_hdr_offset;
29+
i16 l4_hdr_offset = vnet_buffer (b)->l4_hdr_offset;
30+
tcp_header_t *tcp = (void *) (b->data + l4_hdr_offset);
31+
u32 is_ip4 = b->flags & VNET_BUFFER_F_IS_IP4;
32+
u32 l2 = l3_hdr_offset - b->current_data, l3 = l4_hdr_offset - l3_hdr_offset;
33+
u32 l4 = tcp_header_bytes (tcp), mss = vnet_buffer2 (b)->gso_size;
34+
35+
*ctx = (atl_tx_ctx_desc_t) {
36+
.type_txc = 1,
37+
.ipv6 = !is_ip4,
38+
.tcp = 1,
39+
.l2_len = l2,
40+
.l3_len_lo = l3 & 1,
41+
.l3_len_hi = l3 >> 1,
42+
.l4_len = l4,
43+
.mss = mss,
44+
};
45+
46+
if (is_ip4)
47+
((ip4_header_t *) (b->data + l3_hdr_offset))->checksum = 0;
48+
return ATL_TX_GSO | ATL_TX_CSO_L4 | (is_ip4 ? ATL_TX_CSO_IP4 : 0);
49+
}
50+
1951
if (oflags & (VNET_BUFFER_OFFLOAD_F_TCP_CKSUM | VNET_BUFFER_OFFLOAD_F_UDP_CKSUM))
2052
cso |= ATL_TX_CSO_L4;
2153

@@ -43,6 +75,7 @@ atl_tx_one_batch (vlib_main_t *vm, vlib_node_runtime_t *node, vnet_dev_t *dev,
4375
u16 pkt_first_seg[32];
4476
u32 pkt_len[32];
4577
u8 pkt_cso[32];
78+
atl_tx_ctx_desc_t pkt_ctx[32];
4679
u32 n_drop = *n_drop_ptr;
4780
u32 n = 0;
4881
u16 tail = *tail_ptr;
@@ -57,12 +90,15 @@ atl_tx_one_batch (vlib_main_t *vm, vlib_node_runtime_t *node, vnet_dev_t *dev,
5790
u32 total_len = 0;
5891
u32 n_desc = 0;
5992

60-
if (n_free < ((b0->flags & VLIB_BUFFER_NEXT_PRESENT) ? 8 : 1))
93+
u32 max_segs = (b0->flags & VNET_BUFFER_F_GSO) ? ATL_TX_MAX_GSO_SEGS : ATL_TX_MAX_SEGS;
94+
95+
if (n_free < ((b0->flags & VLIB_BUFFER_NEXT_PRESENT) ? max_segs + 1 : 1) ||
96+
n_seg + max_segs > ARRAY_LEN (seg_len))
6197
break;
6298

6399
pkt_cso[n_enq] = 0;
64-
if (PREDICT_FALSE (b0->flags & VNET_BUFFER_F_OFFLOAD))
65-
pkt_cso[n_enq] = atl_tx_prepare_offload (b0);
100+
if (PREDICT_FALSE (b0->flags & (VNET_BUFFER_F_OFFLOAD | VNET_BUFFER_F_GSO)))
101+
pkt_cso[n_enq] = atl_tx_prepare_offload (b0, &pkt_ctx[n_enq]);
66102

67103
pkt_first_seg[n_enq] = n_seg;
68104

@@ -78,7 +114,7 @@ atl_tx_one_batch (vlib_main_t *vm, vlib_node_runtime_t *node, vnet_dev_t *dev,
78114
if ((b0->flags & VLIB_BUFFER_NEXT_PRESENT) == 0)
79115
break;
80116

81-
if (PREDICT_FALSE (n_desc == 8))
117+
if (PREDICT_FALSE (n_desc == max_segs))
82118
{
83119
drop_indices[n_drop++] = from[p];
84120
n++;
@@ -91,6 +127,22 @@ atl_tx_one_batch (vlib_main_t *vm, vlib_node_runtime_t *node, vnet_dev_t *dev,
91127

92128
pkt_len[n_enq] = total_len;
93129

130+
if (PREDICT_FALSE (pkt_cso[n_enq] & ATL_TX_GSO))
131+
{
132+
u16 slot = tail & mask;
133+
u32 hbi = seg_bi[pkt_first_seg[n_enq]];
134+
135+
aq->descs[slot].qwords[0] = pkt_ctx[n_enq].qwords[0];
136+
aq->descs[slot].qwords[1] = pkt_ctx[n_enq].qwords[1];
137+
bi_ring[slot] = hbi;
138+
vlib_get_buffer (vm, hbi)->ref_count++;
139+
tail++;
140+
n_free--;
141+
pkt_len[n_enq] -= pkt_ctx[n_enq].l2_len +
142+
(pkt_ctx[n_enq].l3_len_hi << 1 | pkt_ctx[n_enq].l3_len_lo) +
143+
pkt_ctx[n_enq].l4_len;
144+
}
145+
94146
for (u32 i = 0; i < n_desc; i++)
95147
{
96148
u32 seg_index = pkt_first_seg[n_enq] + i;
@@ -107,6 +159,8 @@ atl_tx_one_batch (vlib_main_t *vm, vlib_node_runtime_t *node, vnet_dev_t *dev,
107159
.len = pkt_len[n_enq],
108160
.ip4csum = (i == 0) & (pkt_cso[n_enq] & ATL_TX_CSO_IP4),
109161
.l4csum = (i == 0) & !!(pkt_cso[n_enq] & ATL_TX_CSO_L4),
162+
.lso = !!(pkt_cso[n_enq] & ATL_TX_GSO),
163+
.ctx_en = !!(pkt_cso[n_enq] & ATL_TX_GSO),
110164
};
111165

112166
aq->descs[slot] = desc;
@@ -144,6 +198,7 @@ atl_tx_trace_frame (vlib_main_t *vm, vlib_node_runtime_t *node, vnet_dev_tx_queu
144198

145199
if (first != tail && aq->buffer_indices[first & mask] == from[i])
146200
{
201+
n_desc = aq->descs[first & mask].type_txc;
147202
do
148203
n_desc++;
149204
while (aq->descs[(first + n_desc - 1) & mask].eop == 0);

0 commit comments

Comments
 (0)