Lines Matching defs:fbd
40 static u64 __fbnic_time_get_slow(struct fbnic_dev *fbd)
44 lockdep_assert_held(&fbd->time_lock);
47 hi = fbnic_rd32(fbd, FBNIC_PTP_CTR_VAL_HI);
48 lo = fbnic_rd32(fbd, FBNIC_PTP_CTR_VAL_LO);
49 } while (hi != fbnic_rd32(fbd, FBNIC_PTP_CTR_VAL_HI));
54 static void __fbnic_time_set_addend(struct fbnic_dev *fbd, u64 addend)
56 lockdep_assert_held(&fbd->time_lock);
58 fbnic_wr32(fbd, FBNIC_PTP_ADD_VAL_NS,
60 fbnic_wr32(fbd, FBNIC_PTP_ADD_VAL_SUBNS, (u32)addend);
63 static void fbnic_ptp_fresh_check(struct fbnic_dev *fbd)
65 if (time_is_after_jiffies(fbd->last_read +
69 dev_warn(fbd->dev, "NIC timestamp refresh stall, delayed by %lu sec\n",
70 (jiffies - fbd->last_read - FBNIC_TS_HIGH_REFRESH_JIF) / HZ);
73 static void fbnic_ptp_refresh_time(struct fbnic_dev *fbd, struct fbnic_net *fbn)
78 spin_lock_irqsave(&fbd->time_lock, flags);
79 hi = fbnic_rd32(fbn->fbd, FBNIC_PTP_CTR_VAL_HI);
80 if (!fbnic_present(fbd))
89 fbd->last_read = jiffies;
91 spin_unlock_irqrestore(&fbd->time_lock, flags);
96 struct fbnic_dev *fbd = fbnic_from_ptp_info(ptp);
99 fbn = netdev_priv(fbd->netdev);
101 fbnic_ptp_fresh_check(fbd);
102 fbnic_ptp_refresh_time(fbd, fbn);
109 struct fbnic_dev *fbd = fbnic_from_ptp_info(ptp);
117 spin_lock_irqsave(&fbd->time_lock, flags);
118 __fbnic_time_set_addend(fbd, addend);
119 fbnic_wr32(fbd, FBNIC_PTP_ADJUST, FBNIC_PTP_ADJUST_ADDEND_SET);
122 fbnic_rd32(fbd, FBNIC_PTP_SPARE);
123 spin_unlock_irqrestore(&fbd->time_lock, flags);
125 return fbnic_present(fbd) ? 0 : -EIO;
130 struct fbnic_dev *fbd = fbnic_from_ptp_info(ptp);
134 fbn = netdev_priv(fbd->netdev);
136 spin_lock_irqsave(&fbd->time_lock, flags);
140 spin_unlock_irqrestore(&fbd->time_lock, flags);
149 struct fbnic_dev *fbd = fbnic_from_ptp_info(ptp);
155 fbn = netdev_priv(fbd->netdev);
157 spin_lock_irqsave(&fbd->time_lock, flags);
160 hi = fbnic_rd32(fbd, FBNIC_PTP_CTR_VAL_HI);
162 lo = fbnic_rd32(fbd, FBNIC_PTP_CTR_VAL_LO);
167 } while (hi != fbnic_rd32(fbd, FBNIC_PTP_CTR_VAL_HI));
170 spin_unlock_irqrestore(&fbd->time_lock, flags);
172 if (!fbnic_present(fbd))
183 struct fbnic_dev *fbd = fbnic_from_ptp_info(ptp);
189 fbn = netdev_priv(fbd->netdev);
193 spin_lock_irqsave(&fbd->time_lock, flags);
195 dev_ns = __fbnic_time_get_slow(fbd);
197 if (fbnic_present(fbd)) {
205 spin_unlock_irqrestore(&fbd->time_lock, flags);
223 static void fbnic_ptp_reset(struct fbnic_dev *fbd)
225 struct fbnic_net *fbn = netdev_priv(fbd->netdev);
228 fbnic_wr32(fbd, FBNIC_PTP_CTRL,
235 __fbnic_time_set_addend(fbd, dclk_period);
237 fbnic_wr32(fbd, FBNIC_PTP_INIT_HI, 0);
238 fbnic_wr32(fbd, FBNIC_PTP_INIT_LO, 0);
240 fbnic_wr32(fbd, FBNIC_PTP_ADJUST, FBNIC_PTP_ADJUST_INIT);
242 fbnic_wr32(fbd, FBNIC_PTP_CTRL,
248 fbnic_rd32(fbd, FBNIC_PTP_SPARE);
265 fbnic_ptp_refresh_time(fbn->fbd, fbn);
269 return ptp_schedule_worker(fbn->fbd->ptp, FBNIC_TS_HIGH_REFRESH_JIF);
274 ptp_cancel_worker_sync(fbn->fbd->ptp);
275 fbnic_ptp_fresh_check(fbn->fbd);
278 int fbnic_ptp_setup(struct fbnic_dev *fbd)
280 struct device *dev = fbd->dev;
283 spin_lock_init(&fbd->time_lock);
285 spin_lock_irqsave(&fbd->time_lock, flags); /* Appease lockdep */
286 fbnic_ptp_reset(fbd);
287 spin_unlock_irqrestore(&fbd->time_lock, flags);
289 memcpy(&fbd->ptp_info, &fbnic_ptp_info, sizeof(fbnic_ptp_info));
291 fbd->ptp = ptp_clock_register(&fbd->ptp_info, dev);
292 if (IS_ERR(fbd->ptp))
293 dev_err(dev, "Failed to register PTP: %pe\n", fbd->ptp);
295 return PTR_ERR_OR_ZERO(fbd->ptp);
298 void fbnic_ptp_destroy(struct fbnic_dev *fbd)
300 if (!fbd->ptp)
302 ptp_clock_unregister(fbd->ptp);