Lines Matching refs:pf

141 static int i40e_ptp_set_pins(struct i40e_pf *pf,
152 struct i40e_pf *pf = container_of(work, struct i40e_pf, in i40e_ptp_extts0_work() local
154 struct i40e_hw *hw = &pf->hw; in i40e_ptp_extts0_work()
172 ptp_clock_event(pf->ptp_clock, &event); in i40e_ptp_extts0_work()
196 static enum i40e_can_set_pins i40e_can_set_pins(struct i40e_pf *pf) in i40e_can_set_pins() argument
198 if (!i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_can_set_pins()
199 dev_warn(&pf->pdev->dev, in i40e_can_set_pins()
204 if (!pf->ptp_pins) { in i40e_can_set_pins()
205 dev_warn(&pf->pdev->dev, in i40e_can_set_pins()
210 if (pf->hw.pf_id) { in i40e_can_set_pins()
211 dev_warn(&pf->pdev->dev, in i40e_can_set_pins()
225 static void i40_ptp_reset_timing_events(struct i40e_pf *pf) in i40_ptp_reset_timing_events() argument
229 spin_lock_bh(&pf->ptp_rx_lock); in i40_ptp_reset_timing_events()
232 rd32(&pf->hw, I40E_PRTTSYN_RXTIME_L(i)); in i40_ptp_reset_timing_events()
233 rd32(&pf->hw, I40E_PRTTSYN_RXTIME_H(i)); in i40_ptp_reset_timing_events()
234 pf->latch_events[i] = 0; in i40_ptp_reset_timing_events()
237 rd32(&pf->hw, I40E_PRTTSYN_TXTIME_L); in i40_ptp_reset_timing_events()
238 rd32(&pf->hw, I40E_PRTTSYN_TXTIME_H); in i40_ptp_reset_timing_events()
240 pf->tx_hwtstamp_timeouts = 0; in i40_ptp_reset_timing_events()
241 pf->tx_hwtstamp_skipped = 0; in i40_ptp_reset_timing_events()
242 pf->rx_hwtstamp_cleared = 0; in i40_ptp_reset_timing_events()
243 pf->latch_event_flags = 0; in i40_ptp_reset_timing_events()
244 spin_unlock_bh(&pf->ptp_rx_lock); in i40_ptp_reset_timing_events()
281 static void i40e_ptp_read(struct i40e_pf *pf, struct timespec64 *ts, in i40e_ptp_read() argument
284 struct i40e_hw *hw = &pf->hw; in i40e_ptp_read()
308 static void i40e_ptp_write(struct i40e_pf *pf, const struct timespec64 *ts) in i40e_ptp_write() argument
310 struct i40e_hw *hw = &pf->hw; in i40e_ptp_write()
349 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps); in i40e_ptp_adjfine() local
350 struct i40e_hw *hw = &pf->hw; in i40e_ptp_adjfine()
354 base_adj = I40E_PTP_40GB_INCVAL * READ_ONCE(pf->ptp_adj_mult); in i40e_ptp_adjfine()
370 static void i40e_ptp_set_1pps_signal_hw(struct i40e_pf *pf) in i40e_ptp_set_1pps_signal_hw() argument
372 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_1pps_signal_hw()
380 i40e_ptp_read(pf, &now, NULL); in i40e_ptp_set_1pps_signal_hw()
404 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps); in i40e_ptp_adjtime() local
405 struct i40e_hw *hw = &pf->hw; in i40e_ptp_adjtime()
407 mutex_lock(&pf->tmreg_lock); in i40e_ptp_adjtime()
429 i40e_ptp_read(pf, &now, NULL); in i40e_ptp_adjtime()
431 i40e_ptp_write(pf, (const struct timespec64 *)&now); in i40e_ptp_adjtime()
432 i40e_ptp_set_1pps_signal_hw(pf); in i40e_ptp_adjtime()
435 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_adjtime()
452 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps); in i40e_ptp_gettimex() local
454 mutex_lock(&pf->tmreg_lock); in i40e_ptp_gettimex()
455 i40e_ptp_read(pf, ts, sts); in i40e_ptp_gettimex()
456 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_gettimex()
472 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps); in i40e_ptp_settime() local
474 mutex_lock(&pf->tmreg_lock); in i40e_ptp_settime()
475 i40e_ptp_write(pf, ts); in i40e_ptp_settime()
476 mutex_unlock(&pf->tmreg_lock); in i40e_ptp_settime()
494 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps); in i40e_pps_configure() local
497 i40e_ptp_set_1pps_signal_hw(pf); in i40e_pps_configure()
536 static int i40e_ptp_enable_pin(struct i40e_pf *pf, unsigned int chan, in i40e_ptp_enable_pin() argument
544 if (pf->hw.pf_id) in i40e_ptp_enable_pin()
548 pins.sdp3_2 = pf->ptp_pins->sdp3_2; in i40e_ptp_enable_pin()
549 pins.sdp3_3 = pf->ptp_pins->sdp3_3; in i40e_ptp_enable_pin()
550 pins.gpio_4 = pf->ptp_pins->gpio_4; in i40e_ptp_enable_pin()
559 pin_index = ptp_find_pin(pf->ptp_clock, func, chan); in i40e_ptp_enable_pin()
584 return i40e_ptp_set_pins(pf, &pins) ? -EINVAL : 0; in i40e_ptp_enable_pin()
599 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps); in i40e_ptp_feature_enable() local
620 return i40e_ptp_enable_pin(pf, chan, func, on); in i40e_ptp_feature_enable()
635 static u32 i40e_ptp_get_rx_events(struct i40e_pf *pf) in i40e_ptp_get_rx_events() argument
637 struct i40e_hw *hw = &pf->hw; in i40e_ptp_get_rx_events()
642 new_latch_events = prttsyn_stat & ~pf->latch_event_flags; in i40e_ptp_get_rx_events()
655 pf->latch_events[i] = jiffies; in i40e_ptp_get_rx_events()
659 pf->latch_event_flags = prttsyn_stat; in i40e_ptp_get_rx_events()
673 void i40e_ptp_rx_hang(struct i40e_pf *pf) in i40e_ptp_rx_hang() argument
675 struct i40e_hw *hw = &pf->hw; in i40e_ptp_rx_hang()
683 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_rx) in i40e_ptp_rx_hang()
686 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hang()
689 i40e_ptp_get_rx_events(pf); in i40e_ptp_rx_hang()
698 if ((pf->latch_event_flags & BIT(i)) && in i40e_ptp_rx_hang()
699 time_is_before_jiffies(pf->latch_events[i] + HZ)) { in i40e_ptp_rx_hang()
701 pf->latch_event_flags &= ~BIT(i); in i40e_ptp_rx_hang()
706 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hang()
715 dev_dbg(&pf->pdev->dev, in i40e_ptp_rx_hang()
720 pf->rx_hwtstamp_cleared += cleared; in i40e_ptp_rx_hang()
732 void i40e_ptp_tx_hang(struct i40e_pf *pf) in i40e_ptp_tx_hang() argument
736 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_tx) in i40e_ptp_tx_hang()
740 if (!test_bit(__I40E_PTP_TX_IN_PROGRESS, pf->state)) in i40e_ptp_tx_hang()
747 if (time_is_before_jiffies(pf->ptp_tx_start + HZ)) { in i40e_ptp_tx_hang()
748 skb = pf->ptp_tx_skb; in i40e_ptp_tx_hang()
749 pf->ptp_tx_skb = NULL; in i40e_ptp_tx_hang()
750 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_tx_hang()
754 pf->tx_hwtstamp_timeouts++; in i40e_ptp_tx_hang()
766 void i40e_ptp_tx_hwtstamp(struct i40e_pf *pf) in i40e_ptp_tx_hwtstamp() argument
769 struct sk_buff *skb = pf->ptp_tx_skb; in i40e_ptp_tx_hwtstamp()
770 struct i40e_hw *hw = &pf->hw; in i40e_ptp_tx_hwtstamp()
774 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_tx) in i40e_ptp_tx_hwtstamp()
778 if (!pf->ptp_tx_skb) in i40e_ptp_tx_hwtstamp()
792 pf->ptp_tx_skb = NULL; in i40e_ptp_tx_hwtstamp()
793 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_tx_hwtstamp()
812 void i40e_ptp_rx_hwtstamp(struct i40e_pf *pf, struct sk_buff *skb, u8 index) in i40e_ptp_rx_hwtstamp() argument
821 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_rx) in i40e_ptp_rx_hwtstamp()
824 hw = &pf->hw; in i40e_ptp_rx_hwtstamp()
826 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
829 prttsyn_stat = i40e_ptp_get_rx_events(pf); in i40e_ptp_rx_hwtstamp()
833 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
838 pf->latch_event_flags &= ~BIT(index); in i40e_ptp_rx_hwtstamp()
843 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_rx_hwtstamp()
858 void i40e_ptp_set_increment(struct i40e_pf *pf) in i40e_ptp_set_increment() argument
861 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_increment()
867 i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); in i40e_ptp_set_increment()
884 dev_warn(&pf->pdev->dev, in i40e_ptp_set_increment()
910 WRITE_ONCE(pf->ptp_adj_mult, mult); in i40e_ptp_set_increment()
923 int i40e_ptp_get_ts_config(struct i40e_pf *pf, struct ifreq *ifr) in i40e_ptp_get_ts_config() argument
925 struct hwtstamp_config *config = &pf->tstamp_config; in i40e_ptp_get_ts_config()
927 if (!(pf->flags & I40E_FLAG_PTP)) in i40e_ptp_get_ts_config()
940 static void i40e_ptp_free_pins(struct i40e_pf *pf) in i40e_ptp_free_pins() argument
942 if (i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_ptp_free_pins()
943 kfree(pf->ptp_pins); in i40e_ptp_free_pins()
944 kfree(pf->ptp_caps.pin_config); in i40e_ptp_free_pins()
945 pf->ptp_pins = NULL; in i40e_ptp_free_pins()
1037 static void i40e_ptp_set_pins_hw(struct i40e_pf *pf) in i40e_ptp_set_pins_hw() argument
1039 const struct i40e_ptp_pins_settings *pins = pf->ptp_pins; in i40e_ptp_set_pins_hw()
1040 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_pins_hw()
1056 dev_info(&pf->pdev->dev, in i40e_ptp_set_pins_hw()
1071 static int i40e_ptp_set_pins(struct i40e_pf *pf, in i40e_ptp_set_pins() argument
1074 enum i40e_can_set_pins pin_caps = i40e_can_set_pins(pf); in i40e_ptp_set_pins()
1083 pins->sdp3_2 = pf->ptp_pins->sdp3_2; in i40e_ptp_set_pins()
1085 pins->sdp3_3 = pf->ptp_pins->sdp3_3; in i40e_ptp_set_pins()
1087 pins->gpio_4 = pf->ptp_pins->gpio_4; in i40e_ptp_set_pins()
1105 dev_warn(&pf->pdev->dev, in i40e_ptp_set_pins()
1113 memcpy(pf->ptp_pins, pins, sizeof(*pins)); in i40e_ptp_set_pins()
1114 i40e_ptp_set_pins_hw(pf); in i40e_ptp_set_pins()
1115 i40_ptp_reset_timing_events(pf); in i40e_ptp_set_pins()
1126 int i40e_ptp_alloc_pins(struct i40e_pf *pf) in i40e_ptp_alloc_pins() argument
1128 if (!i40e_is_ptp_pin_dev(&pf->hw)) in i40e_ptp_alloc_pins()
1131 pf->ptp_pins = in i40e_ptp_alloc_pins()
1134 if (!pf->ptp_pins) { in i40e_ptp_alloc_pins()
1135 dev_warn(&pf->pdev->dev, "Cannot allocate memory for PTP pins structure.\n"); in i40e_ptp_alloc_pins()
1139 pf->ptp_pins->sdp3_2 = off; in i40e_ptp_alloc_pins()
1140 pf->ptp_pins->sdp3_3 = off; in i40e_ptp_alloc_pins()
1141 pf->ptp_pins->gpio_4 = off; in i40e_ptp_alloc_pins()
1142 pf->ptp_pins->led2_0 = high; in i40e_ptp_alloc_pins()
1143 pf->ptp_pins->led2_1 = high; in i40e_ptp_alloc_pins()
1144 pf->ptp_pins->led3_0 = high; in i40e_ptp_alloc_pins()
1145 pf->ptp_pins->led3_1 = high; in i40e_ptp_alloc_pins()
1148 if (pf->hw.pf_id) in i40e_ptp_alloc_pins()
1151 i40e_ptp_init_leds_hw(&pf->hw); in i40e_ptp_alloc_pins()
1152 i40e_ptp_set_pins_hw(pf); in i40e_ptp_alloc_pins()
1169 static int i40e_ptp_set_timestamp_mode(struct i40e_pf *pf, in i40e_ptp_set_timestamp_mode() argument
1172 struct i40e_hw *hw = &pf->hw; in i40e_ptp_set_timestamp_mode()
1188 INIT_WORK(&pf->ptp_extts0_work, i40e_ptp_extts0_work); in i40e_ptp_set_timestamp_mode()
1192 pf->ptp_tx = false; in i40e_ptp_set_timestamp_mode()
1195 pf->ptp_tx = true; in i40e_ptp_set_timestamp_mode()
1203 pf->ptp_rx = false; in i40e_ptp_set_timestamp_mode()
1214 if (!(pf->hw_features & I40E_HW_PTP_L4_CAPABLE)) in i40e_ptp_set_timestamp_mode()
1216 pf->ptp_rx = true; in i40e_ptp_set_timestamp_mode()
1228 if (!(pf->hw_features & I40E_HW_PTP_L4_CAPABLE)) in i40e_ptp_set_timestamp_mode()
1234 pf->ptp_rx = true; in i40e_ptp_set_timestamp_mode()
1237 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE) { in i40e_ptp_set_timestamp_mode()
1251 spin_lock_bh(&pf->ptp_rx_lock); in i40e_ptp_set_timestamp_mode()
1258 pf->latch_event_flags = 0; in i40e_ptp_set_timestamp_mode()
1259 spin_unlock_bh(&pf->ptp_rx_lock); in i40e_ptp_set_timestamp_mode()
1263 if (pf->ptp_tx) in i40e_ptp_set_timestamp_mode()
1270 if (pf->ptp_tx) in i40e_ptp_set_timestamp_mode()
1306 int i40e_ptp_set_ts_config(struct i40e_pf *pf, struct ifreq *ifr) in i40e_ptp_set_ts_config() argument
1311 if (!(pf->flags & I40E_FLAG_PTP)) in i40e_ptp_set_ts_config()
1317 err = i40e_ptp_set_timestamp_mode(pf, &config); in i40e_ptp_set_ts_config()
1322 pf->tstamp_config = config; in i40e_ptp_set_ts_config()
1335 static int i40e_init_pin_config(struct i40e_pf *pf) in i40e_init_pin_config() argument
1339 pf->ptp_caps.n_pins = 3; in i40e_init_pin_config()
1340 pf->ptp_caps.n_ext_ts = 2; in i40e_init_pin_config()
1341 pf->ptp_caps.pps = 1; in i40e_init_pin_config()
1342 pf->ptp_caps.n_per_out = 2; in i40e_init_pin_config()
1344 pf->ptp_caps.pin_config = kcalloc(pf->ptp_caps.n_pins, in i40e_init_pin_config()
1345 sizeof(*pf->ptp_caps.pin_config), in i40e_init_pin_config()
1347 if (!pf->ptp_caps.pin_config) in i40e_init_pin_config()
1350 for (i = 0; i < pf->ptp_caps.n_pins; i++) { in i40e_init_pin_config()
1351 snprintf(pf->ptp_caps.pin_config[i].name, in i40e_init_pin_config()
1352 sizeof(pf->ptp_caps.pin_config[i].name), in i40e_init_pin_config()
1354 pf->ptp_caps.pin_config[i].index = sdp_desc[i].index; in i40e_init_pin_config()
1355 pf->ptp_caps.pin_config[i].func = PTP_PF_NONE; in i40e_init_pin_config()
1356 pf->ptp_caps.pin_config[i].chan = sdp_desc[i].chan; in i40e_init_pin_config()
1359 pf->ptp_caps.verify = i40e_ptp_verify; in i40e_init_pin_config()
1360 pf->ptp_caps.enable = i40e_ptp_feature_enable; in i40e_init_pin_config()
1362 pf->ptp_caps.pps = 1; in i40e_init_pin_config()
1377 static long i40e_ptp_create_clock(struct i40e_pf *pf) in i40e_ptp_create_clock() argument
1380 if (!IS_ERR_OR_NULL(pf->ptp_clock)) in i40e_ptp_create_clock()
1383 strscpy(pf->ptp_caps.name, i40e_driver_name, in i40e_ptp_create_clock()
1384 sizeof(pf->ptp_caps.name) - 1); in i40e_ptp_create_clock()
1385 pf->ptp_caps.owner = THIS_MODULE; in i40e_ptp_create_clock()
1386 pf->ptp_caps.max_adj = 999999999; in i40e_ptp_create_clock()
1387 pf->ptp_caps.adjfine = i40e_ptp_adjfine; in i40e_ptp_create_clock()
1388 pf->ptp_caps.adjtime = i40e_ptp_adjtime; in i40e_ptp_create_clock()
1389 pf->ptp_caps.gettimex64 = i40e_ptp_gettimex; in i40e_ptp_create_clock()
1390 pf->ptp_caps.settime64 = i40e_ptp_settime; in i40e_ptp_create_clock()
1391 if (i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_ptp_create_clock()
1392 int err = i40e_init_pin_config(pf); in i40e_ptp_create_clock()
1399 pf->ptp_clock = ptp_clock_register(&pf->ptp_caps, &pf->pdev->dev); in i40e_ptp_create_clock()
1400 if (IS_ERR(pf->ptp_clock)) in i40e_ptp_create_clock()
1401 return PTR_ERR(pf->ptp_clock); in i40e_ptp_create_clock()
1407 pf->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; in i40e_ptp_create_clock()
1408 pf->tstamp_config.tx_type = HWTSTAMP_TX_OFF; in i40e_ptp_create_clock()
1411 ktime_get_real_ts64(&pf->ptp_prev_hw_time); in i40e_ptp_create_clock()
1412 pf->ptp_reset_start = ktime_get(); in i40e_ptp_create_clock()
1426 void i40e_ptp_save_hw_time(struct i40e_pf *pf) in i40e_ptp_save_hw_time() argument
1429 if (!(pf->flags & I40E_FLAG_PTP)) in i40e_ptp_save_hw_time()
1432 i40e_ptp_gettimex(&pf->ptp_caps, &pf->ptp_prev_hw_time, NULL); in i40e_ptp_save_hw_time()
1434 pf->ptp_reset_start = ktime_get(); in i40e_ptp_save_hw_time()
1449 void i40e_ptp_restore_hw_time(struct i40e_pf *pf) in i40e_ptp_restore_hw_time() argument
1451 ktime_t delta = ktime_sub(ktime_get(), pf->ptp_reset_start); in i40e_ptp_restore_hw_time()
1454 timespec64_add_ns(&pf->ptp_prev_hw_time, ktime_to_ns(delta)); in i40e_ptp_restore_hw_time()
1457 i40e_ptp_settime(&pf->ptp_caps, &pf->ptp_prev_hw_time); in i40e_ptp_restore_hw_time()
1473 void i40e_ptp_init(struct i40e_pf *pf) in i40e_ptp_init() argument
1475 struct net_device *netdev = pf->vsi[pf->lan_vsi]->netdev; in i40e_ptp_init()
1476 struct i40e_hw *hw = &pf->hw; in i40e_ptp_init()
1486 pf->flags &= ~I40E_FLAG_PTP; in i40e_ptp_init()
1487 dev_info(&pf->pdev->dev, "%s: PTP not supported on %s\n", in i40e_ptp_init()
1493 mutex_init(&pf->tmreg_lock); in i40e_ptp_init()
1494 spin_lock_init(&pf->ptp_rx_lock); in i40e_ptp_init()
1497 err = i40e_ptp_create_clock(pf); in i40e_ptp_init()
1499 pf->ptp_clock = NULL; in i40e_ptp_init()
1500 dev_err(&pf->pdev->dev, "%s: ptp_clock_register failed\n", in i40e_ptp_init()
1502 } else if (pf->ptp_clock) { in i40e_ptp_init()
1505 if (pf->hw.debug_mask & I40E_DEBUG_LAN) in i40e_ptp_init()
1506 dev_info(&pf->pdev->dev, "PHC enabled\n"); in i40e_ptp_init()
1507 pf->flags |= I40E_FLAG_PTP; in i40e_ptp_init()
1518 i40e_ptp_set_increment(pf); in i40e_ptp_init()
1521 i40e_ptp_set_timestamp_mode(pf, &pf->tstamp_config); in i40e_ptp_init()
1524 i40e_ptp_restore_hw_time(pf); in i40e_ptp_init()
1527 i40e_ptp_set_1pps_signal_hw(pf); in i40e_ptp_init()
1537 void i40e_ptp_stop(struct i40e_pf *pf) in i40e_ptp_stop() argument
1539 struct i40e_hw *hw = &pf->hw; in i40e_ptp_stop()
1542 pf->flags &= ~I40E_FLAG_PTP; in i40e_ptp_stop()
1543 pf->ptp_tx = false; in i40e_ptp_stop()
1544 pf->ptp_rx = false; in i40e_ptp_stop()
1546 if (pf->ptp_tx_skb) { in i40e_ptp_stop()
1547 struct sk_buff *skb = pf->ptp_tx_skb; in i40e_ptp_stop()
1549 pf->ptp_tx_skb = NULL; in i40e_ptp_stop()
1550 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state); in i40e_ptp_stop()
1554 if (pf->ptp_clock) { in i40e_ptp_stop()
1555 ptp_clock_unregister(pf->ptp_clock); in i40e_ptp_stop()
1556 pf->ptp_clock = NULL; in i40e_ptp_stop()
1557 dev_info(&pf->pdev->dev, "%s: removed PHC on %s\n", __func__, in i40e_ptp_stop()
1558 pf->vsi[pf->lan_vsi]->netdev->name); in i40e_ptp_stop()
1561 if (i40e_is_ptp_pin_dev(&pf->hw)) { in i40e_ptp_stop()
1576 i40e_ptp_free_pins(pf); in i40e_ptp_stop()