Skip to content

Commit b54c65c

Browse files
kolacinskikarolanguy11
authored andcommitted
ice: Implement ice_ptp_pin_desc
Add a new internal structure describing PTP pins. Use the new structure for all non-E810T products. Reviewed-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com> Signed-off-by: Karol Kolacinski <karol.kolacinski@intel.com> Reviewed-by: Simon Horman <horms@kernel.org>
1 parent 0c51228 commit b54c65c

File tree

2 files changed

+228
-107
lines changed

2 files changed

+228
-107
lines changed

drivers/net/ethernet/intel/ice/ice_ptp.c

Lines changed: 184 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@
55
#include "ice_lib.h"
66
#include "ice_trace.h"
77

8+
static const char ice_pin_names[][64] = {
9+
"SDP0",
10+
"SDP1",
11+
"SDP2",
12+
"SDP3",
13+
"TIME_SYNC",
14+
"1PPS"
15+
};
16+
17+
static const struct ice_ptp_pin_desc ice_pin_desc_e82x[] = {
18+
/* name, gpio */
19+
{ TIME_SYNC, { -1, 4 }},
20+
{ ONE_PPS, { 5, -1 }},
21+
};
22+
23+
static const struct ice_ptp_pin_desc ice_pin_desc_e810[] = {
24+
/* name, gpio */
25+
{ SDP0, { 0, 0 }},
26+
{ SDP1, { 1, 1 }},
27+
{ SDP2, { 2, 2 }},
28+
{ SDP3, { 3, 3 }},
29+
{ ONE_PPS, { 5, -1 }},
30+
};
31+
832
#define E810_OUT_PROP_DELAY_NS 1
933

1034
static const struct ptp_pin_desc ice_pin_desc_e810t[] = {
@@ -16,6 +40,29 @@ static const struct ptp_pin_desc ice_pin_desc_e810t[] = {
1640
{ "U.FL2", UFL2, PTP_PF_NONE, 2, { 0, } },
1741
};
1842

43+
/**
44+
* ice_ptp_find_pin_idx - Find pin index in ptp_pin_desc
45+
* @pf: Board private structure
46+
* @func: Pin function
47+
* @chan: GPIO channel
48+
*
49+
* Return: positive pin number when pin is present, -1 otherwise
50+
*/
51+
static int ice_ptp_find_pin_idx(struct ice_pf *pf, enum ptp_pin_function func,
52+
unsigned int chan)
53+
{
54+
const struct ptp_clock_info *info = &pf->ptp.info;
55+
int i;
56+
57+
for (i = 0; i < info->n_pins; i++) {
58+
if (info->pin_config[i].func == func &&
59+
info->pin_config[i].chan == chan)
60+
return i;
61+
}
62+
63+
return -1;
64+
}
65+
1966
/**
2067
* ice_get_sma_config_e810t
2168
* @hw: pointer to the hw struct
@@ -1896,14 +1943,14 @@ static void ice_ptp_enable_all_clkout(struct ice_pf *pf)
18961943
}
18971944

18981945
/**
1899-
* ice_ptp_gpio_enable_e810 - Enable/disable ancillary features of PHC
1946+
* ice_ptp_gpio_enable_e810t - Enable/disable ancillary features of PHC
19001947
* @info: the driver's PTP info structure
19011948
* @rq: The requested feature to change
19021949
* @on: Enable/disable flag
19031950
*/
19041951
static int
1905-
ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
1906-
struct ptp_clock_request *rq, int on)
1952+
ice_ptp_gpio_enable_e810t(struct ptp_clock_info *info,
1953+
struct ptp_clock_request *rq, int on)
19071954
{
19081955
struct ice_pf *pf = ptp_info_to_pf(info);
19091956
bool sma_pres = false;
@@ -1926,22 +1973,18 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
19261973
clk_cfg.gpio_pin = GPIO_22;
19271974
else
19281975
return -1;
1929-
} else if (ice_is_e810t(&pf->hw)) {
1976+
} else {
19301977
if (chan == 0)
19311978
clk_cfg.gpio_pin = GPIO_20;
19321979
else
19331980
clk_cfg.gpio_pin = GPIO_22;
1934-
} else if (chan == PPS_CLK_GEN_CHAN) {
1935-
clk_cfg.gpio_pin = PPS_PIN_INDEX;
1936-
} else {
1937-
clk_cfg.gpio_pin = chan;
19381981
}
19391982

19401983
clk_cfg.flags = rq->perout.flags;
1941-
clk_cfg.period = ((rq->perout.period.sec * NSEC_PER_SEC) +
1942-
rq->perout.period.nsec);
1943-
clk_cfg.start_time = ((rq->perout.start.sec * NSEC_PER_SEC) +
1944-
rq->perout.start.nsec);
1984+
clk_cfg.period = rq->perout.period.sec * NSEC_PER_SEC +
1985+
rq->perout.period.nsec;
1986+
clk_cfg.start_time = rq->perout.start.sec * NSEC_PER_SEC +
1987+
rq->perout.start.nsec;
19451988
clk_cfg.ena = !!on;
19461989

