[PATCH] PCI: dwc: ep: Use FIELD_GET()

Hans Zhang posted 1 patch 9 months, 3 weeks ago
There is a newer version of this series
drivers/pci/controller/dwc/pcie-designware-ep.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
[PATCH] PCI: dwc: ep: Use FIELD_GET()
Posted by Hans Zhang 9 months, 3 weeks ago
Use FIELD_GET() and FIELD_PREP() to remove dependences on the field
position, i.e., the shift value. No functional change intended.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
I referred to Bjorn Helgaas' submitted patch.
https://lore.kernel.org/all/20231010204436.1000644-2-helgaas@kernel.org/
---
 drivers/pci/controller/dwc/pcie-designware-ep.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c
index 1a0bf9341542..f3daf46b5e63 100644
--- a/drivers/pci/controller/dwc/pcie-designware-ep.c
+++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
@@ -256,11 +256,11 @@ static unsigned int dw_pcie_ep_get_rebar_offset(struct dw_pcie *pci,
 		return offset;
 
 	reg = dw_pcie_readl_dbi(pci, offset + PCI_REBAR_CTRL);
-	nbars = (reg & PCI_REBAR_CTRL_NBAR_MASK) >> PCI_REBAR_CTRL_NBAR_SHIFT;
+	nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, reg);
 
 	for (i = 0; i < nbars; i++, offset += PCI_REBAR_CTRL) {
 		reg = dw_pcie_readl_dbi(pci, offset + PCI_REBAR_CTRL);
-		bar_index = reg & PCI_REBAR_CTRL_BAR_IDX;
+		bar_index = FIELD_GET(PCI_REBAR_CTRL_BAR_IDX, reg);
 		if (bar_index == bar)
 			return offset;
 	}
@@ -875,8 +875,7 @@ static void dw_pcie_ep_init_non_sticky_registers(struct dw_pcie *pci)
 
 	if (offset) {
 		reg = dw_pcie_readl_dbi(pci, offset + PCI_REBAR_CTRL);
-		nbars = (reg & PCI_REBAR_CTRL_NBAR_MASK) >>
-			PCI_REBAR_CTRL_NBAR_SHIFT;
+		nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, reg);
 
 		/*
 		 * PCIe r6.0, sec 7.8.6.2 require us to support at least one
@@ -897,7 +896,7 @@ static void dw_pcie_ep_init_non_sticky_registers(struct dw_pcie *pci)
 			 * is why RESBAR_CAP_REG is written here.
 			 */
 			val = dw_pcie_readl_dbi(pci, offset + PCI_REBAR_CTRL);
-			bar = val & PCI_REBAR_CTRL_BAR_IDX;
+			bar = FIELD_GET(PCI_REBAR_CTRL_BAR_IDX, val);
 			if (ep->epf_bar[bar])
 				pci_epc_bar_size_to_rebar_cap(ep->epf_bar[bar]->size, &val);
 			else

base-commit: 9d7a0577c9db35c4cc52db90bc415ea248446472
-- 
2.25.1
Re: [PATCH] PCI: dwc: ep: Use FIELD_GET()
Posted by Niklas Cassel 9 months, 2 weeks ago
On Mon, Apr 21, 2025 at 07:45:48PM +0800, Hans Zhang wrote:
> Use FIELD_GET() and FIELD_PREP() to remove dependences on the field
> position, i.e., the shift value. No functional change intended.

Nit: It is a little bit misleading to write "Use ... FIELD_PREP()"
since this patch actually never uses FIELD_PREP().

Reviewed-by: Niklas Cassel <cassel@kernel.org>
Re: [PATCH] PCI: dwc: ep: Use FIELD_GET()
Posted by Hans Zhang 9 months, 2 weeks ago

On 2025/4/24 21:44, Niklas Cassel wrote:
> On Mon, Apr 21, 2025 at 07:45:48PM +0800, Hans Zhang wrote:
>> Use FIELD_GET() and FIELD_PREP() to remove dependences on the field
>> position, i.e., the shift value. No functional change intended.
> 
> Nit: It is a little bit misleading to write "Use ... FIELD_PREP()"
> since this patch actually never uses FIELD_PREP().
> 
> Reviewed-by: Niklas Cassel <cassel@kernel.org>

Hi Niklas,

Thank you very much for your review. I think Mani can help me modify it 
when merging to the temporary branch.

Best regards,
Hans