From patchwork Thu Nov 24 11:15:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 25457 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3334435wrr; Thu, 24 Nov 2022 03:23:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf6T2zAl9E35L4PWhwwt3RbrqRNQyl1LMCGybQlfsDfhrVOkf0uelfDuMjgI3l7q7Do/IUUG X-Received: by 2002:a62:5e41:0:b0:56b:db09:a235 with SMTP id s62-20020a625e41000000b0056bdb09a235mr14916897pfb.20.1669289006839; Thu, 24 Nov 2022 03:23:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669289006; cv=none; d=google.com; s=arc-20160816; b=xJPyTKgHbt+MEyyKZ1GxdhIEp4DCHXEY00ncBMs5R2qZIlY3XWdjPbOqCIf7+e+O4K aW61Oc/IOXRWr17COwh2WLQn0VM9vn5oNVjGznwMc55WgR6KbhCrcbpQ69oHmwWRstD5 ERy1UVWqInObcX6NQ01SDf7XIfm4huRkqtf8nzpl3GKM9fJhSucbAzjj3uFWK5TXj1BU Ro1MucqSCQIGcf1VzR0hBTnWZfrAB0pjRF5Ct96R60xJ5SK8F2L9BIxD491I9+jrZ9lg 7KkFtt4Gjsj5/rc/nPmB94AMiS5K5ZUAC21UjAW5lRl2A1bn//Ha1I7sYBYdk0CaoTlk sfIA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=s42uM41w9ysmCNZE9IaonrxU6NJPatbC7hYnvHselLY=; b=E/um85hyeUTlJOgt93ARopzuQXjTVsZFrfu7cmptLmktDEXxmN3zkTFE5LqVVAGBZJ 4bh2JqulH7xQkOtLOaKnZHaIZVWcUbCOCdtTgqDSq7QMZR/GoXXICINn63OxSNQxvx0X K8jPbzLkwvY+JY3N5CgAtIJM8lYuF1yaei1F9hCq+73+t7eFSwMamT9WnU/uv66BP9oj XbG9rg0fldDTQQDo6HWGSr1flGSDM7rgZO21jx4GshWGsHGuwt9zwQYpk4DbjlMNpJRW XKJoeosls3PgPAqqVF5Ycjg81l640sjD6aGYLARNxPUKrTbluO8jm/MHOxnv6Xuy95K1 LRug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=HCXhEKvs; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j6-20020a170903024600b0018542a1b588si925620plh.196.2022.11.24.03.23.14; Thu, 24 Nov 2022 03:23:26 -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=@bootlin.com header.s=gm1 header.b=HCXhEKvs; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbiKXLQt (ORCPT + 99 others); Thu, 24 Nov 2022 06:16:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229943AbiKXLQi (ORCPT ); Thu, 24 Nov 2022 06:16:38 -0500 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19345146F8D; Thu, 24 Nov 2022 03:16:21 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id BB3351C0019; Thu, 24 Nov 2022 11:16:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1669288580; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s42uM41w9ysmCNZE9IaonrxU6NJPatbC7hYnvHselLY=; b=HCXhEKvsJrrzmpZ6OKhK9SABZxwycYvZjnfneAz5D7wWn4u74NVgS6KdAXFKxJbpDp2/z7 r65VnNGRgNSxE5YVkr8TvbkzUBcoHyLc0+xtGQGfHNIE8INTy3fKN+7VDEBb8Ugmf0OaHY /NFcd5FDP4v8zxfCoMxMaOEkWfs2E6PUUUUQseKALeXpwSq1JjYnFN1uy3Qg+OogXpJH7w 8lIJsNRNci3dc11gMMqiitnnrVp4V43sRQTMi41gkAnAAy6voQeUvLOafpB2Fm4QPaFSn5 yeRUm/AhHBjeBMx2vY9bV1PHXtlYId5m0LZqQoczoTIRPQnTeKg+csxB3042uQ== From: Miquel Raynal To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org Cc: Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, Robert Marko , Luka Perkov , Thomas Petazzoni , Michael Walle , Marcin Wojtas , , , Vadym Kochan , Miquel Raynal Subject: [PATCH net-next v2 7/7] net: mvpp2: Consider NVMEM cells as possible MAC address source Date: Thu, 24 Nov 2022 12:15:56 +0100 Message-Id: <20221124111556.264647-8-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221124111556.264647-1-miquel.raynal@bootlin.com> References: <20221124111556.264647-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750376389642618768?= X-GMAIL-MSGID: =?utf-8?q?1750376389642618768?= The ONIE standard describes the organization of tlv (type-length-value) arrays commonly stored within NVMEM devices on common networking hardware. Several drivers already make use of NVMEM cells for purposes like retrieving a default MAC address provided by the manufacturer. What made ONIE tables unusable so far was the fact that the information where "dynamically" located within the table depending on the manufacturer wishes, while Linux NVMEM support only allowed statically defined NVMEM cells. Fortunately, this limitation was eventually tackled with the introduction of discoverable cells through the use of NVMEM layouts, making it possible to extract and consistently use the content of tables like ONIE's tlv arrays. Parsing this table at runtime in order to get various information is now possible. So, because many Marvell networking switches already follow this standard, let's consider using NVMEM cells as a new valid source of information when looking for a base MAC address, which is one of the primary uses of these new fields. Indeed, manufacturers following the ONIE standard are encouraged to provide a default MAC address there, so let's eventually use it if no other MAC address has been found using the existing methods. Link: https://opencomputeproject.github.io/onie/design-spec/hw_requirements.html Signed-off-by: Miquel Raynal --- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index eb0fb8128096..12f0b5ad8cee 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -6104,6 +6104,13 @@ static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv, } } + /* Only valid on OF enabled platforms */ + if (!of_get_mac_address_nvmem(to_of_node(fwnode), fw_mac_addr)) { + *mac_from = "nvmem cell"; + eth_hw_addr_set(dev, fw_mac_addr); + return; + } + *mac_from = "random"; eth_hw_addr_random(dev); }