From mboxrd@z Thu Jan 1 00:00:00 1970 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 -- 2.31.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel