Files
cubelinux-kernel/drivers/net/ethernet/microchip/lan966x/lan966x_cbs.c
T
Greg Kroah-Hartman 598cf27219 Linux 6.19.3
Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org
Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com>
Tested-by: Peter Schneider <pschneider1968@googlemail.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Salvatore Bonaccorso <carnil@debian.org>
Tested-by: Brett A C Sheffield <bacs@librecast.net>
Tested-by: Mark Brown <broonie@kernel.org>
Tested-by: Luna Jernberg <droidbittin@gmail.com>
Tested-by: Ronald Warsow <rwarsow@gmx.de>
Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
Tested-by: Ron Economos <re@w6rz.net>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-02-19 16:33:27 +01:00

71 lines
1.7 KiB
C

// SPDX-License-Identifier: GPL-2.0+
#include "lan966x_main.h"
int lan966x_cbs_add(struct lan966x_port *port,
struct tc_cbs_qopt_offload *qopt)
{
struct lan966x *lan966x = port->lan966x;
u32 cir, cbs;
u8 se_idx;
/* Check for invalid values */
if (qopt->idleslope <= 0 ||
qopt->sendslope >= 0 ||
qopt->locredit >= qopt->hicredit)
return -EINVAL;
se_idx = SE_IDX_QUEUE + port->chip_port * NUM_PRIO_QUEUES + qopt->queue;
cir = qopt->idleslope;
cbs = (qopt->idleslope - qopt->sendslope) *
(qopt->hicredit - qopt->locredit) /
-qopt->sendslope;
/* Rate unit is 100 kbps */
cir = DIV_ROUND_UP(cir, 100);
/* Avoid using zero rate */
cir = cir ?: 1;
/* Burst unit is 4kB */
cbs = DIV_ROUND_UP(cbs, 4096);
/* Avoid using zero burst */
cbs = cbs ?: 1;
/* Check that actually the result can be written */
if (cir > GENMASK(15, 0) ||
cbs > GENMASK(6, 0))
return -EINVAL;
lan_rmw(QSYS_SE_CFG_SE_AVB_ENA_SET(1) |
QSYS_SE_CFG_SE_FRM_MODE_SET(1),
QSYS_SE_CFG_SE_AVB_ENA |
QSYS_SE_CFG_SE_FRM_MODE,
lan966x, QSYS_SE_CFG(se_idx));
lan_wr(QSYS_CIR_CFG_CIR_RATE_SET(cir) |
QSYS_CIR_CFG_CIR_BURST_SET(cbs),
lan966x, QSYS_CIR_CFG(se_idx));
return 0;
}
int lan966x_cbs_del(struct lan966x_port *port,
struct tc_cbs_qopt_offload *qopt)
{
struct lan966x *lan966x = port->lan966x;
u8 se_idx;
se_idx = SE_IDX_QUEUE + port->chip_port * NUM_PRIO_QUEUES + qopt->queue;
lan_rmw(QSYS_SE_CFG_SE_AVB_ENA_SET(1) |
QSYS_SE_CFG_SE_FRM_MODE_SET(0),
QSYS_SE_CFG_SE_AVB_ENA |
QSYS_SE_CFG_SE_FRM_MODE,
lan966x, QSYS_SE_CFG(se_idx));
lan_wr(QSYS_CIR_CFG_CIR_RATE_SET(0) |
QSYS_CIR_CFG_CIR_BURST_SET(0),
lan966x, QSYS_CIR_CFG(se_idx));
return 0;
}