net: ethernet: ti: am65-cpsw-qos: Add Frame Preemption MAC Merge support
Subsystems (2)
PATCH v3 1/1 net: ethernet: ti: am65-cpsw-qos: Add Frame Preemption MAC Merge support
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.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:
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
base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
prerequisite-patch-id: 822e60d8307a2c00495cd40179118c06387c3e9a
Signature · 1 line
2.34.1
Paolo Abeni
maintainerQuoted 26 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(-)
Quoted 4 lines
Changelog:
v3:
- Rebase on top of v6.6-rc1 and mqprio support [1]
I'm unsure if this will require a rebase for the next revision of the mqprio support. Anyhow the two patches are related, it's probably better bundle them in a series so that the dep is straight-forward.
When reposting, please insert the target tree in the subject profix (net-next in this case).
Thanks!
Paolo
Quoted 27 lines · Paolo Abeni
Quoted 26 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(-)
Quoted 8 lines
Quoted 4 lines
Changelog:
v3:
- Rebase on top of v6.6-rc1 and mqprio support [1]I'm unsure if this will require a rebase for the next revision of the mqprio support. Anyhow the two patches are related, it's probably better bundle them in a series so that the dep is straight-forward.
Good idea.
Quoted 3 lines
When reposting, please insert the target tree in the subject profix (net-next in this case).
My bad. I will add. Thanks.
Signature · 2 lines
cheers, -roger