178178
179179#define MSI_IRQ_NUM 32
180180
181+ #define CFG_RD_CRS_VAL 0xffff0001
182+
181183struct advk_pcie {
182184 struct platform_device * pdev ;
183185 void __iomem * base ;
@@ -473,7 +475,7 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
473475 advk_writel (pcie , reg , PCIE_CORE_CMD_STATUS_REG );
474476}
475477
476- static int advk_pcie_check_pio_status (struct advk_pcie * pcie , u32 * val )
478+ static int advk_pcie_check_pio_status (struct advk_pcie * pcie , bool allow_crs , u32 * val )
477479{
478480 struct device * dev = & pcie -> pdev -> dev ;
479481 u32 reg ;
@@ -515,9 +517,30 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, u32 *val)
515517 strcomp_status = "UR" ;
516518 break ;
517519 case PIO_COMPLETION_STATUS_CRS :
520+ if (allow_crs && val ) {
521+ /* PCIe r4.0, sec 2.3.2, says:
522+ * If CRS Software Visibility is enabled:
523+ * For a Configuration Read Request that includes both
524+ * bytes of the Vendor ID field of a device Function's
525+ * Configuration Space Header, the Root Complex must
526+ * complete the Request to the host by returning a
527+ * read-data value of 0001h for the Vendor ID field and
528+ * all '1's for any additional bytes included in the
529+ * request.
530+ *
531+ * So CRS in this case is not an error status.
532+ */
533+ * val = CFG_RD_CRS_VAL ;
534+ strcomp_status = NULL ;
535+ break ;
536+ }
518537 /* PCIe r4.0, sec 2.3.2, says:
519538 * If CRS Software Visibility is not enabled, the Root Complex
520539 * must re-issue the Configuration Request as a new Request.
540+ * If CRS Software Visibility is enabled: For a Configuration
541+ * Write Request or for any other Configuration Read Request,
542+ * the Root Complex must re-issue the Configuration Request as
543+ * a new Request.
521544 * A Root Complex implementation may choose to limit the number
522545 * of Configuration Request/CRS Completion Status loops before
523546 * determining that something is wrong with the target of the
@@ -586,6 +609,7 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,
586609 case PCI_EXP_RTCTL : {
587610 u32 val = advk_readl (pcie , PCIE_ISR0_MASK_REG );
588611 * value = (val & PCIE_MSG_PM_PME_MASK ) ? 0 : PCI_EXP_RTCTL_PMEIE ;
612+ * value |= PCI_EXP_RTCAP_CRSVIS << 16 ;
589613 return PCI_BRIDGE_EMUL_HANDLED ;
590614 }
591615
@@ -667,6 +691,7 @@ static struct pci_bridge_emul_ops advk_pci_bridge_emul_ops = {
667691static int advk_sw_pci_bridge_init (struct advk_pcie * pcie )
668692{
669693 struct pci_bridge_emul * bridge = & pcie -> bridge ;
694+ int ret ;
670695
671696 bridge -> conf .vendor =
672697 cpu_to_le16 (advk_readl (pcie , PCIE_CORE_DEV_ID_REG ) & 0xffff );
@@ -690,7 +715,15 @@ static int advk_sw_pci_bridge_init(struct advk_pcie *pcie)
690715 bridge -> data = pcie ;
691716 bridge -> ops = & advk_pci_bridge_emul_ops ;
692717
693- return pci_bridge_emul_init (bridge , 0 );
718+ /* PCIe config space can be initialized after pci_bridge_emul_init() */
719+ ret = pci_bridge_emul_init (bridge , 0 );
720+ if (ret < 0 )
721+ return ret ;
722+
723+ /* Indicates supports for Completion Retry Status */
724+ bridge -> pcie_conf .rootcap = cpu_to_le16 (PCI_EXP_RTCAP_CRSVIS );
725+
726+ return 0 ;
694727}
695728
696729static bool advk_pcie_valid_device (struct advk_pcie * pcie , struct pci_bus * bus ,
@@ -742,6 +775,7 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
742775 int where , int size , u32 * val )
743776{
744777 struct advk_pcie * pcie = bus -> sysdata ;
778+ bool allow_crs ;
745779 u32 reg ;
746780 int ret ;
747781
@@ -754,7 +788,24 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
754788 return pci_bridge_emul_conf_read (& pcie -> bridge , where ,
755789 size , val );
756790
791+ /*
792+ * Completion Retry Status is possible to return only when reading all
793+ * 4 bytes from PCI_VENDOR_ID and PCI_DEVICE_ID registers at once and
794+ * CRSSVE flag on Root Bridge is enabled.
795+ */
796+ allow_crs = (where == PCI_VENDOR_ID ) && (size == 4 ) &&
797+ (le16_to_cpu (pcie -> bridge .pcie_conf .rootctl ) &
798+ PCI_EXP_RTCTL_CRSSVE );
799+
757800 if (advk_pcie_pio_is_running (pcie )) {
801+ /*
802+ * If it is possible return Completion Retry Status so caller
803+ * tries to issue the request again instead of failing.
804+ */
805+ if (allow_crs ) {
806+ * val = CFG_RD_CRS_VAL ;
807+ return PCIBIOS_SUCCESSFUL ;
808+ }
758809 * val = 0xffffffff ;
759810 return PCIBIOS_SET_FAILED ;
760811 }
@@ -782,12 +833,20 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
782833
783834 ret = advk_pcie_wait_pio (pcie );
784835 if (ret < 0 ) {
836+ /*
837+ * If it is possible return Completion Retry Status so caller
838+ * tries to issue the request again instead of failing.
839+ */
840+ if (allow_crs ) {
841+ * val = CFG_RD_CRS_VAL ;
842+ return PCIBIOS_SUCCESSFUL ;
843+ }
785844 * val = 0xffffffff ;
786845 return PCIBIOS_SET_FAILED ;
787846 }
788847
789848 /* Check PIO status and get the read result */
790- ret = advk_pcie_check_pio_status (pcie , val );
849+ ret = advk_pcie_check_pio_status (pcie , allow_crs , val );
791850 if (ret < 0 ) {
792851 * val = 0xffffffff ;
793852 return PCIBIOS_SET_FAILED ;
@@ -856,7 +915,7 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
856915 if (ret < 0 )
857916 return PCIBIOS_SET_FAILED ;
858917
859- ret = advk_pcie_check_pio_status (pcie , NULL );
918+ ret = advk_pcie_check_pio_status (pcie , false, NULL );
860919 if (ret < 0 )
861920 return PCIBIOS_SET_FAILED ;
862921
0 commit comments