Set the egress scheduler of every port in use to WFQ (weighted fair queuing) with equal weights at setup. WFQ serves all queues of a port in turn, so no queue is served before another. The chip resets every queue to strict priority. With strict priority a busy higher queue can starve the lower ones. By default every frame gets the Best Effort traffic type and uses one queue. The scheduler change therefore shows only after apptrust or the default 802.1Q priority of a port is configured. The next patch lets tc switch a user port to strict priority. No tc interface reaches the scheduler of the CPU port, so it stays on WFQ. The microchip ksz9477 family driver uses the same default. Signed-off-by: Oleksij Rempel --- drivers/net/dsa/realtek/rtl8365mb_main.c | 4 ++ drivers/net/dsa/realtek/rtl8365mb_qos.c | 90 ++++++++++++++++++++++++++++++++ drivers/net/dsa/realtek/rtl8365mb_qos.h | 1 + 3 files changed, 95 insertions(+) diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index 6c11c3631eb10f8eebdb8526908534c2256ed12d..a81ef9dfaf970f45a988a1b496c011e0824ba939 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -3199,6 +3199,10 @@ static int rtl8365mb_setup(struct dsa_switch *ds) if (ret) goto out_teardown_irq; + ret = rtl8365mb_qos_sched_init(priv); + if (ret) + goto out_teardown_irq; + /* Start with all ports blocked, including unused ports */ dsa_switch_for_each_port(dp, ds) { struct rtl8365mb_port *p = &mb->ports[dp->index]; diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.c b/drivers/net/dsa/realtek/rtl8365mb_qos.c index 5b9e1abe75c8b43b0cb6d07de0fd2ac09353f9d1..25d18cbc6fd1228fb0bf5c535b2a16548d614087 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_qos.c +++ b/drivers/net/dsa/realtek/rtl8365mb_qos.c @@ -90,6 +90,38 @@ static_assert(RTL8365MB_QOS_1Q_REMAP_REG(IEEE_8021Q_MAX_PRIORITIES - 1) < static_assert(RTL8365MB_QOS_DSCP_PRI_REG(DSCP_MAX - 1) < RTL8365MB_QOS_PORT_PRI_REG(0)); +/* Egress queue ids per port */ +#define RTL8365MB_QOS_SCHED_QIDS 8 + +/* Egress scheduler queue type: one bit per (port, queue id), two ports per + * register + */ +#define RTL8365MB_QOS_SCHED_QTYPE_PORTS_PER_REG 2 +#define RTL8365MB_QOS_SCHED_QTYPE_REG(_p) \ + (0x0302 + (_p) / RTL8365MB_QOS_SCHED_QTYPE_PORTS_PER_REG) +#define RTL8365MB_QOS_SCHED_QTYPE_BIT(_p, _qid) \ + (((_p) % RTL8365MB_QOS_SCHED_QTYPE_PORTS_PER_REG) * \ + RTL8365MB_QOS_SCHED_QIDS + (_qid)) + +#define RTL8365MB_QOS_SCHED_QTYPE_STRICT 0 +#define RTL8365MB_QOS_SCHED_QTYPE_WFQ 1 + +static_assert(RTL8365MB_QOS_SCHED_QIDS * + RTL8365MB_QOS_SCHED_QTYPE_PORTS_PER_REG <= + RTL8365MB_QOS_REG_BITS); + +/* WFQ weight of a queue: one whole register per (port, queue id) */ +#define RTL8365MB_QOS_SCHED_WFQ_WEIGHT_REG(_p, _qid) \ + (0x030c + (_p) * RTL8365MB_QOS_SCHED_QIDS + (_qid)) + +/* The unit of the WFQ weight is unknown; the driver writes the same weight to + * every queue. + */ +#define RTL8365MB_QOS_SCHED_WFQ_WEIGHT_DEFAULT 1 + +static_assert(RTL8365MB_QOS_SCHED_QTYPE_REG(RTL8365MB_QOS_MAX_PORTS - 1) < + RTL8365MB_QOS_SCHED_WFQ_WEIGHT_REG(0, 0)); + /* Priority-decision weight tables. In the driver's model of the decision * hardware, a source ranks by its highest set weight bit (a one-hot rank), not * by numeric magnitude. A weight of zero disables the source. @@ -294,6 +326,8 @@ static int rtl8365mb_qos_set_qmap_qid(struct realtek_priv *priv, int qmap, */ #define RTL8365MB_QOS_QID_TOP 7 +static_assert(RTL8365MB_QOS_QID_TOP < RTL8365MB_QOS_SCHED_QIDS); + static u8 rtl8365mb_qos_tc_to_qid(unsigned int num_queues, u8 tc) { if (num_queues > 1 && tc == num_queues - 1) @@ -334,6 +368,62 @@ int rtl8365mb_qos_qmap_init(struct realtek_priv *priv) return 0; } +static int rtl8365mb_qos_write_port_sched(struct realtek_priv *priv, int port, + unsigned int num_queues) +{ + u32 weight = RTL8365MB_QOS_SCHED_WFQ_WEIGHT_DEFAULT; + unsigned int tc; + u32 qtype; + int ret; + u32 reg; + + if (!num_queues || num_queues > RTL8365MB_QOS_SCHED_QIDS) + return -EINVAL; + + reg = RTL8365MB_QOS_SCHED_QTYPE_REG(port); + qtype = RTL8365MB_QOS_SCHED_QTYPE_WFQ; + + /* Program the queue ids that the traffic-type-to-queue map uses */ + for (tc = 0; tc < num_queues; tc++) { + u32 mask; + u32 wreg; + u8 qid; + + qid = rtl8365mb_qos_tc_to_qid(num_queues, tc); + mask = BIT(RTL8365MB_QOS_SCHED_QTYPE_BIT(port, qid)); + wreg = RTL8365MB_QOS_SCHED_WFQ_WEIGHT_REG(port, qid); + + ret = regmap_write(priv->map, wreg, weight); + if (ret) + return ret; + + ret = rtl8365mb_qos_regmap_update_field(priv, reg, mask, qtype); + if (ret) + return ret; + } + + return 0; +} + +/* The chip resets every queue to strict priority. Put the ports in use on + * WFQ with equal weights. + */ +int rtl8365mb_qos_sched_init(struct realtek_priv *priv) +{ + unsigned int nq = priv->ds.num_tx_queues; + struct dsa_port *dp; + int ret; + + /* Unused ports carry no traffic; their scheduler is left alone */ + dsa_switch_for_each_available_port(dp, &priv->ds) { + ret = rtl8365mb_qos_write_port_sched(priv, dp->index, nq); + if (ret) + return ret; + } + + return 0; +} + static int rtl8365mb_qos_set_pridec(struct realtek_priv *priv, int table, int src, u8 weight) { diff --git a/drivers/net/dsa/realtek/rtl8365mb_qos.h b/drivers/net/dsa/realtek/rtl8365mb_qos.h index 9602807f7db5b9c5bf0202612e4cd77b85079cb7..1daeee16e47294dead49b0843a863991de9731cd 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_qos.h +++ b/drivers/net/dsa/realtek/rtl8365mb_qos.h @@ -19,6 +19,7 @@ struct realtek_priv; int rtl8365mb_qos_pridec_init(struct realtek_priv *priv); int rtl8365mb_qos_qmap_init(struct realtek_priv *priv); +int rtl8365mb_qos_sched_init(struct realtek_priv *priv); int rtl8365mb_qos_get_port_prio(struct realtek_priv *priv, int port); int rtl8365mb_qos_set_port_prio(struct realtek_priv *priv, int port, u8 iprio, u8 untag_pcp); -- 2.47.3