fsl_rio.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. /*
  2. * Freescale MPC85xx/MPC86xx RapidIO support
  3. *
  4. * Copyright (C) 2007, 2008 Freescale Semiconductor, Inc.
  5. * Zhang Wei <wei.zhang@freescale.com>
  6. *
  7. * Copyright 2005 MontaVista Software, Inc.
  8. * Matt Porter <mporter@kernel.crashing.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/types.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/device.h>
  21. #include <linux/rio.h>
  22. #include <linux/rio_drv.h>
  23. #include <linux/of_platform.h>
  24. #include <linux/delay.h>
  25. #include <linux/slab.h>
  26. #include <asm/io.h>
  27. /* RapidIO definition irq, which read from OF-tree */
  28. #define IRQ_RIO_BELL(m) (((struct rio_priv *)(m->priv))->bellirq)
  29. #define IRQ_RIO_TX(m) (((struct rio_priv *)(m->priv))->txirq)
  30. #define IRQ_RIO_RX(m) (((struct rio_priv *)(m->priv))->rxirq)
  31. #define RIO_ATMU_REGS_OFFSET 0x10c00
  32. #define RIO_P_MSG_REGS_OFFSET 0x11000
  33. #define RIO_S_MSG_REGS_OFFSET 0x13000
  34. #define RIO_ESCSR 0x158
  35. #define RIO_CCSR 0x15c
  36. #define RIO_ISR_AACR 0x10120
  37. #define RIO_ISR_AACR_AA 0x1 /* Accept All ID */
  38. #define RIO_MAINT_WIN_SIZE 0x400000
  39. #define RIO_DBELL_WIN_SIZE 0x1000
  40. #define RIO_MSG_OMR_MUI 0x00000002
  41. #define RIO_MSG_OSR_TE 0x00000080
  42. #define RIO_MSG_OSR_QOI 0x00000020
  43. #define RIO_MSG_OSR_QFI 0x00000010
  44. #define RIO_MSG_OSR_MUB 0x00000004
  45. #define RIO_MSG_OSR_EOMI 0x00000002
  46. #define RIO_MSG_OSR_QEI 0x00000001
  47. #define RIO_MSG_IMR_MI 0x00000002
  48. #define RIO_MSG_ISR_TE 0x00000080
  49. #define RIO_MSG_ISR_QFI 0x00000010
  50. #define RIO_MSG_ISR_DIQI 0x00000001
  51. #define RIO_MSG_DESC_SIZE 32
  52. #define RIO_MSG_BUFFER_SIZE 4096
  53. #define RIO_MIN_TX_RING_SIZE 2
  54. #define RIO_MAX_TX_RING_SIZE 2048
  55. #define RIO_MIN_RX_RING_SIZE 2
  56. #define RIO_MAX_RX_RING_SIZE 2048
  57. #define DOORBELL_DMR_DI 0x00000002
  58. #define DOORBELL_DSR_TE 0x00000080
  59. #define DOORBELL_DSR_QFI 0x00000010
  60. #define DOORBELL_DSR_DIQI 0x00000001
  61. #define DOORBELL_TID_OFFSET 0x02
  62. #define DOORBELL_SID_OFFSET 0x04
  63. #define DOORBELL_INFO_OFFSET 0x06
  64. #define DOORBELL_MESSAGE_SIZE 0x08
  65. #define DBELL_SID(x) (*(u16 *)(x + DOORBELL_SID_OFFSET))
  66. #define DBELL_TID(x) (*(u16 *)(x + DOORBELL_TID_OFFSET))
  67. #define DBELL_INF(x) (*(u16 *)(x + DOORBELL_INFO_OFFSET))
  68. struct rio_atmu_regs {
  69. u32 rowtar;
  70. u32 rowtear;
  71. u32 rowbar;
  72. u32 pad2;
  73. u32 rowar;
  74. u32 pad3[3];
  75. };
  76. struct rio_msg_regs {
  77. u32 omr;
  78. u32 osr;
  79. u32 pad1;
  80. u32 odqdpar;
  81. u32 pad2;
  82. u32 osar;
  83. u32 odpr;
  84. u32 odatr;
  85. u32 odcr;
  86. u32 pad3;
  87. u32 odqepar;
  88. u32 pad4[13];
  89. u32 imr;
  90. u32 isr;
  91. u32 pad5;
  92. u32 ifqdpar;
  93. u32 pad6;
  94. u32 ifqepar;
  95. u32 pad7[226];
  96. u32 odmr;
  97. u32 odsr;
  98. u32 res0[4];
  99. u32 oddpr;
  100. u32 oddatr;
  101. u32 res1[3];
  102. u32 odretcr;
  103. u32 res2[12];
  104. u32 dmr;
  105. u32 dsr;
  106. u32 pad8;
  107. u32 dqdpar;
  108. u32 pad9;
  109. u32 dqepar;
  110. u32 pad10[26];
  111. u32 pwmr;
  112. u32 pwsr;
  113. u32 pad11;
  114. u32 pwqbar;
  115. };
  116. struct rio_tx_desc {
  117. u32 res1;
  118. u32 saddr;
  119. u32 dport;
  120. u32 dattr;
  121. u32 res2;
  122. u32 res3;
  123. u32 dwcnt;
  124. u32 res4;
  125. };
  126. struct rio_dbell_ring {
  127. void *virt;
  128. dma_addr_t phys;
  129. };
  130. struct rio_msg_tx_ring {
  131. void *virt;
  132. dma_addr_t phys;
  133. void *virt_buffer[RIO_MAX_TX_RING_SIZE];
  134. dma_addr_t phys_buffer[RIO_MAX_TX_RING_SIZE];
  135. int tx_slot;
  136. int size;
  137. void *dev_id;
  138. };
  139. struct rio_msg_rx_ring {
  140. void *virt;
  141. dma_addr_t phys;
  142. void *virt_buffer[RIO_MAX_RX_RING_SIZE];
  143. int rx_slot;
  144. int size;
  145. void *dev_id;
  146. };
  147. struct rio_priv {
  148. struct device *dev;
  149. void __iomem *regs_win;
  150. struct rio_atmu_regs __iomem *atmu_regs;
  151. struct rio_atmu_regs __iomem *maint_atmu_regs;
  152. struct rio_atmu_regs __iomem *dbell_atmu_regs;
  153. void __iomem *dbell_win;
  154. void __iomem *maint_win;
  155. struct rio_msg_regs __iomem *msg_regs;
  156. struct rio_dbell_ring dbell_ring;
  157. struct rio_msg_tx_ring msg_tx_ring;
  158. struct rio_msg_rx_ring msg_rx_ring;
  159. int bellirq;
  160. int txirq;
  161. int rxirq;
  162. };
  163. /**
  164. * fsl_rio_doorbell_send - Send a MPC85xx doorbell message
  165. * @mport: RapidIO master port info
  166. * @index: ID of RapidIO interface
  167. * @destid: Destination ID of target device
  168. * @data: 16-bit info field of RapidIO doorbell message
  169. *
  170. * Sends a MPC85xx doorbell message. Returns %0 on success or
  171. * %-EINVAL on failure.
  172. */
  173. static int fsl_rio_doorbell_send(struct rio_mport *mport,
  174. int index, u16 destid, u16 data)
  175. {
  176. struct rio_priv *priv = mport->priv;
  177. pr_debug("fsl_doorbell_send: index %d destid %4.4x data %4.4x\n",
  178. index, destid, data);
  179. switch (mport->phy_type) {
  180. case RIO_PHY_PARALLEL:
  181. out_be32(&priv->dbell_atmu_regs->rowtar, destid << 22);
  182. out_be16(priv->dbell_win, data);
  183. break;
  184. case RIO_PHY_SERIAL:
  185. /* In the serial version silicons, such as MPC8548, MPC8641,
  186. * below operations is must be.
  187. */
  188. out_be32(&priv->msg_regs->odmr, 0x00000000);
  189. out_be32(&priv->msg_regs->odretcr, 0x00000004);
  190. out_be32(&priv->msg_regs->oddpr, destid << 16);
  191. out_be32(&priv->msg_regs->oddatr, data);
  192. out_be32(&priv->msg_regs->odmr, 0x00000001);
  193. break;
  194. }
  195. return 0;
  196. }
  197. /**
  198. * fsl_local_config_read - Generate a MPC85xx local config space read
  199. * @mport: RapidIO master port info
  200. * @index: ID of RapdiIO interface
  201. * @offset: Offset into configuration space
  202. * @len: Length (in bytes) of the maintenance transaction
  203. * @data: Value to be read into
  204. *
  205. * Generates a MPC85xx local configuration space read. Returns %0 on
  206. * success or %-EINVAL on failure.
  207. */
  208. static int fsl_local_config_read(struct rio_mport *mport,
  209. int index, u32 offset, int len, u32 *data)
  210. {
  211. struct rio_priv *priv = mport->priv;
  212. pr_debug("fsl_local_config_read: index %d offset %8.8x\n", index,
  213. offset);
  214. *data = in_be32(priv->regs_win + offset);
  215. return 0;
  216. }
  217. /**
  218. * fsl_local_config_write - Generate a MPC85xx local config space write
  219. * @mport: RapidIO master port info
  220. * @index: ID of RapdiIO interface
  221. * @offset: Offset into configuration space
  222. * @len: Length (in bytes) of the maintenance transaction
  223. * @data: Value to be written
  224. *
  225. * Generates a MPC85xx local configuration space write. Returns %0 on
  226. * success or %-EINVAL on failure.
  227. */
  228. static int fsl_local_config_write(struct rio_mport *mport,
  229. int index, u32 offset, int len, u32 data)
  230. {
  231. struct rio_priv *priv = mport->priv;
  232. pr_debug
  233. ("fsl_local_config_write: index %d offset %8.8x data %8.8x\n",
  234. index, offset, data);
  235. out_be32(priv->regs_win + offset, data);
  236. return 0;
  237. }
  238. /**
  239. * fsl_rio_config_read - Generate a MPC85xx read maintenance transaction
  240. * @mport: RapidIO master port info
  241. * @index: ID of RapdiIO interface
  242. * @destid: Destination ID of transaction
  243. * @hopcount: Number of hops to target device
  244. * @offset: Offset into configuration space
  245. * @len: Length (in bytes) of the maintenance transaction
  246. * @val: Location to be read into
  247. *
  248. * Generates a MPC85xx read maintenance transaction. Returns %0 on
  249. * success or %-EINVAL on failure.
  250. */
  251. static int
  252. fsl_rio_config_read(struct rio_mport *mport, int index, u16 destid,
  253. u8 hopcount, u32 offset, int len, u32 *val)
  254. {
  255. struct rio_priv *priv = mport->priv;
  256. u8 *data;
  257. pr_debug
  258. ("fsl_rio_config_read: index %d destid %d hopcount %d offset %8.8x len %d\n",
  259. index, destid, hopcount, offset, len);
  260. out_be32(&priv->maint_atmu_regs->rowtar,
  261. (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9));
  262. data = (u8 *) priv->maint_win + offset;
  263. switch (len) {
  264. case 1:
  265. *val = in_8((u8 *) data);
  266. break;
  267. case 2:
  268. *val = in_be16((u16 *) data);
  269. break;
  270. default:
  271. *val = in_be32((u32 *) data);
  272. break;
  273. }
  274. return 0;
  275. }
  276. /**
  277. * fsl_rio_config_write - Generate a MPC85xx write maintenance transaction
  278. * @mport: RapidIO master port info
  279. * @index: ID of RapdiIO interface
  280. * @destid: Destination ID of transaction
  281. * @hopcount: Number of hops to target device
  282. * @offset: Offset into configuration space
  283. * @len: Length (in bytes) of the maintenance transaction
  284. * @val: Value to be written
  285. *
  286. * Generates an MPC85xx write maintenance transaction. Returns %0 on
  287. * success or %-EINVAL on failure.
  288. */
  289. static int
  290. fsl_rio_config_write(struct rio_mport *mport, int index, u16 destid,
  291. u8 hopcount, u32 offset, int len, u32 val)
  292. {
  293. struct rio_priv *priv = mport->priv;
  294. u8 *data;
  295. pr_debug
  296. ("fsl_rio_config_write: index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
  297. index, destid, hopcount, offset, len, val);
  298. out_be32(&priv->maint_atmu_regs->rowtar,
  299. (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9));
  300. data = (u8 *) priv->maint_win + offset;
  301. switch (len) {
  302. case 1:
  303. out_8((u8 *) data, val);
  304. break;
  305. case 2:
  306. out_be16((u16 *) data, val);
  307. break;
  308. default:
  309. out_be32((u32 *) data, val);
  310. break;
  311. }
  312. return 0;
  313. }
  314. /**
  315. * rio_hw_add_outb_message - Add message to the MPC85xx outbound message queue
  316. * @mport: Master port with outbound message queue
  317. * @rdev: Target of outbound message
  318. * @mbox: Outbound mailbox
  319. * @buffer: Message to add to outbound queue
  320. * @len: Length of message
  321. *
  322. * Adds the @buffer message to the MPC85xx outbound message queue. Returns
  323. * %0 on success or %-EINVAL on failure.
  324. */
  325. int
  326. rio_hw_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox,
  327. void *buffer, size_t len)
  328. {
  329. struct rio_priv *priv = mport->priv;
  330. u32 omr;
  331. struct rio_tx_desc *desc = (struct rio_tx_desc *)priv->msg_tx_ring.virt
  332. + priv->msg_tx_ring.tx_slot;
  333. int ret = 0;
  334. pr_debug
  335. ("RIO: rio_hw_add_outb_message(): destid %4.4x mbox %d buffer %8.8x len %8.8x\n",
  336. rdev->destid, mbox, (int)buffer, len);
  337. if ((len < 8) || (len > RIO_MAX_MSG_SIZE)) {
  338. ret = -EINVAL;
  339. goto out;
  340. }
  341. /* Copy and clear rest of buffer */
  342. memcpy(priv->msg_tx_ring.virt_buffer[priv->msg_tx_ring.tx_slot], buffer,
  343. len);
  344. if (len < (RIO_MAX_MSG_SIZE - 4))
  345. memset(priv->msg_tx_ring.virt_buffer[priv->msg_tx_ring.tx_slot]
  346. + len, 0, RIO_MAX_MSG_SIZE - len);
  347. switch (mport->phy_type) {
  348. case RIO_PHY_PARALLEL:
  349. /* Set mbox field for message */
  350. desc->dport = mbox & 0x3;
  351. /* Enable EOMI interrupt, set priority, and set destid */
  352. desc->dattr = 0x28000000 | (rdev->destid << 2);
  353. break;
  354. case RIO_PHY_SERIAL:
  355. /* Set mbox field for message, and set destid */
  356. desc->dport = (rdev->destid << 16) | (mbox & 0x3);
  357. /* Enable EOMI interrupt and priority */
  358. desc->dattr = 0x28000000;
  359. break;
  360. }
  361. /* Set transfer size aligned to next power of 2 (in double words) */
  362. desc->dwcnt = is_power_of_2(len) ? len : 1 << get_bitmask_order(len);
  363. /* Set snooping and source buffer address */
  364. desc->saddr = 0x00000004
  365. | priv->msg_tx_ring.phys_buffer[priv->msg_tx_ring.tx_slot];
  366. /* Increment enqueue pointer */
  367. omr = in_be32(&priv->msg_regs->omr);
  368. out_be32(&priv->msg_regs->omr, omr | RIO_MSG_OMR_MUI);
  369. /* Go to next descriptor */
  370. if (++priv->msg_tx_ring.tx_slot == priv->msg_tx_ring.size)
  371. priv->msg_tx_ring.tx_slot = 0;
  372. out:
  373. return ret;
  374. }
  375. EXPORT_SYMBOL_GPL(rio_hw_add_outb_message);
  376. /**
  377. * fsl_rio_tx_handler - MPC85xx outbound message interrupt handler
  378. * @irq: Linux interrupt number
  379. * @dev_instance: Pointer to interrupt-specific data
  380. *
  381. * Handles outbound message interrupts. Executes a register outbound
  382. * mailbox event handler and acks the interrupt occurrence.
  383. */
  384. static irqreturn_t
  385. fsl_rio_tx_handler(int irq, void *dev_instance)
  386. {
  387. int osr;
  388. struct rio_mport *port = (struct rio_mport *)dev_instance;
  389. struct rio_priv *priv = port->priv;
  390. osr = in_be32(&priv->msg_regs->osr);
  391. if (osr & RIO_MSG_OSR_TE) {
  392. pr_info("RIO: outbound message transmission error\n");
  393. out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_TE);
  394. goto out;
  395. }
  396. if (osr & RIO_MSG_OSR_QOI) {
  397. pr_info("RIO: outbound message queue overflow\n");
  398. out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_QOI);
  399. goto out;
  400. }
  401. if (osr & RIO_MSG_OSR_EOMI) {
  402. u32 dqp = in_be32(&priv->msg_regs->odqdpar);
  403. int slot = (dqp - priv->msg_tx_ring.phys) >> 5;
  404. port->outb_msg[0].mcback(port, priv->msg_tx_ring.dev_id, -1,
  405. slot);
  406. /* Ack the end-of-message interrupt */
  407. out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_EOMI);
  408. }
  409. out:
  410. return IRQ_HANDLED;
  411. }
  412. /**
  413. * rio_open_outb_mbox - Initialize MPC85xx outbound mailbox
  414. * @mport: Master port implementing the outbound message unit
  415. * @dev_id: Device specific pointer to pass on event
  416. * @mbox: Mailbox to open
  417. * @entries: Number of entries in the outbound mailbox ring
  418. *
  419. * Initializes buffer ring, request the outbound message interrupt,
  420. * and enables the outbound message unit. Returns %0 on success and
  421. * %-EINVAL or %-ENOMEM on failure.
  422. */
  423. int rio_open_outb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries)
  424. {
  425. int i, j, rc = 0;
  426. struct rio_priv *priv = mport->priv;
  427. if ((entries < RIO_MIN_TX_RING_SIZE) ||
  428. (entries > RIO_MAX_TX_RING_SIZE) || (!is_power_of_2(entries))) {
  429. rc = -EINVAL;
  430. goto out;
  431. }
  432. /* Initialize shadow copy ring */
  433. priv->msg_tx_ring.dev_id = dev_id;
  434. priv->msg_tx_ring.size = entries;
  435. for (i = 0; i < priv->msg_tx_ring.size; i++) {
  436. priv->msg_tx_ring.virt_buffer[i] =
  437. dma_alloc_coherent(priv->dev, RIO_MSG_BUFFER_SIZE,
  438. &priv->msg_tx_ring.phys_buffer[i], GFP_KERNEL);
  439. if (!priv->msg_tx_ring.virt_buffer[i]) {
  440. rc = -ENOMEM;
  441. for (j = 0; j < priv->msg_tx_ring.size; j++)
  442. if (priv->msg_tx_ring.virt_buffer[j])
  443. dma_free_coherent(priv->dev,
  444. RIO_MSG_BUFFER_SIZE,
  445. priv->msg_tx_ring.
  446. virt_buffer[j],
  447. priv->msg_tx_ring.
  448. phys_buffer[j]);
  449. goto out;
  450. }
  451. }
  452. /* Initialize outbound message descriptor ring */
  453. priv->msg_tx_ring.virt = dma_alloc_coherent(priv->dev,
  454. priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
  455. &priv->msg_tx_ring.phys, GFP_KERNEL);
  456. if (!priv->msg_tx_ring.virt) {
  457. rc = -ENOMEM;
  458. goto out_dma;
  459. }
  460. memset(priv->msg_tx_ring.virt, 0,
  461. priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE);
  462. priv->msg_tx_ring.tx_slot = 0;
  463. /* Point dequeue/enqueue pointers at first entry in ring */
  464. out_be32(&priv->msg_regs->odqdpar, priv->msg_tx_ring.phys);
  465. out_be32(&priv->msg_regs->odqepar, priv->msg_tx_ring.phys);
  466. /* Configure for snooping */
  467. out_be32(&priv->msg_regs->osar, 0x00000004);
  468. /* Clear interrupt status */
  469. out_be32(&priv->msg_regs->osr, 0x000000b3);
  470. /* Hook up outbound message handler */
  471. rc = request_irq(IRQ_RIO_TX(mport), fsl_rio_tx_handler, 0,
  472. "msg_tx", (void *)mport);
  473. if (rc < 0)
  474. goto out_irq;
  475. /*
  476. * Configure outbound message unit
  477. * Snooping
  478. * Interrupts (all enabled, except QEIE)
  479. * Chaining mode
  480. * Disable
  481. */
  482. out_be32(&priv->msg_regs->omr, 0x00100220);
  483. /* Set number of entries */
  484. out_be32(&priv->msg_regs->omr,
  485. in_be32(&priv->msg_regs->omr) |
  486. ((get_bitmask_order(entries) - 2) << 12));
  487. /* Now enable the unit */
  488. out_be32(&priv->msg_regs->omr, in_be32(&priv->msg_regs->omr) | 0x1);
  489. out:
  490. return rc;
  491. out_irq:
  492. dma_free_coherent(priv->dev,
  493. priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
  494. priv->msg_tx_ring.virt, priv->msg_tx_ring.phys);
  495. out_dma:
  496. for (i = 0; i < priv->msg_tx_ring.size; i++)
  497. dma_free_coherent(priv->dev, RIO_MSG_BUFFER_SIZE,
  498. priv->msg_tx_ring.virt_buffer[i],
  499. priv->msg_tx_ring.phys_buffer[i]);
  500. return rc;
  501. }
  502. /**
  503. * rio_close_outb_mbox - Shut down MPC85xx outbound mailbox
  504. * @mport: Master port implementing the outbound message unit
  505. * @mbox: Mailbox to close
  506. *
  507. * Disables the outbound message unit, free all buffers, and
  508. * frees the outbound message interrupt.
  509. */
  510. void rio_close_outb_mbox(struct rio_mport *mport, int mbox)
  511. {
  512. struct rio_priv *priv = mport->priv;
  513. /* Disable inbound message unit */
  514. out_be32(&priv->msg_regs->omr, 0);
  515. /* Free ring */
  516. dma_free_coherent(priv->dev,
  517. priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
  518. priv->msg_tx_ring.virt, priv->msg_tx_ring.phys);
  519. /* Free interrupt */
  520. free_irq(IRQ_RIO_TX(mport), (void *)mport);
  521. }
  522. /**
  523. * fsl_rio_rx_handler - MPC85xx inbound message interrupt handler
  524. * @irq: Linux interrupt number
  525. * @dev_instance: Pointer to interrupt-specific data
  526. *
  527. * Handles inbound message interrupts. Executes a registered inbound
  528. * mailbox event handler and acks the interrupt occurrence.
  529. */
  530. static irqreturn_t
  531. fsl_rio_rx_handler(int irq, void *dev_instance)
  532. {
  533. int isr;
  534. struct rio_mport *port = (struct rio_mport *)dev_instance;
  535. struct rio_priv *priv = port->priv;
  536. isr = in_be32(&priv->msg_regs->isr);
  537. if (isr & RIO_MSG_ISR_TE) {
  538. pr_info("RIO: inbound message reception error\n");
  539. out_be32((void *)&priv->msg_regs->isr, RIO_MSG_ISR_TE);
  540. goto out;
  541. }
  542. /* XXX Need to check/dispatch until queue empty */
  543. if (isr & RIO_MSG_ISR_DIQI) {
  544. /*
  545. * We implement *only* mailbox 0, but can receive messages
  546. * for any mailbox/letter to that mailbox destination. So,
  547. * make the callback with an unknown/invalid mailbox number
  548. * argument.
  549. */
  550. port->inb_msg[0].mcback(port, priv->msg_rx_ring.dev_id, -1, -1);
  551. /* Ack the queueing interrupt */
  552. out_be32(&priv->msg_regs->isr, RIO_MSG_ISR_DIQI);
  553. }
  554. out:
  555. return IRQ_HANDLED;
  556. }
  557. /**
  558. * rio_open_inb_mbox - Initialize MPC85xx inbound mailbox
  559. * @mport: Master port implementing the inbound message unit
  560. * @dev_id: Device specific pointer to pass on event
  561. * @mbox: Mailbox to open
  562. * @entries: Number of entries in the inbound mailbox ring
  563. *
  564. * Initializes buffer ring, request the inbound message interrupt,
  565. * and enables the inbound message unit. Returns %0 on success
  566. * and %-EINVAL or %-ENOMEM on failure.
  567. */
  568. int rio_open_inb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries)
  569. {
  570. int i, rc = 0;
  571. struct rio_priv *priv = mport->priv;
  572. if ((entries < RIO_MIN_RX_RING_SIZE) ||
  573. (entries > RIO_MAX_RX_RING_SIZE) || (!is_power_of_2(entries))) {
  574. rc = -EINVAL;
  575. goto out;
  576. }
  577. /* Initialize client buffer ring */
  578. priv->msg_rx_ring.dev_id = dev_id;
  579. priv->msg_rx_ring.size = entries;
  580. priv->msg_rx_ring.rx_slot = 0;
  581. for (i = 0; i < priv->msg_rx_ring.size; i++)
  582. priv->msg_rx_ring.virt_buffer[i] = NULL;
  583. /* Initialize inbound message ring */
  584. priv->msg_rx_ring.virt = dma_alloc_coherent(priv->dev,
  585. priv->msg_rx_ring.size * RIO_MAX_MSG_SIZE,
  586. &priv->msg_rx_ring.phys, GFP_KERNEL);
  587. if (!priv->msg_rx_ring.virt) {
  588. rc = -ENOMEM;
  589. goto out;
  590. }
  591. /* Point dequeue/enqueue pointers at first entry in ring */
  592. out_be32(&priv->msg_regs->ifqdpar, (u32) priv->msg_rx_ring.phys);
  593. out_be32(&priv->msg_regs->ifqepar, (u32) priv->msg_rx_ring.phys);
  594. /* Clear interrupt status */
  595. out_be32(&priv->msg_regs->isr, 0x00000091);
  596. /* Hook up inbound message handler */
  597. rc = request_irq(IRQ_RIO_RX(mport), fsl_rio_rx_handler, 0,
  598. "msg_rx", (void *)mport);
  599. if (rc < 0) {
  600. dma_free_coherent(priv->dev, RIO_MSG_BUFFER_SIZE,
  601. priv->msg_tx_ring.virt_buffer[i],
  602. priv->msg_tx_ring.phys_buffer[i]);
  603. goto out;
  604. }
  605. /*
  606. * Configure inbound message unit:
  607. * Snooping
  608. * 4KB max message size
  609. * Unmask all interrupt sources
  610. * Disable
  611. */
  612. out_be32(&priv->msg_regs->imr, 0x001b0060);
  613. /* Set number of queue entries */
  614. setbits32(&priv->msg_regs->imr, (get_bitmask_order(entries) - 2) << 12);
  615. /* Now enable the unit */
  616. setbits32(&priv->msg_regs->imr, 0x1);
  617. out:
  618. return rc;
  619. }
  620. /**
  621. * rio_close_inb_mbox - Shut down MPC85xx inbound mailbox
  622. * @mport: Master port implementing the inbound message unit
  623. * @mbox: Mailbox to close
  624. *
  625. * Disables the inbound message unit, free all buffers, and
  626. * frees the inbound message interrupt.
  627. */
  628. void rio_close_inb_mbox(struct rio_mport *mport, int mbox)
  629. {
  630. struct rio_priv *priv = mport->priv;
  631. /* Disable inbound message unit */
  632. out_be32(&priv->msg_regs->imr, 0);
  633. /* Free ring */
  634. dma_free_coherent(priv->dev, priv->msg_rx_ring.size * RIO_MAX_MSG_SIZE,
  635. priv->msg_rx_ring.virt, priv->msg_rx_ring.phys);
  636. /* Free interrupt */
  637. free_irq(IRQ_RIO_RX(mport), (void *)mport);
  638. }
  639. /**
  640. * rio_hw_add_inb_buffer - Add buffer to the MPC85xx inbound message queue
  641. * @mport: Master port implementing the inbound message unit
  642. * @mbox: Inbound mailbox number
  643. * @buf: Buffer to add to inbound queue
  644. *
  645. * Adds the @buf buffer to the MPC85xx inbound message queue. Returns
  646. * %0 on success or %-EINVAL on failure.
  647. */
  648. int rio_hw_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf)
  649. {
  650. int rc = 0;
  651. struct rio_priv *priv = mport->priv;
  652. pr_debug("RIO: rio_hw_add_inb_buffer(), msg_rx_ring.rx_slot %d\n",
  653. priv->msg_rx_ring.rx_slot);
  654. if (priv->msg_rx_ring.virt_buffer[priv->msg_rx_ring.rx_slot]) {
  655. printk(KERN_ERR
  656. "RIO: error adding inbound buffer %d, buffer exists\n",
  657. priv->msg_rx_ring.rx_slot);
  658. rc = -EINVAL;
  659. goto out;
  660. }
  661. priv->msg_rx_ring.virt_buffer[priv->msg_rx_ring.rx_slot] = buf;
  662. if (++priv->msg_rx_ring.rx_slot == priv->msg_rx_ring.size)
  663. priv->msg_rx_ring.rx_slot = 0;
  664. out:
  665. return rc;
  666. }
  667. EXPORT_SYMBOL_GPL(rio_hw_add_inb_buffer);
  668. /**
  669. * rio_hw_get_inb_message - Fetch inbound message from the MPC85xx message unit
  670. * @mport: Master port implementing the inbound message unit
  671. * @mbox: Inbound mailbox number
  672. *
  673. * Gets the next available inbound message from the inbound message queue.
  674. * A pointer to the message is returned on success or NULL on failure.
  675. */
  676. void *rio_hw_get_inb_message(struct rio_mport *mport, int mbox)
  677. {
  678. struct rio_priv *priv = mport->priv;
  679. u32 phys_buf, virt_buf;
  680. void *buf = NULL;
  681. int buf_idx;
  682. phys_buf = in_be32(&priv->msg_regs->ifqdpar);
  683. /* If no more messages, then bail out */
  684. if (phys_buf == in_be32(&priv->msg_regs->ifqepar))
  685. goto out2;
  686. virt_buf = (u32) priv->msg_rx_ring.virt + (phys_buf
  687. - priv->msg_rx_ring.phys);
  688. buf_idx = (phys_buf - priv->msg_rx_ring.phys) / RIO_MAX_MSG_SIZE;
  689. buf = priv->msg_rx_ring.virt_buffer[buf_idx];
  690. if (!buf) {
  691. printk(KERN_ERR
  692. "RIO: inbound message copy failed, no buffers\n");
  693. goto out1;
  694. }
  695. /* Copy max message size, caller is expected to allocate that big */
  696. memcpy(buf, (void *)virt_buf, RIO_MAX_MSG_SIZE);
  697. /* Clear the available buffer */
  698. priv->msg_rx_ring.virt_buffer[buf_idx] = NULL;
  699. out1:
  700. setbits32(&priv->msg_regs->imr, RIO_MSG_IMR_MI);
  701. out2:
  702. return buf;
  703. }
  704. EXPORT_SYMBOL_GPL(rio_hw_get_inb_message);
  705. /**
  706. * fsl_rio_dbell_handler - MPC85xx doorbell interrupt handler
  707. * @irq: Linux interrupt number
  708. * @dev_instance: Pointer to interrupt-specific data
  709. *
  710. * Handles doorbell interrupts. Parses a list of registered
  711. * doorbell event handlers and executes a matching event handler.
  712. */
  713. static irqreturn_t
  714. fsl_rio_dbell_handler(int irq, void *dev_instance)
  715. {
  716. int dsr;
  717. struct rio_mport *port = (struct rio_mport *)dev_instance;
  718. struct rio_priv *priv = port->priv;
  719. dsr = in_be32(&priv->msg_regs->dsr);
  720. if (dsr & DOORBELL_DSR_TE) {
  721. pr_info("RIO: doorbell reception error\n");
  722. out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_TE);
  723. goto out;
  724. }
  725. if (dsr & DOORBELL_DSR_QFI) {
  726. pr_info("RIO: doorbell queue full\n");
  727. out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_QFI);
  728. goto out;
  729. }
  730. /* XXX Need to check/dispatch until queue empty */
  731. if (dsr & DOORBELL_DSR_DIQI) {
  732. u32 dmsg =
  733. (u32) priv->dbell_ring.virt +
  734. (in_be32(&priv->msg_regs->dqdpar) & 0xfff);
  735. struct rio_dbell *dbell;
  736. int found = 0;
  737. pr_debug
  738. ("RIO: processing doorbell, sid %2.2x tid %2.2x info %4.4x\n",
  739. DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg));
  740. list_for_each_entry(dbell, &port->dbells, node) {
  741. if ((dbell->res->start <= DBELL_INF(dmsg)) &&
  742. (dbell->res->end >= DBELL_INF(dmsg))) {
  743. found = 1;
  744. break;
  745. }
  746. }
  747. if (found) {
  748. dbell->dinb(port, dbell->dev_id, DBELL_SID(dmsg), DBELL_TID(dmsg),
  749. DBELL_INF(dmsg));
  750. } else {
  751. pr_debug
  752. ("RIO: spurious doorbell, sid %2.2x tid %2.2x info %4.4x\n",
  753. DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg));
  754. }
  755. setbits32(&priv->msg_regs->dmr, DOORBELL_DMR_DI);
  756. out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_DIQI);
  757. }
  758. out:
  759. return IRQ_HANDLED;
  760. }
  761. /**
  762. * fsl_rio_doorbell_init - MPC85xx doorbell interface init
  763. * @mport: Master port implementing the inbound doorbell unit
  764. *
  765. * Initializes doorbell unit hardware and inbound DMA buffer
  766. * ring. Called from fsl_rio_setup(). Returns %0 on success
  767. * or %-ENOMEM on failure.
  768. */
  769. static int fsl_rio_doorbell_init(struct rio_mport *mport)
  770. {
  771. struct rio_priv *priv = mport->priv;
  772. int rc = 0;
  773. /* Map outbound doorbell window immediately after maintenance window */
  774. priv->dbell_win = ioremap(mport->iores.start + RIO_MAINT_WIN_SIZE,
  775. RIO_DBELL_WIN_SIZE);
  776. if (!priv->dbell_win) {
  777. printk(KERN_ERR
  778. "RIO: unable to map outbound doorbell window\n");
  779. rc = -ENOMEM;
  780. goto out;
  781. }
  782. /* Initialize inbound doorbells */
  783. priv->dbell_ring.virt = dma_alloc_coherent(priv->dev, 512 *
  784. DOORBELL_MESSAGE_SIZE, &priv->dbell_ring.phys, GFP_KERNEL);
  785. if (!priv->dbell_ring.virt) {
  786. printk(KERN_ERR "RIO: unable allocate inbound doorbell ring\n");
  787. rc = -ENOMEM;
  788. iounmap(priv->dbell_win);
  789. goto out;
  790. }
  791. /* Point dequeue/enqueue pointers at first entry in ring */
  792. out_be32(&priv->msg_regs->dqdpar, (u32) priv->dbell_ring.phys);
  793. out_be32(&priv->msg_regs->dqepar, (u32) priv->dbell_ring.phys);
  794. /* Clear interrupt status */
  795. out_be32(&priv->msg_regs->dsr, 0x00000091);
  796. /* Hook up doorbell handler */
  797. rc = request_irq(IRQ_RIO_BELL(mport), fsl_rio_dbell_handler, 0,
  798. "dbell_rx", (void *)mport);
  799. if (rc < 0) {
  800. iounmap(priv->dbell_win);
  801. dma_free_coherent(priv->dev, 512 * DOORBELL_MESSAGE_SIZE,
  802. priv->dbell_ring.virt, priv->dbell_ring.phys);
  803. printk(KERN_ERR
  804. "MPC85xx RIO: unable to request inbound doorbell irq");
  805. goto out;
  806. }
  807. /* Configure doorbells for snooping, 512 entries, and enable */
  808. out_be32(&priv->msg_regs->dmr, 0x00108161);
  809. out:
  810. return rc;
  811. }
  812. static char *cmdline = NULL;
  813. static int fsl_rio_get_hdid(int index)
  814. {
  815. /* XXX Need to parse multiple entries in some format */
  816. if (!cmdline)
  817. return -1;
  818. return simple_strtol(cmdline, NULL, 0);
  819. }
  820. static int fsl_rio_get_cmdline(char *s)
  821. {
  822. if (!s)
  823. return 0;
  824. cmdline = s;
  825. return 1;
  826. }
  827. __setup("riohdid=", fsl_rio_get_cmdline);
  828. static inline void fsl_rio_info(struct device *dev, u32 ccsr)
  829. {
  830. const char *str;
  831. if (ccsr & 1) {
  832. /* Serial phy */
  833. switch (ccsr >> 30) {
  834. case 0:
  835. str = "1";
  836. break;
  837. case 1:
  838. str = "4";
  839. break;
  840. default:
  841. str = "Unknown";
  842. break;
  843. }
  844. dev_info(dev, "Hardware port width: %s\n", str);
  845. switch ((ccsr >> 27) & 7) {
  846. case 0:
  847. str = "Single-lane 0";
  848. break;
  849. case 1:
  850. str = "Single-lane 2";
  851. break;
  852. case 2:
  853. str = "Four-lane";
  854. break;
  855. default:
  856. str = "Unknown";
  857. break;
  858. }
  859. dev_info(dev, "Training connection status: %s\n", str);
  860. } else {
  861. /* Parallel phy */
  862. if (!(ccsr & 0x80000000))
  863. dev_info(dev, "Output port operating in 8-bit mode\n");
  864. if (!(ccsr & 0x08000000))
  865. dev_info(dev, "Input port operating in 8-bit mode\n");
  866. }
  867. }
  868. /**
  869. * fsl_rio_setup - Setup Freescale PowerPC RapidIO interface
  870. * @dev: of_device pointer
  871. *
  872. * Initializes MPC85xx RapidIO hardware interface, configures
  873. * master port with system-specific info, and registers the
  874. * master port with the RapidIO subsystem.
  875. */
  876. int fsl_rio_setup(struct of_device *dev)
  877. {
  878. struct rio_ops *ops;
  879. struct rio_mport *port;
  880. struct rio_priv *priv;
  881. int rc = 0;
  882. const u32 *dt_range, *cell;
  883. struct resource regs;
  884. int rlen;
  885. u32 ccsr;
  886. u64 law_start, law_size;
  887. int paw, aw, sw;
  888. if (!dev->node) {
  889. dev_err(&dev->dev, "Device OF-Node is NULL");
  890. return -EFAULT;
  891. }
  892. rc = of_address_to_resource(dev->node, 0, &regs);
  893. if (rc) {
  894. dev_err(&dev->dev, "Can't get %s property 'reg'\n",
  895. dev->node->full_name);
  896. return -EFAULT;
  897. }
  898. dev_info(&dev->dev, "Of-device full name %s\n", dev->node->full_name);
  899. dev_info(&dev->dev, "Regs: %pR\n", &regs);
  900. dt_range = of_get_property(dev->node, "ranges", &rlen);
  901. if (!dt_range) {
  902. dev_err(&dev->dev, "Can't get %s property 'ranges'\n",
  903. dev->node->full_name);
  904. return -EFAULT;
  905. }
  906. /* Get node address wide */
  907. cell = of_get_property(dev->node, "#address-cells", NULL);
  908. if (cell)
  909. aw = *cell;
  910. else
  911. aw = of_n_addr_cells(dev->node);
  912. /* Get node size wide */
  913. cell = of_get_property(dev->node, "#size-cells", NULL);
  914. if (cell)
  915. sw = *cell;
  916. else
  917. sw = of_n_size_cells(dev->node);
  918. /* Get parent address wide wide */
  919. paw = of_n_addr_cells(dev->node);
  920. law_start = of_read_number(dt_range + aw, paw);
  921. law_size = of_read_number(dt_range + aw + paw, sw);
  922. dev_info(&dev->dev, "LAW start 0x%016llx, size 0x%016llx.\n",
  923. law_start, law_size);
  924. ops = kmalloc(sizeof(struct rio_ops), GFP_KERNEL);
  925. if (!ops) {
  926. rc = -ENOMEM;
  927. goto err_ops;
  928. }
  929. ops->lcread = fsl_local_config_read;
  930. ops->lcwrite = fsl_local_config_write;
  931. ops->cread = fsl_rio_config_read;
  932. ops->cwrite = fsl_rio_config_write;
  933. ops->dsend = fsl_rio_doorbell_send;
  934. port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL);
  935. if (!port) {
  936. rc = -ENOMEM;
  937. goto err_port;
  938. }
  939. port->id = 0;
  940. port->index = 0;
  941. priv = kzalloc(sizeof(struct rio_priv), GFP_KERNEL);
  942. if (!priv) {
  943. printk(KERN_ERR "Can't alloc memory for 'priv'\n");
  944. rc = -ENOMEM;
  945. goto err_priv;
  946. }
  947. INIT_LIST_HEAD(&port->dbells);
  948. port->iores.start = law_start;
  949. port->iores.end = law_start + law_size - 1;
  950. port->iores.flags = IORESOURCE_MEM;
  951. port->iores.name = "rio_io_win";
  952. priv->bellirq = irq_of_parse_and_map(dev->node, 2);
  953. priv->txirq = irq_of_parse_and_map(dev->node, 3);
  954. priv->rxirq = irq_of_parse_and_map(dev->node, 4);
  955. dev_info(&dev->dev, "bellirq: %d, txirq: %d, rxirq %d\n", priv->bellirq,
  956. priv->txirq, priv->rxirq);
  957. rio_init_dbell_res(&port->riores[RIO_DOORBELL_RESOURCE], 0, 0xffff);
  958. rio_init_mbox_res(&port->riores[RIO_INB_MBOX_RESOURCE], 0, 0);
  959. rio_init_mbox_res(&port->riores[RIO_OUTB_MBOX_RESOURCE], 0, 0);
  960. strcpy(port->name, "RIO0 mport");
  961. priv->dev = &dev->dev;
  962. port->ops = ops;
  963. port->host_deviceid = fsl_rio_get_hdid(port->id);
  964. port->priv = priv;
  965. rio_register_mport(port);
  966. priv->regs_win = ioremap(regs.start, regs.end - regs.start + 1);
  967. /* Probe the master port phy type */
  968. ccsr = in_be32(priv->regs_win + RIO_CCSR);
  969. port->phy_type = (ccsr & 1) ? RIO_PHY_SERIAL : RIO_PHY_PARALLEL;
  970. dev_info(&dev->dev, "RapidIO PHY type: %s\n",
  971. (port->phy_type == RIO_PHY_PARALLEL) ? "parallel" :
  972. ((port->phy_type == RIO_PHY_SERIAL) ? "serial" :
  973. "unknown"));
  974. /* Checking the port training status */
  975. if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) {
  976. dev_err(&dev->dev, "Port is not ready. "
  977. "Try to restart connection...\n");
  978. switch (port->phy_type) {
  979. case RIO_PHY_SERIAL:
  980. /* Disable ports */
  981. out_be32(priv->regs_win + RIO_CCSR, 0);
  982. /* Set 1x lane */
  983. setbits32(priv->regs_win + RIO_CCSR, 0x02000000);
  984. /* Enable ports */
  985. setbits32(priv->regs_win + RIO_CCSR, 0x00600000);
  986. break;
  987. case RIO_PHY_PARALLEL:
  988. /* Disable ports */
  989. out_be32(priv->regs_win + RIO_CCSR, 0x22000000);
  990. /* Enable ports */
  991. out_be32(priv->regs_win + RIO_CCSR, 0x44000000);
  992. break;
  993. }
  994. msleep(100);
  995. if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) {
  996. dev_err(&dev->dev, "Port restart failed.\n");
  997. rc = -ENOLINK;
  998. goto err;
  999. }
  1000. dev_info(&dev->dev, "Port restart success!\n");
  1001. }
  1002. fsl_rio_info(&dev->dev, ccsr);
  1003. port->sys_size = (in_be32((priv->regs_win + RIO_PEF_CAR))
  1004. & RIO_PEF_CTLS) >> 4;
  1005. dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n",
  1006. port->sys_size ? 65536 : 256);
  1007. priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win
  1008. + RIO_ATMU_REGS_OFFSET);
  1009. priv->maint_atmu_regs = priv->atmu_regs + 1;
  1010. priv->dbell_atmu_regs = priv->atmu_regs + 2;
  1011. priv->msg_regs = (struct rio_msg_regs *)(priv->regs_win +
  1012. ((port->phy_type == RIO_PHY_SERIAL) ?
  1013. RIO_S_MSG_REGS_OFFSET : RIO_P_MSG_REGS_OFFSET));
  1014. /* Set to receive any dist ID for serial RapidIO controller. */
  1015. if (port->phy_type == RIO_PHY_SERIAL)
  1016. out_be32((priv->regs_win + RIO_ISR_AACR), RIO_ISR_AACR_AA);
  1017. /* Configure maintenance transaction window */
  1018. out_be32(&priv->maint_atmu_regs->rowbar, law_start >> 12);
  1019. out_be32(&priv->maint_atmu_regs->rowar, 0x80077015); /* 4M */
  1020. priv->maint_win = ioremap(law_start, RIO_MAINT_WIN_SIZE);
  1021. /* Configure outbound doorbell window */
  1022. out_be32(&priv->dbell_atmu_regs->rowbar,
  1023. (law_start + RIO_MAINT_WIN_SIZE) >> 12);
  1024. out_be32(&priv->dbell_atmu_regs->rowar, 0x8004200b); /* 4k */
  1025. fsl_rio_doorbell_init(port);
  1026. return 0;
  1027. err:
  1028. iounmap(priv->regs_win);
  1029. kfree(priv);
  1030. err_priv:
  1031. kfree(port);
  1032. err_port:
  1033. kfree(ops);
  1034. err_ops:
  1035. return rc;
  1036. }
  1037. /* The probe function for RapidIO peer-to-peer network.
  1038. */
  1039. static int __devinit fsl_of_rio_rpn_probe(struct of_device *dev,
  1040. const struct of_device_id *match)
  1041. {
  1042. int rc;
  1043. printk(KERN_INFO "Setting up RapidIO peer-to-peer network %s\n",
  1044. dev->node->full_name);
  1045. rc = fsl_rio_setup(dev);
  1046. if (rc)
  1047. goto out;
  1048. /* Enumerate all registered ports */
  1049. rc = rio_init_mports();
  1050. out:
  1051. return rc;
  1052. };
  1053. static const struct of_device_id fsl_of_rio_rpn_ids[] = {
  1054. {
  1055. .compatible = "fsl,rapidio-delta",
  1056. },
  1057. {},
  1058. };
  1059. static struct of_platform_driver fsl_of_rio_rpn_driver = {
  1060. .name = "fsl-of-rio",
  1061. .match_table = fsl_of_rio_rpn_ids,
  1062. .probe = fsl_of_rio_rpn_probe,
  1063. };
  1064. static __init int fsl_of_rio_rpn_init(void)
  1065. {
  1066. return of_register_platform_driver(&fsl_of_rio_rpn_driver);
  1067. }
  1068. subsys_initcall(fsl_of_rio_rpn_init);