From patchwork Fri Oct 15 19:38:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 12562717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDBAFC433F5 for ; Fri, 15 Oct 2021 19:40:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B738260FE3 for ; Fri, 15 Oct 2021 19:40:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B738260FE3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yOkIxIm7MzBo92iNhKH6q/HZP2JxwCkiHiogwjhdKNg=; b=xVzEuLuLrc/YHe DquB85Sr3BrdhHVdfNxYLK3JYpXMPt+tVYQYKxaINSknXh6A1ZUT2ju/SsocAGjmizHYzaFc3yR+r VlviNlJRW0B76utXr7G7HUxeKmPKf3kWEIpiEDcyy+3OCdHX34r36MTCwkw471hZOzMMrAH5ybLds plLYDTbqkbWcGtvIRkly0f2rjAdyEPUrTH6xIZ2KiQexzqKtq6tkoSc8dSkMg6vmFpt5oC46Zvp2Z HR82rWw1J63cNJutDXlU2VKf2XcqBI+6Z6iFZm7cqVmtBjKLw6caRqcOPPEDKclvqya3e2HeHplHu +rb4xRhtYQ9HR+e+gX3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbT2j-008caF-S0; Fri, 15 Oct 2021 19:39:02 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbT2f-008cYa-Mc for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 19:38:59 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id C049861164; Fri, 15 Oct 2021 19:38:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634326736; bh=weNnvNYdaUNDb2w7q63P4w4fOKU0Ms7iHvDrdhhtdvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C4gNANYJeBAz6008qkwRD+phVRGzXjAWc2hr+qzgy76G3g3pKYM4x8Kg39tBa2iAF ybgA9GTqWyc1jJRtKB1k1m1UKQxoifl82RA2ztTbWP3qZfjPrNqQqDChXvWwg2/JOG iZMl6HBTxdcwoGSNH208fISk1YcFJI3NCJ3hn8KmNWqyvjWb/iO17nthU4LQ+e6P1U XP6y8mh9qzdzCcjWZPUNAxcg1hCaiKe6wi9yKMa7u4OVnzGS/jOmOkRbEdb9rDAhtb tfVhRq36sms/aDglqv/Qv41S+CCXms6vF8UdckT18zMihuXPWvB3lrPfSBQMZN39jW 6YSYBIptgeWYg== From: Jakub Kicinski To: netdev@vger.kernel.org Cc: olteanv@gmail.com, andrew@lunn.ch, idosch@idosch.org, f.fainelli@gmail.com, Jakub Kicinski , jiri@nvidia.com, idosch@nvidia.com, lars.povlsen@microchip.com, Steen.Hegelund@microchip.com, UNGLinuxDriver@microchip.com, bjarni.jonasson@microchip.com, linux-arm-kernel@lists.infradead.org, qiangqing.zhang@nxp.com, vkochan@marvell.com, tchornyi@marvell.com, vladimir.oltean@nxp.com, claudiu.manoil@nxp.com, alexandre.belloni@bootlin.com Subject: [RFC net-next 1/6] ethernet: add a helper for assigning port addresses Date: Fri, 15 Oct 2021 12:38:43 -0700 Message-Id: <20211015193848.779420-2-kuba@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211015193848.779420-1-kuba@kernel.org> References: <20211015193848.779420-1-kuba@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211015_123857_785160_1701948A X-CRM114-Status: GOOD ( 11.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We have 5 drivers which offset base MAC addr by port id. Create a helper for them. This helper takes care of overflows, which some drivers did not do, please complain if that's going to break anything! Signed-off-by: Jakub Kicinski --- CC: jiri@nvidia.com CC: idosch@nvidia.com CC: lars.povlsen@microchip.com CC: Steen.Hegelund@microchip.com CC: UNGLinuxDriver@microchip.com CC: bjarni.jonasson@microchip.com CC: linux-arm-kernel@lists.infradead.org CC: qiangqing.zhang@nxp.com CC: vkochan@marvell.com CC: tchornyi@marvell.com CC: vladimir.oltean@nxp.com CC: claudiu.manoil@nxp.com CC: alexandre.belloni@bootlin.com CC: UNGLinuxDriver@microchip.com --- include/linux/etherdevice.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index 23681c3d3b8a..157f6c7ac9ff 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -551,6 +551,27 @@ static inline unsigned long compare_ether_header(const void *a, const void *b) #endif } +/** + * eth_hw_addr_set_port - Generate and assign Ethernet address to a port + * @dev: pointer to port's net_device structure + * @base_addr: base Ethernet address + * @id: offset to add to the base address + * + * Assign a MAC address to the net_device using a base address and an offset. + * Commonly used by switch drivers which need to compute addresses for all + * their ports. addr_assign_type is not changed. + */ +static inline void eth_hw_addr_set_port(struct net_device *dev, + const u8 *base_addr, u8 id) +{ + u64 u = ether_addr_to_u64(base_addr); + u8 addr[ETH_ALEN]; + + u += id; + u64_to_ether_addr(u, addr); + eth_hw_addr_set(dev, addr); +} + /** * eth_skb_pad - Pad buffer to mininum number of octets for Ethernet frame * @skb: Buffer to pad From patchwork Fri Oct 15 19:38:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 12562715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6664EC433FE for ; Fri, 15 Oct 2021 19:40:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 32F3460FE3 for ; Fri, 15 Oct 2021 19:40:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 32F3460FE3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FNJxOvqus2gon3gNTOvY8NP85sclclStR2+5/ZaQVc4=; b=qbqEqsDe5KepC1 hQBaA55LIH3m05U/aBoRF7FFSMxS4Npzb8LYsc6zFoNOKmUQ1rRQaZFtNom+LlRhMRhunAe4pM8N/ ud4vMXsVUvL7g2/ylOmcK+C7rdnuyW6g9oSC4KPSK7W9E9gsJ/MZRZN+cMPoS2WZk8nW6Yte0P9sC tcDge9WMPwchSSu9UkaarDDrMI6AX7hD7ueDeN7BLR7qH6FhH3xaxemOWmfNOrBFEpX6RJtxhnS1h lIGino0iuMmGwJ3ex86XHxLl4jpKIkUDfXFyWb3rYvAk1VNZ+BdA1IE6aYwiPhKrLqBmynP1t2bdX AZ0Z7qZp0u8MQcNUjoXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbT2t-008cbI-EI; Fri, 15 Oct 2021 19:39:11 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbT2h-008cZC-2N for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 19:39:00 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 61E23611CE; Fri, 15 Oct 2021 19:38:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634326738; bh=6uFO95BN/xrQKbOn4Vvtf8HObXa+wJ7r9KR4eAFX2r4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UlOcikDPQK5qOHLPoXnMhure6248BRumpYf0PLp8bMfsoEhY6E2rsJIkXpsSXGk3l qFs04zTRQL9CD8PFmz2jewJDVxZNEsZ4nB2xt7eI6a3CgXSo0F88TWaFg+xfKp3V+f rIzf1SwoFL7OZEI5qGmnK+W//KUejsRpk4D3cRwyQaMwjRaGNHA+3QJ/EUGtrmsIHz /4SfCDfx4v5LUn5HceJ/18KZtujDEYkeasSAJSlSPjEIblcZECRLgIIgeKGR8iJKED NHWMlYtLjb4sWetcRfwuNv5lIZxa6XwCKI/YCPFf9Rwn3qIYpw9iRLhsA5Z2Hqq9ay wFgssf2X8Z7Tg== From: Jakub Kicinski To: netdev@vger.kernel.org Cc: olteanv@gmail.com, andrew@lunn.ch, idosch@idosch.org, f.fainelli@gmail.com, Jakub Kicinski , lars.povlsen@microchip.com, Steen.Hegelund@microchip.com, UNGLinuxDriver@microchip.com, bjarni.jonasson@microchip.com, linux-arm-kernel@lists.infradead.org Subject: [RFC net-next 6/6] ethernet: sparx5: use eth_hw_addr_set_port() Date: Fri, 15 Oct 2021 12:38:48 -0700 Message-Id: <20211015193848.779420-7-kuba@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211015193848.779420-1-kuba@kernel.org> References: <20211015193848.779420-1-kuba@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211015_123859_159628_BD38E26A X-CRM114-Status: UNSURE ( 9.05 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Commit 406f42fa0d3c ("net-next: When a bond have a massive amount of VLANs...") introduced a rbtree for faster Ethernet address look up. To maintain netdev->dev_addr in this tree we need to make all the writes to it got through appropriate helpers. Signed-off-by: Jakub Kicinski --- CC: lars.povlsen@microchip.com CC: Steen.Hegelund@microchip.com CC: UNGLinuxDriver@microchip.com CC: bjarni.jonasson@microchip.com CC: linux-arm-kernel@lists.infradead.org --- drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c b/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c index b21ebaa32d7e..d56822f6d09e 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c @@ -200,7 +200,6 @@ struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno) { struct sparx5_port *spx5_port; struct net_device *ndev; - u64 val; ndev = devm_alloc_etherdev(sparx5->dev, sizeof(struct sparx5_port)); if (!ndev) @@ -216,8 +215,7 @@ struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno) ndev->netdev_ops = &sparx5_port_netdev_ops; ndev->ethtool_ops = &sparx5_ethtool_ops; - val = ether_addr_to_u64(sparx5->base_mac) + portno + 1; - u64_to_ether_addr(val, ndev->dev_addr); + eth_hw_addr_set_port(ndev, sparx5->base_mac, portno + 1); return ndev; }