Lines Matching refs:hdev
9 static int hclge_ptp_get_cycle(struct hclge_dev *hdev) in hclge_ptp_get_cycle() argument
11 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_get_cycle()
13 ptp->cycle.quo = readl(hdev->ptp->io_base + HCLGE_PTP_CYCLE_QUO_REG) & in hclge_ptp_get_cycle()
15 ptp->cycle.numer = readl(hdev->ptp->io_base + HCLGE_PTP_CYCLE_NUM_REG); in hclge_ptp_get_cycle()
16 ptp->cycle.den = readl(hdev->ptp->io_base + HCLGE_PTP_CYCLE_DEN_REG); in hclge_ptp_get_cycle()
19 dev_err(&hdev->pdev->dev, "invalid ptp cycle denominator!\n"); in hclge_ptp_get_cycle()
28 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_adjfine() local
29 struct hclge_ptp_cycle *cycle = &hdev->ptp->cycle; in hclge_ptp_adjfine()
44 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_adjfine()
46 hdev->ptp->io_base + HCLGE_PTP_CYCLE_QUO_REG); in hclge_ptp_adjfine()
47 writel(numerator, hdev->ptp->io_base + HCLGE_PTP_CYCLE_NUM_REG); in hclge_ptp_adjfine()
48 writel(cycle->den, hdev->ptp->io_base + HCLGE_PTP_CYCLE_DEN_REG); in hclge_ptp_adjfine()
50 hdev->ptp->io_base + HCLGE_PTP_CYCLE_CFG_REG); in hclge_ptp_adjfine()
51 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_adjfine()
59 struct hclge_dev *hdev = vport->back; in hclge_ptp_set_tx_info() local
60 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_set_tx_info()
66 test_and_set_bit(HCLGE_STATE_PTP_TX_HANDLING, &hdev->state)) { in hclge_ptp_set_tx_info()
78 void hclge_ptp_clean_tx_hwts(struct hclge_dev *hdev) in hclge_ptp_clean_tx_hwts() argument
80 struct sk_buff *skb = hdev->ptp->tx_skb; in hclge_ptp_clean_tx_hwts()
85 ns = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_NSEC_REG) & in hclge_ptp_clean_tx_hwts()
87 lo = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_SEC_L_REG); in hclge_ptp_clean_tx_hwts()
88 hi = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_SEC_H_REG) & in hclge_ptp_clean_tx_hwts()
90 hdev->ptp->last_tx_seqid = readl(hdev->ptp->io_base + in hclge_ptp_clean_tx_hwts()
94 hdev->ptp->tx_skb = NULL; in hclge_ptp_clean_tx_hwts()
95 hdev->ptp->tx_cleaned++; in hclge_ptp_clean_tx_hwts()
103 clear_bit(HCLGE_STATE_PTP_TX_HANDLING, &hdev->state); in hclge_ptp_clean_tx_hwts()
110 struct hclge_dev *hdev = vport->back; in hclge_ptp_get_rx_hwts() local
115 if (!hdev->ptp || !test_bit(HCLGE_PTP_FLAG_RX_EN, &hdev->ptp->flags)) in hclge_ptp_get_rx_hwts()
122 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_get_rx_hwts()
123 sec_h = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_H_REG); in hclge_ptp_get_rx_hwts()
124 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_get_rx_hwts()
128 hdev->ptp->last_rx = jiffies; in hclge_ptp_get_rx_hwts()
129 hdev->ptp->rx_cnt++; in hclge_ptp_get_rx_hwts()
135 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_gettimex() local
140 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_gettimex()
141 ns = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_NSEC_REG); in hclge_ptp_gettimex()
142 hi = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_H_REG); in hclge_ptp_gettimex()
143 lo = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_L_REG); in hclge_ptp_gettimex()
144 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_gettimex()
155 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_settime() local
158 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_settime()
159 writel(ts->tv_nsec, hdev->ptp->io_base + HCLGE_PTP_TIME_NSEC_REG); in hclge_ptp_settime()
161 hdev->ptp->io_base + HCLGE_PTP_TIME_SEC_H_REG); in hclge_ptp_settime()
163 hdev->ptp->io_base + HCLGE_PTP_TIME_SEC_L_REG); in hclge_ptp_settime()
166 hdev->ptp->io_base + HCLGE_PTP_TIME_SYNC_REG); in hclge_ptp_settime()
167 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_settime()
174 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_adjtime() local
198 spin_lock_irqsave(&hdev->ptp->lock, flags); in hclge_ptp_adjtime()
199 writel(adj_val, hdev->ptp->io_base + HCLGE_PTP_TIME_NSEC_REG); in hclge_ptp_adjtime()
201 hdev->ptp->io_base + HCLGE_PTP_TIME_ADJ_REG); in hclge_ptp_adjtime()
202 spin_unlock_irqrestore(&hdev->ptp->lock, flags); in hclge_ptp_adjtime()
207 int hclge_ptp_get_cfg(struct hclge_dev *hdev, struct ifreq *ifr) in hclge_ptp_get_cfg() argument
209 if (!test_bit(HCLGE_STATE_PTP_EN, &hdev->state)) in hclge_ptp_get_cfg()
212 return copy_to_user(ifr->ifr_data, &hdev->ptp->ts_cfg, in hclge_ptp_get_cfg()
216 static int hclge_ptp_int_en(struct hclge_dev *hdev, bool en) in hclge_ptp_int_en() argument
226 ret = hclge_cmd_send(&hdev->hw, &desc, 1); in hclge_ptp_int_en()
228 dev_err(&hdev->pdev->dev, in hclge_ptp_int_en()
235 int hclge_ptp_cfg_qry(struct hclge_dev *hdev, u32 *cfg) in hclge_ptp_cfg_qry() argument
243 ret = hclge_cmd_send(&hdev->hw, &desc, 1); in hclge_ptp_cfg_qry()
245 dev_err(&hdev->pdev->dev, in hclge_ptp_cfg_qry()
255 static int hclge_ptp_cfg(struct hclge_dev *hdev, u32 cfg) in hclge_ptp_cfg() argument
264 ret = hclge_cmd_send(&hdev->hw, &desc, 1); in hclge_ptp_cfg()
266 dev_err(&hdev->pdev->dev, in hclge_ptp_cfg()
334 static int hclge_ptp_set_ts_mode(struct hclge_dev *hdev, in hclge_ptp_set_ts_mode() argument
337 unsigned long flags = hdev->ptp->flags; in hclge_ptp_set_ts_mode()
341 if (test_bit(HCLGE_PTP_FLAG_EN, &hdev->ptp->flags)) in hclge_ptp_set_ts_mode()
352 ret = hclge_ptp_cfg(hdev, ptp_cfg); in hclge_ptp_set_ts_mode()
356 hdev->ptp->flags = flags; in hclge_ptp_set_ts_mode()
357 hdev->ptp->ptp_cfg = ptp_cfg; in hclge_ptp_set_ts_mode()
362 int hclge_ptp_set_cfg(struct hclge_dev *hdev, struct ifreq *ifr) in hclge_ptp_set_cfg() argument
367 if (!test_bit(HCLGE_STATE_PTP_EN, &hdev->state)) { in hclge_ptp_set_cfg()
368 dev_err(&hdev->pdev->dev, "phc is unsupported\n"); in hclge_ptp_set_cfg()
375 ret = hclge_ptp_set_ts_mode(hdev, &cfg); in hclge_ptp_set_cfg()
379 hdev->ptp->ts_cfg = cfg; in hclge_ptp_set_cfg()
388 struct hclge_dev *hdev = vport->back; in hclge_ptp_get_ts_info() local
390 if (!test_bit(HCLGE_STATE_PTP_EN, &hdev->state)) { in hclge_ptp_get_ts_info()
391 dev_err(&hdev->pdev->dev, "phc is unsupported\n"); in hclge_ptp_get_ts_info()
400 if (hdev->ptp->clock) in hclge_ptp_get_ts_info()
401 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()