mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans Zhang <18255117159@163.com>
To: Manivannan Sadhasivam <mani@kernel.org>
Cc: lpieralisi@kernel.org, bhelgaas@google.com,
	kwilczynski@kernel.org, robh@kernel.org, jingoohan1@gmail.com,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 13/13] PCI: tegra194: Refactor code by using dw_pcie_clear_and_set_dword()
Date: Thu, 26 Jun 2025 22:31:17 +0800	[thread overview]
Message-ID: <55158500-73b4-4715-87f5-94b872357391@163.com> (raw)
In-Reply-To: <ci3ojmiiuajwedx3desa7vf5lkk35meaj4kdqnunf3f66knvm5@gtgxoagzl7ek>



On 2025/6/26 04:57, Manivannan Sadhasivam wrote:
> On Wed, Jun 18, 2025 at 11:21:12PM +0800, Hans Zhang wrote:
>> Tegra194 PCIe driver contains extensive manual bit manipulation across
>> interrupt handling, ASPM configuration, and controller initialization.
>> The driver implements complex read-modify-write sequences with explicit
>> bit masking, leading to verbose and hard-to-maintain code.
>>
>> Refactor interrupt handling, ASPM setup, capability configuration, and
>> controller initialization using dw_pcie_clear_and_set_dword(). Replace
>> multi-step register modifications with single helper calls, eliminating
>> intermediate variables and reducing code size by ~100 lines. For CDMA
>> error handling, initialize the value variable to zero before setting
>> status bits.
>>
>> This comprehensive refactoring significantly improves code readability
>> and maintainability. Standardizing on the helper ensures consistent
>> register access patterns across all driver components and reduces the
>> risk of bit manipulation errors in this complex controller driver.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
>> ---
>>   drivers/pci/controller/dwc/pcie-tegra194.c | 155 +++++++++------------
>>   1 file changed, 64 insertions(+), 91 deletions(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
>> index 4f26086f25da..c6f5c35a4be4 100644
>> --- a/drivers/pci/controller/dwc/pcie-tegra194.c
>> +++ b/drivers/pci/controller/dwc/pcie-tegra194.c
>> @@ -378,9 +378,8 @@ static irqreturn_t tegra_pcie_rp_irq_handler(int irq, void *arg)
>>   			val |= APPL_CAR_RESET_OVRD_CYA_OVERRIDE_CORE_RST_N;
>>   			appl_writel(pcie, val, APPL_CAR_RESET_OVRD);
>>   
>> -			val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
>> -			val |= PORT_LOGIC_SPEED_CHANGE;
>> -			dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
>> +			dw_pcie_clear_and_set_dword(pci, PCIE_LINK_WIDTH_SPEED_CONTROL,
>> +						    0, PORT_LOGIC_SPEED_CHANGE);
>>   		}
>>   	}
>>   
>> @@ -412,7 +411,7 @@ static irqreturn_t tegra_pcie_rp_irq_handler(int irq, void *arg)
>>   
>>   	if (status_l0 & APPL_INTR_STATUS_L0_CDM_REG_CHK_INT) {
>>   		status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_18);
>> -		val = dw_pcie_readl_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS);
>> +		val = 0;
>>   		if (status_l1 & APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMPLT) {
>>   			dev_info(pci->dev, "CDM check complete\n");
>>   			val |= PCIE_PL_CHK_REG_CHK_REG_COMPLETE;
>> @@ -425,7 +424,8 @@ static irqreturn_t tegra_pcie_rp_irq_handler(int irq, void *arg)
>>   			dev_err(pci->dev, "CDM Logic error\n");
>>   			val |= PCIE_PL_CHK_REG_CHK_REG_LOGIC_ERROR;
>>   		}
>> -		dw_pcie_writel_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS, val);
>> +		dw_pcie_clear_and_set_dword(pci, PCIE_PL_CHK_REG_CONTROL_STATUS,
>> +					    PORT_LOGIC_SPEED_CHANGE, val);
> 
> I don't know why you are clearing PORT_LOGIC_SPEED_CHANGE here which is not part
> of PCIE_PL_CHK_REG_CONTROL_STATUS. Typo?
> 
Dear Mani,

Thank you very much for your reply and reminder.

This is copied from the first change of this patch and will be fixed in 
the next version.

Best regards,
Hans


> - Mani
> 


  reply	other threads:[~2025-06-26 14:31 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18 15:20 [PATCH v2 00/13] PCI: dwc: Refactor register access with dw_pcie_clear_and_set_dword helper Hans Zhang
2025-06-18 15:21 ` [PATCH v2 01/13] PCI: dwc: Add dw_pcie_clear_and_set_dword() for register bit manipulation Hans Zhang
2025-06-19  4:29   ` Frank Li
2025-06-19  5:42     ` Hans Zhang
2025-06-19 15:12       ` Frank Li
2025-06-18 15:21 ` [PATCH v2 02/13] PCI: dwc: Refactor code by using dw_pcie_clear_and_set_dword() Hans Zhang
2025-06-18 15:21 ` [PATCH v2 03/13] PCI: dra7xx: " Hans Zhang
2025-06-18 15:21 ` [PATCH v2 04/13] PCI: imx6: " Hans Zhang
2025-06-19 15:16   ` Frank Li
2025-06-18 15:21 ` [PATCH v2 05/13] PCI: meson: " Hans Zhang
2025-06-18 15:21 ` [PATCH v2 06/13] PCI: armada8k: " Hans Zhang
2025-06-18 15:21 ` [PATCH v2 07/13] PCI: bt1: " Hans Zhang
2025-06-18 15:21 ` [PATCH v2 08/13] PCI: dw-rockchip: " Hans Zhang
2025-06-18 15:21 ` [PATCH v2 09/13] PCI: fu740: " Hans Zhang
2025-06-18 15:21 ` [PATCH v2 10/13] PCI: qcom: " Hans Zhang
2025-06-18 15:21 ` [PATCH v2 11/13] PCI: qcom-ep: " Hans Zhang
2025-06-18 15:21 ` [PATCH v2 12/13] PCI: rcar-gen4: " Hans Zhang
2025-06-18 15:21 ` [PATCH v2 13/13] PCI: tegra194: " Hans Zhang
2025-06-25 20:57   ` Manivannan Sadhasivam
2025-06-26 14:31     ` Hans Zhang [this message]
2025-06-25 21:00 ` [PATCH v2 00/13] PCI: dwc: Refactor register access with dw_pcie_clear_and_set_dword helper Manivannan Sadhasivam
2025-06-26 14:51   ` Hans Zhang

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=55158500-73b4-4715-87f5-94b872357391@163.com \
    --to=18255117159@163.com \
    --cc=bhelgaas@google.com \
    --cc=jingoohan1@gmail.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=robh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®