fsl_rio.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * Freescale MPC85xx/MPC86xx RapidIO support
  3. *
  4. * Copyright 2009 Sysgo AG
  5. * Thomas Moll <thomas.moll@sysgo.com>
  6. * - fixed maintenance access routines, check for aligned access
  7. *
  8. * Copyright 2009 Integrated Device Technology, Inc.
  9. * Alex Bounine <alexandre.bounine@idt.com>
  10. * - Added Port-Write message handling
  11. * - Added Machine Check exception handling
  12. *
  13. * Copyright (C) 2007, 2008, 2010, 2011 Freescale Semiconductor, Inc.
  14. * Zhang Wei <wei.zhang@freescale.com>
  15. *
  16. * Copyright 2005 MontaVista Software, Inc.
  17. * Matt Porter <mporter@kernel.crashing.org>
  18. *
  19. * This program is free software; you can redistribute it and/or modify it
  20. * under the terms of the GNU General Public License as published by the
  21. * Free Software Foundation; either version 2 of the License, or (at your
  22. * option) any later version.
  23. */
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <linux/dma-mapping.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/device.h>
  30. #include <linux/of_address.h>
  31. #include <linux/of_irq.h>
  32. #include <linux/of_platform.h>
  33. #include <linux/delay.h>
  34. #include <linux/slab.h>
  35. #include <linux/io.h>
  36. #include <linux/uaccess.h>
  37. #include <asm/machdep.h>
  38. #include "fsl_rio.h"
  39. #undef DEBUG_PW /* Port-Write debugging */
  40. #define RIO_PORT1_EDCSR 0x0640
  41. #define RIO_PORT2_EDCSR 0x0680
  42. #define RIO_PORT1_IECSR 0x10130
  43. #define RIO_PORT2_IECSR 0x101B0
  44. #define RIO_GCCSR 0x13c
  45. #define RIO_ESCSR 0x158
  46. #define ESCSR_CLEAR 0x07120204
  47. #define RIO_PORT2_ESCSR 0x178
  48. #define RIO_CCSR 0x15c
  49. #define RIO_LTLEDCSR_IER 0x80000000
  50. #define RIO_LTLEDCSR_PRT 0x01000000
  51. #define IECSR_CLEAR 0x80000000
  52. #define RIO_ISR_AACR 0x10120
  53. #define RIO_ISR_AACR_AA 0x1 /* Accept All ID */
  54. #define __fsl_read_rio_config(x, addr, err, op) \
  55. __asm__ __volatile__( \
  56. "1: "op" %1,0(%2)\n" \
  57. " eieio\n" \
  58. "2:\n" \
  59. ".section .fixup,\"ax\"\n" \
  60. "3: li %1,-1\n" \
  61. " li %0,%3\n" \
  62. " b 2b\n" \
  63. ".section __ex_table,\"a\"\n" \
  64. PPC_LONG_ALIGN "\n" \
  65. PPC_LONG "1b,3b\n" \
  66. ".text" \
  67. : "=r" (err), "=r" (x) \
  68. : "b" (addr), "i" (-EFAULT), "0" (err))
  69. void __iomem *rio_regs_win;
  70. void __iomem *rmu_regs_win;
  71. resource_size_t rio_law_start;
  72. struct fsl_rio_dbell *dbell;
  73. struct fsl_rio_pw *pw;
  74. #ifdef CONFIG_E500
  75. int fsl_rio_mcheck_exception(struct pt_regs *regs)
  76. {
  77. const struct exception_table_entry *entry;
  78. unsigned long reason;
  79. if (!rio_regs_win)
  80. return 0;
  81. reason = in_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR));
  82. if (reason & (RIO_LTLEDCSR_IER | RIO_LTLEDCSR_PRT)) {
  83. /* Check if we are prepared to handle this fault */
  84. entry = search_exception_tables(regs->nip);
  85. if (entry) {
  86. pr_debug("RIO: %s - MC Exception handled\n",
  87. __func__);
  88. out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR),
  89. 0);
  90. regs->msr |= MSR_RI;
  91. regs->nip = entry->fixup;
  92. return 1;
  93. }
  94. }
  95. return 0;
  96. }
  97. EXPORT_SYMBOL_GPL(fsl_rio_mcheck_exception);
  98. #endif
  99. /**
  100. * fsl_local_config_read - Generate a MPC85xx local config space read
  101. * @mport: RapidIO master port info
  102. * @index: ID of RapdiIO interface
  103. * @offset: Offset into configuration space
  104. * @len: Length (in bytes) of the maintenance transaction
  105. * @data: Value to be read into
  106. *
  107. * Generates a MPC85xx local configuration space read. Returns %0 on
  108. * success or %-EINVAL on failure.
  109. */
  110. static int fsl_local_config_read(struct rio_mport *mport,
  111. int index, u32 offset, int len, u32 *data)
  112. {
  113. struct rio_priv *priv = mport->priv;
  114. pr_debug("fsl_local_config_read: index %d offset %8.8x\n", index,
  115. offset);
  116. *data = in_be32(priv->regs_win + offset);
  117. return 0;
  118. }
  119. /**
  120. * fsl_local_config_write - Generate a MPC85xx local config space write
  121. * @mport: RapidIO master port info
  122. * @index: ID of RapdiIO interface
  123. * @offset: Offset into configuration space
  124. * @len: Length (in bytes) of the maintenance transaction
  125. * @data: Value to be written
  126. *
  127. * Generates a MPC85xx local configuration space write. Returns %0 on
  128. * success or %-EINVAL on failure.
  129. */
  130. static int fsl_local_config_write(struct rio_mport *mport,
  131. int index, u32 offset, int len, u32 data)
  132. {
  133. struct rio_priv *priv = mport->priv;
  134. pr_debug
  135. ("fsl_local_config_write: index %d offset %8.8x data %8.8x\n",
  136. index, offset, data);
  137. out_be32(priv->regs_win + offset, data);
  138. return 0;
  139. }
  140. /**
  141. * fsl_rio_config_read - Generate a MPC85xx read maintenance transaction
  142. * @mport: RapidIO master port info
  143. * @index: ID of RapdiIO interface
  144. * @destid: Destination ID of transaction
  145. * @hopcount: Number of hops to target device
  146. * @offset: Offset into configuration space
  147. * @len: Length (in bytes) of the maintenance transaction
  148. * @val: Location to be read into
  149. *
  150. * Generates a MPC85xx read maintenance transaction. Returns %0 on
  151. * success or %-EINVAL on failure.
  152. */
  153. static int
  154. fsl_rio_config_read(struct rio_mport *mport, int index, u16 destid,
  155. u8 hopcount, u32 offset, int len, u32 *val)
  156. {
  157. struct rio_priv *priv = mport->priv;
  158. u8 *data;
  159. u32 rval, err = 0;
  160. pr_debug
  161. ("fsl_rio_config_read:"
  162. " index %d destid %d hopcount %d offset %8.8x len %d\n",
  163. index, destid, hopcount, offset, len);
  164. /* 16MB maintenance window possible */
  165. /* allow only aligned access to maintenance registers */
  166. if (offset > (0x1000000 - len) || !IS_ALIGNED(offset, len))
  167. return -EINVAL;
  168. out_be32(&priv->maint_atmu_regs->rowtar,
  169. (destid << 22) | (hopcount << 12) | (offset >> 12));
  170. out_be32(&priv->maint_atmu_regs->rowtear, (destid >> 10));
  171. data = (u8 *) priv->maint_win + (offset & (RIO_MAINT_WIN_SIZE - 1));
  172. switch (len) {
  173. case 1:
  174. __fsl_read_rio_config(rval, data, err, "lbz");
  175. break;
  176. case 2:
  177. __fsl_read_rio_config(rval, data, err, "lhz");
  178. break;
  179. case 4:
  180. __fsl_read_rio_config(rval, data, err, "lwz");
  181. break;
  182. default:
  183. return -EINVAL;
  184. }
  185. if (err) {
  186. pr_debug("RIO: cfg_read error %d for %x:%x:%x\n",
  187. err, destid, hopcount, offset);
  188. }
  189. *val = rval;
  190. return err;
  191. }
  192. /**
  193. * fsl_rio_config_write - Generate a MPC85xx write maintenance transaction
  194. * @mport: RapidIO master port info
  195. * @index: ID of RapdiIO interface
  196. * @destid: Destination ID of transaction
  197. * @hopcount: Number of hops to target device
  198. * @offset: Offset into configuration space
  199. * @len: Length (in bytes) of the maintenance transaction
  200. * @val: Value to be written
  201. *
  202. * Generates an MPC85xx write maintenance transaction. Returns %0 on
  203. * success or %-EINVAL on failure.
  204. */
  205. static int
  206. fsl_rio_config_write(struct rio_mport *mport, int index, u16 destid,
  207. u8 hopcount, u32 offset, int len, u32 val)
  208. {
  209. struct rio_priv *priv = mport->priv;
  210. u8 *data;
  211. pr_debug
  212. ("fsl_rio_config_write:"
  213. " index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
  214. index, destid, hopcount, offset, len, val);
  215. /* 16MB maintenance windows possible */
  216. /* allow only aligned access to maintenance registers */
  217. if (offset > (0x1000000 - len) || !IS_ALIGNED(offset, len))
  218. return -EINVAL;
  219. out_be32(&priv->maint_atmu_regs->rowtar,
  220. (destid << 22) | (hopcount << 12) | (offset >> 12));
  221. out_be32(&priv->maint_atmu_regs->rowtear, (destid >> 10));
  222. data = (u8 *) priv->maint_win + (offset & (RIO_MAINT_WIN_SIZE - 1));
  223. switch (len) {
  224. case 1:
  225. out_8((u8 *) data, val);
  226. break;
  227. case 2:
  228. out_be16((u16 *) data, val);
  229. break;
  230. case 4:
  231. out_be32((u32 *) data, val);
  232. break;
  233. default:
  234. return -EINVAL;
  235. }
  236. return 0;
  237. }
  238. void fsl_rio_port_error_handler(int offset)
  239. {
  240. /*XXX: Error recovery is not implemented, we just clear errors */
  241. out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR), 0);
  242. if (offset == 0) {
  243. out_be32((u32 *)(rio_regs_win + RIO_PORT1_EDCSR), 0);
  244. out_be32((u32 *)(rio_regs_win + RIO_PORT1_IECSR), IECSR_CLEAR);
  245. out_be32((u32 *)(rio_regs_win + RIO_ESCSR), ESCSR_CLEAR);
  246. } else {
  247. out_be32((u32 *)(rio_regs_win + RIO_PORT2_EDCSR), 0);
  248. out_be32((u32 *)(rio_regs_win + RIO_PORT2_IECSR), IECSR_CLEAR);
  249. out_be32((u32 *)(rio_regs_win + RIO_PORT2_ESCSR), ESCSR_CLEAR);
  250. }
  251. }
  252. static inline void fsl_rio_info(struct device *dev, u32 ccsr)
  253. {
  254. const char *str;
  255. if (ccsr & 1) {
  256. /* Serial phy */
  257. switch (ccsr >> 30) {
  258. case 0:
  259. str = "1";
  260. break;
  261. case 1:
  262. str = "4";
  263. break;
  264. default:
  265. str = "Unknown";
  266. break;
  267. }
  268. dev_info(dev, "Hardware port width: %s\n", str);
  269. switch ((ccsr >> 27) & 7) {
  270. case 0:
  271. str = "Single-lane 0";
  272. break;
  273. case 1:
  274. str = "Single-lane 2";
  275. break;
  276. case 2:
  277. str = "Four-lane";
  278. break;
  279. default:
  280. str = "Unknown";
  281. break;
  282. }
  283. dev_info(dev, "Training connection status: %s\n", str);
  284. } else {
  285. /* Parallel phy */
  286. if (!(ccsr & 0x80000000))
  287. dev_info(dev, "Output port operating in 8-bit mode\n");
  288. if (!(ccsr & 0x08000000))
  289. dev_info(dev, "Input port operating in 8-bit mode\n");
  290. }
  291. }
  292. /**
  293. * fsl_rio_setup - Setup Freescale PowerPC RapidIO interface
  294. * @dev: platform_device pointer
  295. *
  296. * Initializes MPC85xx RapidIO hardware interface, configures
  297. * master port with system-specific info, and registers the
  298. * master port with the RapidIO subsystem.
  299. */
  300. int fsl_rio_setup(struct platform_device *dev)
  301. {
  302. struct rio_ops *ops;
  303. struct rio_mport *port;
  304. struct rio_priv *priv;
  305. int rc = 0;
  306. const u32 *dt_range, *cell, *port_index;
  307. u32 active_ports = 0;
  308. struct resource regs, rmu_regs;
  309. struct device_node *np, *rmu_node;
  310. int rlen;
  311. u32 ccsr;
  312. u64 range_start, range_size;
  313. int paw, aw, sw;
  314. u32 i;
  315. static int tmp;
  316. struct device_node *rmu_np[MAX_MSG_UNIT_NUM] = {NULL};
  317. if (!dev->dev.of_node) {
  318. dev_err(&dev->dev, "Device OF-Node is NULL");
  319. return -ENODEV;
  320. }
  321. rc = of_address_to_resource(dev->dev.of_node, 0, &regs);
  322. if (rc) {
  323. dev_err(&dev->dev, "Can't get %s property 'reg'\n",
  324. dev->dev.of_node->full_name);
  325. return -EFAULT;
  326. }
  327. dev_info(&dev->dev, "Of-device full name %s\n",
  328. dev->dev.of_node->full_name);
  329. dev_info(&dev->dev, "Regs: %pR\n", &regs);
  330. rio_regs_win = ioremap(regs.start, resource_size(&regs));
  331. if (!rio_regs_win) {
  332. dev_err(&dev->dev, "Unable to map rio register window\n");
  333. rc = -ENOMEM;
  334. goto err_rio_regs;
  335. }
  336. ops = kzalloc(sizeof(struct rio_ops), GFP_KERNEL);
  337. if (!ops) {
  338. rc = -ENOMEM;
  339. goto err_ops;
  340. }
  341. ops->lcread = fsl_local_config_read;
  342. ops->lcwrite = fsl_local_config_write;
  343. ops->cread = fsl_rio_config_read;
  344. ops->cwrite = fsl_rio_config_write;
  345. ops->dsend = fsl_rio_doorbell_send;
  346. ops->pwenable = fsl_rio_pw_enable;
  347. ops->open_outb_mbox = fsl_open_outb_mbox;
  348. ops->open_inb_mbox = fsl_open_inb_mbox;
  349. ops->close_outb_mbox = fsl_close_outb_mbox;
  350. ops->close_inb_mbox = fsl_close_inb_mbox;
  351. ops->add_outb_message = fsl_add_outb_message;
  352. ops->add_inb_buffer = fsl_add_inb_buffer;
  353. ops->get_inb_message = fsl_get_inb_message;
  354. rmu_node = of_parse_phandle(dev->dev.of_node, "fsl,srio-rmu-handle", 0);
  355. if (!rmu_node) {
  356. dev_err(&dev->dev, "No valid fsl,srio-rmu-handle property\n");
  357. goto err_rmu;
  358. }
  359. rc = of_address_to_resource(rmu_node, 0, &rmu_regs);
  360. if (rc) {
  361. dev_err(&dev->dev, "Can't get %s property 'reg'\n",
  362. rmu_node->full_name);
  363. goto err_rmu;
  364. }
  365. rmu_regs_win = ioremap(rmu_regs.start, resource_size(&rmu_regs));
  366. if (!rmu_regs_win) {
  367. dev_err(&dev->dev, "Unable to map rmu register window\n");
  368. rc = -ENOMEM;
  369. goto err_rmu;
  370. }
  371. for_each_compatible_node(np, NULL, "fsl,srio-msg-unit") {
  372. rmu_np[tmp] = np;
  373. tmp++;
  374. }
  375. /*set up doobell node*/
  376. np = of_find_compatible_node(NULL, NULL, "fsl,srio-dbell-unit");
  377. if (!np) {
  378. dev_err(&dev->dev, "No fsl,srio-dbell-unit node\n");
  379. rc = -ENODEV;
  380. goto err_dbell;
  381. }
  382. dbell = kzalloc(sizeof(struct fsl_rio_dbell), GFP_KERNEL);
  383. if (!(dbell)) {
  384. dev_err(&dev->dev, "Can't alloc memory for 'fsl_rio_dbell'\n");
  385. rc = -ENOMEM;
  386. goto err_dbell;
  387. }
  388. dbell->dev = &dev->dev;
  389. dbell->bellirq = irq_of_parse_and_map(np, 1);
  390. dev_info(&dev->dev, "bellirq: %d\n", dbell->bellirq);
  391. aw = of_n_addr_cells(np);
  392. dt_range = of_get_property(np, "reg", &rlen);
  393. if (!dt_range) {
  394. pr_err("%s: unable to find 'reg' property\n",
  395. np->full_name);
  396. rc = -ENOMEM;
  397. goto err_pw;
  398. }
  399. range_start = of_read_number(dt_range, aw);
  400. dbell->dbell_regs = (struct rio_dbell_regs *)(rmu_regs_win +
  401. (u32)range_start);
  402. /*set up port write node*/
  403. np = of_find_compatible_node(NULL, NULL, "fsl,srio-port-write-unit");
  404. if (!np) {
  405. dev_err(&dev->dev, "No fsl,srio-port-write-unit node\n");
  406. rc = -ENODEV;
  407. goto err_pw;
  408. }
  409. pw = kzalloc(sizeof(struct fsl_rio_pw), GFP_KERNEL);
  410. if (!(pw)) {
  411. dev_err(&dev->dev, "Can't alloc memory for 'fsl_rio_pw'\n");
  412. rc = -ENOMEM;
  413. goto err_pw;
  414. }
  415. pw->dev = &dev->dev;
  416. pw->pwirq = irq_of_parse_and_map(np, 0);
  417. dev_info(&dev->dev, "pwirq: %d\n", pw->pwirq);
  418. aw = of_n_addr_cells(np);
  419. dt_range = of_get_property(np, "reg", &rlen);
  420. if (!dt_range) {
  421. pr_err("%s: unable to find 'reg' property\n",
  422. np->full_name);
  423. rc = -ENOMEM;
  424. goto err;
  425. }
  426. range_start = of_read_number(dt_range, aw);
  427. pw->pw_regs = (struct rio_pw_regs *)(rmu_regs_win + (u32)range_start);
  428. /*set up ports node*/
  429. for_each_child_of_node(dev->dev.of_node, np) {
  430. port_index = of_get_property(np, "cell-index", NULL);
  431. if (!port_index) {
  432. dev_err(&dev->dev, "Can't get %s property 'cell-index'\n",
  433. np->full_name);
  434. continue;
  435. }
  436. dt_range = of_get_property(np, "ranges", &rlen);
  437. if (!dt_range) {
  438. dev_err(&dev->dev, "Can't get %s property 'ranges'\n",
  439. np->full_name);
  440. continue;
  441. }
  442. /* Get node address wide */
  443. cell = of_get_property(np, "#address-cells", NULL);
  444. if (cell)
  445. aw = *cell;
  446. else
  447. aw = of_n_addr_cells(np);
  448. /* Get node size wide */
  449. cell = of_get_property(np, "#size-cells", NULL);
  450. if (cell)
  451. sw = *cell;
  452. else
  453. sw = of_n_size_cells(np);
  454. /* Get parent address wide wide */
  455. paw = of_n_addr_cells(np);
  456. range_start = of_read_number(dt_range + aw, paw);
  457. range_size = of_read_number(dt_range + aw + paw, sw);
  458. dev_info(&dev->dev, "%s: LAW start 0x%016llx, size 0x%016llx.\n",
  459. np->full_name, range_start, range_size);
  460. port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL);
  461. if (!port)
  462. continue;
  463. i = *port_index - 1;
  464. port->index = (unsigned char)i;
  465. priv = kzalloc(sizeof(struct rio_priv), GFP_KERNEL);
  466. if (!priv) {
  467. dev_err(&dev->dev, "Can't alloc memory for 'priv'\n");
  468. kfree(port);
  469. continue;
  470. }
  471. INIT_LIST_HEAD(&port->dbells);
  472. port->iores.start = range_start;
  473. port->iores.end = port->iores.start + range_size - 1;
  474. port->iores.flags = IORESOURCE_MEM;
  475. port->iores.name = "rio_io_win";
  476. if (request_resource(&iomem_resource, &port->iores) < 0) {
  477. dev_err(&dev->dev, "RIO: Error requesting master port region"
  478. " 0x%016llx-0x%016llx\n",
  479. (u64)port->iores.start, (u64)port->iores.end);
  480. kfree(priv);
  481. kfree(port);
  482. continue;
  483. }
  484. sprintf(port->name, "RIO mport %d", i);
  485. priv->dev = &dev->dev;
  486. port->dev.parent = &dev->dev;
  487. port->ops = ops;
  488. port->priv = priv;
  489. port->phys_efptr = 0x100;
  490. priv->regs_win = rio_regs_win;
  491. /* Probe the master port phy type */
  492. ccsr = in_be32(priv->regs_win + RIO_CCSR + i*0x20);
  493. port->phy_type = (ccsr & 1) ? RIO_PHY_SERIAL : RIO_PHY_PARALLEL;
  494. if (port->phy_type == RIO_PHY_PARALLEL) {
  495. dev_err(&dev->dev, "RIO: Parallel PHY type, unsupported port type!\n");
  496. release_resource(&port->iores);
  497. kfree(priv);
  498. kfree(port);
  499. continue;
  500. }
  501. dev_info(&dev->dev, "RapidIO PHY type: Serial\n");
  502. /* Checking the port training status */
  503. if (in_be32((priv->regs_win + RIO_ESCSR + i*0x20)) & 1) {
  504. dev_err(&dev->dev, "Port %d is not ready. "
  505. "Try to restart connection...\n", i);
  506. /* Disable ports */
  507. out_be32(priv->regs_win
  508. + RIO_CCSR + i*0x20, 0);
  509. /* Set 1x lane */
  510. setbits32(priv->regs_win
  511. + RIO_CCSR + i*0x20, 0x02000000);
  512. /* Enable ports */
  513. setbits32(priv->regs_win
  514. + RIO_CCSR + i*0x20, 0x00600000);
  515. msleep(100);
  516. if (in_be32((priv->regs_win
  517. + RIO_ESCSR + i*0x20)) & 1) {
  518. dev_err(&dev->dev,
  519. "Port %d restart failed.\n", i);
  520. release_resource(&port->iores);
  521. kfree(priv);
  522. kfree(port);
  523. continue;
  524. }
  525. dev_info(&dev->dev, "Port %d restart success!\n", i);
  526. }
  527. fsl_rio_info(&dev->dev, ccsr);
  528. port->sys_size = (in_be32((priv->regs_win + RIO_PEF_CAR))
  529. & RIO_PEF_CTLS) >> 4;
  530. dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n",
  531. port->sys_size ? 65536 : 256);
  532. if (rio_register_mport(port)) {
  533. release_resource(&port->iores);
  534. kfree(priv);
  535. kfree(port);
  536. continue;
  537. }
  538. if (port->host_deviceid >= 0)
  539. out_be32(priv->regs_win + RIO_GCCSR, RIO_PORT_GEN_HOST |
  540. RIO_PORT_GEN_MASTER | RIO_PORT_GEN_DISCOVERED);
  541. else
  542. out_be32(priv->regs_win + RIO_GCCSR,
  543. RIO_PORT_GEN_MASTER);
  544. priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win
  545. + ((i == 0) ? RIO_ATMU_REGS_PORT1_OFFSET :
  546. RIO_ATMU_REGS_PORT2_OFFSET));
  547. priv->maint_atmu_regs = priv->atmu_regs + 1;
  548. /* Set to receive any dist ID for serial RapidIO controller. */
  549. if (port->phy_type == RIO_PHY_SERIAL)
  550. out_be32((priv->regs_win
  551. + RIO_ISR_AACR + i*0x80), RIO_ISR_AACR_AA);
  552. /* Configure maintenance transaction window */
  553. out_be32(&priv->maint_atmu_regs->rowbar,
  554. port->iores.start >> 12);
  555. out_be32(&priv->maint_atmu_regs->rowar,
  556. 0x80077000 | (ilog2(RIO_MAINT_WIN_SIZE) - 1));
  557. priv->maint_win = ioremap(port->iores.start,
  558. RIO_MAINT_WIN_SIZE);
  559. rio_law_start = range_start;
  560. fsl_rio_setup_rmu(port, rmu_np[i]);
  561. dbell->mport[i] = port;
  562. active_ports++;
  563. }
  564. if (!active_ports) {
  565. rc = -ENOLINK;
  566. goto err;
  567. }
  568. fsl_rio_doorbell_init(dbell);
  569. fsl_rio_port_write_init(pw);
  570. return 0;
  571. err:
  572. kfree(pw);
  573. pw = NULL;
  574. err_pw:
  575. kfree(dbell);
  576. dbell = NULL;
  577. err_dbell:
  578. iounmap(rmu_regs_win);
  579. rmu_regs_win = NULL;
  580. err_rmu:
  581. kfree(ops);
  582. err_ops:
  583. iounmap(rio_regs_win);
  584. rio_regs_win = NULL;
  585. err_rio_regs:
  586. return rc;
  587. }
  588. /* The probe function for RapidIO peer-to-peer network.
  589. */
  590. static int fsl_of_rio_rpn_probe(struct platform_device *dev)
  591. {
  592. printk(KERN_INFO "Setting up RapidIO peer-to-peer network %s\n",
  593. dev->dev.of_node->full_name);
  594. return fsl_rio_setup(dev);
  595. };
  596. static const struct of_device_id fsl_of_rio_rpn_ids[] = {
  597. {
  598. .compatible = "fsl,srio",
  599. },
  600. {},
  601. };
  602. static struct platform_driver fsl_of_rio_rpn_driver = {
  603. .driver = {
  604. .name = "fsl-of-rio",
  605. .owner = THIS_MODULE,
  606. .of_match_table = fsl_of_rio_rpn_ids,
  607. },
  608. .probe = fsl_of_rio_rpn_probe,
  609. };
  610. static __init int fsl_of_rio_rpn_init(void)
  611. {
  612. return platform_driver_register(&fsl_of_rio_rpn_driver);
  613. }
  614. subsys_initcall(fsl_of_rio_rpn_init);