1 /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
2 /*
3  * DSA driver for:
4  * Hirschmann Hellcreek TSN switch.
5  *
6  * Copyright (C) 2019,2020 Hochschule Offenburg
7  * Copyright (C) 2019,2020 Linutronix GmbH
8  * Authors: Kurt Kanzenbach <kurt@linutronix.de>
9  *	    Kamil Alkhouri <kamil.alkhouri@hs-offenburg.de>
10  */
11 
12 #ifndef _HELLCREEK_HWTSTAMP_H_
13 #define _HELLCREEK_HWTSTAMP_H_
14 
15 #include <net/dsa.h>
16 #include "hellcreek.h"
17 
18 /* Timestamp Register */
19 #define PR_TS_RX_P1_STATUS_C	(0x1d * 2)
20 #define PR_TS_RX_P1_DATA_C	(0x1e * 2)
21 #define PR_TS_TX_P1_STATUS_C	(0x1f * 2)
22 #define PR_TS_TX_P1_DATA_C	(0x20 * 2)
23 #define PR_TS_RX_P2_STATUS_C	(0x25 * 2)
24 #define PR_TS_RX_P2_DATA_C	(0x26 * 2)
25 #define PR_TS_TX_P2_STATUS_C	(0x27 * 2)
26 #define PR_TS_TX_P2_DATA_C	(0x28 * 2)
27 
28 #define PR_TS_STATUS_TS_AVAIL	BIT(2)
29 #define PR_TS_STATUS_TS_LOST	BIT(3)
30 
31 #define SKB_PTP_TYPE(__skb) (*(unsigned int *)((__skb)->cb))
32 
33 /* TX_TSTAMP_TIMEOUT: This limits the time spent polling for a TX
34  * timestamp. When working properly, hardware will produce a timestamp
35  * within 1ms. Software may enounter delays, so the timeout is set
36  * accordingly.
37  */
38 #define TX_TSTAMP_TIMEOUT	msecs_to_jiffies(40)
39 
40 int hellcreek_port_hwtstamp_set(struct dsa_switch *ds, int port,
41 				struct ifreq *ifr);
42 int hellcreek_port_hwtstamp_get(struct dsa_switch *ds, int port,
43 				struct ifreq *ifr);
44 
45 bool hellcreek_port_rxtstamp(struct dsa_switch *ds, int port,
46 			     struct sk_buff *clone, unsigned int type);
47 void hellcreek_port_txtstamp(struct dsa_switch *ds, int port,
48 			     struct sk_buff *skb);
49 
50 int hellcreek_get_ts_info(struct dsa_switch *ds, int port,
51 			  struct ethtool_ts_info *info);
52 
53 long hellcreek_hwtstamp_work(struct ptp_clock_info *ptp);
54 
55 int hellcreek_hwtstamp_setup(struct hellcreek *chip);
56 void hellcreek_hwtstamp_free(struct hellcreek *chip);
57 
58 #endif /* _HELLCREEK_HWTSTAMP_H_ */
59