Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2778227lqo; Tue, 14 May 2024 08:52:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVVhkwsWH23hIKvMt/QBhFT6k7kUxfHQ+wGzsJkRMrkKY/JD34nX1rZMR9YqyeDsC5/3jhVNskAjAp+anPYdoxhbevC86Ofw3JigbgfTQ== X-Google-Smtp-Source: AGHT+IFMQk5gCapE9f9FPBVr3apoDW4gLe/JVNsMy2BAm1pv6S+Ys1SSDmqgHjEz5DpPLggHPEGf X-Received: by 2002:a19:e008:0:b0:51c:68a3:6f8e with SMTP id 2adb3069b0e04-5220fd7d378mr7384210e87.31.1715701948630; Tue, 14 May 2024 08:52:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715701948; cv=pass; d=google.com; s=arc-20160816; b=sAmWoLwnaIRKsTdNoGzrJR8x0t3BCcfnATU/uphyBqtU9/10gWz8OUN5fEdaFlpL8p hRGJdwo5QeJU3AhJUb/pGQSgzPj4UjxQyX9/CqhUc66B6J0eRx8ZX+ibGdu8GltAXiLo 41Tt+nRvWwVY5FkfHhiS53V8SnoFjib5dqc/Sgg/ar3KGvymUHIafUuttLezzJmMHN81 thABirN0lh0y5AVGf/lJ9jfMGhzgf0LiNJyeMuqj5c/zzZ9+rooeujrWnyLqYb00X2xC 6ZwqWr/k8dwefHJ81KIkHYrCPDiQbd9v0vLHJgkcWsisTnJKun8CLGzh5ACDEdB1k+Fz 88KQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=GC6vphaMtsQYBsWq7tPRncewuro5e75gbpvX8lW6DpY=; fh=vcGDIN/mfbuUPvkhvpieVvHCC+YIk0wMhqt/5Fd4KJI=; b=z6RAO8VF9k/aYFMmDtny9NbPSLUW9reTjPIP0VIMy0CsY1m5YW6EoyuE5iTVDUBp3G J+y8u2XLeCbR3gZ9EDfZmaibURdvd7b/zMDl2YpL3Ffm0ldjRFWTxmvxkwe5dm4Zq/lC 6f3gB8gspYISlNPF+JbQCRYYaaliWu+vscGulFQulzoWzXJWC3AxMrFIQZH2ZAulQI2K 5I9N8Yg9lD1RdZqneX6KmElisJ0x1/f92oCNEs5t7NYisiIQEPTW+tcvWK0XX+sUHtVR t/2WPfAhRT2BGz/sAjq5vmYxXnOUnil19jFwqCeBEH8ZrqAvrd5rF+KunFbleWiuwzw7 4fLA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=YbjS75tX; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-178885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c2d56d6si6119936a12.301.2024.05.14.08.52.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 08:52:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=YbjS75tX; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-178885-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F209C1F21C20 for ; Tue, 14 May 2024 15:52:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 932551802D3; Tue, 14 May 2024 15:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="YbjS75tX" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4453917EBA6; Tue, 14 May 2024 15:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715701892; cv=none; b=apWzzTX01mRAc4VtV/SW0ZAM4lLLMnUYuxmWLJNbcJOLIfXwGfe8QaimaJOZKXabnzPzjMlVym63vridx4v5Co11unONlnpnM9OTjjBdxgk1BgH6sKnMaEOUxFgHXQIIbWzKSKdgo8DZVsnwozaBEWQGb3q2QWRiu7JEumjTm/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715701892; c=relaxed/simple; bh=23y+UJ5pwLExAtfwQqC8M2QubpaMy0NV+G7Fb5nYuy4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OarKrE8oI5OJsM2nSos+0YLMBrDwxz9nlg6i1mPb6wUn7gJakBcZUqUc6f5ui7/dosEDkQZVmEl+50l25nWBOP5gUkqqS6IEaRaqlyMYl9eshP0JII9KBZpdiL4QE2wa7MgeWqs3USM+/ScaDm1GTgodjiM0yZb6MzqUP4kwwmg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=YbjS75tX; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 4242C1C000D; Tue, 14 May 2024 15:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715701888; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GC6vphaMtsQYBsWq7tPRncewuro5e75gbpvX8lW6DpY=; b=YbjS75tXNZ+5VHWUuHSb4yYvVB5WvVKvTf2RU7EInsv+TuqD7BFZzJyB1Grh1IEZm4Tvyl XSmWyfBk5j9pPOvEI44Wh0FsY7f2QKMNcP0mYsjTr38Og8qh5u29aFPrzuWviJHmpspZWs Vf4yWfYwQbEvprWTqVWxChEO+I1S5sclz+hOIJM4bO525kF3hJuJwiQG+iqxkgtDv0RmAj KHYyUwbSyvZpdKb1nZkKK4ZF1n6mJSDHjboTCNuBuLQcaefJPLApytnSeSXgoztLKyxkwq WIOLB2JWAMaBfBq70aqc4fd/OMUDbCLvpcGXmBh776vKso+tXA4A1XVXgsM5Ew== From: =?utf-8?q?Alexis_Lothor=C3=A9?= Date: Tue, 14 May 2024 17:51:22 +0200 Subject: [PATCH v2 4/6] wifi: wilc1000: add function to read mac address from eFuse Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240514-mac_addr_at_probe-v2-4-afef09f1cd10@bootlin.com> References: <20240514-mac_addr_at_probe-v2-0-afef09f1cd10@bootlin.com> In-Reply-To: <20240514-mac_addr_at_probe-v2-0-afef09f1cd10@bootlin.com> To: Ajay Singh , Claudiu Beznea , Kalle Valo Cc: Thomas Petazzoni , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Heiko Thiery , =?utf-8?q?Alexis_Lothor=C3=A9?= X-Mailer: b4 0.13.0 X-GND-Sasl: alexis.lothore@bootlin.com wilc driver currently reads and sets mac address by firmware calls. It means that we can not access mac address if no interface has been brought up (so firmware is up and running). Another way to get mac address is to read it directly from eFUSE. Add a function helper to read the mac address written in eFuse, without firmware assistance Signed-off-by: Alexis LothorĂ© --- Changes in v2: - move introduced helper at bottom of file - export its symbol to make it accessible from sdio/spi modules --- drivers/net/wireless/microchip/wilc1000/fw.h | 13 +++++++ drivers/net/wireless/microchip/wilc1000/netdev.h | 2 + drivers/net/wireless/microchip/wilc1000/wlan.c | 49 ++++++++++++++++++++++++ drivers/net/wireless/microchip/wilc1000/wlan.h | 1 + 4 files changed, 65 insertions(+) diff --git a/drivers/net/wireless/microchip/wilc1000/fw.h b/drivers/net/wireless/microchip/wilc1000/fw.h index 5c5cac4aab02..7a930e89614c 100644 --- a/drivers/net/wireless/microchip/wilc1000/fw.h +++ b/drivers/net/wireless/microchip/wilc1000/fw.h @@ -13,6 +13,12 @@ #define WILC_MAX_RATES_SUPPORTED 12 #define WILC_MAX_NUM_PMKIDS 16 #define WILC_MAX_NUM_SCANNED_CH 14 +#define WILC_NVMEM_MAX_NUM_BANK 6 +#define WILC_NVMEM_BANK_BASE 0x30000000 +#define WILC_NVMEM_LOW_BANK_OFFSET 0x102c +#define WILC_NVMEM_HIGH_BANK_OFFSET 0x1380 +#define WILC_NVMEM_IS_BANK_USED BIT(31) +#define WILC_NVMEM_IS_BANK_INVALID BIT(30) struct wilc_assoc_resp { __le16 capab_info; @@ -127,4 +133,11 @@ struct wilc_external_auth_param { __le32 key_mgmt_suites; __le16 status; } __packed; + +static inline u32 get_bank_offset_from_bank_index(unsigned int i) +{ + return (((i) < 2) ? WILC_NVMEM_LOW_BANK_OFFSET + ((i) * 32) : + WILC_NVMEM_HIGH_BANK_OFFSET + ((i) - 2) * 16); +} + #endif diff --git a/drivers/net/wireless/microchip/wilc1000/netdev.h b/drivers/net/wireless/microchip/wilc1000/netdev.h index eecee3973d6a..20ba030022a1 100644 --- a/drivers/net/wireless/microchip/wilc1000/netdev.h +++ b/drivers/net/wireless/microchip/wilc1000/netdev.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "hif.h" #include "wlan.h" @@ -278,6 +279,7 @@ struct wilc { struct ieee80211_rate bitrates[ARRAY_SIZE(wilc_bitrates)]; struct ieee80211_supported_band band; u32 cipher_suites[ARRAY_SIZE(wilc_cipher_suites)]; + u8 nv_mac_address[ETH_ALEN]; }; struct wilc_wfi_mon_priv { diff --git a/drivers/net/wireless/microchip/wilc1000/wlan.c b/drivers/net/wireless/microchip/wilc1000/wlan.c index 37c32d17856e..b3fee8c8b7ad 100644 --- a/drivers/net/wireless/microchip/wilc1000/wlan.c +++ b/drivers/net/wireless/microchip/wilc1000/wlan.c @@ -1472,6 +1472,55 @@ u32 wilc_get_chipid(struct wilc *wilc, bool update) return wilc->chipid; } +int wilc_load_mac_from_nv(struct wilc *wl) +{ + int ret = -EINVAL; + unsigned int i; + + acquire_bus(wl, WILC_BUS_ACQUIRE_AND_WAKEUP); + + for (i = 0; i < WILC_NVMEM_MAX_NUM_BANK; i++) { + int bank_offset = get_bank_offset_from_bank_index(i); + u32 reg1, reg2; + u8 invalid; + u8 used; + + ret = wl->hif_func->hif_read_reg(wl, + WILC_NVMEM_BANK_BASE + bank_offset, + ®1); + if (ret) { + pr_err("Can not read address %d lower part", i); + break; + } + ret = wl->hif_func->hif_read_reg(wl, + WILC_NVMEM_BANK_BASE + bank_offset + 4, + ®2); + if (ret) { + pr_err("Can not read address %d upper part", i); + break; + } + + used = FIELD_GET(WILC_NVMEM_IS_BANK_USED, reg1); + invalid = FIELD_GET(WILC_NVMEM_IS_BANK_INVALID, reg1); + if (!used || invalid) + continue; + + wl->nv_mac_address[0] = FIELD_GET(GENMASK(23, 16), reg1); + wl->nv_mac_address[1] = FIELD_GET(GENMASK(15, 8), reg1); + wl->nv_mac_address[2] = FIELD_GET(GENMASK(7, 0), reg1); + wl->nv_mac_address[3] = FIELD_GET(GENMASK(31, 24), reg2); + wl->nv_mac_address[4] = FIELD_GET(GENMASK(23, 16), reg2); + wl->nv_mac_address[5] = FIELD_GET(GENMASK(15, 8), reg2); + + ret = 0; + break; + } + + release_bus(wl, WILC_BUS_RELEASE_ALLOW_SLEEP); + return ret; +} +EXPORT_SYMBOL_GPL(wilc_load_mac_from_nv); + int wilc_wlan_init(struct net_device *dev) { int ret = 0; diff --git a/drivers/net/wireless/microchip/wilc1000/wlan.h b/drivers/net/wireless/microchip/wilc1000/wlan.h index 54643d8fef04..d72a0a81bbda 100644 --- a/drivers/net/wireless/microchip/wilc1000/wlan.h +++ b/drivers/net/wireless/microchip/wilc1000/wlan.h @@ -445,4 +445,5 @@ int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids, u32 count); int wilc_wlan_init(struct net_device *dev); u32 wilc_get_chipid(struct wilc *wilc, bool update); +int wilc_load_mac_from_nv(struct wilc *wilc); #endif -- 2.44.0