forked from Joyist2021/gl-infra-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0010-kernel-fix-mac-increment.patch
86 lines (83 loc) · 2.34 KB
/
0010-kernel-fix-mac-increment.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From f30e6c611cf8dcdb2c695124427063177e5517bb Mon Sep 17 00:00:00 2001
From: Jianhui Zhao <[email protected]>
Date: Mon, 26 Apr 2021 15:43:29 +0800
Subject: [PATCH 09/26] kernel: fix mac increment
Signed-off-by: Jianhui Zhao <[email protected]>
---
.../pending-4.14/954-fix-mac-increment.patch | 66 +++++++++++++++++++
1 file changed, 66 insertions(+)
create mode 100644 target/linux/generic/pending-4.14/954-fix-mac-increment.patch
diff --git a/target/linux/generic/pending-4.14/954-fix-mac-increment.patch b/target/linux/generic/pending-4.14/954-fix-mac-increment.patch
new file mode 100644
index 0000000000..554068113b
--- /dev/null
+++ b/target/linux/generic/pending-4.14/954-fix-mac-increment.patch
@@ -0,0 +1,66 @@
+--- a/drivers/of/of_net.c
++++ b/drivers/of/of_net.c
+@@ -12,6 +12,41 @@
+ #include <linux/export.h>
+ #include <linux/mtd/mtd.h>
+
++#ifndef CHAR_BIT
++ #define CHAR_BIT 8
++#endif
++
++/** Convert hex mac address to uint64_t
++ * @param[in] hwaddr hex mac address
++ * @return mac address as uint64_t
++ */
++static uint64_t mac2int(const uint8_t hwaddr[])
++{
++ int8_t i;
++ uint64_t ret = 0;
++ const uint8_t *p = hwaddr;
++
++ for (i = 5; i >= 0; i--) {
++ ret |= (uint64_t) *p++ << (CHAR_BIT * i);
++ }
++
++ return ret;
++}
++
++/** Convert uint64_t mac address to hex
++ * @param[in] mac uint64_t mac address
++ * @param[out] hwaddr hex mac address
++ */
++static void int2mac(const uint64_t mac, uint8_t *hwaddr)
++{
++ int8_t i;
++ uint8_t *p = hwaddr;
++
++ for (i = 5; i >= 0; i--) {
++ *p++ = mac >> (CHAR_BIT * i);
++ }
++}
++
+ /**
+ * of_get_phy_mode - Get phy mode for given device_node
+ * @np: Pointer to the given device_node
+@@ -60,6 +95,7 @@ static const void *of_get_mac_address_mt
+ const __be32 *list;
+ phandle phandle;
+ u32 mac_inc = 0;
++ uint64_t mac_int = 0;
+ u8 mac[ETH_ALEN];
+ void *addr;
+ u32 inc_idx;
+@@ -91,8 +127,11 @@ static const void *of_get_mac_address_mt
+ if (inc_idx > 5)
+ return NULL;
+
+- if (!of_property_read_u32(np, "mtd-mac-address-increment", &mac_inc))
+- mac[inc_idx] += mac_inc;
++ if (!of_property_read_u32(np, "mtd-mac-address-increment", &mac_inc)){
++ mac_int = mac2int(mac);
++ mac_int += mac_inc << ((5-inc_idx) * CHAR_BIT);
++ int2mac(mac_int,mac);
++ }
+
+ if (!is_valid_ether_addr(mac))
+ return NULL;
--
2.17.1