Skip to content

Commit 9a946de

Browse files
Vamsi Attunurukuba-moo
authored andcommitted
octeontx2-af: Modify nix_vtag_cfg mailbox to support TX VTAG entries
This patch modifies the existing nix_vtag_config mailbox message to allocate and free TX VTAG entries as requested by a NIX PF. The TX VTAG entries are global resource that shared by all PFs and each entry specifies the size of VTAG to insert and the VTAG header data to insert. The mailbox response contains the entry index which is used by mailbox requester in configuring the NPC_TX_VTAG_ACTION for any MCAM entry. Signed-off-by: Vamsi Attunuru <[email protected]> Signed-off-by: Sunil Goutham <[email protected]> Signed-off-by: Naveen Mamindlapalli <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4d6beb9 commit 9a946de

File tree

3 files changed

+250
-13
lines changed

3 files changed

+250
-13
lines changed

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

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ M(NIX_TXSCH_ALLOC, 0x8004, nix_txsch_alloc, \
204204
M(NIX_TXSCH_FREE, 0x8005, nix_txsch_free, nix_txsch_free_req, msg_rsp) \
205205
M(NIX_TXSCHQ_CFG, 0x8006, nix_txschq_cfg, nix_txschq_config, msg_rsp) \
206206
M(NIX_STATS_RST, 0x8007, nix_stats_rst, msg_req, msg_rsp) \
207-
M(NIX_VTAG_CFG, 0x8008, nix_vtag_cfg, nix_vtag_config, msg_rsp) \
207+
M(NIX_VTAG_CFG, 0x8008, nix_vtag_cfg, nix_vtag_config, \
208+
nix_vtag_config_rsp) \
208209
M(NIX_RSS_FLOWKEY_CFG, 0x8009, nix_rss_flowkey_cfg, \
209210
nix_rss_flowkey_cfg, \
210211
nix_rss_flowkey_cfg_rsp) \
@@ -477,6 +478,7 @@ enum nix_af_status {
477478
NIX_AF_ERR_LSO_CFG_FAIL = -418,
478479
NIX_AF_INVAL_NPA_PF_FUNC = -419,
479480
NIX_AF_INVAL_SSO_PF_FUNC = -420,
481+
NIX_AF_ERR_TX_VTAG_NOSPC = -421,
480482
};
481483

482484
/* For NIX LF context alloc and init */
@@ -516,7 +518,8 @@ struct nix_lf_alloc_rsp {
516518

517519
struct nix_lf_free_req {
518520
struct mbox_msghdr hdr;
519-
#define NIX_LF_DISABLE_FLOWS BIT_ULL(0)
521+
#define NIX_LF_DISABLE_FLOWS BIT_ULL(0)
522+
#define NIX_LF_DONT_FREE_TX_VTAG BIT_ULL(1)
520523
u64 flags;
521524
};
522525

@@ -610,14 +613,40 @@ struct nix_vtag_config {
610613
union {
611614
/* valid when cfg_type is '0' */
612615
struct {
613-
/* tx vlan0 tag(C-VLAN) */
614-
u64 vlan0;
615-
/* tx vlan1 tag(S-VLAN) */
616-
u64 vlan1;
617-
/* insert tx vlan tag */
618-
u8 insert_vlan :1;
619-
/* insert tx double vlan tag */
620-
u8 double_vlan :1;
616+
u64 vtag0;
617+
u64 vtag1;
618+
619+
/* cfg_vtag0 & cfg_vtag1 fields are valid
620+
* when free_vtag0 & free_vtag1 are '0's.
621+
*/
622+
/* cfg_vtag0 = 1 to configure vtag0 */
623+
u8 cfg_vtag0 :1;
624+
/* cfg_vtag1 = 1 to configure vtag1 */
625+
u8 cfg_vtag1 :1;
626+
627+
/* vtag0_idx & vtag1_idx are only valid when
628+
* both cfg_vtag0 & cfg_vtag1 are '0's,
629+
* these fields are used along with free_vtag0
630+
* & free_vtag1 to free the nix lf's tx_vlan
631+
* configuration.
632+
*
633+
* Denotes the indices of tx_vtag def registers
634+
* that needs to be cleared and freed.
635+
*/
636+
int vtag0_idx;
637+
int vtag1_idx;
638+
639+
/* free_vtag0 & free_vtag1 fields are valid
640+
* when cfg_vtag0 & cfg_vtag1 are '0's.
641+
*/
642+
/* free_vtag0 = 1 clears vtag0 configuration
643+
* vtag0_idx denotes the index to be cleared.
644+
*/
645+
u8 free_vtag0 :1;
646+
/* free_vtag1 = 1 clears vtag1 configuration
647+
* vtag1_idx denotes the index to be cleared.
648+
*/
649+
u8 free_vtag1 :1;
621650
} tx;
622651

623652
/* valid when cfg_type is '1' */
@@ -632,6 +661,17 @@ struct nix_vtag_config {
632661
};
633662
};
634663

664+
struct nix_vtag_config_rsp {
665+
struct mbox_msghdr hdr;
666+
int vtag0_idx;
667+
int vtag1_idx;
668+
/* Indices of tx_vtag def registers used to configure
669+
* tx vtag0 & vtag1 headers, these indices are valid
670+
* when nix_vtag_config mbox requested for vtag0 and/
671+
* or vtag1 configuration.
672+
*/
673+
};
674+
635675
struct nix_rss_flowkey_cfg {
636676
struct mbox_msghdr hdr;
637677
int mcam_index; /* MCAM entry index to modify */

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ struct nix_lso {
264264
u8 in_use;
265265
};
266266

267+
struct nix_txvlan {
268+
#define NIX_TX_VTAG_DEF_MAX 0x400
269+
struct rsrc_bmap rsrc;
270+
u16 *entry2pfvf_map;
271+
struct mutex rsrc_lock; /* Serialize resource alloc/free */
272+
};
273+
267274
struct nix_hw {
268275
int blkaddr;
269276
struct rvu *rvu;
@@ -272,6 +279,7 @@ struct nix_hw {
272279
struct nix_flowkey flowkey;
273280
struct nix_mark_format mark_format;
274281
struct nix_lso lso;
282+
struct nix_txvlan txvlan;
275283
};
276284

277285
/* RVU block's capabilities or functionality,

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

Lines changed: 192 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "npc.h"
1818
#include "cgx.h"
1919

20+
static void nix_free_tx_vtag_entries(struct rvu *rvu, u16 pcifunc);
2021
static int rvu_nix_get_bpid(struct rvu *rvu, struct nix_bp_cfg_req *req,
2122
int type, int chan_id);
2223

@@ -1251,6 +1252,10 @@ int rvu_mbox_handler_nix_lf_free(struct rvu *rvu, struct nix_lf_free_req *req,
12511252
else
12521253
rvu_npc_free_mcam_entries(rvu, pcifunc, nixlf);
12531254

1255+
/* Free any tx vtag def entries used by this NIX LF */
1256+
if (!(req->flags & NIX_LF_DONT_FREE_TX_VTAG))
1257+
nix_free_tx_vtag_entries(rvu, pcifunc);
1258+
12541259
nix_interface_deinit(rvu, pcifunc, nixlf);
12551260

12561261
/* Reset this NIX LF */
@@ -1992,9 +1997,149 @@ static int nix_rx_vtag_cfg(struct rvu *rvu, int nixlf, int blkaddr,
19921997
return 0;
19931998
}
19941999

2000+
static int nix_tx_vtag_free(struct rvu *rvu, int blkaddr,
2001+
u16 pcifunc, int index)
2002+
{
2003+
struct nix_hw *nix_hw = get_nix_hw(rvu->hw, blkaddr);
2004+
struct nix_txvlan *vlan = &nix_hw->txvlan;
2005+
2006+
if (vlan->entry2pfvf_map[index] != pcifunc)
2007+
return NIX_AF_ERR_PARAM;
2008+
2009+
rvu_write64(rvu, blkaddr,
2010+
NIX_AF_TX_VTAG_DEFX_DATA(index), 0x0ull);
2011+
rvu_write64(rvu, blkaddr,
2012+
NIX_AF_TX_VTAG_DEFX_CTL(index), 0x0ull);
2013+
2014+
vlan->entry2pfvf_map[index] = 0;
2015+
rvu_free_rsrc(&vlan->rsrc, index);
2016+
2017+
return 0;
2018+
}
2019+
2020+
static void nix_free_tx_vtag_entries(struct rvu *rvu, u16 pcifunc)
2021+
{
2022+
struct nix_txvlan *vlan;
2023+
struct nix_hw *nix_hw;
2024+
int index, blkaddr;
2025+
2026+
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NIX, pcifunc);
2027+
if (blkaddr < 0)
2028+
return;
2029+
2030+
nix_hw = get_nix_hw(rvu->hw, blkaddr);
2031+
vlan = &nix_hw->txvlan;
2032+
2033+
mutex_lock(&vlan->rsrc_lock);
2034+
/* Scan all the entries and free the ones mapped to 'pcifunc' */
2035+
for (index = 0; index < vlan->rsrc.max; index++) {
2036+
if (vlan->entry2pfvf_map[index] == pcifunc)
2037+
nix_tx_vtag_free(rvu, blkaddr, pcifunc, index);
2038+
}
2039+
mutex_unlock(&vlan->rsrc_lock);
2040+
}
2041+
2042+
static int nix_tx_vtag_alloc(struct rvu *rvu, int blkaddr,
2043+
u64 vtag, u8 size)
2044+
{
2045+
struct nix_hw *nix_hw = get_nix_hw(rvu->hw, blkaddr);
2046+
struct nix_txvlan *vlan = &nix_hw->txvlan;
2047+
u64 regval;
2048+
int index;
2049+
2050+
mutex_lock(&vlan->rsrc_lock);
2051+
2052+
index = rvu_alloc_rsrc(&vlan->rsrc);
2053+
if (index < 0) {
2054+
mutex_unlock(&vlan->rsrc_lock);
2055+
return index;
2056+
}
2057+
2058+
mutex_unlock(&vlan->rsrc_lock);
2059+
2060+
regval = size ? vtag : vtag << 32;
2061+
2062+
rvu_write64(rvu, blkaddr,
2063+
NIX_AF_TX_VTAG_DEFX_DATA(index), regval);
2064+
rvu_write64(rvu, blkaddr,
2065+
NIX_AF_TX_VTAG_DEFX_CTL(index), size);
2066+
2067+
return index;
2068+
}
2069+
2070+
static int nix_tx_vtag_decfg(struct rvu *rvu, int blkaddr,
2071+
struct nix_vtag_config *req)
2072+
{
2073+
struct nix_hw *nix_hw = get_nix_hw(rvu->hw, blkaddr);
2074+
struct nix_txvlan *vlan = &nix_hw->txvlan;
2075+
u16 pcifunc = req->hdr.pcifunc;
2076+
int idx0 = req->tx.vtag0_idx;
2077+
int idx1 = req->tx.vtag1_idx;
2078+
int err;
2079+
2080+
if (req->tx.free_vtag0 && req->tx.free_vtag1)
2081+
if (vlan->entry2pfvf_map[idx0] != pcifunc ||
2082+
vlan->entry2pfvf_map[idx1] != pcifunc)
2083+
return NIX_AF_ERR_PARAM;
2084+
2085+
mutex_lock(&vlan->rsrc_lock);
2086+
2087+
if (req->tx.free_vtag0) {
2088+
err = nix_tx_vtag_free(rvu, blkaddr, pcifunc, idx0);
2089+
if (err)
2090+
goto exit;
2091+
}
2092+
2093+
if (req->tx.free_vtag1)
2094+
err = nix_tx_vtag_free(rvu, blkaddr, pcifunc, idx1);
2095+
2096+
exit:
2097+
mutex_unlock(&vlan->rsrc_lock);
2098+
return err;
2099+
}
2100+
2101+
static int nix_tx_vtag_cfg(struct rvu *rvu, int blkaddr,
2102+
struct nix_vtag_config *req,
2103+
struct nix_vtag_config_rsp *rsp)
2104+
{
2105+
struct nix_hw *nix_hw = get_nix_hw(rvu->hw, blkaddr);
2106+
struct nix_txvlan *vlan = &nix_hw->txvlan;
2107+
u16 pcifunc = req->hdr.pcifunc;
2108+
2109+
if (req->tx.cfg_vtag0) {
2110+
rsp->vtag0_idx =
2111+
nix_tx_vtag_alloc(rvu, blkaddr,
2112+
req->tx.vtag0, req->vtag_size);
2113+
2114+
if (rsp->vtag0_idx < 0)
2115+
return NIX_AF_ERR_TX_VTAG_NOSPC;
2116+
2117+
vlan->entry2pfvf_map[rsp->vtag0_idx] = pcifunc;
2118+
}
2119+
2120+
if (req->tx.cfg_vtag1) {
2121+
rsp->vtag1_idx =
2122+
nix_tx_vtag_alloc(rvu, blkaddr,
2123+
req->tx.vtag1, req->vtag_size);
2124+
2125+
if (rsp->vtag1_idx < 0)
2126+
goto err_free;
2127+
2128+
vlan->entry2pfvf_map[rsp->vtag1_idx] = pcifunc;
2129+
}
2130+
2131+
return 0;
2132+
2133+
err_free:
2134+
if (req->tx.cfg_vtag0)
2135+
nix_tx_vtag_free(rvu, blkaddr, pcifunc, rsp->vtag0_idx);
2136+
2137+
return NIX_AF_ERR_TX_VTAG_NOSPC;
2138+
}
2139+
19952140
int rvu_mbox_handler_nix_vtag_cfg(struct rvu *rvu,
19962141
struct nix_vtag_config *req,
1997-
struct msg_rsp *rsp)
2142+
struct nix_vtag_config_rsp *rsp)
19982143
{
19992144
u16 pcifunc = req->hdr.pcifunc;
20002145
int blkaddr, nixlf, err;
@@ -2004,12 +2149,21 @@ int rvu_mbox_handler_nix_vtag_cfg(struct rvu *rvu,
20042149
return err;
20052150

20062151
if (req->cfg_type) {
2152+
/* rx vtag configuration */
20072153
err = nix_rx_vtag_cfg(rvu, nixlf, blkaddr, req);
20082154
if (err)
20092155
return NIX_AF_ERR_PARAM;
20102156
} else {
2011-
/* TODO: handle tx vtag configuration */
2012-
return 0;
2157+
/* tx vtag configuration */
2158+
if ((req->tx.cfg_vtag0 || req->tx.cfg_vtag1) &&
2159+
(req->tx.free_vtag0 || req->tx.free_vtag1))
2160+
return NIX_AF_ERR_PARAM;
2161+
2162+
if (req->tx.cfg_vtag0 || req->tx.cfg_vtag1)
2163+
return nix_tx_vtag_cfg(rvu, blkaddr, req, rsp);
2164+
2165+
if (req->tx.free_vtag0 || req->tx.free_vtag1)
2166+
return nix_tx_vtag_decfg(rvu, blkaddr, req);
20132167
}
20142168

20152169
return 0;
@@ -2247,6 +2401,31 @@ static int nix_setup_mcast(struct rvu *rvu, struct nix_hw *nix_hw, int blkaddr)
22472401
return nix_setup_bcast_tables(rvu, nix_hw);
22482402
}
22492403

2404+
static int nix_setup_txvlan(struct rvu *rvu, struct nix_hw *nix_hw)
2405+
{
2406+
struct nix_txvlan *vlan = &nix_hw->txvlan;
2407+
int err;
2408+
2409+
/* Allocate resource bimap for tx vtag def registers*/
2410+
vlan->rsrc.max = NIX_TX_VTAG_DEF_MAX;
2411+
err = rvu_alloc_bitmap(&vlan->rsrc);
2412+
if (err)
2413+
return -ENOMEM;
2414+
2415+
/* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
2416+
vlan->entry2pfvf_map = devm_kcalloc(rvu->dev, vlan->rsrc.max,
2417+
sizeof(u16), GFP_KERNEL);
2418+
if (!vlan->entry2pfvf_map)
2419+
goto free_mem;
2420+
2421+
mutex_init(&vlan->rsrc_lock);
2422+
return 0;
2423+
2424+
free_mem:
2425+
kfree(vlan->rsrc.bmap);
2426+
return -ENOMEM;
2427+
}
2428+
22502429
static int nix_setup_txschq(struct rvu *rvu, struct nix_hw *nix_hw, int blkaddr)
22512430
{
22522431
struct nix_txsch *txsch;
@@ -3241,6 +3420,10 @@ static int rvu_nix_block_init(struct rvu *rvu, struct nix_hw *nix_hw)
32413420
if (err)
32423421
return err;
32433422

3423+
err = nix_setup_txvlan(rvu, nix_hw);
3424+
if (err)
3425+
return err;
3426+
32443427
/* Configure segmentation offload formats */
32453428
nix_setup_lso(rvu, nix_hw, blkaddr);
32463429

@@ -3327,6 +3510,7 @@ static void rvu_nix_block_freemem(struct rvu *rvu, int blkaddr,
33273510
{
33283511
struct nix_txsch *txsch;
33293512
struct nix_mcast *mcast;
3513+
struct nix_txvlan *vlan;
33303514
struct nix_hw *nix_hw;
33313515
int lvl;
33323516

@@ -3342,6 +3526,11 @@ static void rvu_nix_block_freemem(struct rvu *rvu, int blkaddr,
33423526
kfree(txsch->schq.bmap);
33433527
}
33443528

3529+
vlan = &nix_hw->txvlan;
3530+
kfree(vlan->rsrc.bmap);
3531+
mutex_destroy(&vlan->rsrc_lock);
3532+
devm_kfree(rvu->dev, vlan->entry2pfvf_map);
3533+
33453534
mcast = &nix_hw->mcast;
33463535
qmem_free(rvu->dev, mcast->mce_ctx);
33473536
qmem_free(rvu->dev, mcast->mcast_buf);

0 commit comments

Comments
 (0)