Lines Matching +full:tx +full:- +full:sec
1 /* SPDX-License-Identifier: GPL-2.0+ */
37 return -EINVAL; in lan743x_get_channel()
42 struct lan743x_gpio *gpio = &adapter->gpio; in lan743x_gpio_init()
44 spin_lock_init(&gpio->gpio_lock); in lan743x_gpio_init()
46 gpio->gpio_cfg0 = 0; /* set all direction to input, data = 0 */ in lan743x_gpio_init()
47 gpio->gpio_cfg1 = 0x0FFF0000;/* disable all gpio, set to open drain */ in lan743x_gpio_init()
48 gpio->gpio_cfg2 = 0;/* set all to 1588 low polarity level */ in lan743x_gpio_init()
49 gpio->gpio_cfg3 = 0;/* disable all 1588 output */ in lan743x_gpio_init()
50 lan743x_csr_write(adapter, GPIO_CFG0, gpio->gpio_cfg0); in lan743x_gpio_init()
51 lan743x_csr_write(adapter, GPIO_CFG1, gpio->gpio_cfg1); in lan743x_gpio_init()
52 lan743x_csr_write(adapter, GPIO_CFG2, gpio->gpio_cfg2); in lan743x_gpio_init()
53 lan743x_csr_write(adapter, GPIO_CFG3, gpio->gpio_cfg3); in lan743x_gpio_init()
68 timeout--; in lan743x_ptp_wait_till_cmd_done()
71 netif_err(adapter, drv, adapter->netdev, in lan743x_ptp_wait_till_cmd_done()
81 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_tx_ts_enqueue_ts()
83 spin_lock_bh(&ptp->tx_ts_lock); in lan743x_ptp_tx_ts_enqueue_ts()
84 if (ptp->tx_ts_queue_size < LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS) { in lan743x_ptp_tx_ts_enqueue_ts()
85 ptp->tx_ts_seconds_queue[ptp->tx_ts_queue_size] = seconds; in lan743x_ptp_tx_ts_enqueue_ts()
86 ptp->tx_ts_nseconds_queue[ptp->tx_ts_queue_size] = nano_seconds; in lan743x_ptp_tx_ts_enqueue_ts()
87 ptp->tx_ts_header_queue[ptp->tx_ts_queue_size] = header; in lan743x_ptp_tx_ts_enqueue_ts()
88 ptp->tx_ts_queue_size++; in lan743x_ptp_tx_ts_enqueue_ts()
90 netif_err(adapter, drv, adapter->netdev, in lan743x_ptp_tx_ts_enqueue_ts()
91 "tx ts queue overflow\n"); in lan743x_ptp_tx_ts_enqueue_ts()
93 spin_unlock_bh(&ptp->tx_ts_lock); in lan743x_ptp_tx_ts_enqueue_ts()
98 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_tx_ts_complete()
105 spin_lock_bh(&ptp->tx_ts_lock); in lan743x_ptp_tx_ts_complete()
106 c = ptp->tx_ts_skb_queue_size; in lan743x_ptp_tx_ts_complete()
108 if (c > ptp->tx_ts_queue_size) in lan743x_ptp_tx_ts_complete()
109 c = ptp->tx_ts_queue_size; in lan743x_ptp_tx_ts_complete()
114 ignore_sync = ((ptp->tx_ts_ignore_sync_queue & in lan743x_ptp_tx_ts_complete()
116 skb = ptp->tx_ts_skb_queue[i]; in lan743x_ptp_tx_ts_complete()
117 nseconds = ptp->tx_ts_nseconds_queue[i]; in lan743x_ptp_tx_ts_complete()
118 seconds = ptp->tx_ts_seconds_queue[i]; in lan743x_ptp_tx_ts_complete()
119 header = ptp->tx_ts_header_queue[i]; in lan743x_ptp_tx_ts_complete()
130 ptp->tx_ts_skb_queue[i] = NULL; in lan743x_ptp_tx_ts_complete()
131 ptp->tx_ts_seconds_queue[i] = 0; in lan743x_ptp_tx_ts_complete()
132 ptp->tx_ts_nseconds_queue[i] = 0; in lan743x_ptp_tx_ts_complete()
133 ptp->tx_ts_header_queue[i] = 0; in lan743x_ptp_tx_ts_complete()
137 ptp->tx_ts_ignore_sync_queue >>= c; in lan743x_ptp_tx_ts_complete()
139 ptp->tx_ts_skb_queue[i - c] = ptp->tx_ts_skb_queue[i]; in lan743x_ptp_tx_ts_complete()
140 ptp->tx_ts_seconds_queue[i - c] = ptp->tx_ts_seconds_queue[i]; in lan743x_ptp_tx_ts_complete()
141 ptp->tx_ts_nseconds_queue[i - c] = ptp->tx_ts_nseconds_queue[i]; in lan743x_ptp_tx_ts_complete()
142 ptp->tx_ts_header_queue[i - c] = ptp->tx_ts_header_queue[i]; in lan743x_ptp_tx_ts_complete()
144 ptp->tx_ts_skb_queue[i] = NULL; in lan743x_ptp_tx_ts_complete()
145 ptp->tx_ts_seconds_queue[i] = 0; in lan743x_ptp_tx_ts_complete()
146 ptp->tx_ts_nseconds_queue[i] = 0; in lan743x_ptp_tx_ts_complete()
147 ptp->tx_ts_header_queue[i] = 0; in lan743x_ptp_tx_ts_complete()
149 ptp->tx_ts_skb_queue_size -= c; in lan743x_ptp_tx_ts_complete()
150 ptp->tx_ts_queue_size -= c; in lan743x_ptp_tx_ts_complete()
152 ptp->pending_tx_timestamps -= c; in lan743x_ptp_tx_ts_complete()
153 spin_unlock_bh(&ptp->tx_ts_lock); in lan743x_ptp_tx_ts_complete()
159 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_reserve_event_ch()
160 int result = -ENODEV; in lan743x_ptp_reserve_event_ch()
162 mutex_lock(&ptp->command_lock); in lan743x_ptp_reserve_event_ch()
163 if (!(test_bit(event_channel, &ptp->used_event_ch))) { in lan743x_ptp_reserve_event_ch()
164 ptp->used_event_ch |= BIT(event_channel); in lan743x_ptp_reserve_event_ch()
167 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_reserve_event_ch()
171 mutex_unlock(&ptp->command_lock); in lan743x_ptp_reserve_event_ch()
178 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_release_event_ch()
180 mutex_lock(&ptp->command_lock); in lan743x_ptp_release_event_ch()
181 if (test_bit(event_channel, &ptp->used_event_ch)) { in lan743x_ptp_release_event_ch()
182 ptp->used_event_ch &= ~BIT(event_channel); in lan743x_ptp_release_event_ch()
184 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_release_event_ch()
188 mutex_unlock(&ptp->command_lock); in lan743x_ptp_release_event_ch()
195 u32 *sec, u32 *nsec, u32 *sub_nsec);
202 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_led_mux_enable()
204 if (ptp->leds_multiplexed && in lan743x_led_mux_enable()
205 ptp->led_enabled[pin]) { in lan743x_led_mux_enable()
219 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_led_mux_save()
220 u32 id_rev = adapter->csr.id_rev & ID_REV_ID_MASK_; in lan743x_led_mux_save()
229 ptp->led_enabled[i] = led_enabled; in lan743x_led_mux_save()
231 ptp->leds_multiplexed = true; in lan743x_led_mux_save()
233 ptp->leds_multiplexed = false; in lan743x_led_mux_save()
239 u32 id_rev = adapter->csr.id_rev & ID_REV_ID_MASK_; in lan743x_led_mux_restore()
252 struct lan743x_gpio *gpio = &adapter->gpio; in lan743x_gpio_rsrv_ptp_out()
255 int ret = -EBUSY; in lan743x_gpio_rsrv_ptp_out()
257 spin_lock_irqsave(&gpio->gpio_lock, irq_flags); in lan743x_gpio_rsrv_ptp_out()
259 if (!(gpio->used_bits & bit_mask)) { in lan743x_gpio_rsrv_ptp_out()
260 gpio->used_bits |= bit_mask; in lan743x_gpio_rsrv_ptp_out()
261 gpio->output_bits |= bit_mask; in lan743x_gpio_rsrv_ptp_out()
262 gpio->ptp_bits |= bit_mask; in lan743x_gpio_rsrv_ptp_out()
268 gpio->gpio_cfg0 |= GPIO_CFG0_GPIO_DIR_BIT_(pin); in lan743x_gpio_rsrv_ptp_out()
269 gpio->gpio_cfg0 &= ~GPIO_CFG0_GPIO_DATA_BIT_(pin); in lan743x_gpio_rsrv_ptp_out()
270 lan743x_csr_write(adapter, GPIO_CFG0, gpio->gpio_cfg0); in lan743x_gpio_rsrv_ptp_out()
273 gpio->gpio_cfg1 &= ~GPIO_CFG1_GPIOEN_BIT_(pin); in lan743x_gpio_rsrv_ptp_out()
274 gpio->gpio_cfg1 |= GPIO_CFG1_GPIOBUF_BIT_(pin); in lan743x_gpio_rsrv_ptp_out()
275 lan743x_csr_write(adapter, GPIO_CFG1, gpio->gpio_cfg1); in lan743x_gpio_rsrv_ptp_out()
278 gpio->gpio_cfg2 |= GPIO_CFG2_1588_POL_BIT_(pin); in lan743x_gpio_rsrv_ptp_out()
279 lan743x_csr_write(adapter, GPIO_CFG2, gpio->gpio_cfg2); in lan743x_gpio_rsrv_ptp_out()
283 gpio->gpio_cfg3 &= ~GPIO_CFG3_1588_CH_SEL_BIT_(pin); in lan743x_gpio_rsrv_ptp_out()
286 gpio->gpio_cfg3 |= GPIO_CFG3_1588_CH_SEL_BIT_(pin); in lan743x_gpio_rsrv_ptp_out()
288 gpio->gpio_cfg3 |= GPIO_CFG3_1588_OE_BIT_(pin); in lan743x_gpio_rsrv_ptp_out()
289 lan743x_csr_write(adapter, GPIO_CFG3, gpio->gpio_cfg3); in lan743x_gpio_rsrv_ptp_out()
293 spin_unlock_irqrestore(&gpio->gpio_lock, irq_flags); in lan743x_gpio_rsrv_ptp_out()
299 struct lan743x_gpio *gpio = &adapter->gpio; in lan743x_gpio_release()
303 spin_lock_irqsave(&gpio->gpio_lock, irq_flags); in lan743x_gpio_release()
304 if (gpio->used_bits & bit_mask) { in lan743x_gpio_release()
305 gpio->used_bits &= ~bit_mask; in lan743x_gpio_release()
306 if (gpio->output_bits & bit_mask) { in lan743x_gpio_release()
307 gpio->output_bits &= ~bit_mask; in lan743x_gpio_release()
309 if (gpio->ptp_bits & bit_mask) { in lan743x_gpio_release()
310 gpio->ptp_bits &= ~bit_mask; in lan743x_gpio_release()
312 gpio->gpio_cfg3 &= ~GPIO_CFG3_1588_OE_BIT_(pin); in lan743x_gpio_release()
314 gpio->gpio_cfg3); in lan743x_gpio_release()
319 gpio->gpio_cfg1 |= GPIO_CFG1_GPIOEN_BIT_(pin); in lan743x_gpio_release()
320 gpio->gpio_cfg1 &= ~GPIO_CFG1_GPIOBUF_BIT_(pin); in lan743x_gpio_release()
321 lan743x_csr_write(adapter, GPIO_CFG1, gpio->gpio_cfg1); in lan743x_gpio_release()
324 gpio->gpio_cfg0 &= ~GPIO_CFG0_GPIO_DIR_BIT_(pin); in lan743x_gpio_release()
325 gpio->gpio_cfg0 &= ~GPIO_CFG0_GPIO_DATA_BIT_(pin); in lan743x_gpio_release()
326 lan743x_csr_write(adapter, GPIO_CFG0, gpio->gpio_cfg0); in lan743x_gpio_release()
332 spin_unlock_irqrestore(&gpio->gpio_lock, irq_flags); in lan743x_gpio_release()
344 if ((scaled_ppm < (-LAN743X_PTP_MAX_FINE_ADJ_IN_SCALED_PPM)) || in lan743x_ptpci_adjfine()
346 return -EINVAL; in lan743x_ptpci_adjfine()
383 if (adapter->is_pci11x1x) in lan743x_ptpci_gettime64()
388 ts->tv_sec = seconds; in lan743x_ptpci_gettime64()
389 ts->tv_nsec = nano_seconds; in lan743x_ptpci_gettime64()
404 if (ts->tv_sec > 0xFFFFFFFFLL) { in lan743x_ptpci_settime64()
405 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptpci_settime64()
406 "ts->tv_sec out of range, %lld\n", in lan743x_ptpci_settime64()
407 ts->tv_sec); in lan743x_ptpci_settime64()
408 return -ERANGE; in lan743x_ptpci_settime64()
410 if (ts->tv_nsec < 0) { in lan743x_ptpci_settime64()
411 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptpci_settime64()
412 "ts->tv_nsec out of range, %ld\n", in lan743x_ptpci_settime64()
413 ts->tv_nsec); in lan743x_ptpci_settime64()
414 return -ERANGE; in lan743x_ptpci_settime64()
416 seconds = ts->tv_sec; in lan743x_ptpci_settime64()
417 nano_seconds = ts->tv_nsec; in lan743x_ptpci_settime64()
426 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_perout_off()
428 struct lan743x_ptp_perout *perout = &ptp->perout[index]; in lan743x_ptp_perout_off()
430 if (perout->gpio_pin >= 0) { in lan743x_ptp_perout_off()
431 lan743x_gpio_release(adapter, perout->gpio_pin); in lan743x_ptp_perout_off()
432 perout->gpio_pin = -1; in lan743x_ptp_perout_off()
435 if (perout->event_ch >= 0) { in lan743x_ptp_perout_off()
438 PTP_CLOCK_TARGET_SEC_X(perout->event_ch), in lan743x_ptp_perout_off()
441 PTP_CLOCK_TARGET_NS_X(perout->event_ch), in lan743x_ptp_perout_off()
446 (perout->event_ch); in lan743x_ptp_perout_off()
448 lan743x_ptp_release_event_ch(adapter, perout->event_ch); in lan743x_ptp_perout_off()
449 perout->event_ch = -1; in lan743x_ptp_perout_off()
456 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_perout()
462 unsigned int index = perout_request->index; in lan743x_ptp_perout()
463 struct lan743x_ptp_perout *perout = &ptp->perout[index]; in lan743x_ptp_perout()
467 if (perout_request->flags & ~PTP_PEROUT_DUTY_CYCLE) in lan743x_ptp_perout()
468 return -EOPNOTSUPP; in lan743x_ptp_perout()
471 perout_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT, in lan743x_ptp_perout()
472 perout_request->index); in lan743x_ptp_perout()
474 return -EBUSY; in lan743x_ptp_perout()
480 if (perout->event_ch >= 0 || in lan743x_ptp_perout()
481 perout->gpio_pin >= 0) { in lan743x_ptp_perout()
486 perout->event_ch = lan743x_ptp_reserve_event_ch(adapter, index); in lan743x_ptp_perout()
488 if (perout->event_ch < 0) { in lan743x_ptp_perout()
489 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_perout()
492 ret = -EBUSY; in lan743x_ptp_perout()
496 perout->gpio_pin = lan743x_gpio_rsrv_ptp_out(adapter, in lan743x_ptp_perout()
498 perout->event_ch); in lan743x_ptp_perout()
500 if (perout->gpio_pin < 0) { in lan743x_ptp_perout()
501 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_perout()
504 ret = -EBUSY; in lan743x_ptp_perout()
508 start_sec = perout_request->start.sec; in lan743x_ptp_perout()
509 start_sec += perout_request->start.nsec / 1000000000; in lan743x_ptp_perout()
510 start_nsec = perout_request->start.nsec % 1000000000; in lan743x_ptp_perout()
512 period_sec = perout_request->period.sec; in lan743x_ptp_perout()
513 period_sec += perout_request->period.nsec / 1000000000; in lan743x_ptp_perout()
514 period_nsec = perout_request->period.nsec % 1000000000; in lan743x_ptp_perout()
516 if (perout_request->flags & PTP_PEROUT_DUTY_CYCLE) { in lan743x_ptp_perout()
521 ts_on.tv_sec = perout_request->on.sec; in lan743x_ptp_perout()
522 ts_on.tv_nsec = perout_request->on.nsec; in lan743x_ptp_perout()
524 ts_period.tv_sec = perout_request->period.sec; in lan743x_ptp_perout()
525 ts_period.tv_nsec = perout_request->period.nsec; in lan743x_ptp_perout()
529 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_perout()
531 ret = -EOPNOTSUPP; in lan743x_ptp_perout()
535 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_perout()
537 ret = -EINVAL; in lan743x_ptp_perout()
543 * pulse width is the same as one of pre-defined width values. in lan743x_ptp_perout()
573 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_perout()
575 ret = -EOPNOTSUPP; in lan743x_ptp_perout()
593 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_perout()
595 ret = -EOPNOTSUPP; in lan743x_ptp_perout()
606 PTP_CLOCK_TARGET_SEC_X(perout->event_ch), in lan743x_ptp_perout()
609 PTP_CLOCK_TARGET_NS_X(perout->event_ch), 0); in lan743x_ptp_perout()
614 (perout->event_ch)); in lan743x_ptp_perout()
616 (perout->event_ch, pulse_width); in lan743x_ptp_perout()
618 (perout->event_ch); in lan743x_ptp_perout()
623 PTP_CLOCK_TARGET_RELOAD_SEC_X(perout->event_ch), in lan743x_ptp_perout()
626 PTP_CLOCK_TARGET_RELOAD_NS_X(perout->event_ch), in lan743x_ptp_perout()
631 PTP_CLOCK_TARGET_SEC_X(perout->event_ch), in lan743x_ptp_perout()
634 PTP_CLOCK_TARGET_NS_X(perout->event_ch), in lan743x_ptp_perout()
647 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_io_perout_off()
653 event_ch = ptp->ptp_io_perout[index]; in lan743x_ptp_io_perout_off()
676 ptp->ptp_io_perout[index] = -1; in lan743x_ptp_io_perout_off()
679 perout_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT, index); in lan743x_ptp_io_perout_off()
699 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_io_perout()
710 index = perout_request->index; in lan743x_ptp_io_perout()
711 event_ch = ptp->ptp_io_perout[index]; in lan743x_ptp_io_perout()
714 perout_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT, index); in lan743x_ptp_io_perout()
716 return -EBUSY; in lan743x_ptp_io_perout()
729 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_io_perout()
734 ptp->ptp_io_perout[index] = event_ch; in lan743x_ptp_io_perout()
736 if (perout_request->flags & PTP_PEROUT_DUTY_CYCLE) { in lan743x_ptp_io_perout()
737 pulse_sec = perout_request->on.sec; in lan743x_ptp_io_perout()
738 pulse_sec += perout_request->on.nsec / 1000000000; in lan743x_ptp_io_perout()
739 pulse_nsec = perout_request->on.nsec % 1000000000; in lan743x_ptp_io_perout()
741 pulse_sec = perout_request->period.sec; in lan743x_ptp_io_perout()
742 pulse_sec += perout_request->period.nsec / 1000000000; in lan743x_ptp_io_perout()
743 pulse_nsec = perout_request->period.nsec % 1000000000; in lan743x_ptp_io_perout()
776 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_io_perout()
801 period_sec = perout_request->period.sec; in lan743x_ptp_io_perout()
802 period_sec += perout_request->period.nsec / 1000000000; in lan743x_ptp_io_perout()
803 period_nsec = perout_request->period.nsec % 1000000000; in lan743x_ptp_io_perout()
811 start_sec = perout_request->start.sec; in lan743x_ptp_io_perout()
812 start_sec += perout_request->start.nsec / 1000000000; in lan743x_ptp_io_perout()
813 start_nsec = perout_request->start.nsec % 1000000000; in lan743x_ptp_io_perout()
850 return -ENODEV; in lan743x_ptp_io_perout()
856 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_io_extts_off()
860 extts = &ptp->extts[index]; in lan743x_ptp_io_extts_off()
862 if (extts->flags & PTP_FALLING_EDGE) in lan743x_ptp_io_extts_off()
868 /* Disables PTP-IO edge lock */ in lan743x_ptp_io_extts_off()
870 if (extts->flags & PTP_FALLING_EDGE) { in lan743x_ptp_io_extts_off()
879 /* PTP-IO De-select register */ in lan743x_ptp_io_extts_off()
885 memset(&extts->ts, 0, sizeof(struct timespec64)); in lan743x_ptp_io_extts_off()
886 extts->flags = 0; in lan743x_ptp_io_extts_off()
892 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_io_event_cap_en()
896 return -EOPNOTSUPP; in lan743x_ptp_io_event_cap_en()
898 mutex_lock(&ptp->command_lock); in lan743x_ptp_io_event_cap_en()
899 /* PTP-IO Event Capture Enable */ in lan743x_ptp_io_event_cap_en()
915 /* PTP-IO Select */ in lan743x_ptp_io_event_cap_en()
928 mutex_unlock(&ptp->command_lock); in lan743x_ptp_io_event_cap_en()
936 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_io_extts()
937 u32 flags = extts_request->flags; in lan743x_ptp_io_extts()
938 u32 index = extts_request->index; in lan743x_ptp_io_extts()
943 extts = &ptp->extts[index]; in lan743x_ptp_io_extts()
946 extts_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, index); in lan743x_ptp_io_extts()
948 return -EBUSY; in lan743x_ptp_io_extts()
952 extts->flags = flags; in lan743x_ptp_io_extts()
969 switch (request->type) { in lan743x_ptpci_enable()
971 if (request->extts.index < ptpci->n_ext_ts) in lan743x_ptpci_enable()
973 &request->extts); in lan743x_ptpci_enable()
974 return -EINVAL; in lan743x_ptpci_enable()
976 if (request->perout.index < ptpci->n_per_out) { in lan743x_ptpci_enable()
977 if (adapter->is_pci11x1x) in lan743x_ptpci_enable()
979 &request->perout); in lan743x_ptpci_enable()
982 &request->perout); in lan743x_ptpci_enable()
984 return -EINVAL; in lan743x_ptpci_enable()
986 return -EINVAL; in lan743x_ptpci_enable()
988 netif_err(adapter, drv, adapter->netdev, in lan743x_ptpci_enable()
989 "request->type == %d, Unknown\n", in lan743x_ptpci_enable()
990 request->type); in lan743x_ptpci_enable()
994 netif_err(adapter, drv, adapter->netdev, "request == NULL\n"); in lan743x_ptpci_enable()
1018 if (!adapter->is_pci11x1x) in lan743x_ptpci_verify_pin_config()
1019 result = -1; in lan743x_ptpci_verify_pin_config()
1023 result = -1; in lan743x_ptpci_verify_pin_config()
1033 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_io_event_clock_get()
1035 u32 sec, nsec; in lan743x_ptp_io_event_clock_get() local
1037 mutex_lock(&ptp->command_lock); in lan743x_ptp_io_event_clock_get()
1039 sec = lan743x_csr_read(adapter, PTP_IO_FE_LTC_SEC_CAP_X); in lan743x_ptp_io_event_clock_get()
1042 sec = lan743x_csr_read(adapter, PTP_IO_RE_LTC_SEC_CAP_X); in lan743x_ptp_io_event_clock_get()
1046 mutex_unlock(&ptp->command_lock); in lan743x_ptp_io_event_clock_get()
1049 extts = &ptp->extts[channel]; in lan743x_ptp_io_event_clock_get()
1050 extts->ts.tv_sec = sec; in lan743x_ptp_io_event_clock_get()
1051 extts->ts.tv_nsec = nsec; in lan743x_ptp_io_event_clock_get()
1052 ts->tv_sec = sec; in lan743x_ptp_io_event_clock_get()
1053 ts->tv_nsec = nsec; in lan743x_ptp_io_event_clock_get()
1098 netif_err(adapter, drv, adapter->netdev, in lan743x_ptpci_do_aux_work()
1101 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptpci_do_aux_work()
1102 "unknown tx timestamp capture cause\n"); in lan743x_ptpci_do_aux_work()
1105 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptpci_do_aux_work()
1106 "TX TS INT but no TX TS CNT\n"); in lan743x_ptpci_do_aux_work()
1128 ptp_clock_event(ptp->ptp_clock, in lan743x_ptpci_do_aux_work()
1161 ptp_clock_event(ptp->ptp_clock, in lan743x_ptpci_do_aux_work()
1186 return -1; in lan743x_ptpci_do_aux_work()
1193 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_clock_get()
1195 mutex_lock(&ptp->command_lock); in lan743x_ptp_clock_get()
1210 mutex_unlock(&ptp->command_lock); in lan743x_ptp_clock_get()
1214 u32 *sec, u32 *nsec, u32 *sub_nsec) in lan743x_ptp_io_clock_get() argument
1216 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_io_clock_get()
1218 mutex_lock(&ptp->command_lock); in lan743x_ptp_io_clock_get()
1222 if (sec) in lan743x_ptp_io_clock_get()
1223 (*sec) = lan743x_csr_read(adapter, PTP_LTC_RD_SEC_LO); in lan743x_ptp_io_clock_get()
1232 mutex_unlock(&ptp->command_lock); in lan743x_ptp_io_clock_get()
1238 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_clock_step()
1248 if (adapter->is_pci11x1x) in lan743x_ptp_clock_step()
1259 nano_seconds -= 1000000000; in lan743x_ptp_clock_step()
1264 } else if (time_step_ns < -15000000000LL) { in lan743x_ptp_clock_step()
1266 time_step_ns = -time_step_ns; in lan743x_ptp_clock_step()
1268 if (adapter->is_pci11x1x) { in lan743x_ptp_clock_step()
1275 unsigned_seconds -= div_u64_rem(time_step_ns, 1000000000LL, in lan743x_ptp_clock_step()
1279 unsigned_seconds--; in lan743x_ptp_clock_step()
1282 nano_seconds -= nano_seconds_step; in lan743x_ptp_clock_step()
1295 abs_time_step_ns = (u64)(-time_step_ns); in lan743x_ptp_clock_step()
1296 seconds = -((s32)div_u64_rem(abs_time_step_ns, 1000000000, in lan743x_ptp_clock_step()
1304 seconds--; in lan743x_ptp_clock_step()
1305 nano_seconds = (1000000000 - nano_seconds); in lan743x_ptp_clock_step()
1317 nano_seconds -= 1000000000; in lan743x_ptp_clock_step()
1321 mutex_lock(&ptp->command_lock); in lan743x_ptp_clock_step()
1330 seconds -= ((s32)adjustment_value); in lan743x_ptp_clock_step()
1332 u32 adjustment_value = (u32)(-seconds); in lan743x_ptp_clock_step()
1344 mutex_unlock(&ptp->command_lock); in lan743x_ptp_clock_step()
1347 mutex_lock(&ptp->command_lock); in lan743x_ptp_clock_step()
1356 mutex_unlock(&ptp->command_lock); in lan743x_ptp_clock_step()
1367 ptp = &adapter->ptp; in lan743x_ptp_isr()
1375 ptp_schedule_worker(ptp->ptp_clock, 0); in lan743x_ptp_isr()
1376 enable_flag = 0;/* tasklet will re-enable later */ in lan743x_ptp_isr()
1379 netif_err(adapter, drv, adapter->netdev, in lan743x_ptp_isr()
1380 "PTP TX Software Timestamp Error\n"); in lan743x_ptp_isr()
1397 /* re-enable isr */ in lan743x_ptp_isr()
1405 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_tx_ts_enqueue_skb()
1407 spin_lock_bh(&ptp->tx_ts_lock); in lan743x_ptp_tx_ts_enqueue_skb()
1408 if (ptp->tx_ts_skb_queue_size < LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS) { in lan743x_ptp_tx_ts_enqueue_skb()
1409 ptp->tx_ts_skb_queue[ptp->tx_ts_skb_queue_size] = skb; in lan743x_ptp_tx_ts_enqueue_skb()
1411 ptp->tx_ts_ignore_sync_queue |= in lan743x_ptp_tx_ts_enqueue_skb()
1412 BIT(ptp->tx_ts_skb_queue_size); in lan743x_ptp_tx_ts_enqueue_skb()
1413 ptp->tx_ts_skb_queue_size++; in lan743x_ptp_tx_ts_enqueue_skb()
1415 /* this should never happen, so long as the tx channel in lan743x_ptp_tx_ts_enqueue_skb()
1419 netif_err(adapter, drv, adapter->netdev, in lan743x_ptp_tx_ts_enqueue_skb()
1420 "tx ts skb queue overflow\n"); in lan743x_ptp_tx_ts_enqueue_skb()
1423 spin_unlock_bh(&ptp->tx_ts_lock); in lan743x_ptp_tx_ts_enqueue_skb()
1459 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_init()
1462 mutex_init(&ptp->command_lock); in lan743x_ptp_init()
1463 spin_lock_init(&ptp->tx_ts_lock); in lan743x_ptp_init()
1464 ptp->used_event_ch = 0; in lan743x_ptp_init()
1467 ptp->perout[i].event_ch = -1; in lan743x_ptp_init()
1468 ptp->perout[i].gpio_pin = -1; in lan743x_ptp_init()
1478 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_open()
1479 int ret = -ENODEV; in lan743x_ptp_open()
1497 ptp->flags |= PTP_FLAG_ISR_ENABLED; in lan743x_ptp_open()
1502 switch (adapter->csr.id_rev & ID_REV_ID_MASK_) { in lan743x_ptp_open()
1512 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_open()
1514 adapter->csr.id_rev); in lan743x_ptp_open()
1523 struct ptp_pin_desc *ptp_pin = &ptp->pin_config[i]; in lan743x_ptp_open()
1525 snprintf(ptp_pin->name, in lan743x_ptp_open()
1526 sizeof(ptp_pin->name), "lan743x_ptp_pin_%02d", i); in lan743x_ptp_open()
1527 ptp_pin->index = i; in lan743x_ptp_open()
1528 ptp_pin->func = PTP_PF_NONE; in lan743x_ptp_open()
1531 ptp->ptp_clock_info.owner = THIS_MODULE; in lan743x_ptp_open()
1532 snprintf(ptp->ptp_clock_info.name, 16, "%pm", in lan743x_ptp_open()
1533 adapter->netdev->dev_addr); in lan743x_ptp_open()
1534 ptp->ptp_clock_info.max_adj = LAN743X_PTP_MAX_FREQ_ADJ_IN_PPB; in lan743x_ptp_open()
1535 ptp->ptp_clock_info.n_alarm = 0; in lan743x_ptp_open()
1536 ptp->ptp_clock_info.n_ext_ts = LAN743X_PTP_N_EXTTS; in lan743x_ptp_open()
1537 ptp->ptp_clock_info.n_per_out = LAN743X_PTP_N_EVENT_CHAN; in lan743x_ptp_open()
1538 ptp->ptp_clock_info.n_pins = n_pins; in lan743x_ptp_open()
1539 ptp->ptp_clock_info.pps = LAN743X_PTP_N_PPS; in lan743x_ptp_open()
1540 ptp->ptp_clock_info.pin_config = ptp->pin_config; in lan743x_ptp_open()
1541 ptp->ptp_clock_info.adjfine = lan743x_ptpci_adjfine; in lan743x_ptp_open()
1542 ptp->ptp_clock_info.adjtime = lan743x_ptpci_adjtime; in lan743x_ptp_open()
1543 ptp->ptp_clock_info.gettime64 = lan743x_ptpci_gettime64; in lan743x_ptp_open()
1544 ptp->ptp_clock_info.getcrosststamp = NULL; in lan743x_ptp_open()
1545 ptp->ptp_clock_info.settime64 = lan743x_ptpci_settime64; in lan743x_ptp_open()
1546 ptp->ptp_clock_info.enable = lan743x_ptpci_enable; in lan743x_ptp_open()
1547 ptp->ptp_clock_info.do_aux_work = lan743x_ptpci_do_aux_work; in lan743x_ptp_open()
1548 ptp->ptp_clock_info.verify = lan743x_ptpci_verify_pin_config; in lan743x_ptp_open()
1550 ptp->ptp_clock = ptp_clock_register(&ptp->ptp_clock_info, in lan743x_ptp_open()
1551 &adapter->pdev->dev); in lan743x_ptp_open()
1553 if (IS_ERR(ptp->ptp_clock)) { in lan743x_ptp_open()
1554 netif_err(adapter, ifup, adapter->netdev, in lan743x_ptp_open()
1558 ptp->flags |= PTP_FLAG_PTP_CLOCK_REGISTERED; in lan743x_ptp_open()
1559 netif_info(adapter, ifup, adapter->netdev, in lan743x_ptp_open()
1570 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_close()
1574 (ptp->flags & PTP_FLAG_PTP_CLOCK_REGISTERED)) { in lan743x_ptp_close()
1575 ptp_clock_unregister(ptp->ptp_clock); in lan743x_ptp_close()
1576 ptp->ptp_clock = NULL; in lan743x_ptp_close()
1577 ptp->flags &= ~PTP_FLAG_PTP_CLOCK_REGISTERED; in lan743x_ptp_close()
1578 netif_info(adapter, drv, adapter->netdev, in lan743x_ptp_close()
1582 if (ptp->flags & PTP_FLAG_ISR_ENABLED) { in lan743x_ptp_close()
1587 ptp->flags &= ~PTP_FLAG_ISR_ENABLED; in lan743x_ptp_close()
1592 spin_lock_bh(&ptp->tx_ts_lock); in lan743x_ptp_close()
1596 struct sk_buff *skb = ptp->tx_ts_skb_queue[index]; in lan743x_ptp_close()
1599 ptp->tx_ts_skb_queue[index] = NULL; in lan743x_ptp_close()
1600 ptp->tx_ts_seconds_queue[index] = 0; in lan743x_ptp_close()
1601 ptp->tx_ts_nseconds_queue[index] = 0; in lan743x_ptp_close()
1603 ptp->tx_ts_skb_queue_size = 0; in lan743x_ptp_close()
1604 ptp->tx_ts_queue_size = 0; in lan743x_ptp_close()
1605 ptp->pending_tx_timestamps = 0; in lan743x_ptp_close()
1606 spin_unlock_bh(&ptp->tx_ts_lock); in lan743x_ptp_close()
1635 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_enable()
1637 mutex_lock(&ptp->command_lock); in lan743x_ptp_enable()
1640 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_enable()
1646 mutex_unlock(&ptp->command_lock); in lan743x_ptp_enable()
1651 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_disable()
1656 mutex_lock(&ptp->command_lock); in lan743x_ptp_disable()
1658 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_disable()
1665 mutex_unlock(&ptp->command_lock); in lan743x_ptp_disable()
1670 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_reset()
1672 mutex_lock(&ptp->command_lock); in lan743x_ptp_reset()
1675 netif_err(adapter, drv, adapter->netdev, in lan743x_ptp_reset()
1683 mutex_unlock(&ptp->command_lock); in lan743x_ptp_reset()
1690 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_clock_set()
1692 mutex_lock(&ptp->command_lock); in lan743x_ptp_clock_set()
1700 mutex_unlock(&ptp->command_lock); in lan743x_ptp_clock_set()
1705 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_request_tx_timestamp()
1708 spin_lock(&ptp->tx_ts_lock); in lan743x_ptp_request_tx_timestamp()
1709 if (ptp->pending_tx_timestamps < LAN743X_PTP_NUMBER_OF_TX_TIMESTAMPS) { in lan743x_ptp_request_tx_timestamp()
1711 ptp->pending_tx_timestamps++; in lan743x_ptp_request_tx_timestamp()
1714 spin_unlock(&ptp->tx_ts_lock); in lan743x_ptp_request_tx_timestamp()
1720 struct lan743x_ptp *ptp = &adapter->ptp; in lan743x_ptp_unrequest_tx_timestamp()
1722 spin_lock_bh(&ptp->tx_ts_lock); in lan743x_ptp_unrequest_tx_timestamp()
1723 if (ptp->pending_tx_timestamps > 0) in lan743x_ptp_unrequest_tx_timestamp()
1724 ptp->pending_tx_timestamps--; in lan743x_ptp_unrequest_tx_timestamp()
1726 netif_err(adapter, drv, adapter->netdev, in lan743x_ptp_unrequest_tx_timestamp()
1728 spin_unlock_bh(&ptp->tx_ts_lock); in lan743x_ptp_unrequest_tx_timestamp()
1747 netif_err(adapter, drv, adapter->netdev, in lan743x_ptp_ioctl()
1749 return -EINVAL; in lan743x_ptp_ioctl()
1752 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in lan743x_ptp_ioctl()
1753 return -EFAULT; in lan743x_ptp_ioctl()
1757 for (index = 0; index < adapter->used_tx_channels; in lan743x_ptp_ioctl()
1759 lan743x_tx_set_timestamping_mode(&adapter->tx[index], in lan743x_ptp_ioctl()
1764 for (index = 0; index < adapter->used_tx_channels; in lan743x_ptp_ioctl()
1766 lan743x_tx_set_timestamping_mode(&adapter->tx[index], in lan743x_ptp_ioctl()
1771 for (index = 0; index < adapter->used_tx_channels; in lan743x_ptp_ioctl()
1773 lan743x_tx_set_timestamping_mode(&adapter->tx[index], in lan743x_ptp_ioctl()
1779 ret = -ERANGE; in lan743x_ptp_ioctl()
1782 netif_warn(adapter, drv, adapter->netdev, in lan743x_ptp_ioctl()
1784 ret = -EINVAL; in lan743x_ptp_ioctl()
1791 return copy_to_user(ifr->ifr_data, &config, in lan743x_ptp_ioctl()
1792 sizeof(config)) ? -EFAULT : 0; in lan743x_ptp_ioctl()