Externel ptp clock support
Subsystems (4)
cover Externel ptp clock support
Externel ptp support is required in a scenario like connecting a external timing device to the chip for time synchronization. This series of patches adds support to ptp driver to use external clock and enables PTP config in CN10K MAC block (RPM). Currently PTP configuration is left unchanged in FLR handler these patches addresses the same.
Hariprasad Kelam (1):
octeontx2-af: cn10k: RPM hardware timestamp configuration
Harman Kalra (1):
octeontx2-af: Reset PTP config in FLR handler
Subbaraya Sundeep (1):
octeontx2-af: Use ptp input clock info from firmware data
Yi Guo (1):
octeontx2-af: Add external ptp input clock
.../net/ethernet/marvell/octeontx2/af/cgx.c | 10 +- .../marvell/octeontx2/af/lmac_common.h | 5 + .../net/ethernet/marvell/octeontx2/af/mbox.h | 44 +++--- .../net/ethernet/marvell/octeontx2/af/ptp.c | 133 +++++++++++------- .../net/ethernet/marvell/octeontx2/af/ptp.h | 1 + .../net/ethernet/marvell/octeontx2/af/rpm.c | 17 +++ .../net/ethernet/marvell/octeontx2/af/rpm.h | 3 + .../net/ethernet/marvell/octeontx2/af/rvu.c | 4 + .../net/ethernet/marvell/octeontx2/af/rvu.h | 5 +- .../ethernet/marvell/octeontx2/af/rvu_cgx.c | 7 +- .../ethernet/marvell/octeontx2/af/rvu_nix.c | 16 +++ .../marvell/octeontx2/nic/otx2_common.h | 6 + .../ethernet/marvell/octeontx2/nic/otx2_ptp.c | 120 +++++++++++++++- 13 files changed, 292 insertions(+), 79 deletions(-)
--
2.17.1
PATCH 1/4 octeontx2-af: Reset PTP config in FLR handler
From: Harman Kalra <[email protected]>
Upon receiving ptp config request from netdev interface , Octeontx2 MAC block CGX is configured to append timestamp to every incoming packet and NPC config is updated with DMAC offset change.
Currently this configuration is not reset in FLR handler. This patch resets the same.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 1 + .../net/ethernet/marvell/octeontx2/af/rvu_cgx.c | 3 +++ .../net/ethernet/marvell/octeontx2/af/rvu_nix.c | 14 ++++++++++++++ 3 files changed, 18 insertions(+)
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +1 -0
@@ -220,6 +220,7 @@ struct rvu_pfvf {u16 maxlen;u16 minlen; +bool hw_rx_tstamp_en;/* Is rx_tstamp enabled */ u8 mac_addr[ETH_ALEN ];/* MAC address of this PF/VF */ u8 default_mac[ETH_ALEN ];/* MAC address from FWdata */
drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c +3 -0
@@ -694,6 +694,7 @@ int rvu_mbox_handler_cgx_promisc_disable(struct rvu *rvu, struct msg_req *req,static int rvu_cgx_ptp_rx_cfg (struct rvu *rvu,u16 pcifunc,bool enable) { +struct rvu_pfvf *pfvf =rvu_get_pfvf (rvu, pcifunc);int pf =rvu_get_pf (pcifunc);u8 cgx_id, lmac_id;void *cgxd;
@@ -718,6 +719,8 @@ static int rvu_cgx_ptp_rx_cfg(struct rvu *rvu, u16 pcifunc, bool enable)*/ if (npc_config_ts_kpuaction (rvu, pf, pcifunc, enable))return -EINVAL ; +/* This flag is required to clean up CGX conf if app gets killed */ + pfvf->hw_rx_tstamp_en = enable;return 0 ; }
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +14 -0
@@ -4516,6 +4516,9 @@ void rvu_nix_lf_teardown(struct rvu *rvu, u16 pcifunc, int blkaddr, int nixlf) {struct rvu_pfvf *pfvf =rvu_get_pfvf (rvu, pcifunc);struct hwctx_disable_req ctx_req; +int pf =rvu_get_pf (pcifunc); +u8 cgx_id, lmac_id; +void *cgxd;int err; ctx_req.hdr.pcifunc = pcifunc;
@@ -4556,6 +4559,17 @@ void rvu_nix_lf_teardown(struct rvu *rvu, u16 pcifunc, int blkaddr, int nixlf)rvu_npc_set_parse_mode (rvu, pcifunc,OTX2_PRIV_FLAGS_DEFAULT , (PKIND_TX |PKIND_RX ),0 ,0 ,0 ,0 ); +/* Disabling CGX and NPC config done for PTP */ +if (pfvf->hw_rx_tstamp_en) { +rvu_get_cgx_lmac_id (rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); + cgxd =rvu_cgx_pdata (cgx_id, rvu); +cgx_lmac_ptp_config (cgxd, lmac_id, false); +/* Undo NPC config done for PTP */ +if (npc_config_ts_kpuaction (rvu, pf, pcifunc, false)) +dev_err (rvu->dev,"NPC config for PTP failed\n" ); + pfvf->hw_rx_tstamp_en = false; + } +nix_ctx_free (rvu, pfvf);nix_free_all_bandprof (rvu, pcifunc);
Signature · 1 line
2.17.1
PATCH 2/4 octeontx2-af: cn10k: RPM hardware timestamp configuration
In reply to Hariprasad KelamMAC on CN10K support hardware timestamping such that 8 bytes addition header is prepended to incoming packets. This patch does necessary configuration to enable Hardware time stamping upon receiving request from PF netdev interfaces.
Timestamp configuration is different on MAC (CGX) Octeontx2 silicon and MAC (RPM) OcteonTX3 CN10k. Based on silicon variant appropriate fn() pointer is called. Refactor MAC specific mbox messages to remove unnecessary gaps in mboxids.
--- .../net/ethernet/marvell/octeontx2/af/cgx.c | 10 ++--- .../marvell/octeontx2/af/lmac_common.h | 5 +++ .../net/ethernet/marvell/octeontx2/af/mbox.h | 41 ++++++++++--------- .../net/ethernet/marvell/octeontx2/af/rpm.c | 17 ++++++++ .../net/ethernet/marvell/octeontx2/af/rpm.h | 3 ++ .../ethernet/marvell/octeontx2/af/rvu_cgx.c | 4 +- .../ethernet/marvell/octeontx2/af/rvu_nix.c | 4 +- 7 files changed, 58 insertions(+), 26 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +5 -5
@@ -838,9 +838,6 @@ void cgx_lmac_ptp_config(void *cgxd, int lmac_id, bool enable)if (!cgx)return ; -if (is_dev_rpm (cgx)) -return ; -if (enable) {/* Enable inbound PTP timestamping */ cfg =cgx_read (cgx, lmac_id,CGXX_GMP_GMI_RXX_FRM_CTL );
@@ -1545,9 +1542,11 @@ static int cgx_lmac_exit(struct cgx *cgx)static void cgx_populate_features (struct cgx *cgx) {if (is_dev_rpm (cgx)) - cgx->hw_features = (RVU_MAC_RPM |RVU_LMAC_FEAT_FC ); + cgx->hw_features = (RVU_LMAC_FEAT_DMACF |RVU_MAC_RPM | +RVU_LMAC_FEAT_FC |RVU_LMAC_FEAT_PTP );else - cgx->hw_features = (RVU_LMAC_FEAT_FC |RVU_LMAC_FEAT_PTP ); + cgx->hw_features = (RVU_LMAC_FEAT_FC |RVU_LMAC_FEAT_HIGIG2 | +RVU_LMAC_FEAT_PTP |RVU_LMAC_FEAT_DMACF ); }static struct mac_ops cgx_mac_ops = {
@@ -1571,6 +1570,7 @@ static struct mac_ops cgx_mac_ops = { .mac_get_pause_frm_status = cgx_lmac_get_pause_frm_status, .mac_enadis_pause_frm = cgx_lmac_enadis_pause_frm, .mac_pause_frm_config = cgx_lmac_pause_frm_config, + .mac_enadis_ptp_config = cgx_lmac_ptp_config, };static int cgx_probe (struct pci_dev *pdev,const struct pci_device_id *id)
drivers/net/ethernet/marvell/octeontx2/af/lmac_common.h +5 -0
@@ -102,6 +102,11 @@ struct mac_ops {void (*mac_pause_frm_config)(void *cgxd,int lmac_id,bool enable); + +/* Enable/Disable Inbound PTP */ +void (*mac_enadis_ptp_config)(void *cgxd, +int lmac_id, +bool enable); };struct cgx {
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +22 -19
55 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/rpm.c +17 -0
@@ -29,6 +29,7 @@ static struct mac_ops rpm_mac_ops = { .mac_get_pause_frm_status = rpm_lmac_get_pause_frm_status, .mac_enadis_pause_frm = rpm_lmac_enadis_pause_frm, .mac_pause_frm_config = rpm_lmac_pause_frm_config, + .mac_enadis_ptp_config = rpm_lmac_ptp_config, };struct mac_ops *rpm_get_mac_ops (void )
@@ -270,3 +271,19 @@ int rpm_lmac_internal_loopback(void *rpmd, int lmac_id, bool enable)return 0 ; } + +void rpm_lmac_ptp_config (void *rpmd,int lmac_id,bool enable) +{ +rpm_t *rpm = rpmd; +u64 cfg; + +if (!is_lmac_valid (rpm, lmac_id)) +return ; + + cfg =rpm_read (rpm, lmac_id,RPMX_CMRX_CFG ); +if (enable) + cfg |=RPMX_RX_TS_PREPEND ; +else + cfg &= ~RPMX_RX_TS_PREPEND ; +rpm_write (rpm, lmac_id,RPMX_CMRX_CFG , cfg); +}
drivers/net/ethernet/marvell/octeontx2/af/rpm.h +3 -0
@@ -14,6 +14,8 @@#define PCI_DEVID_CN10K_RPM 0xA060/* Registers */ +#define RPMX_CMRX_CFG 0x00 +#define RPMX_RX_TS_PREPEND BIT_ULL(22)#define RPMX_CMRX_SW_INT 0x180#define RPMX_CMRX_SW_INT_W1S 0x188#define RPMX_CMRX_SW_INT_ENA_W1S 0x198
@@ -54,4 +56,5 @@ int rpm_lmac_enadis_pause_frm(void *rpmd, int lmac_id, u8 tx_pause, u8 rx_pause);int rpm_get_tx_stats (void *rpmd,int lmac_id,int idx,u64 *tx_stat);int rpm_get_rx_stats (void *rpmd,int lmac_id,int idx,u64 *rx_stat); +void rpm_lmac_ptp_config (void *rpmd,int lmac_id,bool enable);#endif /* RPM_H */
drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c +3 -1
@@ -696,6 +696,7 @@ static int rvu_cgx_ptp_rx_cfg(struct rvu *rvu, u16 pcifunc, bool enable) {struct rvu_pfvf *pfvf =rvu_get_pfvf (rvu, pcifunc);int pf =rvu_get_pf (pcifunc); +struct mac_ops *mac_ops;u8 cgx_id, lmac_id;void *cgxd;
@@ -712,7 +713,8 @@ static int rvu_cgx_ptp_rx_cfg(struct rvu *rvu, u16 pcifunc, bool enable)rvu_get_cgx_lmac_id (rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); cgxd =rvu_cgx_pdata (cgx_id, rvu); -cgx_lmac_ptp_config (cgxd, lmac_id, enable); + mac_ops =get_mac_ops (cgxd); + mac_ops->mac_enadis_ptp_config (cgxd, lmac_id, true);/* If PTP is enabled then inform NPC that packets to be * parsed by this PF will have their data shifted by 8 bytes * and if PTP is disabled then no shift is required
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +3 -1
@@ -4517,6 +4517,7 @@ void rvu_nix_lf_teardown(struct rvu *rvu, u16 pcifunc, int blkaddr, int nixlf)struct rvu_pfvf *pfvf =rvu_get_pfvf (rvu, pcifunc);struct hwctx_disable_req ctx_req;int pf =rvu_get_pf (pcifunc); +struct mac_ops *mac_ops;u8 cgx_id, lmac_id;void *cgxd;int err;
@@ -4563,7 +4564,8 @@ void rvu_nix_lf_teardown(struct rvu *rvu, u16 pcifunc, int blkaddr, int nixlf)if (pfvf->hw_rx_tstamp_en) {rvu_get_cgx_lmac_id (rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); cgxd =rvu_cgx_pdata (cgx_id, rvu); -cgx_lmac_ptp_config (cgxd, lmac_id, false); + mac_ops =get_mac_ops (cgxd); + mac_ops->mac_enadis_ptp_config (cgxd, lmac_id, false);/* Undo NPC config done for PTP */ if (npc_config_ts_kpuaction (rvu, pf, pcifunc, false))dev_err (rvu->dev,"NPC config for PTP failed\n" );
Signature · 1 line
2.17.1
PATCH 3/4 octeontx2-af: Use ptp input clock info from firmware data
In reply to Hariprasad KelamFrom: Subbaraya Sundeep <[email protected]>
The input clock frequency of PTP block is figured out from hardware reset block currently. The firmware data already has this info in sclk. Hence simplify ptp driver to use sclk from firmware data.
--- .../net/ethernet/marvell/octeontx2/af/ptp.c | 80 +++++++------------ .../net/ethernet/marvell/octeontx2/af/ptp.h | 1 + .../net/ethernet/marvell/octeontx2/af/rvu.c | 3 + 3 files changed, 33 insertions(+), 51 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +29 -51
@@ -27,7 +27,6 @@#define PCI_DEVID_CN10K_PTP 0xA09E#define PCI_PTP_BAR_NO 0 -#define PCI_RST_BAR_NO 0#define PTP_CLOCK_CFG 0xF00ULL#define PTP_CLOCK_CFG_PTP_EN BIT_ULL(0)
@@ -35,46 +34,9 @@#define PTP_CLOCK_HI 0xF10ULL#define PTP_CLOCK_COMP 0xF18ULL -#define RST_BOOT 0x1600ULL -#define RST_MUL_BITS GENMASK_ULL(38, 33) -#define CLOCK_BASE_RATE 50000000ULL -static struct ptp *first_ptp_block;static const struct pci_device_id ptp_id_table[]; -static u64 get_clock_rate (void ) -{ -u64 cfg, ret =CLOCK_BASE_RATE *16 ; -struct pci_dev *pdev; -void __iomem *base; - -/* To get the input clock frequency with which PTP co-processor -* block is running the base frequency(50 MHz) needs to be multiplied -* with multiplier bits present in RST_BOOT register of RESET block. -* Hence below code gets the multiplier bits from the RESET PCI -* device present in the system. -*/ - pdev =pci_get_device (PCI_VENDOR_ID_CAVIUM , -PCI_DEVID_OCTEONTX2_RST ,NULL ); -if (!pdev) - goto error; - - base =pci_ioremap_bar (pdev,PCI_RST_BAR_NO ); -if (!base) - goto error_put_pdev; - - cfg =readq (base +RST_BOOT ); - ret =CLOCK_BASE_RATE *FIELD_GET (RST_MUL_BITS , cfg); - -iounmap (base); - -error_put_pdev: -pci_dev_put (pdev); - -error: -return ret; -} -struct ptp *ptp_get (void ) {struct ptp *ptp = first_ptp_block;
@@ -145,13 +107,40 @@ static int ptp_get_clock(struct ptp *ptp, u64 *clk)return 0 ; } +void ptp_start (struct ptp *ptp,u64 sclk) +{ +struct pci_dev *pdev; +u64 clock_comp; +u64 clock_cfg; + +if (!ptp) +return ; + + pdev = ptp->pdev; + +if (!sclk) { +dev_err (&pdev->dev,"PTP input clock cannot be zero\n" ); +return ; + } + +/* sclk is in MHz */ + ptp->clock_rate = sclk *1000000 ; + +/* Enable PTP clock */ + clock_cfg =readq (ptp->reg_base +PTP_CLOCK_CFG ); + clock_cfg |=PTP_CLOCK_CFG_PTP_EN ; +writeq (clock_cfg, ptp->reg_base +PTP_CLOCK_CFG ); + + clock_comp = ((u64 )1000000000ull <<32 ) / ptp->clock_rate; +/* Initial compensation value to start the nanosecs counter */ +writeq (clock_comp, ptp->reg_base +PTP_CLOCK_COMP ); +} +static int ptp_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {struct device *dev = &pdev->dev;struct ptp *ptp; -u64 clock_comp; -u64 clock_cfg;int err; ptp =devm_kzalloc (dev,sizeof (*ptp),GFP_KERNEL );
@@ -172,17 +161,6 @@ static int ptp_probe(struct pci_dev *pdev, ptp->reg_base =pcim_iomap_table (pdev)[PCI_PTP_BAR_NO ]; - ptp->clock_rate =get_clock_rate (); - -/* Enable PTP clock */ - clock_cfg =readq (ptp->reg_base +PTP_CLOCK_CFG ); - clock_cfg |=PTP_CLOCK_CFG_PTP_EN ; -writeq (clock_cfg, ptp->reg_base +PTP_CLOCK_CFG ); - - clock_comp = ((u64 )1000000000ull <<32 ) / ptp->clock_rate; -/* Initial compensation value to start the nanosecs counter */ -writeq (clock_comp, ptp->reg_base +PTP_CLOCK_COMP ); -pci_set_drvdata (pdev, ptp);if (!first_ptp_block) first_ptp_block = ptp;
drivers/net/ethernet/marvell/octeontx2/af/ptp.h +1 -0
@@ -20,6 +20,7 @@ struct ptp {struct ptp *ptp_get (void );void ptp_put (struct ptp *ptp); +void ptp_start (struct ptp *ptp,u64 sclk);extern struct pci_driver ptp_driver;
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +3 -0
@@ -3240,6 +3240,9 @@ static int rvu_probe(struct pci_dev *pdev, const struct pci_device_id *id)mutex_init (&rvu->rswitch.switch_lock); +if (rvu->fwdata) +ptp_start (rvu->ptp, rvu->fwdata->sclk); +return 0 ; err_dl:rvu_unregister_dl (rvu);
Signature · 1 line
2.17.1
PATCH 4/4 octeontx2-af: Add external ptp input clock
In reply to Hariprasad KelamFrom: Yi Guo <[email protected]>
PTP hardware block can be configured to utilize the external clock. Also the current ptp timestamp can be captured when external trigger is applied on a gpio pin. These features are required in scenarios like connecting a external timing device to the chip for time synchronization. The timing device provides the clock and trigger(PPS signal) to the PTP block. This patch does the following:
1. configures PTP block to use external clock frequency and timestamp capture on external event.
2. sends PTP_REQ_EXTTS events to kernel ptp phc susbsytem with captured timestamps
3. aligns PPS edge to adjusted ptp clock in the ptp device by setting the PPS_THRESH to the reminder of the last timestamp value captured by external PPS
--- .../net/ethernet/marvell/octeontx2/af/mbox.h | 3 + .../net/ethernet/marvell/octeontx2/af/ptp.c | 55 +++++++- .../net/ethernet/marvell/octeontx2/af/ptp.h | 2 +- .../net/ethernet/marvell/octeontx2/af/rvu.c | 3 +- .../net/ethernet/marvell/octeontx2/af/rvu.h | 4 +- .../marvell/octeontx2/nic/otx2_common.h | 6 + .../ethernet/marvell/octeontx2/nic/otx2_ptp.c | 120 +++++++++++++++++- 7 files changed, 187 insertions(+), 6 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +3 -0
@@ -1420,12 +1420,15 @@ struct npc_mcam_get_stats_rsp {enum ptp_op {PTP_OP_ADJFINE =0 ,PTP_OP_GET_CLOCK =1 , +PTP_OP_GET_TSTMP =2 , +PTP_OP_SET_THRESH =3 , };struct ptp_req {struct mbox_msghdr hdr;u8 op;s64 scaled_ppm; +u64 thresh; };struct ptp_rsp {
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +54 -1
90 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/af/ptp.h +1 -1
@@ -20,7 +20,7 @@ struct ptp {struct ptp *ptp_get (void );void ptp_put (struct ptp *ptp); -void ptp_start (struct ptp *ptp,u64 sclk); +void ptp_start (struct ptp *ptp,u64 sclk,u32 ext_clk_freq,u32 extts);extern struct pci_driver ptp_driver;
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +2 -1
@@ -3241,7 +3241,8 @@ static int rvu_probe(struct pci_dev *pdev, const struct pci_device_id *id)mutex_init (&rvu->rswitch.switch_lock);if (rvu->fwdata) -ptp_start (rvu->ptp, rvu->fwdata->sclk); +ptp_start (rvu->ptp, rvu->fwdata->sclk, rvu->fwdata->ptp_ext_clk_rate, + rvu->fwdata->ptp_ext_tstamp);return 0 ; err_dl:
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +3 -1
@@ -396,7 +396,9 @@ struct rvu_fwdata {u64 mcam_addr;u64 mcam_sz;u64 msixtr_base; -#define FWDATA_RESERVED_MEM 1023 +u32 ptp_ext_clk_rate; +u32 ptp_ext_tstamp; +#define FWDATA_RESERVED_MEM 1022u64 reserved[FWDATA_RESERVED_MEM ];#define CGX_MAX 5#define CGX_LMACS_MAX 4
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +6 -0
@@ -264,6 +264,12 @@ struct otx2_ptp {struct cyclecounter cycle_counter;struct timecounter time_counter; + +struct delayed_work extts_work; +u64 last_extts; +u64 thresh; + +struct ptp_pin_desc extts_config; };#define OTX2_HW_TIMESTAMP_LEN 8
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c +118 -2
159 lines not on this page · raw message
Signature · 1 line
2.17.1
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 8 lines · On Tue, 28 Sep 2021 17:00:57 +0530 you wrote:
Externel ptp support is required in a scenario like connecting a external timing device to the chip for time synchronization. This series of patches adds support to ptp driver to use external clock and enables PTP config in CN10K MAC block (RPM). Currently PTP configuration is left unchanged in FLR handler these patches addresses the same.
[...]
Here is the summary with links:
- [net-next,1/4] octeontx2-af: Reset PTP config in FLR handler
https://git.kernel.org/netdev/net-next/c/e37e08fffc37 - [net-next,2/4] octeontx2-af: cn10k: RPM hardware timestamp configuration https://git.kernel.org/netdev/net-next/c/d1489208681d - [net-next,3/4] octeontx2-af: Use ptp input clock info from firmware data https://git.kernel.org/netdev/net-next/c/e266f6639396 - [net-next,4/4] octeontx2-af: Add external ptp input clock https://git.kernel.org/netdev/net-next/c/99bbc4ae69b9
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html