Enable RX HW timestamp for PTP packets using CPTS FIFO
Subsystems (2)
v5 cover Enable RX HW timestamp for PTP packets using CPTS FIFO
The CPSW offers two mechanisms for communicating packet ingress timestamp information to the host.
The first mechanism is via the CPTS Event FIFO which records timestamp when triggered by certain events. One such event is the reception of an Ethernet packet with a specified EtherType field. This is used to capture ingress timestamps for PTP packets. With this mechanism the host must read the timestamp (from the CPTS FIFO) separately from the packet payload which is delivered via DMA.
In the second mechanism of timestamping, CPSW driver enables hardware timestamping for all received packets by setting the TSTAMP_EN bit in CPTS_CONTROL register, which directs the CPTS module to timestamp all received packets, followed by passing timestamp via DMA descriptors. This mechanism is responsible for triggering errata i2401:
"CPSW: Host Timestamps Cause CPSW Port to Lock up."
The errata affects all K3 SoCs. Link to errata for AM64x:
https://www.ti.com/lit/er/sprz457h/sprz457h.pdf
As a workaround we can use first mechanism to timestamp received packets.
Link to v4:
https://lore.kernel.org/r/[email protected]/
Changes from v4 to v5:
- Added cover letter
- Updated commit messages.
- Combined [PATCH v4 2/3] and [PATCH v4 3/3] in v5.
- Replaced "list_del_entry()" and "list_add()" functions with equivalent "list_move()" function in [PATCH v4 1/1].
This changes are done as per discussion at here:
https://lore.kernel.org/all/[email protected]/
Chintan Vankar (2):
net: ethernet: ti: am65-cpts: Enable RX HW timestamp for PTP packets
using CPTS FIFO
net: ethernet: ti: am65-cpsw/ethtool: Enable RX HW timestamp only for
PTP packets
drivers/net/ethernet/ti/am65-cpsw-ethtool.c | 13 ++- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 50 ++++++------ drivers/net/ethernet/ti/am65-cpts.c | 87 +++++++++++++++------ drivers/net/ethernet/ti/am65-cpts.h | 11 +-- 4 files changed, 105 insertions(+), 56 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 1/2 net: ethernet: ti: am65-cpts: Enable RX HW timestamp for PTP packets using CPTS FIFO
Add a new function "am65_cpts_rx_timestamp()" which checks for PTP packets from header and timestamps them.
Add another function "am65_cpts_find_rx_ts()" which finds CPTS FIFO Event to get the timestamp of received PTP packet.
---
Link to v4:
https://lore.kernel.org/r/[email protected]/
Changes from v4 to v5:
- Updated commit message.
- Replaced "list_del_entry()" and "list_add()" functions with equivalent "list_move()" function.
drivers/net/ethernet/ti/am65-cpts.c | 64 +++++++++++++++++++++++++++++ drivers/net/ethernet/ti/am65-cpts.h | 6 +++ 2 files changed, 70 insertions(+)
drivers/net/ethernet/ti/am65-cpts.c +64 -0
@@ -906,6 +906,70 @@ static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid)return 1 ; } +static u64 am65_cpts_find_rx_ts (struct am65_cpts *cpts,u32 skb_mtype_seqid) +{ +struct list_head *this, *next; +struct am65_cpts_event *event; +unsigned long flags; +u32 mtype_seqid; +u64 ns =0 ; + +am65_cpts_fifo_read (cpts); +spin_lock_irqsave (&cpts->lock, flags); +list_for_each_safe (this, next, &cpts->events) { + event = list_entry(this, struct am65_cpts_event, list); +if (time_after (jiffies, event->tmo)) { +list_del_init (&event->list); +list_add (&event->list, &cpts->pool); +continue ; + } + + mtype_seqid = event->event1 & + (AM65_CPTS_EVENT_1_MESSAGE_TYPE_MASK | +AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK | +AM65_CPTS_EVENT_1_EVENT_TYPE_MASK ); + +if (mtype_seqid == skb_mtype_seqid) { + ns = event->timestamp; +list_move (&event->list, &cpts->pool); +break ; + } + } +spin_unlock_irqrestore (&cpts->lock, flags); + +return ns; +} + +void am65_cpts_rx_timestamp (struct am65_cpts *cpts,struct sk_buff *skb) +{ +struct am65_cpts_skb_cb_data *skb_cb = (struct am65_cpts_skb_cb_data *)skb->cb; +struct skb_shared_hwtstamps *ssh; +int ret; +u64 ns; + +/* am65_cpts_rx_timestamp() is called before eth_type_trans(), so +* skb MAC Hdr properties are not configured yet. Hence need to +* reset skb MAC header here +*/ +skb_reset_mac_header (skb); + ret =am65_skb_get_mtype_seqid (skb, &skb_cb->skb_mtype_seqid); +if (!ret) +return ;/* if not PTP class packet */ + + skb_cb->skb_mtype_seqid |= (AM65_CPTS_EV_RX <<AM65_CPTS_EVENT_1_EVENT_TYPE_SHIFT ); + +dev_dbg (cpts->dev,"%s mtype seqid %08x\n" , __func__, skb_cb->skb_mtype_seqid); + + ns =am65_cpts_find_rx_ts (cpts, skb_cb->skb_mtype_seqid); +if (!ns) +return ; + + ssh =skb_hwtstamps (skb); +memset (ssh,0 ,sizeof (*ssh)); + ssh->hwtstamp =ns_to_ktime (ns); +} +EXPORT_SYMBOL_GPL (am65_cpts_rx_timestamp); +/** * am65_cpts_tx_timestamp - save tx packet for timestamping * @cpts: cpts handle
drivers/net/ethernet/ti/am65-cpts.h +6 -0
@@ -22,6 +22,7 @@ void am65_cpts_release(struct am65_cpts *cpts);struct am65_cpts *am65_cpts_create (struct device *dev,void __iomem *regs,struct device_node *node);int am65_cpts_phc_index (struct am65_cpts *cpts); +void am65_cpts_rx_timestamp (struct am65_cpts *cpts,struct sk_buff *skb);void am65_cpts_tx_timestamp (struct am65_cpts *cpts,struct sk_buff *skb);void am65_cpts_prep_tx_timestamp (struct am65_cpts *cpts,struct sk_buff *skb);void am65_cpts_rx_enable (struct am65_cpts *cpts,bool en);
@@ -48,6 +49,11 @@ static inline int am65_cpts_phc_index(struct am65_cpts *cpts)return -1 ; } +static inline void am65_cpts_rx_timestamp (struct am65_cpts *cpts, +struct sk_buff *skb) +{ +} +static inline void am65_cpts_tx_timestamp (struct am65_cpts *cpts,struct sk_buff *skb) {
Signature · 1 line
2.34.1
Paolo Abeni
maintainerRe: [PATCH net-next v5 1/2] net: ethernet: ti: am65-cpts: Enable RX HW timestamp for PTP packets using CPTS FIFO
Quoted 29 lines · Chintan Vankar
Add a new function "
am65_cpts_rx_timestamp()" which checks for PTP packets from header and timestamps them.Add another function "
am65_cpts_find_rx_ts()" which finds CPTS FIFO Event to get the timestamp of received PTP packet.Signed-off-by Chintan Vankar <[email protected]>---
Link to v4:
https://lore.kernel.org/r/[email protected]/Changes from v4 to v5:
- Updated commit message.
- Replaced "list_del_entry()" and "list_add()" functions with equivalent "list_move()" function.drivers/net/ethernet/ti/am65-cpts.c | 64 +++++++++++++++++++++++++++++ drivers/net/ethernet/ti/am65-cpts.h | 6 +++ 2 files changed, 70 insertions(+)drivers/net/ethernet/ti/am65-cpts.c +0
-0@@ -906,6 +906,70 @@ static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid)return 1 ; }
drivers/net/ethernet/ti/am65-cpts.c static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid) · line 918
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpts.c +10
-0+static u64 am65_cpts_find_rx_ts (struct am65_cpts *cpts,u32 skb_mtype_seqid) +{ +struct list_head *this, *next; +struct am65_cpts_event *event; +unsigned long flags; +u32 mtype_seqid; +u64 ns =0 ; + +am65_cpts_fifo_read (cpts); +spin_lock_irqsave (&cpts->lock, flags);
am65_cpts_fifo_read() acquires and releases this same lock. If moving to a lockless schema is too complex, you should at least try to acquire the lock only once. e.g. factor out a lockless __am65_cpts_fifo_read variant and explicitly acquire the lock before invoke it.
drivers/net/ethernet/ti/am65-cpts.c static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid) · line 923
Quoted 5 lines
drivers/net/ethernet/ti/am65-cpts.c +5
-0+list_for_each_safe (this, next, &cpts->events) { + event = list_entry(this, struct am65_cpts_event, list); +if (time_after (jiffies, event->tmo)) { +list_del_init (&event->list); +list_add (&event->list, &cpts->pool);
Jakub suggested to use list_move() in v4, you should apply that here, too.
Cheers,
Paolo
Re: [PATCH net-next v5 1/2] net: ethernet: ti: am65-cpts: Enable RX HW timestamp for PTP packets using CPTS FIFO
Quoted 30 lines · Paolo Abeni
Quoted 29 lines · Chintan Vankar
Add a new function "
am65_cpts_rx_timestamp()" which checks for PTP packets from header and timestamps them.Add another function "
am65_cpts_find_rx_ts()" which finds CPTS FIFO Event to get the timestamp of received PTP packet.Signed-off-by Chintan Vankar <[email protected]>---
Link to v4:
https://lore.kernel.org/r/[email protected]/Changes from v4 to v5:
- Updated commit message.
- Replaced "list_del_entry()" and "list_add()" functions with equivalent "list_move()" function.drivers/net/ethernet/ti/am65-cpts.c | 64 +++++++++++++++++++++++++++++ drivers/net/ethernet/ti/am65-cpts.h | 6 +++ 2 files changed, 70 insertions(+)drivers/net/ethernet/ti/am65-cpts.c +0
-0@@ -906,6 +906,70 @@ static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid)return 1 ; }
Quoted 16 lines
drivers/net/ethernet/ti/am65-cpts.c static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid) · line 918
Quoted 10 lines
drivers/net/ethernet/ti/am65-cpts.c +10
-0+static u64 am65_cpts_find_rx_ts (struct am65_cpts *cpts,u32 skb_mtype_seqid) +{ +struct list_head *this, *next; +struct am65_cpts_event *event; +unsigned long flags; +u32 mtype_seqid; +u64 ns =0 ; + +am65_cpts_fifo_read (cpts); +spin_lock_irqsave (&cpts->lock, flags);
am65_cpts_fifo_read()acquires and releases this same lock. If moving to a lockless schema is too complex, you should at least try to acquire the lock only once. e.g. factor out a lockless__am65_cpts_fifo_readvariant and explicitly acquire the lock before invoke it.
Moving to a lockless schema is complex for now, but I will make the changes suggested by you in next version.
Quoted 9 lines
drivers/net/ethernet/ti/am65-cpts.c static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid) · line 923
Quoted 5 lines
drivers/net/ethernet/ti/am65-cpts.c +5
-0+list_for_each_safe (this, next, &cpts->events) { + event = list_entry(this, struct am65_cpts_event, list); +if (time_after (jiffies, event->tmo)) { +list_del_init (&event->list); +list_add (&event->list, &cpts->pool);Jakub suggested to use
list_move()in v4, you should apply that here, too.
Okay. I will update that too.
Quoted 5 lines
Cheers,
Paolo
PATCH v5 2/2 net: ethernet: ti: am65-cpsw/ethtool: Enable RX HW timestamp only for PTP packets
In reply to Chintan VankarIn the current mechanism of timestamping, am65-cpsw-nuss driver enables hardware timestamping for all received packets by setting the TSTAMP_EN bit in CPTS_CONTROL register, which directs the CPTS module to timestamp all received packets, followed by passing timestamp via DMA descriptors. This mechanism causes CPSW Port to Lock up.
To prevent port lock up, don't enable rx packet timestamping by setting TSTAMP_EN bit in CPTS_CONTROL register. The workaround for timestamping received packets is to utilize the CPTS Event FIFO that records timestamps corresponding to certain events. The CPTS module is configured to generate timestamps for Multicast Ethernet, UDP/IPv4 and UDP/IPv6 PTP packets.
Update supported hwtstamp_rx_filters values for CPSW's timestamping capability.
---
Link to v4:
https://lore.kernel.org/r/[email protected]/
Changes from v4 to v5:
- Updated commit message.
- Combined [PATCH v4 2/3] and [PATCH v4 3/3] in v5.
drivers/net/ethernet/ti/am65-cpsw-ethtool.c | 13 +++++- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 50 ++++++++++----------- drivers/net/ethernet/ti/am65-cpts.c | 23 ---------- drivers/net/ethernet/ti/am65-cpts.h | 5 --- 4 files changed, 35 insertions(+), 56 deletions(-)
drivers/net/ethernet/ti/am65-cpsw-ethtool.c +12 -1
@@ -695,6 +695,17 @@ static int am65_cpsw_get_ethtool_ts_info(struct net_device *ndev, struct ethtool_ts_info *info) {struct am65_cpsw_common *common =am65_ndev_to_common (ndev); +unsigned int ptp_v2_filter; + + ptp_v2_filter =BIT (HWTSTAMP_FILTER_PTP_V2_L4_EVENT ) | +BIT (HWTSTAMP_FILTER_PTP_V2_L4_SYNC ) | +BIT (HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ ) | +BIT (HWTSTAMP_FILTER_PTP_V2_L2_EVENT ) | +BIT (HWTSTAMP_FILTER_PTP_V2_L2_SYNC ) | +BIT (HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ ) | +BIT (HWTSTAMP_FILTER_PTP_V2_EVENT ) | +BIT (HWTSTAMP_FILTER_PTP_V2_SYNC ) | +BIT (HWTSTAMP_FILTER_PTP_V2_DELAY_REQ );if (!IS_ENABLED (CONFIG_TI_K3_AM65_CPTS ))return ethtool_op_get_ts_info (ndev, info);
@@ -708,7 +719,7 @@ static int am65_cpsw_get_ethtool_ts_info(struct net_device *ndev,SOF_TIMESTAMPING_RAW_HARDWARE ; info->phc_index =am65_cpts_phc_index (common->cpts); info->tx_types =BIT (HWTSTAMP_TX_OFF ) |BIT (HWTSTAMP_TX_ON ); - info->rx_filters =BIT (HWTSTAMP_FILTER_NONE ) |BIT (HWTSTAMP_FILTER_ALL ); + info->rx_filters =BIT (HWTSTAMP_FILTER_NONE ) | ptp_v2_filter;return 0 ; }
drivers/net/ethernet/ti/am65-cpsw-nuss.c +23 -27
118 lines not on this page · raw message
drivers/net/ethernet/ti/am65-cpts.c +0 -23
@@ -859,29 +859,6 @@ static long am65_cpts_ts_work(struct ptp_clock_info *ptp)return delay; } -/** -* am65_cpts_rx_enable - enable rx timestamping -* @cpts: cpts handle -* @en: enable -* -* This functions enables rx packets timestamping. The CPTS can timestamp all -* rx packets. -*/ -void am65_cpts_rx_enable (struct am65_cpts *cpts,bool en) -{ -u32 val; - -mutex_lock (&cpts->ptp_clk_lock); - val =am65_cpts_read32 (cpts, control); -if (en) - val |=AM65_CPTS_CONTROL_TSTAMP_EN ; -else - val &= ~AM65_CPTS_CONTROL_TSTAMP_EN ; -am65_cpts_write32 (cpts, val, control); -mutex_unlock (&cpts->ptp_clk_lock); -} -EXPORT_SYMBOL_GPL (am65_cpts_rx_enable); -static int am65_skb_get_mtype_seqid (struct sk_buff *skb,u32 *mtype_seqid) {unsigned int ptp_class =ptp_classify_raw (skb);
drivers/net/ethernet/ti/am65-cpts.h +0 -5
@@ -25,7 +25,6 @@ int am65_cpts_phc_index(struct am65_cpts *cpts);void am65_cpts_rx_timestamp (struct am65_cpts *cpts,struct sk_buff *skb);void am65_cpts_tx_timestamp (struct am65_cpts *cpts,struct sk_buff *skb);void am65_cpts_prep_tx_timestamp (struct am65_cpts *cpts,struct sk_buff *skb); -void am65_cpts_rx_enable (struct am65_cpts *cpts,bool en);u64 am65_cpts_ns_gettime (struct am65_cpts *cpts);int am65_cpts_estf_enable (struct am65_cpts *cpts,int idx,struct am65_cpts_estf_cfg *cfg);
@@ -64,10 +63,6 @@ static inline void am65_cpts_prep_tx_timestamp(struct am65_cpts *cpts, { } -static inline void am65_cpts_rx_enable (struct am65_cpts *cpts,bool en) -{ -} -static inline s64 am65_cpts_ns_gettime (struct am65_cpts *cpts) {return 0 ;
Signature · 1 line
2.34.1