18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/* Atlantic Network Driver
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2014-2019 aQuantia Corporation
58c2ecf20Sopenharmony_ci * Copyright (C) 2019-2020 Marvell International Ltd.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/* File aq_ptp.h: Declaration of PTP functions.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci#ifndef AQ_PTP_H
118c2ecf20Sopenharmony_ci#define AQ_PTP_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/net_tstamp.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include "aq_ring.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define PTP_8TC_RING_IDX             8
188c2ecf20Sopenharmony_ci#define PTP_4TC_RING_IDX            16
198c2ecf20Sopenharmony_ci#define PTP_HWST_RING_IDX           31
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* Index must to be 8 (8 TCs) or 16 (4 TCs).
228c2ecf20Sopenharmony_ci * It depends from Traffic Class mode.
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_cistatic inline unsigned int aq_ptp_ring_idx(const enum aq_tc_mode tc_mode)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	if (tc_mode == AQ_TC_MODE_8TCS)
278c2ecf20Sopenharmony_ci		return PTP_8TC_RING_IDX;
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	return PTP_4TC_RING_IDX;
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* Common functions */
358c2ecf20Sopenharmony_ciint aq_ptp_init(struct aq_nic_s *aq_nic, unsigned int idx_vec);
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_civoid aq_ptp_unregister(struct aq_nic_s *aq_nic);
388c2ecf20Sopenharmony_civoid aq_ptp_free(struct aq_nic_s *aq_nic);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciint aq_ptp_irq_alloc(struct aq_nic_s *aq_nic);
418c2ecf20Sopenharmony_civoid aq_ptp_irq_free(struct aq_nic_s *aq_nic);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciint aq_ptp_ring_alloc(struct aq_nic_s *aq_nic);
448c2ecf20Sopenharmony_civoid aq_ptp_ring_free(struct aq_nic_s *aq_nic);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciint aq_ptp_ring_init(struct aq_nic_s *aq_nic);
478c2ecf20Sopenharmony_ciint aq_ptp_ring_start(struct aq_nic_s *aq_nic);
488c2ecf20Sopenharmony_civoid aq_ptp_ring_stop(struct aq_nic_s *aq_nic);
498c2ecf20Sopenharmony_civoid aq_ptp_ring_deinit(struct aq_nic_s *aq_nic);
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_civoid aq_ptp_service_task(struct aq_nic_s *aq_nic);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_civoid aq_ptp_tm_offset_set(struct aq_nic_s *aq_nic, unsigned int mbps);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_civoid aq_ptp_clock_init(struct aq_nic_s *aq_nic);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* Traffic processing functions */
588c2ecf20Sopenharmony_ciint aq_ptp_xmit(struct aq_nic_s *aq_nic, struct sk_buff *skb);
598c2ecf20Sopenharmony_civoid aq_ptp_tx_hwtstamp(struct aq_nic_s *aq_nic, u64 timestamp);
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/* Must be to check available of PTP before call */
628c2ecf20Sopenharmony_civoid aq_ptp_hwtstamp_config_get(struct aq_ptp_s *aq_ptp,
638c2ecf20Sopenharmony_ci				struct hwtstamp_config *config);
648c2ecf20Sopenharmony_ciint aq_ptp_hwtstamp_config_set(struct aq_ptp_s *aq_ptp,
658c2ecf20Sopenharmony_ci			       struct hwtstamp_config *config);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/* Return either ring is belong to PTP or not*/
688c2ecf20Sopenharmony_cibool aq_ptp_ring(struct aq_nic_s *aq_nic, struct aq_ring_s *ring);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciu16 aq_ptp_extract_ts(struct aq_nic_s *aq_nic, struct sk_buff *skb, u8 *p,
718c2ecf20Sopenharmony_ci		      unsigned int len);
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistruct ptp_clock *aq_ptp_get_ptp_clock(struct aq_ptp_s *aq_ptp);
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciint aq_ptp_link_change(struct aq_nic_s *aq_nic);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/* PTP ring statistics */
788c2ecf20Sopenharmony_ciint aq_ptp_get_ring_cnt(struct aq_nic_s *aq_nic, const enum atl_ring_type ring_type);
798c2ecf20Sopenharmony_ciu64 *aq_ptp_get_stats(struct aq_nic_s *aq_nic, u64 *data);
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#else
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_cistatic inline int aq_ptp_init(struct aq_nic_s *aq_nic, unsigned int idx_vec)
848c2ecf20Sopenharmony_ci{
858c2ecf20Sopenharmony_ci	return 0;
868c2ecf20Sopenharmony_ci}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic inline void aq_ptp_unregister(struct aq_nic_s *aq_nic) {}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic inline void aq_ptp_free(struct aq_nic_s *aq_nic)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic inline int aq_ptp_irq_alloc(struct aq_nic_s *aq_nic)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	return 0;
978c2ecf20Sopenharmony_ci}
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistatic inline void aq_ptp_irq_free(struct aq_nic_s *aq_nic)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistatic inline int aq_ptp_ring_alloc(struct aq_nic_s *aq_nic)
1048c2ecf20Sopenharmony_ci{
1058c2ecf20Sopenharmony_ci	return 0;
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistatic inline void aq_ptp_ring_free(struct aq_nic_s *aq_nic) {}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic inline int aq_ptp_ring_init(struct aq_nic_s *aq_nic)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	return 0;
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistatic inline int aq_ptp_ring_start(struct aq_nic_s *aq_nic)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	return 0;
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic inline void aq_ptp_ring_stop(struct aq_nic_s *aq_nic) {}
1218c2ecf20Sopenharmony_cistatic inline void aq_ptp_ring_deinit(struct aq_nic_s *aq_nic) {}
1228c2ecf20Sopenharmony_cistatic inline void aq_ptp_service_task(struct aq_nic_s *aq_nic) {}
1238c2ecf20Sopenharmony_cistatic inline void aq_ptp_tm_offset_set(struct aq_nic_s *aq_nic,
1248c2ecf20Sopenharmony_ci					unsigned int mbps) {}
1258c2ecf20Sopenharmony_cistatic inline void aq_ptp_clock_init(struct aq_nic_s *aq_nic) {}
1268c2ecf20Sopenharmony_cistatic inline int aq_ptp_xmit(struct aq_nic_s *aq_nic, struct sk_buff *skb)
1278c2ecf20Sopenharmony_ci{
1288c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
1298c2ecf20Sopenharmony_ci}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistatic inline void aq_ptp_tx_hwtstamp(struct aq_nic_s *aq_nic, u64 timestamp) {}
1328c2ecf20Sopenharmony_cistatic inline void aq_ptp_hwtstamp_config_get(struct aq_ptp_s *aq_ptp,
1338c2ecf20Sopenharmony_ci					      struct hwtstamp_config *config) {}
1348c2ecf20Sopenharmony_cistatic inline int aq_ptp_hwtstamp_config_set(struct aq_ptp_s *aq_ptp,
1358c2ecf20Sopenharmony_ci					     struct hwtstamp_config *config)
1368c2ecf20Sopenharmony_ci{
1378c2ecf20Sopenharmony_ci	return 0;
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic inline bool aq_ptp_ring(struct aq_nic_s *aq_nic, struct aq_ring_s *ring)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	return false;
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic inline u16 aq_ptp_extract_ts(struct aq_nic_s *aq_nic,
1468c2ecf20Sopenharmony_ci				    struct sk_buff *skb, u8 *p,
1478c2ecf20Sopenharmony_ci				    unsigned int len)
1488c2ecf20Sopenharmony_ci{
1498c2ecf20Sopenharmony_ci	return 0;
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cistatic inline struct ptp_clock *aq_ptp_get_ptp_clock(struct aq_ptp_s *aq_ptp)
1538c2ecf20Sopenharmony_ci{
1548c2ecf20Sopenharmony_ci	return NULL;
1558c2ecf20Sopenharmony_ci}
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistatic inline int aq_ptp_link_change(struct aq_nic_s *aq_nic)
1588c2ecf20Sopenharmony_ci{
1598c2ecf20Sopenharmony_ci	return 0;
1608c2ecf20Sopenharmony_ci}
1618c2ecf20Sopenharmony_ci#endif
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#endif /* AQ_PTP_H */
164