95d8aaf6f0f64461a1fc486fa3f89031f343ee04
[oweals/openwrt.git] / target / linux / layerscape / patches-4.9 / 202-core-linux-support-layerscape.patch
1 From 67a2eceebe9dcd92a1a5f3e912340c8975c84434 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Wed, 17 Jan 2018 14:50:41 +0800
4 Subject: [PATCH 02/30] core-linux: support layerscape
5
6 This is an integrated patch for layerscape core-linux support.
7
8 Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
9 Signed-off-by: Zhao Qiang <qiang.zhao@nxp.com>
10 Signed-off-by: Camelia Groza <camelia.groza@nxp.com>
11 Signed-off-by: Madalin Bucur <madalin.bucur@nxp.com>
12 Signed-off-by: Zhang Ying-22455 <ying.zhang22455@nxp.com>
13 Signed-off-by: Ramneek Mehresh <ramneek.mehresh@freescale.com>
14 Signed-off-by: Jarod Wilson <jarod@redhat.com>
15 Signed-off-by: Nikhil Badola <nikhil.badola@freescale.com>
16 Signed-off-by: stephen hemminger <stephen@networkplumber.org>
17 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
18 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
19 ---
20  drivers/base/devres.c           | 66 ++++++++++++++++++++++++++++
21  drivers/base/soc.c              | 70 +++++++++++++++++++++++++++++
22  include/linux/device.h          | 19 ++++++++
23  include/linux/fsl/svr.h         | 97 +++++++++++++++++++++++++++++++++++++++++
24  include/linux/fsl_devices.h     |  3 ++
25  include/linux/netdev_features.h |  2 +
26  include/linux/netdevice.h       |  4 ++
27  include/linux/skbuff.h          |  2 +
28  include/linux/sys_soc.h         |  3 ++
29  include/uapi/linux/if_ether.h   |  1 +
30  net/core/dev.c                  | 13 +++++-
31  net/core/skbuff.c               | 29 +++++++++++-
32  net/sched/sch_generic.c         |  7 +++
33  13 files changed, 313 insertions(+), 3 deletions(-)
34  create mode 100644 include/linux/fsl/svr.h
35
36 --- a/drivers/base/devres.c
37 +++ b/drivers/base/devres.c
38 @@ -10,6 +10,7 @@
39  #include <linux/device.h>
40  #include <linux/module.h>
41  #include <linux/slab.h>
42 +#include <linux/percpu.h>
43  
44  #include "base.h"
45  
46 @@ -985,3 +986,68 @@ void devm_free_pages(struct device *dev,
47                                &devres));
48  }
49  EXPORT_SYMBOL_GPL(devm_free_pages);
50 +
51 +static void devm_percpu_release(struct device *dev, void *pdata)
52 +{
53 +       void __percpu *p;
54 +
55 +       p = *(void __percpu **)pdata;
56 +       free_percpu(p);
57 +}
58 +
59 +static int devm_percpu_match(struct device *dev, void *data, void *p)
60 +{
61 +       struct devres *devr = container_of(data, struct devres, data);
62 +
63 +       return *(void **)devr->data == p;
64 +}
65 +
66 +/**
67 + * __devm_alloc_percpu - Resource-managed alloc_percpu
68 + * @dev: Device to allocate per-cpu memory for
69 + * @size: Size of per-cpu memory to allocate
70 + * @align: Alignment of per-cpu memory to allocate
71 + *
72 + * Managed alloc_percpu. Per-cpu memory allocated with this function is
73 + * automatically freed on driver detach.
74 + *
75 + * RETURNS:
76 + * Pointer to allocated memory on success, NULL on failure.
77 + */
78 +void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
79 +               size_t align)
80 +{
81 +       void *p;
82 +       void __percpu *pcpu;
83 +
84 +       pcpu = __alloc_percpu(size, align);
85 +       if (!pcpu)
86 +               return NULL;
87 +
88 +       p = devres_alloc(devm_percpu_release, sizeof(void *), GFP_KERNEL);
89 +       if (!p) {
90 +               free_percpu(pcpu);
91 +               return NULL;
92 +       }
93 +
94 +       *(void __percpu **)p = pcpu;
95 +
96 +       devres_add(dev, p);
97 +
98 +       return pcpu;
99 +}
100 +EXPORT_SYMBOL_GPL(__devm_alloc_percpu);
101 +
102 +/**
103 + * devm_free_percpu - Resource-managed free_percpu
104 + * @dev: Device this memory belongs to
105 + * @pdata: Per-cpu memory to free
106 + *
107 + * Free memory allocated with devm_alloc_percpu().
108 + */
109 +void devm_free_percpu(struct device *dev, void __percpu *pdata)
110 +{
111 +       WARN_ON(devres_destroy(dev, devm_percpu_release, devm_percpu_match,
112 +                              (void *)pdata));
113 +}
114 +EXPORT_SYMBOL_GPL(devm_free_percpu);
115 --- a/drivers/base/soc.c
116 +++ b/drivers/base/soc.c
117 @@ -13,6 +13,7 @@
118  #include <linux/spinlock.h>
119  #include <linux/sys_soc.h>
120  #include <linux/err.h>
121 +#include <linux/glob.h>
122  
123  static DEFINE_IDA(soc_ida);
124  
125 @@ -161,3 +162,72 @@ static int __init soc_bus_register(void)
126         return bus_register(&soc_bus_type);
127  }
128  core_initcall(soc_bus_register);
129 +
130 +static int soc_device_match_one(struct device *dev, void *arg)
131 +{
132 +       struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
133 +       const struct soc_device_attribute *match = arg;
134 +
135 +       if (match->machine &&
136 +           (!soc_dev->attr->machine ||
137 +            !glob_match(match->machine, soc_dev->attr->machine)))
138 +               return 0;
139 +
140 +       if (match->family &&
141 +           (!soc_dev->attr->family ||
142 +            !glob_match(match->family, soc_dev->attr->family)))
143 +               return 0;
144 +
145 +       if (match->revision &&
146 +           (!soc_dev->attr->revision ||
147 +            !glob_match(match->revision, soc_dev->attr->revision)))
148 +               return 0;
149 +
150 +       if (match->soc_id &&
151 +           (!soc_dev->attr->soc_id ||
152 +            !glob_match(match->soc_id, soc_dev->attr->soc_id)))
153 +               return 0;
154 +
155 +       return 1;
156 +}
157 +
158 +/*
159 + * soc_device_match - identify the SoC in the machine
160 + * @matches: zero-terminated array of possible matches
161 + *
162 + * returns the first matching entry of the argument array, or NULL
163 + * if none of them match.
164 + *
165 + * This function is meant as a helper in place of of_match_node()
166 + * in cases where either no device tree is available or the information
167 + * in a device node is insufficient to identify a particular variant
168 + * by its compatible strings or other properties. For new devices,
169 + * the DT binding should always provide unique compatible strings
170 + * that allow the use of of_match_node() instead.
171 + *
172 + * The calling function can use the .data entry of the
173 + * soc_device_attribute to pass a structure or function pointer for
174 + * each entry.
175 + */
176 +const struct soc_device_attribute *soc_device_match(
177 +       const struct soc_device_attribute *matches)
178 +{
179 +       int ret = 0;
180 +
181 +       if (!matches)
182 +               return NULL;
183 +
184 +       while (!ret) {
185 +               if (!(matches->machine || matches->family ||
186 +                     matches->revision || matches->soc_id))
187 +                       break;
188 +               ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches,
189 +                                      soc_device_match_one);
190 +               if (!ret)
191 +                       matches++;
192 +               else
193 +                       return matches;
194 +       }
195 +       return NULL;
196 +}
197 +EXPORT_SYMBOL_GPL(soc_device_match);
198 --- a/include/linux/device.h
199 +++ b/include/linux/device.h
200 @@ -688,6 +688,25 @@ void __iomem *devm_ioremap_resource(stru
201  int devm_add_action(struct device *dev, void (*action)(void *), void *data);
202  void devm_remove_action(struct device *dev, void (*action)(void *), void *data);
203  
204 +/**
205 + * devm_alloc_percpu - Resource-managed alloc_percpu
206 + * @dev: Device to allocate per-cpu memory for
207 + * @type: Type to allocate per-cpu memory for
208 + *
209 + * Managed alloc_percpu. Per-cpu memory allocated with this function is
210 + * automatically freed on driver detach.
211 + *
212 + * RETURNS:
213 + * Pointer to allocated memory on success, NULL on failure.
214 + */
215 +#define devm_alloc_percpu(dev, type)      \
216 +       ((typeof(type) __percpu *)__devm_alloc_percpu((dev), sizeof(type), \
217 +                                                     __alignof__(type)))
218 +
219 +void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
220 +                                  size_t align);
221 +void devm_free_percpu(struct device *dev, void __percpu *pdata);
222 +
223  static inline int devm_add_action_or_reset(struct device *dev,
224                                            void (*action)(void *), void *data)
225  {
226 --- /dev/null
227 +++ b/include/linux/fsl/svr.h
228 @@ -0,0 +1,97 @@
229 +/*
230 + * MPC85xx cpu type detection
231 + *
232 + * Copyright 2011-2012 Freescale Semiconductor, Inc.
233 + *
234 + * This is free software; you can redistribute it and/or modify
235 + * it under the terms of the GNU General Public License as published by
236 + * the Free Software Foundation; either version 2 of the License, or
237 + * (at your option) any later version.
238 + */
239 +
240 +#ifndef FSL_SVR_H
241 +#define FSL_SVR_H
242 +
243 +#define SVR_REV(svr)   ((svr) & 0xFF)          /* SOC design resision */
244 +#define SVR_MAJ(svr)   (((svr) >>  4) & 0xF)   /* Major revision field*/
245 +#define SVR_MIN(svr)   (((svr) >>  0) & 0xF)   /* Minor revision field*/
246 +
247 +/* Some parts define SVR[0:23] as the SOC version */
248 +#define SVR_SOC_VER(svr) (((svr) >> 8) & 0xFFF7FF)     /* SOC Version fields */
249 +
250 +#define SVR_8533       0x803400
251 +#define SVR_8535       0x803701
252 +#define SVR_8536       0x803700
253 +#define SVR_8540       0x803000
254 +#define SVR_8541       0x807200
255 +#define SVR_8543       0x803200
256 +#define SVR_8544       0x803401
257 +#define SVR_8545       0x803102
258 +#define SVR_8547       0x803101
259 +#define SVR_8548       0x803100
260 +#define SVR_8555       0x807100
261 +#define SVR_8560       0x807000
262 +#define SVR_8567       0x807501
263 +#define SVR_8568       0x807500
264 +#define SVR_8569       0x808000
265 +#define SVR_8572       0x80E000
266 +#define SVR_P1010      0x80F100
267 +#define SVR_P1011      0x80E500
268 +#define SVR_P1012      0x80E501
269 +#define SVR_P1013      0x80E700
270 +#define SVR_P1014      0x80F101
271 +#define SVR_P1017      0x80F700
272 +#define SVR_P1020      0x80E400
273 +#define SVR_P1021      0x80E401
274 +#define SVR_P1022      0x80E600
275 +#define SVR_P1023      0x80F600
276 +#define SVR_P1024      0x80E402
277 +#define SVR_P1025      0x80E403
278 +#define SVR_P2010      0x80E300
279 +#define SVR_P2020      0x80E200
280 +#define SVR_P2040      0x821000
281 +#define SVR_P2041      0x821001
282 +#define SVR_P3041      0x821103
283 +#define SVR_P4040      0x820100
284 +#define SVR_P4080      0x820000
285 +#define SVR_P5010      0x822100
286 +#define SVR_P5020      0x822000
287 +#define SVR_P5021      0X820500
288 +#define SVR_P5040      0x820400
289 +#define SVR_T4240      0x824000
290 +#define SVR_T4120      0x824001
291 +#define SVR_T4160      0x824100
292 +#define SVR_T4080      0x824102
293 +#define SVR_C291       0x850000
294 +#define SVR_C292       0x850020
295 +#define SVR_C293       0x850030
296 +#define SVR_B4860      0X868000
297 +#define SVR_G4860      0x868001
298 +#define SVR_G4060      0x868003
299 +#define SVR_B4440      0x868100
300 +#define SVR_G4440      0x868101
301 +#define SVR_B4420      0x868102
302 +#define SVR_B4220      0x868103
303 +#define SVR_T1040      0x852000
304 +#define SVR_T1041      0x852001
305 +#define SVR_T1042      0x852002
306 +#define SVR_T1020      0x852100
307 +#define SVR_T1021      0x852101
308 +#define SVR_T1022      0x852102
309 +#define SVR_T1023      0x854100
310 +#define SVR_T1024      0x854000
311 +#define SVR_T2080      0x853000
312 +#define SVR_T2081      0x853100
313 +
314 +#define SVR_8610       0x80A000
315 +#define SVR_8641       0x809000
316 +#define SVR_8641D      0x809001
317 +
318 +#define SVR_9130       0x860001
319 +#define SVR_9131       0x860000
320 +#define SVR_9132       0x861000
321 +#define SVR_9232       0x861400
322 +
323 +#define SVR_Unknown    0xFFFFFF
324 +
325 +#endif
326 --- a/include/linux/fsl_devices.h
327 +++ b/include/linux/fsl_devices.h
328 @@ -99,7 +99,10 @@ struct fsl_usb2_platform_data {
329         unsigned        suspended:1;
330         unsigned        already_suspended:1;
331         unsigned        has_fsl_erratum_a007792:1;
332 +       unsigned        has_fsl_erratum_14:1;
333         unsigned        has_fsl_erratum_a005275:1;
334 +       unsigned        has_fsl_erratum_a006918:1;
335 +       unsigned        has_fsl_erratum_a005697:1;
336         unsigned        check_phy_clk_valid:1;
337  
338         /* register save area for suspend/resume */
339 --- a/include/linux/netdev_features.h
340 +++ b/include/linux/netdev_features.h
341 @@ -76,6 +76,7 @@ enum {
342         NETIF_F_BUSY_POLL_BIT,          /* Busy poll */
343  
344         NETIF_F_HW_TC_BIT,              /* Offload TC infrastructure */
345 +       NETIF_F_HW_ACCEL_MQ_BIT,        /* Hardware-accelerated multiqueue */
346  
347         /*
348          * Add your fresh new feature above and remember to update
349 @@ -138,6 +139,7 @@ enum {
350  #define NETIF_F_HW_L2FW_DOFFLOAD       __NETIF_F(HW_L2FW_DOFFLOAD)
351  #define NETIF_F_BUSY_POLL      __NETIF_F(BUSY_POLL)
352  #define NETIF_F_HW_TC          __NETIF_F(HW_TC)
353 +#define NETIF_F_HW_ACCEL_MQ    __NETIF_F(HW_ACCEL_MQ)
354  
355  /* Finds the next feature with the highest number of the range of start till 0.
356   */
357 --- a/include/linux/netdevice.h
358 +++ b/include/linux/netdevice.h
359 @@ -1512,6 +1512,8 @@ enum netdev_priv_flags {
360   *     @if_port:       Selectable AUI, TP, ...
361   *     @dma:           DMA channel
362   *     @mtu:           Interface MTU value
363 + *     @min_mtu:       Interface Minimum MTU value
364 + *     @max_mtu:       Interface Maximum MTU value
365   *     @type:          Interface hardware type
366   *     @hard_header_len: Maximum hardware header length.
367   *     @min_header_len:  Minimum hardware header length
368 @@ -1738,6 +1740,8 @@ struct net_device {
369         unsigned char           dma;
370  
371         unsigned int            mtu;
372 +       unsigned int            min_mtu;
373 +       unsigned int            max_mtu;
374         unsigned short          type;
375         unsigned short          hard_header_len;
376         unsigned short          min_header_len;
377 --- a/include/linux/skbuff.h
378 +++ b/include/linux/skbuff.h
379 @@ -908,6 +908,7 @@ void kfree_skb(struct sk_buff *skb);
380  void kfree_skb_list(struct sk_buff *segs);
381  void skb_tx_error(struct sk_buff *skb);
382  void consume_skb(struct sk_buff *skb);
383 +void skb_recycle(struct sk_buff *skb);
384  void  __kfree_skb(struct sk_buff *skb);
385  extern struct kmem_cache *skbuff_head_cache;
386  
387 @@ -3082,6 +3083,7 @@ static inline void skb_free_datagram_loc
388  }
389  int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags);
390  int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len);
391 +void copy_skb_header(struct sk_buff *new, const struct sk_buff *old);
392  int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len);
393  __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, u8 *to,
394                               int len, __wsum csum);
395 --- a/include/linux/sys_soc.h
396 +++ b/include/linux/sys_soc.h
397 @@ -13,6 +13,7 @@ struct soc_device_attribute {
398         const char *family;
399         const char *revision;
400         const char *soc_id;
401 +       const void *data;
402  };
403  
404  /**
405 @@ -34,4 +35,6 @@ void soc_device_unregister(struct soc_de
406   */
407  struct device *soc_device_to_device(struct soc_device *soc);
408  
409 +const struct soc_device_attribute *soc_device_match(
410 +       const struct soc_device_attribute *matches);
411  #endif /* __SOC_BUS_H */
412 --- a/include/uapi/linux/if_ether.h
413 +++ b/include/uapi/linux/if_ether.h
414 @@ -35,6 +35,7 @@
415  #define ETH_DATA_LEN   1500            /* Max. octets in payload        */
416  #define ETH_FRAME_LEN  1514            /* Max. octets in frame sans FCS */
417  #define ETH_FCS_LEN    4               /* Octets in the FCS             */
418 +#define ETH_MIN_MTU    68              /* Min IPv4 MTU per RFC791      */
419  
420  /*
421   *     These are the defined Ethernet Protocol ID's.
422 --- a/net/core/dev.c
423 +++ b/net/core/dev.c
424 @@ -6659,9 +6659,18 @@ int dev_set_mtu(struct net_device *dev,
425         if (new_mtu == dev->mtu)
426                 return 0;
427  
428 -       /*      MTU must be positive.    */
429 -       if (new_mtu < 0)
430 +       /* MTU must be positive, and in range */
431 +       if (new_mtu < 0 || new_mtu < dev->min_mtu) {
432 +               net_err_ratelimited("%s: Invalid MTU %d requested, hw min %d\n",
433 +                                   dev->name, new_mtu, dev->min_mtu);
434                 return -EINVAL;
435 +       }
436 +
437 +       if (dev->max_mtu > 0 && new_mtu > dev->max_mtu) {
438 +               net_err_ratelimited("%s: Invalid MTU %d requested, hw max %d\n",
439 +                                   dev->name, new_mtu, dev->min_mtu);
440 +               return -EINVAL;
441 +       }
442  
443         if (!netif_device_present(dev))
444                 return -ENODEV;
445 --- a/net/core/skbuff.c
446 +++ b/net/core/skbuff.c
447 @@ -846,6 +846,32 @@ void napi_consume_skb(struct sk_buff *sk
448  }
449  EXPORT_SYMBOL(napi_consume_skb);
450  
451 +/**
452 + *     skb_recycle - clean up an skb for reuse
453 + *     @skb: buffer
454 + *
455 + *     Recycles the skb to be reused as a receive buffer. This
456 + *     function does any necessary reference count dropping, and
457 + *     cleans up the skbuff as if it just came from __alloc_skb().
458 + */
459 +void skb_recycle(struct sk_buff *skb)
460 +{
461 +       struct skb_shared_info *shinfo;
462 +       u8 head_frag = skb->head_frag;
463 +
464 +       skb_release_head_state(skb);
465 +
466 +       shinfo = skb_shinfo(skb);
467 +       memset(shinfo, 0, offsetof(struct skb_shared_info, dataref));
468 +       atomic_set(&shinfo->dataref, 1);
469 +
470 +       memset(skb, 0, offsetof(struct sk_buff, tail));
471 +       skb->data = skb->head + NET_SKB_PAD;
472 +       skb->head_frag = head_frag;
473 +       skb_reset_tail_pointer(skb);
474 +}
475 +EXPORT_SYMBOL(skb_recycle);
476 +
477  /* Make sure a field is enclosed inside headers_start/headers_end section */
478  #define CHECK_SKB_FIELD(field) \
479         BUILD_BUG_ON(offsetof(struct sk_buff, field) <          \
480 @@ -1079,7 +1105,7 @@ static void skb_headers_offset_update(st
481         skb->inner_mac_header += off;
482  }
483  
484 -static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
485 +void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
486  {
487         __copy_skb_header(new, old);
488  
489 @@ -1087,6 +1113,7 @@ static void copy_skb_header(struct sk_bu
490         skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
491         skb_shinfo(new)->gso_type = skb_shinfo(old)->gso_type;
492  }
493 +EXPORT_SYMBOL(copy_skb_header);
494  
495  static inline int skb_alloc_rx_flag(const struct sk_buff *skb)
496  {
497 --- a/net/sched/sch_generic.c
498 +++ b/net/sched/sch_generic.c
499 @@ -309,6 +309,13 @@ static void dev_watchdog(unsigned long a
500                                         txq->trans_timeout++;
501                                         break;
502                                 }
503 +
504 +                               /* Devices with HW_ACCEL_MQ have multiple txqs
505 +                                * but update only the first one's transmission
506 +                                * timestamp so avoid checking the rest.
507 +                                */
508 +                               if (dev->features & NETIF_F_HW_ACCEL_MQ)
509 +                                       break;
510                         }
511  
512                         if (some_queue_timedout) {