Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1433483pxb; Thu, 28 Oct 2021 03:42:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFSWbq2+NgPcMHAtI6JbuIZLqau4MmntYMVwQ05L3JMmpVsmIRMq+aPYvLwap/HmJ/0kDA X-Received: by 2002:a50:99c6:: with SMTP id n6mr4940382edb.171.1635417728677; Thu, 28 Oct 2021 03:42:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635417728; cv=none; d=google.com; s=arc-20160816; b=t1uY8f2ObbD2qjTtyux+wj/kl4UQZtbP1UQGEi7KLc4l79UwwAd14S2g+pyzSlzUPV vTN5XhnHfg16QBaK4RSC283XlrrYI/CReL6qJoaKNoLV+IIVZ5QQeVmDguOiF1wJLa9d 1Q5esuAGJpDQYUltMZlouprjTibNGTgoeFUglfikNqEGO/BSN0GcW3/GV39GZrpwdBVQ rXM+5symW6kvmQJRzpZySOpXijCuaovOEChDV7SVn0oBgTrh4ZufjXx/Dl5DrBKpQaJa 4eaExgUvRCNJDnWnfpu68XT0au2vQxTBCNpNjFZjVr557u+NjVD12V3D2xTiERqJ4X2t F5UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=id/MnZB1ukSXh0UyXTTDaVrqYwlatifecBHZYL0HGCc=; b=xqXvqLuzMd5H4nHtM+B32yDDgZY+f80aDjaYEkG+C6q77dLKPXNglzYksQ6A2Uup3G +WISkmkaZbV5RPRs+HwCQ0dDe/vN1IWDAH7pg9x2VxgYGVp37+t1+6/VFgJpeddp4kw3 QHW3TA83XuuRX12YWDGtwx3IE4sAQQ5qqu8rkC8O5bTNUuRLjBxkrex8NLIJpvpwP/rV jTGZnHmgHUiQZDdFxyKA5qi//cTLugceUfv2HXeBS1lOFtrNE8k6yg6JKLC4et0zYk5T q7Zzr0XwZUV4b47Cnr3geAOKidtvQqdrmoSc0gojw/ctzz7nWXMZyXUO4q3RzvSqO/9W g4kg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u1si4016171edp.348.2021.10.28.03.41.48; Thu, 28 Oct 2021 03:42:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229775AbhJ1KoC (ORCPT + 67 others); Thu, 28 Oct 2021 06:44:02 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:59068 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229835AbhJ1KoB (ORCPT ); Thu, 28 Oct 2021 06:44:01 -0400 X-UUID: 96d34b3098694bb5b0937d5446ff412f-20211028 X-UUID: 96d34b3098694bb5b0937d5446ff412f-20211028 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1888420858; Thu, 28 Oct 2021 18:41:30 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Thu, 28 Oct 2021 18:41:29 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 28 Oct 2021 18:41:29 +0800 From: Shayne Chen To: Felix Fietkau CC: linux-wireless , Lorenzo Bianconi , Ryder Lee , "Evelyn Tsai" , linux-mediatek , Shayne Chen , Bo Jiao Subject: [PATCH v2] mt76: mt7915: add default calibrated data support Date: Thu, 28 Oct 2021 18:41:24 +0800 Message-ID: <20211028104124.4872-1-shayne.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Load the default eeprom data when the content of flash/efuse is invalid. This could help to eliminate some issues due to incorrect or insufficient rf values. Co-developed-by: Bo Jiao Signed-off-by: Bo Jiao Signed-off-by: Shayne Chen Reviewed-by: Ryder Lee --- v2: drop unnecessary goto and return --- .../wireless/mediatek/mt76/mt7915/eeprom.c | 81 +++++++++++++++---- .../net/wireless/mediatek/mt76/mt7915/mcu.c | 24 ++++++ .../net/wireless/mediatek/mt76/mt7915/mcu.h | 1 + .../wireless/mediatek/mt76/mt7915/mt7915.h | 4 + 4 files changed, 96 insertions(+), 14 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c index ee3d644..a21a6fa 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: ISC /* Copyright (C) 2020 MediaTek Inc. */ +#include #include "mt7915.h" #include "eeprom.h" @@ -10,6 +11,9 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) u8 *eeprom = mdev->eeprom.data; u32 val = eeprom[MT_EE_DO_PRE_CAL]; + if (!dev->flash_mode) + return 0; + if (val != (MT_EE_WIFI_CAL_DPD | MT_EE_WIFI_CAL_GROUP)) return 0; @@ -21,6 +25,49 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) return mt76_get_of_eeprom(mdev, dev->cal, MT_EE_PRECAL, val); } +static int mt7915_check_eeprom(struct mt7915_dev *dev) +{ + u8 *eeprom = dev->mt76.eeprom.data; + u16 val = get_unaligned_le16(eeprom); + + switch (val) { + case 0x7915: + return 0; + default: + return -EINVAL; + } +} + +static int +mt7915_eeprom_load_default(struct mt7915_dev *dev) +{ + char *default_bin = MT7915_EEPROM_DEFAULT; + u8 *eeprom = dev->mt76.eeprom.data; + const struct firmware *fw = NULL; + int ret; + + if (dev->dbdc_support) + default_bin = MT7915_EEPROM_DEFAULT_DBDC; + + ret = request_firmware(&fw, default_bin, dev->mt76.dev); + if (ret) + return ret; + + if (!fw || !fw->data) { + dev_err(dev->mt76.dev, "Invalid default bin\n"); + ret = -EINVAL; + goto out; + } + + memcpy(eeprom, fw->data, MT7915_EEPROM_SIZE); + dev->flash_mode = true; + +out: + release_firmware(fw); + + return ret; +} + static int mt7915_eeprom_load(struct mt7915_dev *dev) { int ret; @@ -31,8 +78,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) if (ret) { dev->flash_mode = true; - ret = mt7915_eeprom_load_precal(dev); } else { + /* read eeprom data from efuse */ u32 block_num, i; block_num = DIV_ROUND_UP(MT7915_EEPROM_SIZE, @@ -42,20 +89,26 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) i * MT7915_EEPROM_BLOCK_SIZE); } - return ret; -} - -static int mt7915_check_eeprom(struct mt7915_dev *dev) -{ - u8 *eeprom = dev->mt76.eeprom.data; - u16 val = get_unaligned_le16(eeprom); + if (!dev->flash_mode) { + u8 free_block_num; + + mt7915_mcu_get_eeprom_free_block(dev, &free_block_num); + if (free_block_num >= 29) { + dev_warn(dev->mt76.dev, + "efuse info not enough, use default bin\n"); + ret = mt7915_eeprom_load_default(dev); + if (ret) + return ret; + } + } - switch (val) { - case 0x7915: - return 0; - default: - return -EINVAL; + ret = mt7915_check_eeprom(dev); + if (ret) { + dev_warn(dev->mt76.dev, "eeprom check fail, use default bin\n"); + ret = mt7915_eeprom_load_default(dev); } + + return ret; } void mt7915_eeprom_parse_band_config(struct mt7915_phy *phy) @@ -120,7 +173,7 @@ int mt7915_eeprom_init(struct mt7915_dev *dev) if (ret < 0) return ret; - ret = mt7915_check_eeprom(dev); + ret = mt7915_eeprom_load_precal(dev); if (ret) return ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c index b054663..ee9952d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c @@ -3580,6 +3580,30 @@ int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset) return 0; } +int mt7915_mcu_get_eeprom_free_block(struct mt7915_dev *dev, u8 *block_num) +{ + struct { + u8 _rsv; + u8 version; + u8 die_idx; + u8 _rsv2; + } __packed req = { + .version = 1, + }; + struct sk_buff *skb; + int ret; + + ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(EFUSE_FREE_BLOCK), &req, + sizeof(req), true, &skb); + if (ret) + return ret; + + *block_num = *(u8 *)skb->data; + dev_kfree_skb(skb); + + return 0; +} + static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx, u8 *data, u32 len, int cmd) { diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h index b563e7c..e9f39ed 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h @@ -278,6 +278,7 @@ enum { MCU_EXT_CMD_MUAR_UPDATE = 0x48, MCU_EXT_CMD_RX_AIRTIME_CTRL = 0x4a, MCU_EXT_CMD_SET_RX_PATH = 0x4e, + MCU_EXT_CMD_EFUSE_FREE_BLOCK = 0x4f, MCU_EXT_CMD_TX_POWER_FEATURE_CTRL = 0x58, MCU_EXT_CMD_GET_MIB_INFO = 0x5a, MCU_EXT_CMD_MWDS_SUPPORT = 0x80, diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h index e69b4c8..c6c846d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h @@ -30,6 +30,9 @@ #define MT7915_FIRMWARE_WM "mediatek/mt7915_wm.bin" #define MT7915_ROM_PATCH "mediatek/mt7915_rom_patch.bin" +#define MT7915_EEPROM_DEFAULT "mediatek/mt7915_eeprom.bin" +#define MT7915_EEPROM_DEFAULT_DBDC "mediatek/mt7915_eeprom_dbdc.bin" + #define MT7915_EEPROM_SIZE 3584 #define MT7915_EEPROM_BLOCK_SIZE 16 #define MT7915_TOKEN_SIZE 8192 @@ -423,6 +426,7 @@ int mt7915_mcu_set_fixed_rate_ctrl(struct mt7915_dev *dev, void *data, u32 field); int mt7915_mcu_set_eeprom(struct mt7915_dev *dev); int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset); +int mt7915_mcu_get_eeprom_free_block(struct mt7915_dev *dev, u8 *block_num); int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable, bool hdr_trans); int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode, -- 2.25.1