1 From dd8b8f6baf4917124ed268022f7ce4a08d35cc89 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Wed, 20 Nov 2019 16:23:15 +0800
4 Subject: [PATCH] net: mscc: ocelot: convert to use ocelot_get_txtstamp()
6 The method getting TX timestamp by reading timestamp FIFO and
7 matching skbs list is common for DSA Felix driver too.
8 So move code out of ocelot_board.c, convert to use
9 ocelot_get_txtstamp() function and export it.
11 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
12 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
13 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
16 drivers/net/ethernet/mscc/ocelot.c | 62 ++++++++++++++++++++++++++++++--
17 drivers/net/ethernet/mscc/ocelot.h | 6 ----
18 drivers/net/ethernet/mscc/ocelot_board.c | 53 +--------------------------
19 include/soc/mscc/ocelot.h | 9 ++++-
20 4 files changed, 69 insertions(+), 61 deletions(-)
22 --- a/drivers/net/ethernet/mscc/ocelot.c
23 +++ b/drivers/net/ethernet/mscc/ocelot.c
24 @@ -661,7 +661,8 @@ out:
28 -void ocelot_get_hwtimestamp(struct ocelot *ocelot, struct timespec64 *ts)
29 +static void ocelot_get_hwtimestamp(struct ocelot *ocelot,
30 + struct timespec64 *ts)
34 @@ -686,7 +687,64 @@ void ocelot_get_hwtimestamp(struct ocelo
36 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
38 -EXPORT_SYMBOL(ocelot_get_hwtimestamp);
40 +void ocelot_get_txtstamp(struct ocelot *ocelot)
42 + int budget = OCELOT_PTP_QUEUE_SZ;
45 + struct skb_shared_hwtstamps shhwtstamps;
46 + struct list_head *pos, *tmp;
47 + struct sk_buff *skb = NULL;
48 + struct ocelot_skb *entry;
49 + struct ocelot_port *port;
50 + struct timespec64 ts;
51 + u32 val, id, txport;
53 + val = ocelot_read(ocelot, SYS_PTP_STATUS);
55 + /* Check if a timestamp can be retrieved */
56 + if (!(val & SYS_PTP_STATUS_PTP_MESS_VLD))
59 + WARN_ON(val & SYS_PTP_STATUS_PTP_OVFL);
61 + /* Retrieve the ts ID and Tx port */
62 + id = SYS_PTP_STATUS_PTP_MESS_ID_X(val);
63 + txport = SYS_PTP_STATUS_PTP_MESS_TXPORT_X(val);
65 + /* Retrieve its associated skb */
66 + port = ocelot->ports[txport];
68 + list_for_each_safe(pos, tmp, &port->skbs) {
69 + entry = list_entry(pos, struct ocelot_skb, head);
70 + if (entry->id != id)
80 + ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT);
85 + /* Get the h/w timestamp */
86 + ocelot_get_hwtimestamp(ocelot, &ts);
88 + /* Set the timestamp into the skb */
89 + memset(&shhwtstamps, 0, sizeof(shhwtstamps));
90 + shhwtstamps.hwtstamp = ktime_set(ts.tv_sec, ts.tv_nsec);
91 + skb_tstamp_tx(skb, &shhwtstamps);
93 + dev_kfree_skb_any(skb);
96 +EXPORT_SYMBOL(ocelot_get_txtstamp);
98 static int ocelot_mc_unsync(struct net_device *dev, const unsigned char *addr)
100 --- a/drivers/net/ethernet/mscc/ocelot.h
101 +++ b/drivers/net/ethernet/mscc/ocelot.h
102 @@ -74,12 +74,6 @@ struct ocelot_port_private {
103 struct ocelot_port_tc tc;
107 - struct list_head head;
108 - struct sk_buff *skb;
112 u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
113 void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
115 --- a/drivers/net/ethernet/mscc/ocelot_board.c
116 +++ b/drivers/net/ethernet/mscc/ocelot_board.c
117 @@ -198,60 +198,9 @@ static irqreturn_t ocelot_xtr_irq_handle
119 static irqreturn_t ocelot_ptp_rdy_irq_handler(int irq, void *arg)
121 - int budget = OCELOT_PTP_QUEUE_SZ;
122 struct ocelot *ocelot = arg;
125 - struct skb_shared_hwtstamps shhwtstamps;
126 - struct list_head *pos, *tmp;
127 - struct sk_buff *skb = NULL;
128 - struct ocelot_skb *entry;
129 - struct ocelot_port *port;
130 - struct timespec64 ts;
131 - u32 val, id, txport;
133 - val = ocelot_read(ocelot, SYS_PTP_STATUS);
135 - /* Check if a timestamp can be retrieved */
136 - if (!(val & SYS_PTP_STATUS_PTP_MESS_VLD))
139 - WARN_ON(val & SYS_PTP_STATUS_PTP_OVFL);
141 - /* Retrieve the ts ID and Tx port */
142 - id = SYS_PTP_STATUS_PTP_MESS_ID_X(val);
143 - txport = SYS_PTP_STATUS_PTP_MESS_TXPORT_X(val);
145 - /* Retrieve its associated skb */
146 - port = ocelot->ports[txport];
148 - list_for_each_safe(pos, tmp, &port->skbs) {
149 - entry = list_entry(pos, struct ocelot_skb, head);
150 - if (entry->id != id)
160 - ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT);
162 - if (unlikely(!skb))
165 - /* Get the h/w timestamp */
166 - ocelot_get_hwtimestamp(ocelot, &ts);
168 - /* Set the timestamp into the skb */
169 - memset(&shhwtstamps, 0, sizeof(shhwtstamps));
170 - shhwtstamps.hwtstamp = ktime_set(ts.tv_sec, ts.tv_nsec);
171 - skb_tstamp_tx(skb, &shhwtstamps);
173 - dev_kfree_skb_any(skb);
175 + ocelot_get_txtstamp(ocelot);
179 --- a/include/soc/mscc/ocelot.h
180 +++ b/include/soc/mscc/ocelot.h
181 @@ -406,6 +406,13 @@ struct ocelot_ops {
182 int (*reset)(struct ocelot *ocelot);
186 + struct list_head head;
187 + struct sk_buff *skb;
193 struct ocelot *ocelot;
195 @@ -536,6 +543,6 @@ int ocelot_vlan_del(struct ocelot *ocelo
196 int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr);
197 int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr);
198 int ocelot_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts);
199 -void ocelot_get_hwtimestamp(struct ocelot *ocelot, struct timespec64 *ts);
200 +void ocelot_get_txtstamp(struct ocelot *ocelot);