Support one PTP device per hardware clock
Subsystems (8)
Tariq Toukan
maintainercover Support one PTP device per hardware clock
Hi,
This series contains two features from Jianbo, followed by simple cleanups.
Patches 1-9 by Jianbo add support for one PTP device per hardware clock, described below [1].
Patches 10-12 by Jianbo add support for 200Gbps per-lane link modes in kernel and mlx5 driver.
Patches 13-15 are simple cleanups by Gal and Carolina.
Regards,
Tariq
[1]
PHC (PTP hardware clock) is normally shared by multiple functions (PF/VF/SF). mlx5 driver currently creates a separate PTP device for each network interface that shares one PHC.
PHC can be configured to work as free running mode or real time mode. In this series, only one PTP device is created for the shared PHC when it is running in real time mode.
To support this feature,
* Firmware needs to support clock identity. When functions share a PHC, the clock identities they query are same.
* Driver dynamically allocates mlx5_clock to represent a PHC.
* New devcom component is added for hardware clock. Functions are grouped by the identity, and one mlx5_clock is allocated and shared by the functions with the same identity.
* When PTP device accesses PHC by its callbacks, the first function in the clock devcom list is selected to send commands to firmware.
* PPS IN event is armed on one function. It should be re-armed on the other one when current is unloaded.
Carolina Jubran (1):
net/mlx5e: Avoid WARN_ON when configuring MQPRIO with HTB offload
enabled
Gal Pressman (2):
net/mlx5: Remove stray semicolon in LAG port selection table creation net/mlx5e: Remove unused mlx5e_tc_flow_action struct
Jianbo Liu (12):
net/mlx5: Add helper functions for PTP callbacks net/mlx5: Change parameters for PTP internal functions net/mlx5: Add init and destruction functions for a single HW clock net/mlx5: Add API to get mlx5_core_dev from mlx5_clock net/mlx5: Change clock in mlx5_core_dev to mlx5_clock pointer net/mlx5: Add devcom component for the clock shared by functions net/mlx5: Move PPS notifier and out_work to clock_state net/mlx5: Support one PTP device per hardware clock net/mlx5: Generate PPS IN event on new function for shared clock
ethtool: Add support for 200Gbps per lane link modes net/mlx5: Add support for 200Gbps per lane link modes net/mlx5e: Support FEC settings for 200G per lane link modes
.../net/ethernet/mellanox/mlx5/core/en/port.c | 64 +- .../net/ethernet/mellanox/mlx5/core/en/port.h | 1 + .../net/ethernet/mellanox/mlx5/core/en/ptp.c | 4 +- .../mellanox/mlx5/core/en/tc/act/act.h | 5 - .../net/ethernet/mellanox/mlx5/core/en/trap.c | 2 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 4 +- .../mellanox/mlx5/core/en/xsk/setup.c | 2 +- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 22 + .../net/ethernet/mellanox/mlx5/core/en_main.c | 11 +- .../mellanox/mlx5/core/lag/port_sel.c | 2 +- .../ethernet/mellanox/mlx5/core/lib/clock.c | 582 ++++++++++++++---- .../ethernet/mellanox/mlx5/core/lib/clock.h | 39 +- .../ethernet/mellanox/mlx5/core/lib/devcom.h | 1 + .../net/ethernet/mellanox/mlx5/core/main.c | 15 +- .../net/ethernet/mellanox/mlx5/core/port.c | 3 + drivers/net/phy/phy-core.c | 20 +- include/linux/mlx5/driver.h | 33 +- include/linux/mlx5/port.h | 3 + include/uapi/linux/ethtool.h | 18 + net/ethtool/common.c | 42 ++ 20 files changed, 701 insertions(+), 172 deletions(-)
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 1/15 net/mlx5: Add helper functions for PTP callbacks
From: Jianbo Liu <[email protected]>
The PTP callback functions should not be used directly by internal callers. Add helpers that can be used internally and externally.
--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +22 -10
@@ -119,6 +119,13 @@ static u32 mlx5_ptp_shift_constant(u32 dev_freq_khz) ilog2((U32_MAX / NSEC_PER_MSEC) * dev_freq_khz)); } +static s32 mlx5_clock_getmaxphase (struct mlx5_core_dev *mdev) +{ +return MLX5_CAP_MCAM_FEATURE (mdev, mtutc_time_adjustment_extended_range) ? +MLX5_MTUTC_OPERATION_ADJUST_TIME_EXTENDED_MAX : +MLX5_MTUTC_OPERATION_ADJUST_TIME_MAX ; +} +static s32 mlx5_ptp_getmaxphase (struct ptp_clock_info *ptp) { struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
@@ -126,14 +133,12 @@ static s32 mlx5_ptp_getmaxphase(struct ptp_clock_info *ptp) mdev = container_of(clock, struct mlx5_core_dev, clock); -return MLX5_CAP_MCAM_FEATURE (mdev, mtutc_time_adjustment_extended_range) ? -MLX5_MTUTC_OPERATION_ADJUST_TIME_EXTENDED_MAX : -MLX5_MTUTC_OPERATION_ADJUST_TIME_MAX ; +return mlx5_clock_getmaxphase (mdev); }static bool mlx5_is_mtutc_time_adj_cap (struct mlx5_core_dev *mdev,s64 delta) { -s64 max =mlx5_ptp_getmaxphase (&mdev->clock.ptp_info); +s64 max =mlx5_clock_getmaxphase (mdev);if (delta < -max || delta > max)return false;
@@ -361,15 +366,12 @@ static int mlx5_ptp_settime_real_time(struct mlx5_core_dev *mdev,return mlx5_set_mtutc (mdev, in,sizeof (in)); } -static int mlx5_ptp_settime (struct ptp_clock_info *ptp,const struct timespec64 *ts) +static int mlx5_clock_settime (struct mlx5_core_dev *mdev,struct mlx5_clock *clock, +const struct timespec64 *ts) { - struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);struct mlx5_timer *timer = &clock->timer; -struct mlx5_core_dev *mdev;unsigned long flags; - mdev = container_of(clock, struct mlx5_core_dev, clock); -if (mlx5_modify_mtutc_allowed (mdev)) {int err =mlx5_ptp_settime_real_time (mdev, ts);
@@ -385,6 +387,16 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64return 0 ; } +static int mlx5_ptp_settime (struct ptp_clock_info *ptp,const struct timespec64 *ts) +{ + struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); +struct mlx5_core_dev *mdev; + + mdev = container_of(clock, struct mlx5_core_dev, clock); + +return mlx5_clock_settime (mdev, clock, ts); +} +static struct timespec64 mlx5_ptp_gettimex_real_time (struct mlx5_core_dev *mdev,struct ptp_system_timestamp *sts)
@@ -1129,7 +1141,7 @@ static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev)struct timespec64 ts;ktime_get_real_ts64 (&ts); -mlx5_ptp_settime (&clock->ptp_info, &ts); +mlx5_clock_settime (mdev, clock, &ts); } }
Signature · 1 line
2.45.0
Re: [PATCH net-next 01/15] net/mlx5: Add helper functions for PTP callbacks
Quoted 21 lines · Tariq Toukan
From: Jianbo Liu <[email protected]>
The PTP callback functions should not be used directly by internal callers. Add helpers that can be used internally and externally.
Signed-off-by Jianbo Liu <[email protected]>Reviewed-by Carolina Jubran <[email protected]>Reviewed-by Dragos Tatulea <[email protected]>Signed-off-by Tariq Toukan <[email protected]>--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +0
-0@@ -119,6 +119,13 @@ static u32 mlx5_ptp_shift_constant(u32 dev_freq_khz) ilog2((U32_MAX / NSEC_PER_MSEC) * dev_freq_khz)); }
[...]
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 · line 396
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +7
-0+static int mlx5_ptp_settime (struct ptp_clock_info *ptp,const struct timespec64 *ts) +{ + struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); +struct mlx5_core_dev *mdev; + + mdev = container_of(clock, struct mlx5_core_dev, clock); +
Maybe just oneliner for mdev instead of dividing it into two lines? But it's up to you
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +3
-0+return mlx5_clock_settime (mdev, clock, ts); +} +static struct timespec64 mlx5_ptp_gettimex_real_time (struct mlx5_core_dev *mdev,struct ptp_system_timestamp *sts)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev) · line 1147
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-1@@ -1129,7 +1141,7 @@ static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev)struct timespec64 ts;ktime_get_real_ts64 (&ts); -mlx5_ptp_settime (&clock->ptp_info, &ts); +mlx5_clock_settime (mdev, clock, &ts); } }
Only one small nitpick, overall the code looks good, nice rework.
Re: [PATCH net-next 01/15] net/mlx5: Add helper functions for PTP callbacks
Quoted 26 lines · Mateusz Polchlopek
Quoted 20 lines · Tariq Toukan
From: Jianbo Liu <[email protected]>
The PTP callback functions should not be used directly by internal callers. Add helpers that can be used internally and externally.
Signed-off-by Jianbo Liu <[email protected]>Reviewed-by Carolina Jubran <[email protected]>Reviewed-by Dragos Tatulea <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
.../ethernet/mellanox/mlx5/core/lib/clock.c | 32 +++++++++++++------1 file changed, 22 insertions(+), 10 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +0
-0@@ -119,6 +119,13 @@ static u32 mlx5_ptp_shift_constant(u32 dev_freq_khz) ilog2((U32_MAX / NSEC_PER_MSEC) * dev_freq_khz)); }[...]
Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 · line 396
Quoted 9 lines
+static int
mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 *ts)
+{
+ structmlx5_clock*clock =container_of(ptp, struct mlx5_clock, ptp_info);
+ structmlx5_core_dev*mdev;drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +3
-0+ + mdev = container_of(clock, struct mlx5_core_dev, clock); +Maybe just oneliner for mdev instead of dividing it into two lines? But it's up to you
We'll keep it as is.
This also maintains the reversed Christmas tree.
Quoted 17 lines
Quoted 7 lines
+ return
mlx5_clock_settime(mdev, clock, ts);drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +2
-0+} +static
struct timespec64mlx5_ptp_gettimex_real_time(struct mlx5_core_dev *mdev, struct ptp_system_timestamp *sts)drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static void mlx5_init_timer_clock(struct · line 1146
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-1@@ -1129,7 +1141,7 @@ static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev) struct timespec64 ts; ktime_get_real_ts64(&ts); - mlx5_ptp_settime(&clock->ptp_info, &ts); + mlx5_clock_settime(mdev, clock, &ts); } }Only one small nitpick, overall the code looks good, nice rework.
Quoted 2 lines
Reviewed-by Mateusz Polchlopek <[email protected]>
Thanks for your review.
Tariq Toukan
maintainerPATCH 2/15 net/mlx5: Change parameters for PTP internal functions
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
In later patch, the mlx5_clock will be allocated dynamically, its address can be obtained from mlx5_core_dev struct, but mdev can't be obtained from mlx5_clock because it can be shared by multiple interfaces. So change the parameter for such internal functions, only mdev is passed down from the callers.
--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +8 -11
@@ -878,10 +878,8 @@ static int mlx5_query_mtpps_pin_mode(struct mlx5_core_dev *mdev, u8 pin, mtpps_size, MLX5_REG_MTPPS, 0, 0); } -static int mlx5_get_pps_pin_mode (struct mlx5_clock *clock,u8 pin) +static int mlx5_get_pps_pin_mode (struct mlx5_core_dev *mdev,u8 pin) { - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, clock); -u32 out[MLX5_ST_SZ_DW (mtpps_reg)] = {};u8 mode;int err;
@@ -900,8 +898,9 @@ static int mlx5_get_pps_pin_mode(struct mlx5_clock *clock, u8 pin)return PTP_PF_NONE ; } -static void mlx5_init_pin_config (struct mlx5_clock *clock) +static void mlx5_init_pin_config (struct mlx5_core_dev *mdev) { +struct mlx5_clock *clock = &mdev->clock;int i;if (!clock->ptp_info.n_pins)
@@ -922,7 +921,7 @@ static void mlx5_init_pin_config(struct mlx5_clock *clock)sizeof (clock->ptp_info.pin_config[i].name), "mlx5_pps%d", i); clock->ptp_info.pin_config[i].index = i; - clock->ptp_info.pin_config[i].func =mlx5_get_pps_pin_mode (clock, i); + clock->ptp_info.pin_config[i].func =mlx5_get_pps_pin_mode (mdev, i); clock->ptp_info.pin_config[i].chan =0 ; } }
@@ -1041,10 +1040,10 @@ static void mlx5_timecounter_init(struct mlx5_core_dev *mdev) ktime_to_ns(ktime_get_real())); } -static void mlx5_init_overflow_period (struct mlx5_clock *clock) +static void mlx5_init_overflow_period (struct mlx5_core_dev *mdev) { - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, clock);struct mlx5_ib_clock_info *clock_info = mdev->clock_info; +struct mlx5_clock *clock = &mdev->clock;struct mlx5_timer *timer = &clock->timer;u64 overflow_cycles;u64 frac =0 ;
@@ -1135,7 +1134,7 @@ static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev)mlx5_timecounter_init (mdev);mlx5_init_clock_info (mdev); -mlx5_init_overflow_period (clock); +mlx5_init_overflow_period (mdev);if (mlx5_real_time_mode (mdev)) {struct timespec64 ts;
@@ -1147,13 +1146,11 @@ static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev)static void mlx5_init_pps (struct mlx5_core_dev *mdev) { -struct mlx5_clock *clock = &mdev->clock; -if (!MLX5_PPS_CAP (mdev))return ;mlx5_get_pps_caps (mdev); -mlx5_init_pin_config (clock); +mlx5_init_pin_config (mdev); }void mlx5_init_clock (struct mlx5_core_dev *mdev)
Signature · 1 line
2.45.0
Re: [PATCH net-next 02/15] net/mlx5: Change parameters for PTP internal functions
Quoted 53 lines · Tariq Toukan
From: Jianbo Liu <[email protected]>
In later patch, the
mlx5_clockwill be allocated dynamically, its address can be obtained frommlx5_core_devstruct, but mdev can't be obtained frommlx5_clockbecause it can be shared by multiple interfaces. So change the parameter for such internal functions, only mdev is passed down from the callers.Signed-off-by Jianbo Liu <[email protected]>Reviewed-by Carolina Jubran <[email protected]>Reviewed-by Dragos Tatulea <[email protected]>Signed-off-by Tariq Toukan <[email protected]>--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +4
-5@@ -878,10 +878,8 @@ static int mlx5_query_mtpps_pin_mode(struct mlx5_core_dev *mdev, u8 pin, mtpps_size, MLX5_REG_MTPPS, 0, 0); } -static int mlx5_get_pps_pin_mode (struct mlx5_clock *clock,u8 pin) +static int mlx5_get_pps_pin_mode (struct mlx5_core_dev *mdev,u8 pin) { - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, clock); -u32 out[MLX5_ST_SZ_DW (mtpps_reg)] = {};u8 mode;int err;@@ -900,8 +898,9 @@ static int mlx5_get_pps_pin_mode(struct mlx5_clock *clock, u8 pin)return PTP_PF_NONE ; } -static void mlx5_init_pin_config (struct mlx5_clock *clock) +static void mlx5_init_pin_config (struct mlx5_core_dev *mdev) { +struct mlx5_clock *clock = &mdev->clock;int i;if (!clock->ptp_info.n_pins)@@ -922,7 +921,7 @@ static void mlx5_init_pin_config(struct mlx5_clock *clock)sizeof (clock->ptp_info.pin_config[i].name), "mlx5_pps%d", i); clock->ptp_info.pin_config[i].index = i; - clock->ptp_info.pin_config[i].func =mlx5_get_pps_pin_mode (clock, i); + clock->ptp_info.pin_config[i].func =mlx5_get_pps_pin_mode (mdev, i); clock->ptp_info.pin_config[i].chan =0 ; } }
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static void mlx5_timecounter_init(struct mlx5_core_dev *mdev) · line 1047
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +2
-2@@ -1041,10 +1040,10 @@ static void mlx5_timecounter_init(struct mlx5_core_dev *mdev) ktime_to_ns(ktime_get_real())); } -static void mlx5_init_overflow_period (struct mlx5_clock *clock) +static void mlx5_init_overflow_period (struct mlx5_core_dev *mdev) { - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, clock);struct mlx5_ib_clock_info *clock_info = mdev->clock_info; +struct mlx5_clock *clock = &mdev->clock;struct mlx5_timer *timer = &clock->timer;
It seems that because of the refactor the RCT rule has been violated. I think you have to split *timer into two lines.
Quoted 16 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-2u64 overflow_cycles;u64 frac =0 ;@@ -1135,7 +1134,7 @@ static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev)mlx5_timecounter_init (mdev);mlx5_init_clock_info (mdev); -mlx5_init_overflow_period (clock); +mlx5_init_overflow_period (mdev);if (mlx5_real_time_mode (mdev)) {struct timespec64 ts;@@ -1147,13 +1146,11 @@ static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev)static void mlx5_init_pps (struct mlx5_core_dev *mdev) { -struct mlx5_clock *clock = &mdev->clock;
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev) · line 1156
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-2-if (!MLX5_PPS_CAP (mdev))return ;mlx5_get_pps_caps (mdev); -mlx5_init_pin_config (clock); +mlx5_init_pin_config (mdev); }void mlx5_init_clock (struct mlx5_core_dev *mdev)
Overall if you fix that RCT issue then feel free to add my RB tag, thanks.
Re: [PATCH net-next 02/15] net/mlx5: Change parameters for PTP internal functions
Quoted 65 lines · Mateusz Polchlopek
Quoted 62 lines · Tariq Toukan
From: Jianbo Liu <[email protected]>
In later patch, the
mlx5_clockwill be allocated dynamically, its address can be obtained frommlx5_core_devstruct, but mdev can't be obtained frommlx5_clockbecause it can be shared by multiple interfaces. So change the parameter for such internal functions, only mdev is passed down from the callers.Signed-off-by Jianbo Liu <[email protected]>Reviewed-by Carolina Jubran <[email protected]>Reviewed-by Dragos Tatulea <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
.../ethernet/mellanox/mlx5/core/lib/clock.c | 19 ++++++++-----------1 file changed, 8 insertions(+), 11 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-3@@ -878,10 +878,8 @@ static int mlx5_query_mtpps_pin_mode(struct mlx5_core_dev *mdev, u8 pin, mtpps_size, MLX5_REG_MTPPS, 0, 0); } -static int mlx5_get_pps_pin_mode(struct mlx5_clock *clock, u8 pin) +static int mlx5_get_pps_pin_mode(struct mlx5_core_dev *mdev, u8 pin) { - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, clock); - u32 out[MLX5_ST_SZ_DW(mtpps_reg)] = {}; u8 mode;int err;
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +3
-2@@ -900,8 +898,9 @@ static int mlx5_get_pps_pin_mode(struct mlx5_clock *clock, u8 pin) return PTP_PF_NONE; } -static void mlx5_init_pin_config (struct mlx5_clock *clock) +static void mlx5_init_pin_config (struct mlx5_core_dev *mdev) { + struct mlx5_clock *clock = &mdev->clock; int i; if (!clock->ptp_info.n_pins)@@ -922,7 +921,7 @@ static void mlx5_init_pin_config(struct mlx5_clock *clock) sizeof(clock->ptp_info.pin_config[i].name), "mlx5_pps%d", i); clock->ptp_info.pin_config[i].index = i; - clock->ptp_info.pin_config[i].func =mlx5_get_pps_pin_mode (clock, i); + clock->ptp_info.pin_config[i].func =mlx5_get_pps_pin_mode (mdev, i);clock->ptp_info.pin_config[i].chan = 0;
}
}drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-1@@ -1041,10 +1040,10 @@ static void mlx5_timecounter_init(struct mlx5_core_dev *mdev) ktime_to_ns(ktime_get_real())); } -static void mlx5_init_overflow_period (struct mlx5_clock *clock) +static void mlx5_init_overflow_period (struct mlx5_core_dev *mdev) {
Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static void mlx5_timecounter_init(struct mlx5_core_dev *mdev) · line 1047
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-1- struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, clock); struct mlx5_ib_clock_info *clock_info = mdev->clock_info; + struct mlx5_clock *clock = &mdev->clock; struct mlx5_timer *timer = &clock->timer;It seems that because of the refactor the RCT rule has been violated. I think you have to split *timer into two lines.
This is an existing line of code.
Due to dependency, clock had to come before.
I wouldn't split 'timer' just for this reason. Readability is not hurt. Let's keep it as is.
Quoted 18 lines
Quoted 18 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +0
-0u64 overflow_cycles;u64 frac = 0;
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-3@@ -1135,7 +1134,7 @@ static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev) mlx5_timecounter_init(mdev); mlx5_init_clock_info(mdev); - mlx5_init_overflow_period(clock); + mlx5_init_overflow_period(mdev); if (mlx5_real_time_mode(mdev)) { struct timespec64 ts;@@ -1147,13 +1146,11 @@ static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev) static void mlx5_init_pps(struct mlx5_core_dev *mdev) { - struct mlx5_clock *clock = &mdev->clock; - if (!MLX5_PPS_CAP(mdev)) return;
Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static void mlx5_init_timer_clock(struct mlx5_core_dev *mdev) · line 1156
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-1mlx5_get_pps_caps(mdev); - mlx5_init_pin_config(clock); + mlx5_init_pin_config(mdev); } void mlx5_init_clock(struct mlx5_core_dev *mdev)Overall if you fix that RCT issue then feel free to add my RB tag, thanks.
Thanks for your review.
Tariq Toukan
maintainerPATCH 3/15 net/mlx5: Add init and destruction functions for a single HW clock
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
Move hardware clock initialization and destruction to the functions, which will be used for dynamically allocated clock. Such clock is shared by all the devices if the queried clock identities are same.
The out_work is for PPS out event, which can't be triggered when clock is shared, so INIT_WORK is not moved to the initialization function. Besides, we still need to register notifier for each device.
--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +31 -17
@@ -1153,17 +1153,11 @@ static void mlx5_init_pps(struct mlx5_core_dev *mdev)mlx5_init_pin_config (mdev); } -void mlx5_init_clock (struct mlx5_core_dev *mdev) +static void mlx5_init_clock_dev (struct mlx5_core_dev *mdev) {struct mlx5_clock *clock = &mdev->clock; -if (!MLX5_CAP_GEN (mdev, device_frequency_khz)) { -mlx5_core_warn (mdev,"invalid device_frequency_khz, aborting HW clock init\n" ); -return ; - } -seqlock_init (&clock->lock); -INIT_WORK (&clock->pps_info.out_work, mlx5_pps_out);/* Initialize the device clock */ mlx5_init_timer_clock (mdev);
@@ -1179,28 +1173,19 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev) clock->ptp =NULL ; } -MLX5_NB_INIT (&clock->pps_nb, mlx5_pps_event,PPS_EVENT ); -mlx5_eq_notifier_register (mdev, &clock->pps_nb); -if (clock->ptp)ptp_schedule_worker (clock->ptp,0 ); } -void mlx5_cleanup_clock (struct mlx5_core_dev *mdev) +static void mlx5_destroy_clock_dev (struct mlx5_core_dev *mdev) {struct mlx5_clock *clock = &mdev->clock; -if (!MLX5_CAP_GEN (mdev, device_frequency_khz)) -return ; - -mlx5_eq_notifier_unregister (mdev, &clock->pps_nb);if (clock->ptp) {ptp_clock_unregister (clock->ptp); clock->ptp =NULL ; } -cancel_work_sync (&clock->pps_info.out_work); -if (mdev->clock_info) {free_page ((unsigned long )mdev->clock_info); mdev->clock_info =NULL ;
@@ -1208,3 +1193,32 @@ void mlx5_cleanup_clock(struct mlx5_core_dev *mdev)kfree (clock->ptp_info.pin_config); } + +void mlx5_init_clock (struct mlx5_core_dev *mdev) +{ +struct mlx5_clock *clock = &mdev->clock; + +if (!MLX5_CAP_GEN (mdev, device_frequency_khz)) { +mlx5_core_warn (mdev,"invalid device_frequency_khz, aborting HW clock init\n" ); +return ; + } + +mlx5_init_clock_dev (mdev); + +INIT_WORK (&clock->pps_info.out_work, mlx5_pps_out); +MLX5_NB_INIT (&clock->pps_nb, mlx5_pps_event,PPS_EVENT ); +mlx5_eq_notifier_register (mdev, &clock->pps_nb); +} + +void mlx5_cleanup_clock (struct mlx5_core_dev *mdev) +{ +struct mlx5_clock *clock = &mdev->clock; + +if (!MLX5_CAP_GEN (mdev, device_frequency_khz)) +return ; + +mlx5_eq_notifier_unregister (mdev, &clock->pps_nb); +cancel_work_sync (&clock->pps_info.out_work); + +mlx5_destroy_clock_dev (mdev); +}
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 4/15 net/mlx5: Add API to get mlx5_core_dev from mlx5_clock
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
The mdev is calculated directly from mlx5_clock, as it's one of the fields in mlx5_core_dev. Move to a function so it can be easily changed in next patch.
--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +18 -17
@@ -77,6 +77,11 @@ enum { MLX5_MTUTC_OPERATION_ADJUST_TIME_EXTENDED_MAX = 200000, }; +static struct mlx5_core_dev *mlx5_clock_mdev_get (struct mlx5_clock *clock) +{ + return container_of(clock, struct mlx5_core_dev, clock); +} +static bool mlx5_real_time_mode (struct mlx5_core_dev *mdev) {return (mlx5_is_real_time_rq (mdev) ||mlx5_is_real_time_sq (mdev));
@@ -131,7 +136,7 @@ static s32 mlx5_ptp_getmaxphase(struct ptp_clock_info *ptp) struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);struct mlx5_core_dev *mdev; - mdev = container_of(clock, struct mlx5_core_dev, clock); + mdev =mlx5_clock_mdev_get (clock);return mlx5_clock_getmaxphase (mdev); }
@@ -226,7 +231,7 @@ static int mlx5_ptp_getcrosststamp(struct ptp_clock_info *ptp,struct system_time_snapshot history_begin = {0 };struct mlx5_core_dev *mdev; - mdev = container_of(clock, struct mlx5_core_dev, clock); + mdev =mlx5_clock_mdev_get (clock);if (!mlx5_is_ptm_source_time_available (mdev))return -EBUSY ;
@@ -268,8 +273,7 @@ static u64 read_internal_timer(const struct cyclecounter *cc) { struct mlx5_timer *timer = container_of(cc, struct mlx5_timer, cycles); struct mlx5_clock *clock = container_of(timer, struct mlx5_clock, timer); - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, - clock); +struct mlx5_core_dev *mdev =mlx5_clock_mdev_get (clock);return mlx5_read_time (mdev,NULL , false) & cc->mask; }
@@ -304,8 +308,7 @@ static void mlx5_pps_out(struct work_struct *work) out_work); struct mlx5_clock *clock = container_of(pps_info, struct mlx5_clock, pps_info); - struct mlx5_core_dev *mdev = container_of(clock, struct mlx5_core_dev, - clock); +struct mlx5_core_dev *mdev =mlx5_clock_mdev_get (clock);u32 in[MLX5_ST_SZ_DW (mtpps_reg)] = {0 };unsigned long flags;int i;
@@ -335,7 +338,7 @@ static long mlx5_timestamp_overflow(struct ptp_clock_info *ptp_info)unsigned long flags; clock = container_of(ptp_info, struct mlx5_clock, ptp_info); - mdev = container_of(clock, struct mlx5_core_dev, clock); + mdev =mlx5_clock_mdev_get (clock); timer = &clock->timer;if (mdev->state ==MLX5_DEVICE_STATE_INTERNAL_ERROR )
@@ -392,7 +395,7 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);struct mlx5_core_dev *mdev; - mdev = container_of(clock, struct mlx5_core_dev, clock); + mdev =mlx5_clock_mdev_get (clock);return mlx5_clock_settime (mdev, clock, ts); }
@@ -416,7 +419,7 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,struct mlx5_core_dev *mdev;u64 cycles, ns; - mdev = container_of(clock, struct mlx5_core_dev, clock); + mdev =mlx5_clock_mdev_get (clock);if (mlx5_real_time_mode (mdev)) { *ts =mlx5_ptp_gettimex_real_time (mdev, sts); goto out;
@@ -457,7 +460,7 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)struct mlx5_core_dev *mdev;unsigned long flags; - mdev = container_of(clock, struct mlx5_core_dev, clock); + mdev =mlx5_clock_mdev_get (clock);if (mlx5_modify_mtutc_allowed (mdev)) {int err =mlx5_ptp_adjtime_real_time (mdev, delta);
@@ -479,7 +482,7 @@ static int mlx5_ptp_adjphase(struct ptp_clock_info *ptp, s32 delta) struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);struct mlx5_core_dev *mdev; - mdev = container_of(clock, struct mlx5_core_dev, clock); + mdev =mlx5_clock_mdev_get (clock);return mlx5_ptp_adjtime_real_time (mdev, delta); }
@@ -512,7 +515,7 @@ static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)unsigned long flags;u32 mult; - mdev = container_of(clock, struct mlx5_core_dev, clock); + mdev =mlx5_clock_mdev_get (clock);if (mlx5_modify_mtutc_allowed (mdev)) {int err =mlx5_ptp_freq_adj_real_time (mdev, scaled_ppm);
@@ -539,8 +542,7 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp, {struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); -struct mlx5_core_dev *mdev = - container_of(clock, struct mlx5_core_dev, clock); +struct mlx5_core_dev *mdev =mlx5_clock_mdev_get (clock);u32 in[MLX5_ST_SZ_DW (mtpps_reg)] = {0 };u32 field_select =0 ;u8 pin_mode =0 ;
@@ -724,8 +726,7 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp, {struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); -struct mlx5_core_dev *mdev = - container_of(clock, struct mlx5_core_dev, clock); +struct mlx5_core_dev *mdev =mlx5_clock_mdev_get (clock);bool rt_mode =mlx5_real_time_mode (mdev);u32 in[MLX5_ST_SZ_DW (mtpps_reg)] = {0 };u32 out_pulse_duration_ns =0 ;
@@ -987,7 +988,7 @@ static int mlx5_pps_event(struct notifier_block *nb,unsigned long flags;u64 ns; - mdev = container_of(clock, struct mlx5_core_dev, clock); + mdev =mlx5_clock_mdev_get (clock);switch (clock->ptp_info.pin_config[pin].func) {case PTP_PF_EXTTS :
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 5/15 net/mlx5: Change clock in mlx5_core_dev to mlx5_clock pointer
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
Change clock member in mlx5_core_dev to a pointer, so it can point to a clock shared by multiple functions in later patch.
For now, each function has its own clock, so mdev in mlx5_clock_priv is the back pointer to the function. Later it points to one (normally the first one) of the multiple functions sharing the same clock.
Change mlx5_init_clock() to return error if mlx5_clock is not allocated. Besides, a null clock is defined and used when hardware clock is not supported. So, the clock pointer is always pointing to something valid.
--- .../net/ethernet/mellanox/mlx5/core/en/ptp.c | 4 +- .../net/ethernet/mellanox/mlx5/core/en/trap.c | 2 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 4 +- .../mellanox/mlx5/core/en/xsk/setup.c | 2 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 4 +- .../ethernet/mellanox/mlx5/core/lib/clock.c | 87 ++++++++++++++----- .../ethernet/mellanox/mlx5/core/lib/clock.h | 35 +++++++- .../net/ethernet/mellanox/mlx5/core/main.c | 11 ++- include/linux/mlx5/driver.h | 31 +------ 9 files changed, 116 insertions(+), 64 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c +2 -2
@@ -326,7 +326,7 @@ static int mlx5e_ptp_alloc_txqsq(struct mlx5e_ptp *c, int txq_ix,int node; sq->pdev = c->pdev; - sq->clock = &mdev->clock; + sq->clock = mdev->clock; sq->mkey_be = c->mkey_be; sq->netdev = c->netdev; sq->priv = c->priv;
@@ -696,7 +696,7 @@ static int mlx5e_init_ptp_rq(struct mlx5e_ptp *c, struct mlx5e_params *params, rq->pdev = c->pdev; rq->netdev = priv->netdev; rq->priv = priv; - rq->clock = &mdev->clock; + rq->clock = mdev->clock; rq->tstamp = &priv->tstamp; rq->mdev = mdev; rq->hw_mtu =MLX5E_SW2HW_MTU (params, params->sw_mtu);
drivers/net/ethernet/mellanox/mlx5/core/en/trap.c +1 -1
@@ -46,7 +46,7 @@ static void mlx5e_init_trap_rq(struct mlx5e_trap *t, struct mlx5e_params *params rq->pdev = t->pdev; rq->netdev = priv->netdev; rq->priv = priv; - rq->clock = &mdev->clock; + rq->clock = mdev->clock; rq->tstamp = &priv->tstamp; rq->mdev = mdev; rq->hw_mtu =MLX5E_SW2HW_MTU (params, params->sw_mtu);
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +2 -2
@@ -289,9 +289,9 @@ static u64 mlx5e_xsk_fill_timestamp(void *_priv) ts =get_cqe_ts (priv->cqe);if (mlx5_is_real_time_rq (priv->cq->mdev) ||mlx5_is_real_time_sq (priv->cq->mdev)) -return mlx5_real_time_cyc2time (&priv->cq->mdev->clock, ts); +return mlx5_real_time_cyc2time (priv->cq->mdev->clock, ts); -return mlx5_timecounter_cyc2time (&priv->cq->mdev->clock, ts); +return mlx5_timecounter_cyc2time (priv->cq->mdev->clock, ts); }static void mlx5e_xsk_request_checksum (u16 csum_start,u16 csum_offset,void *priv)
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c +1 -1
@@ -72,7 +72,7 @@ static int mlx5e_init_xsk_rq(struct mlx5e_channel *c, rq->netdev = c->netdev; rq->priv = c->priv; rq->tstamp = c->tstamp; - rq->clock = &mdev->clock; + rq->clock = mdev->clock; rq->icosq = &c->icosq; rq->ix = c->ix; rq->channel = c;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +2 -2
@@ -737,7 +737,7 @@ static int mlx5e_init_rxq_rq(struct mlx5e_channel *c, struct mlx5e_params *param rq->netdev = c->netdev; rq->priv = c->priv; rq->tstamp = c->tstamp; - rq->clock = &mdev->clock; + rq->clock = mdev->clock; rq->icosq = &c->icosq; rq->ix = c->ix; rq->channel = c;
@@ -1614,7 +1614,7 @@ static int mlx5e_alloc_txqsq(struct mlx5e_channel *c,int err; sq->pdev = c->pdev; - sq->clock = &mdev->clock; + sq->clock = mdev->clock; sq->mkey_be = c->mkey_be; sq->netdev = c->netdev; sq->mdev = c->mdev;
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +66 -21
204 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h +32 -3
@@ -33,6 +33,35 @@#ifndef __LIB_CLOCK_H__#define __LIB_CLOCK_H__ +#include <linux/ptp_clock_kernel.h> + +#define MAX_PIN_NUM 8 +struct mlx5_pps { +u8 pin_caps[MAX_PIN_NUM ]; +struct work_struct out_work; +u64 start[MAX_PIN_NUM ]; +u8 enabled; +u64 min_npps_period; +u64 min_out_pulse_duration_ns; +}; + +struct mlx5_timer { +struct cyclecounter cycles; +struct timecounter tc; +u32 nominal_c_mult; +unsigned long overflow_period; +}; + +struct mlx5_clock { +struct mlx5_nb pps_nb; +seqlock_t lock; +struct hwtstamp_config hwtstamp_config; +struct ptp_clock *ptp; +struct ptp_clock_info ptp_info; +struct mlx5_pps pps_info; +struct mlx5_timer timer; +}; +static inline bool mlx5_is_real_time_rq (struct mlx5_core_dev *mdev) {u8 rq_ts_format_cap =MLX5_CAP_GEN (mdev, rq_ts_format);
@@ -54,12 +83,12 @@ static inline bool mlx5_is_real_time_sq(struct mlx5_core_dev *mdev)typedef ktime_t (*cqe_ts_to_ns )(struct mlx5_clock *,u64 );#if IS_ENABLED (CONFIG_PTP_1588_CLOCK ) -void mlx5_init_clock (struct mlx5_core_dev *mdev); +int mlx5_init_clock (struct mlx5_core_dev *mdev);void mlx5_cleanup_clock (struct mlx5_core_dev *mdev);static inline int mlx5_clock_get_ptp_index (struct mlx5_core_dev *mdev) { -return mdev->clock.ptp ?ptp_clock_index (mdev->clock.ptp) :-1 ; +return mdev->clock->ptp ?ptp_clock_index (mdev->clock->ptp) :-1 ; } static inline ktime_t mlx5_timecounter_cyc2time(struct mlx5_clock *clock,
@@ -87,7 +116,7 @@ static inline ktime_t mlx5_real_time_cyc2time(struct mlx5_clock *clock, return ns_to_ktime(time); }#else -static inline void mlx5_init_clock (struct mlx5_core_dev *mdev) {} +static inline int mlx5_init_clock (struct mlx5_core_dev *mdev) {return 0 ; }static inline void mlx5_cleanup_clock (struct mlx5_core_dev *mdev) {}static inline int mlx5_clock_get_ptp_index (struct mlx5_core_dev *mdev) {
drivers/net/ethernet/mellanox/mlx5/core/main.c +8 -3
@@ -1038,7 +1038,11 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)mlx5_init_reserved_gids (dev); -mlx5_init_clock (dev); + err =mlx5_init_clock (dev); +if (err) { +mlx5_core_err (dev,"failed to initialize hardware clock\n" ); + goto err_tables_cleanup; + } dev->vxlan =mlx5_vxlan_create (dev); dev->geneve =mlx5_geneve_create (dev);
@@ -1046,7 +1050,7 @@ static int mlx5_init_once(struct mlx5_core_dev *dev) err =mlx5_init_rl_table (dev);if (err) {mlx5_core_err (dev,"Failed to init rate limiting\n" ); - goto err_tables_cleanup; + goto err_clock_cleanup; } err =mlx5_mpfs_init (dev);
@@ -1123,10 +1127,11 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)mlx5_mpfs_cleanup (dev); err_rl_cleanup:mlx5_cleanup_rl_table (dev); -err_tables_cleanup: +err_clock_cleanup:mlx5_geneve_destroy (dev->geneve);mlx5_vxlan_destroy (dev->vxlan);mlx5_cleanup_clock (dev); +err_tables_cleanup:mlx5_cleanup_reserved_gids (dev);mlx5_cq_debugfs_cleanup (dev);mlx5_fw_reset_cleanup (dev);
include/linux/mlx5/driver.h +2 -29
@@ -54,7 +54,6 @@#include <linux/mlx5/doorbell.h> #include <linux/mlx5/eq.h> #include <linux/timecounter.h> -#include <linux/ptp_clock_kernel.h> #include <net/devlink.h> #define MLX5_ADEV_NAME "mlx5_core"
@@ -679,33 +678,7 @@ struct mlx5_rsvd_gids {struct ida ida; }; -#define MAX_PIN_NUM 8 -struct mlx5_pps { -u8 pin_caps[MAX_PIN_NUM ]; -struct work_struct out_work; -u64 start[MAX_PIN_NUM ]; -u8 enabled; -u64 min_npps_period; -u64 min_out_pulse_duration_ns; -}; - -struct mlx5_timer { -struct cyclecounter cycles; -struct timecounter tc; -u32 nominal_c_mult; -unsigned long overflow_period; -}; - -struct mlx5_clock { -struct mlx5_nb pps_nb; -seqlock_t lock; -struct hwtstamp_config hwtstamp_config; -struct ptp_clock *ptp; -struct ptp_clock_info ptp_info; -struct mlx5_pps pps_info; -struct mlx5_timer timer; -}; - +struct mlx5_clock ;struct mlx5_dm ;struct mlx5_fw_tracer ;struct mlx5_vxlan ;
@@ -789,7 +762,7 @@ struct mlx5_core_dev {#ifdef CONFIG_MLX5_FPGA struct mlx5_fpga_device *fpga;#endif -struct mlx5_clock clock; +struct mlx5_clock *clock;struct mlx5_ib_clock_info *clock_info;struct mlx5_fw_tracer *tracer;struct mlx5_rsc_dump *rsc_dump;
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 6/15 net/mlx5: Add devcom component for the clock shared by functions
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
Add new devcom component for hardware clock. When it is running in real time mode, the functions are grouped by the identify they query.
According to firmware document, the clock identify size is 64 bits, so it's safe to memcpy to component key, as the key size is also 64 bits.
--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 59 ++++++++++++++++++- .../ethernet/mellanox/mlx5/core/lib/devcom.h | 1 + include/linux/mlx5/driver.h | 2 + 3 files changed, 61 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +58 -1
@@ -43,6 +43,8 @@#include <linux/cpufeature.h> #endif /* CONFIG_X86 */ +#define MLX5_RT_CLOCK_IDENTITY_SIZE MLX5_FLD_SZ_BYTES(mrtcq_reg, rt_clock_identity) +enum {MLX5_PIN_MODE_IN =0x0 ,MLX5_PIN_MODE_OUT =0x1 ,
@@ -77,6 +79,10 @@ enum { MLX5_MTUTC_OPERATION_ADJUST_TIME_EXTENDED_MAX = 200000, }; +struct mlx5_clock_dev_state { +struct mlx5_devcom_comp_dev *compdev; +}; +struct mlx5_clock_priv {struct mlx5_clock clock;struct mlx5_core_dev *mdev;
@@ -109,6 +115,22 @@ static bool mlx5_modify_mtutc_allowed(struct mlx5_core_dev *mdev)return MLX5_CAP_MCAM_FEATURE (mdev, ptpcyc2realtime_modify); } +static int mlx5_clock_identity_get (struct mlx5_core_dev *mdev, +u8 identify[MLX5_RT_CLOCK_IDENTITY_SIZE ]) +{ +u32 out[MLX5_ST_SZ_DW (mrtcq_reg)] = {}; +u32 in[MLX5_ST_SZ_DW (mrtcq_reg)] = {}; +int err; + + err =mlx5_core_access_reg (mdev, in,sizeof (in), + out,sizeof (out),MLX5_REG_MRTCQ ,0 ,0 ); +if (!err) +memcpy (identify,MLX5_ADDR_OF (mrtcq_reg, out, rt_clock_identity), +MLX5_RT_CLOCK_IDENTITY_SIZE ); + +return err; +} +static u32 mlx5_ptp_shift_constant (u32 dev_freq_khz) {/* Optimal shift constant leads to corrections above just 1 scaled ppm.
@@ -1231,11 +1253,26 @@ static int mlx5_clock_alloc(struct mlx5_core_dev *mdev)return 0 ; } +static void mlx5_shared_clock_register (struct mlx5_core_dev *mdev,u64 key) +{ + mdev->clock_state->compdev =mlx5_devcom_register_component (mdev->priv.devc, +MLX5_DEVCOM_SHARED_CLOCK , + key,NULL , mdev); +} + +static void mlx5_shared_clock_unregister (struct mlx5_core_dev *mdev) +{ +mlx5_devcom_unregister_component (mdev->clock_state->compdev); +} +static struct mlx5_clock null_clock;int mlx5_init_clock (struct mlx5_core_dev *mdev) { +u8 identity[MLX5_RT_CLOCK_IDENTITY_SIZE ]; +struct mlx5_clock_dev_state *clock_state;struct mlx5_clock *clock; +u64 key;int err;if (!MLX5_CAP_GEN (mdev, device_frequency_khz)) {
@@ -1244,9 +1281,26 @@ int mlx5_init_clock(struct mlx5_core_dev *mdev)return 0 ; } + clock_state =kzalloc (sizeof (*clock_state),GFP_KERNEL ); +if (!clock_state) +return -ENOMEM ; + mdev->clock_state = clock_state; + +if (MLX5_CAP_MCAM_REG3 (mdev, mrtcq) &&mlx5_real_time_mode (mdev)) { +if (mlx5_clock_identity_get (mdev, identity)) { +mlx5_core_warn (mdev,"failed to get rt clock identity, create ptp dev per function\n" ); + }else { +memcpy (&key, &identity,sizeof (key)); +mlx5_shared_clock_register (mdev, key); + } + } + err =mlx5_clock_alloc (mdev); -if (err) +if (err) { +kfree (clock_state); + mdev->clock_state =NULL ;return err; + } clock = mdev->clock;INIT_WORK (&clock->pps_info.out_work, mlx5_pps_out);
@@ -1267,4 +1321,7 @@ void mlx5_cleanup_clock(struct mlx5_core_dev *mdev)cancel_work_sync (&clock->pps_info.out_work);mlx5_clock_free (mdev); +mlx5_shared_clock_unregister (mdev); +kfree (mdev->clock_state); + mdev->clock_state =NULL ; }
drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.h +1 -0
@@ -11,6 +11,7 @@ enum mlx5_devcom_component {MLX5_DEVCOM_MPV ,MLX5_DEVCOM_HCA_PORTS ,MLX5_DEVCOM_SD_GROUP , +MLX5_DEVCOM_SHARED_CLOCK , MLX5_DEVCOM_NUM_COMPONENTS, };
include/linux/mlx5/driver.h +2 -0
@@ -679,6 +679,7 @@ struct mlx5_rsvd_gids { };struct mlx5_clock ; +struct mlx5_clock_dev_state ;struct mlx5_dm ;struct mlx5_fw_tracer ;struct mlx5_vxlan ;
@@ -763,6 +764,7 @@ struct mlx5_core_dev {struct mlx5_fpga_device *fpga;#endif struct mlx5_clock *clock; +struct mlx5_clock_dev_state *clock_state;struct mlx5_ib_clock_info *clock_info;struct mlx5_fw_tracer *tracer;struct mlx5_rsc_dump *rsc_dump;
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 7/15 net/mlx5: Move PPS notifier and out_work to clock_state
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
The PPS notifier is currently in mlx5_clock, and mlx5_clock can be shared in later patch, so the notifier should be registered for each device to avoid any event miss. Besides, the out_work is scheduled by PPS out event which is triggered only when the device is in free running mode. So, both are moved to mlx5_core_dev's clock_state.
--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 37 +++++++++---------- .../ethernet/mellanox/mlx5/core/lib/clock.h | 2 - 2 files changed, 18 insertions(+), 21 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +18 -19
@@ -80,7 +80,10 @@ enum { };struct mlx5_clock_dev_state { +struct mlx5_core_dev *mdev;struct mlx5_devcom_comp_dev *compdev; +struct mlx5_nb pps_nb; +struct work_struct out_work; };struct mlx5_clock_priv {
@@ -336,11 +339,10 @@ static void mlx5_update_clock_info_page(struct mlx5_core_dev *mdev)static void mlx5_pps_out (struct work_struct *work) { - struct mlx5_pps *pps_info = container_of(work, struct mlx5_pps, - out_work); - struct mlx5_clock *clock = container_of(pps_info, struct mlx5_clock, - pps_info); -struct mlx5_core_dev *mdev =mlx5_clock_mdev_get (clock); + struct mlx5_clock_dev_state *clock_state = container_of(work, struct mlx5_clock_dev_state, + out_work); +struct mlx5_core_dev *mdev = clock_state->mdev; +struct mlx5_clock *clock = mdev->clock;u32 in[MLX5_ST_SZ_DW (mtpps_reg)] = {0 };unsigned long flags;int i;
@@ -1012,16 +1014,16 @@ static u64 perout_conf_next_event_timer(struct mlx5_core_dev *mdev,static int mlx5_pps_event (struct notifier_block *nb,unsigned long type,void *data) { - struct mlx5_clock *clock = mlx5_nb_cof(nb, struct mlx5_clock, pps_nb); + struct mlx5_clock_dev_state *clock_state = mlx5_nb_cof(nb, struct mlx5_clock_dev_state, + pps_nb); +struct mlx5_core_dev *mdev = clock_state->mdev; +struct mlx5_clock *clock = mdev->clock;struct ptp_clock_event ptp_event;struct mlx5_eqe *eqe = data;int pin = eqe->data.pps.pin; -struct mlx5_core_dev *mdev;unsigned long flags;u64 ns; - mdev =mlx5_clock_mdev_get (clock); -switch (clock->ptp_info.pin_config[pin].func) {case PTP_PF_EXTTS : ptp_event.index = pin;
@@ -1045,7 +1047,7 @@ static int mlx5_pps_event(struct notifier_block *nb,write_seqlock_irqsave (&clock->lock, flags); clock->pps_info.start[pin] = ns;write_sequnlock_irqrestore (&clock->lock, flags); -schedule_work (&clock->pps_info.out_work); +schedule_work (&clock_state->out_work);break ;default : mlx5_core_err(mdev, " Unhandled clock PPS event, func %d\n",
@@ -1271,7 +1273,6 @@ int mlx5_init_clock(struct mlx5_core_dev *mdev) {u8 identity[MLX5_RT_CLOCK_IDENTITY_SIZE ];struct mlx5_clock_dev_state *clock_state; -struct mlx5_clock *clock;u64 key;int err;
@@ -1284,6 +1285,7 @@ int mlx5_init_clock(struct mlx5_core_dev *mdev) clock_state =kzalloc (sizeof (*clock_state),GFP_KERNEL );if (!clock_state)return -ENOMEM ; + clock_state->mdev = mdev; mdev->clock_state = clock_state;if (MLX5_CAP_MCAM_REG3 (mdev, mrtcq) &&mlx5_real_time_mode (mdev)) {
@@ -1301,24 +1303,21 @@ int mlx5_init_clock(struct mlx5_core_dev *mdev) mdev->clock_state =NULL ;return err; } - clock = mdev->clock; -INIT_WORK (&clock->pps_info.out_work, mlx5_pps_out); -MLX5_NB_INIT (&clock->pps_nb, mlx5_pps_event,PPS_EVENT ); -mlx5_eq_notifier_register (mdev, &clock->pps_nb); +INIT_WORK (&mdev->clock_state->out_work, mlx5_pps_out); +MLX5_NB_INIT (&mdev->clock_state->pps_nb, mlx5_pps_event,PPS_EVENT ); +mlx5_eq_notifier_register (mdev, &mdev->clock_state->pps_nb);return 0 ; }void mlx5_cleanup_clock (struct mlx5_core_dev *mdev) { -struct mlx5_clock *clock = mdev->clock; -if (!MLX5_CAP_GEN (mdev, device_frequency_khz))return ; -mlx5_eq_notifier_unregister (mdev, &clock->pps_nb); -cancel_work_sync (&clock->pps_info.out_work); +mlx5_eq_notifier_unregister (mdev, &mdev->clock_state->pps_nb); +cancel_work_sync (&mdev->clock_state->out_work);mlx5_clock_free (mdev);mlx5_shared_clock_unregister (mdev);
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h +0 -2
@@ -38,7 +38,6 @@#define MAX_PIN_NUM 8struct mlx5_pps {u8 pin_caps[MAX_PIN_NUM ]; -struct work_struct out_work;u64 start[MAX_PIN_NUM ];u8 enabled;u64 min_npps_period;
@@ -53,7 +52,6 @@ struct mlx5_timer { };struct mlx5_clock { -struct mlx5_nb pps_nb;seqlock_t lock;struct hwtstamp_config hwtstamp_config;struct ptp_clock *ptp;
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 8/15 net/mlx5: Support one PTP device per hardware clock
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
Currently, mlx5 driver exposes a PTP device for each network interface, resulting in multiple device nodes representing the same underlying PHC (PTP hardware clock). This causes problem if it is trying to synchronize to itself. For instance, when ptp4l operates on multiple interfaces following different masters, phc2sys attempts to synchronize them in automatic mode.
PHC can be configured to work as free running mode or real time mode. All functions can access it directly. In this patch, we create one PTP device for each PHC when it's running in real time mode. All the functions share the same PTP device if the clock identifies they query are same, and they are already grouped by devcom in previous commit. The first mdev in the peer list is chosen when sending MTPPS/MTUTC/MTPPSE/MRTCQ to firmware. Since the function can be unloaded at any time, we need to use a mutex lock to protect the mdev pointer used in PTP and PPS callbacks. Besides, new one should be picked from the peer list when the current is not available.
The clock info, which is used by IB, is shared by all the interfaces using the same hardware clock.
--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 250 ++++++++++++++---- .../ethernet/mellanox/mlx5/core/lib/clock.h | 1 + 2 files changed, 203 insertions(+), 48 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +202 -48
@@ -89,6 +89,7 @@ struct mlx5_clock_dev_state {struct mlx5_clock_priv {struct mlx5_clock clock;struct mlx5_core_dev *mdev; +struct mutex lock;/* protect mdev and used in PTP callbacks */ };static struct mlx5_clock_priv *clock_priv (struct mlx5_clock *clock)
@@ -96,11 +97,37 @@ static struct mlx5_clock_priv *clock_priv(struct mlx5_clock *clock) return container_of(clock, struct mlx5_clock_priv, clock); } +static void mlx5_clock_lockdep_assert (struct mlx5_clock *clock) +{ +if (!clock->shared) +return ; + +lockdep_assert (lockdep_is_held (&clock_priv (clock)->lock)); +} +static struct mlx5_core_dev *mlx5_clock_mdev_get (struct mlx5_clock *clock) { +mlx5_clock_lockdep_assert (clock); +return clock_priv (clock)->mdev; } +static void mlx5_clock_lock (struct mlx5_clock *clock) +{ +if (!clock->shared) +return ; + +mutex_lock (&clock_priv (clock)->lock); +} + +static void mlx5_clock_unlock (struct mlx5_clock *clock) +{ +if (!clock->shared) +return ; + +mutex_unlock (&clock_priv (clock)->lock); +} +static bool mlx5_real_time_mode (struct mlx5_core_dev *mdev) {return (mlx5_is_real_time_rq (mdev) ||mlx5_is_real_time_sq (mdev));
@@ -170,10 +197,14 @@ static s32 mlx5_ptp_getmaxphase(struct ptp_clock_info *ptp) { struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);struct mlx5_core_dev *mdev; +s32 ret; +mlx5_clock_lock (clock); mdev =mlx5_clock_mdev_get (clock); + ret =mlx5_clock_getmaxphase (mdev); +mlx5_clock_unlock (clock); -return mlx5_clock_getmaxphase (mdev); +return ret; }static bool mlx5_is_mtutc_time_adj_cap (struct mlx5_core_dev *mdev,s64 delta)
@@ -265,16 +296,23 @@ static int mlx5_ptp_getcrosststamp(struct ptp_clock_info *ptp, struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);struct system_time_snapshot history_begin = {0 };struct mlx5_core_dev *mdev; +int err; +mlx5_clock_lock (clock); mdev =mlx5_clock_mdev_get (clock); -if (!mlx5_is_ptm_source_time_available (mdev)) -return -EBUSY ; +if (!mlx5_is_ptm_source_time_available (mdev)) { + err = -EBUSY ; + goto unlock; + }ktime_get_snapshot (&history_begin); -return get_device_system_crosststamp (mlx5_mtctr_syncdevicetime, mdev, - &history_begin, cts); + err =get_device_system_crosststamp (mlx5_mtctr_syncdevicetime, mdev, + &history_begin, cts); +unlock: +mlx5_clock_unlock (clock); + return err; }#endif /* CONFIG_X86 */
@@ -372,6 +410,7 @@ static long mlx5_timestamp_overflow(struct ptp_clock_info *ptp_info)unsigned long flags; clock = container_of(ptp_info, struct mlx5_clock, ptp_info); +mlx5_clock_lock (clock); mdev =mlx5_clock_mdev_get (clock); timer = &clock->timer;
@@ -384,6 +423,7 @@ static long mlx5_timestamp_overflow(struct ptp_clock_info *ptp_info)write_sequnlock_irqrestore (&clock->lock, flags); out: +mlx5_clock_unlock (clock);return timer->overflow_period; }
@@ -428,10 +468,14 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp, const struct timespec64 { struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);struct mlx5_core_dev *mdev; +int err; +mlx5_clock_lock (clock); mdev =mlx5_clock_mdev_get (clock); + err =mlx5_clock_settime (mdev, clock, ts); +mlx5_clock_unlock (clock); -return mlx5_clock_settime (mdev, clock, ts); +return err; } static
@@ -453,6 +497,7 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,struct mlx5_core_dev *mdev;u64 cycles, ns; +mlx5_clock_lock (clock); mdev =mlx5_clock_mdev_get (clock);if (mlx5_real_time_mode (mdev)) { *ts =mlx5_ptp_gettimex_real_time (mdev, sts);
@@ -463,6 +508,7 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts, ns =mlx5_timecounter_cyc2time (clock, cycles); *ts =ns_to_timespec64 (ns); out: +mlx5_clock_unlock (clock);return 0 ; }
@@ -493,14 +539,16 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)struct mlx5_timer *timer = &clock->timer;struct mlx5_core_dev *mdev;unsigned long flags; +int err =0 ; +mlx5_clock_lock (clock); mdev =mlx5_clock_mdev_get (clock);if (mlx5_modify_mtutc_allowed (mdev)) { -int err =mlx5_ptp_adjtime_real_time (mdev, delta); + err =mlx5_ptp_adjtime_real_time (mdev, delta);if (err) -return err; + goto unlock; }write_seqlock_irqsave (&clock->lock, flags);
@@ -508,17 +556,23 @@ static int mlx5_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)mlx5_update_clock_info_page (mdev);write_sequnlock_irqrestore (&clock->lock, flags); -return 0 ; +unlock: +mlx5_clock_unlock (clock); +return err; }static int mlx5_ptp_adjphase (struct ptp_clock_info *ptp,s32 delta) { struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);struct mlx5_core_dev *mdev; +int err; +mlx5_clock_lock (clock); mdev =mlx5_clock_mdev_get (clock); + err =mlx5_ptp_adjtime_real_time (mdev, delta); +mlx5_clock_unlock (clock); -return mlx5_ptp_adjtime_real_time (mdev, delta); +return err; }static int mlx5_ptp_freq_adj_real_time (struct mlx5_core_dev *mdev,long scaled_ppm)
@@ -547,15 +601,17 @@ static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)struct mlx5_timer *timer = &clock->timer;struct mlx5_core_dev *mdev;unsigned long flags; +int err =0 ;u32 mult; +mlx5_clock_lock (clock); mdev =mlx5_clock_mdev_get (clock);if (mlx5_modify_mtutc_allowed (mdev)) { -int err =mlx5_ptp_freq_adj_real_time (mdev, scaled_ppm); + err =mlx5_ptp_freq_adj_real_time (mdev, scaled_ppm);if (err) -return err; + goto unlock; } mult = (u32 )adjust_by_scaled_ppm (timer->nominal_c_mult, scaled_ppm);
@@ -567,7 +623,9 @@ static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)write_sequnlock_irqrestore (&clock->lock, flags);ptp_schedule_worker (clock->ptp, timer->overflow_period); -return 0 ; +unlock: +mlx5_clock_unlock (clock); +return err; } static int mlx5_extts_configure(struct ptp_clock_info *ptp,
@@ -576,17 +634,14 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp, {struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); -struct mlx5_core_dev *mdev =mlx5_clock_mdev_get (clock);u32 in[MLX5_ST_SZ_DW (mtpps_reg)] = {0 }; +struct mlx5_core_dev *mdev;u32 field_select =0 ;u8 pin_mode =0 ;u8 pattern =0 ;int pin =-1 ;int err =0 ; -if (!MLX5_PPS_CAP (mdev)) -return -EOPNOTSUPP ; -/* Reject requests with unsupported flags */ if (rq->extts.flags & ~(PTP_ENABLE_FEATURE | PTP_RISING_EDGE |
@@ -617,6 +672,14 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp, field_select =MLX5_MTPPS_FS_ENABLE ; } +mlx5_clock_lock (clock); + mdev =mlx5_clock_mdev_get (clock); + +if (!MLX5_PPS_CAP (mdev)) { + err = -EOPNOTSUPP ; + goto unlock; + } +MLX5_SET (mtpps_reg, in, pin, pin);MLX5_SET (mtpps_reg, in, pin_mode, pin_mode);MLX5_SET (mtpps_reg, in, pattern, pattern);
@@ -625,10 +688,13 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp, err =mlx5_set_mtpps (mdev, in,sizeof (in));if (err) -return err; + goto unlock; + + err =mlx5_set_mtppse (mdev, pin,0 ,MLX5_EVENT_MODE_REPETETIVE & on); -return mlx5_set_mtppse (mdev, pin,0 , -MLX5_EVENT_MODE_REPETETIVE & on); +unlock: +mlx5_clock_unlock (clock); +return err; }static u64 find_target_cycles (struct mlx5_core_dev *mdev,s64 target_ns)
@@ -760,25 +826,18 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp, {struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info); -struct mlx5_core_dev *mdev =mlx5_clock_mdev_get (clock); -bool rt_mode =mlx5_real_time_mode (mdev);u32 in[MLX5_ST_SZ_DW (mtpps_reg)] = {0 };u32 out_pulse_duration_ns =0 ; +struct mlx5_core_dev *mdev;u32 field_select =0 ;u64 npps_period =0 ;u64 time_stamp =0 ;u8 pin_mode =0 ;u8 pattern =0 ; +bool rt_mode;int pin =-1 ;int err =0 ; -if (!MLX5_PPS_CAP (mdev)) -return -EOPNOTSUPP ; - -/* Reject requests with unsupported flags */ -if (mlx5_perout_verify_flags (mdev, rq->perout.flags)) -return -EOPNOTSUPP ; -if (rq->perout.index >= clock->ptp_info.n_pins)return -EINVAL ;
@@ -787,14 +846,29 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp,if (pin <0 )return -EBUSY ; -if (on) { -bool rt_mode =mlx5_real_time_mode (mdev); +mlx5_clock_lock (clock); + mdev =mlx5_clock_mdev_get (clock); + rt_mode =mlx5_real_time_mode (mdev); + +if (!MLX5_PPS_CAP (mdev)) { + err = -EOPNOTSUPP ; + goto unlock; + } + +/* Reject requests with unsupported flags */ +if (mlx5_perout_verify_flags (mdev, rq->perout.flags)) { + err = -EOPNOTSUPP ; + goto unlock; + } +if (on) { pin_mode =MLX5_PIN_MODE_OUT ; pattern =MLX5_OUT_PATTERN_PERIODIC ; -if (rt_mode && rq->perout.start.sec >U32_MAX ) -return -EINVAL ; +if (rt_mode && rq->perout.start.sec >U32_MAX ) { + err = -EINVAL ; + goto unlock; + } field_select |=MLX5_MTPPS_FS_PIN_MODE | MLX5_MTPPS_FS_PATTERN |
@@ -807,7 +881,7 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp,else err =perout_conf_1pps (mdev, rq, &time_stamp, rt_mode);if (err) -return err; + goto unlock; }MLX5_SET (mtpps_reg, in, pin, pin);
@@ -820,13 +894,16 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp,MLX5_SET (mtpps_reg, in, out_pulse_duration_ns, out_pulse_duration_ns); err =mlx5_set_mtpps (mdev, in,sizeof (in));if (err) -return err; + goto unlock;if (rt_mode) -return 0 ; + goto unlock; -return mlx5_set_mtppse (mdev, pin,0 , -MLX5_EVENT_MODE_REPETETIVE & on); + err =mlx5_set_mtppse (mdev, pin,0 ,MLX5_EVENT_MODE_REPETETIVE & on); + +unlock: +mlx5_clock_unlock (clock); +return err; } static int mlx5_pps_configure(struct ptp_clock_info *ptp,
@@ -1043,6 +1120,10 @@ static int mlx5_pps_event(struct notifier_block *nb,ptp_clock_event (clock->ptp, &ptp_event);break ;case PTP_PF_PEROUT : +if (clock->shared) { +mlx5_core_warn (mdev," Received unexpected PPS out event\n" ); +break ; + } ns =perout_conf_next_event_timer (mdev, clock);write_seqlock_irqsave (&clock->lock, flags); clock->pps_info.start[pin] = ns;
@@ -1201,9 +1282,10 @@ static void mlx5_init_clock_dev(struct mlx5_core_dev *mdev)mlx5_init_pps (mdev); clock->ptp =ptp_clock_register (&clock->ptp_info, - &mdev->pdev->dev); + clock->shared ?NULL : &mdev->pdev->dev);if (IS_ERR (clock->ptp)) { -mlx5_core_warn (mdev,"ptp_clock_register failed %ld\n" , +mlx5_core_warn (mdev,"%sptp_clock_register failed %ld\n" , + clock->shared ?"shared clock " :"" ,PTR_ERR (clock->ptp)); clock->ptp =NULL ; }
@@ -1234,11 +1316,12 @@ static void mlx5_clock_free(struct mlx5_core_dev *mdev)struct mlx5_clock_priv *cpriv =clock_priv (mdev->clock);mlx5_destroy_clock_dev (mdev); +mutex_destroy (&cpriv->lock);kfree (cpriv); mdev->clock =NULL ; } -static int mlx5_clock_alloc (struct mlx5_core_dev *mdev) +static int mlx5_clock_alloc (struct mlx5_core_dev *mdev,bool shared) {struct mlx5_clock_priv *cpriv;struct mlx5_clock *clock;
@@ -1247,23 +1330,90 @@ static int mlx5_clock_alloc(struct mlx5_core_dev *mdev)if (!cpriv)return -ENOMEM ; +mutex_init (&cpriv->lock); cpriv->mdev = mdev; clock = &cpriv->clock; + clock->shared = shared; mdev->clock = clock; +mlx5_clock_lock (clock);mlx5_init_clock_dev (mdev); +mlx5_clock_unlock (clock); + +if (!clock->shared) +return 0 ; + +if (!clock->ptp) { +mlx5_core_warn (mdev,"failed to create ptp dev shared by multiple functions" ); +mlx5_clock_free (mdev); +return -EINVAL ; + }return 0 ; }static void mlx5_shared_clock_register (struct mlx5_core_dev *mdev,u64 key) { +struct mlx5_core_dev *peer_dev, *next =NULL ; +struct mlx5_devcom_comp_dev *pos; + mdev->clock_state->compdev =mlx5_devcom_register_component (mdev->priv.devc,MLX5_DEVCOM_SHARED_CLOCK , key,NULL , mdev); +if (IS_ERR (mdev->clock_state->compdev)) +return ; + +mlx5_devcom_comp_lock (mdev->clock_state->compdev); +mlx5_devcom_for_each_peer_entry (mdev->clock_state->compdev, peer_dev, pos) { +if (peer_dev->clock) { + next = peer_dev; +break ; + } + } + +if (next) { + mdev->clock = next->clock; +/* clock info is shared among all the functions using the same clock */ + mdev->clock_info = next->clock_info; + }else { +mlx5_clock_alloc (mdev, true); + } +mlx5_devcom_comp_unlock (mdev->clock_state->compdev); + +if (!mdev->clock) { +mlx5_devcom_unregister_component (mdev->clock_state->compdev); + mdev->clock_state->compdev =NULL ; + } }static void mlx5_shared_clock_unregister (struct mlx5_core_dev *mdev) { +struct mlx5_core_dev *peer_dev, *next =NULL ; +struct mlx5_clock *clock = mdev->clock; +struct mlx5_devcom_comp_dev *pos; + +mlx5_devcom_comp_lock (mdev->clock_state->compdev); +mlx5_devcom_for_each_peer_entry (mdev->clock_state->compdev, peer_dev, pos) { +if (peer_dev->clock && peer_dev != mdev) { + next = peer_dev; +break ; + } + } + +if (next) { +struct mlx5_clock_priv *cpriv =clock_priv (clock); + +mlx5_clock_lock (clock); +if (mdev == cpriv->mdev) + cpriv->mdev = next; +mlx5_clock_unlock (clock); + }else { +mlx5_clock_free (mdev); + } + + mdev->clock =NULL ; + mdev->clock_info =NULL ; +mlx5_devcom_comp_unlock (mdev->clock_state->compdev); +mlx5_devcom_unregister_component (mdev->clock_state->compdev); }
@@ -1297,11 +1447,13 @@ int mlx5_init_clock(struct mlx5_core_dev *mdev) } } - err =mlx5_clock_alloc (mdev); -if (err) { -kfree (clock_state); - mdev->clock_state =NULL ; -return err; +if (!mdev->clock) { + err =mlx5_clock_alloc (mdev, false); +if (err) { +kfree (clock_state); + mdev->clock_state =NULL ; +return err; + } }INIT_WORK (&mdev->clock_state->out_work, mlx5_pps_out);
@@ -1319,8 +1471,10 @@ void mlx5_cleanup_clock(struct mlx5_core_dev *mdev)mlx5_eq_notifier_unregister (mdev, &mdev->clock_state->pps_nb);cancel_work_sync (&mdev->clock_state->out_work); -mlx5_clock_free (mdev); -mlx5_shared_clock_unregister (mdev); +if (mdev->clock->shared) +mlx5_shared_clock_unregister (mdev); +else +mlx5_clock_free (mdev);kfree (mdev->clock_state); mdev->clock_state =NULL ; }
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h +1 -0
@@ -58,6 +58,7 @@ struct mlx5_clock {struct ptp_clock_info ptp_info;struct mlx5_pps pps_info;struct mlx5_timer timer; +bool shared; };static inline bool mlx5_is_real_time_rq (struct mlx5_core_dev *mdev)
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 9/15 net/mlx5: Generate PPS IN event on new function for shared clock
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
As a specific function (mdev) is chosen to send MTPPSE command to firmware, the event is generated only on that function. When that function is unloaded, the PPS event can't be forward to PTP device, even when there are other functions in the group, and PTP device is not destroyed. To resolve this problem, need to send MTPPSE again from new function, and dis-arm the event on old function after that.
PPS events are handled by EQ notifier. The async EQs and notifiers are destroyed in mlx5_eq_table_destroy() which is called before mlx5_cleanup_clock(). During the period between mlx5_eq_table_destroy() and mlx5_cleanup_clock(), the events can't be handled. To avoid event loss, add mlx5_clock_unload() in mlx5_unload() to arm the event on other available function, and mlx5_clock_load in mlx5_load() for symmetry.
--- .../ethernet/mellanox/mlx5/core/lib/clock.c | 97 +++++++++++++++++-- .../ethernet/mellanox/mlx5/core/lib/clock.h | 5 + .../net/ethernet/mellanox/mlx5/core/main.c | 4 + 3 files changed, 99 insertions(+), 7 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +90 -7
@@ -90,6 +90,7 @@ struct mlx5_clock_priv {struct mlx5_clock clock;struct mlx5_core_dev *mdev;struct mutex lock;/* protect mdev and used in PTP callbacks */ +struct mlx5_core_dev *event_mdev; };static struct mlx5_clock_priv *clock_priv (struct mlx5_clock *clock)
@@ -691,6 +692,11 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp, goto unlock; err =mlx5_set_mtppse (mdev, pin,0 ,MLX5_EVENT_MODE_REPETETIVE & on); +if (err) + goto unlock; + + clock->pps_info.pin_armed[pin] = on; +clock_priv (clock)->event_mdev = mdev; unlock:mlx5_clock_unlock (clock);
@@ -1417,6 +1423,90 @@ static void mlx5_shared_clock_unregister(struct mlx5_core_dev *mdev)mlx5_devcom_unregister_component (mdev->clock_state->compdev); } +static void mlx5_clock_arm_pps_in_event (struct mlx5_clock *clock, +struct mlx5_core_dev *new_mdev, +struct mlx5_core_dev *old_mdev) +{ +struct ptp_clock_info *ptp_info = &clock->ptp_info; +struct mlx5_clock_priv *cpriv =clock_priv (clock); +int i; + +for (i =0 ; i < ptp_info->n_pins; i++) { +if (ptp_info->pin_config[i].func !=PTP_PF_EXTTS || + !clock->pps_info.pin_armed[i]) +continue ; + +if (new_mdev) { +mlx5_set_mtppse (new_mdev, i,0 ,MLX5_EVENT_MODE_REPETETIVE ); + cpriv->event_mdev = new_mdev; + }else { + cpriv->event_mdev =NULL ; + } + +if (old_mdev) +mlx5_set_mtppse (old_mdev, i,0 ,MLX5_EVENT_MODE_DISABLE ); + } +} + +void mlx5_clock_load (struct mlx5_core_dev *mdev) +{ +struct mlx5_clock *clock = mdev->clock; +struct mlx5_clock_priv *cpriv; + +if (!MLX5_CAP_GEN (mdev, device_frequency_khz)) +return ; + +INIT_WORK (&mdev->clock_state->out_work, mlx5_pps_out); +MLX5_NB_INIT (&mdev->clock_state->pps_nb, mlx5_pps_event,PPS_EVENT ); +mlx5_eq_notifier_register (mdev, &mdev->clock_state->pps_nb); + +if (!clock->shared) { +mlx5_clock_arm_pps_in_event (clock, mdev,NULL ); +return ; + } + + cpriv =clock_priv (clock); +mlx5_devcom_comp_lock (mdev->clock_state->compdev); +mlx5_clock_lock (clock); +if (mdev == cpriv->mdev && mdev != cpriv->event_mdev) +mlx5_clock_arm_pps_in_event (clock, mdev, cpriv->event_mdev); +mlx5_clock_unlock (clock); +mlx5_devcom_comp_unlock (mdev->clock_state->compdev); +} + +void mlx5_clock_unload (struct mlx5_core_dev *mdev) +{ +struct mlx5_core_dev *peer_dev, *next =NULL ; +struct mlx5_clock *clock = mdev->clock; +struct mlx5_devcom_comp_dev *pos; + +if (!MLX5_CAP_GEN (mdev, device_frequency_khz)) +return ; + +if (!clock->shared) { +mlx5_clock_arm_pps_in_event (clock,NULL , mdev); + goto out; + } + +mlx5_devcom_comp_lock (mdev->clock_state->compdev); +mlx5_devcom_for_each_peer_entry (mdev->clock_state->compdev, peer_dev, pos) { +if (peer_dev->clock && peer_dev != mdev) { + next = peer_dev; +break ; + } + } + +mlx5_clock_lock (clock); +if (mdev ==clock_priv (clock)->event_mdev) +mlx5_clock_arm_pps_in_event (clock, next, mdev); +mlx5_clock_unlock (clock); +mlx5_devcom_comp_unlock (mdev->clock_state->compdev); + +out: +mlx5_eq_notifier_unregister (mdev, &mdev->clock_state->pps_nb); +cancel_work_sync (&mdev->clock_state->out_work); +} +static struct mlx5_clock null_clock;int mlx5_init_clock (struct mlx5_core_dev *mdev)
@@ -1456,10 +1546,6 @@ int mlx5_init_clock(struct mlx5_core_dev *mdev) } } -INIT_WORK (&mdev->clock_state->out_work, mlx5_pps_out); -MLX5_NB_INIT (&mdev->clock_state->pps_nb, mlx5_pps_event,PPS_EVENT ); -mlx5_eq_notifier_register (mdev, &mdev->clock_state->pps_nb); -return 0 ; }
@@ -1468,9 +1554,6 @@ void mlx5_cleanup_clock(struct mlx5_core_dev *mdev)if (!MLX5_CAP_GEN (mdev, device_frequency_khz))return ; -mlx5_eq_notifier_unregister (mdev, &mdev->clock_state->pps_nb); -cancel_work_sync (&mdev->clock_state->out_work); -if (mdev->clock->shared)mlx5_shared_clock_unregister (mdev);else
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h +5 -0
@@ -42,6 +42,7 @@ struct mlx5_pps {u8 enabled;u64 min_npps_period;u64 min_out_pulse_duration_ns; +bool pin_armed[MAX_PIN_NUM ]; };struct mlx5_timer {
@@ -84,6 +85,8 @@ typedef ktime_t (*cqe_ts_to_ns)(struct mlx5_clock *, u64);#if IS_ENABLED (CONFIG_PTP_1588_CLOCK )int mlx5_init_clock (struct mlx5_core_dev *mdev);void mlx5_cleanup_clock (struct mlx5_core_dev *mdev); +void mlx5_clock_load (struct mlx5_core_dev *mdev); +void mlx5_clock_unload (struct mlx5_core_dev *mdev);static inline int mlx5_clock_get_ptp_index (struct mlx5_core_dev *mdev) {
@@ -117,6 +120,8 @@ static inline ktime_t mlx5_real_time_cyc2time(struct mlx5_clock *clock,#else static inline int mlx5_init_clock (struct mlx5_core_dev *mdev) {return 0 ; }static inline void mlx5_cleanup_clock (struct mlx5_core_dev *mdev) {} +static inline void mlx5_clock_load (struct mlx5_core_dev *mdev) {} +static inline void mlx5_clock_unload (struct mlx5_core_dev *mdev) {}static inline int mlx5_clock_get_ptp_index (struct mlx5_core_dev *mdev) {return -1 ;
drivers/net/ethernet/mellanox/mlx5/core/main.c +4 -0
@@ -1364,6 +1364,8 @@ static int mlx5_load(struct mlx5_core_dev *dev) goto err_eq_table; } +mlx5_clock_load (dev); + err =mlx5_fw_tracer_init (dev->tracer);if (err) {mlx5_core_err (dev,"Failed to init FW tracer %d\n" , err);
@@ -1447,6 +1449,7 @@ static int mlx5_load(struct mlx5_core_dev *dev)mlx5_hv_vhca_cleanup (dev->hv_vhca);mlx5_fw_reset_events_stop (dev);mlx5_fw_tracer_cleanup (dev->tracer); +mlx5_clock_unload (dev);mlx5_eq_table_destroy (dev); err_eq_table:mlx5_irq_table_destroy (dev);
@@ -1473,6 +1476,7 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_hv_vhca_cleanup (dev->hv_vhca);mlx5_fw_reset_events_stop (dev);mlx5_fw_tracer_cleanup (dev->tracer); +mlx5_clock_unload (dev);mlx5_eq_table_destroy (dev);mlx5_irq_table_destroy (dev);mlx5_pagealloc_stop (dev);
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 10/15 ethtool: Add support for 200Gbps per lane link modes
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
Define 200G, 400G and 800G link modes using 200Gbps per lane.
--- drivers/net/phy/phy-core.c | 20 ++++++++++++++++- include/uapi/linux/ethtool.h | 18 ++++++++++++++++ net/ethtool/common.c | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-)
drivers/net/phy/phy-core.c +19 -1
@@ -13,7 +13,7 @@*/ const char *phy_speed_to_str (int speed) { -BUILD_BUG_ON_MSG (__ETHTOOL_LINK_MODE_MASK_NBITS !=103 , +BUILD_BUG_ON_MSG (__ETHTOOL_LINK_MODE_MASK_NBITS !=121 ,"Enum ethtool_link_mode_bit_indices and phylib are out of sync. " "If a speed or mode has been added please update phy_speed_to_str " "and the PHY settings array.\n" );
@@ -169,6 +169,12 @@ static const struct phy_setting settings[] = { PHY_SETTING( 800000, FULL, 800000baseDR8_2_Full ), PHY_SETTING( 800000, FULL, 800000baseSR8_Full ), PHY_SETTING( 800000, FULL, 800000baseVR8_Full ), + PHY_SETTING( 800000, FULL, 800000baseCR4_Full ), + PHY_SETTING( 800000, FULL, 800000baseKR4_Full ), + PHY_SETTING( 800000, FULL, 800000baseDR4_Full ), + PHY_SETTING( 800000, FULL, 800000baseDR4_2_Full ), + PHY_SETTING( 800000, FULL, 800000baseSR4_Full ), + PHY_SETTING( 800000, FULL, 800000baseVR4_Full ),/* 400G */ PHY_SETTING( 400000, FULL, 400000baseCR8_Full ), PHY_SETTING( 400000, FULL, 400000baseKR8_Full ),
@@ -180,6 +186,12 @@ static const struct phy_setting settings[] = { PHY_SETTING( 400000, FULL, 400000baseLR4_ER4_FR4_Full ), PHY_SETTING( 400000, FULL, 400000baseDR4_Full ), PHY_SETTING( 400000, FULL, 400000baseSR4_Full ), + PHY_SETTING( 400000, FULL, 400000baseCR2_Full ), + PHY_SETTING( 400000, FULL, 400000baseKR2_Full ), + PHY_SETTING( 400000, FULL, 400000baseDR2_Full ), + PHY_SETTING( 400000, FULL, 400000baseDR2_2_Full ), + PHY_SETTING( 400000, FULL, 400000baseSR2_Full ), + PHY_SETTING( 400000, FULL, 400000baseVR2_Full ),/* 200G */ PHY_SETTING( 200000, FULL, 200000baseCR4_Full ), PHY_SETTING( 200000, FULL, 200000baseKR4_Full ),
@@ -191,6 +203,12 @@ static const struct phy_setting settings[] = { PHY_SETTING( 200000, FULL, 200000baseLR2_ER2_FR2_Full ), PHY_SETTING( 200000, FULL, 200000baseDR2_Full ), PHY_SETTING( 200000, FULL, 200000baseSR2_Full ), + PHY_SETTING( 200000, FULL, 200000baseCR_Full ), + PHY_SETTING( 200000, FULL, 200000baseKR_Full ), + PHY_SETTING( 200000, FULL, 200000baseDR_Full ), + PHY_SETTING( 200000, FULL, 200000baseDR_2_Full ), + PHY_SETTING( 200000, FULL, 200000baseSR_Full ), + PHY_SETTING( 200000, FULL, 200000baseVR_Full ),/* 100G */ PHY_SETTING( 100000, FULL, 100000baseCR4_Full ), PHY_SETTING( 100000, FULL, 100000baseKR4_Full ),
include/uapi/linux/ethtool.h +18 -0
@@ -2057,6 +2057,24 @@ enum ethtool_link_mode_bit_indices { ETHTOOL_LINK_MODE_10baseT1S_Half_BIT =100 , ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT =101 , ETHTOOL_LINK_MODE_10baseT1BRR_Full_BIT =102 , + ETHTOOL_LINK_MODE_200000baseCR_Full_BIT =103 , + ETHTOOL_LINK_MODE_200000baseKR_Full_BIT =104 , + ETHTOOL_LINK_MODE_200000baseDR_Full_BIT =105 , + ETHTOOL_LINK_MODE_200000baseDR_2_Full_BIT =106 , + ETHTOOL_LINK_MODE_200000baseSR_Full_BIT =107 , + ETHTOOL_LINK_MODE_200000baseVR_Full_BIT =108 , + ETHTOOL_LINK_MODE_400000baseCR2_Full_BIT =109 , + ETHTOOL_LINK_MODE_400000baseKR2_Full_BIT =110 , + ETHTOOL_LINK_MODE_400000baseDR2_Full_BIT =111 , + ETHTOOL_LINK_MODE_400000baseDR2_2_Full_BIT =112 , + ETHTOOL_LINK_MODE_400000baseSR2_Full_BIT =113 , + ETHTOOL_LINK_MODE_400000baseVR2_Full_BIT =114 , + ETHTOOL_LINK_MODE_800000baseCR4_Full_BIT =115 , + ETHTOOL_LINK_MODE_800000baseKR4_Full_BIT =116 , + ETHTOOL_LINK_MODE_800000baseDR4_Full_BIT =117 , + ETHTOOL_LINK_MODE_800000baseDR4_2_Full_BIT =118 , + ETHTOOL_LINK_MODE_800000baseSR4_Full_BIT =119 , + ETHTOOL_LINK_MODE_800000baseVR4_Full_BIT =120 ,/* must be last entry */ __ETHTOOL_LINK_MODE_MASK_NBITS
net/ethtool/common.c +42 -0
68 lines not on this page · raw message
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 11/15 net/mlx5: Add support for 200Gbps per lane link modes
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
This patch exposes new link modes using 200Gbps per lane, including 200G, 400G and 800G modes.
--- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 21 +++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/port.c | 3 +++ include/linux/mlx5/port.h | 3 +++ 3 files changed, 27 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +21 -0
@@ -237,6 +237,27 @@ void mlx5e_build_ptys2ethtool_map(void) ETHTOOL_LINK_MODE_800000baseDR8_2_Full_BIT, ETHTOOL_LINK_MODE_800000baseSR8_Full_BIT, ETHTOOL_LINK_MODE_800000baseVR8_Full_BIT); +MLX5_BUILD_PTYS2ETHTOOL_CONFIG (MLX5E_200GAUI_1_200GBASE_CR1_KR1 , ext, + ETHTOOL_LINK_MODE_200000baseCR_Full_BIT, + ETHTOOL_LINK_MODE_200000baseKR_Full_BIT, + ETHTOOL_LINK_MODE_200000baseDR_Full_BIT, + ETHTOOL_LINK_MODE_200000baseDR_2_Full_BIT, + ETHTOOL_LINK_MODE_200000baseSR_Full_BIT, + ETHTOOL_LINK_MODE_200000baseVR_Full_BIT); +MLX5_BUILD_PTYS2ETHTOOL_CONFIG (MLX5E_400GAUI_2_400GBASE_CR2_KR2 , ext, + ETHTOOL_LINK_MODE_400000baseCR2_Full_BIT, + ETHTOOL_LINK_MODE_400000baseKR2_Full_BIT, + ETHTOOL_LINK_MODE_400000baseDR2_Full_BIT, + ETHTOOL_LINK_MODE_400000baseDR2_2_Full_BIT, + ETHTOOL_LINK_MODE_400000baseSR2_Full_BIT, + ETHTOOL_LINK_MODE_400000baseVR2_Full_BIT); +MLX5_BUILD_PTYS2ETHTOOL_CONFIG (MLX5E_800GAUI_4_800GBASE_CR4_KR4 , ext, + ETHTOOL_LINK_MODE_800000baseCR4_Full_BIT, + ETHTOOL_LINK_MODE_800000baseKR4_Full_BIT, + ETHTOOL_LINK_MODE_800000baseDR4_Full_BIT, + ETHTOOL_LINK_MODE_800000baseDR4_2_Full_BIT, + ETHTOOL_LINK_MODE_800000baseSR4_Full_BIT, + ETHTOOL_LINK_MODE_800000baseVR4_Full_BIT); } static void mlx5e_ethtool_get_speed_arr(struct mlx5_core_dev *mdev,
drivers/net/ethernet/mellanox/mlx5/core/port.c +3 -0
@@ -1105,6 +1105,9 @@ static const u32 mlx5e_ext_link_speed[MLX5E_EXT_LINK_MODES_NUMBER] = { [MLX5E_200GAUI_2_200GBASE_CR2_KR2] = 200000, [MLX5E_400GAUI_4_400GBASE_CR4_KR4] = 400000, [MLX5E_800GAUI_8_800GBASE_CR8_KR8] = 800000, + [MLX5E_200GAUI_1_200GBASE_CR1_KR1] = 200000, + [MLX5E_400GAUI_2_400GBASE_CR2_KR2] = 400000, + [MLX5E_800GAUI_4_800GBASE_CR4_KR4] = 800000, }; int mlx5_port_query_eth_proto(struct mlx5_core_dev *dev, u8 port, bool ext,
include/linux/mlx5/port.h +3 -0
@@ -115,9 +115,12 @@ enum mlx5e_ext_link_mode {MLX5E_100GAUI_1_100GBASE_CR_KR =11 ,MLX5E_200GAUI_4_200GBASE_CR4_KR4 =12 ,MLX5E_200GAUI_2_200GBASE_CR2_KR2 =13 , +MLX5E_200GAUI_1_200GBASE_CR1_KR1 =14 ,MLX5E_400GAUI_8_400GBASE_CR8 =15 ,MLX5E_400GAUI_4_400GBASE_CR4_KR4 =16 , +MLX5E_400GAUI_2_400GBASE_CR2_KR2 =17 ,MLX5E_800GAUI_8_800GBASE_CR8_KR8 =19 , +MLX5E_800GAUI_4_800GBASE_CR4_KR4 =20 , MLX5E_EXT_LINK_MODES_NUMBER, };
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 12/15 net/mlx5e: Support FEC settings for 200G per lane link modes
In reply to Tariq ToukanFrom: Jianbo Liu <[email protected]>
Add support to show and config FEC by ethtool for 200G/lane link modes. The RS encoding setting is mapped, and can be overridden to FEC_RS_544_514_INTERLEAVED_QUAD for these modes.
--- .../net/ethernet/mellanox/mlx5/core/en/port.c | 64 ++++++++++++++++--- .../net/ethernet/mellanox/mlx5/core/en/port.h | 1 + .../ethernet/mellanox/mlx5/core/en_ethtool.c | 1 + 3 files changed, 56 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/port.c +54 -10
@@ -296,11 +296,16 @@ enum mlx5e_fec_supported_link_mode {MLX5E_FEC_SUPPORTED_LINK_MODE_200G_2X ,MLX5E_FEC_SUPPORTED_LINK_MODE_400G_4X ,MLX5E_FEC_SUPPORTED_LINK_MODE_800G_8X , +MLX5E_FEC_SUPPORTED_LINK_MODE_200G_1X , +MLX5E_FEC_SUPPORTED_LINK_MODE_400G_2X , +MLX5E_FEC_SUPPORTED_LINK_MODE_800G_4X , +MLX5E_FEC_SUPPORTED_LINK_MODE_1600G_8X , MLX5E_MAX_FEC_SUPPORTED_LINK_MODE, };#define MLX5E_FEC_FIRST_50G_PER_LANE_MODE MLX5E_FEC_SUPPORTED_LINK_MODE_50G_1X#define MLX5E_FEC_FIRST_100G_PER_LANE_MODE MLX5E_FEC_SUPPORTED_LINK_MODE_100G_1X +#define MLX5E_FEC_FIRST_200G_PER_LANE_MODE MLX5E_FEC_SUPPORTED_LINK_MODE_200G_1X#define MLX5E_FEC_OVERRIDE_ADMIN_POLICY (buf, policy, write, link) \ do { \
@@ -320,8 +325,10 @@ static bool mlx5e_is_fec_supported_link_mode(struct mlx5_core_dev *dev,return link_mode <MLX5E_FEC_FIRST_50G_PER_LANE_MODE || (link_mode <MLX5E_FEC_FIRST_100G_PER_LANE_MODE &&MLX5_CAP_PCAM_FEATURE (dev, fec_50G_per_lane_in_pplm)) || - (link_mode >=MLX5E_FEC_FIRST_100G_PER_LANE_MODE && -MLX5_CAP_PCAM_FEATURE (dev, fec_100G_per_lane_in_pplm)); + (link_mode <MLX5E_FEC_FIRST_200G_PER_LANE_MODE && +MLX5_CAP_PCAM_FEATURE (dev, fec_100G_per_lane_in_pplm)) || + (link_mode >=MLX5E_FEC_FIRST_200G_PER_LANE_MODE && +MLX5_CAP_PCAM_FEATURE (dev, fec_200G_per_lane_in_pplm)); }/* get/set FEC admin field for a given speed */
@@ -368,6 +375,18 @@ static int mlx5e_fec_admin_field(u32 *pplm, u16 *fec_policy, bool write,case MLX5E_FEC_SUPPORTED_LINK_MODE_800G_8X : MLX5E_FEC_OVERRIDE_ADMIN_POLICY(pplm, *fec_policy, write, 800g_8x);break ; +case MLX5E_FEC_SUPPORTED_LINK_MODE_200G_1X : + MLX5E_FEC_OVERRIDE_ADMIN_POLICY(pplm, *fec_policy, write, 200g_1x); +break ; +case MLX5E_FEC_SUPPORTED_LINK_MODE_400G_2X : + MLX5E_FEC_OVERRIDE_ADMIN_POLICY(pplm, *fec_policy, write, 400g_2x); +break ; +case MLX5E_FEC_SUPPORTED_LINK_MODE_800G_4X : + MLX5E_FEC_OVERRIDE_ADMIN_POLICY(pplm, *fec_policy, write, 800g_4x); +break ; +case MLX5E_FEC_SUPPORTED_LINK_MODE_1600G_8X : + MLX5E_FEC_OVERRIDE_ADMIN_POLICY(pplm, *fec_policy, write, 1600g_8x); +break ;default :return -EINVAL ; }
@@ -421,6 +440,18 @@ static int mlx5e_get_fec_cap_field(u32 *pplm, u16 *fec_cap,case MLX5E_FEC_SUPPORTED_LINK_MODE_800G_8X : *fec_cap = MLX5E_GET_FEC_OVERRIDE_CAP(pplm, 800g_8x);break ; +case MLX5E_FEC_SUPPORTED_LINK_MODE_200G_1X : + *fec_cap = MLX5E_GET_FEC_OVERRIDE_CAP(pplm, 200g_1x); +break ; +case MLX5E_FEC_SUPPORTED_LINK_MODE_400G_2X : + *fec_cap = MLX5E_GET_FEC_OVERRIDE_CAP(pplm, 400g_2x); +break ; +case MLX5E_FEC_SUPPORTED_LINK_MODE_800G_4X : + *fec_cap = MLX5E_GET_FEC_OVERRIDE_CAP(pplm, 800g_4x); +break ; +case MLX5E_FEC_SUPPORTED_LINK_MODE_1600G_8X : + *fec_cap = MLX5E_GET_FEC_OVERRIDE_CAP(pplm, 1600g_8x); +break ;default :return -EINVAL ; }
@@ -494,6 +525,26 @@ int mlx5e_get_fec_mode(struct mlx5_core_dev *dev, u32 *fec_mode_active,return 0 ; } +static u16 mlx5e_remap_fec_conf_mode (enum mlx5e_fec_supported_link_mode link_mode, +u16 conf_fec) +{ +/* RS fec in ethtool is originally mapped to MLX5E_FEC_RS_528_514. +* For link modes up to 25G per lane, the value is kept. +* For 50G or 100G per lane, it's remapped to MLX5E_FEC_RS_544_514. +* For 200G per lane, remapped to MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD. +*/ +if (conf_fec !=BIT (MLX5E_FEC_RS_528_514 )) +return conf_fec; + +if (link_mode >=MLX5E_FEC_FIRST_200G_PER_LANE_MODE ) +return BIT (MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD ); + +if (link_mode >=MLX5E_FEC_FIRST_50G_PER_LANE_MODE ) +return BIT (MLX5E_FEC_RS_544_514 ); + +return conf_fec; +} +int mlx5e_set_fec_mode (struct mlx5_core_dev *dev,u16 fec_policy) {bool fec_50g_per_lane =MLX5_CAP_PCAM_FEATURE (dev, fec_50G_per_lane_in_pplm);
@@ -530,14 +581,7 @@ int mlx5e_set_fec_mode(struct mlx5_core_dev *dev, u16 fec_policy)if (!mlx5e_is_fec_supported_link_mode (dev, i))break ; -/* RS fec in ethtool is mapped to MLX5E_FEC_RS_528_514 -* to link modes up to 25G per lane and to -* MLX5E_FEC_RS_544_514 in the new link modes based on -* 50G or 100G per lane -*/ -if (conf_fec == (1 <<MLX5E_FEC_RS_528_514 ) && - i >=MLX5E_FEC_FIRST_50G_PER_LANE_MODE ) - conf_fec = (1 <<MLX5E_FEC_RS_544_514 ); + conf_fec =mlx5e_remap_fec_conf_mode (i, conf_fec);mlx5e_get_fec_cap_field (out, &fec_caps, i);
drivers/net/ethernet/mellanox/mlx5/core/en/port.h +1 -0
@@ -61,6 +61,7 @@ enum {MLX5E_FEC_NOFEC ,MLX5E_FEC_FIRECODE ,MLX5E_FEC_RS_528_514 , +MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD =4 ,MLX5E_FEC_RS_544_514 =7 , MLX5E_FEC_LLRS_272_257_1 = 9, };
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +1 -0
@@ -952,6 +952,7 @@ static const u32 pplm_fec_2_ethtool[] = { [MLX5E_FEC_RS_528_514] = ETHTOOL_FEC_RS, [MLX5E_FEC_RS_544_514] = ETHTOOL_FEC_RS, [MLX5E_FEC_LLRS_272_257_1] = ETHTOOL_FEC_LLRS, + [MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD] = ETHTOOL_FEC_RS, };static u32 pplm2ethtool_fec (u_long fec_mode,unsigned long size)
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 13/15 net/mlx5: Remove stray semicolon in LAG port selection table creation
In reply to Tariq ToukanFrom: Gal Pressman <[email protected]>
Remove the stray semicolon in the mlx5_ldev_for_each_reverse() loop.
--- drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c +1 -1
@@ -97,7 +97,7 @@ static int mlx5_lag_create_port_sel_table(struct mlx5_lag *ldev,mlx5_del_flow_rules (lag_definer->rules[idx]); } j = ldev->buckets; - }; + } goto destroy_fg; } }
Signature · 1 line
2.45.0
Re: [PATCH net-next 13/15] net/mlx5: Remove stray semicolon in LAG port selection table creation
Quoted 7 lines · Tariq Toukan
From: Gal Pressman <[email protected]>
Remove the stray semicolon in the
mlx5_ldev_for_each_reverse()loop.Signed-off-by Gal Pressman <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
LGTM,
Signature · 2 lines
Regards, Kalesh AP
Tariq Toukan
maintainerPATCH 14/15 net/mlx5e: Remove unused mlx5e_tc_flow_action struct
In reply to Tariq ToukanFrom: Gal Pressman <[email protected]>
Commit 67efaf45930d ("net/mlx5e: TC, Remove CT action reordering") removed the usage of mlx5e_tc_flow_action struct, remove the struct as well.
--- drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/act.h | 5 ----- 1 file changed, 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/act.h +0 -5
@@ -73,11 +73,6 @@ struct mlx5e_tc_act {bool is_terminating_action; }; -struct mlx5e_tc_flow_action { -unsigned int num_entries; -struct flow_action_entry **entries; -}; -extern struct mlx5e_tc_act mlx5e_tc_act_drop;extern struct mlx5e_tc_act mlx5e_tc_act_trap;extern struct mlx5e_tc_act mlx5e_tc_act_accept;
Signature · 1 line
2.45.0
Re: [PATCH net-next 14/15] net/mlx5e: Remove unused mlx5e_tc_flow_action struct
Quoted 10 lines · Tariq Toukan
From: Gal Pressman <[email protected]>
Commit
67efaf45930d("net/mlx5e: TC, Remove CT action reordering") removed the usage ofmlx5e_tc_flow_actionstruct, remove the struct as well.Signed-off-by Gal Pressman <[email protected]>Reviewed-by Cosmin Ratiu <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
LGTM,
Signature · 2 lines
Regards, Kalesh AP
Tariq Toukan
maintainerPATCH 15/15 net/mlx5e: Avoid WARN_ON when configuring MQPRIO with HTB offload enabled
In reply to Tariq ToukanFrom: Carolina Jubran <[email protected]>
When attempting to enable MQPRIO while HTB offload is already configured, the driver currently returns -EINVAL and triggers a WARN_ON, leading to an unnecessary call trace.
Update the code to handle this case more gracefully by returning -EOPNOTSUPP instead, while also providing a helpful user message.
--- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +5 -2
@@ -3816,8 +3816,11 @@ static int mlx5e_setup_tc_mqprio(struct mlx5e_priv *priv,/* MQPRIO is another toplevel qdisc that can't be attached * simultaneously with the offloaded HTB. */ -if (WARN_ON (mlx5e_selq_is_htb_enabled (&priv->selq))) -return -EINVAL ; +if (mlx5e_selq_is_htb_enabled (&priv->selq)) { +NL_SET_ERR_MSG_MOD (mqprio->extack, +"MQPRIO cannot be configured when HTB offload is enabled." ); +return -EOPNOTSUPP ; + }switch (mqprio->mode) {case TC_MQPRIO_MODE_DCB :
Signature · 1 line
2.45.0
Re: [PATCH net-next 15/15] net/mlx5e: Avoid WARN_ON when configuring MQPRIO with HTB offload enabled
Quoted 7 lines · Tariq Toukan
From: Carolina Jubran <[email protected]>
When attempting to enable MQPRIO while HTB offload is already configured, the driver currently returns
-EINVALand triggers aWARN_ON, leading to an unnecessary call trace.
Quoted 7 lines
Update the code to handle this case more gracefully by returning
-EOPNOTSUPPinstead, while also providing a helpful user message.Signed-off-by Carolina Jubran <[email protected]>Reviewed-by Yael Chemla <[email protected]>Reviewed-by Cosmin Ratiu <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
LGTM,
Signature · 2 lines
Regards, Kalesh AP
Quoted 8 lines · Tariq Toukan
Hi,
This series contains two features from Jianbo, followed by simple cleanups.
Patches 1-9 by Jianbo add support for one PTP device per hardware clock, described below [1].
Quoted 8 lines
Patches 10-12 by Jianbo add support for 200Gbps per-lane link modes in kernel and mlx5 driver.
Patches 13-15 are simple cleanups by Gal and Carolina.
Regards,
Tariq
Hi,
The series state is marked "Needs ACK" in patchwork. Which ACK is needed here? From who?
Thanks,
Tariq
Paolo Abeni
maintainerQuoted 14 lines · Tariq Toukan
Quoted 13 lines · Tariq Toukan
Hi,
This series contains two features from Jianbo, followed by simple cleanups.
Patches 1-9 by Jianbo add support for one PTP device per hardware clock, described below [1].
Patches 10-12 by Jianbo add support for 200Gbps per-lane link modes in kernel and mlx5 driver.
Patches 13-15 are simple cleanups by Gal and Carolina.
Quoted 8 lines
Quoted 3 lines
Regards,
TariqHi,
The series state is marked "Needs ACK" in patchwork. Which ACK is needed here? From who?
I *guess* Dave was waiting for some explicit ack on the ethtool bits.
I went over the series: LGTM and the ethtool part looks uncontroversial. I'll apply it soon.
/P
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Mon, 3 Feb 2025 23:35:01 +0200 you wrote:
Hi,
This series contains two features from Jianbo, followed by simple cleanups.
Patches 1-9 by Jianbo add support for one PTP device per hardware clock, described below [1].
[...]
Here is the summary with links:
- [net-next,01/15] net/mlx5: Add helper functions for PTP callbacks
https://git.kernel.org/netdev/net-next/c/e3ad54f5bdb9 - [net-next,02/15] net/mlx5: Change parameters for PTP internal functions https://git.kernel.org/netdev/net-next/c/9f722fb10521 - [net-next,03/15] net/mlx5: Add init and destruction functions for a single HW clock https://git.kernel.org/netdev/net-next/c/ccb717a88b2e - [net-next,04/15] net/mlx5: Add API to get mlx5_core_dev from mlx5_clock https://git.kernel.org/netdev/net-next/c/355f58f10911 - [net-next,05/15] net/mlx5: Change clock in mlx5_core_dev to mlx5_clock pointer https://git.kernel.org/netdev/net-next/c/f9beaf4fac64 - [net-next,06/15] net/mlx5: Add devcom component for the clock shared by functions https://git.kernel.org/netdev/net-next/c/574998cf3b3f - [net-next,07/15] net/mlx5: Move PPS notifier and out_work to clock_state https://git.kernel.org/netdev/net-next/c/79faf9d76d66 - [net-next,08/15] net/mlx5: Support one PTP device per hardware clock https://git.kernel.org/netdev/net-next/c/f538ffb7a22d - [net-next,09/15] net/mlx5: Generate PPS IN event on new function for shared clock https://git.kernel.org/netdev/net-next/c/39c1202fa942 - [net-next,10/15] ethtool: Add support for 200Gbps per lane link modes https://git.kernel.org/netdev/net-next/c/4897f9b7f8bd - [net-next,11/15] net/mlx5: Add support for 200Gbps per lane link modes https://git.kernel.org/netdev/net-next/c/ee0a4fc396f1 - [net-next,12/15] net/mlx5e: Support FEC settings for 200G per lane link modes https://git.kernel.org/netdev/net-next/c/4e343c11efbb - [net-next,13/15] net/mlx5: Remove stray semicolon in LAG port selection table creation https://git.kernel.org/netdev/net-next/c/6fa15a20b7c3 - [net-next,14/15] net/mlx5e: Remove unused mlx5e_tc_flow_action struct https://git.kernel.org/netdev/net-next/c/96d64a1ab795 - [net-next,15/15] net/mlx5e: Avoid WARN_ON when configuring MQPRIO with HTB offload enabled https://git.kernel.org/netdev/net-next/c/689805dcc474
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html