@@ -163,12 +163,15 @@ static inline void ts_register_tx_event(const struct device *dev,
163
163
struct net_pkt * pkt = frameinfo -> context ;
164
164
165
165
if (pkt && atomic_get (& pkt -> atomic_ref ) > 0 ) {
166
- if (eth_get_ptp_data (net_pkt_iface (pkt ), pkt ) && frameinfo -> isTsAvail ) {
166
+ if ((eth_get_ptp_data (net_pkt_iface (pkt ), pkt ) ||
167
+ net_pkt_is_tx_timestamping (pkt )) &&
168
+ frameinfo -> isTsAvail ) {
167
169
/* Timestamp is written to packet in ISR.
168
170
* Semaphore ensures sequential execution of writing
169
171
* the timestamp here and subsequently reading the timestamp
170
172
* after waiting for the semaphore in eth_wait_for_ptp_ts().
171
173
*/
174
+
172
175
pkt -> timestamp .nanosecond = frameinfo -> timeStamp .nanosecond ;
173
176
pkt -> timestamp .second = frameinfo -> timeStamp .second ;
174
177
@@ -184,7 +187,9 @@ static inline void eth_wait_for_ptp_ts(const struct device *dev, struct net_pkt
184
187
struct nxp_enet_mac_data * data = dev -> data ;
185
188
186
189
net_pkt_ref (pkt );
187
- k_sem_take (& data -> ptp .ptp_ts_sem , K_FOREVER );
190
+ while (k_sem_take (& data -> ptp .ptp_ts_sem , K_MSEC (200 )) != 0 ) {
191
+ LOG_ERR ("error on take PTP semaphore" );
192
+ }
188
193
}
189
194
#else
190
195
#define eth_get_ptp_data (...) false
@@ -220,10 +225,11 @@ static int eth_nxp_enet_tx(const struct device *dev, struct net_pkt *pkt)
220
225
goto exit ;
221
226
}
222
227
223
- frame_is_timestamped = eth_get_ptp_data (net_pkt_iface (pkt ), pkt );
228
+ frame_is_timestamped =
229
+ eth_get_ptp_data (net_pkt_iface (pkt ), pkt ) || net_pkt_is_tx_timestamping (pkt );
224
230
225
- ret = ENET_SendFrame (data -> base , & data -> enet_handle , data -> tx_frame_buf ,
226
- total_len , RING_ID , frame_is_timestamped , pkt );
231
+ ret = ENET_SendFrame (data -> base , & data -> enet_handle , data -> tx_frame_buf , total_len , RING_ID ,
232
+ frame_is_timestamped , pkt );
227
233
228
234
if (ret != kStatus_Success ) {
229
235
LOG_ERR ("ENET_SendFrame error: %d" , ret );
@@ -339,6 +345,7 @@ static int eth_nxp_enet_rx(const struct device *dev)
339
345
{
340
346
#if defined(CONFIG_PTP_CLOCK_NXP_ENET )
341
347
const struct nxp_enet_mac_config * config = dev -> config ;
348
+ struct net_ptp_time ptp_time ;
342
349
#endif
343
350
struct nxp_enet_mac_data * data = dev -> data ;
344
351
uint32_t frame_length = 0U ;
@@ -391,26 +398,20 @@ static int eth_nxp_enet_rx(const struct device *dev)
391
398
#if defined(CONFIG_PTP_CLOCK_NXP_ENET )
392
399
k_mutex_lock (data -> ptp .ptp_mutex , K_FOREVER );
393
400
394
- /* Invalid value by default. */
395
- pkt -> timestamp .nanosecond = UINT32_MAX ;
396
- pkt -> timestamp .second = UINT64_MAX ;
397
-
398
- /* Timestamp the packet using PTP clock */
399
- if (eth_get_ptp_data (get_iface (data ), pkt )) {
400
- struct net_ptp_time ptp_time ;
401
-
402
- ptp_clock_get (config -> ptp_clock , & ptp_time );
403
-
404
- /* If latest timestamp reloads after getting from Rx BD,
405
- * then second - 1 to make sure the actual Rx timestamp is accurate
406
- */
407
- if (ptp_time .nanosecond < ts ) {
408
- ptp_time .second -- ;
409
- }
401
+ /* Timestamp the packet using PTP clock. Add full second part
402
+ * the hardware timestamp contains the fractional part of the second only
403
+ */
404
+ ptp_clock_get (config -> ptp_clock , & ptp_time );
410
405
411
- pkt -> timestamp .nanosecond = ts ;
412
- pkt -> timestamp .second = ptp_time .second ;
406
+ /* If latest timestamp reloads after getting from Rx BD,
407
+ * then second - 1 to make sure the actual Rx timestamp is accurate
408
+ */
409
+ if (ptp_time .nanosecond < ts ) {
410
+ ptp_time .second -- ;
413
411
}
412
+
413
+ pkt -> timestamp .nanosecond = ts ;
414
+ pkt -> timestamp .second = ptp_time .second ;
414
415
k_mutex_unlock (data -> ptp .ptp_mutex );
415
416
#endif /* CONFIG_PTP_CLOCK_NXP_ENET */
416
417
0 commit comments