meta-tizen: neard: add Tizen patches
[scm/bb/tizen-distro.git] / meta-tizen / meta-tizen-adaptation / meta / recipes-kernel / linux / linux-yocto / 0001-net-ptp-do-not-reimplement-PTP-BPF-classifier.patch
1 From 164d8c6665213c931645578310256da7b1259331 Mon Sep 17 00:00:00 2001
2 From: Daniel Borkmann <dborkman@redhat.com>
3 Date: Fri, 28 Mar 2014 18:58:22 +0100
4 Subject: [PATCH] meta-tizen: net: ptp: do not reimplement PTP/BPF classifier
5
6 There are currently pch_gbe, cpts, and ixp4xx_eth drivers that open-code
7 and reimplement a BPF classifier for the PTP protocol. Since all of them
8 effectively do the very same thing and load the very same PTP/BPF filter,
9 we can just consolidate that code by introducing ptp_classify_raw() in
10 the time-stamping core framework which can be used in drivers.
11
12 As drivers get initialized after bootstrapping the core networking
13 subsystem, they can make use of ptp_insns wrapped through
14 ptp_classify_raw(), which allows to simplify and remove PTP classifier
15 setup code in drivers.
16
17 Joint work with Alexei Starovoitov.
18
19 Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
20 Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
21 Cc: Richard Cochran <richard.cochran@omicron.at>
22 Cc: Jiri Benc <jbenc@redhat.com>
23 Signed-off-by: David S. Miller <davem@davemloft.net>
24 ---
25  drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 11 +----------
26  drivers/net/ethernet/ti/cpts.c                       | 10 +---------
27  drivers/net/ethernet/xscale/ixp4xx_eth.c             | 11 +----------
28  include/linux/ptp_classify.h                         | 10 ++--------
29  net/core/timestamping.c                              |  8 +++++++-
30  5 files changed, 12 insertions(+), 38 deletions(-)
31
32 diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
33 index 464e910..73e6683 100644
34 --- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
35 +++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
36 @@ -120,10 +120,6 @@ static void pch_gbe_mdio_write(struct net_device *netdev, int addr, int reg,
37                                int data);
38  static void pch_gbe_set_multi(struct net_device *netdev);
39  
40 -static struct sock_filter ptp_filter[] = {
41 -       PTP_FILTER
42 -};
43 -
44  static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
45  {
46         u8 *data = skb->data;
47 @@ -131,7 +127,7 @@ static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
48         u16 *hi, *id;
49         u32 lo;
50  
51 -       if (sk_run_filter(skb, ptp_filter) == PTP_CLASS_NONE)
52 +       if (ptp_classify_raw(skb) == PTP_CLASS_NONE)
53                 return 0;
54  
55         offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
56 @@ -2635,11 +2631,6 @@ static int pch_gbe_probe(struct pci_dev *pdev,
57  
58         adapter->ptp_pdev = pci_get_bus_and_slot(adapter->pdev->bus->number,
59                                                PCI_DEVFN(12, 4));
60 -       if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
61 -               dev_err(&pdev->dev, "Bad ptp filter\n");
62 -               ret = -EINVAL;
63 -               goto err_free_netdev;
64 -       }
65  
66         netdev->netdev_ops = &pch_gbe_netdev_ops;
67         netdev->watchdog_timeo = PCH_GBE_WATCHDOG_PERIOD;
68 diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
69 index 372cb19..a3bbf59 100644
70 --- a/drivers/net/ethernet/ti/cpts.c
71 +++ b/drivers/net/ethernet/ti/cpts.c
72 @@ -31,10 +31,6 @@
73  
74  #ifdef CONFIG_TI_CPTS
75  
76 -static struct sock_filter ptp_filter[] = {
77 -       PTP_FILTER
78 -};
79 -
80  #define cpts_read32(c, r)      __raw_readl(&c->reg->r)
81  #define cpts_write32(c, v, r)  __raw_writel(v, &c->reg->r)
82  
83 @@ -301,7 +297,7 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type)
84         u64 ns = 0;
85         struct cpts_event *event;
86         struct list_head *this, *next;
87 -       unsigned int class = sk_run_filter(skb, ptp_filter);
88 +       unsigned int class = ptp_classify_raw(skb);
89         unsigned long flags;
90         u16 seqid;
91         u8 mtype;
92 @@ -372,10 +368,6 @@ int cpts_register(struct device *dev, struct cpts *cpts,
93         int err, i;
94         unsigned long flags;
95  
96 -       if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
97 -               pr_err("cpts: bad ptp filter\n");
98 -               return -EINVAL;
99 -       }
100         cpts->info = cpts_info;
101         cpts->clock = ptp_clock_register(&cpts->info, dev);
102         if (IS_ERR(cpts->clock)) {
103 diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
104 index 25283f1..f7e0f0f 100644
105 --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
106 +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
107 @@ -256,10 +256,6 @@ static int ports_open;
108  static struct port *npe_port_tab[MAX_NPES];
109  static struct dma_pool *dma_pool;
110  
111 -static struct sock_filter ptp_filter[] = {
112 -       PTP_FILTER
113 -};
114 -
115  static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
116  {
117         u8 *data = skb->data;
118 @@ -267,7 +263,7 @@ static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
119         u16 *hi, *id;
120         u32 lo;
121  
122 -       if (sk_run_filter(skb, ptp_filter) != PTP_CLASS_V1_IPV4)
123 +       if (ptp_classify_raw(skb) != PTP_CLASS_V1_IPV4)
124                 return 0;
125  
126         offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
127 @@ -1413,11 +1409,6 @@ static int eth_init_one(struct platform_device *pdev)
128         char phy_id[MII_BUS_ID_SIZE + 3];
129         int err;
130  
131 -       if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
132 -               pr_err("ixp4xx_eth: bad ptp filter\n");
133 -               return -EINVAL;
134 -       }
135 -
136         if (!(dev = alloc_etherdev(sizeof(struct port))))
137                 return -ENOMEM;
138  
139 diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h
140 index 3decfa4..6d3b0a2 100644
141 --- a/include/linux/ptp_classify.h
142 +++ b/include/linux/ptp_classify.h
143 @@ -80,14 +80,6 @@
144  #define OP_RETA        (BPF_RET | BPF_A)
145  #define OP_RETK        (BPF_RET | BPF_K)
146  
147 -static inline int ptp_filter_init(struct sock_filter *f, int len)
148 -{
149 -       if (OP_LDH == f[0].code)
150 -               return sk_chk_filter(f, len);
151 -       else
152 -               return 0;
153 -}
154 -
155  #define PTP_FILTER \
156         {OP_LDH,        0,   0, OFF_ETYPE               }, /*              */ \
157         {OP_JEQ,        0,  12, ETH_P_IP                }, /* f goto L20   */ \
158 @@ -133,4 +125,6 @@ static inline int ptp_filter_init(struct sock_filter *f, int len)
159         {OP_RETA,       0,   0, 0                       }, /*              */ \
160  /*L6x*/        {OP_RETK,       0,   0, PTP_CLASS_NONE          },
161  
162 +unsigned int ptp_classify_raw(const struct sk_buff *skb);
163 +
164  #endif
165 diff --git a/net/core/timestamping.c b/net/core/timestamping.c
166 index e43d56a..9ff26b3 100644
167 --- a/net/core/timestamping.c
168 +++ b/net/core/timestamping.c
169 @@ -25,11 +25,17 @@
170  
171  static struct sk_filter *ptp_insns __read_mostly;
172  
173 +unsigned int ptp_classify_raw(const struct sk_buff *skb)
174 +{
175 +       return SK_RUN_FILTER(ptp_insns, skb);
176 +}
177 +EXPORT_SYMBOL_GPL(ptp_classify_raw);
178 +
179  static unsigned int classify(const struct sk_buff *skb)
180  {
181         if (likely(skb->dev && skb->dev->phydev &&
182                    skb->dev->phydev->drv))
183 -               return SK_RUN_FILTER(ptp_insns, skb);
184 +               return ptp_classify_raw(skb);
185         else
186                 return PTP_CLASS_NONE;
187  }
188 -- 
189 1.8.1.4
190