[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <E1uzIcE-00000006n0r-3cMV@rmk-PC.armlinux.org.uk>
Date: Thu, 18 Sep 2025 18:40:18 +0100
From: "Russell King (Oracle)" <rmk+kernel@...linux.org.uk>
To: netdev@...r.kernel.org
Cc: Andrew Lunn <andrew@...n.ch>,
Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Heiner Kallweit <hkallweit1@...il.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Richard Cochran <richardcochran@...il.com>,
Vladimir Oltean <olteanv@...il.com>
Subject: [PATCH RFC net-next 17/20] net: dsa: mv88e6xxx: switch tx
timestamping to core
---
drivers/net/dsa/mv88e6xxx/chip.h | 6 --
drivers/net/dsa/mv88e6xxx/hwtstamp.c | 116 ++-------------------------
drivers/net/dsa/mv88e6xxx/hwtstamp.h | 3 -
3 files changed, 7 insertions(+), 118 deletions(-)
diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h
index a297b8867225..16de29c6cd43 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.h
+++ b/drivers/net/dsa/mv88e6xxx/chip.h
@@ -222,7 +222,6 @@ struct mv88e6xxx_irq {
/* state flags for mv88e6xxx_port_hwtstamp::state */
enum {
MV88E6XXX_HWTSTAMP_ENABLED,
- MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS,
};
struct mv88e6xxx_port_hwtstamp {
@@ -236,11 +235,6 @@ struct mv88e6xxx_port_hwtstamp {
struct sk_buff_head rx_queue;
struct sk_buff_head rx_queue2;
- /* Resources for transmit timestamping */
- unsigned long tx_tstamp_start;
- struct sk_buff *tx_skb;
- u16 tx_seq_id;
-
/* Current timestamp configuration */
struct kernel_hwtstamp_config tstamp_config;
};
diff --git a/drivers/net/dsa/mv88e6xxx/hwtstamp.c b/drivers/net/dsa/mv88e6xxx/hwtstamp.c
index 3e6a0481fc19..7422beba5496 100644
--- a/drivers/net/dsa/mv88e6xxx/hwtstamp.c
+++ b/drivers/net/dsa/mv88e6xxx/hwtstamp.c
@@ -357,90 +357,6 @@ bool mv88e6xxx_port_rxtstamp(struct dsa_switch *ds, int port,
return true;
}
-static int mv88e6xxx_txtstamp_work(struct mv88e6xxx_chip *chip,
- struct mv88e6xxx_port_hwtstamp *ps)
-{
- const struct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops;
- struct skb_shared_hwtstamps shhwtstamps;
- u16 departure_block[4], status;
- struct sk_buff *tmp_skb;
- u32 time_raw;
- int err;
- u64 ns;
-
- if (!ps->tx_skb)
- return 0;
-
- mv88e6xxx_reg_lock(chip);
- err = mv88e6xxx_port_ptp_read(chip, ps->port_id,
- ptp_ops->dep_sts_reg,
- departure_block,
- ARRAY_SIZE(departure_block));
- mv88e6xxx_reg_unlock(chip);
-
- if (err)
- goto free_and_clear_skb;
-
- if (!(departure_block[0] & MV88E6XXX_PTP_TS_VALID)) {
- if (time_is_before_jiffies(ps->tx_tstamp_start +
- TX_TSTAMP_TIMEOUT)) {
- dev_warn(chip->dev, "p%d: clearing tx timestamp hang\n",
- ps->port_id);
- goto free_and_clear_skb;
- }
- /* The timestamp should be available quickly, while getting it
- * is high priority and time bounded to only 10ms. A poll is
- * warranted so restart the work.
- */
- return 1;
- }
-
- /* We have the timestamp; go ahead and clear valid now */
- mv88e6xxx_reg_lock(chip);
- mv88e6xxx_port_ptp_write(chip, ps->port_id, ptp_ops->dep_sts_reg, 0);
- mv88e6xxx_reg_unlock(chip);
-
- status = departure_block[0] & MV88E6XXX_PTP_TS_STATUS_MASK;
- if (status != MV88E6XXX_PTP_TS_STATUS_NORMAL) {
- dev_warn(chip->dev, "p%d: tx timestamp overrun\n", ps->port_id);
- goto free_and_clear_skb;
- }
-
- if (departure_block[3] != ps->tx_seq_id) {
- dev_warn(chip->dev, "p%d: unexpected seq. id\n", ps->port_id);
- goto free_and_clear_skb;
- }
-
- memset(&shhwtstamps, 0, sizeof(shhwtstamps));
- time_raw = ((u32)departure_block[2] << 16) | departure_block[1];
- ns = marvell_tai_cyc2time(chip->tai, time_raw);
- shhwtstamps.hwtstamp = ns_to_ktime(ns);
-
- dev_dbg(chip->dev,
- "p%d: txtstamp %llx status 0x%04x skb ID 0x%04x hw ID 0x%04x\n",
- ps->port_id, ktime_to_ns(shhwtstamps.hwtstamp),
- departure_block[0], ps->tx_seq_id, departure_block[3]);
-
- /* skb_complete_tx_timestamp() will free up the client to make
- * another timestamp-able transmit. We have to be ready for it
- * -- by clearing the ps->tx_skb "flag" -- beforehand.
- */
-
- tmp_skb = ps->tx_skb;
- ps->tx_skb = NULL;
- clear_bit_unlock(MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS, &ps->state);
- skb_complete_tx_timestamp(tmp_skb, &shhwtstamps);
-
- return 0;
-
-free_and_clear_skb:
- dev_kfree_skb_any(ps->tx_skb);
- ps->tx_skb = NULL;
- clear_bit_unlock(MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS, &ps->state);
-
- return 0;
-}
-
long mv88e6xxx_hwtstamp_work(struct mv88e6xxx_chip *chip)
{
struct dsa_switch *ds = chip->ds;
@@ -453,16 +369,7 @@ long mv88e6xxx_hwtstamp_work(struct mv88e6xxx_chip *chip)
continue;
ps = &chip->port_hwtstamp[i];
- if (test_bit(MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS, &ps->state) &&
- mv88e6xxx_txtstamp_work(chip, ps))
- delay = 1;
-
mv88e6xxx_rxtstamp_work(chip, ps);
- }
-
- for (i = 0; i < ds->num_ports; i++) {
- if (!dsa_is_user_port(ds, i))
- continue;
ret = marvell_ts_aux_work(&chip->ptp_ts[i]);
if (ret >= 0 && (delay == -1 || delay > ret))
@@ -476,34 +383,25 @@ void mv88e6xxx_port_txtstamp(struct dsa_switch *ds, int port,
struct sk_buff *skb)
{
struct mv88e6xxx_chip *chip = ds->priv;
- struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
- struct ptp_header *hdr;
struct sk_buff *clone;
unsigned int type;
- type = ptp_classify_raw(skb);
- if (type == PTP_CLASS_NONE)
+ /* The DSA core will have checked the tx_flags of the skb, so we only
+ * see packets that have had hardware timestamping requested here.
+ */
+ if (!chip->info->ptp_support)
return;
- hdr = mv88e6xxx_should_tstamp(chip, port, skb, type);
- if (!hdr)
+ type = ptp_classify_raw(skb);
+ if (type == PTP_CLASS_NONE)
return;
clone = skb_clone_sk(skb);
if (!clone)
return;
- if (test_and_set_bit_lock(MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS,
- &ps->state)) {
+ if (!marvell_ts_txtstamp(&chip->ptp_ts[port], clone, type))
kfree_skb(clone);
- return;
- }
-
- ps->tx_skb = clone;
- ps->tx_tstamp_start = jiffies;
- ps->tx_seq_id = be16_to_cpu(hdr->sequence_id);
-
- marvell_tai_schedule(chip->tai, 0);
}
int mv88e6165_global_disable(struct mv88e6xxx_chip *chip)
diff --git a/drivers/net/dsa/mv88e6xxx/hwtstamp.h b/drivers/net/dsa/mv88e6xxx/hwtstamp.h
index f82383764653..f27fe0cb27ea 100644
--- a/drivers/net/dsa/mv88e6xxx/hwtstamp.h
+++ b/drivers/net/dsa/mv88e6xxx/hwtstamp.h
@@ -103,9 +103,6 @@
/* Status fields for arrival and depature timestamp status registers */
#define MV88E6XXX_PTP_TS_STATUS_MASK 0x0006
-#define MV88E6XXX_PTP_TS_STATUS_NORMAL 0x0000
-#define MV88E6XXX_PTP_TS_STATUS_OVERWITTEN 0x0002
-#define MV88E6XXX_PTP_TS_STATUS_DISCARDED 0x0004
#define MV88E6XXX_PTP_TS_VALID 0x0001
#ifdef CONFIG_NET_DSA_MV88E6XXX_PTP
--
2.47.3
Powered by blists - more mailing lists