2018-01-26 12:50:27 -06:00
// SPDX-License-Identifier: GPL-2.0
2013-06-21 16:24:54 +09:00
/*
2017-09-01 16:35:50 -05:00
* Synopsys DesignWare PCIe host controller driver
2013-06-21 16:24:54 +09:00
*
* Copyright ( C ) 2013 Samsung Electronics Co . , Ltd .
2020-06-27 12:30:50 +02:00
* https : //www.samsung.com
2013-06-21 16:24:54 +09:00
*
* Author : Jingoo Han < jg1 . han @ samsung . com >
*/
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-10 14:44:35 -06:00
# include <linux/delay.h>
2017-02-15 18:48:17 +05:30
# include <linux/of.h>
2020-09-30 14:36:06 +09:00
# include <linux/of_platform.h>
2017-02-15 18:48:17 +05:30
# include <linux/types.h>
2013-06-21 16:24:54 +09:00
2019-12-09 11:20:05 +08:00
# include "../../pci.h"
2013-07-31 17:14:10 +09:00
# include "pcie-designware.h"
2013-06-21 16:24:54 +09:00
2019-08-13 17:06:18 +05:30
/*
* These interfaces resemble the pci_find_ * capability ( ) interfaces , but these
* are for configuring host controllers , which are bridges * to * PCI devices but
* are not PCI devices themselves .
*/
static u8 __dw_pcie_find_next_cap ( struct dw_pcie * pci , u8 cap_ptr ,
u8 cap )
{
u8 cap_id , next_cap_ptr ;
u16 reg ;
if ( ! cap_ptr )
return 0 ;
reg = dw_pcie_readw_dbi ( pci , cap_ptr ) ;
cap_id = ( reg & 0x00ff ) ;
if ( cap_id > PCI_CAP_ID_MAX )
return 0 ;
if ( cap_id = = cap )
return cap_ptr ;
next_cap_ptr = ( reg & 0xff00 ) > > 8 ;
return __dw_pcie_find_next_cap ( pci , next_cap_ptr , cap ) ;
}
u8 dw_pcie_find_capability ( struct dw_pcie * pci , u8 cap )
{
u8 next_cap_ptr ;
u16 reg ;
reg = dw_pcie_readw_dbi ( pci , PCI_CAPABILITY_LIST ) ;
next_cap_ptr = ( reg & 0x00ff ) ;
return __dw_pcie_find_next_cap ( pci , next_cap_ptr , cap ) ;
}
EXPORT_SYMBOL_GPL ( dw_pcie_find_capability ) ;
2019-08-13 17:06:19 +05:30
static u16 dw_pcie_find_next_ext_capability ( struct dw_pcie * pci , u16 start ,
u8 cap )
{
u32 header ;
int ttl ;
int pos = PCI_CFG_SPACE_SIZE ;
/* minimum 8 bytes per capability */
ttl = ( PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE ) / 8 ;
if ( start )
pos = start ;
header = dw_pcie_readl_dbi ( pci , pos ) ;
/*
* If we have no capabilities , this is indicated by cap ID ,
* cap version and next pointer all being 0.
*/
if ( header = = 0 )
return 0 ;
while ( ttl - - > 0 ) {
if ( PCI_EXT_CAP_ID ( header ) = = cap & & pos ! = start )
return pos ;
pos = PCI_EXT_CAP_NEXT ( header ) ;
if ( pos < PCI_CFG_SPACE_SIZE )
break ;
header = dw_pcie_readl_dbi ( pci , pos ) ;
}
return 0 ;
}
u16 dw_pcie_find_ext_capability ( struct dw_pcie * pci , u8 cap )
{
return dw_pcie_find_next_ext_capability ( pci , 0 , cap ) ;
}
EXPORT_SYMBOL_GPL ( dw_pcie_find_ext_capability ) ;
2017-02-15 18:48:12 +05:30
int dw_pcie_read ( void __iomem * addr , int size , u32 * val )
2013-06-21 16:24:54 +09:00
{
2019-02-19 12:02:38 -08:00
if ( ! IS_ALIGNED ( ( uintptr_t ) addr , size ) ) {
2015-10-08 14:27:53 -05:00
* val = 0 ;
return PCIBIOS_BAD_REGISTER_NUMBER ;
}
2017-02-15 18:48:16 +05:30
if ( size = = 4 ) {
2015-10-08 14:27:43 -05:00
* val = readl ( addr ) ;
2017-02-15 18:48:16 +05:30
} else if ( size = = 2 ) {
2015-10-08 14:27:48 -05:00
* val = readw ( addr ) ;
2017-02-15 18:48:16 +05:30
} else if ( size = = 1 ) {
2015-10-08 14:27:48 -05:00
* val = readb ( addr ) ;
2017-02-15 18:48:16 +05:30
} else {
2015-10-08 14:27:43 -05:00
* val = 0 ;
2013-06-21 16:24:54 +09:00
return PCIBIOS_BAD_REGISTER_NUMBER ;
2015-10-08 14:27:43 -05:00
}
2013-06-21 16:24:54 +09:00
return PCIBIOS_SUCCESSFUL ;
}
2019-06-25 14:52:38 +05:30
EXPORT_SYMBOL_GPL ( dw_pcie_read ) ;
2013-06-21 16:24:54 +09:00
2017-02-15 18:48:12 +05:30
int dw_pcie_write ( void __iomem * addr , int size , u32 val )
2013-06-21 16:24:54 +09:00
{
2019-02-19 12:02:38 -08:00
if ( ! IS_ALIGNED ( ( uintptr_t ) addr , size ) )
2015-10-08 14:27:53 -05:00
return PCIBIOS_BAD_REGISTER_NUMBER ;
2013-06-21 16:24:54 +09:00
if ( size = = 4 )
writel ( val , addr ) ;
else if ( size = = 2 )
2015-10-08 14:27:48 -05:00
writew ( val , addr ) ;
2013-06-21 16:24:54 +09:00
else if ( size = = 1 )
2015-10-08 14:27:48 -05:00
writeb ( val , addr ) ;
2013-06-21 16:24:54 +09:00
else
return PCIBIOS_BAD_REGISTER_NUMBER ;
return PCIBIOS_SUCCESSFUL ;
}
2019-06-25 14:52:38 +05:30
EXPORT_SYMBOL_GPL ( dw_pcie_write ) ;
2013-06-21 16:24:54 +09:00
2019-06-25 14:52:37 +05:30
u32 dw_pcie_read_dbi ( struct dw_pcie * pci , u32 reg , size_t size )
2013-06-21 16:24:54 +09:00
{
2017-03-13 19:13:26 +05:30
int ret ;
u32 val ;
2016-08-17 14:17:58 -05:00
2021-01-28 14:42:58 +08:00
if ( pci - > ops & & pci - > ops - > read_dbi )
2019-06-25 14:52:37 +05:30
return pci - > ops - > read_dbi ( pci , pci - > dbi_base , reg , size ) ;
2017-03-13 19:13:26 +05:30
2019-06-25 14:52:37 +05:30
ret = dw_pcie_read ( pci - > dbi_base + reg , size , & val ) ;
2017-03-13 19:13:26 +05:30
if ( ret )
2018-05-14 16:09:48 +01:00
dev_err ( pci - > dev , " Read DBI address failed \n " ) ;
2017-03-13 19:13:26 +05:30
return val ;
2013-06-21 16:24:54 +09:00
}
2019-06-25 14:52:38 +05:30
EXPORT_SYMBOL_GPL ( dw_pcie_read_dbi ) ;
2013-06-21 16:24:54 +09:00
2019-06-25 14:52:37 +05:30
void dw_pcie_write_dbi ( struct dw_pcie * pci , u32 reg , size_t size , u32 val )
2013-06-21 16:24:54 +09:00
{
2017-03-13 19:13:26 +05:30
int ret ;
2021-01-28 14:42:58 +08:00
if ( pci - > ops & & pci - > ops - > write_dbi ) {
2019-06-25 14:52:37 +05:30
pci - > ops - > write_dbi ( pci , pci - > dbi_base , reg , size , val ) ;
2017-03-13 19:13:26 +05:30
return ;
}
2019-06-25 14:52:37 +05:30
ret = dw_pcie_write ( pci - > dbi_base + reg , size , val ) ;
2017-03-13 19:13:26 +05:30
if ( ret )
2018-05-14 16:09:48 +01:00
dev_err ( pci - > dev , " Write DBI address failed \n " ) ;
2013-06-21 16:24:54 +09:00
}
2019-06-25 14:52:38 +05:30
EXPORT_SYMBOL_GPL ( dw_pcie_write_dbi ) ;
2013-06-21 16:24:54 +09:00
2019-06-25 14:52:37 +05:30
void dw_pcie_write_dbi2 ( struct dw_pcie * pci , u32 reg , size_t size , u32 val )
2019-03-25 15:09:42 +05:30
{
int ret ;
2021-01-28 14:42:58 +08:00
if ( pci - > ops & & pci - > ops - > write_dbi2 ) {
2019-06-25 14:52:37 +05:30
pci - > ops - > write_dbi2 ( pci , pci - > dbi_base2 , reg , size , val ) ;
2019-03-25 15:09:42 +05:30
return ;
}
2019-06-25 14:52:37 +05:30
ret = dw_pcie_write ( pci - > dbi_base2 + reg , size , val ) ;
2019-03-25 15:09:42 +05:30
if ( ret )
dev_err ( pci - > dev , " write DBI address failed \n " ) ;
}
2020-08-20 21:54:13 -06:00
static u32 dw_pcie_readl_atu ( struct dw_pcie * pci , u32 reg )
2019-06-25 14:52:37 +05:30
{
int ret ;
u32 val ;
2021-01-28 14:42:58 +08:00
if ( pci - > ops & & pci - > ops - > read_dbi )
2020-08-20 21:54:13 -06:00
return pci - > ops - > read_dbi ( pci , pci - > atu_base , reg , 4 ) ;
2019-06-25 14:52:37 +05:30
2020-08-20 21:54:13 -06:00
ret = dw_pcie_read ( pci - > atu_base + reg , 4 , & val ) ;
2019-06-25 14:52:37 +05:30
if ( ret )
dev_err ( pci - > dev , " Read ATU address failed \n " ) ;
return val ;
}
2020-08-20 21:54:13 -06:00
static void dw_pcie_writel_atu ( struct dw_pcie * pci , u32 reg , u32 val )
2019-06-25 14:52:37 +05:30
{
int ret ;
2021-01-28 14:42:58 +08:00
if ( pci - > ops & & pci - > ops - > write_dbi ) {
2020-08-20 21:54:13 -06:00
pci - > ops - > write_dbi ( pci , pci - > atu_base , reg , 4 , val ) ;
2019-06-25 14:52:37 +05:30
return ;
}
2020-08-20 21:54:13 -06:00
ret = dw_pcie_write ( pci - > atu_base + reg , 4 , val ) ;
2019-06-25 14:52:37 +05:30
if ( ret )
dev_err ( pci - > dev , " Write ATU address failed \n " ) ;
}
2017-03-13 19:13:27 +05:30
static u32 dw_pcie_readl_ob_unroll ( struct dw_pcie * pci , u32 index , u32 reg )
2016-08-10 11:02:39 +01:00
{
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET ( index ) ;
PCI: dwc: Don't hard-code DBI/ATU offset
The DWC PCIe core contains various separate register spaces: DBI, DBI2,
ATU, DMA, etc. The relationship between the addresses of these register
spaces is entirely determined by the implementation of the IP block, not
by the IP block design itself. Hence, the DWC driver must not make
assumptions that one register space can be accessed at a fixed offset from
any other register space. To avoid such assumptions, introduce an
explicit/separate register pointer for the ATU register space. In
particular, the current assumption is not valid for NVIDIA's T194 SoC.
The ATU register space is only used on systems that require unrolled ATU
access. This property is detected at run-time for host controllers, and
when this is detected, this patch provides a default value for atu_base
that matches the previous assumption re: register layout. An alternative
would be to update all drivers for HW that requires unrolled access to
explicitly set atu_base. However, it's hard to tell which drivers would
require atu_base to be set. The unrolled property is not detected for
endpoint systems, and so any endpoint driver that requires unrolled access
must explicitly set the iatu_unroll_enabled flag (none do at present), and
so a check is added to require the driver to also set atu_base while at
it.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Acked-by: Vidya Sagar <vidyas@nvidia.com>
2018-11-30 11:37:19 -07:00
return dw_pcie_readl_atu ( pci , offset + reg ) ;
2016-08-10 11:02:39 +01:00
}
2017-03-13 19:13:27 +05:30
static void dw_pcie_writel_ob_unroll ( struct dw_pcie * pci , u32 index , u32 reg ,
u32 val )
2016-08-10 11:02:39 +01:00
{
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET ( index ) ;
PCI: dwc: Don't hard-code DBI/ATU offset
The DWC PCIe core contains various separate register spaces: DBI, DBI2,
ATU, DMA, etc. The relationship between the addresses of these register
spaces is entirely determined by the implementation of the IP block, not
by the IP block design itself. Hence, the DWC driver must not make
assumptions that one register space can be accessed at a fixed offset from
any other register space. To avoid such assumptions, introduce an
explicit/separate register pointer for the ATU register space. In
particular, the current assumption is not valid for NVIDIA's T194 SoC.
The ATU register space is only used on systems that require unrolled ATU
access. This property is detected at run-time for host controllers, and
when this is detected, this patch provides a default value for atu_base
that matches the previous assumption re: register layout. An alternative
would be to update all drivers for HW that requires unrolled access to
explicitly set atu_base. However, it's hard to tell which drivers would
require atu_base to be set. The unrolled property is not detected for
endpoint systems, and so any endpoint driver that requires unrolled access
must explicitly set the iatu_unroll_enabled flag (none do at present), and
so a check is added to require the driver to also set atu_base while at
it.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Acked-by: Vidya Sagar <vidyas@nvidia.com>
2018-11-30 11:37:19 -07:00
dw_pcie_writel_atu ( pci , offset + reg , val ) ;
2016-08-10 11:02:39 +01:00
}
2020-12-30 22:27:23 +05:30
static inline u32 dw_pcie_enable_ecrc ( u32 val )
{
/*
* DesignWare core version 4.90 A has a design issue where the ' TD '
* bit in the Control register - 1 of the ATU outbound region acts
* like an override for the ECRC setting , i . e . , the presence of TLP
* Digest ( ECRC ) in the outgoing TLPs is solely determined by this
* bit . This is contrary to the PCIe spec which says that the
* enablement of the ECRC is solely determined by the AER
* registers .
*
* Because of this , even when the ECRC is enabled through AER
* registers , the transactions going through ATU won ' t have TLP
* Digest as there is no way the PCI core AER code could program
* the TD bit which is specific to the DesignWare core .
*
* The best way to handle this scenario is to program the TD bit
* always . It affects only the traffic from root port to downstream
* devices .
*
* At this point ,
* When ECRC is enabled in AER registers , everything works normally
* When ECRC is NOT enabled in AER registers , then ,
* on Root Port : - TLP Digest ( DWord size ) gets appended to each packet
* even through it is not required . Since downstream
* TLPs are mostly for configuration accesses and BAR
* accesses , they are not in critical path and won ' t
* have much negative effect on the performance .
* on End Point : - TLP Digest is received for some / all the packets coming
* from the root port . TLP Digest is ignored because ,
* as per the PCIe Spec r5 .0 v1 .0 section 2.2 .3
* " TLP Digest Rules " , when an endpoint receives TLP
* Digest when its ECRC check functionality is disabled
* in AER registers , received TLP Digest is just ignored .
* Since there is no issue or error reported either side , best way to
* handle the scenario is to program TD bit by default .
*/
return val | PCIE_ATU_TD ;
}
2020-09-18 16:00:13 +08:00
static void dw_pcie_prog_outbound_atu_unroll ( struct dw_pcie * pci , u8 func_no ,
int index , int type ,
u64 cpu_addr , u64 pci_addr ,
2020-11-18 20:16:26 +05:30
u64 size )
2017-03-13 19:13:27 +05:30
{
u32 retries , val ;
2020-04-01 16:58:13 -07:00
u64 limit_addr = cpu_addr + size - 1 ;
2017-03-13 19:13:27 +05:30
dw_pcie_writel_ob_unroll ( pci , index , PCIE_ATU_UNR_LOWER_BASE ,
lower_32_bits ( cpu_addr ) ) ;
dw_pcie_writel_ob_unroll ( pci , index , PCIE_ATU_UNR_UPPER_BASE ,
upper_32_bits ( cpu_addr ) ) ;
2020-04-01 16:58:13 -07:00
dw_pcie_writel_ob_unroll ( pci , index , PCIE_ATU_UNR_LOWER_LIMIT ,
lower_32_bits ( limit_addr ) ) ;
dw_pcie_writel_ob_unroll ( pci , index , PCIE_ATU_UNR_UPPER_LIMIT ,
upper_32_bits ( limit_addr ) ) ;
2017-03-13 19:13:27 +05:30
dw_pcie_writel_ob_unroll ( pci , index , PCIE_ATU_UNR_LOWER_TARGET ,
lower_32_bits ( pci_addr ) ) ;
dw_pcie_writel_ob_unroll ( pci , index , PCIE_ATU_UNR_UPPER_TARGET ,
upper_32_bits ( pci_addr ) ) ;
2020-11-18 20:16:26 +05:30
val = type | PCIE_ATU_FUNC_NUM ( func_no ) ;
val = upper_32_bits ( size - 1 ) ?
val | PCIE_ATU_INCREASE_REGION_SIZE : val ;
2020-12-30 22:27:23 +05:30
if ( pci - > version = = 0x490A )
val = dw_pcie_enable_ecrc ( val ) ;
2020-11-18 20:16:26 +05:30
dw_pcie_writel_ob_unroll ( pci , index , PCIE_ATU_UNR_REGION_CTRL1 , val ) ;
2017-03-13 19:13:27 +05:30
dw_pcie_writel_ob_unroll ( pci , index , PCIE_ATU_UNR_REGION_CTRL2 ,
PCIE_ATU_ENABLE ) ;
/*
* Make sure ATU enable takes effect before any subsequent config
* and I / O accesses .
*/
for ( retries = 0 ; retries < LINK_WAIT_MAX_IATU_RETRIES ; retries + + ) {
val = dw_pcie_readl_ob_unroll ( pci , index ,
PCIE_ATU_UNR_REGION_CTRL2 ) ;
if ( val & PCIE_ATU_ENABLE )
return ;
2018-09-20 16:32:52 -05:00
mdelay ( LINK_WAIT_IATU ) ;
2017-03-13 19:13:27 +05:30
}
2018-05-14 16:09:48 +01:00
dev_err ( pci - > dev , " Outbound iATU is not being enabled \n " ) ;
2017-03-13 19:13:27 +05:30
}
2020-09-18 16:00:13 +08:00
static void __dw_pcie_prog_outbound_atu ( struct dw_pcie * pci , u8 func_no ,
int index , int type , u64 cpu_addr ,
2020-11-18 20:16:26 +05:30
u64 pci_addr , u64 size )
2015-04-30 16:22:28 +08:00
{
2016-08-17 13:26:07 -05:00
u32 retries , val ;
2015-12-18 14:38:55 +02:00
2021-01-28 14:42:58 +08:00
if ( pci - > ops & & pci - > ops - > cpu_addr_fixup )
PCI: dwc: Make cpu_addr_fixup take struct dw_pcie as argument
The current cpu addr fixup mask for ARTPEC-6, GENMASK(27, 0), is wrong.
The correct cpu addr fixup mask for ARTPEC-6 is GENMASK(28, 0).
However, having a hardcoded cpu addr fixup mask in each driver is
arguably wrong.
A device tree property called something like "cpu-addr-fixup-mask"
would have been a better solution.
Introducing such a property is not needed though, since we already have
pp->cfg0_base and ep->phys_base, which is derived from already existing
device tree properties.
It is also worth noting that for ARTPEC-7, hardcoding the cpu addr fixup
mask is not possible, since it uses a High Address Bits Look Up Table,
which means that it can, at runtime, map the PCIe window to an arbitrary
address in the 32-bit address space.
By using pp->cfg0_base and ep->phys_base, we avoid hardcoding a mask
in each driver. This should work for ARTPEC-6, DRA7xx, and ARTPEC-7.
I have not changed the code in DRA7xx though, since their existing
code works, but if they want, they could use the same logic as
artpec6_pcie_cpu_addr_fixup, and thus remove their hardcoded mask.
The reason why the fixup mask is needed is explained in commit f4c55c5a3f7f
("PCI: designware: Program ATU with untranslated address").
Signed-off-by: Niklas Cassel <niklas.cassel@axis.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Kishon Vijay Abraham I <kishon@ti.com>
2017-12-20 00:29:36 +01:00
cpu_addr = pci - > ops - > cpu_addr_fixup ( pci , cpu_addr ) ;
2017-03-13 19:13:22 +05:30
2017-02-15 18:48:14 +05:30
if ( pci - > iatu_unroll_enabled ) {
2020-09-18 16:00:13 +08:00
dw_pcie_prog_outbound_atu_unroll ( pci , func_no , index , type ,
cpu_addr , pci_addr , size ) ;
2017-03-13 19:13:27 +05:30
return ;
2016-08-10 11:02:39 +01:00
}
2015-12-18 14:38:55 +02:00
2017-03-13 19:13:27 +05:30
dw_pcie_writel_dbi ( pci , PCIE_ATU_VIEWPORT ,
PCIE_ATU_REGION_OUTBOUND | index ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_LOWER_BASE ,
lower_32_bits ( cpu_addr ) ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_UPPER_BASE ,
upper_32_bits ( cpu_addr ) ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_LIMIT ,
lower_32_bits ( cpu_addr + size - 1 ) ) ;
2021-02-02 12:58:38 +05:30
if ( pci - > version > = 0x460A )
dw_pcie_writel_dbi ( pci , PCIE_ATU_UPPER_LIMIT ,
upper_32_bits ( cpu_addr + size - 1 ) ) ;
2017-03-13 19:13:27 +05:30
dw_pcie_writel_dbi ( pci , PCIE_ATU_LOWER_TARGET ,
lower_32_bits ( pci_addr ) ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_UPPER_TARGET ,
upper_32_bits ( pci_addr ) ) ;
2020-12-30 22:27:23 +05:30
val = type | PCIE_ATU_FUNC_NUM ( func_no ) ;
2021-02-02 12:58:38 +05:30
val = ( ( upper_32_bits ( size - 1 ) ) & & ( pci - > version > = 0x460A ) ) ?
val | PCIE_ATU_INCREASE_REGION_SIZE : val ;
2020-12-30 22:27:23 +05:30
if ( pci - > version = = 0x490A )
val = dw_pcie_enable_ecrc ( val ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_CR1 , val ) ;
2017-03-13 19:13:27 +05:30
dw_pcie_writel_dbi ( pci , PCIE_ATU_CR2 , PCIE_ATU_ENABLE ) ;
2015-12-18 14:38:55 +02:00
/*
* Make sure ATU enable takes effect before any subsequent config
* and I / O accesses .
*/
2016-08-17 13:26:07 -05:00
for ( retries = 0 ; retries < LINK_WAIT_MAX_IATU_RETRIES ; retries + + ) {
2017-03-13 19:13:27 +05:30
val = dw_pcie_readl_dbi ( pci , PCIE_ATU_CR2 ) ;
2017-07-18 14:48:21 +08:00
if ( val & PCIE_ATU_ENABLE )
2016-08-17 13:26:07 -05:00
return ;
2018-09-20 16:32:52 -05:00
mdelay ( LINK_WAIT_IATU ) ;
2016-08-17 13:26:07 -05:00
}
2018-05-14 16:09:48 +01:00
dev_err ( pci - > dev , " Outbound iATU is not being enabled \n " ) ;
2015-04-30 16:22:28 +08:00
}
2020-09-18 16:00:13 +08:00
void dw_pcie_prog_outbound_atu ( struct dw_pcie * pci , int index , int type ,
2020-11-18 20:16:26 +05:30
u64 cpu_addr , u64 pci_addr , u64 size )
2020-09-18 16:00:13 +08:00
{
__dw_pcie_prog_outbound_atu ( pci , 0 , index , type ,
cpu_addr , pci_addr , size ) ;
}
void dw_pcie_prog_ep_outbound_atu ( struct dw_pcie * pci , u8 func_no , int index ,
int type , u64 cpu_addr , u64 pci_addr ,
2021-01-06 16:15:00 +05:30
u64 size )
2020-09-18 16:00:13 +08:00
{
__dw_pcie_prog_outbound_atu ( pci , func_no , index , type ,
cpu_addr , pci_addr , size ) ;
}
2017-03-27 15:15:05 +05:30
static u32 dw_pcie_readl_ib_unroll ( struct dw_pcie * pci , u32 index , u32 reg )
{
u32 offset = PCIE_GET_ATU_INB_UNR_REG_OFFSET ( index ) ;
PCI: dwc: Don't hard-code DBI/ATU offset
The DWC PCIe core contains various separate register spaces: DBI, DBI2,
ATU, DMA, etc. The relationship between the addresses of these register
spaces is entirely determined by the implementation of the IP block, not
by the IP block design itself. Hence, the DWC driver must not make
assumptions that one register space can be accessed at a fixed offset from
any other register space. To avoid such assumptions, introduce an
explicit/separate register pointer for the ATU register space. In
particular, the current assumption is not valid for NVIDIA's T194 SoC.
The ATU register space is only used on systems that require unrolled ATU
access. This property is detected at run-time for host controllers, and
when this is detected, this patch provides a default value for atu_base
that matches the previous assumption re: register layout. An alternative
would be to update all drivers for HW that requires unrolled access to
explicitly set atu_base. However, it's hard to tell which drivers would
require atu_base to be set. The unrolled property is not detected for
endpoint systems, and so any endpoint driver that requires unrolled access
must explicitly set the iatu_unroll_enabled flag (none do at present), and
so a check is added to require the driver to also set atu_base while at
it.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Acked-by: Vidya Sagar <vidyas@nvidia.com>
2018-11-30 11:37:19 -07:00
return dw_pcie_readl_atu ( pci , offset + reg ) ;
2017-03-27 15:15:05 +05:30
}
static void dw_pcie_writel_ib_unroll ( struct dw_pcie * pci , u32 index , u32 reg ,
u32 val )
{
u32 offset = PCIE_GET_ATU_INB_UNR_REG_OFFSET ( index ) ;
PCI: dwc: Don't hard-code DBI/ATU offset
The DWC PCIe core contains various separate register spaces: DBI, DBI2,
ATU, DMA, etc. The relationship between the addresses of these register
spaces is entirely determined by the implementation of the IP block, not
by the IP block design itself. Hence, the DWC driver must not make
assumptions that one register space can be accessed at a fixed offset from
any other register space. To avoid such assumptions, introduce an
explicit/separate register pointer for the ATU register space. In
particular, the current assumption is not valid for NVIDIA's T194 SoC.
The ATU register space is only used on systems that require unrolled ATU
access. This property is detected at run-time for host controllers, and
when this is detected, this patch provides a default value for atu_base
that matches the previous assumption re: register layout. An alternative
would be to update all drivers for HW that requires unrolled access to
explicitly set atu_base. However, it's hard to tell which drivers would
require atu_base to be set. The unrolled property is not detected for
endpoint systems, and so any endpoint driver that requires unrolled access
must explicitly set the iatu_unroll_enabled flag (none do at present), and
so a check is added to require the driver to also set atu_base while at
it.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Acked-by: Vidya Sagar <vidyas@nvidia.com>
2018-11-30 11:37:19 -07:00
dw_pcie_writel_atu ( pci , offset + reg , val ) ;
2017-03-27 15:15:05 +05:30
}
2020-09-18 16:00:13 +08:00
static int dw_pcie_prog_inbound_atu_unroll ( struct dw_pcie * pci , u8 func_no ,
int index , int bar , u64 cpu_addr ,
2017-07-17 14:13:34 +01:00
enum dw_pcie_as_type as_type )
2017-03-27 15:15:05 +05:30
{
int type ;
u32 retries , val ;
dw_pcie_writel_ib_unroll ( pci , index , PCIE_ATU_UNR_LOWER_TARGET ,
lower_32_bits ( cpu_addr ) ) ;
dw_pcie_writel_ib_unroll ( pci , index , PCIE_ATU_UNR_UPPER_TARGET ,
upper_32_bits ( cpu_addr ) ) ;
switch ( as_type ) {
case DW_PCIE_AS_MEM :
type = PCIE_ATU_TYPE_MEM ;
break ;
case DW_PCIE_AS_IO :
type = PCIE_ATU_TYPE_IO ;
break ;
default :
return - EINVAL ;
}
2020-09-18 16:00:13 +08:00
dw_pcie_writel_ib_unroll ( pci , index , PCIE_ATU_UNR_REGION_CTRL1 , type |
PCIE_ATU_FUNC_NUM ( func_no ) ) ;
2017-03-27 15:15:05 +05:30
dw_pcie_writel_ib_unroll ( pci , index , PCIE_ATU_UNR_REGION_CTRL2 ,
2020-09-18 16:00:13 +08:00
PCIE_ATU_FUNC_NUM_MATCH_EN |
2017-03-27 15:15:05 +05:30
PCIE_ATU_ENABLE |
PCIE_ATU_BAR_MODE_ENABLE | ( bar < < 8 ) ) ;
/*
* Make sure ATU enable takes effect before any subsequent config
* and I / O accesses .
*/
for ( retries = 0 ; retries < LINK_WAIT_MAX_IATU_RETRIES ; retries + + ) {
val = dw_pcie_readl_ib_unroll ( pci , index ,
PCIE_ATU_UNR_REGION_CTRL2 ) ;
if ( val & PCIE_ATU_ENABLE )
return 0 ;
2018-09-20 16:32:52 -05:00
mdelay ( LINK_WAIT_IATU ) ;
2017-03-27 15:15:05 +05:30
}
2018-05-14 16:09:48 +01:00
dev_err ( pci - > dev , " Inbound iATU is not being enabled \n " ) ;
2017-03-27 15:15:05 +05:30
return - EBUSY ;
}
2020-09-18 16:00:13 +08:00
int dw_pcie_prog_inbound_atu ( struct dw_pcie * pci , u8 func_no , int index ,
int bar , u64 cpu_addr ,
enum dw_pcie_as_type as_type )
2017-03-27 15:15:05 +05:30
{
int type ;
u32 retries , val ;
if ( pci - > iatu_unroll_enabled )
2020-09-18 16:00:13 +08:00
return dw_pcie_prog_inbound_atu_unroll ( pci , func_no , index , bar ,
2017-03-27 15:15:05 +05:30
cpu_addr , as_type ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_VIEWPORT , PCIE_ATU_REGION_INBOUND |
index ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_LOWER_TARGET , lower_32_bits ( cpu_addr ) ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_UPPER_TARGET , upper_32_bits ( cpu_addr ) ) ;
switch ( as_type ) {
case DW_PCIE_AS_MEM :
type = PCIE_ATU_TYPE_MEM ;
break ;
case DW_PCIE_AS_IO :
type = PCIE_ATU_TYPE_IO ;
break ;
default :
return - EINVAL ;
}
2020-09-18 16:00:13 +08:00
dw_pcie_writel_dbi ( pci , PCIE_ATU_CR1 , type |
PCIE_ATU_FUNC_NUM ( func_no ) ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_CR2 , PCIE_ATU_ENABLE |
PCIE_ATU_FUNC_NUM_MATCH_EN |
PCIE_ATU_BAR_MODE_ENABLE | ( bar < < 8 ) ) ;
2017-03-27 15:15:05 +05:30
/*
* Make sure ATU enable takes effect before any subsequent config
* and I / O accesses .
*/
for ( retries = 0 ; retries < LINK_WAIT_MAX_IATU_RETRIES ; retries + + ) {
val = dw_pcie_readl_dbi ( pci , PCIE_ATU_CR2 ) ;
if ( val & PCIE_ATU_ENABLE )
return 0 ;
2018-09-20 16:32:52 -05:00
mdelay ( LINK_WAIT_IATU ) ;
2017-03-27 15:15:05 +05:30
}
2018-05-14 16:09:48 +01:00
dev_err ( pci - > dev , " Inbound iATU is not being enabled \n " ) ;
2017-03-27 15:15:05 +05:30
return - EBUSY ;
}
void dw_pcie_disable_atu ( struct dw_pcie * pci , int index ,
enum dw_pcie_region_type type )
{
int region ;
switch ( type ) {
case DW_PCIE_REGION_INBOUND :
region = PCIE_ATU_REGION_INBOUND ;
break ;
case DW_PCIE_REGION_OUTBOUND :
region = PCIE_ATU_REGION_OUTBOUND ;
break ;
default :
return ;
}
dw_pcie_writel_dbi ( pci , PCIE_ATU_VIEWPORT , region | index ) ;
2020-09-22 11:59:10 +02:00
dw_pcie_writel_dbi ( pci , PCIE_ATU_CR2 , ~ ( u32 ) PCIE_ATU_ENABLE ) ;
2017-03-27 15:15:05 +05:30
}
2017-02-15 18:48:14 +05:30
int dw_pcie_wait_for_link ( struct dw_pcie * pci )
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-10 14:44:35 -06:00
{
int retries ;
2018-05-14 16:09:48 +01:00
/* Check if the link is up or not */
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-10 14:44:35 -06:00
for ( retries = 0 ; retries < LINK_WAIT_MAX_RETRIES ; retries + + ) {
2017-02-15 18:48:14 +05:30
if ( dw_pcie_link_up ( pci ) ) {
2018-05-14 16:09:48 +01:00
dev_info ( pci - > dev , " Link up \n " ) ;
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-10 14:44:35 -06:00
return 0 ;
}
usleep_range ( LINK_WAIT_USLEEP_MIN , LINK_WAIT_USLEEP_MAX ) ;
}
2019-08-13 17:06:27 +05:30
dev_info ( pci - > dev , " Phy link never came up \n " ) ;
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-10 14:44:35 -06:00
return - ETIMEDOUT ;
}
2019-08-13 17:06:20 +05:30
EXPORT_SYMBOL_GPL ( dw_pcie_wait_for_link ) ;
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-10 14:44:35 -06:00
2017-02-15 18:48:14 +05:30
int dw_pcie_link_up ( struct dw_pcie * pci )
2013-07-31 17:14:10 +09:00
{
2016-03-10 14:44:44 -06:00
u32 val ;
2021-01-28 14:42:58 +08:00
if ( pci - > ops & & pci - > ops - > link_up )
2017-02-15 18:48:14 +05:30
return pci - > ops - > link_up ( pci ) ;
2016-01-05 15:48:11 -06:00
2019-04-14 17:46:26 -07:00
val = readl ( pci - > dbi_base + PCIE_PORT_DEBUG1 ) ;
return ( ( val & PCIE_PORT_DEBUG1_LINK_UP ) & &
( ! ( val & PCIE_PORT_DEBUG1_LINK_IN_TRAINING ) ) ) ;
2013-07-31 17:14:10 +09:00
}
2019-12-09 11:20:05 +08:00
void dw_pcie_upconfig_setup ( struct dw_pcie * pci )
{
u32 val ;
val = dw_pcie_readl_dbi ( pci , PCIE_PORT_MULTI_LANE_CTRL ) ;
val | = PORT_MLTI_UPCFG_SUPPORT ;
dw_pcie_writel_dbi ( pci , PCIE_PORT_MULTI_LANE_CTRL , val ) ;
}
EXPORT_SYMBOL_GPL ( dw_pcie_upconfig_setup ) ;
2020-08-20 21:54:14 -06:00
static void dw_pcie_link_set_max_speed ( struct dw_pcie * pci , u32 link_gen )
2019-12-09 11:20:05 +08:00
{
2020-08-20 21:54:14 -06:00
u32 cap , ctrl2 , link_speed ;
2019-12-09 11:20:05 +08:00
u8 offset = dw_pcie_find_capability ( pci , PCI_CAP_ID_EXP ) ;
2020-08-20 21:54:14 -06:00
cap = dw_pcie_readl_dbi ( pci , offset + PCI_EXP_LNKCAP ) ;
ctrl2 = dw_pcie_readl_dbi ( pci , offset + PCI_EXP_LNKCTL2 ) ;
ctrl2 & = ~ PCI_EXP_LNKCTL2_TLS ;
2019-12-09 11:20:05 +08:00
switch ( pcie_link_speed [ link_gen ] ) {
case PCIE_SPEED_2_5GT :
2020-08-20 21:54:14 -06:00
link_speed = PCI_EXP_LNKCTL2_TLS_2_5GT ;
2019-12-09 11:20:05 +08:00
break ;
case PCIE_SPEED_5_0GT :
2020-08-20 21:54:14 -06:00
link_speed = PCI_EXP_LNKCTL2_TLS_5_0GT ;
2019-12-09 11:20:05 +08:00
break ;
case PCIE_SPEED_8_0GT :
2020-08-20 21:54:14 -06:00
link_speed = PCI_EXP_LNKCTL2_TLS_8_0GT ;
2019-12-09 11:20:05 +08:00
break ;
case PCIE_SPEED_16_0GT :
2020-08-20 21:54:14 -06:00
link_speed = PCI_EXP_LNKCTL2_TLS_16_0GT ;
2019-12-09 11:20:05 +08:00
break ;
default :
/* Use hardware capability */
2020-08-20 21:54:14 -06:00
link_speed = FIELD_GET ( PCI_EXP_LNKCAP_SLS , cap ) ;
ctrl2 & = ~ PCI_EXP_LNKCTL2_HASD ;
2019-12-09 11:20:05 +08:00
break ;
}
2020-08-20 21:54:14 -06:00
dw_pcie_writel_dbi ( pci , offset + PCI_EXP_LNKCTL2 , ctrl2 | link_speed ) ;
cap & = ~ ( ( u32 ) PCI_EXP_LNKCAP_SLS ) ;
dw_pcie_writel_dbi ( pci , offset + PCI_EXP_LNKCAP , cap | link_speed ) ;
2019-12-09 11:20:05 +08:00
}
2019-03-25 15:09:31 +05:30
static u8 dw_pcie_iatu_unroll_enabled ( struct dw_pcie * pci )
{
u32 val ;
val = dw_pcie_readl_dbi ( pci , PCIE_ATU_VIEWPORT ) ;
if ( val = = 0xffffffff )
return 1 ;
return 0 ;
}
2020-11-05 15:11:59 -06:00
static void dw_pcie_iatu_detect_regions_unroll ( struct dw_pcie * pci )
{
int max_region , i , ob = 0 , ib = 0 ;
u32 val ;
max_region = min ( ( int ) pci - > atu_size / 512 , 256 ) ;
for ( i = 0 ; i < max_region ; i + + ) {
dw_pcie_writel_ob_unroll ( pci , i , PCIE_ATU_UNR_LOWER_TARGET ,
0x11110000 ) ;
val = dw_pcie_readl_ob_unroll ( pci , i , PCIE_ATU_UNR_LOWER_TARGET ) ;
if ( val = = 0x11110000 )
ob + + ;
else
break ;
}
for ( i = 0 ; i < max_region ; i + + ) {
dw_pcie_writel_ib_unroll ( pci , i , PCIE_ATU_UNR_LOWER_TARGET ,
0x11110000 ) ;
val = dw_pcie_readl_ib_unroll ( pci , i , PCIE_ATU_UNR_LOWER_TARGET ) ;
if ( val = = 0x11110000 )
ib + + ;
else
break ;
}
pci - > num_ib_windows = ib ;
pci - > num_ob_windows = ob ;
}
static void dw_pcie_iatu_detect_regions ( struct dw_pcie * pci )
{
int max_region , i , ob = 0 , ib = 0 ;
u32 val ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_VIEWPORT , 0xFF ) ;
max_region = dw_pcie_readl_dbi ( pci , PCIE_ATU_VIEWPORT ) + 1 ;
for ( i = 0 ; i < max_region ; i + + ) {
dw_pcie_writel_dbi ( pci , PCIE_ATU_VIEWPORT , PCIE_ATU_REGION_OUTBOUND | i ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_LOWER_TARGET , 0x11110000 ) ;
val = dw_pcie_readl_dbi ( pci , PCIE_ATU_LOWER_TARGET ) ;
if ( val = = 0x11110000 )
ob + + ;
else
break ;
}
for ( i = 0 ; i < max_region ; i + + ) {
dw_pcie_writel_dbi ( pci , PCIE_ATU_VIEWPORT , PCIE_ATU_REGION_INBOUND | i ) ;
dw_pcie_writel_dbi ( pci , PCIE_ATU_LOWER_TARGET , 0x11110000 ) ;
val = dw_pcie_readl_dbi ( pci , PCIE_ATU_LOWER_TARGET ) ;
if ( val = = 0x11110000 )
ib + + ;
else
break ;
}
pci - > num_ib_windows = ib ;
pci - > num_ob_windows = ob ;
}
2017-02-15 18:48:17 +05:30
void dw_pcie_setup ( struct dw_pcie * pci )
2013-06-21 16:24:54 +09:00
{
u32 val ;
2017-02-15 18:48:15 +05:30
struct device * dev = pci - > dev ;
struct device_node * np = dev - > of_node ;
2020-09-30 14:36:06 +09:00
struct platform_device * pdev = to_platform_device ( dev ) ;
2017-02-15 18:48:15 +05:30
2019-03-25 15:09:32 +05:30
if ( pci - > version > = 0x480A | | ( ! pci - > version & &
dw_pcie_iatu_unroll_enabled ( pci ) ) ) {
pci - > iatu_unroll_enabled = true ;
2020-11-05 15:11:59 -06:00
if ( ! pci - > atu_base ) {
struct resource * res =
platform_get_resource_byname ( pdev , IORESOURCE_MEM , " atu " ) ;
if ( res )
pci - > atu_size = resource_size ( res ) ;
pci - > atu_base = devm_ioremap_resource ( dev , res ) ;
if ( IS_ERR ( pci - > atu_base ) )
pci - > atu_base = pci - > dbi_base + DEFAULT_DBI_ATU_OFFSET ;
}
if ( ! pci - > atu_size )
/* Pick a minimal default, enough for 8 in and 8 out windows */
pci - > atu_size = SZ_4K ;
dw_pcie_iatu_detect_regions_unroll ( pci ) ;
} else
dw_pcie_iatu_detect_regions ( pci ) ;
dev_info ( pci - > dev , " iATU unroll: %s \n " , pci - > iatu_unroll_enabled ?
2019-03-25 15:09:32 +05:30
" enabled " : " disabled " ) ;
2019-03-25 15:09:31 +05:30
2020-11-05 15:11:59 -06:00
dev_info ( pci - > dev , " Detected iATU regions: %u outbound, %u inbound " ,
pci - > num_ob_windows , pci - > num_ib_windows ) ;
2020-08-20 21:54:14 -06:00
if ( pci - > link_gen > 0 )
dw_pcie_link_set_max_speed ( pci , pci - > link_gen ) ;
2020-08-20 21:54:19 -06:00
/* Configure Gen1 N_FTS */
if ( pci - > n_fts [ 0 ] ) {
val = dw_pcie_readl_dbi ( pci , PCIE_PORT_AFR ) ;
val & = ~ ( PORT_AFR_N_FTS_MASK | PORT_AFR_CC_N_FTS_MASK ) ;
val | = PORT_AFR_N_FTS ( pci - > n_fts [ 0 ] ) ;
val | = PORT_AFR_CC_N_FTS ( pci - > n_fts [ 0 ] ) ;
dw_pcie_writel_dbi ( pci , PCIE_PORT_AFR , val ) ;
}
/* Configure Gen2+ N_FTS */
if ( pci - > n_fts [ 1 ] ) {
val = dw_pcie_readl_dbi ( pci , PCIE_LINK_WIDTH_SPEED_CONTROL ) ;
val & = ~ PORT_LOGIC_N_FTS_MASK ;
val | = pci - > n_fts [ pci - > link_gen - 1 ] ;
dw_pcie_writel_dbi ( pci , PCIE_LINK_WIDTH_SPEED_CONTROL , val ) ;
}
2020-08-20 21:54:04 -06:00
val = dw_pcie_readl_dbi ( pci , PCIE_PORT_LINK_CONTROL ) ;
val & = ~ PORT_LINK_FAST_LINK_MODE ;
2020-08-20 21:54:15 -06:00
val | = PORT_LINK_DLL_LINK_EN ;
2020-08-20 21:54:04 -06:00
dw_pcie_writel_dbi ( pci , PCIE_PORT_LINK_CONTROL , val ) ;
2019-03-25 15:09:31 +05:30
2020-08-20 21:54:03 -06:00
of_property_read_u32 ( np , " num-lanes " , & pci - > num_lanes ) ;
if ( ! pci - > num_lanes ) {
dev_dbg ( pci - > dev , " Using h/w default number of lanes \n " ) ;
2019-08-20 07:28:49 +00:00
return ;
}
2013-06-21 16:24:54 +09:00
2018-05-14 16:09:48 +01:00
/* Set the number of lanes */
2020-08-20 21:54:04 -06:00
val & = ~ PORT_LINK_FAST_LINK_MODE ;
2013-06-21 16:24:54 +09:00
val & = ~ PORT_LINK_MODE_MASK ;
2020-08-20 21:54:03 -06:00
switch ( pci - > num_lanes ) {
2013-07-31 17:14:10 +09:00
case 1 :
val | = PORT_LINK_MODE_1_LANES ;
break ;
case 2 :
val | = PORT_LINK_MODE_2_LANES ;
break ;
case 4 :
val | = PORT_LINK_MODE_4_LANES ;
break ;
2015-05-13 14:44:34 +08:00
case 8 :
val | = PORT_LINK_MODE_8_LANES ;
break ;
2015-09-29 00:03:10 +08:00
default :
2020-08-20 21:54:03 -06:00
dev_err ( pci - > dev , " num-lanes %u: invalid value \n " , pci - > num_lanes ) ;
2015-09-29 00:03:10 +08:00
return ;
2013-07-31 17:14:10 +09:00
}
2017-02-15 18:48:14 +05:30
dw_pcie_writel_dbi ( pci , PCIE_PORT_LINK_CONTROL , val ) ;
2013-06-21 16:24:54 +09:00
2018-05-14 16:09:48 +01:00
/* Set link width speed control register */
2017-02-15 18:48:14 +05:30
val = dw_pcie_readl_dbi ( pci , PCIE_LINK_WIDTH_SPEED_CONTROL ) ;
2013-06-21 16:24:54 +09:00
val & = ~ PORT_LOGIC_LINK_WIDTH_MASK ;
2020-08-20 21:54:03 -06:00
switch ( pci - > num_lanes ) {
2013-07-31 17:14:10 +09:00
case 1 :
val | = PORT_LOGIC_LINK_WIDTH_1_LANES ;
break ;
case 2 :
val | = PORT_LOGIC_LINK_WIDTH_2_LANES ;
break ;
case 4 :
val | = PORT_LOGIC_LINK_WIDTH_4_LANES ;
break ;
2015-05-13 14:44:34 +08:00
case 8 :
val | = PORT_LOGIC_LINK_WIDTH_8_LANES ;
break ;
2013-07-31 17:14:10 +09:00
}
2017-02-15 18:48:14 +05:30
dw_pcie_writel_dbi ( pci , PCIE_LINK_WIDTH_SPEED_CONTROL , val ) ;
2019-08-13 17:06:22 +05:30
if ( of_property_read_bool ( np , " snps,enable-cdm-check " ) ) {
val = dw_pcie_readl_dbi ( pci , PCIE_PL_CHK_REG_CONTROL_STATUS ) ;
val | = PCIE_PL_CHK_REG_CHK_REG_CONTINUOUS |
PCIE_PL_CHK_REG_CHK_REG_START ;
dw_pcie_writel_dbi ( pci , PCIE_PL_CHK_REG_CONTROL_STATUS , val ) ;
}
2013-06-21 16:24:54 +09:00
}