1 /* Broadcom NetXtreme-C/E network driver.
2  *
3  * Copyright (c) 2021 Broadcom Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation.
8  */
9 
10 #ifndef BNXT_PTP_H
11 #define BNXT_PTP_H
12 
13 #define BNXT_PTP_GRC_WIN	5
14 #define BNXT_PTP_GRC_WIN_BASE	0x5000
15 
16 #define BNXT_MAX_PHC_DRIFT	31000000
17 #define BNXT_LO_TIMER_MASK	0x0000ffffffffUL
18 #define BNXT_HI_TIMER_MASK	0xffff00000000UL
19 
20 #define BNXT_PTP_QTS_TIMEOUT	1000
21 #define BNXT_PTP_QTS_TX_ENABLES	(PORT_TS_QUERY_REQ_ENABLES_PTP_SEQ_ID |	\
22 				 PORT_TS_QUERY_REQ_ENABLES_TS_REQ_TIMEOUT)
23 
24 struct bnxt_ptp_cfg {
25 	struct ptp_clock_info	ptp_info;
26 	struct ptp_clock	*ptp_clock;
27 	struct cyclecounter	cc;
28 	struct timecounter	tc;
29 	/* serialize timecounter access */
30 	spinlock_t		ptp_lock;
31 	struct sk_buff		*tx_skb;
32 	u64			current_time;
33 	u64			old_time;
34 	unsigned long		next_period;
35 	u16			tx_seqid;
36 	struct bnxt		*bp;
37 	atomic_t		tx_avail;
38 #define BNXT_MAX_TX_TS	1
39 	u16			rxctl;
40 #define BNXT_PTP_MSG_SYNC			(1 << 0)
41 #define BNXT_PTP_MSG_DELAY_REQ			(1 << 1)
42 #define BNXT_PTP_MSG_PDELAY_REQ			(1 << 2)
43 #define BNXT_PTP_MSG_PDELAY_RESP		(1 << 3)
44 #define BNXT_PTP_MSG_FOLLOW_UP			(1 << 8)
45 #define BNXT_PTP_MSG_DELAY_RESP			(1 << 9)
46 #define BNXT_PTP_MSG_PDELAY_RESP_FOLLOW_UP	(1 << 10)
47 #define BNXT_PTP_MSG_ANNOUNCE			(1 << 11)
48 #define BNXT_PTP_MSG_SIGNALING			(1 << 12)
49 #define BNXT_PTP_MSG_MANAGEMENT			(1 << 13)
50 #define BNXT_PTP_MSG_EVENTS		(BNXT_PTP_MSG_SYNC |		\
51 					 BNXT_PTP_MSG_DELAY_REQ |	\
52 					 BNXT_PTP_MSG_PDELAY_REQ |	\
53 					 BNXT_PTP_MSG_PDELAY_RESP)
54 	u8			tx_tstamp_en:1;
55 	int			rx_filter;
56 
57 	u32			refclk_regs[2];
58 	u32			refclk_mapped_regs[2];
59 };
60 
61 #if BITS_PER_LONG == 32
62 #define BNXT_READ_TIME64(ptp, dst, src)		\
63 do {						\
64 	spin_lock_bh(&(ptp)->ptp_lock);		\
65 	(dst) = (src);				\
66 	spin_unlock_bh(&(ptp)->ptp_lock);	\
67 } while (0)
68 #else
69 #define BNXT_READ_TIME64(ptp, dst, src)		\
70 	((dst) = READ_ONCE(src))
71 #endif
72 
73 int bnxt_ptp_parse(struct sk_buff *skb, u16 *seq_id);
74 int bnxt_hwtstamp_set(struct net_device *dev, struct ifreq *ifr);
75 int bnxt_hwtstamp_get(struct net_device *dev, struct ifreq *ifr);
76 int bnxt_get_tx_ts_p5(struct bnxt *bp, struct sk_buff *skb);
77 int bnxt_get_rx_ts_p5(struct bnxt *bp, u64 *ts, u32 pkt_ts);
78 int bnxt_ptp_init(struct bnxt *bp);
79 void bnxt_ptp_clear(struct bnxt *bp);
80 #endif
81