aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Habets <mhabets@solarflare.com>2018-01-25 12:25:50 -0500
committerDavid S. Miller <davem@davemloft.net>2018-01-25 16:05:14 -0500
commitc1d0d33946725775be1c68515c07d0ff8237d222 (patch)
treed9b46639951eefe13a76f9f3c85e94037d3b0fc8
parent50663fe1808fcd08cc60c3adfa3692b27a51161d (diff)
sfc: MAC TX timestamp handling on the 8000 series
TX timestamps on 8000 series are supplied from the MAC. This timestamp is only 48 bits long. The high order bits from the last time sync event are used for the top 16 bits. Signed-off-by: Martin Habets <mhabets@solarflare.com> Signed-off-by: Edward Cree <ecree@solarflare.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/sfc/nic.h1
-rw-r--r--drivers/net/ethernet/sfc/ptp.c47
2 files changed, 46 insertions, 2 deletions
diff --git a/drivers/net/ethernet/sfc/nic.h b/drivers/net/ethernet/sfc/nic.h
index ac54b50f57a5..6549fc685a48 100644
--- a/drivers/net/ethernet/sfc/nic.h
+++ b/drivers/net/ethernet/sfc/nic.h
@@ -449,6 +449,7 @@ void efx_fini_sriov(void);
449struct ethtool_ts_info; 449struct ethtool_ts_info;
450int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel); 450int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel);
451void efx_ptp_defer_probe_with_channel(struct efx_nic *efx); 451void efx_ptp_defer_probe_with_channel(struct efx_nic *efx);
452struct efx_channel *efx_ptp_channel(struct efx_nic *efx);
452void efx_ptp_remove(struct efx_nic *efx); 453void efx_ptp_remove(struct efx_nic *efx);
453int efx_ptp_set_ts_config(struct efx_nic *efx, struct ifreq *ifr); 454int efx_ptp_set_ts_config(struct efx_nic *efx, struct ifreq *ifr);
454int efx_ptp_get_ts_config(struct efx_nic *efx, struct ifreq *ifr); 455int efx_ptp_get_ts_config(struct efx_nic *efx, struct ifreq *ifr);
diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
index 7f877312c646..0d0160f15c35 100644
--- a/drivers/net/ethernet/sfc/ptp.c
+++ b/drivers/net/ethernet/sfc/ptp.c
@@ -483,14 +483,57 @@ static ktime_t efx_ptp_s27_to_ktime_correction(u32 nic_major, u32 nic_minor,
483 return efx_ptp_s27_to_ktime(nic_major, nic_minor); 483 return efx_ptp_s27_to_ktime(nic_major, nic_minor);
484} 484}
485 485
486struct efx_channel *efx_ptp_channel(struct efx_nic *efx)
487{
488 return efx->ptp_data ? efx->ptp_data->channel : NULL;
489}
490
491static u32 last_sync_timestamp_major(struct efx_nic *efx)
492{
493 struct efx_channel *channel = efx_ptp_channel(efx);
494 u32 major = 0;
495
496 if (channel)
497 major = channel->sync_timestamp_major;
498 return major;
499}
500
501/* The 8000 series and later can provide the time from the MAC, which is only
502 * 48 bits long and provides meta-information in the top 2 bits.
503 */
504static ktime_t
505efx_ptp_mac_s27_to_ktime_correction(struct efx_nic *efx,
506 u32 nic_major, u32 nic_minor,
507 s32 correction)
508{
509 ktime_t kt = { 0 };
510
511 if (!(nic_major & 0x80000000)) {
512 WARN_ON_ONCE(nic_major >> 16);
513 /* Use the top bits from the latest sync event. */
514 nic_major &= 0xffff;
515 nic_major |= (last_sync_timestamp_major(efx) & 0xffff0000);
516
517 kt = efx_ptp_s27_to_ktime_correction(nic_major, nic_minor,
518 correction);
519 }
520 return kt;
521}
522
486ktime_t efx_ptp_nic_to_kernel_time(struct efx_tx_queue *tx_queue) 523ktime_t efx_ptp_nic_to_kernel_time(struct efx_tx_queue *tx_queue)
487{ 524{
488 struct efx_nic *efx = tx_queue->efx; 525 struct efx_nic *efx = tx_queue->efx;
489 struct efx_ptp_data *ptp = efx->ptp_data; 526 struct efx_ptp_data *ptp = efx->ptp_data;
490 ktime_t kt; 527 ktime_t kt;
491 528
492 kt = ptp->nic_to_kernel_time(tx_queue->completed_timestamp_major, 529 if (efx_ptp_use_mac_tx_timestamps(efx))
493 tx_queue->completed_timestamp_minor, 0); 530 kt = efx_ptp_mac_s27_to_ktime_correction(efx,
531 tx_queue->completed_timestamp_major,
532 tx_queue->completed_timestamp_minor, 0);
533 else
534 kt = ptp->nic_to_kernel_time(
535 tx_queue->completed_timestamp_major,
536 tx_queue->completed_timestamp_minor, 0);
494 return kt; 537 return kt;
495} 538}
496 539