From patchwork Thu Jun 23 14:57:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9195403 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 16C7B6075F for ; Thu, 23 Jun 2016 14:57:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07BAA2843A for ; Thu, 23 Jun 2016 14:57:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0AD02845B; Thu, 23 Jun 2016 14:57:48 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 4D1A72843A for ; Thu, 23 Jun 2016 14:57:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751357AbcFWO5q (ORCPT ); Thu, 23 Jun 2016 10:57:46 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35700 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751308AbcFWO5p (ORCPT ); Thu, 23 Jun 2016 10:57:45 -0400 Received: by mail-wm0-f65.google.com with SMTP id a66so11659980wme.2 for ; Thu, 23 Jun 2016 07:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oiGotG3llMwafB0aI+i6y2lobhhHlEgyFIvY5LPngRU=; b=ozlc7qo/ij+pjtibGGWt+zbF/7VyY3C/aAP2CMPdkKdHCejw7BapEPDLQeta3+XBXO HbJvSfKGvbB+3TqLIvQo16bJDg0Y8dVaBroHx1Doomd5Yb9NVOfZwOROGP7WaYqbo58/ HgIOrDg6pC9S4snc9ser2Ss9F/BAYcXCfCKKecfMK11FfPd3gl0m9bpHDZFoeotW4Lpj 1nzKXZlu5enrJBi6fvGIBHary2LslF6RRK86n5GBj+J8QWQX2FB1MT3vlailasPcFWSc 4evjqL83Bgevd22jv7zwJvU6SZMkjHG/TbbWLk303AHHaJrunxuGb+JIc2Q/CjCqV9Ty 61Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oiGotG3llMwafB0aI+i6y2lobhhHlEgyFIvY5LPngRU=; b=ClFBhQty++cHJ2JTAt19u5CUQbLv/9U1EGjJRXgBllIODWvUKh4MN8GAq8WrGv/k2I nkdn6O93CPcsHpgwwZVbYUaeSchI0qO/iJklUoeXc/gOyy1IhpwFQTRLAmvVopw4GHON E+SecsxYtC6MfgtcFMn34IVaU0XMieWUYmbGG9YOusBQZvUKc7cLf525rNTveYxZoz+k S/PNJlQKtFgVYfK4uy8qHZ/KJguD2AZfWH9A/D022aonPHzaq97yBh6u3j61cNp2wPNm MSx65Y0Mo3C6VwOG3Xc5vJ9oHfaUvRvutWiz0orN+44JQEHrG1uMsEZyZP8v7tvdU/fk ZAEw== X-Gm-Message-State: ALyK8tJrDgrSERdUQRn2KkIVIGAEAHjK0TNKkQexmVOQDODueQX8EP+oNgwg6bG5VwcuLw== X-Received: by 10.194.178.167 with SMTP id cz7mr12850219wjc.66.1466693863731; Thu, 23 Jun 2016 07:57:43 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD3CD1B0478F6703992958538.dip0.t-ipconnect.de. [2003:dc:d3cd:1b04:78f6:7039:9295:8538]) by smtp.googlemail.com with ESMTPSA id yr4sm535503wjc.18.2016.06.23.07.57.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jun 2016 07:57:43 -0700 (PDT) From: Martin Blumenstingl To: ath9k-devel@qca.qualcomm.com, linux-wireless@vger.kernel.org, ath9k-devel@lists.ath9k.org Cc: nbd@nbd.name, Martin Blumenstingl Subject: [PATCH 6/6] ath9k: simplify the code-paths when not using the built-in EEPROM Date: Thu, 23 Jun 2016 16:57:14 +0200 Message-Id: <20160623145714.20576-7-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160623145714.20576-1-martin.blumenstingl@googlemail.com> References: <20160623145714.20576-1-martin.blumenstingl@googlemail.com> 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 There were two paths in the code for "external" eeprom sources. The code in eeprom.c only handled the cases where the eeprom data was loaded via request_firmware. ahb.c and pci.c on the other hand had some duplicate code which was only used when the eeprom data was passed via ath9k_platform_data. With this change all eeprom data handling is now unified in eeprom.c. Signed-off-by: Martin Blumenstingl --- This supersedes the following patch by Eduardo Abinader : "ath9k: return false when reading wrong eeprom offset" https://patchwork.kernel.org/patch/9181371/ drivers/net/wireless/ath/ath9k/ahb.c | 18 +++------------ drivers/net/wireless/ath/ath9k/eeprom.c | 19 +++++++++------ drivers/net/wireless/ath/ath9k/pci.c | 41 +++++++++++---------------------- 3 files changed, 28 insertions(+), 50 deletions(-) diff --git a/drivers/net/wireless/ath/ath9k/ahb.c b/drivers/net/wireless/ath/ath9k/ahb.c index bd4a1a6..bea6186 100644 --- a/drivers/net/wireless/ath/ath9k/ahb.c +++ b/drivers/net/wireless/ath/ath9k/ahb.c @@ -18,7 +18,6 @@ #include #include -#include #include #include "ath9k.h" @@ -58,20 +57,9 @@ static void ath_ahb_read_cachesize(struct ath_common *common, int *csz) static bool ath_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data) { - struct ath_softc *sc = (struct ath_softc *)common->priv; - struct platform_device *pdev = to_platform_device(sc->dev); - struct ath9k_platform_data *pdata; - - pdata = dev_get_platdata(&pdev->dev); - if (off >= (ARRAY_SIZE(pdata->eeprom_data))) { - ath_err(common, - "%s: flash read failed, offset %08x is out of range\n", - __func__, off); - return false; - } - - *data = pdata->eeprom_data[off]; - return true; + ath_err(common, "%s: eeprom data has to be provided externally\n", + __func__); + return false; } static struct ath_bus_ops ath_ahb_bus_ops = { diff --git a/drivers/net/wireless/ath/ath9k/eeprom.c b/drivers/net/wireless/ath/ath9k/eeprom.c index a794157..ba1c8ba 100644 --- a/drivers/net/wireless/ath/ath9k/eeprom.c +++ b/drivers/net/wireless/ath/ath9k/eeprom.c @@ -15,6 +15,7 @@ */ #include "hw.h" +#include void ath9k_hw_analog_shift_regwrite(struct ath_hw *ah, u32 reg, u32 val) { @@ -108,26 +109,30 @@ void ath9k_hw_usb_gen_fill_eeprom(struct ath_hw *ah, u16 *eep_data, } } -static bool ath9k_hw_nvram_read_blob(struct ath_hw *ah, u32 off, +static bool ath9k_hw_nvram_read_blob(u16 *blob, size_t blob_size, u32 offset, u16 *data) { - u16 *blob_data; - - if (off * sizeof(u16) > ah->eeprom_blob->size) + if (offset * sizeof(u16) > blob_size) return false; - blob_data = (u16 *)ah->eeprom_blob->data; - *data = blob_data[off]; + *data = blob[offset]; return true; } bool ath9k_hw_nvram_read(struct ath_hw *ah, u32 off, u16 *data) { struct ath_common *common = ath9k_hw_common(ah); + struct ath9k_platform_data *pdata = ah->dev->platform_data; bool ret; if (ah->eeprom_blob) - ret = ath9k_hw_nvram_read_blob(ah, off, data); + ret = ath9k_hw_nvram_read_blob((u16 *) ah->eeprom_blob->data, + ah->eeprom_blob->size, off, + data); + else if (pdata && !pdata->use_eeprom && pdata->eeprom_data) + ret = ath9k_hw_nvram_read_blob(pdata->eeprom_data, + ARRAY_SIZE(pdata->eeprom_data), + off, data); else ret = common->bus_ops->eeprom_read(common, off, data); diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c index 7cdaf40..0dd454a 100644 --- a/drivers/net/wireless/ath/ath9k/pci.c +++ b/drivers/net/wireless/ath/ath9k/pci.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include "ath9k.h" @@ -786,35 +785,21 @@ static void ath_pci_read_cachesize(struct ath_common *common, int *csz) static bool ath_pci_eeprom_read(struct ath_common *common, u32 off, u16 *data) { - struct ath_softc *sc = (struct ath_softc *) common->priv; - struct ath9k_platform_data *pdata = sc->dev->platform_data; - - if (pdata && !pdata->use_eeprom) { - if (off >= (ARRAY_SIZE(pdata->eeprom_data))) { - ath_err(common, - "%s: eeprom read failed, offset %08x is out of range\n", - __func__, off); - } - - *data = pdata->eeprom_data[off]; - } else { - struct ath_hw *ah = (struct ath_hw *) common->ah; - - common->ops->read(ah, AR5416_EEPROM_OFFSET + - (off << AR5416_EEPROM_S)); - - if (!ath9k_hw_wait(ah, - AR_EEPROM_STATUS_DATA, - AR_EEPROM_STATUS_DATA_BUSY | - AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0, - AH_WAIT_TIMEOUT)) { - return false; - } - - *data = MS(common->ops->read(ah, AR_EEPROM_STATUS_DATA), - AR_EEPROM_STATUS_DATA_VAL); + struct ath_hw *ah = (struct ath_hw *) common->ah; + + common->ops->read(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S)); + + if (!ath9k_hw_wait(ah, + AR_EEPROM_STATUS_DATA, + AR_EEPROM_STATUS_DATA_BUSY | + AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0, + AH_WAIT_TIMEOUT)) { + return false; } + *data = MS(common->ops->read(ah, AR_EEPROM_STATUS_DATA), + AR_EEPROM_STATUS_DATA_VAL); + return true; }