Skip to content

Commit 8d43e99

Browse files
Furong Xukuba-moo
authored andcommitted
net: stmmac: refactor FPE verification process
Drop driver defined stmmac_fpe_state, and switch to common ethtool_mm_verify_status for local TX verification status. Local side and remote side verification processes are completely independent. There is no reason at all to keep a local state and a remote state. Add a spinlock to avoid races among ISR, timer, link update and register configuration. This patch is based on Vladimir Oltean's proposal. Vladimir Oltean says: ==================== In the INITIAL state, the timer sends MPACKET_VERIFY. Eventually the stmmac_fpe_event_status() IRQ fires and advances the state to VERIFYING, then rearms the timer after verify_time ms. If a subsequent IRQ comes in and modifies the state to SUCCEEDED after getting MPACKET_RESPONSE, the timer sees this. It must enable the EFPE bit now. Otherwise, it decrements the verify_limit counter and tries again. Eventually it moves the status to FAILED, from which the IRQ cannot move it anywhere else, except for another stmmac_fpe_apply() call. ==================== Co-developed-by: Vladimir Oltean <[email protected]> Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: Furong Xu <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://patch.msgid.link/151f86c8428eba967039718c6bf90a7d841e703b.1725631883.git.0x1207@gmail.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 59dd7fc commit 8d43e99

File tree

8 files changed

+166
-170
lines changed

8 files changed

