Skip to content

Commit 6f91d7a

Browse files
committed
Merge branch 'octeon-DMAC'
Subbaraya Sundeep says: ==================== octeontx2-af: Introduce DMAC based switching With this patch set packets can be switched between all CGX mapped PFs and VFs in the system based on the DMAC addresses. To implement this: AF allocates high priority rules from top entry(0) in MCAM. Rules are allocated for all the CGX mapped PFs and VFs though they are not active and with no NIXLFs attached. Rules for a PF/VF will be enabled only after they are brought up. Two rules one for TX and one for RX are allocated for each PF/VF. A packet sent from a PF/VF with a destination mac of another PF/VF will be hit by TX rule and sent to LBK channel 63. The same returned packet will be hit by RX rule whose action is to forward packet to PF/VF with that destination mac. Implementation of this for 98xx is tricky since there are two NIX blocks and till now a PF/VF can install rule for an NIX0/1 interface only if it is mapped to corresponding NIX0/1 block. Hence Tx rules are modified such that TX interface in MCAM entry can be either NIX0-TX or NIX1-TX. Testing: 1. Create two VFs over PF1(on NIX0) and assign two VFs to two VMs 2. Assign ip addresses to two VFs in VMs and PF2(on NIX1) in host. 3. Assign static arp entries in two VMs and PF2. 4. Ping between VMs and host PF2. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 97d0931 + 23109f8 commit 6f91d7a

File tree

10 files changed

+427
-32
lines changed

10 files changed

+427
-32
lines changed

drivers/net/ethernet/marvell/octeontx2/af/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ obj-$(CONFIG_OCTEONTX2_AF) += rvu_af.o
1010
rvu_mbox-y := mbox.o rvu_trace.o
1111
rvu_af-y := cgx.o rvu.o rvu_cgx.o rvu_npa.o rvu_nix.o \
1212
rvu_reg.o rvu_npc.o rvu_debugfs.o ptp.o rvu_npc_fs.o \
13-
rvu_cpt.o rvu_devlink.o rpm.o rvu_cn10k.o
13+
rvu_cpt.o rvu_devlink.o rpm.o rvu_cn10k.o rvu_switch.o

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ int rvu_mbox_handler_detach_resources(struct rvu *rvu,
13141314
return rvu_detach_rsrcs(rvu, detach, detach->hdr.pcifunc);
13151315
}
13161316

1317-
static int rvu_get_nix_blkaddr(struct rvu *rvu, u16 pcifunc)
1317+
int rvu_get_nix_blkaddr(struct rvu *rvu, u16 pcifunc)
13181318
{
13191319
struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc);
13201320
int blkaddr = BLKADDR_NIX0, vf;
@@ -2859,6 +2859,12 @@ static int rvu_enable_sriov(struct rvu *rvu)
28592859
if (!vfs)
28602860
return 0;
28612861

2862+
/* LBK channel number 63 is used for switching packets between
2863+
* CGX mapped VFs. Hence limit LBK pairs till 62 only.
2864+
*/
2865+
if (vfs > 62)
2866+
vfs = 62;
2867+
28622868
/* Save VFs number for reference in VF interrupts handlers.
28632869
* Since interrupts might start arriving during SRIOV enablement
28642870
* ordinary API cannot be used to get number of enabled VFs.
@@ -3001,6 +3007,8 @@ static int rvu_probe(struct pci_dev *pdev, const struct pci_device_id *id)
30013007
/* Initialize debugfs */
30023008
rvu_dbg_init(rvu);
30033009

3010+
mutex_init(&rvu->rswitch.switch_lock);
3011+
30043012
return 0;
30053013
err_dl:
30063014
rvu_unregister_dl(rvu);

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,16 @@ struct npc_kpu_profile_adapter {
415415
size_t kpus;
416416
};
417417

