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
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.
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.
17 Joint work with Alexei Starovoitov.
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>
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(-)
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,
38 static void pch_gbe_set_multi(struct net_device *netdev);
40 -static struct sock_filter ptp_filter[] = {
44 static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
47 @@ -131,7 +127,7 @@ static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
51 - if (sk_run_filter(skb, ptp_filter) == PTP_CLASS_NONE)
52 + if (ptp_classify_raw(skb) == PTP_CLASS_NONE)
55 offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
56 @@ -2635,11 +2631,6 @@ static int pch_gbe_probe(struct pci_dev *pdev,
58 adapter->ptp_pdev = pci_get_bus_and_slot(adapter->pdev->bus->number,
60 - if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
61 - dev_err(&pdev->dev, "Bad ptp filter\n");
63 - goto err_free_netdev;
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
76 -static struct sock_filter ptp_filter[] = {
80 #define cpts_read32(c, r) __raw_readl(&c->reg->r)
81 #define cpts_write32(c, v, r) __raw_writel(v, &c->reg->r)
83 @@ -301,7 +297,7 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type)
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);
92 @@ -372,10 +368,6 @@ int cpts_register(struct device *dev, struct cpts *cpts,
96 - if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
97 - pr_err("cpts: bad ptp filter\n");
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;
111 -static struct sock_filter ptp_filter[] = {
115 static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
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)
122 - if (sk_run_filter(skb, ptp_filter) != PTP_CLASS_V1_IPV4)
123 + if (ptp_classify_raw(skb) != PTP_CLASS_V1_IPV4)
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];
131 - if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
132 - pr_err("ixp4xx_eth: bad ptp filter\n");
136 if (!(dev = alloc_etherdev(sizeof(struct port))))
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
144 #define OP_RETA (BPF_RET | BPF_A)
145 #define OP_RETK (BPF_RET | BPF_K)
147 -static inline int ptp_filter_init(struct sock_filter *f, int len)
149 - if (OP_LDH == f[0].code)
150 - return sk_chk_filter(f, len);
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 },
162 +unsigned int ptp_classify_raw(const struct sk_buff *skb);
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
171 static struct sk_filter *ptp_insns __read_mostly;
173 +unsigned int ptp_classify_raw(const struct sk_buff *skb)
175 + return SK_RUN_FILTER(ptp_insns, skb);
177 +EXPORT_SYMBOL_GPL(ptp_classify_raw);
179 static unsigned int classify(const struct sk_buff *skb)
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);
186 return PTP_CLASS_NONE;