* [PATCH 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
@ 2025-04-22 11:28 Hans Zhang
2025-04-22 11:28 ` [PATCH 1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG Hans Zhang
` (3 more replies)
0 siblings, 4 replies; 15+ messages in thread
From: Hans Zhang @ 2025-04-22 11:28 UTC (permalink / raw)
To: lpieralisi, kw, bhelgaas, heiko
Cc: manivannan.sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip, Hans Zhang
1. PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG
2. PCI: dw-rockchip: Reorganize register and bitfield definitions
3. PCI: dw-rockchip: Unify link status checks with FIELD_GET
---
https://patchwork.kernel.org/project/linux-pci/patch/20250416151926.140202-1-18255117159@163.com/
Bjorn Helgaas:
These would be material for a separate patch:
- The #defines for register offsets and bits are kind of a mess,
e.g., PCIE_SMLH_LINKUP, PCIE_RDLH_LINKUP, PCIE_LINKUP,
PCIE_L0S_ENTRY, and PCIE_LTSSM_STATUS_MASK are in
PCIE_CLIENT_LTSSM_STATUS, but you couldn't tell that from the
names, and they're not even defined together.
- Same for PCIE_RDLH_LINK_UP_CHGED, PCIE_LINK_REQ_RST_NOT_INT,
PCIE_RDLH_LINK_UP_CHGED, which are in PCIE_CLIENT_INTR_STATUS_MISC.
- PCIE_LTSSM_ENABLE_ENHANCE is apparently in PCIE_CLIENT_HOT_RESET_CTRL?
Sure wouldn't guess that from the names or the order of #defines.
- PCIE_CLIENT_GENERAL_DEBUG isn't used at all.
- Submissions based on the following v5 patches:
https://patchwork.kernel.org/project/linux-pci/patch/1744850111-236269-1-git-send-email-shawn.lin@rock-chips.com/
https://patchwork.kernel.org/project/linux-pci/patch/1744850111-236269-2-git-send-email-shawn.lin@rock-chips.com/
https://patchwork.kernel.org/project/linux-pci/patch/1744850111-236269-3-git-send-email-shawn.lin@rock-chips.com/
https://patchwork.kernel.org/project/linux-pci/patch/1744940759-23823-1-git-send-email-shawn.lin@rock-chips.com/
---
Hans Zhang (3):
PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG
PCI: dw-rockchip: Reorganize register and bitfield definitions
PCI: dw-rockchip: Unify link status checks with FIELD_GET
drivers/pci/controller/dwc/pcie-dw-rockchip.c | 58 +++++++++----------
1 file changed, 29 insertions(+), 29 deletions(-)
base-commit: 9d7a0577c9db35c4cc52db90bc415ea248446472
prerequisite-patch-id: 5d9f110f238212cde763b841f1337d0045d93f5b
prerequisite-patch-id: b63975b89227a41b9b6d701c9130ee342848c8b6
prerequisite-patch-id: 46f02da0db4737b46cd06cd0d25ba69b8d789f90
prerequisite-patch-id: d06e25de3658b73ad85d148728ed3948bfcec731
--
2.25.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG
2025-04-22 11:28 [PATCH 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
@ 2025-04-22 11:28 ` Hans Zhang
2025-04-22 11:35 ` Niklas Cassel
2025-04-22 11:28 ` [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
` (2 subsequent siblings)
3 siblings, 1 reply; 15+ messages in thread
From: Hans Zhang @ 2025-04-22 11:28 UTC (permalink / raw)
To: lpieralisi, kw, bhelgaas, heiko
Cc: manivannan.sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip, Hans Zhang
The PCIE_CLIENT_GENERAL_DEBUG register offset is defined but never
used in the driver. Its presence adds noise to the register map and
may mislead future developers.
Remove this redundant definition to keep the register list minimal
and aligned with actual hardware usage.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/pci/controller/dwc/pcie-dw-rockchip.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
index 0e0c09bafd63..fd5827bbfae3 100644
--- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
+++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -54,7 +54,6 @@
#define PCIE_CLIENT_GENERAL_CONTROL 0x0
#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
-#define PCIE_CLIENT_GENERAL_DEBUG 0x104
#define PCIE_CLIENT_HOT_RESET_CTRL 0x180
#define PCIE_CLIENT_LTSSM_STATUS 0x300
#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-22 11:28 [PATCH 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
2025-04-22 11:28 ` [PATCH 1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG Hans Zhang
@ 2025-04-22 11:28 ` Hans Zhang
2025-04-22 11:47 ` Niklas Cassel
2025-04-22 12:30 ` Niklas Cassel
2025-04-22 11:28 ` [PATCH 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET Hans Zhang
2025-04-22 11:35 ` [PATCH 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
3 siblings, 2 replies; 15+ messages in thread
From: Hans Zhang @ 2025-04-22 11:28 UTC (permalink / raw)
To: lpieralisi, kw, bhelgaas, heiko
Cc: manivannan.sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip, Hans Zhang
Register definitions were scattered with ambiguous names (e.g.,
PCIE_RDLH_LINK_UP_CHGED in PCIE_CLIENT_INTR_STATUS_MISC) and lacked
hierarchical grouping. Magic values for bit operations reduced code
clarity.
Group registers and their associated bitfields logically. This improves
maintainability and aligns the code with hardware documentation.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/pci/controller/dwc/pcie-dw-rockchip.c | 42 +++++++++++--------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
index fd5827bbfae3..cdc8afc6cfc1 100644
--- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
+++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -8,6 +8,7 @@
* Author: Simon Xue <xxm@rock-chips.com>
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/gpio/consumer.h>
#include <linux/irqchip/chained_irq.h>
@@ -34,30 +35,35 @@
#define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
-#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
-#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
-#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
-#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
-#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x04
+#define PCIE_CLIENT_GENERAL_CONTROL 0x0
+#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
+#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
+#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
+#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
+
+#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x4
+#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
+
#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
+#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
+#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
+
+#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
#define PCIE_CLIENT_INTR_MASK_MISC 0x24
+
#define PCIE_CLIENT_POWER 0x2c
+#define PME_READY_ENTER_L23 BIT(3)
+
#define PCIE_CLIENT_MSG_GEN 0x34
-#define PME_READY_ENTER_L23 BIT(3)
-#define PME_TURN_OFF (BIT(4) | BIT(20))
-#define PME_TO_ACK (BIT(9) | BIT(25))
-#define PCIE_SMLH_LINKUP BIT(16)
-#define PCIE_RDLH_LINKUP BIT(17)
-#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
-#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
-#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
-#define PCIE_CLIENT_GENERAL_CONTROL 0x0
-#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
-#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
+#define PME_TURN_OFF HIWORD_UPDATE_BIT(BIT(4))
+#define PME_TO_ACK HIWORD_UPDATE_BIT(BIT(9))
+
#define PCIE_CLIENT_HOT_RESET_CTRL 0x180
+#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
+
#define PCIE_CLIENT_LTSSM_STATUS 0x300
-#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
-#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
+#define PCIE_LINKUP_MASK GENMASK(17, 16)
+#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
struct rockchip_pcie {
struct dw_pcie pci;
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET
2025-04-22 11:28 [PATCH 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
2025-04-22 11:28 ` [PATCH 1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG Hans Zhang
2025-04-22 11:28 ` [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
@ 2025-04-22 11:28 ` Hans Zhang
2025-04-22 11:39 ` Niklas Cassel
2025-04-22 11:35 ` [PATCH 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
3 siblings, 1 reply; 15+ messages in thread
From: Hans Zhang @ 2025-04-22 11:28 UTC (permalink / raw)
To: lpieralisi, kw, bhelgaas, heiko
Cc: manivannan.sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip, Hans Zhang
Link-up detection manually checked PCIE_LINKUP bits across RC/EP modes,
leading to code duplication. Centralize the logic using FIELD_GET. This
removes redundancy and abstracts hardware-specific bit masking, ensuring
consistent link state handling.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/pci/controller/dwc/pcie-dw-rockchip.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
index cdc8afc6cfc1..2b26060af5c2 100644
--- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
+++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -196,10 +196,7 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
u32 val = rockchip_pcie_get_ltssm(rockchip);
- if ((val & PCIE_LINKUP) == PCIE_LINKUP)
- return 1;
-
- return 0;
+ return FIELD_GET(PCIE_LINKUP_MASK, val) == 3;
}
static void rockchip_pcie_enable_l0s(struct dw_pcie *pci)
@@ -499,7 +496,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
struct dw_pcie *pci = &rockchip->pci;
struct dw_pcie_rp *pp = &pci->pp;
struct device *dev = pci->dev;
- u32 reg, val;
+ u32 reg;
reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
@@ -508,8 +505,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
dev_dbg(dev, "LTSSM_STATUS: %#x\n", rockchip_pcie_get_ltssm(rockchip));
if (reg & PCIE_RDLH_LINK_UP_CHGED) {
- val = rockchip_pcie_get_ltssm(rockchip);
- if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
+ if (rockchip_pcie_link_up(pci)) {
dev_dbg(dev, "Received Link up event. Starting enumeration!\n");
/* Rescan the bus to enumerate endpoint devices */
pci_lock_rescan_remove();
@@ -526,7 +522,7 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
struct rockchip_pcie *rockchip = arg;
struct dw_pcie *pci = &rockchip->pci;
struct device *dev = pci->dev;
- u32 reg, val;
+ u32 reg;
reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
@@ -540,8 +536,7 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
}
if (reg & PCIE_RDLH_LINK_UP_CHGED) {
- val = rockchip_pcie_get_ltssm(rockchip);
- if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
+ if (rockchip_pcie_link_up(pci)) {
dev_dbg(dev, "link up\n");
dw_pcie_ep_linkup(&pci->ep);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG
2025-04-22 11:28 ` [PATCH 1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG Hans Zhang
@ 2025-04-22 11:35 ` Niklas Cassel
0 siblings, 0 replies; 15+ messages in thread
From: Niklas Cassel @ 2025-04-22 11:35 UTC (permalink / raw)
To: Hans Zhang
Cc: lpieralisi, kw, bhelgaas, heiko, manivannan.sadhasivam, robh,
jingoohan1, shawn.lin, linux-pci, linux-kernel, linux-arm-kernel,
linux-rockchip
On Tue, Apr 22, 2025 at 07:28:28PM +0800, Hans Zhang wrote:
> The PCIE_CLIENT_GENERAL_DEBUG register offset is defined but never
> used in the driver. Its presence adds noise to the register map and
> may mislead future developers.
>
> Remove this redundant definition to keep the register list minimal
> and aligned with actual hardware usage.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> index 0e0c09bafd63..fd5827bbfae3 100644
> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> @@ -54,7 +54,6 @@
> #define PCIE_CLIENT_GENERAL_CONTROL 0x0
> #define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
> #define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
> -#define PCIE_CLIENT_GENERAL_DEBUG 0x104
> #define PCIE_CLIENT_HOT_RESET_CTRL 0x180
> #define PCIE_CLIENT_LTSSM_STATUS 0x300
> #define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
> --
> 2.25.1
>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-22 11:28 [PATCH 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
` (2 preceding siblings ...)
2025-04-22 11:28 ` [PATCH 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET Hans Zhang
@ 2025-04-22 11:35 ` Hans Zhang
3 siblings, 0 replies; 15+ messages in thread
From: Hans Zhang @ 2025-04-22 11:35 UTC (permalink / raw)
To: lpieralisi, kw, bhelgaas, heiko
Cc: manivannan.sadhasivam, robh, jingoohan1, shawn.lin, linux-pci,
linux-kernel, linux-arm-kernel, linux-rockchip
On 2025/4/22 19:28, Hans Zhang wrote:
> 1. PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG
> 2. PCI: dw-rockchip: Reorganize register and bitfield definitions
> 3. PCI: dw-rockchip: Unify link status checks with FIELD_GET
>
> ---
> https://patchwork.kernel.org/project/linux-pci/patch/20250416151926.140202-1-18255117159@163.com/
>
> Bjorn Helgaas:
> These would be material for a separate patch:
>
> - The #defines for register offsets and bits are kind of a mess,
> e.g., PCIE_SMLH_LINKUP, PCIE_RDLH_LINKUP, PCIE_LINKUP,
> PCIE_L0S_ENTRY, and PCIE_LTSSM_STATUS_MASK are in
> PCIE_CLIENT_LTSSM_STATUS, but you couldn't tell that from the
> names, and they're not even defined together.
>
> - Same for PCIE_RDLH_LINK_UP_CHGED, PCIE_LINK_REQ_RST_NOT_INT,
> PCIE_RDLH_LINK_UP_CHGED, which are in PCIE_CLIENT_INTR_STATUS_MISC.
>
> - PCIE_LTSSM_ENABLE_ENHANCE is apparently in PCIE_CLIENT_HOT_RESET_CTRL?
> Sure wouldn't guess that from the names or the order of #defines.
>
> - PCIE_CLIENT_GENERAL_DEBUG isn't used at all.
>
> - Submissions based on the following v5 patches:
I'm very sorry. It should be like this:
- Submissions based on the following patches:
> https://patchwork.kernel.org/project/linux-pci/patch/1744850111-236269-1-git-send-email-shawn.lin@rock-chips.com/
> https://patchwork.kernel.org/project/linux-pci/patch/1744850111-236269-2-git-send-email-shawn.lin@rock-chips.com/
> https://patchwork.kernel.org/project/linux-pci/patch/1744850111-236269-3-git-send-email-shawn.lin@rock-chips.com/
> https://patchwork.kernel.org/project/linux-pci/patch/1744940759-23823-1-git-send-email-shawn.lin@rock-chips.com/
> ---
>
> Hans Zhang (3):
> PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG
> PCI: dw-rockchip: Reorganize register and bitfield definitions
> PCI: dw-rockchip: Unify link status checks with FIELD_GET
>
> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 58 +++++++++----------
> 1 file changed, 29 insertions(+), 29 deletions(-)
>
>
> base-commit: 9d7a0577c9db35c4cc52db90bc415ea248446472
> prerequisite-patch-id: 5d9f110f238212cde763b841f1337d0045d93f5b
> prerequisite-patch-id: b63975b89227a41b9b6d701c9130ee342848c8b6
> prerequisite-patch-id: 46f02da0db4737b46cd06cd0d25ba69b8d789f90
> prerequisite-patch-id: d06e25de3658b73ad85d148728ed3948bfcec731
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET
2025-04-22 11:28 ` [PATCH 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET Hans Zhang
@ 2025-04-22 11:39 ` Niklas Cassel
2025-04-22 11:50 ` Hans Zhang
0 siblings, 1 reply; 15+ messages in thread
From: Niklas Cassel @ 2025-04-22 11:39 UTC (permalink / raw)
To: Hans Zhang
Cc: lpieralisi, kw, bhelgaas, heiko, manivannan.sadhasivam, robh,
jingoohan1, shawn.lin, linux-pci, linux-kernel, linux-arm-kernel,
linux-rockchip
On Tue, Apr 22, 2025 at 07:28:30PM +0800, Hans Zhang wrote:
> Link-up detection manually checked PCIE_LINKUP bits across RC/EP modes,
> leading to code duplication. Centralize the logic using FIELD_GET. This
> removes redundancy and abstracts hardware-specific bit masking, ensuring
> consistent link state handling.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> index cdc8afc6cfc1..2b26060af5c2 100644
> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> @@ -196,10 +196,7 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
> struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
> u32 val = rockchip_pcie_get_ltssm(rockchip);
>
> - if ((val & PCIE_LINKUP) == PCIE_LINKUP)
> - return 1;
> -
> - return 0;
> + return FIELD_GET(PCIE_LINKUP_MASK, val) == 3;
While I like the idea of your patch, here you are replacing something that
is easy to read (PCIE_LINKUP) with a magic value, which IMO is a step in
the wrong direction.
> }
>
> static void rockchip_pcie_enable_l0s(struct dw_pcie *pci)
> @@ -499,7 +496,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
> struct dw_pcie *pci = &rockchip->pci;
> struct dw_pcie_rp *pp = &pci->pp;
> struct device *dev = pci->dev;
> - u32 reg, val;
> + u32 reg;
>
> reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
> rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
> @@ -508,8 +505,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
> dev_dbg(dev, "LTSSM_STATUS: %#x\n", rockchip_pcie_get_ltssm(rockchip));
>
> if (reg & PCIE_RDLH_LINK_UP_CHGED) {
> - val = rockchip_pcie_get_ltssm(rockchip);
> - if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
> + if (rockchip_pcie_link_up(pci)) {
> dev_dbg(dev, "Received Link up event. Starting enumeration!\n");
> /* Rescan the bus to enumerate endpoint devices */
> pci_lock_rescan_remove();
> @@ -526,7 +522,7 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
> struct rockchip_pcie *rockchip = arg;
> struct dw_pcie *pci = &rockchip->pci;
> struct device *dev = pci->dev;
> - u32 reg, val;
> + u32 reg;
>
> reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
> rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
> @@ -540,8 +536,7 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
> }
>
> if (reg & PCIE_RDLH_LINK_UP_CHGED) {
> - val = rockchip_pcie_get_ltssm(rockchip);
> - if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
> + if (rockchip_pcie_link_up(pci)) {
> dev_dbg(dev, "link up\n");
> dw_pcie_ep_linkup(&pci->ep);
> }
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-22 11:28 ` [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
@ 2025-04-22 11:47 ` Niklas Cassel
2025-04-22 11:51 ` Hans Zhang
2025-04-22 12:30 ` Niklas Cassel
1 sibling, 1 reply; 15+ messages in thread
From: Niklas Cassel @ 2025-04-22 11:47 UTC (permalink / raw)
To: Hans Zhang
Cc: lpieralisi, kw, bhelgaas, heiko, manivannan.sadhasivam, robh,
jingoohan1, shawn.lin, linux-pci, linux-kernel, linux-arm-kernel,
linux-rockchip
On Tue, Apr 22, 2025 at 07:28:29PM +0800, Hans Zhang wrote:
> Register definitions were scattered with ambiguous names (e.g.,
> PCIE_RDLH_LINK_UP_CHGED in PCIE_CLIENT_INTR_STATUS_MISC) and lacked
> hierarchical grouping. Magic values for bit operations reduced code
> clarity.
>
> Group registers and their associated bitfields logically. This improves
> maintainability and aligns the code with hardware documentation.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 42 +++++++++++--------
> 1 file changed, 24 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> index fd5827bbfae3..cdc8afc6cfc1 100644
> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> @@ -8,6 +8,7 @@
> * Author: Simon Xue <xxm@rock-chips.com>
> */
>
> +#include <linux/bitfield.h>
> #include <linux/clk.h>
> #include <linux/gpio/consumer.h>
> #include <linux/irqchip/chained_irq.h>
> @@ -34,30 +35,35 @@
>
> #define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
>
> -#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
> -#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
> -#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
> -#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
> -#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x04
> +#define PCIE_CLIENT_GENERAL_CONTROL 0x0
> +#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
> +#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
> +#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
> +#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
> +
> +#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x4
> +#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
> +
> #define PCIE_CLIENT_INTR_STATUS_MISC 0x10
> +#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
> +#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
> +
> +#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
> #define PCIE_CLIENT_INTR_MASK_MISC 0x24
> +
> #define PCIE_CLIENT_POWER 0x2c
> +#define PME_READY_ENTER_L23 BIT(3)
> +
> #define PCIE_CLIENT_MSG_GEN 0x34
> -#define PME_READY_ENTER_L23 BIT(3)
> -#define PME_TURN_OFF (BIT(4) | BIT(20))
> -#define PME_TO_ACK (BIT(9) | BIT(25))
> -#define PCIE_SMLH_LINKUP BIT(16)
> -#define PCIE_RDLH_LINKUP BIT(17)
> -#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
> -#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
> -#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
> -#define PCIE_CLIENT_GENERAL_CONTROL 0x0
> -#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
> -#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
> +#define PME_TURN_OFF HIWORD_UPDATE_BIT(BIT(4))
> +#define PME_TO_ACK HIWORD_UPDATE_BIT(BIT(9))
> +
> #define PCIE_CLIENT_HOT_RESET_CTRL 0x180
> +#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
> +
> #define PCIE_CLIENT_LTSSM_STATUS 0x300
> -#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
> -#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
> +#define PCIE_LINKUP_MASK GENMASK(17, 16)
Here you are adding a macro (PCIE_LINKUP_MASK) that is not used.
I suggest that you move the addition to the patch where it is actually used.
Kind regards,
Niklas
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET
2025-04-22 11:39 ` Niklas Cassel
@ 2025-04-22 11:50 ` Hans Zhang
2025-04-22 12:24 ` Niklas Cassel
0 siblings, 1 reply; 15+ messages in thread
From: Hans Zhang @ 2025-04-22 11:50 UTC (permalink / raw)
To: Niklas Cassel
Cc: lpieralisi, kw, bhelgaas, heiko, manivannan.sadhasivam, robh,
jingoohan1, shawn.lin, linux-pci, linux-kernel, linux-arm-kernel,
linux-rockchip
On 2025/4/22 19:39, Niklas Cassel wrote:
> On Tue, Apr 22, 2025 at 07:28:30PM +0800, Hans Zhang wrote:
>> Link-up detection manually checked PCIE_LINKUP bits across RC/EP modes,
>> leading to code duplication. Centralize the logic using FIELD_GET. This
>> removes redundancy and abstracts hardware-specific bit masking, ensuring
>> consistent link state handling.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
>> ---
>> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 15 +++++----------
>> 1 file changed, 5 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> index cdc8afc6cfc1..2b26060af5c2 100644
>> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> @@ -196,10 +196,7 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
>> struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
>> u32 val = rockchip_pcie_get_ltssm(rockchip);
>>
>> - if ((val & PCIE_LINKUP) == PCIE_LINKUP)
>> - return 1;
>> -
>> - return 0;
>> + return FIELD_GET(PCIE_LINKUP_MASK, val) == 3;
>
> While I like the idea of your patch, here you are replacing something that
> is easy to read (PCIE_LINKUP) with a magic value, which IMO is a step in
> the wrong direction.
>
Hi Niklas,
Thank you very much for your reply. How about I add another macro
definition?
#define PCIE_LINKUP 3
If not, I'll restore it. At least the following can use the
rockchip_pcie_get_ltssm function to avoid duplicate code.
Best regards,
Hans
>
>> }
>>
>> static void rockchip_pcie_enable_l0s(struct dw_pcie *pci)
>> @@ -499,7 +496,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
>> struct dw_pcie *pci = &rockchip->pci;
>> struct dw_pcie_rp *pp = &pci->pp;
>> struct device *dev = pci->dev;
>> - u32 reg, val;
>> + u32 reg;
>>
>> reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
>> rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
>> @@ -508,8 +505,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
>> dev_dbg(dev, "LTSSM_STATUS: %#x\n", rockchip_pcie_get_ltssm(rockchip));
>>
>> if (reg & PCIE_RDLH_LINK_UP_CHGED) {
>> - val = rockchip_pcie_get_ltssm(rockchip);
>> - if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
>> + if (rockchip_pcie_link_up(pci)) {
>> dev_dbg(dev, "Received Link up event. Starting enumeration!\n");
>> /* Rescan the bus to enumerate endpoint devices */
>> pci_lock_rescan_remove();
>> @@ -526,7 +522,7 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
>> struct rockchip_pcie *rockchip = arg;
>> struct dw_pcie *pci = &rockchip->pci;
>> struct device *dev = pci->dev;
>> - u32 reg, val;
>> + u32 reg;
>>
>> reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
>> rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
>> @@ -540,8 +536,7 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
>> }
>>
>> if (reg & PCIE_RDLH_LINK_UP_CHGED) {
>> - val = rockchip_pcie_get_ltssm(rockchip);
>> - if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
>> + if (rockchip_pcie_link_up(pci)) {
>> dev_dbg(dev, "link up\n");
>> dw_pcie_ep_linkup(&pci->ep);
>> }
>> --
>> 2.25.1
>>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-22 11:47 ` Niklas Cassel
@ 2025-04-22 11:51 ` Hans Zhang
0 siblings, 0 replies; 15+ messages in thread
From: Hans Zhang @ 2025-04-22 11:51 UTC (permalink / raw)
To: Niklas Cassel
Cc: lpieralisi, kw, bhelgaas, heiko, manivannan.sadhasivam, robh,
jingoohan1, shawn.lin, linux-pci, linux-kernel, linux-arm-kernel,
linux-rockchip
On 2025/4/22 19:47, Niklas Cassel wrote:
> On Tue, Apr 22, 2025 at 07:28:29PM +0800, Hans Zhang wrote:
>> Register definitions were scattered with ambiguous names (e.g.,
>> PCIE_RDLH_LINK_UP_CHGED in PCIE_CLIENT_INTR_STATUS_MISC) and lacked
>> hierarchical grouping. Magic values for bit operations reduced code
>> clarity.
>>
>> Group registers and their associated bitfields logically. This improves
>> maintainability and aligns the code with hardware documentation.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
>> ---
>> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 42 +++++++++++--------
>> 1 file changed, 24 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> index fd5827bbfae3..cdc8afc6cfc1 100644
>> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> @@ -8,6 +8,7 @@
>> * Author: Simon Xue <xxm@rock-chips.com>
>> */
>>
>> +#include <linux/bitfield.h>
>> #include <linux/clk.h>
>> #include <linux/gpio/consumer.h>
>> #include <linux/irqchip/chained_irq.h>
>> @@ -34,30 +35,35 @@
>>
>> #define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
>>
>> -#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
>> -#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
>> -#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
>> -#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
>> -#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x04
>> +#define PCIE_CLIENT_GENERAL_CONTROL 0x0
>> +#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
>> +#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
>> +#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
>> +#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
>> +
>> +#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x4
>> +#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
>> +
>> #define PCIE_CLIENT_INTR_STATUS_MISC 0x10
>> +#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
>> +#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
>> +
>> +#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
>> #define PCIE_CLIENT_INTR_MASK_MISC 0x24
>> +
>> #define PCIE_CLIENT_POWER 0x2c
>> +#define PME_READY_ENTER_L23 BIT(3)
>> +
>> #define PCIE_CLIENT_MSG_GEN 0x34
>> -#define PME_READY_ENTER_L23 BIT(3)
>> -#define PME_TURN_OFF (BIT(4) | BIT(20))
>> -#define PME_TO_ACK (BIT(9) | BIT(25))
>> -#define PCIE_SMLH_LINKUP BIT(16)
>> -#define PCIE_RDLH_LINKUP BIT(17)
>> -#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
>> -#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
>> -#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
>> -#define PCIE_CLIENT_GENERAL_CONTROL 0x0
>> -#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
>> -#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
>> +#define PME_TURN_OFF HIWORD_UPDATE_BIT(BIT(4))
>> +#define PME_TO_ACK HIWORD_UPDATE_BIT(BIT(9))
>> +
>> #define PCIE_CLIENT_HOT_RESET_CTRL 0x180
>> +#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
>> +
>> #define PCIE_CLIENT_LTSSM_STATUS 0x300
>> -#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
>> -#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
>> +#define PCIE_LINKUP_MASK GENMASK(17, 16)
>
> Here you are adding a macro (PCIE_LINKUP_MASK) that is not used.
>
> I suggest that you move the addition to the patch where it is actually used.
>
Hi Niklas,
Thank you very much for your reply. Will change.
Best regards,
Hans
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET
2025-04-22 11:50 ` Hans Zhang
@ 2025-04-22 12:24 ` Niklas Cassel
2025-04-22 12:29 ` Hans Zhang
0 siblings, 1 reply; 15+ messages in thread
From: Niklas Cassel @ 2025-04-22 12:24 UTC (permalink / raw)
To: Hans Zhang
Cc: lpieralisi, kw, bhelgaas, heiko, manivannan.sadhasivam, robh,
jingoohan1, shawn.lin, linux-pci, linux-kernel, linux-arm-kernel,
linux-rockchip
On Tue, Apr 22, 2025 at 07:50:50PM +0800, Hans Zhang wrote:
>
>
> On 2025/4/22 19:39, Niklas Cassel wrote:
> > On Tue, Apr 22, 2025 at 07:28:30PM +0800, Hans Zhang wrote:
> > > Link-up detection manually checked PCIE_LINKUP bits across RC/EP modes,
> > > leading to code duplication. Centralize the logic using FIELD_GET. This
> > > removes redundancy and abstracts hardware-specific bit masking, ensuring
> > > consistent link state handling.
> > >
> > > Signed-off-by: Hans Zhang <18255117159@163.com>
> > > ---
> > > drivers/pci/controller/dwc/pcie-dw-rockchip.c | 15 +++++----------
> > > 1 file changed, 5 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> > > index cdc8afc6cfc1..2b26060af5c2 100644
> > > --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> > > +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> > > @@ -196,10 +196,7 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
> > > struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
> > > u32 val = rockchip_pcie_get_ltssm(rockchip);
> > > - if ((val & PCIE_LINKUP) == PCIE_LINKUP)
> > > - return 1;
> > > -
> > > - return 0;
> > > + return FIELD_GET(PCIE_LINKUP_MASK, val) == 3;
> >
> > While I like the idea of your patch, here you are replacing something that
> > is easy to read (PCIE_LINKUP) with a magic value, which IMO is a step in
> > the wrong direction.
> >
>
> Hi Niklas,
>
> Thank you very much for your reply. How about I add another macro
> definition?
>
> #define PCIE_LINKUP 3
Yes, adding another macro for it is what I meant.
Kind regards,
Niklas
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET
2025-04-22 12:24 ` Niklas Cassel
@ 2025-04-22 12:29 ` Hans Zhang
0 siblings, 0 replies; 15+ messages in thread
From: Hans Zhang @ 2025-04-22 12:29 UTC (permalink / raw)
To: Niklas Cassel
Cc: lpieralisi, kw, bhelgaas, heiko, manivannan.sadhasivam, robh,
jingoohan1, shawn.lin, linux-pci, linux-kernel, linux-arm-kernel,
linux-rockchip
On 2025/4/22 20:24, Niklas Cassel wrote:
> On Tue, Apr 22, 2025 at 07:50:50PM +0800, Hans Zhang wrote:
>>
>>
>> On 2025/4/22 19:39, Niklas Cassel wrote:
>>> On Tue, Apr 22, 2025 at 07:28:30PM +0800, Hans Zhang wrote:
>>>> Link-up detection manually checked PCIE_LINKUP bits across RC/EP modes,
>>>> leading to code duplication. Centralize the logic using FIELD_GET. This
>>>> removes redundancy and abstracts hardware-specific bit masking, ensuring
>>>> consistent link state handling.
>>>>
>>>> Signed-off-by: Hans Zhang <18255117159@163.com>
>>>> ---
>>>> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 15 +++++----------
>>>> 1 file changed, 5 insertions(+), 10 deletions(-)
>>>>
>>>> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>>>> index cdc8afc6cfc1..2b26060af5c2 100644
>>>> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>>>> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>>>> @@ -196,10 +196,7 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
>>>> struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
>>>> u32 val = rockchip_pcie_get_ltssm(rockchip);
>>>> - if ((val & PCIE_LINKUP) == PCIE_LINKUP)
>>>> - return 1;
>>>> -
>>>> - return 0;
>>>> + return FIELD_GET(PCIE_LINKUP_MASK, val) == 3;
>>>
>>> While I like the idea of your patch, here you are replacing something that
>>> is easy to read (PCIE_LINKUP) with a magic value, which IMO is a step in
>>> the wrong direction.
>>>
>>
>> Hi Niklas,
>>
>> Thank you very much for your reply. How about I add another macro
>> definition?
>>
>> #define PCIE_LINKUP 3
>
> Yes, adding another macro for it is what I meant.
>
Hi Niklas,
Thank you very much for your reply and reminder. The second and third
patches will be changed as follows:
patch 0002:
diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
index fd5827bbfae3..4d5c8ed18953 100644
--- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
+++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -34,30 +34,37 @@
#define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
-#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
-#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
-#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
-#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
-#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x04
+#define PCIE_CLIENT_GENERAL_CONTROL 0x0
+#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
+#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
+#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
+#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
+
+#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x4
+#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
+
#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
+#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
+#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
+
+#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
#define PCIE_CLIENT_INTR_MASK_MISC 0x24
+
#define PCIE_CLIENT_POWER 0x2c
+#define PME_READY_ENTER_L23 BIT(3)
+
#define PCIE_CLIENT_MSG_GEN 0x34
-#define PME_READY_ENTER_L23 BIT(3)
-#define PME_TURN_OFF (BIT(4) | BIT(20))
-#define PME_TO_ACK (BIT(9) | BIT(25))
-#define PCIE_SMLH_LINKUP BIT(16)
-#define PCIE_RDLH_LINKUP BIT(17)
-#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
-#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
-#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
-#define PCIE_CLIENT_GENERAL_CONTROL 0x0
-#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
-#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
+#define PME_TURN_OFF HIWORD_UPDATE_BIT(BIT(4))
+#define PME_TO_ACK HIWORD_UPDATE_BIT(BIT(9))
+
#define PCIE_CLIENT_HOT_RESET_CTRL 0x180
+#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
+
#define PCIE_CLIENT_LTSSM_STATUS 0x300
-#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
-#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
+#define PCIE_SMLH_LINKUP BIT(16)
+#define PCIE_RDLH_LINKUP BIT(17)
+#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
+#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
struct rockchip_pcie {
struct dw_pcie pci;
patch 0003:
diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
index 4d5c8ed18953..0553e7e80e1b 100644
--- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
+++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -8,6 +8,7 @@
* Author: Simon Xue <xxm@rock-chips.com>
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/gpio/consumer.h>
#include <linux/irqchip/chained_irq.h>
@@ -61,9 +62,8 @@
#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
#define PCIE_CLIENT_LTSSM_STATUS 0x300
-#define PCIE_SMLH_LINKUP BIT(16)
-#define PCIE_RDLH_LINKUP BIT(17)
-#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
+#define PCIE_LINKUP 0x3
+#define PCIE_LINKUP_MASK GENMASK(17, 16)
#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
struct rockchip_pcie {
@@ -197,10 +197,7 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
u32 val = rockchip_pcie_get_ltssm(rockchip);
- if ((val & PCIE_LINKUP) == PCIE_LINKUP)
- return 1;
-
- return 0;
+ return FIELD_GET(PCIE_LINKUP_MASK, val) == PCIE_LINKUP;
}
static void rockchip_pcie_enable_l0s(struct dw_pcie *pci)
@@ -500,7 +497,7 @@ static irqreturn_t
rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
struct dw_pcie *pci = &rockchip->pci;
struct dw_pcie_rp *pp = &pci->pp;
struct device *dev = pci->dev;
- u32 reg, val;
+ u32 reg;
reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
@@ -509,8 +506,7 @@ static irqreturn_t
rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
dev_dbg(dev, "LTSSM_STATUS: %#x\n", rockchip_pcie_get_ltssm(rockchip));
if (reg & PCIE_RDLH_LINK_UP_CHGED) {
- val = rockchip_pcie_get_ltssm(rockchip);
- if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
+ if (rockchip_pcie_link_up(pci)) {
dev_dbg(dev, "Received Link up event. Starting enumeration!\n");
/* Rescan the bus to enumerate endpoint devices */
pci_lock_rescan_remove();
@@ -527,7 +523,7 @@ static irqreturn_t
rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
struct rockchip_pcie *rockchip = arg;
struct dw_pcie *pci = &rockchip->pci;
struct device *dev = pci->dev;
- u32 reg, val;
+ u32 reg;
reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
@@ -541,8 +537,7 @@ static irqreturn_t
rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
}
if (reg & PCIE_RDLH_LINK_UP_CHGED) {
- val = rockchip_pcie_get_ltssm(rockchip);
- if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
+ if (rockchip_pcie_link_up(pci)) {
dev_dbg(dev, "link up\n");
dw_pcie_ep_linkup(&pci->ep);
}
Best regards,
Hans
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-22 11:28 ` [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
2025-04-22 11:47 ` Niklas Cassel
@ 2025-04-22 12:30 ` Niklas Cassel
2025-04-22 12:39 ` Hans Zhang
2025-04-22 16:03 ` Hans Zhang
1 sibling, 2 replies; 15+ messages in thread
From: Niklas Cassel @ 2025-04-22 12:30 UTC (permalink / raw)
To: Hans Zhang
Cc: lpieralisi, kw, bhelgaas, heiko, manivannan.sadhasivam, robh,
jingoohan1, shawn.lin, linux-pci, linux-kernel, linux-arm-kernel,
linux-rockchip
On Tue, Apr 22, 2025 at 07:28:29PM +0800, Hans Zhang wrote:
> Register definitions were scattered with ambiguous names (e.g.,
> PCIE_RDLH_LINK_UP_CHGED in PCIE_CLIENT_INTR_STATUS_MISC) and lacked
> hierarchical grouping. Magic values for bit operations reduced code
> clarity.
>
> Group registers and their associated bitfields logically. This improves
> maintainability and aligns the code with hardware documentation.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 42 +++++++++++--------
> 1 file changed, 24 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> index fd5827bbfae3..cdc8afc6cfc1 100644
> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
> @@ -8,6 +8,7 @@
> * Author: Simon Xue <xxm@rock-chips.com>
> */
>
> +#include <linux/bitfield.h>
> #include <linux/clk.h>
> #include <linux/gpio/consumer.h>
> #include <linux/irqchip/chained_irq.h>
> @@ -34,30 +35,35 @@
>
> #define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
>
> -#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
> -#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
> -#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
> -#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
> -#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x04
> +#define PCIE_CLIENT_GENERAL_CONTROL 0x0
> +#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
> +#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
> +#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
> +#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
> +
> +#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x4
> +#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
> +
> #define PCIE_CLIENT_INTR_STATUS_MISC 0x10
> +#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
> +#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
> +
> +#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
> #define PCIE_CLIENT_INTR_MASK_MISC 0x24
> +
> #define PCIE_CLIENT_POWER 0x2c
> +#define PME_READY_ENTER_L23 BIT(3)
> +
> #define PCIE_CLIENT_MSG_GEN 0x34
> -#define PME_READY_ENTER_L23 BIT(3)
> -#define PME_TURN_OFF (BIT(4) | BIT(20))
> -#define PME_TO_ACK (BIT(9) | BIT(25))
> -#define PCIE_SMLH_LINKUP BIT(16)
> -#define PCIE_RDLH_LINKUP BIT(17)
> -#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
This patch removes PCIE_LINKUP, without adding it somewhere else
so I don't think this patch will compile.
I think the removal of this line has to be in patch 3/3.
Also, I think that Bjorn's primary concern:
"""
The #defines for register offsets and bits are kind of a mess,
e.g., PCIE_SMLH_LINKUP, PCIE_RDLH_LINKUP, PCIE_LINKUP,
PCIE_L0S_ENTRY, and PCIE_LTSSM_STATUS_MASK are in
PCIE_CLIENT_LTSSM_STATUS, but you couldn't tell that from the
names, and they're not even defined together.
""""
is that the fields are not prefixed with the register name.
the secondary concern is that they are not grouped together.
This patch is just solving the secondary concern.
Since you are fixing his secondary concern, should you perhaps also
address his primary concern?
Kind regards,
Niklas
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-22 12:30 ` Niklas Cassel
@ 2025-04-22 12:39 ` Hans Zhang
2025-04-22 16:03 ` Hans Zhang
1 sibling, 0 replies; 15+ messages in thread
From: Hans Zhang @ 2025-04-22 12:39 UTC (permalink / raw)
To: Niklas Cassel
Cc: lpieralisi, kw, bhelgaas, heiko, manivannan.sadhasivam, robh,
jingoohan1, shawn.lin, linux-pci, linux-kernel, linux-arm-kernel,
linux-rockchip
On 2025/4/22 20:30, Niklas Cassel wrote:
> On Tue, Apr 22, 2025 at 07:28:29PM +0800, Hans Zhang wrote:
>> Register definitions were scattered with ambiguous names (e.g.,
>> PCIE_RDLH_LINK_UP_CHGED in PCIE_CLIENT_INTR_STATUS_MISC) and lacked
>> hierarchical grouping. Magic values for bit operations reduced code
>> clarity.
>>
>> Group registers and their associated bitfields logically. This improves
>> maintainability and aligns the code with hardware documentation.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
>> ---
>> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 42 +++++++++++--------
>> 1 file changed, 24 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> index fd5827bbfae3..cdc8afc6cfc1 100644
>> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> @@ -8,6 +8,7 @@
>> * Author: Simon Xue <xxm@rock-chips.com>
>> */
>>
>> +#include <linux/bitfield.h>
>> #include <linux/clk.h>
>> #include <linux/gpio/consumer.h>
>> #include <linux/irqchip/chained_irq.h>
>> @@ -34,30 +35,35 @@
>>
>> #define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
>>
>> -#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
>> -#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
>> -#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
>> -#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
>> -#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x04
>> +#define PCIE_CLIENT_GENERAL_CONTROL 0x0
>> +#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
>> +#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
>> +#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
>> +#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
>> +
>> +#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x4
>> +#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
>> +
>> #define PCIE_CLIENT_INTR_STATUS_MISC 0x10
>> +#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
>> +#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
>> +
>> +#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
>> #define PCIE_CLIENT_INTR_MASK_MISC 0x24
>> +
>> #define PCIE_CLIENT_POWER 0x2c
>> +#define PME_READY_ENTER_L23 BIT(3)
>> +
>> #define PCIE_CLIENT_MSG_GEN 0x34
>> -#define PME_READY_ENTER_L23 BIT(3)
>> -#define PME_TURN_OFF (BIT(4) | BIT(20))
>> -#define PME_TO_ACK (BIT(9) | BIT(25))
>> -#define PCIE_SMLH_LINKUP BIT(16)
>> -#define PCIE_RDLH_LINKUP BIT(17)
>> -#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
>
> This patch removes PCIE_LINKUP, without adding it somewhere else
> so I don't think this patch will compile.
>
> I think the removal of this line has to be in patch 3/3.
>
Hi Niklas,
Thank you very much for your reply. Yes, I replied to you in patch 0003.
>
>
> Also, I think that Bjorn's primary concern:
> """
> The #defines for register offsets and bits are kind of a mess,
> e.g., PCIE_SMLH_LINKUP, PCIE_RDLH_LINKUP, PCIE_LINKUP,
> PCIE_L0S_ENTRY, and PCIE_LTSSM_STATUS_MASK are in
> PCIE_CLIENT_LTSSM_STATUS, but you couldn't tell that from the
> names, and they're not even defined together.
> """"
>
> is that the fields are not prefixed with the register name.
>
> the secondary concern is that they are not grouped together.
>
> This patch is just solving the secondary concern.
>
> Since you are fixing his secondary concern, should you perhaps also
> address his primary concern?
Ok. I missed this problem and I will fix it in the next version.
Best regards,
Hans
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions
2025-04-22 12:30 ` Niklas Cassel
2025-04-22 12:39 ` Hans Zhang
@ 2025-04-22 16:03 ` Hans Zhang
1 sibling, 0 replies; 15+ messages in thread
From: Hans Zhang @ 2025-04-22 16:03 UTC (permalink / raw)
To: Niklas Cassel
Cc: lpieralisi, kw, bhelgaas, heiko, manivannan.sadhasivam, robh,
jingoohan1, shawn.lin, linux-pci, linux-kernel, linux-arm-kernel,
linux-rockchip
On 2025/4/22 20:30, Niklas Cassel wrote:
> On Tue, Apr 22, 2025 at 07:28:29PM +0800, Hans Zhang wrote:
>> Register definitions were scattered with ambiguous names (e.g.,
>> PCIE_RDLH_LINK_UP_CHGED in PCIE_CLIENT_INTR_STATUS_MISC) and lacked
>> hierarchical grouping. Magic values for bit operations reduced code
>> clarity.
>>
>> Group registers and their associated bitfields logically. This improves
>> maintainability and aligns the code with hardware documentation.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
>> ---
>> drivers/pci/controller/dwc/pcie-dw-rockchip.c | 42 +++++++++++--------
>> 1 file changed, 24 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-dw-rockchip.c b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> index fd5827bbfae3..cdc8afc6cfc1 100644
>> --- a/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> +++ b/drivers/pci/controller/dwc/pcie-dw-rockchip.c
>> @@ -8,6 +8,7 @@
>> * Author: Simon Xue <xxm@rock-chips.com>
>> */
>>
>> +#include <linux/bitfield.h>
>> #include <linux/clk.h>
>> #include <linux/gpio/consumer.h>
>> #include <linux/irqchip/chained_irq.h>
>> @@ -34,30 +35,35 @@
>>
>> #define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
>>
>> -#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
>> -#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
>> -#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
>> -#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
>> -#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x04
>> +#define PCIE_CLIENT_GENERAL_CONTROL 0x0
>> +#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
>> +#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
>> +#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
>> +#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
>> +
>> +#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x4
>> +#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
>> +
>> #define PCIE_CLIENT_INTR_STATUS_MISC 0x10
>> +#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
>> +#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
>> +
>> +#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
>> #define PCIE_CLIENT_INTR_MASK_MISC 0x24
>> +
>> #define PCIE_CLIENT_POWER 0x2c
>> +#define PME_READY_ENTER_L23 BIT(3)
>> +
>> #define PCIE_CLIENT_MSG_GEN 0x34
>> -#define PME_READY_ENTER_L23 BIT(3)
>> -#define PME_TURN_OFF (BIT(4) | BIT(20))
>> -#define PME_TO_ACK (BIT(9) | BIT(25))
>> -#define PCIE_SMLH_LINKUP BIT(16)
>> -#define PCIE_RDLH_LINKUP BIT(17)
>> -#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
>
> This patch removes PCIE_LINKUP, without adding it somewhere else
> so I don't think this patch will compile.
>
> I think the removal of this line has to be in patch 3/3.
>
>
>
> Also, I think that Bjorn's primary concern:
> """
> The #defines for register offsets and bits are kind of a mess,
> e.g., PCIE_SMLH_LINKUP, PCIE_RDLH_LINKUP, PCIE_LINKUP,
> PCIE_L0S_ENTRY, and PCIE_LTSSM_STATUS_MASK are in
> PCIE_CLIENT_LTSSM_STATUS, but you couldn't tell that from the
> names, and they're not even defined together.
> """"
>
> is that the fields are not prefixed with the register name.
Hi Niklas,
As per rk3588 TRM, section "11.4.2.1 PCIE_CLIENT Registers Summary
Detail Registers Description"
The register names are as follows. I plan to add comments for each
register in the next version, and the comments come from the register
description of TRM.
/* General Control Register */
#define PCIE_CLIENT_GENERAL_CON 0x0
#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
#define PCIE_CLIENT_ENABLE_LTSSM HIWORD_UPDATE_BIT(0xc)
#define PCIE_CLIENT_DISABLE_LTSSM HIWORD_UPDATE(0x0c, 0x8)
/* Interrupt Status Register Related to Message Reception */
#define PCIE_CLIENT_INTR_STATUS_MSG_RX 0x4
/* Interrupt Status Register Related to Legacy Interrupt */
#define PCIE_CLIENT_INTR_STATUS_LEGACY 0x8
/* Interrupt Status Register Related to Miscellaneous Operation */
#define PCIE_CLIENT_INTR_STATUS_MISC 0x10
#define PCIE_RDLH_LINK_UP_CHGED BIT(1)
#define PCIE_LINK_REQ_RST_NOT_INT BIT(2)
/* Interrupt Mask Register Related to Legacy Interrupt */
#define PCIE_CLIENT_INTR_MASK_LEGACY 0x1c
/* Interrupt Mask Register Related to Miscellaneous Operation */
#define PCIE_CLIENT_INTR_MASK_MISC 0x24
/* Power Management Control Register */
#define PCIE_CLIENT_POWER_CON 0x2c
#define PME_READY_ENTER_L23 BIT(3)
/* Message Generation Control Register */
#define PCIE_CLIENT_MSG_GEN_CON 0x34
#define PME_TURN_OFF HIWORD_UPDATE_BIT(BIT(4))
#define PME_TO_ACK HIWORD_UPDATE_BIT(BIT(9))
/* Hot Reset Control Register */
#define PCIE_CLIENT_HOT_RESET_CTRL 0x180
#define PCIE_LTSSM_ENABLE_ENHANCE BIT(4)
/* LTSSM Status Register */
#define PCIE_CLIENT_LTSSM_STATUS 0x300
#define PCIE_SMLH_LINKUP BIT(16)
#define PCIE_RDLH_LINKUP BIT(17)
#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
Best regards,
Hans
>
> the secondary concern is that they are not grouped together.
>
> This patch is just solving the secondary concern.
>
> Since you are fixing his secondary concern, should you perhaps also
> address his primary concern?
>
>
>
> Kind regards,
> Niklas
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2025-04-22 16:04 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-22 11:28 [PATCH 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
2025-04-22 11:28 ` [PATCH 1/3] PCI: dw-rockchip: Remove unused PCIE_CLIENT_GENERAL_DEBUG Hans Zhang
2025-04-22 11:35 ` Niklas Cassel
2025-04-22 11:28 ` [PATCH 2/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
2025-04-22 11:47 ` Niklas Cassel
2025-04-22 11:51 ` Hans Zhang
2025-04-22 12:30 ` Niklas Cassel
2025-04-22 12:39 ` Hans Zhang
2025-04-22 16:03 ` Hans Zhang
2025-04-22 11:28 ` [PATCH 3/3] PCI: dw-rockchip: Unify link status checks with FIELD_GET Hans Zhang
2025-04-22 11:39 ` Niklas Cassel
2025-04-22 11:50 ` Hans Zhang
2025-04-22 12:24 ` Niklas Cassel
2025-04-22 12:29 ` Hans Zhang
2025-04-22 11:35 ` [PATCH 0/3] PCI: dw-rockchip: Reorganize register and bitfield definitions Hans Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).