Lines Matching refs:hdev

8 static int hclge_ptp_get_cycle(struct hclge_dev *hdev)  in hclge_ptp_get_cycle()  argument
10 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_get_cycle()
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()
18 dev_err(&hdev->pdev->dev, "invalid ptp cycle denominator!\n"); in hclge_ptp_get_cycle()
27 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_adjfine() local
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()
58 struct hclge_dev *hdev = vport->back; in hclge_ptp_set_tx_info() local
59 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_set_tx_info()
62 test_and_set_bit(HCLGE_STATE_PTP_TX_HANDLING, &hdev->state)) { in hclge_ptp_set_tx_info()
74 void hclge_ptp_clean_tx_hwts(struct hclge_dev *hdev) in hclge_ptp_clean_tx_hwts() argument
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()
99 clear_bit(HCLGE_STATE_PTP_TX_HANDLING, &hdev->state); in hclge_ptp_clean_tx_hwts()
106 struct hclge_dev *hdev = vport->back; in hclge_ptp_get_rx_hwts() local
111 if (!hdev->ptp || !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()
131 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_gettimex() local
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()
151 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_settime() local
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()
170 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_adjtime() local
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()
203 int hclge_ptp_get_cfg(struct hclge_dev *hdev, struct ifreq *ifr) in hclge_ptp_get_cfg() argument
205 if (!test_bit(HCLGE_STATE_PTP_EN, &hdev->state)) in hclge_ptp_get_cfg()
208 return copy_to_user(ifr->ifr_data, &hdev->ptp->ts_cfg, in hclge_ptp_get_cfg()
212 static int hclge_ptp_int_en(struct hclge_dev *hdev, bool en) in hclge_ptp_int_en() argument
222 ret = hclge_cmd_send(&hdev->hw, &desc, 1); in hclge_ptp_int_en()
224 dev_err(&hdev->pdev->dev, in hclge_ptp_int_en()
231 int hclge_ptp_cfg_qry(struct hclge_dev *hdev, u32 *cfg) in hclge_ptp_cfg_qry() argument
239 ret = hclge_cmd_send(&hdev->hw, &desc, 1); in hclge_ptp_cfg_qry()
241 dev_err(&hdev->pdev->dev, in hclge_ptp_cfg_qry()
251 static int hclge_ptp_cfg(struct hclge_dev *hdev, u32 cfg) in hclge_ptp_cfg() argument
260 ret = hclge_cmd_send(&hdev->hw, &desc, 1); in hclge_ptp_cfg()
262 dev_err(&hdev->pdev->dev, in hclge_ptp_cfg()
330 static int hclge_ptp_set_ts_mode(struct hclge_dev *hdev, in hclge_ptp_set_ts_mode() argument
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()
348 ret = hclge_ptp_cfg(hdev, ptp_cfg); 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()
358 int hclge_ptp_set_cfg(struct hclge_dev *hdev, struct ifreq *ifr) in hclge_ptp_set_cfg() argument
363 if (!test_bit(HCLGE_STATE_PTP_EN, &hdev->state)) { in hclge_ptp_set_cfg()
364 dev_err(&hdev->pdev->dev, "phc is unsupported\n"); in hclge_ptp_set_cfg()
371 ret = hclge_ptp_set_ts_mode(hdev, &cfg); in hclge_ptp_set_cfg()
375 hdev->ptp->ts_cfg = cfg; in hclge_ptp_set_cfg()
384 struct hclge_dev *hdev = vport->back; in hclge_ptp_get_ts_info() local
386 if (!test_bit(HCLGE_STATE_PTP_EN, &hdev->state)) { in hclge_ptp_get_ts_info()
387 dev_err(&hdev->pdev->dev, "phc is unsupported\n"); in hclge_ptp_get_ts_info()
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()
422 static int hclge_ptp_create_clock(struct hclge_dev *hdev) in hclge_ptp_create_clock() argument
426 ptp = devm_kzalloc(&hdev->pdev->dev, sizeof(*ptp), GFP_KERNEL); in hclge_ptp_create_clock()
430 ptp->hdev = hdev; in hclge_ptp_create_clock()
443 ptp->clock = ptp_clock_register(&ptp->info, &hdev->pdev->dev); in hclge_ptp_create_clock()
445 dev_err(&hdev->pdev->dev, in hclge_ptp_create_clock()
450 dev_err(&hdev->pdev->dev, "failed to register ptp clock\n"); in hclge_ptp_create_clock()
455 ptp->io_base = hdev->hw.hw.io_base + HCLGE_PTP_REG_OFFSET; in hclge_ptp_create_clock()
458 hdev->ptp = ptp; in hclge_ptp_create_clock()
463 static void hclge_ptp_destroy_clock(struct hclge_dev *hdev) in hclge_ptp_destroy_clock() argument
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()
471 int hclge_ptp_init(struct hclge_dev *hdev) in hclge_ptp_init() argument
473 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(hdev->pdev); in hclge_ptp_init()
480 if (!hdev->ptp) { in hclge_ptp_init()
481 ret = hclge_ptp_create_clock(hdev); in hclge_ptp_init()
485 ret = hclge_ptp_get_cycle(hdev); in hclge_ptp_init()
490 ret = hclge_ptp_int_en(hdev, true); 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()
497 dev_err(&hdev->pdev->dev, in hclge_ptp_init()
502 ret = hclge_ptp_set_ts_mode(hdev, &hdev->ptp->ts_cfg); in hclge_ptp_init()
504 dev_err(&hdev->pdev->dev, in hclge_ptp_init()
510 ret = hclge_ptp_settime(&hdev->ptp->info, &ts); in hclge_ptp_init()
512 dev_err(&hdev->pdev->dev, in hclge_ptp_init()
517 set_bit(HCLGE_STATE_PTP_EN, &hdev->state); in hclge_ptp_init()
518 dev_info(&hdev->pdev->dev, "phc initializes ok!\n"); in hclge_ptp_init()
523 hclge_ptp_destroy_clock(hdev); in hclge_ptp_init()
528 void hclge_ptp_uninit(struct hclge_dev *hdev) in hclge_ptp_uninit() argument
530 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_uninit()
535 hclge_ptp_int_en(hdev, false); in hclge_ptp_uninit()
536 clear_bit(HCLGE_STATE_PTP_EN, &hdev->state); in hclge_ptp_uninit()
541 if (hclge_ptp_set_ts_mode(hdev, &ptp->ts_cfg)) in hclge_ptp_uninit()
542 dev_err(&hdev->pdev->dev, "failed to disable phc\n"); in hclge_ptp_uninit()
551 hclge_ptp_destroy_clock(hdev); in hclge_ptp_uninit()