Received: by 10.223.185.116 with SMTP id b49csp1043513wrg; Wed, 21 Feb 2018 11:05:44 -0800 (PST) X-Google-Smtp-Source: AH8x224MAREgDD6N8E4ulcuC2fEsNWBwniU9YFFVuIZ1OCDLosoIuM+Fu6D3oPyMg1IOKIOq68Yq X-Received: by 2002:a17:902:6589:: with SMTP id c9-v6mr3982570plk.51.1519239944813; Wed, 21 Feb 2018 11:05:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519239944; cv=none; d=google.com; s=arc-20160816; b=0SwY4X7COxNm38GP8HPoGh7+14Pdye2AMRkww6C9iKTO7OXT0x3w5PHRWGTzeTC65P 3qdPsCkTfdZI+sJFwCRtLW5Y//5T2omBYwERJb7Bj5xsA/svJijVcqjHatSGkxHinBCD pF820ykvGgqUdzgdFPfSdqWW0OjVluRqkoGMSgvjxVgIf0ODQEukwkXDyJeGEhQtx10x +OPEoBWEI1XYJz2Bix/Z68Y5YTZmyxGg8ZX4H7v8u2+9My5XreEwNX+CYtnqXVHPU327 b++wenadlR3HQbFWG0bN2grga6e5RcepIuIlw6fbrTtvawBJxRPAeRTMyUlx+z8m/lkb Ef1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ru/rH1siKtPjG0bZFCPawAbXEhMRwiZA02wayPPVFug=; b=ioGc/aOfsuEnrr7bXnkfDmFhtgOxLm8eC+JewJmbzoX0Yq1JHFCukmd+HrTw9VDhCX 3wJoC7cmUnQKVoxFLAMtzeAkTrJs+L/3fVnlOQwkSvr2Iv99wwvVLpG8/aqkyzd709fs UwlE/qdLLqPP4f30iOy+zno3VJbewIRcVClKKvMkfStbn0jX0j3DmKNRjkIE3AjijBPY KiwKdFi2vOP/HNGl1LsN0Gd1pfdOsnMAHU7xtM14baLKfBxB4XgQeA9/Ez44Pa75A02J wvwTDbqlwV2s0nRXtPGF38PvhfvrKTm9kSGKjqh+bmg3afmHLC65gGprWip2k2mYCKVC VBmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bQ8TWuLQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n27si493049pfg.102.2018.02.21.11.05.30; Wed, 21 Feb 2018 11:05:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bQ8TWuLQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937175AbeBUQnr (ORCPT + 99 others); Wed, 21 Feb 2018 11:43:47 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:35386 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933097AbeBUQnp (ORCPT ); Wed, 21 Feb 2018 11:43:45 -0500 Received: by mail-qt0-f193.google.com with SMTP id g14so2693044qti.2 for ; Wed, 21 Feb 2018 08:43:45 -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; bh=ru/rH1siKtPjG0bZFCPawAbXEhMRwiZA02wayPPVFug=; b=bQ8TWuLQaRbz/rM3LJFK6/coQszfyJ0tB5Ok4xy1o4i5qxfe6TCEedsHT0XiYe9ecA MqHodQLuPrKovQzLWGDnPxPxKQZEmEJeYFySLGPKHPC11p6glk7HXf6AnD4VOSY+Czkz bwJiXBnEUmgxzP9qXGO/oUbA3tsnO8JRKpMwg7Ss6yJOhSxAnT/qqEFHGtxrixUWFfr3 o1/P94ufmvXpkPi5SbYD/GNtB82eJqyecHvabO/t09gxxqb73LVQA1q6VEsItKtZHL4n AOr0u0dFp289j+0LGdQKNQ9LwHd2VHQhXd8FgubKjlXuyUBXjR/waHPEVSB/PFLAyOrD 4eLA== 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; bh=ru/rH1siKtPjG0bZFCPawAbXEhMRwiZA02wayPPVFug=; b=YVxkC1bj2q2sDuOZ2IW7xWJMTeT88Xd1WfS7GNedqNxxTZcHauOFBEjL54jSY06Y3M 8EmT2sD5MsH2o7uFxkhupnAJWtzVY5PutBsg+RlUCDeEj9SpVrFHh397TepSKcjD+4tz f3fJ2A0BRBM7px5+Q3I3Tu+OU7rfNCCKzmRrQv1pvNqBMq5kX8sdAWsYrM76zhiMfOB3 0EPmafXhVK/FIv/VXhaD41+Yp1vHEUgspJYVYYZl+kiv2Nrqz7T5FX6zNU+x3x44PKEs sTlGG3rYurbhfzOhMRwInJFt9BJQDas4f4gWFknZXQhP0yYQs/gW1N9NTu3w7K7E0UK8 LDvA== X-Gm-Message-State: APf1xPBehcC9UqWh3x0xAYAtZu4O4OX8IO+Hp4msUicX+AFFfesE1vnX P+gTUXNc3RcNKJagnOep8/OvHUS/s8Y= X-Received: by 10.200.47.101 with SMTP id k34mr6401303qta.151.1519231424756; Wed, 21 Feb 2018 08:43:44 -0800 (PST) Received: from stingray.tufts.edu ([2601:18d:4600:e68c:3252:cbff:fe84:d255]) by smtp.gmail.com with ESMTPSA id m30sm17027039qkh.91.2018.02.21.08.43.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 08:43:43 -0800 (PST) From: Thomas Hebb To: Kalle Valo , ath10k@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Thomas Hebb Subject: [PATCH] ath10k: search all IEs for variant before falling back Date: Wed, 21 Feb 2018 11:43:39 -0500 Message-Id: X-Mailer: git-send-email 2.16.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit f2593cb1b291 ("ath10k: Search SMBIOS for OEM board file extension") added a feature to ath10k that allows Board Data File (BDF) conflicts between multiple devices that use the same device IDs but have different calibration requirements to be resolved by allowing a "variant" string to be stored in SMBIOS [and later device tree, added by commit d06f26c5c8a4 ("ath10k: search DT for qcom,ath10k-calibration- variant")] that gets appended to the ID stored in board-2.bin. This original patch had a regression, however. Namely that devices with a variant present in SMBIOS that didn't need custom BDFs could no longer find the default BDF, which has no variant appended. The patch was reverted and re-applied with a fix for this issue in commit 1657b8f84ed9 ("search SMBIOS for OEM board file extension"). But the fix to fall back to a default BDF introduced another issue: the driver currently parses IEs in board-2.bin one by one, and for each one it first checks to see if it matches the ID with the variant appended. If it doesn't, it checks to see if it matches the "fallback" ID with no variant. If a matching BDF is found at any point during this search, the search is terminated and that BDF is used. The issue is that it's very possible (and is currently the case for board-2.bin files present in the ath10k-firmware repository) for the default BDF to occur in an earlier IE than the variant-specific BDF. In this case, the current code will happily choose the default BDF even though a better-matching BDF is present later in the file. This patch fixes the issue by first searching the entire file for the ID with variant, and searching for the fallback ID only if that search fails. It also includes some code cleanup in the area, as ath10k_core_fetch_board_data_api_n() no longer does its own string mangling to remove the variant from an ID, instead leaving that job to a new flag passed to ath10k_core_create_board_name(). I've tested this patch on a QCA4019 and verified that the driver behaves correctly for 1) both fallback and variant BDFs present, 2) only fallback BDF present, and 3) no matching BDFs present. Fixes: 1657b8f84ed9 ("ath10k: search SMBIOS for OEM board file extension") Signed-off-by: Thomas Hebb --- drivers/net/wireless/ath/ath10k/core.c | 134 ++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 62 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c index f3ec13b80b20..2233f7e8cc68 100644 --- a/drivers/net/wireless/ath/ath10k/core.c +++ b/drivers/net/wireless/ath/ath10k/core.c @@ -1252,14 +1252,61 @@ static int ath10k_core_parse_bd_ie_board(struct ath10k *ar, return ret; } +static int ath10k_core_search_bd(struct ath10k *ar, + const char *boardname, + const u8 *data, + size_t len) +{ + size_t ie_len; + struct ath10k_fw_ie *hdr; + int ret = -ENOENT, ie_id; + + while (len > sizeof(struct ath10k_fw_ie)) { + hdr = (struct ath10k_fw_ie *)data; + ie_id = le32_to_cpu(hdr->id); + ie_len = le32_to_cpu(hdr->len); + + len -= sizeof(*hdr); + data = hdr->data; + + if (len < ALIGN(ie_len, 4)) { + ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n", + ie_id, ie_len, len); + return -EINVAL; + } + + switch (ie_id) { + case ATH10K_BD_IE_BOARD: + ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len, + boardname); + if (ret == -ENOENT) + /* no match found, continue */ + break; + + /* either found or error, so stop searching */ + goto out; + } + + /* jump over the padding */ + ie_len = ALIGN(ie_len, 4); + + len -= ie_len; + data += ie_len; + } + +out: + /* return result of parse_bd_ie_board() or -ENOENT */ + return ret; +} + static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar, const char *boardname, + const char *fallback_boardname, const char *filename) { - size_t len, magic_len, ie_len; - struct ath10k_fw_ie *hdr; + size_t len, magic_len; const u8 *data; - int ret, ie_id; + int ret; ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, @@ -1297,69 +1344,23 @@ static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar, data += magic_len; len -= magic_len; - while (len > sizeof(struct ath10k_fw_ie)) { - hdr = (struct ath10k_fw_ie *)data; - ie_id = le32_to_cpu(hdr->id); - ie_len = le32_to_cpu(hdr->len); - - len -= sizeof(*hdr); - data = hdr->data; - - if (len < ALIGN(ie_len, 4)) { - ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n", - ie_id, ie_len, len); - ret = -EINVAL; - goto err; - } + /* attempt to find boardname in the IE list */ + ret = ath10k_core_search_bd(ar, boardname, data, len); - switch (ie_id) { - case ATH10K_BD_IE_BOARD: - ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len, - boardname); - if (ret == -ENOENT && ar->id.bdf_ext[0] != '\0') { - /* try default bdf if variant was not found */ - char *s, *v = ",variant="; - char boardname2[100]; - - strlcpy(boardname2, boardname, - sizeof(boardname2)); - - s = strstr(boardname2, v); - if (s) - *s = '\0'; /* strip ",variant=%s" */ + /* if we didn't find it and have a fallback name, try that */ + if (ret == -ENOENT && fallback_boardname) + ret = ath10k_core_search_bd(ar, fallback_boardname, data, len); - ret = ath10k_core_parse_bd_ie_board(ar, data, - ie_len, - boardname2); - } - - if (ret == -ENOENT) - /* no match found, continue */ - break; - else if (ret) - /* there was an error, bail out */ - goto err; - - /* board data found */ - goto out; - } - - /* jump over the padding */ - ie_len = ALIGN(ie_len, 4); - - len -= ie_len; - data += ie_len; - } - -out: - if (!ar->normal_mode_fw.board_data || !ar->normal_mode_fw.board_len) { + if (ret == -ENOENT) { ath10k_err(ar, "failed to fetch board data for %s from %s/%s\n", boardname, ar->hw_params.fw.dir, filename); ret = -ENODATA; - goto err; } + if (ret) + goto err; + return 0; err: @@ -1368,12 +1369,12 @@ static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar, } static int ath10k_core_create_board_name(struct ath10k *ar, char *name, - size_t name_len) + size_t name_len, bool with_variant) { /* strlen(',variant=') + strlen(ar->id.bdf_ext) */ char variant[9 + ATH10K_SMBIOS_BDF_EXT_STR_LENGTH] = { 0 }; - if (ar->id.bdf_ext[0] != '\0') + if (with_variant && ar->id.bdf_ext[0] != '\0') scnprintf(variant, sizeof(variant), ",variant=%s", ar->id.bdf_ext); @@ -1399,17 +1400,26 @@ static int ath10k_core_create_board_name(struct ath10k *ar, char *name, static int ath10k_core_fetch_board_file(struct ath10k *ar) { - char boardname[100]; + char boardname[100], fallback_boardname[100]; int ret; - ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname)); + ret = ath10k_core_create_board_name(ar, boardname, + sizeof(boardname), true); if (ret) { ath10k_err(ar, "failed to create board name: %d", ret); return ret; } + ret = ath10k_core_create_board_name(ar, fallback_boardname, + sizeof(boardname), false); + if (ret) { + ath10k_err(ar, "failed to create fallback board name: %d", ret); + return ret; + } + ar->bd_api = 2; ret = ath10k_core_fetch_board_data_api_n(ar, boardname, + fallback_boardname, ATH10K_BOARD_API2_FILE); if (!ret) goto success; -- 2.16.2