Skip to content

Commit 86cea61

Browse files
Tomasz Duszynskidavem330
authored andcommitted
octeontx2-af: Add support for stripping STAG/CTAG
This works by shadowing existing UCAST MCAM entry with a new one additionally matching either NPC_LT_LB_CTAG or NPC_LT_LB_STAG. For this to fully work one needs to send properly configured NIX_VTAG_CFG message afterwards i.e with strip and capture enabled and type set to 0. On receiving tagged packet NIX will remove outer VLAN and capture TCI in NIX_RX_PARSE_S. Also simplified RX Vtag configuration flow With this setting STRIP/CAPTURE VTAG actions separately would be possible. Following combinations are possible: STRIP, STRIP and CAPTURE, CAPTURE or nothing (0 disables respective actions). Signed-off-by: Tomasz Duszynski <[email protected]> Signed-off-by: Sunil Goutham <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 40df309 commit 86cea61

File tree

5 files changed

+125
-21
lines changed

5 files changed

+125
-21
lines changed

drivers/net/ethernet/marvell/octeontx2/af/mbox.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ M(NIX_SET_MAC_ADDR, 0x800a, nix_set_mac_addr, nix_set_mac_addr, msg_rsp) \
197197
M(NIX_SET_RX_MODE, 0x800b, nix_set_rx_mode, nix_rx_mode, msg_rsp) \
198198
M(NIX_SET_HW_FRS, 0x800c, nix_set_hw_frs, nix_frs_cfg, msg_rsp) \
199199
M(NIX_LF_START_RX, 0x800d, nix_lf_start_rx, msg_req, msg_rsp) \
200-
M(NIX_LF_STOP_RX, 0x800e, nix_lf_stop_rx, msg_req, msg_rsp)
200+
M(NIX_LF_STOP_RX, 0x800e, nix_lf_stop_rx, msg_req, msg_rsp) \
201+
M(NIX_RXVLAN_ALLOC, 0x8012, nix_rxvlan_alloc, msg_req, msg_rsp)
201202

