2 * Copyright (C) 2013 Realtek Semiconductor Corp.
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
10 * Purpose : RTL8367/RTL8367C switch high-level API
12 * Feature : The file includes time module high-layer API defination
16 #ifndef __RTK_API_PTP_H__
17 #define __RTK_API_PTP_H__
22 #define RTK_MAX_NUM_OF_NANO_SECOND 0x3B9AC9FF
23 #define RTK_PTP_INTR_MASK 0xFF
24 #define RTK_MAX_NUM_OF_TPID 0xFFFF
27 typedef enum rtk_ptp_msgType_e
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
,
34 PTP_MSG_TYPE_RX_DELAY_REQ
,
35 PTP_MSG_TYPE_RX_PDELAY_REQ
,
36 PTP_MSG_TYPE_RX_PDELAY_RESP
,
40 typedef enum rtk_ptp_intType_e
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
,
47 PTP_INT_TYPE_RX_DELAY_REQ
,
48 PTP_INT_TYPE_RX_PDELAY_REQ
,
49 PTP_INT_TYPE_RX_PDELAY_RESP
,
54 typedef enum rtk_ptp_sys_adjust_e
59 } rtk_ptp_sys_adjust_t
;
63 typedef struct rtk_ptp_timeStamp_s
67 } rtk_ptp_timeStamp_t
;
69 typedef struct rtk_ptp_info_s
71 rtk_uint32 sequenceId
;
72 rtk_ptp_timeStamp_t timeStamp
;
75 typedef rtk_uint32 rtk_ptp_tpid_t
;
77 typedef rtk_uint32 rtk_ptp_intStatus_t
; /* interrupt status mask */
84 * Function Declaration
89 * PTP function initialization.
96 * RT_ERR_FAILED - Failed
97 * RT_ERR_SMI - SMI access error
99 * This API is used to initialize EEE status.
101 extern rtk_api_ret_t
rtk_ptp_init(void);
106 * Configure PTP mac address.
108 * mac - mac address to parser PTP packets.
113 * RT_ERR_FAILED - Failed
114 * RT_ERR_SMI - SMI access error
115 * RT_ERR_INPUT - Invalid input parameter.
119 extern rtk_api_ret_t
rtk_ptp_mac_set(rtk_mac_t mac
);
124 * Get PTP mac address.
128 * pMac - mac address to parser PTP packets.
131 * RT_ERR_FAILED - Failed
132 * RT_ERR_SMI - SMI access error
133 * RT_ERR_INPUT - Invalid input parameter.
137 extern rtk_api_ret_t
rtk_ptp_mac_get(rtk_mac_t
*pMac
);
142 * Configure PTP accepted outer & inner tag TPID.
144 * outerId - Ether type of S-tag frame parsing in PTP ports.
145 * innerId - Ether type of C-tag frame parsing in PTP ports.
150 * RT_ERR_FAILED - Failed
151 * RT_ERR_SMI - SMI access error
152 * RT_ERR_INPUT - Invalid input parameter.
156 extern rtk_api_ret_t
rtk_ptp_tpid_set(rtk_ptp_tpid_t outerId
, rtk_ptp_tpid_t innerId
);
161 * Get PTP accepted outer & inner tag TPID.
165 * pOuterId - Ether type of S-tag frame parsing in PTP ports.
166 * pInnerId - Ether type of C-tag frame parsing in PTP ports.
169 * RT_ERR_FAILED - Failed
170 * RT_ERR_SMI - SMI access error
174 extern rtk_api_ret_t
rtk_ptp_tpid_get(rtk_ptp_tpid_t
*pOuterId
, rtk_ptp_tpid_t
*pInnerId
);
177 * rtk_ptp_refTime_set
179 * Set the reference time of the specified device.
181 * timeStamp - reference timestamp value
187 * RT_ERR_INPUT - invalid input parameter
193 extern rtk_api_ret_t
rtk_ptp_refTime_set(rtk_ptp_timeStamp_t timeStamp
);
196 * rtk_ptp_refTime_get
198 * Get the reference time of the specified device.
201 * pTimeStamp - pointer buffer of the reference time
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
213 extern rtk_api_ret_t
rtk_ptp_refTime_get(rtk_ptp_timeStamp_t
*pTimeStamp
);
216 * rtk_ptp_refTimeAdjust_set
218 * Adjust the reference time.
222 * timeStamp - reference timestamp value
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
232 * sign=0 for positive adjustment, sign=1 for negative adjustment.
234 extern rtk_api_ret_t
rtk_ptp_refTimeAdjust_set(rtk_ptp_sys_adjust_t sign
, rtk_ptp_timeStamp_t timeStamp
);
237 * rtk_ptp_refTimeEnable_set
239 * Set the enable state of reference time of the specified device.
247 * RT_ERR_INPUT - invalid input parameter
251 extern rtk_api_ret_t
rtk_ptp_refTimeEnable_set(rtk_enable_t enable
);
254 * rtk_ptp_refTimeEnable_get
256 * Get the enable state of reference time of the specified device.
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
271 extern rtk_api_ret_t
rtk_ptp_refTimeEnable_get(rtk_enable_t
*pEnable
);
274 * rtk_ptp_portEnable_set
276 * Set PTP status of the specified port.
285 * RT_ERR_PORT - invalid port id
286 * RT_ERR_INPUT - invalid input parameter
290 extern rtk_api_ret_t
rtk_ptp_portEnable_set(rtk_port_t port
, rtk_enable_t enable
);
293 * rtk_ptp_portEnable_get
295 * Get PTP status of the specified port.
303 * RT_ERR_PORT - invalid port id
304 * RT_ERR_NULL_POINTER - input parameter may be null pointer
308 extern rtk_api_ret_t
rtk_ptp_portEnable_get(rtk_port_t port
, rtk_enable_t
*pEnable
);
311 * rtk_ptp_portTimestamp_get
313 * Get PTP timstamp according to the PTP identifier on the dedicated port from the specified device.
317 * type - PTP message type
319 * pInfo - pointer buffer of sequence ID and timestamp
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
331 extern rtk_api_ret_t
rtk_ptp_portTimestamp_get( rtk_port_t port
, rtk_ptp_msgType_t type
, rtk_ptp_info_t
*pInfo
);
334 * rtk_ptp_intControl_set
336 * Set PTP interrupt trigger status configuration.
338 * type - Interrupt type.
339 * enable - Interrupt status.
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.
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,
361 extern rtk_api_ret_t
rtk_ptp_intControl_set(rtk_ptp_intType_t type
, rtk_enable_t enable
);
364 * rtk_ptp_intControl_get
366 * Get PTP interrupt trigger status configuration.
368 * type - Interrupt type.
370 * pEnable - Interrupt status.
373 * RT_ERR_FAILED - Failed
374 * RT_ERR_SMI - SMI access error
375 * RT_ERR_INPUT - Invalid input parameters.
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,
388 extern rtk_api_ret_t
rtk_ptp_intControl_get(rtk_ptp_intType_t type
, rtk_enable_t
*pEnable
);
392 * rtk_ptp_intStatus_get
394 * Get PTP port interrupt trigger status.
396 * port - physical port
398 * pStatusMask - Interrupt status bit mask.
401 * RT_ERR_FAILED - Failed
402 * RT_ERR_SMI - SMI access error
403 * RT_ERR_INPUT - Invalid input parameters.
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))
415 extern rtk_api_ret_t
rtk_ptp_intStatus_get(rtk_ptp_intStatus_t
*pStatusMask
);
418 * rtk_ptp_portIntStatus_set
420 * Set PTP port interrupt trigger status to clean.
422 * port - physical port
423 * statusMask - Interrupt status bit mask.
428 * RT_ERR_FAILED - Failed
429 * RT_ERR_SMI - SMI access error
430 * RT_ERR_INPUT - Invalid input parameters.
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.
444 extern rtk_api_ret_t
rtk_ptp_portIntStatus_set(rtk_port_t port
, rtk_ptp_intStatus_t statusMask
);
447 * rtk_ptp_portIntStatus_get
449 * Get PTP port interrupt trigger status.
451 * port - physical port
453 * pStatusMask - Interrupt status bit mask.
456 * RT_ERR_FAILED - Failed
457 * RT_ERR_SMI - SMI access error
458 * RT_ERR_INPUT - Invalid input parameters.
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))
472 extern rtk_api_ret_t
rtk_ptp_portIntStatus_get(rtk_port_t port
, rtk_ptp_intStatus_t
*pStatusMask
);
475 * rtk_ptp_portPtpTrap_set
477 * Set PTP packet trap of the specified port.
486 * RT_ERR_PORT - invalid port id
487 * RT_ERR_INPUT - invalid input parameter
491 extern rtk_api_ret_t
rtk_ptp_portTrap_set(rtk_port_t port
, rtk_enable_t enable
);
494 * rtk_ptp_portPtpEnable_get
496 * Get PTP packet trap of the specified port.
504 * RT_ERR_PORT - invalid port id
505 * RT_ERR_NULL_POINTER - input parameter may be null pointer
509 extern rtk_api_ret_t
rtk_ptp_portTrap_get(rtk_port_t port
, rtk_enable_t
*pEnable
);
511 #endif /* __RTK_API_PTP_H__ */