19471990
return ice_ptp_cfg_clkout(pf, chan, &clk_cfg, true);
@@ -1956,13 +1999,11 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
19561999
gpio_pin = GPIO_21;
19572000
else
19582001
gpio_pin = GPIO_23;
1959-
} else if (ice_is_e810t(&pf->hw)) {
2002+
} else {
19602003
if (chan == 0)
19612004
gpio_pin = GPIO_21;
19622005
else
19632006
gpio_pin = GPIO_23;
1964-
} else {
1965-
gpio_pin = chan;
19662007
}
19672008

19682009
extts_cfg.flags = rq->extts.flags;
@@ -1977,34 +2018,89 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
19772018
}
19782019

19792020
/**
1980-
* ice_ptp_gpio_enable_e823 - Enable/disable ancillary features of PHC
2021+
* ice_verify_pin - verify if pin supports requested pin function
19812022
* @info: the driver's PTP info structure
2023+
* @pin: Pin index
2024+
* @func: Assigned function
2025+
* @chan: Assigned channel
2026+
*
2027+
* Return: 0 on success, -EOPNOTSUPP when function is not supported.
2028+
*/
2029+
static int ice_verify_pin(struct ptp_clock_info *info, unsigned int pin,
2030+
enum ptp_pin_function func, unsigned int chan)
2031+
{
2032+
struct ice_pf *pf = ptp_info_to_pf(info);
2033+
const struct ice_ptp_pin_desc *pin_desc;
2034+
2035+
pin_desc = &pf->ptp.ice_pin_desc[pin];
2036+
2037+
/* Is assigned function allowed? */
2038+
switch (func) {
2039+
case PTP_PF_EXTTS:
2040+
if (pin_desc->gpio[0] < 0)
2041+
return -EOPNOTSUPP;
2042+
break;
2043+
case PTP_PF_PEROUT:
2044+
if (pin_desc->gpio[1] < 0)
2045+
return -EOPNOTSUPP;
2046+
break;
2047+
case PTP_PF_NONE:
2048+
break;
2049+
case PTP_PF_PHYSYNC:
2050+
default:
2051+
return -EOPNOTSUPP;
2052+
}
2053+
2054+
return 0;
2055+
}
2056+
2057+
/**
2058+
* ice_ptp_gpio_enable - Enable/disable ancillary features of PHC
2059+
* @info: The driver's PTP info structure
19822060
* @rq: The requested feature to change
19832061
* @on: Enable/disable flag
2062+
*
2063+
* Return: 0 on success, -EOPNOTSUPP when request type is not supported
19842064
*/
1985-
static int ice_ptp_gpio_enable_e823(struct ptp_clock_info *info,
1986-
struct ptp_clock_request *rq, int on)
2065+
static int ice_ptp_gpio_enable(struct ptp_clock_info *info,
2066+
struct ptp_clock_request *rq, int on)
19872067
{
19882068
struct ice_pf *pf = ptp_info_to_pf(info);
19892069

19902070
switch (rq->type) {
1991-
case PTP_CLK_REQ_PPS:
2071+
case PTP_CLK_REQ_PEROUT:
19922072
{
1993-
struct ice_perout_channel clk_cfg = {};
2073+
struct ice_perout_channel clk_cfg;
2074+
int pin_desc_idx;
2075+
2076+
pin_desc_idx = ice_ptp_find_pin_idx(pf, PTP_PF_PEROUT,
2077+
rq->perout.index);
2078+
if (pin_desc_idx < 0)
2079+
return -EIO;
2080+
19942081

19952082
clk_cfg.flags = rq->perout.flags;
1996-
clk_cfg.gpio_pin = PPS_PIN_INDEX;
1997-
clk_cfg.period = NSEC_PER_SEC;
2083+
clk_cfg.gpio_pin = pf->ptp.ice_pin_desc[pin_desc_idx].gpio[1];
2084+
clk_cfg.period = rq->perout.period.sec * NSEC_PER_SEC +
2085+
rq->perout.period.nsec;
2086+
clk_cfg.start_time = rq->perout.start.sec * NSEC_PER_SEC +
2087+
rq->perout.start.nsec;
19982088
clk_cfg.ena = !!on;
19992089

2000-
return ice_ptp_cfg_clkout(pf, PPS_CLK_GEN_CHAN, &clk_cfg, true);
2090+
return ice_ptp_cfg_clkout(pf, rq->perout.index, &clk_cfg, true);
20012091
}
20022092
case PTP_CLK_REQ_EXTTS:
20032093
{
20042094
struct ice_extts_channel extts_cfg = {};
2095+
int pin_desc_idx;
2096+
2097+
pin_desc_idx = ice_ptp_find_pin_idx(pf, PTP_PF_EXTTS,
2098+
rq->extts.index);
2099+
if (pin_desc_idx < 0)
2100+
return -EIO;
20052101

20062102
extts_cfg.flags = rq->extts.flags;
2007-
extts_cfg.gpio_pin = TIME_SYNC_PIN_INDEX;
2103+
extts_cfg.gpio_pin = pf->ptp.ice_pin_desc[pin_desc_idx].gpio[0];
20082104
extts_cfg.ena = !!on;
20092105

20102106
return ice_ptp_cfg_extts(pf, rq->extts.index, &extts_cfg, true);
@@ -2400,6 +2496,40 @@ u64 ice_ptp_get_rx_hwts(const union ice_32b_rx_flex_desc *rx_desc,
24002496
return ts_ns;
24012497
}
24022498

2499+
/**
2500+
* ice_ptp_setup_pin_cfg - setup PTP pin_config structure
2501+
* @pf: Board private structure
2502+
*/
2503+
static void ice_ptp_setup_pin_cfg(struct ice_pf *pf)
2504+
{
2505+
uint extts_chans = 0;
2506+
uint po_chans = 0;
2507+
uint i;
2508+
2509+
for (i = 0; i < pf->ptp.info.n_pins; i++) {
2510+
const struct ice_ptp_pin_desc *desc = &pf->ptp.ice_pin_desc[i];
2511+
struct ptp_pin_desc *pin = &pf->ptp.pin_desc[i];
2512+
const char *name = NULL;
2513+
2514+
name = ice_pin_names[desc->name_idx];
2515+
strscpy(pin->name, name, sizeof(pin->name));
2516+
2517+
pin->index = i;
2518+
if (desc->gpio[0] >= 0 && desc->gpio[1] < 0) {
2519+
pin->func = PTP_PF_EXTTS;
2520+
pin->chan = extts_chans++;
2521+
} else if (desc->gpio[1] >= 0 && desc->gpio[0] < 0) {
2522+
pin->func = PTP_PF_PEROUT;
2523+
pin->chan = po_chans++;
2524+
} else {
2525+
pin->func = PTP_PF_NONE;
2526+
pin->chan = 0;
2527+
}
2528+
}
2529+
2530+
pf->ptp.info.pin_config = pf->ptp.pin_desc;
2531+
}
2532+
24032533
/**
24042534
* ice_ptp_disable_sma_pins_e810t - Disable E810-T SMA pins
24052535
* @pf: pointer to the PF structure
@@ -2453,61 +2583,41 @@ ice_ptp_setup_sma_pins_e810t(struct ice_pf *pf, struct ptp_clock_info *info)
24532583
}
24542584

24552585
/**
2456-
* ice_ptp_setup_pins_e810 - Setup PTP pins in sysfs
2457-
* @pf: pointer to the PF instance
2458-
* @info: PTP clock capabilities
2459-
*/
2460-
static void
2461-
ice_ptp_setup_pins_e810(struct ice_pf *pf, struct ptp_clock_info *info)
2462-
{
2463-
if (ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) {
2464-
info->n_ext_ts = N_EXT_TS_E810;
2465-
info->n_per_out = N_PER_OUT_E810T;
2466-
info->n_pins = NUM_PTP_PINS_E810T;
2467-
info->verify = ice_verify_pin_e810t;
2468-
2469-
/* Complete setup of the SMA pins */
2470-
ice_ptp_setup_sma_pins_e810t(pf, info);
2471-
} else if (ice_is_e810t(&pf->hw)) {
2472-
info->n_ext_ts = N_EXT_TS_NO_SMA_E810T;
2473-
info->n_per_out = N_PER_OUT_NO_SMA_E810T;
2474-
} else {
2475-
info->n_per_out = N_PER_OUT_E810;
2476-
info->n_ext_ts = N_EXT_TS_E810;
2477-
}
2478-
}
2479-
2480-
/**
2481-
* ice_ptp_setup_pins_e823 - Setup PTP pins in sysfs
2586+
* ice_ptp_setup_pins_e810t - Setup PTP pins in sysfs
24822587
* @pf: pointer to the PF instance
2483-
* @info: PTP clock capabilities
24842588
*/
2485-
static void
2486-
ice_ptp_setup_pins_e823(struct ice_pf *pf, struct ptp_clock_info *info)
2589+
static void ice_ptp_setup_pins_e810t(struct ice_pf *pf)
24872590
{
2488-
info->pps = 1;
2489-
info->n_per_out = 0;
2490-
info->n_ext_ts = 1;
2591+
pf->ptp.info.enable = ice_ptp_gpio_enable_e810t;
2592+
pf->ptp.info.n_pins = NUM_PTP_PINS_E810T;
2593+
pf->ptp.info.verify = ice_verify_pin_e810t;
2594+
2595+
/* Complete setup of the SMA pins */
2596+
ice_ptp_setup_sma_pins_e810t(pf, &pf->ptp.info);
24912597
}
24922598

24932599
/**
2494-
* ice_ptp_set_funcs_e82x - Set specialized functions for E82x support
2600+
* ice_ptp_set_funcs_e82x - Set specialized functions for E82X support
24952601
* @pf: Board private structure
2496-
* @info: PTP info to fill
24972602
*
2498-
* Assign functions to the PTP capabiltiies structure for E82x devices.
2603+
* Assign functions to the PTP capabilities structure for E82X devices.
24992604
* Functions which operate across all device families should be set directly
2500-
* in ice_ptp_set_caps. Only add functions here which are distinct for E82x
2605+
* in ice_ptp_set_caps. Only add functions here which are distinct for E82X
25012606
* devices.
25022607
*/
2503-
static void
2504-
ice_ptp_set_funcs_e82x(struct ice_pf *pf, struct ptp_clock_info *info)
2608+
static void ice_ptp_set_funcs_e82x(struct ice_pf *pf)
25052609
{
25062610
#ifdef CONFIG_ICE_HWTS
25072611
if (boot_cpu_has(X86_FEATURE_ART) &&
25082612
boot_cpu_has(X86_FEATURE_TSC_KNOWN_FREQ))
2509-
info->getcrosststamp = ice_ptp_getcrosststamp_e82x;
2613+
pf->ptp.info.getcrosststamp = ice_ptp_getcrosststamp_e82x;
2614+
25102615
#endif /* CONFIG_ICE_HWTS */
2616+
pf->ptp.info.enable = ice_ptp_gpio_enable;
2617+
pf->ptp.info.verify = ice_verify_pin;
2618+
pf->ptp.ice_pin_desc = ice_pin_desc_e82x;
2619+
pf->ptp.info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e82x);
2620+
ice_ptp_setup_pin_cfg(pf);
25112621
}
25122622

25132623
/**
@@ -2523,27 +2633,15 @@ ice_ptp_set_funcs_e82x(struct ice_pf *pf, struct ptp_clock_info *info)
25232633
static void
25242634
ice_ptp_set_funcs_e810(struct ice_pf *pf, struct ptp_clock_info *info)
25252635
{
2526-
info->enable = ice_ptp_gpio_enable_e810;
2527-
ice_ptp_setup_pins_e810(pf, info);
2528-
}
2529-
2530-
/**
2531-
* ice_ptp_set_funcs_e823 - Set specialized functions for E823 support
2532-
* @pf: Board private structure
2533-
* @info: PTP info to fill
2534-
*
2535-
* Assign functions to the PTP capabiltiies structure for E823 devices.
2536-
* Functions which operate across all device families should be set directly
2537-
* in ice_ptp_set_caps. Only add functions here which are distinct for e823
2538-
* devices.
2539-
*/
2540-
static void
2541-
ice_ptp_set_funcs_e823(struct ice_pf *pf, struct ptp_clock_info *info)
2542-
{
2543-
ice_ptp_set_funcs_e82x(pf, info);
2636+
if (ice_is_e810t(&pf->hw) &&
2637+
ice_is_feature_supported(pf, ICE_F_SMA_CTRL)) {
2638+
ice_ptp_setup_pins_e810t(pf);
2639+
return;
2640+
}
25442641

2545-
info->enable = ice_ptp_gpio_enable_e823;
2546-
ice_ptp_setup_pins_e823(pf, info);
2642+
pf->ptp.ice_pin_desc = ice_pin_desc_e810;
2643+
pf->ptp.info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e810);
2644+
ice_ptp_setup_pin_cfg(pf);
25472645
}
25482646

25492647
/**
@@ -2563,13 +2661,13 @@ static void ice_ptp_set_caps(struct ice_pf *pf)
25632661
info->adjfine = ice_ptp_adjfine;
25642662
info->gettimex64 = ice_ptp_gettimex64;
25652663
info->settime64 = ice_ptp_settime64;
2664+
info->n_per_out = GLTSYN_TGT_H_IDX_MAX;
2665+
info->n_ext_ts = GLTSYN_EVNT_H_IDX_MAX;
25662666

25672667
if (ice_is_e810(&pf->hw))
25682668
ice_ptp_set_funcs_e810(pf, info);
2569-
else if (ice_is_e823(&pf->hw))
2570-
ice_ptp_set_funcs_e823(pf, info);
25712669
else
2572-
ice_ptp_set_funcs_e82x(pf, info);
2670+
ice_ptp_set_funcs_e82x(pf);
25732671
}
25742672

25752673
/**

0 commit comments

Comments
 (0)