@@ -275,15 +275,13 @@ static bool am65_cpts_fifo_pop_event(struct am65_cpts *cpts,
275
275
return true;
276
276
}
277
277
278
- static int am65_cpts_fifo_read (struct am65_cpts * cpts )
278
+ static int __am65_cpts_fifo_read (struct am65_cpts * cpts )
279
279
{
280
280
struct ptp_clock_event pevent ;
281
281
struct am65_cpts_event * event ;
282
282
bool schedule = false;
283
283
int i , type , ret = 0 ;
284
- unsigned long flags ;
285
284
286
- spin_lock_irqsave (& cpts -> lock , flags );
287
285
for (i = 0 ; i < AM65_CPTS_FIFO_DEPTH ; i ++ ) {
288
286
event = list_first_entry_or_null (& cpts -> pool ,
289
287
struct am65_cpts_event , list );
@@ -312,8 +310,7 @@ static int am65_cpts_fifo_read(struct am65_cpts *cpts)
312
310
event -> tmo = jiffies +
313
311
msecs_to_jiffies (AM65_CPTS_EVENT_RX_TX_TIMEOUT );
314
312
315
- list_del_init (& event -> list );
316
- list_add_tail (& event -> list , & cpts -> events );
313
+ list_move_tail (& event -> list , & cpts -> events );
317
314
318
315
dev_dbg (cpts -> dev ,
319
316
"AM65_CPTS_EV_TX e1:%08x e2:%08x t:%lld\n" ,
@@ -356,14 +353,24 @@ static int am65_cpts_fifo_read(struct am65_cpts *cpts)
356
353
}
357
354
358
355
out :
359
- spin_unlock_irqrestore (& cpts -> lock , flags );
360
-
361
356
if (schedule )
362
357
ptp_schedule_worker (cpts -> ptp_clock , 0 );
363
358
364
359
return ret ;
365
360
}
366
361
362
+ static int am65_cpts_fifo_read (struct am65_cpts * cpts )
363
+ {
364
+ unsigned long flags ;
365
+ int ret = 0 ;
366
+
367
+ spin_lock_irqsave (& cpts -> lock , flags );
368
+ ret = __am65_cpts_fifo_read (cpts );
369
+ spin_unlock_irqrestore (& cpts -> lock , flags );
370
+
371
+ return ret ;
372
+ }
373
+
367
374
static u64 am65_cpts_gettime (struct am65_cpts * cpts ,
368
375
struct ptp_system_timestamp * sts )
369
376
{
@@ -906,6 +913,69 @@ static int am65_skb_get_mtype_seqid(struct sk_buff *skb, u32 *mtype_seqid)
906
913
return 1 ;
907
914
}
908
915
916
+ static u64 am65_cpts_find_rx_ts (struct am65_cpts * cpts , u32 skb_mtype_seqid )
917
+ {
918
+ struct list_head * this , * next ;
919
+ struct am65_cpts_event * event ;
920
+ unsigned long flags ;
921
+ u32 mtype_seqid ;
922
+ u64 ns = 0 ;
923
+
924
+ spin_lock_irqsave (& cpts -> lock , flags );
925
+ __am65_cpts_fifo_read (cpts );
926
+ list_for_each_safe (this , next , & cpts -> events ) {
927
+ event = list_entry (this , struct am65_cpts_event , list );
928
+ if (time_after (jiffies , event -> tmo )) {
929
+ list_move (& event -> list , & cpts -> pool );
930
+ continue ;
931
+ }
932
+
933
+ mtype_seqid = event -> event1 &
934
+ (AM65_CPTS_EVENT_1_MESSAGE_TYPE_MASK |
935
+ AM65_CPTS_EVENT_1_SEQUENCE_ID_MASK |
936
+ AM65_CPTS_EVENT_1_EVENT_TYPE_MASK );
937
+
938
+ if (mtype_seqid == skb_mtype_seqid ) {
939
+ ns = event -> timestamp ;
940
+ list_move (& event -> list , & cpts -> pool );
941
+ break ;
942
+ }
943
+ }
944
+ spin_unlock_irqrestore (& cpts -> lock , flags );
945
+
946
+ return ns ;
947
+ }
948
+
949
+ void am65_cpts_rx_timestamp (struct am65_cpts * cpts , struct sk_buff * skb )
950
+ {
951
+ struct am65_cpts_skb_cb_data * skb_cb = (struct am65_cpts_skb_cb_data * )skb -> cb ;
952
+ struct skb_shared_hwtstamps * ssh ;
953
+ int ret ;
954
+ u64 ns ;
955
+
956
+ /* am65_cpts_rx_timestamp() is called before eth_type_trans(), so
957
+ * skb MAC Hdr properties are not configured yet. Hence need to
958
+ * reset skb MAC header here
959
+ */
960
+ skb_reset_mac_header (skb );
961
+ ret = am65_skb_get_mtype_seqid (skb , & skb_cb -> skb_mtype_seqid );
962
+ if (!ret )
963
+ return ; /* if not PTP class packet */
964
+
965
+ skb_cb -> skb_mtype_seqid |= (AM65_CPTS_EV_RX << AM65_CPTS_EVENT_1_EVENT_TYPE_SHIFT );
966
+
967
+ dev_dbg (cpts -> dev , "%s mtype seqid %08x\n" , __func__ , skb_cb -> skb_mtype_seqid );
968
+
969
+ ns = am65_cpts_find_rx_ts (cpts , skb_cb -> skb_mtype_seqid );
970
+ if (!ns )
971
+ return ;
972
+
973
+ ssh = skb_hwtstamps (skb );
974
+ memset (ssh , 0 , sizeof (* ssh ));
975
+ ssh -> hwtstamp = ns_to_ktime (ns );
976
+ }
977
+ EXPORT_SYMBOL_GPL (am65_cpts_rx_timestamp );
978
+
909
979
/**
910
980
* am65_cpts_tx_timestamp - save tx packet for timestamping
911
981
* @cpts: cpts handle
0 commit comments