blob: 9dda1e7b897c75b5a8bc8d03cfd8a3f328203ef7 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From e7e0b3b89da97e3186fbe3774a1ca9b77402d893 Mon Sep 17 00:00:00 2001
2From: Yangbo Lu <yangbo.lu@nxp.com>
3Date: Wed, 27 Nov 2019 15:27:57 +0800
4Subject: [PATCH] net: mscc: ocelot: use skb queue instead of skbs list
5
6Convert to use skb queue instead of the list of skbs.
7The skb queue could provide protection with lock.
8
9Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
10Signed-off-by: David S. Miller <davem@davemloft.net>
11---
12 drivers/net/ethernet/mscc/ocelot.c | 54 +++++++++++++-------------------------
13 include/soc/mscc/ocelot.h | 9 +------
14 2 files changed, 19 insertions(+), 44 deletions(-)
15
16--- a/drivers/net/ethernet/mscc/ocelot.c
17+++ b/drivers/net/ethernet/mscc/ocelot.c
18@@ -583,18 +583,10 @@ int ocelot_port_add_txtstamp_skb(struct
19
20 if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP &&
21 ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) {
22- struct ocelot_skb *oskb =
23- kzalloc(sizeof(struct ocelot_skb), GFP_ATOMIC);
24-
25- if (unlikely(!oskb))
26- return -ENOMEM;
27-
28 shinfo->tx_flags |= SKBTX_IN_PROGRESS;
29-
30- oskb->skb = skb;
31- oskb->id = ocelot_port->ts_id % 4;
32-
33- list_add_tail(&oskb->head, &ocelot_port->skbs);
34+ /* Store timestamp ID in cb[0] of sk_buff */
35+ skb->cb[0] = ocelot_port->ts_id % 4;
36+ skb_queue_tail(&ocelot_port->tx_skbs, skb);
37 return 0;
38 }
39 return -ENODATA;
40@@ -704,12 +696,11 @@ void ocelot_get_txtstamp(struct ocelot *
41 int budget = OCELOT_PTP_QUEUE_SZ;
42
43 while (budget--) {
44+ struct sk_buff *skb, *skb_tmp, *skb_match = NULL;
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+ unsigned long flags;
52 u32 val, id, txport;
53
54 val = ocelot_read(ocelot, SYS_PTP_STATUS);
55@@ -727,22 +718,22 @@ void ocelot_get_txtstamp(struct ocelot *
56 /* Retrieve its associated skb */
57 port = ocelot->ports[txport];
58
59- list_for_each_safe(pos, tmp, &port->skbs) {
60- entry = list_entry(pos, struct ocelot_skb, head);
61- if (entry->id != id)
62- continue;
63+ spin_lock_irqsave(&port->tx_skbs.lock, flags);
64
65- skb = entry->skb;
66-
67- list_del(pos);
68- kfree(entry);
69+ skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) {
70+ if (skb->cb[0] != id)
71+ continue;
72+ __skb_unlink(skb, &port->tx_skbs);
73+ skb_match = skb;
74 break;
75 }
76
77+ spin_unlock_irqrestore(&port->tx_skbs.lock, flags);
78+
79 /* Next ts */
80 ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT);
81
82- if (unlikely(!skb))
83+ if (unlikely(!skb_match))
84 continue;
85
86 /* Get the h/w timestamp */
87@@ -751,9 +742,9 @@ void ocelot_get_txtstamp(struct ocelot *
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+ skb_tstamp_tx(skb_match, &shhwtstamps);
93
94- dev_kfree_skb_any(skb);
95+ dev_kfree_skb_any(skb_match);
96 }
97 }
98 EXPORT_SYMBOL(ocelot_get_txtstamp);
99@@ -2205,7 +2196,7 @@ void ocelot_init_port(struct ocelot *oce
100 {
101 struct ocelot_port *ocelot_port = ocelot->ports[port];
102
103- INIT_LIST_HEAD(&ocelot_port->skbs);
104+ skb_queue_head_init(&ocelot_port->tx_skbs);
105
106 /* Basic L2 initialization */
107
108@@ -2494,9 +2485,7 @@ EXPORT_SYMBOL(ocelot_init);
109
110 void ocelot_deinit(struct ocelot *ocelot)
111 {
112- struct list_head *pos, *tmp;
113 struct ocelot_port *port;
114- struct ocelot_skb *entry;
115 int i;
116
117 cancel_delayed_work(&ocelot->stats_work);
118@@ -2508,14 +2497,7 @@ void ocelot_deinit(struct ocelot *ocelot
119
120 for (i = 0; i < ocelot->num_phys_ports; i++) {
121 port = ocelot->ports[i];
122-
123- list_for_each_safe(pos, tmp, &port->skbs) {
124- entry = list_entry(pos, struct ocelot_skb, head);
125-
126- list_del(pos);
127- dev_kfree_skb_any(entry->skb);
128- kfree(entry);
129- }
130+ skb_queue_purge(&port->tx_skbs);
131 }
132 }
133 EXPORT_SYMBOL(ocelot_deinit);
134--- a/include/soc/mscc/ocelot.h
135+++ b/include/soc/mscc/ocelot.h
136@@ -406,13 +406,6 @@ struct ocelot_ops {
137 int (*reset)(struct ocelot *ocelot);
138 };
139
140-struct ocelot_skb {
141- struct list_head head;
142- struct sk_buff *skb;
143- u8 id;
144-};
145-
146-
147 struct ocelot_port {
148 struct ocelot *ocelot;
149
150@@ -425,7 +418,7 @@ struct ocelot_port {
151 u16 vid;
152
153 u8 ptp_cmd;
154- struct list_head skbs;
155+ struct sk_buff_head tx_skbs;
156 u8 ts_id;
157 };
158