xref: /linux/drivers/net/ethernet/aquantia/atlantic/aq_ptp.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
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  */
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 
83 static inline int aq_ptp_init(struct aq_nic_s *aq_nic, unsigned int idx_vec)
84 {
85 	return 0;
86 }
87 
88 static inline void aq_ptp_unregister(struct aq_nic_s *aq_nic) {}
89 
90 static inline void aq_ptp_free(struct aq_nic_s *aq_nic)
91 {
92 }
93 
94 static inline int aq_ptp_irq_alloc(struct aq_nic_s *aq_nic)
95 {
96 	return 0;
97 }
98 
99 static inline void aq_ptp_irq_free(struct aq_nic_s *aq_nic)
100 {
101 }
102 
103 static inline int aq_ptp_ring_alloc(struct aq_nic_s *aq_nic)
104 {
105 	return 0;
106 }
107 
108 static inline void aq_ptp_ring_free(struct aq_nic_s *aq_nic) {}
109 
110 static inline int aq_ptp_ring_init(struct aq_nic_s *aq_nic)
111 {
112 	return 0;
113 }
114 
115 static inline int aq_ptp_ring_start(struct aq_nic_s *aq_nic)
116 {
117 	return 0;
118 }
119 
120 static inline void aq_ptp_ring_stop(struct aq_nic_s *aq_nic) {}
121 static inline void aq_ptp_ring_deinit(struct aq_nic_s *aq_nic) {}
122 static inline void aq_ptp_service_task(struct aq_nic_s *aq_nic) {}
123 static inline void aq_ptp_tm_offset_set(struct aq_nic_s *aq_nic,
124 					unsigned int mbps) {}
125 static inline void aq_ptp_clock_init(struct aq_nic_s *aq_nic) {}
126 static inline int aq_ptp_xmit(struct aq_nic_s *aq_nic, struct sk_buff *skb)
127 {
128 	return -EOPNOTSUPP;
129 }
130 
131 static inline void aq_ptp_tx_hwtstamp(struct aq_nic_s *aq_nic, u64 timestamp) {}
132 static inline void aq_ptp_hwtstamp_config_get(struct aq_ptp_s *aq_ptp,
133 					      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 
140 static inline bool aq_ptp_ring(struct aq_nic_s *aq_nic, struct aq_ring_s *ring)
141 {
142 	return false;
143 }
144 
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 
152 static inline struct ptp_clock *aq_ptp_get_ptp_clock(struct aq_ptp_s *aq_ptp)
153 {
154 	return NULL;
155 }
156 
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