Skip to content

Commit c8729ca

Browse files
vishalsdkdavem330
authored andcommitted
cxgb4: add ethtool n-tuple filter insertion
Add support to parse and insert ethtool n-tuple filters. Translate n-tuple spec to flow spec and use the existing tc-flower offload infra to insert ethtool n-tuple filters. Signed-off-by: Rahul Lakkireddy <[email protected]> Signed-off-by: Vishal Kulkarni <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d915c29 commit c8729ca

File tree

5 files changed

+135
-47
lines changed

5 files changed

+135
-47
lines changed

drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "t4fw_api.h"
1212
#include "cxgb4_cudbg.h"
1313
#include "cxgb4_filter.h"
14+
#include "cxgb4_tc_flower.h"
1415

1516
#define EEPROM_MAGIC 0x38E2F10C
1617

@@ -1635,6 +1636,79 @@ static int get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
16351636
return -EOPNOTSUPP;
16361637
}
16371638

1639+
/* Add Ethtool n-tuple filters. */
1640+
static int cxgb4_ntuple_set_filter(struct net_device *netdev,
1641+
struct ethtool_rxnfc *cmd)
1642+
{
1643+
struct ethtool_rx_flow_spec_input input = {};
1644+
struct cxgb4_ethtool_filter_info *filter_info;
1645+
struct adapter *adapter = netdev2adap(netdev);
1646+
struct port_info *pi = netdev_priv(netdev);
1647+
struct ch_filter_specification fs;
1648+
struct ethtool_rx_flow_rule *flow;
1649+
u32 tid;
1650+
int ret;
1651+
1652+
if (!(adapter->flags & CXGB4_FULL_INIT_DONE))
1653+
return -EAGAIN; /* can still change nfilters */
1654+
1655+
if (!adapter->ethtool_filters)
1656+
return -EOPNOTSUPP;
1657+
1658+
if (cmd->fs.location >= adapter->ethtool_filters->nentries) {
1659+
dev_err(adapter->pdev_dev,
1660+
"Location must be < %u",
1661+
adapter->ethtool_filters->nentries);
1662+
return -ERANGE;
1663+
}
1664+
1665+
if (test_bit(cmd->fs.location,
1666+
adapter->ethtool_filters->port[pi->port_id].bmap))
1667+
return -EEXIST;
1668+
1669+
memset(&fs, 0, sizeof(fs));
1670+
1671+
input.fs = &cmd->fs;
1672+
flow = ethtool_rx_flow_rule_create(&input);
1673+
if (IS_ERR(flow)) {
1674+
ret = PTR_ERR(flow);
1675+
goto exit;
1676+
}
1677+
1678+
fs.hitcnts = 1;
1679+
1680+
ret = cxgb4_flow_rule_replace(netdev, flow->rule, cmd->fs.location,
1681+
NULL, &fs, &tid);
1682+
if (ret)
1683+
goto free;
1684+
1685+
filter_info = &adapter->ethtool_filters->port[pi->port_id];
1686+
1687+
filter_info->loc_array[cmd->fs.location] = tid;
1688+
set_bit(cmd->fs.location, filter_info->bmap);
1689+
filter_info->in_use++;
1690+
1691+
free:
1692+
ethtool_rx_flow_rule_destroy(flow);
1693+
exit:
1694+
return ret;
1695+
}
1696+
1697+
static int set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
1698+
{
1699+
int ret = -EOPNOTSUPP;
1700+
1701+
switch (cmd->cmd) {
1702+
case ETHTOOL_SRXCLSRLINS:
1703+
ret = cxgb4_ntuple_set_filter(dev, cmd);
1704+
break;
1705+
default:
1706+
break;
1707+
}
1708+
1709+
return ret;
1710+
}
1711+
16381712
static int set_dump(struct net_device *dev, struct ethtool_dump *eth_dump)
16391713
{
16401714
struct adapter *adapter = netdev2adap(dev);
@@ -1840,6 +1914,7 @@ static const struct ethtool_ops cxgb_ethtool_ops = {
18401914
.get_regs_len = get_regs_len,
18411915
.get_regs = get_regs,
18421916
.get_rxnfc = get_rxnfc,
1917+
.set_rxnfc = set_rxnfc,
18431918
.get_rxfh_indir_size = get_rss_table_size,
18441919
.get_rxfh = get_rss_table,
18451920
.set_rxfh = set_rss_table,

drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,11 @@ bool is_filter_exact_match(struct adapter *adap,
11521152
if (!is_hashfilter(adap))
11531153
return false;
11541154

1155+
if ((atomic_read(&adap->tids.hash_tids_in_use) +
1156+
atomic_read(&adap->tids.tids_in_use)) >=
1157+
(adap->tids.nhash + (adap->tids.stid_base - adap->tids.tid_base)))
1158+
return false;
1159+
11551160
/* Keep tunnel VNI match disabled for hash-filters for now */
11561161
if (fs->mask.encap_vld)
11571162
return false;

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6371,7 +6371,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
63716371
NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
63726372
NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_GRO |
63736373
NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
6374-
NETIF_F_HW_TC;
6374+
NETIF_F_HW_TC | NETIF_F_NTUPLE;
63756375

63766376
if (chip_ver > CHELSIO_T5) {
63776377
netdev->hw_enc_features |= NETIF_F_IP_CSUM |

drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,9 @@ static struct ch_tc_flower_entry *ch_flower_lookup(struct adapter *adap,
8181
}
8282

8383
static void cxgb4_process_flow_match(struct net_device *dev,
84-
struct flow_cls_offload *cls,
84+
struct flow_rule *rule,
8585
struct ch_filter_specification *fs)
8686
{
87-
struct flow_rule *rule = flow_cls_offload_flow_rule(cls);
88-
u16 addr_type = 0;
89-
90-
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
91-
struct flow_match_control match;
92-
93-
flow_rule_match_control(rule, &match);
94-
addr_type = match.key->addr_type;
95-
}
96-
9787
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
9888
struct flow_match_basic match;
9989
u16 ethtype_key, ethtype_mask;
@@ -116,7 +106,7 @@ static void cxgb4_process_flow_match(struct net_device *dev,
116106
fs->mask.proto = match.mask->ip_proto;
117107
}
118108

119-
if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
109+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {
120110
struct flow_match_ipv4_addrs match;
121111

122112
flow_rule_match_ipv4_addrs(rule, &match);
@@ -131,7 +121,7 @@ static void cxgb4_process_flow_match(struct net_device *dev,
131121
memcpy(&fs->nat_fip[0], &match.key->src, sizeof(match.key->src));
132122
}
133123

134-
if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
124+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {
135125
struct flow_match_ipv6_addrs match;
136126

137127
flow_rule_match_ipv6_addrs(rule, &match);
@@ -224,9 +214,8 @@ static void cxgb4_process_flow_match(struct net_device *dev,
224214
}
225215

226216
static int cxgb4_validate_flow_match(struct net_device *dev,
227-
struct flow_cls_offload *cls)
217+
struct flow_rule *rule)
228218
{
229-
struct flow_rule *rule = flow_cls_offload_flow_rule(cls);
230219
struct flow_dissector *dissector = rule->match.dissector;
231220
u16 ethtype_mask = 0;
232221
u16 ethtype_key = 0;
@@ -693,33 +682,22 @@ static void cxgb4_tc_flower_hash_prio_del(struct adapter *adap, u32 tc_prio)
693682
spin_unlock_bh(&t->ftid_lock);
694683
}
695684

696-
int cxgb4_tc_flower_replace(struct net_device *dev,
697-
struct flow_cls_offload *cls)
685+
int cxgb4_flow_rule_replace(struct net_device *dev, struct flow_rule *rule,
686+
u32 tc_prio, struct netlink_ext_ack *extack,
687+
struct ch_filter_specification *fs, u32 *tid)
698688
{
699-
struct flow_rule *rule = flow_cls_offload_flow_rule(cls);
700-
struct netlink_ext_ack *extack = cls->common.extack;
701689
struct adapter *adap = netdev2adap(dev);
702-
struct ch_tc_flower_entry *ch_flower;
703-
struct ch_filter_specification *fs;
704690
struct filter_ctx ctx;
705691
u8 inet_family;
706692
int fidx, ret;
707693

708694
if (cxgb4_validate_flow_actions(dev, &rule->action, extack))
709695
return -EOPNOTSUPP;
710696

711-
if (cxgb4_validate_flow_match(dev, cls))
697+
if (cxgb4_validate_flow_match(dev, rule))
712698
return -EOPNOTSUPP;
713699

714-
ch_flower = allocate_flower_entry();
715-
if (!ch_flower) {
716-
netdev_err(dev, "%s: ch_flower alloc failed.\n", __func__);
717-
return -ENOMEM;
718-
}
719-
720-
fs = &ch_flower->fs;
721-
fs->hitcnts = 1;
722-
cxgb4_process_flow_match(dev, cls, fs);
700+
cxgb4_process_flow_match(dev, rule, fs);
723701
cxgb4_process_flow_actions(dev, &rule->action, fs);
724702

725703
fs->hash = is_filter_exact_match(adap, fs);
@@ -730,12 +708,11 @@ int cxgb4_tc_flower_replace(struct net_device *dev,
730708
* existing rules.
731709
*/
732710
fidx = cxgb4_get_free_ftid(dev, inet_family, fs->hash,
733-
cls->common.prio);
711+
tc_prio);
734712
if (fidx < 0) {
735713
NL_SET_ERR_MSG_MOD(extack,
736714
"No free LETCAM index available");
737-
ret = -ENOMEM;
738-
goto free_entry;
715+
return -ENOMEM;
739716
}
740717

741718
if (fidx < adap->tids.nhpftids) {
@@ -749,42 +726,70 @@ int cxgb4_tc_flower_replace(struct net_device *dev,
749726
if (fs->hash)
750727
fidx = 0;
751728

752-
fs->tc_prio = cls->common.prio;
753-
fs->tc_cookie = cls->cookie;
729+
fs->tc_prio = tc_prio;
754730

755731
init_completion(&ctx.completion);
756732
ret = __cxgb4_set_filter(dev, fidx, fs, &ctx);
757733
if (ret) {
758734
netdev_err(dev, "%s: filter creation err %d\n",
759735
__func__, ret);
760-
goto free_entry;
736+
return ret;
761737
}
762738

763739
/* Wait for reply */
764740
ret = wait_for_completion_timeout(&ctx.completion, 10 * HZ);
765-
if (!ret) {
766-
ret = -ETIMEDOUT;
767-
goto free_entry;
768-
}
741+
if (!ret)
742+
return -ETIMEDOUT;
769743

770-
ret = ctx.result;
771744
/* Check if hw returned error for filter creation */
745+
if (ctx.result)
746+
return ctx.result;
747+
748+
*tid = ctx.tid;
749+
750+
if (fs->hash)
751+
cxgb4_tc_flower_hash_prio_add(adap, tc_prio);
752+
753+
return 0;
754+
}
755+
756+
int cxgb4_tc_flower_replace(struct net_device *dev,
757+
struct flow_cls_offload *cls)
758+
{
759+
struct flow_rule *rule = flow_cls_offload_flow_rule(cls);
760+
struct netlink_ext_ack *extack = cls->common.extack;
761+
struct adapter *adap = netdev2adap(dev);
762+
struct ch_tc_flower_entry *ch_flower;
763+
struct ch_filter_specification *fs;
764+
int ret;
765+
766+
ch_flower = allocate_flower_entry();
767+
if (!ch_flower) {
768+
netdev_err(dev, "%s: ch_flower alloc failed.\n", __func__);
769+
return -ENOMEM;
770+
}
771+
772+
fs = &ch_flower->fs;
773+
fs->hitcnts = 1;
774+
fs->tc_cookie = cls->cookie;
775+
776+
ret = cxgb4_flow_rule_replace(dev, rule, cls->common.prio, extack, fs,
777+
&ch_flower->filter_id);
772778
if (ret)
773779
goto free_entry;
774780

775781
ch_flower->tc_flower_cookie = cls->cookie;
776-
ch_flower->filter_id = ctx.tid;
777782
ret = rhashtable_insert_fast(&adap->flower_tbl, &ch_flower->node,
778783
adap->flower_ht_params);
779784
if (ret)
780785
goto del_filter;
781786

782-
if (fs->hash)
783-
cxgb4_tc_flower_hash_prio_add(adap, cls->common.prio);
784-
785787
return 0;
786788

787789
del_filter:
790+
if (fs->hash)
791+
cxgb4_tc_flower_hash_prio_del(adap, cls->common.prio);
792+
788793
cxgb4_del_filter(dev, ch_flower->filter_id, &ch_flower->fs);
789794

790795
free_entry:

drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ int cxgb4_tc_flower_destroy(struct net_device *dev,
121121
struct flow_cls_offload *cls);
122122
int cxgb4_tc_flower_stats(struct net_device *dev,
123123
struct flow_cls_offload *cls);
124+
int cxgb4_flow_rule_replace(struct net_device *dev, struct flow_rule *rule,
125+
u32 tc_prio, struct netlink_ext_ack *extack,
126+
struct ch_filter_specification *fs, u32 *tid);
124127

125128
int cxgb4_init_tc_flower(struct adapter *adap);
126129
void cxgb4_cleanup_tc_flower(struct adapter *adap);

0 commit comments

Comments
 (0)