040-0002-PCI-iproc-Add-PAXC-interface-support.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. From 943ebae781f519ecfecbfa1b997f15f59116e41d Mon Sep 17 00:00:00 2001
  2. From: Ray Jui <rjui@broadcom.com>
  3. Date: Fri, 4 Dec 2015 09:34:59 -0800
  4. Subject: [PATCH 2/5] PCI: iproc: Add PAXC interface support
  5. Traditionally, all iProc PCIe root complexes use PAXB-based wrapper, with
  6. an integrated on-chip Serdes to support external endpoint devices. On
  7. newer iProc platforms, a PAXC-based wrapper is introduced, for connection
  8. with internally emulated PCIe endpoint devices in the ASIC.
  9. Add support for PAXC-based iProc PCIe root complex in the iProc PCIe core
  10. driver. This change factors out common logic between PAXB and PAXC, and
  11. uses tables to store register offsets that are different between PAXB and
  12. PAXC. This allows the driver to be scaled to support subsequent PAXC
  13. revisions in the future.
  14. Signed-off-by: Ray Jui <rjui@broadcom.com>
  15. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
  16. Reviewed-by: Scott Branden <sbranden@broadcom.com>
  17. ---
  18. drivers/pci/host/pcie-iproc-platform.c | 24 +++-
  19. drivers/pci/host/pcie-iproc.c | 202 +++++++++++++++++++++++++++------
  20. drivers/pci/host/pcie-iproc.h | 19 ++++
  21. 3 files changed, 205 insertions(+), 40 deletions(-)
  22. --- a/drivers/pci/host/pcie-iproc-platform.c
  23. +++ b/drivers/pci/host/pcie-iproc-platform.c
  24. @@ -26,8 +26,21 @@
  25. #include "pcie-iproc.h"
  26. +static const struct of_device_id iproc_pcie_of_match_table[] = {
  27. + {
  28. + .compatible = "brcm,iproc-pcie",
  29. + .data = (int *)IPROC_PCIE_PAXB,
  30. + }, {
  31. + .compatible = "brcm,iproc-pcie-paxc",
  32. + .data = (int *)IPROC_PCIE_PAXC,
  33. + },
  34. + { /* sentinel */ }
  35. +};
  36. +MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);
  37. +
  38. static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
  39. {
  40. + const struct of_device_id *of_id;
  41. struct iproc_pcie *pcie;
  42. struct device_node *np = pdev->dev.of_node;
  43. struct resource reg;
  44. @@ -35,11 +48,16 @@ static int iproc_pcie_pltfm_probe(struct
  45. LIST_HEAD(res);
  46. int ret;
  47. + of_id = of_match_device(iproc_pcie_of_match_table, &pdev->dev);
  48. + if (!of_id)
  49. + return -EINVAL;
  50. +
  51. pcie = devm_kzalloc(&pdev->dev, sizeof(struct iproc_pcie), GFP_KERNEL);
  52. if (!pcie)
  53. return -ENOMEM;
  54. pcie->dev = &pdev->dev;
  55. + pcie->type = (enum iproc_pcie_type)of_id->data;
  56. platform_set_drvdata(pdev, pcie);
  57. ret = of_address_to_resource(np, 0, &reg);
  58. @@ -114,12 +132,6 @@ static int iproc_pcie_pltfm_remove(struc
  59. return iproc_pcie_remove(pcie);
  60. }
  61. -static const struct of_device_id iproc_pcie_of_match_table[] = {
  62. - { .compatible = "brcm,iproc-pcie", },
  63. - { /* sentinel */ }
  64. -};
  65. -MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);
  66. -
  67. static struct platform_driver iproc_pcie_pltfm_driver = {
  68. .driver = {
  69. .name = "iproc-pcie",
  70. --- a/drivers/pci/host/pcie-iproc.c
  71. +++ b/drivers/pci/host/pcie-iproc.c
  72. @@ -30,20 +30,16 @@
  73. #include "pcie-iproc.h"
  74. -#define CLK_CONTROL_OFFSET 0x000
  75. #define EP_PERST_SOURCE_SELECT_SHIFT 2
  76. #define EP_PERST_SOURCE_SELECT BIT(EP_PERST_SOURCE_SELECT_SHIFT)
  77. #define EP_MODE_SURVIVE_PERST_SHIFT 1
  78. #define EP_MODE_SURVIVE_PERST BIT(EP_MODE_SURVIVE_PERST_SHIFT)
  79. #define RC_PCIE_RST_OUTPUT_SHIFT 0
  80. #define RC_PCIE_RST_OUTPUT BIT(RC_PCIE_RST_OUTPUT_SHIFT)
  81. +#define PAXC_RESET_MASK 0x7f
  82. -#define CFG_IND_ADDR_OFFSET 0x120
  83. #define CFG_IND_ADDR_MASK 0x00001ffc
  84. -#define CFG_IND_DATA_OFFSET 0x124
  85. -
  86. -#define CFG_ADDR_OFFSET 0x1f8
  87. #define CFG_ADDR_BUS_NUM_SHIFT 20
  88. #define CFG_ADDR_BUS_NUM_MASK 0x0ff00000
  89. #define CFG_ADDR_DEV_NUM_SHIFT 15
  90. @@ -55,12 +51,8 @@
  91. #define CFG_ADDR_CFG_TYPE_SHIFT 0
  92. #define CFG_ADDR_CFG_TYPE_MASK 0x00000003
  93. -#define CFG_DATA_OFFSET 0x1fc
  94. -
  95. -#define SYS_RC_INTX_EN 0x330
  96. #define SYS_RC_INTX_MASK 0xf
  97. -#define PCIE_LINK_STATUS_OFFSET 0xf0c
  98. #define PCIE_PHYLINKUP_SHIFT 3
  99. #define PCIE_PHYLINKUP BIT(PCIE_PHYLINKUP_SHIFT)
  100. #define PCIE_DL_ACTIVE_SHIFT 2
  101. @@ -71,12 +63,54 @@
  102. #define OARR_SIZE_CFG_SHIFT 1
  103. #define OARR_SIZE_CFG BIT(OARR_SIZE_CFG_SHIFT)
  104. -#define OARR_LO(window) (0xd20 + (window) * 8)
  105. -#define OARR_HI(window) (0xd24 + (window) * 8)
  106. -#define OMAP_LO(window) (0xd40 + (window) * 8)
  107. -#define OMAP_HI(window) (0xd44 + (window) * 8)
  108. -
  109. #define MAX_NUM_OB_WINDOWS 2
  110. +#define MAX_NUM_PAXC_PF 4
  111. +
  112. +#define IPROC_PCIE_REG_INVALID 0xffff
  113. +
  114. +enum iproc_pcie_reg {
  115. + IPROC_PCIE_CLK_CTRL = 0,
  116. + IPROC_PCIE_CFG_IND_ADDR,
  117. + IPROC_PCIE_CFG_IND_DATA,
  118. + IPROC_PCIE_CFG_ADDR,
  119. + IPROC_PCIE_CFG_DATA,
  120. + IPROC_PCIE_INTX_EN,
  121. + IPROC_PCIE_OARR_LO,
  122. + IPROC_PCIE_OARR_HI,
  123. + IPROC_PCIE_OMAP_LO,
  124. + IPROC_PCIE_OMAP_HI,
  125. + IPROC_PCIE_LINK_STATUS,
  126. +};
  127. +
  128. +/* iProc PCIe PAXB registers */
  129. +static const u16 iproc_pcie_reg_paxb[] = {
  130. + [IPROC_PCIE_CLK_CTRL] = 0x000,
  131. + [IPROC_PCIE_CFG_IND_ADDR] = 0x120,
  132. + [IPROC_PCIE_CFG_IND_DATA] = 0x124,
  133. + [IPROC_PCIE_CFG_ADDR] = 0x1f8,
  134. + [IPROC_PCIE_CFG_DATA] = 0x1fc,
  135. + [IPROC_PCIE_INTX_EN] = 0x330,
  136. + [IPROC_PCIE_OARR_LO] = 0xd20,
  137. + [IPROC_PCIE_OARR_HI] = 0xd24,
  138. + [IPROC_PCIE_OMAP_LO] = 0xd40,
  139. + [IPROC_PCIE_OMAP_HI] = 0xd44,
  140. + [IPROC_PCIE_LINK_STATUS] = 0xf0c,
  141. +};
  142. +
  143. +/* iProc PCIe PAXC v1 registers */
  144. +static const u16 iproc_pcie_reg_paxc[] = {
  145. + [IPROC_PCIE_CLK_CTRL] = 0x000,
  146. + [IPROC_PCIE_CFG_IND_ADDR] = 0x1f0,
  147. + [IPROC_PCIE_CFG_IND_DATA] = 0x1f4,
  148. + [IPROC_PCIE_CFG_ADDR] = 0x1f8,
  149. + [IPROC_PCIE_CFG_DATA] = 0x1fc,
  150. + [IPROC_PCIE_INTX_EN] = IPROC_PCIE_REG_INVALID,
  151. + [IPROC_PCIE_OARR_LO] = IPROC_PCIE_REG_INVALID,
  152. + [IPROC_PCIE_OARR_HI] = IPROC_PCIE_REG_INVALID,
  153. + [IPROC_PCIE_OMAP_LO] = IPROC_PCIE_REG_INVALID,
  154. + [IPROC_PCIE_OMAP_HI] = IPROC_PCIE_REG_INVALID,
  155. + [IPROC_PCIE_LINK_STATUS] = IPROC_PCIE_REG_INVALID,
  156. +};
  157. static inline struct iproc_pcie *iproc_data(struct pci_bus *bus)
  158. {
  159. @@ -91,6 +125,65 @@ static inline struct iproc_pcie *iproc_d
  160. return pcie;
  161. }
  162. +static inline bool iproc_pcie_reg_is_invalid(u16 reg_offset)
  163. +{
  164. + return !!(reg_offset == IPROC_PCIE_REG_INVALID);
  165. +}
  166. +
  167. +static inline u16 iproc_pcie_reg_offset(struct iproc_pcie *pcie,
  168. + enum iproc_pcie_reg reg)
  169. +{
  170. + return pcie->reg_offsets[reg];
  171. +}
  172. +
  173. +static inline u32 iproc_pcie_read_reg(struct iproc_pcie *pcie,
  174. + enum iproc_pcie_reg reg)
  175. +{
  176. + u16 offset = iproc_pcie_reg_offset(pcie, reg);
  177. +
  178. + if (iproc_pcie_reg_is_invalid(offset))
  179. + return 0;
  180. +
  181. + return readl(pcie->base + offset);
  182. +}
  183. +
  184. +static inline void iproc_pcie_write_reg(struct iproc_pcie *pcie,
  185. + enum iproc_pcie_reg reg, u32 val)
  186. +{
  187. + u16 offset = iproc_pcie_reg_offset(pcie, reg);
  188. +
  189. + if (iproc_pcie_reg_is_invalid(offset))
  190. + return;
  191. +
  192. + writel(val, pcie->base + offset);
  193. +}
  194. +
  195. +static inline void iproc_pcie_ob_write(struct iproc_pcie *pcie,
  196. + enum iproc_pcie_reg reg,
  197. + unsigned window, u32 val)
  198. +{
  199. + u16 offset = iproc_pcie_reg_offset(pcie, reg);
  200. +
  201. + if (iproc_pcie_reg_is_invalid(offset))
  202. + return;
  203. +
  204. + writel(val, pcie->base + offset + (window * 8));
  205. +}
  206. +
  207. +static inline bool iproc_pcie_device_is_valid(struct iproc_pcie *pcie,
  208. + unsigned int slot,
  209. + unsigned int fn)
  210. +{
  211. + if (slot > 0)
  212. + return false;
  213. +
  214. + /* PAXC can only support limited number of functions */
  215. + if (pcie->type == IPROC_PCIE_PAXC && fn >= MAX_NUM_PAXC_PF)
  216. + return false;
  217. +
  218. + return true;
  219. +}
  220. +
  221. /**
  222. * Note access to the configuration registers are protected at the higher layer
  223. * by 'pci_lock' in drivers/pci/access.c
  224. @@ -104,28 +197,34 @@ static void __iomem *iproc_pcie_map_cfg_
  225. unsigned fn = PCI_FUNC(devfn);
  226. unsigned busno = bus->number;
  227. u32 val;
  228. + u16 offset;
  229. +
  230. + if (!iproc_pcie_device_is_valid(pcie, slot, fn))
  231. + return NULL;
  232. /* root complex access */
  233. if (busno == 0) {
  234. - if (slot >= 1)
  235. + iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_IND_ADDR,
  236. + where & CFG_IND_ADDR_MASK);
  237. + offset = iproc_pcie_reg_offset(pcie, IPROC_PCIE_CFG_IND_DATA);
  238. + if (iproc_pcie_reg_is_invalid(offset))
  239. return NULL;
  240. - writel(where & CFG_IND_ADDR_MASK,
  241. - pcie->base + CFG_IND_ADDR_OFFSET);
  242. - return (pcie->base + CFG_IND_DATA_OFFSET);
  243. + else
  244. + return (pcie->base + offset);
  245. }
  246. - if (fn > 1)
  247. - return NULL;
  248. -
  249. /* EP device access */
  250. val = (busno << CFG_ADDR_BUS_NUM_SHIFT) |
  251. (slot << CFG_ADDR_DEV_NUM_SHIFT) |
  252. (fn << CFG_ADDR_FUNC_NUM_SHIFT) |
  253. (where & CFG_ADDR_REG_NUM_MASK) |
  254. (1 & CFG_ADDR_CFG_TYPE_MASK);
  255. - writel(val, pcie->base + CFG_ADDR_OFFSET);
  256. -
  257. - return (pcie->base + CFG_DATA_OFFSET);
  258. + iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_ADDR, val);
  259. + offset = iproc_pcie_reg_offset(pcie, IPROC_PCIE_CFG_DATA);
  260. + if (iproc_pcie_reg_is_invalid(offset))
  261. + return NULL;
  262. + else
  263. + return (pcie->base + offset);
  264. }
  265. static struct pci_ops iproc_pcie_ops = {
  266. @@ -138,18 +237,29 @@ static void iproc_pcie_reset(struct ipro
  267. {
  268. u32 val;
  269. + if (pcie->type == IPROC_PCIE_PAXC) {
  270. + val = iproc_pcie_read_reg(pcie, IPROC_PCIE_CLK_CTRL);
  271. + val &= ~PAXC_RESET_MASK;
  272. + iproc_pcie_write_reg(pcie, IPROC_PCIE_CLK_CTRL, val);
  273. + udelay(100);
  274. + val |= PAXC_RESET_MASK;
  275. + iproc_pcie_write_reg(pcie, IPROC_PCIE_CLK_CTRL, val);
  276. + udelay(100);
  277. + return;
  278. + }
  279. +
  280. /*
  281. * Select perst_b signal as reset source. Put the device into reset,
  282. * and then bring it out of reset
  283. */
  284. - val = readl(pcie->base + CLK_CONTROL_OFFSET);
  285. + val = iproc_pcie_read_reg(pcie, IPROC_PCIE_CLK_CTRL);
  286. val &= ~EP_PERST_SOURCE_SELECT & ~EP_MODE_SURVIVE_PERST &
  287. ~RC_PCIE_RST_OUTPUT;
  288. - writel(val, pcie->base + CLK_CONTROL_OFFSET);
  289. + iproc_pcie_write_reg(pcie, IPROC_PCIE_CLK_CTRL, val);
  290. udelay(250);
  291. val |= RC_PCIE_RST_OUTPUT;
  292. - writel(val, pcie->base + CLK_CONTROL_OFFSET);
  293. + iproc_pcie_write_reg(pcie, IPROC_PCIE_CLK_CTRL, val);
  294. msleep(100);
  295. }
  296. @@ -160,7 +270,14 @@ static int iproc_pcie_check_link(struct
  297. u16 pos, link_status;
  298. bool link_is_active = false;
  299. - val = readl(pcie->base + PCIE_LINK_STATUS_OFFSET);
  300. + /*
  301. + * PAXC connects to emulated endpoint devices directly and does not
  302. + * have a Serdes. Therefore skip the link detection logic here.
  303. + */
  304. + if (pcie->type == IPROC_PCIE_PAXC)
  305. + return 0;
  306. +
  307. + val = iproc_pcie_read_reg(pcie, IPROC_PCIE_LINK_STATUS);
  308. if (!(val & PCIE_PHYLINKUP) || !(val & PCIE_DL_ACTIVE)) {
  309. dev_err(pcie->dev, "PHY or data link is INACTIVE!\n");
  310. return -ENODEV;
  311. @@ -221,7 +338,7 @@ static int iproc_pcie_check_link(struct
  312. static void iproc_pcie_enable(struct iproc_pcie *pcie)
  313. {
  314. - writel(SYS_RC_INTX_MASK, pcie->base + SYS_RC_INTX_EN);
  315. + iproc_pcie_write_reg(pcie, IPROC_PCIE_INTX_EN, SYS_RC_INTX_MASK);
  316. }
  317. /**
  318. @@ -272,11 +389,15 @@ static int iproc_pcie_setup_ob(struct ip
  319. axi_addr -= ob->axi_offset;
  320. for (i = 0; i < MAX_NUM_OB_WINDOWS; i++) {
  321. - writel(lower_32_bits(axi_addr) | OARR_VALID |
  322. - (ob->set_oarr_size ? 1 : 0), pcie->base + OARR_LO(i));
  323. - writel(upper_32_bits(axi_addr), pcie->base + OARR_HI(i));
  324. - writel(lower_32_bits(pci_addr), pcie->base + OMAP_LO(i));
  325. - writel(upper_32_bits(pci_addr), pcie->base + OMAP_HI(i));
  326. + iproc_pcie_ob_write(pcie, IPROC_PCIE_OARR_LO, i,
  327. + lower_32_bits(axi_addr) | OARR_VALID |
  328. + (ob->set_oarr_size ? 1 : 0));
  329. + iproc_pcie_ob_write(pcie, IPROC_PCIE_OARR_HI, i,
  330. + upper_32_bits(axi_addr));
  331. + iproc_pcie_ob_write(pcie, IPROC_PCIE_OMAP_LO, i,
  332. + lower_32_bits(pci_addr));
  333. + iproc_pcie_ob_write(pcie, IPROC_PCIE_OMAP_HI, i,
  334. + upper_32_bits(pci_addr));
  335. size -= ob->window_size;
  336. if (size == 0)
  337. @@ -340,6 +461,19 @@ int iproc_pcie_setup(struct iproc_pcie *
  338. goto err_exit_phy;
  339. }
  340. + switch (pcie->type) {
  341. + case IPROC_PCIE_PAXB:
  342. + pcie->reg_offsets = iproc_pcie_reg_paxb;
  343. + break;
  344. + case IPROC_PCIE_PAXC:
  345. + pcie->reg_offsets = iproc_pcie_reg_paxc;
  346. + break;
  347. + default:
  348. + dev_err(pcie->dev, "incompatible iProc PCIe interface\n");
  349. + ret = -EINVAL;
  350. + goto err_power_off_phy;
  351. + }
  352. +
  353. iproc_pcie_reset(pcie);
  354. if (pcie->need_ob_cfg) {
  355. --- a/drivers/pci/host/pcie-iproc.h
  356. +++ b/drivers/pci/host/pcie-iproc.h
  357. @@ -15,6 +15,20 @@
  358. #define _PCIE_IPROC_H
  359. /**
  360. + * iProc PCIe interface type
  361. + *
  362. + * PAXB is the wrapper used in root complex that can be connected to an
  363. + * external endpoint device.
  364. + *
  365. + * PAXC is the wrapper used in root complex dedicated for internal emulated
  366. + * endpoint devices.
  367. + */
  368. +enum iproc_pcie_type {
  369. + IPROC_PCIE_PAXB = 0,
  370. + IPROC_PCIE_PAXC,
  371. +};
  372. +
  373. +/**
  374. * iProc PCIe outbound mapping
  375. * @set_oarr_size: indicates the OARR size bit needs to be set
  376. * @axi_offset: offset from the AXI address to the internal address used by
  377. @@ -29,7 +43,10 @@ struct iproc_pcie_ob {
  378. /**
  379. * iProc PCIe device
  380. + *
  381. * @dev: pointer to device data structure
  382. + * @type: iProc PCIe interface type
  383. + * @reg_offsets: register offsets
  384. * @base: PCIe host controller I/O register base
  385. * @sysdata: Per PCI controller data (ARM-specific)
  386. * @root_bus: pointer to root bus
  387. @@ -41,6 +58,8 @@ struct iproc_pcie_ob {
  388. */
  389. struct iproc_pcie {
  390. struct device *dev;
  391. + enum iproc_pcie_type type;
  392. + const u16 *reg_offsets;
  393. void __iomem *base;
  394. #ifdef CONFIG_ARM
  395. struct pci_sys_data sysdata;