当前位置:网站首页>Tso hardware sharding is a header copy problem

Tso hardware sharding is a header copy problem

2022-06-24 21:24:00 already_ skb

//skb->date It points to the layer 2 header address , Here is the calculation Ethernet head + IP head size

static inline int skb_transport_offset(const struct sk_buff *skb)

{
return skb_transport_header(skb) - skb->data;
}

static int e1000_tso(struct e1000_adapter *adapter,

     struct e1000_tx_ring *tx_ring, struct sk_buff *skb,
     __be16 protocol)
{
struct e1000_context_desc *context_desc;
struct e1000_buffer *buffer_info;
unsigned int i;
u32 cmd_length = 0;
u16 ipcse = 0, tucse, mss;
u8 ipcss, ipcso, tucss, tucso, hdr_len;
int err;


if (skb_is_gso(skb)) {
if (skb_header_cloned(skb)) {
err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
if (err)
return err;
}


                //hdr_len =  Ethernet head   +  IP Head + TCP Head

hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);

                //MSS size

mss = skb_shinfo(skb)->gso_size;

if (protocol == htons(ETH_P_IP)) {
struct iphdr *iph = ip_hdr(skb);
iph->tot_len = 0;
iph->check = 0;
tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
iph->daddr, 0,
IPPROTO_TCP,
0);
cmd_length = E1000_TXD_CMD_IP;
ipcse = skb_transport_offset(skb) - 1;
} else if (skb_is_gso_v6(skb)) {
ipv6_hdr(skb)->payload_len = 0;
tcp_hdr(skb)->check =
~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
&ipv6_hdr(skb)->daddr,
0, IPPROTO_TCP, 0);
ipcse = 0;
}
ipcss = skb_network_offset(skb);
ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
tucss = skb_transport_offset(skb);
tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
tucse = 0;


cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
       E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));


i = tx_ring->next_to_use;
context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
buffer_info = &tx_ring->buffer_info[i];


context_desc->lower_setup.ip_fields.ipcss  = ipcss;
context_desc->lower_setup.ip_fields.ipcso  = ipcso;
context_desc->lower_setup.ip_fields.ipcse  = cpu_to_le16(ipcse);
context_desc->upper_setup.tcp_fields.tucss = tucss;
context_desc->upper_setup.tcp_fields.tucso = tucso;

context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);

                // Basic information of hardware sharding

                // Network card hardware slicing requires automatic hardware copy , How much data to test , Where to start ?

                // The Ethernet header data is copied + IP The head of data   +  TCP Head ( So far, the code flow has built the Ethernet header )

                // Network card according to MSS Slice data , That is, the pure data part is MSS size

                // So the network card partition is copied from the Ethernet head

                // But because the data part changes, the network card must also support hardware verification

context_desc->tcp_seg_setup.fields.mss     = cpu_to_le16(mss);

context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;


context_desc->cmd_and_length = cpu_to_le32(cmd_length);


buffer_info->time_stamp = jiffies;
buffer_info->next_to_watch = i;


if (++i == tx_ring->count) i = 0;
tx_ring->next_to_use = i;


return true;
}
return false;
}
原网站

版权声明
本文为[already_ skb]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211315156155.html