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_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) in hclge_ptp_adjfine() argument
27 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_adjfine()
28 struct hclge_ptp_cycle *cycle = &hdev->ptp->cycle; in hclge_ptp_adjfine()
43 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_adjfine()
45 hdev->ptp->io_base + HCLGE_PTP_CYCLE_QUO_REG); in hclge_ptp_adjfine()
46 writel(numerator, hdev->ptp->io_base + HCLGE_PTP_CYCLE_NUM_REG); in hclge_ptp_adjfine()
47 writel(cycle->den, hdev->ptp->io_base + HCLGE_PTP_CYCLE_DEN_REG); in hclge_ptp_adjfine()
49 hdev->ptp->io_base + HCLGE_PTP_CYCLE_CFG_REG); in hclge_ptp_adjfine()
50 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_adjfine()
59 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_set_tx_info() local
61 if (!test_bit(HCLGE_PTP_FLAG_TX_EN, &ptp->flags) || in hclge_ptp_set_tx_info()
63 ptp->tx_skipped++; in hclge_ptp_set_tx_info()
67 ptp->tx_start = jiffies; in hclge_ptp_set_tx_info()
68 ptp->tx_skb = skb_get(skb); in hclge_ptp_set_tx_info()
69 ptp->tx_cnt++; in hclge_ptp_set_tx_info()
76 struct sk_buff *skb = hdev->ptp->tx_skb; in hclge_ptp_clean_tx_hwts()
81 ns = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_NSEC_REG) & in hclge_ptp_clean_tx_hwts()
83 lo = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_SEC_L_REG); in hclge_ptp_clean_tx_hwts()
84 hi = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_SEC_H_REG) & in hclge_ptp_clean_tx_hwts()
86 hdev->ptp->last_tx_seqid = readl(hdev->ptp->io_base + in hclge_ptp_clean_tx_hwts()
90 hdev->ptp->tx_skb = NULL; in hclge_ptp_clean_tx_hwts()
91 hdev->ptp->tx_cleaned++; in hclge_ptp_clean_tx_hwts()
111 if (!test_bit(HCLGE_PTP_FLAG_RX_EN, &hdev->ptp->flags)) in hclge_ptp_get_rx_hwts()
118 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_get_rx_hwts()
119 sec_h = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_H_REG); in hclge_ptp_get_rx_hwts()
120 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_get_rx_hwts()
124 hdev->ptp->last_rx = jiffies; in hclge_ptp_get_rx_hwts()
125 hdev->ptp->rx_cnt++; in hclge_ptp_get_rx_hwts()
128 static int hclge_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts, in hclge_ptp_gettimex() argument
131 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_gettimex()
136 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_gettimex()
137 ns = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_NSEC_REG); in hclge_ptp_gettimex()
138 hi = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_H_REG); in hclge_ptp_gettimex()
139 lo = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_L_REG); in hclge_ptp_gettimex()
140 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_gettimex()
148 static int hclge_ptp_settime(struct ptp_clock_info *ptp, in hclge_ptp_settime() argument
151 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_settime()
154 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_settime()
155 writel(ts->tv_nsec, hdev->ptp->io_base + HCLGE_PTP_TIME_NSEC_REG); in hclge_ptp_settime()
157 hdev->ptp->io_base + HCLGE_PTP_TIME_SEC_H_REG); in hclge_ptp_settime()
159 hdev->ptp->io_base + HCLGE_PTP_TIME_SEC_L_REG); in hclge_ptp_settime()
162 hdev->ptp->io_base + HCLGE_PTP_TIME_SYNC_REG); in hclge_ptp_settime()
163 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_settime()
168 static int hclge_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) in hclge_ptp_adjtime() argument
170 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_adjtime()
185 hclge_ptp_gettimex(ptp, &ts, NULL); in hclge_ptp_adjtime()
189 return hclge_ptp_settime(ptp, &ts); in hclge_ptp_adjtime()
194 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_adjtime()
195 writel(adj_val, hdev->ptp->io_base + HCLGE_PTP_TIME_NSEC_REG); in hclge_ptp_adjtime()
197 hdev->ptp->io_base + HCLGE_PTP_TIME_ADJ_REG); in hclge_ptp_adjtime()
198 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_adjtime()
208 return copy_to_user(ifr->ifr_data, &hdev->ptp->ts_cfg, in hclge_ptp_get_cfg()
333 unsigned long flags = hdev->ptp->flags; in hclge_ptp_set_ts_mode()
337 if (test_bit(HCLGE_PTP_FLAG_EN, &hdev->ptp->flags)) in hclge_ptp_set_ts_mode()
352 hdev->ptp->flags = flags; in hclge_ptp_set_ts_mode()
353 hdev->ptp->ptp_cfg = ptp_cfg; in hclge_ptp_set_ts_mode()
375 hdev->ptp->ts_cfg = cfg; in hclge_ptp_set_cfg()
398 if (hdev->ptp->clock) in hclge_ptp_get_ts_info()
399 info->phc_index = ptp_clock_index(hdev->ptp->clock); in hclge_ptp_get_ts_info()
424 struct hclge_ptp *ptp; in hclge_ptp_create_clock() local
426 ptp = devm_kzalloc(&hdev->pdev->dev, sizeof(*ptp), GFP_KERNEL); in hclge_ptp_create_clock()
427 if (!ptp) in hclge_ptp_create_clock()
430 ptp->hdev = hdev; in hclge_ptp_create_clock()
431 snprintf(ptp->info.name, sizeof(ptp->info.name), "%s", in hclge_ptp_create_clock()
433 ptp->info.owner = THIS_MODULE; in hclge_ptp_create_clock()
434 ptp->info.max_adj = HCLGE_PTP_CYCLE_ADJ_MAX; in hclge_ptp_create_clock()
435 ptp->info.n_ext_ts = 0; in hclge_ptp_create_clock()
436 ptp->info.pps = 0; in hclge_ptp_create_clock()
437 ptp->info.adjfine = hclge_ptp_adjfine; in hclge_ptp_create_clock()
438 ptp->info.adjtime = hclge_ptp_adjtime; in hclge_ptp_create_clock()
439 ptp->info.gettimex64 = hclge_ptp_gettimex; in hclge_ptp_create_clock()
440 ptp->info.settime64 = hclge_ptp_settime; in hclge_ptp_create_clock()
442 ptp->info.n_alarm = 0; in hclge_ptp_create_clock()
443 ptp->clock = ptp_clock_register(&ptp->info, &hdev->pdev->dev); in hclge_ptp_create_clock()
444 if (IS_ERR(ptp->clock)) { in hclge_ptp_create_clock()
447 ptp->info.n_alarm, PTR_ERR(ptp->clock)); in hclge_ptp_create_clock()
449 } else if (!ptp->clock) { in hclge_ptp_create_clock()
454 spin_lock_init(&ptp->lock); in hclge_ptp_create_clock()
455 ptp->io_base = hdev->hw.hw.io_base + HCLGE_PTP_REG_OFFSET; in hclge_ptp_create_clock()
456 ptp->ts_cfg.rx_filter = HWTSTAMP_FILTER_NONE; in hclge_ptp_create_clock()
457 ptp->ts_cfg.tx_type = HWTSTAMP_TX_OFF; in hclge_ptp_create_clock()
458 hdev->ptp = ptp; in hclge_ptp_create_clock()
465 ptp_clock_unregister(hdev->ptp->clock); in hclge_ptp_destroy_clock()
466 hdev->ptp->clock = NULL; in hclge_ptp_destroy_clock()
467 devm_kfree(&hdev->pdev->dev, hdev->ptp); in hclge_ptp_destroy_clock()
468 hdev->ptp = NULL; in hclge_ptp_destroy_clock()
480 if (!hdev->ptp) { in hclge_ptp_init()
494 set_bit(HCLGE_PTP_FLAG_EN, &hdev->ptp->flags); in hclge_ptp_init()
495 ret = hclge_ptp_adjfine(&hdev->ptp->info, 0); in hclge_ptp_init()
502 ret = hclge_ptp_set_ts_mode(hdev, &hdev->ptp->ts_cfg); in hclge_ptp_init()
510 ret = hclge_ptp_settime(&hdev->ptp->info, &ts); in hclge_ptp_init()
530 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_uninit() local
532 if (!ptp) in hclge_ptp_uninit()
537 clear_bit(HCLGE_PTP_FLAG_EN, &ptp->flags); in hclge_ptp_uninit()
538 ptp->ts_cfg.rx_filter = HWTSTAMP_FILTER_NONE; in hclge_ptp_uninit()
539 ptp->ts_cfg.tx_type = HWTSTAMP_TX_OFF; in hclge_ptp_uninit()
541 if (hclge_ptp_set_ts_mode(hdev, &ptp->ts_cfg)) in hclge_ptp_uninit()
544 if (ptp->tx_skb) { in hclge_ptp_uninit()
545 struct sk_buff *skb = ptp->tx_skb; in hclge_ptp_uninit()
547 ptp->tx_skb = NULL; in hclge_ptp_uninit()