From nobody Wed Dec 17 12:18:34 2025 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BA522EFD8F; Wed, 18 Jun 2025 15:21:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750260104; cv=none; b=lw7O+CSn/ypLhhpyC+1z36tW9uM+oZiFEYO/i4suYRhWDjzKxr6QpPcCxmW/Lv43aQkXIt12VEs9hAmPDowetTjQel4qWil0CkSlI7oYikbddrgDjZuppQtwVhl3QCSGKx+1UMc2NgeygfMVBM46FqIPJDgpsr3oMcglUwcjZSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750260104; c=relaxed/simple; bh=05XlbY/UQu42xpAJ30ZAd5vgZ/sIRKkwHCnOZ7Imj1U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qCoskcMNNeNfiBWaGG3qjYJb6Yt82q8beBJ3u3xPFFgJtRHNEZl7TJ+j537rkCxh5MJka28I5WMccJ2tsdXTsVoHdP2JL01XXfa0AWAjbgfPcU6EuU//DgFzupNHHGQIFrQc9zWzqY1cpGPVGy7u7yfCjkpqJeA1VHE+vPFIcfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=CxjYLbSm; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="CxjYLbSm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=hb y962xhyP4Qgrj7aPF+nhZQMZCQ5u6zcns9wRaSiWI=; b=CxjYLbSmpjtu1dc5vM aMieCCjyVYXgvJ9VMWNlsQbptNmSQ2jGEBQ/R9HPNn+QBt7tesYFff5vlLQJs3vd S+6pxaCP5LXJt2cQby1geDwDQXSb+WXz2TMpRNjB9or5XbzXzcFzeb6ID1Gv/UrE gPs7urQaz6Bmcqzax45ww3a/c= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wBXvXd32VJoWFISAQ--.22704S2; Wed, 18 Jun 2025 23:21:28 +0800 (CST) From: Hans Zhang <18255117159@163.com> To: lpieralisi@kernel.org, bhelgaas@google.com, mani@kernel.org, kwilczynski@kernel.org Cc: robh@kernel.org, jingoohan1@gmail.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Zhang <18255117159@163.com> Subject: [PATCH v2 05/13] PCI: meson: Refactor code by using dw_pcie_clear_and_set_dword() Date: Wed, 18 Jun 2025 23:21:04 +0800 Message-Id: <20250618152112.1010147-6-18255117159@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250618152112.1010147-1-18255117159@163.com> References: <20250618152112.1010147-1-18255117159@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wBXvXd32VJoWFISAQ--.22704S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxXFyDXFW7tr48XFyxJw1xAFb_yoW5CFWkpr ZxuF4FyF47Jr45uw4qva95uay3Jas3Cw17JFnxG34S9Fy2yr9rta4aya45uayxGrW0g34j 9r98trW8Z3W5tF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piq2NLUUUUU= X-CM-SenderInfo: rpryjkyvrrlimvzbiqqrwthudrp/1tbiOgNwo2hS1URl9wAAsT Content-Type: text/plain; charset="utf-8" Meson PCIe driver implements payload size configuration through manual register manipulation. The current code reads device control registers, modifies specific bitfields for maximum payload and read request sizes, then writes back the updated values. This pattern repeats twice with similar logic but different bit masks. Replace explicit bit manipulation with dw_pcie_clear_and_set_dword() for payload and read request size configuration. The helper consolidates read-clear-set-write operations into a single call, eliminating redundant register read operations and local variable usage. This refactoring reduces code duplication in size configuration logic and improves maintainability. By using the DesignWare helper, the driver aligns with standard PCIe controller programming patterns and simplifies future updates to device capability settings. Signed-off-by: Hans Zhang <18255117159@163.com> --- drivers/pci/controller/dwc/pci-meson.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controlle= r/dwc/pci-meson.c index 787469d1b396..cd6280a8e619 100644 --- a/drivers/pci/controller/dwc/pci-meson.c +++ b/drivers/pci/controller/dwc/pci-meson.c @@ -264,33 +264,27 @@ static int meson_size_to_payload(struct meson_pcie *m= p, int size) static void meson_set_max_payload(struct meson_pcie *mp, int size) { struct dw_pcie *pci =3D &mp->pci; - u32 val; u16 offset =3D dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); int max_payload_size =3D meson_size_to_payload(mp, size); =20 - val =3D dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL); - val &=3D ~PCI_EXP_DEVCTL_PAYLOAD; - dw_pcie_writel_dbi(pci, offset + PCI_EXP_DEVCTL, val); + dw_pcie_clear_and_set_dword(pci, offset + PCI_EXP_DEVCTL, + PCI_EXP_DEVCTL_PAYLOAD, 0); =20 - val =3D dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL); - val |=3D PCIE_CAP_MAX_PAYLOAD_SIZE(max_payload_size); - dw_pcie_writel_dbi(pci, offset + PCI_EXP_DEVCTL, val); + dw_pcie_clear_and_set_dword(pci, offset + PCI_EXP_DEVCTL, 0, + PCIE_CAP_MAX_PAYLOAD_SIZE(max_payload_size)); } =20 static void meson_set_max_rd_req_size(struct meson_pcie *mp, int size) { struct dw_pcie *pci =3D &mp->pci; - u32 val; u16 offset =3D dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); int max_rd_req_size =3D meson_size_to_payload(mp, size); =20 - val =3D dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL); - val &=3D ~PCI_EXP_DEVCTL_READRQ; - dw_pcie_writel_dbi(pci, offset + PCI_EXP_DEVCTL, val); + dw_pcie_clear_and_set_dword(pci, offset + PCI_EXP_DEVCTL, + PCI_EXP_DEVCTL_READRQ, 0); =20 - val =3D dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL); - val |=3D PCIE_CAP_MAX_READ_REQ_SIZE(max_rd_req_size); - dw_pcie_writel_dbi(pci, offset + PCI_EXP_DEVCTL, val); + dw_pcie_clear_and_set_dword(pci, offset + PCI_EXP_DEVCTL, 0, + PCIE_CAP_MAX_READ_REQ_SIZE(max_rd_req_size)); } =20 static int meson_pcie_start_link(struct dw_pcie *pci) --=20 2.25.1