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

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