Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp526614img; Thu, 28 Feb 2019 03:44:19 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib23EEmQzdkhQCRu9DFZOVYaIURkQr/9+o92oGhBkA15ub+r79nptPrg5pXmBHP/tsu17Dr X-Received: by 2002:aa7:9211:: with SMTP id 17mr6907611pfo.220.1551354259859; Thu, 28 Feb 2019 03:44:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551354259; cv=none; d=google.com; s=arc-20160816; b=C2BGLAZwVTQb4N0DArAVrNHVLcYAvhQsnm8HDqFfRNYs2fw32IKbyQMXHSGRUJDZSp LoV/4HBeRU2bH7VYbJc1iH8xJwzXb9g4KYJSQYDK+OfOY7Dchi3AihGFJymMoLp+u7Uv AHtb3XcQFh8rhDflgosTl62X1EjzHqEy28tJZ7i1CBeM3+r6VgJzAkfFMTo32G0vdI/d XJrzl6xezwC0YyuMjFGXqScea5FsGsYBZX4NTIn4fj06fZVZQ7vPKLD0UMq1sqNVDqXx FW58etKMOPd6Cv2Ia+tjl9fGV3NlKjEh7dWbx6KpjvSPgzk+zWTj1isgrdtgSFqZbDKz afDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=7Cxwxo7xoBxQl4tNStd5bPwXMz5T4r3/hLuMLDPuyG4=; b=D3YiAJFVoZNM1hX8jxY7LbiNQitgNGMBmhJdW4eSex/1vj4gnksr/Lh1lnWmE1Fknu VKQxNls3ngm839ceOX4BfvpGMFEHiHzX6lp6knvQJ0gP6JSDO/oSksG6PaCQRHgRD1uE c4XhK9dJF+XP4t6Ag7tKuyl3SzGcqzmyGLzMD2HkWksvTOsnJj4jw1YvTRJmxi95UajN JZ03nEFiqko4Vov/ytdUQmMx3A0Nx20gCiAL+NWMnIbyxwedSymCL41qklP66iB0B3eT sT2DvgMfmNnrtCr6TM6LuCTtNiSjBzpjMZsIsyCJrsR5tnvFdn/ispADfin9OgFZOFqd LBFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si17201636pgm.541.2019.02.28.03.44.04; Thu, 28 Feb 2019 03:44:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731032AbfB1JUy (ORCPT + 99 others); Thu, 28 Feb 2019 04:20:54 -0500 Received: from smtp.asem.it ([151.1.184.197]:64947 "EHLO smtp.asem.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726717AbfB1JUy (ORCPT ); Thu, 28 Feb 2019 04:20:54 -0500 Received: from webmail.asem.it by asem.it (smtp.asem.it) (SecurityGateway 5.5.0) with ESMTP id SG003722240.MSG for ; Thu, 28 Feb 2019 10:20:50 +0100S Received: from ASAS044.asem.intra (172.16.16.44) by ASAS044.asem.intra (172.16.16.44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Thu, 28 Feb 2019 10:20:50 +0100 Received: from flavio-x.asem.intra (172.16.17.161) by ASAS044.asem.intra (172.16.16.44) with Microsoft SMTP Server id 15.1.1261.35 via Frontend Transport; Thu, 28 Feb 2019 10:20:50 +0100 From: Flavio Suligoi To: Jeff Kirsher , "David S . Miller" , , , CC: Flavio Suligoi Subject: [PATCH] net: e1000e: add MAC address kernel cmd line parameter Date: Thu, 28 Feb 2019 10:20:35 +0100 Message-ID: <1551345635-10291-1-git-send-email-f.suligoi@asem.it> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-SGHeloLookup-Result: pass smtp.helo=webmail.asem.it (ip=172.16.16.44) X-SGSPF-Result: none (smtp.asem.it) X-SGOP-RefID: str=0001.0A0B020E.5C77A7F2.006E,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 (_st=1 _vt=0 _iwf=0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes, in some embedded systems boards (i.e. ARM boards), the NVM eeprom is not mounted, to save cost and space. In this case it is necessary to bypass the NVM management and directly force the MAC address using a kernel command-line parameter (macaddr). Signed-off-by: Flavio Suligoi --- drivers/net/ethernet/intel/e1000e/netdev.c | 50 ++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c index 189f231..054c398 100644 --- a/drivers/net/ethernet/intel/e1000e/netdev.c +++ b/drivers/net/ethernet/intel/e1000e/netdev.c @@ -39,6 +39,10 @@ static int debug = -1; module_param(debug, int, 0); MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); +static unsigned char macaddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; +module_param_array(macaddr, byte, NULL, 0); +MODULE_PARM_DESC(macaddr, "e1000e Ethernet MAC address"); + static const struct e1000_info *e1000_info_tbl[] = { [board_82571] = &e1000_82571_info, [board_82572] = &e1000_82572_info, @@ -7053,6 +7057,7 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) static int cards_found; u16 aspm_disable_flag = 0; int bars, i, err, pci_using_dac; + u16 eeprom_data = 0; u16 eeprom_apme_mask = E1000_EEPROM_APME; s32 ret_val = 0; @@ -7232,27 +7237,38 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) */ adapter->hw.mac.ops.reset_hw(&adapter->hw); - /* systems with ASPM and others may see the checksum fail on the first - * attempt. Let's give it a few tries - */ - for (i = 0;; i++) { - if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) - break; - if (i == 2) { - dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n"); - err = -EIO; - goto err_eeprom; + /* If the MAC address is supplied by the bootloader, use it! */ + if (!is_multicast_ether_addr(macaddr)) { + dev_info(&pdev->dev, + "MAC address from kernel command line argument\n"); + memcpy(adapter->hw.mac.addr, macaddr, netdev->addr_len); + memcpy(netdev->dev_addr, macaddr, netdev->addr_len); + } else { + /* systems with ASPM and others may see the checksum fail on + * the first attempt. Let's give it a few tries + */ + dev_info(&pdev->dev, "MAC address from NVM\n"); + for (i = 0;; i++) { + if (e1000_validate_nvm_checksum(&adapter->hw) >= 0) + break; + if (i == 2) { + dev_err(&pdev->dev, + "The NVM Checksum Is Not Valid\n"); + err = -EIO; + goto err_eeprom; + } } - } - e1000_eeprom_checks(adapter); + e1000_eeprom_checks(adapter); - /* copy the MAC address */ - if (e1000e_read_mac_addr(&adapter->hw)) - dev_err(&pdev->dev, - "NVM Read Error while reading MAC address\n"); + /* copy the MAC address */ + if (e1000e_read_mac_addr(&adapter->hw)) + dev_err(&pdev->dev, + "NVM Read Error while reading MAC address\n"); - memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len); + memcpy(netdev->dev_addr, adapter->hw.mac.addr, + netdev->addr_len); + } if (!is_valid_ether_addr(netdev->dev_addr)) { dev_err(&pdev->dev, "Invalid MAC Address: %pM\n", -- 2.7.4