Lines Matching +full:ptp +full:- +full:timer
2 * cxgb4_ptp.c:Chelsio PTP support for T5/T6
4 * Copyright (c) 2003-2017 Chelsio Communications, Inc. All rights reserved.
16 * - Redistributions of source code must retain the above
20 * - Redistributions in binary form must reproduce the above
54 * cxgb4_ptp_is_ptp_tx - determine whether TX packet is PTP or not
55 * @skb: skb of outgoing ptp request
63 return skb->len >= PTP_MIN_LENGTH && in cxgb4_ptp_is_ptp_tx()
64 skb->len <= PTP_IN_TRANSMIT_PACKET_MAXNUM && in cxgb4_ptp_is_ptp_tx()
65 likely(skb->protocol == htons(ETH_P_IP)) && in cxgb4_ptp_is_ptp_tx()
66 ip_hdr(skb)->protocol == IPPROTO_UDP && in cxgb4_ptp_is_ptp_tx()
67 uh->dest == htons(PTP_EVENT_PORT); in cxgb4_ptp_is_ptp_tx()
75 return (pi->ptp_enable && cxgb4_xmit_with_hwtstamp(skb) && in is_ptp_enabled()
80 * cxgb4_ptp_is_ptp_rx - determine whether RX packet is PTP or not
81 * @skb: skb of incoming ptp request
86 struct udphdr *uh = (struct udphdr *)(skb->data + ETH_HLEN + in cxgb4_ptp_is_ptp_rx()
87 IPV4_HLEN(skb->data)); in cxgb4_ptp_is_ptp_rx()
89 return uh->dest == htons(PTP_EVENT_PORT) && in cxgb4_ptp_is_ptp_rx()
90 uh->source == htons(PTP_EVENT_PORT); in cxgb4_ptp_is_ptp_rx()
94 * cxgb4_ptp_read_hwstamp - read timestamp for TX event PTP message
104 skb_ts = skb_hwtstamps(adapter->ptp_tx_skb); in cxgb4_ptp_read_hwstamp()
107 T5_PORT_REG(pi->port_id, MAC_PORT_TX_TS_VAL_LO)); in cxgb4_ptp_read_hwstamp()
110 T5_PORT_REG(pi->port_id, in cxgb4_ptp_read_hwstamp()
112 skb_ts->hwtstamp = ns_to_ktime(tx_ts); in cxgb4_ptp_read_hwstamp()
113 skb_tstamp_tx(adapter->ptp_tx_skb, skb_ts); in cxgb4_ptp_read_hwstamp()
114 dev_kfree_skb_any(adapter->ptp_tx_skb); in cxgb4_ptp_read_hwstamp()
115 spin_lock(&adapter->ptp_lock); in cxgb4_ptp_read_hwstamp()
116 adapter->ptp_tx_skb = NULL; in cxgb4_ptp_read_hwstamp()
117 spin_unlock(&adapter->ptp_lock); in cxgb4_ptp_read_hwstamp()
121 * cxgb4_ptprx_timestamping - Enable Timestamp for RX PTP event message
129 struct adapter *adapter = pi->adapter; in cxgb4_ptprx_timestamping()
142 err = t4_wr_mbox(adapter, adapter->mbox, &c, sizeof(c), NULL); in cxgb4_ptprx_timestamping()
144 dev_err(adapter->pdev_dev, in cxgb4_ptprx_timestamping()
145 "PTP: %s error %d\n", __func__, -err); in cxgb4_ptprx_timestamping()
163 err = t4_wr_mbox(adapter, adapter->mbox, &c, sizeof(c), NULL); in cxgb4_ptp_txtype()
165 dev_err(adapter->pdev_dev, in cxgb4_ptp_txtype()
166 "PTP: %s error %d\n", __func__, -err); in cxgb4_ptp_txtype()
173 struct sge *s = &adapter->sge; in cxgb4_ptp_redirect_rx_packet()
174 struct sge_eth_rxq *receive_q = &s->ethrxq[pi->first_qset]; in cxgb4_ptp_redirect_rx_packet()
182 FW_PTP_CMD_PORTID_V(pi->port_id)); in cxgb4_ptp_redirect_rx_packet()
186 c.u.init.txchan = pi->tx_chan; in cxgb4_ptp_redirect_rx_packet()
187 c.u.init.absid = cpu_to_be16(receive_q->rspq.abs_id); in cxgb4_ptp_redirect_rx_packet()
189 err = t4_wr_mbox(adapter, adapter->mbox, &c, sizeof(c), NULL); in cxgb4_ptp_redirect_rx_packet()
191 dev_err(adapter->pdev_dev, in cxgb4_ptp_redirect_rx_packet()
192 "PTP: %s error %d\n", __func__, -err); in cxgb4_ptp_redirect_rx_packet()
197 * cxgb4_ptp_adjfine - Adjust frequency of PHC cycle counter
198 * @ptp: ptp clock structure
204 * Scaled parts per million is ppm with a 16-bit binary fractional field.
206 static int cxgb4_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) in cxgb4_ptp_adjfine() argument
208 struct adapter *adapter = (struct adapter *)container_of(ptp, in cxgb4_ptp_adjfine()
223 ppb = -ppb; in cxgb4_ptp_adjfine()
226 err = t4_wr_mbox(adapter, adapter->mbox, &c, sizeof(c), NULL); in cxgb4_ptp_adjfine()
228 dev_err(adapter->pdev_dev, in cxgb4_ptp_adjfine()
229 "PTP: %s error %d\n", __func__, -err); in cxgb4_ptp_adjfine()
235 * cxgb4_ptp_fineadjtime - Shift the time of the hardware clock
239 * Adjust the timer by resetting the timecounter structure.
255 delta = -delta; in cxgb4_ptp_fineadjtime()
258 err = t4_wr_mbox(adapter, adapter->mbox, &c, sizeof(c), NULL); in cxgb4_ptp_fineadjtime()
260 dev_err(adapter->pdev_dev, in cxgb4_ptp_fineadjtime()
261 "PTP: %s error %d\n", __func__, -err); in cxgb4_ptp_fineadjtime()
266 * cxgb4_ptp_adjtime - Shift the time of the hardware clock
267 * @ptp: ptp clock structure
270 * Adjust the timer by resetting the timecounter structure.
272 static int cxgb4_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) in cxgb4_ptp_adjtime() argument
275 (struct adapter *)container_of(ptp, struct adapter, in cxgb4_ptp_adjtime()
282 sign = -1; in cxgb4_ptp_adjtime()
294 delta = -delta; in cxgb4_ptp_adjtime()
297 err = t4_wr_mbox(adapter, adapter->mbox, &c, sizeof(c), NULL); in cxgb4_ptp_adjtime()
299 dev_err(adapter->pdev_dev, in cxgb4_ptp_adjtime()
300 "PTP: %s error %d\n", __func__, -err); in cxgb4_ptp_adjtime()
309 * cxgb4_ptp_gettime - Reads the current time from the hardware clock
310 * @ptp: ptp clock structure
316 static int cxgb4_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts) in cxgb4_ptp_gettime() argument
318 struct adapter *adapter = container_of(ptp, struct adapter, in cxgb4_ptp_gettime()
332 * cxgb4_ptp_settime - Set the current time on the hardware clock
333 * @ptp: ptp clock structure
337 * wall timer value.
339 static int cxgb4_ptp_settime(struct ptp_clock_info *ptp, in cxgb4_ptp_settime() argument
342 struct adapter *adapter = (struct adapter *)container_of(ptp, in cxgb4_ptp_settime()
359 err = t4_wr_mbox(adapter, adapter->mbox, &c, sizeof(c), NULL); in cxgb4_ptp_settime()
361 dev_err(adapter->pdev_dev, in cxgb4_ptp_settime()
362 "PTP: %s error %d\n", __func__, -err); in cxgb4_ptp_settime()
380 err = t4_wr_mbox(adapter, adapter->mbox, &c, sizeof(c), NULL); in cxgb4_init_ptp_timer()
382 dev_err(adapter->pdev_dev, in cxgb4_init_ptp_timer()
383 "PTP: %s error %d\n", __func__, -err); in cxgb4_init_ptp_timer()
387 * cxgb4_ptp_enable - enable or disable an ancillary feature
388 * @ptp: ptp clock structure
395 static int cxgb4_ptp_enable(struct ptp_clock_info __always_unused *ptp, in cxgb4_ptp_enable() argument
399 return -ENOTSUPP; in cxgb4_ptp_enable()
418 * cxgb4_ptp_init - initialize PTP for devices which support it
421 * This function performs the required steps for enabling PTP support.
427 if (!IS_ERR_OR_NULL(adapter->ptp_clock)) in cxgb4_ptp_init()
430 adapter->ptp_tx_skb = NULL; in cxgb4_ptp_init()
431 adapter->ptp_clock_info = cxgb4_ptp_clock_info; in cxgb4_ptp_init()
432 spin_lock_init(&adapter->ptp_lock); in cxgb4_ptp_init()
434 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info, in cxgb4_ptp_init()
435 &adapter->pdev->dev); in cxgb4_ptp_init()
436 if (IS_ERR_OR_NULL(adapter->ptp_clock)) { in cxgb4_ptp_init()
437 adapter->ptp_clock = NULL; in cxgb4_ptp_init()
438 dev_err(adapter->pdev_dev, in cxgb4_ptp_init()
439 "PTP %s Clock registration has failed\n", __func__); in cxgb4_ptp_init()
445 if (cxgb4_ptp_settime(&adapter->ptp_clock_info, &now) < 0) { in cxgb4_ptp_init()
446 ptp_clock_unregister(adapter->ptp_clock); in cxgb4_ptp_init()
447 adapter->ptp_clock = NULL; in cxgb4_ptp_init()
452 * cxgb4_ptp_stop - disable PTP device and stop the overflow check
455 * Stop the PTP support.
459 if (adapter->ptp_tx_skb) { in cxgb4_ptp_stop()
460 dev_kfree_skb_any(adapter->ptp_tx_skb); in cxgb4_ptp_stop()
461 adapter->ptp_tx_skb = NULL; in cxgb4_ptp_stop()
464 if (adapter->ptp_clock) { in cxgb4_ptp_stop()
465 ptp_clock_unregister(adapter->ptp_clock); in cxgb4_ptp_stop()
466 adapter->ptp_clock = NULL; in cxgb4_ptp_stop()