From patchwork Sat Dec 24 16:53:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 9488093 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4268F601D3 for ; Sat, 24 Dec 2016 17:02:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F2F0209CF for ; Sat, 24 Dec 2016 17:02:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21279212D9; Sat, 24 Dec 2016 17:02:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCCDF209CF for ; Sat, 24 Dec 2016 17:02:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754937AbcLXRBu (ORCPT ); Sat, 24 Dec 2016 12:01:50 -0500 Received: from mail-wj0-f195.google.com ([209.85.210.195]:33466 "EHLO mail-wj0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753533AbcLXRBs (ORCPT ); Sat, 24 Dec 2016 12:01:48 -0500 Received: by mail-wj0-f195.google.com with SMTP id kp2so44155495wjc.0; Sat, 24 Dec 2016 09:01:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xyei+ZkCTh0BUda9hpUXnYKGWwMHTCITmCGNpHPoT9A=; b=AMBCutdNGkBVJozu8JZuaSOQx2FTR2N0Ng3Iliv3bAEHSqjUClzHv1JQKBKI4isAdX TYs60rsQCzBfDTou+fl226Xyb7lsBbiiSf9pb4MXhtfmAeFI5cDenwk4rkUK+tBIA+m9 oVZzvXfCysFBQs/ObrU8X4G3SUYw27tpmXUAydCXEV88vqGTBbs2IQJyX3m8gOicFlsm A9FqgpA04zgQJ/w5fTwgylX2Ls1JPasswYPpQRTNTIgkvCuZYxpniIegU0W+HJqjyQH2 QHzw4pPjBItR2nuj/X2iMPCSX9B4Jsr9qMvAlk/qJ5eamLw/XPgpx3apw+liuTVeFe2S rccA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xyei+ZkCTh0BUda9hpUXnYKGWwMHTCITmCGNpHPoT9A=; b=YGkGpORTZUjIu2YWEkyTVG0wDIcvvlIzEkIqc4U1CXaUtqKhmJgz1yWa/N/wXaQyug cxSDXsMust0oSPWrYU8EbC4AhSx63bgOyZ3lc+8crYm28eCosZeGTI+x/PzG1kpjmU0q Gvxyi4KI0TaqEi3KemHLNhvd7cKgIHbgOk/G2yzI8ybGy+YdD/HgtTrSebO7IgOFUhX3 Fg2xzpjq0z4Fcu0fnyEcaZOI2jgu79O+ywbV94AqURNc4ODKXru7VTPwz6isXJXSyqmx 8EY4cpsu5GMaLrkREcDVF1zwsD9fR1xBoV7k0CztnO17hvJIjJWBvVWYHYoPGjhSMcE+ 16XA== X-Gm-Message-State: AIkVDXJJA+CdPcuENSXCtgkQNw17Q2WR44pYLVhcvkbbCjgUUcfmoWbrrM3MqxlvN21hRw== X-Received: by 10.194.188.40 with SMTP id fx8mr18055730wjc.128.1482598452792; Sat, 24 Dec 2016 08:54:12 -0800 (PST) Received: from localhost.localdomain (ip-88-212-34-237.antik.sk. [88.212.34.237]) by smtp.gmail.com with ESMTPSA id b15sm42736940wma.5.2016.12.24.08.54.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Dec 2016 08:54:12 -0800 (PST) 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 5/6] wl1251: Parse and use MAC address from supplied NVS data Date: Sat, 24 Dec 2016 17:53:00 +0100 Message-Id: <1482598381-16513-6-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 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch implements parsing MAC address from NVS data which are sent to wl1251 chip. Calibration NVS data could contain valid MAC address and it will be used instead randomly generated. This patch also move code for requesting NVS data from userspace to driver initialization code to make sure that NVS data will be there at time when permanent MAC address is needed. Calibration NVS data for wl1251 are model specific. Every one device with wl1251 chip should have been calibrated in factory and needs to provide own calibration data. Default example wl1251-nvs.bin data found in linux-firmware repository and contains MAC address 00:00:20:07:03:09. So this MAC address is marked as invalid as it is not real device specific address, just example one. Format of calibration NVS data can be found at: http://notaz.gp2x.de/misc/pnd/wl1251/nvs_map.txt Signed-off-by: Pali Rohár --- drivers/net/wireless/ti/wl1251/main.c | 39 ++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c index c3fa0b6..1454ba2 100644 --- a/drivers/net/wireless/ti/wl1251/main.c +++ b/drivers/net/wireless/ti/wl1251/main.c @@ -205,13 +205,6 @@ static int wl1251_chip_wakeup(struct wl1251 *wl) goto out; } - if (wl->nvs == NULL && !wl->use_eeprom) { - /* No NVS from netlink, try to get it from the filesystem */ - ret = wl1251_fetch_nvs(wl); - if (ret < 0) - goto out; - } - out: return ret; } @@ -1538,6 +1531,30 @@ static int wl1251_read_eeprom_mac(struct wl1251 *wl) return 0; } +static int wl1251_read_nvs_mac(struct wl1251 *wl) +{ + u8 mac[ETH_ALEN]; + 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++) + mac[i] = wl->nvs[0x1c + ETH_ALEN - i - 1]; + + /* 00:00:20:07:03:09 is in default example wl1251-nvs.bin, so invalid */ + if (ether_addr_equal_unaligned(mac, "\x00\x00\x20\x07\x03\x09")) + return -EINVAL; + + memcpy(wl->mac_addr, mac, ETH_ALEN); + return 0; +} + static int wl1251_register_hw(struct wl1251 *wl) { int ret; @@ -1581,10 +1598,16 @@ int wl1251_init_ieee80211(struct wl1251 *wl) wl->hw->queues = 4; + if (wl->nvs == NULL && !wl->use_eeprom) { + ret = wl1251_fetch_nvs(wl); + if (ret < 0) + goto out; + } + if (wl->use_eeprom) ret = wl1251_read_eeprom_mac(wl); else - ret = -EINVAL; + ret = wl1251_read_nvs_mac(wl); if (ret == 0 && !is_valid_ether_addr(wl->mac_addr)) ret = -EINVAL;