Skip to content

Commit d92e4e6

Browse files
pmachatadavem330
authored andcommitted
mlxsw: spectrum: PTP: Support timestamping on Spectrum-1
On Spectrum-1, timestamps arrive through a pair of dedicated events: MLXSW_TRAP_ID_PTP_ING_FIFO and _EGR_FIFO. The payload delivered with those traps is contents of the timestamp FIFO at a given port in a given direction. Add a Spectrum-1-specific handler for these two events which decodes the timestamps and forwards them to the PTP module. Add a function that parses a packet, dispatching to ptp_classify_raw(), and decodes PTP message type, domain number, and sequence ID. Add a new mlxsw dependency on the PTP classifier. Add helpers that can store and retrieve unmatched timestamps and SKBs to the hash table added in a preceding patch. Add the matching code itself: upon arrival of a timestamp or a packet, look up the corresponding unmatched entry, and match it up. If there is none, add a new unmatched entry. This logic is the same on ingress as on egress. Packets and timestamps that never matched need to be eventually disposed of. A garbage collector added in a follow-up patch will take care of that. Since currently all this code is turned off, no crud will accumulate in the hash table. Signed-off-by: Petr Machata <[email protected]> Acked-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 89e602e commit d92e4e6

File tree

6 files changed

+388
-2
lines changed

6 files changed

+388
-2
lines changed

drivers/net/ethernet/mellanox/mlxsw/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ config MLXSW_SPECTRUM
8484
select OBJAGG
8585
select MLXFW
8686
imply PTP_1588_CLOCK
87+
select NET_PTP_CLASSIFY if PTP_1588_CLOCK
8788
default m
8889
---help---
8990
This driver supports Mellanox Technologies Spectrum Ethernet

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3970,6 +3970,46 @@ static void mlxsw_sp_pude_event_func(const struct mlxsw_reg_info *reg,
39703970
}
39713971
}
39723972

3973+
static void mlxsw_sp1_ptp_fifo_event_func(struct mlxsw_sp *mlxsw_sp,
3974+
char *mtpptr_pl, bool ingress)
3975+
{
3976+
u8 local_port;
3977+
u8 num_rec;
3978+
int i;
3979+
3980+
local_port = mlxsw_reg_mtpptr_local_port_get(mtpptr_pl);
3981+
num_rec = mlxsw_reg_mtpptr_num_rec_get(mtpptr_pl);
3982+
for (i = 0; i < num_rec; i++) {
3983+
u8 domain_number;
3984+
u8 message_type;
3985+
u16 sequence_id;
3986+
u64 timestamp;
3987+
3988+
mlxsw_reg_mtpptr_unpack(mtpptr_pl, i, &message_type,
3989+
&domain_number, &sequence_id,
3990+
&timestamp);
3991+
mlxsw_sp1_ptp_got_timestamp(mlxsw_sp, ingress, local_port,
3992+
message_type, domain_number,
3993+
sequence_id, timestamp);
3994+
}
3995+
}
3996+
3997+
static void mlxsw_sp1_ptp_ing_fifo_event_func(const struct mlxsw_reg_info *reg,
3998+
char *mtpptr_pl, void *priv)
3999+
{
4000+
struct mlxsw_sp *mlxsw_sp = priv;
4001+
4002+
mlxsw_sp1_ptp_fifo_event_func(mlxsw_sp, mtpptr_pl, true);
4003+
}
4004+
4005+
static void mlxsw_sp1_ptp_egr_fifo_event_func(const struct mlxsw_reg_info *reg,
4006+
char *mtpptr_pl, void *priv)
4007+
{
4008+
struct mlxsw_sp *mlxsw_sp = priv;
4009+
4010+
mlxsw_sp1_ptp_fifo_event_func(mlxsw_sp, mtpptr_pl, false);
4011+
}
4012+
39734013
void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
39744014
u8 local_port, void *priv)
39754015
{
@@ -4151,6 +4191,9 @@ static const struct mlxsw_listener mlxsw_sp_listener[] = {
41514191
};
41524192

41534193
static const struct mlxsw_listener mlxsw_sp1_listener[] = {
4194+
/* Events */
4195+
MLXSW_EVENTL(mlxsw_sp1_ptp_egr_fifo_event_func, PTP_EGR_FIFO, SP_PTP0),
4196+
MLXSW_EVENTL(mlxsw_sp1_ptp_ing_fifo_event_func, PTP_ING_FIFO, SP_PTP0),
41544197
};
41554198

41564199
static int mlxsw_sp_cpu_policers_set(struct mlxsw_core *mlxsw_core)

drivers/net/ethernet/mellanox/mlxsw/spectrum.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ struct mlxsw_sp_port {
266266
unsigned acl_rule_count;
267267
struct mlxsw_sp_acl_block *ing_acl_block;
268268
struct mlxsw_sp_acl_block *eg_acl_block;
269+
struct {
270+
struct hwtstamp_config hwtstamp_config;
271+
u16 ing_types;
272+
u16 egr_types;
273+
} ptp;
269274
};
270275

271276
struct mlxsw_sp_port_type_speed_ops {

0 commit comments

Comments
 (0)