Hello Nicolas,
On Thu, Jun 12, 2025 at 08:56:19PM +0200, Nicolas Frattaroli wrote:
PCIE_CLIENT_RC_MODE/PCIE_CLIENT_EP_MODE was another field that wasn't
super clear on what the bit field modification actually is. As far as I
can tell, switching to RC mode doesn't actually write the correct value
to the field if any of its bits have been set previously, as it only
updates one bit of a 4 bit field.
Replace it by actually writing the full values to the field, using the
new HWORD_UPDATE macro, which grants us the benefit of better
compile-time error checking.
The current code looks like this:
#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
#define PCIE_CLIENT_EP_MODE HIWORD_UPDATE(0xf0, 0x0)
The device_type field is defined like this:
4'h0: PCI Express endpoint
4'h1: Legacy PCI Express endpoint
4'h4: Root port of PCI Express root complex
The reset value of the device_type field is 0x0 (EP mode).
So switching between RC mode / EP mode should be fine.
But I agree, theoretically there could be a bug if e.g. bootloader
has set the device_type to 0x1 (Legacy EP).
So if you want, you could send a patch:
-#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE_BIT(0x40)
+#define PCIE_CLIENT_RC_MODE HIWORD_UPDATE(0xf0, 0x40)
With:
Fixes: 0e898eb8df4e ("PCI: rockchip-dwc: Add Rockchip RK356X host controller driver")
But I also think that your current patch is fine as-is.
I do however think that you can drop this line:
+#define PCIE_CLIENT_MODE_LEGACY 0x1U
Since the define is never used.
Also, is there any point in adding the U suffix?
Usually you see UL or ULL suffix, when that is needed, but there actually
seems to be extremely few hits of simply U suffix:
$ git grep 0x1U | grep -v UL
Kind regards,
Niklas