Lines Matching +full:extts +full:- +full:fifo
1 // SPDX-License-Identifier: GPL-2.0+
12 * The value is calculated as following: (1/1000000)/((2^-59)/6.037735849)
57 struct lan966x *lan966x = port->lan966x;
61 vrule = vcap_get_rule(lan966x->vcap_ctrl, rule_id);
68 mask &= ~BIT(port->chip_port);
76 vrule = vcap_alloc_rule(lan966x->vcap_ctrl, port->dev,
103 struct lan966x *lan966x = port->lan966x;
108 vrule = vcap_get_rule(lan966x->vcap_ctrl, rule_id);
110 return -EEXIST;
113 mask |= BIT(port->chip_port);
116 if (mask == GENMASK(lan966x->num_phys_ports, 0)) {
117 err = vcap_del_rule(lan966x->vcap_ctrl, port->dev, rule_id);
254 if (cfg->rx_filter == HWTSTAMP_FILTER_NONE)
264 struct lan966x *lan966x = port->lan966x;
267 switch (cfg->tx_type) {
269 port->ptp_tx_cmd = IFH_REW_OP_TWO_STEP_PTP;
272 port->ptp_tx_cmd = IFH_REW_OP_ONE_STEP_PTP;
275 port->ptp_tx_cmd = IFH_REW_OP_NOOP;
278 return -ERANGE;
281 switch (cfg->rx_filter) {
283 port->ptp_rx_cmd = false;
299 port->ptp_rx_cmd = true;
300 cfg->rx_filter = HWTSTAMP_FILTER_ALL;
303 return -ERANGE;
307 mutex_lock(&lan966x->ptp_lock);
308 phc = &lan966x->phc[LAN966X_PHC_PORT];
309 phc->hwtstamp_config = *cfg;
310 mutex_unlock(&lan966x->ptp_lock);
318 struct lan966x *lan966x = port->lan966x;
321 phc = &lan966x->phc[LAN966X_PHC_PORT];
322 *cfg = phc->hwtstamp_config;
332 if (port->ptp_tx_cmd == IFH_REW_OP_NOOP) {
359 if (port->ptp_tx_cmd == IFH_REW_OP_TWO_STEP_PTP) {
381 spin_lock_irqsave(&port->tx_skbs.lock, flags);
382 skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) {
383 if time_after(LAN966X_SKB_CB(skb)->jiffies + LAN966X_PTP_TIMEOUT,
387 __skb_unlink(skb, &port->tx_skbs);
390 spin_unlock_irqrestore(&port->tx_skbs.lock, flags);
396 struct lan966x *lan966x = port->lan966x;
402 LAN966X_SKB_CB(skb)->rew_op = rew_op;
403 LAN966X_SKB_CB(skb)->pdu_type = pdu_type;
410 spin_lock_irqsave(&lan966x->ptp_ts_id_lock, flags);
411 if (lan966x->ptp_skbs == LAN966X_MAX_PTP_ID) {
412 spin_unlock_irqrestore(&lan966x->ptp_ts_id_lock, flags);
413 return -EBUSY;
416 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
418 skb_queue_tail(&port->tx_skbs, skb);
419 LAN966X_SKB_CB(skb)->ts_id = port->ts_id;
420 LAN966X_SKB_CB(skb)->jiffies = jiffies;
422 lan966x->ptp_skbs++;
423 port->ts_id++;
424 if (port->ts_id == LAN966X_MAX_PTP_ID)
425 port->ts_id = 0;
427 spin_unlock_irqrestore(&lan966x->ptp_ts_id_lock, flags);
435 struct lan966x *lan966x = port->lan966x;
438 spin_lock_irqsave(&lan966x->ptp_ts_id_lock, flags);
439 port->ts_id--;
440 lan966x->ptp_skbs--;
441 skb_unlink(skb, &port->tx_skbs);
442 spin_unlock_irqrestore(&lan966x->ptp_ts_id_lock, flags);
453 spin_lock_irqsave(&lan966x->ptp_clock_lock, flags);
463 ts->tv_sec = lan_rd(lan966x, PTP_TOD_SEC_LSB(TOD_ACC_PIN));
466 ts->tv_nsec = nsec;
470 ts->tv_sec--;
472 spin_unlock_irqrestore(&lan966x->ptp_clock_lock, flags);
480 while (budget--) {
504 port = lan966x->ports[txport];
510 /* Get next timestamp from fifo, which needs to be the
526 spin_lock_irqsave(&port->tx_skbs.lock, flags);
527 skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) {
528 if (LAN966X_SKB_CB(skb)->ts_id != id)
531 __skb_unlink(skb, &port->tx_skbs);
535 spin_unlock_irqrestore(&port->tx_skbs.lock, flags);
545 spin_lock_irqsave(&lan966x->ptp_ts_id_lock, flags);
546 lan966x->ptp_skbs--;
547 spin_unlock_irqrestore(&lan966x->ptp_ts_id_lock, flags);
579 phc = &lan966x->phc[i];
580 pin = ptp_find_pin_unlocked(phc->clock, PTP_PF_EXTTS, 0);
581 if (pin == -1)
587 spin_lock_irqsave(&lan966x->ptp_clock_lock, flags);
601 spin_unlock_irqrestore(&lan966x->ptp_clock_lock, flags);
604 s--;
613 ptp_clock_event(phc->clock, &ptp_event);
622 struct lan966x *lan966x = phc->lan966x;
633 scaled_ppm = -scaled_ppm;
644 tod_inc = neg_adj ? tod_inc - ref : tod_inc + ref;
646 spin_lock_irqsave(&lan966x->ptp_clock_lock, flags);
648 lan_rmw(PTP_DOM_CFG_CLKCFG_DIS_SET(1 << BIT(phc->index)),
653 PTP_CLK_PER_CFG(phc->index, 0));
655 PTP_CLK_PER_CFG(phc->index, 1));
661 spin_unlock_irqrestore(&lan966x->ptp_clock_lock, flags);
670 struct lan966x *lan966x = phc->lan966x;
673 spin_lock_irqsave(&lan966x->ptp_clock_lock, flags);
677 PTP_PIN_CFG_PIN_DOM_SET(phc->index) |
685 lan_wr(PTP_TOD_SEC_MSB_TOD_SEC_MSB_SET(upper_32_bits(ts->tv_sec)),
687 lan_wr(lower_32_bits(ts->tv_sec),
689 lan_wr(ts->tv_nsec, lan966x, PTP_TOD_NSEC(TOD_ACC_PIN));
693 PTP_PIN_CFG_PIN_DOM_SET(phc->index) |
700 spin_unlock_irqrestore(&lan966x->ptp_clock_lock, flags);
708 struct lan966x *lan966x = phc->lan966x;
713 spin_lock_irqsave(&lan966x->ptp_clock_lock, flags);
716 PTP_PIN_CFG_PIN_DOM_SET(phc->index) |
729 spin_unlock_irqrestore(&lan966x->ptp_clock_lock, flags);
733 s--;
745 struct lan966x *lan966x = phc->lan966x;
747 if (delta > -(NSEC_PER_SEC / 2) && delta < (NSEC_PER_SEC / 2)) {
750 spin_lock_irqsave(&lan966x->ptp_clock_lock, flags);
754 PTP_PIN_CFG_PIN_DOM_SET(phc->index) |
766 PTP_PIN_CFG_PIN_DOM_SET(phc->index) |
773 spin_unlock_irqrestore(&lan966x->ptp_clock_lock, flags);
794 struct lan966x *lan966x = phc->lan966x;
800 return -1;
808 return -1;
816 info = &lan966x->phc[i].info;
822 if (info->pin_config[pin].func == PTP_PF_PEROUT ||
823 info->pin_config[pin].func == PTP_PF_EXTTS)
824 return -1;
834 struct lan966x *lan966x = phc->lan966x;
841 pin = ptp_find_pin(phc->clock, PTP_PF_PEROUT, rq->perout.index);
842 if (pin == -1 || pin >= LAN966X_PHC_PINS_NUM)
843 return -EINVAL;
846 spin_lock_irqsave(&lan966x->ptp_clock_lock, flags);
848 PTP_PIN_CFG_PIN_DOM_SET(phc->index) |
854 spin_unlock_irqrestore(&lan966x->ptp_clock_lock, flags);
858 if (rq->perout.period.sec == 1 &&
859 rq->perout.period.nsec == 0)
862 if (rq->perout.flags & PTP_PEROUT_PHASE) {
863 ts_phase.tv_sec = rq->perout.phase.sec;
864 ts_phase.tv_nsec = rq->perout.phase.nsec;
866 ts_phase.tv_sec = rq->perout.start.sec;
867 ts_phase.tv_nsec = rq->perout.start.nsec;
871 dev_warn(lan966x->dev,
873 return -EINVAL;
876 if (rq->perout.flags & PTP_PEROUT_DUTY_CYCLE) {
879 ts_on.tv_sec = rq->perout.on.sec;
880 ts_on.tv_nsec = rq->perout.on.nsec;
888 spin_lock_irqsave(&lan966x->ptp_clock_lock, flags);
894 PTP_PIN_CFG_PIN_DOM_SET(phc->index) |
900 spin_unlock_irqrestore(&lan966x->ptp_clock_lock, flags);
904 ts_period.tv_sec = rq->perout.period.sec;
905 ts_period.tv_nsec = rq->perout.period.nsec;
908 wf_low -= wf_high;
910 spin_lock_irqsave(&lan966x->ptp_clock_lock, flags);
916 PTP_PIN_CFG_PIN_DOM_SET(phc->index) |
922 spin_unlock_irqrestore(&lan966x->ptp_clock_lock, flags);
931 struct lan966x *lan966x = phc->lan966x;
936 if (lan966x->ptp_ext_irq <= 0)
937 return -EOPNOTSUPP;
939 pin = ptp_find_pin(phc->clock, PTP_PF_EXTTS, rq->extts.index);
940 if (pin == -1 || pin >= LAN966X_PHC_PINS_NUM)
941 return -EINVAL;
943 spin_lock_irqsave(&lan966x->ptp_clock_lock, flags);
946 PTP_PIN_CFG_PIN_DOM_SET(phc->index) |
961 spin_unlock_irqrestore(&lan966x->ptp_clock_lock, flags);
969 switch (rq->type) {
975 return -EOPNOTSUPP;
1004 struct lan966x_phc *phc = &lan966x->phc[index];
1009 p = &phc->pins[i];
1011 snprintf(p->name, sizeof(p->name), "pin%d", i);
1012 p->index = i;
1013 p->func = PTP_PF_NONE;
1016 phc->info = *clock_info;
1017 phc->info.pin_config = &phc->pins[0];
1018 phc->clock = ptp_clock_register(&phc->info, lan966x->dev);
1019 if (IS_ERR(phc->clock))
1020 return PTR_ERR(phc->clock);
1022 phc->index = index;
1023 phc->lan966x = lan966x;
1034 if (!lan966x->ptp)
1043 spin_lock_init(&lan966x->ptp_clock_lock);
1044 spin_lock_init(&lan966x->ptp_ts_id_lock);
1045 mutex_init(&lan966x->ptp_lock);
1069 for (i = 0; i < lan966x->num_phys_ports; i++) {
1070 port = lan966x->ports[i];
1074 skb_queue_head_init(&port->tx_skbs);
1085 if (!lan966x->ptp)
1088 for (i = 0; i < lan966x->num_phys_ports; i++) {
1089 port = lan966x->ports[i];
1093 skb_queue_purge(&port->tx_skbs);
1097 ptp_clock_unregister(lan966x->phc[i].clock);
1108 if (!lan966x->ptp ||
1109 !lan966x->ports[src_port]->ptp_rx_cmd)
1112 phc = &lan966x->phc[LAN966X_PHC_PORT];
1113 lan966x_ptp_gettime64(&phc->info, &ts);
1115 /* Drop the sub-ns precision */
1118 ts.tv_sec--;
1123 shhwtstamps->hwtstamp = full_ts_in_ns;