layerscape: add patches-5.4
[openwrt/staging/hauke.git] / target / linux / layerscape / patches-5.4 / 701-net-0266-net-mscc-ocelot-convert-to-use-ocelot_get_txtstamp.patch
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()
5
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.
10
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>
15 ---
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(-)
21
22 --- a/drivers/net/ethernet/mscc/ocelot.c
23 +++ b/drivers/net/ethernet/mscc/ocelot.c
24 @@ -661,7 +661,8 @@ out:
25 return NETDEV_TX_OK;
26 }
27
28 -void ocelot_get_hwtimestamp(struct ocelot *ocelot, struct timespec64 *ts)
29 +static void ocelot_get_hwtimestamp(struct ocelot *ocelot,
30 + struct timespec64 *ts)
31 {
32 unsigned long flags;
33 u32 val;
34 @@ -686,7 +687,64 @@ void ocelot_get_hwtimestamp(struct ocelo
35
36 spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
37 }
38 -EXPORT_SYMBOL(ocelot_get_hwtimestamp);
39 +
40 +void ocelot_get_txtstamp(struct ocelot *ocelot)
41 +{
42 + int budget = OCELOT_PTP_QUEUE_SZ;
43 +
44 + while (budget--) {
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;
52 +
53 + val = ocelot_read(ocelot, SYS_PTP_STATUS);
54 +
55 + /* Check if a timestamp can be retrieved */
56 + if (!(val & SYS_PTP_STATUS_PTP_MESS_VLD))
57 + break;
58 +
59 + WARN_ON(val & SYS_PTP_STATUS_PTP_OVFL);
60 +
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);
64 +
65 + /* Retrieve its associated skb */
66 + port = ocelot->ports[txport];
67 +
68 + list_for_each_safe(pos, tmp, &port->skbs) {
69 + entry = list_entry(pos, struct ocelot_skb, head);
70 + if (entry->id != id)
71 + continue;
72 +
73 + skb = entry->skb;
74 +
75 + list_del(pos);
76 + kfree(entry);
77 + }
78 +
79 + /* Next ts */
80 + ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT);
81 +
82 + if (unlikely(!skb))
83 + continue;
84 +
85 + /* Get the h/w timestamp */
86 + ocelot_get_hwtimestamp(ocelot, &ts);
87 +
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);
92 +
93 + dev_kfree_skb_any(skb);
94 + }
95 +}
96 +EXPORT_SYMBOL(ocelot_get_txtstamp);
97
98 static int ocelot_mc_unsync(struct net_device *dev, const unsigned char *addr)
99 {
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;
104 };
105
106 -struct ocelot_skb {
107 - struct list_head head;
108 - struct sk_buff *skb;
109 - u8 id;
110 -};
111 -
112 u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
113 void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
114
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
118
119 static irqreturn_t ocelot_ptp_rdy_irq_handler(int irq, void *arg)
120 {
121 - int budget = OCELOT_PTP_QUEUE_SZ;
122 struct ocelot *ocelot = arg;
123
124 - while (budget--) {
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;
132 -
133 - val = ocelot_read(ocelot, SYS_PTP_STATUS);
134 -
135 - /* Check if a timestamp can be retrieved */
136 - if (!(val & SYS_PTP_STATUS_PTP_MESS_VLD))
137 - break;
138 -
139 - WARN_ON(val & SYS_PTP_STATUS_PTP_OVFL);
140 -
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);
144 -
145 - /* Retrieve its associated skb */
146 - port = ocelot->ports[txport];
147 -
148 - list_for_each_safe(pos, tmp, &port->skbs) {
149 - entry = list_entry(pos, struct ocelot_skb, head);
150 - if (entry->id != id)
151 - continue;
152 -
153 - skb = entry->skb;
154 -
155 - list_del(pos);
156 - kfree(entry);
157 - }
158 -
159 - /* Next ts */
160 - ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT);
161 -
162 - if (unlikely(!skb))
163 - continue;
164 -
165 - /* Get the h/w timestamp */
166 - ocelot_get_hwtimestamp(ocelot, &ts);
167 -
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);
172 -
173 - dev_kfree_skb_any(skb);
174 - }
175 + ocelot_get_txtstamp(ocelot);
176
177 return IRQ_HANDLED;
178 }
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);
183 };
184
185 +struct ocelot_skb {
186 + struct list_head head;
187 + struct sk_buff *skb;
188 + u8 id;
189 +};
190 +
191 +
192 struct ocelot_port {
193 struct ocelot *ocelot;
194
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);
201
202 #endif