Skip to content

Commit 23109f8

Browse files
Subbaraya Sundeepdavem330
authored andcommitted
octeontx2-af: Introduce internal packet switching
As of now any communication between CGXs PFs and their VFs within the system is possible only by external switches sending packets back to the system. This patch adds internal switching support. Broadcast packet replication is not covered here. RVU admin function (AF) maintains MAC addresses of all interfaces in the system. When switching is enabled, MCAM entries are allocated to install rules such that packets with DMAC matching any of the internal interface MAC addresses is punted back into the system via the loopback channel. On the receive side the default unicast rules are modified to not check for ingress channel. So any packet with matching DMAC irrespective of which interface it is coming from will be forwarded to the respective PF/VF interface. The transmit side rules and default unicast rules are updated if user changes MAC address of an interface. Signed-off-by: Subbaraya Sundeep <sbhatta@marvell.com> Signed-off-by: Sunil Kovvuri Goutham <sgoutham@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cb7a6b3 commit 23109f8

File tree

8 files changed

+336
-11
lines changed

8 files changed

+336
-11
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: 3 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;
@@ -3007,6 +3007,8 @@ static int rvu_probe(struct pci_dev *pdev, const struct pci_device_id *id)
30073007
/* Initialize debugfs */
30083008
rvu_dbg_init(rvu);
30093009

3010+
mutex_init(&rvu->rswitch.switch_lock);
3011+
30103012
return 0;
30113013
err_dl:
30123014
rvu_unregister_dl(rvu);

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,14 @@ struct npc_kpu_profile_adapter {
417417

418418
#define RVU_SWITCH_LBK_CHAN 63
419419

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+
420428
struct rvu {
421429
void __iomem *afreg_base;
422430
void __iomem *pfreg_base;
@@ -447,6 +455,7 @@ struct rvu {
447455

448456
/* CGX */
449457
#define PF_CGXMAP_BASE 1 /* PF 0 is reserved for RVU PF */
458+
u16 cgx_mapped_vfs; /* maximum CGX mapped VFs */
450459
u8 cgx_mapped_pfs;
451460
u8 cgx_cnt_max; /* CGX port count max */
452461
u8 *pf2cgxlmac_map; /* pf to cgx_lmac map */
@@ -479,6 +488,9 @@ struct rvu {
479488
struct rvu_debugfs rvu_dbg;
480489
#endif
481490
struct rvu_devlink *rvu_dl;
491+
492+
/* RVU switch implementation over NPC with DMAC rules */
493+
struct rvu_switch rswitch;
482494
};
483495

484496
static inline void rvu_write64(struct rvu *rvu, u64 block, u64 offset, u64 val)
@@ -693,6 +705,7 @@ int nix_aq_context_read(struct rvu *rvu, struct nix_hw *nix_hw,
693705
struct nix_cn10k_aq_enq_req *aq_req,
694706
struct nix_cn10k_aq_enq_rsp *aq_rsp,
695707
u16 pcifunc, u8 ctype, u32 qidx);
708+
int rvu_get_nix_blkaddr(struct rvu *rvu, u16 pcifunc);
696709

697710
/* NPC APIs */
698711
int rvu_npc_init(struct rvu *rvu);
@@ -770,4 +783,10 @@ void rvu_dbg_exit(struct rvu *rvu);
770783
static inline void rvu_dbg_init(struct rvu *rvu) {}
771784
static inline void rvu_dbg_exit(struct rvu *rvu) {}
772785
#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+
773792
#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_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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,6 +3212,8 @@ int rvu_mbox_handler_nix_set_mac_addr(struct rvu *rvu,
32123212
if (test_bit(PF_SET_VF_TRUSTED, &pfvf->flags) && from_vf)
32133213
ether_addr_copy(pfvf->default_mac, req->mac_addr);
32143214

3215+
rvu_switch_update_rules(rvu, pcifunc);
3216+
32153217
return 0;
32163218
}
32173219

@@ -3881,6 +3883,8 @@ int rvu_mbox_handler_nix_lf_start_rx(struct rvu *rvu, struct msg_req *req,
38813883
pfvf = rvu_get_pfvf(rvu, pcifunc);
38823884
set_bit(NIXLF_INITIALIZED, &pfvf->flags);
38833885

3886+
rvu_switch_update_rules(rvu, pcifunc);
3887+
38843888
return rvu_cgx_start_stop_io(rvu, pcifunc, true);
38853889
}
38863890

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,15 @@ static void rvu_mcam_add_counter_to_rule(struct rvu *rvu, u16 pcifunc,
910910

911911
static void npc_update_rx_entry(struct rvu *rvu, struct rvu_pfvf *pfvf,
912912
struct mcam_entry *entry,
913-
struct npc_install_flow_req *req, u16 target)
913+
struct npc_install_flow_req *req,
914+
u16 target, bool pf_set_vfs_mac)
914915
{
916+
struct rvu_switch *rswitch = &rvu->rswitch;
915917
struct nix_rx_action action;
916918

919+
if (rswitch->mode == DEVLINK_ESWITCH_MODE_SWITCHDEV && pf_set_vfs_mac)
920+
req->chan_mask = 0x0; /* Do not care channel */
921+
917922
npc_update_entry(rvu, NPC_CHAN, entry, req->channel, 0, req->chan_mask,
918923
0, NIX_INTF_RX);
919924

@@ -1007,7 +1012,7 @@ static int npc_install_flow(struct rvu *rvu, int blkaddr, u16 target,
10071012
req->intf);
10081013

10091014
if (is_npc_intf_rx(req->intf))
1010-
npc_update_rx_entry(rvu, pfvf, entry, req, target);
1015+
npc_update_rx_entry(rvu, pfvf, entry, req, target, pf_set_vfs_mac);
10111016
else
10121017
npc_update_tx_entry(rvu, pfvf, entry, req, target);
10131018

0 commit comments

Comments
 (0)