Add QoS offload support for sparx5
Subsystems (3)
Daniel Machon
maintainerv2 cover Add QoS offload support for sparx5
This patch series adds support for offloading QoS features with the tc command suite, to the sparx5 switch. The new offloadable QoS features introduced in this patch series are:
- tc-mqprio for mapping traffic class to hardware queue. Queues are by default mapped 1:1 in hardware, as such the mqprio qdisc is used as an attachment point for qdiscs tbf and ets.
$ tc qdisc add dev eth0 root handle 1:0 mqprio
- tc-tbf for setting up shaping on scheduler elements of the HSCH
(Hierarchical Scheduler) block. Shaping on either port output or
queue output is supported.
Port shaper: $ tc qdisc add dev eth0 root handle 1:0 tbf rate \
10000000 burst 8192 limit 1m
Queue shaper: $ tc qdisc replace dev eth0 parent 1:5 handle 2:0 tbf \
rate 10000000 burst 8192 limit 1m- tc-ets for setting up strict and or bandwidth-sharing bands on one through eight priority queues.
Configure a mix of strict and bw-sharing bands:
$ tc qdisc add dev eth0 handle 1: root ets bands 8 strict 5 \
quanta 1000 1000 1000 priomap 7 6 5 4 3 2 1 0
Patch #1 Sets up the tc hook.
Patch #2 Adds support for offloading the tc-mqprio qdisc. Patch #3 Adds support for offloading the tc-tbf qdisc. Patch #4 Adds support for offloading the tc-ets qdisc. Patch #5 Updates the maintainers of the sparx5 driver.
========================================================================
v1:
https://lore.kernel.org/netdev/[email protected]/
v1 -> v2:
- Fix compiler warning in patch #2
- Fix comment style in patch #4
Daniel Machon (5):
net: microchip: sparx5: add tc setup hook
net: microchip: sparx5: add support for offloading mqprio qdisc
net: microchip: sparx5: add support for offloading tbf qdisc
net: microchip: sparx5: add support for offloading ets qdisc
maintainers: update MAINTAINERS file.
MAINTAINERS | 1 + .../net/ethernet/microchip/sparx5/Makefile | 2 +- .../ethernet/microchip/sparx5/sparx5_main.c | 7 + .../microchip/sparx5/sparx5_main_regs.h | 165 ++++++ .../ethernet/microchip/sparx5/sparx5_netdev.c | 8 +- .../ethernet/microchip/sparx5/sparx5_qos.c | 514 ++++++++++++++++++ .../ethernet/microchip/sparx5/sparx5_qos.h | 82 +++ .../net/ethernet/microchip/sparx5/sparx5_tc.c | 125 +++++ .../net/ethernet/microchip/sparx5/sparx5_tc.h | 15 + 9 files changed, 917 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_qos.c create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_qos.h create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_tc.c create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_tc.h
Signature · 1 line
2.34.1
Daniel Machon
maintainerPATCH v2 1/5 net: microchip: sparx5: add tc setup hook
Add tc setup hook for QoS features.
--- .../net/ethernet/microchip/sparx5/Makefile | 2 +- .../ethernet/microchip/sparx5/sparx5_netdev.c | 2 ++ .../net/ethernet/microchip/sparx5/sparx5_tc.c | 19 +++++++++++++++++++ .../net/ethernet/microchip/sparx5/sparx5_tc.h | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_tc.c create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_tc.h
drivers/net/ethernet/microchip/sparx5/Makefile +1 -1
@@ -8,4 +8,4 @@ obj-$(CONFIG_SPARX5_SWITCH) += sparx5-switch.o sparx5-switch-objs := sparx5_main.o sparx5_packet.o \ sparx5_netdev.o sparx5_phylink.o sparx5_port.o sparx5_mactable.o sparx5_vlan.o \ sparx5_switchdev.o sparx5_calendar.o sparx5_ethtool.o sparx5_fdma.o \ - sparx5_ptp.o sparx5_pgid.o + sparx5_ptp.o sparx5_pgid.o sparx5_tc.o
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +2 -0
@@ -7,6 +7,7 @@#include "sparx5_main_regs.h" #include "sparx5_main.h" #include "sparx5_port.h" +#include "sparx5_tc.h" /* The IFH bit position of the first VSTAX bit. This is because the * VSTAX bit positions in Data sheet is starting from zero.
@@ -228,6 +229,7 @@ static const struct net_device_ops sparx5_port_netdev_ops = { .ndo_get_stats64 = sparx5_get_stats64, .ndo_get_port_parent_id = sparx5_get_port_parent_id, .ndo_eth_ioctl = sparx5_port_ioctl, + .ndo_setup_tc = sparx5_port_setup_tc, };bool sparx5_netdevice_check (const struct net_device *dev)
drivers/net/ethernet/microchip/sparx5/sparx5_tc.c new file +19 -0
@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Microchip Sparx5 Switch driver +* +* Copyright (c) 2022 Microchip Technology Inc. and its subsidiaries. +*/ + +#include "sparx5_tc.h" +#include "sparx5_main.h" + +int sparx5_port_setup_tc (struct net_device *ndev,enum tc_setup_type type, +void *type_data) +{ +switch (type) { +default : +return -EOPNOTSUPP ; + } + +return 0 ; +}
drivers/net/ethernet/microchip/sparx5/sparx5_tc.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Microchip Sparx5 Switch driver +* +* Copyright (c) 2022 Microchip Technology Inc. and its subsidiaries. +*/ + +#ifndef __SPARX5_TC_H__ +#define __SPARX5_TC_H__ + +#include <linux/netdevice.h> + +int sparx5_port_setup_tc (struct net_device *ndev,enum tc_setup_type type, +void *type_data); + +#endif /* __SPARX5_TC_H__ */
Signature · 1 line
2.34.1
Daniel Machon
maintainerPATCH v2 2/5 net: microchip: sparx5: add support for offloading mqprio qdisc
In reply to Daniel MachonAdd support for offloading mqprio qdisc to sparx5 switch.
The offloaded mqprio qdisc currently does nothing by itself, but serves as an attachment point for other qdiscs (tbf, ets etc.)
--- .../net/ethernet/microchip/sparx5/Makefile | 2 +- .../ethernet/microchip/sparx5/sparx5_netdev.c | 6 ++- .../ethernet/microchip/sparx5/sparx5_qos.c | 39 +++++++++++++++++++ .../ethernet/microchip/sparx5/sparx5_qos.h | 16 ++++++++ .../net/ethernet/microchip/sparx5/sparx5_tc.c | 16 ++++++++ 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_qos.c create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_qos.h
drivers/net/ethernet/microchip/sparx5/Makefile +1 -1
@@ -8,4 +8,4 @@ obj-$(CONFIG_SPARX5_SWITCH) += sparx5-switch.o sparx5-switch-objs := sparx5_main.o sparx5_packet.o \ sparx5_netdev.o sparx5_phylink.o sparx5_port.o sparx5_mactable.o sparx5_vlan.o \ sparx5_switchdev.o sparx5_calendar.o sparx5_ethtool.o sparx5_fdma.o \ - sparx5_ptp.o sparx5_pgid.o sparx5_tc.o + sparx5_ptp.o sparx5_pgid.o sparx5_tc.o sparx5_qos.o
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +5 -1
@@ -242,10 +242,14 @@ struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno)struct sparx5_port *spx5_port;struct net_device *ndev; - ndev =devm_alloc_etherdev (sparx5->dev,sizeof (struct sparx5_port )); + ndev =devm_alloc_etherdev_mqs (sparx5->dev,sizeof (struct sparx5_port ), +SPX5_PRIOS ,1 );if (!ndev)return ERR_PTR (-ENOMEM ); + ndev->hw_features |=NETIF_F_HW_TC ; + ndev->features |=NETIF_F_HW_TC ; +SET_NETDEV_DEV (ndev, sparx5->dev); spx5_port =netdev_priv (ndev); spx5_port->ndev = ndev;
drivers/net/ethernet/microchip/sparx5/sparx5_qos.c new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Microchip Sparx5 Switch driver +* +* Copyright (c) 2022 Microchip Technology Inc. and its subsidiaries. +*/ + +#include "sparx5_main.h" +#include "sparx5_qos.h" + +int sparx5_tc_mqprio_add (struct net_device *ndev,u8 num_tc) +{ +int i; + +if (num_tc !=SPX5_PRIOS ) { +netdev_err (ndev,"Only %d traffic classes supported\n" , +SPX5_PRIOS ); +return -EINVAL ; + } + +netdev_set_num_tc (ndev, num_tc); + +for (i =0 ; i < num_tc; i++) +netdev_set_tc_queue (ndev, i,1 , i); + +netdev_dbg (ndev,"dev->num_tc %u dev->real_num_tx_queues %u\n" , + ndev->num_tc, ndev->real_num_tx_queues); + +return 0 ; +} + +int sparx5_tc_mqprio_del (struct net_device *ndev) +{ +netdev_reset_tc (ndev); + +netdev_dbg (ndev,"dev->num_tc %u dev->real_num_tx_queues %u\n" , + ndev->num_tc, ndev->real_num_tx_queues); + +return 0 ; +}
drivers/net/ethernet/microchip/sparx5/sparx5_qos.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Microchip Sparx5 Switch driver +* +* Copyright (c) 2022 Microchip Technology Inc. and its subsidiaries. +*/ + +#ifndef __SPARX5_QOS_H__ +#define __SPARX5_QOS_H__ + +#include <linux/netdevice.h> + +/* Multi-Queue Priority */ +int sparx5_tc_mqprio_add (struct net_device *ndev,u8 num_tc); +int sparx5_tc_mqprio_del (struct net_device *ndev); + +#endif /* __SPARX5_QOS_H__ */
drivers/net/ethernet/microchip/sparx5/sparx5_tc.c +16 -0
@@ -4,13 +4,29 @@* Copyright (c) 2022 Microchip Technology Inc. and its subsidiaries. */ +#include <net/pkt_cls.h> +#include "sparx5_tc.h" #include "sparx5_main.h" +#include "sparx5_qos.h" + +static int sparx5_tc_setup_qdisc_mqprio (struct net_device *ndev, +struct tc_mqprio_qopt_offload *m) +{ + m->qopt.hw =TC_MQPRIO_HW_OFFLOAD_TCS ; + +if (m->qopt.num_tc ==0 ) +return sparx5_tc_mqprio_del (ndev); +else +return sparx5_tc_mqprio_add (ndev, m->qopt.num_tc); +}int sparx5_port_setup_tc (struct net_device *ndev,enum tc_setup_type type,void *type_data) {switch (type) { +case TC_SETUP_QDISC_MQPRIO : +return sparx5_tc_setup_qdisc_mqprio (ndev, type_data);default :return -EOPNOTSUPP ; }
Signature · 1 line
2.34.1
Daniel Machon
maintainerPATCH v2 3/5 net: microchip: sparx5: add support for offloading tbf qdisc
In reply to Daniel MachonAdd support for offloading tbf qdisc to sparx5 qdisc.
The tbf qdisc makes it possible to attach a shaper on traffic egressing from a port or a queue. Per-port tbf qdiscs are attached as a root qdisc directly and queue tbf qdiscs are attached to one of the classes of a parent qdisc (such as mqprio).
--- .../ethernet/microchip/sparx5/sparx5_main.c | 7 + .../microchip/sparx5/sparx5_main_regs.h | 150 +++++++ .../ethernet/microchip/sparx5/sparx5_qos.c | 401 ++++++++++++++++++ .../ethernet/microchip/sparx5/sparx5_qos.h | 51 +++ .../net/ethernet/microchip/sparx5/sparx5_tc.c | 39 ++ 5 files changed, 648 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +7 -0
@@ -27,6 +27,7 @@#include "sparx5_main_regs.h" #include "sparx5_main.h" #include "sparx5_port.h" +#include "sparx5_qos.h" #define QLIM_WM (fraction) \ ((SPX5_BUFFER_MEMORY / SPX5_BUFFER_CELL_SZ - 100) * (fraction) / 100)
@@ -868,6 +869,12 @@ static int mchp_sparx5_probe(struct platform_device *pdev) goto cleanup_ports; } + err =sparx5_qos_init (sparx5); +if (err) { +dev_err (sparx5->dev,"Failed to initialize QoS\n" ); + goto cleanup_ports; + } + err =sparx5_ptp_init (sparx5);if (err) {dev_err (sparx5->dev,"PTP failed\n" );
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +150 -0
162 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_qos.c +401 -0
413 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_qos.h +51 -0
59 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_tc.c +39 -0
@@ -10,6 +10,19 @@#include "sparx5_main.h" #include "sparx5_qos.h" +static void sparx5_tc_get_layer_and_idx (u32 parent,u32 portno,u32 *layer, +u32 *idx) +{ +if (parent ==TC_H_ROOT ) { + *layer =2 ; + *idx = portno; + }else { +u32 queue =TC_H_MIN (parent) -1 ; + *layer =0 ; + *idx =SPX5_HSCH_L0_GET_IDX (portno, queue); + } +} +static int sparx5_tc_setup_qdisc_mqprio (struct net_device *ndev,struct tc_mqprio_qopt_offload *m) {
@@ -21,12 +34,38 @@ static int sparx5_tc_setup_qdisc_mqprio(struct net_device *ndev,return sparx5_tc_mqprio_add (ndev, m->qopt.num_tc); } +static int sparx5_tc_setup_qdisc_tbf (struct net_device *ndev, +struct tc_tbf_qopt_offload *qopt) +{ +struct sparx5_port *port =netdev_priv (ndev); +u32 layer, se_idx; + +sparx5_tc_get_layer_and_idx (qopt->parent, port->portno, &layer, + &se_idx); + +switch (qopt->command) { +case TC_TBF_REPLACE : +return sparx5_tc_tbf_add (port, &qopt->replace_params, layer, + se_idx); +case TC_TBF_DESTROY : +return sparx5_tc_tbf_del (port, layer, se_idx); +case TC_TBF_STATS : +return -EOPNOTSUPP ; +default : +return -EOPNOTSUPP ; + } + +return -EOPNOTSUPP ; +} +int sparx5_port_setup_tc (struct net_device *ndev,enum tc_setup_type type,void *type_data) {switch (type) {case TC_SETUP_QDISC_MQPRIO :return sparx5_tc_setup_qdisc_mqprio (ndev, type_data); +case TC_SETUP_QDISC_TBF : +return sparx5_tc_setup_qdisc_tbf (ndev, type_data);default :return -EOPNOTSUPP ; }
Signature · 1 line
2.34.1
Daniel Machon
maintainerPATCH v2 4/5 net: microchip: sparx5: add support for offloading ets qdisc
In reply to Daniel MachonAdd support for offloading ets qdisc to sparx5 switch.
The ets qdisc makes it possible to configure a mix og strict and bandwidth-sharing bands. The ets qdisc must be attached as a root qdisc.
--- .../microchip/sparx5/sparx5_main_regs.h | 15 ++++ .../ethernet/microchip/sparx5/sparx5_qos.c | 73 +++++++++++++++++++ .../ethernet/microchip/sparx5/sparx5_qos.h | 15 ++++ .../net/ethernet/microchip/sparx5/sparx5_tc.c | 51 +++++++++++++ 4 files changed, 154 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +15 -0
@@ -3098,6 +3098,21 @@ enum sparx5_target {#define HSCH_SE_DLB_SENSE_SE_DLB_DPORT_ENA_GET (x)\ FIELD_GET(HSCH_SE_DLB_SENSE_SE_DLB_DPORT_ENA, x) +/* HSCH:HSCH_DWRR:DWRR_ENTRY */ +#define HSCH_DWRR_ENTRY (g) __REG(TARGET_HSCH, 0, 1, 162816, g, 72, 4, 0, 0, 1, 4) + +#define HSCH_DWRR_ENTRY_DWRR_COST GENMASK(24, 20) +#define HSCH_DWRR_ENTRY_DWRR_COST_SET (x)\ + FIELD_PREP(HSCH_DWRR_ENTRY_DWRR_COST, x) +#define HSCH_DWRR_ENTRY_DWRR_COST_GET (x)\ + FIELD_GET(HSCH_DWRR_ENTRY_DWRR_COST, x) + +#define HSCH_DWRR_ENTRY_DWRR_BALANCE GENMASK(19, 0) +#define HSCH_DWRR_ENTRY_DWRR_BALANCE_SET (x)\ + FIELD_PREP(HSCH_DWRR_ENTRY_DWRR_BALANCE, x) +#define HSCH_DWRR_ENTRY_DWRR_BALANCE_GET (x)\ + FIELD_GET(HSCH_DWRR_ENTRY_DWRR_BALANCE, x) +/* HSCH:HSCH_MISC:HSCH_CFG_CFG */ #define HSCH_HSCH_CFG_CFG __REG(TARGET_HSCH, 0, 1, 163104, 0, 1, 648, 284, 0, 1, 4)
drivers/net/ethernet/microchip/sparx5/sparx5_qos.c +73 -0
82 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_qos.h +15 -0
@@ -34,6 +34,9 @@#define SPX5_SE_BURST_MIN 1#define SPX5_SE_BURST_UNIT 4096 +/* Dwrr */ +#define SPX5_DWRR_COST_MAX 63 +struct sparx5_shaper {u32 mode;u32 rate;
@@ -51,6 +54,11 @@ struct sparx5_layer {struct sparx5_lg leak_groups[SPX5_HSCH_LEAK_GRP_CNT ]; }; +struct sparx5_dwrr { +u32 count;/* Number of inputs running dwrr */ +u8 cost[SPX5_PRIOS ]; +}; +int sparx5_qos_init (struct sparx5 *sparx5);/* Multi-Queue Priority */
@@ -64,4 +72,11 @@ int sparx5_tc_tbf_add(struct sparx5_port *port, u32 layer, u32 idx);int sparx5_tc_tbf_del (struct sparx5_port *port,u32 layer,u32 idx); +/* Enhanced Transmission Selection */ +struct tc_ets_qopt_offload_replace_params ; +int sparx5_tc_ets_add (struct sparx5_port *port, +struct tc_ets_qopt_offload_replace_params *params); + +int sparx5_tc_ets_del (struct sparx5_port *port); +#endif /* __SPARX5_QOS_H__ */
drivers/net/ethernet/microchip/sparx5/sparx5_tc.c +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.34.1
Daniel Machon
maintainerPATCH v2 5/5 maintainers: update MAINTAINERS file.
In reply to Daniel MachonUpdate Maintainers file.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -2401,6 +2401,7 @@ N: atmel ARM/Microchip Sparx5 SoC support M: Lars Povlsen <[email protected]> M: Steen Hegelund <[email protected]> +M: Daniel Machon <[email protected]> M: [email protected] L: [email protected] (moderated for non-subscribers) S: Supported
Signature · 1 line
2.34.1
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 9 lines · On Tue, 20 Sep 2022 12:14:27 +0200 you wrote:
This patch series adds support for offloading QoS features with the tc command suite, to the sparx5 switch. The new offloadable QoS features introduced in this patch series are:
- tc-mqprio for mapping traffic class to hardware queue. Queues are by default mapped 1:1 in hardware, as such the mqprio qdisc is used as an attachment point for qdiscs tbf and ets.
[...]
Here is the summary with links:
- [net-next,v2,1/5] net: microchip: sparx5: add tc setup hook
https://git.kernel.org/netdev/net-next/c/65ec1bbe0297 - [net-next,v2,2/5] net: microchip: sparx5: add support for offloading mqprio qdisc https://git.kernel.org/netdev/net-next/c/ab0e493e75bd - [net-next,v2,3/5] net: microchip: sparx5: add support for offloading tbf qdisc https://git.kernel.org/netdev/net-next/c/e02a5ac6bf77 - [net-next,v2,4/5] net: microchip: sparx5: add support for offloading ets qdisc https://git.kernel.org/netdev/net-next/c/211225428d65 - [net-next,v2,5/5] maintainers: update MAINTAINERS file. https://git.kernel.org/netdev/net-next/c/d91a6d049010
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html