Commit 736fc0e1 authored by Jian Shen's avatar Jian Shen Committed by David S. Miller

net: hns3: split out hclge_fd_check_ether_tuple()

For readability and maintainability, this patch separates the
handling part of each flow type in hclge_fd_check_ether_tuple()
into standalone functions.
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 b785b06c
...@@ -5244,157 +5244,158 @@ static int hclge_config_action(struct hclge_dev *hdev, u8 stage, ...@@ -5244,157 +5244,158 @@ static int hclge_config_action(struct hclge_dev *hdev, u8 stage,
return hclge_fd_ad_config(hdev, stage, ad_data.ad_id, &ad_data); return hclge_fd_ad_config(hdev, stage, ad_data.ad_id, &ad_data);
} }
static int hclge_fd_check_spec(struct hclge_dev *hdev, static int hclge_fd_check_tcpip4_tuple(struct ethtool_tcpip4_spec *spec,
struct ethtool_rx_flow_spec *fs, u32 *unused) u32 *unused_tuple)
{ {
struct ethtool_tcpip4_spec *tcp_ip4_spec; if (!spec || !unused_tuple)
struct ethtool_usrip4_spec *usr_ip4_spec;
struct ethtool_tcpip6_spec *tcp_ip6_spec;
struct ethtool_usrip6_spec *usr_ip6_spec;
struct ethhdr *ether_spec;
if (fs->location >= hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1])
return -EINVAL; return -EINVAL;
if (!(fs->flow_type & hdev->fd_cfg.proto_support)) *unused_tuple |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC);
return -EOPNOTSUPP;
if ((fs->flow_type & FLOW_EXT) &&
(fs->h_ext.data[0] != 0 || fs->h_ext.data[1] != 0)) {
dev_err(&hdev->pdev->dev, "user-def bytes are not supported\n");
return -EOPNOTSUPP;
}
switch (fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) { if (!spec->ip4src)
case SCTP_V4_FLOW: *unused_tuple |= BIT(INNER_SRC_IP);
case TCP_V4_FLOW:
case UDP_V4_FLOW:
tcp_ip4_spec = &fs->h_u.tcp_ip4_spec;
*unused |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC);
if (!tcp_ip4_spec->ip4src) if (!spec->ip4dst)
*unused |= BIT(INNER_SRC_IP); *unused_tuple |= BIT(INNER_DST_IP);
if (!tcp_ip4_spec->ip4dst) if (!spec->psrc)
*unused |= BIT(INNER_DST_IP); *unused_tuple |= BIT(INNER_SRC_PORT);
if (!tcp_ip4_spec->psrc) if (!spec->pdst)
*unused |= BIT(INNER_SRC_PORT); *unused_tuple |= BIT(INNER_DST_PORT);
if (!tcp_ip4_spec->pdst) if (!spec->tos)
*unused |= BIT(INNER_DST_PORT); *unused_tuple |= BIT(INNER_IP_TOS);
if (!tcp_ip4_spec->tos) return 0;
*unused |= BIT(INNER_IP_TOS); }
break; static int hclge_fd_check_ip4_tuple(struct ethtool_usrip4_spec *spec,
case IP_USER_FLOW: u32 *unused_tuple)
usr_ip4_spec = &fs->h_u.usr_ip4_spec; {
*unused |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC) | if (!spec || !unused_tuple)
BIT(INNER_SRC_PORT) | BIT(INNER_DST_PORT); return -EINVAL;
if (!usr_ip4_spec->ip4src) *unused_tuple |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC) |
*unused |= BIT(INNER_SRC_IP); BIT(INNER_SRC_PORT) | BIT(INNER_DST_PORT);
if (!usr_ip4_spec->ip4dst) if (!spec->ip4src)
*unused |= BIT(INNER_DST_IP); *unused_tuple |= BIT(INNER_SRC_IP);
if (!usr_ip4_spec->tos) if (!spec->ip4dst)
*unused |= BIT(INNER_IP_TOS); *unused_tuple |= BIT(INNER_DST_IP);
if (!usr_ip4_spec->proto) if (!spec->tos)
*unused |= BIT(INNER_IP_PROTO); *unused_tuple |= BIT(INNER_IP_TOS);
if (usr_ip4_spec->l4_4_bytes) if (!spec->proto)
return -EOPNOTSUPP; *unused_tuple |= BIT(INNER_IP_PROTO);
if (usr_ip4_spec->ip_ver != ETH_RX_NFC_IP4) if (spec->l4_4_bytes)
return -EOPNOTSUPP; return -EOPNOTSUPP;
break; if (spec->ip_ver != ETH_RX_NFC_IP4)
case SCTP_V6_FLOW: return -EOPNOTSUPP;
case TCP_V6_FLOW:
case UDP_V6_FLOW:
tcp_ip6_spec = &fs->h_u.tcp_ip6_spec;
*unused |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC) |
BIT(INNER_IP_TOS);
/* check whether src/dst ip address used */ return 0;
if (!tcp_ip6_spec->ip6src[0] && !tcp_ip6_spec->ip6src[1] && }
!tcp_ip6_spec->ip6src[2] && !tcp_ip6_spec->ip6src[3])
*unused |= BIT(INNER_SRC_IP);
if (!tcp_ip6_spec->ip6dst[0] && !tcp_ip6_spec->ip6dst[1] && static int hclge_fd_check_tcpip6_tuple(struct ethtool_tcpip6_spec *spec,
!tcp_ip6_spec->ip6dst[2] && !tcp_ip6_spec->ip6dst[3]) u32 *unused_tuple)
*unused |= BIT(INNER_DST_IP); {
if (!spec || !unused_tuple)
return -EINVAL;
if (!tcp_ip6_spec->psrc) *unused_tuple |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC) |
*unused |= BIT(INNER_SRC_PORT); BIT(INNER_IP_TOS);
if (!tcp_ip6_spec->pdst) /* check whether src/dst ip address used */
*unused |= BIT(INNER_DST_PORT); if (!spec->ip6src[0] && !spec->ip6src[1] &&
!spec->ip6src[2] && !spec->ip6src[3])
*unused_tuple |= BIT(INNER_SRC_IP);
if (tcp_ip6_spec->tclass) if (!spec->ip6dst[0] && !spec->ip6dst[1] &&
return -EOPNOTSUPP; !spec->ip6dst[2] && !spec->ip6dst[3])
*unused_tuple |= BIT(INNER_DST_IP);
break; if (!spec->psrc)
case IPV6_USER_FLOW: *unused_tuple |= BIT(INNER_SRC_PORT);
usr_ip6_spec = &fs->h_u.usr_ip6_spec;
*unused |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC) |
BIT(INNER_IP_TOS) | BIT(INNER_SRC_PORT) |
BIT(INNER_DST_PORT);
/* check whether src/dst ip address used */ if (!spec->pdst)
if (!usr_ip6_spec->ip6src[0] && !usr_ip6_spec->ip6src[1] && *unused_tuple |= BIT(INNER_DST_PORT);
!usr_ip6_spec->ip6src[2] && !usr_ip6_spec->ip6src[3])
*unused |= BIT(INNER_SRC_IP);
if (!usr_ip6_spec->ip6dst[0] && !usr_ip6_spec->ip6dst[1] && if (spec->tclass)
!usr_ip6_spec->ip6dst[2] && !usr_ip6_spec->ip6dst[3]) return -EOPNOTSUPP;
*unused |= BIT(INNER_DST_IP);
if (!usr_ip6_spec->l4_proto) return 0;
*unused |= BIT(INNER_IP_PROTO); }
if (usr_ip6_spec->tclass) static int hclge_fd_check_ip6_tuple(struct ethtool_usrip6_spec *spec,
return -EOPNOTSUPP; u32 *unused_tuple)
{
if (!spec || !unused_tuple)
return -EINVAL;
if (usr_ip6_spec->l4_4_bytes) *unused_tuple |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC) |
return -EOPNOTSUPP; BIT(INNER_IP_TOS) | BIT(INNER_SRC_PORT) | BIT(INNER_DST_PORT);
break; /* check whether src/dst ip address used */
case ETHER_FLOW: if (!spec->ip6src[0] && !spec->ip6src[1] &&
ether_spec = &fs->h_u.ether_spec; !spec->ip6src[2] && !spec->ip6src[3])
*unused |= BIT(INNER_SRC_IP) | BIT(INNER_DST_IP) | *unused_tuple |= BIT(INNER_SRC_IP);
BIT(INNER_SRC_PORT) | BIT(INNER_DST_PORT) |
BIT(INNER_IP_TOS) | BIT(INNER_IP_PROTO);
if (is_zero_ether_addr(ether_spec->h_source)) if (!spec->ip6dst[0] && !spec->ip6dst[1] &&
*unused |= BIT(INNER_SRC_MAC); !spec->ip6dst[2] && !spec->ip6dst[3])
*unused_tuple |= BIT(INNER_DST_IP);
if (is_zero_ether_addr(ether_spec->h_dest)) if (!spec->l4_proto)
*unused |= BIT(INNER_DST_MAC); *unused_tuple |= BIT(INNER_IP_PROTO);
if (!ether_spec->h_proto) if (spec->tclass)
*unused |= BIT(INNER_ETH_TYPE); return -EOPNOTSUPP;
break; if (spec->l4_4_bytes)
default:
return -EOPNOTSUPP; return -EOPNOTSUPP;
}
return 0;
}
static int hclge_fd_check_ether_tuple(struct ethhdr *spec, u32 *unused_tuple)
{
if (!spec || !unused_tuple)
return -EINVAL;
*unused_tuple |= BIT(INNER_SRC_IP) | BIT(INNER_DST_IP) |
BIT(INNER_SRC_PORT) | BIT(INNER_DST_PORT) |
BIT(INNER_IP_TOS) | BIT(INNER_IP_PROTO);
if (is_zero_ether_addr(spec->h_source))
*unused_tuple |= BIT(INNER_SRC_MAC);
if (is_zero_ether_addr(spec->h_dest))
*unused_tuple |= BIT(INNER_DST_MAC);
if (!spec->h_proto)
*unused_tuple |= BIT(INNER_ETH_TYPE);
return 0;
}
static int hclge_fd_check_ext_tuple(struct hclge_dev *hdev,
struct ethtool_rx_flow_spec *fs,
u32 *unused_tuple)
{
if ((fs->flow_type & FLOW_EXT)) { if ((fs->flow_type & FLOW_EXT)) {
if (fs->h_ext.vlan_etype) if (fs->h_ext.vlan_etype)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (!fs->h_ext.vlan_tci) if (!fs->h_ext.vlan_tci)
*unused |= BIT(INNER_VLAN_TAG_FST); *unused_tuple |= BIT(INNER_VLAN_TAG_FST);
if (fs->m_ext.vlan_tci) { if (fs->m_ext.vlan_tci &&
if (be16_to_cpu(fs->h_ext.vlan_tci) >= VLAN_N_VID) be16_to_cpu(fs->h_ext.vlan_tci) >= VLAN_N_VID)
return -EINVAL; return -EINVAL;
}
} else { } else {
*unused |= BIT(INNER_VLAN_TAG_FST); *unused_tuple |= BIT(INNER_VLAN_TAG_FST);
} }
if (fs->flow_type & FLOW_MAC_EXT) { if (fs->flow_type & FLOW_MAC_EXT) {
...@@ -5402,14 +5403,74 @@ static int hclge_fd_check_spec(struct hclge_dev *hdev, ...@@ -5402,14 +5403,74 @@ static int hclge_fd_check_spec(struct hclge_dev *hdev,
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (is_zero_ether_addr(fs->h_ext.h_dest)) if (is_zero_ether_addr(fs->h_ext.h_dest))
*unused |= BIT(INNER_DST_MAC); *unused_tuple |= BIT(INNER_DST_MAC);
else else
*unused &= ~(BIT(INNER_DST_MAC)); *unused_tuple &= ~(BIT(INNER_DST_MAC));
} }
return 0; return 0;
} }
static int hclge_fd_check_spec(struct hclge_dev *hdev,
struct ethtool_rx_flow_spec *fs,
u32 *unused_tuple)
{
int ret;
if (fs->location >= hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1])
return -EINVAL;
if (!(fs->flow_type & hdev->fd_cfg.proto_support))
return -EOPNOTSUPP;
if ((fs->flow_type & FLOW_EXT) &&
(fs->h_ext.data[0] != 0 || fs->h_ext.data[1] != 0)) {
dev_err(&hdev->pdev->dev, "user-def bytes are not supported\n");
return -EOPNOTSUPP;
}
switch (fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
case SCTP_V4_FLOW:
case TCP_V4_FLOW:
case UDP_V4_FLOW:
ret = hclge_fd_check_tcpip4_tuple(&fs->h_u.tcp_ip4_spec,
unused_tuple);
break;
case IP_USER_FLOW:
ret = hclge_fd_check_ip4_tuple(&fs->h_u.usr_ip4_spec,
unused_tuple);
break;
case SCTP_V6_FLOW:
case TCP_V6_FLOW:
case UDP_V6_FLOW:
ret = hclge_fd_check_tcpip6_tuple(&fs->h_u.tcp_ip6_spec,
unused_tuple);
break;
case IPV6_USER_FLOW:
ret = hclge_fd_check_ip6_tuple(&fs->h_u.usr_ip6_spec,
unused_tuple);
break;
case ETHER_FLOW:
if (hdev->fd_cfg.fd_mode !=
HCLGE_FD_MODE_DEPTH_2K_WIDTH_400B_STAGE_1) {
dev_err(&hdev->pdev->dev,
"ETHER_FLOW is not supported in current fd mode!\n");
return -EOPNOTSUPP;
}
ret = hclge_fd_check_ether_tuple(&fs->h_u.ether_spec,
unused_tuple);
break;
default:
return -EOPNOTSUPP;
}
if (ret)
return ret;
return hclge_fd_check_ext_tuple(hdev, fs, unused_tuple);
}
static bool hclge_fd_rule_exist(struct hclge_dev *hdev, u16 location) static bool hclge_fd_rule_exist(struct hclge_dev *hdev, u16 location)
{ {
struct hclge_fd_rule *rule = NULL; struct hclge_fd_rule *rule = NULL;
......
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