202203
/* Messages initiated by AF (range 0xC00 - 0xDFF) */
203204
#define MBOX_UP_CGX_MESSAGES \
@@ -515,6 +516,7 @@ struct nix_txschq_config {
515516

516517
struct nix_vtag_config {
517518
struct mbox_msghdr hdr;
519+
/* '0' for 4 octet VTAG, '1' for 8 octet VTAG */
518520
u8 vtag_size;
519521
/* cfg_type is '0' for tx vlan cfg
520522
* cfg_type is '1' for rx vlan cfg
@@ -535,7 +537,7 @@ struct nix_vtag_config {
535537

536538
/* valid when cfg_type is '1' */
537539
struct {
538-
/* rx vtag type index */
540+
/* rx vtag type index, valid values are in 0..7 range */
539541
u8 vtag_type;
540542
/* rx vtag strip */
541543
u8 strip_vtag :1;

drivers/net/ethernet/marvell/octeontx2/af/npc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,10 @@ struct nix_rx_action {
259259
#endif
260260
};
261261

262+
/* NIX Receive Vtag Action Structure */
263+
#define VTAG0_VALID_BIT BIT_ULL(15)
264+
#define VTAG0_TYPE_MASK GENMASK_ULL(14, 12)
265+
#define VTAG0_LID_MASK GENMASK_ULL(10, 8)
266+
#define VTAG0_RELPTR_MASK GENMASK_ULL(7, 0)
267+
262268
#endif /* NPC_H */

drivers/net/ethernet/marvell/octeontx2/af/rvu.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ struct rvu_pfvf {
142142
/* Broadcast pkt replication info */
143143
u16 bcast_mce_idx;
144144
struct nix_mce_list bcast_mce_list;
145+
146+
/* VLAN offload */
147+
struct mcam_entry entry;
148+
int rxvlan_index;
149+
bool rxvlan;
145150
};
146151

147152
struct nix_txsch {
@@ -356,6 +361,8 @@ int rvu_mbox_handler_nix_stats_rst(struct rvu *rvu, struct msg_req *req,
356361
int rvu_mbox_handler_nix_vtag_cfg(struct rvu *rvu,
357362
struct nix_vtag_config *req,
358363
struct msg_rsp *rsp);
364+
int rvu_mbox_handler_nix_rxvlan_alloc(struct rvu *rvu, struct msg_req *req,
365+
struct msg_rsp *rsp);
359366
int rvu_mbox_handler_nix_rss_flowkey_cfg(struct rvu *rvu,
360367
struct nix_rss_flowkey_cfg *req,
361368
struct msg_rsp *rsp);
@@ -384,6 +391,7 @@ void rvu_npc_disable_promisc_entry(struct rvu *rvu, u16 pcifunc, int nixlf);
384391
void rvu_npc_enable_promisc_entry(struct rvu *rvu, u16 pcifunc, int nixlf);
385392
void rvu_npc_install_bcast_match_entry(struct rvu *rvu, u16 pcifunc,
386393
int nixlf, u64 chan);
394+
int rvu_npc_update_rxvlan(struct rvu *rvu, u16 pcifunc, int nixlf);
387395
void rvu_npc_disable_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
388396
void rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
389397
void rvu_npc_enable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);

drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ static void nix_interface_deinit(struct rvu *rvu, u16 pcifunc, u8 nixlf)
192192

193193
pfvf->maxlen = 0;
194194
pfvf->minlen = 0;
195+
pfvf->rxvlan = false;
195196

196197
/* Remove this PF_FUNC from bcast pkt replication list */
197198
err = nix_update_bcast_mce_list(rvu, pcifunc, false);
@@ -1209,28 +1210,15 @@ int rvu_mbox_handler_nix_txschq_cfg(struct rvu *rvu,
12091210
static int nix_rx_vtag_cfg(struct rvu *rvu, int nixlf, int blkaddr,
12101211
struct nix_vtag_config *req)
12111212
{
1212-
u64 regval = 0;
1213+
u64 regval = req->vtag_size;
12131214

1214-
#define NIX_VTAGTYPE_MAX 0x8ull
1215-
#define NIX_VTAGSIZE_MASK 0x7ull
1216-
#define NIX_VTAGSTRIP_CAP_MASK 0x30ull
1217-
1218-
if (req->rx.vtag_type >= NIX_VTAGTYPE_MAX ||
1219-
req->vtag_size > VTAGSIZE_T8)
1215+
if (req->rx.vtag_type > 7 || req->vtag_size > VTAGSIZE_T8)
12201216
return -EINVAL;
12211217

1222-
regval = rvu_read64(rvu, blkaddr,
1223-
NIX_AF_LFX_RX_VTAG_TYPEX(nixlf, req->rx.vtag_type));
1224-
1225-
if (req->rx.strip_vtag && req->rx.capture_vtag)
1226-
regval |= BIT_ULL(4) | BIT_ULL(5);
1227-
else if (req->rx.strip_vtag)
1218+
if (req->rx.capture_vtag)
1219+
regval |= BIT_ULL(5);
1220+
if (req->rx.strip_vtag)
12281221
regval |= BIT_ULL(4);
1229-
else
1230-
regval &= ~(BIT_ULL(4) | BIT_ULL(5));
1231-
1232-
regval &= ~NIX_VTAGSIZE_MASK;
1233-
regval |= req->vtag_size & NIX_VTAGSIZE_MASK;
12341222

12351223
rvu_write64(rvu, blkaddr,
12361224
NIX_AF_LFX_RX_VTAG_TYPEX(nixlf, req->rx.vtag_type), regval);
@@ -1770,6 +1758,9 @@ int rvu_mbox_handler_nix_set_mac_addr(struct rvu *rvu,
17701758

17711759
rvu_npc_install_ucast_entry(rvu, pcifunc, nixlf,
17721760
pfvf->rx_chan_base, req->mac_addr);
1761+
1762+
rvu_npc_update_rxvlan(rvu, pcifunc, nixlf);
1763+
17731764
return 0;
17741765
}
17751766

@@ -1803,6 +1794,9 @@ int rvu_mbox_handler_nix_set_rx_mode(struct rvu *rvu, struct nix_rx_mode *req,
18031794
else
18041795
rvu_npc_install_promisc_entry(rvu, pcifunc, nixlf,
18051796
pfvf->rx_chan_base, allmulti);
1797+
1798+
rvu_npc_update_rxvlan(rvu, pcifunc, nixlf);
1799+
18061800
return 0;
18071801
}
18081802

@@ -1941,6 +1935,59 @@ int rvu_mbox_handler_nix_set_hw_frs(struct rvu *rvu, struct nix_frs_cfg *req,
19411935
return 0;
19421936
}
19431937

1938+
int rvu_mbox_handler_nix_rxvlan_alloc(struct rvu *rvu, struct msg_req *req,
1939+
struct msg_rsp *rsp)
1940+
{
1941+
struct npc_mcam_alloc_entry_req alloc_req = { };
1942+
struct npc_mcam_alloc_entry_rsp alloc_rsp = { };
1943+
struct npc_mcam_free_entry_req free_req = { };
1944+
u16 pcifunc = req->hdr.pcifunc;
1945+
int blkaddr, nixlf, err;
1946+
struct rvu_pfvf *pfvf;
1947+
1948+
pfvf = rvu_get_pfvf(rvu, pcifunc);
1949+
if (pfvf->rxvlan)
1950+
return 0;
1951+
1952+
/* alloc new mcam entry */
1953+
alloc_req.hdr.pcifunc = pcifunc;
1954+
alloc_req.count = 1;
1955+
1956+
err = rvu_mbox_handler_npc_mcam_alloc_entry(rvu, &alloc_req,
1957+
&alloc_rsp);
1958+
if (err)
1959+
return err;
1960+
1961+
/* update entry to enable rxvlan offload */
1962+
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NIX, pcifunc);
1963+
if (blkaddr < 0) {
1964+
err = NIX_AF_ERR_AF_LF_INVALID;
1965+
goto free_entry;
1966+
}
1967+
1968+
nixlf = rvu_get_lf(rvu, &rvu->hw->block[blkaddr], pcifunc, 0);
1969+
if (nixlf < 0) {
1970+
err = NIX_AF_ERR_AF_LF_INVALID;
1971+
goto free_entry;
1972+
}
1973+
1974+
pfvf->rxvlan_index = alloc_rsp.entry_list[0];
1975+
/* all it means is that rxvlan_index is valid */
1976+
pfvf->rxvlan = true;
1977+
1978+
err = rvu_npc_update_rxvlan(rvu, pcifunc, nixlf);
1979+
if (err)
1980+
goto free_entry;
1981+
1982+
return 0;
1983+
free_entry:
1984+
free_req.hdr.pcifunc = pcifunc;
1985+
free_req.entry = alloc_rsp.entry_list[0];
1986+
rvu_mbox_handler_npc_mcam_free_entry(rvu, &free_req, rsp);
1987+
pfvf->rxvlan = false;
1988+
return err;
1989+
}
1990+
19441991
static void nix_link_config(struct rvu *rvu, int blkaddr)
19451992
{
19461993
struct rvu_hwinfo *hw = rvu->hw;

drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* published by the Free Software Foundation.
99
*/
1010

11+
#include <linux/bitfield.h>
1112
#include <linux/module.h>
1213
#include <linux/pci.h>
1314

@@ -306,6 +307,7 @@ static u64 npc_get_mcam_action(struct rvu *rvu, struct npc_mcam *mcam,
306307
void rvu_npc_install_ucast_entry(struct rvu *rvu, u16 pcifunc,
307308
int nixlf, u64 chan, u8 *mac_addr)
308309
{
310+
struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
309311
struct npc_mcam *mcam = &rvu->hw->mcam;
310312
struct mcam_entry entry = { {0} };
311313
struct nix_rx_action action;
@@ -345,14 +347,25 @@ void rvu_npc_install_ucast_entry(struct rvu *rvu, u16 pcifunc,
345347
entry.action = *(u64 *)&action;
346348
npc_config_mcam_entry(rvu, mcam, blkaddr, index,
347349
NIX_INTF_RX, &entry, true);
350+
351+
/* add VLAN matching, setup action and save entry back for later */
352+
entry.kw[0] |= (NPC_LT_LB_STAG | NPC_LT_LB_CTAG) << 20;
353+
entry.kw_mask[0] |= (NPC_LT_LB_STAG & NPC_LT_LB_CTAG) << 20;
354+
355+
entry.vtag_action = VTAG0_VALID_BIT |
356+
FIELD_PREP(VTAG0_TYPE_MASK, 0) |
357+
FIELD_PREP(VTAG0_LID_MASK, NPC_LID_LA) |
358+
FIELD_PREP(VTAG0_RELPTR_MASK, 12);
359+
360+
memcpy(&pfvf->entry, &entry, sizeof(entry));
348361
}
349362

350363
void rvu_npc_install_promisc_entry(struct rvu *rvu, u16 pcifunc,
351364
int nixlf, u64 chan, bool allmulti)
352365
{
353366
struct npc_mcam *mcam = &rvu->hw->mcam;
354367
struct mcam_entry entry = { {0} };
355-
struct nix_rx_action action;
368+
struct nix_rx_action action = { };
356369
int blkaddr, index, kwi;
357370

358371
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
@@ -521,6 +534,8 @@ void rvu_npc_update_flowkey_alg_idx(struct rvu *rvu, u16 pcifunc, int nixlf,
521534

522535
rvu_write64(rvu, blkaddr,
523536
NPC_AF_MCAMEX_BANKX_ACTION(index, bank), *(u64 *)&action);
537+
538+
rvu_npc_update_rxvlan(rvu, pcifunc, nixlf);
524539
}
525540

526541
static void npc_enadis_default_entries(struct rvu *rvu, u16 pcifunc,
@@ -560,6 +575,8 @@ static void npc_enadis_default_entries(struct rvu *rvu, u16 pcifunc,
560575
rvu_npc_enable_promisc_entry(rvu, pcifunc, nixlf);
561576
else
562577
rvu_npc_disable_promisc_entry(rvu, pcifunc, nixlf);
578+
579+
rvu_npc_update_rxvlan(rvu, pcifunc, nixlf);
563580
}
564581

565582
void rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
@@ -2018,3 +2035,27 @@ int rvu_mbox_handler_npc_get_kex_cfg(struct rvu *rvu, struct msg_req *req,
20182035
}
20192036
return 0;
20202037
}
2038+
2039+
int rvu_npc_update_rxvlan(struct rvu *rvu, u16 pcifunc, int nixlf)
2040+
{
2041+
struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
2042+
struct npc_mcam *mcam = &rvu->hw->mcam;
2043+
int blkaddr, index;
2044+
bool enable;
2045+
2046+
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
2047+
if (blkaddr < 0)
2048+
return NIX_AF_ERR_AF_LF_INVALID;
2049+
2050+
if (!pfvf->rxvlan)
2051+
return 0;
2052+
2053+
index = npc_get_nixlf_mcam_index(mcam, pcifunc, nixlf,
2054+
NIXLF_UCAST_ENTRY);
2055+
pfvf->entry.action = npc_get_mcam_action(rvu, mcam, blkaddr, index);
2056+
enable = is_mcam_entry_enabled(rvu, mcam, blkaddr, index);
2057+
npc_config_mcam_entry(rvu, mcam, blkaddr, pfvf->rxvlan_index,
2058+
NIX_INTF_RX, &pfvf->entry, enable);
2059+
2060+
return 0;
2061+
}

0 commit comments

Comments
 (0)