net: ethernet: am65-cpsw: Add mqprio, frame pre-emption & coalescing
Subsystems (2)
v5 cover net: ethernet: am65-cpsw: Add mqprio, frame pre-emption & coalescing
Hi,
This series adds mqprio qdisc offload in channel mode, Frame Pre-emption MAC merge support and RX/TX coalesing for AM65 CPSW driver.
Comparted to v4, this series picks up the coalesing patch.
Changelog information in each patch file.
cheers,
-roger
Grygorii Strashko (2):
net: ethernet: ti: am65-cpsw: add mqprio qdisc offload in channel mode
net: ethernet: ti: am65-cpsw: add sw tx/rx irq coalescing based on
hrtimers
Roger Quadros (2):
net: ethernet: ti: am65-cpsw: Move code to avoid forward declaration
net: ethernet: ti: am65-cpsw-qos: Add Frame Preemption MAC Merge
support
drivers/net/ethernet/ti/am65-cpsw-ethtool.c | 229 ++++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.c | 61 ++- drivers/net/ethernet/ti/am65-cpsw-nuss.h | 9 + drivers/net/ethernet/ti/am65-cpsw-qos.c | 550 +++++++++++++++++--- drivers/net/ethernet/ti/am65-cpsw-qos.h | 112 ++++ 5 files changed, 879 insertions(+), 82 deletions(-)
base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
Signature · 1 line
2.34.1
PATCH v5 1/4 net: ethernet: ti: am65-cpsw: Move code to avoid forward declaration
Move this code to the end to avoid forward declaration. No functional change.
--- drivers/net/ethernet/ti/am65-cpsw-qos.c | 78 ++++++++++++------------- 1 file changed, 39 insertions(+), 39 deletions(-)
Changelog:
v5: no change
v4: initial commit
drivers/net/ethernet/ti/am65-cpsw-qos.c +39 -39
@@ -787,45 +787,6 @@ static int am65_cpsw_qos_setup_tc_block(struct net_device *ndev, struct flow_blo port, port, true); } -int am65_cpsw_qos_ndo_setup_tc (struct net_device *ndev,enum tc_setup_type type, -void *type_data) -{ -switch (type) { -case TC_QUERY_CAPS : -return am65_cpsw_tc_query_caps (ndev, type_data); -case TC_SETUP_QDISC_TAPRIO : -return am65_cpsw_setup_taprio (ndev, type_data); -case TC_SETUP_BLOCK : -return am65_cpsw_qos_setup_tc_block (ndev, type_data); -default : -return -EOPNOTSUPP ; - } -} - -void am65_cpsw_qos_link_up (struct net_device *ndev,int link_speed) -{ -struct am65_cpsw_port *port =am65_ndev_to_port (ndev); - -if (!IS_ENABLED (CONFIG_TI_AM65_CPSW_TAS )) -return ; - -am65_cpsw_est_link_up (ndev, link_speed); - port->qos.link_down_time =0 ; -} - -void am65_cpsw_qos_link_down (struct net_device *ndev) -{ -struct am65_cpsw_port *port =am65_ndev_to_port (ndev); - -if (!IS_ENABLED (CONFIG_TI_AM65_CPSW_TAS )) -return ; - -if (!port->qos.link_down_time) - port->qos.link_down_time =ktime_get (); - - port->qos.link_speed =SPEED_UNKNOWN ; -} -static u32 am65_cpsw_qos_tx_rate_calc (u32 rate_mbps,unsigned long bus_freq) {
@@ -937,3 +898,42 @@ void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) host->port_base + AM65_CPSW_PN_REG_PRI_CIR(tx_ch)); } } + +int am65_cpsw_qos_ndo_setup_tc (struct net_device *ndev,enum tc_setup_type type, +void *type_data) +{ +switch (type) { +case TC_QUERY_CAPS : +return am65_cpsw_tc_query_caps (ndev, type_data); +case TC_SETUP_QDISC_TAPRIO : +return am65_cpsw_setup_taprio (ndev, type_data); +case TC_SETUP_BLOCK : +return am65_cpsw_qos_setup_tc_block (ndev, type_data); +default : +return -EOPNOTSUPP ; + } +} + +void am65_cpsw_qos_link_up (struct net_device *ndev,int link_speed) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); + +if (!IS_ENABLED (CONFIG_TI_AM65_CPSW_TAS )) +return ; + +am65_cpsw_est_link_up (ndev, link_speed); + port->qos.link_down_time =0 ; +} + +void am65_cpsw_qos_link_down (struct net_device *ndev) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); + +if (!IS_ENABLED (CONFIG_TI_AM65_CPSW_TAS )) +return ; + +if (!port->qos.link_down_time) + port->qos.link_down_time =ktime_get (); + + port->qos.link_speed =SPEED_UNKNOWN ; +}
Signature · 1 line
2.34.1
PATCH v5 2/4 net: ethernet: ti: am65-cpsw: add mqprio qdisc offload in channel mode
In reply to Roger QuadrosFrom: Grygorii Strashko <[email protected]>
This patch adds MQPRIO Qdisc offload in full 'channel' mode which allows not only setting up pri:tc mapping, but also configuring TX shapers (rate-limiting) on external port FIFOs.
The MQPRIO Qdisc offload is expected to work with or without VLAN/priority tagged packets.
The CPSW external Port FIFO has 8 Priority queues. The rate-limit can be set for each of these priority queues. Which Priority queue a packet is assigned to depends on PN_REG_TX_PRI_MAP register which maps header priority to switch priority.
The header priority of a packet is assigned via the RX_PRI_MAP_REG which maps packet priority to header priority.
The packet priority is either the VLAN priority (for VLAN tagged packets) or the thread/channel offset.
For simplicity, we assign the same priority queue to all queues of a Traffic Class so it can be rate-limited correctly.
Configuration example:
ethtool -L eth1 tx 5
ethtool --set-priv-flags eth1 p0-rx-ptype-rrobin off
tc qdisc add dev eth1 parent root handle 100: mqprio num_tc 3 \
map 0 0 1 2 0 0 0 0 0 0 0 0 0 0 0 0 \
queues 1@0 1@1 1@2 hw 1 mode channel \
shaper bw_rlimit min_rate 0 100mbit 200mbit max_rate 0 101mbit 202mbit
tc qdisc replace dev eth2 handle 100: parent root mqprio num_tc 1 \
map 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 queues 1@0 hw 1
ip link add link eth1 name eth1.100 type vlan id 100
ip link set eth1.100 type vlan egress 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
In the above example two ports share the same TX CPPI queue 0 for low priority traffic. 3 traffic classes are defined for eth1 and mapped to:
TC0 - low priority, TX CPPI queue 0 -> ext Port 1 fifo0, no rate limit TC1 - prio 2, TX CPPI queue 1 -> ext Port 1 fifo1, CIR=100Mbit/s, EIR=1Mbit/s TC2 - prio 3, TX CPPI queue 2 -> ext Port 1 fifo2, CIR=200Mbit/s, EIR=2Mbit/s
--- drivers/net/ethernet/ti/am65-cpsw-qos.c | 262 +++++++++++++++++++++++- drivers/net/ethernet/ti/am65-cpsw-qos.h | 8 + 2 files changed, 267 insertions(+), 3 deletions(-)
Changelog:
v5:
- fix warning at NL_SET_ERR_MSG_FMT_MOD()
v4:
- use macro TO_MBPS()
- use bool for 'shaper_en'
- split code movement into separate patch
- drop rate vs link speed check as mqprio can be set at link down
- call am65_cpsw_reset_tc_mqprio() after pm_runtime_get_sync()
v2:
- clean up commit message
- avoid forward declarations
- use tc_mqprio_qopt_offload :: extack for error message reporting
- avoid unnecessary mqprio->qopt.hw == 0 checks
- set struct tc_mqprio_caps :: validate_queue_counts = true and get rid of am65_cpsw_mqprio_verify()
- do not modify AM65_CPSW_P0_REG_RX_PRI_MAP register.
drivers/net/ethernet/ti/am65-cpsw-qos.c +259 -3
@@ -16,10 +16,19 @@#include "cpsw_ale.h" #define AM65_CPSW_REG_CTL 0x004 +#define AM65_CPSW_P0_REG_TX_PRI_MAP 0x018 +#define AM65_CPSW_P0_REG_RX_PRI_MAP 0x020 +#define AM65_CPSW_P0_REG_FIFO_STATUS 0x050 +#define AM65_CPSW_P0_REG_PRI_CIR (pri) (0x140 + 4 * (pri)) +#define AM65_CPSW_P0_REG_PRI_EIR (pri) (0x160 + 4 * (pri)) +#define AM65_CPSW_PN_REG_CTL 0x004 +#define AM65_CPSW_PN_REG_TX_PRI_MAP 0x018 +#define AM65_CPSW_PN_REG_RX_PRI_MAP 0x020#define AM65_CPSW_PN_REG_FIFO_STATUS 0x050#define AM65_CPSW_PN_REG_EST_CTL 0x060#define AM65_CPSW_PN_REG_PRI_CIR (pri) (0x140 + 4 * (pri)) +#define AM65_CPSW_PN_REG_PRI_EIR (pri) (0x160 + 4 * (pri))/* AM65_CPSW_REG_CTL register fields */ #define AM65_CPSW_CTL_EST_EN BIT(18)
@@ -50,12 +59,18 @@#define AM65_CPSW_FETCH_ALLOW_MSK GENMASK(7, 0)#define AM65_CPSW_FETCH_ALLOW_MAX AM65_CPSW_FETCH_ALLOW_MSK +#define TO_MBPS (x) ((x) * 8 / 1000000) +enum timer_act {TACT_PROG ,/* need program timer */ TACT_NEED_STOP ,/* need stop first */ TACT_SKIP_PROG ,/* just buffer can be updated */ }; +/* number of priority queues per port FIFO */ +#define AM65_CPSW_PN_FIFO_PRIO_NUM 8 +#define AM65_CPSW_PN_TX_PRI_MAP_DEFAULT 0x76543210 +static int am65_cpsw_port_est_enabled (struct am65_cpsw_port *port) {return port->qos.est_oper || port->qos.est_admin;
@@ -541,7 +556,6 @@ static void am65_cpsw_est_link_up(struct net_device *ndev, int link_speed)ktime_t cur_time;s64 delta; - port->qos.link_speed = link_speed;if (!am65_cpsw_port_est_enabled (port))return ;
@@ -596,6 +610,14 @@ static int am65_cpsw_tc_query_caps(struct net_device *ndev, void *type_data)struct tc_query_caps_base *base = type_data;switch (base->type) { +case TC_SETUP_QDISC_MQPRIO : { +struct tc_mqprio_caps *caps = base->caps; + + caps->validate_queue_counts = true; + +return 0 ; + } +case TC_SETUP_QDISC_TAPRIO : {struct tc_taprio_caps *caps = base->caps;
@@ -899,6 +921,234 @@ void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) } } +static void am65_cpsw_tx_pn_shaper_reset (struct am65_cpsw_port *port) +{ +int prio; + +for (prio =0 ; prio <AM65_CPSW_PN_FIFO_PRIO_NUM ; prio++) { +writel (0 , port->port_base +AM65_CPSW_PN_REG_PRI_CIR (prio)); +writel (0 , port->port_base +AM65_CPSW_PN_REG_PRI_EIR (prio)); + } +} + +static void am65_cpsw_tx_pn_shaper_apply (struct am65_cpsw_port *port) +{ +struct am65_cpsw_mqprio *p_mqprio = &port->qos.mqprio; +struct am65_cpsw_common *common = port->common; +struct tc_mqprio_qopt_offload *mqprio; +bool enable, shaper_susp = false; +u32 rate_mbps; +int tc, prio; + + mqprio = &p_mqprio->mqprio_hw; +/* takes care of no link case as well */ +if (p_mqprio->max_rate_total > port->qos.link_speed) + shaper_susp = true; + +am65_cpsw_tx_pn_shaper_reset (port); + + enable = p_mqprio->shaper_en && !shaper_susp; +if (!enable) +return ; + +/* Rate limit is specified per Traffic Class but +* for CPSW, rate limit can be applied per priority +* at port FIFO. +* +* We have assigned the same priority (TCn) to all queues +* of a Traffic Class so they share the same shaper +* bandwidth. +*/ +for (tc =0 ; tc < mqprio->qopt.num_tc; tc++) { + prio = tc; + + rate_mbps =TO_MBPS (mqprio->min_rate[tc]); + rate_mbps =am65_cpsw_qos_tx_rate_calc (rate_mbps, + common->bus_freq); +writel (rate_mbps, + port->port_base +AM65_CPSW_PN_REG_PRI_CIR (prio)); + + rate_mbps =0 ; + +if (mqprio->max_rate[tc]) { + rate_mbps = mqprio->max_rate[tc] - mqprio->min_rate[tc]; + rate_mbps =TO_MBPS (rate_mbps); + rate_mbps =am65_cpsw_qos_tx_rate_calc (rate_mbps, + common->bus_freq); + } + +writel (rate_mbps, + port->port_base +AM65_CPSW_PN_REG_PRI_EIR (prio)); + } +} + +static int am65_cpsw_mqprio_verify_shaper (struct am65_cpsw_port *port, +struct tc_mqprio_qopt_offload *mqprio) +{ +struct am65_cpsw_mqprio *p_mqprio = &port->qos.mqprio; +struct netlink_ext_ack *extack = mqprio->extack; +u64 min_rate_total =0 , max_rate_total =0 ; +u32 min_rate_msk =0 , max_rate_msk =0 ; +bool has_min_rate, has_max_rate; +int num_tc, i; + +if (!(mqprio->flags &TC_MQPRIO_F_SHAPER )) +return 0 ; + +if (mqprio->shaper !=TC_MQPRIO_SHAPER_BW_RATE ) +return 0 ; + + has_min_rate = !!(mqprio->flags &TC_MQPRIO_F_MIN_RATE ); + has_max_rate = !!(mqprio->flags &TC_MQPRIO_F_MAX_RATE ); + +if (!has_min_rate && has_max_rate) { +NL_SET_ERR_MSG_MOD (extack,"min_rate is required with max_rate" ); +return -EOPNOTSUPP ; + } + +if (!has_min_rate) +return 0 ; + + num_tc = mqprio->qopt.num_tc; + +for (i = num_tc -1 ; i >=0 ; i--) { +u32 ch_msk; + +if (mqprio->min_rate[i]) + min_rate_msk |=BIT (i); + min_rate_total += mqprio->min_rate[i]; + +if (has_max_rate) { +if (mqprio->max_rate[i]) + max_rate_msk |=BIT (i); + max_rate_total += mqprio->max_rate[i]; + +if (!mqprio->min_rate[i] && mqprio->max_rate[i]) { +NL_SET_ERR_MSG_FMT_MOD (extack, +"TX tc%d rate max>0 but min=0\n" , + i); +return -EINVAL ; + } + +if (mqprio->max_rate[i] && + mqprio->max_rate[i] < mqprio->min_rate[i]) { +NL_SET_ERR_MSG_FMT_MOD (extack, +"TX tc%d rate min(%llu)>max(%llu)\n" , + i, mqprio->min_rate[i], + mqprio->max_rate[i]); +return -EINVAL ; + } + } + + ch_msk =GENMASK (num_tc -1 , i); +if ((min_rate_msk &BIT (i)) && (min_rate_msk ^ ch_msk)) { +NL_SET_ERR_MSG_FMT_MOD (extack, +"Min rate must be set sequentially hi->lo tx_rate_msk%x\n" , + min_rate_msk); +return -EINVAL ; + } + +if ((max_rate_msk &BIT (i)) && (max_rate_msk ^ ch_msk)) { +NL_SET_ERR_MSG_FMT_MOD (extack, +"Max rate must be set sequentially hi->lo tx_rate_msk%x\n" , + max_rate_msk); +return -EINVAL ; + } + } + + min_rate_total =TO_MBPS (min_rate_total); + max_rate_total =TO_MBPS (max_rate_total); + + p_mqprio->shaper_en = true; + p_mqprio->max_rate_total =max_t (u64, min_rate_total, max_rate_total); + +return 0 ; +} + +static void am65_cpsw_reset_tc_mqprio (struct net_device *ndev) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_mqprio *p_mqprio = &port->qos.mqprio; +struct am65_cpsw_common *common = port->common; + + p_mqprio->shaper_en = false; + p_mqprio->max_rate_total =0 ; + +am65_cpsw_tx_pn_shaper_reset (port); +netdev_reset_tc (ndev); +netif_set_real_num_tx_queues (ndev, common->tx_ch_num); + +/* Reset all Queue priorities to 0 */ +writel (0 , port->port_base +AM65_CPSW_PN_REG_TX_PRI_MAP ); +} + +static int am65_cpsw_setup_mqprio (struct net_device *ndev,void *type_data) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_mqprio *p_mqprio = &port->qos.mqprio; +struct tc_mqprio_qopt_offload *mqprio = type_data; +struct am65_cpsw_common *common = port->common; +struct tc_mqprio_qopt *qopt = &mqprio->qopt; +int tc, offset, count, ret, prio; +u8 num_tc = qopt->num_tc; +u32 tx_prio_map =0 ; +int i; + +memcpy (&p_mqprio->mqprio_hw, mqprio,sizeof (*mqprio)); + + ret =pm_runtime_get_sync (common->dev); +if (ret <0 ) { +pm_runtime_put_noidle (common->dev); +return ret; + } + +if (!num_tc) { +am65_cpsw_reset_tc_mqprio (ndev); + goto exit_put; + } + + ret =am65_cpsw_mqprio_verify_shaper (port, mqprio); +if (ret) + goto exit_put; + +netdev_set_num_tc (ndev, num_tc); + +/* Multiple Linux priorities can map to a Traffic Class +* A Traffic Class can have multiple contiguous Queues, +* Queues get mapped to Channels (thread_id), +* if not VLAN tagged, thread_id is used as packet_priority +* if VLAN tagged. VLAN priority is used as packet_priorit +* packet_priority gets mapped to header_priority in p0_rx_pri_map, +* header_priority gets mapped to switch_priority in pn_tx_pri_map. +* As p0_rx_pri_map is left at defaults (0x76543210), we can +* assume that Queue_n gets mapped to header_priority_n. We can then +* set the switch priority in pn_tx_pri_map. +*/ + +for (tc =0 ; tc < num_tc; tc++) { + prio = tc; + +/* For simplicity we assign the same priority (TCn) to +* all queues of a Traffic Class. +*/ +for (i = qopt->offset[tc]; i < qopt->offset[tc] + qopt->count[tc]; i++) + tx_prio_map |= prio << (4 * i); + + count = qopt->count[tc]; + offset = qopt->offset[tc]; +netdev_set_tc_queue (ndev, tc, count, offset); + } + +writel (tx_prio_map, + port->port_base +AM65_CPSW_PN_REG_TX_PRI_MAP ); + +am65_cpsw_tx_pn_shaper_apply (port); + +exit_put: +pm_runtime_put (common->dev); +return 0 ; +} +int am65_cpsw_qos_ndo_setup_tc (struct net_device *ndev,enum tc_setup_type type,void *type_data) {
@@ -907,6 +1157,8 @@ int am65_cpsw_qos_ndo_setup_tc(struct net_device *ndev, enum tc_setup_type type,return am65_cpsw_tc_query_caps (ndev, type_data);case TC_SETUP_QDISC_TAPRIO :return am65_cpsw_setup_taprio (ndev, type_data); +case TC_SETUP_QDISC_MQPRIO : +return am65_cpsw_setup_mqprio (ndev, type_data);case TC_SETUP_BLOCK :return am65_cpsw_qos_setup_tc_block (ndev, type_data);default :
@@ -918,6 +1170,9 @@ void am65_cpsw_qos_link_up(struct net_device *ndev, int link_speed) {struct am65_cpsw_port *port =am65_ndev_to_port (ndev); + port->qos.link_speed = link_speed; +am65_cpsw_tx_pn_shaper_apply (port); +if (!IS_ENABLED (CONFIG_TI_AM65_CPSW_TAS ))return ;
@@ -929,11 +1184,12 @@ void am65_cpsw_qos_link_down(struct net_device *ndev) {struct am65_cpsw_port *port =am65_ndev_to_port (ndev); + port->qos.link_speed =SPEED_UNKNOWN ; +am65_cpsw_tx_pn_shaper_apply (port); +if (!IS_ENABLED (CONFIG_TI_AM65_CPSW_TAS ))return ;if (!port->qos.link_down_time) port->qos.link_down_time =ktime_get (); - - port->qos.link_speed =SPEED_UNKNOWN ; }
drivers/net/ethernet/ti/am65-cpsw-qos.h +8 -0
@@ -9,6 +9,7 @@#include <net/pkt_sched.h> struct am65_cpsw_common ; +struct am65_cpsw_port ;struct am65_cpsw_est {int buf;
@@ -16,6 +17,12 @@ struct am65_cpsw_est {struct tc_taprio_qopt_offload taprio; }; +struct am65_cpsw_mqprio { +struct tc_mqprio_qopt_offload mqprio_hw; +u64 max_rate_total; +bool shaper_en; +}; +struct am65_cpsw_ale_ratelimit {unsigned long cookie;u64 rate_packet_ps;
@@ -26,6 +33,7 @@ struct am65_cpsw_qos {struct am65_cpsw_est *est_oper;ktime_t link_down_time;int link_speed; +struct am65_cpsw_mqprio mqprio;struct am65_cpsw_ale_ratelimit ale_bc_ratelimit;struct am65_cpsw_ale_ratelimit ale_mc_ratelimit;
Signature · 1 line
2.34.1
Simon Horman
reviewerRe: [PATCH v5 net-next 2/4] net: ethernet: ti: am65-cpsw: add mqprio qdisc offload in channel mode
On Wed, Sep 27, 2023 at 10:27:39AM +0300, Roger Quadros wrote:
...
Quoted 26 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +26
-0+static int am65_cpsw_setup_mqprio (struct net_device *ndev,void *type_data) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_mqprio *p_mqprio = &port->qos.mqprio; +struct tc_mqprio_qopt_offload *mqprio = type_data; +struct am65_cpsw_common *common = port->common; +struct tc_mqprio_qopt *qopt = &mqprio->qopt; +int tc, offset, count, ret, prio; +u8 num_tc = qopt->num_tc; +u32 tx_prio_map =0 ; +int i; + +memcpy (&p_mqprio->mqprio_hw, mqprio,sizeof (*mqprio)); + + ret =pm_runtime_get_sync (common->dev); +if (ret <0 ) { +pm_runtime_put_noidle (common->dev); +return ret; + } + +if (!num_tc) { +am65_cpsw_reset_tc_mqprio (ndev); + goto exit_put; + } + + ret =am65_cpsw_mqprio_verify_shaper (port, mqprio);
drivers/net/ethernet/ti/am65-cpsw-qos.c void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) · line 1120
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +10
-0+if (ret) + goto exit_put; + +netdev_set_num_tc (ndev, num_tc); + +/* Multiple Linux priorities can map to a Traffic Class +* A Traffic Class can have multiple contiguous Queues, +* Queues get mapped to Channels (thread_id), +* if not VLAN tagged, thread_id is used as packet_priority +* if VLAN tagged. VLAN priority is used as packet_priorit
Hi,
I don't think it is worth respinning just because of this, but there seems to be a 'y' missing from the end of the line above.
Quoted 6 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +6
-0+* packet_priority gets mapped to header_priority in p0_rx_pri_map, +* header_priority gets mapped to switch_priority in pn_tx_pri_map. +* As p0_rx_pri_map is left at defaults (0x76543210), we can +* assume that Queue_n gets mapped to header_priority_n. We can then +* set the switch priority in pn_tx_pri_map. +*/
...
Re: [PATCH v5 net-next 2/4] net: ethernet: ti: am65-cpsw: add mqprio qdisc offload in channel mode
Quoted 43 lines · Simon Horman
On Wed, Sep 27, 2023 at 10:27:39AM +0300, Roger Quadros wrote:
...
Quoted 26 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +26
-0+static int am65_cpsw_setup_mqprio (struct net_device *ndev,void *type_data) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_mqprio *p_mqprio = &port->qos.mqprio; +struct tc_mqprio_qopt_offload *mqprio = type_data; +struct am65_cpsw_common *common = port->common; +struct tc_mqprio_qopt *qopt = &mqprio->qopt; +int tc, offset, count, ret, prio; +u8 num_tc = qopt->num_tc; +u32 tx_prio_map =0 ; +int i; + +memcpy (&p_mqprio->mqprio_hw, mqprio,sizeof (*mqprio)); + + ret =pm_runtime_get_sync (common->dev); +if (ret <0 ) { +pm_runtime_put_noidle (common->dev); +return ret; + } + +if (!num_tc) { +am65_cpsw_reset_tc_mqprio (ndev); + goto exit_put;am65_cpsw_iet_commit_preemptible_tcs + } + + ret =am65_cpsw_mqprio_verify_shaper (port, mqprio);drivers/net/ethernet/ti/am65-cpsw-qos.c void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) · line 1120
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +10
-0+if (ret) + goto exit_put; + +netdev_set_num_tc (ndev, num_tc); + +/* Multiple Linux priorities can map to a Traffic Class +* A Traffic Class can have multiple contiguous Queues, +* Queues get mapped to Channels (thread_id), +* if not VLAN tagged, thread_id is used as packet_priority +* if VLAN tagged. VLAN priority is used as packet_priorit Hi,
Quoted 2 lines
I don't think it is worth respinning just because of this, but there seems to be a 'y' missing from the end of the line above.
Now that there will be a re-spin. I'll fix this. Thanks!
Quoted 9 lines
Quoted 7 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +6
-0+* packet_priority gets mapped to header_priority in p0_rx_pri_map, +* header_priority gets mapped to switch_priority in pn_tx_pri_map. +* As p0_rx_pri_map is left at defaults (0x76543210), we can +* assume that Queue_n gets mapped to header_priority_n. We can then +* set the switch priority in pn_tx_pri_map. +*/ ...
Signature · 2 lines
cheers, -roger
Re: [PATCH v5 net-next 2/4] net: ethernet: ti: am65-cpsw: add mqprio qdisc offload in channel mode
In reply to Roger QuadrosQuoted 42 lines · Roger Quadros
drivers/net/ethernet/ti/am65-cpsw-qos.c +16
-0@@ -16,10 +16,19 @@#include "cpsw_ale.h" #define AM65_CPSW_REG_CTL 0x004 +#define AM65_CPSW_P0_REG_TX_PRI_MAP 0x018 +#define AM65_CPSW_P0_REG_RX_PRI_MAP 0x020 +#define AM65_CPSW_P0_REG_FIFO_STATUS 0x050 +#define AM65_CPSW_P0_REG_PRI_CIR (pri) (0x140 + 4 * (pri)) +#define AM65_CPSW_P0_REG_PRI_EIR (pri) (0x160 + 4 * (pri)) +#define AM65_CPSW_PN_REG_CTL 0x004 +#define AM65_CPSW_PN_REG_TX_PRI_MAP 0x018 +#define AM65_CPSW_PN_REG_RX_PRI_MAP 0x020#define AM65_CPSW_PN_REG_FIFO_STATUS 0x050#define AM65_CPSW_PN_REG_EST_CTL 0x060#define AM65_CPSW_PN_REG_PRI_CIR (pri) (0x140 + 4 * (pri)) +#define AM65_CPSW_PN_REG_PRI_EIR (pri) (0x160 + 4 * (pri))/* AM65_CPSW_REG_CTL register fields */ #define AM65_CPSW_CTL_EST_EN BIT(18)@@ -50,12 +59,18 @@#define AM65_CPSW_FETCH_ALLOW_MSK GENMASK(7, 0)#define AM65_CPSW_FETCH_ALLOW_MAX AM65_CPSW_FETCH_ALLOW_MSK +#define TO_MBPS (x) ((x) * 8 / 1000000) +enum timer_act {TACT_PROG ,/* need program timer */ TACT_NEED_STOP ,/* need stop first */ TACT_SKIP_PROG ,/* just buffer can be updated */ }; +/* number of priority queues per port FIFO */ +#define AM65_CPSW_PN_FIFO_PRIO_NUM 8 +#define AM65_CPSW_PN_TX_PRI_MAP_DEFAULT 0x76543210 +static void am65_cpsw_reset_tc_mqprio (struct net_device *ndev) +{
drivers/net/ethernet/ti/am65-cpsw-qos.c
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +10
-0+struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_mqprio *p_mqprio = &port->qos.mqprio; +struct am65_cpsw_common *common = port->common; + + p_mqprio->shaper_en = false; + p_mqprio->max_rate_total =0 ; + +am65_cpsw_tx_pn_shaper_reset (port); +netdev_reset_tc (ndev); +netif_set_real_num_tx_queues (ndev, common->tx_ch_num);
If this never gets changed from the value set by am65_cpsw_nuss_ndo_slave_open(), then there is no reason to call netif_set_real_num_tx_queues() here.
drivers/net/ethernet/ti/am65-cpsw-qos.c void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) · line 1082
Quoted 3 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +3
-0+ +/* Reset all Queue priorities to 0 */ +writel (0 , port->port_base +AM65_CPSW_PN_REG_TX_PRI_MAP );
To 0 or to AM65_CPSW_PN_TX_PRI_MAP_DEFAULT (which is now unused)? Also, do I understand correctly that immediately after boot, TX_PRI_MAP will have a different value than after the deletion of the mqprio root qdisc (if AM65_CPSW_PN_TX_PRI_MAP_DEFAULT represents the hardware default value)? The behavior needs to be identical in the 2 cases, since both represent "no mqprio offload".
Quoted 20 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +20
-0+} + +static int am65_cpsw_setup_mqprio (struct net_device *ndev,void *type_data) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_mqprio *p_mqprio = &port->qos.mqprio; +struct tc_mqprio_qopt_offload *mqprio = type_data; +struct am65_cpsw_common *common = port->common; +struct tc_mqprio_qopt *qopt = &mqprio->qopt; +int tc, offset, count, ret, prio; +u8 num_tc = qopt->num_tc; +u32 tx_prio_map =0 ; +int i; + +memcpy (&p_mqprio->mqprio_hw, mqprio,sizeof (*mqprio)); + + ret =pm_runtime_get_sync (common->dev); +if (ret <0 ) { +pm_runtime_put_noidle (common->dev); +return ret;
drivers/net/ethernet/ti/am65-cpsw-qos.c void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) · line 1112
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +10
-0+ } + +if (!num_tc) { +am65_cpsw_reset_tc_mqprio (ndev); + goto exit_put; + } + + ret =am65_cpsw_mqprio_verify_shaper (port, mqprio); +if (ret) + goto exit_put;
At "exit_put" we have "return 0" and this discards the value of "ret".
Quoted 18 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +18
-0+ +netdev_set_num_tc (ndev, num_tc); + +/* Multiple Linux priorities can map to a Traffic Class +* A Traffic Class can have multiple contiguous Queues, +* Queues get mapped to Channels (thread_id), +* if not VLAN tagged, thread_id is used as packet_priority +* if VLAN tagged. VLAN priority is used as packet_priorit +* packet_priority gets mapped to header_priority in p0_rx_pri_map, +* header_priority gets mapped to switch_priority in pn_tx_pri_map. +* As p0_rx_pri_map is left at defaults (0x76543210), we can +* assume that Queue_n gets mapped to header_priority_n. We can then +* set the switch priority in pn_tx_pri_map. +*/ + +for (tc =0 ; tc < num_tc; tc++) { + prio = tc; +
drivers/net/ethernet/ti/am65-cpsw-qos.c void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) · line 1140
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +10
-0+/* For simplicity we assign the same priority (TCn) to +* all queues of a Traffic Class. +*/ +for (i = qopt->offset[tc]; i < qopt->offset[tc] + qopt->count[tc]; i++) + tx_prio_map |= prio << (4 * i); + + count = qopt->count[tc]; + offset = qopt->offset[tc]; +netdev_set_tc_queue (ndev, tc, count, offset); + }
I think this is okay.
drivers/net/ethernet/ti/am65-cpsw-qos.c void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) · line 1143
Quoted 3 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +3
-0+ +writel (tx_prio_map, + port->port_base +AM65_CPSW_PN_REG_TX_PRI_MAP );
Nit: This can be written on a single line.
Quoted 11 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +8
-0+ +am65_cpsw_tx_pn_shaper_apply (port); + +exit_put: +pm_runtime_put (common->dev); +return 0 ; +} +int am65_cpsw_qos_ndo_setup_tc (struct net_device *ndev,enum tc_setup_type type,void *type_data) {
Re: [PATCH v5 net-next 2/4] net: ethernet: ti: am65-cpsw: add mqprio qdisc offload in channel mode
Quoted 57 lines · Vladimir Oltean
Quoted 42 lines · Roger Quadros
drivers/net/ethernet/ti/am65-cpsw-qos.c +16
-0@@ -16,10 +16,19 @@#include "cpsw_ale.h" #define AM65_CPSW_REG_CTL 0x004 +#define AM65_CPSW_P0_REG_TX_PRI_MAP 0x018 +#define AM65_CPSW_P0_REG_RX_PRI_MAP 0x020 +#define AM65_CPSW_P0_REG_FIFO_STATUS 0x050 +#define AM65_CPSW_P0_REG_PRI_CIR (pri) (0x140 + 4 * (pri)) +#define AM65_CPSW_P0_REG_PRI_EIR (pri) (0x160 + 4 * (pri)) +#define AM65_CPSW_PN_REG_CTL 0x004 +#define AM65_CPSW_PN_REG_TX_PRI_MAP 0x018 +#define AM65_CPSW_PN_REG_RX_PRI_MAP 0x020#define AM65_CPSW_PN_REG_FIFO_STATUS 0x050#define AM65_CPSW_PN_REG_EST_CTL 0x060#define AM65_CPSW_PN_REG_PRI_CIR (pri) (0x140 + 4 * (pri)) +#define AM65_CPSW_PN_REG_PRI_EIR (pri) (0x160 + 4 * (pri))/* AM65_CPSW_REG_CTL register fields */ #define AM65_CPSW_CTL_EST_EN BIT(18)@@ -50,12 +59,18 @@#define AM65_CPSW_FETCH_ALLOW_MSK GENMASK(7, 0)#define AM65_CPSW_FETCH_ALLOW_MAX AM65_CPSW_FETCH_ALLOW_MSK +#define TO_MBPS (x) ((x) * 8 / 1000000) +enum timer_act {TACT_PROG ,/* need program timer */ TACT_NEED_STOP ,/* need stop first */ TACT_SKIP_PROG ,/* just buffer can be updated */ }; +/* number of priority queues per port FIFO */ +#define AM65_CPSW_PN_FIFO_PRIO_NUM 8 +#define AM65_CPSW_PN_TX_PRI_MAP_DEFAULT 0x76543210 +static void am65_cpsw_reset_tc_mqprio (struct net_device *ndev) +{drivers/net/ethernet/ti/am65-cpsw-qos.c
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +10
-0+struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_mqprio *p_mqprio = &port->qos.mqprio; +struct am65_cpsw_common *common = port->common; + + p_mqprio->shaper_en = false; + p_mqprio->max_rate_total =0 ; + +am65_cpsw_tx_pn_shaper_reset (port); +netdev_reset_tc (ndev); +netif_set_real_num_tx_queues (ndev, common->tx_ch_num);If this never gets changed from the value set by
am65_cpsw_nuss_ndo_slave_open(), then there is no reason to callnetif_set_real_num_tx_queues()here.
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) · line 1082
Quoted 3 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +3
-0+ +/* Reset all Queue priorities to 0 */ +writel (0 , port->port_base +AM65_CPSW_PN_REG_TX_PRI_MAP );To 0 or to
AM65_CPSW_PN_TX_PRI_MAP_DEFAULT(which is now unused)? Also, do I understand correctly that immediately after boot,TX_PRI_MAPwill have a different value than after the deletion of the mqprio root qdisc (ifAM65_CPSW_PN_TX_PRI_MAP_DEFAULTrepresents the hardware default value)? The behavior needs to be identical in the 2 cases, since both represent "no mqprio offload".
Good catch. I'll get rid of AM65_CPSW_PN_TX_PRI_MAP_DEFAULT and set this to 0 at init time.
Quoted 25 lines
Quoted 25 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +24
-0+} + +static int am65_cpsw_setup_mqprio (struct net_device *ndev,void *type_data) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_mqprio *p_mqprio = &port->qos.mqprio; +struct tc_mqprio_qopt_offload *mqprio = type_data; +struct am65_cpsw_common *common = port->common; +struct tc_mqprio_qopt *qopt = &mqprio->qopt; +int tc, offset, count, ret, prio; +u8 num_tc = qopt->num_tc; +u32 tx_prio_map =0 ; +int i; + +memcpy (&p_mqprio->mqprio_hw, mqprio,sizeof (*mqprio)); + + ret =pm_runtime_get_sync (common->dev); +if (ret <0 ) { +pm_runtime_put_noidle (common->dev); +return ret; + } + +if (!num_tc) { +am65_cpsw_reset_tc_mqprio (ndev);
Quoted 8 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) · line 1112
Quoted 6 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +6
-0+ goto exit_put; + } + + ret =am65_cpsw_mqprio_verify_shaper (port, mqprio); +if (ret) + goto exit_put;At "
exit_put" we have "return 0" and this discards the value of "ret".
Will fix.
Quoted 32 lines
Quoted 19 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +18
-0+ +netdev_set_num_tc (ndev, num_tc); + +/* Multiple Linux priorities can map to a Traffic Class +* A Traffic Class can have multiple contiguous Queues, +* Queues get mapped to Channels (thread_id), +* if not VLAN tagged, thread_id is used as packet_priority +* if VLAN tagged. VLAN priority is used as packet_priorit +* packet_priority gets mapped to header_priority in p0_rx_pri_map, +* header_priority gets mapped to switch_priority in pn_tx_pri_map. +* As p0_rx_pri_map is left at defaults (0x76543210), we can +* assume that Queue_n gets mapped to header_priority_n. We can then +* set the switch priority in pn_tx_pri_map. +*/ + +for (tc =0 ; tc < num_tc; tc++) { + prio = tc; +drivers/net/ethernet/ti/am65-cpsw-qos.c void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) · line 1140
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +10
-0+/* For simplicity we assign the same priority (TCn) to +* all queues of a Traffic Class. +*/ +for (i = qopt->offset[tc]; i < qopt->offset[tc] + qopt->count[tc]; i++) + tx_prio_map |= prio << (4 * i); + + count = qopt->count[tc]; + offset = qopt->offset[tc]; +netdev_set_tc_queue (ndev, tc, count, offset); + }I think this is okay.
Quoted 6 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c void am65_cpsw_qos_tx_p0_rate_init(struct am65_cpsw_common *common) · line 1143
Quoted 3 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +3
-0+ +writel (tx_prio_map, + port->port_base +AM65_CPSW_PN_REG_TX_PRI_MAP );Nit: This can be written on a single line.
OK.
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +8
-0+ +am65_cpsw_tx_pn_shaper_apply (port); + +exit_put: +pm_runtime_put (common->dev); +return 0 ; +} +int am65_cpsw_qos_ndo_setup_tc (struct net_device *ndev,enum tc_setup_type type,void *type_data) {
Signature · 2 lines
cheers, -roger
PATCH v5 3/4 net: ethernet: ti: am65-cpsw-qos: Add Frame Preemption MAC Merge support
In reply to Roger QuadrosAdd driver support for viewing / changing the MAC Merge sublayer parameters and seeing the verification state machine's current state via ethtool.
As hardware does not support interrupt notification for verification events we resort to polling on link up. On link up we try a couple of times for verification success and if unsuccessful then give up.
The Frame Preemption feature is described in the Technical Reference Manual [1] in section:
12.3.1.4.6.7 Intersperced Express Traffic (IET – P802.3br/D2.0)
Due to Silicon Errata i2208 [2] we set limit min IET fragment size to 124.
[1] AM62x TRM - https://www.ti.com/lit/ug/spruiv7a/spruiv7a.pdf
[2] AM62x Silicon Errata - https://www.ti.com/lit/er/sprz487c/sprz487c.pdf
--- drivers/net/ethernet/ti/am65-cpsw-ethtool.c | 150 ++++++++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.c | 2 + drivers/net/ethernet/ti/am65-cpsw-nuss.h | 5 + drivers/net/ethernet/ti/am65-cpsw-qos.c | 240 ++++++++++++++++---- drivers/net/ethernet/ti/am65-cpsw-qos.h | 104 +++++++++ 5 files changed, 454 insertions(+), 47 deletions(-)
Changelog:
v5:
- No change
v4:
- Rebase and include in the same series as mqprio support.
v3:
- Rebase on top of v6.6-rc1 and mqprio support [1]
- Support ethtool_ops :: get_mm_stats()
- drop unused variables cmn_ctrl and verify_cnt
- make am65_cpsw_iet_link_state_update() and am65_cpsw_iet_change_preemptible_tcs() static
[1] https://lore.kernel.org/all/[email protected]/
v2:
- Use proper control bits for PMAC enable (AM65_CPSW_PN_CTL_IET_PORT_EN) and TX enable (AM65_CPSW_PN_IET_MAC_PENABLE)
- Common IET Enable (AM65_CPSW_CTL_IET_EN) is set if any port has AM65_CPSW_PN_CTL_IET_PORT_EN set.
- Fix workaround for erratum i2208. i.e. Limit rx_min_frag_size to 124
- Fix am65_cpsw_iet_get_verify_timeout_ms() to default to timeout for 1G link if link is inactive.
- resize the RX FIFO based on pmac_enabled, not tx_enabled.
Test Procedure:
- 2 EVMs with AM65-CPSW network port connected to each other
- Run iet-setup-mqprio.sh on both
#!/bin/sh
#iet-setup-mqprio.sh
ifconfig eth0 down
ifconfig eth1 down
ethtool -L eth0 tx 4
ethtool --set-mm eth0 pmac-enabled on tx-enabled on verify-enabled on verify-time 10 tx-min-frag-size 124 ifconfig eth0 up
sleep 10
tc qdisc add dev eth0 handle 100: root mqprio \num_tc 4 \
map 0 1 2 3 \
queues 1@0 1@1 1@2 1@3 \
hw 1 \
mode dcb \
fp P P P E
tc -g class show dev eth0
tc qdisc add dev eth0 clsact
tc filter add dev eth0 egress protocol ip prio 1 u32 match ip dport 5002 0xffff action skbedit priority 2 tc filter add dev eth0 egress protocol ip prio 1 u32 match ip dport 5003 0xffff action skbedit priority 3 ip addr add 192.168.3.102/24 dev eth0
- check that MAC merge verification has succeeded
ethtool --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED
- On receiver EVM run 2 iperf instances
iperf3 -s -i30 -p5002&
iperf3 -s -i30 -p5003&
- On sender EVM run 2 iperf instances
iperf3 -c 192.168.3.102 -u -b200M -l1472 -u -t5 -i30 -p5002& iperf3 -c 192.168.3.102 -u -b50M -l1472 -u -t5 -i30 -p5003&
- Check IET stats on sender. Look for MACMergeFragCountTx: increments
ethtool -I --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED
Statistics:
MACMergeFrameAssErrorCount: 0
MACMergeFrameSmdErrorCount: 0
MACMergeFrameAssOkCount: 0
MACMergeFragCountRx: 0
MACMergeFragCountTx: 57824
MACMergeHoldCount: 0
- Check IET stats on receiver. Look for MACMergeFragCountRx: and MACMergeFrameAssOkCount:
ethtool -I --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED
Statistics:
MACMergeFrameAssErrorCount: 0
MACMergeFrameSmdErrorCount: 0
MACMergeFrameAssOkCount: 57018
MACMergeFragCountRx: 57824
MACMergeFragCountTx: 0
MACMergeHoldCount: 0
drivers/net/ethernet/ti/am65-cpsw-ethtool.c +150 -0
@@ -11,6 +11,7 @@#include <linux/pm_runtime.h> #include "am65-cpsw-nuss.h" +#include "am65-cpsw-qos.h" #include "cpsw_ale.h" #include "am65-cpts.h"
@@ -715,6 +716,152 @@ static int am65_cpsw_set_ethtool_priv_flags(struct net_device *ndev, u32 flags)return 0 ; } +static void am65_cpsw_port_iet_rx_enable (struct am65_cpsw_port *port,bool enable) +{ +u32 val; + + val =readl (port->port_base +AM65_CPSW_PN_REG_CTL ); +if (enable) + val |=AM65_CPSW_PN_CTL_IET_PORT_EN ; +else + val &= ~AM65_CPSW_PN_CTL_IET_PORT_EN ; + +writel (val, port->port_base +AM65_CPSW_PN_REG_CTL ); +am65_cpsw_iet_common_enable (port->common); +} + +static void am65_cpsw_port_iet_tx_enable (struct am65_cpsw_port *port,bool enable) +{ +u32 val; + + val =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +if (enable) + val |=AM65_CPSW_PN_IET_MAC_PENABLE ; +else + val &= ~AM65_CPSW_PN_IET_MAC_PENABLE ; + +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +} + +static int am65_cpsw_get_mm (struct net_device *ndev,struct ethtool_mm_state *state) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_ndev_priv *priv =netdev_priv (ndev); +u32 port_ctrl, iet_ctrl, iet_status; +u32 add_frag_size; + +mutex_lock (&priv->mm_lock); + + iet_ctrl =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + port_ctrl =readl (port->port_base +AM65_CPSW_PN_REG_CTL ); + + state->tx_enabled = !!(iet_ctrl &AM65_CPSW_PN_IET_MAC_PENABLE ); + state->pmac_enabled = !!(port_ctrl &AM65_CPSW_PN_CTL_IET_PORT_EN ); + + iet_status =readl (port->port_base +AM65_CPSW_PN_REG_IET_STATUS ); + +if (iet_ctrl &AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ) + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_DISABLED ; +else if (iet_status &AM65_CPSW_PN_MAC_VERIFIED ) + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED ; +else if (iet_status &AM65_CPSW_PN_MAC_VERIFY_FAIL ) + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_FAILED ; +else + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_UNKNOWN ; + + add_frag_size =AM65_CPSW_PN_IET_MAC_GET_ADDFRAGSIZE (iet_ctrl); + state->tx_min_frag_size =ethtool_mm_frag_size_add_to_min (add_frag_size); + +/* Errata i2208: RX min fragment size cannot be less than 124 */ + state->rx_min_frag_size =124 ; + +/* FPE active if common tx_enabled and verification success or disabled (forced) */ + state->tx_active = state->tx_enabled && + (state->verify_status ==ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED || + state->verify_status ==ETHTOOL_MM_VERIFY_STATUS_DISABLED ); + state->verify_enabled = !(iet_ctrl &AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ); + + state->verify_time = port->qos.iet.verify_time_ms; + state->max_verify_time =am65_cpsw_iet_get_verify_timeout_ms (AM65_CPSW_PN_MAC_VERIFY_CNT_MASK , + port); +mutex_unlock (&priv->mm_lock); + +return 0 ; +} + +static int am65_cpsw_set_mm (struct net_device *ndev,struct ethtool_mm_cfg *cfg, +struct netlink_ext_ack *extack) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_ndev_priv *priv =netdev_priv (ndev); +struct am65_cpsw_iet *iet = &port->qos.iet; +u32 val, add_frag_size; +int err; + + err =ethtool_mm_frag_size_min_to_add (cfg->tx_min_frag_size, &add_frag_size, extack); +if (err) +return err; + +mutex_lock (&priv->mm_lock); + +if (cfg->pmac_enabled) { +/* change TX & RX FIFO MAX_BLKS as per TRM recommendation */ +if (!iet->original_max_blks) + iet->original_max_blks =readl (port->port_base +AM65_CPSW_PN_REG_MAX_BLKS ); + +writel (AM65_CPSW_PN_TX_RX_MAX_BLKS_IET , + port->port_base +AM65_CPSW_PN_REG_MAX_BLKS ); + }else { +/* restore RX & TX FIFO MAX_BLKS */ +if (iet->original_max_blks) { +writel (iet->original_max_blks, + port->port_base +AM65_CPSW_PN_REG_MAX_BLKS ); + } + } + +am65_cpsw_port_iet_rx_enable (port, cfg->pmac_enabled); +am65_cpsw_port_iet_tx_enable (port, cfg->tx_enabled); + + val =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +if (cfg->verify_enabled) { + val &= ~AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ; +/* Reset Verify state machine. Verification won't start here. +* Verification will be done once link-up. +*/ + val |=AM65_CPSW_PN_IET_MAC_LINKFAIL ; + }else { + val |=AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ; + } + + val &= ~AM65_CPSW_PN_IET_MAC_MAC_ADDFRAGSIZE_MASK ; + val |=AM65_CPSW_PN_IET_MAC_SET_ADDFRAGSIZE (add_frag_size); +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + +/* verify_timeout_count can only be set at valid link */ + port->qos.iet.verify_time_ms = cfg->verify_time; + +/* enable/disable pre-emption based on link status */ +am65_cpsw_iet_commit_preemptible_tcs (port); + +mutex_unlock (&priv->mm_lock); + +return 0 ; +} + +static void am65_cpsw_get_mm_stats (struct net_device *ndev, +struct ethtool_mm_stats *s) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +void __iomem *base = port->stat_base; + + s->MACMergeFrameAssOkCount =readl (base +AM65_CPSW_STATN_IET_RX_ASSEMBLY_OK ); + s->MACMergeFrameAssErrorCount =readl (base +AM65_CPSW_STATN_IET_RX_ASSEMBLY_ERROR ); + s->MACMergeFrameSmdErrorCount =readl (base +AM65_CPSW_STATN_IET_RX_SMD_ERROR ); + s->MACMergeFragCountRx =readl (base +AM65_CPSW_STATN_IET_RX_FRAG ); + s->MACMergeFragCountTx =readl (base +AM65_CPSW_STATN_IET_TX_FRAG ); + s->MACMergeHoldCount =readl (base +AM65_CPSW_STATN_IET_TX_HOLD ); +} +const struct ethtool_ops am65_cpsw_ethtool_ops_slave = { .begin = am65_cpsw_ethtool_op_begin, .complete = am65_cpsw_ethtool_op_complete,
@@ -743,4 +890,7 @@ const struct ethtool_ops am65_cpsw_ethtool_ops_slave = { .get_eee = am65_cpsw_get_eee, .set_eee = am65_cpsw_set_eee, .nway_reset = am65_cpsw_nway_reset, + .get_mm = am65_cpsw_get_mm, + .set_mm = am65_cpsw_set_mm, + .get_mm_stats = am65_cpsw_get_mm_stats, };
drivers/net/ethernet/ti/am65-cpsw-nuss.c +2 -0
@@ -2161,6 +2161,8 @@ am65_cpsw_nuss_init_port_ndev(struct am65_cpsw_common *common, u32 port_idx) ndev_priv =netdev_priv (port->ndev); ndev_priv->port = port; ndev_priv->msg_enable =AM65_CPSW_DEBUG ; +mutex_init (&ndev_priv->mm_lock); + port->qos.link_speed =SPEED_UNKNOWN ;SET_NETDEV_DEV (port->ndev, dev);eth_hw_addr_set (port->ndev, port->slave.mac_addr);
drivers/net/ethernet/ti/am65-cpsw-nuss.h +5 -0
@@ -145,6 +145,7 @@ struct am65_cpsw_common {bool pf_p0_rx_ptype_rrobin;struct am65_cpts *cpts;int est_enabled; +bool iet_enabled;bool is_emac_mode;u16 br_members;
@@ -170,6 +171,10 @@ struct am65_cpsw_ndev_priv {struct am65_cpsw_port *port;struct am65_cpsw_ndev_stats __percpu *stats;bool offload_fwd_mark; +/* Serialize access to MAC Merge state between ethtool requests +* and link state updates +*/ +struct mutex mm_lock; };#define am65_ndev_to_priv (ndev) \
drivers/net/ethernet/ti/am65-cpsw-qos.c +193 -47
286 lines not on this page · raw message
drivers/net/ethernet/ti/am65-cpsw-qos.h +104 -0
120 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v5 net-next 3/4] net: ethernet: ti: am65-cpsw-qos: Add Frame Preemption MAC Merge support
Quoted 140 lines · Roger Quadros
Add driver support for viewing / changing the MAC Merge sublayer parameters and seeing the verification state machine's current state via ethtool.
As hardware does not support interrupt notification for verification events we resort to polling on link up. On link up we try a couple of times for verification success and if unsuccessful then give up.
The Frame Preemption feature is described in the Technical Reference Manual [1] in section:
12.3.1.4.6.7 Intersperced Express Traffic (IET – P802.3br/D2.0)Due to Silicon Errata i2208 [2] we set limit min IET fragment size to 124.
[1] AM62x TRM - https://www.ti.com/lit/ug/spruiv7a/spruiv7a.pdf
[2] AM62x Silicon Errata - https://www.ti.com/lit/er/sprz487c/sprz487c.pdfSigned-off-by Roger Quadros <[email protected]>--- drivers/net/ethernet/ti/am65-cpsw-ethtool.c | 150 ++++++++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.c | 2 + drivers/net/ethernet/ti/am65-cpsw-nuss.h | 5 + drivers/net/ethernet/ti/am65-cpsw-qos.c | 240 ++++++++++++++++---- drivers/net/ethernet/ti/am65-cpsw-qos.h | 104 +++++++++ 5 files changed, 454 insertions(+), 47 deletions(-)Changelog:
v5:
- No changev4:
- Rebase and include in the same series as mqprio support.v3:
- Rebase on top of v6.6-rc1 and mqprio support [1]
- Supportethtool_ops::get_mm_stats()
- drop unused variablescmn_ctrlandverify_cnt
- makeam65_cpsw_iet_link_state_update()andam65_cpsw_iet_change_preemptible_tcs()static[1] https://lore.kernel.org/all/[email protected]/
v2:
- Use proper control bits for PMAC enable (AM65_CPSW_PN_CTL_IET_PORT_EN) and TX enable (AM65_CPSW_PN_IET_MAC_PENABLE)
- Common IET Enable (AM65_CPSW_CTL_IET_EN) is set if any port hasAM65_CPSW_PN_CTL_IET_PORT_ENset.
- Fix workaround for erratum i2208. i.e. Limitrx_min_frag_sizeto 124
- Fixam65_cpsw_iet_get_verify_timeout_ms()to default to timeout for 1G link if link is inactive.
- resize the RX FIFO based onpmac_enabled, nottx_enabled.Test Procedure:
- 2 EVMs with AM65-CPSW network port connected to each other
- Runiet-setup-mqprio.shon both#!/bin/sh
#iet-setup-mqprio.shifconfig eth0 down
ifconfig eth1 down
ethtool -L eth0 tx 4
ethtool --set-mm eth0 pmac-enabled on tx-enabled on verify-enabled on verify-time 10 tx-min-frag-size 124 ifconfig eth0 up
sleep 10tc qdisc add dev eth0 handle 100: root mqprio \
num_tc4 \
map 0 1 2 3 \
queues 1@0 1@1 1@2 1@3 \
hw 1 \
mode dcb \
fp P P P Etc -g class show dev eth0
tc qdisc add dev eth0 clsact
tc filter add dev eth0 egress protocol ip prio 1 u32 match ip dport 50020xffffaction skbedit priority 2 tc filter add dev eth0 egress protocol ip prio 1 u32 match ip dport 50030xffffaction skbedit priority 3 ip addr add 192.168.3.102/24 dev eth0- check that MAC merge verification has succeeded
ethtool --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED- On receiver EVM run 2 iperf instances
iperf3 -s -i30 -p5002&
iperf3 -s -i30 -p5003&- On sender EVM run 2 iperf instances
iperf3 -c 192.168.3.102 -u -b200M -l1472 -u -t5 -i30 -p5002& iperf3 -c 192.168.3.102 -u -b50M -l1472 -u -t5 -i30 -p5003&
- Check IET stats on sender. Look for MACMergeFragCountTx: increments
ethtool -I --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED
Statistics:
MACMergeFrameAssErrorCount: 0
MACMergeFrameSmdErrorCount: 0
MACMergeFrameAssOkCount: 0
MACMergeFragCountRx: 0
MACMergeFragCountTx: 57824
MACMergeHoldCount: 0- Check IET stats on receiver. Look for MACMergeFragCountRx: and MACMergeFrameAssOkCount:
ethtool -I --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Quoted 8 lines
Verification status: SUCCEEDED
Statistics:
MACMergeFrameAssErrorCount: 0
MACMergeFrameSmdErrorCount: 0
MACMergeFrameAssOkCount: 57018
MACMergeFragCountRx: 57824
MACMergeFragCountTx: 0
MACMergeHoldCount: 0
Nice of you to post commands, but could you also please clearly state whether the implementation passes tools/testing/selftests/net/forwarding/ethtool_mm.sh?
drivers/net/ethernet/ti/am65-cpsw-ethtool.c static int am65_cpsw_set_ethtool_priv_flags(struct net_device *ndev, u32 flags) · line 843
Quoted 8 lines
drivers/net/ethernet/ti/am65-cpsw-ethtool.c +8
-0+ val &= ~AM65_CPSW_PN_IET_MAC_MAC_ADDFRAGSIZE_MASK ; + val |=AM65_CPSW_PN_IET_MAC_SET_ADDFRAGSIZE (add_frag_size); +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + +/* verify_timeout_count can only be set at valid link */ + port->qos.iet.verify_time_ms = cfg->verify_time; + +/* enable/disable pre-emption based on link status */
For the benefit of grep, I would appreciate if it was spelled "preemption" everywhere.
Quoted 11 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +7
-0+am65_cpsw_iet_commit_preemptible_tcs (port); + +mutex_unlock (&priv->mm_lock); + +return 0 ; +} +static int am65_cpsw_port_est_enabled (struct am65_cpsw_port *port) {return port->qos.est_oper || port->qos.est_admin;
drivers/net/ethernet/ti/am65-cpsw-qos.c static int am65_cpsw_setup_taprio(struct net_device *ndev, void *type_data) · line 747
Quoted 5 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +2
-0@@ -602,6 +743,8 @@ static int am65_cpsw_setup_taprio(struct net_device *ndev, void *type_data)if (port->qos.link_speed ==SPEED_UNKNOWN )return -ENOLINK ; +am65_cpsw_iet_change_preemptible_tcs (port, taprio->mqprio.preemptible_tcs); +
Hmm, why just look at the preemptible traffic classes and not at taprio's entire mqprio configuration? This bypasses the mapping between Linux traffic classes and switch priorities that you've established in am65_cpsw_setup_mqprio().
With the addition of the "mqprio" structure in tc_taprio_qopt_offload, my intention was to facilitate calling am65_cpsw_setup_mqprio() from am65_cpsw_setup_taprio().
Quoted 2 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +0
-0return am65_cpsw_set_taprio (ndev, type_data); }
Re: [PATCH v5 net-next 3/4] net: ethernet: ti: am65-cpsw-qos: Add Frame Preemption MAC Merge support
Quoted 150 lines · Vladimir Oltean
Quoted 140 lines · Roger Quadros
Add driver support for viewing / changing the MAC Merge sublayer parameters and seeing the verification state machine's current state via ethtool.
As hardware does not support interrupt notification for verification events we resort to polling on link up. On link up we try a couple of times for verification success and if unsuccessful then give up.
The Frame Preemption feature is described in the Technical Reference Manual [1] in section:
12.3.1.4.6.7 Intersperced Express Traffic (IET – P802.3br/D2.0)Due to Silicon Errata i2208 [2] we set limit min IET fragment size to 124.
[1] AM62x TRM - https://www.ti.com/lit/ug/spruiv7a/spruiv7a.pdf
[2] AM62x Silicon Errata - https://www.ti.com/lit/er/sprz487c/sprz487c.pdfSigned-off-by Roger Quadros <[email protected]>--- drivers/net/ethernet/ti/am65-cpsw-ethtool.c | 150 ++++++++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.c | 2 + drivers/net/ethernet/ti/am65-cpsw-nuss.h | 5 + drivers/net/ethernet/ti/am65-cpsw-qos.c | 240 ++++++++++++++++---- drivers/net/ethernet/ti/am65-cpsw-qos.h | 104 +++++++++ 5 files changed, 454 insertions(+), 47 deletions(-)Changelog:
v5:
- No changev4:
- Rebase and include in the same series as mqprio support.v3:
- Rebase on top of v6.6-rc1 and mqprio support [1]
- Supportethtool_ops::get_mm_stats()
- drop unused variablescmn_ctrlandverify_cnt
- makeam65_cpsw_iet_link_state_update()andam65_cpsw_iet_change_preemptible_tcs()static[1] https://lore.kernel.org/all/[email protected]/
v2:
- Use proper control bits for PMAC enable (AM65_CPSW_PN_CTL_IET_PORT_EN) and TX enable (AM65_CPSW_PN_IET_MAC_PENABLE)
- Common IET Enable (AM65_CPSW_CTL_IET_EN) is set if any port hasAM65_CPSW_PN_CTL_IET_PORT_ENset.
- Fix workaround for erratum i2208. i.e. Limitrx_min_frag_sizeto 124
- Fixam65_cpsw_iet_get_verify_timeout_ms()to default to timeout for 1G link if link is inactive.
- resize the RX FIFO based onpmac_enabled, nottx_enabled.Test Procedure:
- 2 EVMs with AM65-CPSW network port connected to each other
- Runiet-setup-mqprio.shon both#!/bin/sh
#iet-setup-mqprio.shifconfig eth0 down
ifconfig eth1 down
ethtool -L eth0 tx 4
ethtool --set-mm eth0 pmac-enabled on tx-enabled on verify-enabled on verify-time 10 tx-min-frag-size 124 ifconfig eth0 up
sleep 10tc qdisc add dev eth0 handle 100: root mqprio \
num_tc4 \
map 0 1 2 3 \
queues 1@0 1@1 1@2 1@3 \
hw 1 \
mode dcb \
fp P P P Etc -g class show dev eth0
tc qdisc add dev eth0 clsact
tc filter add dev eth0 egress protocol ip prio 1 u32 match ip dport 50020xffffaction skbedit priority 2 tc filter add dev eth0 egress protocol ip prio 1 u32 match ip dport 50030xffffaction skbedit priority 3 ip addr add 192.168.3.102/24 dev eth0- check that MAC merge verification has succeeded
ethtool --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED- On receiver EVM run 2 iperf instances
iperf3 -s -i30 -p5002&
iperf3 -s -i30 -p5003&- On sender EVM run 2 iperf instances
iperf3 -c 192.168.3.102 -u -b200M -l1472 -u -t5 -i30 -p5002& iperf3 -c 192.168.3.102 -u -b50M -l1472 -u -t5 -i30 -p5003&
- Check IET stats on sender. Look for MACMergeFragCountTx: increments
ethtool -I --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED
Statistics:
MACMergeFrameAssErrorCount: 0
MACMergeFrameSmdErrorCount: 0
MACMergeFrameAssOkCount: 0
MACMergeFragCountRx: 0
MACMergeFragCountTx: 57824
MACMergeHoldCount: 0- Check IET stats on receiver. Look for MACMergeFragCountRx: and MACMergeFrameAssOkCount:
ethtool -I --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134Quoted 8 lines
Verification status: SUCCEEDED
Statistics:
MACMergeFrameAssErrorCount: 0
MACMergeFrameSmdErrorCount: 0
MACMergeFrameAssOkCount: 57018
MACMergeFragCountRx: 57824
MACMergeFragCountTx: 0
MACMergeHoldCount: 0
Quoted 2 lines
Nice of you to post commands, but could you also please clearly state whether the implementation passes
tools/testing/selftests/net/forwarding/ethtool_mm.sh?
Honestly, I didn't spend much time with it. I will try to run those tests and get back.
Quoted 12 lines
drivers/net/ethernet/ti/am65-cpsw-ethtool.c static int am65_cpsw_set_ethtool_priv_flags(struct net_device *ndev, u32 flags) · line 843
Quoted 9 lines
drivers/net/ethernet/ti/am65-cpsw-ethtool.c +8
-0+ val &= ~AM65_CPSW_PN_IET_MAC_MAC_ADDFRAGSIZE_MASK ; + val |=AM65_CPSW_PN_IET_MAC_SET_ADDFRAGSIZE (add_frag_size); +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + +/* verify_timeout_count can only be set at valid link */ + port->qos.iet.verify_time_ms = cfg->verify_time; + +/* enable/disable pre-emption based on link status */ For the benefit of grep, I would appreciate if it was spelled "preemption" everywhere.
OK.
Quoted 23 lines
Quoted 12 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +7
-0+am65_cpsw_iet_commit_preemptible_tcs (port); + +mutex_unlock (&priv->mm_lock); + +return 0 ; +} +static int am65_cpsw_port_est_enabled (struct am65_cpsw_port *port) {return port->qos.est_oper || port->qos.est_admin;drivers/net/ethernet/ti/am65-cpsw-qos.c static int am65_cpsw_setup_taprio(struct net_device *ndev, void *type_data) · line 747
Quoted 5 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +2
-0@@ -602,6 +743,8 @@ static int am65_cpsw_setup_taprio(struct net_device *ndev, void *type_data)if (port->qos.link_speed ==SPEED_UNKNOWN )return -ENOLINK ; +am65_cpsw_iet_change_preemptible_tcs (port, taprio->mqprio.preemptible_tcs); +Hmm, why just look at the preemptible traffic classes and not at taprio's entire mqprio configuration? This bypasses the mapping between Linux traffic classes and switch priorities that you've established in
am65_cpsw_setup_mqprio().
Quoted 3 lines
With the addition of the "mqprio" structure in
tc_taprio_qopt_offload, my intention was to facilitate callingam65_cpsw_setup_mqprio()fromam65_cpsw_setup_taprio().
OK. I will take a look at this. Thanks!
Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +0
-0return am65_cpsw_set_taprio (ndev, type_data); }
Signature · 2 lines
cheers, -roger
Paolo Abeni
maintainerRe: [PATCH v5 net-next 3/4] net: ethernet: ti: am65-cpsw-qos: Add Frame Preemption MAC Merge support
In reply to Roger QuadrosQuoted 596 lines · Roger Quadros
Add driver support for viewing / changing the MAC Merge sublayer parameters and seeing the verification state machine's current state via ethtool.
As hardware does not support interrupt notification for verification events we resort to polling on link up. On link up we try a couple of times for verification success and if unsuccessful then give up.
The Frame Preemption feature is described in the Technical Reference Manual [1] in section:
12.3.1.4.6.7 Intersperced Express Traffic (IET – P802.3br/D2.0)Due to Silicon Errata i2208 [2] we set limit min IET fragment size to 124.
[1] AM62x TRM - https://www.ti.com/lit/ug/spruiv7a/spruiv7a.pdf
[2] AM62x Silicon Errata - https://www.ti.com/lit/er/sprz487c/sprz487c.pdfSigned-off-by Roger Quadros <[email protected]>--- drivers/net/ethernet/ti/am65-cpsw-ethtool.c | 150 ++++++++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.c | 2 + drivers/net/ethernet/ti/am65-cpsw-nuss.h | 5 + drivers/net/ethernet/ti/am65-cpsw-qos.c | 240 ++++++++++++++++---- drivers/net/ethernet/ti/am65-cpsw-qos.h | 104 +++++++++ 5 files changed, 454 insertions(+), 47 deletions(-)Changelog:
v5:
- No changev4:
- Rebase and include in the same series as mqprio support.v3:
- Rebase on top of v6.6-rc1 and mqprio support [1]
- Supportethtool_ops::get_mm_stats()
- drop unused variablescmn_ctrlandverify_cnt
- makeam65_cpsw_iet_link_state_update()andam65_cpsw_iet_change_preemptible_tcs()static[1] https://lore.kernel.org/all/[email protected]/
v2:
- Use proper control bits for PMAC enable (AM65_CPSW_PN_CTL_IET_PORT_EN) and TX enable (AM65_CPSW_PN_IET_MAC_PENABLE)
- Common IET Enable (AM65_CPSW_CTL_IET_EN) is set if any port hasAM65_CPSW_PN_CTL_IET_PORT_ENset.
- Fix workaround for erratum i2208. i.e. Limitrx_min_frag_sizeto 124
- Fixam65_cpsw_iet_get_verify_timeout_ms()to default to timeout for 1G link if link is inactive.
- resize the RX FIFO based onpmac_enabled, nottx_enabled.Test Procedure:
- 2 EVMs with AM65-CPSW network port connected to each other
- Runiet-setup-mqprio.shon both#!/bin/sh
#iet-setup-mqprio.shifconfig eth0 down
ifconfig eth1 down
ethtool -L eth0 tx 4
ethtool --set-mm eth0 pmac-enabled on tx-enabled on verify-enabled on verify-time 10 tx-min-frag-size 124 ifconfig eth0 up
sleep 10tc qdisc add dev eth0 handle 100: root mqprio \
num_tc4 \
map 0 1 2 3 \
queues 1@0 1@1 1@2 1@3 \
hw 1 \
mode dcb \
fp P P P Etc -g class show dev eth0
tc qdisc add dev eth0 clsact
tc filter add dev eth0 egress protocol ip prio 1 u32 match ip dport 50020xffffaction skbedit priority 2 tc filter add dev eth0 egress protocol ip prio 1 u32 match ip dport 50030xffffaction skbedit priority 3 ip addr add 192.168.3.102/24 dev eth0- check that MAC merge verification has succeeded
ethtool --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED- On receiver EVM run 2 iperf instances
iperf3 -s -i30 -p5002&
iperf3 -s -i30 -p5003&- On sender EVM run 2 iperf instances
iperf3 -c 192.168.3.102 -u -b200M -l1472 -u -t5 -i30 -p5002& iperf3 -c 192.168.3.102 -u -b50M -l1472 -u -t5 -i30 -p5003&
- Check IET stats on sender. Look for MACMergeFragCountTx: increments
ethtool -I --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED
Statistics:
MACMergeFrameAssErrorCount: 0
MACMergeFrameSmdErrorCount: 0
MACMergeFrameAssOkCount: 0
MACMergeFragCountRx: 0
MACMergeFragCountTx: 57824
MACMergeHoldCount: 0- Check IET stats on receiver. Look for MACMergeFragCountRx: and MACMergeFrameAssOkCount:
ethtool -I --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED
Statistics:
MACMergeFrameAssErrorCount: 0
MACMergeFrameSmdErrorCount: 0
MACMergeFrameAssOkCount: 57018
MACMergeFragCountRx: 57824
MACMergeFragCountTx: 0
MACMergeHoldCount: 0drivers/net/ethernet/ti/am65-cpsw-ethtool.c +150
-0@@ -11,6 +11,7 @@#include <linux/pm_runtime.h> #include "am65-cpsw-nuss.h" +#include "am65-cpsw-qos.h" #include "cpsw_ale.h" #include "am65-cpts.h" @@ -715,6 +716,152 @@ static int am65_cpsw_set_ethtool_priv_flags(struct net_device *ndev, u32 flags)return 0 ; } +static void am65_cpsw_port_iet_rx_enable (struct am65_cpsw_port *port,bool enable) +{ +u32 val; + + val =readl (port->port_base +AM65_CPSW_PN_REG_CTL ); +if (enable) + val |=AM65_CPSW_PN_CTL_IET_PORT_EN ; +else + val &= ~AM65_CPSW_PN_CTL_IET_PORT_EN ; + +writel (val, port->port_base +AM65_CPSW_PN_REG_CTL ); +am65_cpsw_iet_common_enable (port->common); +} + +static void am65_cpsw_port_iet_tx_enable (struct am65_cpsw_port *port,bool enable) +{ +u32 val; + + val =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +if (enable) + val |=AM65_CPSW_PN_IET_MAC_PENABLE ; +else + val &= ~AM65_CPSW_PN_IET_MAC_PENABLE ; + +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +} + +static int am65_cpsw_get_mm (struct net_device *ndev,struct ethtool_mm_state *state) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_ndev_priv *priv =netdev_priv (ndev); +u32 port_ctrl, iet_ctrl, iet_status; +u32 add_frag_size; + +mutex_lock (&priv->mm_lock); + + iet_ctrl =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + port_ctrl =readl (port->port_base +AM65_CPSW_PN_REG_CTL ); + + state->tx_enabled = !!(iet_ctrl &AM65_CPSW_PN_IET_MAC_PENABLE ); + state->pmac_enabled = !!(port_ctrl &AM65_CPSW_PN_CTL_IET_PORT_EN ); + + iet_status =readl (port->port_base +AM65_CPSW_PN_REG_IET_STATUS ); + +if (iet_ctrl &AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ) + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_DISABLED ; +else if (iet_status &AM65_CPSW_PN_MAC_VERIFIED ) + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED ; +else if (iet_status &AM65_CPSW_PN_MAC_VERIFY_FAIL ) + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_FAILED ; +else + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_UNKNOWN ; + + add_frag_size =AM65_CPSW_PN_IET_MAC_GET_ADDFRAGSIZE (iet_ctrl); + state->tx_min_frag_size =ethtool_mm_frag_size_add_to_min (add_frag_size); + +/* Errata i2208: RX min fragment size cannot be less than 124 */ + state->rx_min_frag_size =124 ; + +/* FPE active if common tx_enabled and verification success or disabled (forced) */ + state->tx_active = state->tx_enabled && + (state->verify_status ==ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED || + state->verify_status ==ETHTOOL_MM_VERIFY_STATUS_DISABLED ); + state->verify_enabled = !(iet_ctrl &AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ); + + state->verify_time = port->qos.iet.verify_time_ms; + state->max_verify_time =am65_cpsw_iet_get_verify_timeout_ms (AM65_CPSW_PN_MAC_VERIFY_CNT_MASK , + port); +mutex_unlock (&priv->mm_lock); + +return 0 ; +} + +static int am65_cpsw_set_mm (struct net_device *ndev,struct ethtool_mm_cfg *cfg, +struct netlink_ext_ack *extack) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_ndev_priv *priv =netdev_priv (ndev); +struct am65_cpsw_iet *iet = &port->qos.iet; +u32 val, add_frag_size; +int err; + + err =ethtool_mm_frag_size_min_to_add (cfg->tx_min_frag_size, &add_frag_size, extack); +if (err) +return err; + +mutex_lock (&priv->mm_lock); + +if (cfg->pmac_enabled) { +/* change TX & RX FIFO MAX_BLKS as per TRM recommendation */ +if (!iet->original_max_blks) + iet->original_max_blks =readl (port->port_base +AM65_CPSW_PN_REG_MAX_BLKS ); + +writel (AM65_CPSW_PN_TX_RX_MAX_BLKS_IET , + port->port_base +AM65_CPSW_PN_REG_MAX_BLKS ); + }else { +/* restore RX & TX FIFO MAX_BLKS */ +if (iet->original_max_blks) { +writel (iet->original_max_blks, + port->port_base +AM65_CPSW_PN_REG_MAX_BLKS ); + } + } + +am65_cpsw_port_iet_rx_enable (port, cfg->pmac_enabled); +am65_cpsw_port_iet_tx_enable (port, cfg->tx_enabled); + + val =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +if (cfg->verify_enabled) { + val &= ~AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ; +/* Reset Verify state machine. Verification won't start here. +* Verification will be done once link-up. +*/ + val |=AM65_CPSW_PN_IET_MAC_LINKFAIL ; + }else { + val |=AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ; + } + + val &= ~AM65_CPSW_PN_IET_MAC_MAC_ADDFRAGSIZE_MASK ; + val |=AM65_CPSW_PN_IET_MAC_SET_ADDFRAGSIZE (add_frag_size); +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + +/* verify_timeout_count can only be set at valid link */ + port->qos.iet.verify_time_ms = cfg->verify_time; + +/* enable/disable pre-emption based on link status */ +am65_cpsw_iet_commit_preemptible_tcs (port); + +mutex_unlock (&priv->mm_lock); + +return 0 ; +} + +static void am65_cpsw_get_mm_stats (struct net_device *ndev, +struct ethtool_mm_stats *s) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +void __iomem *base = port->stat_base; + + s->MACMergeFrameAssOkCount =readl (base +AM65_CPSW_STATN_IET_RX_ASSEMBLY_OK ); + s->MACMergeFrameAssErrorCount =readl (base +AM65_CPSW_STATN_IET_RX_ASSEMBLY_ERROR ); + s->MACMergeFrameSmdErrorCount =readl (base +AM65_CPSW_STATN_IET_RX_SMD_ERROR ); + s->MACMergeFragCountRx =readl (base +AM65_CPSW_STATN_IET_RX_FRAG ); + s->MACMergeFragCountTx =readl (base +AM65_CPSW_STATN_IET_TX_FRAG ); + s->MACMergeHoldCount =readl (base +AM65_CPSW_STATN_IET_TX_HOLD ); +} +const struct ethtool_ops am65_cpsw_ethtool_ops_slave = { .begin = am65_cpsw_ethtool_op_begin, .complete = am65_cpsw_ethtool_op_complete,@@ -743,4 +890,7 @@ const struct ethtool_ops am65_cpsw_ethtool_ops_slave = { .get_eee = am65_cpsw_get_eee, .set_eee = am65_cpsw_set_eee, .nway_reset = am65_cpsw_nway_reset, + .get_mm = am65_cpsw_get_mm, + .set_mm = am65_cpsw_set_mm, + .get_mm_stats = am65_cpsw_get_mm_stats, };drivers/net/ethernet/ti/am65-cpsw-nuss.c +2
-0@@ -2161,6 +2161,8 @@ am65_cpsw_nuss_init_port_ndev(struct am65_cpsw_common *common, u32 port_idx) ndev_priv =netdev_priv (port->ndev); ndev_priv->port = port; ndev_priv->msg_enable =AM65_CPSW_DEBUG ; +mutex_init (&ndev_priv->mm_lock); + port->qos.link_speed =SPEED_UNKNOWN ;SET_NETDEV_DEV (port->ndev, dev);eth_hw_addr_set (port->ndev, port->slave.mac_addr);drivers/net/ethernet/ti/am65-cpsw-nuss.h +5
-0@@ -145,6 +145,7 @@ struct am65_cpsw_common {bool pf_p0_rx_ptype_rrobin;struct am65_cpts *cpts;int est_enabled; +bool iet_enabled;bool is_emac_mode;u16 br_members;@@ -170,6 +171,10 @@ struct am65_cpsw_ndev_priv {struct am65_cpsw_port *port;struct am65_cpsw_ndev_stats __percpu *stats;bool offload_fwd_mark; +/* Serialize access to MAC Merge state between ethtool requests +* and link state updates +*/ +struct mutex mm_lock; };#define am65_ndev_to_priv (ndev) \drivers/net/ethernet/ti/am65-cpsw-qos.c +165
-47@@ -4,9 +4,11 @@* * quality of service module includes: * Enhanced Scheduler Traffic (EST - P802.1Qbv/D2.2) +* Interspersed Express Traffic (IET - P802.3br/D2.0) */ #include <linux/pm_runtime.h> +#include <linux/units.h> #include <linux/time.h> #include <net/pkt_cls.h> @@ -15,50 +17,6 @@#include "am65-cpts.h" #include "cpsw_ale.h" -#define AM65_CPSW_REG_CTL 0x004 -#define AM65_CPSW_P0_REG_TX_PRI_MAP 0x018 -#define AM65_CPSW_P0_REG_RX_PRI_MAP 0x020 -#define AM65_CPSW_P0_REG_FIFO_STATUS 0x050 -#define AM65_CPSW_P0_REG_PRI_CIR (pri) (0x140 + 4 * (pri)) -#define AM65_CPSW_P0_REG_PRI_EIR (pri) (0x160 + 4 * (pri)) - -#define AM65_CPSW_PN_REG_CTL 0x004 -#define AM65_CPSW_PN_REG_TX_PRI_MAP 0x018 -#define AM65_CPSW_PN_REG_RX_PRI_MAP 0x020 -#define AM65_CPSW_PN_REG_FIFO_STATUS 0x050 -#define AM65_CPSW_PN_REG_EST_CTL 0x060 -#define AM65_CPSW_PN_REG_PRI_CIR (pri) (0x140 + 4 * (pri)) -#define AM65_CPSW_PN_REG_PRI_EIR (pri) (0x160 + 4 * (pri)) - -/* AM65_CPSW_REG_CTL register fields */ -#define AM65_CPSW_CTL_EST_EN BIT(18) - -/* AM65_CPSW_PN_REG_CTL register fields */ -#define AM65_CPSW_PN_CTL_EST_PORT_EN BIT(17) - -/* AM65_CPSW_PN_REG_EST_CTL register fields */ -#define AM65_CPSW_PN_EST_ONEBUF BIT(0) -#define AM65_CPSW_PN_EST_BUFSEL BIT(1) -#define AM65_CPSW_PN_EST_TS_EN BIT(2) -#define AM65_CPSW_PN_EST_TS_FIRST BIT(3) -#define AM65_CPSW_PN_EST_ONEPRI BIT(4) -#define AM65_CPSW_PN_EST_TS_PRI_MSK GENMASK(7, 5) - -/* AM65_CPSW_PN_REG_FIFO_STATUS register fields */ -#define AM65_CPSW_PN_FST_TX_PRI_ACTIVE_MSK GENMASK(7, 0) -#define AM65_CPSW_PN_FST_TX_E_MAC_ALLOW_MSK GENMASK(15, 8) -#define AM65_CPSW_PN_FST_EST_CNT_ERR BIT(16) -#define AM65_CPSW_PN_FST_EST_ADD_ERR BIT(17) -#define AM65_CPSW_PN_FST_EST_BUFACT BIT(18) - -/* EST FETCH COMMAND RAM */ -#define AM65_CPSW_FETCH_RAM_CMD_NUM 0x80 -#define AM65_CPSW_FETCH_CNT_MSK GENMASK(21, 8) -#define AM65_CPSW_FETCH_CNT_MAX (AM65_CPSW_FETCH_CNT_MSK >> 8) -#define AM65_CPSW_FETCH_CNT_OFFSET 8 -#define AM65_CPSW_FETCH_ALLOW_MSK GENMASK(7, 0) -#define AM65_CPSW_FETCH_ALLOW_MAX AM65_CPSW_FETCH_ALLOW_MSK -#define TO_MBPS (x) ((x) * 8 / 1000000)enum timer_act {@@ -67,10 +25,193 @@ enum timer_act { TACT_SKIP_PROG, /* just buffer can be updated */ }; -/* number of priority queues per port FIFO */ -#define AM65_CPSW_PN_FIFO_PRIO_NUM 8 -#define AM65_CPSW_PN_TX_PRI_MAP_DEFAULT 0x76543210 +/* IET */ +static int am65_cpsw_iet_set_verify_timeout_count (struct am65_cpsw_port *port) +{ +int verify_time_ms = port->qos.iet.verify_time_ms; +int link_speed = port->qos.link_speed; +u32 val; + +if (WARN_ON (link_speed ==SPEED_UNKNOWN )) +return -ENODEV ; + +/* The number of wireside clocks contained in the verify +* timeout counter. The default is 0x1312d0 +* (10ms at 125Mhz in 1G mode). +*/ + val =125 *HZ_PER_MHZ ;/* assuming 125MHz wireside clock */ + + val /=MILLIHZ_PER_HZ ;/* count per ms timeout */ + val *= verify_time_ms;/* count for timeout ms */ +if (link_speed <SPEED_1000 ) + val <<=1 ;/* FIXME: Is this correct? */ + +if (val >AM65_CPSW_PN_MAC_VERIFY_CNT_MASK ) +return -EINVAL ; + +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_VERIFY ); + +return 0 ; +} + +unsigned int am65_cpsw_iet_get_verify_timeout_ms (u32 count,struct am65_cpsw_port *port) +{ +int link_speed = port->qos.link_speed; +u32 val =125 *HZ_PER_MHZ ;/* assuming 125MHz wireside clock */ +unsigned int timeout_ms; + +if (link_speed ==SPEED_UNKNOWN ) + link_speed =SPEED_1000 ; + + val /=MILLIHZ_PER_HZ ;/* count per ms timeout */ + + timeout_ms = count / val; + +if (link_speed <SPEED_1000 ) + timeout_ms >>=1 ;/* FIXME: Is this correct? */ + +return timeout_ms; +} + +static int am65_cpsw_iet_verify_wait (struct am65_cpsw_port *port) +{ +u32 ctrl, status; +int try; + + try =20 ; +do { +/* Clear MAC_LINKFAIL bit to start Verify. */ + ctrl =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + ctrl &= ~AM65_CPSW_PN_IET_MAC_LINKFAIL ; +writel (ctrl, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + +msleep (port->qos.iet.verify_time_ms); + + status =readl (port->port_base +AM65_CPSW_PN_REG_IET_STATUS ); +if (status &AM65_CPSW_PN_MAC_VERIFIED ) +return 0 ; + +if (status &AM65_CPSW_PN_MAC_VERIFY_FAIL ) { +netdev_dbg (port->ndev, +"MAC Merge verify failed, trying again" ); +/* Reset the verify state machine by writing 1 +* to LINKFAIL +*/ + ctrl =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + ctrl |=AM65_CPSW_PN_IET_MAC_LINKFAIL ; +writel (ctrl, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +continue ; + } + +if (status &AM65_CPSW_PN_MAC_RESPOND_ERR ) { +netdev_dbg (port->ndev,"MAC Merge respond error" ); +return -ENODEV ; + } + +if (status &AM65_CPSW_PN_MAC_VERIFY_ERR ) { +netdev_dbg (port->ndev,"MAC Merge verify error" ); +return -ENODEV ; + } + }while (try-- >0 ); + +netdev_dbg (port->ndev,"MAC Merge verify timeout" ); +return -ETIMEDOUT ; +} + +static void am65_cpsw_iet_set_preempt_mask (struct am65_cpsw_port *port,u8 preemptible_tcs) +{ +u32 val; + + val =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + val &= ~AM65_CPSW_PN_IET_MAC_PREMPT_MASK ; + val |=AM65_CPSW_PN_IET_MAC_SET_PREEMPT (preemptible_tcs); +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +} + +/* enable common IET_ENABLE only if at least 1 port has rx IET enabled. +* UAPI doesn't allow tx enable without rx enable. +*/ +void am65_cpsw_iet_common_enable (struct am65_cpsw_common *common) +{ +struct am65_cpsw_port *port; +bool rx_enable = false; +u32 val; +int i; + +for (i =0 ; i < common->port_num; i++) { + port = &common->ports[i]; + val =readl (port->port_base +AM65_CPSW_PN_REG_CTL ); + rx_enable = !!(val &AM65_CPSW_PN_CTL_IET_PORT_EN ); +if (rx_enable) +break ; + } + + val =readl (common->cpsw_base +AM65_CPSW_REG_CTL ); + +if (rx_enable) + val |=AM65_CPSW_CTL_IET_EN ; +else + val &= ~AM65_CPSW_CTL_IET_EN ; + +writel (val, common->cpsw_base +AM65_CPSW_REG_CTL ); + common->iet_enabled = rx_enable; +} + +/* CPSW does not have an IRQ to notify changes to the MAC Merge TX status +* (active/inactive), but the preemptible traffic classes should only be +* committed to hardware once TX is active. Resort to polling. +*/ +void am65_cpsw_iet_commit_preemptible_tcs (struct am65_cpsw_port *port) +{ +u8 preemptible_tcs =0 ; +int err; +u32 val; + +if (port->qos.link_speed ==SPEED_UNKNOWN ) +return ; + + val =readl (port->port_base +AM65_CPSW_PN_REG_CTL ); +if (!(val &AM65_CPSW_PN_CTL_IET_PORT_EN )) +return ; + +/* update common IET enable */ +am65_cpsw_iet_common_enable (port->common); +/* update verify count */ + err =am65_cpsw_iet_set_verify_timeout_count (port); +if (err) { +netdev_err (port->ndev,"couldn't set verify count: %d\n" , err); +return ; + } + + val =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +if (!(val &AM65_CPSW_PN_IET_MAC_DISABLEVERIFY )) { + err =am65_cpsw_iet_verify_wait (port); +if (err) +return ;
drivers/net/ethernet/ti/am65-cpsw-qos.c enum timer_act { · line 201
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +10
-0+ } + + preemptible_tcs = port->qos.iet.preemptible_tcs; +am65_cpsw_iet_set_preempt_mask (port, preemptible_tcs); +} + +static void am65_cpsw_iet_change_preemptible_tcs (struct am65_cpsw_port *port,u8 preemptible_tcs) +{ + port->qos.iet.preemptible_tcs = preemptible_tcs; +am65_cpsw_iet_commit_preemptible_tcs (port);
I'm sorry for the late feedback, but I was unable to notice the following before.
It looks like am65_cpsw_iet_commit_preemptible_tcs() is always invoked with the priv->mm_lock lock held, except in the above call that can be reached without such lock held, via the am65_cpsw_qos_ndo_setup_tc().
Is that safe? If so I think it deserves at least a comment in the code.
Cheers,
Paolo
Re: [PATCH v5 net-next 3/4] net: ethernet: ti: am65-cpsw-qos: Add Frame Preemption MAC Merge support
Quoted 611 lines · Paolo Abeni
Quoted 596 lines · Roger Quadros
Add driver support for viewing / changing the MAC Merge sublayer parameters and seeing the verification state machine's current state via ethtool.
As hardware does not support interrupt notification for verification events we resort to polling on link up. On link up we try a couple of times for verification success and if unsuccessful then give up.
The Frame Preemption feature is described in the Technical Reference Manual [1] in section:
12.3.1.4.6.7 Intersperced Express Traffic (IET – P802.3br/D2.0)Due to Silicon Errata i2208 [2] we set limit min IET fragment size to 124.
[1] AM62x TRM - https://www.ti.com/lit/ug/spruiv7a/spruiv7a.pdf
[2] AM62x Silicon Errata - https://www.ti.com/lit/er/sprz487c/sprz487c.pdfSigned-off-by Roger Quadros <[email protected]>--- drivers/net/ethernet/ti/am65-cpsw-ethtool.c | 150 ++++++++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.c | 2 + drivers/net/ethernet/ti/am65-cpsw-nuss.h | 5 + drivers/net/ethernet/ti/am65-cpsw-qos.c | 240 ++++++++++++++++---- drivers/net/ethernet/ti/am65-cpsw-qos.h | 104 +++++++++ 5 files changed, 454 insertions(+), 47 deletions(-)Changelog:
v5:
- No changev4:
- Rebase and include in the same series as mqprio support.v3:
- Rebase on top of v6.6-rc1 and mqprio support [1]
- Supportethtool_ops::get_mm_stats()
- drop unused variablescmn_ctrlandverify_cnt
- makeam65_cpsw_iet_link_state_update()andam65_cpsw_iet_change_preemptible_tcs()static[1] https://lore.kernel.org/all/[email protected]/
v2:
- Use proper control bits for PMAC enable (AM65_CPSW_PN_CTL_IET_PORT_EN) and TX enable (AM65_CPSW_PN_IET_MAC_PENABLE)
- Common IET Enable (AM65_CPSW_CTL_IET_EN) is set if any port hasAM65_CPSW_PN_CTL_IET_PORT_ENset.
- Fix workaround for erratum i2208. i.e. Limitrx_min_frag_sizeto 124
- Fixam65_cpsw_iet_get_verify_timeout_ms()to default to timeout for 1G link if link is inactive.
- resize the RX FIFO based onpmac_enabled, nottx_enabled.Test Procedure:
- 2 EVMs with AM65-CPSW network port connected to each other
- Runiet-setup-mqprio.shon both#!/bin/sh
#iet-setup-mqprio.shifconfig eth0 down
ifconfig eth1 down
ethtool -L eth0 tx 4
ethtool --set-mm eth0 pmac-enabled on tx-enabled on verify-enabled on verify-time 10 tx-min-frag-size 124 ifconfig eth0 up
sleep 10tc qdisc add dev eth0 handle 100: root mqprio \
num_tc4 \
map 0 1 2 3 \
queues 1@0 1@1 1@2 1@3 \
hw 1 \
mode dcb \
fp P P P Etc -g class show dev eth0
tc qdisc add dev eth0 clsact
tc filter add dev eth0 egress protocol ip prio 1 u32 match ip dport 50020xffffaction skbedit priority 2 tc filter add dev eth0 egress protocol ip prio 1 u32 match ip dport 50030xffffaction skbedit priority 3 ip addr add 192.168.3.102/24 dev eth0- check that MAC merge verification has succeeded
ethtool --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED- On receiver EVM run 2 iperf instances
iperf3 -s -i30 -p5002&
iperf3 -s -i30 -p5003&- On sender EVM run 2 iperf instances
iperf3 -c 192.168.3.102 -u -b200M -l1472 -u -t5 -i30 -p5002& iperf3 -c 192.168.3.102 -u -b50M -l1472 -u -t5 -i30 -p5003&
- Check IET stats on sender. Look for MACMergeFragCountTx: increments
ethtool -I --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED
Statistics:
MACMergeFrameAssErrorCount: 0
MACMergeFrameSmdErrorCount: 0
MACMergeFrameAssOkCount: 0
MACMergeFragCountRx: 0
MACMergeFragCountTx: 57824
MACMergeHoldCount: 0- Check IET stats on receiver. Look for MACMergeFragCountRx: and MACMergeFrameAssOkCount:
ethtool -I --show-mm eth0
MAC Merge layer state for eth0:
pMAC enabled: on
TX enabled: on
TX active: on
TX minimum fragment size: 124
RX minimum fragment size: 124
Verify enabled: on
Verify time: 10
Max verify time: 134
Verification status: SUCCEEDED
Statistics:
MACMergeFrameAssErrorCount: 0
MACMergeFrameSmdErrorCount: 0
MACMergeFrameAssOkCount: 57018
MACMergeFragCountRx: 57824
MACMergeFragCountTx: 0
MACMergeHoldCount: 0drivers/net/ethernet/ti/am65-cpsw-ethtool.c +150
-0@@ -11,6 +11,7 @@#include <linux/pm_runtime.h> #include "am65-cpsw-nuss.h" +#include "am65-cpsw-qos.h" #include "cpsw_ale.h" #include "am65-cpts.h" @@ -715,6 +716,152 @@ static int am65_cpsw_set_ethtool_priv_flags(struct net_device *ndev, u32 flags)return 0 ; } +static void am65_cpsw_port_iet_rx_enable (struct am65_cpsw_port *port,bool enable) +{ +u32 val; + + val =readl (port->port_base +AM65_CPSW_PN_REG_CTL ); +if (enable) + val |=AM65_CPSW_PN_CTL_IET_PORT_EN ; +else + val &= ~AM65_CPSW_PN_CTL_IET_PORT_EN ; + +writel (val, port->port_base +AM65_CPSW_PN_REG_CTL ); +am65_cpsw_iet_common_enable (port->common); +} + +static void am65_cpsw_port_iet_tx_enable (struct am65_cpsw_port *port,bool enable) +{ +u32 val; + + val =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +if (enable) + val |=AM65_CPSW_PN_IET_MAC_PENABLE ; +else + val &= ~AM65_CPSW_PN_IET_MAC_PENABLE ; + +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +} + +static int am65_cpsw_get_mm (struct net_device *ndev,struct ethtool_mm_state *state) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_ndev_priv *priv =netdev_priv (ndev); +u32 port_ctrl, iet_ctrl, iet_status; +u32 add_frag_size; + +mutex_lock (&priv->mm_lock); + + iet_ctrl =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + port_ctrl =readl (port->port_base +AM65_CPSW_PN_REG_CTL ); + + state->tx_enabled = !!(iet_ctrl &AM65_CPSW_PN_IET_MAC_PENABLE ); + state->pmac_enabled = !!(port_ctrl &AM65_CPSW_PN_CTL_IET_PORT_EN ); + + iet_status =readl (port->port_base +AM65_CPSW_PN_REG_IET_STATUS ); + +if (iet_ctrl &AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ) + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_DISABLED ; +else if (iet_status &AM65_CPSW_PN_MAC_VERIFIED ) + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED ; +else if (iet_status &AM65_CPSW_PN_MAC_VERIFY_FAIL ) + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_FAILED ; +else + state->verify_status =ETHTOOL_MM_VERIFY_STATUS_UNKNOWN ; + + add_frag_size =AM65_CPSW_PN_IET_MAC_GET_ADDFRAGSIZE (iet_ctrl); + state->tx_min_frag_size =ethtool_mm_frag_size_add_to_min (add_frag_size); + +/* Errata i2208: RX min fragment size cannot be less than 124 */ + state->rx_min_frag_size =124 ; + +/* FPE active if common tx_enabled and verification success or disabled (forced) */ + state->tx_active = state->tx_enabled && + (state->verify_status ==ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED || + state->verify_status ==ETHTOOL_MM_VERIFY_STATUS_DISABLED ); + state->verify_enabled = !(iet_ctrl &AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ); + + state->verify_time = port->qos.iet.verify_time_ms; + state->max_verify_time =am65_cpsw_iet_get_verify_timeout_ms (AM65_CPSW_PN_MAC_VERIFY_CNT_MASK , + port); +mutex_unlock (&priv->mm_lock); + +return 0 ; +} + +static int am65_cpsw_set_mm (struct net_device *ndev,struct ethtool_mm_cfg *cfg, +struct netlink_ext_ack *extack) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +struct am65_cpsw_ndev_priv *priv =netdev_priv (ndev); +struct am65_cpsw_iet *iet = &port->qos.iet; +u32 val, add_frag_size; +int err; + + err =ethtool_mm_frag_size_min_to_add (cfg->tx_min_frag_size, &add_frag_size, extack); +if (err) +return err; + +mutex_lock (&priv->mm_lock); + +if (cfg->pmac_enabled) { +/* change TX & RX FIFO MAX_BLKS as per TRM recommendation */ +if (!iet->original_max_blks) + iet->original_max_blks =readl (port->port_base +AM65_CPSW_PN_REG_MAX_BLKS ); + +writel (AM65_CPSW_PN_TX_RX_MAX_BLKS_IET , + port->port_base +AM65_CPSW_PN_REG_MAX_BLKS ); + }else { +/* restore RX & TX FIFO MAX_BLKS */ +if (iet->original_max_blks) { +writel (iet->original_max_blks, + port->port_base +AM65_CPSW_PN_REG_MAX_BLKS ); + } + } + +am65_cpsw_port_iet_rx_enable (port, cfg->pmac_enabled); +am65_cpsw_port_iet_tx_enable (port, cfg->tx_enabled); + + val =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +if (cfg->verify_enabled) { + val &= ~AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ; +/* Reset Verify state machine. Verification won't start here. +* Verification will be done once link-up. +*/ + val |=AM65_CPSW_PN_IET_MAC_LINKFAIL ; + }else { + val |=AM65_CPSW_PN_IET_MAC_DISABLEVERIFY ; + } + + val &= ~AM65_CPSW_PN_IET_MAC_MAC_ADDFRAGSIZE_MASK ; + val |=AM65_CPSW_PN_IET_MAC_SET_ADDFRAGSIZE (add_frag_size); +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + +/* verify_timeout_count can only be set at valid link */ + port->qos.iet.verify_time_ms = cfg->verify_time; + +/* enable/disable pre-emption based on link status */ +am65_cpsw_iet_commit_preemptible_tcs (port); + +mutex_unlock (&priv->mm_lock); + +return 0 ; +} + +static void am65_cpsw_get_mm_stats (struct net_device *ndev, +struct ethtool_mm_stats *s) +{ +struct am65_cpsw_port *port =am65_ndev_to_port (ndev); +void __iomem *base = port->stat_base; + + s->MACMergeFrameAssOkCount =readl (base +AM65_CPSW_STATN_IET_RX_ASSEMBLY_OK ); + s->MACMergeFrameAssErrorCount =readl (base +AM65_CPSW_STATN_IET_RX_ASSEMBLY_ERROR ); + s->MACMergeFrameSmdErrorCount =readl (base +AM65_CPSW_STATN_IET_RX_SMD_ERROR ); + s->MACMergeFragCountRx =readl (base +AM65_CPSW_STATN_IET_RX_FRAG ); + s->MACMergeFragCountTx =readl (base +AM65_CPSW_STATN_IET_TX_FRAG ); + s->MACMergeHoldCount =readl (base +AM65_CPSW_STATN_IET_TX_HOLD ); +} +const struct ethtool_ops am65_cpsw_ethtool_ops_slave = { .begin = am65_cpsw_ethtool_op_begin, .complete = am65_cpsw_ethtool_op_complete,@@ -743,4 +890,7 @@ const struct ethtool_ops am65_cpsw_ethtool_ops_slave = { .get_eee = am65_cpsw_get_eee, .set_eee = am65_cpsw_set_eee, .nway_reset = am65_cpsw_nway_reset, + .get_mm = am65_cpsw_get_mm, + .set_mm = am65_cpsw_set_mm, + .get_mm_stats = am65_cpsw_get_mm_stats, };drivers/net/ethernet/ti/am65-cpsw-nuss.c +2
-0@@ -2161,6 +2161,8 @@ am65_cpsw_nuss_init_port_ndev(struct am65_cpsw_common *common, u32 port_idx) ndev_priv =netdev_priv (port->ndev); ndev_priv->port = port; ndev_priv->msg_enable =AM65_CPSW_DEBUG ; +mutex_init (&ndev_priv->mm_lock); + port->qos.link_speed =SPEED_UNKNOWN ;SET_NETDEV_DEV (port->ndev, dev);eth_hw_addr_set (port->ndev, port->slave.mac_addr);drivers/net/ethernet/ti/am65-cpsw-nuss.h +5
-0@@ -145,6 +145,7 @@ struct am65_cpsw_common {bool pf_p0_rx_ptype_rrobin;struct am65_cpts *cpts;int est_enabled; +bool iet_enabled;bool is_emac_mode;u16 br_members;@@ -170,6 +171,10 @@ struct am65_cpsw_ndev_priv {struct am65_cpsw_port *port;struct am65_cpsw_ndev_stats __percpu *stats;bool offload_fwd_mark; +/* Serialize access to MAC Merge state between ethtool requests +* and link state updates +*/ +struct mutex mm_lock; };#define am65_ndev_to_priv (ndev) \drivers/net/ethernet/ti/am65-cpsw-qos.c +165
-47@@ -4,9 +4,11 @@* * quality of service module includes: * Enhanced Scheduler Traffic (EST - P802.1Qbv/D2.2) +* Interspersed Express Traffic (IET - P802.3br/D2.0) */ #include <linux/pm_runtime.h> +#include <linux/units.h> #include <linux/time.h> #include <net/pkt_cls.h> @@ -15,50 +17,6 @@#include "am65-cpts.h" #include "cpsw_ale.h" -#define AM65_CPSW_REG_CTL 0x004 -#define AM65_CPSW_P0_REG_TX_PRI_MAP 0x018 -#define AM65_CPSW_P0_REG_RX_PRI_MAP 0x020 -#define AM65_CPSW_P0_REG_FIFO_STATUS 0x050 -#define AM65_CPSW_P0_REG_PRI_CIR (pri) (0x140 + 4 * (pri)) -#define AM65_CPSW_P0_REG_PRI_EIR (pri) (0x160 + 4 * (pri)) - -#define AM65_CPSW_PN_REG_CTL 0x004 -#define AM65_CPSW_PN_REG_TX_PRI_MAP 0x018 -#define AM65_CPSW_PN_REG_RX_PRI_MAP 0x020 -#define AM65_CPSW_PN_REG_FIFO_STATUS 0x050 -#define AM65_CPSW_PN_REG_EST_CTL 0x060 -#define AM65_CPSW_PN_REG_PRI_CIR (pri) (0x140 + 4 * (pri)) -#define AM65_CPSW_PN_REG_PRI_EIR (pri) (0x160 + 4 * (pri)) - -/* AM65_CPSW_REG_CTL register fields */ -#define AM65_CPSW_CTL_EST_EN BIT(18) - -/* AM65_CPSW_PN_REG_CTL register fields */ -#define AM65_CPSW_PN_CTL_EST_PORT_EN BIT(17) - -/* AM65_CPSW_PN_REG_EST_CTL register fields */ -#define AM65_CPSW_PN_EST_ONEBUF BIT(0) -#define AM65_CPSW_PN_EST_BUFSEL BIT(1) -#define AM65_CPSW_PN_EST_TS_EN BIT(2) -#define AM65_CPSW_PN_EST_TS_FIRST BIT(3) -#define AM65_CPSW_PN_EST_ONEPRI BIT(4) -#define AM65_CPSW_PN_EST_TS_PRI_MSK GENMASK(7, 5) - -/* AM65_CPSW_PN_REG_FIFO_STATUS register fields */ -#define AM65_CPSW_PN_FST_TX_PRI_ACTIVE_MSK GENMASK(7, 0) -#define AM65_CPSW_PN_FST_TX_E_MAC_ALLOW_MSK GENMASK(15, 8) -#define AM65_CPSW_PN_FST_EST_CNT_ERR BIT(16) -#define AM65_CPSW_PN_FST_EST_ADD_ERR BIT(17) -#define AM65_CPSW_PN_FST_EST_BUFACT BIT(18) - -/* EST FETCH COMMAND RAM */ -#define AM65_CPSW_FETCH_RAM_CMD_NUM 0x80 -#define AM65_CPSW_FETCH_CNT_MSK GENMASK(21, 8) -#define AM65_CPSW_FETCH_CNT_MAX (AM65_CPSW_FETCH_CNT_MSK >> 8) -#define AM65_CPSW_FETCH_CNT_OFFSET 8 -#define AM65_CPSW_FETCH_ALLOW_MSK GENMASK(7, 0) -#define AM65_CPSW_FETCH_ALLOW_MAX AM65_CPSW_FETCH_ALLOW_MSK -#define TO_MBPS (x) ((x) * 8 / 1000000)enum timer_act {@@ -67,10 +25,193 @@ enum timer_act { TACT_SKIP_PROG, /* just buffer can be updated */ }; -/* number of priority queues per port FIFO */ -#define AM65_CPSW_PN_FIFO_PRIO_NUM 8 -#define AM65_CPSW_PN_TX_PRI_MAP_DEFAULT 0x76543210 +/* IET */ +static int am65_cpsw_iet_set_verify_timeout_count (struct am65_cpsw_port *port) +{ +int verify_time_ms = port->qos.iet.verify_time_ms; +int link_speed = port->qos.link_speed; +u32 val; + +if (WARN_ON (link_speed ==SPEED_UNKNOWN )) +return -ENODEV ; + +/* The number of wireside clocks contained in the verify +* timeout counter. The default is 0x1312d0 +* (10ms at 125Mhz in 1G mode). +*/ + val =125 *HZ_PER_MHZ ;/* assuming 125MHz wireside clock */ + + val /=MILLIHZ_PER_HZ ;/* count per ms timeout */ + val *= verify_time_ms;/* count for timeout ms */ +if (link_speed <SPEED_1000 ) + val <<=1 ;/* FIXME: Is this correct? */ + +if (val >AM65_CPSW_PN_MAC_VERIFY_CNT_MASK ) +return -EINVAL ; + +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_VERIFY ); + +return 0 ; +} + +unsigned int am65_cpsw_iet_get_verify_timeout_ms (u32 count,struct am65_cpsw_port *port) +{ +int link_speed = port->qos.link_speed; +u32 val =125 *HZ_PER_MHZ ;/* assuming 125MHz wireside clock */ +unsigned int timeout_ms; + +if (link_speed ==SPEED_UNKNOWN ) + link_speed =SPEED_1000 ; + + val /=MILLIHZ_PER_HZ ;/* count per ms timeout */ + + timeout_ms = count / val; + +if (link_speed <SPEED_1000 ) + timeout_ms >>=1 ;/* FIXME: Is this correct? */ + +return timeout_ms; +} + +static int am65_cpsw_iet_verify_wait (struct am65_cpsw_port *port) +{ +u32 ctrl, status; +int try; + + try =20 ; +do { +/* Clear MAC_LINKFAIL bit to start Verify. */ + ctrl =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + ctrl &= ~AM65_CPSW_PN_IET_MAC_LINKFAIL ; +writel (ctrl, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + +msleep (port->qos.iet.verify_time_ms); + + status =readl (port->port_base +AM65_CPSW_PN_REG_IET_STATUS ); +if (status &AM65_CPSW_PN_MAC_VERIFIED ) +return 0 ; + +if (status &AM65_CPSW_PN_MAC_VERIFY_FAIL ) { +netdev_dbg (port->ndev, +"MAC Merge verify failed, trying again" ); +/* Reset the verify state machine by writing 1 +* to LINKFAIL +*/ + ctrl =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + ctrl |=AM65_CPSW_PN_IET_MAC_LINKFAIL ; +writel (ctrl, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +continue ; + } + +if (status &AM65_CPSW_PN_MAC_RESPOND_ERR ) { +netdev_dbg (port->ndev,"MAC Merge respond error" ); +return -ENODEV ; + } + +if (status &AM65_CPSW_PN_MAC_VERIFY_ERR ) { +netdev_dbg (port->ndev,"MAC Merge verify error" ); +return -ENODEV ; + } + }while (try-- >0 ); + +netdev_dbg (port->ndev,"MAC Merge verify timeout" ); +return -ETIMEDOUT ; +} + +static void am65_cpsw_iet_set_preempt_mask (struct am65_cpsw_port *port,u8 preemptible_tcs) +{ +u32 val; + + val =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); + val &= ~AM65_CPSW_PN_IET_MAC_PREMPT_MASK ; + val |=AM65_CPSW_PN_IET_MAC_SET_PREEMPT (preemptible_tcs); +writel (val, port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +} + +/* enable common IET_ENABLE only if at least 1 port has rx IET enabled. +* UAPI doesn't allow tx enable without rx enable. +*/ +void am65_cpsw_iet_common_enable (struct am65_cpsw_common *common) +{ +struct am65_cpsw_port *port; +bool rx_enable = false; +u32 val; +int i; + +for (i =0 ; i < common->port_num; i++) { + port = &common->ports[i]; + val =readl (port->port_base +AM65_CPSW_PN_REG_CTL ); + rx_enable = !!(val &AM65_CPSW_PN_CTL_IET_PORT_EN ); +if (rx_enable) +break ; + } + + val =readl (common->cpsw_base +AM65_CPSW_REG_CTL ); + +if (rx_enable) + val |=AM65_CPSW_CTL_IET_EN ; +else + val &= ~AM65_CPSW_CTL_IET_EN ; + +writel (val, common->cpsw_base +AM65_CPSW_REG_CTL ); + common->iet_enabled = rx_enable; +} + +/* CPSW does not have an IRQ to notify changes to the MAC Merge TX status +* (active/inactive), but the preemptible traffic classes should only be +* committed to hardware once TX is active. Resort to polling. +*/ +void am65_cpsw_iet_commit_preemptible_tcs (struct am65_cpsw_port *port) +{ +u8 preemptible_tcs =0 ; +int err; +u32 val; + +if (port->qos.link_speed ==SPEED_UNKNOWN ) +return ; + + val =readl (port->port_base +AM65_CPSW_PN_REG_CTL ); +if (!(val &AM65_CPSW_PN_CTL_IET_PORT_EN )) +return ; + +/* update common IET enable */ +am65_cpsw_iet_common_enable (port->common); +/* update verify count */ + err =am65_cpsw_iet_set_verify_timeout_count (port); +if (err) { +netdev_err (port->ndev,"couldn't set verify count: %d\n" , err); +return ; + } + + val =readl (port->port_base +AM65_CPSW_PN_REG_IET_CTRL ); +if (!(val &AM65_CPSW_PN_IET_MAC_DISABLEVERIFY )) { + err =am65_cpsw_iet_verify_wait (port); +if (err) +return ;drivers/net/ethernet/ti/am65-cpsw-qos.c enum timer_act { · line 201
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpsw-qos.c +10
-0+ } + + preemptible_tcs = port->qos.iet.preemptible_tcs; +am65_cpsw_iet_set_preempt_mask (port, preemptible_tcs); +} + +static void am65_cpsw_iet_change_preemptible_tcs (struct am65_cpsw_port *port,u8 preemptible_tcs) +{ + port->qos.iet.preemptible_tcs = preemptible_tcs; +am65_cpsw_iet_commit_preemptible_tcs (port);I'm sorry for the late feedback, but I was unable to notice the following before.
Quoted 5 lines
It looks like
am65_cpsw_iet_commit_preemptible_tcs()is always invoked with thepriv->mm_locklock held, except in the above call that can be reached without such lock held, via theam65_cpsw_qos_ndo_setup_tc().Is that safe? If so I think it deserves at least a comment in the code.
I think it is better to call it with the priv->mm_lock held. Thanks!
Signature · 2 lines
cheers, -roger
PATCH v5 4/4 net: ethernet: ti: am65-cpsw: add sw tx/rx irq coalescing based on hrtimers
In reply to Roger QuadrosFrom: Grygorii Strashko <[email protected]>
Add SW IRQ coalescing based on hrtimers for TX and RX data path which can be enabled by ethtool commands:
- RX coalescing
ethtool -C eth1 rx-usecs 50
- TX coalescing can be enabled per TX queue
- by default enables coalesing for TX0
ethtool -C eth1 tx-usecs 50
- configure TX0
ethtool -Q eth0 queue_mask 1 --coalesce tx-usecs 100
- configure TX1
ethtool -Q eth0 queue_mask 2 --coalesce tx-usecs 100
- configure TX0 and TX1
ethtool -Q eth0 queue_mask 3 --coalesce tx-usecs 100 --coalesce tx-usecs 100
show configuration for TX0 and TX1:
ethtool -Q eth0 queue_mask 3 --show-coalesce
Comparing to gro_flush_timeout and napi_defer_hard_irqs, this patch allows to enable IRQ coalesing for RX path separately.
--- drivers/net/ethernet/ti/am65-cpsw-ethtool.c | 79 +++++++++++++++++++++ drivers/net/ethernet/ti/am65-cpsw-nuss.c | 59 ++++++++++++--- drivers/net/ethernet/ti/am65-cpsw-nuss.h | 4 ++ 3 files changed, 134 insertions(+), 8 deletions(-)
Changelog:
v5: Included in this series. No change.
v1: initial patch.
drivers/net/ethernet/ti/am65-cpsw-ethtool.c +79 -0
@@ -862,6 +862,80 @@ static void am65_cpsw_get_mm_stats(struct net_device *ndev, s->MACMergeHoldCount =readl (base +AM65_CPSW_STATN_IET_TX_HOLD ); } +static int am65_cpsw_get_coalesce (struct net_device *ndev,struct ethtool_coalesce *coal, +struct kernel_ethtool_coalesce *kernel_coal, +struct netlink_ext_ack *extack) +{ +struct am65_cpsw_common *common =am65_ndev_to_common (ndev); +struct am65_cpsw_tx_chn *tx_chn; + + tx_chn = &common->tx_chns[0 ]; + + coal->rx_coalesce_usecs = common->rx_pace_timeout /1000 ; + coal->tx_coalesce_usecs = tx_chn->tx_pace_timeout /1000 ; + +return 0 ; +} + +static int am65_cpsw_get_per_queue_coalesce (struct net_device *ndev,u32 queue, +struct ethtool_coalesce *coal) +{ +struct am65_cpsw_common *common =am65_ndev_to_common (ndev); +struct am65_cpsw_tx_chn *tx_chn; + +if (queue >=AM65_CPSW_MAX_TX_QUEUES ) +return -EINVAL ; + + tx_chn = &common->tx_chns[queue]; + + coal->tx_coalesce_usecs = tx_chn->tx_pace_timeout /1000 ; + +return 0 ; +} + +static int am65_cpsw_set_coalesce (struct net_device *ndev,struct ethtool_coalesce *coal, +struct kernel_ethtool_coalesce *kernel_coal, +struct netlink_ext_ack *extack) +{ +struct am65_cpsw_common *common =am65_ndev_to_common (ndev); +struct am65_cpsw_tx_chn *tx_chn; + + tx_chn = &common->tx_chns[0 ]; + +if (coal->rx_coalesce_usecs && coal->rx_coalesce_usecs <20 ) +return -EINVAL ; + +if (coal->tx_coalesce_usecs && coal->tx_coalesce_usecs <20 ) +return -EINVAL ; + + common->rx_pace_timeout = coal->rx_coalesce_usecs *1000 ; + tx_chn->tx_pace_timeout = coal->tx_coalesce_usecs *1000 ; + +return 0 ; +} + +static int am65_cpsw_set_per_queue_coalesce (struct net_device *ndev,u32 queue, +struct ethtool_coalesce *coal) +{ +struct am65_cpsw_common *common =am65_ndev_to_common (ndev); +struct am65_cpsw_tx_chn *tx_chn; + +if (queue >=AM65_CPSW_MAX_TX_QUEUES ) +return -EINVAL ; + + tx_chn = &common->tx_chns[queue]; + +if (coal->tx_coalesce_usecs && coal->tx_coalesce_usecs <20 ) { +dev_info (common->dev,"defaulting to min value of 20us for tx-usecs for tx-%u\n" , + queue); + coal->tx_coalesce_usecs =20 ; + } + + tx_chn->tx_pace_timeout = coal->tx_coalesce_usecs *1000 ; + +return 0 ; +} +const struct ethtool_ops am65_cpsw_ethtool_ops_slave = { .begin = am65_cpsw_ethtool_op_begin, .complete = am65_cpsw_ethtool_op_complete,
@@ -879,6 +953,11 @@ const struct ethtool_ops am65_cpsw_ethtool_ops_slave = { .get_ts_info = am65_cpsw_get_ethtool_ts_info, .get_priv_flags = am65_cpsw_get_ethtool_priv_flags, .set_priv_flags = am65_cpsw_set_ethtool_priv_flags, + .supported_coalesce_params = ETHTOOL_COALESCE_USECS, + .get_coalesce = am65_cpsw_get_coalesce, + .set_coalesce = am65_cpsw_set_coalesce, + .get_per_queue_coalesce = am65_cpsw_get_per_queue_coalesce, + .set_per_queue_coalesce = am65_cpsw_set_per_queue_coalesce, .get_link = ethtool_op_get_link, .get_link_ksettings = am65_cpsw_get_link_ksettings,
drivers/net/ethernet/ti/am65-cpsw-nuss.c +51 -8
137 lines not on this page · raw message
drivers/net/ethernet/ti/am65-cpsw-nuss.h +4 -0
@@ -75,6 +75,8 @@ struct am65_cpsw_tx_chn {struct k3_cppi_desc_pool *desc_pool;struct k3_udma_glue_tx_channel *tx_chn;spinlock_t lock;/* protect TX rings in multi-port mode */ +struct hrtimer tx_hrtimer; +unsigned long tx_pace_timeout;int irq;u32 id;u32 descs_num;
@@ -138,6 +140,8 @@ struct am65_cpsw_common {struct napi_struct napi_rx;bool rx_irq_disabled; +struct hrtimer rx_hrtimer; +unsigned long rx_pace_timeout;u32 nuss_ver;u32 cpsw_ver;
Signature · 1 line
2.34.1
Quoted 18 lines · Roger Quadros
Hi,
This series adds mqprio qdisc offload in channel mode, Frame Pre-emption MAC merge support and RX/TX coalesing for AM65 CPSW driver.
Comparted to v4, this series picks up the coalesing patch.
Changelog information in each patch file.
cheers,
-rogerGrygorii Strashko (2):
net: ethernet: ti: am65-cpsw: add mqprio qdisc offload in channel mode
net: ethernet: ti: am65-cpsw: add sw tx/rx irq coalescing based on
hrtimers
Quoted 4 lines
Roger Quadros (2):
net: ethernet: ti: am65-cpsw: Move code to avoid forward declaration
net: ethernet: ti: am65-cpsw-qos: Add Frame Preemption MAC Merge
support
...
For series,