From patchwork Sat Jul 9 23:09:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9222187 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 3D63A60467 for ; Sat, 9 Jul 2016 23:10:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27E5F223B3 for ; Sat, 9 Jul 2016 23:10:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 075AF26538; Sat, 9 Jul 2016 23:10:25 +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 591E2223B3 for ; Sat, 9 Jul 2016 23:10:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933144AbcGIXKW (ORCPT ); Sat, 9 Jul 2016 19:10:22 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35419 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756867AbcGIXKV (ORCPT ); Sat, 9 Jul 2016 19:10:21 -0400 Received: by mail-wm0-f68.google.com with SMTP id k123so12124416wme.2 for ; Sat, 09 Jul 2016 16:10:20 -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=hv2oJDnsVg8761MJM1h0N4RiXBCORTWEBE4lHFOoZtA=; b=VQ0uodz+VdXjFXVZ6UNjfEs5wEHHCFE3qaNL1I/9w69fm4Fcy47OkfL9ibxQCzZOMm 2YlXJdX+uh/LD3cHNBISWDVoPztgT0LouVCz4/+t5epT9DxCdT5P4NrxIBN67vdk0d5t JCjXdoIZtt4sMYxr/dnd88rpHxRlpMlVW3DAGKdr96VxdvH63erp99PDQp7y+osGx2es j6d5IfJl1rk95qdw8ZzdnH+iA534slJx1QNyCQdUvS06239nUPrCxPuYT+e6Z/KkZ2WN LAC3WU8HwTm5YFHm07Ja52RciMX21IQUm0Q/yuWII7/hw1TifZctmpIDORLpuJL2BjVy gMYg== 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=hv2oJDnsVg8761MJM1h0N4RiXBCORTWEBE4lHFOoZtA=; b=Btghut2xyL9yuuQniRgudEwlu1AdV18f9cf5gRMZxBR0YQlJAfyPi3OiAjtNy06mWW F7M/oD+/WnDl3EsakfWUA5qpOL/ILfkRDzc+Rip3OlH7zIARrUmEZjR43Xbz6uvFIPtA XMdWqUBfZV4eBy00q55lodRantLra44/SnYltOe1+nRTn4yX4SlJxBwZicz4OYQlw6Re vehg4J6CN5wQofu8UERFmYoEJGIjEzR1PhQCj+Ysq8heo4NmvvO4y281l7HZBd/4p/Xc Ah4Al7lFWqhzN/S3ZW3VYuFI7in40zgvjUfe43RfZhr8K34oZJ8XXxUQl/VmHF/NpRmx j1vw== X-Gm-Message-State: ALyK8tL9EQh0hhXbHoxCTC54WfpepiNzAJHOv5kZnHwQNFSXzIAEBVCjHOEBuz5cbBob3Q== X-Received: by 10.194.87.68 with SMTP id v4mr10825276wjz.180.1468105819303; Sat, 09 Jul 2016 16:10:19 -0700 (PDT) Received: from blackbox.darklights.net (p5DE38945.dip0.t-ipconnect.de. [93.227.137.69]) by smtp.googlemail.com with ESMTPSA id jt1sm2901064wjc.8.2016.07.09.16.10.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Jul 2016 16:10:18 -0700 (PDT) From: Martin Blumenstingl To: ath9k-devel@qca.qualcomm.com, linux-wireless@vger.kernel.org, ath9k-devel@lists.ath9k.org, kvalo@qca.qualcomm.com Cc: nbd@nbd.name, Martin Blumenstingl Subject: [PATCH v2] ath9k: simplify the code-paths when not using the built-in EEPROM Date: Sun, 10 Jul 2016 01:09:55 +0200 Message-Id: <20160709230955.27266-1-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160623145714.20576-7-martin.blumenstingl@googlemail.com> References: <20160623145714.20576-7-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 --- Changes since v1: - rebased to currrent ath.git/ath-next to resolve a small merge conflict with commit "0f27ac40fb64 ath9k: return false when reading wrong eeprom offset" - renamed ath9k_hw_nvram_read_blob to ath9k_hw_nvram_read_array since that name fit the function's purpose better - fixed a bug in v1 which caused ARRAY_SIZE(pdata->eeprom_blob) to be interpreted as "count of u8", while it is actually "count of u16" (this led to some small code changes, such as introduction of the _read_pdata and _read_firmware functions to make the code easier to read) drivers/net/wireless/ath/ath9k/ahb.c | 18 +++----------- drivers/net/wireless/ath/ath9k/eeprom.c | 33 +++++++++++++++++++------ drivers/net/wireless/ath/ath9k/pci.c | 43 ++++++++++----------------------- 3 files changed, 41 insertions(+), 53 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..a449588 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,42 @@ 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, - u16 *data) +static bool ath9k_hw_nvram_read_array(u16 *blob, size_t blob_size, + off_t offset, u16 *data) { - u16 *blob_data; - - if (off * sizeof(u16) > ah->eeprom_blob->size) + if (offset > blob_size) return false; - blob_data = (u16 *)ah->eeprom_blob->data; - *data = blob_data[off]; + *data = blob[offset]; return true; } +static bool ath9k_hw_nvram_read_pdata(struct ath9k_platform_data *pdata, + off_t offset, u16 *data) +{ + return ath9k_hw_nvram_read_array(pdata->eeprom_data, + ARRAY_SIZE(pdata->eeprom_data), + offset, data); +} + +static bool ath9k_hw_nvram_read_firmware(const struct firmware *eeprom_blob, + off_t offset, u16 *data) +{ + return ath9k_hw_nvram_read_array((u16 *) eeprom_blob->data, + eeprom_blob->size / sizeof(u16), + offset, data); +} + 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_firmware(ah->eeprom_blob, off, data); + else if (pdata && !pdata->use_eeprom && pdata->eeprom_data) + ret = ath9k_hw_nvram_read_pdata(pdata, 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 aa04b13..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,37 +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); - - return false; - } - - *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; }