Lines Matching refs:ptp
47 #include "nic.h" /* indirectly includes ptp.h */
350 static int efx_phc_adjfine(struct ptp_clock_info *ptp, long scaled_ppm);
351 static int efx_phc_adjtime(struct ptp_clock_info *ptp, s64 delta);
352 static int efx_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts);
353 static int efx_phc_settime(struct ptp_clock_info *ptp,
355 static int efx_phc_enable(struct ptp_clock_info *ptp,
559 struct efx_ptp_data *ptp,
603 kt = ptp->nic_to_kernel_time(nic_major, nic_minor,
612 struct efx_ptp_data *ptp = efx->ptp_data;
616 kt = efx_ptp_mac_nic_to_ktime_correction(efx, ptp,
619 ptp->ts_corrections.general_tx);
621 kt = ptp->nic_to_kernel_time(
624 ptp->ts_corrections.general_tx);
633 struct efx_ptp_data *ptp = efx->ptp_data;
661 ptp->ns_to_nic_time = efx_ptp_ns_to_s27;
662 ptp->nic_to_kernel_time = efx_ptp_s27_to_ktime_correction;
663 ptp->nic_time.minor_max = 1 << 27;
664 ptp->nic_time.sync_event_minor_shift = 19;
667 ptp->ns_to_nic_time = efx_ptp_ns_to_s_ns;
668 ptp->nic_to_kernel_time = efx_ptp_s_ns_to_ktime_correction;
669 ptp->nic_time.minor_max = 1000000000;
670 ptp->nic_time.sync_event_minor_shift = 22;
673 ptp->ns_to_nic_time = efx_ptp_ns_to_s_qns;
674 ptp->nic_to_kernel_time = efx_ptp_s_qns_to_ktime_correction;
675 ptp->nic_time.minor_max = 4000000000UL;
676 ptp->nic_time.sync_event_minor_shift = 24;
688 ptp->nic_time.sync_event_diff_min = ptp->nic_time.minor_max
689 - (ptp->nic_time.minor_max / 10);
690 ptp->nic_time.sync_event_diff_max = (ptp->nic_time.minor_max / 4)
691 + (ptp->nic_time.minor_max / 10);
702 ptp->min_synchronisation_ns =
706 ptp->min_synchronisation_ns = DEFAULT_MIN_SYNCHRONISATION_NS;
710 ptp->capabilities = MCDI_DWORD(outbuf,
713 ptp->capabilities = 0;
719 if (ptp->capabilities & (1 << MC_CMD_PTP_OUT_GET_ATTRIBUTES_FP44_FREQ_ADJ_LBN))
720 ptp->adjfreq_ppb_shift = PPB_SHIFT_FP44;
722 ptp->adjfreq_ppb_shift = PPB_SHIFT_FP40;
861 struct efx_ptp_data *ptp = efx->ptp_data;
862 int *mc_running = ptp->start.addr;
932 struct efx_ptp_data *ptp = efx->ptp_data;
954 &ptp->timeset[i]);
957 ptp->nic_to_kernel_time(0, ptp->timeset[i].wait, 0));
958 window = ptp->timeset[i].window;
971 ++ptp->invalid_sync_windows;
973 ++ptp->oversize_sync_windows;
974 } else if (corrected < ptp->min_synchronisation_ns) {
975 ++ptp->undersize_sync_windows;
994 start_sec = ptp->timeset[last_good].host_start >> MC_NANOSECOND_BITS;
1005 (ptp->timeset[last_good].host_start & MC_NANOSECOND_MASK);
1011 mc_time = ptp->nic_to_kernel_time(ptp->timeset[last_good].major,
1012 ptp->timeset[last_good].minor, 0);
1018 ptp->host_time_pps = *last_time;
1019 pps_sub_ts(&ptp->host_time_pps, delta);
1027 struct efx_ptp_data *ptp = efx->ptp_data;
1034 int *start = ptp->start.addr;
1041 ptp->start.dma_addr);
1057 ++ptp->fast_syncs;
1059 ++ptp->sync_timeouts;
1073 ++ptp->good_syncs;
1075 ++ptp->no_time_syncs;
1082 ++ptp->bad_syncs;
1154 struct efx_ptp_data *ptp = efx->ptp_data;
1158 if (ptp->rx_ts_inline)
1162 spin_lock_bh(&ptp->evt_lock);
1163 list_for_each_safe(cursor, next, &ptp->evt_list) {
1169 list_move(&evt->link, &ptp->evt_free_list);
1174 spin_unlock_bh(&ptp->evt_lock);
1180 struct efx_ptp_data *ptp = efx->ptp_data;
1187 WARN_ON_ONCE(ptp->rx_ts_inline);
1189 spin_lock_bh(&ptp->evt_lock);
1190 evts_waiting = !list_empty(&ptp->evt_list);
1191 spin_unlock_bh(&ptp->evt_lock);
1198 spin_lock_bh(&ptp->evt_lock);
1199 list_for_each_safe(cursor, next, &ptp->evt_list) {
1213 list_move(&evt->link, &ptp->evt_free_list);
1217 spin_unlock_bh(&ptp->evt_lock);
1228 struct efx_ptp_data *ptp = efx->ptp_data;
1231 while ((skb = skb_dequeue(&ptp->rxq))) {
1242 ++ptp->rx_no_timestamp;
1246 skb_queue_head(&ptp->rxq, skb);
1262 struct efx_ptp_data *ptp = efx->ptp_data;
1264 if (ptp->rxfilter_installed) {
1266 ptp->rxfilter_general);
1268 ptp->rxfilter_event);
1269 ptp->rxfilter_installed = false;
1275 struct efx_ptp_data *ptp = efx->ptp_data;
1279 if (!ptp->channel || ptp->rxfilter_installed)
1287 efx_channel_get_rx_queue(ptp->channel)));
1297 ptp->rxfilter_event = rc;
1301 efx_channel_get_rx_queue(ptp->channel)));
1311 ptp->rxfilter_general = rc;
1313 ptp->rxfilter_installed = true;
1318 ptp->rxfilter_event);
1324 struct efx_ptp_data *ptp = efx->ptp_data;
1327 ptp->reset_required = false;
1337 ptp->evt_frag_idx = 0;
1338 ptp->current_adjfreq = 0;
1349 struct efx_ptp_data *ptp = efx->ptp_data;
1354 if (ptp == NULL)
1384 struct efx_ptp_data *ptp =
1386 struct efx_nic *efx = ptp->efx;
1393 ptp_evt.pps_times = ptp->host_time_pps;
1394 ptp_clock_event(ptp->phc_clock, &ptp_evt);
1442 struct efx_ptp_data *ptp;
1446 ptp = kzalloc(sizeof(struct efx_ptp_data), GFP_KERNEL);
1447 efx->ptp_data = ptp;
1451 ptp->efx = efx;
1452 ptp->channel = channel;
1453 ptp->rx_ts_inline = efx_nic_rev(efx) >= EFX_REV_HUNT_A0;
1455 rc = efx_siena_alloc_buffer(efx, &ptp->start, sizeof(int), GFP_KERNEL);
1459 skb_queue_head_init(&ptp->rxq);
1460 skb_queue_head_init(&ptp->txq);
1461 ptp->workwq = create_singlethread_workqueue("sfc_siena_ptp");
1462 if (!ptp->workwq) {
1468 ptp->xmit_skb = efx_ptp_xmit_skb_queue;
1472 ptp->xmit_skb = efx_ptp_xmit_skb_mc;
1475 INIT_WORK(&ptp->work, efx_ptp_worker);
1476 ptp->config.flags = 0;
1477 ptp->config.tx_type = HWTSTAMP_TX_OFF;
1478 ptp->config.rx_filter = HWTSTAMP_FILTER_NONE;
1479 INIT_LIST_HEAD(&ptp->evt_list);
1480 INIT_LIST_HEAD(&ptp->evt_free_list);
1481 spin_lock_init(&ptp->evt_lock);
1483 list_add(&ptp->rx_evts[pos].link, &ptp->evt_free_list);
1497 ptp->phc_clock_info = efx_phc_clock_info;
1498 ptp->phc_clock = ptp_clock_register(&ptp->phc_clock_info,
1500 if (IS_ERR(ptp->phc_clock)) {
1501 rc = PTR_ERR(ptp->phc_clock);
1503 } else if (ptp->phc_clock) {
1504 INIT_WORK(&ptp->pps_work, efx_ptp_pps_worker);
1505 ptp->pps_workwq =
1507 if (!ptp->pps_workwq) {
1513 ptp->nic_ts_enabled = false;
1523 efx_siena_free_buffer(efx, &ptp->start);
1535 * overlap with 'rxq0' because ptp.c doesn't use skb_record_rx_queue.
1591 snprintf(buf, len, "%s-ptp", channel->efx->name);
1619 struct efx_ptp_data *ptp = efx->ptp_data;
1628 if (ptp->mode == MC_CMD_PTP_MODE_V1) {
1661 if (ptp->mode == MC_CMD_PTP_MODE_V2) {
1665 BUG_ON(ptp->mode != MC_CMD_PTP_MODE_V2_ENHANCED);
1693 skb_queue_tail(&ptp->rxq, skb);
1694 queue_work(ptp->workwq, &ptp->work);
1705 struct efx_ptp_data *ptp = efx->ptp_data;
1707 skb_queue_tail(&ptp->txq, skb);
1712 queue_work(ptp->workwq, &ptp->work);
1784 struct efx_ptp_data *ptp = efx->ptp_data;
1789 if (!ptp)
1799 ts_info->rx_filters = ptp->efx->type->hwtstamp_filters;
1833 struct efx_ptp_data *ptp = efx->ptp_data;
1837 ptp->evt_frag_idx, expected_frag_len);
1838 ptp->reset_required = true;
1839 queue_work(ptp->workwq, &ptp->work);
1846 static void ptp_event_rx(struct efx_nic *efx, struct efx_ptp_data *ptp)
1850 if (WARN_ON_ONCE(ptp->rx_ts_inline))
1853 if (ptp->evt_frag_idx != 3) {
1858 spin_lock_bh(&ptp->evt_lock);
1859 if (!list_empty(&ptp->evt_free_list)) {
1860 evt = list_first_entry(&ptp->evt_free_list,
1864 evt->seq0 = EFX_QWORD_FIELD(ptp->evt_frags[2], MCDI_EVENT_DATA);
1865 evt->seq1 = (EFX_QWORD_FIELD(ptp->evt_frags[2],
1867 (EFX_QWORD_FIELD(ptp->evt_frags[1],
1869 (EFX_QWORD_FIELD(ptp->evt_frags[0],
1872 EFX_QWORD_FIELD(ptp->evt_frags[0], MCDI_EVENT_DATA),
1873 EFX_QWORD_FIELD(ptp->evt_frags[1], MCDI_EVENT_DATA),
1874 ptp->ts_corrections.ptp_rx);
1876 list_add_tail(&evt->link, &ptp->evt_list);
1878 queue_work(ptp->workwq, &ptp->work);
1883 spin_unlock_bh(&ptp->evt_lock);
1886 static void ptp_event_fault(struct efx_nic *efx, struct efx_ptp_data *ptp)
1888 int code = EFX_QWORD_FIELD(ptp->evt_frags[0], MCDI_EVENT_DATA);
1889 if (ptp->evt_frag_idx != 1) {
1897 static void ptp_event_pps(struct efx_nic *efx, struct efx_ptp_data *ptp)
1899 if (ptp->nic_ts_enabled)
1900 queue_work(ptp->pps_workwq, &ptp->pps_work);
1905 struct efx_ptp_data *ptp = efx->ptp_data;
1908 if (!ptp) {
1917 if (!ptp->enabled)
1920 if (ptp->evt_frag_idx == 0) {
1921 ptp->evt_code = code;
1922 } else if (ptp->evt_code != code) {
1925 ptp->evt_frag_idx = 0;
1928 ptp->evt_frags[ptp->evt_frag_idx++] = *ev;
1933 ptp_event_rx(efx, ptp);
1936 ptp_event_fault(efx, ptp);
1939 ptp_event_pps(efx, ptp);
1946 ptp->evt_frag_idx = 0;
1947 } else if (MAX_EVENT_FRAGS == ptp->evt_frag_idx) {
1950 ptp->evt_frag_idx = 0;
1957 struct efx_ptp_data *ptp = efx->ptp_data;
1968 << ptp->nic_time.sync_event_minor_shift;
1994 struct efx_ptp_data *ptp = efx->ptp_data;
2009 diff += ptp->nic_time.minor_max;
2012 carry = (channel->sync_timestamp_minor >= ptp->nic_time.minor_max - diff) ?
2015 if (diff <= ptp->nic_time.sync_event_diff_max) {
2020 } else if (diff >= ptp->nic_time.sync_event_diff_min) {
2042 ptp->nic_to_kernel_time(pkt_timestamp_major,
2044 ptp->ts_corrections.general_rx);
2047 static int efx_phc_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
2049 struct efx_ptp_data *ptp_data = container_of(ptp,
2082 static int efx_phc_adjtime(struct ptp_clock_info *ptp, s64 delta)
2085 struct efx_ptp_data *ptp_data = container_of(ptp,
2102 static int efx_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
2104 struct efx_ptp_data *ptp_data = container_of(ptp,
2128 static int efx_phc_settime(struct ptp_clock_info *ptp,
2139 rc = efx_phc_gettime(ptp, &time_now);
2145 rc = efx_phc_adjtime(ptp, timespec64_to_ns(&delta));
2152 static int efx_phc_enable(struct ptp_clock_info *ptp,
2156 struct efx_ptp_data *ptp_data = container_of(ptp,