From 934ba9a81ce07365edb96fcbf227783d0372bdb9 Mon Sep 17 00:00:00 2001 Message-Id: <934ba9a81ce07365edb96fcbf227783d0372bdb9.1531317141.git.marcel.ziswiler@toradex.com> In-Reply-To: <6654e1bd342708a683daf47e7558455f709a3e7e.1531317141.git.marcel.ziswiler@toradex.com> References: <6654e1bd342708a683daf47e7558455f709a3e7e.1531317141.git.marcel.ziswiler@toradex.com> From: Marcel Ziswiler Date: Thu, 15 Dec 2016 10:55:54 +0100 Subject: [PATCH 04/33] 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 Acked-by: Dominik Sliwa (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 94ac43034033..e9d6a8742826 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -55,6 +55,7 @@ #include #endif #include +#include #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, }; @@ -259,6 +263,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; @@ -2521,12 +2556,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); } igb_set_default_mac_filter(adapter); -- 2.14.4