Lines Matching refs:phc

79 	if (!lif->phc || !lif->phc->ptp)  in ionic_lif_hwstamp_set_ts_config()
82 mutex_lock(&lif->phc->config_lock); in ionic_lif_hwstamp_set_ts_config()
94 memcpy(config, &lif->phc->ts_config, sizeof(*config)); in ionic_lif_hwstamp_set_ts_config()
95 memset(&lif->phc->ts_config, 0, sizeof(lif->phc->ts_config)); in ionic_lif_hwstamp_set_ts_config()
96 lif->phc->ts_config_tx_mode = 0; in ionic_lif_hwstamp_set_ts_config()
97 lif->phc->ts_config_rx_filt = 0; in ionic_lif_hwstamp_set_ts_config()
137 if (tx_mode != lif->phc->ts_config_tx_mode) { in ionic_lif_hwstamp_set_ts_config()
143 if (rx_filt != lif->phc->ts_config_rx_filt) { in ionic_lif_hwstamp_set_ts_config()
149 if (rx_all != (lif->phc->ts_config.rx_filter == HWTSTAMP_FILTER_ALL)) { in ionic_lif_hwstamp_set_ts_config()
155 memcpy(&lif->phc->ts_config, config, sizeof(*config)); in ionic_lif_hwstamp_set_ts_config()
156 lif->phc->ts_config_rx_filt = rx_filt; in ionic_lif_hwstamp_set_ts_config()
157 lif->phc->ts_config_tx_mode = tx_mode; in ionic_lif_hwstamp_set_ts_config()
159 mutex_unlock(&lif->phc->config_lock); in ionic_lif_hwstamp_set_ts_config()
164 if (rx_filt != lif->phc->ts_config_rx_filt) { in ionic_lif_hwstamp_set_ts_config()
165 rx_filt = lif->phc->ts_config_rx_filt; in ionic_lif_hwstamp_set_ts_config()
172 if (tx_mode != lif->phc->ts_config_tx_mode) { in ionic_lif_hwstamp_set_ts_config()
173 tx_mode = lif->phc->ts_config_tx_mode; in ionic_lif_hwstamp_set_ts_config()
182 mutex_unlock(&lif->phc->config_lock); in ionic_lif_hwstamp_set_ts_config()
191 if (!lif->phc || !lif->phc->ptp) in ionic_lif_hwstamp_set()
215 if (!lif->phc || !lif->phc->ptp) in ionic_lif_hwstamp_replay()
229 if (!lif->phc || !lif->phc->ptp) in ionic_lif_hwstamp_recreate_queues()
232 mutex_lock(&lif->phc->config_lock); in ionic_lif_hwstamp_recreate_queues()
234 if (lif->phc->ts_config_tx_mode) { in ionic_lif_hwstamp_recreate_queues()
240 if (lif->phc->ts_config_rx_filt) { in ionic_lif_hwstamp_recreate_queues()
246 mutex_unlock(&lif->phc->config_lock); in ionic_lif_hwstamp_recreate_queues()
253 if (!lif->phc || !lif->phc->ptp) in ionic_lif_hwstamp_get()
256 mutex_lock(&lif->phc->config_lock); in ionic_lif_hwstamp_get()
257 memcpy(&config, &lif->phc->ts_config, sizeof(config)); in ionic_lif_hwstamp_get()
258 mutex_unlock(&lif->phc->config_lock); in ionic_lif_hwstamp_get()
295 struct ionic_phc *phc = container_of(cc, struct ionic_phc, cc); in ionic_cc_read() local
296 struct ionic *ionic = phc->lif->ionic; in ionic_cc_read()
301 static int ionic_setphc_cmd(struct ionic_phc *phc, struct ionic_admin_ctx *ctx) in ionic_setphc_cmd() argument
306 ctx->cmd.lif_setphc.lif_index = cpu_to_le16(phc->lif->index); in ionic_setphc_cmd()
308 ctx->cmd.lif_setphc.tick = cpu_to_le64(phc->tc.cycle_last); in ionic_setphc_cmd()
309 ctx->cmd.lif_setphc.nsec = cpu_to_le64(phc->tc.nsec); in ionic_setphc_cmd()
310 ctx->cmd.lif_setphc.frac = cpu_to_le64(phc->tc.frac); in ionic_setphc_cmd()
311 ctx->cmd.lif_setphc.mult = cpu_to_le32(phc->cc.mult); in ionic_setphc_cmd()
312 ctx->cmd.lif_setphc.shift = cpu_to_le32(phc->cc.shift); in ionic_setphc_cmd()
314 return ionic_adminq_post(phc->lif, ctx); in ionic_setphc_cmd()
319 struct ionic_phc *phc = container_of(info, struct ionic_phc, ptp_info); in ionic_phc_adjfine() local
326 if (test_bit(IONIC_LIF_F_FW_RESET, phc->lif->state)) in ionic_phc_adjfine()
330 adj = (s64)scaled_ppm * phc->init_cc_mult; in ionic_phc_adjfine()
336 adj += phc->init_cc_mult; in ionic_phc_adjfine()
338 spin_lock_irqsave(&phc->lock, irqflags); in ionic_phc_adjfine()
341 timecounter_read(&phc->tc); in ionic_phc_adjfine()
342 phc->cc.mult = adj; in ionic_phc_adjfine()
347 err = ionic_setphc_cmd(phc, &ctx); in ionic_phc_adjfine()
349 spin_unlock_irqrestore(&phc->lock, irqflags); in ionic_phc_adjfine()
351 return ionic_adminq_wait(phc->lif, &ctx, err, true); in ionic_phc_adjfine()
356 struct ionic_phc *phc = container_of(info, struct ionic_phc, ptp_info); in ionic_phc_adjtime() local
362 if (test_bit(IONIC_LIF_F_FW_RESET, phc->lif->state)) in ionic_phc_adjtime()
365 spin_lock_irqsave(&phc->lock, irqflags); in ionic_phc_adjtime()
367 timecounter_adjtime(&phc->tc, delta); in ionic_phc_adjtime()
372 err = ionic_setphc_cmd(phc, &ctx); in ionic_phc_adjtime()
374 spin_unlock_irqrestore(&phc->lock, irqflags); in ionic_phc_adjtime()
376 return ionic_adminq_wait(phc->lif, &ctx, err, true); in ionic_phc_adjtime()
382 struct ionic_phc *phc = container_of(info, struct ionic_phc, ptp_info); in ionic_phc_settime64() local
389 if (test_bit(IONIC_LIF_F_FW_RESET, phc->lif->state)) in ionic_phc_settime64()
394 spin_lock_irqsave(&phc->lock, irqflags); in ionic_phc_settime64()
396 timecounter_init(&phc->tc, &phc->cc, ns); in ionic_phc_settime64()
401 err = ionic_setphc_cmd(phc, &ctx); in ionic_phc_settime64()
403 spin_unlock_irqrestore(&phc->lock, irqflags); in ionic_phc_settime64()
405 return ionic_adminq_wait(phc->lif, &ctx, err, true); in ionic_phc_settime64()
412 struct ionic_phc *phc = container_of(info, struct ionic_phc, ptp_info); in ionic_phc_gettimex64() local
413 struct ionic *ionic = phc->lif->ionic; in ionic_phc_gettimex64()
418 if (test_bit(IONIC_LIF_F_FW_RESET, phc->lif->state)) in ionic_phc_gettimex64()
421 spin_lock_irqsave(&phc->lock, irqflags); in ionic_phc_gettimex64()
425 ns = timecounter_cyc2time(&phc->tc, tick); in ionic_phc_gettimex64()
427 spin_unlock_irqrestore(&phc->lock, irqflags); in ionic_phc_gettimex64()
436 struct ionic_phc *phc = container_of(info, struct ionic_phc, ptp_info); in ionic_phc_aux_work() local
447 if (test_bit(IONIC_LIF_F_FW_RESET, phc->lif->state)) in ionic_phc_aux_work()
448 return phc->aux_work_delay; in ionic_phc_aux_work()
450 spin_lock_irqsave(&phc->lock, irqflags); in ionic_phc_aux_work()
453 timecounter_read(&phc->tc); in ionic_phc_aux_work()
458 err = ionic_setphc_cmd(phc, &ctx); in ionic_phc_aux_work()
460 spin_unlock_irqrestore(&phc->lock, irqflags); in ionic_phc_aux_work()
462 ionic_adminq_wait(phc->lif, &ctx, err, true); in ionic_phc_aux_work()
464 return phc->aux_work_delay; in ionic_phc_aux_work()
472 if (!lif->phc) in ionic_lif_phc_ktime()
475 spin_lock_irqsave(&lif->phc->lock, irqflags); in ionic_lif_phc_ktime()
476 ns = timecounter_cyc2time(&lif->phc->tc, tick); in ionic_lif_phc_ktime()
477 spin_unlock_irqrestore(&lif->phc->lock, irqflags); in ionic_lif_phc_ktime()
494 if (!lif->phc || !(lif->hw_features & IONIC_ETH_HW_TIMESTAMP)) in ionic_lif_register_phc()
497 lif->phc->ptp = ptp_clock_register(&lif->phc->ptp_info, lif->ionic->dev); in ionic_lif_register_phc()
499 if (IS_ERR(lif->phc->ptp)) { in ionic_lif_register_phc()
501 PTR_ERR(lif->phc->ptp)); in ionic_lif_register_phc()
503 lif->phc->ptp = NULL; in ionic_lif_register_phc()
506 if (lif->phc->ptp) in ionic_lif_register_phc()
507 ptp_schedule_worker(lif->phc->ptp, lif->phc->aux_work_delay); in ionic_lif_register_phc()
512 if (!lif->phc || !lif->phc->ptp) in ionic_lif_unregister_phc()
515 ptp_clock_unregister(lif->phc->ptp); in ionic_lif_unregister_phc()
517 lif->phc->ptp = NULL; in ionic_lif_unregister_phc()
523 struct ionic_phc *phc; in ionic_lif_alloc_phc() local
536 phc = devm_kzalloc(ionic->dev, sizeof(*phc), GFP_KERNEL); in ionic_lif_alloc_phc()
537 if (!phc) in ionic_lif_alloc_phc()
540 phc->lif = lif; in ionic_lif_alloc_phc()
542 phc->cc.read = ionic_cc_read; in ionic_lif_alloc_phc()
543 phc->cc.mask = le64_to_cpu(ionic->ident.dev.hwstamp_mask); in ionic_lif_alloc_phc()
544 phc->cc.mult = le32_to_cpu(ionic->ident.dev.hwstamp_mult); in ionic_lif_alloc_phc()
545 phc->cc.shift = le32_to_cpu(ionic->ident.dev.hwstamp_shift); in ionic_lif_alloc_phc()
547 if (!phc->cc.mult) { in ionic_lif_alloc_phc()
550 phc->cc.mult); in ionic_lif_alloc_phc()
551 devm_kfree(lif->ionic->dev, phc); in ionic_lif_alloc_phc()
552 lif->phc = NULL; in ionic_lif_alloc_phc()
557 phc->cc.mask, phc->cc.mult, phc->cc.shift); in ionic_lif_alloc_phc()
559 spin_lock_init(&phc->lock); in ionic_lif_alloc_phc()
560 mutex_init(&phc->config_lock); in ionic_lif_alloc_phc()
563 if (phc->cc.shift + 2 + ilog2(IONIC_PHC_UPDATE_NS) >= 64) { in ionic_lif_alloc_phc()
567 diff = U64_MAX / phc->cc.mult / 2; in ionic_lif_alloc_phc()
570 diff = (u64)IONIC_PHC_UPDATE_NS << (phc->cc.shift + 2); in ionic_lif_alloc_phc()
571 diff = DIV_ROUND_UP(diff, phc->cc.mult); in ionic_lif_alloc_phc()
583 diff &= phc->cc.mask; in ionic_lif_alloc_phc()
584 phc->cc.mask = diff; in ionic_lif_alloc_phc()
604 shift = mult / phc->cc.mult; in ionic_lif_alloc_phc()
609 phc->cc.mult <<= shift; in ionic_lif_alloc_phc()
610 phc->cc.shift += shift; in ionic_lif_alloc_phc()
614 phc->cc.mask, phc->cc.mult, phc->cc.shift); in ionic_lif_alloc_phc()
617 phc->init_cc_mult = phc->cc.mult; in ionic_lif_alloc_phc()
619 timecounter_init(&phc->tc, &phc->cc, ktime_get_real_ns()); in ionic_lif_alloc_phc()
623 cyclecounter_cyc2ns(&phc->cc, diff / 4, 0, &frac)); in ionic_lif_alloc_phc()
626 phc->aux_work_delay = nsecs_to_jiffies(delay); in ionic_lif_alloc_phc()
628 phc->ptp_info = ionic_ptp_info; in ionic_lif_alloc_phc()
633 phc->ptp_info.max_adj = NORMAL_PPB; in ionic_lif_alloc_phc()
635 lif->phc = phc; in ionic_lif_alloc_phc()
640 if (!lif->phc) in ionic_lif_free_phc()
643 mutex_destroy(&lif->phc->config_lock); in ionic_lif_free_phc()
645 devm_kfree(lif->ionic->dev, lif->phc); in ionic_lif_free_phc()
646 lif->phc = NULL; in ionic_lif_free_phc()