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_adjfreq() local
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()
70 struct hclge_dev *hdev = vport->back; in hclge_ptp_set_tx_info() local
71 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_set_tx_info()
74 test_and_set_bit(HCLGE_STATE_PTP_TX_HANDLING, &hdev->state)) { in hclge_ptp_set_tx_info()
86 void hclge_ptp_clean_tx_hwts(struct hclge_dev *hdev) in hclge_ptp_clean_tx_hwts() argument
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()
111 clear_bit(HCLGE_STATE_PTP_TX_HANDLING, &hdev->state); in hclge_ptp_clean_tx_hwts()
118 struct hclge_dev *hdev = vport->back; in hclge_ptp_get_rx_hwts() local
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()
143 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_gettimex() local
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()
163 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_settime() local
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()
182 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); in hclge_ptp_adjtime() local
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()
215 int hclge_ptp_get_cfg(struct hclge_dev *hdev, struct ifreq *ifr) in hclge_ptp_get_cfg() argument
217 if (!test_bit(HCLGE_STATE_PTP_EN, &hdev->state)) in hclge_ptp_get_cfg()
220 return copy_to_user(ifr->ifr_data, &hdev->ptp->ts_cfg, in hclge_ptp_get_cfg()
224 static int hclge_ptp_int_en(struct hclge_dev *hdev, bool en) in hclge_ptp_int_en() argument
234 ret = hclge_cmd_send(&hdev->hw, &desc, 1); in hclge_ptp_int_en()
236 dev_err(&hdev->pdev->dev, in hclge_ptp_int_en()
243 int hclge_ptp_cfg_qry(struct hclge_dev *hdev, u32 *cfg) in hclge_ptp_cfg_qry() argument
251 ret = hclge_cmd_send(&hdev->hw, &desc, 1); in hclge_ptp_cfg_qry()
253 dev_err(&hdev->pdev->dev, in hclge_ptp_cfg_qry()
263 static int hclge_ptp_cfg(struct hclge_dev *hdev, u32 cfg) in hclge_ptp_cfg() argument
272 ret = hclge_cmd_send(&hdev->hw, &desc, 1); in hclge_ptp_cfg()
274 dev_err(&hdev->pdev->dev, in hclge_ptp_cfg()
342 static int hclge_ptp_set_ts_mode(struct hclge_dev *hdev, in hclge_ptp_set_ts_mode() argument
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()
360 ret = hclge_ptp_cfg(hdev, ptp_cfg); 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()
370 int hclge_ptp_set_cfg(struct hclge_dev *hdev, struct ifreq *ifr) in hclge_ptp_set_cfg() argument
375 if (!test_bit(HCLGE_STATE_PTP_EN, &hdev->state)) { in hclge_ptp_set_cfg()
376 dev_err(&hdev->pdev->dev, "phc is unsupported\n"); in hclge_ptp_set_cfg()
383 ret = hclge_ptp_set_ts_mode(hdev, &cfg); in hclge_ptp_set_cfg()
387 hdev->ptp->ts_cfg = cfg; in hclge_ptp_set_cfg()
396 struct hclge_dev *hdev = vport->back; in hclge_ptp_get_ts_info() local
398 if (!test_bit(HCLGE_STATE_PTP_EN, &hdev->state)) { in hclge_ptp_get_ts_info()
399 dev_err(&hdev->pdev->dev, "phc is unsupported\n"); in hclge_ptp_get_ts_info()
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()
434 static int hclge_ptp_create_clock(struct hclge_dev *hdev) in hclge_ptp_create_clock() argument
438 ptp = devm_kzalloc(&hdev->pdev->dev, sizeof(*ptp), GFP_KERNEL); in hclge_ptp_create_clock()
442 ptp->hdev = hdev; in hclge_ptp_create_clock()
455 ptp->clock = ptp_clock_register(&ptp->info, &hdev->pdev->dev); in hclge_ptp_create_clock()
457 dev_err(&hdev->pdev->dev, in hclge_ptp_create_clock()
462 dev_err(&hdev->pdev->dev, "failed to register ptp clock\n"); in hclge_ptp_create_clock()
467 ptp->io_base = hdev->hw.hw.io_base + HCLGE_PTP_REG_OFFSET; in hclge_ptp_create_clock()
470 hdev->ptp = ptp; in hclge_ptp_create_clock()
475 static void hclge_ptp_destroy_clock(struct hclge_dev *hdev) in hclge_ptp_destroy_clock() argument
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()
483 int hclge_ptp_init(struct hclge_dev *hdev) in hclge_ptp_init() argument
485 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(hdev->pdev); in hclge_ptp_init()
492 if (!hdev->ptp) { in hclge_ptp_init()
493 ret = hclge_ptp_create_clock(hdev); in hclge_ptp_init()
497 ret = hclge_ptp_get_cycle(hdev); in hclge_ptp_init()
502 ret = hclge_ptp_int_en(hdev, true); 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()
509 dev_err(&hdev->pdev->dev, in hclge_ptp_init()
514 ret = hclge_ptp_set_ts_mode(hdev, &hdev->ptp->ts_cfg); in hclge_ptp_init()
516 dev_err(&hdev->pdev->dev, in hclge_ptp_init()
522 ret = hclge_ptp_settime(&hdev->ptp->info, &ts); in hclge_ptp_init()
524 dev_err(&hdev->pdev->dev, in hclge_ptp_init()
529 set_bit(HCLGE_STATE_PTP_EN, &hdev->state); in hclge_ptp_init()
530 dev_info(&hdev->pdev->dev, "phc initializes ok!\n"); in hclge_ptp_init()
535 hclge_ptp_destroy_clock(hdev); in hclge_ptp_init()
540 void hclge_ptp_uninit(struct hclge_dev *hdev) in hclge_ptp_uninit() argument
542 struct hclge_ptp *ptp = hdev->ptp; in hclge_ptp_uninit()
547 hclge_ptp_int_en(hdev, false); in hclge_ptp_uninit()
548 clear_bit(HCLGE_STATE_PTP_EN, &hdev->state); in hclge_ptp_uninit()
553 if (hclge_ptp_set_ts_mode(hdev, &ptp->ts_cfg)) in hclge_ptp_uninit()
554 dev_err(&hdev->pdev->dev, "failed to disable phc\n"); in hclge_ptp_uninit()
563 hclge_ptp_destroy_clock(hdev); in hclge_ptp_uninit()