Skip to content

Commit 98f3697

Browse files
Kumar Sanghvidavem330
authored andcommitted
cxgb4: add tc flower match support for tunnel VNI
Adds support for matching flows based on tunnel VNI value. Introduces fw APIs for allocating/removing MPS entries related to encapsulation. And uses the same while adding/deleting filters for offloading flows based on tunnel VNI match. Signed-off-by: Kumar Sanghvi <kumaras@chelsio.com> Signed-off-by: Ganesh Goudar <ganeshgr@chelsio.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 96faf24 commit 98f3697

7 files changed

Lines changed: 237 additions & 7 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,7 @@ struct ch_sched_queue {
10381038
#define VF_BITWIDTH 8
10391039
#define IVLAN_BITWIDTH 16
10401040
#define OVLAN_BITWIDTH 16
1041+
#define ENCAP_VNI_BITWIDTH 24
10411042

10421043
/* Filter matching rules. These consist of a set of ingress packet field
10431044
* (value, mask) tuples. The associated ingress packet field matches the
@@ -1068,6 +1069,7 @@ struct ch_filter_tuple {
10681069
uint32_t ivlan_vld:1; /* inner VLAN valid */
10691070
uint32_t ovlan_vld:1; /* outer VLAN valid */
10701071
uint32_t pfvf_vld:1; /* PF/VF valid */
1072+
uint32_t encap_vld:1; /* Encapsulation valid */
10711073
uint32_t macidx:MACIDX_BITWIDTH; /* exact match MAC index */
10721074
uint32_t fcoe:FCOE_BITWIDTH; /* FCoE packet */
10731075
uint32_t iport:IPORT_BITWIDTH; /* ingress port */
@@ -1078,6 +1080,7 @@ struct ch_filter_tuple {
10781080
uint32_t vf:VF_BITWIDTH; /* PCI-E VF ID */
10791081
uint32_t ivlan:IVLAN_BITWIDTH; /* inner VLAN */
10801082
uint32_t ovlan:OVLAN_BITWIDTH; /* outer VLAN */
1083+
uint32_t vni:ENCAP_VNI_BITWIDTH; /* VNI of tunnel */
10811084

10821085
/* Uncompressed header matching field rules. These are always
10831086
* available for field rules.
@@ -1694,6 +1697,12 @@ int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
16941697
int t4_free_raw_mac_filt(struct adapter *adap, unsigned int viid,
16951698
const u8 *addr, const u8 *mask, unsigned int idx,
16961699
u8 lookup_type, u8 port_id, bool sleep_ok);
1700+
int t4_free_encap_mac_filt(struct adapter *adap, unsigned int viid, int idx,
1701+
bool sleep_ok);
1702+
int t4_alloc_encap_mac_filt(struct adapter *adap, unsigned int viid,
1703+
const u8 *addr, const u8 *mask, unsigned int vni,
1704+
unsigned int vni_mask, u8 dip_hit, u8 lookup_type,
1705+
bool sleep_ok);
16971706
int t4_alloc_raw_mac_filt(struct adapter *adap, unsigned int viid,
16981707
const u8 *addr, const u8 *mask, unsigned int idx,
16991708
u8 lookup_type, u8 port_id, bool sleep_ok);

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

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ static int validate_filter(struct net_device *dev,
265265
fs->mask.pfvf_vld) ||
266266
unsupported(fconf, VNIC_ID_F, fs->val.ovlan_vld,
267267
fs->mask.ovlan_vld) ||
268+
unsupported(fconf, VNIC_ID_F, fs->val.encap_vld,
269+
fs->mask.encap_vld) ||
268270
unsupported(fconf, VLAN_F, fs->val.ivlan_vld, fs->mask.ivlan_vld))
269271
return -EOPNOTSUPP;
270272

@@ -275,8 +277,12 @@ static int validate_filter(struct net_device *dev,
275277
* carries that overlap, we need to translate any PF/VF
276278
* specification into that internal format below.
277279
*/
278-
if (is_field_set(fs->val.pfvf_vld, fs->mask.pfvf_vld) &&
279-
is_field_set(fs->val.ovlan_vld, fs->mask.ovlan_vld))
280+
if ((is_field_set(fs->val.pfvf_vld, fs->mask.pfvf_vld) &&
281+
is_field_set(fs->val.ovlan_vld, fs->mask.ovlan_vld)) ||
282+
(is_field_set(fs->val.pfvf_vld, fs->mask.pfvf_vld) &&
283+
is_field_set(fs->val.encap_vld, fs->mask.encap_vld)) ||
284+
(is_field_set(fs->val.ovlan_vld, fs->mask.ovlan_vld) &&
285+
is_field_set(fs->val.encap_vld, fs->mask.encap_vld)))
280286
return -EOPNOTSUPP;
281287
if (unsupported(iconf, VNIC_F, fs->val.pfvf_vld, fs->mask.pfvf_vld) ||
282288
(is_field_set(fs->val.ovlan_vld, fs->mask.ovlan_vld) &&
@@ -306,6 +312,9 @@ static int validate_filter(struct net_device *dev,
306312
fs->newvlan == VLAN_REWRITE))
307313
return -EOPNOTSUPP;
308314

315+
if (fs->val.encap_vld &&
316+
CHELSIO_CHIP_VERSION(adapter->params.chip) < CHELSIO_T6)
317+
return -EOPNOTSUPP;
309318
return 0;
310319
}
311320

@@ -705,6 +714,8 @@ int delete_filter(struct adapter *adapter, unsigned int fidx)
705714
*/
706715
void clear_filter(struct adapter *adap, struct filter_entry *f)
707716
{
717+
struct port_info *pi = netdev_priv(f->dev);
718+
708719
/* If the new or old filter have loopback rewriteing rules then we'll
709720
* need to free any existing L2T, SMT, CLIP entries of filter
710721
* rule.
@@ -715,6 +726,12 @@ void clear_filter(struct adapter *adap, struct filter_entry *f)
715726
if (f->smt)
716727
cxgb4_smt_release(f->smt);
717728

729+
if (f->fs.val.encap_vld && f->fs.val.ovlan_vld)
730+
if (atomic_dec_and_test(&adap->mps_encap[f->fs.val.ovlan &
731+
0x1ff].refcnt))
732+
t4_free_encap_mac_filt(adap, pi->viid,
733+
f->fs.val.ovlan & 0x1ff, 0);
734+
718735
if ((f->fs.hash || is_t6(adap->params.chip)) && f->fs.type)
719736
cxgb4_clip_release(f->dev, (const u32 *)&f->fs.val.lip, 1);
720737

@@ -840,6 +857,10 @@ bool is_filter_exact_match(struct adapter *adap,
840857
if (!is_hashfilter(adap))
841858
return false;
842859

860+
/* Keep tunnel VNI match disabled for hash-filters for now */
861+
if (fs->mask.encap_vld)
862+
return false;
863+
843864
if (fs->type) {
844865
if (is_inaddr_any(fs->val.fip, AF_INET6) ||
845866
!is_addr_all_mask(fs->mask.fip, AF_INET6))
@@ -961,8 +982,12 @@ static u64 hash_filter_ntuple(struct ch_filter_specification *fs,
961982
ntuple |= (u64)(fs->val.tos) << tp->tos_shift;
962983

963984
if (tp->vnic_shift >= 0) {
964-
if ((adap->params.tp.ingress_config & VNIC_F) &&
965-
fs->mask.pfvf_vld)
985+
if ((adap->params.tp.ingress_config & USE_ENC_IDX_F) &&
986+
fs->mask.encap_vld)
987+
ntuple |= (u64)((fs->val.encap_vld << 16) |
988+
(fs->val.ovlan)) << tp->vnic_shift;
989+
else if ((adap->params.tp.ingress_config & VNIC_F) &&
990+
fs->mask.pfvf_vld)
966991
ntuple |= (u64)((fs->val.pfvf_vld << 16) |
967992
(fs->val.pf << 13) |
968993
(fs->val.vf)) << tp->vnic_shift;
@@ -1076,6 +1101,7 @@ static int cxgb4_set_hash_filter(struct net_device *dev,
10761101
struct filter_ctx *ctx)
10771102
{
10781103
struct adapter *adapter = netdev2adap(dev);
1104+
struct port_info *pi = netdev_priv(dev);
10791105
struct tid_info *t = &adapter->tids;
10801106
struct filter_entry *f;
10811107
struct sk_buff *skb;
@@ -1142,13 +1168,34 @@ static int cxgb4_set_hash_filter(struct net_device *dev,
11421168
f->fs.mask.ovlan = (fs->mask.pf << 13) | fs->mask.vf;
11431169
f->fs.val.ovlan_vld = fs->val.pfvf_vld;
11441170
f->fs.mask.ovlan_vld = fs->mask.pfvf_vld;
1171+
} else if (iconf & USE_ENC_IDX_F) {
1172+
if (f->fs.val.encap_vld) {
1173+
struct port_info *pi = netdev_priv(f->dev);
1174+
u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
1175+
1176+
/* allocate MPS TCAM entry */
1177+
ret = t4_alloc_encap_mac_filt(adapter, pi->viid,
1178+
match_all_mac,
1179+
match_all_mac,
1180+
f->fs.val.vni,
1181+
f->fs.mask.vni,
1182+
0, 1, 1);
1183+
if (ret < 0)
1184+
goto free_atid;
1185+
1186+
atomic_inc(&adapter->mps_encap[ret].refcnt);
1187+
f->fs.val.ovlan = ret;
1188+
f->fs.mask.ovlan = 0xffff;
1189+
f->fs.val.ovlan_vld = 1;
1190+
f->fs.mask.ovlan_vld = 1;
1191+
}
11451192
}
11461193

11471194
size = sizeof(struct cpl_t6_act_open_req);
11481195
if (f->fs.type) {
11491196
ret = cxgb4_clip_get(f->dev, (const u32 *)&f->fs.val.lip, 1);
11501197
if (ret)
1151-
goto free_atid;
1198+
goto free_mps;
11521199

11531200
skb = alloc_skb(size, GFP_KERNEL);
11541201
if (!skb) {
@@ -1163,7 +1210,7 @@ static int cxgb4_set_hash_filter(struct net_device *dev,
11631210
skb = alloc_skb(size, GFP_KERNEL);
11641211
if (!skb) {
11651212
ret = -ENOMEM;
1166-
goto free_atid;
1213+
goto free_mps;
11671214
}
11681215

11691216
mk_act_open_req(f, skb,
@@ -1179,6 +1226,10 @@ static int cxgb4_set_hash_filter(struct net_device *dev,
11791226
free_clip:
11801227
cxgb4_clip_release(f->dev, (const u32 *)&f->fs.val.lip, 1);
11811228

1229+
free_mps:
1230+
if (f->fs.val.encap_vld && f->fs.val.ovlan_vld)
1231+
t4_free_encap_mac_filt(adapter, pi->viid, f->fs.val.ovlan, 1);
1232+
11821233
free_atid:
11831234
cxgb4_free_atid(t, atid);
11841235

@@ -1360,6 +1411,27 @@ int __cxgb4_set_filter(struct net_device *dev, int filter_id,
13601411
f->fs.mask.ovlan = (fs->mask.pf << 13) | fs->mask.vf;
13611412
f->fs.val.ovlan_vld = fs->val.pfvf_vld;
13621413
f->fs.mask.ovlan_vld = fs->mask.pfvf_vld;
1414+
} else if (iconf & USE_ENC_IDX_F) {
1415+
if (f->fs.val.encap_vld) {
1416+
struct port_info *pi = netdev_priv(f->dev);
1417+
u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
1418+
1419+
/* allocate MPS TCAM entry */
1420+
ret = t4_alloc_encap_mac_filt(adapter, pi->viid,
1421+
match_all_mac,
1422+
match_all_mac,
1423+
f->fs.val.vni,
1424+
f->fs.mask.vni,
1425+
0, 1, 1);
1426+
if (ret < 0)
1427+
goto free_clip;
1428+
1429+
atomic_inc(&adapter->mps_encap[ret].refcnt);
1430+
f->fs.val.ovlan = ret;
1431+
f->fs.mask.ovlan = 0x1ff;
1432+
f->fs.val.ovlan_vld = 1;
1433+
f->fs.mask.ovlan_vld = 1;
1434+
}
13631435
}
13641436

13651437
/* Attempt to set the filter. If we don't succeed, we clear
@@ -1376,6 +1448,13 @@ int __cxgb4_set_filter(struct net_device *dev, int filter_id,
13761448
}
13771449

13781450
return ret;
1451+
1452+
free_clip:
1453+
if (is_t6(adapter->params.chip) && f->fs.type)
1454+
cxgb4_clip_release(f->dev, (const u32 *)&f->fs.val.lip, 1);
1455+
cxgb4_clear_ftid(&adapter->tids, filter_id,
1456+
fs->type ? PF_INET6 : PF_INET, chip_ver);
1457+
return ret;
13791458
}
13801459

13811460
static int cxgb4_del_hash_filter(struct net_device *dev, int filter_id,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,23 @@ static void cxgb4_process_flow_match(struct net_device *dev,
194194
fs->mask.tos = mask->tos;
195195
}
196196

197+
if (dissector_uses_key(cls->dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
198+
struct flow_dissector_key_keyid *key, *mask;
199+
200+
key = skb_flow_dissector_target(cls->dissector,
201+
FLOW_DISSECTOR_KEY_ENC_KEYID,
202+
cls->key);
203+
mask = skb_flow_dissector_target(cls->dissector,
204+
FLOW_DISSECTOR_KEY_ENC_KEYID,
205+
cls->mask);
206+
fs->val.vni = be32_to_cpu(key->keyid);
207+
fs->mask.vni = be32_to_cpu(mask->keyid);
208+
if (fs->mask.vni) {
209+
fs->val.encap_vld = 1;
210+
fs->mask.encap_vld = 1;
211+
}
212+
}
213+
197214
if (dissector_uses_key(cls->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
198215
struct flow_dissector_key_vlan *key, *mask;
199216
u16 vlan_tci, vlan_tci_mask;
@@ -247,6 +264,7 @@ static int cxgb4_validate_flow_match(struct net_device *dev,
247264
BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
248265
BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
249266
BIT(FLOW_DISSECTOR_KEY_PORTS) |
267+
BIT(FLOW_DISSECTOR_KEY_ENC_KEYID) |
250268
BIT(FLOW_DISSECTOR_KEY_VLAN) |
251269
BIT(FLOW_DISSECTOR_KEY_IP))) {
252270
netdev_warn(dev, "Unsupported key used: 0x%x\n",

‎drivers/net/ethernet/chelsio/cxgb4/l2t.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ u64 cxgb4_select_ntuple(struct net_device *dev,
491491
if (tp->protocol_shift >= 0)
492492
ntuple |= (u64)IPPROTO_TCP << tp->protocol_shift;
493493

494-
if (tp->vnic_shift >= 0) {
494+
if (tp->vnic_shift >= 0 && (tp->ingress_config & VNIC_F)) {
495495
u32 viid = cxgb4_port_viid(dev);
496496
u32 vf = FW_VIID_VIN_G(viid);
497497
u32 pf = FW_VIID_PFN_G(viid);

‎drivers/net/ethernet/chelsio/cxgb4/t4_hw.c‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7512,6 +7512,43 @@ int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
75127512
return t4_wr_mbox_meat(adap, mbox, &c, sizeof(c), NULL, sleep_ok);
75137513
}
75147514

7515+
/**
7516+
* t4_free_encap_mac_filt - frees MPS entry at given index
7517+
* @adap: the adapter
7518+
* @viid: the VI id
7519+
* @idx: index of MPS entry to be freed
7520+
* @sleep_ok: call is allowed to sleep
7521+
*
7522+
* Frees the MPS entry at supplied index
7523+
*
7524+
* Returns a negative error number or zero on success
7525+
*/
7526+
int t4_free_encap_mac_filt(struct adapter *adap, unsigned int viid,
7527+
int idx, bool sleep_ok)
7528+
{
7529+
struct fw_vi_mac_exact *p;
7530+
u8 addr[] = {0, 0, 0, 0, 0, 0};
7531+
struct fw_vi_mac_cmd c;
7532+
int ret = 0;
7533+
u32 exact;
7534+
7535+
memset(&c, 0, sizeof(c));
7536+
c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
7537+
FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
7538+
FW_CMD_EXEC_V(0) |
7539+
FW_VI_MAC_CMD_VIID_V(viid));
7540+
exact = FW_VI_MAC_CMD_ENTRY_TYPE_V(FW_VI_MAC_TYPE_EXACTMAC);
7541+
c.freemacs_to_len16 = cpu_to_be32(FW_VI_MAC_CMD_FREEMACS_V(0) |
7542+
exact |
7543+
FW_CMD_LEN16_V(1));
7544+
p = c.u.exact;
7545+
p->valid_to_idx = cpu_to_be16(FW_VI_MAC_CMD_VALID_F |
7546+
FW_VI_MAC_CMD_IDX_V(idx));
7547+
memcpy(p->macaddr, addr, sizeof(p->macaddr));
7548+
ret = t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
7549+
return ret;
7550+
}
7551+
75157552
/**
75167553
* t4_free_raw_mac_filt - Frees a raw mac entry in mps tcam
75177554
* @adap: the adapter
@@ -7562,6 +7599,55 @@ int t4_free_raw_mac_filt(struct adapter *adap, unsigned int viid,
75627599
return t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
75637600
}
75647601

7602+
/**
7603+
* t4_alloc_encap_mac_filt - Adds a mac entry in mps tcam with VNI support
7604+
* @adap: the adapter
7605+
* @viid: the VI id
7606+
* @mac: the MAC address
7607+
* @mask: the mask
7608+
* @vni: the VNI id for the tunnel protocol
7609+
* @vni_mask: mask for the VNI id
7610+
* @dip_hit: to enable DIP match for the MPS entry
7611+
* @lookup_type: MAC address for inner (1) or outer (0) header
7612+
* @sleep_ok: call is allowed to sleep
7613+
*
7614+
* Allocates an MPS entry with specified MAC address and VNI value.
7615+
*
7616+
* Returns a negative error number or the allocated index for this mac.
7617+
*/
7618+
int t4_alloc_encap_mac_filt(struct adapter *adap, unsigned int viid,
7619+
const u8 *addr, const u8 *mask, unsigned int vni,
7620+
unsigned int vni_mask, u8 dip_hit, u8 lookup_type,
7621+
bool sleep_ok)
7622+
{
7623+
struct fw_vi_mac_cmd c;
7624+
struct fw_vi_mac_vni *p = c.u.exact_vni;
7625+
int ret = 0;
7626+
u32 val;
7627+
7628+
memset(&c, 0, sizeof(c));
7629+
c.op_to_viid = cpu_to_be32(FW_CMD_OP_V(FW_VI_MAC_CMD) |
7630+
FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
7631+
FW_VI_MAC_CMD_VIID_V(viid));
7632+
val = FW_CMD_LEN16_V(1) |
7633+
FW_VI_MAC_CMD_ENTRY_TYPE_V(FW_VI_MAC_TYPE_EXACTMAC_VNI);
7634+
c.freemacs_to_len16 = cpu_to_be32(val);
7635+
p->valid_to_idx = cpu_to_be16(FW_VI_MAC_CMD_VALID_F |
7636+
FW_VI_MAC_CMD_IDX_V(FW_VI_MAC_ADD_MAC));
7637+
memcpy(p->macaddr, addr, sizeof(p->macaddr));
7638+
memcpy(p->macaddr_mask, mask, sizeof(p->macaddr_mask));
7639+
7640+
p->lookup_type_to_vni =
7641+
cpu_to_be32(FW_VI_MAC_CMD_VNI_V(vni) |
7642+
FW_VI_MAC_CMD_DIP_HIT_V(dip_hit) |
7643+
FW_VI_MAC_CMD_LOOKUP_TYPE_V(lookup_type));
7644+
p->vni_mask_pkd = cpu_to_be32(FW_VI_MAC_CMD_VNI_MASK_V(vni_mask));
7645+
ret = t4_wr_mbox_meat(adap, adap->mbox, &c, sizeof(c), &c, sleep_ok);
7646+
if (ret == 0)
7647+
ret = FW_VI_MAC_CMD_IDX_G(be16_to_cpu(p->valid_to_idx));
7648+
return ret;
7649+
}
7650+
75657651
/**
75667652
* t4_alloc_raw_mac_filt - Adds a mac entry in mps tcam
75677653
* @adap: the adapter

‎drivers/net/ethernet/chelsio/cxgb4/t4_regs.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,10 @@
15981598
#define VNIC_V(x) ((x) << VNIC_S)
15991599
#define VNIC_F VNIC_V(1U)
16001600

1601+
#define USE_ENC_IDX_S 13
1602+
#define USE_ENC_IDX_V(x) ((x) << USE_ENC_IDX_S)
1603+
#define USE_ENC_IDX_F USE_ENC_IDX_V(1U)
1604+
16011605
#define CSUM_HAS_PSEUDO_HDR_S 10
16021606
#define CSUM_HAS_PSEUDO_HDR_V(x) ((x) << CSUM_HAS_PSEUDO_HDR_S)
16031607
#define CSUM_HAS_PSEUDO_HDR_F CSUM_HAS_PSEUDO_HDR_V(1U)

0 commit comments

Comments
 (0)