@@ -1559,6 +1559,10 @@ void ice_ptp_extts_event(struct ice_pf *pf)
1559
1559
u8 chan , tmr_idx ;
1560
1560
u32 hi , lo ;
1561
1561
1562
+ /* Don't process timestamp events if PTP is not ready */
1563
+ if (pf -> ptp .state != ICE_PTP_READY )
1564
+ return ;
1565
+
1562
1566
tmr_idx = hw -> func_caps .ts_func_info .tmr_index_owned ;
1563
1567
/* Event time is captured by one of the two matched registers
1564
1568
* GLTSYN_EVNT_L: 32 LSB of sampled time event
@@ -1584,27 +1588,33 @@ void ice_ptp_extts_event(struct ice_pf *pf)
1584
1588
/**
1585
1589
* ice_ptp_cfg_extts - Configure EXTTS pin and channel
1586
1590
* @pf: Board private structure
1587
- * @ena: true to enable; false to disable
1588
1591
* @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
1591
1598
*/
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 )
1595
1601
{
1596
1602
u32 func , aux_reg , gpio_reg , irq_reg ;
1597
1603
struct ice_hw * hw = & pf -> hw ;
1598
1604
u8 tmr_idx ;
1599
1605
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 ;
1602
1612
1603
1613
tmr_idx = hw -> func_caps .ts_func_info .tmr_index_owned ;
1604
1614
1605
1615
irq_reg = rd32 (hw , PFINT_OICR_ENA );
1606
1616
1607
- if (ena ) {
1617
+ if (config -> ena ) {
1608
1618
/* Enable the interrupt */
1609
1619
irq_reg |= PFINT_OICR_TSYN_EVNT_M ;
1610
1620
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,
1613
1623
#define GLTSYN_AUX_IN_0_EVNTLVL_FALLING_EDGE BIT(1)
1614
1624
1615
1625
/* set event level to requested edge */
1616
- if (extts_flags & PTP_FALLING_EDGE )
1626
+ if (config -> flags & PTP_FALLING_EDGE )
1617
1627
aux_reg |= GLTSYN_AUX_IN_0_EVNTLVL_FALLING_EDGE ;
1618
- if (extts_flags & PTP_RISING_EDGE )
1628
+ if (config -> flags & PTP_RISING_EDGE )
1619
1629
aux_reg |= GLTSYN_AUX_IN_0_EVNTLVL_RISING_EDGE ;
1620
1630
1621
1631
/* Write GPIO CTL reg.
@@ -1636,11 +1646,51 @@ ice_ptp_cfg_extts(struct ice_pf *pf, bool ena, unsigned int chan, u32 gpio_pin,
1636
1646
1637
1647
wr32 (hw , PFINT_OICR_ENA , irq_reg );
1638
1648
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 ));
1640
1653
1641
1654
return 0 ;
1642
1655
}
1643
1656
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
+
1644
1694
/**
1645
1695
* ice_ptp_cfg_clkout - Configure clock to generate periodic wave
1646
1696
* @pf: Board private structure
@@ -1659,6 +1709,9 @@ static int ice_ptp_cfg_clkout(struct ice_pf *pf, unsigned int chan,
1659
1709
u32 func , val , gpio_pin ;
1660
1710
u8 tmr_idx ;
1661
1711
1712
+ if (config && config -> flags & ~PTP_PEROUT_PHASE )
1713
+ return - EOPNOTSUPP ;
1714
+
1662
1715
tmr_idx = hw -> func_caps .ts_func_info .tmr_index_owned ;
1663
1716
1664
1717
/* 0. Reset mode & out_en in AUX_OUT */
@@ -1795,17 +1848,18 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
1795
1848
struct ptp_clock_request * rq , int on )
1796
1849
{
1797
1850
struct ice_pf * pf = ptp_info_to_pf (info );
1798
- struct ice_perout_channel clk_cfg = {0 };
1799
1851
bool sma_pres = false;
1800
1852
unsigned int chan ;
1801
1853
u32 gpio_pin ;
1802
- int err ;
1803
1854
1804
1855
if (ice_is_feature_supported (pf , ICE_F_SMA_CTRL ))
1805
1856
sma_pres = true;
1806
1857
1807
1858
switch (rq -> type ) {
1808
1859
case PTP_CLK_REQ_PEROUT :
1860
+ {
1861
+ struct ice_perout_channel clk_cfg = {};
1862
+
1809
1863
chan = rq -> perout .index ;
1810
1864
if (sma_pres ) {
1811
1865
if (chan == ice_pin_desc_e810t [SMA1 ].chan )
@@ -1825,15 +1879,19 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
1825
1879
clk_cfg .gpio_pin = chan ;
1826
1880
}
1827
1881
1882
+ clk_cfg .flags = rq -> perout .flags ;
1828
1883
clk_cfg .period = ((rq -> perout .period .sec * NSEC_PER_SEC ) +
1829
1884
rq -> perout .period .nsec );
1830
1885
clk_cfg .start_time = ((rq -> perout .start .sec * NSEC_PER_SEC ) +
1831
1886
rq -> perout .start .nsec );
1832
1887
clk_cfg .ena = !!on ;
1833
1888
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
+ }
1836
1891
case PTP_CLK_REQ_EXTTS :
1892
+ {
1893
+ struct ice_extts_channel extts_cfg = {};
1894
+
1837
1895
chan = rq -> extts .index ;
1838
1896
if (sma_pres ) {
1839
1897
if (chan < ice_pin_desc_e810t [SMA2 ].chan )
@@ -1849,14 +1907,15 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
1849
1907
gpio_pin = chan ;
1850
1908
}
1851
1909
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
+ }
1855
1916
default :
1856
1917
return - EOPNOTSUPP ;
1857
1918
}
1858
-
1859
- return err ;
1860
1919
}
1861
1920
1862
1921
/**
@@ -1869,26 +1928,32 @@ static int ice_ptp_gpio_enable_e823(struct ptp_clock_info *info,
1869
1928
struct ptp_clock_request * rq , int on )
1870
1929
{
1871
1930
struct ice_pf * pf = ptp_info_to_pf (info );
1872
- struct ice_perout_channel clk_cfg = {0 };
1873
- int err ;
1874
1931
1875
1932
switch (rq -> type ) {
1876
1933
case PTP_CLK_REQ_PPS :
1934
+ {
1935
+ struct ice_perout_channel clk_cfg = {};
1936
+
1937
+ clk_cfg .flags = rq -> perout .flags ;
1877
1938
clk_cfg .gpio_pin = PPS_PIN_INDEX ;
1878
1939
clk_cfg .period = NSEC_PER_SEC ;
1879
1940
clk_cfg .ena = !!on ;
1880
1941
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
+ }
1883
1944
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
+ }
1887
1954
default :
1888
1955
return - EOPNOTSUPP ;
1889
1956
}
1890
-
1891
- return err ;
1892
1957
}
1893
1958
1894
1959
/**
@@ -2720,6 +2785,10 @@ static int ice_ptp_rebuild_owner(struct ice_pf *pf)
2720
2785
ice_ptp_restart_all_phy (pf );
2721
2786
}
2722
2787
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
+
2723
2792
return 0 ;
2724
2793
}
2725
2794
@@ -3275,6 +3344,8 @@ void ice_ptp_release(struct ice_pf *pf)
3275
3344
3276
3345
ice_ptp_release_tx_tracker (pf , & pf -> ptp .port .tx );
3277
3346
3347
+ ice_ptp_disable_all_extts (pf );
3348
+
3278
3349
kthread_cancel_delayed_work_sync (& pf -> ptp .work );
3279
3350
3280
3351
ice_ptp_port_phy_stop (& pf -> ptp .port );
0 commit comments