提交 7cccd501 编写于 作者: Y Yunsheng Lin 提交者: Xie XiuQi

net: hns3: combine len and checksum handling for inner and outer header.

driver inclusion
category: bugfix
bugzilla: NA
CVE: NA

When filling len and checksum info to description, there is some
similar checking or calculation.

So this patch adds hns3_set_l2l3l4 to fill the inner(/normal)
header's len and checksum info. If it is a encapsulation skb, it
calls hns3_set_outer_l2l3l4 to handle the outer header's len and
checksum info, in order to avoid some similar checking or
calculation.

Feature or Bugfix:Bugfix
Signed-off-by: NYunsheng Lin <linyunsheng@huawei.com>
Reviewed-by: Nlipeng <lipeng321@huawei.com>
Reviewed-by: NXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 fb68a3f9
...@@ -789,79 +789,6 @@ static int hns3_get_l4_protocol(struct sk_buff *skb, u8 *ol4_proto, ...@@ -789,79 +789,6 @@ static int hns3_get_l4_protocol(struct sk_buff *skb, u8 *ol4_proto,
return 0; return 0;
} }
static void hns3_set_l2l3l4_len(struct sk_buff *skb, u8 ol4_proto,
u8 il4_proto, u32 *type_cs_vlan_tso,
u32 *ol_type_vlan_len_msec)
{
unsigned char *l2_hdr = skb->data;
u8 l4_proto = ol4_proto;
union l3_hdr_info l3;
union l4_hdr_info l4;
u32 l2_len;
u32 l3_len;
u32 l4_len;
l3.hdr = skb_network_header(skb);
l4.hdr = skb_transport_header(skb);
/* tunnel packet */
if (skb->encapsulation) {
/* not MAC in UDP, MAC in GRE (0x6558) */
if (!(ol4_proto == IPPROTO_UDP || ol4_proto == IPPROTO_GRE))
return;
/* compute OL2 header size, defined in 2 Bytes */
l2_len = l3.hdr - skb->data;
hns3_set_field(*ol_type_vlan_len_msec,
HNS3_TXD_L2LEN_S, l2_len >> 1);
/* compute OL3 header size, defined in 4 Bytes */
l3_len = l4.hdr - l3.hdr;
hns3_set_field(*ol_type_vlan_len_msec, HNS3_TXD_L3LEN_S,
l3_len >> 2);
l2_hdr = skb_inner_mac_header(skb);
/* compute OL4 header size, defined in 4 Bytes. */
l4_len = l2_hdr - l4.hdr;
hns3_set_field(*ol_type_vlan_len_msec, HNS3_TXD_L4LEN_S,
l4_len >> 2);
/* switch to inner header */
l2_hdr = skb_inner_mac_header(skb);
l3.hdr = skb_inner_network_header(skb);
l4.hdr = skb_inner_transport_header(skb);
l4_proto = il4_proto;
}
l2_len = l3.hdr - l2_hdr;
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L2LEN_S, l2_len >> 1);
/* compute inner(/normal) L3 header size, defined in 4 Bytes */
l3_len = l4.hdr - l3.hdr;
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L3LEN_S, l3_len >> 2);
/* compute inner(/normal) L4 header size, defined in 4 Bytes */
switch (l4_proto) {
case IPPROTO_TCP:
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4LEN_S,
l4.tcp->doff);
break;
case IPPROTO_SCTP:
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4LEN_S,
(sizeof(struct sctphdr) >> 2));
break;
case IPPROTO_UDP:
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4LEN_S,
(sizeof(struct udphdr) >> 2));
break;
default:
/* skb packet types not supported by hardware,
* txbd len fild doesn't be filled.
*/
return;
}
}
/* when skb->encapsulation is 0, skb->ip_summed is CHECKSUM_PARTIAL /* when skb->encapsulation is 0, skb->ip_summed is CHECKSUM_PARTIAL
* and it is udp packet, which has a dest port as the IANA assigned. * and it is udp packet, which has a dest port as the IANA assigned.
* the hardware is expected to do the checksum offload, but the * the hardware is expected to do the checksum offload, but the
...@@ -883,84 +810,71 @@ static bool hns3_tunnel_csum_bug(struct sk_buff *skb) ...@@ -883,84 +810,71 @@ static bool hns3_tunnel_csum_bug(struct sk_buff *skb)
return true; return true;
} }
static int hns3_check_l4_proto(struct sk_buff *skb, u32 l4_proto, static void hns3_set_outer_l2l3l4(struct sk_buff *skb, u8 ol4_proto,
u32 *type_cs_vlan_tso) u32 *ol_type_vlan_len_msec)
{ {
switch (l4_proto) { u32 l2_len, l3_len, l4_len;
case IPPROTO_TCP: unsigned char *il2_hdr;
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4CS_B, 1); union l3_hdr_info l3;
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4T_S, union l4_hdr_info l4;
HNS3_L4T_TCP);
break;
case IPPROTO_UDP:
if (hns3_tunnel_csum_bug(skb))
break;
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4CS_B, 1); l3.hdr = skb_network_header(skb);
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4T_S, l4.hdr = skb_transport_header(skb);
HNS3_L4T_UDP);
break; /* compute OL2 header size, defined in 2 Bytes */
case IPPROTO_SCTP: l2_len = l3.hdr - skb->data;
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4CS_B, 1); hns3_set_field(*ol_type_vlan_len_msec, HNS3_TXD_L2LEN_S, l2_len >> 1);
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4T_S,
HNS3_L4T_SCTP); /* compute OL3 header size, defined in 4 Bytes */
break; l3_len = l4.hdr - l3.hdr;
default: hns3_set_field(*ol_type_vlan_len_msec, HNS3_TXD_L3LEN_S, l3_len >> 2);
/* drop the skb tunnel packet if hardware don't support,
* because hardware can't calculate csum when TSO. il2_hdr = skb_inner_mac_header(skb);
*/ /* compute OL4 header size, defined in 4 Bytes. */
l4_len = il2_hdr - l4.hdr;
hns3_set_field(*ol_type_vlan_len_msec, HNS3_TXD_L4LEN_S, l4_len >> 2);
/* define outer network header type */
if (skb->protocol == htons(ETH_P_IP)) {
if (skb_is_gso(skb)) if (skb_is_gso(skb))
return -EDOM; hns3_set_field(*ol_type_vlan_len_msec,
HNS3_TXD_OL3T_S,
HNS3_OL3T_IPV4_CSUM);
else
hns3_set_field(*ol_type_vlan_len_msec,
HNS3_TXD_OL3T_S,
HNS3_OL3T_IPV4_NO_CSUM);
/* the stack computes the IP header already, } else if (skb->protocol == htons(ETH_P_IPV6)) {
* driver calculate l4 checksum when not TSO. hns3_set_field(*ol_type_vlan_len_msec, HNS3_TXD_OL3T_S,
*/ HNS3_OL3T_IPV6);
skb_checksum_help(skb);
} }
return 0; if (ol4_proto == IPPROTO_UDP)
hns3_set_field(*ol_type_vlan_len_msec, HNS3_TXD_TUNTYPE_S,
HNS3_TUN_MAC_IN_UDP);
else if (ol4_proto == IPPROTO_GRE)
hns3_set_field(*ol_type_vlan_len_msec, HNS3_TXD_TUNTYPE_S,
HNS3_TUN_NVGRE);
} }
static int hns3_set_l3l4_type_csum(struct sk_buff *skb, u8 ol4_proto, static int hns3_set_l2l3l4(struct sk_buff *skb, u8 ol4_proto,
u8 il4_proto, u32 *type_cs_vlan_tso, u8 il4_proto, u32 *type_cs_vlan_tso,
u32 *ol_type_vlan_len_msec) u32 *ol_type_vlan_len_msec)
{ {
union l3_hdr_info l3; unsigned char *l2_hdr = l2_hdr = skb->data;
u32 l4_proto = ol4_proto; u32 l4_proto = ol4_proto;
union l4_hdr_info l4;
union l3_hdr_info l3;
u32 l2_len, l3_len;
l4.hdr = skb_transport_header(skb);
l3.hdr = skb_network_header(skb); l3.hdr = skb_network_header(skb);
/* define OL3 type and tunnel type(OL4) */ /* handle encapsulation skb */
if (skb->encapsulation) { if (skb->encapsulation) {
/* define outer network header type */ /* If this is a not UDP/GRE encapsulation skb */
if (skb->protocol == htons(ETH_P_IP)) { if (!(ol4_proto == IPPROTO_UDP || ol4_proto == IPPROTO_GRE)) {
if (skb_is_gso(skb))
hns3_set_field(*ol_type_vlan_len_msec,
HNS3_TXD_OL3T_S,
HNS3_OL3T_IPV4_CSUM);
else
hns3_set_field(*ol_type_vlan_len_msec,
HNS3_TXD_OL3T_S,
HNS3_OL3T_IPV4_NO_CSUM);
} else if (skb->protocol == htons(ETH_P_IPV6)) {
hns3_set_field(*ol_type_vlan_len_msec, HNS3_TXD_OL3T_S,
HNS3_OL3T_IPV6);
}
/* define tunnel type(OL4) */
switch (l4_proto) {
case IPPROTO_UDP:
hns3_set_field(*ol_type_vlan_len_msec,
HNS3_TXD_TUNTYPE_S,
HNS3_TUN_MAC_IN_UDP);
break;
case IPPROTO_GRE:
hns3_set_field(*ol_type_vlan_len_msec,
HNS3_TXD_TUNTYPE_S,
HNS3_TUN_NVGRE);
break;
default:
/* drop the skb tunnel packet if hardware don't support, /* drop the skb tunnel packet if hardware don't support,
* because hardware can't calculate csum when TSO. * because hardware can't calculate csum when TSO.
*/ */
...@@ -974,7 +888,12 @@ static int hns3_set_l3l4_type_csum(struct sk_buff *skb, u8 ol4_proto, ...@@ -974,7 +888,12 @@ static int hns3_set_l3l4_type_csum(struct sk_buff *skb, u8 ol4_proto,
return 0; return 0;
} }
hns3_set_outer_l2l3l4(skb, ol4_proto, ol_type_vlan_len_msec);
/* switch to inner header */
l2_hdr = skb_inner_mac_header(skb);
l3.hdr = skb_inner_network_header(skb); l3.hdr = skb_inner_network_header(skb);
l4.hdr = skb_inner_transport_header(skb);
l4_proto = il4_proto; l4_proto = il4_proto;
} }
...@@ -992,7 +911,55 @@ static int hns3_set_l3l4_type_csum(struct sk_buff *skb, u8 ol4_proto, ...@@ -992,7 +911,55 @@ static int hns3_set_l3l4_type_csum(struct sk_buff *skb, u8 ol4_proto,
HNS3_L3T_IPV6); HNS3_L3T_IPV6);
} }
return hns3_check_l4_proto(skb, l4_proto, type_cs_vlan_tso); /* compute inner(/normal) L2 header size, defined in 2 Bytes */
l2_len = l3.hdr - l2_hdr;
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L2LEN_S, l2_len >> 1);
/* compute inner(/normal) L3 header size, defined in 4 Bytes */
l3_len = l4.hdr - l3.hdr;
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L3LEN_S, l3_len >> 2);
/* compute inner(/normal) L4 header size, defined in 4 Bytes */
switch (l4_proto) {
case IPPROTO_TCP:
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4CS_B, 1);
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4T_S,
HNS3_L4T_TCP);
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4LEN_S,
l4.tcp->doff);
break;
case IPPROTO_UDP:
if (hns3_tunnel_csum_bug(skb))
break;
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4CS_B, 1);
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4T_S,
HNS3_L4T_UDP);
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4LEN_S,
(sizeof(struct udphdr) >> 2));
break;
case IPPROTO_SCTP:
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4CS_B, 1);
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4T_S,
HNS3_L4T_SCTP);
hns3_set_field(*type_cs_vlan_tso, HNS3_TXD_L4LEN_S,
(sizeof(struct sctphdr) >> 2));
break;
default:
/* drop the skb tunnel packet if hardware don't support,
* because hardware can't calculate csum when TSO.
*/
if (skb_is_gso(skb))
return -EDOM;
/* the stack computes the IP header already,
* driver calculate l4 checksum when not TSO.
*/
skb_checksum_help(skb);
return 0;
}
return 0;
} }
static void hns3_set_txbd_baseinfo(u16 *bdtp_fe_sc_vld_ra_ri, int frag_end) static void hns3_set_txbd_baseinfo(u16 *bdtp_fe_sc_vld_ra_ri, int frag_end)
...@@ -1107,12 +1074,10 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv, ...@@ -1107,12 +1074,10 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
ret = hns3_get_l4_protocol(skb, &ol4_proto, &il4_proto); ret = hns3_get_l4_protocol(skb, &ol4_proto, &il4_proto);
if (unlikely(ret)) if (unlikely(ret))
return ret; return ret;
hns3_set_l2l3l4_len(skb, ol4_proto, il4_proto,
&type_cs_vlan_tso, ret = hns3_set_l2l3l4(skb, ol4_proto, il4_proto,
&ol_type_vlan_len_msec); &type_cs_vlan_tso,
ret = hns3_set_l3l4_type_csum(skb, ol4_proto, il4_proto, &ol_type_vlan_len_msec);
&type_cs_vlan_tso,
&ol_type_vlan_len_msec);
if (unlikely(ret)) if (unlikely(ret))
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册