Skip to content

Commit be2a9d1

Browse files
jacob-kellerkuba-moo
authored andcommitted
ice: Reject pin requests with unsupported flags
The driver receives requests for configuring pins via the .enable callback of the PTP clock object. These requests come into the driver with flags which modify the requested behavior from userspace. Current implementation in ice does not reject flags that it doesn't support. This causes the driver to incorrectly apply requests with such flags as PTP_PEROUT_DUTY_CYCLE, or any future flags added by the kernel which it is not yet aware of. Fix this by properly validating flags in both ice_ptp_cfg_perout and ice_ptp_cfg_extts. Ensure that we check by bit-wise negating supported flags rather than just checking and rejecting known un-supported flags. This is preferable, as it ensures better compatibility with future kernels. Fixes: 172db5f ("ice: add support for auxiliary input/output pins") Reviewed-by: Przemek Kitszel <[email protected]> Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Karol Kolacinski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Tested-by: Pucha Himasekhar Reddy <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 996422e commit be2a9d1

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,14 +1593,23 @@ void ice_ptp_extts_event(struct ice_pf *pf)
15931593
* @store: If set to true, the values will be stored
15941594
*
15951595
* Configure an external timestamp event on the requested channel.
1596+
*
1597+
* Return: 0 on success, -EOPNOTUSPP on unsupported flags
15961598
*/
1597-
static void ice_ptp_cfg_extts(struct ice_pf *pf, unsigned int chan,
1598-
struct ice_extts_channel *config, bool store)
1599+
static int ice_ptp_cfg_extts(struct ice_pf *pf, unsigned int chan,
1600+
struct ice_extts_channel *config, bool store)
15991601
{
16001602
u32 func, aux_reg, gpio_reg, irq_reg;
16011603
struct ice_hw *hw = &pf->hw;
16021604
u8 tmr_idx;
16031605

1606+
/* Reject requests with unsupported flags */
1607+
if (config->flags & ~(PTP_ENABLE_FEATURE |
1608+
PTP_RISING_EDGE |
1609+
PTP_FALLING_EDGE |
1610+
PTP_STRICT_FLAGS))
1611+
return -EOPNOTSUPP;
1612+
16041613
tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;
16051614

16061615
irq_reg = rd32(hw, PFINT_OICR_ENA);
@@ -1641,6 +1650,8 @@ static void ice_ptp_cfg_extts(struct ice_pf *pf, unsigned int chan,
16411650

16421651
if (store)
16431652
memcpy(&pf->ptp.extts_channels[chan], config, sizeof(*config));
1653+
1654+
return 0;
16441655
}
16451656

16461657
/**
@@ -1698,6 +1709,9 @@ static int ice_ptp_cfg_clkout(struct ice_pf *pf, unsigned int chan,
16981709
u32 func, val, gpio_pin;
16991710
u8 tmr_idx;
17001711

1712+
if (config && config->flags & ~PTP_PEROUT_PHASE)
1713+
return -EOPNOTSUPP;
1714+
17011715
tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;
17021716

17031717
/* 0. Reset mode & out_en in AUX_OUT */
@@ -1837,7 +1851,6 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
18371851
bool sma_pres = false;
18381852
unsigned int chan;
18391853
u32 gpio_pin;
1840-
int err;
18411854

18421855
if (ice_is_feature_supported(pf, ICE_F_SMA_CTRL))
18431856
sma_pres = true;
@@ -1866,14 +1879,14 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
18661879
clk_cfg.gpio_pin = chan;
18671880
}
18681881

1882+
clk_cfg.flags = rq->perout.flags;
18691883
clk_cfg.period = ((rq->perout.period.sec * NSEC_PER_SEC) +
18701884
rq->perout.period.nsec);
18711885
clk_cfg.start_time = ((rq->perout.start.sec * NSEC_PER_SEC) +
18721886
rq->perout.start.nsec);
18731887
clk_cfg.ena = !!on;
18741888

1875-
err = ice_ptp_cfg_clkout(pf, chan, &clk_cfg, true);
1876-
break;
1889+
return ice_ptp_cfg_clkout(pf, chan, &clk_cfg, true);
18771890
}
18781891
case PTP_CLK_REQ_EXTTS:
18791892
{
@@ -1898,14 +1911,11 @@ ice_ptp_gpio_enable_e810(struct ptp_clock_info *info,
18981911
extts_cfg.gpio_pin = gpio_pin;
18991912
extts_cfg.ena = !!on;
19001913

1901-
ice_ptp_cfg_extts(pf, chan, &extts_cfg, true);
1902-
return 0;
1914+
return ice_ptp_cfg_extts(pf, chan, &extts_cfg, true);
19031915
}
19041916
default:
19051917
return -EOPNOTSUPP;
19061918
}
1907-
1908-
return err;
19091919
}
19101920

19111921
/**
@@ -1918,19 +1928,18 @@ static int ice_ptp_gpio_enable_e823(struct ptp_clock_info *info,
19181928
struct ptp_clock_request *rq, int on)
19191929
{
19201930
struct ice_pf *pf = ptp_info_to_pf(info);
1921-
int err;
19221931

19231932
switch (rq->type) {
19241933
case PTP_CLK_REQ_PPS:
19251934
{
19261935
struct ice_perout_channel clk_cfg = {};
19271936

1937+
clk_cfg.flags = rq->perout.flags;
19281938
clk_cfg.gpio_pin = PPS_PIN_INDEX;
19291939
clk_cfg.period = NSEC_PER_SEC;
19301940
clk_cfg.ena = !!on;
19311941

1932-
err = ice_ptp_cfg_clkout(pf, PPS_CLK_GEN_CHAN, &clk_cfg, true);
1933-
break;
1942+
return ice_ptp_cfg_clkout(pf, PPS_CLK_GEN_CHAN, &clk_cfg, true);
19341943
}
19351944
case PTP_CLK_REQ_EXTTS:
19361945
{
@@ -1940,14 +1949,11 @@ static int ice_ptp_gpio_enable_e823(struct ptp_clock_info *info,
19401949
extts_cfg.gpio_pin = TIME_SYNC_PIN_INDEX;
19411950
extts_cfg.ena = !!on;
19421951

1943-
ice_ptp_cfg_extts(pf, rq->extts.index, &extts_cfg, true);
1944-
return 0;
1952+
return ice_ptp_cfg_extts(pf, rq->extts.index, &extts_cfg, true);
19451953
}
19461954
default:
19471955
return -EOPNOTSUPP;
19481956
}
1949-
1950-
return err;
19511957
}
19521958

19531959
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum ice_ptp_pin_e810t {
2929
struct ice_perout_channel {
3030
bool ena;
3131
u32 gpio_pin;
32+
u32 flags;
3233
u64 period;
3334
u64 start_time;
3435
};

0 commit comments

Comments
 (0)