mediatek: mt7622: add Linux 5.10 support
[openwrt/openwrt.git] / target / linux / mediatek / files-5.10 / drivers / net / phy / rtk / rtl8367c / include / ptp.h
1 /*
2 * Copyright (C) 2013 Realtek Semiconductor Corp.
3 * All Rights Reserved.
4 *
5 * Unless you and Realtek execute a separate written software license
6 * agreement governing use of this software, this software is licensed
7 * to you under the terms of the GNU General Public License version 2,
8 * available at https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
9 *
10 * Purpose : RTL8367/RTL8367C switch high-level API
11 *
12 * Feature : The file includes time module high-layer API defination
13 *
14 */
15
16 #ifndef __RTK_API_PTP_H__
17 #define __RTK_API_PTP_H__
18
19 /*
20 * Symbol Definition
21 */
22 #define RTK_MAX_NUM_OF_NANO_SECOND 0x3B9AC9FF
23 #define RTK_PTP_INTR_MASK 0xFF
24 #define RTK_MAX_NUM_OF_TPID 0xFFFF
25
26 /* Message Type */
27 typedef enum rtk_ptp_msgType_e
28 {
29 PTP_MSG_TYPE_TX_SYNC = 0,
30 PTP_MSG_TYPE_TX_DELAY_REQ,
31 PTP_MSG_TYPE_TX_PDELAY_REQ,
32 PTP_MSG_TYPE_TX_PDELAY_RESP,
33 PTP_MSG_TYPE_RX_SYNC,
34 PTP_MSG_TYPE_RX_DELAY_REQ,
35 PTP_MSG_TYPE_RX_PDELAY_REQ,
36 PTP_MSG_TYPE_RX_PDELAY_RESP,
37 PTP_MSG_TYPE_END
38 } rtk_ptp_msgType_t;
39
40 typedef enum rtk_ptp_intType_e
41 {
42 PTP_INT_TYPE_TX_SYNC = 0,
43 PTP_INT_TYPE_TX_DELAY_REQ,
44 PTP_INT_TYPE_TX_PDELAY_REQ,
45 PTP_INT_TYPE_TX_PDELAY_RESP,
46 PTP_INT_TYPE_RX_SYNC,
47 PTP_INT_TYPE_RX_DELAY_REQ,
48 PTP_INT_TYPE_RX_PDELAY_REQ,
49 PTP_INT_TYPE_RX_PDELAY_RESP,
50 PTP_INT_TYPE_ALL,
51 PTP_INT_TYPE_END
52 }rtk_ptp_intType_t;
53
54 typedef enum rtk_ptp_sys_adjust_e
55 {
56 SYS_ADJUST_PLUS = 0,
57 SYS_ADJUST_MINUS,
58 SYS_ADJUST_END
59 } rtk_ptp_sys_adjust_t;
60
61
62 /* Reference Time */
63 typedef struct rtk_ptp_timeStamp_s
64 {
65 rtk_uint32 sec;
66 rtk_uint32 nsec;
67 } rtk_ptp_timeStamp_t;
68
69 typedef struct rtk_ptp_info_s
70 {
71 rtk_uint32 sequenceId;
72 rtk_ptp_timeStamp_t timeStamp;
73 } rtk_ptp_info_t;
74
75 typedef rtk_uint32 rtk_ptp_tpid_t;
76
77 typedef rtk_uint32 rtk_ptp_intStatus_t; /* interrupt status mask */
78
79 /*
80 * Data Declaration
81 */
82
83 /*
84 * Function Declaration
85 */
86 /* Function Name:
87 * rtk_time_init
88 * Description:
89 * PTP function initialization.
90 * Input:
91 * None
92 * Output:
93 * None
94 * Return:
95 * RT_ERR_OK - OK
96 * RT_ERR_FAILED - Failed
97 * RT_ERR_SMI - SMI access error
98 * Note:
99 * This API is used to initialize EEE status.
100 */
101 extern rtk_api_ret_t rtk_ptp_init(void);
102
103 /* Function Name:
104 * rtk_ptp_mac_set
105 * Description:
106 * Configure PTP mac address.
107 * Input:
108 * mac - mac address to parser PTP packets.
109 * Output:
110 * None
111 * Return:
112 * RT_ERR_OK - OK
113 * RT_ERR_FAILED - Failed
114 * RT_ERR_SMI - SMI access error
115 * RT_ERR_INPUT - Invalid input parameter.
116 * Note:
117 * None
118 */
119 extern rtk_api_ret_t rtk_ptp_mac_set(rtk_mac_t mac);
120
121 /* Function Name:
122 * rtk_ptp_mac_get
123 * Description:
124 * Get PTP mac address.
125 * Input:
126 * None
127 * Output:
128 * pMac - mac address to parser PTP packets.
129 * Return:
130 * RT_ERR_OK - OK
131 * RT_ERR_FAILED - Failed
132 * RT_ERR_SMI - SMI access error
133 * RT_ERR_INPUT - Invalid input parameter.
134 * Note:
135 * None
136 */
137 extern rtk_api_ret_t rtk_ptp_mac_get(rtk_mac_t *pMac);
138
139 /* Function Name:
140 * rtk_ptp_tpid_set
141 * Description:
142 * Configure PTP accepted outer & inner tag TPID.
143 * Input:
144 * outerId - Ether type of S-tag frame parsing in PTP ports.
145 * innerId - Ether type of C-tag frame parsing in PTP ports.
146 * Output:
147 * None
148 * Return:
149 * RT_ERR_OK - OK
150 * RT_ERR_FAILED - Failed
151 * RT_ERR_SMI - SMI access error
152 * RT_ERR_INPUT - Invalid input parameter.
153 * Note:
154 * None
155 */
156 extern rtk_api_ret_t rtk_ptp_tpid_set(rtk_ptp_tpid_t outerId, rtk_ptp_tpid_t innerId);
157
158 /* Function Name:
159 * rtk_ptp_tpid_get
160 * Description:
161 * Get PTP accepted outer & inner tag TPID.
162 * Input:
163 * None
164 * Output:
165 * pOuterId - Ether type of S-tag frame parsing in PTP ports.
166 * pInnerId - Ether type of C-tag frame parsing in PTP ports.
167 * Return:
168 * RT_ERR_OK - OK
169 * RT_ERR_FAILED - Failed
170 * RT_ERR_SMI - SMI access error
171 * Note:
172 * None
173 */
174 extern rtk_api_ret_t rtk_ptp_tpid_get(rtk_ptp_tpid_t *pOuterId, rtk_ptp_tpid_t *pInnerId);
175
176 /* Function Name:
177 * rtk_ptp_refTime_set
178 * Description:
179 * Set the reference time of the specified device.
180 * Input:
181 * timeStamp - reference timestamp value
182 * Output:
183 * None
184 * Return:
185 * RT_ERR_OK
186 * RT_ERR_FAILED
187 * RT_ERR_INPUT - invalid input parameter
188 * Applicable:
189 * 8390, 8380
190 * Note:
191 * None
192 */
193 extern rtk_api_ret_t rtk_ptp_refTime_set(rtk_ptp_timeStamp_t timeStamp);
194
195 /* Function Name:
196 * rtk_ptp_refTime_get
197 * Description:
198 * Get the reference time of the specified device.
199 * Input:
200 * Output:
201 * pTimeStamp - pointer buffer of the reference time
202 * Return:
203 * RT_ERR_OK
204 * RT_ERR_FAILED
205 * RT_ERR_UNIT_ID - invalid unit id
206 * RT_ERR_NOT_INIT - The module is not initial
207 * RT_ERR_NULL_POINTER - input parameter may be null pointer
208 * Applicable:
209 * 8390, 8380
210 * Note:
211 * None
212 */
213 extern rtk_api_ret_t rtk_ptp_refTime_get(rtk_ptp_timeStamp_t *pTimeStamp);
214
215 /* Function Name:
216 * rtk_ptp_refTimeAdjust_set
217 * Description:
218 * Adjust the reference time.
219 * Input:
220 * unit - unit id
221 * sign - significant
222 * timeStamp - reference timestamp value
223 * Output:
224 * None
225 * Return:
226 * RT_ERR_OK
227 * RT_ERR_FAILED
228 * RT_ERR_UNIT_ID - invalid unit id
229 * RT_ERR_NOT_INIT - The module is not initial
230 * RT_ERR_INPUT - invalid input parameter
231 * Note:
232 * sign=0 for positive adjustment, sign=1 for negative adjustment.
233 */
234 extern rtk_api_ret_t rtk_ptp_refTimeAdjust_set(rtk_ptp_sys_adjust_t sign, rtk_ptp_timeStamp_t timeStamp);
235
236 /* Function Name:
237 * rtk_ptp_refTimeEnable_set
238 * Description:
239 * Set the enable state of reference time of the specified device.
240 * Input:
241 * enable - status
242 * Output:
243 * None
244 * Return:
245 * RT_ERR_OK
246 * RT_ERR_FAILED
247 * RT_ERR_INPUT - invalid input parameter
248 * Note:
249 * None
250 */
251 extern rtk_api_ret_t rtk_ptp_refTimeEnable_set(rtk_enable_t enable);
252
253 /* Function Name:
254 * rtk_ptp_refTimeEnable_get
255 * Description:
256 * Get the enable state of reference time of the specified device.
257 * Input:
258 * Output:
259 * pEnable - status
260 * Return:
261 * RT_ERR_OK
262 * RT_ERR_FAILED
263 * RT_ERR_UNIT_ID - invalid unit id
264 * RT_ERR_NOT_INIT - The module is not initial
265 * RT_ERR_NULL_POINTER - input parameter may be null pointer
266 * Applicable:
267 * 8390, 8380
268 * Note:
269 * None
270 */
271 extern rtk_api_ret_t rtk_ptp_refTimeEnable_get(rtk_enable_t *pEnable);
272
273 /* Function Name:
274 * rtk_ptp_portEnable_set
275 * Description:
276 * Set PTP status of the specified port.
277 * Input:
278 * port - port id
279 * enable - status
280 * Output:
281 * None
282 * Return:
283 * RT_ERR_OK
284 * RT_ERR_FAILED
285 * RT_ERR_PORT - invalid port id
286 * RT_ERR_INPUT - invalid input parameter
287 * Note:
288 * None
289 */
290 extern rtk_api_ret_t rtk_ptp_portEnable_set(rtk_port_t port, rtk_enable_t enable);
291
292 /* Function Name:
293 * rtk_ptp_portEnable_get
294 * Description:
295 * Get PTP status of the specified port.
296 * Input:
297 * port - port id
298 * Output:
299 * pEnable - status
300 * Return:
301 * RT_ERR_OK
302 * RT_ERR_FAILED
303 * RT_ERR_PORT - invalid port id
304 * RT_ERR_NULL_POINTER - input parameter may be null pointer
305 * Note:
306 * None
307 */
308 extern rtk_api_ret_t rtk_ptp_portEnable_get(rtk_port_t port, rtk_enable_t *pEnable);
309
310 /* Function Name:
311 * rtk_ptp_portTimestamp_get
312 * Description:
313 * Get PTP timstamp according to the PTP identifier on the dedicated port from the specified device.
314 * Input:
315 * unit - unit id
316 * port - port id
317 * type - PTP message type
318 * Output:
319 * pInfo - pointer buffer of sequence ID and timestamp
320 * Return:
321 * RT_ERR_OK
322 * RT_ERR_FAILED
323 * RT_ERR_PORT_ID - invalid port id
324 * RT_ERR_INPUT - invalid input parameter
325 * RT_ERR_NULL_POINTER - input parameter may be null pointer
326 * Applicable:
327 * 8390, 8380
328 * Note:
329 * None
330 */
331 extern rtk_api_ret_t rtk_ptp_portTimestamp_get( rtk_port_t port, rtk_ptp_msgType_t type, rtk_ptp_info_t *pInfo);
332
333 /* Function Name:
334 * rtk_ptp_intControl_set
335 * Description:
336 * Set PTP interrupt trigger status configuration.
337 * Input:
338 * type - Interrupt type.
339 * enable - Interrupt status.
340 * Output:
341 * None
342 * Return:
343 * RT_ERR_OK - OK
344 * RT_ERR_FAILED - Failed
345 * RT_ERR_SMI - SMI access error
346 * RT_ERR_INPUT - Invalid input parameters.
347 * RT_ERR_ENABLE - Invalid enable input.
348 * Note:
349 * The API can set PTP interrupt status configuration.
350 * The interrupt trigger status is shown in the following:
351 * PTP_INT_TYPE_TX_SYNC = 0,
352 * PTP_INT_TYPE_TX_DELAY_REQ,
353 * PTP_INT_TYPE_TX_PDELAY_REQ,
354 * PTP_INT_TYPE_TX_PDELAY_RESP,
355 * PTP_INT_TYPE_RX_SYNC,
356 * PTP_INT_TYPE_RX_DELAY_REQ,
357 * PTP_INT_TYPE_RX_PDELAY_REQ,
358 * PTP_INT_TYPE_RX_PDELAY_RESP,
359 * PTP_INT_TYPE_ALL,
360 */
361 extern rtk_api_ret_t rtk_ptp_intControl_set(rtk_ptp_intType_t type, rtk_enable_t enable);
362
363 /* Function Name:
364 * rtk_ptp_intControl_get
365 * Description:
366 * Get PTP interrupt trigger status configuration.
367 * Input:
368 * type - Interrupt type.
369 * Output:
370 * pEnable - Interrupt status.
371 * Return:
372 * RT_ERR_OK - OK
373 * RT_ERR_FAILED - Failed
374 * RT_ERR_SMI - SMI access error
375 * RT_ERR_INPUT - Invalid input parameters.
376 * Note:
377 * The API can get interrupt status configuration.
378 * The interrupt trigger status is shown in the following:
379 * PTP_INT_TYPE_TX_SYNC = 0,
380 * PTP_INT_TYPE_TX_DELAY_REQ,
381 * PTP_INT_TYPE_TX_PDELAY_REQ,
382 * PTP_INT_TYPE_TX_PDELAY_RESP,
383 * PTP_INT_TYPE_RX_SYNC,
384 * PTP_INT_TYPE_RX_DELAY_REQ,
385 * PTP_INT_TYPE_RX_PDELAY_REQ,
386 * PTP_INT_TYPE_RX_PDELAY_RESP,
387 */
388 extern rtk_api_ret_t rtk_ptp_intControl_get(rtk_ptp_intType_t type, rtk_enable_t *pEnable);
389
390
391 /* Function Name:
392 * rtk_ptp_intStatus_get
393 * Description:
394 * Get PTP port interrupt trigger status.
395 * Input:
396 * port - physical port
397 * Output:
398 * pStatusMask - Interrupt status bit mask.
399 * Return:
400 * RT_ERR_OK - OK
401 * RT_ERR_FAILED - Failed
402 * RT_ERR_SMI - SMI access error
403 * RT_ERR_INPUT - Invalid input parameters.
404 * Note:
405 * The API can get interrupt trigger status when interrupt happened.
406 * The interrupt trigger status is shown in the following:
407 * - PORT 0 INT (value[0] (Bit0))
408 * - PORT 1 INT (value[0] (Bit1))
409 * - PORT 2 INT (value[0] (Bit2))
410 * - PORT 3 INT (value[0] (Bit3))
411 * - PORT 4 INT (value[0] (Bit4))
412
413 *
414 */
415 extern rtk_api_ret_t rtk_ptp_intStatus_get(rtk_ptp_intStatus_t *pStatusMask);
416
417 /* Function Name:
418 * rtk_ptp_portIntStatus_set
419 * Description:
420 * Set PTP port interrupt trigger status to clean.
421 * Input:
422 * port - physical port
423 * statusMask - Interrupt status bit mask.
424 * Output:
425 * None
426 * Return:
427 * RT_ERR_OK - OK
428 * RT_ERR_FAILED - Failed
429 * RT_ERR_SMI - SMI access error
430 * RT_ERR_INPUT - Invalid input parameters.
431 * Note:
432 * The API can clean interrupt trigger status when interrupt happened.
433 * The interrupt trigger status is shown in the following:
434 * - PTP_INT_TYPE_TX_SYNC (value[0] (Bit0))
435 * - PTP_INT_TYPE_TX_DELAY_REQ (value[0] (Bit1))
436 * - PTP_INT_TYPE_TX_PDELAY_REQ (value[0] (Bit2))
437 * - PTP_INT_TYPE_TX_PDELAY_RESP (value[0] (Bit3))
438 * - PTP_INT_TYPE_RX_SYNC (value[0] (Bit4))
439 * - PTP_INT_TYPE_RX_DELAY_REQ (value[0] (Bit5))
440 * - PTP_INT_TYPE_RX_PDELAY_REQ (value[0] (Bit6))
441 * - PTP_INT_TYPE_RX_PDELAY_RESP (value[0] (Bit7))
442 * The status will be cleared after execute this API.
443 */
444 extern rtk_api_ret_t rtk_ptp_portIntStatus_set(rtk_port_t port, rtk_ptp_intStatus_t statusMask);
445
446 /* Function Name:
447 * rtk_ptp_portIntStatus_get
448 * Description:
449 * Get PTP port interrupt trigger status.
450 * Input:
451 * port - physical port
452 * Output:
453 * pStatusMask - Interrupt status bit mask.
454 * Return:
455 * RT_ERR_OK - OK
456 * RT_ERR_FAILED - Failed
457 * RT_ERR_SMI - SMI access error
458 * RT_ERR_INPUT - Invalid input parameters.
459 * Note:
460 * The API can get interrupt trigger status when interrupt happened.
461 * The interrupt trigger status is shown in the following:
462 * - PTP_INT_TYPE_TX_SYNC (value[0] (Bit0))
463 * - PTP_INT_TYPE_TX_DELAY_REQ (value[0] (Bit1))
464 * - PTP_INT_TYPE_TX_PDELAY_REQ (value[0] (Bit2))
465 * - PTP_INT_TYPE_TX_PDELAY_RESP (value[0] (Bit3))
466 * - PTP_INT_TYPE_RX_SYNC (value[0] (Bit4))
467 * - PTP_INT_TYPE_RX_DELAY_REQ (value[0] (Bit5))
468 * - PTP_INT_TYPE_RX_PDELAY_REQ (value[0] (Bit6))
469 * - PTP_INT_TYPE_RX_PDELAY_RESP (value[0] (Bit7))
470 *
471 */
472 extern rtk_api_ret_t rtk_ptp_portIntStatus_get(rtk_port_t port, rtk_ptp_intStatus_t *pStatusMask);
473
474 /* Function Name:
475 * rtk_ptp_portPtpTrap_set
476 * Description:
477 * Set PTP packet trap of the specified port.
478 * Input:
479 * port - port id
480 * enable - status
481 * Output:
482 * None
483 * Return:
484 * RT_ERR_OK
485 * RT_ERR_FAILED
486 * RT_ERR_PORT - invalid port id
487 * RT_ERR_INPUT - invalid input parameter
488 * Note:
489 * None
490 */
491 extern rtk_api_ret_t rtk_ptp_portTrap_set(rtk_port_t port, rtk_enable_t enable);
492
493 /* Function Name:
494 * rtk_ptp_portPtpEnable_get
495 * Description:
496 * Get PTP packet trap of the specified port.
497 * Input:
498 * port - port id
499 * Output:
500 * pEnable - status
501 * Return:
502 * RT_ERR_OK
503 * RT_ERR_FAILED
504 * RT_ERR_PORT - invalid port id
505 * RT_ERR_NULL_POINTER - input parameter may be null pointer
506 * Note:
507 * None
508 */
509 extern rtk_api_ret_t rtk_ptp_portTrap_get(rtk_port_t port, rtk_enable_t *pEnable);
510
511 #endif /* __RTK_API_PTP_H__ */