Commit 29aaf3d4 authored by Horatiu Vultur's avatar Horatiu Vultur Committed by David S. Miller

net: lan966x: Add offload support for ets

Add ets qdisc which allows to mix strict priority with bandwidth-sharing
bands. The ets qdisc needs to be attached as root qdisc.
Signed-off-by: default avatarHoratiu Vultur <horatiu.vultur@microchip.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 21ce14a8
...@@ -10,4 +10,4 @@ lan966x-switch-objs := lan966x_main.o lan966x_phylink.o lan966x_port.o \ ...@@ -10,4 +10,4 @@ lan966x-switch-objs := lan966x_main.o lan966x_phylink.o lan966x_port.o \
lan966x_vlan.o lan966x_fdb.o lan966x_mdb.o \ lan966x_vlan.o lan966x_fdb.o lan966x_mdb.o \
lan966x_ptp.o lan966x_fdma.o lan966x_lag.o \ lan966x_ptp.o lan966x_fdma.o lan966x_lag.o \
lan966x_tc.o lan966x_mqprio.o lan966x_taprio.o \ lan966x_tc.o lan966x_mqprio.o lan966x_taprio.o \
lan966x_tbf.o lan966x_cbs.o lan966x_tbf.o lan966x_cbs.o lan966x_ets.o
// 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;
}
...@@ -476,6 +476,11 @@ int lan966x_cbs_add(struct lan966x_port *port, ...@@ -476,6 +476,11 @@ int lan966x_cbs_add(struct lan966x_port *port,
int lan966x_cbs_del(struct lan966x_port *port, int lan966x_cbs_del(struct lan966x_port *port,
struct tc_cbs_qopt_offload *qopt); struct tc_cbs_qopt_offload *qopt);
int lan966x_ets_add(struct lan966x_port *port,
struct tc_ets_qopt_offload *qopt);
int lan966x_ets_del(struct lan966x_port *port,
struct tc_ets_qopt_offload *qopt);
static inline void __iomem *lan_addr(void __iomem *base[], static inline void __iomem *lan_addr(void __iomem *base[],
int id, int tinst, int tcnt, int id, int tinst, int tcnt,
int gbase, int ginst, int gbase, int ginst,
......
...@@ -1036,6 +1036,18 @@ enum lan966x_target { ...@@ -1036,6 +1036,18 @@ enum lan966x_target {
/* QSYS:HSCH:SE_CFG */ /* QSYS:HSCH:SE_CFG */
#define QSYS_SE_CFG(g) __REG(TARGET_QSYS, 0, 1, 16384, g, 90, 128, 8, 0, 1, 4) #define QSYS_SE_CFG(g) __REG(TARGET_QSYS, 0, 1, 16384, g, 90, 128, 8, 0, 1, 4)
#define QSYS_SE_CFG_SE_DWRR_CNT GENMASK(9, 6)
#define QSYS_SE_CFG_SE_DWRR_CNT_SET(x)\
FIELD_PREP(QSYS_SE_CFG_SE_DWRR_CNT, x)
#define QSYS_SE_CFG_SE_DWRR_CNT_GET(x)\
FIELD_GET(QSYS_SE_CFG_SE_DWRR_CNT, x)
#define QSYS_SE_CFG_SE_RR_ENA BIT(5)
#define QSYS_SE_CFG_SE_RR_ENA_SET(x)\
FIELD_PREP(QSYS_SE_CFG_SE_RR_ENA, x)
#define QSYS_SE_CFG_SE_RR_ENA_GET(x)\
FIELD_GET(QSYS_SE_CFG_SE_RR_ENA, x)
#define QSYS_SE_CFG_SE_AVB_ENA BIT(4) #define QSYS_SE_CFG_SE_AVB_ENA BIT(4)
#define QSYS_SE_CFG_SE_AVB_ENA_SET(x)\ #define QSYS_SE_CFG_SE_AVB_ENA_SET(x)\
FIELD_PREP(QSYS_SE_CFG_SE_AVB_ENA, x) FIELD_PREP(QSYS_SE_CFG_SE_AVB_ENA, x)
...@@ -1048,6 +1060,14 @@ enum lan966x_target { ...@@ -1048,6 +1060,14 @@ enum lan966x_target {
#define QSYS_SE_CFG_SE_FRM_MODE_GET(x)\ #define QSYS_SE_CFG_SE_FRM_MODE_GET(x)\
FIELD_GET(QSYS_SE_CFG_SE_FRM_MODE, x) FIELD_GET(QSYS_SE_CFG_SE_FRM_MODE, x)
#define QSYS_SE_DWRR_CFG(g, r) __REG(TARGET_QSYS, 0, 1, 16384, g, 90, 128, 12, r, 12, 4)
#define QSYS_SE_DWRR_CFG_DWRR_COST GENMASK(4, 0)
#define QSYS_SE_DWRR_CFG_DWRR_COST_SET(x)\
FIELD_PREP(QSYS_SE_DWRR_CFG_DWRR_COST, x)
#define QSYS_SE_DWRR_CFG_DWRR_COST_GET(x)\
FIELD_GET(QSYS_SE_DWRR_CFG_DWRR_COST, x)
/* QSYS:TAS_CONFIG:TAS_CFG_CTRL */ /* QSYS:TAS_CONFIG:TAS_CFG_CTRL */
#define QSYS_TAS_CFG_CTRL __REG(TARGET_QSYS, 0, 1, 57372, 0, 1, 12, 0, 0, 1, 4) #define QSYS_TAS_CFG_CTRL __REG(TARGET_QSYS, 0, 1, 57372, 0, 1, 12, 0, 0, 1, 4)
......
...@@ -44,6 +44,21 @@ static int lan966x_tc_setup_qdisc_cbs(struct lan966x_port *port, ...@@ -44,6 +44,21 @@ static int lan966x_tc_setup_qdisc_cbs(struct lan966x_port *port,
lan966x_cbs_del(port, qopt); lan966x_cbs_del(port, qopt);
} }
static int lan966x_tc_setup_qdisc_ets(struct lan966x_port *port,
struct tc_ets_qopt_offload *qopt)
{
switch (qopt->command) {
case TC_ETS_REPLACE:
return lan966x_ets_add(port, qopt);
case TC_ETS_DESTROY:
return lan966x_ets_del(port, qopt);
default:
return -EOPNOTSUPP;
};
return -EOPNOTSUPP;
}
int lan966x_tc_setup(struct net_device *dev, enum tc_setup_type type, int lan966x_tc_setup(struct net_device *dev, enum tc_setup_type type,
void *type_data) void *type_data)
{ {
...@@ -58,6 +73,8 @@ int lan966x_tc_setup(struct net_device *dev, enum tc_setup_type type, ...@@ -58,6 +73,8 @@ int lan966x_tc_setup(struct net_device *dev, enum tc_setup_type type,
return lan966x_tc_setup_qdisc_tbf(port, type_data); return lan966x_tc_setup_qdisc_tbf(port, type_data);
case TC_SETUP_QDISC_CBS: case TC_SETUP_QDISC_CBS:
return lan966x_tc_setup_qdisc_cbs(port, type_data); return lan966x_tc_setup_qdisc_cbs(port, type_data);
case TC_SETUP_QDISC_ETS:
return lan966x_tc_setup_qdisc_ets(port, type_data);
default: default:
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment