All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ping-Ke Shih <pkshih@realtek.com>
To: <kvalo@codeaurora.org>
Cc: <linux-wireless@vger.kernel.org>
Subject: [PATCH 05/24] rtw89: add efuse files
Date: Fri, 18 Jun 2021 14:46:06 +0800	[thread overview]
Message-ID: <20210618064625.14131-6-pkshih@realtek.com> (raw)
In-Reply-To: <20210618064625.14131-1-pkshih@realtek.com>

Efuse is divided into several parts, in which physical map and PHY cap
parts are read and parsed by driver.

Storing main data, physical map is translated into logic map, and then use
chip specific map to explain the logic map. Then, we can have MAC address,
country code, thermal tracking calibration values, and so on.

PHY cap part is used to store PHY data. We don't need to translate it,
because it's a direct map, like logic map.

Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
---
 drivers/net/wireless/realtek/rtw89/efuse.c | 188 +++++++++++++++++++++
 drivers/net/wireless/realtek/rtw89/efuse.h |  13 ++
 2 files changed, 201 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtw89/efuse.c
 create mode 100644 drivers/net/wireless/realtek/rtw89/efuse.h

diff --git a/drivers/net/wireless/realtek/rtw89/efuse.c b/drivers/net/wireless/realtek/rtw89/efuse.c
new file mode 100644
index 000000000000..3bea7d813985
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw89/efuse.c
@@ -0,0 +1,188 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+/* Copyright(c) 2019-2020  Realtek Corporation
+ */
+
+#include "debug.h"
+#include "efuse.h"
+#include "reg.h"
+
+enum rtw89_efuse_bank {
+	RTW89_EFUSE_BANK_WIFI,
+	RTW89_EFUSE_BANK_BT,
+};
+
+static int rtw89_switch_efuse_bank(struct rtw89_dev *rtwdev,
+				   enum rtw89_efuse_bank bank)
+{
+	u8 val;
+
+	val = rtw89_read32_mask(rtwdev, R_AX_EFUSE_CTRL_1,
+				B_AX_EF_CELL_SEL_MASK);
+	if (bank == val)
+		return 0;
+
+	rtw89_write32_mask(rtwdev, R_AX_EFUSE_CTRL_1, B_AX_EF_CELL_SEL_MASK,
+			   bank);
+
+	val = rtw89_read32_mask(rtwdev, R_AX_EFUSE_CTRL_1,
+				B_AX_EF_CELL_SEL_MASK);
+	if (bank == val)
+		return 0;
+
+	return -EBUSY;
+}
+
+static int rtw89_dump_physical_efuse_map(struct rtw89_dev *rtwdev, u8 *map,
+					 u32 dump_addr, u32 dump_size)
+{
+	u32 efuse_ctl;
+	u32 addr;
+	int ret;
+
+	rtw89_switch_efuse_bank(rtwdev, RTW89_EFUSE_BANK_WIFI);
+
+	for (addr = dump_addr; addr < dump_addr + dump_size; addr++) {
+		efuse_ctl = u32_encode_bits(addr, B_AX_EF_ADDR_MASK);
+		rtw89_write32(rtwdev, R_AX_EFUSE_CTRL, efuse_ctl & ~B_AX_EF_RDY);
+
+		ret = read_poll_timeout_atomic(rtw89_read32, efuse_ctl,
+					       efuse_ctl & B_AX_EF_RDY, 1, 1000000,
+					       true, rtwdev, R_AX_EFUSE_CTRL);
+		if (ret)
+			return -EBUSY;
+
+		*map++ = (u8)(efuse_ctl & 0xff);
+	}
+
+	return 0;
+}
+
+#define invalid_efuse_header(hdr1, hdr2) \
+	((hdr1) == 0xff || (hdr2) == 0xff)
+#define invalid_efuse_content(word_en, i) \
+	(((word_en) & BIT(i)) != 0x0)
+#define get_efuse_blk_idx(hdr1, hdr2) \
+	((((hdr2) & 0xf0) >> 4) | (((hdr1) & 0x0f) << 4))
+#define block_idx_to_logical_idx(blk_idx, i) \
+	(((blk_idx) << 3) + ((i) << 1))
+static int rtw89_dump_logical_efuse_map(struct rtw89_dev *rtwdev, u8 *phy_map,
+					u8 *log_map)
+{
+	u32 physical_size = rtwdev->chip->physical_efuse_size;
+	u32 logical_size = rtwdev->chip->logical_efuse_size;
+	u8 sec_ctrl_size = rtwdev->chip->sec_ctrl_efuse_size;
+	u32 phy_idx = sec_ctrl_size;
+	u32 log_idx;
+	u8 hdr1, hdr2;
+	u8 blk_idx;
+	u8 word_en;
+	int i;
+
+	while (phy_idx < physical_size - sec_ctrl_size) {
+		hdr1 = phy_map[phy_idx];
+		hdr2 = phy_map[phy_idx + 1];
+		if (invalid_efuse_header(hdr1, hdr2))
+			break;
+
+		blk_idx = get_efuse_blk_idx(hdr1, hdr2);
+		word_en = hdr2 & 0xf;
+		phy_idx += 2;
+
+		for (i = 0; i < 4; i++) {
+			if (invalid_efuse_content(word_en, i))
+				continue;
+
+			log_idx = block_idx_to_logical_idx(blk_idx, i);
+			if (phy_idx + 1 > physical_size - sec_ctrl_size - 1 ||
+			    log_idx + 1 > logical_size)
+				return -EINVAL;
+
+			log_map[log_idx] = phy_map[phy_idx];
+			log_map[log_idx + 1] = phy_map[phy_idx + 1];
+			phy_idx += 2;
+		}
+	}
+	return 0;
+}
+
+int rtw89_parse_efuse_map(struct rtw89_dev *rtwdev)
+{
+	u32 phy_size = rtwdev->chip->physical_efuse_size;
+	u32 log_size = rtwdev->chip->logical_efuse_size;
+	u8 *phy_map = NULL;
+	u8 *log_map = NULL;
+	int ret;
+
+	if (rtw89_read16(rtwdev, R_AX_SYS_EEPROM_CTRL) & B_AX_AUTOLOAD_SUS)
+		rtwdev->efuse.valid = true;
+	else
+		rtw89_warn(rtwdev, "failed to check efuse autoload\n");
+
+	phy_map = kmalloc(phy_size, GFP_KERNEL);
+	log_map = kmalloc(log_size, GFP_KERNEL);
+
+	if (!phy_map || !log_map) {
+		ret = -ENOMEM;
+		goto out_free;
+	}
+
+	ret = rtw89_dump_physical_efuse_map(rtwdev, phy_map, 0, phy_size);
+	if (ret) {
+		rtw89_warn(rtwdev, "failed to dump efuse physical map\n");
+		goto out_free;
+	}
+
+	memset(log_map, 0xff, log_size);
+	ret = rtw89_dump_logical_efuse_map(rtwdev, phy_map, log_map);
+	if (ret) {
+		rtw89_warn(rtwdev, "failed to dump efuse logical map\n");
+		goto out_free;
+	}
+
+	rtw89_hex_dump(rtwdev, RTW89_DBG_FW, "log_map: ", log_map, log_size);
+
+	ret = rtwdev->chip->ops->read_efuse(rtwdev, log_map);
+	if (ret) {
+		rtw89_warn(rtwdev, "failed to read efuse map\n");
+		goto out_free;
+	}
+
+out_free:
+	kfree(log_map);
+	kfree(phy_map);
+
+	return ret;
+}
+
+int rtw89_parse_phycap_map(struct rtw89_dev *rtwdev)
+{
+	u32 phycap_addr = rtwdev->chip->phycap_addr;
+	u32 phycap_size = rtwdev->chip->phycap_size;
+	u8 *phycap_map = NULL;
+	int ret = 0;
+
+	if (!phycap_size)
+		return 0;
+
+	phycap_map = kmalloc(phycap_size, GFP_KERNEL);
+	if (!phycap_map)
+		return -ENOMEM;
+
+	ret = rtw89_dump_physical_efuse_map(rtwdev, phycap_map,
+					    phycap_addr, phycap_size);
+	if (ret) {
+		rtw89_warn(rtwdev, "failed to dump phycap map\n");
+		goto out_free;
+	}
+
+	ret = rtwdev->chip->ops->read_phycap(rtwdev, phycap_map);
+	if (ret) {
+		rtw89_warn(rtwdev, "failed to read phycap map\n");
+		goto out_free;
+	}
+
+out_free:
+	kfree(phycap_map);
+
+	return ret;
+}
diff --git a/drivers/net/wireless/realtek/rtw89/efuse.h b/drivers/net/wireless/realtek/rtw89/efuse.h
new file mode 100644
index 000000000000..622ff95e7476
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtw89/efuse.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
+/* Copyright(c) 2019-2020  Realtek Corporation
+ */
+
+#ifndef __RTW89_EFUSE_H__
+#define __RTW89_EFUSE_H__
+
+#include "core.h"
+
+int rtw89_parse_efuse_map(struct rtw89_dev *rtwdev);
+int rtw89_parse_phycap_map(struct rtw89_dev *rtwdev);
+
+#endif
-- 
2.25.1


  parent reply	other threads:[~2021-06-18  6:47 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18  6:46 [PATCH 00/24] rtw89: add Realtek 802.11ax driver Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 01/24] rtw89: add CAM files Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 02/24] rtw89: add BT coexistence files Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 03/24] rtw89: add core and trx files Ping-Ke Shih
