18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright (c) 2019 Mellanox Technologies. All rights reserved */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef _MLXSW_SPECTRUM_PTP_H
58c2ecf20Sopenharmony_ci#define _MLXSW_SPECTRUM_PTP_H
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/device.h>
88c2ecf20Sopenharmony_ci#include <linux/rhashtable.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_cistruct mlxsw_sp;
118c2ecf20Sopenharmony_cistruct mlxsw_sp_port;
128c2ecf20Sopenharmony_cistruct mlxsw_sp_ptp_clock;
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cienum {
158c2ecf20Sopenharmony_ci	MLXSW_SP_PTP_MESSAGE_TYPE_SYNC,
168c2ecf20Sopenharmony_ci	MLXSW_SP_PTP_MESSAGE_TYPE_DELAY_REQ,
178c2ecf20Sopenharmony_ci	MLXSW_SP_PTP_MESSAGE_TYPE_PDELAY_REQ,
188c2ecf20Sopenharmony_ci	MLXSW_SP_PTP_MESSAGE_TYPE_PDELAY_RESP,
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic inline int mlxsw_sp_ptp_get_ts_info_noptp(struct ethtool_ts_info *info)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
248c2ecf20Sopenharmony_ci				SOF_TIMESTAMPING_SOFTWARE;
258c2ecf20Sopenharmony_ci	info->phc_index = -1;
268c2ecf20Sopenharmony_ci	return 0;
278c2ecf20Sopenharmony_ci}
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistruct mlxsw_sp_ptp_clock *
328c2ecf20Sopenharmony_cimlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_civoid mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistruct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp);
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_civoid mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_civoid mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
418c2ecf20Sopenharmony_ci			   u8 local_port);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_civoid mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
448c2ecf20Sopenharmony_ci			       struct sk_buff *skb, u8 local_port);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_civoid mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
478c2ecf20Sopenharmony_ci				 u8 local_port, u8 message_type,
488c2ecf20Sopenharmony_ci				 u8 domain_number, u16 sequence_id,
498c2ecf20Sopenharmony_ci				 u64 timestamp);
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciint mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
528c2ecf20Sopenharmony_ci			       struct hwtstamp_config *config);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ciint mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
558c2ecf20Sopenharmony_ci			       struct hwtstamp_config *config);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_civoid mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciint mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
608c2ecf20Sopenharmony_ci			      struct ethtool_ts_info *info);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciint mlxsw_sp1_get_stats_count(void);
638c2ecf20Sopenharmony_civoid mlxsw_sp1_get_stats_strings(u8 **p);
648c2ecf20Sopenharmony_civoid mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
658c2ecf20Sopenharmony_ci			 u64 *data, int data_index);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#else
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic inline struct mlxsw_sp_ptp_clock *
708c2ecf20Sopenharmony_cimlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	return NULL;
738c2ecf20Sopenharmony_ci}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistatic inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic inline struct mlxsw_sp_ptp_state *
808c2ecf20Sopenharmony_cimlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	return NULL;
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci}
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp,
908c2ecf20Sopenharmony_ci					 struct sk_buff *skb, u8 local_port)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci	mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
938c2ecf20Sopenharmony_ci}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistatic inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
968c2ecf20Sopenharmony_ci					     struct sk_buff *skb, u8 local_port)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	dev_kfree_skb_any(skb);
998c2ecf20Sopenharmony_ci}
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_cistatic inline void
1028c2ecf20Sopenharmony_cimlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
1038c2ecf20Sopenharmony_ci			    u8 local_port, u8 message_type,
1048c2ecf20Sopenharmony_ci			    u8 domain_number,
1058c2ecf20Sopenharmony_ci			    u16 sequence_id, u64 timestamp)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistatic inline int
1108c2ecf20Sopenharmony_cimlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
1118c2ecf20Sopenharmony_ci			   struct hwtstamp_config *config)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic inline int
1178c2ecf20Sopenharmony_cimlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
1188c2ecf20Sopenharmony_ci			   struct hwtstamp_config *config)
1198c2ecf20Sopenharmony_ci{
1208c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic inline int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
1288c2ecf20Sopenharmony_ci					    struct ethtool_ts_info *info)
1298c2ecf20Sopenharmony_ci{
1308c2ecf20Sopenharmony_ci	return mlxsw_sp_ptp_get_ts_info_noptp(info);
1318c2ecf20Sopenharmony_ci}
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistatic inline int mlxsw_sp1_get_stats_count(void)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci	return 0;
1368c2ecf20Sopenharmony_ci}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic inline void mlxsw_sp1_get_stats_strings(u8 **p)
1398c2ecf20Sopenharmony_ci{
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistatic inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
1438c2ecf20Sopenharmony_ci				       u64 *data, int data_index)
1448c2ecf20Sopenharmony_ci{
1458c2ecf20Sopenharmony_ci}
1468c2ecf20Sopenharmony_ci#endif
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic inline struct mlxsw_sp_ptp_clock *
1498c2ecf20Sopenharmony_cimlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	return NULL;
1528c2ecf20Sopenharmony_ci}
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistatic inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
1558c2ecf20Sopenharmony_ci{
1568c2ecf20Sopenharmony_ci}
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistatic inline struct mlxsw_sp_ptp_state *
1598c2ecf20Sopenharmony_cimlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
1608c2ecf20Sopenharmony_ci{
1618c2ecf20Sopenharmony_ci	return NULL;
1628c2ecf20Sopenharmony_ci}
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cistatic inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
1658c2ecf20Sopenharmony_ci{
1668c2ecf20Sopenharmony_ci}
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_cistatic inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
1698c2ecf20Sopenharmony_ci					 struct sk_buff *skb, u8 local_port)
1708c2ecf20Sopenharmony_ci{
1718c2ecf20Sopenharmony_ci	mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
1728c2ecf20Sopenharmony_ci}
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_cistatic inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
1758c2ecf20Sopenharmony_ci					     struct sk_buff *skb, u8 local_port)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	dev_kfree_skb_any(skb);
1788c2ecf20Sopenharmony_ci}
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic inline int
1818c2ecf20Sopenharmony_cimlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
1828c2ecf20Sopenharmony_ci			   struct hwtstamp_config *config)
1838c2ecf20Sopenharmony_ci{
1848c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
1858c2ecf20Sopenharmony_ci}
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic inline int
1888c2ecf20Sopenharmony_cimlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
1898c2ecf20Sopenharmony_ci			   struct hwtstamp_config *config)
1908c2ecf20Sopenharmony_ci{
1918c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
1928c2ecf20Sopenharmony_ci}
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cistatic inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
1958c2ecf20Sopenharmony_ci{
1968c2ecf20Sopenharmony_ci}
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_cistatic inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
1998c2ecf20Sopenharmony_ci					    struct ethtool_ts_info *info)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	return mlxsw_sp_ptp_get_ts_info_noptp(info);
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_cistatic inline int mlxsw_sp2_get_stats_count(void)
2058c2ecf20Sopenharmony_ci{
2068c2ecf20Sopenharmony_ci	return 0;
2078c2ecf20Sopenharmony_ci}
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistatic inline void mlxsw_sp2_get_stats_strings(u8 **p)
2108c2ecf20Sopenharmony_ci{
2118c2ecf20Sopenharmony_ci}
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_cistatic inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
2148c2ecf20Sopenharmony_ci				       u64 *data, int data_index)
2158c2ecf20Sopenharmony_ci{
2168c2ecf20Sopenharmony_ci}
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci#endif
219