1212
1313#include "aq_nic.h"
1414#include "aq_ptp.h"
15+ #include "aq_ring.h"
16+
17+ struct ptp_skb_ring {
18+ struct sk_buff * * buff ;
19+ spinlock_t lock ;
20+ unsigned int size ;
21+ unsigned int head ;
22+ unsigned int tail ;
23+ };
1524
1625struct aq_ptp_s {
1726 struct aq_nic_s * aq_nic ;
1827 spinlock_t ptp_lock ;
28+ spinlock_t ptp_ring_lock ;
1929 struct ptp_clock * ptp_clock ;
2030 struct ptp_clock_info ptp_info ;
31+
32+ struct aq_ring_param_s ptp_ring_param ;
33+
34+ struct aq_ring_s ptp_tx ;
35+ struct aq_ring_s ptp_rx ;
36+ struct aq_ring_s hwts_rx ;
37+
38+ struct ptp_skb_ring skb_ring ;
2139};
2240
41+ static int aq_ptp_skb_ring_init (struct ptp_skb_ring * ring , unsigned int size )
42+ {
43+ struct sk_buff * * buff = kmalloc (sizeof (* buff ) * size , GFP_KERNEL );
44+
45+ if (!buff )
46+ return - ENOMEM ;
47+
48+ spin_lock_init (& ring -> lock );
49+
50+ ring -> buff = buff ;
51+ ring -> size = size ;
52+ ring -> head = 0 ;
53+ ring -> tail = 0 ;
54+
55+ return 0 ;
56+ }
57+
58+ static void aq_ptp_skb_ring_release (struct ptp_skb_ring * ring )
59+ {
60+ kfree (ring -> buff );
61+ ring -> buff = NULL ;
62+ }
63+
2364/* aq_ptp_adjfine
2465 * @ptp: the ptp clock structure
2566 * @ppb: parts per billion adjustment from base
@@ -107,6 +148,190 @@ static int aq_ptp_settime(struct ptp_clock_info *ptp,
107148 return 0 ;
108149}
109150
151+ int aq_ptp_ring_init (struct aq_nic_s * aq_nic )
152+ {
153+ struct aq_ptp_s * aq_ptp = aq_nic -> aq_ptp ;
154+ int err = 0 ;
155+
156+ if (!aq_ptp )
157+ return 0 ;
158+
159+ err = aq_ring_init (& aq_ptp -> ptp_tx );
160+ if (err < 0 )
161+ goto err_exit ;
162+ err = aq_nic -> aq_hw_ops -> hw_ring_tx_init (aq_nic -> aq_hw ,
163+ & aq_ptp -> ptp_tx ,
164+ & aq_ptp -> ptp_ring_param );
165+ if (err < 0 )
166+ goto err_exit ;
167+
168+ err = aq_ring_init (& aq_ptp -> ptp_rx );
169+ if (err < 0 )
170+ goto err_exit ;
171+ err = aq_nic -> aq_hw_ops -> hw_ring_rx_init (aq_nic -> aq_hw ,
172+ & aq_ptp -> ptp_rx ,
173+ & aq_ptp -> ptp_ring_param );
174+ if (err < 0 )
175+ goto err_exit ;
176+
177+ err = aq_ring_rx_fill (& aq_ptp -> ptp_rx );
178+ if (err < 0 )
179+ goto err_rx_free ;
180+ err = aq_nic -> aq_hw_ops -> hw_ring_rx_fill (aq_nic -> aq_hw ,
181+ & aq_ptp -> ptp_rx ,
182+ 0U );
183+ if (err < 0 )
184+ goto err_rx_free ;
185+
186+ err = aq_ring_init (& aq_ptp -> hwts_rx );
187+ if (err < 0 )
188+ goto err_rx_free ;
189+ err = aq_nic -> aq_hw_ops -> hw_ring_rx_init (aq_nic -> aq_hw ,
190+ & aq_ptp -> hwts_rx ,
191+ & aq_ptp -> ptp_ring_param );
192+
193+ return err ;
194+
195+ err_rx_free :
196+ aq_ring_rx_deinit (& aq_ptp -> ptp_rx );
197+ err_exit :
198+ return err ;
199+ }
200+
201+ int aq_ptp_ring_start (struct aq_nic_s * aq_nic )
202+ {
203+ struct aq_ptp_s * aq_ptp = aq_nic -> aq_ptp ;
204+ int err = 0 ;
205+
206+ if (!aq_ptp )
207+ return 0 ;
208+
209+ err = aq_nic -> aq_hw_ops -> hw_ring_tx_start (aq_nic -> aq_hw , & aq_ptp -> ptp_tx );
210+ if (err < 0 )
211+ goto err_exit ;
212+
213+ err = aq_nic -> aq_hw_ops -> hw_ring_rx_start (aq_nic -> aq_hw , & aq_ptp -> ptp_rx );
214+ if (err < 0 )
215+ goto err_exit ;
216+
217+ err = aq_nic -> aq_hw_ops -> hw_ring_rx_start (aq_nic -> aq_hw ,
218+ & aq_ptp -> hwts_rx );
219+ if (err < 0 )
220+ goto err_exit ;
221+
222+ err_exit :
223+ return err ;
224+ }
225+
226+ void aq_ptp_ring_stop (struct aq_nic_s * aq_nic )
227+ {
228+ struct aq_ptp_s * aq_ptp = aq_nic -> aq_ptp ;
229+
230+ if (!aq_ptp )
231+ return ;
232+
233+ aq_nic -> aq_hw_ops -> hw_ring_tx_stop (aq_nic -> aq_hw , & aq_ptp -> ptp_tx );
234+ aq_nic -> aq_hw_ops -> hw_ring_rx_stop (aq_nic -> aq_hw , & aq_ptp -> ptp_rx );
235+
236+ aq_nic -> aq_hw_ops -> hw_ring_rx_stop (aq_nic -> aq_hw , & aq_ptp -> hwts_rx );
237+ }
238+
239+ void aq_ptp_ring_deinit (struct aq_nic_s * aq_nic )
240+ {
241+ struct aq_ptp_s * aq_ptp = aq_nic -> aq_ptp ;
242+
243+ if (!aq_ptp || !aq_ptp -> ptp_tx .aq_nic || !aq_ptp -> ptp_rx .aq_nic )
244+ return ;
245+
246+ aq_ring_tx_clean (& aq_ptp -> ptp_tx );
247+ aq_ring_rx_deinit (& aq_ptp -> ptp_rx );
248+ }
249+
250+ #define PTP_8TC_RING_IDX 8
251+ #define PTP_4TC_RING_IDX 16
252+ #define PTP_HWST_RING_IDX 31
253+
254+ int aq_ptp_ring_alloc (struct aq_nic_s * aq_nic )
255+ {
256+ struct aq_ptp_s * aq_ptp = aq_nic -> aq_ptp ;
257+ unsigned int tx_ring_idx , rx_ring_idx ;
258+ struct aq_ring_s * hwts = 0 ;
259+ u32 tx_tc_mode , rx_tc_mode ;
260+ struct aq_ring_s * ring ;
261+ int err ;
262+
263+ if (!aq_ptp )
264+ return 0 ;
265+
266+ /* Index must to be 8 (8 TCs) or 16 (4 TCs).
267+ * It depends from Traffic Class mode.
268+ */
269+ aq_nic -> aq_hw_ops -> hw_tx_tc_mode_get (aq_nic -> aq_hw , & tx_tc_mode );
270+ if (tx_tc_mode == 0 )
271+ tx_ring_idx = PTP_8TC_RING_IDX ;
272+ else
273+ tx_ring_idx = PTP_4TC_RING_IDX ;
274+
275+ ring = aq_ring_tx_alloc (& aq_ptp -> ptp_tx , aq_nic ,
276+ tx_ring_idx , & aq_nic -> aq_nic_cfg );
277+ if (!ring ) {
278+ err = - ENOMEM ;
279+ goto err_exit ;
280+ }
281+
282+ aq_nic -> aq_hw_ops -> hw_rx_tc_mode_get (aq_nic -> aq_hw , & rx_tc_mode );
283+ if (rx_tc_mode == 0 )
284+ rx_ring_idx = PTP_8TC_RING_IDX ;
285+ else
286+ rx_ring_idx = PTP_4TC_RING_IDX ;
287+
288+ ring = aq_ring_rx_alloc (& aq_ptp -> ptp_rx , aq_nic ,
289+ rx_ring_idx , & aq_nic -> aq_nic_cfg );
290+ if (!ring ) {
291+ err = - ENOMEM ;
292+ goto err_exit_ptp_tx ;
293+ }
294+
295+ hwts = aq_ring_hwts_rx_alloc (& aq_ptp -> hwts_rx , aq_nic , PTP_HWST_RING_IDX ,
296+ aq_nic -> aq_nic_cfg .rxds ,
297+ aq_nic -> aq_nic_cfg .aq_hw_caps -> rxd_size );
298+ if (!hwts ) {
299+ err = - ENOMEM ;
300+ goto err_exit_ptp_rx ;
301+ }
302+
303+ err = aq_ptp_skb_ring_init (& aq_ptp -> skb_ring , aq_nic -> aq_nic_cfg .rxds );
304+ if (err != 0 ) {
305+ err = - ENOMEM ;
306+ goto err_exit_hwts_rx ;
307+ }
308+
309+ return 0 ;
310+
311+ err_exit_hwts_rx :
312+ aq_ring_free (& aq_ptp -> hwts_rx );
313+ err_exit_ptp_rx :
314+ aq_ring_free (& aq_ptp -> ptp_rx );
315+ err_exit_ptp_tx :
316+ aq_ring_free (& aq_ptp -> ptp_tx );
317+ err_exit :
318+ return err ;
319+ }
320+
321+ void aq_ptp_ring_free (struct aq_nic_s * aq_nic )
322+ {
323+ struct aq_ptp_s * aq_ptp = aq_nic -> aq_ptp ;
324+
325+ if (!aq_ptp )
326+ return ;
327+
328+ aq_ring_free (& aq_ptp -> ptp_tx );
329+ aq_ring_free (& aq_ptp -> ptp_rx );
330+ aq_ring_free (& aq_ptp -> hwts_rx );
331+
332+ aq_ptp_skb_ring_release (& aq_ptp -> skb_ring );
333+ }
334+
110335static struct ptp_clock_info aq_ptp_clock = {
111336 .owner = THIS_MODULE ,
112337 .name = "atlantic ptp" ,
@@ -122,6 +347,15 @@ static struct ptp_clock_info aq_ptp_clock = {
122347 .pin_config = NULL ,
123348};
124349
350+ void aq_ptp_clock_init (struct aq_nic_s * aq_nic )
351+ {
352+ struct aq_ptp_s * aq_ptp = aq_nic -> aq_ptp ;
353+ struct timespec64 ts ;
354+
355+ ktime_get_real_ts64 (& ts );
356+ aq_ptp_settime (& aq_ptp -> ptp_info , & ts );
357+ }
358+
125359int aq_ptp_init (struct aq_nic_s * aq_nic , unsigned int idx_vec )
126360{
127361 struct hw_atl_utils_mbox mbox ;
@@ -155,6 +389,7 @@ int aq_ptp_init(struct aq_nic_s *aq_nic, unsigned int idx_vec)
155389 aq_ptp -> aq_nic = aq_nic ;
156390
157391 spin_lock_init (& aq_ptp -> ptp_lock );
392+ spin_lock_init (& aq_ptp -> ptp_ring_lock );
158393
159394 aq_ptp -> ptp_info = aq_ptp_clock ;
160395 clock = ptp_clock_register (& aq_ptp -> ptp_info , & aq_nic -> ndev -> dev );
0 commit comments