| .. | .. |
|---|
| 2 | 2 | /* Copyright (C) 2018 Microchip Technology Inc. */ |
|---|
| 3 | 3 | |
|---|
| 4 | 4 | #include <linux/netdevice.h> |
|---|
| 5 | | -#include "lan743x_main.h" |
|---|
| 6 | 5 | |
|---|
| 7 | 6 | #include <linux/ptp_clock_kernel.h> |
|---|
| 8 | 7 | #include <linux/module.h> |
|---|
| 9 | 8 | #include <linux/pci.h> |
|---|
| 10 | 9 | #include <linux/net_tstamp.h> |
|---|
| 10 | +#include "lan743x_main.h" |
|---|
| 11 | 11 | |
|---|
| 12 | 12 | #include "lan743x_ptp.h" |
|---|
| 13 | 13 | |
|---|
| 14 | | -#define LAN743X_NUMBER_OF_GPIO (12) |
|---|
| 14 | +#define LAN743X_LED0_ENABLE 20 /* LED0 offset in HW_CFG */ |
|---|
| 15 | +#define LAN743X_LED_ENABLE(pin) BIT(LAN743X_LED0_ENABLE + (pin)) |
|---|
| 16 | + |
|---|
| 15 | 17 | #define LAN743X_PTP_MAX_FREQ_ADJ_IN_PPB (31249999) |
|---|
| 16 | 18 | #define LAN743X_PTP_MAX_FINE_ADJ_IN_SCALED_PPM (2047999934) |
|---|
| 17 | 19 | |
|---|
| .. | .. |
|---|
| 139 | 141 | spin_unlock_bh(&ptp->tx_ts_lock); |
|---|
| 140 | 142 | } |
|---|
| 141 | 143 | |
|---|
| 142 | | -static int lan743x_ptp_reserve_event_ch(struct lan743x_adapter *adapter) |
|---|
| 144 | +static int lan743x_ptp_reserve_event_ch(struct lan743x_adapter *adapter, |
|---|
| 145 | + int event_channel) |
|---|
| 143 | 146 | { |
|---|
| 144 | 147 | struct lan743x_ptp *ptp = &adapter->ptp; |
|---|
| 145 | 148 | int result = -ENODEV; |
|---|
| 146 | | - int index = 0; |
|---|
| 147 | 149 | |
|---|
| 148 | 150 | mutex_lock(&ptp->command_lock); |
|---|
| 149 | | - for (index = 0; index < LAN743X_PTP_NUMBER_OF_EVENT_CHANNELS; index++) { |
|---|
| 150 | | - if (!(test_bit(index, &ptp->used_event_ch))) { |
|---|
| 151 | | - ptp->used_event_ch |= BIT(index); |
|---|
| 152 | | - result = index; |
|---|
| 153 | | - break; |
|---|
| 154 | | - } |
|---|
| 151 | + if (!(test_bit(event_channel, &ptp->used_event_ch))) { |
|---|
| 152 | + ptp->used_event_ch |= BIT(event_channel); |
|---|
| 153 | + result = event_channel; |
|---|
| 154 | + } else { |
|---|
| 155 | + netif_warn(adapter, drv, adapter->netdev, |
|---|
| 156 | + "attempted to reserved a used event_channel = %d\n", |
|---|
| 157 | + event_channel); |
|---|
| 155 | 158 | } |
|---|
| 156 | 159 | mutex_unlock(&ptp->command_lock); |
|---|
| 157 | 160 | return result; |
|---|
| .. | .. |
|---|
| 179 | 182 | static void lan743x_ptp_clock_step(struct lan743x_adapter *adapter, |
|---|
| 180 | 183 | s64 time_step_ns); |
|---|
| 181 | 184 | |
|---|
| 185 | +static void lan743x_led_mux_enable(struct lan743x_adapter *adapter, |
|---|
| 186 | + int pin, bool enable) |
|---|
| 187 | +{ |
|---|
| 188 | + struct lan743x_ptp *ptp = &adapter->ptp; |
|---|
| 189 | + |
|---|
| 190 | + if (ptp->leds_multiplexed && |
|---|
| 191 | + ptp->led_enabled[pin]) { |
|---|
| 192 | + u32 val = lan743x_csr_read(adapter, HW_CFG); |
|---|
| 193 | + |
|---|
| 194 | + if (enable) |
|---|
| 195 | + val |= LAN743X_LED_ENABLE(pin); |
|---|
| 196 | + else |
|---|
| 197 | + val &= ~LAN743X_LED_ENABLE(pin); |
|---|
| 198 | + |
|---|
| 199 | + lan743x_csr_write(adapter, HW_CFG, val); |
|---|
| 200 | + } |
|---|
| 201 | +} |
|---|
| 202 | + |
|---|
| 203 | +static void lan743x_led_mux_save(struct lan743x_adapter *adapter) |
|---|
| 204 | +{ |
|---|
| 205 | + struct lan743x_ptp *ptp = &adapter->ptp; |
|---|
| 206 | + u32 id_rev = adapter->csr.id_rev & ID_REV_ID_MASK_; |
|---|
| 207 | + |
|---|
| 208 | + if (id_rev == ID_REV_ID_LAN7430_) { |
|---|
| 209 | + int i; |
|---|
| 210 | + u32 val = lan743x_csr_read(adapter, HW_CFG); |
|---|
| 211 | + |
|---|
| 212 | + for (i = 0; i < LAN7430_N_LED; i++) { |
|---|
| 213 | + bool led_enabled = (val & LAN743X_LED_ENABLE(i)) != 0; |
|---|
| 214 | + |
|---|
| 215 | + ptp->led_enabled[i] = led_enabled; |
|---|
| 216 | + } |
|---|
| 217 | + ptp->leds_multiplexed = true; |
|---|
| 218 | + } else { |
|---|
| 219 | + ptp->leds_multiplexed = false; |
|---|
| 220 | + } |
|---|
| 221 | +} |
|---|
| 222 | + |
|---|
| 223 | +static void lan743x_led_mux_restore(struct lan743x_adapter *adapter) |
|---|
| 224 | +{ |
|---|
| 225 | + u32 id_rev = adapter->csr.id_rev & ID_REV_ID_MASK_; |
|---|
| 226 | + |
|---|
| 227 | + if (id_rev == ID_REV_ID_LAN7430_) { |
|---|
| 228 | + int i; |
|---|
| 229 | + |
|---|
| 230 | + for (i = 0; i < LAN7430_N_LED; i++) |
|---|
| 231 | + lan743x_led_mux_enable(adapter, i, true); |
|---|
| 232 | + } |
|---|
| 233 | +} |
|---|
| 234 | + |
|---|
| 182 | 235 | static int lan743x_gpio_rsrv_ptp_out(struct lan743x_adapter *adapter, |
|---|
| 183 | | - int bit, int ptp_channel) |
|---|
| 236 | + int pin, int event_channel) |
|---|
| 184 | 237 | { |
|---|
| 185 | 238 | struct lan743x_gpio *gpio = &adapter->gpio; |
|---|
| 186 | 239 | unsigned long irq_flags = 0; |
|---|
| 187 | | - int bit_mask = BIT(bit); |
|---|
| 240 | + int bit_mask = BIT(pin); |
|---|
| 188 | 241 | int ret = -EBUSY; |
|---|
| 189 | 242 | |
|---|
| 190 | 243 | spin_lock_irqsave(&gpio->gpio_lock, irq_flags); |
|---|
| .. | .. |
|---|
| 194 | 247 | gpio->output_bits |= bit_mask; |
|---|
| 195 | 248 | gpio->ptp_bits |= bit_mask; |
|---|
| 196 | 249 | |
|---|
| 250 | + /* assign pin to GPIO function */ |
|---|
| 251 | + lan743x_led_mux_enable(adapter, pin, false); |
|---|
| 252 | + |
|---|
| 197 | 253 | /* set as output, and zero initial value */ |
|---|
| 198 | | - gpio->gpio_cfg0 |= GPIO_CFG0_GPIO_DIR_BIT_(bit); |
|---|
| 199 | | - gpio->gpio_cfg0 &= ~GPIO_CFG0_GPIO_DATA_BIT_(bit); |
|---|
| 254 | + gpio->gpio_cfg0 |= GPIO_CFG0_GPIO_DIR_BIT_(pin); |
|---|
| 255 | + gpio->gpio_cfg0 &= ~GPIO_CFG0_GPIO_DATA_BIT_(pin); |
|---|
| 200 | 256 | lan743x_csr_write(adapter, GPIO_CFG0, gpio->gpio_cfg0); |
|---|
| 201 | 257 | |
|---|
| 202 | 258 | /* enable gpio, and set buffer type to push pull */ |
|---|
| 203 | | - gpio->gpio_cfg1 &= ~GPIO_CFG1_GPIOEN_BIT_(bit); |
|---|
| 204 | | - gpio->gpio_cfg1 |= GPIO_CFG1_GPIOBUF_BIT_(bit); |
|---|
| 259 | + gpio->gpio_cfg1 &= ~GPIO_CFG1_GPIOEN_BIT_(pin); |
|---|
| 260 | + gpio->gpio_cfg1 |= GPIO_CFG1_GPIOBUF_BIT_(pin); |
|---|
| 205 | 261 | lan743x_csr_write(adapter, GPIO_CFG1, gpio->gpio_cfg1); |
|---|
| 206 | 262 | |
|---|
| 207 | 263 | /* set 1588 polarity to high */ |
|---|
| 208 | | - gpio->gpio_cfg2 |= GPIO_CFG2_1588_POL_BIT_(bit); |
|---|
| 264 | + gpio->gpio_cfg2 |= GPIO_CFG2_1588_POL_BIT_(pin); |
|---|
| 209 | 265 | lan743x_csr_write(adapter, GPIO_CFG2, gpio->gpio_cfg2); |
|---|
| 210 | 266 | |
|---|
| 211 | | - if (!ptp_channel) { |
|---|
| 267 | + if (event_channel == 0) { |
|---|
| 212 | 268 | /* use channel A */ |
|---|
| 213 | | - gpio->gpio_cfg3 &= ~GPIO_CFG3_1588_CH_SEL_BIT_(bit); |
|---|
| 269 | + gpio->gpio_cfg3 &= ~GPIO_CFG3_1588_CH_SEL_BIT_(pin); |
|---|
| 214 | 270 | } else { |
|---|
| 215 | 271 | /* use channel B */ |
|---|
| 216 | | - gpio->gpio_cfg3 |= GPIO_CFG3_1588_CH_SEL_BIT_(bit); |
|---|
| 272 | + gpio->gpio_cfg3 |= GPIO_CFG3_1588_CH_SEL_BIT_(pin); |
|---|
| 217 | 273 | } |
|---|
| 218 | | - gpio->gpio_cfg3 |= GPIO_CFG3_1588_OE_BIT_(bit); |
|---|
| 274 | + gpio->gpio_cfg3 |= GPIO_CFG3_1588_OE_BIT_(pin); |
|---|
| 219 | 275 | lan743x_csr_write(adapter, GPIO_CFG3, gpio->gpio_cfg3); |
|---|
| 220 | 276 | |
|---|
| 221 | | - ret = bit; |
|---|
| 277 | + ret = pin; |
|---|
| 222 | 278 | } |
|---|
| 223 | 279 | spin_unlock_irqrestore(&gpio->gpio_lock, irq_flags); |
|---|
| 224 | 280 | return ret; |
|---|
| 225 | 281 | } |
|---|
| 226 | 282 | |
|---|
| 227 | | -static void lan743x_gpio_release(struct lan743x_adapter *adapter, int bit) |
|---|
| 283 | +static void lan743x_gpio_release(struct lan743x_adapter *adapter, int pin) |
|---|
| 228 | 284 | { |
|---|
| 229 | 285 | struct lan743x_gpio *gpio = &adapter->gpio; |
|---|
| 230 | 286 | unsigned long irq_flags = 0; |
|---|
| 231 | | - int bit_mask = BIT(bit); |
|---|
| 287 | + int bit_mask = BIT(pin); |
|---|
| 232 | 288 | |
|---|
| 233 | 289 | spin_lock_irqsave(&gpio->gpio_lock, irq_flags); |
|---|
| 234 | 290 | if (gpio->used_bits & bit_mask) { |
|---|
| .. | .. |
|---|
| 239 | 295 | if (gpio->ptp_bits & bit_mask) { |
|---|
| 240 | 296 | gpio->ptp_bits &= ~bit_mask; |
|---|
| 241 | 297 | /* disable ptp output */ |
|---|
| 242 | | - gpio->gpio_cfg3 &= ~GPIO_CFG3_1588_OE_BIT_(bit); |
|---|
| 298 | + gpio->gpio_cfg3 &= ~GPIO_CFG3_1588_OE_BIT_(pin); |
|---|
| 243 | 299 | lan743x_csr_write(adapter, GPIO_CFG3, |
|---|
| 244 | 300 | gpio->gpio_cfg3); |
|---|
| 245 | 301 | } |
|---|
| 246 | 302 | /* release gpio output */ |
|---|
| 247 | 303 | |
|---|
| 248 | 304 | /* disable gpio */ |
|---|
| 249 | | - gpio->gpio_cfg1 |= GPIO_CFG1_GPIOEN_BIT_(bit); |
|---|
| 250 | | - gpio->gpio_cfg1 &= ~GPIO_CFG1_GPIOBUF_BIT_(bit); |
|---|
| 305 | + gpio->gpio_cfg1 |= GPIO_CFG1_GPIOEN_BIT_(pin); |
|---|
| 306 | + gpio->gpio_cfg1 &= ~GPIO_CFG1_GPIOBUF_BIT_(pin); |
|---|
| 251 | 307 | lan743x_csr_write(adapter, GPIO_CFG1, gpio->gpio_cfg1); |
|---|
| 252 | 308 | |
|---|
| 253 | 309 | /* reset back to input */ |
|---|
| 254 | | - gpio->gpio_cfg0 &= ~GPIO_CFG0_GPIO_DIR_BIT_(bit); |
|---|
| 255 | | - gpio->gpio_cfg0 &= ~GPIO_CFG0_GPIO_DATA_BIT_(bit); |
|---|
| 310 | + gpio->gpio_cfg0 &= ~GPIO_CFG0_GPIO_DIR_BIT_(pin); |
|---|
| 311 | + gpio->gpio_cfg0 &= ~GPIO_CFG0_GPIO_DATA_BIT_(pin); |
|---|
| 256 | 312 | lan743x_csr_write(adapter, GPIO_CFG0, gpio->gpio_cfg0); |
|---|
| 313 | + |
|---|
| 314 | + /* assign pin to original function */ |
|---|
| 315 | + lan743x_led_mux_enable(adapter, pin, true); |
|---|
| 257 | 316 | } |
|---|
| 258 | 317 | } |
|---|
| 259 | 318 | spin_unlock_irqrestore(&gpio->gpio_lock, irq_flags); |
|---|
| .. | .. |
|---|
| 391 | 450 | return 0; |
|---|
| 392 | 451 | } |
|---|
| 393 | 452 | |
|---|
| 394 | | -static void lan743x_ptp_perout_off(struct lan743x_adapter *adapter) |
|---|
| 453 | +static void lan743x_ptp_perout_off(struct lan743x_adapter *adapter, |
|---|
| 454 | + unsigned int index) |
|---|
| 395 | 455 | { |
|---|
| 396 | 456 | struct lan743x_ptp *ptp = &adapter->ptp; |
|---|
| 397 | 457 | u32 general_config = 0; |
|---|
| 458 | + struct lan743x_ptp_perout *perout = &ptp->perout[index]; |
|---|
| 398 | 459 | |
|---|
| 399 | | - if (ptp->perout_gpio_bit >= 0) { |
|---|
| 400 | | - lan743x_gpio_release(adapter, ptp->perout_gpio_bit); |
|---|
| 401 | | - ptp->perout_gpio_bit = -1; |
|---|
| 460 | + if (perout->gpio_pin >= 0) { |
|---|
| 461 | + lan743x_gpio_release(adapter, perout->gpio_pin); |
|---|
| 462 | + perout->gpio_pin = -1; |
|---|
| 402 | 463 | } |
|---|
| 403 | 464 | |
|---|
| 404 | | - if (ptp->perout_event_ch >= 0) { |
|---|
| 465 | + if (perout->event_ch >= 0) { |
|---|
| 405 | 466 | /* set target to far in the future, effectively disabling it */ |
|---|
| 406 | 467 | lan743x_csr_write(adapter, |
|---|
| 407 | | - PTP_CLOCK_TARGET_SEC_X(ptp->perout_event_ch), |
|---|
| 468 | + PTP_CLOCK_TARGET_SEC_X(perout->event_ch), |
|---|
| 408 | 469 | 0xFFFF0000); |
|---|
| 409 | 470 | lan743x_csr_write(adapter, |
|---|
| 410 | | - PTP_CLOCK_TARGET_NS_X(ptp->perout_event_ch), |
|---|
| 471 | + PTP_CLOCK_TARGET_NS_X(perout->event_ch), |
|---|
| 411 | 472 | 0); |
|---|
| 412 | 473 | |
|---|
| 413 | 474 | general_config = lan743x_csr_read(adapter, PTP_GENERAL_CONFIG); |
|---|
| 414 | 475 | general_config |= PTP_GENERAL_CONFIG_RELOAD_ADD_X_ |
|---|
| 415 | | - (ptp->perout_event_ch); |
|---|
| 476 | + (perout->event_ch); |
|---|
| 416 | 477 | lan743x_csr_write(adapter, PTP_GENERAL_CONFIG, general_config); |
|---|
| 417 | | - lan743x_ptp_release_event_ch(adapter, ptp->perout_event_ch); |
|---|
| 418 | | - ptp->perout_event_ch = -1; |
|---|
| 478 | + lan743x_ptp_release_event_ch(adapter, perout->event_ch); |
|---|
| 479 | + perout->event_ch = -1; |
|---|
| 419 | 480 | } |
|---|
| 420 | 481 | } |
|---|
| 421 | 482 | |
|---|
| 422 | 483 | static int lan743x_ptp_perout(struct lan743x_adapter *adapter, int on, |
|---|
| 423 | | - struct ptp_perout_request *perout) |
|---|
| 484 | + struct ptp_perout_request *perout_request) |
|---|
| 424 | 485 | { |
|---|
| 425 | 486 | struct lan743x_ptp *ptp = &adapter->ptp; |
|---|
| 426 | 487 | u32 period_sec = 0, period_nsec = 0; |
|---|
| 427 | 488 | u32 start_sec = 0, start_nsec = 0; |
|---|
| 428 | 489 | u32 general_config = 0; |
|---|
| 429 | 490 | int pulse_width = 0; |
|---|
| 430 | | - int perout_bit = 0; |
|---|
| 491 | + int perout_pin = 0; |
|---|
| 492 | + unsigned int index = perout_request->index; |
|---|
| 493 | + struct lan743x_ptp_perout *perout = &ptp->perout[index]; |
|---|
| 431 | 494 | |
|---|
| 432 | | - if (!on) { |
|---|
| 433 | | - lan743x_ptp_perout_off(adapter); |
|---|
| 495 | + /* Reject requests with unsupported flags */ |
|---|
| 496 | + if (perout_request->flags) |
|---|
| 497 | + return -EOPNOTSUPP; |
|---|
| 498 | + |
|---|
| 499 | + if (on) { |
|---|
| 500 | + perout_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT, |
|---|
| 501 | + perout_request->index); |
|---|
| 502 | + if (perout_pin < 0) |
|---|
| 503 | + return -EBUSY; |
|---|
| 504 | + } else { |
|---|
| 505 | + lan743x_ptp_perout_off(adapter, index); |
|---|
| 434 | 506 | return 0; |
|---|
| 435 | 507 | } |
|---|
| 436 | 508 | |
|---|
| 437 | | - if (ptp->perout_event_ch >= 0 || |
|---|
| 438 | | - ptp->perout_gpio_bit >= 0) { |
|---|
| 509 | + if (perout->event_ch >= 0 || |
|---|
| 510 | + perout->gpio_pin >= 0) { |
|---|
| 439 | 511 | /* already on, turn off first */ |
|---|
| 440 | | - lan743x_ptp_perout_off(adapter); |
|---|
| 512 | + lan743x_ptp_perout_off(adapter, index); |
|---|
| 441 | 513 | } |
|---|
| 442 | 514 | |
|---|
| 443 | | - ptp->perout_event_ch = lan743x_ptp_reserve_event_ch(adapter); |
|---|
| 444 | | - if (ptp->perout_event_ch < 0) { |
|---|
| 515 | + perout->event_ch = lan743x_ptp_reserve_event_ch(adapter, index); |
|---|
| 516 | + |
|---|
| 517 | + if (perout->event_ch < 0) { |
|---|
| 445 | 518 | netif_warn(adapter, drv, adapter->netdev, |
|---|
| 446 | | - "Failed to reserve event channel for PEROUT\n"); |
|---|
| 519 | + "Failed to reserve event channel %d for PEROUT\n", |
|---|
| 520 | + index); |
|---|
| 447 | 521 | goto failed; |
|---|
| 448 | 522 | } |
|---|
| 449 | 523 | |
|---|
| 450 | | - switch (adapter->csr.id_rev & ID_REV_ID_MASK_) { |
|---|
| 451 | | - case ID_REV_ID_LAN7430_: |
|---|
| 452 | | - perout_bit = 2;/* GPIO 2 is preferred on EVB LAN7430 */ |
|---|
| 453 | | - break; |
|---|
| 454 | | - case ID_REV_ID_LAN7431_: |
|---|
| 455 | | - perout_bit = 4;/* GPIO 4 is preferred on EVB LAN7431 */ |
|---|
| 456 | | - break; |
|---|
| 457 | | - } |
|---|
| 524 | + perout->gpio_pin = lan743x_gpio_rsrv_ptp_out(adapter, |
|---|
| 525 | + perout_pin, |
|---|
| 526 | + perout->event_ch); |
|---|
| 458 | 527 | |
|---|
| 459 | | - ptp->perout_gpio_bit = lan743x_gpio_rsrv_ptp_out(adapter, |
|---|
| 460 | | - perout_bit, |
|---|
| 461 | | - ptp->perout_event_ch); |
|---|
| 462 | | - |
|---|
| 463 | | - if (ptp->perout_gpio_bit < 0) { |
|---|
| 528 | + if (perout->gpio_pin < 0) { |
|---|
| 464 | 529 | netif_warn(adapter, drv, adapter->netdev, |
|---|
| 465 | 530 | "Failed to reserve gpio %d for PEROUT\n", |
|---|
| 466 | | - perout_bit); |
|---|
| 531 | + perout_pin); |
|---|
| 467 | 532 | goto failed; |
|---|
| 468 | 533 | } |
|---|
| 469 | 534 | |
|---|
| 470 | | - start_sec = perout->start.sec; |
|---|
| 471 | | - start_sec += perout->start.nsec / 1000000000; |
|---|
| 472 | | - start_nsec = perout->start.nsec % 1000000000; |
|---|
| 535 | + start_sec = perout_request->start.sec; |
|---|
| 536 | + start_sec += perout_request->start.nsec / 1000000000; |
|---|
| 537 | + start_nsec = perout_request->start.nsec % 1000000000; |
|---|
| 473 | 538 | |
|---|
| 474 | | - period_sec = perout->period.sec; |
|---|
| 475 | | - period_sec += perout->period.nsec / 1000000000; |
|---|
| 476 | | - period_nsec = perout->period.nsec % 1000000000; |
|---|
| 539 | + period_sec = perout_request->period.sec; |
|---|
| 540 | + period_sec += perout_request->period.nsec / 1000000000; |
|---|
| 541 | + period_nsec = perout_request->period.nsec % 1000000000; |
|---|
| 477 | 542 | |
|---|
| 478 | 543 | if (period_sec == 0) { |
|---|
| 479 | 544 | if (period_nsec >= 400000000) { |
|---|
| .. | .. |
|---|
| 499 | 564 | |
|---|
| 500 | 565 | /* turn off by setting target far in future */ |
|---|
| 501 | 566 | lan743x_csr_write(adapter, |
|---|
| 502 | | - PTP_CLOCK_TARGET_SEC_X(ptp->perout_event_ch), |
|---|
| 567 | + PTP_CLOCK_TARGET_SEC_X(perout->event_ch), |
|---|
| 503 | 568 | 0xFFFF0000); |
|---|
| 504 | 569 | lan743x_csr_write(adapter, |
|---|
| 505 | | - PTP_CLOCK_TARGET_NS_X(ptp->perout_event_ch), 0); |
|---|
| 570 | + PTP_CLOCK_TARGET_NS_X(perout->event_ch), 0); |
|---|
| 506 | 571 | |
|---|
| 507 | 572 | /* Configure to pulse every period */ |
|---|
| 508 | 573 | general_config = lan743x_csr_read(adapter, PTP_GENERAL_CONFIG); |
|---|
| 509 | 574 | general_config &= ~(PTP_GENERAL_CONFIG_CLOCK_EVENT_X_MASK_ |
|---|
| 510 | | - (ptp->perout_event_ch)); |
|---|
| 575 | + (perout->event_ch)); |
|---|
| 511 | 576 | general_config |= PTP_GENERAL_CONFIG_CLOCK_EVENT_X_SET_ |
|---|
| 512 | | - (ptp->perout_event_ch, pulse_width); |
|---|
| 577 | + (perout->event_ch, pulse_width); |
|---|
| 513 | 578 | general_config &= ~PTP_GENERAL_CONFIG_RELOAD_ADD_X_ |
|---|
| 514 | | - (ptp->perout_event_ch); |
|---|
| 579 | + (perout->event_ch); |
|---|
| 515 | 580 | lan743x_csr_write(adapter, PTP_GENERAL_CONFIG, general_config); |
|---|
| 516 | 581 | |
|---|
| 517 | 582 | /* set the reload to one toggle cycle */ |
|---|
| 518 | 583 | lan743x_csr_write(adapter, |
|---|
| 519 | | - PTP_CLOCK_TARGET_RELOAD_SEC_X(ptp->perout_event_ch), |
|---|
| 584 | + PTP_CLOCK_TARGET_RELOAD_SEC_X(perout->event_ch), |
|---|
| 520 | 585 | period_sec); |
|---|
| 521 | 586 | lan743x_csr_write(adapter, |
|---|
| 522 | | - PTP_CLOCK_TARGET_RELOAD_NS_X(ptp->perout_event_ch), |
|---|
| 587 | + PTP_CLOCK_TARGET_RELOAD_NS_X(perout->event_ch), |
|---|
| 523 | 588 | period_nsec); |
|---|
| 524 | 589 | |
|---|
| 525 | 590 | /* set the start time */ |
|---|
| 526 | 591 | lan743x_csr_write(adapter, |
|---|
| 527 | | - PTP_CLOCK_TARGET_SEC_X(ptp->perout_event_ch), |
|---|
| 592 | + PTP_CLOCK_TARGET_SEC_X(perout->event_ch), |
|---|
| 528 | 593 | start_sec); |
|---|
| 529 | 594 | lan743x_csr_write(adapter, |
|---|
| 530 | | - PTP_CLOCK_TARGET_NS_X(ptp->perout_event_ch), |
|---|
| 595 | + PTP_CLOCK_TARGET_NS_X(perout->event_ch), |
|---|
| 531 | 596 | start_nsec); |
|---|
| 532 | 597 | |
|---|
| 533 | 598 | return 0; |
|---|
| 534 | 599 | |
|---|
| 535 | 600 | failed: |
|---|
| 536 | | - lan743x_ptp_perout_off(adapter); |
|---|
| 601 | + lan743x_ptp_perout_off(adapter, index); |
|---|
| 537 | 602 | return -ENODEV; |
|---|
| 538 | 603 | } |
|---|
| 539 | 604 | |
|---|
| .. | .. |
|---|
| 550 | 615 | case PTP_CLK_REQ_EXTTS: |
|---|
| 551 | 616 | return -EINVAL; |
|---|
| 552 | 617 | case PTP_CLK_REQ_PEROUT: |
|---|
| 553 | | - if (request->perout.index == 0) |
|---|
| 618 | + if (request->perout.index < ptpci->n_per_out) |
|---|
| 554 | 619 | return lan743x_ptp_perout(adapter, on, |
|---|
| 555 | 620 | &request->perout); |
|---|
| 556 | 621 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 566 | 631 | netif_err(adapter, drv, adapter->netdev, "request == NULL\n"); |
|---|
| 567 | 632 | } |
|---|
| 568 | 633 | return 0; |
|---|
| 634 | +} |
|---|
| 635 | + |
|---|
| 636 | +static int lan743x_ptpci_verify_pin_config(struct ptp_clock_info *ptp, |
|---|
| 637 | + unsigned int pin, |
|---|
| 638 | + enum ptp_pin_function func, |
|---|
| 639 | + unsigned int chan) |
|---|
| 640 | +{ |
|---|
| 641 | + int result = 0; |
|---|
| 642 | + |
|---|
| 643 | + /* Confirm the requested function is supported. Parameter |
|---|
| 644 | + * validation is done by the caller. |
|---|
| 645 | + */ |
|---|
| 646 | + switch (func) { |
|---|
| 647 | + case PTP_PF_NONE: |
|---|
| 648 | + case PTP_PF_PEROUT: |
|---|
| 649 | + break; |
|---|
| 650 | + case PTP_PF_EXTTS: |
|---|
| 651 | + case PTP_PF_PHYSYNC: |
|---|
| 652 | + default: |
|---|
| 653 | + result = -1; |
|---|
| 654 | + break; |
|---|
| 655 | + } |
|---|
| 656 | + return result; |
|---|
| 569 | 657 | } |
|---|
| 570 | 658 | |
|---|
| 571 | 659 | static long lan743x_ptpci_do_aux_work(struct ptp_clock_info *ptpci) |
|---|
| .. | .. |
|---|
| 861 | 949 | int lan743x_ptp_init(struct lan743x_adapter *adapter) |
|---|
| 862 | 950 | { |
|---|
| 863 | 951 | struct lan743x_ptp *ptp = &adapter->ptp; |
|---|
| 952 | + int i; |
|---|
| 864 | 953 | |
|---|
| 865 | 954 | mutex_init(&ptp->command_lock); |
|---|
| 866 | 955 | spin_lock_init(&ptp->tx_ts_lock); |
|---|
| 867 | 956 | ptp->used_event_ch = 0; |
|---|
| 868 | | - ptp->perout_event_ch = -1; |
|---|
| 869 | | - ptp->perout_gpio_bit = -1; |
|---|
| 957 | + |
|---|
| 958 | + for (i = 0; i < LAN743X_PTP_N_EVENT_CHAN; i++) { |
|---|
| 959 | + ptp->perout[i].event_ch = -1; |
|---|
| 960 | + ptp->perout[i].gpio_pin = -1; |
|---|
| 961 | + } |
|---|
| 962 | + |
|---|
| 963 | + lan743x_led_mux_save(adapter); |
|---|
| 964 | + |
|---|
| 870 | 965 | return 0; |
|---|
| 871 | 966 | } |
|---|
| 872 | 967 | |
|---|
| .. | .. |
|---|
| 875 | 970 | struct lan743x_ptp *ptp = &adapter->ptp; |
|---|
| 876 | 971 | int ret = -ENODEV; |
|---|
| 877 | 972 | u32 temp; |
|---|
| 973 | + int i; |
|---|
| 974 | + int n_pins; |
|---|
| 878 | 975 | |
|---|
| 879 | 976 | lan743x_ptp_reset(adapter); |
|---|
| 880 | 977 | lan743x_ptp_sync_to_system_clock(adapter); |
|---|
| .. | .. |
|---|
| 890 | 987 | if (!IS_ENABLED(CONFIG_PTP_1588_CLOCK)) |
|---|
| 891 | 988 | return 0; |
|---|
| 892 | 989 | |
|---|
| 893 | | - snprintf(ptp->pin_config[0].name, 32, "lan743x_ptp_pin_0"); |
|---|
| 894 | | - ptp->pin_config[0].index = 0; |
|---|
| 895 | | - ptp->pin_config[0].func = PTP_PF_PEROUT; |
|---|
| 896 | | - ptp->pin_config[0].chan = 0; |
|---|
| 990 | + switch (adapter->csr.id_rev & ID_REV_ID_MASK_) { |
|---|
| 991 | + case ID_REV_ID_LAN7430_: |
|---|
| 992 | + n_pins = LAN7430_N_GPIO; |
|---|
| 993 | + break; |
|---|
| 994 | + case ID_REV_ID_LAN7431_: |
|---|
| 995 | + n_pins = LAN7431_N_GPIO; |
|---|
| 996 | + break; |
|---|
| 997 | + default: |
|---|
| 998 | + netif_warn(adapter, drv, adapter->netdev, |
|---|
| 999 | + "Unknown LAN743x (%08x). Assuming no GPIO\n", |
|---|
| 1000 | + adapter->csr.id_rev); |
|---|
| 1001 | + n_pins = 0; |
|---|
| 1002 | + break; |
|---|
| 1003 | + } |
|---|
| 1004 | + |
|---|
| 1005 | + if (n_pins > LAN743X_PTP_N_GPIO) |
|---|
| 1006 | + n_pins = LAN743X_PTP_N_GPIO; |
|---|
| 1007 | + |
|---|
| 1008 | + for (i = 0; i < n_pins; i++) { |
|---|
| 1009 | + struct ptp_pin_desc *ptp_pin = &ptp->pin_config[i]; |
|---|
| 1010 | + |
|---|
| 1011 | + snprintf(ptp_pin->name, |
|---|
| 1012 | + sizeof(ptp_pin->name), "lan743x_ptp_pin_%02d", i); |
|---|
| 1013 | + ptp_pin->index = i; |
|---|
| 1014 | + ptp_pin->func = PTP_PF_NONE; |
|---|
| 1015 | + } |
|---|
| 897 | 1016 | |
|---|
| 898 | 1017 | ptp->ptp_clock_info.owner = THIS_MODULE; |
|---|
| 899 | 1018 | snprintf(ptp->ptp_clock_info.name, 16, "%pm", |
|---|
| .. | .. |
|---|
| 901 | 1020 | ptp->ptp_clock_info.max_adj = LAN743X_PTP_MAX_FREQ_ADJ_IN_PPB; |
|---|
| 902 | 1021 | ptp->ptp_clock_info.n_alarm = 0; |
|---|
| 903 | 1022 | ptp->ptp_clock_info.n_ext_ts = 0; |
|---|
| 904 | | - ptp->ptp_clock_info.n_per_out = 1; |
|---|
| 905 | | - ptp->ptp_clock_info.n_pins = 0; |
|---|
| 1023 | + ptp->ptp_clock_info.n_per_out = LAN743X_PTP_N_EVENT_CHAN; |
|---|
| 1024 | + ptp->ptp_clock_info.n_pins = n_pins; |
|---|
| 906 | 1025 | ptp->ptp_clock_info.pps = 0; |
|---|
| 907 | | - ptp->ptp_clock_info.pin_config = NULL; |
|---|
| 1026 | + ptp->ptp_clock_info.pin_config = ptp->pin_config; |
|---|
| 908 | 1027 | ptp->ptp_clock_info.adjfine = lan743x_ptpci_adjfine; |
|---|
| 909 | 1028 | ptp->ptp_clock_info.adjfreq = lan743x_ptpci_adjfreq; |
|---|
| 910 | 1029 | ptp->ptp_clock_info.adjtime = lan743x_ptpci_adjtime; |
|---|
| .. | .. |
|---|
| 913 | 1032 | ptp->ptp_clock_info.settime64 = lan743x_ptpci_settime64; |
|---|
| 914 | 1033 | ptp->ptp_clock_info.enable = lan743x_ptpci_enable; |
|---|
| 915 | 1034 | ptp->ptp_clock_info.do_aux_work = lan743x_ptpci_do_aux_work; |
|---|
| 916 | | - ptp->ptp_clock_info.verify = NULL; |
|---|
| 1035 | + ptp->ptp_clock_info.verify = lan743x_ptpci_verify_pin_config; |
|---|
| 917 | 1036 | |
|---|
| 918 | 1037 | ptp->ptp_clock = ptp_clock_register(&ptp->ptp_clock_info, |
|---|
| 919 | 1038 | &adapter->pdev->dev); |
|---|
| .. | .. |
|---|
| 939 | 1058 | int index; |
|---|
| 940 | 1059 | |
|---|
| 941 | 1060 | if (IS_ENABLED(CONFIG_PTP_1588_CLOCK) && |
|---|
| 942 | | - ptp->flags & PTP_FLAG_PTP_CLOCK_REGISTERED) { |
|---|
| 1061 | + (ptp->flags & PTP_FLAG_PTP_CLOCK_REGISTERED)) { |
|---|
| 943 | 1062 | ptp_clock_unregister(ptp->ptp_clock); |
|---|
| 944 | 1063 | ptp->ptp_clock = NULL; |
|---|
| 945 | 1064 | ptp->flags &= ~PTP_FLAG_PTP_CLOCK_REGISTERED; |
|---|
| .. | .. |
|---|
| 963 | 1082 | index++) { |
|---|
| 964 | 1083 | struct sk_buff *skb = ptp->tx_ts_skb_queue[index]; |
|---|
| 965 | 1084 | |
|---|
| 966 | | - if (skb) |
|---|
| 967 | | - dev_kfree_skb(skb); |
|---|
| 1085 | + dev_kfree_skb(skb); |
|---|
| 968 | 1086 | ptp->tx_ts_skb_queue[index] = NULL; |
|---|
| 969 | 1087 | ptp->tx_ts_seconds_queue[index] = 0; |
|---|
| 970 | 1088 | ptp->tx_ts_nseconds_queue[index] = 0; |
|---|
| .. | .. |
|---|
| 974 | 1092 | ptp->pending_tx_timestamps = 0; |
|---|
| 975 | 1093 | spin_unlock_bh(&ptp->tx_ts_lock); |
|---|
| 976 | 1094 | |
|---|
| 1095 | + lan743x_led_mux_restore(adapter); |
|---|
| 1096 | + |
|---|
| 977 | 1097 | lan743x_ptp_disable(adapter); |
|---|
| 978 | 1098 | } |
|---|
| 979 | 1099 | |
|---|
| 980 | | -void lan743x_ptp_set_sync_ts_insert(struct lan743x_adapter *adapter, |
|---|
| 981 | | - bool ts_insert_enable) |
|---|
| 1100 | +static void lan743x_ptp_set_sync_ts_insert(struct lan743x_adapter *adapter, |
|---|
| 1101 | + bool ts_insert_enable) |
|---|
| 982 | 1102 | { |
|---|
| 983 | 1103 | u32 ptp_tx_mod = lan743x_csr_read(adapter, PTP_TX_MOD); |
|---|
| 984 | 1104 | |
|---|
| .. | .. |
|---|
| 1145 | 1265 | |
|---|
| 1146 | 1266 | lan743x_ptp_set_sync_ts_insert(adapter, true); |
|---|
| 1147 | 1267 | break; |
|---|
| 1268 | + case HWTSTAMP_TX_ONESTEP_P2P: |
|---|
| 1269 | + ret = -ERANGE; |
|---|
| 1270 | + break; |
|---|
| 1148 | 1271 | default: |
|---|
| 1149 | 1272 | netif_warn(adapter, drv, adapter->netdev, |
|---|
| 1150 | 1273 | " tx_type = %d, UNKNOWN\n", config.tx_type); |
|---|