1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Atlantic Network Driver
3  *
4  * Copyright (C) 2014-2019 aQuantia Corporation
5  * Copyright (C) 2019-2020 Marvell International Ltd.
6  */
7 
8 /* File aq_ptp.h: Declaration of PTP functions.
9  */
10 #ifndef AQ_PTP_H
11 #define AQ_PTP_H
12 
13 #include <linux/net_tstamp.h>
14 
15 #include "aq_ring.h"
16 
17 #define PTP_8TC_RING_IDX             8
18 #define PTP_4TC_RING_IDX            16
19 #define PTP_HWST_RING_IDX           31
20 
21 /* Index must to be 8 (8 TCs) or 16 (4 TCs).
22  * It depends from Traffic Class mode.
23  */
aq_ptp_ring_idx(const enum aq_tc_mode tc_mode)24 static inline unsigned int aq_ptp_ring_idx(const enum aq_tc_mode tc_mode)
25 {
26 	if (tc_mode == AQ_TC_MODE_8TCS)
27 		return PTP_8TC_RING_IDX;
28 
29 	return PTP_4TC_RING_IDX;
30 }
31 
32 #if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
33 
34 /* Common functions */
35 int aq_ptp_init(struct aq_nic_s *aq_nic, unsigned int idx_vec);
36 
37 void aq_ptp_unregister(struct aq_nic_s *aq_nic);
38 void aq_ptp_free(struct aq_nic_s *aq_nic);
39 
40 int aq_ptp_irq_alloc(struct aq_nic_s *aq_nic);
41 void aq_ptp_irq_free(struct aq_nic_s *aq_nic);
42 
43 int aq_ptp_ring_alloc(struct aq_nic_s *aq_nic);
44 void aq_ptp_ring_free(struct aq_nic_s *aq_nic);
45 
46 int aq_ptp_ring_init(struct aq_nic_s *aq_nic);
47 int aq_ptp_ring_start(struct aq_nic_s *aq_nic);
48 void aq_ptp_ring_stop(struct aq_nic_s *aq_nic);
49 void aq_ptp_ring_deinit(struct aq_nic_s *aq_nic);
50 
51 void aq_ptp_service_task(struct aq_nic_s *aq_nic);
52 
53 void aq_ptp_tm_offset_set(struct aq_nic_s *aq_nic, unsigned int mbps);
54 
55 void aq_ptp_clock_init(struct aq_nic_s *aq_nic);
56 
57 /* Traffic processing functions */
58 int aq_ptp_xmit(struct aq_nic_s *aq_nic, struct sk_buff *skb);
59 void aq_ptp_tx_hwtstamp(struct aq_nic_s *aq_nic, u64 timestamp);
60 
61 /* Must be to check available of PTP before call */
62 void aq_ptp_hwtstamp_config_get(struct aq_ptp_s *aq_ptp,
63 				struct hwtstamp_config *config);
64 int aq_ptp_hwtstamp_config_set(struct aq_ptp_s *aq_ptp,
65 			       struct hwtstamp_config *config);
66 
67 /* Return either ring is belong to PTP or not*/
68 bool aq_ptp_ring(struct aq_nic_s *aq_nic, struct aq_ring_s *ring);
69 
70 u16 aq_ptp_extract_ts(struct aq_nic_s *aq_nic, struct sk_buff *skb, u8 *p,
71 		      unsigned int len);
72 
73 struct ptp_clock *aq_ptp_get_ptp_clock(struct aq_ptp_s *aq_ptp);
74 
75 int aq_ptp_link_change(struct aq_nic_s *aq_nic);
76 
77 /* PTP ring statistics */
78 int aq_ptp_get_ring_cnt(struct aq_nic_s *aq_nic, const enum atl_ring_type ring_type);
79 u64 *aq_ptp_get_stats(struct aq_nic_s *aq_nic, u64 *data);
80 
81 #else
82 
aq_ptp_init(struct aq_nic_s * aq_nic,unsigned int idx_vec)83 static inline int aq_ptp_init(struct aq_nic_s *aq_nic, unsigned int idx_vec)
84 {
85 	return 0;
86 }
87 
aq_ptp_unregister(struct aq_nic_s * aq_nic)88 static inline void aq_ptp_unregister(struct aq_nic_s *aq_nic) {}
89 
aq_ptp_free(struct aq_nic_s * aq_nic)90 static inline void aq_ptp_free(struct aq_nic_s *aq_nic)
91 {
92 }
93 
aq_ptp_irq_alloc(struct aq_nic_s * aq_nic)94 static inline int aq_ptp_irq_alloc(struct aq_nic_s *aq_nic)
95 {
96 	return 0;
97 }
98 
aq_ptp_irq_free(struct aq_nic_s * aq_nic)99 static inline void aq_ptp_irq_free(struct aq_nic_s *aq_nic)
100 {
101 }
102 
aq_ptp_ring_alloc(struct aq_nic_s * aq_nic)103 static inline int aq_ptp_ring_alloc(struct aq_nic_s *aq_nic)
104 {
105 	return 0;
106 }
107 
aq_ptp_ring_free(struct aq_nic_s * aq_nic)108 static inline void aq_ptp_ring_free(struct aq_nic_s *aq_nic) {}
109 
aq_ptp_ring_init(struct aq_nic_s * aq_nic)110 static inline int aq_ptp_ring_init(struct aq_nic_s *aq_nic)
111 {
112 	return 0;
113 }
114 
aq_ptp_ring_start(struct aq_nic_s * aq_nic)115 static inline int aq_ptp_ring_start(struct aq_nic_s *aq_nic)
116 {
117 	return 0;
118 }
119 
aq_ptp_ring_stop(struct aq_nic_s * aq_nic)120 static inline void aq_ptp_ring_stop(struct aq_nic_s *aq_nic) {}
aq_ptp_ring_deinit(struct aq_nic_s * aq_nic)121 static inline void aq_ptp_ring_deinit(struct aq_nic_s *aq_nic) {}
aq_ptp_service_task(struct aq_nic_s * aq_nic)122 static inline void aq_ptp_service_task(struct aq_nic_s *aq_nic) {}
aq_ptp_tm_offset_set(struct aq_nic_s * aq_nic,unsigned int mbps)123 static inline void aq_ptp_tm_offset_set(struct aq_nic_s *aq_nic,
124 					unsigned int mbps) {}
aq_ptp_clock_init(struct aq_nic_s * aq_nic)125 static inline void aq_ptp_clock_init(struct aq_nic_s *aq_nic) {}
aq_ptp_xmit(struct aq_nic_s * aq_nic,struct sk_buff * skb)126 static inline int aq_ptp_xmit(struct aq_nic_s *aq_nic, struct sk_buff *skb)
127 {
128 	return -EOPNOTSUPP;
129 }
130 
aq_ptp_tx_hwtstamp(struct aq_nic_s * aq_nic,u64 timestamp)131 static inline void aq_ptp_tx_hwtstamp(struct aq_nic_s *aq_nic, u64 timestamp) {}
aq_ptp_hwtstamp_config_get(struct aq_ptp_s * aq_ptp,struct hwtstamp_config * config)132 static inline void aq_ptp_hwtstamp_config_get(struct aq_ptp_s *aq_ptp,
133 					      struct hwtstamp_config *config) {}
aq_ptp_hwtstamp_config_set(struct aq_ptp_s * aq_ptp,struct hwtstamp_config * config)134 static inline int aq_ptp_hwtstamp_config_set(struct aq_ptp_s *aq_ptp,
135 					     struct hwtstamp_config *config)
136 {
137 	return 0;
138 }
139 
aq_ptp_ring(struct aq_nic_s * aq_nic,struct aq_ring_s * ring)140 static inline bool aq_ptp_ring(struct aq_nic_s *aq_nic, struct aq_ring_s *ring)
141 {
142 	return false;
143 }
144 
aq_ptp_extract_ts(struct aq_nic_s * aq_nic,struct sk_buff * skb,u8 * p,unsigned int len)145 static inline u16 aq_ptp_extract_ts(struct aq_nic_s *aq_nic,
146 				    struct sk_buff *skb, u8 *p,
147 				    unsigned int len)
148 {
149 	return 0;
150 }
151 
aq_ptp_get_ptp_clock(struct aq_ptp_s * aq_ptp)152 static inline struct ptp_clock *aq_ptp_get_ptp_clock(struct aq_ptp_s *aq_ptp)
153 {
154 	return NULL;
155 }
156 
aq_ptp_link_change(struct aq_nic_s * aq_nic)157 static inline int aq_ptp_link_change(struct aq_nic_s *aq_nic)
158 {
159 	return 0;
160 }
161 #endif
162 
163 #endif /* AQ_PTP_H */
164