Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755852AbcLXRCX (ORCPT ); Sat, 24 Dec 2016 12:02:23 -0500 Received: from mail-wj0-f196.google.com ([209.85.210.196]:35755 "EHLO mail-wj0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755530AbcLXRCU (ORCPT ); Sat, 24 Dec 2016 12:02:20 -0500 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Ming Lei , "Luis R. Rodriguez" , Greg Kroah-Hartman , Kalle Valo , David Gnedt , Michal Kazior , Daniel Wagner , Tony Lindgren , Sebastian Reichel , Pavel Machek , Ivaylo Dimitrov , Aaro Koskinen , Grazvydas Ignotas Cc: linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [PATCH 6/6] wl1251: Set generated MAC address back to NVS data Date: Sat, 24 Dec 2016 17:53:01 +0100 Message-Id: <1482598381-16513-7-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1482598381-16513-1-git-send-email-pali.rohar@gmail.com> References: <1482598381-16513-1-git-send-email-pali.rohar@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1577 Lines: 50 In case there is no valid MAC address kernel generates random one. This patch propagate this generated MAC address back to NVS data which will be uploaded to wl1251 chip. So HW would have same MAC address as linux kernel uses. Signed-off-by: Pali Rohár --- drivers/net/wireless/ti/wl1251/main.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c index 1454ba2..895ae05 100644 --- a/drivers/net/wireless/ti/wl1251/main.c +++ b/drivers/net/wireless/ti/wl1251/main.c @@ -1555,6 +1555,24 @@ static int wl1251_read_nvs_mac(struct wl1251 *wl) return 0; } +static int wl1251_write_nvs_mac(struct wl1251 *wl) +{ + int i; + + if (wl->nvs_len < 0x24) + return -ENODATA; + + /* length is 2 and data address is 0x546c (mask is 0xfffe) */ + if (wl->nvs[0x19] != 2 || wl->nvs[0x1a] != 0x6d || wl->nvs[0x1b] != 0x54) + return -EINVAL; + + /* MAC is stored in reverse order */ + for (i = 0; i < ETH_ALEN; i++) + wl->nvs[0x1c + i] = wl->mac_addr[ETH_ALEN - i - 1]; + + return 0; +} + static int wl1251_register_hw(struct wl1251 *wl) { int ret; @@ -1620,6 +1638,8 @@ int wl1251_init_ieee80211(struct wl1251 *wl) static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf}; memcpy(wl->mac_addr, nokia_oui, 3); get_random_bytes(wl->mac_addr + 3, 3); + if (!wl->use_eeprom) + wl1251_write_nvs_mac(wl); wl1251_warning("MAC address in eeprom or nvs data is not valid"); wl1251_warning("Setting random MAC address: %pM", wl->mac_addr); } -- 1.7.9.5