From patchwork Fri Nov 10 09:41:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiji Yang X-Patchwork-Id: 1862383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=QBmlGnpp; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=nIV+oejn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SRYn95rMtz1yQy for ; Fri, 10 Nov 2023 20:44:13 +1100 (AEDT) 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: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:In-Reply-To:References: List-Owner; bh=o8aCwfLF8ix56TzN8uZShY2elN/AmCEtihd+2loDIQU=; b=QBmlGnppNzovvj xaxikL/M6GgQFwm8RZsxgdhDSDLVprNHbqeqrbB3czNM8p1Kp4y6Zf7o2OhdCD/YElvgqgouUr7XW 8uqqGCGrS+mGPHxUwDLgRMMyGcrMK6+OqD31vHOvGBuZSrxl21nnE1ySVnooFrkq0HCiRsWZkiuZL HV80Wgeh7PIqvVj0ylcFVDDHcmzgB59Xx2oOsoLdGkb0wq7ZbAIpP/Z7BjfvblEgzNF6MjAFmUuoE 5QfXTyV1qVfSe2ZnbqiEPXq6Fq1pEH88JyZF9IeZyDsRUischXL3w3XhkdD+YrI1ojPIyDYsOdnPf isK6d55IDXELvYA+0qVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r1O1s-008DD7-1C; Fri, 10 Nov 2023 09:42:20 +0000 Received: from mail-os0jpn01olkn20801.outbound.protection.outlook.com ([2a01:111:f403:2815::801] helo=JPN01-OS0-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r1O1o-008DCi-2h for openwrt-devel@lists.openwrt.org; Fri, 10 Nov 2023 09:42:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fDZabPkbUdVS6KnMz+SnjYaBAuKmLELl2XwZr6qD7kWreouC/VpMhanqr4xvATCd9EGbgWbk7mQd7HpLlMFNpeOkU2WHLwD4ScKfDeMqZqn+Irz4+rxOfeS7sh9DSzGxH70md1cGMieVCJ6XC3Ig7xwuvkrQIV136kZ56jTFKcrUT+6rC5sphoB1WMtvX4dKzWfDagegbRTcwi2JCW9Z7ttoI3glZ9r6FGO/zR5ubIsCbBDWfc/djKMSfbqFtP+cAxwMZ1vjUBbjzWRBv2yCjnHcrJGs3D7iq8ne4pfgESS6j2+6wZIIGSLlPjfdt0N4Sev9FaNys/h6rOHTi+2hsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=52G9o/sn12gPxBNW+xIEmQcuMueWugHHHHNIgx6q4OA=; b=hGO02GA2enIoVQcPC/gSxuuTLCFDKC6MomL/v4qWvhNagJm5XXwvtV40GNwzcMzxhtZh5/tAgWauePGDPHoiOBv2JZEfj6VVHtaz048tEZ3TM3pSpJqb3QzEpQd9Qmn4rVQn6KmuyvHDlmtGTxucdqxQwnMNnX7ySVDbqJCYtZ608+lDsaFvwrSgoDl4QRFu/tO7MYbmi3toyYbIwDFlm/ZmF2KAmyaKf68WAVhQCtqW2BW5wLiHdFBlEZK7q6hArM8PnH/QmjqRfSDt8L9XSvx2/lfAulQs9VUr/K9X4pOI2f/H4UUSDGYy/Dt/niQ8GcF+uNPR4tOHqKDEtavfQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=52G9o/sn12gPxBNW+xIEmQcuMueWugHHHHNIgx6q4OA=; b=nIV+oejnkUvkXOpTfPrZF7XCXS6JlWRa8DhhsK1wdMIUZ7BsXd0+8AL31c/TROs4iyA5aT4UPSmmSN2lwzNLjXvrQBle+zMG3eGQWXZtkdx8RIIedog6kVmuLmfEKuFBahTX1LA3ZrUvv6sNbqsLw9oZvngyjOKBFpaotHJabpumwCnUTmV4OwRM8G4hthtlaoIoRxKhq9k9j7bvYWBnJ4prEFaa1NnY+b0lnfG+JrMwTELdQpFpU1HlPxdHdSlSz707wdrhGki/bK8pYWUdkJlv02xm9Grh7kuKUiiKcvB4W/Y71+JpLvbnJcBfBXidlmD5FJ0jiWNOL6tUOar0FA== Received: from TYAP286MB0315.JPNP286.PROD.OUTLOOK.COM (2603:1096:404:8041::8) by OS3P286MB2407.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:17f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.19; Fri, 10 Nov 2023 09:42:09 +0000 Received: from TYAP286MB0315.JPNP286.PROD.OUTLOOK.COM ([fe80::465a:2534:4d99:a25b]) by TYAP286MB0315.JPNP286.PROD.OUTLOOK.COM ([fe80::465a:2534:4d99:a25b%6]) with mapi id 15.20.6954.029; Fri, 10 Nov 2023 09:42:09 +0000 From: Shiji Yang To: openwrt-devel@lists.openwrt.org Cc: Christian Marangi , Hauke Mehrtens , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Shiji Yang Subject: [PATCH] kernel: of: add DT MAC address bitwise operation support Date: Fri, 10 Nov 2023 17:41:52 +0800 Message-ID: X-Mailer: git-send-email 2.39.2 X-TMN: [BdcOgNZZUTj/p0J9nIJni1Yw/gXOgfCH6cc+xKaxPSA=] X-ClientProxiedBy: SI2P153CA0011.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::14) To TYAP286MB0315.JPNP286.PROD.OUTLOOK.COM (2603:1096:404:8041::8) X-Microsoft-Original-Message-ID: <20231110094152.5118-1-yangshiji66@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYAP286MB0315:EE_|OS3P286MB2407:EE_ X-MS-Office365-Filtering-Correlation-Id: 8153bc60-1253-4df7-58ec-08dbe1d14e93 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jubUDt9opIMjM0zTYWSBRTvPXvC4iH1mNwEUzjLsjm6i9vT1gK0sI3w+KM9W6G2GUEqrqrMlrN1R6uhKYlSFlrYqFP2GcvRuBGcAiUgG9amEU/TWiv/qN4SGViKh4g/giHmFSxslQwxi2MU0bMCBdmgeiA2Q7sWJbjEortccsBYqt0a+r6wmbVJTuWVvh3Y4lI8qtrDELFdrkDXTTheUQMrhsvbSrGvnyQAU1ghaq6Utged4Whmu5fGCVkQWH8o4Dv+dvbpDJZviVoDf6xxtA7U8fkQXbHWLFYiRzpmqvYu5uaPimCvIat0m3azP1i7s6DtywnHvMBxYpkxNaB5nrRFxLhBGe21xMkJ9BvAAf0IlV1jCF7jx+om7Y1BbMZCufwlrazOWkcrydA3CYR9wtE0QHGzf32IBOy8ziXXjVWokYhTfweo7mXRoHQ7sJMM2vb434nlvSRWvZY2CYJir5Wvg/m1gmdk5PoJc9eYUalhu4nrdr4tAu6ijbyM3PtQs4/MsticQui3tgQfIFKWto3nuBp81kMJ+IQwTQZhog32UyxEvuCvlxBd4TKN8scPp/D8wTEtc6H5uuGQ+0mbMz/JICdUyu7tjc0PPpbUXbAaK042myQ4JYWCE2AJCSnw/RAYlj3VQl5Vyfx0x2ni4fw== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aCnTpXPGW7VDLvWhqYGzKYPXzT76ECJllHm8PsB0minP4/Wf/9JANCkl+7t8XrEVWeGssxkb8flyGE+knjCd/nHU1TUdt+tzR1FYwZRCrUNF17L282y/dE4dWqV4k4xnzDfvysZl0ZE75x9nKB9bixBFpW5bI6fB8Nef8Oq0ouq7I9ZxPUVUBe9bTZ2xAr1qwXwOScBVSmeSIFm69btelLQ4Pdd7g4oH3L5hJYc5H+KKS0cqBWd0qaLfAhKSjdvGtADDKDXUhW3bUpQEBOMkrADzAE9kK2eFF/5BIm3eJF4QaFn0Agk7ZEzaESK9mmGFmYmX8ANEJkT7qsDQJSD0B+hluZIFbF1Kvj/UXcI3DDAF10mTFC/HBQ9XH5yD+y7j6Ivs0Ky6Jmb4n0ipT8MR+RClVJtop5VkNidya05LKPetP1ftsRgmKe/qPVu8w1pEaCp5/Pv7BUj4fcVhxeGln+Hq/iKwuL7D7w+ZyJQ+0fTEdkgB+I6NKNqjBuadwsyg+WVzEQS+cfIrEWuKVJvIV8jYENejja4wa5ELq4p/M+8nn4fFAEphOcfJsrP+10qRfDrKo5q1mLM8ovtiSaW6f37RbxYJdHsduaw+TAA6fbdE2xGu8qr8lsYiX8cmaVXSVmUUtlv6aU5R8sEMpA+W48beiJ3hrx030L1PSAWj149J8GoGSXLc4/ZEfHxPFvSkSQWboG7k5tVQtgk3bUbbkZdK1KlrcHuaEZnZB5+gaFqYwEN7Ve2Y650zyfm99R1yDpVdAYHrivOc2/uGIkOIazsvyDLE+0Y5ejvyr19KRu8ldZ4r+clxAOzwKdREeUQuPfQUs8WIn/xoHFhGRUUBWSSuCVDREkDDKDhgMypIcW7FKY5l35omKgGfxe/T9kwsZqD/F5Hi+oBOjL6/3zoKwYj8wgD6U/bPi5gl47MTCQYgHc96rKOjTYSkB13tQpoShS1s9Fou9tVJSnoVL9GQ+sIvvWuwuDJFisdr4yz9ysjTjZeLq1ziHVEdjt3FG/318h6Fdwo1gqOLQOXC+YXXVQtCulZTRepiFDa5uLS6+mdlklwDerwxOSXKmnWEfXSmUbogJIXmmyOCv3VceDikhGZf1ES//jjGwFRlw0X+Ira6bPf4TlACwhQZWW1BNmtX8zcCoaTjkagRBZNYdZrxYdqNye3E8z4lhi+z9bA/2vOnK9K5mHxuqPVWot+N47lSgLJFvJ/n7AKet1YQTBFqbyPQ0/ZRUgtkFKuG3JDy0iA= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8153bc60-1253-4df7-58ec-08dbe1d14e93 X-MS-Exchange-CrossTenant-AuthSource: TYAP286MB0315.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2023 09:42:08.9600 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB2407 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231110_014217_213390_F6D4F735 X-CRM114-Status: GOOD ( 17.26 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Shiji Yang This patch allow user to perform basic bitwise clear/set operation on OF DT MAC address. We use two new added dt-bindings to specific the MAC address bits clear/set mask. "mac-address-bitwise-set" can [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a01:111:f403:2815:0:0:0:801 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [yangshiji66[at]outlook.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [yangshiji66[at]outlook.com] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Shiji Yang This patch allow user to perform basic bitwise clear/set operation on OF DT MAC address. We use two new added dt-bindings to specific the MAC address bits clear/set mask. "mac-address-bitwise-set" can be used to set bit. And "mac-address-bitwise-clear" can be used to clear bit. Signed-off-by: Shiji Yang --- Hi! This patch can benefit a lot of devices. Git grep ref: macaddr_setbit_la https://git.openwrt.org/?p=openwrt%2Fopenwrt.git&a=search&h=HEAD&st=grep&s=macaddr_setbit_la&sr=1 macaddr_setbit https://git.openwrt.org/?p=openwrt%2Fopenwrt.git&a=search&h=HEAD&st=grep&s=macaddr_setbit&sr=1 macaddr_unsetbit https://git.openwrt.org/?p=openwrt%2Fopenwrt.git&a=search&h=HEAD&st=grep&s=macaddr_unsetbit&sr=1 If this hack/idea is unacceptable, please let me know. Thanks! Regards, Shiji Yang ...-cell-MAC-address-bitwise-operation-.patch | 101 ++++++++++++++++++ ...-cell-MAC-address-bitwise-operation-.patch | 101 ++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 target/linux/generic/hack-5.15/686-of-net-add-NVMEM-cell-MAC-address-bitwise-operation-.patch create mode 100644 target/linux/generic/hack-6.1/686-of-net-add-NVMEM-cell-MAC-address-bitwise-operation-.patch diff --git a/target/linux/generic/hack-5.15/686-of-net-add-NVMEM-cell-MAC-address-bitwise-operation-.patch b/target/linux/generic/hack-5.15/686-of-net-add-NVMEM-cell-MAC-address-bitwise-operation-.patch new file mode 100644 index 0000000000..396eed8f4a --- /dev/null +++ b/target/linux/generic/hack-5.15/686-of-net-add-NVMEM-cell-MAC-address-bitwise-operation-.patch @@ -0,0 +1,101 @@ +From: Shiji Yang +Date: Sun, 16 Jul 2023 21:00:15 +0800 +Subject: [PATCH] of: net: add DT MAC address bitwise operation support + +This patch allow user to perform basic bitwise clear/set operation on +OF DT MAC address. We use two new added dt-bindings to specific the +MAC address bits clear/set mask. "mac-address-bitwise-set" can be used +to set bit. And "mac-address-bitwise-clear" can be used to clear bit. + +The "mac-address-bitwise-*" property consists of two 32-bit(4 Bytes) +hexadecimal. The first hex number mask the Byte[1-2] and the second +one mask the Byte[3-6]. Each MAC address bit corresponds to the unique +mask bit. When setting mask bit to "1", OF driver will clear/set the +corresponding MAC address bit. + +Sample MAC Address and Property Mask: +AA: BB : CC : DD : EE : FF --> mask: <0xAABB 0xCCDDEEFF> +^ ^ ^ +Byte[1] Byte[3] Byte[6] + +Usage Example: +Assuming the base MAC address is "00:11:22:33:44:55", and we have dts +as follows. then the final MAC address should be "ff:11:22:33:44:66". + +0xff1122334466 = 0x001122334455 & (~0x0000000000ff) | 0xff0000000066 + +&gmac0 { + nvmem-cells = <&macaddr_base>; + nvmem-cell-names = "mac-address"; + mac-address-bitwise-clear = <0x0000 0x000000ff>; + mac-address-bitwise-set = <0xff00 0x00000066>; +}; + +Signed-off-by: Shiji Yang +--- + net/core/of_net.c | 35 +++++++++++++++++++---------------- + 1 file changed, 19 insertions(+), 16 deletions(-) + +--- a/net/core/of_net.c ++++ b/net/core/of_net.c +@@ -154,17 +154,10 @@ free: + */ + int of_get_mac_address(struct device_node *np, u8 *addr) + { +- u32 inc_idx, mac_inc, mac_val; ++ u32 inc_idx, mac_inc; ++ u64 mac_val, mac_msk; + int ret; + +- /* Check first if the increment byte is present and valid. +- * If not set assume to increment the last byte if found. +- */ +- if (of_property_read_u32(np, "mac-address-increment-byte", &inc_idx)) +- inc_idx = 5; +- if (inc_idx < 3 || inc_idx > 5) +- return -EINVAL; +- + if (!np) + return -ENODEV; + +@@ -185,16 +178,24 @@ int of_get_mac_address(struct device_nod + return ret; + + found: ++ mac_val = ether_addr_to_u64(addr); ++ ++ if (!of_property_read_u64(np, "mac-address-bitwise-clear", &mac_msk)) ++ mac_val &= ~mac_msk; ++ ++ if (!of_property_read_u64(np, "mac-address-bitwise-set", &mac_msk)) ++ mac_val |= mac_msk; ++ + if (!of_property_read_u32(np, "mac-address-increment", &mac_inc)) { +- /* Convert to a contiguous value */ +- mac_val = (addr[3] << 16) + (addr[4] << 8) + addr[5]; ++ /* Check first if the increment byte is present and valid. ++ * If not set assume to increment the last byte if found. ++ */ ++ if (of_property_read_u32(np, "mac-address-increment-byte", &inc_idx)) ++ inc_idx = 5; ++ if (inc_idx < 3 || inc_idx > 5) ++ return -EINVAL; + mac_val += mac_inc << 8 * (5-inc_idx); + +- /* Apply the incremented value handling overflow case */ +- addr[3] = (mac_val >> 16) & 0xff; +- addr[4] = (mac_val >> 8) & 0xff; +- addr[5] = (mac_val >> 0) & 0xff; +- + /* Remove mac-address-increment and mac-address-increment-byte + * DT property to make sure MAC address would not get incremented + * more if this function is stared again. */ +@@ -202,6 +203,8 @@ found: + of_remove_property(np, of_find_property(np, "mac-address-increment-byte", NULL)); + } + ++ u64_to_ether_addr(mac_val, addr); ++ + of_add_mac_address(np, addr); + return ret; + } diff --git a/target/linux/generic/hack-6.1/686-of-net-add-NVMEM-cell-MAC-address-bitwise-operation-.patch b/target/linux/generic/hack-6.1/686-of-net-add-NVMEM-cell-MAC-address-bitwise-operation-.patch new file mode 100644 index 0000000000..396eed8f4a --- /dev/null +++ b/target/linux/generic/hack-6.1/686-of-net-add-NVMEM-cell-MAC-address-bitwise-operation-.patch @@ -0,0 +1,101 @@ +From: Shiji Yang +Date: Sun, 16 Jul 2023 21:00:15 +0800 +Subject: [PATCH] of: net: add DT MAC address bitwise operation support + +This patch allow user to perform basic bitwise clear/set operation on +OF DT MAC address. We use two new added dt-bindings to specific the +MAC address bits clear/set mask. "mac-address-bitwise-set" can be used +to set bit. And "mac-address-bitwise-clear" can be used to clear bit. + +The "mac-address-bitwise-*" property consists of two 32-bit(4 Bytes) +hexadecimal. The first hex number mask the Byte[1-2] and the second +one mask the Byte[3-6]. Each MAC address bit corresponds to the unique +mask bit. When setting mask bit to "1", OF driver will clear/set the +corresponding MAC address bit. + +Sample MAC Address and Property Mask: +AA: BB : CC : DD : EE : FF --> mask: <0xAABB 0xCCDDEEFF> +^ ^ ^ +Byte[1] Byte[3] Byte[6] + +Usage Example: +Assuming the base MAC address is "00:11:22:33:44:55", and we have dts +as follows. then the final MAC address should be "ff:11:22:33:44:66". + +0xff1122334466 = 0x001122334455 & (~0x0000000000ff) | 0xff0000000066 + +&gmac0 { + nvmem-cells = <&macaddr_base>; + nvmem-cell-names = "mac-address"; + mac-address-bitwise-clear = <0x0000 0x000000ff>; + mac-address-bitwise-set = <0xff00 0x00000066>; +}; + +Signed-off-by: Shiji Yang +--- + net/core/of_net.c | 35 +++++++++++++++++++---------------- + 1 file changed, 19 insertions(+), 16 deletions(-) + +--- a/net/core/of_net.c ++++ b/net/core/of_net.c +@@ -154,17 +154,10 @@ free: + */ + int of_get_mac_address(struct device_node *np, u8 *addr) + { +- u32 inc_idx, mac_inc, mac_val; ++ u32 inc_idx, mac_inc; ++ u64 mac_val, mac_msk; + int ret; + +- /* Check first if the increment byte is present and valid. +- * If not set assume to increment the last byte if found. +- */ +- if (of_property_read_u32(np, "mac-address-increment-byte", &inc_idx)) +- inc_idx = 5; +- if (inc_idx < 3 || inc_idx > 5) +- return -EINVAL; +- + if (!np) + return -ENODEV; + +@@ -185,16 +178,24 @@ int of_get_mac_address(struct device_nod + return ret; + + found: ++ mac_val = ether_addr_to_u64(addr); ++ ++ if (!of_property_read_u64(np, "mac-address-bitwise-clear", &mac_msk)) ++ mac_val &= ~mac_msk; ++ ++ if (!of_property_read_u64(np, "mac-address-bitwise-set", &mac_msk)) ++ mac_val |= mac_msk; ++ + if (!of_property_read_u32(np, "mac-address-increment", &mac_inc)) { +- /* Convert to a contiguous value */ +- mac_val = (addr[3] << 16) + (addr[4] << 8) + addr[5]; ++ /* Check first if the increment byte is present and valid. ++ * If not set assume to increment the last byte if found. ++ */ ++ if (of_property_read_u32(np, "mac-address-increment-byte", &inc_idx)) ++ inc_idx = 5; ++ if (inc_idx < 3 || inc_idx > 5) ++ return -EINVAL; + mac_val += mac_inc << 8 * (5-inc_idx); + +- /* Apply the incremented value handling overflow case */ +- addr[3] = (mac_val >> 16) & 0xff; +- addr[4] = (mac_val >> 8) & 0xff; +- addr[5] = (mac_val >> 0) & 0xff; +- + /* Remove mac-address-increment and mac-address-increment-byte + * DT property to make sure MAC address would not get incremented + * more if this function is stared again. */ +@@ -202,6 +203,8 @@ found: + of_remove_property(np, of_find_property(np, "mac-address-increment-byte", NULL)); + } + ++ u64_to_ether_addr(mac_val, addr); ++ + of_add_mac_address(np, addr); + return ret; + }