Lines Matching full:ptp
21 /* ptp spinlock is used for protecting the cycle/time counter fields
22 * and, also for serializing the qed PTP API invocations.
31 * qede_ptp_adjfreq() - Adjust the frequency of the PTP cycle counter.
33 * @info: The PTP clock info structure.
40 struct qede_ptp *ptp = container_of(info, struct qede_ptp, clock_info); in qede_ptp_adjfreq() local
41 struct qede_dev *edev = ptp->edev; in qede_ptp_adjfreq()
46 spin_lock_bh(&ptp->lock); in qede_ptp_adjfreq()
47 rc = ptp->ops->adjfreq(edev->cdev, ppb); in qede_ptp_adjfreq()
48 spin_unlock_bh(&ptp->lock); in qede_ptp_adjfreq()
50 DP_ERR(edev, "PTP adjfreq called while interface is down\n"); in qede_ptp_adjfreq()
61 struct qede_ptp *ptp; in qede_ptp_adjtime() local
63 ptp = container_of(info, struct qede_ptp, clock_info); in qede_ptp_adjtime()
64 edev = ptp->edev; in qede_ptp_adjtime()
66 DP_VERBOSE(edev, QED_MSG_DEBUG, "PTP adjtime called, delta = %llx\n", in qede_ptp_adjtime()
69 spin_lock_bh(&ptp->lock); in qede_ptp_adjtime()
70 timecounter_adjtime(&ptp->tc, delta); in qede_ptp_adjtime()
71 spin_unlock_bh(&ptp->lock); in qede_ptp_adjtime()
79 struct qede_ptp *ptp; in qede_ptp_gettime() local
82 ptp = container_of(info, struct qede_ptp, clock_info); in qede_ptp_gettime()
83 edev = ptp->edev; in qede_ptp_gettime()
85 spin_lock_bh(&ptp->lock); in qede_ptp_gettime()
86 ns = timecounter_read(&ptp->tc); in qede_ptp_gettime()
87 spin_unlock_bh(&ptp->lock); in qede_ptp_gettime()
89 DP_VERBOSE(edev, QED_MSG_DEBUG, "PTP gettime called, ns = %llu\n", ns); in qede_ptp_gettime()
100 struct qede_ptp *ptp; in qede_ptp_settime() local
103 ptp = container_of(info, struct qede_ptp, clock_info); in qede_ptp_settime()
104 edev = ptp->edev; in qede_ptp_settime()
108 DP_VERBOSE(edev, QED_MSG_DEBUG, "PTP settime called, ns = %llu\n", ns); in qede_ptp_settime()
111 spin_lock_bh(&ptp->lock); in qede_ptp_settime()
112 timecounter_init(&ptp->tc, &ptp->cc, ns); in qede_ptp_settime()
113 spin_unlock_bh(&ptp->lock); in qede_ptp_settime()
124 struct qede_ptp *ptp; in qede_ptp_ancillary_feature_enable() local
126 ptp = container_of(info, struct qede_ptp, clock_info); in qede_ptp_ancillary_feature_enable()
127 edev = ptp->edev; in qede_ptp_ancillary_feature_enable()
138 struct qede_ptp *ptp; in qede_ptp_task() local
143 ptp = container_of(work, struct qede_ptp, work); in qede_ptp_task()
144 edev = ptp->edev; in qede_ptp_task()
145 timedout = time_is_before_jiffies(ptp->ptp_tx_start + in qede_ptp_task()
149 spin_lock_bh(&ptp->lock); in qede_ptp_task()
150 rc = ptp->ops->read_tx_ts(edev->cdev, ×tamp); in qede_ptp_task()
151 spin_unlock_bh(&ptp->lock); in qede_ptp_task()
155 dev_kfree_skb_any(ptp->tx_skb); in qede_ptp_task()
156 ptp->tx_skb = NULL; in qede_ptp_task()
162 schedule_work(&ptp->work); in qede_ptp_task()
167 ns = timecounter_cyc2time(&ptp->tc, timestamp); in qede_ptp_task()
170 skb_tstamp_tx(ptp->tx_skb, &shhwtstamps); in qede_ptp_task()
171 dev_kfree_skb_any(ptp->tx_skb); in qede_ptp_task()
172 ptp->tx_skb = NULL; in qede_ptp_task()
184 struct qede_ptp *ptp; in qede_ptp_read_cc() local
188 ptp = container_of(cc, struct qede_ptp, cc); in qede_ptp_read_cc()
189 edev = ptp->edev; in qede_ptp_read_cc()
190 rc = ptp->ops->read_cc(edev->cdev, &phc_cycles); in qede_ptp_read_cc()
203 struct qede_ptp *ptp = edev->ptp; in qede_ptp_cfg_filters() local
205 if (!ptp) in qede_ptp_cfg_filters()
208 if (!ptp->hw_ts_ioctl_called) { in qede_ptp_cfg_filters()
213 switch (ptp->tx_type) { in qede_ptp_cfg_filters()
230 spin_lock_bh(&ptp->lock); in qede_ptp_cfg_filters()
231 switch (ptp->rx_filter) { in qede_ptp_cfg_filters()
238 ptp->rx_filter = HWTSTAMP_FILTER_NONE; in qede_ptp_cfg_filters()
242 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; in qede_ptp_cfg_filters()
247 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; in qede_ptp_cfg_filters()
248 /* Initialize PTP detection for UDP/IPv4 events */ in qede_ptp_cfg_filters()
252 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT; in qede_ptp_cfg_filters()
257 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT; in qede_ptp_cfg_filters()
258 /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */ in qede_ptp_cfg_filters()
262 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; in qede_ptp_cfg_filters()
267 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; in qede_ptp_cfg_filters()
268 /* Initialize PTP detection L2 events */ in qede_ptp_cfg_filters()
272 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; in qede_ptp_cfg_filters()
277 ptp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; in qede_ptp_cfg_filters()
278 /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */ in qede_ptp_cfg_filters()
283 ptp->ops->cfg_filters(edev->cdev, rx_filter, tx_type); in qede_ptp_cfg_filters()
285 spin_unlock_bh(&ptp->lock); in qede_ptp_cfg_filters()
293 struct qede_ptp *ptp; in qede_ptp_hw_ts() local
296 ptp = edev->ptp; in qede_ptp_hw_ts()
297 if (!ptp) in qede_ptp_hw_ts()
312 ptp->hw_ts_ioctl_called = 1; in qede_ptp_hw_ts()
313 ptp->tx_type = config.tx_type; in qede_ptp_hw_ts()
314 ptp->rx_filter = config.rx_filter; in qede_ptp_hw_ts()
320 config.rx_filter = ptp->rx_filter; in qede_ptp_hw_ts()
328 struct qede_ptp *ptp = edev->ptp; in qede_ptp_get_ts_info() local
330 if (!ptp) { in qede_ptp_get_ts_info()
346 if (ptp->clock) in qede_ptp_get_ts_info()
347 info->phc_index = ptp_clock_index(ptp->clock); in qede_ptp_get_ts_info()
372 struct qede_ptp *ptp; in qede_ptp_disable() local
374 ptp = edev->ptp; in qede_ptp_disable()
375 if (!ptp) in qede_ptp_disable()
378 if (ptp->clock) { in qede_ptp_disable()
379 ptp_clock_unregister(ptp->clock); in qede_ptp_disable()
380 ptp->clock = NULL; in qede_ptp_disable()
383 /* Cancel PTP work queue. Should be done after the Tx queues are in qede_ptp_disable()
386 cancel_work_sync(&ptp->work); in qede_ptp_disable()
387 if (ptp->tx_skb) { in qede_ptp_disable()
388 dev_kfree_skb_any(ptp->tx_skb); in qede_ptp_disable()
389 ptp->tx_skb = NULL; in qede_ptp_disable()
393 /* Disable PTP in HW */ in qede_ptp_disable()
394 spin_lock_bh(&ptp->lock); in qede_ptp_disable()
395 ptp->ops->disable(edev->cdev); in qede_ptp_disable()
396 spin_unlock_bh(&ptp->lock); in qede_ptp_disable()
398 kfree(ptp); in qede_ptp_disable()
399 edev->ptp = NULL; in qede_ptp_disable()
404 struct qede_ptp *ptp; in qede_ptp_init() local
407 ptp = edev->ptp; in qede_ptp_init()
408 if (!ptp) in qede_ptp_init()
411 spin_lock_init(&ptp->lock); in qede_ptp_init()
413 /* Configure PTP in HW */ in qede_ptp_init()
414 rc = ptp->ops->enable(edev->cdev); in qede_ptp_init()
416 DP_INFO(edev, "PTP HW enable failed\n"); in qede_ptp_init()
421 INIT_WORK(&ptp->work, qede_ptp_task); in qede_ptp_init()
424 memset(&ptp->cc, 0, sizeof(ptp->cc)); in qede_ptp_init()
425 ptp->cc.read = qede_ptp_read_cc; in qede_ptp_init()
426 ptp->cc.mask = CYCLECOUNTER_MASK(64); in qede_ptp_init()
427 ptp->cc.shift = 0; in qede_ptp_init()
428 ptp->cc.mult = 1; in qede_ptp_init()
430 timecounter_init(&ptp->tc, &ptp->cc, ktime_to_ns(ktime_get_real())); in qede_ptp_init()
437 struct qede_ptp *ptp; in qede_ptp_enable() local
440 ptp = kzalloc(sizeof(*ptp), GFP_KERNEL); in qede_ptp_enable()
441 if (!ptp) { in qede_ptp_enable()
442 DP_INFO(edev, "Failed to allocate struct for PTP\n"); in qede_ptp_enable()
446 ptp->edev = edev; in qede_ptp_enable()
447 ptp->ops = edev->ops->ptp; in qede_ptp_enable()
448 if (!ptp->ops) { in qede_ptp_enable()
449 DP_INFO(edev, "PTP enable failed\n"); in qede_ptp_enable()
454 edev->ptp = ptp; in qede_ptp_enable()
462 /* Fill the ptp_clock_info struct and register PTP clock */ in qede_ptp_enable()
463 ptp->clock_info.owner = THIS_MODULE; in qede_ptp_enable()
464 snprintf(ptp->clock_info.name, 16, "%s", edev->ndev->name); in qede_ptp_enable()
465 ptp->clock_info.max_adj = QED_MAX_PHC_DRIFT_PPB; in qede_ptp_enable()
466 ptp->clock_info.n_alarm = 0; in qede_ptp_enable()
467 ptp->clock_info.n_ext_ts = 0; in qede_ptp_enable()
468 ptp->clock_info.n_per_out = 0; in qede_ptp_enable()
469 ptp->clock_info.pps = 0; in qede_ptp_enable()
470 ptp->clock_info.adjfreq = qede_ptp_adjfreq; in qede_ptp_enable()
471 ptp->clock_info.adjtime = qede_ptp_adjtime; in qede_ptp_enable()
472 ptp->clock_info.gettime64 = qede_ptp_gettime; in qede_ptp_enable()
473 ptp->clock_info.settime64 = qede_ptp_settime; in qede_ptp_enable()
474 ptp->clock_info.enable = qede_ptp_ancillary_feature_enable; in qede_ptp_enable()
476 ptp->clock = ptp_clock_register(&ptp->clock_info, &edev->pdev->dev); in qede_ptp_enable()
477 if (IS_ERR(ptp->clock)) { in qede_ptp_enable()
478 DP_ERR(edev, "PTP clock registration failed\n"); in qede_ptp_enable()
487 kfree(ptp); in qede_ptp_enable()
489 edev->ptp = NULL; in qede_ptp_enable()
496 struct qede_ptp *ptp; in qede_ptp_tx_ts() local
498 ptp = edev->ptp; in qede_ptp_tx_ts()
499 if (!ptp) in qede_ptp_tx_ts()
514 } else if (unlikely(ptp->tx_skb)) { in qede_ptp_tx_ts()
522 ptp->tx_skb = skb_get(skb); in qede_ptp_tx_ts()
523 ptp->ptp_tx_start = jiffies; in qede_ptp_tx_ts()
524 schedule_work(&ptp->work); in qede_ptp_tx_ts()
530 struct qede_ptp *ptp; in qede_ptp_rx_ts() local
534 ptp = edev->ptp; in qede_ptp_rx_ts()
535 if (!ptp) in qede_ptp_rx_ts()
538 spin_lock_bh(&ptp->lock); in qede_ptp_rx_ts()
539 rc = ptp->ops->read_rx_ts(edev->cdev, ×tamp); in qede_ptp_rx_ts()
541 spin_unlock_bh(&ptp->lock); in qede_ptp_rx_ts()
546 ns = timecounter_cyc2time(&ptp->tc, timestamp); in qede_ptp_rx_ts()
547 spin_unlock_bh(&ptp->lock); in qede_ptp_rx_ts()