Skip to content

Commit af21e86

Browse files
committed
atlantic: add tx checksum offload
Enable the IPv4 header and TCP/UDP checksum engines of the transmit protocol offload block, which are not enabled by default, and set the ip4 and l4 checksum bits in the first data descriptor of offloaded packets. The device computes the complete checksum, including the pseudo header, so the L4 checksum field does not need to be seeded and no context descriptor is needed. Type: feature Change-Id: I39bf70f0aff20d94a126a2eb6539d25c34482094 Signed-off-by: Damjan Marion <dmarion@0xa5.net>
1 parent b182aa3 commit af21e86

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ atl_init (vlib_main_t *vm, vnet_dev_t *dev)
253253
.ip4_cksum = 1,
254254
.l4_cksum = 1,
255255
},
256+
.tx_offloads = {
257+
.ip4_cksum = 1,
258+
.tcp_cksum = 1,
259+
.udp_cksum = 1,
260+
},
256261
},
257262
.ops = {
258263
.init = atl_port_init,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@
253253
__ (1, v6_v4_select) \
254254
__ (8, _reserved_24_31)
255255

256+
#define atl_reg_tpo_offload_ctrl_t_fields \
257+
__ (1, tcp_udp_crc_en) \
258+
__ (3, _reserved_1_3) \
259+
__ (1, ipv4_hdr_crc_en) \
260+
__ (27, _reserved_5_31)
261+
256262
#define atl_reg_tx_dma_ctrl_t_fields \
257263
__ (29, _reserved_0_28) \
258264
__ (1, en) \
@@ -385,6 +391,7 @@ ATL_REG_STRUCT (atl_reg_rx_dma_desc_len_t);
385391
ATL_REG_STRUCT (atl_reg_rx_dma_desc_data_hdr_size_t);
386392
ATL_REG_STRUCT (atl_reg_rx_dma_int_desc_wrwb_en_t);
387393
ATL_REG_STRUCT (atl_reg_rpf_l3_v6_v4_select_t);
394+
ATL_REG_STRUCT (atl_reg_tpo_offload_ctrl_t);
388395
ATL_REG_STRUCT (atl_reg_tx_dma_ctrl_t);
389396
ATL_REG_STRUCT (atl_reg_tx_dma_desc_len_t);
390397
ATL_REG_STRUCT (atl_reg_tx_dma_int_desc_wrwb_en_t);
@@ -471,6 +478,7 @@ ATL_REG_STRUCT (atl_reg_aq2_device_caps_t);
471478
_ (0x06500, RPF_L3_V6_V4_SELECT, atl_reg_rpf_l3_v6_v4_select_t_fields) \
472479
_ (0x06ff0, AQ2_RPF_REC_TAB_ENABLE, atl_reg_aq2_rpf_rec_tab_enable_t_fields) \
473480
_ (0x07000, TX_DMA_CTRL, atl_reg_tx_dma_ctrl_t_fields) \
481+
_ (0x07800, TPO_OFFLOAD_CTRL, atl_reg_tpo_offload_ctrl_t_fields) \
474482
_ (0x07820, THM_LSO_TCP_FLAG1, atl_reg_thm_lso_tcp_flag_t_fields) \
475483
_ (0x07824, THM_LSO_TCP_FLAG2, atl_reg_thm_lso_tcp_flag_t_fields) \
476484
_ (0x07900, TPB_TX_BUF, atl_reg_tpb_tx_buf_t_fields) \
@@ -615,6 +623,7 @@ typedef union
615623
atl_reg_rx_dma_int_desc_wrwb_en_t rx_dma_int_desc_wrwb_en;
616624
atl_reg_rpf_l3_v6_v4_select_t rpf_l3_v6_v4_select;
617625
atl_reg_tx_dma_ctrl_t tx_dma_ctrl;
626+
atl_reg_tpo_offload_ctrl_t tpo_offload_ctrl;
618627
atl_reg_tx_dma_desc_len_t tx_dma_desc_len;
619628
atl_reg_tx_dma_int_desc_wrwb_en_t tx_dma_int_desc_wrwb_en;
620629
atl_reg_intr_moderation_ctl_t intr_moderation_ctl;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ atl_tx_path_init (vnet_dev_port_t *port)
225225
atl_reg_wr (dev, ATL_REG_TX_DMA_CTRL, r);
226226

227227
atl_reg_wr (dev, ATL_REG_TDM_DCA, (atl_reg_t){});
228+
229+
r = atl_reg_rd (dev, ATL_REG_TPO_OFFLOAD_CTRL);
230+
r.tpo_offload_ctrl.tcp_udp_crc_en = 1;
231+
r.tpo_offload_ctrl.ipv4_hdr_crc_en = 1;
232+
atl_reg_wr (dev, ATL_REG_TPO_OFFLOAD_CTRL, r);
233+
228234
log_debug (dev, "tx path init done");
229235
}
230236

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,32 @@
44

