1 From e7e0b3b89da97e3186fbe3774a1ca9b77402d893 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Wed, 27 Nov 2019 15:27:57 +0800
4 Subject: [PATCH] net: mscc: ocelot: use skb queue instead of skbs list
6 Convert to use skb queue instead of the list of skbs.
7 The skb queue could provide protection with lock.
9 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
10 Signed-off-by: David S. Miller <davem@davemloft.net>
12 drivers/net/ethernet/mscc/ocelot.c | 54 +++++++++++++-------------------------
13 include/soc/mscc/ocelot.h | 9 +------
14 2 files changed, 19 insertions(+), 44 deletions(-)
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
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);
25 - if (unlikely(!oskb))
28 shinfo->tx_flags |= SKBTX_IN_PROGRESS;
31 - oskb->id = ocelot_port->ts_id % 4;
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);
40 @@ -704,12 +696,11 @@ void ocelot_get_txtstamp(struct ocelot *
41 int budget = OCELOT_PTP_QUEUE_SZ;
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;
51 + unsigned long flags;
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];
59 - list_for_each_safe(pos, tmp, &port->skbs) {
60 - entry = list_entry(pos, struct ocelot_skb, head);
61 - if (entry->id != id)
63 + spin_lock_irqsave(&port->tx_skbs.lock, flags);
69 + skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) {
70 + if (skb->cb[0] != id)
72 + __skb_unlink(skb, &port->tx_skbs);
77 + spin_unlock_irqrestore(&port->tx_skbs.lock, flags);
80 ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT);
83 + if (unlikely(!skb_match))
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);
94 - dev_kfree_skb_any(skb);
95 + dev_kfree_skb_any(skb_match);
98 EXPORT_SYMBOL(ocelot_get_txtstamp);
99 @@ -2205,7 +2196,7 @@ void ocelot_init_port(struct ocelot *oce
101 struct ocelot_port *ocelot_port = ocelot->ports[port];
103 - INIT_LIST_HEAD(&ocelot_port->skbs);
104 + skb_queue_head_init(&ocelot_port->tx_skbs);
106 /* Basic L2 initialization */
108 @@ -2490,9 +2481,7 @@ EXPORT_SYMBOL(ocelot_init);
110 void ocelot_deinit(struct ocelot *ocelot)
112 - struct list_head *pos, *tmp;
113 struct ocelot_port *port;
114 - struct ocelot_skb *entry;
117 cancel_delayed_work(&ocelot->stats_work);
118 @@ -2504,14 +2493,7 @@ void ocelot_deinit(struct ocelot *ocelot
120 for (i = 0; i < ocelot->num_phys_ports; i++) {
121 port = ocelot->ports[i];
123 - list_for_each_safe(pos, tmp, &port->skbs) {
124 - entry = list_entry(pos, struct ocelot_skb, head);
127 - dev_kfree_skb_any(entry->skb);
130 + skb_queue_purge(&port->tx_skbs);
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);
141 - struct list_head head;
142 - struct sk_buff *skb;
148 struct ocelot *ocelot;
150 @@ -425,7 +418,7 @@ struct ocelot_port {
154 - struct list_head skbs;
155 + struct sk_buff_head tx_skbs;