0001
0002
0003
0004 #include "i40e.h"
0005 #include <linux/ptp_classify.h>
0006 #include <linux/posix-clock.h>
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #define I40E_PTP_40GB_INCVAL 0x0199999999ULL
0021 #define I40E_PTP_10GB_INCVAL_MULT 2
0022 #define I40E_PTP_5GB_INCVAL_MULT 2
0023 #define I40E_PTP_1GB_INCVAL_MULT 20
0024 #define I40E_ISGN 0x80000000
0025
0026 #define I40E_PRTTSYN_CTL1_TSYNTYPE_V1 BIT(I40E_PRTTSYN_CTL1_TSYNTYPE_SHIFT)
0027 #define I40E_PRTTSYN_CTL1_TSYNTYPE_V2 (2 << \
0028 I40E_PRTTSYN_CTL1_TSYNTYPE_SHIFT)
0029 #define I40E_SUBDEV_ID_25G_PTP_PIN 0xB
0030
0031 enum i40e_ptp_pin {
0032 SDP3_2 = 0,
0033 SDP3_3,
0034 GPIO_4
0035 };
0036
0037 enum i40e_can_set_pins_t {
0038 CANT_DO_PINS = -1,
0039 CAN_SET_PINS,
0040 CAN_DO_PINS
0041 };
0042
0043 static struct ptp_pin_desc sdp_desc[] = {
0044
0045 {"SDP3_2", SDP3_2, PTP_PF_NONE, 0},
0046 {"SDP3_3", SDP3_3, PTP_PF_NONE, 1},
0047 {"GPIO_4", GPIO_4, PTP_PF_NONE, 1},
0048 };
0049
0050 enum i40e_ptp_gpio_pin_state {
0051 end = -2,
0052 invalid,
0053 off,
0054 in_A,
0055 in_B,
0056 out_A,
0057 out_B,
0058 };
0059
0060 static const char * const i40e_ptp_gpio_pin_state2str[] = {
0061 "off", "in_A", "in_B", "out_A", "out_B"
0062 };
0063
0064 enum i40e_ptp_led_pin_state {
0065 led_end = -2,
0066 low = 0,
0067 high,
0068 };
0069
0070 struct i40e_ptp_pins_settings {
0071 enum i40e_ptp_gpio_pin_state sdp3_2;
0072 enum i40e_ptp_gpio_pin_state sdp3_3;
0073 enum i40e_ptp_gpio_pin_state gpio_4;
0074 enum i40e_ptp_led_pin_state led2_0;
0075 enum i40e_ptp_led_pin_state led2_1;
0076 enum i40e_ptp_led_pin_state led3_0;
0077 enum i40e_ptp_led_pin_state led3_1;
0078 };
0079
0080 static const struct i40e_ptp_pins_settings
0081 i40e_ptp_pin_led_allowed_states[] = {
0082 {off, off, off, high, high, high, high},
0083 {off, in_A, off, high, high, high, low},
0084 {off, out_A, off, high, low, high, high},
0085 {off, in_B, off, high, high, high, low},
0086 {off, out_B, off, high, low, high, high},
0087 {in_A, off, off, high, high, high, low},
0088 {in_A, in_B, off, high, high, high, low},
0089 {in_A, out_B, off, high, low, high, high},
0090 {out_A, off, off, high, low, high, high},
0091 {out_A, in_B, off, high, low, high, high},
0092 {in_B, off, off, high, high, high, low},
0093 {in_B, in_A, off, high, high, high, low},
0094 {in_B, out_A, off, high, low, high, high},
0095 {out_B, off, off, high, low, high, high},
0096 {out_B, in_A, off, high, low, high, high},
0097 {off, off, in_A, high, high, low, high},
0098 {off, out_A, in_A, high, low, low, high},
0099 {off, in_B, in_A, high, high, low, low},
0100 {off, out_B, in_A, high, low, low, high},
0101 {out_A, off, in_A, high, low, low, high},
0102 {out_A, in_B, in_A, high, low, low, high},
0103 {in_B, off, in_A, high, high, low, low},
0104 {in_B, out_A, in_A, high, low, low, high},
0105 {out_B, off, in_A, high, low, low, high},
0106 {off, off, out_A, low, high, high, high},
0107 {off, in_A, out_A, low, high, high, low},
0108 {off, in_B, out_A, low, high, high, low},
0109 {off, out_B, out_A, low, low, high, high},
0110 {in_A, off, out_A, low, high, high, low},
0111 {in_A, in_B, out_A, low, high, high, low},
0112 {in_A, out_B, out_A, low, low, high, high},
0113 {in_B, off, out_A, low, high, high, low},
0114 {in_B, in_A, out_A, low, high, high, low},
0115 {out_B, off, out_A, low, low, high, high},
0116 {out_B, in_A, out_A, low, low, high, high},
0117 {off, off, in_B, high, high, low, high},
0118 {off, in_A, in_B, high, high, low, low},
0119 {off, out_A, in_B, high, low, low, high},
0120 {off, out_B, in_B, high, low, low, high},
0121 {in_A, off, in_B, high, high, low, low},
0122 {in_A, out_B, in_B, high, low, low, high},
0123 {out_A, off, in_B, high, low, low, high},
0124 {out_B, off, in_B, high, low, low, high},
0125 {out_B, in_A, in_B, high, low, low, high},
0126 {off, off, out_B, low, high, high, high},
0127 {off, in_A, out_B, low, high, high, low},
0128 {off, out_A, out_B, low, low, high, high},
0129 {off, in_B, out_B, low, high, high, low},
0130 {in_A, off, out_B, low, high, high, low},
0131 {in_A, in_B, out_B, low, high, high, low},
0132 {out_A, off, out_B, low, low, high, high},
0133 {out_A, in_B, out_B, low, low, high, high},
0134 {in_B, off, out_B, low, high, high, low},
0135 {in_B, in_A, out_B, low, high, high, low},
0136 {in_B, out_A, out_B, low, low, high, high},
0137 {end, end, end, led_end, led_end, led_end, led_end}
0138 };
0139
0140 static int i40e_ptp_set_pins(struct i40e_pf *pf,
0141 struct i40e_ptp_pins_settings *pins);
0142
0143
0144
0145
0146
0147
0148
0149 static void i40e_ptp_extts0_work(struct work_struct *work)
0150 {
0151 struct i40e_pf *pf = container_of(work, struct i40e_pf,
0152 ptp_extts0_work);
0153 struct i40e_hw *hw = &pf->hw;
0154 struct ptp_clock_event event;
0155 u32 hi, lo;
0156
0157
0158
0159
0160
0161
0162 lo = rd32(hw, I40E_PRTTSYN_EVNT_L(0));
0163 hi = rd32(hw, I40E_PRTTSYN_EVNT_H(0));
0164
0165 event.timestamp = (((u64)hi) << 32) | lo;
0166
0167 event.type = PTP_CLOCK_EXTTS;
0168 event.index = hw->pf_id;
0169
0170
0171 ptp_clock_event(pf->ptp_clock, &event);
0172 }
0173
0174
0175
0176
0177
0178
0179
0180 static bool i40e_is_ptp_pin_dev(struct i40e_hw *hw)
0181 {
0182 return hw->device_id == I40E_DEV_ID_25G_SFP28 &&
0183 hw->subsystem_device_id == I40E_SUBDEV_ID_25G_PTP_PIN;
0184 }
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195 static enum i40e_can_set_pins_t i40e_can_set_pins(struct i40e_pf *pf)
0196 {
0197 if (!i40e_is_ptp_pin_dev(&pf->hw)) {
0198 dev_warn(&pf->pdev->dev,
0199 "PTP external clock not supported.\n");
0200 return CANT_DO_PINS;
0201 }
0202
0203 if (!pf->ptp_pins) {
0204 dev_warn(&pf->pdev->dev,
0205 "PTP PIN manipulation not allowed.\n");
0206 return CANT_DO_PINS;
0207 }
0208
0209 if (pf->hw.pf_id) {
0210 dev_warn(&pf->pdev->dev,
0211 "PTP PINs should be accessed via PF0.\n");
0212 return CAN_DO_PINS;
0213 }
0214
0215 return CAN_SET_PINS;
0216 }
0217
0218
0219
0220
0221
0222
0223
0224 static void i40_ptp_reset_timing_events(struct i40e_pf *pf)
0225 {
0226 u32 i;
0227
0228 spin_lock_bh(&pf->ptp_rx_lock);
0229 for (i = 0; i <= I40E_PRTTSYN_RXTIME_L_MAX_INDEX; i++) {
0230
0231 rd32(&pf->hw, I40E_PRTTSYN_RXTIME_L(i));
0232 rd32(&pf->hw, I40E_PRTTSYN_RXTIME_H(i));
0233 pf->latch_events[i] = 0;
0234 }
0235
0236 rd32(&pf->hw, I40E_PRTTSYN_TXTIME_L);
0237 rd32(&pf->hw, I40E_PRTTSYN_TXTIME_H);
0238
0239 pf->tx_hwtstamp_timeouts = 0;
0240 pf->tx_hwtstamp_skipped = 0;
0241 pf->rx_hwtstamp_cleared = 0;
0242 pf->latch_event_flags = 0;
0243 spin_unlock_bh(&pf->ptp_rx_lock);
0244 }
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256 static int i40e_ptp_verify(struct ptp_clock_info *ptp, unsigned int pin,
0257 enum ptp_pin_function func, unsigned int chan)
0258 {
0259 switch (func) {
0260 case PTP_PF_NONE:
0261 case PTP_PF_EXTTS:
0262 case PTP_PF_PEROUT:
0263 break;
0264 case PTP_PF_PHYSYNC:
0265 return -EOPNOTSUPP;
0266 }
0267 return 0;
0268 }
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280 static void i40e_ptp_read(struct i40e_pf *pf, struct timespec64 *ts,
0281 struct ptp_system_timestamp *sts)
0282 {
0283 struct i40e_hw *hw = &pf->hw;
0284 u32 hi, lo;
0285 u64 ns;
0286
0287
0288 ptp_read_system_prets(sts);
0289 lo = rd32(hw, I40E_PRTTSYN_TIME_L);
0290 ptp_read_system_postts(sts);
0291 hi = rd32(hw, I40E_PRTTSYN_TIME_H);
0292
0293 ns = (((u64)hi) << 32) | lo;
0294
0295 *ts = ns_to_timespec64(ns);
0296 }
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307 static void i40e_ptp_write(struct i40e_pf *pf, const struct timespec64 *ts)
0308 {
0309 struct i40e_hw *hw = &pf->hw;
0310 u64 ns = timespec64_to_ns(ts);
0311
0312
0313
0314
0315 wr32(hw, I40E_PRTTSYN_TIME_L, ns & 0xFFFFFFFF);
0316 wr32(hw, I40E_PRTTSYN_TIME_H, ns >> 32);
0317 }
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328 static void i40e_ptp_convert_to_hwtstamp(struct skb_shared_hwtstamps *hwtstamps,
0329 u64 timestamp)
0330 {
0331 memset(hwtstamps, 0, sizeof(*hwtstamps));
0332
0333 hwtstamps->hwtstamp = ns_to_ktime(timestamp);
0334 }
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346 static int i40e_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
0347 {
0348 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps);
0349 struct i40e_hw *hw = &pf->hw;
0350 u64 adj, freq, diff;
0351 int neg_adj = 0;
0352
0353 if (scaled_ppm < 0) {
0354 neg_adj = 1;
0355 scaled_ppm = -scaled_ppm;
0356 }
0357
0358 smp_mb();
0359 freq = I40E_PTP_40GB_INCVAL * READ_ONCE(pf->ptp_adj_mult);
0360 diff = mul_u64_u64_div_u64(freq, (u64)scaled_ppm,
0361 1000000ULL << 16);
0362
0363 if (neg_adj)
0364 adj = I40E_PTP_40GB_INCVAL - diff;
0365 else
0366 adj = I40E_PTP_40GB_INCVAL + diff;
0367
0368 wr32(hw, I40E_PRTTSYN_INC_L, adj & 0xFFFFFFFF);
0369 wr32(hw, I40E_PRTTSYN_INC_H, adj >> 32);
0370
0371 return 0;
0372 }
0373
0374
0375
0376
0377
0378
0379
0380 static void i40e_ptp_set_1pps_signal_hw(struct i40e_pf *pf)
0381 {
0382 struct i40e_hw *hw = &pf->hw;
0383 struct timespec64 now;
0384 u64 ns;
0385
0386 wr32(hw, I40E_PRTTSYN_AUX_0(1), 0);
0387 wr32(hw, I40E_PRTTSYN_AUX_1(1), I40E_PRTTSYN_AUX_1_INSTNT);
0388 wr32(hw, I40E_PRTTSYN_AUX_0(1), I40E_PRTTSYN_AUX_0_OUT_ENABLE);
0389
0390 i40e_ptp_read(pf, &now, NULL);
0391 now.tv_sec += I40E_PTP_2_SEC_DELAY;
0392 now.tv_nsec = 0;
0393 ns = timespec64_to_ns(&now);
0394
0395
0396 wr32(hw, I40E_PRTTSYN_TGT_L(1), ns & 0xFFFFFFFF);
0397
0398 wr32(hw, I40E_PRTTSYN_TGT_H(1), ns >> 32);
0399 wr32(hw, I40E_PRTTSYN_CLKO(1), I40E_PTP_HALF_SECOND);
0400 wr32(hw, I40E_PRTTSYN_AUX_1(1), I40E_PRTTSYN_AUX_1_INSTNT);
0401 wr32(hw, I40E_PRTTSYN_AUX_0(1),
0402 I40E_PRTTSYN_AUX_0_OUT_ENABLE_CLK_MOD);
0403 }
0404
0405
0406
0407
0408
0409
0410
0411
0412 static int i40e_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
0413 {
0414 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps);
0415 struct i40e_hw *hw = &pf->hw;
0416
0417 mutex_lock(&pf->tmreg_lock);
0418
0419 if (delta > -999999900LL && delta < 999999900LL) {
0420 int neg_adj = 0;
0421 u32 timadj;
0422 u64 tohw;
0423
0424 if (delta < 0) {
0425 neg_adj = 1;
0426 tohw = -delta;
0427 } else {
0428 tohw = delta;
0429 }
0430
0431 timadj = tohw & 0x3FFFFFFF;
0432 if (neg_adj)
0433 timadj |= I40E_ISGN;
0434 wr32(hw, I40E_PRTTSYN_ADJ, timadj);
0435 } else {
0436 struct timespec64 then, now;
0437
0438 then = ns_to_timespec64(delta);
0439 i40e_ptp_read(pf, &now, NULL);
0440 now = timespec64_add(now, then);
0441 i40e_ptp_write(pf, (const struct timespec64 *)&now);
0442 i40e_ptp_set_1pps_signal_hw(pf);
0443 }
0444
0445 mutex_unlock(&pf->tmreg_lock);
0446
0447 return 0;
0448 }
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459 static int i40e_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
0460 struct ptp_system_timestamp *sts)
0461 {
0462 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps);
0463
0464 mutex_lock(&pf->tmreg_lock);
0465 i40e_ptp_read(pf, ts, sts);
0466 mutex_unlock(&pf->tmreg_lock);
0467
0468 return 0;
0469 }
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479 static int i40e_ptp_settime(struct ptp_clock_info *ptp,
0480 const struct timespec64 *ts)
0481 {
0482 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps);
0483
0484 mutex_lock(&pf->tmreg_lock);
0485 i40e_ptp_write(pf, ts);
0486 mutex_unlock(&pf->tmreg_lock);
0487
0488 return 0;
0489 }
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500 static int i40e_pps_configure(struct ptp_clock_info *ptp,
0501 struct ptp_clock_request *rq,
0502 int on)
0503 {
0504 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps);
0505
0506 if (!!on)
0507 i40e_ptp_set_1pps_signal_hw(pf);
0508
0509 return 0;
0510 }
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520 static enum i40e_ptp_gpio_pin_state i40e_pin_state(int index, int func)
0521 {
0522 enum i40e_ptp_gpio_pin_state state = off;
0523
0524 if (index == 0 && func == PTP_PF_EXTTS)
0525 state = in_A;
0526 if (index == 1 && func == PTP_PF_EXTTS)
0527 state = in_B;
0528 if (index == 0 && func == PTP_PF_PEROUT)
0529 state = out_A;
0530 if (index == 1 && func == PTP_PF_PEROUT)
0531 state = out_B;
0532
0533 return state;
0534 }
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546 static int i40e_ptp_enable_pin(struct i40e_pf *pf, unsigned int chan,
0547 enum ptp_pin_function func, int on)
0548 {
0549 enum i40e_ptp_gpio_pin_state *pin = NULL;
0550 struct i40e_ptp_pins_settings pins;
0551 int pin_index;
0552
0553
0554 if (pf->hw.pf_id)
0555 return 0;
0556
0557
0558 pins.sdp3_2 = pf->ptp_pins->sdp3_2;
0559 pins.sdp3_3 = pf->ptp_pins->sdp3_3;
0560 pins.gpio_4 = pf->ptp_pins->gpio_4;
0561
0562
0563
0564
0565
0566
0567
0568 if (on) {
0569 pin_index = ptp_find_pin(pf->ptp_clock, func, chan);
0570 if (pin_index < 0)
0571 return -EBUSY;
0572
0573 switch (pin_index) {
0574 case SDP3_2:
0575 pin = &pins.sdp3_2;
0576 break;
0577 case SDP3_3:
0578 pin = &pins.sdp3_3;
0579 break;
0580 case GPIO_4:
0581 pin = &pins.gpio_4;
0582 break;
0583 default:
0584 return -EINVAL;
0585 }
0586
0587 *pin = i40e_pin_state(chan, func);
0588 } else {
0589 pins.sdp3_2 = off;
0590 pins.sdp3_3 = off;
0591 pins.gpio_4 = off;
0592 }
0593
0594 return i40e_ptp_set_pins(pf, &pins) ? -EINVAL : 0;
0595 }
0596
0597
0598
0599
0600
0601
0602
0603
0604
0605 static int i40e_ptp_feature_enable(struct ptp_clock_info *ptp,
0606 struct ptp_clock_request *rq,
0607 int on)
0608 {
0609 struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps);
0610
0611 enum ptp_pin_function func;
0612 unsigned int chan;
0613
0614
0615 switch (rq->type) {
0616 case PTP_CLK_REQ_EXTTS:
0617 func = PTP_PF_EXTTS;
0618 chan = rq->extts.index;
0619 break;
0620 case PTP_CLK_REQ_PEROUT:
0621 func = PTP_PF_PEROUT;
0622 chan = rq->perout.index;
0623 break;
0624 case PTP_CLK_REQ_PPS:
0625 return i40e_pps_configure(ptp, rq, on);
0626 default:
0627 return -EOPNOTSUPP;
0628 }
0629
0630 return i40e_ptp_enable_pin(pf, chan, func, on);
0631 }
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645 static u32 i40e_ptp_get_rx_events(struct i40e_pf *pf)
0646 {
0647 struct i40e_hw *hw = &pf->hw;
0648 u32 prttsyn_stat, new_latch_events;
0649 int i;
0650
0651 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_1);
0652 new_latch_events = prttsyn_stat & ~pf->latch_event_flags;
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663 for (i = 0; i < 4; i++) {
0664 if (new_latch_events & BIT(i))
0665 pf->latch_events[i] = jiffies;
0666 }
0667
0668
0669 pf->latch_event_flags = prttsyn_stat;
0670
0671 return prttsyn_stat;
0672 }
0673
0674
0675
0676
0677
0678
0679
0680
0681
0682
0683 void i40e_ptp_rx_hang(struct i40e_pf *pf)
0684 {
0685 struct i40e_hw *hw = &pf->hw;
0686 unsigned int i, cleared = 0;
0687
0688
0689
0690
0691
0692
0693 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_rx)
0694 return;
0695
0696 spin_lock_bh(&pf->ptp_rx_lock);
0697
0698
0699 i40e_ptp_get_rx_events(pf);
0700
0701
0702
0703
0704
0705
0706
0707 for (i = 0; i < 4; i++) {
0708 if ((pf->latch_event_flags & BIT(i)) &&
0709 time_is_before_jiffies(pf->latch_events[i] + HZ)) {
0710 rd32(hw, I40E_PRTTSYN_RXTIME_H(i));
0711 pf->latch_event_flags &= ~BIT(i);
0712 cleared++;
0713 }
0714 }
0715
0716 spin_unlock_bh(&pf->ptp_rx_lock);
0717
0718
0719
0720
0721
0722
0723
0724 if (cleared > 2)
0725 dev_dbg(&pf->pdev->dev,
0726 "Dropped %d missed RXTIME timestamp events\n",
0727 cleared);
0728
0729
0730 pf->rx_hwtstamp_cleared += cleared;
0731 }
0732
0733
0734
0735
0736
0737
0738
0739
0740
0741
0742 void i40e_ptp_tx_hang(struct i40e_pf *pf)
0743 {
0744 struct sk_buff *skb;
0745
0746 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_tx)
0747 return;
0748
0749
0750 if (!test_bit(__I40E_PTP_TX_IN_PROGRESS, pf->state))
0751 return;
0752
0753
0754
0755
0756
0757 if (time_is_before_jiffies(pf->ptp_tx_start + HZ)) {
0758 skb = pf->ptp_tx_skb;
0759 pf->ptp_tx_skb = NULL;
0760 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state);
0761
0762
0763 dev_kfree_skb_any(skb);
0764 pf->tx_hwtstamp_timeouts++;
0765 }
0766 }
0767
0768
0769
0770
0771
0772
0773
0774
0775
0776 void i40e_ptp_tx_hwtstamp(struct i40e_pf *pf)
0777 {
0778 struct skb_shared_hwtstamps shhwtstamps;
0779 struct sk_buff *skb = pf->ptp_tx_skb;
0780 struct i40e_hw *hw = &pf->hw;
0781 u32 hi, lo;
0782 u64 ns;
0783
0784 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_tx)
0785 return;
0786
0787
0788 if (!pf->ptp_tx_skb)
0789 return;
0790
0791 lo = rd32(hw, I40E_PRTTSYN_TXTIME_L);
0792 hi = rd32(hw, I40E_PRTTSYN_TXTIME_H);
0793
0794 ns = (((u64)hi) << 32) | lo;
0795 i40e_ptp_convert_to_hwtstamp(&shhwtstamps, ns);
0796
0797
0798
0799
0800
0801
0802 pf->ptp_tx_skb = NULL;
0803 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state);
0804
0805
0806 skb_tstamp_tx(skb, &shhwtstamps);
0807 dev_kfree_skb_any(skb);
0808 }
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820
0821
0822 void i40e_ptp_rx_hwtstamp(struct i40e_pf *pf, struct sk_buff *skb, u8 index)
0823 {
0824 u32 prttsyn_stat, hi, lo;
0825 struct i40e_hw *hw;
0826 u64 ns;
0827
0828
0829
0830
0831 if (!(pf->flags & I40E_FLAG_PTP) || !pf->ptp_rx)
0832 return;
0833
0834 hw = &pf->hw;
0835
0836 spin_lock_bh(&pf->ptp_rx_lock);
0837
0838
0839 prttsyn_stat = i40e_ptp_get_rx_events(pf);
0840
0841
0842 if (!(prttsyn_stat & BIT(index))) {
0843 spin_unlock_bh(&pf->ptp_rx_lock);
0844 return;
0845 }
0846
0847
0848 pf->latch_event_flags &= ~BIT(index);
0849
0850 lo = rd32(hw, I40E_PRTTSYN_RXTIME_L(index));
0851 hi = rd32(hw, I40E_PRTTSYN_RXTIME_H(index));
0852
0853 spin_unlock_bh(&pf->ptp_rx_lock);
0854
0855 ns = (((u64)hi) << 32) | lo;
0856
0857 i40e_ptp_convert_to_hwtstamp(skb_hwtstamps(skb), ns);
0858 }
0859
0860
0861
0862
0863
0864
0865
0866
0867
0868 void i40e_ptp_set_increment(struct i40e_pf *pf)
0869 {
0870 struct i40e_link_status *hw_link_info;
0871 struct i40e_hw *hw = &pf->hw;
0872 u64 incval;
0873 u32 mult;
0874
0875 hw_link_info = &hw->phy.link_info;
0876
0877 i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
0878
0879 switch (hw_link_info->link_speed) {
0880 case I40E_LINK_SPEED_10GB:
0881 mult = I40E_PTP_10GB_INCVAL_MULT;
0882 break;
0883 case I40E_LINK_SPEED_5GB:
0884 mult = I40E_PTP_5GB_INCVAL_MULT;
0885 break;
0886 case I40E_LINK_SPEED_1GB:
0887 mult = I40E_PTP_1GB_INCVAL_MULT;
0888 break;
0889 case I40E_LINK_SPEED_100MB:
0890 {
0891 static int warn_once;
0892
0893 if (!warn_once) {
0894 dev_warn(&pf->pdev->dev,
0895 "1588 functionality is not supported at 100 Mbps. Stopping the PHC.\n");
0896 warn_once++;
0897 }
0898 mult = 0;
0899 break;
0900 }
0901 case I40E_LINK_SPEED_40GB:
0902 default:
0903 mult = 1;
0904 break;
0905 }
0906
0907
0908
0909
0910 incval = I40E_PTP_40GB_INCVAL * mult;
0911
0912
0913
0914
0915
0916 wr32(hw, I40E_PRTTSYN_INC_L, incval & 0xFFFFFFFF);
0917 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
0918
0919
0920 WRITE_ONCE(pf->ptp_adj_mult, mult);
0921 smp_mb();
0922 }
0923
0924
0925
0926
0927
0928
0929
0930
0931
0932
0933 int i40e_ptp_get_ts_config(struct i40e_pf *pf, struct ifreq *ifr)
0934 {
0935 struct hwtstamp_config *config = &pf->tstamp_config;
0936
0937 if (!(pf->flags & I40E_FLAG_PTP))
0938 return -EOPNOTSUPP;
0939
0940 return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ?
0941 -EFAULT : 0;
0942 }
0943
0944
0945
0946
0947
0948
0949
0950 static void i40e_ptp_free_pins(struct i40e_pf *pf)
0951 {
0952 if (i40e_is_ptp_pin_dev(&pf->hw)) {
0953 kfree(pf->ptp_pins);
0954 kfree(pf->ptp_caps.pin_config);
0955 pf->ptp_pins = NULL;
0956 }
0957 }
0958
0959
0960
0961
0962
0963
0964
0965
0966
0967 static void i40e_ptp_set_pin_hw(struct i40e_hw *hw,
0968 unsigned int pin,
0969 enum i40e_ptp_gpio_pin_state state)
0970 {
0971 switch (state) {
0972 case off:
0973 wr32(hw, I40E_GLGEN_GPIO_CTL(pin), 0);
0974 break;
0975 case in_A:
0976 wr32(hw, I40E_GLGEN_GPIO_CTL(pin),
0977 I40E_GLGEN_GPIO_CTL_PORT_0_IN_TIMESYNC_0);
0978 break;
0979 case in_B:
0980 wr32(hw, I40E_GLGEN_GPIO_CTL(pin),
0981 I40E_GLGEN_GPIO_CTL_PORT_1_IN_TIMESYNC_0);
0982 break;
0983 case out_A:
0984 wr32(hw, I40E_GLGEN_GPIO_CTL(pin),
0985 I40E_GLGEN_GPIO_CTL_PORT_0_OUT_TIMESYNC_1);
0986 break;
0987 case out_B:
0988 wr32(hw, I40E_GLGEN_GPIO_CTL(pin),
0989 I40E_GLGEN_GPIO_CTL_PORT_1_OUT_TIMESYNC_1);
0990 break;
0991 default:
0992 break;
0993 }
0994 }
0995
0996
0997
0998
0999
1000
1001
1002
1003
1004 static void i40e_ptp_set_led_hw(struct i40e_hw *hw,
1005 unsigned int led,
1006 enum i40e_ptp_led_pin_state state)
1007 {
1008 switch (state) {
1009 case low:
1010 wr32(hw, I40E_GLGEN_GPIO_SET,
1011 I40E_GLGEN_GPIO_SET_DRV_SDP_DATA | led);
1012 break;
1013 case high:
1014 wr32(hw, I40E_GLGEN_GPIO_SET,
1015 I40E_GLGEN_GPIO_SET_DRV_SDP_DATA |
1016 I40E_GLGEN_GPIO_SET_SDP_DATA_HI | led);
1017 break;
1018 default:
1019 break;
1020 }
1021 }
1022
1023
1024
1025
1026
1027
1028
1029 static void i40e_ptp_init_leds_hw(struct i40e_hw *hw)
1030 {
1031 wr32(hw, I40E_GLGEN_GPIO_CTL(I40E_LED2_0),
1032 I40E_GLGEN_GPIO_CTL_LED_INIT);
1033 wr32(hw, I40E_GLGEN_GPIO_CTL(I40E_LED2_1),
1034 I40E_GLGEN_GPIO_CTL_LED_INIT);
1035 wr32(hw, I40E_GLGEN_GPIO_CTL(I40E_LED3_0),
1036 I40E_GLGEN_GPIO_CTL_LED_INIT);
1037 wr32(hw, I40E_GLGEN_GPIO_CTL(I40E_LED3_1),
1038 I40E_GLGEN_GPIO_CTL_LED_INIT);
1039 }
1040
1041
1042
1043
1044
1045
1046
1047 static void i40e_ptp_set_pins_hw(struct i40e_pf *pf)
1048 {
1049 const struct i40e_ptp_pins_settings *pins = pf->ptp_pins;
1050 struct i40e_hw *hw = &pf->hw;
1051
1052
1053 i40e_ptp_set_pin_hw(hw, I40E_SDP3_2, off);
1054 i40e_ptp_set_pin_hw(hw, I40E_SDP3_3, off);
1055 i40e_ptp_set_pin_hw(hw, I40E_GPIO_4, off);
1056
1057 i40e_ptp_set_pin_hw(hw, I40E_SDP3_2, pins->sdp3_2);
1058 i40e_ptp_set_pin_hw(hw, I40E_SDP3_3, pins->sdp3_3);
1059 i40e_ptp_set_pin_hw(hw, I40E_GPIO_4, pins->gpio_4);
1060
1061 i40e_ptp_set_led_hw(hw, I40E_LED2_0, pins->led2_0);
1062 i40e_ptp_set_led_hw(hw, I40E_LED2_1, pins->led2_1);
1063 i40e_ptp_set_led_hw(hw, I40E_LED3_0, pins->led3_0);
1064 i40e_ptp_set_led_hw(hw, I40E_LED3_1, pins->led3_1);
1065
1066 dev_info(&pf->pdev->dev,
1067 "PTP configuration set to: SDP3_2: %s, SDP3_3: %s, GPIO_4: %s.\n",
1068 i40e_ptp_gpio_pin_state2str[pins->sdp3_2],
1069 i40e_ptp_gpio_pin_state2str[pins->sdp3_3],
1070 i40e_ptp_gpio_pin_state2str[pins->gpio_4]);
1071 }
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081 static int i40e_ptp_set_pins(struct i40e_pf *pf,
1082 struct i40e_ptp_pins_settings *pins)
1083 {
1084 enum i40e_can_set_pins_t pin_caps = i40e_can_set_pins(pf);
1085 int i = 0;
1086
1087 if (pin_caps == CANT_DO_PINS)
1088 return -EOPNOTSUPP;
1089 else if (pin_caps == CAN_DO_PINS)
1090 return 0;
1091
1092 if (pins->sdp3_2 == invalid)
1093 pins->sdp3_2 = pf->ptp_pins->sdp3_2;
1094 if (pins->sdp3_3 == invalid)
1095 pins->sdp3_3 = pf->ptp_pins->sdp3_3;
1096 if (pins->gpio_4 == invalid)
1097 pins->gpio_4 = pf->ptp_pins->gpio_4;
1098 while (i40e_ptp_pin_led_allowed_states[i].sdp3_2 != end) {
1099 if (pins->sdp3_2 == i40e_ptp_pin_led_allowed_states[i].sdp3_2 &&
1100 pins->sdp3_3 == i40e_ptp_pin_led_allowed_states[i].sdp3_3 &&
1101 pins->gpio_4 == i40e_ptp_pin_led_allowed_states[i].gpio_4) {
1102 pins->led2_0 =
1103 i40e_ptp_pin_led_allowed_states[i].led2_0;
1104 pins->led2_1 =
1105 i40e_ptp_pin_led_allowed_states[i].led2_1;
1106 pins->led3_0 =
1107 i40e_ptp_pin_led_allowed_states[i].led3_0;
1108 pins->led3_1 =
1109 i40e_ptp_pin_led_allowed_states[i].led3_1;
1110 break;
1111 }
1112 i++;
1113 }
1114 if (i40e_ptp_pin_led_allowed_states[i].sdp3_2 == end) {
1115 dev_warn(&pf->pdev->dev,
1116 "Unsupported PTP pin configuration: SDP3_2: %s, SDP3_3: %s, GPIO_4: %s.\n",
1117 i40e_ptp_gpio_pin_state2str[pins->sdp3_2],
1118 i40e_ptp_gpio_pin_state2str[pins->sdp3_3],
1119 i40e_ptp_gpio_pin_state2str[pins->gpio_4]);
1120
1121 return -EPERM;
1122 }
1123 memcpy(pf->ptp_pins, pins, sizeof(*pins));
1124 i40e_ptp_set_pins_hw(pf);
1125 i40_ptp_reset_timing_events(pf);
1126
1127 return 0;
1128 }
1129
1130
1131
1132
1133
1134
1135
1136 int i40e_ptp_alloc_pins(struct i40e_pf *pf)
1137 {
1138 if (!i40e_is_ptp_pin_dev(&pf->hw))
1139 return 0;
1140
1141 pf->ptp_pins =
1142 kzalloc(sizeof(struct i40e_ptp_pins_settings), GFP_KERNEL);
1143
1144 if (!pf->ptp_pins) {
1145 dev_warn(&pf->pdev->dev, "Cannot allocate memory for PTP pins structure.\n");
1146 return -I40E_ERR_NO_MEMORY;
1147 }
1148
1149 pf->ptp_pins->sdp3_2 = off;
1150 pf->ptp_pins->sdp3_3 = off;
1151 pf->ptp_pins->gpio_4 = off;
1152 pf->ptp_pins->led2_0 = high;
1153 pf->ptp_pins->led2_1 = high;
1154 pf->ptp_pins->led3_0 = high;
1155 pf->ptp_pins->led3_1 = high;
1156
1157
1158 if (pf->hw.pf_id)
1159 return 0;
1160
1161 i40e_ptp_init_leds_hw(&pf->hw);
1162 i40e_ptp_set_pins_hw(pf);
1163
1164 return 0;
1165 }
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179 static int i40e_ptp_set_timestamp_mode(struct i40e_pf *pf,
1180 struct hwtstamp_config *config)
1181 {
1182 struct i40e_hw *hw = &pf->hw;
1183 u32 tsyntype, regval;
1184
1185
1186 regval = rd32(hw, I40E_PRTTSYN_AUX_0(0));
1187
1188 regval &= 0;
1189 regval |= (1 << I40E_PRTTSYN_AUX_0_EVNTLVL_SHIFT);
1190
1191 wr32(hw, I40E_PRTTSYN_AUX_0(0), regval);
1192
1193
1194 regval = rd32(hw, I40E_PRTTSYN_CTL0);
1195 regval |= 1 << I40E_PRTTSYN_CTL0_EVENT_INT_ENA_SHIFT;
1196 wr32(hw, I40E_PRTTSYN_CTL0, regval);
1197
1198 INIT_WORK(&pf->ptp_extts0_work, i40e_ptp_extts0_work);
1199
1200 switch (config->tx_type) {
1201 case HWTSTAMP_TX_OFF:
1202 pf->ptp_tx = false;
1203 break;
1204 case HWTSTAMP_TX_ON:
1205 pf->ptp_tx = true;
1206 break;
1207 default:
1208 return -ERANGE;
1209 }
1210
1211 switch (config->rx_filter) {
1212 case HWTSTAMP_FILTER_NONE:
1213 pf->ptp_rx = false;
1214
1215
1216
1217
1218
1219 tsyntype = I40E_PRTTSYN_CTL1_TSYNTYPE_V1;
1220 break;
1221 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
1222 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
1223 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
1224 if (!(pf->hw_features & I40E_HW_PTP_L4_CAPABLE))
1225 return -ERANGE;
1226 pf->ptp_rx = true;
1227 tsyntype = I40E_PRTTSYN_CTL1_V1MESSTYPE0_MASK |
1228 I40E_PRTTSYN_CTL1_TSYNTYPE_V1 |
1229 I40E_PRTTSYN_CTL1_UDP_ENA_MASK;
1230 config->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
1231 break;
1232 case HWTSTAMP_FILTER_PTP_V2_EVENT:
1233 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
1234 case HWTSTAMP_FILTER_PTP_V2_SYNC:
1235 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
1236 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
1237 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
1238 if (!(pf->hw_features & I40E_HW_PTP_L4_CAPABLE))
1239 return -ERANGE;
1240 fallthrough;
1241 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
1242 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
1243 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
1244 pf->ptp_rx = true;
1245 tsyntype = I40E_PRTTSYN_CTL1_V2MESSTYPE0_MASK |
1246 I40E_PRTTSYN_CTL1_TSYNTYPE_V2;
1247 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE) {
1248 tsyntype |= I40E_PRTTSYN_CTL1_UDP_ENA_MASK;
1249 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
1250 } else {
1251 config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
1252 }
1253 break;
1254 case HWTSTAMP_FILTER_NTP_ALL:
1255 case HWTSTAMP_FILTER_ALL:
1256 default:
1257 return -ERANGE;
1258 }
1259
1260
1261 spin_lock_bh(&pf->ptp_rx_lock);
1262 rd32(hw, I40E_PRTTSYN_STAT_0);
1263 rd32(hw, I40E_PRTTSYN_TXTIME_H);
1264 rd32(hw, I40E_PRTTSYN_RXTIME_H(0));
1265 rd32(hw, I40E_PRTTSYN_RXTIME_H(1));
1266 rd32(hw, I40E_PRTTSYN_RXTIME_H(2));
1267 rd32(hw, I40E_PRTTSYN_RXTIME_H(3));
1268 pf->latch_event_flags = 0;
1269 spin_unlock_bh(&pf->ptp_rx_lock);
1270
1271
1272 regval = rd32(hw, I40E_PRTTSYN_CTL0);
1273 if (pf->ptp_tx)
1274 regval |= I40E_PRTTSYN_CTL0_TXTIME_INT_ENA_MASK;
1275 else
1276 regval &= ~I40E_PRTTSYN_CTL0_TXTIME_INT_ENA_MASK;
1277 wr32(hw, I40E_PRTTSYN_CTL0, regval);
1278
1279 regval = rd32(hw, I40E_PFINT_ICR0_ENA);
1280 if (pf->ptp_tx)
1281 regval |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
1282 else
1283 regval &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
1284 wr32(hw, I40E_PFINT_ICR0_ENA, regval);
1285
1286
1287
1288
1289
1290
1291
1292 regval = rd32(hw, I40E_PRTTSYN_CTL1);
1293
1294 regval &= I40E_PRTTSYN_CTL1_TSYNENA_MASK;
1295
1296 regval |= tsyntype;
1297 wr32(hw, I40E_PRTTSYN_CTL1, regval);
1298
1299 return 0;
1300 }
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316 int i40e_ptp_set_ts_config(struct i40e_pf *pf, struct ifreq *ifr)
1317 {
1318 struct hwtstamp_config config;
1319 int err;
1320
1321 if (!(pf->flags & I40E_FLAG_PTP))
1322 return -EOPNOTSUPP;
1323
1324 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
1325 return -EFAULT;
1326
1327 err = i40e_ptp_set_timestamp_mode(pf, &config);
1328 if (err)
1329 return err;
1330
1331
1332 pf->tstamp_config = config;
1333
1334 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
1335 -EFAULT : 0;
1336 }
1337
1338
1339
1340
1341
1342
1343
1344
1345 static int i40e_init_pin_config(struct i40e_pf *pf)
1346 {
1347 int i;
1348
1349 pf->ptp_caps.n_pins = 3;
1350 pf->ptp_caps.n_ext_ts = 2;
1351 pf->ptp_caps.pps = 1;
1352 pf->ptp_caps.n_per_out = 2;
1353
1354 pf->ptp_caps.pin_config = kcalloc(pf->ptp_caps.n_pins,
1355 sizeof(*pf->ptp_caps.pin_config),
1356 GFP_KERNEL);
1357 if (!pf->ptp_caps.pin_config)
1358 return -ENOMEM;
1359
1360 for (i = 0; i < pf->ptp_caps.n_pins; i++) {
1361 snprintf(pf->ptp_caps.pin_config[i].name,
1362 sizeof(pf->ptp_caps.pin_config[i].name),
1363 "%s", sdp_desc[i].name);
1364 pf->ptp_caps.pin_config[i].index = sdp_desc[i].index;
1365 pf->ptp_caps.pin_config[i].func = PTP_PF_NONE;
1366 pf->ptp_caps.pin_config[i].chan = sdp_desc[i].chan;
1367 }
1368
1369 pf->ptp_caps.verify = i40e_ptp_verify;
1370 pf->ptp_caps.enable = i40e_ptp_feature_enable;
1371
1372 pf->ptp_caps.pps = 1;
1373
1374 return 0;
1375 }
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387 static long i40e_ptp_create_clock(struct i40e_pf *pf)
1388 {
1389
1390 if (!IS_ERR_OR_NULL(pf->ptp_clock))
1391 return 0;
1392
1393 strlcpy(pf->ptp_caps.name, i40e_driver_name,
1394 sizeof(pf->ptp_caps.name) - 1);
1395 pf->ptp_caps.owner = THIS_MODULE;
1396 pf->ptp_caps.max_adj = 999999999;
1397 pf->ptp_caps.adjfine = i40e_ptp_adjfine;
1398 pf->ptp_caps.adjtime = i40e_ptp_adjtime;
1399 pf->ptp_caps.gettimex64 = i40e_ptp_gettimex;
1400 pf->ptp_caps.settime64 = i40e_ptp_settime;
1401 if (i40e_is_ptp_pin_dev(&pf->hw)) {
1402 int err = i40e_init_pin_config(pf);
1403
1404 if (err)
1405 return err;
1406 }
1407
1408
1409 pf->ptp_clock = ptp_clock_register(&pf->ptp_caps, &pf->pdev->dev);
1410 if (IS_ERR(pf->ptp_clock))
1411 return PTR_ERR(pf->ptp_clock);
1412
1413
1414
1415
1416
1417 pf->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
1418 pf->tstamp_config.tx_type = HWTSTAMP_TX_OFF;
1419
1420
1421 ktime_get_real_ts64(&pf->ptp_prev_hw_time);
1422 pf->ptp_reset_start = ktime_get();
1423
1424 return 0;
1425 }
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436 void i40e_ptp_save_hw_time(struct i40e_pf *pf)
1437 {
1438
1439 if (!(pf->flags & I40E_FLAG_PTP))
1440 return;
1441
1442 i40e_ptp_gettimex(&pf->ptp_caps, &pf->ptp_prev_hw_time, NULL);
1443
1444 pf->ptp_reset_start = ktime_get();
1445 }
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459 void i40e_ptp_restore_hw_time(struct i40e_pf *pf)
1460 {
1461 ktime_t delta = ktime_sub(ktime_get(), pf->ptp_reset_start);
1462
1463
1464 timespec64_add_ns(&pf->ptp_prev_hw_time, ktime_to_ns(delta));
1465
1466
1467 i40e_ptp_settime(&pf->ptp_caps, &pf->ptp_prev_hw_time);
1468 }
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483 void i40e_ptp_init(struct i40e_pf *pf)
1484 {
1485 struct net_device *netdev = pf->vsi[pf->lan_vsi]->netdev;
1486 struct i40e_hw *hw = &pf->hw;
1487 u32 pf_id;
1488 long err;
1489
1490
1491
1492
1493 pf_id = (rd32(hw, I40E_PRTTSYN_CTL0) & I40E_PRTTSYN_CTL0_PF_ID_MASK) >>
1494 I40E_PRTTSYN_CTL0_PF_ID_SHIFT;
1495 if (hw->pf_id != pf_id) {
1496 pf->flags &= ~I40E_FLAG_PTP;
1497 dev_info(&pf->pdev->dev, "%s: PTP not supported on %s\n",
1498 __func__,
1499 netdev->name);
1500 return;
1501 }
1502
1503 mutex_init(&pf->tmreg_lock);
1504 spin_lock_init(&pf->ptp_rx_lock);
1505
1506
1507 err = i40e_ptp_create_clock(pf);
1508 if (err) {
1509 pf->ptp_clock = NULL;
1510 dev_err(&pf->pdev->dev, "%s: ptp_clock_register failed\n",
1511 __func__);
1512 } else if (pf->ptp_clock) {
1513 u32 regval;
1514
1515 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
1516 dev_info(&pf->pdev->dev, "PHC enabled\n");
1517 pf->flags |= I40E_FLAG_PTP;
1518
1519
1520 regval = rd32(hw, I40E_PRTTSYN_CTL0);
1521 regval |= I40E_PRTTSYN_CTL0_TSYNENA_MASK;
1522 wr32(hw, I40E_PRTTSYN_CTL0, regval);
1523 regval = rd32(hw, I40E_PRTTSYN_CTL1);
1524 regval |= I40E_PRTTSYN_CTL1_TSYNENA_MASK;
1525 wr32(hw, I40E_PRTTSYN_CTL1, regval);
1526
1527
1528 i40e_ptp_set_increment(pf);
1529
1530
1531 i40e_ptp_set_timestamp_mode(pf, &pf->tstamp_config);
1532
1533
1534 i40e_ptp_restore_hw_time(pf);
1535 }
1536
1537 i40e_ptp_set_1pps_signal_hw(pf);
1538 }
1539
1540
1541
1542
1543
1544
1545
1546
1547 void i40e_ptp_stop(struct i40e_pf *pf)
1548 {
1549 struct i40e_hw *hw = &pf->hw;
1550 u32 regval;
1551
1552 pf->flags &= ~I40E_FLAG_PTP;
1553 pf->ptp_tx = false;
1554 pf->ptp_rx = false;
1555
1556 if (pf->ptp_tx_skb) {
1557 struct sk_buff *skb = pf->ptp_tx_skb;
1558
1559 pf->ptp_tx_skb = NULL;
1560 clear_bit_unlock(__I40E_PTP_TX_IN_PROGRESS, pf->state);
1561 dev_kfree_skb_any(skb);
1562 }
1563
1564 if (pf->ptp_clock) {
1565 ptp_clock_unregister(pf->ptp_clock);
1566 pf->ptp_clock = NULL;
1567 dev_info(&pf->pdev->dev, "%s: removed PHC on %s\n", __func__,
1568 pf->vsi[pf->lan_vsi]->netdev->name);
1569 }
1570
1571 if (i40e_is_ptp_pin_dev(&pf->hw)) {
1572 i40e_ptp_set_pin_hw(hw, I40E_SDP3_2, off);
1573 i40e_ptp_set_pin_hw(hw, I40E_SDP3_3, off);
1574 i40e_ptp_set_pin_hw(hw, I40E_GPIO_4, off);
1575 }
1576
1577 regval = rd32(hw, I40E_PRTTSYN_AUX_0(0));
1578 regval &= ~I40E_PRTTSYN_AUX_0_PTPFLAG_MASK;
1579 wr32(hw, I40E_PRTTSYN_AUX_0(0), regval);
1580
1581
1582 regval = rd32(hw, I40E_PRTTSYN_CTL0);
1583 regval &= ~I40E_PRTTSYN_CTL0_EVENT_INT_ENA_MASK;
1584 wr32(hw, I40E_PRTTSYN_CTL0, regval);
1585
1586 i40e_ptp_free_pins(pf);
1587 }