Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2778276lqo; Tue, 14 May 2024 08:52:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW0iZdZU0C0ySbaS81tcbj7MzN+hfVG2MgittZjaqMT+F/Pofj8df0A6n/wUE8QNX1vg0dVdxyv8JLg79sW4ggVoKSLNu/WyrfayWci2A== X-Google-Smtp-Source: AGHT+IEzBR5OhC99Dzu2z+Mkakz6RYyLIp/ZRqt97NlTW22kreALd/bRv7k05wyzD9kaj+AbkAA8 X-Received: by 2002:a05:622a:229f:b0:43a:c0c7:a218 with SMTP id d75a77b69052e-43dfce5d50cmr265515921cf.33.1715701953814; Tue, 14 May 2024 08:52:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715701953; cv=pass; d=google.com; s=arc-20160816; b=gwjdyHdPPNgVhDhK+bpmAJVvgyU4d0Iujx5zTUKtq3RWvyI0tN51XT+gjQ06/1GxRG PQwgFZP/d6Ybo4QkcV8XviSZQWtzKXc5ltXROJygBX8ORNSJYGvbcCYVb8HZiS1UPoiP YGUGsyJzNZeE5Bfb+9ZL+Fac5wWf6up0bCYSjmdAn+uYCKjaNd6+qJkGchqaWWAUY8SS vSEWIPfFrgOW5ChGvNL4AGloU4NhIc1uzATxl23TLYmfCqBA/jZTwCQ4odRSvj4Ri+3c u0IAKwMrxgTaa2HY0kNFEXv7mMBjq6c0pP3yaGDmxEThhCHt/E8M3QBD5PacgyLsvp6k 1WEQ== 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=Eq3Rjgw28L31fvGfHlWTTsb6g3gG5Rbyf4qVPui9ZPw=; fh=JG6OC4P8cXgmMl5Th5h73xP2tI/zwa/TGGILITuyHC4=; b=1FSurV9UL9tBUsqc9GsN5J/aBYRkxxP/2L7cQL0qCLQhtanb0rAlRbUHB3nenlgJGJ YupIORQt3jp3rj/Wb1krTpyBhiOPJUOE26xsF6zHK4gdNF9CjirPOyhjMNUa7+jXQLrc dFQEJAq8kh/jDR+suK4ovNxfzg1khmeYyq/kfzPoFwzrizrALOMhg0RjglmEmsGKjOPK Vl0qEB/bewXjNB+l/Ml1GikQ2PvKjH2MUl3SC/VMmBeJb+uCfE3x5GAFJaSjBPuy7PAn rFnakaZ8Ska5ApVLMj3xW78LoU+kaUoKYharJ1c1/cN/5wFwEfK3E7D/vN6e6XFMJACo W1/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=D4wd31aG; 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-wireless+bounces-7654-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-7654-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43df568a586si120936611cf.416.2024.05.14.08.52.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 08:52:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless+bounces-7654-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=D4wd31aG; 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-wireless+bounces-7654-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-7654-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 789491C20B66 for ; Tue, 14 May 2024 15:52:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9A5A180A68; 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="D4wd31aG" X-Original-To: linux-wireless@vger.kernel.org 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 570F617EBA9; Tue, 14 May 2024 15:51:30 +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=1715701893; cv=none; b=uGGuRYnuQt6BJkZVXSC5JhTS+N1/1y6VSaWhz7J1D8MyRMYVYJNK3R+140dCFcttaKmMdvWFd/aMUHT0reXOoTOhqRz8cEMzlYE6iihopeY58q1xWWq9uBX4QzZZBfL6SawbNrF/HKksuktkgPKKfrFKi154u6V3a8z9Mv/LMY0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715701893; c=relaxed/simple; bh=wgjBRltNMkgyiHUnfn56CYOWH+y55q5EPCYwOVEoFJc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C9yovJKB1Q4odJ4EPcdWSJyRm4UXwLiemf3MOHt63ggggmA8sWN3NZMt7tnOa80hWNvpNAXrRJCEyJYaVMoQNL9h8M7px8qmWH1RglmdjE1PFD5R6IThzvbmDcHZFeNvxeAFKK4d8MRqBk3XWieKVBAHTeWeKVE0Mthz7pPiknM= 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=D4wd31aG; 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 3FB811C0009; Tue, 14 May 2024 15:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715701889; 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=Eq3Rjgw28L31fvGfHlWTTsb6g3gG5Rbyf4qVPui9ZPw=; b=D4wd31aGiCjZyWIF3+DC4F3X7veT54su8J22YS7wOvyv/hWS72PK/RT82D053N/V6VROPp +jrAyBme0SlJhyLwsDjW2/p3l1V6UUyfplZ7FKjxHM+hBs56voGdSFFSIYlSOJjpNbqMjW O9MW99a3hEImnLBV7/Mx4NENM4kNFc/IlpMwWroq8RejtHabVUT9JL3DHo2D7OtBot+y2B NYLP3UmTKzAbDrRVETyDWEPsNpYoGuUBO0CSVb+0aO0K+QTPyaOo9tLJEva05vddo6d3iv CCcJFStjdlmivkRAQQSVV2XHU7sqUcYCen50lSpbZe4wAyD7v5UXHUQ5pHmpKw== From: =?utf-8?q?Alexis_Lothor=C3=A9?= Date: Tue, 14 May 2024 17:51:24 +0200 Subject: [PATCH v2 6/6] wifi: wilc1000: read MAC address from fuse at probe Precedence: bulk X-Mailing-List: linux-wireless@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-6-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 , Heiko Thiery , =?utf-8?q?Alexis_Lothor=C3=A9?= X-Mailer: b4 0.13.0 X-GND-Sasl: alexis.lothore@bootlin.com From: Ajay Singh The default netdev interface exposed by WILC1000 is registered at probe, but the chip mac address is not known until ndo_open, which will load and start chip firmware and then retrieve stored MAC address from it. As a consequence, the interface has uninitialized value (00:00:00:00:00) until a user brings up the interface. Fix MAC address at probe by setting the following steps: - at probe, read MAC address directly from fuse - whenever a new netdevice is created, apply saved mac address (which can be a user-provided address, or the eFuse Mac address if no address has been passed by user) - whenever an interface is brought up for the first time (and so the firmware is loaded and started), enforce netdevice mac address to the chip (in case user has changed it) Reported-by: Heiko Thiery Closes: https://lore.kernel.org/netdev/CAEyMn7aV-B4OEhHR4Ad0LM3sKCz1-nDqSb9uZNmRWR-hMZ=z+A@mail.gmail.com/T/ Signed-off-by: Ajay Singh Co-developed-by: Alexis Lothoré Signed-off-by: Alexis Lothoré Tested-by: Heiko Thiery --- drivers/net/wireless/microchip/wilc1000/netdev.c | 38 ++++++++++++++---------- drivers/net/wireless/microchip/wilc1000/sdio.c | 14 +++++++++ drivers/net/wireless/microchip/wilc1000/spi.c | 6 ++++ 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/drivers/net/wireless/microchip/wilc1000/netdev.c b/drivers/net/wireless/microchip/wilc1000/netdev.c index 2ee3d9827826..4e2698528a49 100644 --- a/drivers/net/wireless/microchip/wilc1000/netdev.c +++ b/drivers/net/wireless/microchip/wilc1000/netdev.c @@ -588,7 +588,6 @@ static int wilc_mac_open(struct net_device *ndev) struct wilc *wl = vif->wilc; int ret = 0; struct mgmt_frame_regs mgmt_regs = {}; - u8 addr[ETH_ALEN] __aligned(2); if (!wl || !wl->dev) { netdev_err(ndev, "device not ready\n"); @@ -607,25 +606,19 @@ static int wilc_mac_open(struct net_device *ndev) return ret; } - wilc_set_operation_mode(vif, wilc_get_vif_idx(vif), vif->iftype, - vif->idx); - - if (is_valid_ether_addr(ndev->dev_addr)) { - ether_addr_copy(addr, ndev->dev_addr); - wilc_set_mac_address(vif, addr); - } else { - wilc_get_mac_address(vif, addr); - eth_hw_addr_set(ndev, addr); - } netdev_dbg(ndev, "Mac address: %pM\n", ndev->dev_addr); - - if (!is_valid_ether_addr(ndev->dev_addr)) { - netdev_err(ndev, "Wrong MAC address\n"); + ret = wilc_set_mac_address(vif, ndev->dev_addr); + if (ret) { + netdev_err(ndev, "Failed to enforce MAC address in chip"); wilc_deinit_host_int(ndev); - wilc_wlan_deinitialize(ndev); - return -EINVAL; + if (!wl->open_ifcs) + wilc_wlan_deinitialize(ndev); + return ret; } + wilc_set_operation_mode(vif, wilc_get_vif_idx(vif), vif->iftype, + vif->idx); + mgmt_regs.interface_stypes = vif->mgmt_reg_stypes; /* so we detect a change */ vif->mgmt_reg_stypes = 0; @@ -941,6 +934,7 @@ struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name, int vif_type, enum nl80211_iftype type, bool rtnl_locked) { + u8 mac_address[ETH_ALEN]; struct net_device *ndev; struct wilc_vif *vif; int ret; @@ -969,6 +963,18 @@ struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name, vif->iftype = vif_type; vif->idx = wilc_get_available_idx(wl); vif->mac_opened = 0; + + memcpy(mac_address, wl->nv_mac_address, ETH_ALEN); + /* WILC firmware uses locally administered MAC address for the + * second virtual interface (bit 1 of first byte set), but + * since it is possibly not loaded/running yet, reproduce this behavior + * in the driver during interface creation. + */ + if (vif->idx) + mac_address[0] |= 0x2; + + eth_hw_addr_set(vif->ndev, mac_address); + mutex_lock(&wl->vif_mutex); list_add_tail_rcu(&vif->list, &wl->vif_list); wl->vif_num += 1; diff --git a/drivers/net/wireless/microchip/wilc1000/sdio.c b/drivers/net/wireless/microchip/wilc1000/sdio.c index 04d6565df2cb..e6e20c86b791 100644 --- a/drivers/net/wireless/microchip/wilc1000/sdio.c +++ b/drivers/net/wireless/microchip/wilc1000/sdio.c @@ -24,6 +24,9 @@ MODULE_DEVICE_TABLE(sdio, wilc_sdio_ids); #define WILC_SDIO_BLOCK_SIZE 512 +static int wilc_sdio_init(struct wilc *wilc, bool resume); +static int wilc_sdio_deinit(struct wilc *wilc); + struct wilc_sdio { bool irq_gpio; u32 block_size; @@ -178,6 +181,16 @@ static int wilc_sdio_probe(struct sdio_func *func, } clk_prepare_enable(wilc->rtc_clk); + wilc_sdio_init(wilc, false); + + ret = wilc_load_mac_from_nv(wilc); + if (ret) { + pr_err("Can not retrieve MAC address from chip\n"); + goto clk_disable_unprepare; + } + + wilc_sdio_deinit(wilc); + vif = wilc_netdev_ifc_init(wilc, "wlan%d", WILC_STATION_MODE, NL80211_IFTYPE_STATION, false); if (IS_ERR(vif)) { @@ -187,6 +200,7 @@ static int wilc_sdio_probe(struct sdio_func *func, dev_info(&func->dev, "Driver Initializing success\n"); return 0; + clk_disable_unprepare: clk_disable_unprepare(wilc->rtc_clk); dispose_irq: diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c index add0e70a09ea..5ff940c53ad9 100644 --- a/drivers/net/wireless/microchip/wilc1000/spi.c +++ b/drivers/net/wireless/microchip/wilc1000/spi.c @@ -250,6 +250,12 @@ static int wilc_bus_probe(struct spi_device *spi) if (ret) goto power_down; + ret = wilc_load_mac_from_nv(wilc); + if (ret) { + pr_err("Can not retrieve MAC address from chip\n"); + goto power_down; + } + wilc_wlan_power(wilc, false); vif = wilc_netdev_ifc_init(wilc, "wlan%d", WILC_STATION_MODE, NL80211_IFTYPE_STATION, false); -- 2.44.0