eth: fbnic: add timestamping support
Subsystems (3)
v3 cover eth: fbnic: add timestamping support
The series is to add timestamping support for Meta's NIC driver.
Changelog:
v2 -> v3:
- rebase on top of net-next
- add doc to describe retur value of fbnic_ts40_to_ns() v1 -> v2:
- adjust comment about using u64 stats locking primitive
- fix typo in the first patch
- Cc Richard
Vadim Fedorenko (5):
eth: fbnic: add software TX timestamping support
eth: fbnic: add initial PHC support
eth: fbnic: add RX packets timestamping support
eth: fbnic: add TX packets timestamping support
eth: fbnic: add ethtool timestamping statistics
drivers/net/ethernet/meta/fbnic/Makefile | 3 +- drivers/net/ethernet/meta/fbnic/fbnic.h | 11 + drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 39 +++ .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 54 +++ .../net/ethernet/meta/fbnic/fbnic_netdev.c | 91 ++++- .../net/ethernet/meta/fbnic/fbnic_netdev.h | 18 + drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 9 +- drivers/net/ethernet/meta/fbnic/fbnic_rpc.c | 31 ++ drivers/net/ethernet/meta/fbnic/fbnic_time.c | 311 ++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 166 +++++++++- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 3 + 11 files changed, 728 insertions(+), 8 deletions(-) create mode 100644 drivers/net/ethernet/meta/fbnic/fbnic_time.c
Signature · 1 line
2.43.5
PATCH v3 1/5 eth: fbnic: add software TX timestamping support
Add software TX timestamping support. RX software timestamping is implemented in the core and there is no need to provide special flag in the driver anymore.
--- drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 11 +++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 3 +++ 2 files changed, 14 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +11 -0
@@ -6,6 +6,16 @@#include "fbnic_netdev.h" #include "fbnic_tlv.h" +static int +fbnic_get_ts_info (struct net_device *netdev, +struct kernel_ethtool_ts_info *tsinfo) +{ + tsinfo->so_timestamping = +SOF_TIMESTAMPING_TX_SOFTWARE ; + +return 0 ; +} +static void fbnic_get_drvinfo (struct net_device *netdev,struct ethtool_drvinfo *drvinfo) {
@@ -66,6 +76,7 @@ fbnic_get_eth_mac_stats(struct net_device *netdev,static const struct ethtool_ops fbnic_ethtool_ops = { .get_drvinfo = fbnic_get_drvinfo, + .get_ts_info = fbnic_get_ts_info, .get_eth_mac_stats = fbnic_get_eth_mac_stats, };
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +3 -0
@@ -205,6 +205,9 @@ fbnic_tx_map(struct fbnic_ring *ring, struct sk_buff *skb, __le64 *meta) ring->tail = tail; +/* Record SW timestamp */ +skb_tx_timestamp (skb); +/* Verify there is room for another packet */ fbnic_maybe_stop_tx (skb->dev, ring,FBNIC_MAX_SKB_DESC );
Signature · 1 line
2.43.5
Re: [PATCH net-next v3 1/5] eth: fbnic: add software TX timestamping support
Quoted 18 lines · Vadim Fedorenko
Add software TX timestamping support. RX software timestamping is implemented in the core and there is no need to provide special flag in the driver anymore.
Signed-off-by Vadim Fedorenko <[email protected]>--- drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 11 +++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 3 +++ 2 files changed, 14 insertions(+)drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +0
-0@@ -6,6 +6,16 @@#include "fbnic_netdev.h" #include "fbnic_tlv.h"
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c line 18
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +10
-0+static int +fbnic_get_ts_info (struct net_device *netdev, +struct kernel_ethtool_ts_info *tsinfo) +{ + tsinfo->so_timestamping = +SOF_TIMESTAMPING_TX_SOFTWARE ; + +return 0 ; +} +
You could use ethtool_op_get_ts_info(), but I imagine future patches will update this for hardware timestamping, so I don't think thats a big deal.
I think you *do* still want to report SOF_TIMESTAMPING_RX_SOFTWARE and SOF_TIMESTAMPING_SOFTWARE to get the API correct... Perhaps that could be improved in the core stack though.... Or did that already get changed recently?
You should also set phc_index to -1 until you have a PTP clock device.
Quoted 25 lines
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +1
-0static void fbnic_get_drvinfo (struct net_device *netdev,struct ethtool_drvinfo *drvinfo) {@@ -66,6 +76,7 @@ fbnic_get_eth_mac_stats(struct net_device *netdev,static const struct ethtool_ops fbnic_ethtool_ops = { .get_drvinfo = fbnic_get_drvinfo, + .get_ts_info = fbnic_get_ts_info, .get_eth_mac_stats = fbnic_get_eth_mac_stats, };drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +3
-0@@ -205,6 +205,9 @@ fbnic_tx_map(struct fbnic_ring *ring, struct sk_buff *skb, __le64 *meta) ring->tail = tail; +/* Record SW timestamp */ +skb_tx_timestamp (skb); +/* Verify there is room for another packet */ fbnic_maybe_stop_tx (skb->dev, ring,FBNIC_MAX_SKB_DESC );
Re: [PATCH net-next v3 1/5] eth: fbnic: add software TX timestamping support
Quoted 5 lines · Jacob Keller
I think you *do* still want to report
SOF_TIMESTAMPING_RX_SOFTWAREandSOF_TIMESTAMPING_SOFTWAREto get the API correct... Perhaps that could be improved in the core stack though.... Or did that already get changed recently?
Ah, this did change recently, but the helper ethtool_op_get_ts_info() was not updated to do the same. :D
For other reviewers who weren't aware, this is true since 12d337339d9f ("ethtool: RX software timestamp for all")
Re: [PATCH net-next v3 1/5] eth: fbnic: add software TX timestamping support
In reply to Jacob KellerQuoted 36 lines · Jacob Keller
Quoted 18 lines · Vadim Fedorenko
Add software TX timestamping support. RX software timestamping is implemented in the core and there is no need to provide special flag in the driver anymore.
Signed-off-by Vadim Fedorenko <[email protected]>--- drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 11 +++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 3 +++ 2 files changed, 14 insertions(+)drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +0
-0@@ -6,6 +6,16 @@#include "fbnic_netdev.h" #include "fbnic_tlv.h" drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c line 18
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +10
-0+static int +fbnic_get_ts_info (struct net_device *netdev, +struct kernel_ethtool_ts_info *tsinfo) +{ + tsinfo->so_timestamping = +SOF_TIMESTAMPING_TX_SOFTWARE ; + +return 0 ; +} +You could use
ethtool_op_get_ts_info(), but I imagine future patches will update this for hardware timestamping, so I don't think thats a big deal.
Quoted 4 lines
I think you *do* still want to report
SOF_TIMESTAMPING_RX_SOFTWAREandSOF_TIMESTAMPING_SOFTWAREto get the API correct... Perhaps that could be improved in the core stack though.... Or did that already get changed recently?
Yeah, as you found in the next mail, software RX timestamping was moved to the core recently.
Quoted 1 line
You should also set
phc_indexto -1 until you have a PTP clock device.
That's definitely missing, thanks! I'll add it to the next version.
Quoted 27 lines
Quoted 26 lines
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +1
-0static void fbnic_get_drvinfo (struct net_device *netdev,struct ethtool_drvinfo *drvinfo) {@@ -66,6 +76,7 @@ fbnic_get_eth_mac_stats(struct net_device *netdev,static const struct ethtool_ops fbnic_ethtool_ops = { .get_drvinfo = fbnic_get_drvinfo, + .get_ts_info = fbnic_get_ts_info, .get_eth_mac_stats = fbnic_get_eth_mac_stats, };drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +3
-0@@ -205,6 +205,9 @@ fbnic_tx_map(struct fbnic_ring *ring, struct sk_buff *skb, __le64 *meta) ring->tail = tail; +/* Record SW timestamp */ +skb_tx_timestamp (skb); +/* Verify there is room for another packet */ fbnic_maybe_stop_tx (skb->dev, ring,FBNIC_MAX_SKB_DESC );
Re: [PATCH net-next v3 1/5] eth: fbnic: add software TX timestamping support
Quoted 42 lines · Vadim Fedorenko
Quoted 36 lines · Jacob Keller
Quoted 18 lines · Vadim Fedorenko
Add software TX timestamping support. RX software timestamping is implemented in the core and there is no need to provide special flag in the driver anymore.
Signed-off-by Vadim Fedorenko <[email protected]>--- drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 11 +++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 3 +++ 2 files changed, 14 insertions(+)drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +0
-0@@ -6,6 +6,16 @@#include "fbnic_netdev.h" #include "fbnic_tlv.h" drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c line 18
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +10
-0+static int +fbnic_get_ts_info (struct net_device *netdev, +struct kernel_ethtool_ts_info *tsinfo) +{ + tsinfo->so_timestamping = +SOF_TIMESTAMPING_TX_SOFTWARE ; + +return 0 ; +} +You could use
ethtool_op_get_ts_info(), but I imagine future patches will update this for hardware timestamping, so I don't think thats a big deal.Quoted 4 lines
I think you *do* still want to report
SOF_TIMESTAMPING_RX_SOFTWAREandSOF_TIMESTAMPING_SOFTWAREto get the API correct... Perhaps that could be improved in the core stack though.... Or did that already get changed recently?
Quoted 7 lines
Yeah, as you found in the next mail, software RX timestamping was moved to the core recently.
Quoted 1 line
You should also set
phc_indexto -1 until you have a PTP clock device.That's definitely missing, thanks! I'll add it to the next version.
Since I had missed this, I reviewed the patch that changed Rx timestamp to the core. It also initialized PHC index to -1 automatically so it shouldn't be necessary.
Apologies for the misleading comment.
PATCH v3 2/5 eth: fbnic: add initial PHC support
In reply to Vadim FedorenkoCreate PHC device and provide callbacks needed for ptp_clock device.
--- drivers/net/ethernet/meta/fbnic/Makefile | 3 +- drivers/net/ethernet/meta/fbnic/fbnic.h | 11 + drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 38 +++ .../net/ethernet/meta/fbnic/fbnic_netdev.c | 11 +- .../net/ethernet/meta/fbnic/fbnic_netdev.h | 15 + drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 9 +- drivers/net/ethernet/meta/fbnic/fbnic_time.c | 311 ++++++++++++++++++ 7 files changed, 394 insertions(+), 4 deletions(-) create mode 100644 drivers/net/ethernet/meta/fbnic/fbnic_time.c
drivers/net/ethernet/meta/fbnic/Makefile +2 -1
@@ -18,4 +18,5 @@ fbnic-y := fbnic_devlink.o \ fbnic_phylink.o \ fbnic_rpc.o \ fbnic_tlv.o \ - fbnic_txrx.o + fbnic_txrx.o \ + fbnic_time.o
drivers/net/ethernet/meta/fbnic/fbnic.h +11 -0
@@ -6,6 +6,7 @@#include <linux/interrupt.h> #include <linux/io.h> +#include <linux/ptp_clock_kernel.h> #include <linux/types.h> #include <linux/workqueue.h>
@@ -49,6 +50,16 @@ struct fbnic_dev {/* Number of TCQs/RCQs available on hardware */ u16 max_num_queues; +/* Lock protecting writes to @time_high, @time_offset of fbnic_netdev, +* and the HW time CSR machinery. +*/ +spinlock_t time_lock; +/* Externally accessible PTP clock, may be NULL */ +struct ptp_clock *ptp; +struct ptp_clock_info ptp_info; +/* Last @time_high refresh time in jiffies (to catch stalls) */ +unsigned long last_read; +/* Local copy of hardware statistics */ struct fbnic_hw_stats hw_stats; };
drivers/net/ethernet/meta/fbnic/fbnic_csr.h +38 -0
@@ -413,6 +413,44 @@ enum {#define FBNIC_TMI_DROP_CTRL 0x04401/* 0x11004 */ #define FBNIC_TMI_DROP_CTRL_EN CSR_BIT(0)#define FBNIC_CSR_END_TMI 0x0443f/* CSR section delimiter */ + +/* Precision Time Protocol Registers */ +#define FBNIC_CSR_START_PTP 0x04800/* CSR section delimiter */ +#define FBNIC_PTP_REG_BASE 0x04800/* 0x12000 */ + +#define FBNIC_PTP_CTRL 0x04800/* 0x12000 */ +#define FBNIC_PTP_CTRL_EN CSR_BIT(0) +#define FBNIC_PTP_CTRL_MONO_EN CSR_BIT(4) +#define FBNIC_PTP_CTRL_TQS_OUT_EN CSR_BIT(8) +#define FBNIC_PTP_CTRL_MAC_OUT_IVAL CSR_GENMASK(16, 12) +#define FBNIC_PTP_CTRL_TICK_IVAL CSR_GENMASK(23, 20) + +#define FBNIC_PTP_ADJUST 0x04801/* 0x12004 */ +#define FBNIC_PTP_ADJUST_INIT CSR_BIT(0) +#define FBNIC_PTP_ADJUST_SUB_NUDGE CSR_BIT(8) +#define FBNIC_PTP_ADJUST_ADD_NUDGE CSR_BIT(16) +#define FBNIC_PTP_ADJUST_ADDEND_SET CSR_BIT(24) + +#define FBNIC_PTP_INIT_HI 0x04802/* 0x12008 */ +#define FBNIC_PTP_INIT_LO 0x04803/* 0x1200c */ + +#define FBNIC_PTP_NUDGE_NS 0x04804/* 0x12010 */ +#define FBNIC_PTP_NUDGE_SUBNS 0x04805/* 0x12014 */ + +#define FBNIC_PTP_ADD_VAL_NS 0x04806/* 0x12018 */ +#define FBNIC_PTP_ADD_VAL_NS_MASK CSR_GENMASK(15, 0) +#define FBNIC_PTP_ADD_VAL_SUBNS 0x04807/* 0x1201c */ + +#define FBNIC_PTP_CTR_VAL_HI 0x04808/* 0x12020 */ +#define FBNIC_PTP_CTR_VAL_LO 0x04809/* 0x12024 */ + +#define FBNIC_PTP_MONO_PTP_CTR_HI 0x0480a/* 0x12028 */ +#define FBNIC_PTP_MONO_PTP_CTR_LO 0x0480b/* 0x1202c */ + +#define FBNIC_PTP_CDC_FIFO_STATUS 0x0480c/* 0x12030 */ +#define FBNIC_PTP_SPARE 0x0480d/* 0x12034 */ +#define FBNIC_CSR_END_PTP 0x0480d/* CSR section delimiter */ +/* Rx Buffer Registers */ #define FBNIC_CSR_START_RXB 0x08000/* CSR section delimiter */ enum {
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +9 -2
@@ -42,18 +42,24 @@ int __fbnic_open(struct fbnic_net *fbn) goto free_resources; } - err =fbnic_fw_init_heartbeat (fbd, false); + err =fbnic_time_start (fbn);if (err) goto release_ownership; + err =fbnic_fw_init_heartbeat (fbd, false); +if (err) + goto time_stop; + err =fbnic_pcs_irq_enable (fbd);if (err) - goto release_ownership; + goto time_stop;/* Pull the BMC config and initialize the RPC */ fbnic_bmc_rpc_init (fbd);fbnic_rss_reinit (fbd, fbn);return 0 ; +time_stop: +fbnic_time_stop (fbn); release_ownership:fbnic_fw_xmit_ownership_msg (fbn->fbd, false); free_resources:
@@ -82,6 +88,7 @@ static int fbnic_stop(struct net_device *netdev)fbnic_down (fbn);fbnic_pcs_irq_disable (fbn->fbd); +fbnic_time_stop (fbn);fbnic_fw_xmit_ownership_msg (fbn->fbd, false);fbnic_free_resources (fbn);
drivers/net/ethernet/meta/fbnic/fbnic_netdev.h +15 -0
@@ -33,6 +33,15 @@ struct fbnic_net {u8 fec;u8 link_mode; +/* Cached top bits of the HW time counter for 40b -> 64b conversion */ +u32 time_high; +/* Protect readers of @time_offset, writers take @time_lock. */ +struct u64_stats_sync time_seq; +/* Offset in ns between free running NIC PHC and time set via PTP +* clock callbacks +*/ +s64 time_offset; +u16 num_tx_queues;u16 num_rx_queues;
@@ -60,6 +69,12 @@ void fbnic_reset_queues(struct fbnic_net *fbn, unsigned int tx, unsigned int rx);void fbnic_set_ethtool_ops (struct net_device *dev); +int fbnic_ptp_setup (struct fbnic_dev *fbd); +void fbnic_ptp_destroy (struct fbnic_dev *fbd); +void fbnic_time_init (struct fbnic_net *fbn); +int fbnic_time_start (struct fbnic_net *fbn); +void fbnic_time_stop (struct fbnic_net *fbn); +void __fbnic_set_rx_mode (struct net_device *netdev);void fbnic_clear_rx_mode (struct net_device *netdev);
drivers/net/ethernet/meta/fbnic/fbnic_pci.c +8 -1
@@ -300,14 +300,20 @@ static int fbnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto init_failure_mode; } + err =fbnic_ptp_setup (fbd); +if (err) + goto ifm_free_netdev; + err =fbnic_netdev_register (netdev);if (err) {dev_err (&pdev->dev,"Netdev registration failed: %d\n" , err); - goto ifm_free_netdev; + goto ifm_destroy_ptp; }return 0 ; +ifm_destroy_ptp: +fbnic_ptp_destroy (fbd); ifm_free_netdev:fbnic_netdev_free (fbd); init_failure_mode:
@@ -342,6 +348,7 @@ static void fbnic_remove(struct pci_dev *pdev)fbnic_netdev_unregister (netdev);cancel_delayed_work_sync (&fbd->service_task); +fbnic_ptp_destroy (fbd);fbnic_netdev_free (fbd); }
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +311 -0
311 lines not on this page · raw message
Signature · 1 line
2.43.5
Re: [PATCH net-next v3 2/5] eth: fbnic: add initial PHC support
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 24
Quoted 11 lines · Vadim Fedorenko
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +11
-0+/* FBNIC timing & PTP implementation +* Datapath uses truncated 40b timestamps for scheduling and event reporting. +* We need to promote those to full 64b, hence we periodically cache the top +* 32bit of the HW time counter. Since this makes our time reporting non-atomic +* we leave the HW clock free running and adjust time offsets in SW as needed. +* Time offset is 64bit - we need a seq counter for 32bit machines. +* Time offset and the cache of top bits are independent so we don't need +* a coherent snapshot of both - READ_ONCE()/WRITE_ONCE() + writer side lock +* are enough. +*/ +
If you're going to implement adjustments only in software anyways, can you use a timecounter+cyclecounter instead of re-implementing?
Quoted 16 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +16
-0+/* Period of refresh of top bits of timestamp, give ourselves a 8x margin. +* This should translate to once a minute. +* The use of nsecs_to_jiffies() should be safe for a <=40b nsec value. +*/ +#define FBNIC_TS_HIGH_REFRESH_JIF nsecs_to_jiffies((1ULL << 40) / 16) + +static struct fbnic_dev *fbnic_from_ptp_info (struct ptp_clock_info *ptp) +{ + return container_of(ptp, struct fbnic_dev, ptp_info); +} + +/* This function is "slow" because we could try guessing which high part +* is correct based on low instead of re-reading, and skip reading @hi +* twice altogether if @lo is far enough from 0. +*/ +static u64 __fbnic_time_get_slow (struct fbnic_dev *fbd)
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 50
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +10
-0+{ +u32 hi, lo; + +lockdep_assert_held (&fbd->time_lock); + +do { + hi =fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_HI ); + lo =fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_LO ); + }while (hi !=fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_HI )); +
How long does it take hi to overflow? You may be able to get away without looping.
I think another way to implement this is to read lo, then hi, then lo again, and if lo2 is smaller than lo, you know hi overflowed and you can re-read hi
Quoted 13 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +13
-0+static int fbnic_ptp_adjfine (struct ptp_clock_info *ptp,long scaled_ppm) +{ +int scale =16 ;/* scaled_ppm has 16 fractional places */ +struct fbnic_dev *fbd =fbnic_from_ptp_info (ptp); +u64 scaled_delta, dclk_period; +unsigned long flags; +s64 delta; +int sgn; + + sgn = scaled_ppm >=0 ?1 :-1 ; + scaled_ppm *= sgn; + +/* d_clock is 600 MHz; which in Q16.32 fixed point ns is: */
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 123
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +10
-0+ dclk_period = (((u64 )1000000000 ) <<32 ) /FBNIC_CLOCK_FREQ ; + +while (scaled_ppm >U64_MAX / dclk_period) { + scaled_ppm >>=1 ; + scale--; + } + + scaled_delta = (u64 )scaled_ppm * dclk_period; + delta =div_u64 (scaled_delta,1000 *1000 ) >> scale; + delta *= sgn;
Please use adjust_by_scaled_ppm or diff_by_scaled_ppm. It makes use of mul_u64_u64_div_u64 where feasible to do the temporary multiplication step as 128 bit arithmetic.
Quoted 84 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +84
-0+ +spin_lock_irqsave (&fbd->time_lock, flags); +__fbnic_time_set_addend (fbd, dclk_period + delta); +fbnic_wr32 (fbd,FBNIC_PTP_ADJUST ,FBNIC_PTP_ADJUST_ADDEND_SET ); + +/* Flush, make sure FBNIC_PTP_ADD_VAL_* is stable for at least 4 clks */ +fbnic_rd32 (fbd,FBNIC_PTP_SPARE ); +spin_unlock_irqrestore (&fbd->time_lock, flags); + +return fbnic_present (fbd) ?0 : -EIO ; +} + +static int fbnic_ptp_adjtime (struct ptp_clock_info *ptp,s64 delta) +{ +struct fbnic_dev *fbd =fbnic_from_ptp_info (ptp); +struct fbnic_net *fbn; +unsigned long flags; + + fbn =netdev_priv (fbd->netdev); + +spin_lock_irqsave (&fbd->time_lock, flags); +u64_stats_update_begin (&fbn->time_seq); +WRITE_ONCE (fbn->time_offset,READ_ONCE (fbn->time_offset) + delta); +u64_stats_update_end (&fbn->time_seq); +spin_unlock_irqrestore (&fbd->time_lock, flags); + +return 0 ; +} + +static int +fbnic_ptp_gettimex64 (struct ptp_clock_info *ptp,struct timespec64 *ts, +struct ptp_system_timestamp *sts) +{ +struct fbnic_dev *fbd =fbnic_from_ptp_info (ptp); +struct fbnic_net *fbn; +unsigned long flags; +u64 time_ns; +u32 hi, lo; + + fbn =netdev_priv (fbd->netdev); + +spin_lock_irqsave (&fbd->time_lock, flags); + +do { + hi =fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_HI ); +ptp_read_system_prets (sts); + lo =fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_LO ); +ptp_read_system_postts (sts); +/* Similarly to comment above __fbnic_time_get_slow() +* - this can be optimized if needed. +*/ + }while (hi !=fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_HI )); + + time_ns = ((u64 )hi <<32 | lo) + fbn->time_offset; +spin_unlock_irqrestore (&fbd->time_lock, flags); + +if (!fbnic_present (fbd)) +return -EIO ; + + *ts =ns_to_timespec64 (time_ns); + +return 0 ; +} + +static int +fbnic_ptp_settime64 (struct ptp_clock_info *ptp,const struct timespec64 *ts) +{ +struct fbnic_dev *fbd =fbnic_from_ptp_info (ptp); +struct fbnic_net *fbn; +unsigned long flags; +u64 dev_ns, host_ns; +int ret; + + fbn =netdev_priv (fbd->netdev); + + host_ns =timespec64_to_ns (ts); + +spin_lock_irqsave (&fbd->time_lock, flags); + + dev_ns =__fbnic_time_get_slow (fbd); + +if (fbnic_present (fbd)) { +u64_stats_update_begin (&fbn->time_seq); +WRITE_ONCE (fbn->time_offset, host_ns - dev_ns);
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 217
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +10
-0+u64_stats_update_end (&fbn->time_seq); + ret =0 ; + }else { + ret = -EIO ; + } +spin_unlock_irqrestore (&fbd->time_lock, flags); + +return ret; +} +
Since all your operations are using a software offset and leaving the timer free-running, I think this really would make more sense using a timecounter and cyclecounter.
Quoted 32 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +32
-0+static const struct ptp_clock_info fbnic_ptp_info = { + .owner =THIS_MODULE , +/* 1,000,000,000 - 1 PPB to ensure increment is positive +* after max negative adjustment. +*/ + .max_adj =999999999 , + .do_aux_work = fbnic_ptp_do_aux_work, + .adjfine = fbnic_ptp_adjfine, + .adjtime = fbnic_ptp_adjtime, + .gettimex64 = fbnic_ptp_gettimex64, + .settime64 = fbnic_ptp_settime64, +}; + +static void fbnic_ptp_reset (struct fbnic_dev *fbd) +{ +struct fbnic_net *fbn =netdev_priv (fbd->netdev); +u64 dclk_period; + +fbnic_wr32 (fbd,FBNIC_PTP_CTRL , +FBNIC_PTP_CTRL_EN | +FIELD_PREP (FBNIC_PTP_CTRL_TICK_IVAL ,1 )); + +/* d_clock is 600 MHz; which in Q16.32 fixed point ns is: */ + dclk_period = (((u64 )1000000000 ) <<32 ) /FBNIC_CLOCK_FREQ ; + +__fbnic_time_set_addend (fbd, dclk_period); + +fbnic_wr32 (fbd,FBNIC_PTP_INIT_HI ,0 ); +fbnic_wr32 (fbd,FBNIC_PTP_INIT_LO ,0 ); + +fbnic_wr32 (fbd,FBNIC_PTP_ADJUST ,FBNIC_PTP_ADJUST_INIT ); +
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 259
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +10
-0+fbnic_wr32 (fbd,FBNIC_PTP_CTRL , +FBNIC_PTP_CTRL_EN | +FBNIC_PTP_CTRL_TQS_OUT_EN | +FIELD_PREP (FBNIC_PTP_CTRL_MAC_OUT_IVAL ,3 ) | +FIELD_PREP (FBNIC_PTP_CTRL_TICK_IVAL ,1 )); + +fbnic_rd32 (fbd,FBNIC_PTP_SPARE ); + + fbn->time_offset =0 ; + fbn->time_high =0 ;
Not entirely sure how it works for you, but we found that most users expect to minimize the time loss or changes due to a reset, and we re-apply the last known configuration during a reset instead of letting the clock reset back to base state.
Re: [PATCH net-next v3 2/5] eth: fbnic: add initial PHC support
Quoted 17 lines · Jacob Keller
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 24
Quoted 11 lines · Vadim Fedorenko
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +11
-0+/* FBNIC timing & PTP implementation +* Datapath uses truncated 40b timestamps for scheduling and event reporting. +* We need to promote those to full 64b, hence we periodically cache the top +* 32bit of the HW time counter. Since this makes our time reporting non-atomic +* we leave the HW clock free running and adjust time offsets in SW as needed. +* Time offset is 64bit - we need a seq counter for 32bit machines. +* Time offset and the cache of top bits are independent so we don't need +* a coherent snapshot of both - READ_ONCE()/WRITE_ONCE() + writer side lock +* are enough. +*/ +If you're going to implement adjustments only in software anyways, can you use a timecounter+cyclecounter instead of re-implementing?
Thanks for pointing this out, I'll make it with timecounter/cyclecounter
Quoted 22 lines
Quoted 22 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +21
-0+/* Period of refresh of top bits of timestamp, give ourselves a 8x margin. +* This should translate to once a minute. +* The use of nsecs_to_jiffies() should be safe for a <=40b nsec value. +*/ +#define FBNIC_TS_HIGH_REFRESH_JIF nsecs_to_jiffies((1ULL << 40) / 16) + +static struct fbnic_dev *fbnic_from_ptp_info (struct ptp_clock_info *ptp) +{ + return container_of(ptp, struct fbnic_dev, ptp_info); +} + +/* This function is "slow" because we could try guessing which high part +* is correct based on low instead of re-reading, and skip reading @hi +* twice altogether if @lo is far enough from 0. +*/ +static u64 __fbnic_time_get_slow (struct fbnic_dev *fbd) +{ +u32 hi, lo; + +lockdep_assert_held (&fbd->time_lock); +
Quoted 8 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 50
Quoted 5 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +5
-0+do { + hi =fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_HI ); + lo =fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_LO ); + }while (hi !=fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_HI )); +How long does it take hi to overflow? You may be able to get away without looping.
According to comment above it may take up to 8 minutes to overflow, but the updates to the cache should be done every minute. We do not expect this cycle to happen often.
Quoted 3 lines
I think another way to implement this is to read lo, then hi, then lo again, and if lo2 is smaller than lo, you know hi overflowed and you can re-read hi
That's an option too, I'll think of it, thanks!
Quoted 21 lines
Quoted 21 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +20
-0+static int fbnic_ptp_adjfine (struct ptp_clock_info *ptp,long scaled_ppm) +{ +int scale =16 ;/* scaled_ppm has 16 fractional places */ +struct fbnic_dev *fbd =fbnic_from_ptp_info (ptp); +u64 scaled_delta, dclk_period; +unsigned long flags; +s64 delta; +int sgn; + + sgn = scaled_ppm >=0 ?1 :-1 ; + scaled_ppm *= sgn; + +/* d_clock is 600 MHz; which in Q16.32 fixed point ns is: */ + dclk_period = (((u64 )1000000000 ) <<32 ) /FBNIC_CLOCK_FREQ ; + +while (scaled_ppm >U64_MAX / dclk_period) { + scaled_ppm >>=1 ; + scale--; + } +
Quoted 9 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 123
Quoted 3 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +3
-0+ scaled_delta = (u64 )scaled_ppm * dclk_period; + delta =div_u64 (scaled_delta,1000 *1000 ) >> scale; + delta *= sgn;Please use
adjust_by_scaled_ppmordiff_by_scaled_ppm. It makes use ofmul_u64_u64_div_u64where feasible to do the temporary multiplication step as 128 bit arithmetic.
Got it, will use it in the next version.
Quoted 90 lines
Quoted 90 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +90
-0+ +spin_lock_irqsave (&fbd->time_lock, flags); +__fbnic_time_set_addend (fbd, dclk_period + delta); +fbnic_wr32 (fbd,FBNIC_PTP_ADJUST ,FBNIC_PTP_ADJUST_ADDEND_SET ); + +/* Flush, make sure FBNIC_PTP_ADD_VAL_* is stable for at least 4 clks */ +fbnic_rd32 (fbd,FBNIC_PTP_SPARE ); +spin_unlock_irqrestore (&fbd->time_lock, flags); + +return fbnic_present (fbd) ?0 : -EIO ; +} + +static int fbnic_ptp_adjtime (struct ptp_clock_info *ptp,s64 delta) +{ +struct fbnic_dev *fbd =fbnic_from_ptp_info (ptp); +struct fbnic_net *fbn; +unsigned long flags; + + fbn =netdev_priv (fbd->netdev); + +spin_lock_irqsave (&fbd->time_lock, flags); +u64_stats_update_begin (&fbn->time_seq); +WRITE_ONCE (fbn->time_offset,READ_ONCE (fbn->time_offset) + delta); +u64_stats_update_end (&fbn->time_seq); +spin_unlock_irqrestore (&fbd->time_lock, flags); + +return 0 ; +} + +static int +fbnic_ptp_gettimex64 (struct ptp_clock_info *ptp,struct timespec64 *ts, +struct ptp_system_timestamp *sts) +{ +struct fbnic_dev *fbd =fbnic_from_ptp_info (ptp); +struct fbnic_net *fbn; +unsigned long flags; +u64 time_ns; +u32 hi, lo; + + fbn =netdev_priv (fbd->netdev); + +spin_lock_irqsave (&fbd->time_lock, flags); + +do { + hi =fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_HI ); +ptp_read_system_prets (sts); + lo =fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_LO ); +ptp_read_system_postts (sts); +/* Similarly to comment above __fbnic_time_get_slow() +* - this can be optimized if needed. +*/ + }while (hi !=fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_HI )); + + time_ns = ((u64 )hi <<32 | lo) + fbn->time_offset; +spin_unlock_irqrestore (&fbd->time_lock, flags); + +if (!fbnic_present (fbd)) +return -EIO ; + + *ts =ns_to_timespec64 (time_ns); + +return 0 ; +} + +static int +fbnic_ptp_settime64 (struct ptp_clock_info *ptp,const struct timespec64 *ts) +{ +struct fbnic_dev *fbd =fbnic_from_ptp_info (ptp); +struct fbnic_net *fbn; +unsigned long flags; +u64 dev_ns, host_ns; +int ret; + + fbn =netdev_priv (fbd->netdev); + + host_ns =timespec64_to_ns (ts); + +spin_lock_irqsave (&fbd->time_lock, flags); + + dev_ns =__fbnic_time_get_slow (fbd); + +if (fbnic_present (fbd)) { +u64_stats_update_begin (&fbn->time_seq); +WRITE_ONCE (fbn->time_offset, host_ns - dev_ns); +u64_stats_update_end (&fbn->time_seq); + ret =0 ; + }else { + ret = -EIO ; + } +spin_unlock_irqrestore (&fbd->time_lock, flags);
Quoted 9 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 217
Quoted 4 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +4
-0+ +return ret; +} +Since all your operations are using a software offset and leaving the timer free-running, I think this really would make more sense using a timecounter and cyclecounter.
Yeah, looks like it's better to use common interfaces.
Quoted 39 lines
Quoted 39 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +39
-0+static const struct ptp_clock_info fbnic_ptp_info = { + .owner =THIS_MODULE , +/* 1,000,000,000 - 1 PPB to ensure increment is positive +* after max negative adjustment. +*/ + .max_adj =999999999 , + .do_aux_work = fbnic_ptp_do_aux_work, + .adjfine = fbnic_ptp_adjfine, + .adjtime = fbnic_ptp_adjtime, + .gettimex64 = fbnic_ptp_gettimex64, + .settime64 = fbnic_ptp_settime64, +}; + +static void fbnic_ptp_reset (struct fbnic_dev *fbd) +{ +struct fbnic_net *fbn =netdev_priv (fbd->netdev); +u64 dclk_period; + +fbnic_wr32 (fbd,FBNIC_PTP_CTRL , +FBNIC_PTP_CTRL_EN | +FIELD_PREP (FBNIC_PTP_CTRL_TICK_IVAL ,1 )); + +/* d_clock is 600 MHz; which in Q16.32 fixed point ns is: */ + dclk_period = (((u64 )1000000000 ) <<32 ) /FBNIC_CLOCK_FREQ ; + +__fbnic_time_set_addend (fbd, dclk_period); + +fbnic_wr32 (fbd,FBNIC_PTP_INIT_HI ,0 ); +fbnic_wr32 (fbd,FBNIC_PTP_INIT_LO ,0 ); + +fbnic_wr32 (fbd,FBNIC_PTP_ADJUST ,FBNIC_PTP_ADJUST_INIT ); + +fbnic_wr32 (fbd,FBNIC_PTP_CTRL , +FBNIC_PTP_CTRL_EN | +FBNIC_PTP_CTRL_TQS_OUT_EN | +FIELD_PREP (FBNIC_PTP_CTRL_MAC_OUT_IVAL ,3 ) | +FIELD_PREP (FBNIC_PTP_CTRL_TICK_IVAL ,1 )); + +fbnic_rd32 (fbd,FBNIC_PTP_SPARE );
Quoted 8 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 259
Quoted 3 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +3
-0+ + fbn->time_offset =0 ; + fbn->time_high =0 ;Not entirely sure how it works for you, but we found that most users expect to minimize the time loss or changes due to a reset, and we re-apply the last known configuration during a reset instead of letting the clock reset back to base state.
In case of reset the counter will be re-initialized, which means the stored offset will be invalid anyways. It's better to reset values back to base state because it will make easier for the app to decide to make a step rather then adjust frequency. And it will make clocks align faster.
Jakub Kicinski
maintainerRe: [PATCH net-next v3 2/5] eth: fbnic: add initial PHC support
Quoted 14 lines · On Mon, 7 Oct 2024 14:07:17 +0100 Vadim Fedorenko wrote:
Quoted 13 lines · Jacob Keller
Quoted 11 lines · Vadim Fedorenko
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +11
-0+/* FBNIC timing & PTP implementation +* Datapath uses truncated 40b timestamps for scheduling and event reporting. +* We need to promote those to full 64b, hence we periodically cache the top +* 32bit of the HW time counter. Since this makes our time reporting non-atomic +* we leave the HW clock free running and adjust time offsets in SW as needed. +* Time offset is 64bit - we need a seq counter for 32bit machines. +* Time offset and the cache of top bits are independent so we don't need +* a coherent snapshot of both - READ_ONCE()/WRITE_ONCE() + writer side lock +* are enough. +*/ +
Quoted 4 lines
Quoted 2 lines
If you're going to implement adjustments only in software anyways, can you use a timecounter+cyclecounter instead of re-implementing?
Thanks for pointing this out, I'll make it with timecounter/cyclecounter
Please don't, the clock is synthonized, we only do simple offsetting.
Quoted 34 lines
Quoted 21 lines
Quoted 21 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +21
-0+/* Period of refresh of top bits of timestamp, give ourselves a 8x margin. +* This should translate to once a minute. +* The use of nsecs_to_jiffies() should be safe for a <=40b nsec value. +*/ +#define FBNIC_TS_HIGH_REFRESH_JIF nsecs_to_jiffies((1ULL << 40) / 16) + +static struct fbnic_dev *fbnic_from_ptp_info (struct ptp_clock_info *ptp) +{ + return container_of(ptp, struct fbnic_dev, ptp_info); +} + +/* This function is "slow" because we could try guessing which high part +* is correct based on low instead of re-reading, and skip reading @hi +* twice altogether if @lo is far enough from 0. +*/ +static u64 __fbnic_time_get_slow (struct fbnic_dev *fbd) +{ +u32 hi, lo; + +lockdep_assert_held (&fbd->time_lock); +Quoted 8 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c line 50
Quoted 5 lines
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +5
-0+do { + hi =fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_HI ); + lo =fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_LO ); + }while (hi !=fbnic_rd32 (fbd,FBNIC_PTP_CTR_VAL_HI )); +How long does it take hi to overflow? You may be able to get away without looping.
According to comment above it may take up to 8 minutes to overflow, but the updates to the cache should be done every minute. We do not expect this cycle to happen often.
Quoted 5 lines
Quoted 3 lines
I think another way to implement this is to read lo, then hi, then lo again, and if lo2 is smaller than lo, you know hi overflowed and you can re-read hi
That's an option too, I'll think of it, thanks!
The triple read is less neat in case hi jumps by more than 1.
Re: [PATCH net-next v3 2/5] eth: fbnic: add initial PHC support
Quoted 15 lines · Jakub Kicinski
Quoted 14 lines · On Mon, 7 Oct 2024 14:07:17 +0100 Vadim Fedorenko wrote:
Quoted 13 lines · Jacob Keller
Quoted 11 lines · Vadim Fedorenko
drivers/net/ethernet/meta/fbnic/fbnic_time.c new file +11
-0+/* FBNIC timing & PTP implementation +* Datapath uses truncated 40b timestamps for scheduling and event reporting. +* We need to promote those to full 64b, hence we periodically cache the top +* 32bit of the HW time counter. Since this makes our time reporting non-atomic +* we leave the HW clock free running and adjust time offsets in SW as needed. +* Time offset is 64bit - we need a seq counter for 32bit machines. +* Time offset and the cache of top bits are independent so we don't need +* a coherent snapshot of both - READ_ONCE()/WRITE_ONCE() + writer side lock +* are enough. +*/ +
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
If you're going to implement adjustments only in software anyways, can you use a timecounter+cyclecounter instead of re-implementing?
Thanks for pointing this out, I'll make it with timecounter/cyclecounter
Please don't, the clock is synthonized, we only do simple offsetting.
I still think it makes sense to re-use the logic for converting cycles to full 64bit time values if possible.
If you're already doing offset adjustment, you still have to apply the same logic to every timestamp, which is exactly what a timecounter does for you.
You can even use a timecounter and cyclecounter without using its ability to do syntonizing, by just setting the cyclecounter values appropriately, and leaving the syntonizing to the hardware mechanism.
I think the result is much easier to understand and follow than re-implementing a different mechanism for offset correction with bespoke code.
Jakub Kicinski
maintainerRe: [PATCH net-next v3 2/5] eth: fbnic: add initial PHC support
Quoted 10 lines · On Mon, 7 Oct 2024 16:49:45 -0700 Jacob Keller wrote:
Quoted 4 lines
Quoted 1 line
Thanks for pointing this out, I'll make it with timecounter/cyclecounter
Please don't, the clock is synthonized, we only do simple offsetting.
I still think it makes sense to re-use the logic for converting cycles to full 64bit time values if possible.
If you're already doing offset adjustment, you still have to apply the same logic to every timestamp, which is exactly what a timecounter does for you.
"exactly what a timecounter does for you" is an overstatement. timecounter tracks the overflows by itself and synthonizes. We have the 64b value, just need to combine the top bits.
Quoted 7 lines
You can even use a timecounter and cyclecounter without using its ability to do syntonizing, by just setting the cyclecounter values appropriately, and leaving the syntonizing to the hardware mechanism.
I think the result is much easier to understand and follow than re-implementing a different mechanism for offset correction with bespoke code.
This is fast path code, I hope we can get a simple addition and an overflow check right.
Re: [PATCH net-next v3 2/5] eth: fbnic: add initial PHC support
In reply to Jakub KicinskiQuoted 8 lines · Jakub Kicinski
Quoted 5 lines
Quoted 3 lines
I think another way to implement this is to read lo, then hi, then lo again, and if lo2 is smaller than lo, you know hi overflowed and you can re-read hi
That's an option too, I'll think of it, thanks!
The triple read is less neat in case hi jumps by more than 1.
Wouldn't that require the lower bits to accumulate more than an entire cycle for that to happen?
PATCH v3 3/5 eth: fbnic: add RX packets timestamping support
In reply to Vadim FedorenkoAdd callbacks to support timestamping configuration via ethtool. Add processing of RX timestamps.
--- drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 1 + .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 16 +++- .../net/ethernet/meta/fbnic/fbnic_netdev.c | 80 +++++++++++++++++++ .../net/ethernet/meta/fbnic/fbnic_netdev.h | 3 + drivers/net/ethernet/meta/fbnic/fbnic_rpc.c | 31 +++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 61 ++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 1 + 7 files changed, 192 insertions(+), 1 deletion(-)
drivers/net/ethernet/meta/fbnic/fbnic_csr.h +1 -0
@@ -586,6 +586,7 @@ enum { };#define FBNIC_RPC_ACT_TBL0_DMA_HINT CSR_GENMASK(24, 16) +#define FBNIC_RPC_ACT_TBL0_TS_ENA CSR_BIT(28)#define FBNIC_RPC_ACT_TBL0_RSS_CTXT_ID CSR_BIT(30)#define FBNIC_RPC_ACT_TBL1_DEFAULT 0x0840b/* 0x2102c */
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +15 -1
@@ -10,8 +10,22 @@ static int fbnic_get_ts_info(struct net_device *netdev, struct kernel_ethtool_ts_info *tsinfo) { + struct fbnic_net *fbn = netdev_priv(netdev); + + tsinfo->phc_index =ptp_clock_index (fbn->fbd->ptp); + tsinfo->so_timestamping = -SOF_TIMESTAMPING_TX_SOFTWARE ; +SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + + tsinfo->rx_filters = +BIT (HWTSTAMP_FILTER_NONE ) | +BIT (HWTSTAMP_FILTER_PTP_V1_L4_EVENT ) | +BIT (HWTSTAMP_FILTER_PTP_V2_L4_EVENT ) | +BIT (HWTSTAMP_FILTER_PTP_V2_L2_EVENT ) | +BIT (HWTSTAMP_FILTER_PTP_V2_EVENT ) | +BIT (HWTSTAMP_FILTER_ALL );return 0 ; }
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +80 -0
92 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_netdev.h +3 -0
@@ -54,6 +54,9 @@ struct fbnic_net {struct fbnic_queue_stats rx_stats;u64 link_down_events; +/* Time stampinn filter config */ +struct kernel_hwtstamp_config hwtstamp_config; +struct list_head napis; };
drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +31 -0
@@ -244,6 +244,12 @@ void fbnic_bmc_rpc_init(struct fbnic_dev *fbd) ((_ip) ? FBNIC_RPC_TCAM_ACT1_IP_VALID : 0) | \ ((_v6) ? FBNIC_RPC_TCAM_ACT1_IP_IS_V6 : 0)) +#define FBNIC_TSTAMP_MASK (_all, _udp, _ether) \ + (((_all) ? ((1u << FBNIC_NUM_HASH_OPT) - 1) : 0) | \ + ((_udp) ? (1u << FBNIC_UDP6_HASH_OPT) | \ + (1u << FBNIC_UDP4_HASH_OPT) : 0) | \ + ((_ether) ? (1u << FBNIC_ETHER_HASH_OPT) : 0)) +void fbnic_rss_reinit (struct fbnic_dev *fbd,struct fbnic_net *fbn) {static const u32 act1_value[FBNIC_NUM_HASH_OPT ] = {
@@ -255,6 +261,7 @@ void fbnic_rss_reinit(struct fbnic_dev *fbd, struct fbnic_net *fbn)FBNIC_ACT1_INIT (0 ,0 ,1 ,0 ),/* IP4 */ 0 /* Ether */ }; +u32 tstamp_mask =0 ;unsigned int i;/* To support scenarios where a BMC is present we must write the
@@ -264,6 +271,28 @@ void fbnic_rss_reinit(struct fbnic_dev *fbd, struct fbnic_net *fbn)BUILD_BUG_ON (FBNIC_RSS_EN_NUM_UNICAST *2 !=FBNIC_RSS_EN_NUM_ENTRIES );BUILD_BUG_ON (ARRAY_SIZE (act1_value) !=FBNIC_NUM_HASH_OPT ); +/* Set timestamp mask with 1b per flow type */ +if (fbn->hwtstamp_config.rx_filter !=HWTSTAMP_FILTER_NONE ) { +switch (fbn->hwtstamp_config.rx_filter) { +case HWTSTAMP_FILTER_ALL : + tstamp_mask =FBNIC_TSTAMP_MASK (1 ,1 ,1 ); +break ; +case HWTSTAMP_FILTER_PTP_V2_EVENT : + tstamp_mask =FBNIC_TSTAMP_MASK (0 ,1 ,1 ); +break ; +case HWTSTAMP_FILTER_PTP_V1_L4_EVENT : +case HWTSTAMP_FILTER_PTP_V2_L4_EVENT : + tstamp_mask =FBNIC_TSTAMP_MASK (0 ,1 ,0 ); +break ; +case HWTSTAMP_FILTER_PTP_V2_L2_EVENT : + tstamp_mask =FBNIC_TSTAMP_MASK (0 ,0 ,1 ); +break ; +default : +netdev_warn (fbn->netdev,"Unsupported hwtstamp_rx_filter\n" ); +break ; + } + } +/* Program RSS hash enable mask for host in action TCAM/table. */ for (i =fbnic_bmc_present (fbd) ?0 :FBNIC_RSS_EN_NUM_UNICAST ; i <FBNIC_RSS_EN_NUM_ENTRIES ; i++) {
@@ -287,6 +316,8 @@ void fbnic_rss_reinit(struct fbnic_dev *fbd, struct fbnic_net *fbn)if (!dest) dest =FBNIC_RPC_ACT_TBL0_DROP ; +else if (tstamp_mask & (1u << flow_type)) + dest |=FBNIC_RPC_ACT_TBL0_TS_ENA ;if (act1_value[flow_type] &FBNIC_RPC_TCAM_ACT1_L4_VALID ) dest |= FIELD_PREP(FBNIC_RPC_ACT_TBL0_DMA_HINT,
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +61 -0
85 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +1 -0
@@ -47,6 +47,7 @@ struct fbnic_net;struct fbnic_pkt_buff {struct xdp_buff buff; +ktime_t hwtstamp;u32 data_truesize;u16 data_len;u16 nr_frags;
Signature · 1 line
2.43.5
Re: [PATCH net-next v3 3/5] eth: fbnic: add RX packets timestamping support
Quoted 33 lines · Vadim Fedorenko
Add callbacks to support timestamping configuration via ethtool. Add processing of RX timestamps.
Signed-off-by Vadim Fedorenko <[email protected]>drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +28
-0+/** +* fbnic_ts40_to_ns() - convert descriptor timestamp to PHC time +* @fbn: netdev priv of the FB NIC +* @ts40: timestamp read from a descriptor +* +* Return: u64 value of PHC time in nanoseconds +* +* Convert truncated 40 bit device timestamp as read from a descriptor +* to the full PHC time in nanoseconds. +*/ +static __maybe_unused u64 fbnic_ts40_to_ns (struct fbnic_net *fbn,u64 ts40) +{ +unsigned int s; +u64 time_ns; +s64 offset; +u8 ts_top; +u32 high; + +do { + s =u64_stats_fetch_begin (&fbn->time_seq); + offset =READ_ONCE (fbn->time_offset); + }while (u64_stats_fetch_retry (&fbn->time_seq, s)); + + high =READ_ONCE (fbn->time_high); + +/* Bits 63..40 from periodic clock reads, 39..0 from ts40 */ + time_ns = (u64)(high >>8 ) <<40 | ts40; +
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c static void fbnic_ring_wr32(struct fbnic_ring *ring, unsigned int csr, u32 val) · line 83
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +10
-0+/* Compare bits 32-39 between periodic reads and ts40, +* see if HW clock may have wrapped since last read +*/ + ts_top = ts40 >>32 ; +if (ts_top < (u8 )high && (u8 )high - ts_top >U8_MAX /2 ) + time_ns +=1ULL <<40 ; + +return time_ns + offset; +} +
This logic doesn't seem to match the logic used by the cyclecounter code, and Its not clear to me if this safe against a race between time_high updating and the packet timestamp arriving.
the timestamp could arrive either before or after the time_high update, and the logic needs to ensure the appropriate high bits are applied in both cases.
Again, I think your use case makes sense to just implement with a timecounter and cyclecounter, since you're not modifying the hardware cycle counter and are leaving it as free-running.
Re: [PATCH net-next v3 3/5] eth: fbnic: add RX packets timestamping support
Quoted 51 lines · Jacob Keller
Quoted 33 lines · Vadim Fedorenko
Add callbacks to support timestamping configuration via ethtool. Add processing of RX timestamps.
Signed-off-by Vadim Fedorenko <[email protected]>drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +28
-0+/** +* fbnic_ts40_to_ns() - convert descriptor timestamp to PHC time +* @fbn: netdev priv of the FB NIC +* @ts40: timestamp read from a descriptor +* +* Return: u64 value of PHC time in nanoseconds +* +* Convert truncated 40 bit device timestamp as read from a descriptor +* to the full PHC time in nanoseconds. +*/ +static __maybe_unused u64 fbnic_ts40_to_ns (struct fbnic_net *fbn,u64 ts40) +{ +unsigned int s; +u64 time_ns; +s64 offset; +u8 ts_top; +u32 high; + +do { + s =u64_stats_fetch_begin (&fbn->time_seq); + offset =READ_ONCE (fbn->time_offset); + }while (u64_stats_fetch_retry (&fbn->time_seq, s)); + + high =READ_ONCE (fbn->time_high); + +/* Bits 63..40 from periodic clock reads, 39..0 from ts40 */ + time_ns = (u64)(high >>8 ) <<40 | ts40; +drivers/net/ethernet/meta/fbnic/fbnic_txrx.c static void fbnic_ring_wr32(struct fbnic_ring *ring, unsigned int csr, u32 val) · line 83
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +10
-0+/* Compare bits 32-39 between periodic reads and ts40, +* see if HW clock may have wrapped since last read +*/ + ts_top = ts40 >>32 ; +if (ts_top < (u8 )high && (u8 )high - ts_top >U8_MAX /2 ) + time_ns +=1ULL <<40 ; + +return time_ns + offset; +} +This logic doesn't seem to match the logic used by the cyclecounter code, and Its not clear to me if this safe against a race between
time_highupdating and the packet timestamp arriving.
Quoted 3 lines
the timestamp could arrive either before or after the
time_highupdate, and the logic needs to ensure the appropriate high bits are applied in both cases.
To avoid this race condition we decided to make sure that incoming timestamps are always later then cached high bits. That will make the logic above correct.
Quoted 3 lines
Again, I think your use case makes sense to just implement with a timecounter and cyclecounter, since you're not modifying the hardware cycle counter and are leaving it as free-running.
After discussion with Jakub we decided to keep simple logic without timecounter + cyclecounter, as it's pretty straight forward.
Re: [PATCH net-next v3 3/5] eth: fbnic: add RX packets timestamping support
Quoted 52 lines · Vadim Fedorenko
Quoted 51 lines · Jacob Keller
Quoted 33 lines · Vadim Fedorenko
Add callbacks to support timestamping configuration via ethtool. Add processing of RX timestamps.
Signed-off-by Vadim Fedorenko <[email protected]>drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +28
-0+/** +* fbnic_ts40_to_ns() - convert descriptor timestamp to PHC time +* @fbn: netdev priv of the FB NIC +* @ts40: timestamp read from a descriptor +* +* Return: u64 value of PHC time in nanoseconds +* +* Convert truncated 40 bit device timestamp as read from a descriptor +* to the full PHC time in nanoseconds. +*/ +static __maybe_unused u64 fbnic_ts40_to_ns (struct fbnic_net *fbn,u64 ts40) +{ +unsigned int s; +u64 time_ns; +s64 offset; +u8 ts_top; +u32 high; + +do { + s =u64_stats_fetch_begin (&fbn->time_seq); + offset =READ_ONCE (fbn->time_offset); + }while (u64_stats_fetch_retry (&fbn->time_seq, s)); + + high =READ_ONCE (fbn->time_high); + +/* Bits 63..40 from periodic clock reads, 39..0 from ts40 */ + time_ns = (u64)(high >>8 ) <<40 | ts40; +drivers/net/ethernet/meta/fbnic/fbnic_txrx.c static void fbnic_ring_wr32(struct fbnic_ring *ring, unsigned int csr, u32 val) · line 83
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +10
-0+/* Compare bits 32-39 between periodic reads and ts40, +* see if HW clock may have wrapped since last read +*/ + ts_top = ts40 >>32 ; +if (ts_top < (u8 )high && (u8 )high - ts_top >U8_MAX /2 ) + time_ns +=1ULL <<40 ; + +return time_ns + offset; +} +This logic doesn't seem to match the logic used by the cyclecounter code, and Its not clear to me if this safe against a race between
time_highupdating and the packet timestamp arriving.
Quoted 8 lines
Quoted 3 lines
the timestamp could arrive either before or after the
time_highupdate, and the logic needs to ensure the appropriate high bits are applied in both cases.To avoid this race condition we decided to make sure that incoming timestamps are always later then cached high bits. That will make the logic above correct.
How do you do that? Timestamps come in asynchronously. The value is captured by hardware. How do you guarantee that it was captured only after an update to the cached high bits?
I guess if it arrives before the roll-over, you handle that by the range check to see if the clock wrapped around.
Hmm.
But what happens if an Rx timestamp races with an update to the high value and comes in just before the 40 bit time would have overflowed, but the cached time_high value is captured just after it overflowed.
Do you have some mechanism to ensure that this is impossible? i.e. either ensuring that the conversion uses the old time_high value, or ensuring that Rx timestamps can't come in during an update?
Otherwise, I think the logic here could accidentally combine a time value from an Rx timestamp that is just prior to the time_high update and just prior to a rollover, then it would see a huge gap between the values and trigger the addition of another 1 << 40, which would cycle it even farther out of what the real value should have been.
Quoted 6 lines
Quoted 3 lines
Again, I think your use case makes sense to just implement with a timecounter and cyclecounter, since you're not modifying the hardware cycle counter and are leaving it as free-running.
After discussion with Jakub we decided to keep simple logic without timecounter + cyclecounter, as it's pretty straight forward.
Fair enough.
Re: [PATCH net-next v3 3/5] eth: fbnic: add RX packets timestamping support
Quoted 81 lines · Jacob Keller
Quoted 52 lines · Vadim Fedorenko
Quoted 51 lines · Jacob Keller
Quoted 33 lines · Vadim Fedorenko
Add callbacks to support timestamping configuration via ethtool. Add processing of RX timestamps.
Signed-off-by Vadim Fedorenko <[email protected]>drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +28
-0+/** +* fbnic_ts40_to_ns() - convert descriptor timestamp to PHC time +* @fbn: netdev priv of the FB NIC +* @ts40: timestamp read from a descriptor +* +* Return: u64 value of PHC time in nanoseconds +* +* Convert truncated 40 bit device timestamp as read from a descriptor +* to the full PHC time in nanoseconds. +*/ +static __maybe_unused u64 fbnic_ts40_to_ns (struct fbnic_net *fbn,u64 ts40) +{ +unsigned int s; +u64 time_ns; +s64 offset; +u8 ts_top; +u32 high; + +do { + s =u64_stats_fetch_begin (&fbn->time_seq); + offset =READ_ONCE (fbn->time_offset); + }while (u64_stats_fetch_retry (&fbn->time_seq, s)); + + high =READ_ONCE (fbn->time_high); + +/* Bits 63..40 from periodic clock reads, 39..0 from ts40 */ + time_ns = (u64)(high >>8 ) <<40 | ts40; +drivers/net/ethernet/meta/fbnic/fbnic_txrx.c static void fbnic_ring_wr32(struct fbnic_ring *ring, unsigned int csr, u32 val) · line 83
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +10
-0+/* Compare bits 32-39 between periodic reads and ts40, +* see if HW clock may have wrapped since last read +*/ + ts_top = ts40 >>32 ; +if (ts_top < (u8 )high && (u8 )high - ts_top >U8_MAX /2 ) + time_ns +=1ULL <<40 ; + +return time_ns + offset; +} +This logic doesn't seem to match the logic used by the cyclecounter code, and Its not clear to me if this safe against a race between
time_highupdating and the packet timestamp arriving.Quoted 8 lines
Quoted 3 lines
the timestamp could arrive either before or after the
time_highupdate, and the logic needs to ensure the appropriate high bits are applied in both cases.To avoid this race condition we decided to make sure that incoming timestamps are always later then cached high bits. That will make the logic above correct.
How do you do that? Timestamps come in asynchronously. The value is captured by hardware. How do you guarantee that it was captured only after an update to the cached high bits?
I guess if it arrives before the roll-over, you handle that by the range check to see if the clock wrapped around.
Hmm.
But what happens if an Rx timestamp races with an update to the high value and comes in just before the 40 bit time would have overflowed, but the cached
time_highvalue is captured just after it overflowed.Do you have some mechanism to ensure that this is impossible? i.e. either ensuring that the conversion uses the old
time_highvalue, or ensuring that Rx timestamps can't come in during an update?
Quoted 5 lines
Otherwise, I think the logic here could accidentally combine a time value from an Rx timestamp that is just prior to the
time_highupdate and just prior to a rollover, then it would see a huge gap between the values and trigger the addition of another 1 << 40, which would cycle it even farther out of what the real value should have been.
Yes, you are absolutely correct, we have missed the situation when the logic can bring additional (1 << 40) value on top of wrongly calculated higher bits. This can only happen in case of overflow of lower 8 bits of high cached value. But if we keep high cached value a bit below the real value, this will never happen. If we subtract 16 from high value it will translate into ~1 minute of oldness of cached value. If for any reasons the packet processing will be delayed by 1 minute, user-space app will definitely give up on waiting for the packet/timestamp and will ignore wrong timestamp. In all other cases the logic in fbnic_ts40_to_ns() will work perfectly fine.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Again, I think your use case makes sense to just implement with a timecounter and cyclecounter, since you're not modifying the hardware cycle counter and are leaving it as free-running.
After discussion with Jakub we decided to keep simple logic without timecounter + cyclecounter, as it's pretty straight forward.
Fair enough.
Re: [PATCH net-next v3 3/5] eth: fbnic: add RX packets timestamping support
In reply to Vadim FedorenkoQuoted 57 lines · Vadim Fedorenko
Add callbacks to support timestamping configuration via ethtool. Add processing of RX timestamps.
Signed-off-by Vadim Fedorenko <[email protected]>---
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +52
-0+static int fbnic_hwtstamp_set (struct net_device *netdev, +struct kernel_hwtstamp_config *config, +struct netlink_ext_ack *extack) +{ +struct fbnic_net *fbn =netdev_priv (netdev); +int old_rx_filter; + +if (config->source !=HWTSTAMP_SOURCE_NETDEV ) +return -EOPNOTSUPP ; + +if (!kernel_hwtstamp_config_changed (config, &fbn->hwtstamp_config)) +return 0 ; + +/* Upscale the filters */ +switch (config->rx_filter) { +case HWTSTAMP_FILTER_NONE : +case HWTSTAMP_FILTER_ALL : +case HWTSTAMP_FILTER_PTP_V1_L4_EVENT : +case HWTSTAMP_FILTER_PTP_V2_L4_EVENT : +case HWTSTAMP_FILTER_PTP_V2_L2_EVENT : +case HWTSTAMP_FILTER_PTP_V2_EVENT : +break ; +case HWTSTAMP_FILTER_NTP_ALL : + config->rx_filter =HWTSTAMP_FILTER_ALL ; +break ; +case HWTSTAMP_FILTER_PTP_V1_L4_SYNC : +case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ : + config->rx_filter =HWTSTAMP_FILTER_PTP_V1_L4_EVENT ; +break ; +case HWTSTAMP_FILTER_PTP_V2_L4_SYNC : +case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ : + config->rx_filter =HWTSTAMP_FILTER_PTP_V2_L4_EVENT ; +break ; +case HWTSTAMP_FILTER_PTP_V2_L2_SYNC : +case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ : + config->rx_filter =HWTSTAMP_FILTER_PTP_V2_L2_EVENT ; +break ; +case HWTSTAMP_FILTER_PTP_V2_SYNC : +case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ : + config->rx_filter =HWTSTAMP_FILTER_PTP_V2_EVENT ; +break ; +default : +return -ERANGE ; + } + +/* Configure */ + old_rx_filter = fbn->hwtstamp_config.rx_filter; +memcpy (&fbn->hwtstamp_config, config,sizeof (*config)); + +if (old_rx_filter != config->rx_filter &&netif_running (fbn->netdev)) { +fbnic_rss_reinit (fbn->fbd, fbn); +fbnic_write_rules (fbn->fbd);
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c void fbnic_clear_rx_mode(struct net_device *netdev) · line 398
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +10
-0+ } + +/* Save / report back filter configuration +* Note that our filter configuration is inexact. Instead of +* filtering for a specific UDP port or L2 Ethertype we are +* filtering in all UDP or all non-IP packets for timestamping. So +* if anything other than FILTER_ALL is requested we report +* FILTER_SOME indicating that we will be timestamping a few +* additional packets. +*/
Is there any benefit to implementing anything other than HWTSTAMP_FILTER_ALL?
Those are typically considered legacy with the primary reason being to support hardware which does not support timestamping all frames.
I suppose if you have measurement that supporting them is valuable (i.e. because of performance impact on timestamping all frames?) it makes sense to support. But otherwise I'm not sure its worth the extra complexity.
Upgrading the filtering modes to HWTSTAMP_FILTER_ALL is acceptable and is done by a few drivers.
Re: [PATCH net-next v3 3/5] eth: fbnic: add RX packets timestamping support
Quoted 77 lines · Jacob Keller
Quoted 57 lines · Vadim Fedorenko
Add callbacks to support timestamping configuration via ethtool. Add processing of RX timestamps.
Signed-off-by Vadim Fedorenko <[email protected]>---
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +52
-0+static int fbnic_hwtstamp_set (struct net_device *netdev, +struct kernel_hwtstamp_config *config, +struct netlink_ext_ack *extack) +{ +struct fbnic_net *fbn =netdev_priv (netdev); +int old_rx_filter; + +if (config->source !=HWTSTAMP_SOURCE_NETDEV ) +return -EOPNOTSUPP ; + +if (!kernel_hwtstamp_config_changed (config, &fbn->hwtstamp_config)) +return 0 ; + +/* Upscale the filters */ +switch (config->rx_filter) { +case HWTSTAMP_FILTER_NONE : +case HWTSTAMP_FILTER_ALL : +case HWTSTAMP_FILTER_PTP_V1_L4_EVENT : +case HWTSTAMP_FILTER_PTP_V2_L4_EVENT : +case HWTSTAMP_FILTER_PTP_V2_L2_EVENT : +case HWTSTAMP_FILTER_PTP_V2_EVENT : +break ; +case HWTSTAMP_FILTER_NTP_ALL : + config->rx_filter =HWTSTAMP_FILTER_ALL ; +break ; +case HWTSTAMP_FILTER_PTP_V1_L4_SYNC : +case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ : + config->rx_filter =HWTSTAMP_FILTER_PTP_V1_L4_EVENT ; +break ; +case HWTSTAMP_FILTER_PTP_V2_L4_SYNC : +case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ : + config->rx_filter =HWTSTAMP_FILTER_PTP_V2_L4_EVENT ; +break ; +case HWTSTAMP_FILTER_PTP_V2_L2_SYNC : +case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ : + config->rx_filter =HWTSTAMP_FILTER_PTP_V2_L2_EVENT ; +break ; +case HWTSTAMP_FILTER_PTP_V2_SYNC : +case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ : + config->rx_filter =HWTSTAMP_FILTER_PTP_V2_EVENT ; +break ; +default : +return -ERANGE ; + } + +/* Configure */ + old_rx_filter = fbn->hwtstamp_config.rx_filter; +memcpy (&fbn->hwtstamp_config, config,sizeof (*config)); + +if (old_rx_filter != config->rx_filter &&netif_running (fbn->netdev)) { +fbnic_rss_reinit (fbn->fbd, fbn); +fbnic_write_rules (fbn->fbd);drivers/net/ethernet/meta/fbnic/fbnic_netdev.c void fbnic_clear_rx_mode(struct net_device *netdev) · line 398
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +10
-0+ } + +/* Save / report back filter configuration +* Note that our filter configuration is inexact. Instead of +* filtering for a specific UDP port or L2 Ethertype we are +* filtering in all UDP or all non-IP packets for timestamping. So +* if anything other than FILTER_ALL is requested we report +* FILTER_SOME indicating that we will be timestamping a few +* additional packets. +*/ Is there any benefit to implementing anything other than
HWTSTAMP_FILTER_ALL?Those are typically considered legacy with the primary reason being to support hardware which does not support timestamping all frames.
Quoted 6 lines
I suppose if you have measurement that supporting them is valuable (i.e. because of performance impact on timestamping all frames?) it makes sense to support. But otherwise I'm not sure its worth the extra complexity.
Upgrading the filtering modes to
HWTSTAMP_FILTER_ALLis acceptable and is done by a few drivers.
Even though the hardware is able to timestamp TX packets at line rate, we would like to avoid having 2x times more interrupts for the cases when we don't need all packets to be timestamped. And as it mentioned in the comment, we don't have very precise HW filters, but we would like to avoid timestamping TCP packets when TCP is the most used one on the host.
Re: [PATCH net-next v3 3/5] eth: fbnic: add RX packets timestamping support
Quoted 14 lines · Vadim Fedorenko
Quoted 6 lines · Jacob Keller
Is there any benefit to implementing anything other than
HWTSTAMP_FILTER_ALL?Those are typically considered legacy with the primary reason being to support hardware which does not support timestamping all frames.
Quoted 6 lines
I suppose if you have measurement that supporting them is valuable (i.e. because of performance impact on timestamping all frames?) it makes sense to support. But otherwise I'm not sure its worth the extra complexity.
Upgrading the filtering modes to
HWTSTAMP_FILTER_ALLis acceptable and is done by a few drivers.
Quoted 6 lines
Even though the hardware is able to timestamp TX packets at line rate, we would like to avoid having 2x times more interrupts for the cases when we don't need all packets to be timestamped. And as it mentioned in the comment, we don't have very precise HW filters, but we would like to avoid timestamping TCP packets when TCP is the most used one on the host.
Tx timestamps don't use the filters in the first place. The filter only applies to Rx timestamps. You should only initiate a Tx timestamp when requested, which will generally not be the case for TCP.
Are you saying that Rx timestamps generate interrupts?
Re: [PATCH net-next v3 3/5] eth: fbnic: add RX packets timestamping support
Quoted 24 lines · Jacob Keller
Quoted 14 lines · Vadim Fedorenko
Quoted 6 lines · Jacob Keller
Is there any benefit to implementing anything other than
HWTSTAMP_FILTER_ALL?Those are typically considered legacy with the primary reason being to support hardware which does not support timestamping all frames.
Quoted 6 lines
I suppose if you have measurement that supporting them is valuable (i.e. because of performance impact on timestamping all frames?) it makes sense to support. But otherwise I'm not sure its worth the extra complexity.
Upgrading the filtering modes to
HWTSTAMP_FILTER_ALLis acceptable and is done by a few drivers.Quoted 6 lines
Even though the hardware is able to timestamp TX packets at line rate, we would like to avoid having 2x times more interrupts for the cases when we don't need all packets to be timestamped. And as it mentioned in the comment, we don't have very precise HW filters, but we would like to avoid timestamping TCP packets when TCP is the most used one on the host.
Quoted 5 lines
Tx timestamps don't use the filters in the first place. The filter only applies to Rx timestamps. You should only initiate a Tx timestamp when requested, which will generally not be the case for TCP.
Are you saying that Rx timestamps generate interrupts?
Sorry for the confusion with TX timestamping.
For RX we will utilize additional buffer to provide timestamp metadata, and we will have to process this metadata even if it will not be needed later in the stack. For 100G links that will add some delays which we would like to avoid.
PATCH v3 4/5 eth: fbnic: add TX packets timestamping support
In reply to Vadim FedorenkoAdd TX configuration to ethtool interface. Add processing of TX timestamp completions as well as configuration to request HW to create TX timestamp completion.
--- .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 5 + drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 93 ++++++++++++++++++- 2 files changed, 95 insertions(+), 3 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +5 -0
@@ -16,9 +16,14 @@ fbnic_get_ts_info(struct net_device *netdev, tsinfo->so_timestamping =SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_TX_HARDWARE |SOF_TIMESTAMPING_RX_HARDWARE |SOF_TIMESTAMPING_RAW_HARDWARE ; + tsinfo->tx_types = +BIT (HWTSTAMP_TX_OFF ) | +BIT (HWTSTAMP_TX_ON ); + tsinfo->rx_filters =BIT (HWTSTAMP_FILTER_NONE ) | BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +90 -3
154 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v3 5/5 eth: fbnic: add ethtool timestamping statistics
In reply to Vadim FedorenkoAdd counters of packets with HW timestamps requests and lost timestamps with no associated skbs. Use ethtool interface to report these counters.
--- .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 24 +++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 9 ++++++- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-)
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +24 -0
@@ -93,9 +93,33 @@ fbnic_get_eth_mac_stats(struct net_device *netdev, &mac_stats->eth_mac.FrameTooLongErrors); } +static void fbnic_get_ts_stats (struct net_device *netdev, +struct ethtool_ts_stats *ts_stats) +{ +struct fbnic_net *fbn =netdev_priv (netdev); +u64 ts_packets, ts_lost; +struct fbnic_ring *ring; +unsigned int start; +int i; + + ts_stats->pkts = fbn->tx_stats.ts_packets; + ts_stats->lost = fbn->tx_stats.ts_lost; +for (i =0 ; i < fbn->num_tx_queues; i++) { + ring = fbn->tx[i]; +do { + start =u64_stats_fetch_begin (&ring->stats.syncp); + ts_packets = ring->stats.ts_packets; + ts_lost = ring->stats.ts_lost; + }while (u64_stats_fetch_retry (&ring->stats.syncp, start)); + ts_stats->pkts += ts_packets; + ts_stats->lost += ts_lost; + } +} +static const struct ethtool_ops fbnic_ethtool_ops = { .get_drvinfo = fbnic_get_drvinfo, .get_ts_info = fbnic_get_ts_info, + .get_ts_stats = fbnic_get_ts_stats, .get_eth_mac_stats = fbnic_get_eth_mac_stats, };
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +8 -1
@@ -383,7 +383,7 @@ static void fbnic_clean_twq0(struct fbnic_napi_vector *nv, int napi_budget, struct fbnic_ring *ring, bool discard, unsigned int hw_head) { - u64 total_bytes = 0, total_packets = 0; + u64 total_bytes = 0, total_packets = 0, ts_lost = 0;unsigned int head = ring->head;struct netdev_queue *txq;unsigned int clean_desc;
@@ -402,6 +402,7 @@ static void fbnic_clean_twq0(struct fbnic_napi_vector *nv, int napi_budget,FBNIC_XMIT_CB (skb)->hw_head = hw_head;if (likely (!discard))break ; + ts_lost++; } ring->tx_buf[head] =NULL ;
@@ -441,6 +442,7 @@ static void fbnic_clean_twq0(struct fbnic_napi_vector *nv, int napi_budget,if (unlikely (discard)) {u64_stats_update_begin (&ring->stats.syncp); ring->stats.dropped += total_packets; + ring->stats.ts_lost += ts_lost;u64_stats_update_end (&ring->stats.syncp);netdev_tx_completed_queue (txq, total_packets, total_bytes);
@@ -502,6 +504,9 @@ static void fbnic_clean_tsq(struct fbnic_napi_vector *nv, }skb_tstamp_tx (skb, &hwtstamp); +u64_stats_update_begin (&ring->stats.syncp); + ring->stats.ts_packets++; +u64_stats_update_end (&ring->stats.syncp); } static void fbnic_page_pool_init(struct fbnic_ring *ring, unsigned int idx,
@@ -1058,6 +1063,8 @@ static void fbnic_aggregate_ring_tx_counters(struct fbnic_net *fbn, fbn->tx_stats.bytes += stats->bytes; fbn->tx_stats.packets += stats->packets; fbn->tx_stats.dropped += stats->dropped; + fbn->tx_stats.ts_lost += stats->ts_lost; + fbn->tx_stats.ts_packets += stats->ts_packets; } static void fbnic_remove_tx_ring(struct fbnic_net *fbn,
drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +2 -0
@@ -57,6 +57,8 @@ struct fbnic_queue_stats {u64 packets;u64 bytes;u64 dropped; +u64 ts_packets; +u64 ts_lost;struct u64_stats_sync syncp; };
Signature · 1 line
2.43.5