Lines Matching defs:ptp

47 #include "nic.h" /* indirectly includes ptp.h */
351 static int efx_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta);
352 static int efx_phc_adjtime(struct ptp_clock_info *ptp, s64 delta);
353 static int efx_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts);
354 static int efx_phc_settime(struct ptp_clock_info *ptp,
356 static int efx_phc_enable(struct ptp_clock_info *ptp,
566 struct efx_ptp_data *ptp,
610 kt = ptp->nic_to_kernel_time(nic_major, nic_minor,
619 struct efx_ptp_data *ptp = efx->ptp_data;
623 kt = efx_ptp_mac_nic_to_ktime_correction(efx, ptp,
626 ptp->ts_corrections.general_tx);
628 kt = ptp->nic_to_kernel_time(
631 ptp->ts_corrections.general_tx);
640 struct efx_ptp_data *ptp = efx->ptp_data;
668 ptp->ns_to_nic_time = efx_ptp_ns_to_s27;
669 ptp->nic_to_kernel_time = efx_ptp_s27_to_ktime_correction;
670 ptp->nic_time.minor_max = 1 << 27;
671 ptp->nic_time.sync_event_minor_shift = 19;
674 ptp->ns_to_nic_time = efx_ptp_ns_to_s_ns;
675 ptp->nic_to_kernel_time = efx_ptp_s_ns_to_ktime_correction;
676 ptp->nic_time.minor_max = 1000000000;
677 ptp->nic_time.sync_event_minor_shift = 22;
680 ptp->ns_to_nic_time = efx_ptp_ns_to_s_qns;
681 ptp->nic_to_kernel_time = efx_ptp_s_qns_to_ktime_correction;
682 ptp->nic_time.minor_max = 4000000000UL;
683 ptp->nic_time.sync_event_minor_shift = 24;
695 ptp->nic_time.sync_event_diff_min = ptp->nic_time.minor_max
696 - (ptp->nic_time.minor_max / 10);
697 ptp->nic_time.sync_event_diff_max = (ptp->nic_time.minor_max / 4)
698 + (ptp->nic_time.minor_max / 10);
709 ptp->min_synchronisation_ns =
713 ptp->min_synchronisation_ns = DEFAULT_MIN_SYNCHRONISATION_NS;
717 ptp->capabilities = MCDI_DWORD(outbuf,
720 ptp->capabilities = 0;
726 if (ptp->capabilities & (1 << MC_CMD_PTP_OUT_GET_ATTRIBUTES_FP44_FREQ_ADJ_LBN))
727 ptp->adjfreq_ppb_shift = PPB_SHIFT_FP44;
729 ptp->adjfreq_ppb_shift = PPB_SHIFT_FP40;
868 struct efx_ptp_data *ptp = efx->ptp_data;
869 int *mc_running = ptp->start.addr;
939 struct efx_ptp_data *ptp = efx->ptp_data;
961 &ptp->timeset[i]);
964 ptp->nic_to_kernel_time(0, ptp->timeset[i].wait, 0));
965 window = ptp->timeset[i].window;
978 ++ptp->invalid_sync_windows;
980 ++ptp->oversize_sync_windows;
981 } else if (corrected < ptp->min_synchronisation_ns) {
982 ++ptp->undersize_sync_windows;
1001 start_sec = ptp->timeset[last_good].host_start >> MC_NANOSECOND_BITS;
1012 (ptp->timeset[last_good].host_start & MC_NANOSECOND_MASK);
1018 mc_time = ptp->nic_to_kernel_time(ptp->timeset[last_good].major,
1019 ptp->timeset[last_good].minor, 0);
1025 ptp->host_time_pps = *last_time;
1026 pps_sub_ts(&ptp->host_time_pps, delta);
1034 struct efx_ptp_data *ptp = efx->ptp_data;
1041 int *start = ptp->start.addr;
1048 ptp->start.dma_addr);
1064 ++ptp->fast_syncs;
1066 ++ptp->sync_timeouts;
1080 ++ptp->good_syncs;
1082 ++ptp->no_time_syncs;
1089 ++ptp->bad_syncs;
1183 struct efx_ptp_data *ptp = efx->ptp_data;
1187 if (ptp->rx_ts_inline)
1191 spin_lock_bh(&ptp->evt_lock);
1192 list_for_each_safe(cursor, next, &ptp->evt_list) {
1198 list_move(&evt->link, &ptp->evt_free_list);
1203 spin_unlock_bh(&ptp->evt_lock);
1209 struct efx_ptp_data *ptp = efx->ptp_data;
1216 WARN_ON_ONCE(ptp->rx_ts_inline);
1218 spin_lock_bh(&ptp->evt_lock);
1219 evts_waiting = !list_empty(&ptp->evt_list);
1220 spin_unlock_bh(&ptp->evt_lock);
1227 spin_lock_bh(&ptp->evt_lock);
1228 list_for_each_safe(cursor, next, &ptp->evt_list) {
1242 list_move(&evt->link, &ptp->evt_free_list);
1246 spin_unlock_bh(&ptp->evt_lock);
1257 struct efx_ptp_data *ptp = efx->ptp_data;
1260 while ((skb = skb_dequeue(&ptp->rxq))) {
1271 ++ptp->rx_no_timestamp;
1275 skb_queue_head(&ptp->rxq, skb);
1291 struct efx_ptp_data *ptp = efx->ptp_data;
1293 if (ptp->rxfilter_installed) {
1295 ptp->rxfilter_general);
1297 ptp->rxfilter_event);
1298 ptp->rxfilter_installed = false;
1304 struct efx_ptp_data *ptp = efx->ptp_data;
1308 if (!ptp->channel || ptp->rxfilter_installed)
1316 efx_channel_get_rx_queue(ptp->channel)));
1326 ptp->rxfilter_event = rc;
1330 efx_channel_get_rx_queue(ptp->channel)));
1340 ptp->rxfilter_general = rc;
1342 ptp->rxfilter_installed = true;
1347 ptp->rxfilter_event);
1353 struct efx_ptp_data *ptp = efx->ptp_data;
1356 ptp->reset_required = false;
1366 ptp->evt_frag_idx = 0;
1367 ptp->current_adjfreq = 0;
1378 struct efx_ptp_data *ptp = efx->ptp_data;
1383 if (ptp == NULL)
1413 struct efx_ptp_data *ptp =
1415 struct efx_nic *efx = ptp->efx;
1422 ptp_evt.pps_times = ptp->host_time_pps;
1423 ptp_clock_event(ptp->phc_clock, &ptp_evt);
1471 struct efx_ptp_data *ptp;
1480 ptp = kzalloc(sizeof(struct efx_ptp_data), GFP_KERNEL);
1481 efx->ptp_data = ptp;
1485 ptp->efx = efx;
1486 ptp->channel = channel;
1487 ptp->rx_ts_inline = efx_nic_rev(efx) >= EFX_REV_HUNT_A0;
1489 rc = efx_nic_alloc_buffer(efx, &ptp->start, sizeof(int), GFP_KERNEL);
1493 skb_queue_head_init(&ptp->rxq);
1494 skb_queue_head_init(&ptp->txq);
1495 ptp->workwq = create_singlethread_workqueue("sfc_ptp");
1496 if (!ptp->workwq) {
1502 ptp->xmit_skb = efx_ptp_xmit_skb_queue;
1506 ptp->xmit_skb = efx_ptp_xmit_skb_mc;
1509 INIT_WORK(&ptp->work, efx_ptp_worker);
1510 ptp->config.flags = 0;
1511 ptp->config.tx_type = HWTSTAMP_TX_OFF;
1512 ptp->config.rx_filter = HWTSTAMP_FILTER_NONE;
1513 INIT_LIST_HEAD(&ptp->evt_list);
1514 INIT_LIST_HEAD(&ptp->evt_free_list);
1515 spin_lock_init(&ptp->evt_lock);
1517 list_add(&ptp->rx_evts[pos].link, &ptp->evt_free_list);
1531 ptp->phc_clock_info = efx_phc_clock_info;
1532 ptp->phc_clock = ptp_clock_register(&ptp->phc_clock_info,
1534 if (IS_ERR(ptp->phc_clock)) {
1535 rc = PTR_ERR(ptp->phc_clock);
1537 } else if (ptp->phc_clock) {
1538 INIT_WORK(&ptp->pps_work, efx_ptp_pps_worker);
1539 ptp->pps_workwq = create_singlethread_workqueue("sfc_pps");
1540 if (!ptp->pps_workwq) {
1546 ptp->nic_ts_enabled = false;
1556 efx_nic_free_buffer(efx, &ptp->start);
1568 * overlap with 'rxq0' because ptp.c doesn't use skb_record_rx_queue.
1624 snprintf(buf, len, "%s-ptp", channel->efx->name);
1652 struct efx_ptp_data *ptp = efx->ptp_data;
1661 if (ptp->mode == MC_CMD_PTP_MODE_V1) {
1694 if (ptp->mode == MC_CMD_PTP_MODE_V2) {
1698 BUG_ON(ptp->mode != MC_CMD_PTP_MODE_V2_ENHANCED);
1726 skb_queue_tail(&ptp->rxq, skb);
1727 queue_work(ptp->workwq, &ptp->work);
1738 struct efx_ptp_data *ptp = efx->ptp_data;
1740 skb_queue_tail(&ptp->txq, skb);
1745 queue_work(ptp->workwq, &ptp->work);
1819 struct efx_ptp_data *ptp = efx->ptp_data;
1824 if (!ptp)
1845 ts_info->rx_filters = ptp->efx->type->hwtstamp_filters;
1879 struct efx_ptp_data *ptp = efx->ptp_data;
1883 ptp->evt_frag_idx, expected_frag_len);
1884 ptp->reset_required = true;
1885 queue_work(ptp->workwq, &ptp->work);
1892 static void ptp_event_rx(struct efx_nic *efx, struct efx_ptp_data *ptp)
1896 if (WARN_ON_ONCE(ptp->rx_ts_inline))
1899 if (ptp->evt_frag_idx != 3) {
1904 spin_lock_bh(&ptp->evt_lock);
1905 if (!list_empty(&ptp->evt_free_list)) {
1906 evt = list_first_entry(&ptp->evt_free_list,
1910 evt->seq0 = EFX_QWORD_FIELD(ptp->evt_frags[2], MCDI_EVENT_DATA);
1911 evt->seq1 = (EFX_QWORD_FIELD(ptp->evt_frags[2],
1913 (EFX_QWORD_FIELD(ptp->evt_frags[1],
1915 (EFX_QWORD_FIELD(ptp->evt_frags[0],
1918 EFX_QWORD_FIELD(ptp->evt_frags[0], MCDI_EVENT_DATA),
1919 EFX_QWORD_FIELD(ptp->evt_frags[1], MCDI_EVENT_DATA),
1920 ptp->ts_corrections.ptp_rx);
1922 list_add_tail(&evt->link, &ptp->evt_list);
1924 queue_work(ptp->workwq, &ptp->work);
1929 spin_unlock_bh(&ptp->evt_lock);
1932 static void ptp_event_fault(struct efx_nic *efx, struct efx_ptp_data *ptp)
1934 int code = EFX_QWORD_FIELD(ptp->evt_frags[0], MCDI_EVENT_DATA);
1935 if (ptp->evt_frag_idx != 1) {
1943 static void ptp_event_pps(struct efx_nic *efx, struct efx_ptp_data *ptp)
1945 if (ptp->nic_ts_enabled)
1946 queue_work(ptp->pps_workwq, &ptp->pps_work);
1951 struct efx_ptp_data *ptp = efx->ptp_data;
1954 if (!ptp) {
1963 if (!ptp->enabled)
1966 if (ptp->evt_frag_idx == 0) {
1967 ptp->evt_code = code;
1968 } else if (ptp->evt_code != code) {
1971 ptp->evt_frag_idx = 0;
1974 ptp->evt_frags[ptp->evt_frag_idx++] = *ev;
1979 ptp_event_rx(efx, ptp);
1982 ptp_event_fault(efx, ptp);
1985 ptp_event_pps(efx, ptp);
1992 ptp->evt_frag_idx = 0;
1993 } else if (MAX_EVENT_FRAGS == ptp->evt_frag_idx) {
1996 ptp->evt_frag_idx = 0;
2003 struct efx_ptp_data *ptp = efx->ptp_data;
2014 << ptp->nic_time.sync_event_minor_shift;
2040 struct efx_ptp_data *ptp = efx->ptp_data;
2055 diff += ptp->nic_time.minor_max;
2058 carry = (channel->sync_timestamp_minor >= ptp->nic_time.minor_max - diff) ?
2061 if (diff <= ptp->nic_time.sync_event_diff_max) {
2066 } else if (diff >= ptp->nic_time.sync_event_diff_min) {
2088 ptp->nic_to_kernel_time(pkt_timestamp_major,
2090 ptp->ts_corrections.general_rx);
2093 static int efx_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta)
2095 struct efx_ptp_data *ptp_data = container_of(ptp,
2127 static int efx_phc_adjtime(struct ptp_clock_info *ptp, s64 delta)
2130 struct efx_ptp_data *ptp_data = container_of(ptp,
2147 static int efx_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
2149 struct efx_ptp_data *ptp_data = container_of(ptp,
2173 static int efx_phc_settime(struct ptp_clock_info *ptp,
2184 rc = efx_phc_gettime(ptp, &time_now);
2190 rc = efx_phc_adjtime(ptp, timespec64_to_ns(&delta));
2197 static int efx_phc_enable(struct ptp_clock_info *ptp,
2201 struct efx_ptp_data *ptp_data = container_of(ptp,