55
#include <vnet/vnet.h>
66
#include <vnet/dev/dev.h>
7+
#include <vnet/ip/ip4_packet.h>
78
#include <atlantic.h>
89

10+
#define ATL_TX_CSO_IP4 1
11+
#define ATL_TX_CSO_L4 2
12+
13+
static_always_inline u32
14+
atl_tx_prepare_offload (vlib_buffer_t *b)
15+
{
16+
vnet_buffer_oflags_t oflags = vnet_buffer (b)->oflags;
17+
u32 cso = 0;
18+
19+
if (oflags & (VNET_BUFFER_OFFLOAD_F_TCP_CKSUM | VNET_BUFFER_OFFLOAD_F_UDP_CKSUM))
20+
cso |= ATL_TX_CSO_L4;
21+
22+
if ((b->flags & VNET_BUFFER_F_IS_IP4) && (oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM))
23+
{
24+
ip4_header_t *ip4 = (void *) (b->data + vnet_buffer (b)->l3_hdr_offset);
25+
26+
ip4->checksum = 0;
27+
cso |= ATL_TX_CSO_IP4;
28+
}
29+
30+
return cso;
31+
}
32+
933
static_always_inline u32
1034
atl_tx_one_batch (vlib_main_t *vm, vlib_node_runtime_t *node, vnet_dev_t *dev,
1135
vnet_dev_tx_queue_t *txq, u32 *bi_ring, u16 mask, u32 *from, u32 n_pkts,
@@ -18,6 +42,7 @@ atl_tx_one_batch (vlib_main_t *vm, vlib_node_runtime_t *node, vnet_dev_t *dev,
1842
u32 seg_bi[8 * 32];
1943
u16 pkt_first_seg[32];
2044
u32 pkt_len[32];
45+
u8 pkt_cso[32];
2146
u32 n_drop = *n_drop_ptr;
2247
u32 n = 0;
2348
u16 tail = *tail_ptr;
@@ -35,6 +60,10 @@ atl_tx_one_batch (vlib_main_t *vm, vlib_node_runtime_t *node, vnet_dev_t *dev,
3560
if (n_free < ((b0->flags & VLIB_BUFFER_NEXT_PRESENT) ? 8 : 1))
3661
break;
3762

63+
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);
66+
3867
pkt_first_seg[n_enq] = n_seg;
3968

4069
for (;;)
@@ -70,12 +99,14 @@ atl_tx_one_batch (vlib_main_t *vm, vlib_node_runtime_t *node, vnet_dev_t *dev,
7099
u16 slot = tail & mask;
71100
u32 bi = seg_bi[seg_index];
72101

73-
desc = (atl_tx_desc_t){
102+
desc = (atl_tx_desc_t) {
74103
.addr = dma_addr,
75104
.type_txd = 1,
76105
.blen = seg_len[seg_index],
77106
.eop = is_last,
78107
.len = pkt_len[n_enq],
108+
.ip4csum = (i == 0) & (pkt_cso[n_enq] & ATL_TX_CSO_IP4),
109+
.l4csum = (i == 0) & !!(pkt_cso[n_enq] & ATL_TX_CSO_L4),
79110
};
80111

81112
aq->descs[slot] = desc;

0 commit comments

Comments
 (0)