2021-07-09 17:32   ` Oleksij Rempel
2021-07-12  6:23     ` Pkshih
2021-07-15 18:57   ` Brian Norris
2021-07-16  2:00     ` Pkshih
2021-06-18  6:46 ` [PATCH 04/24] rtw89: add debug files Ping-Ke Shih
2021-07-02  7:23   ` Oleksij Rempel
2021-07-02 17:08     ` Brian Norris
2021-07-02 17:57       ` Oleksij Rempel
2021-07-02 18:38         ` Brian Norris
2021-07-02 19:32           ` Oleksij Rempel
2021-07-02 20:00             ` Brian Norris
2021-07-03  4:15               ` Oleksij Rempel
2021-07-13  1:40                 ` Brian Norris
2021-07-05  8:58           ` Pkshih
2021-07-05  9:09             ` Oleksij Rempel
2021-07-05  8:08         ` Kalle Valo
2021-07-05  9:23           ` Oleksij Rempel
2021-07-05  8:58     ` Pkshih
2021-07-13  1:57       ` Brian Norris
2021-07-13  4:50         ` Oleksij Rempel
2021-07-13 11:26           ` Pkshih
2021-06-18  6:46 ` Ping-Ke Shih [this message]
2021-06-18  6:46 ` [PATCH 06/24] rtw89: add files to download and communicate with firmware Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 07/24] rtw89: add MAC files Ping-Ke Shih
2021-07-09 17:38   ` Oleksij Rempel
2021-07-09 18:16     ` Johannes Berg
2021-07-10  4:58       ` Oleksij Rempel
2021-07-12  1:51         ` Pkshih
2021-07-12  6:23     ` Pkshih
2021-06-18  6:46 ` [PATCH 08/24] rtw89: implement mac80211 ops Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 09/24] rtw89: add pci files Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 10/24] rtw89: add phy files Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 11/24] rtw89: define register names Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 12/24] rtw89: add regulatory support Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 13/24] rtw89: 8852a: add 8852a specific files Ping-Ke Shih
2021-07-10  5:27   ` Oleksij Rempel
2021-07-12  6:24     ` Pkshih
2021-06-18  6:46 ` [PATCH 14/24] rtw89: 8852a: add 8852a RFK files Ping-Ke Shih
2021-07-09 17:41   ` Oleksij Rempel
2021-07-12  6:23     ` Pkshih
2021-07-15  3:33     ` Pkshih
2021-07-15  3:59       ` Oleksij Rempel
2021-06-18  6:46 ` [PATCH 15/24] rtw89: 8852a: add 8852a RFK tables Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 16/24] rtw89: 8852a: add 8852a tables (1 of 5) Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 17/24] rtw89: 8852a: add 8852a tables (2 " Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 18/24] rtw89: 8852a: add 8852a tables (3 " Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 19/24] rtw89: 8852a: add 8852a tables (4 " Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 20/24] rtw89: 8852a: add 8852a tables (5 " Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 21/24] rtw89: add ser to recover error reported by firmware Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 22/24] rtw89: add PS files Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 23/24] rtw89: add SAR files Ping-Ke Shih
2021-06-18  6:46 ` [PATCH 24/24] rtw89: add Kconfig and Makefile Ping-Ke Shih
2021-06-19  3:18   ` kernel test robot
2021-06-19  3:18     ` kernel test robot
2021-06-25  8:54     ` Pkshih
2021-06-25  8:54       ` Pkshih
2021-06-19  3:18   ` kernel test robot
2021-06-19  3:18     ` kernel test robot
2021-06-18  7:11 ` [PATCH 00/24] rtw89: add Realtek 802.11ax driver Pkshih
2021-06-23  6:29 ` Aaron Ma
2021-06-30  4:52   ` Aaron Ma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210618064625.14131-6-pkshih@realtek.com \
    --to=pkshih@realtek.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.