Commit 82714539 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Jakub Kicinski

net: enetc: only commit preemptible TCs to hardware when MM TX is active

This was left as TODO in commit 01e23b2b ("net: enetc: add support
for preemptible traffic classes") since it's relatively complicated.

Where this makes a difference is with a configuration as follows:

ethtool --set-mm eno0 pmac-enabled on tx-enabled on verify-enabled on

Preemptible packets should only be sent when the MAC Merge TX direction
becomes active (i.o.w. when the verification process succeeds, aka when
the link partner confirms it can process preemptible traffic). But the
tc qdisc with the preemptible traffic classes is offloaded completely
asynchronously w.r.t. the MM becoming active.

The ENETC manual does suggest that this should be handled in the driver:
"On startup, software should wait for the verification process to
complete (MMCSR[VSTS]=011) before initiating traffic".

Adding the necessary logic allows future selftests to uphold the claim
that an inactive or disabled MAC Merge layer should never send data
packets through the pMAC.

This change moves enetc_set_ptcfpr() from enetc.c to enetc_ethtool.c,
where its only caller is now - enetc_mm_commit_preemptible_tcs().
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 153b5b1d
...@@ -25,23 +25,12 @@ void enetc_port_mac_wr(struct enetc_si *si, u32 reg, u32 val) ...@@ -25,23 +25,12 @@ void enetc_port_mac_wr(struct enetc_si *si, u32 reg, u32 val)
} }
EXPORT_SYMBOL_GPL(enetc_port_mac_wr); EXPORT_SYMBOL_GPL(enetc_port_mac_wr);
void enetc_set_ptcfpr(struct enetc_hw *hw, unsigned long preemptible_tcs) static void enetc_change_preemptible_tcs(struct enetc_ndev_priv *priv,
u8 preemptible_tcs)
{ {
u32 val; priv->preemptible_tcs = preemptible_tcs;
int tc; enetc_mm_commit_preemptible_tcs(priv);
for (tc = 0; tc < 8; tc++) {
val = enetc_port_rd(hw, ENETC_PTCFPR(tc));
if (preemptible_tcs & BIT(tc))
val |= ENETC_PTCFPR_FPE;
else
val &= ~ENETC_PTCFPR_FPE;
enetc_port_wr(hw, ENETC_PTCFPR(tc), val);
}
} }
EXPORT_SYMBOL_GPL(enetc_set_ptcfpr);
static int enetc_num_stack_tx_queues(struct enetc_ndev_priv *priv) static int enetc_num_stack_tx_queues(struct enetc_ndev_priv *priv)
{ {
...@@ -2659,7 +2648,7 @@ static void enetc_reset_tc_mqprio(struct net_device *ndev) ...@@ -2659,7 +2648,7 @@ static void enetc_reset_tc_mqprio(struct net_device *ndev)
enetc_debug_tx_ring_prios(priv); enetc_debug_tx_ring_prios(priv);
enetc_set_ptcfpr(hw, 0); enetc_change_preemptible_tcs(priv, 0);
} }
int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data) int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data)
...@@ -2714,7 +2703,7 @@ int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data) ...@@ -2714,7 +2703,7 @@ int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data)
enetc_debug_tx_ring_prios(priv); enetc_debug_tx_ring_prios(priv);
enetc_set_ptcfpr(hw, mqprio->preemptible_tcs); enetc_change_preemptible_tcs(priv, mqprio->preemptible_tcs);
return 0; return 0;
......
...@@ -355,6 +355,9 @@ struct enetc_ndev_priv { ...@@ -355,6 +355,9 @@ struct enetc_ndev_priv {
u16 rx_bd_count, tx_bd_count; u16 rx_bd_count, tx_bd_count;
u16 msg_enable; u16 msg_enable;
u8 preemptible_tcs;
enum enetc_active_offloads active_offloads; enum enetc_active_offloads active_offloads;
u32 speed; /* store speed for compare update pspeed */ u32 speed; /* store speed for compare update pspeed */
...@@ -433,6 +436,7 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames, ...@@ -433,6 +436,7 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,
/* ethtool */ /* ethtool */
void enetc_set_ethtool_ops(struct net_device *ndev); void enetc_set_ethtool_ops(struct net_device *ndev);
void enetc_mm_link_state_update(struct enetc_ndev_priv *priv, bool link); void enetc_mm_link_state_update(struct enetc_ndev_priv *priv, bool link);
void enetc_mm_commit_preemptible_tcs(struct enetc_ndev_priv *priv);
/* control buffer descriptor ring (CBDR) */ /* control buffer descriptor ring (CBDR) */
int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, int bd_count, int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, int bd_count,
...@@ -486,7 +490,6 @@ static inline void enetc_cbd_free_data_mem(struct enetc_si *si, int size, ...@@ -486,7 +490,6 @@ static inline void enetc_cbd_free_data_mem(struct enetc_si *si, int size,
void enetc_reset_ptcmsdur(struct enetc_hw *hw); void enetc_reset_ptcmsdur(struct enetc_hw *hw);
void enetc_set_ptcmsdur(struct enetc_hw *hw, u32 *queue_max_sdu); void enetc_set_ptcmsdur(struct enetc_hw *hw, u32 *queue_max_sdu);
void enetc_set_ptcfpr(struct enetc_hw *hw, unsigned long preemptible_tcs);
#ifdef CONFIG_FSL_ENETC_QOS #ifdef CONFIG_FSL_ENETC_QOS
int enetc_qos_query_caps(struct net_device *ndev, void *type_data); int enetc_qos_query_caps(struct net_device *ndev, void *type_data);
......
...@@ -991,6 +991,64 @@ static int enetc_get_mm(struct net_device *ndev, struct ethtool_mm_state *state) ...@@ -991,6 +991,64 @@ static int enetc_get_mm(struct net_device *ndev, struct ethtool_mm_state *state)
return 0; return 0;
} }
static int enetc_mm_wait_tx_active(struct enetc_hw *hw, int verify_time)
{
int timeout = verify_time * USEC_PER_MSEC * ENETC_MM_VERIFY_RETRIES;
u32 val;
/* This will time out after the standard value of 3 verification
* attempts. To not sleep forever, it relies on a non-zero verify_time,
* guarantee which is provided by the ethtool nlattr policy.
*/
return read_poll_timeout(enetc_port_rd, val,
ENETC_MMCSR_GET_VSTS(val) == 3,
ENETC_MM_VERIFY_SLEEP_US, timeout,
true, hw, ENETC_MMCSR);
}
static void enetc_set_ptcfpr(struct enetc_hw *hw, u8 preemptible_tcs)
{
u32 val;
int tc;
for (tc = 0; tc < 8; tc++) {
val = enetc_port_rd(hw, ENETC_PTCFPR(tc));
if (preemptible_tcs & BIT(tc))
val |= ENETC_PTCFPR_FPE;
else
val &= ~ENETC_PTCFPR_FPE;
enetc_port_wr(hw, ENETC_PTCFPR(tc), val);
}
}
/* ENETC 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 enetc_mm_commit_preemptible_tcs(struct enetc_ndev_priv *priv)
{
struct enetc_hw *hw = &priv->si->hw;
u8 preemptible_tcs = 0;
u32 val;
int err;
val = enetc_port_rd(hw, ENETC_MMCSR);
if (!(val & ENETC_MMCSR_ME))
goto out;
if (!(val & ENETC_MMCSR_VDIS)) {
err = enetc_mm_wait_tx_active(hw, ENETC_MMCSR_GET_VT(val));
if (err)
goto out;
}
preemptible_tcs = priv->preemptible_tcs;
out:
enetc_set_ptcfpr(hw, preemptible_tcs);
}
/* FIXME: Workaround for the link partner's verification failing if ENETC /* FIXME: Workaround for the link partner's verification failing if ENETC
* priorly received too much express traffic. The documentation doesn't * priorly received too much express traffic. The documentation doesn't
* suggest this is needed. * suggest this is needed.
...@@ -1061,6 +1119,8 @@ static int enetc_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg, ...@@ -1061,6 +1119,8 @@ static int enetc_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg,
enetc_restart_emac_rx(priv->si); enetc_restart_emac_rx(priv->si);
enetc_mm_commit_preemptible_tcs(priv);
mutex_unlock(&priv->mm_lock); mutex_unlock(&priv->mm_lock);
return 0; return 0;
...@@ -1094,6 +1154,8 @@ void enetc_mm_link_state_update(struct enetc_ndev_priv *priv, bool link) ...@@ -1094,6 +1154,8 @@ void enetc_mm_link_state_update(struct enetc_ndev_priv *priv, bool link)
enetc_port_wr(hw, ENETC_MMCSR, val); enetc_port_wr(hw, ENETC_MMCSR, val);
enetc_mm_commit_preemptible_tcs(priv);
mutex_unlock(&priv->mm_lock); mutex_unlock(&priv->mm_lock);
} }
EXPORT_SYMBOL_GPL(enetc_mm_link_state_update); EXPORT_SYMBOL_GPL(enetc_mm_link_state_update);
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
#include <linux/bitops.h> #include <linux/bitops.h>
#define ENETC_MM_VERIFY_SLEEP_US USEC_PER_MSEC
#define ENETC_MM_VERIFY_RETRIES 3
/* ENETC device IDs */ /* ENETC device IDs */
#define ENETC_DEV_ID_PF 0xe100 #define ENETC_DEV_ID_PF 0xe100
#define ENETC_DEV_ID_VF 0xef00 #define ENETC_DEV_ID_VF 0xef00
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment