fsl_rio.c 32 KB

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