summaryrefslogtreecommitdiff
path: root/recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis_t30-tk1-igb-no-nvm-and-Ethernet-MAC-address-h.patch
blob: cd53bc6f340c4e2b8a21131c2301909cca86119f (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
From 259b864ce38d18f7de945f957ee2e11ea4429812 Mon Sep 17 00:00:00 2001
From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Date: Thu, 15 Dec 2016 10:55:54 +0100
Subject: [PATCH 3/4] apalis_t30/tk1: igb: no nvm and Ethernet MAC address
 handling

Only warn rather than fail on NVM validation failures on Apalis T30 and
Apalis TK1.

Revise Ethernet MAC address assignment: should now handle up to two
instances of custom user MACs (2nd one with a 0x100000 offset). This
way customer does not have to worry about NVM on a secondary Ethernet
on the carrier board and still gets a valid official MAC address from
us (e.g. analogous to how we did it on our Protea carrier board).

Use the Toradex OUI as default MAC address if no valid one is
encountered.

Tested on samples of Apalis T30 2GB V1.0B, V1.0C, V1.1A, Apalis T30 1GB
V1.0A, V1.1A and Apalis T30 1GB IT V1.1A both with blank NVMs as well
as iNVMs programmed with Intel's defaults.

Tested on samples of Apalis TK1 2GB V1.0A, V1.0B and V1.1A both with
blank NVMs as well as iNVMs programmed with Intel's defaults.

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Acked-by: Dominik Sliwa <dominik.sliwa@toradex.com>

(cherry picked from toradex_tk1_l4t_r21.5 commit
70efa60d96c9f05d91d8875eee97446df7f9e877)
(cherry picked from tegra commit
c4c3c7449bdb15c53bfebb0a29c73b24ea810d23)

---

 drivers/net/ethernet/intel/igb/igb_main.c | 60 +++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 680abcd..3df0e4e 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -55,6 +55,7 @@
 #include <linux/dca.h>
 #endif
 #include <linux/i2c.h>
+#include <linux/ctype.h>
 #include "igb.h"
 
 #define MAJ 5
@@ -69,6 +70,9 @@ static const char igb_driver_string[] =
 static const char igb_copyright[] =
 				"Copyright (c) 2007-2014 Intel Corporation.";
 
+static char g_mac_addr[ETH_ALEN];
+static int g_usr_mac = 0;
+
 static const struct e1000_info *igb_info_tbl[] = {
 	[board_82575] = &e1000_82575_info,
 };
@@ -258,6 +262,37 @@ static int debug = -1;
 module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
 
+/* Retrieve user set MAC address */
+static int __init setup_igb_mac(char *macstr)
+{
+	int i, j;
+	unsigned char result, value;
+
+	for (i = 0; i < ETH_ALEN; i++) {
+		result = 0;
+
+		if (i != 5 && *(macstr + 2) != ':')
+			return -1;
+
+		for (j = 0; j < 2; j++) {
+			if (isxdigit(*macstr) && (value = isdigit(*macstr) ?
+			    *macstr - '0' : toupper(*macstr) - 'A' + 10) < 16) {
+				result = result * 16 + value;
+				macstr++;
+			} else
+				return -1;
+		}
+
+		macstr++;
+		g_mac_addr[i] = result;
+	}
+
+	g_usr_mac = 1;
+
+	return 0;
+}
+__setup("igb_mac=", setup_igb_mac);
+
 struct igb_reg_info {
 	u32 ofs;
 	char *name;
@@ -2511,12 +2546,31 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 			dev_err(&pdev->dev, "NVM Read Error\n");
 	}
 
+	if (g_usr_mac && (g_usr_mac < 3)) {
+		/* Get user set MAC address */
+		if (g_usr_mac == 2) {
+			/* 0x100000 offset for 2nd Ethernet MAC */
+			g_mac_addr[3] += 0x10;
+			if (g_mac_addr[3] < 0x10)
+				dev_warn(&pdev->dev,
+					 "MAC addr byte 3 (0x%02x) wrap around"
+					 "\n",
+					 g_mac_addr[3]);
+		}
+		memcpy(hw->mac.addr, g_mac_addr, ETH_ALEN);
+		g_usr_mac++;
+	}
+
 	memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
 
 	if (!is_valid_ether_addr(netdev->dev_addr)) {
-		dev_err(&pdev->dev, "Invalid MAC Address\n");
-		err = -EIO;
-		goto err_eeprom;
+		/* Use Toradex OUI as default */
+		char default_mac_addr[ETH_ALEN] = {
+			0x0, 0x14, 0x2d, 0x0, 0x0, 0x0
+		};
+		dev_warn(&pdev->dev, "using Toradex OUI as default igb MAC\n");
+		memcpy(hw->mac.addr, default_mac_addr, ETH_ALEN);
+		memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
 	}
 
 	/* get firmware version for ethtool -i */
-- 
2.9.3