202-core-linux-support-layerscape.patch 15 KB

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