Lines Matching +full:tx +full:- +full:ts +full:- +full:mask
1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
19 int ocelot_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts) in ocelot_ptp_gettime64() argument
27 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_gettime64()
39 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_gettime64()
43 s--; in ocelot_ptp_gettime64()
48 set_normalized_timespec64(ts, s, ns); in ocelot_ptp_gettime64()
54 const struct timespec64 *ts) in ocelot_ptp_settime64() argument
60 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_settime64()
68 ocelot_write_rix(ocelot, lower_32_bits(ts->tv_sec), PTP_PIN_TOD_SEC_LSB, in ocelot_ptp_settime64()
70 ocelot_write_rix(ocelot, upper_32_bits(ts->tv_sec), PTP_PIN_TOD_SEC_MSB, in ocelot_ptp_settime64()
72 ocelot_write_rix(ocelot, ts->tv_nsec, PTP_PIN_TOD_NSEC, TOD_ACC_PIN); in ocelot_ptp_settime64()
80 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_settime64()
82 if (ocelot->ops->tas_clock_adjust) in ocelot_ptp_settime64()
83 ocelot->ops->tas_clock_adjust(ocelot); in ocelot_ptp_settime64()
91 if (delta > -(NSEC_PER_SEC / 2) && delta < (NSEC_PER_SEC / 2)) { in ocelot_ptp_adjtime()
97 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_adjtime()
117 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_adjtime()
119 if (ocelot->ops->tas_clock_adjust) in ocelot_ptp_adjtime()
120 ocelot->ops->tas_clock_adjust(ocelot); in ocelot_ptp_adjtime()
123 struct timespec64 ts; in ocelot_ptp_adjtime() local
126 ocelot_ptp_gettime64(ptp, &ts); in ocelot_ptp_adjtime()
128 now = ktime_to_ns(timespec64_to_ktime(ts)); in ocelot_ptp_adjtime()
129 ts = ns_to_timespec64(now + delta); in ocelot_ptp_adjtime()
131 ocelot_ptp_settime64(ptp, &ts); in ocelot_ptp_adjtime()
145 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_adjfine()
152 scaled_ppm = -scaled_ppm; in ocelot_ptp_adjfine()
173 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_adjfine()
179 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_adjfine()
193 return -1; in ocelot_ptp_verify()
207 int pin = -1; in ocelot_ptp_enable()
212 switch (rq->type) { in ocelot_ptp_enable()
215 if (rq->perout.flags & ~(PTP_PEROUT_DUTY_CYCLE | in ocelot_ptp_enable()
217 return -EOPNOTSUPP; in ocelot_ptp_enable()
219 pin = ptp_find_pin(ocelot->ptp_clock, PTP_PF_PEROUT, in ocelot_ptp_enable()
220 rq->perout.index); in ocelot_ptp_enable()
230 return -EBUSY; in ocelot_ptp_enable()
232 ts_period.tv_sec = rq->perout.period.sec; in ocelot_ptp_enable()
233 ts_period.tv_nsec = rq->perout.period.nsec; in ocelot_ptp_enable()
240 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_enable()
243 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_enable()
247 if (rq->perout.flags & PTP_PEROUT_PHASE) { in ocelot_ptp_enable()
248 ts_phase.tv_sec = rq->perout.phase.sec; in ocelot_ptp_enable()
249 ts_phase.tv_nsec = rq->perout.phase.nsec; in ocelot_ptp_enable()
252 ts_phase.tv_sec = rq->perout.start.sec; in ocelot_ptp_enable()
253 ts_phase.tv_nsec = rq->perout.start.nsec; in ocelot_ptp_enable()
256 dev_warn(ocelot->dev, in ocelot_ptp_enable()
258 dev_warn(ocelot->dev, in ocelot_ptp_enable()
260 return -EINVAL; in ocelot_ptp_enable()
264 if (rq->perout.flags & PTP_PEROUT_DUTY_CYCLE) { in ocelot_ptp_enable()
267 ts_on.tv_sec = rq->perout.on.sec; in ocelot_ptp_enable()
268 ts_on.tv_nsec = rq->perout.on.nsec; in ocelot_ptp_enable()
281 wf_low -= wf_high; in ocelot_ptp_enable()
285 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_enable()
293 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_enable()
299 return -EINVAL; in ocelot_ptp_enable()
301 return -EINVAL; in ocelot_ptp_enable()
303 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_enable()
310 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_ptp_enable()
313 return -EOPNOTSUPP; in ocelot_ptp_enable()
321 trap->key_type = OCELOT_VCAP_KEY_ETYPE; in ocelot_populate_l2_ptp_trap_key()
322 *(__be16 *)trap->key.etype.etype.value = htons(ETH_P_1588); in ocelot_populate_l2_ptp_trap_key()
323 *(__be16 *)trap->key.etype.etype.mask = htons(0xffff); in ocelot_populate_l2_ptp_trap_key()
329 trap->key_type = OCELOT_VCAP_KEY_IPV4; in ocelot_populate_ipv4_ptp_event_trap_key()
330 trap->key.ipv4.proto.value[0] = IPPROTO_UDP; in ocelot_populate_ipv4_ptp_event_trap_key()
331 trap->key.ipv4.proto.mask[0] = 0xff; in ocelot_populate_ipv4_ptp_event_trap_key()
332 trap->key.ipv4.dport.value = PTP_EV_PORT; in ocelot_populate_ipv4_ptp_event_trap_key()
333 trap->key.ipv4.dport.mask = 0xffff; in ocelot_populate_ipv4_ptp_event_trap_key()
339 trap->key_type = OCELOT_VCAP_KEY_IPV6; in ocelot_populate_ipv6_ptp_event_trap_key()
340 trap->key.ipv6.proto.value[0] = IPPROTO_UDP; in ocelot_populate_ipv6_ptp_event_trap_key()
341 trap->key.ipv6.proto.mask[0] = 0xff; in ocelot_populate_ipv6_ptp_event_trap_key()
342 trap->key.ipv6.dport.value = PTP_EV_PORT; in ocelot_populate_ipv6_ptp_event_trap_key()
343 trap->key.ipv6.dport.mask = 0xffff; in ocelot_populate_ipv6_ptp_event_trap_key()
349 trap->key_type = OCELOT_VCAP_KEY_IPV4; in ocelot_populate_ipv4_ptp_general_trap_key()
350 trap->key.ipv4.proto.value[0] = IPPROTO_UDP; in ocelot_populate_ipv4_ptp_general_trap_key()
351 trap->key.ipv4.proto.mask[0] = 0xff; in ocelot_populate_ipv4_ptp_general_trap_key()
352 trap->key.ipv4.dport.value = PTP_GEN_PORT; in ocelot_populate_ipv4_ptp_general_trap_key()
353 trap->key.ipv4.dport.mask = 0xffff; in ocelot_populate_ipv4_ptp_general_trap_key()
359 trap->key_type = OCELOT_VCAP_KEY_IPV6; in ocelot_populate_ipv6_ptp_general_trap_key()
360 trap->key.ipv6.proto.value[0] = IPPROTO_UDP; in ocelot_populate_ipv6_ptp_general_trap_key()
361 trap->key.ipv6.proto.mask[0] = 0xff; in ocelot_populate_ipv6_ptp_general_trap_key()
362 trap->key.ipv6.dport.value = PTP_GEN_PORT; in ocelot_populate_ipv6_ptp_general_trap_key()
363 trap->key.ipv6.dport.mask = 0xffff; in ocelot_populate_ipv6_ptp_general_trap_key()
444 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_setup_ptp_traps()
447 ocelot_port->trap_proto &= ~(OCELOT_PROTO_PTP_L2 | in ocelot_setup_ptp_traps()
474 ocelot_port->trap_proto |= OCELOT_PROTO_PTP_L2; in ocelot_setup_ptp_traps()
476 ocelot_port->trap_proto |= OCELOT_PROTO_PTP_L4; in ocelot_setup_ptp_traps()
516 return -ERANGE; in ocelot_ptp_tx_type_to_cmd()
524 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_hwstamp_get()
527 switch (ocelot_port->ptp_cmd) { in ocelot_hwstamp_get()
539 cfg.rx_filter = ocelot_traps_to_ptp_rx_filter(ocelot_port->trap_proto); in ocelot_hwstamp_get()
541 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; in ocelot_hwstamp_get()
547 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_hwstamp_set()
548 int ptp_cmd, old_ptp_cmd = ocelot_port->ptp_cmd; in ocelot_hwstamp_set()
554 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) in ocelot_hwstamp_set()
555 return -EFAULT; in ocelot_hwstamp_set()
557 /* Tx type sanity check */ in ocelot_hwstamp_set()
582 return -ERANGE; in ocelot_hwstamp_set()
585 old_l2 = ocelot_port->trap_proto & OCELOT_PROTO_PTP_L2; in ocelot_hwstamp_set()
586 old_l4 = ocelot_port->trap_proto & OCELOT_PROTO_PTP_L4; in ocelot_hwstamp_set()
592 ocelot_port->ptp_cmd = ptp_cmd; in ocelot_hwstamp_set()
594 cfg.rx_filter = ocelot_traps_to_ptp_rx_filter(ocelot_port->trap_proto); in ocelot_hwstamp_set()
596 if (copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg))) { in ocelot_hwstamp_set()
597 err = -EFAULT; in ocelot_hwstamp_set()
604 ocelot_port->ptp_cmd = old_ptp_cmd; in ocelot_hwstamp_set()
612 info->phc_index = ocelot->ptp_clock ? in ocelot_get_ts_info()
613 ptp_clock_index(ocelot->ptp_clock) : -1; in ocelot_get_ts_info()
614 if (info->phc_index == -1) { in ocelot_get_ts_info()
615 info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE | in ocelot_get_ts_info()
620 info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE | in ocelot_get_ts_info()
626 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON) | in ocelot_get_ts_info()
628 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | in ocelot_get_ts_info()
641 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_dequeue_ptp_tx_skb()
645 spin_lock(&ocelot->ts_id_lock); in ocelot_port_dequeue_ptp_tx_skb()
647 skb_queue_walk_safe(&ocelot_port->tx_skbs, skb, skb_tmp) { in ocelot_port_dequeue_ptp_tx_skb()
648 if (OCELOT_SKB_CB(skb)->ts_id != ts_id) in ocelot_port_dequeue_ptp_tx_skb()
653 * NULL, because we've pre-validated the packet's ptp_class. in ocelot_port_dequeue_ptp_tx_skb()
655 hdr = ptp_parse_header(skb, OCELOT_SKB_CB(skb)->ptp_class); in ocelot_port_dequeue_ptp_tx_skb()
656 if (seqid != ntohs(hdr->sequence_id)) in ocelot_port_dequeue_ptp_tx_skb()
659 __skb_unlink(skb, &ocelot_port->tx_skbs); in ocelot_port_dequeue_ptp_tx_skb()
660 ocelot->ptp_skbs_in_flight--; in ocelot_port_dequeue_ptp_tx_skb()
665 spin_unlock(&ocelot->ts_id_lock); in ocelot_port_dequeue_ptp_tx_skb()
673 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_queue_ptp_tx_skb()
678 spin_lock(&ocelot->ts_id_lock); in ocelot_port_queue_ptp_tx_skb()
681 * stale packets still waiting in the TX timestamping queue. They are in ocelot_port_queue_ptp_tx_skb()
684 skb_queue_walk_safe(&ocelot_port->tx_skbs, skb, skb_tmp) { in ocelot_port_queue_ptp_tx_skb()
685 if (time_before(OCELOT_SKB_CB(skb)->ptp_tx_time + in ocelot_port_queue_ptp_tx_skb()
687 dev_warn_ratelimited(ocelot->dev, in ocelot_port_queue_ptp_tx_skb()
689 port, OCELOT_SKB_CB(skb)->ts_id); in ocelot_port_queue_ptp_tx_skb()
690 __skb_unlink(skb, &ocelot_port->tx_skbs); in ocelot_port_queue_ptp_tx_skb()
692 ocelot->ptp_skbs_in_flight--; in ocelot_port_queue_ptp_tx_skb()
694 __set_bit(OCELOT_SKB_CB(skb)->ts_id, ts_id_in_flight); in ocelot_port_queue_ptp_tx_skb()
698 if (ocelot->ptp_skbs_in_flight == OCELOT_PTP_FIFO_SIZE) { in ocelot_port_queue_ptp_tx_skb()
699 spin_unlock(&ocelot->ts_id_lock); in ocelot_port_queue_ptp_tx_skb()
700 return -EBUSY; in ocelot_port_queue_ptp_tx_skb()
705 spin_unlock(&ocelot->ts_id_lock); in ocelot_port_queue_ptp_tx_skb()
706 return -EBUSY; in ocelot_port_queue_ptp_tx_skb()
710 OCELOT_SKB_CB(clone)->ts_id = n; in ocelot_port_queue_ptp_tx_skb()
711 OCELOT_SKB_CB(clone)->ptp_tx_time = jiffies; in ocelot_port_queue_ptp_tx_skb()
712 ocelot->ptp_skbs_in_flight++; in ocelot_port_queue_ptp_tx_skb()
713 __skb_queue_tail(&ocelot_port->tx_skbs, clone); in ocelot_port_queue_ptp_tx_skb()
715 spin_unlock(&ocelot->ts_id_lock); in ocelot_port_queue_ptp_tx_skb()
717 dev_dbg_ratelimited(ocelot->dev, "port %d timestamp id %lu\n", port, n); in ocelot_port_queue_ptp_tx_skb()
733 twostep = hdr->flag_field[0] & 0x2; in ocelot_ptp_is_onestep_sync()
745 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_txtstamp_request()
746 u8 ptp_cmd = ocelot_port->ptp_cmd; in ocelot_port_txtstamp_request()
756 return -EINVAL; in ocelot_port_txtstamp_request()
758 /* Store ptp_cmd in OCELOT_SKB_CB(skb)->ptp_cmd */ in ocelot_port_txtstamp_request()
761 OCELOT_SKB_CB(skb)->ptp_cmd = ptp_cmd; in ocelot_port_txtstamp_request()
765 /* Fall back to two-step timestamping */ in ocelot_port_txtstamp_request()
772 return -ENOMEM; in ocelot_port_txtstamp_request()
774 /* Store timestamp ID in OCELOT_SKB_CB(clone)->ts_id */ in ocelot_port_txtstamp_request()
781 skb_shinfo(*clone)->tx_flags |= SKBTX_IN_PROGRESS; in ocelot_port_txtstamp_request()
782 OCELOT_SKB_CB(skb)->ptp_cmd = ptp_cmd; in ocelot_port_txtstamp_request()
783 OCELOT_SKB_CB(*clone)->ptp_class = ptp_class; in ocelot_port_txtstamp_request()
791 struct timespec64 *ts) in ocelot_get_hwtimestamp() argument
796 spin_lock_irqsave(&ocelot->ptp_clock_lock, flags); in ocelot_get_hwtimestamp()
804 ts->tv_sec = ocelot_read_rix(ocelot, PTP_PIN_TOD_SEC_LSB, TOD_ACC_PIN); in ocelot_get_hwtimestamp()
808 ts->tv_nsec = SYS_PTP_TXSTAMP_PTP_TXSTAMP(val); in ocelot_get_hwtimestamp()
810 /* Sec has incremented since the ts was registered */ in ocelot_get_hwtimestamp()
811 if ((ts->tv_sec & 0x1) != !!(val & SYS_PTP_TXSTAMP_PTP_TXSTAMP_SEC)) in ocelot_get_hwtimestamp()
812 ts->tv_sec--; in ocelot_get_hwtimestamp()
814 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags); in ocelot_get_hwtimestamp()
821 while (budget--) { in ocelot_get_txtstamp()
825 struct timespec64 ts; in ocelot_get_txtstamp() local
835 /* Retrieve the ts ID and Tx port */ in ocelot_get_txtstamp()
844 dev_warn_ratelimited(ocelot->dev, in ocelot_get_txtstamp()
845 … "port %d received TX timestamp (seqid %d, ts id %u) for packet previously declared stale\n", in ocelot_get_txtstamp()
851 ocelot_get_hwtimestamp(ocelot, &ts); in ocelot_get_txtstamp()
855 shhwtstamps.hwtstamp = ktime_set(ts.tv_sec, ts.tv_nsec); in ocelot_get_txtstamp()
870 ocelot->ptp_info = *info; in ocelot_init_timestamp()
873 struct ptp_pin_desc *p = &ocelot->ptp_pins[i]; in ocelot_init_timestamp()
875 snprintf(p->name, sizeof(p->name), "switch_1588_dat%d", i); in ocelot_init_timestamp()
876 p->index = i; in ocelot_init_timestamp()
877 p->func = PTP_PF_NONE; in ocelot_init_timestamp()
880 ocelot->ptp_info.pin_config = &ocelot->ptp_pins[0]; in ocelot_init_timestamp()
882 ptp_clock = ptp_clock_register(&ocelot->ptp_info, ocelot->dev); in ocelot_init_timestamp()
889 ocelot->ptp_clock = ptp_clock; in ocelot_init_timestamp()
903 if (ocelot->ptp_clock) in ocelot_deinit_timestamp()
904 ptp_clock_unregister(ocelot->ptp_clock); in ocelot_deinit_timestamp()