+166
-170
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ static void dwmac4_core_init(struct mac_device_info *hw,
5858
if (hw->pcs)
5959
value |= GMAC_PCS_IRQ_DEFAULT;
6060

61-
/* Enable FPE interrupt */
62-
if ((GMAC_HW_FEAT_FPESEL & readl(ioaddr + GMAC_HW_FEATURE3)) >> 26)
63-
value |= GMAC_INT_FPE_EN;
64-
6561
writel(value, ioaddr + GMAC_INT_EN);
6662

6763
if (GMAC_INT_DEFAULT_ENABLE & GMAC_INT_TSIE)

drivers/net/ethernet/stmicro/stmmac/dwmac5.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,11 @@ int dwmac5_flex_pps_config(void __iomem *ioaddr, int index,
575575

576576
void dwmac5_fpe_configure(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg,
577577
u32 num_txq, u32 num_rxq,
578-
bool enable)
578+
bool tx_enable, bool pmac_enable)
579579
{
580580
u32 value;
581581

582-
if (enable) {
582+
if (tx_enable) {
583583
cfg->fpe_csr = EFPE;
584584
value = readl(ioaddr + GMAC_RXQ_CTRL1);
585585
value &= ~GMAC_RXQCTRL_FPRQ;
@@ -589,6 +589,21 @@ void dwmac5_fpe_configure(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg,
589589
cfg->fpe_csr = 0;
590590
}
591591
writel(cfg->fpe_csr, ioaddr + MAC_FPE_CTRL_STS);
592+
593+
value = readl(ioaddr + GMAC_INT_EN);
594+
595+
if (pmac_enable) {
596+
if (!(value & GMAC_INT_FPE_EN)) {
597+
/* Dummy read to clear any pending masked interrupts */
598+
readl(ioaddr + MAC_FPE_CTRL_STS);
599+
600+
value |= GMAC_INT_FPE_EN;
601+
}
602+
} else {
603+
value &= ~GMAC_INT_FPE_EN;
604+
}
605+
606+
writel(value, ioaddr + GMAC_INT_EN);
592607
}
593608

594609
int dwmac5_fpe_irq_status(void __iomem *ioaddr, struct net_device *dev)

drivers/net/ethernet/stmicro/stmmac/dwmac5.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int dwmac5_flex_pps_config(void __iomem *ioaddr, int index,
104104
u32 sub_second_inc, u32 systime_flags);
105105
void dwmac5_fpe_configure(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg,
106106
u32 num_txq, u32 num_rxq,
107-
bool enable);
107+
bool tx_enable, bool pmac_enable);
108108
void dwmac5_fpe_send_mpacket(void __iomem *ioaddr,
109109
struct stmmac_fpe_cfg *cfg,
110110
enum stmmac_mpacket_type type);

drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,13 +1504,14 @@ static void dwxgmac2_set_arp_offload(struct mac_device_info *hw, bool en,
15041504
writel(value, ioaddr + XGMAC_RX_CONFIG);
15051505
}
15061506

1507-
static void dwxgmac3_fpe_configure(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg,
1508-
u32 num_txq,
1509-
u32 num_rxq, bool enable)
1507+
static void dwxgmac3_fpe_configure(void __iomem *ioaddr,
1508+
struct stmmac_fpe_cfg *cfg,
1509+
u32 num_txq, u32 num_rxq,
1510+
bool tx_enable, bool pmac_enable)
15101511
{
15111512
u32 value;
15121513

1513-
if (!enable) {
1514+
if (!tx_enable) {
15141515
value = readl(ioaddr + XGMAC_FPE_CTRL_STS);
15151516

15161517
value &= ~XGMAC_EFPE;

drivers/net/ethernet/stmicro/stmmac/hwif.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ struct stmmac_ops {
421421
void (*set_arp_offload)(struct mac_device_info *hw, bool en, u32 addr);
422422
void (*fpe_configure)(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg,
423423
u32 num_txq, u32 num_rxq,
424-
bool enable);
424+
bool tx_enable, bool pmac_enable);
425425
void (*fpe_send_mpacket)(void __iomem *ioaddr,
426426
struct stmmac_fpe_cfg *cfg,
427427
enum stmmac_mpacket_type type);

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,31 +146,30 @@ struct stmmac_channel {
146146
u32 index;
147147
};
148148

149-
/* FPE link state */
150-
enum stmmac_fpe_state {
151-
FPE_STATE_OFF = 0,
152-
FPE_STATE_CAPABLE = 1,
153-
FPE_STATE_ENTERING_ON = 2,
154-
FPE_STATE_ON = 3,
155-
};
156-
157149
/* FPE link-partner hand-shaking mPacket type */
158150
enum stmmac_mpacket_type {
159151
MPACKET_VERIFY = 0,
160152
MPACKET_RESPONSE = 1,
161153
};
162154

163-
enum stmmac_fpe_task_state_t {
164-
__FPE_REMOVING,
165-
__FPE_TASK_SCHED,
166-
};
155+
#define STMMAC_FPE_MM_MAX_VERIFY_RETRIES 3
156+
#define STMMAC_FPE_MM_MAX_VERIFY_TIME_MS 128
167157

168158
struct stmmac_fpe_cfg {
169-
bool enable; /* FPE enable */
170-
bool hs_enable; /* FPE handshake enable */
171-
enum stmmac_fpe_state lp_fpe_state; /* Link Partner FPE state */
172-
enum stmmac_fpe_state lo_fpe_state; /* Local station FPE state */
159+
/* Serialize access to MAC Merge state between ethtool requests
160+
* and link state updates.
161+
*/
162+
spinlock_t lock;
163+
173164
u32 fpe_csr; /* MAC_FPE_CTRL_STS reg cache */
165+
166+
enum ethtool_mm_verify_status status;
167+
struct timer_list verify_timer;
168+
bool verify_enabled;
169+
int verify_retries;
170+
bool pmac_enabled;
171+
u32 verify_time;
172+
bool tx_enabled;
174173
};
175174

176175
struct stmmac_tc_entry {
@@ -367,10 +366,6 @@ struct stmmac_priv {
367366
struct work_struct service_task;
368367

369368
/* Frame Preemption feature (FPE) */
370-
unsigned long fpe_task_state;
371-
struct workqueue_struct *fpe_wq;
372-
struct work_struct fpe_task;
373-
char wq_name[IFNAMSIZ + 4];
374369
struct stmmac_fpe_cfg fpe_cfg;
375370

376371
/* TC Handling */
@@ -425,6 +420,7 @@ bool stmmac_eee_init(struct stmmac_priv *priv);
425420
int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt);
426421
int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size);
427422
int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled);
423+
void stmmac_fpe_apply(struct stmmac_priv *priv);
428424

429425
static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv)
430426
{

0 commit comments

Comments
 (0)