988c90e79d4008c99a20f53263663fd9234afd25
[openwrt/staging/ynezz.git] /
1 From c0c92f8d9a093faf64397b1874f074e071a5b4e2 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Wed, 20 Nov 2019 16:23:16 +0800
4 Subject: [PATCH] net: mscc: ocelot: convert to use
5 ocelot_port_add_txtstamp_skb()
6
7 Convert to use ocelot_port_add_txtstamp_skb() for adding skbs which
8 require TX timestamp into list. Export it so that DSA Felix driver
9 could reuse it too.
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 | 43 ++++++++++++++++++++++++--------------
17 include/soc/mscc/ocelot.h | 2 ++
18 2 files changed, 29 insertions(+), 16 deletions(-)
19
20 --- a/drivers/net/ethernet/mscc/ocelot.c
21 +++ b/drivers/net/ethernet/mscc/ocelot.c
22 @@ -575,6 +575,32 @@ static int ocelot_gen_ifh(u32 *ifh, stru
23 return 0;
24 }
25
26 +int ocelot_port_add_txtstamp_skb(struct ocelot_port *ocelot_port,
27 + struct sk_buff *skb)
28 +{
29 + struct skb_shared_info *shinfo = skb_shinfo(skb);
30 + struct ocelot *ocelot = ocelot_port->ocelot;
31 +
32 + if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP &&
33 + ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) {
34 + struct ocelot_skb *oskb =
35 + kzalloc(sizeof(struct ocelot_skb), GFP_ATOMIC);
36 +
37 + if (unlikely(!oskb))
38 + return -ENOMEM;
39 +
40 + shinfo->tx_flags |= SKBTX_IN_PROGRESS;
41 +
42 + oskb->skb = skb;
43 + oskb->id = ocelot_port->ts_id % 4;
44 +
45 + list_add_tail(&oskb->head, &ocelot_port->skbs);
46 + return 0;
47 + }
48 + return -ENODATA;
49 +}
50 +EXPORT_SYMBOL(ocelot_port_add_txtstamp_skb);
51 +
52 static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
53 {
54 struct ocelot_port_private *priv = netdev_priv(dev);
55 @@ -637,26 +663,11 @@ static int ocelot_port_xmit(struct sk_bu
56 dev->stats.tx_packets++;
57 dev->stats.tx_bytes += skb->len;
58
59 - if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP &&
60 - ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) {
61 - struct ocelot_skb *oskb =
62 - kzalloc(sizeof(struct ocelot_skb), GFP_ATOMIC);
63 -
64 - if (unlikely(!oskb))
65 - goto out;
66 -
67 - skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
68 -
69 - oskb->skb = skb;
70 - oskb->id = ocelot_port->ts_id % 4;
71 + if (!ocelot_port_add_txtstamp_skb(ocelot_port, skb)) {
72 ocelot_port->ts_id++;
73 -
74 - list_add_tail(&oskb->head, &ocelot_port->skbs);
75 -
76 return NETDEV_TX_OK;
77 }
78
79 -out:
80 dev_kfree_skb_any(skb);
81 return NETDEV_TX_OK;
82 }
83 --- a/include/soc/mscc/ocelot.h
84 +++ b/include/soc/mscc/ocelot.h
85 @@ -543,6 +543,8 @@ int ocelot_vlan_del(struct ocelot *ocelo
86 int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr);
87 int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr);
88 int ocelot_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts);
89 +int ocelot_port_add_txtstamp_skb(struct ocelot_port *ocelot_port,
90 + struct sk_buff *skb);
91 void ocelot_get_txtstamp(struct ocelot *ocelot);
92
93 #endif