@@ -506,39 +506,6 @@ static int sja1105_init_l2_policing(struct sja1105_private *priv)
506
506
return 0 ;
507
507
}
508
508
509
- static int sja1105_init_avb_params (struct sja1105_private * priv ,
510
- bool on )
511
- {
512
- struct sja1105_avb_params_entry * avb ;
513
- struct sja1105_table * table ;
514
-
515
- table = & priv -> static_config .tables [BLK_IDX_AVB_PARAMS ];
516
-
517
- /* Discard previous AVB Parameters Table */
518
- if (table -> entry_count ) {
519
- kfree (table -> entries );
520
- table -> entry_count = 0 ;
521
- }
522
-
523
- /* Configure the reception of meta frames only if requested */
524
- if (!on )
525
- return 0 ;
526
-
527
- table -> entries = kcalloc (SJA1105_MAX_AVB_PARAMS_COUNT ,
528
- table -> ops -> unpacked_entry_size , GFP_KERNEL );
529
- if (!table -> entries )
530
- return - ENOMEM ;
531
-
532
- table -> entry_count = SJA1105_MAX_AVB_PARAMS_COUNT ;
533
-
534
- avb = table -> entries ;
535
-
536
- avb -> destmeta = SJA1105_META_DMAC ;
537
- avb -> srcmeta = SJA1105_META_SMAC ;
538
-
539
- return 0 ;
540
- }
541
-
542
509
static int sja1105_static_config_load (struct sja1105_private * priv ,
543
510
struct sja1105_dt_port * ports )
544
511
{
@@ -577,9 +544,6 @@ static int sja1105_static_config_load(struct sja1105_private *priv,
577
544
if (rc < 0 )
578
545
return rc ;
579
546
rc = sja1105_init_general_params (priv );
580
- if (rc < 0 )
581
- return rc ;
582
- rc = sja1105_init_avb_params (priv , false);
583
547
if (rc < 0 )
584
548
return rc ;
585
549
@@ -1686,7 +1650,7 @@ static int sja1105_setup(struct dsa_switch *ds)
1686
1650
return rc ;
1687
1651
}
1688
1652
1689
- rc = sja1105_ptp_clock_register (priv );
1653
+ rc = sja1105_ptp_clock_register (ds );
1690
1654
if (rc < 0 ) {
1691
1655
dev_err (ds -> dev , "Failed to register PTP clock: %d\n" , rc );
1692
1656
return rc ;
@@ -1728,9 +1692,7 @@ static void sja1105_teardown(struct dsa_switch *ds)
1728
1692
struct sja1105_private * priv = ds -> priv ;
1729
1693
1730
1694
sja1105_tas_teardown (ds );
1731
- cancel_work_sync (& priv -> tagger_data .rxtstamp_work );
1732
- skb_queue_purge (& priv -> tagger_data .skb_rxtstamp_queue );
1733
- sja1105_ptp_clock_unregister (priv );
1695
+ sja1105_ptp_clock_unregister (ds );
1734
1696
sja1105_static_config_free (& priv -> static_config );
1735
1697
}
1736
1698
@@ -1816,11 +1778,8 @@ static netdev_tx_t sja1105_port_deferred_xmit(struct dsa_switch *ds, int port,
1816
1778
{
1817
1779
struct sja1105_private * priv = ds -> priv ;
1818
1780
struct sja1105_port * sp = & priv -> ports [port ];
1819
- struct skb_shared_hwtstamps shwt = {0 };
1820
1781
int slot = sp -> mgmt_slot ;
1821
1782
struct sk_buff * clone ;
1822
- u64 now , ts ;
1823
- int rc ;
1824
1783
1825
1784
/* The tragic fact about the switch having 4x2 slots for installing
1826
1785
* management routes is that all of them except one are actually
@@ -1846,27 +1805,8 @@ static netdev_tx_t sja1105_port_deferred_xmit(struct dsa_switch *ds, int port,
1846
1805
if (!clone )
1847
1806
goto out ;
1848
1807
1849
- skb_shinfo (clone )-> tx_flags |= SKBTX_IN_PROGRESS ;
1850
-
1851
- mutex_lock (& priv -> ptp_lock );
1852
-
1853
- now = priv -> tstamp_cc .read (& priv -> tstamp_cc );
1854
-
1855
- rc = sja1105_ptpegr_ts_poll (priv , slot , & ts );
1856
- if (rc < 0 ) {
1857
- dev_err (ds -> dev , "xmit: timed out polling for tstamp\n" );
1858
- kfree_skb (clone );
1859
- goto out_unlock_ptp ;
1860
- }
1861
-
1862
- ts = sja1105_tstamp_reconstruct (priv , now , ts );
1863
- ts = timecounter_cyc2time (& priv -> tstamp_tc , ts );
1864
-
1865
- shwt .hwtstamp = ns_to_ktime (ts );
1866
- skb_complete_tx_timestamp (clone , & shwt );
1808
+ sja1105_ptp_txtstamp_skb (ds , slot , clone );
1867
1809
1868
- out_unlock_ptp :
1869
- mutex_unlock (& priv -> ptp_lock );
1870
1810
out :
1871
1811
mutex_unlock (& priv -> mgmt_lock );
1872
1812
return NETDEV_TX_OK ;
@@ -1896,170 +1836,6 @@ static int sja1105_set_ageing_time(struct dsa_switch *ds,
1896
1836
return sja1105_static_config_reload (priv );
1897
1837
}
1898
1838
1899
- /* Must be called only with priv->tagger_data.state bit
1900
- * SJA1105_HWTS_RX_EN cleared
1901
- */
1902
- static int sja1105_change_rxtstamping (struct sja1105_private * priv ,
1903
- bool on )
1904
- {
1905
- struct sja1105_general_params_entry * general_params ;
1906
- struct sja1105_table * table ;
1907
- int rc ;
1908
-
1909
- table = & priv -> static_config .tables [BLK_IDX_GENERAL_PARAMS ];
1910
- general_params = table -> entries ;
1911
- general_params -> send_meta1 = on ;
1912
- general_params -> send_meta0 = on ;
1913
-
1914
- rc = sja1105_init_avb_params (priv , on );
1915
- if (rc < 0 )
1916
- return rc ;
1917
-
1918
- /* Initialize the meta state machine to a known state */
1919
- if (priv -> tagger_data .stampable_skb ) {
1920
- kfree_skb (priv -> tagger_data .stampable_skb );
1921
- priv -> tagger_data .stampable_skb = NULL ;
1922
- }
1923
-
1924
- return sja1105_static_config_reload (priv );
1925
- }
1926
-
1927
- static int sja1105_hwtstamp_set (struct dsa_switch * ds , int port ,
1928
- struct ifreq * ifr )
1929
- {
1930
- struct sja1105_private * priv = ds -> priv ;
1931
- struct hwtstamp_config config ;
1932
- bool rx_on ;
1933
- int rc ;
1934
-
1935
- if (copy_from_user (& config , ifr -> ifr_data , sizeof (config )))
1936
- return - EFAULT ;
1937
-
1938
- switch (config .tx_type ) {
1939
- case HWTSTAMP_TX_OFF :
1940
- priv -> ports [port ].hwts_tx_en = false;
1941
- break ;
1942
- case HWTSTAMP_TX_ON :
1943
- priv -> ports [port ].hwts_tx_en = true;
1944
- break ;
1945
- default :
1946
- return - ERANGE ;
1947
- }
1948
-
1949
- switch (config .rx_filter ) {
1950
- case HWTSTAMP_FILTER_NONE :
1951
- rx_on = false;
1952
- break ;
1953
- default :
1954
- rx_on = true;
1955
- break ;
1956
- }
1957
-
1958
- if (rx_on != test_bit (SJA1105_HWTS_RX_EN , & priv -> tagger_data .state )) {
1959
- clear_bit (SJA1105_HWTS_RX_EN , & priv -> tagger_data .state );
1960
-
1961
- rc = sja1105_change_rxtstamping (priv , rx_on );
1962
- if (rc < 0 ) {
1963
- dev_err (ds -> dev ,
1964
- "Failed to change RX timestamping: %d\n" , rc );
1965
- return rc ;
1966
- }
1967
- if (rx_on )
1968
- set_bit (SJA1105_HWTS_RX_EN , & priv -> tagger_data .state );
1969
- }
1970
-
1971
- if (copy_to_user (ifr -> ifr_data , & config , sizeof (config )))
1972
- return - EFAULT ;
1973
- return 0 ;
1974
- }
1975
-
1976
- static int sja1105_hwtstamp_get (struct dsa_switch * ds , int port ,
1977
- struct ifreq * ifr )
1978
- {
1979
- struct sja1105_private * priv = ds -> priv ;
1980
- struct hwtstamp_config config ;
1981
-
1982
- config .flags = 0 ;
1983
- if (priv -> ports [port ].hwts_tx_en )
1984
- config .tx_type = HWTSTAMP_TX_ON ;
1985
- else
1986
- config .tx_type = HWTSTAMP_TX_OFF ;
1987
- if (test_bit (SJA1105_HWTS_RX_EN , & priv -> tagger_data .state ))
1988
- config .rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT ;
1989
- else
1990
- config .rx_filter = HWTSTAMP_FILTER_NONE ;
1991
-
1992
- return copy_to_user (ifr -> ifr_data , & config , sizeof (config )) ?
1993
- - EFAULT : 0 ;
1994
- }
1995
-
1996
- #define to_tagger (d ) \
1997
- container_of((d), struct sja1105_tagger_data, rxtstamp_work)
1998
- #define to_sja1105 (d ) \
1999
- container_of((d), struct sja1105_private, tagger_data)
2000
-
2001
- static void sja1105_rxtstamp_work (struct work_struct * work )
2002
- {
2003
- struct sja1105_tagger_data * data = to_tagger (work );
2004
- struct sja1105_private * priv = to_sja1105 (data );
2005
- struct sk_buff * skb ;
2006
- u64 now ;
2007
-
2008
- mutex_lock (& priv -> ptp_lock );
2009
-
2010
- while ((skb = skb_dequeue (& data -> skb_rxtstamp_queue )) != NULL ) {
2011
- struct skb_shared_hwtstamps * shwt = skb_hwtstamps (skb );
2012
- u64 ts ;
2013
-
2014
- now = priv -> tstamp_cc .read (& priv -> tstamp_cc );
2015
-
2016
- * shwt = (struct skb_shared_hwtstamps ) {0 };
2017
-
2018
- ts = SJA1105_SKB_CB (skb )-> meta_tstamp ;
2019
- ts = sja1105_tstamp_reconstruct (priv , now , ts );
2020
- ts = timecounter_cyc2time (& priv -> tstamp_tc , ts );
2021
-
2022
- shwt -> hwtstamp = ns_to_ktime (ts );
2023
- netif_rx_ni (skb );
2024
- }
2025
-
2026
- mutex_unlock (& priv -> ptp_lock );
2027
- }
2028
-
2029
- /* Called from dsa_skb_defer_rx_timestamp */
2030
- static bool sja1105_port_rxtstamp (struct dsa_switch * ds , int port ,
2031
- struct sk_buff * skb , unsigned int type )
2032
- {
2033
- struct sja1105_private * priv = ds -> priv ;
2034
- struct sja1105_tagger_data * data = & priv -> tagger_data ;
2035
-
2036
- if (!test_bit (SJA1105_HWTS_RX_EN , & data -> state ))
2037
- return false;
2038
-
2039
- /* We need to read the full PTP clock to reconstruct the Rx
2040
- * timestamp. For that we need a sleepable context.
2041
- */
2042
- skb_queue_tail (& data -> skb_rxtstamp_queue , skb );
2043
- schedule_work (& data -> rxtstamp_work );
2044
- return true;
2045
- }
2046
-
2047
- /* Called from dsa_skb_tx_timestamp. This callback is just to make DSA clone
2048
- * the skb and have it available in DSA_SKB_CB in the .port_deferred_xmit
2049
- * callback, where we will timestamp it synchronously.
2050
- */
2051
- static bool sja1105_port_txtstamp (struct dsa_switch * ds , int port ,
2052
- struct sk_buff * skb , unsigned int type )
2053
- {
2054
- struct sja1105_private * priv = ds -> priv ;
2055
- struct sja1105_port * sp = & priv -> ports [port ];
2056
-
2057
- if (!sp -> hwts_tx_en )
2058
- return false;
2059
-
2060
- return true;
2061
- }
2062
-
2063
1839
static int sja1105_port_setup_tc (struct dsa_switch * ds , int port ,
2064
1840
enum tc_setup_type type ,
2065
1841
void * type_data )
@@ -2280,9 +2056,6 @@ static int sja1105_probe(struct spi_device *spi)
2280
2056
priv -> ds = ds ;
2281
2057
2282
2058
tagger_data = & priv -> tagger_data ;
2283
- skb_queue_head_init (& tagger_data -> skb_rxtstamp_queue );
2284
- INIT_WORK (& tagger_data -> rxtstamp_work , sja1105_rxtstamp_work );
2285
- spin_lock_init (& tagger_data -> meta_lock );
2286
2059
2287
2060
/* Connections between dsa_port and sja1105_port */
2288
2061
for (i = 0 ; i < SJA1105_NUM_PORTS ; i ++ ) {
@@ -2292,6 +2065,7 @@ static int sja1105_probe(struct spi_device *spi)
2292
2065
sp -> dp = & ds -> ports [i ];
2293
2066
sp -> data = tagger_data ;
2294
2067
}
2068
+ mutex_init (& priv -> ptp_data .lock );
2295
2069
mutex_init (& priv -> mgmt_lock );
2296
2070
2297
2071
sja1105_tas_setup (ds );
0 commit comments