-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Horatiu Vultur says: ==================== net: lan966x: Add tbf, cbs, ets support Add support for offloading QoS features with tc command to lan966x. The offloaded Qos features are tbf, cbs and ets. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Showing
7 changed files
with
365 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
|
||
#include "lan966x_main.h" | ||
|
||
#define DWRR_COST_BIT_WIDTH BIT(5) | ||
|
||
static u32 lan966x_ets_hw_cost(u32 w_min, u32 weight) | ||
{ | ||
u32 res; | ||
|
||
/* Round half up: Multiply with 16 before division, | ||
* add 8 and divide result with 16 again | ||
*/ | ||
res = (((DWRR_COST_BIT_WIDTH << 4) * w_min / weight) + 8) >> 4; | ||
return max_t(u32, 1, res) - 1; | ||
} | ||
|
||
int lan966x_ets_add(struct lan966x_port *port, | ||
struct tc_ets_qopt_offload *qopt) | ||
{ | ||
struct tc_ets_qopt_offload_replace_params *params; | ||
struct lan966x *lan966x = port->lan966x; | ||
u32 w_min = 100; | ||
u8 count = 0; | ||
u32 se_idx; | ||
u8 i; | ||
|
||
/* Check the input */ | ||
if (qopt->parent != TC_H_ROOT) | ||
return -EINVAL; | ||
|
||
params = &qopt->replace_params; | ||
if (params->bands != NUM_PRIO_QUEUES) | ||
return -EINVAL; | ||
|
||
for (i = 0; i < params->bands; ++i) { | ||
/* In the switch the DWRR is always on the lowest consecutive | ||
* priorities. Due to this, the first priority must map to the | ||
* first DWRR band. | ||
*/ | ||
if (params->priomap[i] != (7 - i)) | ||
return -EINVAL; | ||
|
||
if (params->quanta[i] && params->weights[i] == 0) | ||
return -EINVAL; | ||
} | ||
|
||
se_idx = SE_IDX_PORT + port->chip_port; | ||
|
||
/* Find minimum weight */ | ||
for (i = 0; i < params->bands; ++i) { | ||
if (params->quanta[i] == 0) | ||
continue; | ||
|
||
w_min = min(w_min, params->weights[i]); | ||
} | ||
|
||
for (i = 0; i < params->bands; ++i) { | ||
if (params->quanta[i] == 0) | ||
continue; | ||
|
||
++count; | ||
|
||
lan_wr(lan966x_ets_hw_cost(w_min, params->weights[i]), | ||
lan966x, QSYS_SE_DWRR_CFG(se_idx, 7 - i)); | ||
} | ||
|
||
lan_rmw(QSYS_SE_CFG_SE_DWRR_CNT_SET(count) | | ||
QSYS_SE_CFG_SE_RR_ENA_SET(0), | ||
QSYS_SE_CFG_SE_DWRR_CNT | | ||
QSYS_SE_CFG_SE_RR_ENA, | ||
lan966x, QSYS_SE_CFG(se_idx)); | ||
|
||
return 0; | ||
} | ||
|
||
int lan966x_ets_del(struct lan966x_port *port, | ||
struct tc_ets_qopt_offload *qopt) | ||
{ | ||
struct lan966x *lan966x = port->lan966x; | ||
u32 se_idx; | ||
int i; | ||
|
||
se_idx = SE_IDX_PORT + port->chip_port; | ||
|
||
for (i = 0; i < NUM_PRIO_QUEUES; ++i) | ||
lan_wr(0, lan966x, QSYS_SE_DWRR_CFG(se_idx, i)); | ||
|
||
lan_rmw(QSYS_SE_CFG_SE_DWRR_CNT_SET(0) | | ||
QSYS_SE_CFG_SE_RR_ENA_SET(0), | ||
QSYS_SE_CFG_SE_DWRR_CNT | | ||
QSYS_SE_CFG_SE_RR_ENA, | ||
lan966x, QSYS_SE_CFG(se_idx)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
|
||
#include "lan966x_main.h" | ||
|
||
int lan966x_tbf_add(struct lan966x_port *port, | ||
struct tc_tbf_qopt_offload *qopt) | ||
{ | ||
struct lan966x *lan966x = port->lan966x; | ||
bool root = qopt->parent == TC_H_ROOT; | ||
u32 queue = 0; | ||
u32 cir, cbs; | ||
u32 se_idx; | ||
|
||
if (!root) { | ||
queue = TC_H_MIN(qopt->parent) - 1; | ||
if (queue >= NUM_PRIO_QUEUES) | ||
return -EOPNOTSUPP; | ||
} | ||
|
||
if (root) | ||
se_idx = SE_IDX_PORT + port->chip_port; | ||
else | ||
se_idx = SE_IDX_QUEUE + port->chip_port * NUM_PRIO_QUEUES + queue; | ||
|
||
cir = div_u64(qopt->replace_params.rate.rate_bytes_ps, 1000) * 8; | ||
cbs = qopt->replace_params.max_size; | ||
|
||
/* 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(0) | | ||
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_tbf_del(struct lan966x_port *port, | ||
struct tc_tbf_qopt_offload *qopt) | ||
{ | ||
struct lan966x *lan966x = port->lan966x; | ||
bool root = qopt->parent == TC_H_ROOT; | ||
u32 queue = 0; | ||
u32 se_idx; | ||
|
||
if (!root) { | ||
queue = TC_H_MIN(qopt->parent) - 1; | ||
if (queue >= NUM_PRIO_QUEUES) | ||
return -EOPNOTSUPP; | ||
} | ||
|
||
if (root) | ||
se_idx = SE_IDX_PORT + port->chip_port; | ||
else | ||
se_idx = SE_IDX_QUEUE + port->chip_port * NUM_PRIO_QUEUES + queue; | ||
|
||
lan_rmw(QSYS_SE_CFG_SE_AVB_ENA_SET(0) | | ||
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; | ||
} |
Oops, something went wrong.