Add PTP support for CN10K silicon
Subsystems (4)
cover Add PTP support for CN10K silicon
This patchset adds PTP support for CN10K silicon, specifically to workaround few hardware issues and to add 1-step mode.
Patchset overview:
Patch #1 returns correct ptp timestamp in nanoseconds captured
when external timestamp event occurs.
Patch #2 adds 1-step mode support.
Patch #3 implements software workaround to generate PPS output properly.
Patch #4 provides a software workaround for the rollover register default
value, which causes ptp to return the wrong timestamp.
Hariprasad Kelam (1):
octeontx2-pf: Add support for ptp 1-step mode on CN10K silicon
Naveen Mamindlapalli (3):
octeontx2-af: return correct ptp timestamp for CN10K silicon
octeontx2-af: Add PTP PPS Errata workaround on CN10K silicon
octeontx2-af: Initialize PTP_SEC_ROLLOVER register properly
drivers/net/ethernet/marvell/octeontx2/af/mbox.h | 2 + drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 106 +++++++++++++++++++- drivers/net/ethernet/marvell/octeontx2/af/ptp.h | 3 + drivers/net/ethernet/marvell/octeontx2/af/rpm.c | 19 +++- drivers/net/ethernet/marvell/octeontx2/af/rpm.h | 5 + .../net/ethernet/marvell/octeontx2/af/rvu_nix.c | 8 +- .../net/ethernet/marvell/octeontx2/af/rvu_reg.h | 1 + .../ethernet/marvell/octeontx2/nic/otx2_common.h | 13 +++ .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 8 +- .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 11 +++ .../net/ethernet/marvell/octeontx2/nic/otx2_ptp.c | 103 ++++++++++++++----- .../ethernet/marvell/octeontx2/nic/otx2_struct.h | 11 ++- .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c | 110 ++++++++++++++++++++- 13 files changed, 359 insertions(+), 41 deletions(-)
Signature · 1 line
2.16.5
PATCH 1/4 octeontx2-af: return correct ptp timestamp for CN10K silicon
The MIO_PTP_TIMESTAMP format has been changed in CN10K silicon family. The upper 32-bits represents seconds and lower 32-bits represents nanoseconds. This patch returns nanosecond timestamp to NIX PF driver.
--- drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +13 -1
@@ -56,6 +56,11 @@static struct ptp *first_ptp_block;static const struct pci_device_id ptp_id_table[]; +static bool is_ptp_dev_cn10k (struct ptp *ptp) +{ +return (ptp->pdev->device ==PCI_DEVID_CN10K_PTP ) ? true : false; +} +static bool cn10k_ptp_errata (struct ptp *ptp) { if (ptp->pdev->subsystem_device == PCI_SUBSYS_DEVID_CN10K_A_PTP ||
@@ -282,7 +287,14 @@ void ptp_start(struct ptp *ptp, u64 sclk, u32 ext_clk_freq, u32 extts)static int ptp_get_tstmp (struct ptp *ptp,u64 *clk) { - *clk =readq (ptp->reg_base +PTP_TIMESTAMP ); +u64 timestamp; + +if (is_ptp_dev_cn10k (ptp)) { + timestamp =readq (ptp->reg_base +PTP_TIMESTAMP ); + *clk = (timestamp >>32 ) *NSEC_PER_SEC + (timestamp &0xFFFFFFFF ); + }else { + *clk =readq (ptp->reg_base +PTP_TIMESTAMP ); + }return 0 ; }
Signature · 1 line
2.16.5
PATCH 2/4 octeontx2-pf: Add support for ptp 1-step mode on CN10K silicon
In reply to Naveen MamindlapalliFrom: Hariprasad Kelam <[email protected]>
Add support for ptp 1-step mode using timecounter. The seconds and nanoseconds to be updated in PTP header are calculated by adding the timecounter offset to the free running PTP clock counter time. The PF driver periodically gets the PTP clock time using AF mbox. The 1-step support uses HW feature to update correction field rather than OriginTimestamp field in PTP header.
--- drivers/net/ethernet/marvell/octeontx2/af/rpm.c | 19 +++- drivers/net/ethernet/marvell/octeontx2/af/rpm.h | 5 + .../net/ethernet/marvell/octeontx2/af/rvu_nix.c | 8 +- .../net/ethernet/marvell/octeontx2/af/rvu_reg.h | 1 + .../ethernet/marvell/octeontx2/nic/otx2_common.h | 13 +++ .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 8 +- .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 11 +++ .../net/ethernet/marvell/octeontx2/nic/otx2_ptp.c | 90 +++++++++++------ .../ethernet/marvell/octeontx2/nic/otx2_struct.h | 11 ++- .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c | 110 ++++++++++++++++++++- 10 files changed, 234 insertions(+), 42 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rpm.c +17 -2
@@ -415,11 +415,26 @@ void rpm_lmac_ptp_config(void *rpmd, int lmac_id, bool enable)return ; cfg =rpm_read (rpm, lmac_id,RPMX_CMRX_CFG ); -if (enable) +if (enable) { cfg |=RPMX_RX_TS_PREPEND ; -else + cfg |=RPMX_TX_PTP_1S_SUPPORT ; + }else { cfg &= ~RPMX_RX_TS_PREPEND ; + cfg &= ~RPMX_TX_PTP_1S_SUPPORT ; + } +rpm_write (rpm, lmac_id,RPMX_CMRX_CFG , cfg); + + cfg =rpm_read (rpm, lmac_id,RPMX_MTI_MAC100X_XIF_MODE ); + +if (enable) { + cfg |=RPMX_ONESTEP_ENABLE ; + cfg &= ~RPMX_TS_BINARY_MODE ; + }else { + cfg &= ~RPMX_ONESTEP_ENABLE ; + } + +rpm_write (rpm, lmac_id,RPMX_MTI_MAC100X_XIF_MODE , cfg); }int rpm_lmac_pfc_config (void *rpmd,int lmac_id,u8 tx_pause,u8 rx_pause,u16 pfc_en)
drivers/net/ethernet/marvell/octeontx2/af/rpm.h +5 -0
@@ -16,6 +16,7 @@/* Registers */ #define RPMX_CMRX_CFG 0x00#define RPMX_RX_TS_PREPEND BIT_ULL(22) +#define RPMX_TX_PTP_1S_SUPPORT BIT_ULL(17)#define RPMX_CMRX_SW_INT 0x180#define RPMX_CMRX_SW_INT_W1S 0x188#define RPMX_CMRX_SW_INT_ENA_W1S 0x198
@@ -72,6 +73,10 @@#define RPMX_MTI_MAC100X_CL89_PAUSE_QUANTA 0x8108#define RPM_DEFAULT_PAUSE_TIME 0x7FF +#define RPMX_MTI_MAC100X_XIF_MODE 0x8100 +#define RPMX_ONESTEP_ENABLE BIT_ULL(5) +#define RPMX_TS_BINARY_MODE BIT_ULL(11) +/* Function Declarations */ int rpm_get_nr_lmacs (void *rpmd);u8 rpm_get_lmac_type (void *rpmd,int lmac_id);
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +7 -1
@@ -4296,8 +4296,14 @@ static int rvu_nix_block_init(struct rvu *rvu, struct nix_hw *nix_hw)/* Restore CINT timer delay to HW reset values */ rvu_write64 (rvu, blkaddr,NIX_AF_CINT_DELAY ,0x0ULL ); + cfg =rvu_read64 (rvu, blkaddr,NIX_AF_SEB_CFG ); +/* For better performance use NDC TX instead of NDC RX for SQ's SQEs" */ -rvu_write64 (rvu, blkaddr,NIX_AF_SEB_CFG ,0x1ULL ); + cfg |=1ULL ; +if (!is_rvu_otx2 (rvu)) + cfg |=NIX_PTP_1STEP_EN ; + +rvu_write64 (rvu, blkaddr,NIX_AF_SEB_CFG , cfg);if (is_block_implemented (hw, blkaddr)) { err =nix_setup_txschq (rvu, nix_hw, blkaddr);
drivers/net/ethernet/marvell/octeontx2/af/rvu_reg.h +1 -0
@@ -266,6 +266,7 @@#define NIX_AF_TX_NPC_CAPTURE_CONFIG (0x0660)#define NIX_AF_TX_NPC_CAPTURE_INFO (0x0670)#define NIX_AF_SEB_CFG (0x05F0) +#define NIX_PTP_1STEP_EN BIT_ULL(2)#define NIX_AF_DEBUG_NPC_RESP_DATAX (a) (0x680 | (a) << 3)#define NIX_AF_SMQX_CFG (a) (0x700 | (a) << 16)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +13 -0
@@ -243,6 +243,7 @@ struct otx2_hw {#define CN10K_MBOX 1#define CN10K_LMTST 2#define CN10K_RPM 3 +#define CN10K_PTP_ONESTEP 4unsigned long cap_flag;#define LMT_LINE_SIZE 128
@@ -276,6 +277,13 @@ struct refill_work {struct otx2_nic *pf; }; +/* PTPv2 originTimestamp structure */ +struct ptpv2_tstamp { +__be16 seconds_msb;/* 16 bits + */ +__be32 seconds_lsb;/* 32 bits = 48 bits*/ +__be32 nanoseconds; +} __packed; +struct otx2_ptp {struct ptp_clock_info ptp_info;struct ptp_clock *ptp_clock;
@@ -291,6 +299,9 @@ struct otx2_ptp {struct ptp_pin_desc extts_config;u64 (*convert_rx_ptp_tstmp)(u64 timestamp);u64 (*convert_tx_ptp_tstmp)(u64 timestamp); +struct delayed_work synctstamp_work; +u64 tstamp; +u32 base_ns; };#define OTX2_HW_TIMESTAMP_LEN 8
@@ -363,6 +374,7 @@ struct otx2_nic {#define OTX2_FLAG_TC_MATCHALL_EGRESS_ENABLED BIT_ULL(12)#define OTX2_FLAG_TC_MATCHALL_INGRESS_ENABLED BIT_ULL(13)#define OTX2_FLAG_DMACFLTR_SUPPORT BIT_ULL(14) +#define OTX2_FLAG_PTP_ONESTEP_SYNC BIT_ULL(15)#define OTX2_FLAG_ADPTV_INT_COAL_ENABLED BIT_ULL(16)u64 flags;u64 *cq_op_addr;
@@ -494,6 +506,7 @@ static inline void otx2_setup_dev_hw_settings(struct otx2_nic *pfvf)__set_bit (CN10K_MBOX , &hw->cap_flag);__set_bit (CN10K_LMTST , &hw->cap_flag);__set_bit (CN10K_RPM , &hw->cap_flag); +__set_bit (CN10K_PTP_ONESTEP , &hw->cap_flag); } }
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +5 -3
@@ -963,10 +963,12 @@ static int otx2_get_ts_info(struct net_device *netdev, info->phc_index =otx2_ptp_clock_index (pfvf); - info->tx_types = (1 <<HWTSTAMP_TX_OFF ) | (1 <<HWTSTAMP_TX_ON ); + info->tx_types =BIT (HWTSTAMP_TX_OFF ) |BIT (HWTSTAMP_TX_ON ); +if (test_bit (CN10K_PTP_ONESTEP , &pfvf->hw.cap_flag)) + info->tx_types |=BIT (HWTSTAMP_TX_ONESTEP_SYNC ); - info->rx_filters = (1 <<HWTSTAMP_FILTER_NONE ) | - (1 <<HWTSTAMP_FILTER_ALL ); + info->rx_filters =BIT (HWTSTAMP_FILTER_NONE ) | +BIT (HWTSTAMP_FILTER_ALL );return 0 ; }
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +11 -0
@@ -2038,8 +2038,19 @@ int otx2_config_hwtstamp(struct net_device *netdev, struct ifreq *ifr)switch (config.tx_type) {case HWTSTAMP_TX_OFF : +if (pfvf->flags &OTX2_FLAG_PTP_ONESTEP_SYNC ) + pfvf->flags &= ~OTX2_FLAG_PTP_ONESTEP_SYNC ; + +cancel_delayed_work (&pfvf->ptp->synctstamp_work);otx2_config_hw_tx_tstamp (pfvf, false);break ; +case HWTSTAMP_TX_ONESTEP_SYNC : +if (!test_bit (CN10K_PTP_ONESTEP , &pfvf->hw.cap_flag)) +return -ERANGE ; + pfvf->flags |=OTX2_FLAG_PTP_ONESTEP_SYNC ; +schedule_delayed_work (&pfvf->ptp->synctstamp_work, +msecs_to_jiffies (500 )); + fallthrough;case HWTSTAMP_TX_ON :otx2_config_hw_tx_tstamp (pfvf, true);break ;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c +61 -29
134 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/nic/otx2_struct.h +9 -2
@@ -236,8 +236,15 @@ struct nix_sqe_sg_s {/* NIX send memory subdescriptor structure */ struct nix_sqe_mem_s { -u64 offset :16 ;/* W0 */ -u64 rsvd_51_16 :36 ; +u64 start_offset :8 ; +u64 rsvd_11_8 :4 ; +u64 rsvd_12 :1 ; +u64 udp_csum_crt :1 ; +u64 update64 :1 ; +u64 rsvd_15_16 :1 ; +u64 base_ns :32 ; +u64 step_type :1 ; +u64 rsvd_51_49 :3 ;u64 per_lso_seg :1 ;u64 wmem :1 ;u64 dsz :2 ;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +105 -5
140 lines not on this page · raw message
Signature · 1 line
2.16.5
PATCH 3/4 octeontx2-af: Add PTP PPS Errata workaround on CN10K silicon
In reply to Naveen MamindlapalliErrata:
The ptp_clock_hi rollsover to zero one clock cycle before it reaches one second boundary. As a result, the pps threshold comparison fails after one second and the pps output signal won't toggle further.
This patch workarounds the issue by programming the pps_lo_incr register to 500msec minus one clock cycle period, ensuring that the pps threshold comparison succeeds at one second rollover boundary and pps edge toggles. After that point, the driver will have enough time (~500msec) to reset the pps threshold value. After each one second boundary, hrtimer is invoked which resets the pps threshold value.
--- drivers/net/ethernet/marvell/octeontx2/af/mbox.h | 2 + drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 82 +++++++++++++++++++++- drivers/net/ethernet/marvell/octeontx2/af/ptp.h | 3 + .../net/ethernet/marvell/octeontx2/nic/otx2_ptp.c | 27 +++++-- 4 files changed, 109 insertions(+), 5 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +2 -0
@@ -1471,6 +1471,7 @@ enum ptp_op {PTP_OP_GET_CLOCK =1 ,PTP_OP_GET_TSTMP =2 ,PTP_OP_SET_THRESH =3 , + PTP_OP_EXTTS_ON = 4, }; struct ptp_req {
@@ -1478,6 +1479,7 @@ struct ptp_req {u8 op;s64 scaled_ppm;u64 thresh; +int extts_on; };struct ptp_rsp {
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +81 -1
124 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/ptp.h +3 -0
@@ -17,7 +17,10 @@ struct ptp {void __iomem *reg_base;u64 (*read_ptp_tstmp)(struct ptp *ptp);spinlock_t ptp_lock;/* lock */ +struct hrtimer hrtimer; +ktime_t last_ts;u32 clock_rate; +u32 clock_period; };struct ptp *ptp_get (void );
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c +23 -4
@@ -73,6 +73,23 @@ static int ptp_set_thresh(struct otx2_ptp *ptp, u64 thresh)return otx2_sync_mbox_msg (&ptp->nic->mbox); } +static int ptp_extts_on (struct otx2_ptp *ptp,int on) +{ +struct ptp_req *req; + +if (!ptp->nic) +return -ENODEV ; + + req =otx2_mbox_alloc_msg_ptp_op (&ptp->nic->mbox); +if (!req) +return -ENOMEM ; + + req->op =PTP_OP_EXTTS_ON ; + req->extts_on = on; + +return otx2_sync_mbox_msg (&ptp->nic->mbox); +} +static u64 ptp_cc_read (const struct cyclecounter *cc) { struct otx2_ptp *ptp = container_of(cc, struct otx2_ptp, cycle_counter);
@@ -189,8 +206,6 @@ static void otx2_ptp_extts_check(struct work_struct *work) event.index =0 ; event.timestamp =timecounter_cyc2time (&ptp->time_counter, tstmp);ptp_clock_event (ptp->ptp_clock, &event); - ptp->last_extts = tstmp; - new_thresh = tstmp %500000000 ;if (ptp->thresh != new_thresh) {mutex_lock (&ptp->nic->mbox.lock);
@@ -198,6 +213,7 @@ static void otx2_ptp_extts_check(struct work_struct *work)mutex_unlock (&ptp->nic->mbox.lock); ptp->thresh = new_thresh; } + ptp->last_extts = tstmp; }schedule_delayed_work (&ptp->extts_work,msecs_to_jiffies (200 )); }
@@ -235,10 +251,13 @@ static int otx2_ptp_enable(struct ptp_clock_info *ptp_info, rq->extts.index);if (pin <0 )return -EBUSY ; -if (on) +if (on) { +ptp_extts_on (ptp, on);schedule_delayed_work (&ptp->extts_work,msecs_to_jiffies (200 )); -else + }else { +ptp_extts_on (ptp, on);cancel_delayed_work_sync (&ptp->extts_work); + }return 0 ;default :break ;
Signature · 1 line
2.16.5
PATCH 4/4 octeontx2-af: Initialize PTP_SEC_ROLLOVER register properly
In reply to Naveen MamindlapalliSince the reset value of PTP_SEC_ROLLOVER is incorrect on CNF10KB silicon, the ptp timestamps are inaccurate. This patch initializes the PTP_SEC_ROLLOVER register properly for the CNF10KB silicon.
--- drivers/net/ethernet/marvell/octeontx2/af/ptp.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +10 -0
@@ -52,12 +52,18 @@#define PTP_CLOCK_COMP 0xF18ULL#define PTP_TIMESTAMP 0xF20ULL#define PTP_CLOCK_SEC 0xFD0ULL +#define PTP_SEC_ROLLOVER 0xFD8ULL#define CYCLE_MULT 1000static struct ptp *first_ptp_block;static const struct pci_device_id ptp_id_table[]; +static bool is_ptp_dev_cnf10kb (struct ptp *ptp) +{ +return (ptp->pdev->subsystem_device ==PCI_SUBSYS_DEVID_CNF10K_B_PTP ) ? true : false; +} +static bool is_ptp_dev_cn10k (struct ptp *ptp) {return (ptp->pdev->device ==PCI_DEVID_CN10K_PTP ) ? true : false;
@@ -290,6 +296,10 @@ void ptp_start(struct ptp *ptp, u64 sclk, u32 ext_clk_freq, u32 extts)/* sclk is in MHz */ ptp->clock_rate = sclk *1000000 ; +/* Program the seconds rollover value to 1 second */ +if (is_ptp_dev_cnf10kb (ptp)) +writeq (0x3b9aca00 , ptp->reg_base +PTP_SEC_ROLLOVER ); +/* Enable PTP clock */ clock_cfg =readq (ptp->reg_base +PTP_CLOCK_CFG );
Signature · 1 line
2.16.5
Quoted 15 lines · Naveen Mamindlapalli
This patchset adds PTP support for CN10K silicon, specifically to workaround few hardware issues and to add 1-step mode.
Patchset overview:
Patch #1 returns correct ptp timestamp in nanoseconds captured
when external timestamp event occurs.Patch #2 adds 1-step mode support.
Patch #3 implements software workaround to generate PPS output properly.
Patch #4 provides a software workaround for the rollover register default
value, which causes ptp to return the wrong timestamp.
Quoted 7 lines
Hariprasad Kelam (1):
octeontx2-pf: Add support for ptp 1-step mode on CN10K siliconNaveen Mamindlapalli (3):
octeontx2-af: return correct ptp timestamp for CN10K silicon
octeontx2-af: Add PTP PPS Errata workaround on CN10K silicon
octeontx2-af: InitializePTP_SEC_ROLLOVERregister properly
For the series:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 9 lines · On Sat, 10 Sep 2022 13:24:12 +0530 you wrote:
This patchset adds PTP support for CN10K silicon, specifically to workaround few hardware issues and to add 1-step mode.
Patchset overview:
Patch #1 returns correct ptp timestamp in nanoseconds captured
when external timestamp event occurs.[...]
Here is the summary with links:
- [net-next,1/4] octeontx2-af: return correct ptp timestamp for CN10K silicon
https://git.kernel.org/netdev/net-next/c/a8025e7946a2 - [net-next,2/4] octeontx2-pf: Add support for ptp 1-step mode on CN10K silicon https://git.kernel.org/netdev/net-next/c/2958d17a8984 - [net-next,3/4] octeontx2-af: Add PTP PPS Errata workaround on CN10K silicon https://git.kernel.org/netdev/net-next/c/2ef4e45d99b1 - [net-next,4/4] octeontx2-af: Initialize PTP_SEC_ROLLOVER register properly https://git.kernel.org/netdev/net-next/c/85a5f9638313
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html