Commit a527af9c authored by David S. Miller's avatar David S. Miller

Merge branch 'qed-ethtool-rx-flow-classification-enhancements'

Manish Chopra says:

====================
qed*: ethtool rx flow classification enhancements.

This series re-structures the driver's ethtool rx flow
classification flow, following that it adds other flow
profiles and rx flow classification enhancements
via "ethtool -N/-U"

Please consider applying this to "net-next"
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents e2f4f4e9 608e00d0
......@@ -1677,6 +1677,8 @@ static void __qed_get_vport_tstats(struct qed_hwfn *p_hwfn,
HILO_64_REGPAIR(tstats.mftag_filter_discard);
p_stats->common.mac_filter_discards +=
HILO_64_REGPAIR(tstats.eth_mac_filter_discard);
p_stats->common.gft_filter_drop +=
HILO_64_REGPAIR(tstats.eth_gft_drop_pkt);
}
static void __qed_get_vport_ustats_addrlen(struct qed_hwfn *p_hwfn,
......@@ -1973,6 +1975,8 @@ qed_arfs_mode_to_hsi(enum qed_filter_config_mode mode)
return GFT_PROFILE_TYPE_4_TUPLE;
if (mode == QED_FILTER_CONFIG_MODE_IP_DEST)
return GFT_PROFILE_TYPE_IP_DST_ADDR;
if (mode == QED_FILTER_CONFIG_MODE_IP_SRC)
return GFT_PROFILE_TYPE_IP_SRC_ADDR;
return GFT_PROFILE_TYPE_L4_DST_PORT;
}
......@@ -2013,16 +2017,6 @@ qed_configure_rfs_ntuple_filter(struct qed_hwfn *p_hwfn,
u8 abs_vport_id = 0;
int rc = -EINVAL;
rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
if (rc)
return rc;
if (p_params->qid != QED_RFS_NTUPLE_QID_RSS) {
rc = qed_fw_l2_queue(p_hwfn, p_params->qid, &abs_rx_q_id);
if (rc)
return rc;
}
/* Get SPQ entry */
memset(&init_data, 0, sizeof(init_data));
init_data.cid = qed_spq_get_cid(p_hwfn);
......@@ -2047,15 +2041,28 @@ qed_configure_rfs_ntuple_filter(struct qed_hwfn *p_hwfn,
DMA_REGPAIR_LE(p_ramrod->pkt_hdr_addr, p_params->addr);
p_ramrod->pkt_hdr_length = cpu_to_le16(p_params->length);
if (p_params->b_is_drop) {
p_ramrod->vport_id = cpu_to_le16(ETH_GFT_TRASHCAN_VPORT);
} else {
rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
if (rc)
return rc;
if (p_params->qid != QED_RFS_NTUPLE_QID_RSS) {
rc = qed_fw_l2_queue(p_hwfn, p_params->qid,
&abs_rx_q_id);
if (rc)
return rc;
p_ramrod->rx_qid_valid = 1;
p_ramrod->rx_qid = cpu_to_le16(abs_rx_q_id);
}
p_ramrod->vport_id = cpu_to_le16((u16)abs_vport_id);
}
p_ramrod->flow_id_valid = 0;
p_ramrod->flow_id = 0;
p_ramrod->vport_id = cpu_to_le16((u16)abs_vport_id);
p_ramrod->filter_action = p_params->b_is_add ? GFT_ADD_FILTER
: GFT_DELETE_FILTER;
......
......@@ -75,6 +75,7 @@ struct qede_stats_common {
u64 rx_bcast_pkts;
u64 mftag_filter_discards;
u64 mac_filter_discards;
u64 gft_filter_drop;
u64 tx_ucast_bytes;
u64 tx_mcast_bytes;
u64 tx_bcast_bytes;
......
......@@ -161,6 +161,7 @@ static const struct {
QEDE_STAT(no_buff_discards),
QEDE_PF_STAT(mftag_filter_discards),
QEDE_PF_STAT(mac_filter_discards),
QEDE_PF_STAT(gft_filter_drop),
QEDE_STAT(tx_err_drop_pkts),
QEDE_STAT(ttl0_discard),
QEDE_STAT(packet_too_big_discard),
......
......@@ -38,6 +38,7 @@
#include <linux/qed/qed_if.h>
#include "qede.h"
#define QEDE_FILTER_PRINT_MAX_LEN (64)
struct qede_arfs_tuple {
union {
__be32 src_ipv4;
......@@ -51,6 +52,18 @@ struct qede_arfs_tuple {
__be16 dst_port;
__be16 eth_proto;
u8 ip_proto;
/* Describe filtering mode needed for this kind of filter */
enum qed_filter_config_mode mode;
/* Used to compare new/old filters. Return true if IPs match */
bool (*ip_comp)(struct qede_arfs_tuple *a, struct qede_arfs_tuple *b);
/* Given an address into ethhdr build a header from tuple info */
void (*build_hdr)(struct qede_arfs_tuple *t, void *header);
/* Stringify the tuple for a print into the provided buffer */
void (*stringify)(struct qede_arfs_tuple *t, void *buffer);
};
struct qede_arfs_fltr_node {
......@@ -73,9 +86,11 @@ struct qede_arfs_fltr_node {
u16 sw_id;
u16 rxq_id;
u16 next_rxq_id;
u8 vfid;
bool filter_op;
bool used;
u8 fw_rc;
bool b_is_drop;
struct hlist_node node;
};
......@@ -90,7 +105,9 @@ struct qede_arfs {
spinlock_t arfs_list_lock;
unsigned long *arfs_fltr_bmap;
int filter_count;
bool enable;
/* Currently configured filtering mode */
enum qed_filter_config_mode mode;
};
static void qede_configure_arfs_fltr(struct qede_dev *edev,
......@@ -109,12 +126,22 @@ static void qede_configure_arfs_fltr(struct qede_dev *edev,
params.length = n->buf_len;
params.qid = rxq_id;
params.b_is_add = add_fltr;
params.b_is_drop = n->b_is_drop;
if (n->vfid) {
params.b_is_vf = true;
params.vf_id = n->vfid - 1;
}
if (n->tuple.stringify) {
char tuple_buffer[QEDE_FILTER_PRINT_MAX_LEN];
n->tuple.stringify(&n->tuple, tuple_buffer);
DP_VERBOSE(edev, NETIF_MSG_RX_STATUS,
"%s arfs filter flow_id=%d, sw_id=%d, src_port=%d, dst_port=%d, rxq=%d\n",
"%s sw_id[0x%x]: %s [vf %u queue %d]\n",
add_fltr ? "Adding" : "Deleting",
n->flow_id, n->sw_id, ntohs(n->tuple.src_port),
ntohs(n->tuple.dst_port), rxq_id);
n->sw_id, tuple_buffer, n->vfid, rxq_id);
}
n->used = true;
n->filter_op = add_fltr;
......@@ -145,14 +172,13 @@ qede_enqueue_fltr_and_config_searcher(struct qede_dev *edev,
INIT_HLIST_NODE(&fltr->node);
hlist_add_head(&fltr->node,
QEDE_ARFS_BUCKET_HEAD(edev, bucket_idx));
edev->arfs->filter_count++;
if (edev->arfs->filter_count == 1 && !edev->arfs->enable) {
enum qed_filter_config_mode mode;
mode = QED_FILTER_CONFIG_MODE_5_TUPLE;
edev->ops->configure_arfs_searcher(edev->cdev, mode);
edev->arfs->enable = true;
edev->arfs->filter_count++;
if (edev->arfs->filter_count == 1 &&
edev->arfs->mode == QED_FILTER_CONFIG_MODE_DISABLE) {
edev->ops->configure_arfs_searcher(edev->cdev,
fltr->tuple.mode);
edev->arfs->mode = fltr->tuple.mode;
}
return 0;
......@@ -167,14 +193,15 @@ qede_dequeue_fltr_and_config_searcher(struct qede_dev *edev,
fltr->buf_len, DMA_TO_DEVICE);
qede_free_arfs_filter(edev, fltr);
edev->arfs->filter_count--;
if (!edev->arfs->filter_count && edev->arfs->enable) {
edev->arfs->filter_count--;
if (!edev->arfs->filter_count &&
edev->arfs->mode != QED_FILTER_CONFIG_MODE_DISABLE) {
enum qed_filter_config_mode mode;
mode = QED_FILTER_CONFIG_MODE_DISABLE;
edev->arfs->enable = false;
edev->ops->configure_arfs_searcher(edev->cdev, mode);
edev->arfs->mode = QED_FILTER_CONFIG_MODE_DISABLE;
}
}
......@@ -264,25 +291,17 @@ void qede_process_arfs_filters(struct qede_dev *edev, bool free_fltr)
}
}
#ifdef CONFIG_RFS_ACCEL
spin_lock_bh(&edev->arfs->arfs_list_lock);
if (!edev->arfs->filter_count) {
if (edev->arfs->enable) {
enum qed_filter_config_mode mode;
mode = QED_FILTER_CONFIG_MODE_DISABLE;
edev->arfs->enable = false;
edev->ops->configure_arfs_searcher(edev->cdev, mode);
}
#ifdef CONFIG_RFS_ACCEL
} else {
if (edev->arfs->filter_count) {
set_bit(QEDE_SP_ARFS_CONFIG, &edev->sp_flags);
schedule_delayed_work(&edev->sp_task,
QEDE_SP_TASK_POLL_DELAY);
#endif
}
spin_unlock_bh(&edev->arfs->arfs_list_lock);
#endif
}
/* This function waits until all aRFS filters get deleted and freed.
......@@ -512,6 +531,7 @@ int qede_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
eth->h_proto = skb->protocol;
n->tuple.eth_proto = skb->protocol;
n->tuple.ip_proto = ip_proto;
n->tuple.mode = QED_FILTER_CONFIG_MODE_5_TUPLE;
memcpy(n->data + ETH_HLEN, skb->data, skb_headlen(skb));
rc = qede_enqueue_fltr_and_config_searcher(edev, n, tbl_idx);
......@@ -1339,38 +1359,6 @@ qede_get_arfs_fltr_by_loc(struct hlist_head *head, u32 location)
return NULL;
}
static bool
qede_compare_user_flow_ips(struct qede_arfs_fltr_node *tpos,
struct ethtool_rx_flow_spec *fsp,
__be16 proto)
{
if (proto == htons(ETH_P_IP)) {
struct ethtool_tcpip4_spec *ip;
ip = &fsp->h_u.tcp_ip4_spec;
if (tpos->tuple.src_ipv4 == ip->ip4src &&
tpos->tuple.dst_ipv4 == ip->ip4dst)
return true;
else
return false;
} else {
struct ethtool_tcpip6_spec *ip6;
struct in6_addr *src;
ip6 = &fsp->h_u.tcp_ip6_spec;
src = &tpos->tuple.src_ipv6;
if (!memcmp(src, &ip6->ip6src, sizeof(struct in6_addr)) &&
!memcmp(&tpos->tuple.dst_ipv6, &ip6->ip6dst,
sizeof(struct in6_addr)))
return true;
else
return false;
}
return false;
}
int qede_get_cls_rule_all(struct qede_dev *edev, struct ethtool_rxnfc *info,
u32 *rule_locs)
{
......@@ -1455,102 +1443,444 @@ int qede_get_cls_rule_entry(struct qede_dev *edev, struct ethtool_rxnfc *cmd)
fsp->ring_cookie = fltr->rxq_id;
if (fltr->vfid) {
fsp->ring_cookie |= ((u64)fltr->vfid) <<
ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
}
if (fltr->b_is_drop)
fsp->ring_cookie = RX_CLS_FLOW_DISC;
unlock:
__qede_unlock(edev);
return rc;
}
static int
qede_validate_and_check_flow_exist(struct qede_dev *edev,
struct ethtool_rx_flow_spec *fsp,
int *min_hlen)
qede_poll_arfs_filter_config(struct qede_dev *edev,
struct qede_arfs_fltr_node *fltr)
{
__be16 src_port = 0x0, dst_port = 0x0;
struct qede_arfs_fltr_node *fltr;
struct hlist_node *temp;
struct hlist_head *head;
__be16 eth_proto;
u8 ip_proto;
int count = QEDE_ARFS_POLL_COUNT;
if (fsp->location >= QEDE_RFS_MAX_FLTR ||
fsp->ring_cookie >= QEDE_RSS_COUNT(edev))
return -EINVAL;
while (fltr->used && count) {
msleep(20);
count--;
}
if (count == 0 || fltr->fw_rc) {
DP_NOTICE(edev, "Timeout in polling filter config\n");
qede_dequeue_fltr_and_config_searcher(edev, fltr);
return -EIO;
}
return fltr->fw_rc;
}
if (fsp->flow_type == TCP_V4_FLOW) {
*min_hlen += sizeof(struct iphdr) +
sizeof(struct tcphdr);
eth_proto = htons(ETH_P_IP);
ip_proto = IPPROTO_TCP;
} else if (fsp->flow_type == UDP_V4_FLOW) {
*min_hlen += sizeof(struct iphdr) +
sizeof(struct udphdr);
eth_proto = htons(ETH_P_IP);
ip_proto = IPPROTO_UDP;
} else if (fsp->flow_type == TCP_V6_FLOW) {
*min_hlen += sizeof(struct ipv6hdr) +
sizeof(struct tcphdr);
eth_proto = htons(ETH_P_IPV6);
ip_proto = IPPROTO_TCP;
} else if (fsp->flow_type == UDP_V6_FLOW) {
*min_hlen += sizeof(struct ipv6hdr) +
sizeof(struct udphdr);
eth_proto = htons(ETH_P_IPV6);
ip_proto = IPPROTO_UDP;
static int qede_flow_get_min_header_size(struct qede_arfs_tuple *t)
{
int size = ETH_HLEN;
if (t->eth_proto == htons(ETH_P_IP))
size += sizeof(struct iphdr);
else
size += sizeof(struct ipv6hdr);
if (t->ip_proto == IPPROTO_TCP)
size += sizeof(struct tcphdr);
else
size += sizeof(struct udphdr);
return size;
}
static bool qede_flow_spec_ipv4_cmp(struct qede_arfs_tuple *a,
struct qede_arfs_tuple *b)
{
if (a->eth_proto != htons(ETH_P_IP) ||
b->eth_proto != htons(ETH_P_IP))
return false;
return (a->src_ipv4 == b->src_ipv4) &&
(a->dst_ipv4 == b->dst_ipv4);
}
static void qede_flow_build_ipv4_hdr(struct qede_arfs_tuple *t,
void *header)
{
__be16 *ports = (__be16 *)(header + ETH_HLEN + sizeof(struct iphdr));
struct iphdr *ip = (struct iphdr *)(header + ETH_HLEN);
struct ethhdr *eth = (struct ethhdr *)header;
eth->h_proto = t->eth_proto;
ip->saddr = t->src_ipv4;
ip->daddr = t->dst_ipv4;
ip->version = 0x4;
ip->ihl = 0x5;
ip->protocol = t->ip_proto;
ip->tot_len = cpu_to_be16(qede_flow_get_min_header_size(t) - ETH_HLEN);
/* ports is weakly typed to suit both TCP and UDP ports */
ports[0] = t->src_port;
ports[1] = t->dst_port;
}
static void qede_flow_stringify_ipv4_hdr(struct qede_arfs_tuple *t,
void *buffer)
{
const char *prefix = t->ip_proto == IPPROTO_TCP ? "TCP" : "UDP";
snprintf(buffer, QEDE_FILTER_PRINT_MAX_LEN,
"%s %pI4 (%04x) -> %pI4 (%04x)",
prefix, &t->src_ipv4, t->src_port,
&t->dst_ipv4, t->dst_port);
}
static bool qede_flow_spec_ipv6_cmp(struct qede_arfs_tuple *a,
struct qede_arfs_tuple *b)
{
if (a->eth_proto != htons(ETH_P_IPV6) ||
b->eth_proto != htons(ETH_P_IPV6))
return false;
if (memcmp(&a->src_ipv6, &b->src_ipv6, sizeof(struct in6_addr)))
return false;
if (memcmp(&a->dst_ipv6, &b->dst_ipv6, sizeof(struct in6_addr)))
return false;
return true;
}
static void qede_flow_build_ipv6_hdr(struct qede_arfs_tuple *t,
void *header)
{
__be16 *ports = (__be16 *)(header + ETH_HLEN + sizeof(struct ipv6hdr));
struct ipv6hdr *ip6 = (struct ipv6hdr *)(header + ETH_HLEN);
struct ethhdr *eth = (struct ethhdr *)header;
eth->h_proto = t->eth_proto;
memcpy(&ip6->saddr, &t->src_ipv6, sizeof(struct in6_addr));
memcpy(&ip6->daddr, &t->dst_ipv6, sizeof(struct in6_addr));
ip6->version = 0x6;
if (t->ip_proto == IPPROTO_TCP) {
ip6->nexthdr = NEXTHDR_TCP;
ip6->payload_len = cpu_to_be16(sizeof(struct tcphdr));
} else {
DP_NOTICE(edev, "Unsupported flow type = 0x%x\n",
fsp->flow_type);
return -EPROTONOSUPPORT;
ip6->nexthdr = NEXTHDR_UDP;
ip6->payload_len = cpu_to_be16(sizeof(struct udphdr));
}
/* ports is weakly typed to suit both TCP and UDP ports */
ports[0] = t->src_port;
ports[1] = t->dst_port;
}
/* Validate fields which are set and not accepted by the driver */
static int qede_flow_spec_validate_unused(struct qede_dev *edev,
struct ethtool_rx_flow_spec *fs)
{
if (fs->flow_type & FLOW_MAC_EXT) {
DP_INFO(edev, "Don't support MAC extensions\n");
return -EOPNOTSUPP;
}
if ((fs->flow_type & FLOW_EXT) &&
(fs->h_ext.vlan_etype || fs->h_ext.vlan_tci)) {
DP_INFO(edev, "Don't support vlan-based classification\n");
return -EOPNOTSUPP;
}
if ((fs->flow_type & FLOW_EXT) &&
(fs->h_ext.data[0] || fs->h_ext.data[1])) {
DP_INFO(edev, "Don't support user defined data\n");
return -EOPNOTSUPP;
}
return 0;
}
static int qede_flow_spec_to_tuple_ipv4_common(struct qede_dev *edev,
struct qede_arfs_tuple *t,
struct ethtool_rx_flow_spec *fs)
{
if ((fs->h_u.tcp_ip4_spec.ip4src &
fs->m_u.tcp_ip4_spec.ip4src) != fs->h_u.tcp_ip4_spec.ip4src) {
DP_INFO(edev, "Don't support IP-masks\n");
return -EOPNOTSUPP;
}
if ((fs->h_u.tcp_ip4_spec.ip4dst &
fs->m_u.tcp_ip4_spec.ip4dst) != fs->h_u.tcp_ip4_spec.ip4dst) {
DP_INFO(edev, "Don't support IP-masks\n");
return -EOPNOTSUPP;
}
if ((fs->h_u.tcp_ip4_spec.psrc &
fs->m_u.tcp_ip4_spec.psrc) != fs->h_u.tcp_ip4_spec.psrc) {
DP_INFO(edev, "Don't support port-masks\n");
return -EOPNOTSUPP;
}
if ((fs->h_u.tcp_ip4_spec.pdst &
fs->m_u.tcp_ip4_spec.pdst) != fs->h_u.tcp_ip4_spec.pdst) {
DP_INFO(edev, "Don't support port-masks\n");
return -EOPNOTSUPP;
}
if (fs->h_u.tcp_ip4_spec.tos) {
DP_INFO(edev, "Don't support tos\n");
return -EOPNOTSUPP;
}
t->eth_proto = htons(ETH_P_IP);
t->src_ipv4 = fs->h_u.tcp_ip4_spec.ip4src;
t->dst_ipv4 = fs->h_u.tcp_ip4_spec.ip4dst;
t->src_port = fs->h_u.tcp_ip4_spec.psrc;
t->dst_port = fs->h_u.tcp_ip4_spec.pdst;
/* We must either have a valid 4-tuple or only dst port
* or only src ip as an input
*/
if (t->src_port && t->dst_port && t->src_ipv4 && t->dst_ipv4) {
t->mode = QED_FILTER_CONFIG_MODE_5_TUPLE;
} else if (!t->src_port && t->dst_port &&
!t->src_ipv4 && !t->dst_ipv4) {
t->mode = QED_FILTER_CONFIG_MODE_L4_PORT;
} else if (!t->src_port && !t->dst_port &&
!t->dst_ipv4 && t->src_ipv4) {
t->mode = QED_FILTER_CONFIG_MODE_IP_SRC;
} else {
DP_INFO(edev, "Invalid N-tuple\n");
return -EOPNOTSUPP;
}
t->ip_comp = qede_flow_spec_ipv4_cmp;
t->build_hdr = qede_flow_build_ipv4_hdr;
t->stringify = qede_flow_stringify_ipv4_hdr;
return 0;
}
static int qede_flow_spec_to_tuple_tcpv4(struct qede_dev *edev,
struct qede_arfs_tuple *t,
struct ethtool_rx_flow_spec *fs)
{
t->ip_proto = IPPROTO_TCP;
if (qede_flow_spec_to_tuple_ipv4_common(edev, t, fs))
return -EINVAL;
return 0;
}
static int qede_flow_spec_to_tuple_udpv4(struct qede_dev *edev,
struct qede_arfs_tuple *t,
struct ethtool_rx_flow_spec *fs)
{
t->ip_proto = IPPROTO_UDP;
if (qede_flow_spec_to_tuple_ipv4_common(edev, t, fs))
return -EINVAL;
return 0;
}
static int qede_flow_spec_to_tuple_ipv6_common(struct qede_dev *edev,
struct qede_arfs_tuple *t,
struct ethtool_rx_flow_spec *fs)
{
struct in6_addr zero_addr;
void *p;
p = &zero_addr;
memset(p, 0, sizeof(zero_addr));
if ((fs->h_u.tcp_ip6_spec.psrc &
fs->m_u.tcp_ip6_spec.psrc) != fs->h_u.tcp_ip6_spec.psrc) {
DP_INFO(edev, "Don't support port-masks\n");
return -EOPNOTSUPP;
}
if ((fs->h_u.tcp_ip6_spec.pdst &
fs->m_u.tcp_ip6_spec.pdst) != fs->h_u.tcp_ip6_spec.pdst) {
DP_INFO(edev, "Don't support port-masks\n");
return -EOPNOTSUPP;
}
if (fs->h_u.tcp_ip6_spec.tclass) {
DP_INFO(edev, "Don't support tclass\n");
return -EOPNOTSUPP;
}
if (eth_proto == htons(ETH_P_IP)) {
src_port = fsp->h_u.tcp_ip4_spec.psrc;
dst_port = fsp->h_u.tcp_ip4_spec.pdst;
t->eth_proto = htons(ETH_P_IPV6);
memcpy(&t->src_ipv6, &fs->h_u.tcp_ip6_spec.ip6src,
sizeof(struct in6_addr));
memcpy(&t->dst_ipv6, &fs->h_u.tcp_ip6_spec.ip6dst,
sizeof(struct in6_addr));
t->src_port = fs->h_u.tcp_ip6_spec.psrc;
t->dst_port = fs->h_u.tcp_ip6_spec.pdst;
/* We must make sure we have a valid 4-tuple or only dest port
* or only src ip as an input
*/
if (t->src_port && t->dst_port &&
memcmp(&t->src_ipv6, p, sizeof(struct in6_addr)) &&
memcmp(&t->dst_ipv6, p, sizeof(struct in6_addr))) {
t->mode = QED_FILTER_CONFIG_MODE_5_TUPLE;
} else if (!t->src_port && t->dst_port &&
!memcmp(&t->src_ipv6, p, sizeof(struct in6_addr)) &&
!memcmp(&t->dst_ipv6, p, sizeof(struct in6_addr))) {
t->mode = QED_FILTER_CONFIG_MODE_L4_PORT;
} else if (!t->src_port && !t->dst_port &&
!memcmp(&t->dst_ipv6, p, sizeof(struct in6_addr)) &&
memcmp(&t->src_ipv6, p, sizeof(struct in6_addr))) {
t->mode = QED_FILTER_CONFIG_MODE_IP_SRC;
} else {
src_port = fsp->h_u.tcp_ip6_spec.psrc;
dst_port = fsp->h_u.tcp_ip6_spec.pdst;
DP_INFO(edev, "Invalid N-tuple\n");
return -EOPNOTSUPP;
}
head = QEDE_ARFS_BUCKET_HEAD(edev, 0);
hlist_for_each_entry_safe(fltr, temp, head, node) {
if ((fltr->tuple.ip_proto == ip_proto &&
fltr->tuple.eth_proto == eth_proto &&
qede_compare_user_flow_ips(fltr, fsp, eth_proto) &&
fltr->tuple.src_port == src_port &&
fltr->tuple.dst_port == dst_port) ||
fltr->sw_id == fsp->location)
return -EEXIST;
t->ip_comp = qede_flow_spec_ipv6_cmp;
t->build_hdr = qede_flow_build_ipv6_hdr;
return 0;
}
static int qede_flow_spec_to_tuple_tcpv6(struct qede_dev *edev,
struct qede_arfs_tuple *t,
struct ethtool_rx_flow_spec *fs)
{
t->ip_proto = IPPROTO_TCP;
if (qede_flow_spec_to_tuple_ipv6_common(edev, t, fs))
return -EINVAL;
return 0;
}
static int qede_flow_spec_to_tuple_udpv6(struct qede_dev *edev,
struct qede_arfs_tuple *t,
struct ethtool_rx_flow_spec *fs)
{
t->ip_proto = IPPROTO_UDP;
if (qede_flow_spec_to_tuple_ipv6_common(edev, t, fs))
return -EINVAL;
return 0;
}
static int qede_flow_spec_to_tuple(struct qede_dev *edev,
struct qede_arfs_tuple *t,
struct ethtool_rx_flow_spec *fs)
{
memset(t, 0, sizeof(*t));
if (qede_flow_spec_validate_unused(edev, fs))
return -EOPNOTSUPP;
switch ((fs->flow_type & ~FLOW_EXT)) {
case TCP_V4_FLOW:
return qede_flow_spec_to_tuple_tcpv4(edev, t, fs);
case UDP_V4_FLOW:
return qede_flow_spec_to_tuple_udpv4(edev, t, fs);
case TCP_V6_FLOW:
return qede_flow_spec_to_tuple_tcpv6(edev, t, fs);
case UDP_V6_FLOW:
return qede_flow_spec_to_tuple_udpv6(edev, t, fs);
default:
DP_VERBOSE(edev, NETIF_MSG_IFUP,
"Can't support flow of type %08x\n", fs->flow_type);
return -EOPNOTSUPP;
}
return 0;
}
static int
qede_poll_arfs_filter_config(struct qede_dev *edev,
struct qede_arfs_fltr_node *fltr)
static int qede_flow_spec_validate(struct qede_dev *edev,
struct ethtool_rx_flow_spec *fs,
struct qede_arfs_tuple *t)
{
int count = QEDE_ARFS_POLL_COUNT;
if (fs->location >= QEDE_RFS_MAX_FLTR) {
DP_INFO(edev, "Location out-of-bounds\n");
return -EINVAL;
}
while (fltr->used && count) {
msleep(20);
count--;
/* Check location isn't already in use */
if (test_bit(fs->location, edev->arfs->arfs_fltr_bmap)) {
DP_INFO(edev, "Location already in use\n");
return -EINVAL;
}
if (count == 0 || fltr->fw_rc) {
qede_dequeue_fltr_and_config_searcher(edev, fltr);
return -EIO;
/* Check if the filtering-mode could support the filter */
if (edev->arfs->filter_count &&
edev->arfs->mode != t->mode) {
DP_INFO(edev,
"flow_spec would require filtering mode %08x, but %08x is configured\n",
t->mode, edev->arfs->filter_count);
return -EINVAL;
}
return fltr->fw_rc;
/* If drop requested then no need to validate other data */
if (fs->ring_cookie == RX_CLS_FLOW_DISC)
return 0;
if (ethtool_get_flow_spec_ring_vf(fs->ring_cookie))
return 0;
if (fs->ring_cookie >= QEDE_RSS_COUNT(edev)) {
DP_INFO(edev, "Queue out-of-bounds\n");
return -EINVAL;
}
return 0;
}
/* Must be called while qede lock is held */
static struct qede_arfs_fltr_node *
qede_flow_find_fltr(struct qede_dev *edev, struct qede_arfs_tuple *t)
{
struct qede_arfs_fltr_node *fltr;
struct hlist_node *temp;
struct hlist_head *head;
head = QEDE_ARFS_BUCKET_HEAD(edev, 0);
hlist_for_each_entry_safe(fltr, temp, head, node) {
if (fltr->tuple.ip_proto == t->ip_proto &&
fltr->tuple.src_port == t->src_port &&
fltr->tuple.dst_port == t->dst_port &&
t->ip_comp(&fltr->tuple, t))
return fltr;
}
return NULL;
}
static void qede_flow_set_destination(struct qede_dev *edev,
struct qede_arfs_fltr_node *n,
struct ethtool_rx_flow_spec *fs)
{
if (fs->ring_cookie == RX_CLS_FLOW_DISC) {
n->b_is_drop = true;
return;
}
n->vfid = ethtool_get_flow_spec_ring_vf(fs->ring_cookie);
n->rxq_id = ethtool_get_flow_spec_ring(fs->ring_cookie);
n->next_rxq_id = n->rxq_id;
if (n->vfid)
DP_VERBOSE(edev, QED_MSG_SP,
"Configuring N-tuple for VF 0x%02x\n", n->vfid - 1);
}
int qede_add_cls_rule(struct qede_dev *edev, struct ethtool_rxnfc *info)
{
struct ethtool_rx_flow_spec *fsp = &info->fs;
struct qede_arfs_fltr_node *n;
int min_hlen = ETH_HLEN, rc;
struct ethhdr *eth;
struct iphdr *ip;
__be16 *ports;
struct qede_arfs_tuple t;
int min_hlen, rc;
__qede_lock(edev);
......@@ -1559,16 +1889,28 @@ int qede_add_cls_rule(struct qede_dev *edev, struct ethtool_rxnfc *info)
goto unlock;
}
rc = qede_validate_and_check_flow_exist(edev, fsp, &min_hlen);
/* Translate the flow specification into something fittign our DB */
rc = qede_flow_spec_to_tuple(edev, &t, fsp);
if (rc)
goto unlock;
/* Make sure location is valid and filter isn't already set */
rc = qede_flow_spec_validate(edev, fsp, &t);
if (rc)
goto unlock;
if (qede_flow_find_fltr(edev, &t)) {
rc = -EINVAL;
goto unlock;
}
n = kzalloc(sizeof(*n), GFP_KERNEL);
if (!n) {
rc = -ENOMEM;
goto unlock;
}
min_hlen = qede_flow_get_min_header_size(&t);
n->data = kzalloc(min_hlen, GFP_KERNEL);
if (!n->data) {
kfree(n);
......@@ -1579,68 +1921,13 @@ int qede_add_cls_rule(struct qede_dev *edev, struct ethtool_rxnfc *info)
n->sw_id = fsp->location;
set_bit(n->sw_id, edev->arfs->arfs_fltr_bmap);
n->buf_len = min_hlen;
n->rxq_id = fsp->ring_cookie;
n->next_rxq_id = n->rxq_id;
eth = (struct ethhdr *)n->data;
if (info->fs.flow_type == TCP_V4_FLOW ||
info->fs.flow_type == UDP_V4_FLOW) {
ports = (__be16 *)(n->data + ETH_HLEN +
sizeof(struct iphdr));
eth->h_proto = htons(ETH_P_IP);
n->tuple.eth_proto = htons(ETH_P_IP);
n->tuple.src_ipv4 = info->fs.h_u.tcp_ip4_spec.ip4src;
n->tuple.dst_ipv4 = info->fs.h_u.tcp_ip4_spec.ip4dst;
n->tuple.src_port = info->fs.h_u.tcp_ip4_spec.psrc;
n->tuple.dst_port = info->fs.h_u.tcp_ip4_spec.pdst;
ports[0] = n->tuple.src_port;
ports[1] = n->tuple.dst_port;
ip = (struct iphdr *)(n->data + ETH_HLEN);
ip->saddr = info->fs.h_u.tcp_ip4_spec.ip4src;
ip->daddr = info->fs.h_u.tcp_ip4_spec.ip4dst;
ip->version = 0x4;
ip->ihl = 0x5;
memcpy(&n->tuple, &t, sizeof(n->tuple));
if (info->fs.flow_type == TCP_V4_FLOW) {
n->tuple.ip_proto = IPPROTO_TCP;
ip->protocol = IPPROTO_TCP;
} else {
n->tuple.ip_proto = IPPROTO_UDP;
ip->protocol = IPPROTO_UDP;
}
ip->tot_len = cpu_to_be16(min_hlen - ETH_HLEN);
} else {
struct ipv6hdr *ip6;
ip6 = (struct ipv6hdr *)(n->data + ETH_HLEN);
ports = (__be16 *)(n->data + ETH_HLEN +
sizeof(struct ipv6hdr));
eth->h_proto = htons(ETH_P_IPV6);
n->tuple.eth_proto = htons(ETH_P_IPV6);
memcpy(&n->tuple.src_ipv6, &info->fs.h_u.tcp_ip6_spec.ip6src,
sizeof(struct in6_addr));
memcpy(&n->tuple.dst_ipv6, &info->fs.h_u.tcp_ip6_spec.ip6dst,
sizeof(struct in6_addr));
n->tuple.src_port = info->fs.h_u.tcp_ip6_spec.psrc;
n->tuple.dst_port = info->fs.h_u.tcp_ip6_spec.pdst;
ports[0] = n->tuple.src_port;
ports[1] = n->tuple.dst_port;
memcpy(&ip6->saddr, &n->tuple.src_ipv6,
sizeof(struct in6_addr));
memcpy(&ip6->daddr, &n->tuple.dst_ipv6,
sizeof(struct in6_addr));
ip6->version = 0x6;
qede_flow_set_destination(edev, n, fsp);
if (info->fs.flow_type == TCP_V6_FLOW) {
n->tuple.ip_proto = IPPROTO_TCP;
ip6->nexthdr = NEXTHDR_TCP;
ip6->payload_len = cpu_to_be16(sizeof(struct tcphdr));
} else {
n->tuple.ip_proto = IPPROTO_UDP;
ip6->nexthdr = NEXTHDR_UDP;
ip6->payload_len = cpu_to_be16(sizeof(struct udphdr));
}
}
/* Build a minimal header according to the flow */
n->tuple.build_hdr(&n->tuple, n->data);
rc = qede_enqueue_fltr_and_config_searcher(edev, n, 0);
if (rc)
......@@ -1650,6 +1937,7 @@ int qede_add_cls_rule(struct qede_dev *edev, struct ethtool_rxnfc *info)
rc = qede_poll_arfs_filter_config(edev, n);
unlock:
__qede_unlock(edev);
return rc;
}
......
......@@ -347,6 +347,7 @@ void qede_fill_by_demand_stats(struct qede_dev *edev)
p_common->rx_bcast_pkts = stats.common.rx_bcast_pkts;
p_common->mftag_filter_discards = stats.common.mftag_filter_discards;
p_common->mac_filter_discards = stats.common.mac_filter_discards;
p_common->gft_filter_drop = stats.common.gft_filter_drop;
p_common->tx_ucast_bytes = stats.common.tx_ucast_bytes;
p_common->tx_mcast_bytes = stats.common.tx_mcast_bytes;
......
......@@ -66,6 +66,7 @@ enum qed_filter_config_mode {
QED_FILTER_CONFIG_MODE_5_TUPLE,
QED_FILTER_CONFIG_MODE_L4_PORT,
QED_FILTER_CONFIG_MODE_IP_DEST,
QED_FILTER_CONFIG_MODE_IP_SRC,
};
struct qed_ntuple_filter_params {
......@@ -88,6 +89,9 @@ struct qed_ntuple_filter_params {
/* true iff this filter is to be added. Else to be removed */
bool b_is_add;
/* If flow needs to be dropped */
bool b_is_drop;
};
struct qed_dev_eth_info {
......
......@@ -1129,6 +1129,7 @@ struct qed_eth_stats_common {
u64 rx_bcast_pkts;
u64 mftag_filter_discards;
u64 mac_filter_discards;
u64 gft_filter_drop;
u64 tx_ucast_bytes;
u64 tx_mcast_bytes;
u64 tx_bcast_bytes;
......
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