Message ID | 20221130174259.1591567-1-bmasney@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1063517wrr; Wed, 30 Nov 2022 09:46:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf47TsppGgI6pavF3D6FBZvEtuCeJUGWkvtmt6qJXlOdXSoIT2VYZFRuulDjBPvXXcA0HrDB X-Received: by 2002:aa7:cb07:0:b0:463:ca19:6cdf with SMTP id s7-20020aa7cb07000000b00463ca196cdfmr12057442edt.379.1669830395338; Wed, 30 Nov 2022 09:46:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669830395; cv=none; d=google.com; s=arc-20160816; b=Zg0LHUsoleblJ+hkACCrzlZIs7MAYNllTLODKoskNf73JK9sw9PiAnjugQV6ygjujF KC+ykigf9dTiOsmLQJZedKpDMhdlH/TA9zm+n8cXrWExE44ejsXpEGZRNEZ2Ghcm+kwD mh9Bc4QUT6dIJZG5TOOVOF2JhmWe2DfNHZw0J0Pxkn6UlCTWtsZuxLZzwlKnfn/SpzxA fEu2EzHMxWY7oE2CSsPuo2rfb5WWiw56CjRlHmKTC7V5KgnGqQZFd4tS7eKGRPqPa1PM IW7sT8iXAODwfw/5a8cIusTSqQx/DLH/BmMftwUKekVJ5yXNLDll6Ik/bHNLWEvRMTfV 9Yiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=voK5XLV56Q9FI5eyVszeBGUsLnZ4M62G6sR/KUxS2MY=; b=LKmKq+7wRJ65IK3KCWF+BFubWyn0LbvLYFevHC1C26k/HhG7jDSLrmLxbTvsH7Xkv5 ousSkSz532GVmwqihbHm6vJGc+Z6QegGyWbsDwg7qxer4wgSf53MdFM4muFgudVYqWCC IOsuHvw76vRqc+JPrzgnCixEinkWx6WEJ445krVMnVTUNfHscSr7fc+8xYaiSzBsuMW5 gawqF0eECEofI0PTlug4J4xwheTd8L53yMNTwINQa++jWfgHZu5IXjgvSaE1NCxktYwi DSfQ+5tbyEOtEQR9GAL5yRjePnfbsU9bKtVU8vqxC9aRRHGhygA3VSI5rSdAK70qzjts koxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G+w8sI4c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa40-20020a17090786a800b007330c08fe49si2002720ejc.206.2022.11.30.09.46.11; Wed, 30 Nov 2022 09:46:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G+w8sI4c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbiK3RoK (ORCPT <rfc822;heyuhang3455@gmail.com> + 99 others); Wed, 30 Nov 2022 12:44:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbiK3RoI (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 30 Nov 2022 12:44:08 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01DAA45A06 for <linux-kernel@vger.kernel.org>; Wed, 30 Nov 2022 09:43:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669830188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=voK5XLV56Q9FI5eyVszeBGUsLnZ4M62G6sR/KUxS2MY=; b=G+w8sI4cVrcBaR1WhD13eqcRZ3Fyd0LDd9BiYWVXdBKguGG00u2j0sd//ZCEN43T5XnUeA ilVpDMcE2e+996LbjZPPHSXgfUrBUGUG7lm/7M4IkKlSCeXqdPqX9gyNebH1bhvvzTaglu 5YQddmTdVewnMaf8ezCyDOemYiZGo6w= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-573-EyUi-REFMla6CcfttnjSHg-1; Wed, 30 Nov 2022 12:43:07 -0500 X-MC-Unique: EyUi-REFMla6CcfttnjSHg-1 Received: by mail-qv1-f71.google.com with SMTP id 71-20020a0c804d000000b004b2fb260447so27254643qva.10 for <linux-kernel@vger.kernel.org>; Wed, 30 Nov 2022 09:43:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=voK5XLV56Q9FI5eyVszeBGUsLnZ4M62G6sR/KUxS2MY=; b=v0HQQs0xqn1++GoClpn8xC2y33a5U+4E6aVIe7w1accKnW64kg90FBIHWRWHDlEoL1 qpd8klr3QAsyncNMWRMoiaTSguRN+3wfuBM0tAHQgJq8UbS9TJtc6yR6x8CmQvsNDoxW ePN8eBsuUrJz9yT9dh1Q89fbMRMDSO4UnVjwf+WyxNMQAqWUQbzp8ZkN8wgjCNaj/SJV d95eZNLd5Bmp3QGtCR64k3ggaesDD5kMa06Ek03+FUkI1UDIXjEdVJP6VHzNLcxJPDfE aFQ9vfV4l8XKZE37JTueNz8nLiVScfK/R/jXi4YVS3ddbSvjtXf0cKEqGOeI0IqdbjO9 KGHQ== X-Gm-Message-State: ANoB5pnD6L+1oYhr0YOqAge3ia9bPHz7jgQpQJUhZRSsPdj8gDUMDk8f d+9Ox/kDdpQlmbUlUCO1w2Dz9LySOnbuEXTfGu+ytCNP6/piL0txi7835Ta+aF4L7YQs8BJlU4m Au0028Ozh6389U3ADhgTJ+iw2 X-Received: by 2002:ac8:1416:0:b0:3a5:6822:1a42 with SMTP id k22-20020ac81416000000b003a568221a42mr44920276qtj.174.1669830186982; Wed, 30 Nov 2022 09:43:06 -0800 (PST) X-Received: by 2002:ac8:1416:0:b0:3a5:6822:1a42 with SMTP id k22-20020ac81416000000b003a568221a42mr44920254qtj.174.1669830186742; Wed, 30 Nov 2022 09:43:06 -0800 (PST) Received: from x1.redhat.com (c-73-214-169-22.hsd1.pa.comcast.net. [73.214.169.22]) by smtp.gmail.com with ESMTPSA id s18-20020a05620a29d200b006fba0a389a4sm1666087qkp.88.2022.11.30.09.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 09:43:06 -0800 (PST) From: Brian Masney <bmasney@redhat.com> To: irusskikh@marvell.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, cth451@gmail.com Subject: [PATCH] net: atlantic: fix check for invalid ethernet addresses Date: Wed, 30 Nov 2022 12:42:59 -0500 Message-Id: <20221130174259.1591567-1-bmasney@redhat.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750944076469352151?= X-GMAIL-MSGID: =?utf-8?q?1750944076469352151?= |
Series |
net: atlantic: fix check for invalid ethernet addresses
|
|
Commit Message
Brian Masney
Nov. 30, 2022, 5:42 p.m. UTC
The Qualcomm sa8540p automotive development board (QDrive3) has an
Aquantia NIC wired over PCIe. The ethernet MAC address assigned to
all of the boards in our lab is 00:17:b6:00:00:00. The existing
check in aq_nic_is_valid_ether_addr() only checks for leading zeros
in the MAC address. Let's update the check to also check for trailing
zeros in the MAC address so that a random MAC address is assigned
in this case.
Signed-off-by: Brian Masney <bmasney@redhat.com>
---
drivers/net/ethernet/aquantia/atlantic/aq_nic.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Wed, Nov 30, 2022 at 12:42:59PM -0500, Brian Masney wrote: > The Qualcomm sa8540p automotive development board (QDrive3) has an > Aquantia NIC wired over PCIe. The ethernet MAC address assigned to > all of the boards in our lab is 00:17:b6:00:00:00. The existing > check in aq_nic_is_valid_ether_addr() only checks for leading zeros > in the MAC address. Let's update the check to also check for trailing > zeros in the MAC address so that a random MAC address is assigned > in this case. > > Signed-off-by: Brian Masney <bmasney@redhat.com> I have a question about the original commit that introduced this check: 553217c24426 ("ethernet: aquantia: Try MAC address from device tree"). The commit message talks about getting the MAC address from device tree, however I don't see any compatible lines in this driver, nor a of_match_table. As far as I can tell, this driver is only setup to be accessed over PCIe. The random MAC address is not ideal for our lab since we'd like to have stable addresses. I'd like to have the bootloader be able to inject a MAC address that's generated based on the board's serial number. I assume that it would go in the chosen node in device tree. One of the issues is that there are multiple NICs on this board, so I'm not sure how that would go in the chosen node and identify this particular NIC. Does anyone know of a place in the kernel where this is already done? Brian
On Wed, Nov 30, 2022 at 12:57:23PM -0500, Brian Masney wrote: > I have a question about the original commit that introduced this check: > 553217c24426 ("ethernet: aquantia: Try MAC address from device tree"). > The commit message talks about getting the MAC address from device tree, > however I don't see any compatible lines in this driver, nor a > of_match_table. As far as I can tell, this driver is only setup to be > accessed over PCIe. In aq_nic_ndev_register(), the code calls platform_get_ethdev_address(), which in turn access the device tree via OF interface. > The random MAC address is not ideal for our lab since we'd like to have > stable addresses. I'd like to have the bootloader be able to inject a > MAC address that's generated based on the board's serial number. I > assume that it would go in the chosen node in device tree. One of the > issues is that there are multiple NICs on this board, so I'm not sure > how that would go in the chosen node and identify this particular NIC. > Does anyone know of a place in the kernel where this is already done? I'm not familar with this particular board, but this probably shouldn't be done in kernel. AFAIK uboot allows overriding MAC with env 'ethaddr'. uboot then either writes this MAC into DT or calls NIC specific code to set the MAC into NIC memory before booting the kernel. The other way around I can think of is to use systemd-networkd or some other network management daemon to override the mac address as it tries to establish a network connection. This might be less hassle if you don't want to mess with the boot loader, but for embedded devices you'd need a different root fs image for every board. Acked-by: Tianhao Chai <cth451@gmail.com>
On Wed, Nov 30, 2022 at 01:26:40PM -0500, Tianhao Chai wrote: > I'm not familar with this particular board, but this probably shouldn't > be done in kernel. AFAIK uboot allows overriding MAC with env 'ethaddr'. > uboot then either writes this MAC into DT or calls NIC specific code to > set the MAC into NIC memory before booting the kernel. Our Boot Loader is ABL on the Qualcomm platform. > The other way around I can think of is to use systemd-networkd or some > other network management daemon to override the mac address as it tries > to establish a network connection. This might be less hassle if you > don't want to mess with the boot loader, but for embedded devices you'd > need a different root fs image for every board. We'll look into the systemd approach. I see that our board serial number is available in /sys/devices/soc0/serial_number and we can have a script generate a MAC address based on that. > Acked-by: Tianhao Chai <cth451@gmail.com> Thanks! Brian
On Wed, Nov 30, 2022 at 12:42:59PM -0500, Brian Masney wrote: > The Qualcomm sa8540p automotive development board (QDrive3) has an > Aquantia NIC wired over PCIe. The ethernet MAC address assigned to > all of the boards in our lab is 00:17:b6:00:00:00. The existing > check in aq_nic_is_valid_ether_addr() only checks for leading zeros > in the MAC address. Let's update the check to also check for trailing > zeros in the MAC address so that a random MAC address is assigned > in this case. > > Signed-off-by: Brian Masney <bmasney@redhat.com> > --- > drivers/net/ethernet/aquantia/atlantic/aq_nic.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c > index 06508eebb585..c9c850bbc805 100644 > --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c > +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c > @@ -293,7 +293,8 @@ static bool aq_nic_is_valid_ether_addr(const u8 *addr) > /* Some engineering samples of Aquantia NICs are provisioned with a > * partially populated MAC, which is still invalid. > */ > - return !(addr[0] == 0 && addr[1] == 0 && addr[2] == 0); > + return !(addr[0] == 0 && addr[1] == 0 && addr[2] == 0) && > + !(addr[3] == 0 && addr[4] == 0 && addr[5] == 0); Hi Brian is_valid_ether_addr() Andrew
On Wed, Nov 30, 2022 at 08:41:29PM +0100, Andrew Lunn wrote: > On Wed, Nov 30, 2022 at 12:42:59PM -0500, Brian Masney wrote: > > The Qualcomm sa8540p automotive development board (QDrive3) has an > > Aquantia NIC wired over PCIe. The ethernet MAC address assigned to > > all of the boards in our lab is 00:17:b6:00:00:00. The existing > > check in aq_nic_is_valid_ether_addr() only checks for leading zeros > > in the MAC address. Let's update the check to also check for trailing > > zeros in the MAC address so that a random MAC address is assigned > > in this case. > > > > Signed-off-by: Brian Masney <bmasney@redhat.com> > > --- > > drivers/net/ethernet/aquantia/atlantic/aq_nic.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c > > index 06508eebb585..c9c850bbc805 100644 > > --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c > > +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c > > @@ -293,7 +293,8 @@ static bool aq_nic_is_valid_ether_addr(const u8 *addr) > > /* Some engineering samples of Aquantia NICs are provisioned with a > > * partially populated MAC, which is still invalid. > > */ > > - return !(addr[0] == 0 && addr[1] == 0 && addr[2] == 0); > > + return !(addr[0] == 0 && addr[1] == 0 && addr[2] == 0) && > > + !(addr[3] == 0 && addr[4] == 0 && addr[5] == 0); > > Hi Brian > > is_valid_ether_addr() aq_nic_ndev_register() already calls is_valid_ether_addr(): if (is_valid_ether_addr(addr) && aq_nic_is_valid_ether_addr(addr)) { (self->ndev, addr); } else { ... } That won't work for this board since that function only checks that the MAC "is not 00:00:00:00:00:00, is not a multicast address, and is not FF:FF:FF:FF:FF:FF." The MAC address that we get on all of our boards is 00:17:b6:00:00:00. Brian
> > > - return !(addr[0] == 0 && addr[1] == 0 && addr[2] == 0); > > > + return !(addr[0] == 0 && addr[1] == 0 && addr[2] == 0) && > > > + !(addr[3] == 0 && addr[4] == 0 && addr[5] == 0); > > > > Hi Brian > > > > is_valid_ether_addr() > > aq_nic_ndev_register() already calls is_valid_ether_addr(): > > if (is_valid_ether_addr(addr) && > aq_nic_is_valid_ether_addr(addr)) { > (self->ndev, addr); > } else { > ... > } > > That won't work for this board since that function only checks that the > MAC "is not 00:00:00:00:00:00, is not a multicast address, and is not > FF:FF:FF:FF:FF:FF." The MAC address that we get on all of our boards is > 00:17:b6:00:00:00. Which is a valid MAC address. So i don't see why the kernel should reject it and use a random one. Maybe you should talk to Marvell about how you can program the e-fuses. You can then use MAC addresses from A8-97-DC etc. Andrew
From: Andrew Lunn > Sent: 30 November 2022 21:33 ... > > That won't work for this board since that function only checks that the > > MAC "is not 00:00:00:00:00:00, is not a multicast address, and is not > > FF:FF:FF:FF:FF:FF." The MAC address that we get on all of our boards is > > 00:17:b6:00:00:00. > > Which is a valid MAC address. So i don't see why the kernel should > reject it and use a random one. It isn't very valid... The first three bytes are the mulicast, local and company bits. So the last three bytes being zero indicate you have the very first address the company allocated. Pretty much zero chance of that board ever working well enough to be in a system. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
> Pretty much zero chance of that board ever working well > enough to be in a system. IBM, for example, has at least three ranges. Maybe they could of reached the end of one range, and simply continued shipping products from the beginning of the next range... aQuantia only has one range, so i would however agree for them, the first valid MAC address is probably assigned to some internal development device. Andrew
>> That won't work for this board since that function only checks that the >> MAC "is not 00:00:00:00:00:00, is not a multicast address, and is not >> FF:FF:FF:FF:FF:FF." The MAC address that we get on all of our boards is >> 00:17:b6:00:00:00. > > Which is a valid MAC address. So i don't see why the kernel should > reject it and use a random one. > > Maybe you should talk to Marvell about how you can program the > e-fuses. You can then use MAC addresses from A8-97-DC etc. Hi Brian, I do completely agree with Andrew. Thats not a fix to be made in linux kernel. The boards you get have zero efuse. You should work with Qualcomm on how to update mac addresses of your boards. Igor
On Thu, Dec 01, 2022 at 09:07:49AM +0100, Igor Russkikh wrote: > > >> That won't work for this board since that function only checks that the > >> MAC "is not 00:00:00:00:00:00, is not a multicast address, and is not > >> FF:FF:FF:FF:FF:FF." The MAC address that we get on all of our boards is > >> 00:17:b6:00:00:00. > > > > Which is a valid MAC address. So i don't see why the kernel should > > reject it and use a random one. > > > > Maybe you should talk to Marvell about how you can program the > > e-fuses. You can then use MAC addresses from A8-97-DC etc. > > Hi Brian, > > I do completely agree with Andrew. Thats not a fix to be made in > linux kernel. > > The boards you get have zero efuse. You should work with Qualcomm on > how to update mac addresses of your boards. OK, I'll work to track down someone within Qualcomm that can help us program the MAC address into the boards that we have. In the mean time, we'll go with the systemd unit approach to set a MAC address. Thank you all! Brian
Hi Igor
> You should work with Qualcomm on how to update mac addresses of your boards.
Why Qualcomm? I assume the fuses are part of the MAC chip? So Marvell
should have a tool to program them? Ideally, it should be part of
ethtool -E|--change-eeprom
but when i took a quick look, i could not see anything.
Andrew
Hi Andrew, >> You should work with Qualcomm on how to update mac addresses of your > boards. > > Why Qualcomm? I assume the fuses are part of the MAC chip? So Marvell > should have a tool to program them? Ideally, it should be part of > > ethtool -E|--change-eeprom > > but when i took a quick look, i could not see anything. Normal production chips should have efuses (and macs) programmed on factory. Here I assume we have preproduction/development samples which made no way through the normal process. Marvell provides normally all the tools to the customers, but these are internal, we do not make these available to the end users. Igor
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c index 06508eebb585..c9c850bbc805 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c @@ -293,7 +293,8 @@ static bool aq_nic_is_valid_ether_addr(const u8 *addr) /* Some engineering samples of Aquantia NICs are provisioned with a * partially populated MAC, which is still invalid. */ - return !(addr[0] == 0 && addr[1] == 0 && addr[2] == 0); + return !(addr[0] == 0 && addr[1] == 0 && addr[2] == 0) && + !(addr[3] == 0 && addr[4] == 0 && addr[5] == 0); } int aq_nic_ndev_register(struct aq_nic_s *self)