All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ping-Ke Shih <pkshih@realtek.com>
To: Ali Ghandour <gandour.ali@gmail.com>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Subject: RE: Lenovo LOQ rtw_8852be
Date: Tue, 26 Dec 2023 03:42:03 +0000	[thread overview]
Message-ID: <ec85daec1dd64b2ca731078cd0dd95d3@realtek.com> (raw)
In-Reply-To: CAOE0c94tf8y2hv0QHKEiuo5a7Ly=oJAw+g4Uh6BktHOMdbWY1Q@mail.gmail.com

[-- Attachment #1: Type: text/plain, Size: 1248 bytes --]

Hi Ali,

> -----Original Message-----
> From: Ping-Ke Shih
> Sent: Tuesday, December 12, 2023 2:02 PM
> To: 'Ali Ghandour' <gandour.ali@gmail.com>
> Cc: linux-wireless@vger.kernel.org
> Subject: RE: Lenovo LOQ rtw_8852be
> 
> > -----Original Message-----
> > From: Ali Ghandour <gandour.ali@gmail.com>
> > Sent: Tuesday, December 12, 2023 1:36 PM
> > To: Ping-Ke Shih <pkshih@realtek.com>
> > Cc: linux-wireless@vger.kernel.org
> > Subject: Re: Lenovo LOQ rtw_8852be
> >
> > > Please try below workaround patch to ignore the setting. I have tried that, and
> > > in my side it still works without obvious problem. I will check internally to
> > > check how much this can affect. If not, I would ignore this if certain platform
> > > like yours can't access PCI space over 0x100.
> >
> > I was able to connect. Thanks a lot Ping-Ke!
> >
> 
> Good. Please use it as usual and monitor if it works stable. I would like
> take your results as reference to decide how I can modify the driver.
> 

After internal discussion, people suggest to implement DBI to access PCI config
space as attached patch. Please help to revert workaround and apply this one,
and give us kernel log to see if it works as expected.

Ping-Ke


[-- Attachment #2: 0001-wifi-rtw89-pci-use-DBI-function-for-8852AE-8852BE-88.patch --]
[-- Type: application/octet-stream, Size: 3824 bytes --]

From 0974cd95c6cf3e6096035ee639354b69bd6ca954 Mon Sep 17 00:00:00 2001
From: Chin-Yen Lee <timlee@realtek.com>
Date: Fri, 15 Dec 2023 18:55:28 +0800
Subject: [PATCH] wifi: rtw89: pci: use DBI function for 8852AE/8852BE/8851BE

Sometimes driver can't use kernel api pci_read/write_config_byte
to access the pci config space of above address 0x100 due to
the negotiated pci setting. 8852AE/8852BE/8851BE provide another
way called dbi function, which belongs to wifi mac and could
access all pci config space for this case.

Change-Id: I34f4b70accfab24aec8ff33ddfdc9ee3a31e8e6a
Signed-off-by: Chin-Yen Lee <timlee@realtek.com>
---
 pci.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 pci.h |  1 +
 2 files changed, 68 insertions(+), 2 deletions(-)

diff --git a/pci.c b/pci.c
index e66396dfecb7..c48cb9183c68 100644
--- a/pci.c
+++ b/pci.c
@@ -1907,22 +1907,87 @@ static int rtw89_write16_mdio_clr(struct rtw89_dev *rtwdev, u8 addr, u16 mask, u
 	return 0;
 }
 
+static int rtw89_dbi_write8(struct rtw89_dev *rtwdev, u16 addr, u8 data)
+{
+	u16 addr_2lsb = addr & B_AX_DBI_2LSB;
+	u16 write_addr;
+	u8 flag;
+	int ret;
+
+	write_addr = addr & B_AX_DBI_ADDR_MSK;
+	write_addr |= u16_encode_bits(BIT(addr_2lsb), B_AX_DBI_WREN_MSK);
+	rtw89_write8(rtwdev, R_AX_DBI_WDATA + addr_2lsb, data);
+	rtw89_write16(rtwdev, R_AX_DBI_FLAG, write_addr);
+	rtw89_write8(rtwdev, R_AX_DBI_FLAG + 2, B_AX_DBI_WFLAG >> 16);
+
+	ret = read_poll_timeout_atomic(rtw89_read8, flag, !flag, 10,
+				       10 * RTW89_PCI_WR_RETRY_CNT, false,
+				       rtwdev, R_AX_DBI_FLAG + 2);
+	if (ret)
+		rtw89_err(rtwdev, "failed to write DBI register, addr=0x%X\n",
+			  addr);
+
+	return ret;
+}
+
+static int rtw89_dbi_read8(struct rtw89_dev *rtwdev, u16 addr, u8 *value)
+{
+	u16 read_addr = addr & B_AX_DBI_ADDR_MSK;
+	u8 flag;
+	int ret;
+
+	rtw89_write16(rtwdev, R_AX_DBI_FLAG, read_addr);
+	rtw89_write8(rtwdev, R_AX_DBI_FLAG + 2, B_AX_DBI_RFLAG >> 16);
+
+	ret = read_poll_timeout_atomic(rtw89_read8, flag, !flag, 10,
+				       10 * RTW89_PCI_WR_RETRY_CNT, false,
+				       rtwdev, R_AX_DBI_FLAG + 2);
+	if (ret) {
+		rtw89_err(rtwdev, "failed to read DBI register, addr=0x%X\n",
+			  addr);
+		return ret;
+	}
+
+	read_addr = R_AX_DBI_RDATA + (addr & 3);
+	*value = rtw89_read8(rtwdev, read_addr);
+
+	return 0;
+}
+
 static int rtw89_pci_write_config_byte(struct rtw89_dev *rtwdev, u16 addr,
 				       u8 data)
 {
 	struct rtw89_pci *rtwpci = (struct rtw89_pci *)rtwdev->priv;
+	enum rtw89_core_chip_id chip_id = rtwdev->chip->chip_id;
 	struct pci_dev *pdev = rtwpci->pdev;
+	int ret;
+
+	ret = pci_write_config_byte(pdev, addr, data);
+	if (!ret)
+		return 0;
 
-	return pci_write_config_byte(pdev, addr, data);
+	if (chip_id == RTL8852A || chip_id == RTL8852B || chip_id == RTL8851B)
+		ret = rtw89_dbi_write8(rtwdev, addr, data);
+
+	return ret;
 }
 
 static int rtw89_pci_read_config_byte(struct rtw89_dev *rtwdev, u16 addr,
 				      u8 *value)
 {
 	struct rtw89_pci *rtwpci = (struct rtw89_pci *)rtwdev->priv;
+	enum rtw89_core_chip_id chip_id = rtwdev->chip->chip_id;
 	struct pci_dev *pdev = rtwpci->pdev;
+	int ret;
 
-	return pci_read_config_byte(pdev, addr, value);
+	ret = pci_read_config_byte(pdev, addr, value);
+	if (!ret)
+		return 0;
+
+	if (chip_id == RTL8852A || chip_id == RTL8852B || chip_id == RTL8851B)
+		ret = rtw89_dbi_read8(rtwdev, addr, value);
+
+	return ret;
 }
 
 static int rtw89_pci_config_byte_set(struct rtw89_dev *rtwdev, u16 addr,
diff --git a/pci.h b/pci.h
index ca5de77fee90..1fb7c209fa0d 100644
--- a/pci.h
+++ b/pci.h
@@ -42,6 +42,7 @@
 #define B_AX_DBI_WFLAG			BIT(16)
 #define B_AX_DBI_WREN_MSK		GENMASK(15, 12)
 #define B_AX_DBI_ADDR_MSK		GENMASK(11, 2)
+#define B_AX_DBI_2LSB			GENMASK(1, 0)
 #define R_AX_DBI_WDATA			0x1094
 #define R_AX_DBI_RDATA			0x1098
 
-- 
2.25.1


  parent reply	other threads:[~2023-12-26  3:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1700948088-16140-mlmmj-666d2532@vger.kernel.org>
2023-11-25 21:35 ` Lenovo LOQ rtw_8852be Ali Ghandour
2023-11-27  1:42   ` Ping-Ke Shih
2023-11-27  6:01     ` Ali Ghandour
2023-11-27  6:19       ` Ali Ghandour
2023-11-28  1:21         ` Ping-Ke Shih
2023-12-02  9:23           ` Ali Ghandour
2023-12-05  0:39             ` Ping-Ke Shih
2023-12-05  6:12               ` Ali Ghandour
2023-12-06  2:41                 ` Ping-Ke Shih
2023-12-10  6:24                   ` Ali Ghandour
2023-12-11  1:53                     ` Ping-Ke Shih
2023-12-12  5:36                       ` Ali Ghandour
2023-12-12  6:01                         ` Ping-Ke Shih
2023-12-26  3:42                         ` Ping-Ke Shih [this message]
     [not found]                           ` <CAOE0c95hkCdoKksAO5KhfVPuH1r8bpWXyM4Q_B+R2N-mJFz4yA@mail.gmail.com>
2024-01-03  0:13                             ` Ping-Ke Shih

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=ec85daec1dd64b2ca731078cd0dd95d3@realtek.com \
    --to=pkshih@realtek.com \
    --cc=gandour.ali@gmail.com \
    --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.