Lines Matching refs:ptp

10 	struct hclge_ptp *ptp = hdev->ptp;  in hclge_ptp_get_cycle()  local
12 ptp->cycle.quo = readl(hdev->ptp->io_base + HCLGE_PTP_CYCLE_QUO_REG) & in hclge_ptp_get_cycle()
14 ptp->cycle.numer = readl(hdev->ptp->io_base + HCLGE_PTP_CYCLE_NUM_REG); in hclge_ptp_get_cycle()
15 ptp->cycle.den = readl(hdev->ptp->io_base + HCLGE_PTP_CYCLE_DEN_REG); in hclge_ptp_get_cycle()
17 if (ptp->cycle.den == 0) { in hclge_ptp_get_cycle()
25 static int hclge_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) in hclge_ptp_adjfreq() argument
27 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_adjfreq()
28 struct hclge_ptp_cycle *cycle = &hdev->ptp->cycle; in hclge_ptp_adjfreq()
55 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_adjfreq()
57 hdev->ptp->io_base + HCLGE_PTP_CYCLE_QUO_REG); in hclge_ptp_adjfreq()
58 writel(numerator, hdev->ptp->io_base + HCLGE_PTP_CYCLE_NUM_REG); in hclge_ptp_adjfreq()
59 writel(cycle->den, hdev->ptp->io_base + HCLGE_PTP_CYCLE_DEN_REG); in hclge_ptp_adjfreq()
61 hdev->ptp->io_base + HCLGE_PTP_CYCLE_CFG_REG); in hclge_ptp_adjfreq()
62 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_adjfreq()
71 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_set_tx_info() local
73 if (!test_bit(HCLGE_PTP_FLAG_TX_EN, &ptp->flags) || in hclge_ptp_set_tx_info()
75 ptp->tx_skipped++; in hclge_ptp_set_tx_info()
79 ptp->tx_start = jiffies; in hclge_ptp_set_tx_info()
80 ptp->tx_skb = skb_get(skb); in hclge_ptp_set_tx_info()
81 ptp->tx_cnt++; in hclge_ptp_set_tx_info()
88 struct sk_buff *skb = hdev->ptp->tx_skb; in hclge_ptp_clean_tx_hwts()
93 ns = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_NSEC_REG) & in hclge_ptp_clean_tx_hwts()
95 lo = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_SEC_L_REG); in hclge_ptp_clean_tx_hwts()
96 hi = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_SEC_H_REG) & in hclge_ptp_clean_tx_hwts()
98 hdev->ptp->last_tx_seqid = readl(hdev->ptp->io_base + in hclge_ptp_clean_tx_hwts()
102 hdev->ptp->tx_skb = NULL; in hclge_ptp_clean_tx_hwts()
103 hdev->ptp->tx_cleaned++; in hclge_ptp_clean_tx_hwts()
123 if (!test_bit(HCLGE_PTP_FLAG_RX_EN, &hdev->ptp->flags)) in hclge_ptp_get_rx_hwts()
130 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_get_rx_hwts()
131 sec_h = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_H_REG); in hclge_ptp_get_rx_hwts()
132 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_get_rx_hwts()
136 hdev->ptp->last_rx = jiffies; in hclge_ptp_get_rx_hwts()
137 hdev->ptp->rx_cnt++; in hclge_ptp_get_rx_hwts()
140 static int hclge_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts, in hclge_ptp_gettimex() argument
143 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_gettimex()
148 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_gettimex()
149 ns = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_NSEC_REG); in hclge_ptp_gettimex()
150 hi = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_H_REG); in hclge_ptp_gettimex()
151 lo = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_L_REG); in hclge_ptp_gettimex()
152 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_gettimex()
160 static int hclge_ptp_settime(struct ptp_clock_info *ptp, in hclge_ptp_settime() argument
163 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_settime()
166 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_settime()
167 writel(ts->tv_nsec, hdev->ptp->io_base + HCLGE_PTP_TIME_NSEC_REG); in hclge_ptp_settime()
169 hdev->ptp->io_base + HCLGE_PTP_TIME_SEC_H_REG); in hclge_ptp_settime()
171 hdev->ptp->io_base + HCLGE_PTP_TIME_SEC_L_REG); in hclge_ptp_settime()
174 hdev->ptp->io_base + HCLGE_PTP_TIME_SYNC_REG); in hclge_ptp_settime()
175 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_settime()
180 static int hclge_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) in hclge_ptp_adjtime() argument
182 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_adjtime()
197 hclge_ptp_gettimex(ptp, &ts, NULL); in hclge_ptp_adjtime()
201 return hclge_ptp_settime(ptp, &ts); in hclge_ptp_adjtime()
206 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_adjtime()
207 writel(adj_val, hdev->ptp->io_base + HCLGE_PTP_TIME_NSEC_REG); in hclge_ptp_adjtime()
209 hdev->ptp->io_base + HCLGE_PTP_TIME_ADJ_REG); in hclge_ptp_adjtime()
210 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_adjtime()
220 return copy_to_user(ifr->ifr_data, &hdev->ptp->ts_cfg, in hclge_ptp_get_cfg()
345 unsigned long flags = hdev->ptp->flags; in hclge_ptp_set_ts_mode()
349 if (test_bit(HCLGE_PTP_FLAG_EN, &hdev->ptp->flags)) in hclge_ptp_set_ts_mode()
364 hdev->ptp->flags = flags; in hclge_ptp_set_ts_mode()
365 hdev->ptp->ptp_cfg = ptp_cfg; in hclge_ptp_set_ts_mode()
387 hdev->ptp->ts_cfg = cfg; in hclge_ptp_set_cfg()
410 if (hdev->ptp->clock) in hclge_ptp_get_ts_info()
411 info->phc_index = ptp_clock_index(hdev->ptp->clock); in hclge_ptp_get_ts_info()
436 struct hclge_ptp *ptp; in hclge_ptp_create_clock() local
438 ptp = devm_kzalloc(&hdev->pdev->dev, sizeof(*ptp), GFP_KERNEL); in hclge_ptp_create_clock()
439 if (!ptp) in hclge_ptp_create_clock()
442 ptp->hdev = hdev; in hclge_ptp_create_clock()
443 snprintf(ptp->info.name, sizeof(ptp->info.name), "%s", in hclge_ptp_create_clock()
445 ptp->info.owner = THIS_MODULE; in hclge_ptp_create_clock()
446 ptp->info.max_adj = HCLGE_PTP_CYCLE_ADJ_MAX; in hclge_ptp_create_clock()
447 ptp->info.n_ext_ts = 0; in hclge_ptp_create_clock()
448 ptp->info.pps = 0; in hclge_ptp_create_clock()
449 ptp->info.adjfreq = hclge_ptp_adjfreq; in hclge_ptp_create_clock()
450 ptp->info.adjtime = hclge_ptp_adjtime; in hclge_ptp_create_clock()
451 ptp->info.gettimex64 = hclge_ptp_gettimex; in hclge_ptp_create_clock()
452 ptp->info.settime64 = hclge_ptp_settime; in hclge_ptp_create_clock()
454 ptp->info.n_alarm = 0; in hclge_ptp_create_clock()
455 ptp->clock = ptp_clock_register(&ptp->info, &hdev->pdev->dev); in hclge_ptp_create_clock()
456 if (IS_ERR(ptp->clock)) { in hclge_ptp_create_clock()
459 ptp->info.n_alarm, PTR_ERR(ptp->clock)); in hclge_ptp_create_clock()
461 } else if (!ptp->clock) { in hclge_ptp_create_clock()
466 spin_lock_init(&ptp->lock); in hclge_ptp_create_clock()
467 ptp->io_base = hdev->hw.hw.io_base + HCLGE_PTP_REG_OFFSET; in hclge_ptp_create_clock()
468 ptp->ts_cfg.rx_filter = HWTSTAMP_FILTER_NONE; in hclge_ptp_create_clock()
469 ptp->ts_cfg.tx_type = HWTSTAMP_TX_OFF; in hclge_ptp_create_clock()
470 hdev->ptp = ptp; in hclge_ptp_create_clock()
477 ptp_clock_unregister(hdev->ptp->clock); in hclge_ptp_destroy_clock()
478 hdev->ptp->clock = NULL; in hclge_ptp_destroy_clock()
479 devm_kfree(&hdev->pdev->dev, hdev->ptp); in hclge_ptp_destroy_clock()
480 hdev->ptp = NULL; in hclge_ptp_destroy_clock()
492 if (!hdev->ptp) { in hclge_ptp_init()
506 set_bit(HCLGE_PTP_FLAG_EN, &hdev->ptp->flags); in hclge_ptp_init()
507 ret = hclge_ptp_adjfreq(&hdev->ptp->info, 0); in hclge_ptp_init()
514 ret = hclge_ptp_set_ts_mode(hdev, &hdev->ptp->ts_cfg); in hclge_ptp_init()
522 ret = hclge_ptp_settime(&hdev->ptp->info, &ts); in hclge_ptp_init()
542 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_uninit() local
544 if (!ptp) in hclge_ptp_uninit()
549 clear_bit(HCLGE_PTP_FLAG_EN, &ptp->flags); in hclge_ptp_uninit()
550 ptp->ts_cfg.rx_filter = HWTSTAMP_FILTER_NONE; in hclge_ptp_uninit()
551 ptp->ts_cfg.tx_type = HWTSTAMP_TX_OFF; in hclge_ptp_uninit()
553 if (hclge_ptp_set_ts_mode(hdev, &ptp->ts_cfg)) in hclge_ptp_uninit()
556 if (ptp->tx_skb) { in hclge_ptp_uninit()
557 struct sk_buff *skb = ptp->tx_skb; in hclge_ptp_uninit()
559 ptp->tx_skb = NULL; in hclge_ptp_uninit()