162306a36Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright (c) 2019 Mellanox Technologies. All rights reserved */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#ifndef _MLXSW_SPECTRUM_PTP_H
562306a36Sopenharmony_ci#define _MLXSW_SPECTRUM_PTP_H
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#include <linux/device.h>
862306a36Sopenharmony_ci#include <linux/rhashtable.h>
962306a36Sopenharmony_ci
1062306a36Sopenharmony_cistruct mlxsw_sp;
1162306a36Sopenharmony_cistruct mlxsw_sp_port;
1262306a36Sopenharmony_cistruct mlxsw_sp_ptp_clock;
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cistatic inline int mlxsw_sp_ptp_get_ts_info_noptp(struct ethtool_ts_info *info)
1562306a36Sopenharmony_ci{
1662306a36Sopenharmony_ci	info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
1762306a36Sopenharmony_ci				SOF_TIMESTAMPING_SOFTWARE;
1862306a36Sopenharmony_ci	info->phc_index = -1;
1962306a36Sopenharmony_ci	return 0;
2062306a36Sopenharmony_ci}
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_cistruct mlxsw_sp_ptp_clock *
2562306a36Sopenharmony_cimlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_civoid mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cistruct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp);
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_civoid mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_civoid mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
3462306a36Sopenharmony_ci			   u16 local_port);
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_civoid mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
3762306a36Sopenharmony_ci			       struct sk_buff *skb, u16 local_port);
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_civoid mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
4062306a36Sopenharmony_ci				 u16 local_port, u8 message_type,
4162306a36Sopenharmony_ci				 u8 domain_number, u16 sequence_id,
4262306a36Sopenharmony_ci				 u64 timestamp);
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciint mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
4562306a36Sopenharmony_ci			       struct hwtstamp_config *config);
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ciint mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
4862306a36Sopenharmony_ci			       struct hwtstamp_config *config);
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_civoid mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ciint mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
5362306a36Sopenharmony_ci			      struct ethtool_ts_info *info);
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ciint mlxsw_sp1_get_stats_count(void);
5662306a36Sopenharmony_civoid mlxsw_sp1_get_stats_strings(u8 **p);
5762306a36Sopenharmony_civoid mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
5862306a36Sopenharmony_ci			 u64 *data, int data_index);
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciint mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
6162306a36Sopenharmony_ci				 struct mlxsw_sp_port *mlxsw_sp_port,
6262306a36Sopenharmony_ci				 struct sk_buff *skb,
6362306a36Sopenharmony_ci				 const struct mlxsw_tx_info *tx_info);
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistruct mlxsw_sp_ptp_clock *
6662306a36Sopenharmony_cimlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_civoid mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistruct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp);
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_civoid mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_civoid mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
7562306a36Sopenharmony_ci			   u16 local_port);
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_civoid mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
7862306a36Sopenharmony_ci			       struct sk_buff *skb, u16 local_port);
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ciint mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
8162306a36Sopenharmony_ci			       struct hwtstamp_config *config);
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ciint mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
8462306a36Sopenharmony_ci			       struct hwtstamp_config *config);
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ciint mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
8762306a36Sopenharmony_ci			      struct ethtool_ts_info *info);
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciint mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
9062306a36Sopenharmony_ci				  struct mlxsw_sp_port *mlxsw_sp_port,
9162306a36Sopenharmony_ci				  struct sk_buff *skb,
9262306a36Sopenharmony_ci				  const struct mlxsw_tx_info *tx_info);
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci#else
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_cistatic inline struct mlxsw_sp_ptp_clock *
9762306a36Sopenharmony_cimlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
9862306a36Sopenharmony_ci{
9962306a36Sopenharmony_ci	return NULL;
10062306a36Sopenharmony_ci}
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_cistatic inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
10362306a36Sopenharmony_ci{
10462306a36Sopenharmony_ci}
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_cistatic inline struct mlxsw_sp_ptp_state *
10762306a36Sopenharmony_cimlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
10862306a36Sopenharmony_ci{
10962306a36Sopenharmony_ci	return NULL;
11062306a36Sopenharmony_ci}
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_cistatic inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
11362306a36Sopenharmony_ci{
11462306a36Sopenharmony_ci}
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_cistatic inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp,
11762306a36Sopenharmony_ci					 struct sk_buff *skb, u16 local_port)
11862306a36Sopenharmony_ci{
11962306a36Sopenharmony_ci	mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
12062306a36Sopenharmony_ci}
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_cistatic inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
12362306a36Sopenharmony_ci					     struct sk_buff *skb, u16 local_port)
12462306a36Sopenharmony_ci{
12562306a36Sopenharmony_ci	dev_kfree_skb_any(skb);
12662306a36Sopenharmony_ci}
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_cistatic inline void
12962306a36Sopenharmony_cimlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
13062306a36Sopenharmony_ci			    u16 local_port, u8 message_type,
13162306a36Sopenharmony_ci			    u8 domain_number,
13262306a36Sopenharmony_ci			    u16 sequence_id, u64 timestamp)
13362306a36Sopenharmony_ci{
13462306a36Sopenharmony_ci}
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_cistatic inline int
13762306a36Sopenharmony_cimlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
13862306a36Sopenharmony_ci			   struct hwtstamp_config *config)
13962306a36Sopenharmony_ci{
14062306a36Sopenharmony_ci	return -EOPNOTSUPP;
14162306a36Sopenharmony_ci}
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_cistatic inline int
14462306a36Sopenharmony_cimlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
14562306a36Sopenharmony_ci			   struct hwtstamp_config *config)
14662306a36Sopenharmony_ci{
14762306a36Sopenharmony_ci	return -EOPNOTSUPP;
14862306a36Sopenharmony_ci}
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_cistatic inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
15162306a36Sopenharmony_ci{
15262306a36Sopenharmony_ci}
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_cistatic inline int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
15562306a36Sopenharmony_ci					    struct ethtool_ts_info *info)
15662306a36Sopenharmony_ci{
15762306a36Sopenharmony_ci	return mlxsw_sp_ptp_get_ts_info_noptp(info);
15862306a36Sopenharmony_ci}
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_cistatic inline int mlxsw_sp1_get_stats_count(void)
16162306a36Sopenharmony_ci{
16262306a36Sopenharmony_ci	return 0;
16362306a36Sopenharmony_ci}
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_cistatic inline void mlxsw_sp1_get_stats_strings(u8 **p)
16662306a36Sopenharmony_ci{
16762306a36Sopenharmony_ci}
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_cistatic inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
17062306a36Sopenharmony_ci				       u64 *data, int data_index)
17162306a36Sopenharmony_ci{
17262306a36Sopenharmony_ci}
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_cistatic inline int
17562306a36Sopenharmony_cimlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
17662306a36Sopenharmony_ci			     struct mlxsw_sp_port *mlxsw_sp_port,
17762306a36Sopenharmony_ci			     struct sk_buff *skb,
17862306a36Sopenharmony_ci			     const struct mlxsw_tx_info *tx_info)
17962306a36Sopenharmony_ci{
18062306a36Sopenharmony_ci	return -EOPNOTSUPP;
18162306a36Sopenharmony_ci}
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_cistatic inline struct mlxsw_sp_ptp_clock *
18462306a36Sopenharmony_cimlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
18562306a36Sopenharmony_ci{
18662306a36Sopenharmony_ci	return NULL;
18762306a36Sopenharmony_ci}
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_cistatic inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
19062306a36Sopenharmony_ci{
19162306a36Sopenharmony_ci}
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_cistatic inline struct mlxsw_sp_ptp_state *
19462306a36Sopenharmony_cimlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
19562306a36Sopenharmony_ci{
19662306a36Sopenharmony_ci	return NULL;
19762306a36Sopenharmony_ci}
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_cistatic inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
20062306a36Sopenharmony_ci{
20162306a36Sopenharmony_ci}
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_cistatic inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
20462306a36Sopenharmony_ci					 struct sk_buff *skb, u16 local_port)
20562306a36Sopenharmony_ci{
20662306a36Sopenharmony_ci	mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
20762306a36Sopenharmony_ci}
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_cistatic inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
21062306a36Sopenharmony_ci					     struct sk_buff *skb, u16 local_port)
21162306a36Sopenharmony_ci{
21262306a36Sopenharmony_ci	dev_kfree_skb_any(skb);
21362306a36Sopenharmony_ci}
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_cistatic inline int
21662306a36Sopenharmony_cimlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
21762306a36Sopenharmony_ci			   struct hwtstamp_config *config)
21862306a36Sopenharmony_ci{
21962306a36Sopenharmony_ci	return -EOPNOTSUPP;
22062306a36Sopenharmony_ci}
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_cistatic inline int
22362306a36Sopenharmony_cimlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
22462306a36Sopenharmony_ci			   struct hwtstamp_config *config)
22562306a36Sopenharmony_ci{
22662306a36Sopenharmony_ci	return -EOPNOTSUPP;
22762306a36Sopenharmony_ci}
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_cistatic inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
23062306a36Sopenharmony_ci					    struct ethtool_ts_info *info)
23162306a36Sopenharmony_ci{
23262306a36Sopenharmony_ci	return mlxsw_sp_ptp_get_ts_info_noptp(info);
23362306a36Sopenharmony_ci}
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_cistatic inline int
23662306a36Sopenharmony_cimlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
23762306a36Sopenharmony_ci			      struct mlxsw_sp_port *mlxsw_sp_port,
23862306a36Sopenharmony_ci			      struct sk_buff *skb,
23962306a36Sopenharmony_ci			      const struct mlxsw_tx_info *tx_info)
24062306a36Sopenharmony_ci{
24162306a36Sopenharmony_ci	return -EOPNOTSUPP;
24262306a36Sopenharmony_ci}
24362306a36Sopenharmony_ci#endif
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_cistatic inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
24662306a36Sopenharmony_ci{
24762306a36Sopenharmony_ci}
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_cistatic inline int mlxsw_sp2_get_stats_count(void)
25062306a36Sopenharmony_ci{
25162306a36Sopenharmony_ci	return 0;
25262306a36Sopenharmony_ci}
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_cistatic inline void mlxsw_sp2_get_stats_strings(u8 **p)
25562306a36Sopenharmony_ci{
25662306a36Sopenharmony_ci}
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_cistatic inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
25962306a36Sopenharmony_ci				       u64 *data, int data_index)
26062306a36Sopenharmony_ci{
26162306a36Sopenharmony_ci}
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci#endif
264