418+
#define RVU_SWITCH_LBK_CHAN 63
419+
420+
struct rvu_switch {
421+
struct mutex switch_lock; /* Serialize flow installation */
422+
u32 used_entries;
423+
u16 *entry2pcifunc;
424+
u16 mode;
425+
u16 start_entry;
426+
};
427+
418428
struct rvu {
419429
void __iomem *afreg_base;
420430
void __iomem *pfreg_base;
@@ -445,6 +455,7 @@ struct rvu {
445455

446456
/* CGX */
447457
#define PF_CGXMAP_BASE 1 /* PF 0 is reserved for RVU PF */
458+
u16 cgx_mapped_vfs; /* maximum CGX mapped VFs */
448459
u8 cgx_mapped_pfs;
449460
u8 cgx_cnt_max; /* CGX port count max */
450461
u8 *pf2cgxlmac_map; /* pf to cgx_lmac map */
@@ -477,6 +488,9 @@ struct rvu {
477488
struct rvu_debugfs rvu_dbg;
478489
#endif
479490
struct rvu_devlink *rvu_dl;
491+
492+
/* RVU switch implementation over NPC with DMAC rules */
493+
struct rvu_switch rswitch;
480494
};
481495

482496
static inline void rvu_write64(struct rvu *rvu, u64 block, u64 offset, u64 val)
@@ -691,6 +705,7 @@ int nix_aq_context_read(struct rvu *rvu, struct nix_hw *nix_hw,
691705
struct nix_cn10k_aq_enq_req *aq_req,
692706
struct nix_cn10k_aq_enq_rsp *aq_rsp,
693707
u16 pcifunc, u8 ctype, u32 qidx);
708+
int rvu_get_nix_blkaddr(struct rvu *rvu, u16 pcifunc);
694709

695710
/* NPC APIs */
696711
int rvu_npc_init(struct rvu *rvu);
@@ -768,4 +783,10 @@ void rvu_dbg_exit(struct rvu *rvu);
768783
static inline void rvu_dbg_init(struct rvu *rvu) {}
769784
static inline void rvu_dbg_exit(struct rvu *rvu) {}
770785
#endif
786+
787+
/* RVU Switch */
788+
void rvu_switch_enable(struct rvu *rvu);
789+
void rvu_switch_disable(struct rvu *rvu);
790+
void rvu_switch_update_rules(struct rvu *rvu, u16 pcifunc);
791+
771792
#endif /* RVU_H */

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static int rvu_map_cgx_lmac_pf(struct rvu *rvu)
126126
unsigned long lmac_bmap;
127127
int size, free_pkind;
128128
int cgx, lmac, iter;
129+
int numvfs, hwvfs;
129130

130131
if (!cgx_cnt_max)
131132
return 0;
@@ -166,6 +167,8 @@ static int rvu_map_cgx_lmac_pf(struct rvu *rvu)
166167
pkind->pfchan_map[free_pkind] = ((pf) & 0x3F) << 16;
167168
rvu_map_cgx_nix_block(rvu, pf, cgx, lmac);
168169
rvu->cgx_mapped_pfs++;
170+
rvu_get_pf_numvfs(rvu, pf, &numvfs, &hwvfs);
171+
rvu->cgx_mapped_vfs += numvfs;
169172
pf++;
170173
}
171174
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,9 +2113,6 @@ static void rvu_print_npc_mcam_info(struct seq_file *s,
21132113
int entry_acnt, entry_ecnt;
21142114
int cntr_acnt, cntr_ecnt;
21152115

2116-
/* Skip PF0 */
2117-
if (!pcifunc)
2118-
return;
21192116
rvu_npc_get_mcam_entry_alloc_info(rvu, pcifunc, blkaddr,
21202117
&entry_acnt, &entry_ecnt);
21212118
rvu_npc_get_mcam_counter_alloc_info(rvu, pcifunc, blkaddr,
@@ -2298,7 +2295,7 @@ static void rvu_dbg_npc_mcam_show_flows(struct seq_file *s,
22982295
static void rvu_dbg_npc_mcam_show_action(struct seq_file *s,
22992296
struct rvu_npc_mcam_rule *rule)
23002297
{
2301-
if (rule->intf == NIX_INTF_TX) {
2298+
if (is_npc_intf_tx(rule->intf)) {
23022299
switch (rule->tx_action.op) {
23032300
case NIX_TX_ACTIONOP_DROP:
23042301
seq_puts(s, "\taction: Drop\n");

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

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,44 @@ static void rvu_health_reporters_destroy(struct rvu *rvu)
13641364
rvu_nix_health_reporters_destroy(rvu_dl);
13651365
}
13661366

1367+
static int rvu_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode)
1368+
{
1369+
struct rvu_devlink *rvu_dl = devlink_priv(devlink);
1370+
struct rvu *rvu = rvu_dl->rvu;
1371+
struct rvu_switch *rswitch;
1372+
1373+
rswitch = &rvu->rswitch;
1374+
*mode = rswitch->mode;
1375+
1376+
return 0;
1377+
}
1378+
1379+
static int rvu_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
1380+
struct netlink_ext_ack *extack)
1381+
{
1382+
struct rvu_devlink *rvu_dl = devlink_priv(devlink);
1383+
struct rvu *rvu = rvu_dl->rvu;
1384+
struct rvu_switch *rswitch;
1385+
1386+
rswitch = &rvu->rswitch;
1387+
switch (mode) {
1388+
case DEVLINK_ESWITCH_MODE_LEGACY:
1389+
case DEVLINK_ESWITCH_MODE_SWITCHDEV:
1390+
if (rswitch->mode == mode)
1391+
return 0;
1392+
rswitch->mode = mode;
1393+
if (mode == DEVLINK_ESWITCH_MODE_SWITCHDEV)
1394+
rvu_switch_enable(rvu);
1395+
else
1396+
rvu_switch_disable(rvu);
1397+
break;
1398+
default:
1399+
return -EINVAL;
1400+
}
1401+
1402+
return 0;
1403+
}
1404+
13671405
static int rvu_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
13681406
struct netlink_ext_ack *extack)
13691407
{
@@ -1372,6 +1410,8 @@ static int rvu_devlink_info_get(struct devlink *devlink, struct devlink_info_req
13721410

13731411
static const struct devlink_ops rvu_devlink_ops = {
13741412
.info_get = rvu_devlink_info_get,
1413+
.eswitch_mode_get = rvu_devlink_eswitch_mode_get,
1414+
.eswitch_mode_set = rvu_devlink_eswitch_mode_set,
13751415
};
13761416

13771417
int rvu_register_dl(struct rvu *rvu)
@@ -1380,25 +1420,20 @@ int rvu_register_dl(struct rvu *rvu)
13801420
struct devlink *dl;
13811421
int err;
13821422

1383-
rvu_dl = kzalloc(sizeof(*rvu_dl), GFP_KERNEL);
1384-
if (!rvu_dl)
1385-
return -ENOMEM;
1386-
13871423
dl = devlink_alloc(&rvu_devlink_ops, sizeof(struct rvu_devlink));
13881424
if (!dl) {
13891425
dev_warn(rvu->dev, "devlink_alloc failed\n");
1390-
kfree(rvu_dl);
13911426
return -ENOMEM;
13921427
}
13931428

13941429
err = devlink_register(dl, rvu->dev);
13951430
if (err) {
13961431
dev_err(rvu->dev, "devlink register failed with error %d\n", err);
13971432
devlink_free(dl);
1398-
kfree(rvu_dl);
13991433
return err;
14001434
}
14011435

1436+
rvu_dl = devlink_priv(dl);
14021437
rvu_dl->dl = dl;
14031438
rvu_dl->rvu = rvu;
14041439
rvu->rvu_dl = rvu_dl;
@@ -1417,5 +1452,4 @@ void rvu_unregister_dl(struct rvu *rvu)
14171452
rvu_health_reporters_destroy(rvu);
14181453
devlink_unregister(dl);
14191454
devlink_free(dl);
1420-
kfree(rvu_dl);
14211455
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,35 @@ static void nix_tl1_default_cfg(struct rvu *rvu, struct nix_hw *nix_hw,
19521952
pfvf_map[schq] = TXSCH_SET_FLAG(pfvf_map[schq], NIX_TXSCHQ_CFG_DONE);
19531953
}
19541954

1955+
static void rvu_nix_tx_tl2_cfg(struct rvu *rvu, int blkaddr,
1956+
u16 pcifunc, struct nix_txsch *txsch)
1957+
{
1958+
struct rvu_hwinfo *hw = rvu->hw;
1959+
int lbk_link_start, lbk_links;
1960+
u8 pf = rvu_get_pf(pcifunc);
1961+
int schq;
1962+
1963+
if (!is_pf_cgxmapped(rvu, pf))
1964+
return;
1965+
1966+
lbk_link_start = hw->cgx_links;
1967+
1968+
for (schq = 0; schq < txsch->schq.max; schq++) {
1969+
if (TXSCH_MAP_FUNC(txsch->pfvf_map[schq]) != pcifunc)
1970+
continue;
1971+
/* Enable all LBK links with channel 63 by default so that
1972+
* packets can be sent to LBK with a NPC TX MCAM rule
1973+
*/
1974+
lbk_links = hw->lbk_links;
1975+
while (lbk_links--)
1976+
rvu_write64(rvu, blkaddr,
1977+
NIX_AF_TL3_TL2X_LINKX_CFG(schq,
1978+
lbk_link_start +
1979+
lbk_links),
1980+
BIT_ULL(12) | RVU_SWITCH_LBK_CHAN);
1981+
}
1982+
}
1983+
19551984
int rvu_mbox_handler_nix_txschq_cfg(struct rvu *rvu,
19561985
struct nix_txschq_config *req,
19571986
struct msg_rsp *rsp)
@@ -2040,6 +2069,9 @@ int rvu_mbox_handler_nix_txschq_cfg(struct rvu *rvu,
20402069
rvu_write64(rvu, blkaddr, reg, regval);
20412070
}
20422071

2072+
rvu_nix_tx_tl2_cfg(rvu, blkaddr, pcifunc,
2073+
&nix_hw->txsch[NIX_TXSCH_LVL_TL2]);
2074+
20432075
return 0;
20442076
}
20452077

@@ -3180,6 +3212,8 @@ int rvu_mbox_handler_nix_set_mac_addr(struct rvu *rvu,
31803212
if (test_bit(PF_SET_VF_TRUSTED, &pfvf->flags) && from_vf)
31813213
ether_addr_copy(pfvf->default_mac, req->mac_addr);
31823214

3215+
rvu_switch_update_rules(rvu, pcifunc);
3216+
31833217
return 0;
31843218
}
31853219

@@ -3849,6 +3883,8 @@ int rvu_mbox_handler_nix_lf_start_rx(struct rvu *rvu, struct msg_req *req,
38493883
pfvf = rvu_get_pfvf(rvu, pcifunc);
38503884
set_bit(NIXLF_INITIALIZED, &pfvf->flags);
38513885

3886+
rvu_switch_update_rules(rvu, pcifunc);
3887+
38523888
return rvu_cgx_start_stop_io(rvu, pcifunc, true);
38533889
}
38543890

0 commit comments

Comments
 (0)