PCI: dwc: ep: Multi-function endpoint configuration fixes
v3 cover PCI: dwc: ep: Multi-function endpoint configuration fixes
This series addresses multi-function endpoint configuration issues in the DWC PCIe controller driver. The changes enable proper operations for physical functions and enhance the multi-function endpoint support.
This patch series can be seen as an extension of the patch series:
https://lore.kernel.org/all/[email protected]/
Changes from v2 to v3:
- Wrap the patches to fit within 80 columns
Changes from v1 to v2:
- Fixed the minor nits in the patches
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Aksh Garg (2):
PCI: dwc: ep: Fix MSI-X configuration to write to correct physical
function
PCI: dwc: ep: Mirror the max link width and speed fields to all
functions
.../pci/controller/dwc/pcie-designware-ep.c | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/2 PCI: dwc: ep: Fix MSI-X configuration to write to correct physical function
The MSI-X configuration code reads from the correct physical function's register space using dw_pcie_ep_readw_dbi(), but writes back only to PF0 using the old dw_pcie_writew_dbi() helper. This causes incorrect MSI-X configuration for other PFs.
Fix this by using dw_pcie_ep_writew_dbi() to write to the correct PF's register space, matching the read operation.
---
Changes since v1:
- None
v1: https://lore.kernel.org/all/[email protected]/
drivers/pci/controller/dwc/pcie-designware-ep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -1
@@ -745,7 +745,7 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, val =dw_pcie_ep_readw_dbi (ep, func_no, reg); val &= ~PCI_MSIX_FLAGS_QSIZE ; val |= nr_irqs -1 ;/* encoded as N-1 */ -dw_pcie_writew_dbi (pci, reg, val); +dw_pcie_ep_writew_dbi (ep, func_no, reg, val); reg = ep_func->msix_cap +PCI_MSIX_TABLE ; val = offset | bir;
Signature · 1 line
2.34.1
Re: [PATCH v3 1/2] PCI: dwc: ep: Fix MSI-X configuration to write to correct physical function
Quoted 7 lines · Aksh Garg
The MSI-X configuration code reads from the correct physical function's register space using
dw_pcie_ep_readw_dbi(), but writes back only to PF0 using the olddw_pcie_writew_dbi()helper. This causes incorrect MSI-X configuration for other PFs.Fix this by using
dw_pcie_ep_writew_dbi()to write to the correct PF's register space, matching the read operation.
Is this another case of using "PF" in a non-SR-IOV context, as I asked about here?
https://lore.kernel.org/all/20260223185558.GA3701139@bhelgaas
I do not want to use "PF" unless we're talking about a device with an SR-IOV Capability and we're doing something specific to SR-IOV.
Quoted 29 lines
Fixes 70fa02ca1446 ("PCI: dwc: Add dw_pcie_ep_{read,write}_dbi[2] helpers")Reviewed-by Niklas Cassel <[email protected]>Signed-off-by Aksh Garg <[email protected]>---
Changes since v1:
- Nonev1: https://lore.kernel.org/all/[email protected]/
drivers/pci/controller/dwc/pcie-designware-ep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/controller/dwc/pcie-designware-ep.c +1
-1@@ -745,7 +745,7 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, val =dw_pcie_ep_readw_dbi (ep, func_no, reg); val &= ~PCI_MSIX_FLAGS_QSIZE ; val |= nr_irqs -1 ;/* encoded as N-1 */ -dw_pcie_writew_dbi (pci, reg, val); +dw_pcie_ep_writew_dbi (ep, func_no, reg, val); reg = ep_func->msix_cap +PCI_MSIX_TABLE ; val = offset | bir;Signature · 1 line
2.34.1
Re: [PATCH v3 1/2] PCI: dwc: ep: Fix MSI-X configuration to write to correct physical function
Quoted 9 lines · Bjorn Helgaas
Quoted 7 lines · Aksh Garg
The MSI-X configuration code reads from the correct physical function's register space using
dw_pcie_ep_readw_dbi(), but writes back only to PF0 using the olddw_pcie_writew_dbi()helper. This causes incorrect MSI-X configuration for other PFs.Fix this by using
dw_pcie_ep_writew_dbi()to write to the correct PF's register space, matching the read operation.
Quoted 7 lines
Is this another case of using "PF" in a non-SR-IOV context, as I asked about here?
https://lore.kernel.org/all/20260223185558.GA3701139@bhelgaasI do not want to use "PF" unless we're talking about a device with an SR-IOV Capability and we're doing something specific to SR-IOV.
I apologize to commit the same mistake here after your feedback. While posting this series again, I made changes to patch 2/2, but forgot to look at the commit message for this patch.
Quoted 30 lines
Quoted 30 lines
Fixes 70fa02ca1446 ("PCI: dwc: Add dw_pcie_ep_{read,write}_dbi[2] helpers")Reviewed-by Niklas Cassel <[email protected]>Signed-off-by Aksh Garg <[email protected]>---
Changes since v1:
- Nonev1: https://lore.kernel.org/all/[email protected]/
drivers/pci/controller/dwc/pcie-designware-ep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/controller/dwc/pcie-designware-ep.c +1
-1@@ -745,7 +745,7 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, val =dw_pcie_ep_readw_dbi (ep, func_no, reg); val &= ~PCI_MSIX_FLAGS_QSIZE ; val |= nr_irqs -1 ;/* encoded as N-1 */ -dw_pcie_writew_dbi (pci, reg, val); +dw_pcie_ep_writew_dbi (ep, func_no, reg, val); reg = ep_func->msix_cap +PCI_MSIX_TABLE ; val = offset | bir;Signature · 1 line
2.34.1
Manivannan Sadhasivam
maintainerRe: [PATCH v3 1/2] PCI: dwc: ep: Fix MSI-X configuration to write to correct physical function
In reply to Bjorn HelgaasQuoted 9 lines · Bjorn Helgaas
Quoted 7 lines · Aksh Garg
The MSI-X configuration code reads from the correct physical function's register space using
dw_pcie_ep_readw_dbi(), but writes back only to PF0 using the olddw_pcie_writew_dbi()helper. This causes incorrect MSI-X configuration for other PFs.Fix this by using
dw_pcie_ep_writew_dbi()to write to the correct PF's register space, matching the read operation.
Quoted 8 lines
Is this another case of using "PF" in a non-SR-IOV context, as I asked about here?
https://lore.kernel.org/all/20260223185558.GA3701139@bhelgaas
I do not want to use "PF" unless we're talking about a device with an SR-IOV Capability and we're doing something specific to SR-IOV.
Fixed the subject and commit log:
https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git/commit/?h=controller/dwc&id=271d0b1f058ae9815e75233d04b23e3558c3e4f4
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
PATCH v3 2/2 PCI: dwc: ep: Mirror the max link width and speed fields to all functions
In reply to Aksh GargPCIe r7.0, section 7.5.3.6 states that for multi-function devices, the Max Link Width and Max Link Speed fields in the Link Capabilities Register must report the same values for all functions.
Currently, dw_pcie_setup() programs these fields only for Function 0 via dw_pcie_link_set_max_speed() and dw_pcie_link_set_max_link_width(). For multi-function endpoint configurations, Function 1 and beyond retain their default values, violating the PCIe specification.
Fix this by reading the Max Link Width and Max Link Speed fields from Link Capabilities Register of Function 0 after dw_pcie_setup() completes, then mirroring these values to all other functions.
---
The link speed and width would be negotiated through PF0 during initialization that controls the link behaviour, hence it didn't broke the driver. However, the change is proposed just to make the driver compatible with the PCIe base specifications.
The fix is implemented in pcie-designware-ep.c rather than modifying dw_pcie_setup() directly to keep pcie-designware.c independent of RC/EP specifics and maintain it as common code.
Changes from v2 to v3:
- Wrapped the patches to fit within 80 columns
- Updated the term 'physical function' to 'Function'
Changes from v1 to v2:
- Used FIELD_* macros
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
.../pci/controller/dwc/pcie-designware-ep.c | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +28 -1
@@ -1094,7 +1094,8 @@ static void dw_pcie_ep_init_non_sticky_registers(struct dw_pcie *pci) {struct dw_pcie_ep *ep = &pci->ep;u8 funcs = ep->epc->max_functions; -u8 func_no; +u32 ref_lnkcap, lnkcap; +u8 func_no, offset;dw_pcie_dbi_ro_wr_en (pci);
@@ -1102,6 +1103,32 @@ static void dw_pcie_ep_init_non_sticky_registers(struct dw_pcie *pci)dw_pcie_ep_init_rebar_registers (ep, func_no);dw_pcie_setup (pci); + +/* +* PCIe r7.0, section 7.5.3.6 states that for multi-function +* endpoints, max link width and speed fields must report same +* values for all functions. However, dw_pcie_setup() programs +* these fields only for function 0. Hence, mirror these fields +* to all other functions as well. +*/ +if (funcs >1 ) { + offset =dw_pcie_find_capability (pci,PCI_CAP_ID_EXP ); + ref_lnkcap =dw_pcie_readl_dbi (pci, offset +PCI_EXP_LNKCAP ); + ref_lnkcap =FIELD_GET (PCI_EXP_LNKCAP_MLW |PCI_EXP_LNKCAP_SLS , + ref_lnkcap); + +for (func_no =1 ; func_no < funcs; func_no++) { + offset =dw_pcie_ep_find_capability (ep, func_no, +PCI_CAP_ID_EXP ); + lnkcap =dw_pcie_ep_readl_dbi (ep, func_no, + offset +PCI_EXP_LNKCAP ); +FIELD_MODIFY (PCI_EXP_LNKCAP_MLW |PCI_EXP_LNKCAP_SLS , + &lnkcap, ref_lnkcap); +dw_pcie_ep_writel_dbi (ep, func_no, + offset +PCI_EXP_LNKCAP , lnkcap); + } + } +dw_pcie_dbi_ro_wr_dis (pci); }
Signature · 1 line
2.34.1
Manivannan Sadhasivam
AppliedQuoted 8 lines · Aksh Garg
This series addresses multi-function endpoint configuration issues in the DWC PCIe controller driver. The changes enable proper operations for physical functions and enhance the multi-function endpoint support.
This patch series can be seen as an extension of the patch series:
https://lore.kernel.org/all/[email protected]/[...]
Applied, thanks!
[1/2] PCI: dwc: ep: Fix MSI-X configuration to write to correct physical function
commit: 63ec1248387818f6190569b36d9815699ab5f10e
[2/2] PCI: dwc: ep: Mirror the max link width and speed fields to all functions
commit: 05d013c151d858cc96baa9aa0d19539237435246Best regards,
Signature · 1 line
Manivannan Sadhasivam <[email protected]>