@@ -1559,6 +1559,10 @@ void ice_ptp_extts_event(struct ice_pf *pf)
15591559 u8 chan , tmr_idx ;
15601560 u32 hi , lo ;
15611561
1562+ /* Don't process timestamp events if PTP is not ready */
1563+ if (pf -> ptp .state != ICE_PTP_READY )
1564+ return ;
1565+
15621566 tmr_idx = hw -> func_caps .ts_func_info .tmr_index_owned ;
15631567 /* Event time is captured by one of the two matched registers
15641568 * GLTSYN_EVNT_L: 32 LSB of sampled time event
@@ -1584,27 +1588,33 @@ void ice_ptp_extts_event(struct ice_pf *pf)
15841588/**
15851589 * ice_ptp_cfg_extts - Configure EXTTS pin and channel
15861590 * @pf: Board private structure
1587- * @ena: true to enable; false to disable
15881591 * @chan: GPIO channel (0-3)
1589- * @gpio_pin: GPIO pin
1590- * @extts_flags: request flags from the ptp_extts_request.flags
1592+ * @config: desired EXTTS configuration.
1593+ * @store: If set to true, the values will be stored
1594+ *
1595+ * Configure an external timestamp event on the requested channel.
1596+ *
1597+ * Return: 0 on success, -EOPNOTUSPP on unsupported flags
15911598 */
1592- static int
1593- ice_ptp_cfg_extts (struct ice_pf * pf , bool ena , unsigned int chan , u32 gpio_pin ,
1594- unsigned int extts_flags )
1599+ static int ice_ptp_cfg_extts (struct ice_pf * pf , unsigned int chan ,
1600+ struct ice_extts_channel * config , bool store )
15951601{
15961602 u32 func , aux_reg , gpio_reg , irq_reg ;
15971603 struct ice_hw * hw = & pf -> hw ;
15981604 u8 tmr_idx ;
15991605
1600- if (chan > (unsigned int )pf -> ptp .info .n_ext_ts )
1601- return - EINVAL ;
1606+ /* Reject requests with unsupported flags */
1607+ if (config -> flags & ~(PTP_ENABLE_FEATURE |
1608+ PTP_RISING_EDGE |
1609+ PTP_FALLING_EDGE |
1610+ PTP_STRICT_FLAGS ))
1611+ return - EOPNOTSUPP ;
16021612
16031613 tmr_idx = hw -> func_caps .ts_func_info .tmr_index_owned ;
16041614
16051615 irq_reg = rd32 (hw , PFINT_OICR_ENA );
16061616
1607- if (ena ) {
1617+ if (config -> ena ) {
16081618 /* Enable the interrupt */
16091619 irq_reg |= PFINT_OICR_TSYN_EVNT_M ;
16101620 aux_reg = GLTSYN_AUX_IN_0_INT_ENA_M ;
@@ -1613,9 +1623,9 @@ ice_ptp_cfg_extts(struct ice_pf *pf, bool ena, unsigned int chan, u32 gpio_pin,
16131623#define GLTSYN_AUX_IN_0_EVNTLVL_FALLING_EDGE BIT(1)
16141624
16151625 /* set event level to requested edge */
1616- if (extts_flags & PTP_FALLING_EDGE )
1626+ if (config -> flags & PTP_FALLING_EDGE )
16171627 aux_reg |= GLTSYN_AUX_IN_0_EVNTLVL_FALLING_EDGE ;
1618- if (extts_flags & PTP_RISING_EDGE )
1628+ if (config -> flags & PTP_RISING_EDGE )
16191629 aux_reg |= GLTSYN_AUX_IN_0_EVNTLVL_RISING_EDGE ;
16201630
16211631 /* Write GPIO CTL reg.
@@ -1636,11 +1646,51 @@ ice_ptp_cfg_extts(struct ice_pf *pf, bool ena, unsigned int chan, u32 gpio_pin,
16361646
16371647 wr32 (hw , PFINT_OICR_ENA , irq_reg );
16381648 wr32 (hw , GLTSYN_AUX_IN (chan , tmr_idx ), aux_reg );
1639- wr32 (hw , GLGEN_GPIO_CTL (gpio_pin ), gpio_reg );
1649+ wr32 (hw , GLGEN_GPIO_CTL (config -> gpio_pin ), gpio_reg );
1650+
1651+ if (store )
1652+ memcpy (& pf -> ptp .extts_channels [chan ], config , sizeof (* config ));
16401653
16411654 return 0 ;
16421655}
16431656
1657+ /**
1658+ * ice_ptp_disable_all_extts - Disable all EXTTS channels
1659+ * @pf: Board private structure
1660+ */
1661+ static void ice_ptp_disable_all_extts (struct ice_pf * pf )
1662+ {
1663+ struct ice_extts_channel extts_cfg = {};
1664+ int i ;
1665+
1666+ for (i = 0 ; i < pf -> ptp .info .n_ext_ts ; i ++ ) {
1667+ if (pf -> ptp .extts_channels [i ].ena ) {
1668+ extts_cfg .gpio_pin = pf -> ptp .extts_channels [i ].gpio_pin ;
1669+ extts_cfg .ena = false;
1670+ ice_ptp_cfg_extts (pf , i , & extts_cfg , false);
1671+ }
1672+ }
1673+
1674+ synchronize_irq (pf -> oicr_irq .virq );
1675+ }
1676+
1677+ /**
1678+ * ice_ptp_enable_all_extts - Enable all EXTTS channels
1679+ * @pf: Board private structure
1680+ *
1681+ * Called during reset to restore user configuration.
1682+ */
1683+ static void ice_ptp_enable_all_extts (struct ice_pf * pf )
1684+ {
1685+ int i ;
1686+
1687+ for (i = 0 ; i < pf -> ptp .info .n_ext_ts ; i ++ ) {
1688+ if (pf -> ptp .extts_channels [i ].ena )
1689+ ice_ptp_cfg_extts (pf , i , & pf -> ptp .extts_channels [i ],
1690+ false);
1691+ }
1692+ }
1693+
16441694/**
16451695 * ice_ptp_cfg_clkout - Configure clock to generate periodic wave
16461696 * @pf: Board private structure
@@ -1659,6 +1709,9 @@ static int ice_ptp_cfg_clkout(struct ice_pf *pf, unsigned int chan,
16591709 u32 func , val , gpio_pin ;
16601710 u8 tmr_idx ;
16611711
1712+ if (config && config -> flags & ~PTP_PEROUT_PHASE )
1713+ return - EOPNOTSUPP ;
1714+
16621715 tmr_idx = hw -> func_caps .ts_func_info .tmr_index_owned ;
16631716
16641717 /* 0. Reset mode & out_en in AUX_OUT */
@@ -1795,17 +1848,18 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
17951848 struct ptp_clock_request * rq , int on )
17961849{
17971850 struct ice_pf * pf = ptp_info_to_pf (info );
1798- struct ice_perout_channel clk_cfg = {0 };
17991851 bool sma_pres = false;
18001852 unsigned int chan ;
18011853 u32 gpio_pin ;
1802- int err ;
18031854
18041855 if (ice_is_feature_supported (pf , ICE_F_SMA_CTRL ))
18051856 sma_pres = true;
18061857
18071858 switch (rq -> type ) {
18081859 case PTP_CLK_REQ_PEROUT :
1860+ {
1861+ struct ice_perout_channel clk_cfg = {};
1862+
18091863 chan = rq -> perout .index ;
18101864 if (sma_pres ) {
18111865 if (chan == ice_pin_desc_e810t [SMA1 ].chan )
@@ -1825,15 +1879,19 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
18251879 clk_cfg .gpio_pin = chan ;
18261880 }
18271881
1882+ clk_cfg .flags = rq -> perout .flags ;
18281883 clk_cfg .period = ((rq -> perout .period .sec * NSEC_PER_SEC ) +
18291884 rq -> perout .period .nsec );
18301885 clk_cfg .start_time = ((rq -> perout .start .sec * NSEC_PER_SEC ) +
18311886 rq -> perout .start .nsec );
18321887 clk_cfg .ena = !!on ;
18331888
1834- err = ice_ptp_cfg_clkout (pf , chan , & clk_cfg , true);
1835- break ;
1889+ return ice_ptp_cfg_clkout (pf , chan , & clk_cfg , true);
1890+ }
18361891 case PTP_CLK_REQ_EXTTS :
1892+ {
1893+ struct ice_extts_channel extts_cfg = {};
1894+
18371895 chan = rq -> extts .index ;
18381896 if (sma_pres ) {
18391897 if (chan < ice_pin_desc_e810t [SMA2 ].chan )
@@ -1849,14 +1907,15 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
18491907 gpio_pin = chan ;
18501908 }
18511909
1852- err = ice_ptp_cfg_extts (pf , !!on , chan , gpio_pin ,
1853- rq -> extts .flags );
1854- break ;
1910+ extts_cfg .flags = rq -> extts .flags ;
1911+ extts_cfg .gpio_pin = gpio_pin ;
1912+ extts_cfg .ena = !!on ;
1913+
1914+ return ice_ptp_cfg_extts (pf , chan , & extts_cfg , true);
1915+ }
18551916 default :
18561917 return - EOPNOTSUPP ;
18571918 }
1858-
1859- return err ;
18601919}
18611920
18621921/**
@@ -1869,26 +1928,32 @@ static int ice_ptp_gpio_enable_e823(struct ptp_clock_info *info,
18691928 struct ptp_clock_request * rq , int on )
18701929{
18711930 struct ice_pf * pf = ptp_info_to_pf (info );
1872- struct ice_perout_channel clk_cfg = {0 };
1873- int err ;
18741931
18751932 switch (rq -> type ) {
18761933 case PTP_CLK_REQ_PPS :
1934+ {
1935+ struct ice_perout_channel clk_cfg = {};
1936+
1937+ clk_cfg .flags = rq -> perout .flags ;
18771938 clk_cfg .gpio_pin = PPS_PIN_INDEX ;
18781939 clk_cfg .period = NSEC_PER_SEC ;
18791940 clk_cfg .ena = !!on ;
18801941
1881- err = ice_ptp_cfg_clkout (pf , PPS_CLK_GEN_CHAN , & clk_cfg , true);
1882- break ;
1942+ return ice_ptp_cfg_clkout (pf , PPS_CLK_GEN_CHAN , & clk_cfg , true);
1943+ }
18831944 case PTP_CLK_REQ_EXTTS :
1884- err = ice_ptp_cfg_extts (pf , !!on , rq -> extts .index ,
1885- TIME_SYNC_PIN_INDEX , rq -> extts .flags );
1886- break ;
1945+ {
1946+ struct ice_extts_channel extts_cfg = {};
1947+
1948+ extts_cfg .flags = rq -> extts .flags ;
1949+ extts_cfg .gpio_pin = TIME_SYNC_PIN_INDEX ;
1950+ extts_cfg .ena = !!on ;
1951+
1952+ return ice_ptp_cfg_extts (pf , rq -> extts .index , & extts_cfg , true);
1953+ }
18871954 default :
18881955 return - EOPNOTSUPP ;
18891956 }
1890-
1891- return err ;
18921957}
18931958
18941959/**
@@ -2720,6 +2785,10 @@ static int ice_ptp_rebuild_owner(struct ice_pf *pf)
27202785 ice_ptp_restart_all_phy (pf );
27212786 }
27222787
2788+ /* Re-enable all periodic outputs and external timestamp events */
2789+ ice_ptp_enable_all_clkout (pf );
2790+ ice_ptp_enable_all_extts (pf );
2791+
27232792 return 0 ;
27242793}
27252794
@@ -3275,6 +3344,8 @@ void ice_ptp_release(struct ice_pf *pf)
32753344
32763345 ice_ptp_release_tx_tracker (pf , & pf -> ptp .port .tx );
32773346
3347+ ice_ptp_disable_all_extts (pf );
3348+
32783349 kthread_cancel_delayed_work_sync (& pf -> ptp .work );
32793350
32803351 ice_ptp_port_phy_stop (& pf -> ptp .port );
0 commit comments