From patchwork Tue Aug 11 00:58:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Daney X-Patchwork-Id: 6987341 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E19E8C05AC for ; Tue, 11 Aug 2015 01:08:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 044F4201ED for ; Tue, 11 Aug 2015 01:08:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 192AB201E4 for ; Tue, 11 Aug 2015 01:08:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZOy17-0006wn-Ni; Tue, 11 Aug 2015 01:06:13 +0000 Received: from mail-ig0-x230.google.com ([2607:f8b0:4001:c05::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZOy14-0006uk-FI for linux-arm-kernel@lists.infradead.org; Tue, 11 Aug 2015 01:06:11 +0000 Received: by igui7 with SMTP id i7so30579703igu.1 for ; Mon, 10 Aug 2015 18:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZK3aKsZiMmf+C2JGbMfLNHBgzGVHFDdcQY5SMzWktYM=; b=CXy7BVZGB987vjjHwXVGH5qgiz0m0M/A6BU8pxyHiYWnRZk6z96a4kllDUh9DNxU6m SnztnUu4I2sO1LkJy9GkNsIYAWB3Mzj2rY0SCMedPLbTRwOAQ9m9mVr2POPfYBhZmfx/ E0wHxiQcbtWGFc97+AZAOEspnPEK+YV/IMMvC2EhRuFzDQFhhV/suXZgRmfR+d45sID8 Pv1bg3vS5aT7ietkHCcPrTSZwMO47Tp5YAlB4mOEpj4fDUsPsXVZlvMQVHeHWWTvPb8Y goUEv/2r5LN5BPBMSPdd3e68A1nPBfFcXvzaxoI7X8EnNESJsgsNg1EFSFyJN8GtY7a/ qGQg== X-Received: by 10.50.138.76 with SMTP id qo12mr15513239igb.38.1439254728751; Mon, 10 Aug 2015 17:58:48 -0700 (PDT) Received: from dl.caveonetworks.com (64.2.3.194.ptr.us.xo.net. [64.2.3.194]) by smtp.gmail.com with ESMTPSA id r4sm7026965igh.9.2015.08.10.17.58.46 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 10 Aug 2015 17:58:47 -0700 (PDT) Received: from dl.caveonetworks.com (localhost.localdomain [127.0.0.1]) by dl.caveonetworks.com (8.14.5/8.14.5) with ESMTP id t7B0wjP5002919; Mon, 10 Aug 2015 17:58:45 -0700 Received: (from ddaney@localhost) by dl.caveonetworks.com (8.14.5/8.14.5/Submit) id t7B0wiq7002918; Mon, 10 Aug 2015 17:58:44 -0700 From: David Daney To: netdev@vger.kernel.org, "David S. Miller" , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] net, thunder, bgx: Add support to get MAC address from ACPI. Date: Mon, 10 Aug 2015 17:58:37 -0700 Message-Id: <1439254717-2875-3-git-send-email-ddaney.cavm@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1439254717-2875-1-git-send-email-ddaney.cavm@gmail.com> References: <1439254717-2875-1-git-send-email-ddaney.cavm@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150810_180610_563455_457D833F X-CRM114-Status: GOOD ( 17.28 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , linux-mips@linux-mips.org, rafael@kernel.org, David Daney , Tomasz Nowicki , Robert Richter , linux-acpi@vger.kernel.org, Sunil Goutham , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: David Daney Currently there is no way to get the MAC address in a firmware independent manner, so set the MAC address of the device directly from the ACPI tables. The binding agrees with the proposed standard here: http://www.uefi.org/sites/default/files/resources/nic-request-v2.pdf Based on code from: Narinder Dhillon Tomasz Nowicki Robert Richter Signed-off-by: Tomasz Nowicki Signed-off-by: Robert Richter Signed-off-by: David Daney --- drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 86 ++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c index 615b2af..5e54186 100644 --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c @@ -6,6 +6,7 @@ * as published by the Free Software Foundation. */ +#include #include #include #include @@ -26,7 +27,7 @@ struct lmac { struct bgx *bgx; int dmac; - unsigned char mac[ETH_ALEN]; + u8 mac[ETH_ALEN]; bool link_up; int lmacid; /* ID within BGX */ int lmacid_bd; /* ID on board */ @@ -835,6 +836,86 @@ static void bgx_get_qlm_mode(struct bgx *bgx) } } +#ifdef CONFIG_ACPI + +static int acpi_get_mac_address(struct acpi_device *adev, u8 *dst) +{ + u8 mac[ETH_ALEN]; + int ret; + + ret = fwnode_property_read_u8_array(acpi_fwnode_handle(adev), + "mac-address", mac, ETH_ALEN); + if (ret) + goto out; + + if (!is_valid_ether_addr(mac)) { + ret = -EINVAL; + goto out; + } + + memcpy(dst, mac, ETH_ALEN); +out: + return ret; +} + +/* Currently only sets the MAC address. */ +static acpi_status bgx_acpi_register_phy(acpi_handle handle, + u32 lvl, void *context, void **rv) +{ + struct bgx *bgx = context; + struct acpi_device *adev; + + if (acpi_bus_get_device(handle, &adev)) + goto out; + + acpi_get_mac_address(adev, bgx->lmac[bgx->lmac_count].mac); + + SET_NETDEV_DEV(&bgx->lmac[bgx->lmac_count].netdev, &bgx->pdev->dev); + + bgx->lmac[bgx->lmac_count].lmacid = bgx->lmac_count; +out: + bgx->lmac_count++; + return AE_OK; +} + +static acpi_status bgx_acpi_match_id(acpi_handle handle, u32 lvl, + void *context, void **ret_val) +{ + struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; + struct bgx *bgx = context; + char bgx_sel[5]; + + snprintf(bgx_sel, 5, "BGX%d", bgx->bgx_id); + if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &string))) { + pr_warn("Invalid link device\n"); + return AE_OK; + } + + if (strncmp(string.pointer, bgx_sel, 4)) + return AE_OK; + + acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1, + bgx_acpi_register_phy, NULL, bgx, NULL); + + kfree(string.pointer); + return AE_CTRL_TERMINATE; +} + +static int bgx_init_acpi_phy(struct bgx *bgx) +{ + acpi_get_devices(NULL, bgx_acpi_match_id, bgx, (void **)NULL); + return 0; +} + +#else + +static int bgx_init_acpi_phy(struct bgx *bgx) +{ + return -ENODEV; +} + +#endif /* CONFIG_ACPI */ + #if IS_ENABLED(CONFIG_OF_MDIO) static int bgx_init_of_phy(struct bgx *bgx) @@ -882,6 +963,9 @@ static int bgx_init_of_phy(struct bgx *bgx) static int bgx_init_phy(struct bgx *bgx) { + if (!acpi_disabled) + return bgx_init_acpi_phy(bgx); + return bgx_init_of_phy(bgx); }