Skip to content

Commit 0fbabf8

Browse files
Xiaoliang Yangdavem330
authored andcommitted
net: dsa: felix: add support Credit Based Shaper(CBS) for hardware offload
VSC9959 hardware support the Credit Based Shaper(CBS) which part of the IEEE-802.1Qav. This patch support sch_cbs set for VSC9959. Signed-off-by: Xiaoliang Yang <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent de143c0 commit 0fbabf8

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

drivers/net/dsa/ocelot/felix_vsc9959.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static const u32 vsc9959_qsys_regmap[] = {
207207
REG(QSYS_QMAXSDU_CFG_6, 0x00f62c),
208208
REG(QSYS_QMAXSDU_CFG_7, 0x00f648),
209209
REG(QSYS_PREEMPTION_CFG, 0x00f664),
210-
REG_RESERVED(QSYS_CIR_CFG),
210+
REG(QSYS_CIR_CFG, 0x000000),
211211
REG(QSYS_EIR_CFG, 0x000004),
212212
REG(QSYS_SE_CFG, 0x000008),
213213
REG(QSYS_SE_DWRR_CFG, 0x00000c),
@@ -1332,6 +1332,52 @@ static int vsc9959_qos_port_tas_set(struct ocelot *ocelot, int port,
13321332
return ret;
13331333
}
13341334

1335+
static int vsc9959_qos_port_cbs_set(struct dsa_switch *ds, int port,
1336+
struct tc_cbs_qopt_offload *cbs_qopt)
1337+
{
1338+
struct ocelot *ocelot = ds->priv;
1339+
int port_ix = port * 8 + cbs_qopt->queue;
1340+
u32 rate, burst;
1341+
1342+
if (cbs_qopt->queue >= ds->num_tx_queues)
1343+
return -EINVAL;
1344+
1345+
if (!cbs_qopt->enable) {
1346+
ocelot_write_gix(ocelot, QSYS_CIR_CFG_CIR_RATE(0) |
1347+
QSYS_CIR_CFG_CIR_BURST(0),
1348+
QSYS_CIR_CFG, port_ix);
1349+
1350+
ocelot_rmw_gix(ocelot, 0, QSYS_SE_CFG_SE_AVB_ENA,
1351+
QSYS_SE_CFG, port_ix);
1352+
1353+
return 0;
1354+
}
1355+
1356+
/* Rate unit is 100 kbps */
1357+
rate = DIV_ROUND_UP(cbs_qopt->idleslope, 100);
1358+
/* Avoid using zero rate */
1359+
rate = clamp_t(u32, rate, 1, GENMASK(14, 0));
1360+
/* Burst unit is 4kB */
1361+
burst = DIV_ROUND_UP(cbs_qopt->hicredit, 4096);
1362+
/* Avoid using zero burst size */
1363+
burst = clamp_t(u32, rate, 1, GENMASK(5, 0));
1364+
ocelot_write_gix(ocelot,
1365+
QSYS_CIR_CFG_CIR_RATE(rate) |
1366+
QSYS_CIR_CFG_CIR_BURST(burst),
1367+
QSYS_CIR_CFG,
1368+
port_ix);
1369+
1370+
ocelot_rmw_gix(ocelot,
1371+
QSYS_SE_CFG_SE_FRM_MODE(0) |
1372+
QSYS_SE_CFG_SE_AVB_ENA,
1373+
QSYS_SE_CFG_SE_AVB_ENA |
1374+
QSYS_SE_CFG_SE_FRM_MODE_M,
1375+
QSYS_SE_CFG,
1376+
port_ix);
1377+
1378+
return 0;
1379+
}
1380+
13351381
static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port,
13361382
enum tc_setup_type type,
13371383
void *type_data)
@@ -1341,6 +1387,8 @@ static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port,
13411387
switch (type) {
13421388
case TC_SETUP_QDISC_TAPRIO:
13431389
return vsc9959_qos_port_tas_set(ocelot, port, type_data);
1390+
case TC_SETUP_QDISC_CBS:
1391+
return vsc9959_qos_port_cbs_set(ds, port, type_data);
13441392
default:
13451393
return -EOPNOTSUPP;
13461394
}

0 commit comments

Comments
 (0)