Commit 74b755d1 authored by Jian Shen's avatar Jian Shen Committed by David S. Miller

net: hns3: refactor out hclge_fd_get_tuple()

The process of function hclge_fd_get_tuple() is complex and
prolix. To make it more readable, extract the process of each
flow-type tuple to a single function.
Signed-off-by: default avatarJian Shen <shenjian15@huawei.com>
Signed-off-by: default avatarHuazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5f2b1238
...@@ -5935,144 +5935,158 @@ static int hclge_fd_update_rule_list(struct hclge_dev *hdev, ...@@ -5935,144 +5935,158 @@ static int hclge_fd_update_rule_list(struct hclge_dev *hdev,
return 0; return 0;
} }
static int hclge_fd_get_tuple(struct hclge_dev *hdev, static void hclge_fd_get_tcpip4_tuple(struct hclge_dev *hdev,
struct ethtool_rx_flow_spec *fs, struct ethtool_rx_flow_spec *fs,
struct hclge_fd_rule *rule) struct hclge_fd_rule *rule, u8 ip_proto)
{ {
u32 flow_type = fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT); rule->tuples.src_ip[IPV4_INDEX] =
be32_to_cpu(fs->h_u.tcp_ip4_spec.ip4src);
rule->tuples_mask.src_ip[IPV4_INDEX] =
be32_to_cpu(fs->m_u.tcp_ip4_spec.ip4src);
switch (flow_type) { rule->tuples.dst_ip[IPV4_INDEX] =
case SCTP_V4_FLOW: be32_to_cpu(fs->h_u.tcp_ip4_spec.ip4dst);
case TCP_V4_FLOW: rule->tuples_mask.dst_ip[IPV4_INDEX] =
case UDP_V4_FLOW: be32_to_cpu(fs->m_u.tcp_ip4_spec.ip4dst);
rule->tuples.src_ip[IPV4_INDEX] =
be32_to_cpu(fs->h_u.tcp_ip4_spec.ip4src);
rule->tuples_mask.src_ip[IPV4_INDEX] =
be32_to_cpu(fs->m_u.tcp_ip4_spec.ip4src);
rule->tuples.dst_ip[IPV4_INDEX] = rule->tuples.src_port = be16_to_cpu(fs->h_u.tcp_ip4_spec.psrc);
be32_to_cpu(fs->h_u.tcp_ip4_spec.ip4dst); rule->tuples_mask.src_port = be16_to_cpu(fs->m_u.tcp_ip4_spec.psrc);
rule->tuples_mask.dst_ip[IPV4_INDEX] =
be32_to_cpu(fs->m_u.tcp_ip4_spec.ip4dst);
rule->tuples.src_port = be16_to_cpu(fs->h_u.tcp_ip4_spec.psrc); rule->tuples.dst_port = be16_to_cpu(fs->h_u.tcp_ip4_spec.pdst);
rule->tuples_mask.src_port = rule->tuples_mask.dst_port = be16_to_cpu(fs->m_u.tcp_ip4_spec.pdst);
be16_to_cpu(fs->m_u.tcp_ip4_spec.psrc);
rule->tuples.dst_port = be16_to_cpu(fs->h_u.tcp_ip4_spec.pdst); rule->tuples.ip_tos = fs->h_u.tcp_ip4_spec.tos;
rule->tuples_mask.dst_port = rule->tuples_mask.ip_tos = fs->m_u.tcp_ip4_spec.tos;
be16_to_cpu(fs->m_u.tcp_ip4_spec.pdst);
rule->tuples.ip_tos = fs->h_u.tcp_ip4_spec.tos; rule->tuples.ether_proto = ETH_P_IP;
rule->tuples_mask.ip_tos = fs->m_u.tcp_ip4_spec.tos; rule->tuples_mask.ether_proto = 0xFFFF;
rule->tuples.ether_proto = ETH_P_IP; rule->tuples.ip_proto = ip_proto;
rule->tuples_mask.ether_proto = 0xFFFF; rule->tuples_mask.ip_proto = 0xFF;
}
break; static void hclge_fd_get_ip4_tuple(struct hclge_dev *hdev,
case IP_USER_FLOW: struct ethtool_rx_flow_spec *fs,
rule->tuples.src_ip[IPV4_INDEX] = struct hclge_fd_rule *rule)
be32_to_cpu(fs->h_u.usr_ip4_spec.ip4src); {
rule->tuples_mask.src_ip[IPV4_INDEX] = rule->tuples.src_ip[IPV4_INDEX] =
be32_to_cpu(fs->m_u.usr_ip4_spec.ip4src); be32_to_cpu(fs->h_u.usr_ip4_spec.ip4src);
rule->tuples_mask.src_ip[IPV4_INDEX] =
be32_to_cpu(fs->m_u.usr_ip4_spec.ip4src);
rule->tuples.dst_ip[IPV4_INDEX] = rule->tuples.dst_ip[IPV4_INDEX] =
be32_to_cpu(fs->h_u.usr_ip4_spec.ip4dst); be32_to_cpu(fs->h_u.usr_ip4_spec.ip4dst);
rule->tuples_mask.dst_ip[IPV4_INDEX] = rule->tuples_mask.dst_ip[IPV4_INDEX] =
be32_to_cpu(fs->m_u.usr_ip4_spec.ip4dst); be32_to_cpu(fs->m_u.usr_ip4_spec.ip4dst);
rule->tuples.ip_tos = fs->h_u.usr_ip4_spec.tos; rule->tuples.ip_tos = fs->h_u.usr_ip4_spec.tos;
rule->tuples_mask.ip_tos = fs->m_u.usr_ip4_spec.tos; rule->tuples_mask.ip_tos = fs->m_u.usr_ip4_spec.tos;
rule->tuples.ip_proto = fs->h_u.usr_ip4_spec.proto; rule->tuples.ip_proto = fs->h_u.usr_ip4_spec.proto;
rule->tuples_mask.ip_proto = fs->m_u.usr_ip4_spec.proto; rule->tuples_mask.ip_proto = fs->m_u.usr_ip4_spec.proto;
rule->tuples.ether_proto = ETH_P_IP; rule->tuples.ether_proto = ETH_P_IP;
rule->tuples_mask.ether_proto = 0xFFFF; rule->tuples_mask.ether_proto = 0xFFFF;
}
break; static void hclge_fd_get_tcpip6_tuple(struct hclge_dev *hdev,
case SCTP_V6_FLOW: struct ethtool_rx_flow_spec *fs,
case TCP_V6_FLOW: struct hclge_fd_rule *rule, u8 ip_proto)
case UDP_V6_FLOW: {
be32_to_cpu_array(rule->tuples.src_ip, be32_to_cpu_array(rule->tuples.src_ip, fs->h_u.tcp_ip6_spec.ip6src,
fs->h_u.tcp_ip6_spec.ip6src, IPV6_SIZE); IPV6_SIZE);
be32_to_cpu_array(rule->tuples_mask.src_ip, be32_to_cpu_array(rule->tuples_mask.src_ip, fs->m_u.tcp_ip6_spec.ip6src,
fs->m_u.tcp_ip6_spec.ip6src, IPV6_SIZE); IPV6_SIZE);
be32_to_cpu_array(rule->tuples.dst_ip, be32_to_cpu_array(rule->tuples.dst_ip, fs->h_u.tcp_ip6_spec.ip6dst,
fs->h_u.tcp_ip6_spec.ip6dst, IPV6_SIZE); IPV6_SIZE);
be32_to_cpu_array(rule->tuples_mask.dst_ip, be32_to_cpu_array(rule->tuples_mask.dst_ip, fs->m_u.tcp_ip6_spec.ip6dst,
fs->m_u.tcp_ip6_spec.ip6dst, IPV6_SIZE); IPV6_SIZE);
rule->tuples.src_port = be16_to_cpu(fs->h_u.tcp_ip6_spec.psrc); rule->tuples.src_port = be16_to_cpu(fs->h_u.tcp_ip6_spec.psrc);
rule->tuples_mask.src_port = rule->tuples_mask.src_port = be16_to_cpu(fs->m_u.tcp_ip6_spec.psrc);
be16_to_cpu(fs->m_u.tcp_ip6_spec.psrc);
rule->tuples.dst_port = be16_to_cpu(fs->h_u.tcp_ip6_spec.pdst); rule->tuples.dst_port = be16_to_cpu(fs->h_u.tcp_ip6_spec.pdst);
rule->tuples_mask.dst_port = rule->tuples_mask.dst_port = be16_to_cpu(fs->m_u.tcp_ip6_spec.pdst);
be16_to_cpu(fs->m_u.tcp_ip6_spec.pdst);
rule->tuples.ether_proto = ETH_P_IPV6; rule->tuples.ether_proto = ETH_P_IPV6;
rule->tuples_mask.ether_proto = 0xFFFF; rule->tuples_mask.ether_proto = 0xFFFF;
break; rule->tuples.ip_proto = ip_proto;
case IPV6_USER_FLOW: rule->tuples_mask.ip_proto = 0xFF;
be32_to_cpu_array(rule->tuples.src_ip, }
fs->h_u.usr_ip6_spec.ip6src, IPV6_SIZE);
be32_to_cpu_array(rule->tuples_mask.src_ip,
fs->m_u.usr_ip6_spec.ip6src, IPV6_SIZE);
be32_to_cpu_array(rule->tuples.dst_ip, static void hclge_fd_get_ip6_tuple(struct hclge_dev *hdev,
fs->h_u.usr_ip6_spec.ip6dst, IPV6_SIZE); struct ethtool_rx_flow_spec *fs,
be32_to_cpu_array(rule->tuples_mask.dst_ip, struct hclge_fd_rule *rule)
fs->m_u.usr_ip6_spec.ip6dst, IPV6_SIZE); {
be32_to_cpu_array(rule->tuples.src_ip, fs->h_u.usr_ip6_spec.ip6src,
IPV6_SIZE);
be32_to_cpu_array(rule->tuples_mask.src_ip, fs->m_u.usr_ip6_spec.ip6src,
IPV6_SIZE);
rule->tuples.ip_proto = fs->h_u.usr_ip6_spec.l4_proto; be32_to_cpu_array(rule->tuples.dst_ip, fs->h_u.usr_ip6_spec.ip6dst,
rule->tuples_mask.ip_proto = fs->m_u.usr_ip6_spec.l4_proto; IPV6_SIZE);
be32_to_cpu_array(rule->tuples_mask.dst_ip, fs->m_u.usr_ip6_spec.ip6dst,
IPV6_SIZE);
rule->tuples.ether_proto = ETH_P_IPV6; rule->tuples.ip_proto = fs->h_u.usr_ip6_spec.l4_proto;
rule->tuples_mask.ether_proto = 0xFFFF; rule->tuples_mask.ip_proto = fs->m_u.usr_ip6_spec.l4_proto;
break; rule->tuples.ether_proto = ETH_P_IPV6;
case ETHER_FLOW: rule->tuples_mask.ether_proto = 0xFFFF;
ether_addr_copy(rule->tuples.src_mac, }
fs->h_u.ether_spec.h_source);
ether_addr_copy(rule->tuples_mask.src_mac,
fs->m_u.ether_spec.h_source);
ether_addr_copy(rule->tuples.dst_mac, static void hclge_fd_get_ether_tuple(struct hclge_dev *hdev,
fs->h_u.ether_spec.h_dest); struct ethtool_rx_flow_spec *fs,
ether_addr_copy(rule->tuples_mask.dst_mac, struct hclge_fd_rule *rule)
fs->m_u.ether_spec.h_dest); {
ether_addr_copy(rule->tuples.src_mac, fs->h_u.ether_spec.h_source);
ether_addr_copy(rule->tuples_mask.src_mac, fs->m_u.ether_spec.h_source);
rule->tuples.ether_proto = ether_addr_copy(rule->tuples.dst_mac, fs->h_u.ether_spec.h_dest);
be16_to_cpu(fs->h_u.ether_spec.h_proto); ether_addr_copy(rule->tuples_mask.dst_mac, fs->m_u.ether_spec.h_dest);
rule->tuples_mask.ether_proto =
be16_to_cpu(fs->m_u.ether_spec.h_proto);
break; rule->tuples.ether_proto = be16_to_cpu(fs->h_u.ether_spec.h_proto);
default: rule->tuples_mask.ether_proto = be16_to_cpu(fs->m_u.ether_spec.h_proto);
return -EOPNOTSUPP; }
}
static int hclge_fd_get_tuple(struct hclge_dev *hdev,
struct ethtool_rx_flow_spec *fs,
struct hclge_fd_rule *rule)
{
u32 flow_type = fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT);
switch (flow_type) { switch (flow_type) {
case SCTP_V4_FLOW: case SCTP_V4_FLOW:
case SCTP_V6_FLOW: hclge_fd_get_tcpip4_tuple(hdev, fs, rule, IPPROTO_SCTP);
rule->tuples.ip_proto = IPPROTO_SCTP;
rule->tuples_mask.ip_proto = 0xFF;
break; break;
case TCP_V4_FLOW: case TCP_V4_FLOW:
case TCP_V6_FLOW: hclge_fd_get_tcpip4_tuple(hdev, fs, rule, IPPROTO_TCP);
rule->tuples.ip_proto = IPPROTO_TCP;
rule->tuples_mask.ip_proto = 0xFF;
break; break;
case UDP_V4_FLOW: case UDP_V4_FLOW:
hclge_fd_get_tcpip4_tuple(hdev, fs, rule, IPPROTO_UDP);
break;
case IP_USER_FLOW:
hclge_fd_get_ip4_tuple(hdev, fs, rule);
break;
case SCTP_V6_FLOW:
hclge_fd_get_tcpip6_tuple(hdev, fs, rule, IPPROTO_SCTP);
break;
case TCP_V6_FLOW:
hclge_fd_get_tcpip6_tuple(hdev, fs, rule, IPPROTO_TCP);
break;
case UDP_V6_FLOW: case UDP_V6_FLOW:
rule->tuples.ip_proto = IPPROTO_UDP; hclge_fd_get_tcpip6_tuple(hdev, fs, rule, IPPROTO_UDP);
rule->tuples_mask.ip_proto = 0xFF;
break; break;
default: case IPV6_USER_FLOW:
hclge_fd_get_ip6_tuple(hdev, fs, rule);
break; break;
case ETHER_FLOW:
hclge_fd_get_ether_tuple(hdev, fs, rule);
break;
default:
return -EOPNOTSUPP;
} }
if (fs->flow_type & FLOW_EXT) { if (fs->flow_type & FLOW_EXT) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment