Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ice: change SMA pins to SDP in PTP API

This change aligns E810 PTP pin control to all other products.

Currently, SMA/U.FL port expanders are controlled together with SDP pins
connected to 1588 clock. To align this, separate this control by
exposing only SDP20..23 pins in PTP API on adapters with DPLL.

Clear error for all E810 on absent NVM pin section or other errors to
allow proper initialization on SMA E810 with NVM section.

Use ARRAY_SIZE for pin array instead of internal definition.

Reviewed-by: Milena Olech <milena.olech@intel.com>
Signed-off-by: Karol Kolacinski <karol.kolacinski@intel.com>
Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Tested-by: Rinitha S <sx.rinitha@intel.com> (A Contingent worker at Intel)
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>

authored by

Karol Kolacinski and committed by
Tony Nguyen
a33a302b 2dd5d03c

+40 -219
+40 -216
drivers/net/ethernet/intel/ice/ice_ptp.c
··· 40 40 { ONE_PPS, { -1, 5 }, { 0, 1 }}, 41 41 }; 42 42 43 - static const char ice_pin_names_nvm[][64] = { 44 - "GNSS", 45 - "SMA1", 46 - "U.FL1", 47 - "SMA2", 48 - "U.FL2", 43 + static const char ice_pin_names_dpll[][64] = { 44 + "SDP20", 45 + "SDP21", 46 + "SDP22", 47 + "SDP23", 49 48 }; 50 49 51 - static const struct ice_ptp_pin_desc ice_pin_desc_e810_sma[] = { 50 + static const struct ice_ptp_pin_desc ice_pin_desc_dpll[] = { 52 51 /* name, gpio, delay */ 53 - { GNSS, { 1, -1 }, { 0, 0 }}, 54 - { SMA1, { 1, 0 }, { 0, 1 }}, 55 - { UFL1, { -1, 0 }, { 0, 1 }}, 56 - { SMA2, { 3, 2 }, { 0, 1 }}, 57 - { UFL2, { 3, -1 }, { 0, 0 }}, 52 + { SDP0, { -1, 0 }, { 0, 1 }}, 53 + { SDP1, { 1, -1 }, { 0, 0 }}, 54 + { SDP2, { -1, 2 }, { 0, 1 }}, 55 + { SDP3, { 3, -1 }, { 0, 0 }}, 58 56 }; 59 57 60 58 static struct ice_pf *ice_get_ctrl_pf(struct ice_pf *pf) ··· 88 90 } 89 91 90 92 return -1; 91 - } 92 - 93 - /** 94 - * ice_ptp_update_sma_data - update SMA pins data according to pins setup 95 - * @pf: Board private structure 96 - * @sma_pins: parsed SMA pins status 97 - * @data: SMA data to update 98 - */ 99 - static void ice_ptp_update_sma_data(struct ice_pf *pf, unsigned int sma_pins[], 100 - u8 *data) 101 - { 102 - const char *state1, *state2; 103 - 104 - /* Set the right state based on the desired configuration. 105 - * When bit is set, functionality is disabled. 106 - */ 107 - *data &= ~ICE_ALL_SMA_MASK; 108 - if (!sma_pins[UFL1 - 1]) { 109 - if (sma_pins[SMA1 - 1] == PTP_PF_EXTTS) { 110 - state1 = "SMA1 Rx, U.FL1 disabled"; 111 - *data |= ICE_SMA1_TX_EN; 112 - } else if (sma_pins[SMA1 - 1] == PTP_PF_PEROUT) { 113 - state1 = "SMA1 Tx U.FL1 disabled"; 114 - *data |= ICE_SMA1_DIR_EN; 115 - } else { 116 - state1 = "SMA1 disabled, U.FL1 disabled"; 117 - *data |= ICE_SMA1_MASK; 118 - } 119 - } else { 120 - /* U.FL1 Tx will always enable SMA1 Rx */ 121 - state1 = "SMA1 Rx, U.FL1 Tx"; 122 - } 123 - 124 - if (!sma_pins[UFL2 - 1]) { 125 - if (sma_pins[SMA2 - 1] == PTP_PF_EXTTS) { 126 - state2 = "SMA2 Rx, U.FL2 disabled"; 127 - *data |= ICE_SMA2_TX_EN | ICE_SMA2_UFL2_RX_DIS; 128 - } else if (sma_pins[SMA2 - 1] == PTP_PF_PEROUT) { 129 - state2 = "SMA2 Tx, U.FL2 disabled"; 130 - *data |= ICE_SMA2_DIR_EN | ICE_SMA2_UFL2_RX_DIS; 131 - } else { 132 - state2 = "SMA2 disabled, U.FL2 disabled"; 133 - *data |= ICE_SMA2_MASK; 134 - } 135 - } else { 136 - if (!sma_pins[SMA2 - 1]) { 137 - state2 = "SMA2 disabled, U.FL2 Rx"; 138 - *data |= ICE_SMA2_DIR_EN | ICE_SMA2_TX_EN; 139 - } else { 140 - state2 = "SMA2 Tx, U.FL2 Rx"; 141 - *data |= ICE_SMA2_DIR_EN; 142 - } 143 - } 144 - 145 - dev_dbg(ice_pf_to_dev(pf), "%s, %s\n", state1, state2); 146 - } 147 - 148 - /** 149 - * ice_ptp_set_sma_cfg - set the configuration of the SMA control logic 150 - * @pf: Board private structure 151 - * 152 - * Return: 0 on success, negative error code otherwise 153 - */ 154 - static int ice_ptp_set_sma_cfg(struct ice_pf *pf) 155 - { 156 - const struct ice_ptp_pin_desc *ice_pins = pf->ptp.ice_pin_desc; 157 - struct ptp_pin_desc *pins = pf->ptp.pin_desc; 158 - unsigned int sma_pins[ICE_SMA_PINS_NUM] = {}; 159 - int err; 160 - u8 data; 161 - 162 - /* Read initial pin state value */ 163 - err = ice_read_sma_ctrl(&pf->hw, &data); 164 - if (err) 165 - return err; 166 - 167 - /* Get SMA/U.FL pins states */ 168 - for (int i = 0; i < pf->ptp.info.n_pins; i++) 169 - if (pins[i].func) { 170 - int name_idx = ice_pins[i].name_idx; 171 - 172 - switch (name_idx) { 173 - case SMA1: 174 - case UFL1: 175 - case SMA2: 176 - case UFL2: 177 - sma_pins[name_idx - 1] = pins[i].func; 178 - break; 179 - default: 180 - continue; 181 - } 182 - } 183 - 184 - ice_ptp_update_sma_data(pf, sma_pins, &data); 185 - return ice_write_sma_ctrl(&pf->hw, data); 186 93 } 187 94 188 95 /** ··· 1782 1879 } 1783 1880 1784 1881 /** 1785 - * ice_ptp_disable_shared_pin - Disable enabled pin that shares GPIO 1786 - * @pf: Board private structure 1787 - * @pin: Pin index 1788 - * @func: Assigned function 1789 - * 1790 - * Return: 0 on success, negative error code otherwise 1791 - */ 1792 - static int ice_ptp_disable_shared_pin(struct ice_pf *pf, unsigned int pin, 1793 - enum ptp_pin_function func) 1794 - { 1795 - unsigned int gpio_pin; 1796 - 1797 - switch (func) { 1798 - case PTP_PF_PEROUT: 1799 - gpio_pin = pf->ptp.ice_pin_desc[pin].gpio[1]; 1800 - break; 1801 - case PTP_PF_EXTTS: 1802 - gpio_pin = pf->ptp.ice_pin_desc[pin].gpio[0]; 1803 - break; 1804 - default: 1805 - return -EOPNOTSUPP; 1806 - } 1807 - 1808 - for (unsigned int i = 0; i < pf->ptp.info.n_pins; i++) { 1809 - struct ptp_pin_desc *pin_desc = &pf->ptp.pin_desc[i]; 1810 - unsigned int chan = pin_desc->chan; 1811 - 1812 - /* Skip pin idx from the request */ 1813 - if (i == pin) 1814 - continue; 1815 - 1816 - if (pin_desc->func == PTP_PF_PEROUT && 1817 - pf->ptp.ice_pin_desc[i].gpio[1] == gpio_pin) { 1818 - pf->ptp.perout_rqs[chan].period.sec = 0; 1819 - pf->ptp.perout_rqs[chan].period.nsec = 0; 1820 - pin_desc->func = PTP_PF_NONE; 1821 - pin_desc->chan = 0; 1822 - dev_dbg(ice_pf_to_dev(pf), "Disabling pin %u with shared output GPIO pin %u\n", 1823 - i, gpio_pin); 1824 - return ice_ptp_cfg_perout(pf, &pf->ptp.perout_rqs[chan], 1825 - false); 1826 - } else if (pf->ptp.pin_desc->func == PTP_PF_EXTTS && 1827 - pf->ptp.ice_pin_desc[i].gpio[0] == gpio_pin) { 1828 - pf->ptp.extts_rqs[chan].flags &= ~PTP_ENABLE_FEATURE; 1829 - pin_desc->func = PTP_PF_NONE; 1830 - pin_desc->chan = 0; 1831 - dev_dbg(ice_pf_to_dev(pf), "Disabling pin %u with shared input GPIO pin %u\n", 1832 - i, gpio_pin); 1833 - return ice_ptp_cfg_extts(pf, &pf->ptp.extts_rqs[chan], 1834 - false); 1835 - } 1836 - } 1837 - 1838 - return 0; 1839 - } 1840 - 1841 - /** 1842 1882 * ice_verify_pin - verify if pin supports requested pin function 1843 1883 * @info: the driver's PTP info structure 1844 1884 * @pin: Pin index ··· 1813 1967 case PTP_PF_PHYSYNC: 1814 1968 default: 1815 1969 return -EOPNOTSUPP; 1816 - } 1817 - 1818 - /* On adapters with SMA_CTRL disable other pins that share same GPIO */ 1819 - if (ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) { 1820 - ice_ptp_disable_shared_pin(pf, pin, func); 1821 - pf->ptp.pin_desc[pin].func = func; 1822 - pf->ptp.pin_desc[pin].chan = chan; 1823 - return ice_ptp_set_sma_cfg(pf); 1824 1970 } 1825 1971 1826 1972 return 0; ··· 2337 2499 for (unsigned int i = 0; i < pf->ptp.info.n_pins; i++) { 2338 2500 const struct ice_ptp_pin_desc *desc = &pf->ptp.ice_pin_desc[i]; 2339 2501 struct ptp_pin_desc *pin = &pf->ptp.pin_desc[i]; 2340 - const char *name = NULL; 2502 + const char *name; 2341 2503 2342 2504 if (!ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) 2343 2505 name = ice_pin_names[desc->name_idx]; 2344 - else if (desc->name_idx != GPIO_NA) 2345 - name = ice_pin_names_nvm[desc->name_idx]; 2346 - if (name) 2347 - strscpy(pin->name, name, sizeof(pin->name)); 2506 + else 2507 + name = ice_pin_names_dpll[desc->name_idx]; 2508 + 2509 + strscpy(pin->name, name, sizeof(pin->name)); 2348 2510 2349 2511 pin->index = i; 2350 2512 } ··· 2356 2518 * ice_ptp_disable_pins - Disable PTP pins 2357 2519 * @pf: pointer to the PF structure 2358 2520 * 2359 - * Disable the OS access to the SMA pins. Called to clear out the OS 2360 - * indications of pin support when we fail to setup the SMA control register. 2521 + * Disable the OS access to the pins. Called to clear out the OS 2522 + * indications of pin support when we fail to setup pin array. 2361 2523 */ 2362 2524 static void ice_ptp_disable_pins(struct ice_pf *pf) 2363 2525 { ··· 2398 2560 for (i = 0; i < num_entries; i++) { 2399 2561 u16 entry = le16_to_cpu(entries[i]); 2400 2562 DECLARE_BITMAP(bitmap, GPIO_NA); 2401 - unsigned int bitmap_idx; 2563 + unsigned int idx; 2402 2564 bool dir; 2403 2565 u16 gpio; 2404 2566 2405 2567 *bitmap = FIELD_GET(ICE_AQC_NVM_SDP_AC_PIN_M, entry); 2568 + 2569 + /* Check if entry's pin bitmap is valid. */ 2570 + if (bitmap_empty(bitmap, GPIO_NA)) 2571 + continue; 2572 + 2406 2573 dir = !!FIELD_GET(ICE_AQC_NVM_SDP_AC_DIR_M, entry); 2407 2574 gpio = FIELD_GET(ICE_AQC_NVM_SDP_AC_SDP_NUM_M, entry); 2408 - for_each_set_bit(bitmap_idx, bitmap, GPIO_NA + 1) { 2409 - unsigned int idx; 2410 2575 2411 - /* Check if entry's pin bit is valid */ 2412 - if (bitmap_idx >= NUM_PTP_PINS_NVM && 2413 - bitmap_idx != GPIO_NA) 2414 - continue; 2415 - 2416 - /* Check if pin already exists */ 2417 - for (idx = 0; idx < ICE_N_PINS_MAX; idx++) 2418 - if (pins[idx].name_idx == bitmap_idx) 2419 - break; 2420 - 2421 - if (idx == ICE_N_PINS_MAX) { 2422 - /* Pin not found, setup its entry and name */ 2423 - idx = n_pins++; 2424 - pins[idx].name_idx = bitmap_idx; 2425 - if (bitmap_idx == GPIO_NA) 2426 - strscpy(pf->ptp.pin_desc[idx].name, 2427 - ice_pin_names[gpio], 2428 - sizeof(pf->ptp.pin_desc[idx] 2429 - .name)); 2430 - } 2431 - 2432 - /* Setup in/out GPIO number */ 2433 - pins[idx].gpio[dir] = gpio; 2576 + for (idx = 0; idx < ICE_N_PINS_MAX; idx++) { 2577 + if (pins[idx].name_idx == gpio) 2578 + break; 2434 2579 } 2580 + 2581 + if (idx == ICE_N_PINS_MAX) { 2582 + /* Pin not found, setup its entry and name */ 2583 + idx = n_pins++; 2584 + pins[idx].name_idx = gpio; 2585 + } 2586 + pins[idx].gpio[dir] = gpio; 2435 2587 } 2436 2588 2437 2589 for (i = 0; i < n_pins; i++) { ··· 2449 2621 2450 2622 if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825) { 2451 2623 pf->ptp.ice_pin_desc = ice_pin_desc_e825c; 2452 - pf->ptp.info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e825c); 2624 + pf->ptp.info.n_pins = ARRAY_SIZE(ice_pin_desc_e825c); 2453 2625 } else { 2454 2626 pf->ptp.ice_pin_desc = ice_pin_desc_e82x; 2455 - pf->ptp.info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e82x); 2627 + pf->ptp.info.n_pins = ARRAY_SIZE(ice_pin_desc_e82x); 2456 2628 } 2457 2629 ice_ptp_setup_pin_cfg(pf); 2458 2630 } ··· 2478 2650 if (err) { 2479 2651 /* SDP section does not exist in NVM or is corrupted */ 2480 2652 if (ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) { 2481 - ptp->ice_pin_desc = ice_pin_desc_e810_sma; 2482 - ptp->info.n_pins = 2483 - ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810_sma); 2653 + ptp->ice_pin_desc = ice_pin_desc_dpll; 2654 + ptp->info.n_pins = ARRAY_SIZE(ice_pin_desc_dpll); 2484 2655 } else { 2485 2656 pf->ptp.ice_pin_desc = ice_pin_desc_e810; 2486 - pf->ptp.info.n_pins = 2487 - ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810); 2488 - err = 0; 2657 + pf->ptp.info.n_pins = ARRAY_SIZE(ice_pin_desc_e810); 2489 2658 } 2659 + err = 0; 2490 2660 } else { 2491 2661 desc = devm_kcalloc(ice_pf_to_dev(pf), ICE_N_PINS_MAX, 2492 2662 sizeof(struct ice_ptp_pin_desc), ··· 2502 2676 ptp->info.pin_config = ptp->pin_desc; 2503 2677 ice_ptp_setup_pin_cfg(pf); 2504 2678 2505 - if (ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) 2506 - err = ice_ptp_set_sma_cfg(pf); 2507 2679 err: 2508 2680 if (err) { 2509 2681 devm_kfree(ice_pf_to_dev(pf), desc); ··· 2527 2703 #endif /* CONFIG_ICE_HWTS */ 2528 2704 /* Rest of the config is the same as base E810 */ 2529 2705 pf->ptp.ice_pin_desc = ice_pin_desc_e810; 2530 - pf->ptp.info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810); 2706 + pf->ptp.info.n_pins = ARRAY_SIZE(ice_pin_desc_e810); 2531 2707 ice_ptp_setup_pin_cfg(pf); 2532 2708 } 2533 2709
-3
drivers/net/ethernet/intel/ice/ice_ptp.h
··· 202 202 203 203 /* Pin definitions for PTP */ 204 204 #define ICE_N_PINS_MAX 6 205 - #define ICE_SMA_PINS_NUM 4 206 - #define ICE_PIN_DESC_ARR_LEN(_arr) (sizeof(_arr) / \ 207 - sizeof(struct ice_ptp_pin_desc)) 208 205 209 206 /** 210 207 * struct ice_ptp_pin_desc - hardware pin description data