rio.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. /*
  2. * RapidIO interconnect services
  3. * (RapidIO Interconnect Specification, http://www.rapidio.org)
  4. *
  5. * Copyright 2005 MontaVista Software, Inc.
  6. * Matt Porter <mporter@kernel.crashing.org>
  7. *
  8. * Copyright 2009 Integrated Device Technology, Inc.
  9. * Alex Bounine <alexandre.bounine@idt.com>
  10. * - Added Port-Write/Error Management initialization and handling
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/types.h>
  18. #include <linux/kernel.h>
  19. #include <linux/delay.h>
  20. #include <linux/init.h>
  21. #include <linux/rio.h>
  22. #include <linux/rio_drv.h>
  23. #include <linux/rio_ids.h>
  24. #include <linux/rio_regs.h>
  25. #include <linux/module.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include "rio.h"
  30. static LIST_HEAD(rio_mports);
  31. static unsigned char next_portid;
  32. static DEFINE_SPINLOCK(rio_mmap_lock);
  33. /**
  34. * rio_local_get_device_id - Get the base/extended device id for a port
  35. * @port: RIO master port from which to get the deviceid
  36. *
  37. * Reads the base/extended device id from the local device
  38. * implementing the master port. Returns the 8/16-bit device
  39. * id.
  40. */
  41. u16 rio_local_get_device_id(struct rio_mport *port)
  42. {
  43. u32 result;
  44. rio_local_read_config_32(port, RIO_DID_CSR, &result);
  45. return (RIO_GET_DID(port->sys_size, result));
  46. }
  47. /**
  48. * rio_request_inb_mbox - request inbound mailbox service
  49. * @mport: RIO master port from which to allocate the mailbox resource
  50. * @dev_id: Device specific pointer to pass on event
  51. * @mbox: Mailbox number to claim
  52. * @entries: Number of entries in inbound mailbox queue
  53. * @minb: Callback to execute when inbound message is received
  54. *
  55. * Requests ownership of an inbound mailbox resource and binds
  56. * a callback function to the resource. Returns %0 on success.
  57. */
  58. int rio_request_inb_mbox(struct rio_mport *mport,
  59. void *dev_id,
  60. int mbox,
  61. int entries,
  62. void (*minb) (struct rio_mport * mport, void *dev_id, int mbox,
  63. int slot))
  64. {
  65. int rc = -ENOSYS;
  66. struct resource *res;
  67. if (mport->ops->open_inb_mbox == NULL)
  68. goto out;
  69. res = kmalloc(sizeof(struct resource), GFP_KERNEL);
  70. if (res) {
  71. rio_init_mbox_res(res, mbox, mbox);
  72. /* Make sure this mailbox isn't in use */
  73. if ((rc =
  74. request_resource(&mport->riores[RIO_INB_MBOX_RESOURCE],
  75. res)) < 0) {
  76. kfree(res);
  77. goto out;
  78. }
  79. mport->inb_msg[mbox].res = res;
  80. /* Hook the inbound message callback */
  81. mport->inb_msg[mbox].mcback = minb;
  82. rc = mport->ops->open_inb_mbox(mport, dev_id, mbox, entries);
  83. } else
  84. rc = -ENOMEM;
  85. out:
  86. return rc;
  87. }
  88. /**
  89. * rio_release_inb_mbox - release inbound mailbox message service
  90. * @mport: RIO master port from which to release the mailbox resource
  91. * @mbox: Mailbox number to release
  92. *
  93. * Releases ownership of an inbound mailbox resource. Returns 0
  94. * if the request has been satisfied.
  95. */
  96. int rio_release_inb_mbox(struct rio_mport *mport, int mbox)
  97. {
  98. if (mport->ops->close_inb_mbox) {
  99. mport->ops->close_inb_mbox(mport, mbox);
  100. /* Release the mailbox resource */
  101. return release_resource(mport->inb_msg[mbox].res);
  102. } else
  103. return -ENOSYS;
  104. }
  105. /**
  106. * rio_request_outb_mbox - request outbound mailbox service
  107. * @mport: RIO master port from which to allocate the mailbox resource
  108. * @dev_id: Device specific pointer to pass on event
  109. * @mbox: Mailbox number to claim
  110. * @entries: Number of entries in outbound mailbox queue
  111. * @moutb: Callback to execute when outbound message is sent
  112. *
  113. * Requests ownership of an outbound mailbox resource and binds
  114. * a callback function to the resource. Returns 0 on success.
  115. */
  116. int rio_request_outb_mbox(struct rio_mport *mport,
  117. void *dev_id,
  118. int mbox,
  119. int entries,
  120. void (*moutb) (struct rio_mport * mport, void *dev_id, int mbox, int slot))
  121. {
  122. int rc = -ENOSYS;
  123. struct resource *res;
  124. if (mport->ops->open_outb_mbox == NULL)
  125. goto out;
  126. res = kmalloc(sizeof(struct resource), GFP_KERNEL);
  127. if (res) {
  128. rio_init_mbox_res(res, mbox, mbox);
  129. /* Make sure this outbound mailbox isn't in use */
  130. if ((rc =
  131. request_resource(&mport->riores[RIO_OUTB_MBOX_RESOURCE],
  132. res)) < 0) {
  133. kfree(res);
  134. goto out;
  135. }
  136. mport->outb_msg[mbox].res = res;
  137. /* Hook the inbound message callback */
  138. mport->outb_msg[mbox].mcback = moutb;
  139. rc = mport->ops->open_outb_mbox(mport, dev_id, mbox, entries);
  140. } else
  141. rc = -ENOMEM;
  142. out:
  143. return rc;
  144. }
  145. /**
  146. * rio_release_outb_mbox - release outbound mailbox message service
  147. * @mport: RIO master port from which to release the mailbox resource
  148. * @mbox: Mailbox number to release
  149. *
  150. * Releases ownership of an inbound mailbox resource. Returns 0
  151. * if the request has been satisfied.
  152. */
  153. int rio_release_outb_mbox(struct rio_mport *mport, int mbox)
  154. {
  155. if (mport->ops->close_outb_mbox) {
  156. mport->ops->close_outb_mbox(mport, mbox);
  157. /* Release the mailbox resource */
  158. return release_resource(mport->outb_msg[mbox].res);
  159. } else
  160. return -ENOSYS;
  161. }
  162. /**
  163. * rio_setup_inb_dbell - bind inbound doorbell callback
  164. * @mport: RIO master port to bind the doorbell callback
  165. * @dev_id: Device specific pointer to pass on event
  166. * @res: Doorbell message resource
  167. * @dinb: Callback to execute when doorbell is received
  168. *
  169. * Adds a doorbell resource/callback pair into a port's
  170. * doorbell event list. Returns 0 if the request has been
  171. * satisfied.
  172. */
  173. static int
  174. rio_setup_inb_dbell(struct rio_mport *mport, void *dev_id, struct resource *res,
  175. void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src, u16 dst,
  176. u16 info))
  177. {
  178. int rc = 0;
  179. struct rio_dbell *dbell;
  180. if (!(dbell = kmalloc(sizeof(struct rio_dbell), GFP_KERNEL))) {
  181. rc = -ENOMEM;
  182. goto out;
  183. }
  184. dbell->res = res;
  185. dbell->dinb = dinb;
  186. dbell->dev_id = dev_id;
  187. list_add_tail(&dbell->node, &mport->dbells);
  188. out:
  189. return rc;
  190. }
  191. /**
  192. * rio_request_inb_dbell - request inbound doorbell message service
  193. * @mport: RIO master port from which to allocate the doorbell resource
  194. * @dev_id: Device specific pointer to pass on event
  195. * @start: Doorbell info range start
  196. * @end: Doorbell info range end
  197. * @dinb: Callback to execute when doorbell is received
  198. *
  199. * Requests ownership of an inbound doorbell resource and binds
  200. * a callback function to the resource. Returns 0 if the request
  201. * has been satisfied.
  202. */
  203. int rio_request_inb_dbell(struct rio_mport *mport,
  204. void *dev_id,
  205. u16 start,
  206. u16 end,
  207. void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src,
  208. u16 dst, u16 info))
  209. {
  210. int rc = 0;
  211. struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
  212. if (res) {
  213. rio_init_dbell_res(res, start, end);
  214. /* Make sure these doorbells aren't in use */
  215. if ((rc =
  216. request_resource(&mport->riores[RIO_DOORBELL_RESOURCE],
  217. res)) < 0) {
  218. kfree(res);
  219. goto out;
  220. }
  221. /* Hook the doorbell callback */
  222. rc = rio_setup_inb_dbell(mport, dev_id, res, dinb);
  223. } else
  224. rc = -ENOMEM;
  225. out:
  226. return rc;
  227. }
  228. /**
  229. * rio_release_inb_dbell - release inbound doorbell message service
  230. * @mport: RIO master port from which to release the doorbell resource
  231. * @start: Doorbell info range start
  232. * @end: Doorbell info range end
  233. *
  234. * Releases ownership of an inbound doorbell resource and removes
  235. * callback from the doorbell event list. Returns 0 if the request
  236. * has been satisfied.
  237. */
  238. int rio_release_inb_dbell(struct rio_mport *mport, u16 start, u16 end)
  239. {
  240. int rc = 0, found = 0;
  241. struct rio_dbell *dbell;
  242. list_for_each_entry(dbell, &mport->dbells, node) {
  243. if ((dbell->res->start == start) && (dbell->res->end == end)) {
  244. found = 1;
  245. break;
  246. }
  247. }
  248. /* If we can't find an exact match, fail */
  249. if (!found) {
  250. rc = -EINVAL;
  251. goto out;
  252. }
  253. /* Delete from list */
  254. list_del(&dbell->node);
  255. /* Release the doorbell resource */
  256. rc = release_resource(dbell->res);
  257. /* Free the doorbell event */
  258. kfree(dbell);
  259. out:
  260. return rc;
  261. }
  262. /**
  263. * rio_request_outb_dbell - request outbound doorbell message range
  264. * @rdev: RIO device from which to allocate the doorbell resource
  265. * @start: Doorbell message range start
  266. * @end: Doorbell message range end
  267. *
  268. * Requests ownership of a doorbell message range. Returns a resource
  269. * if the request has been satisfied or %NULL on failure.
  270. */
  271. struct resource *rio_request_outb_dbell(struct rio_dev *rdev, u16 start,
  272. u16 end)
  273. {
  274. struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
  275. if (res) {
  276. rio_init_dbell_res(res, start, end);
  277. /* Make sure these doorbells aren't in use */
  278. if (request_resource(&rdev->riores[RIO_DOORBELL_RESOURCE], res)
  279. < 0) {
  280. kfree(res);
  281. res = NULL;
  282. }
  283. }
  284. return res;
  285. }
  286. /**
  287. * rio_release_outb_dbell - release outbound doorbell message range
  288. * @rdev: RIO device from which to release the doorbell resource
  289. * @res: Doorbell resource to be freed
  290. *
  291. * Releases ownership of a doorbell message range. Returns 0 if the
  292. * request has been satisfied.
  293. */
  294. int rio_release_outb_dbell(struct rio_dev *rdev, struct resource *res)
  295. {
  296. int rc = release_resource(res);
  297. kfree(res);
  298. return rc;
  299. }
  300. /**
  301. * rio_request_inb_pwrite - request inbound port-write message service
  302. * @rdev: RIO device to which register inbound port-write callback routine
  303. * @pwcback: Callback routine to execute when port-write is received
  304. *
  305. * Binds a port-write callback function to the RapidIO device.
  306. * Returns 0 if the request has been satisfied.
  307. */
  308. int rio_request_inb_pwrite(struct rio_dev *rdev,
  309. int (*pwcback)(struct rio_dev *rdev, union rio_pw_msg *msg, int step))
  310. {
  311. int rc = 0;
  312. spin_lock(&rio_global_list_lock);
  313. if (rdev->pwcback != NULL)
  314. rc = -ENOMEM;
  315. else
  316. rdev->pwcback = pwcback;
  317. spin_unlock(&rio_global_list_lock);
  318. return rc;
  319. }
  320. EXPORT_SYMBOL_GPL(rio_request_inb_pwrite);
  321. /**
  322. * rio_release_inb_pwrite - release inbound port-write message service
  323. * @rdev: RIO device which registered for inbound port-write callback
  324. *
  325. * Removes callback from the rio_dev structure. Returns 0 if the request
  326. * has been satisfied.
  327. */
  328. int rio_release_inb_pwrite(struct rio_dev *rdev)
  329. {
  330. int rc = -ENOMEM;
  331. spin_lock(&rio_global_list_lock);
  332. if (rdev->pwcback) {
  333. rdev->pwcback = NULL;
  334. rc = 0;
  335. }
  336. spin_unlock(&rio_global_list_lock);
  337. return rc;
  338. }
  339. EXPORT_SYMBOL_GPL(rio_release_inb_pwrite);
  340. /**
  341. * rio_map_inb_region -- Map inbound memory region.
  342. * @mport: Master port.
  343. * @lstart: physical address of memory region to be mapped
  344. * @rbase: RIO base address assigned to this window
  345. * @size: Size of the memory region
  346. * @rflags: Flags for mapping.
  347. *
  348. * Return: 0 -- Success.
  349. *
  350. * This function will create the mapping from RIO space to local memory.
  351. */
  352. int rio_map_inb_region(struct rio_mport *mport, dma_addr_t local,
  353. u64 rbase, u32 size, u32 rflags)
  354. {
  355. int rc = 0;
  356. unsigned long flags;
  357. if (!mport->ops->map_inb)
  358. return -1;
  359. spin_lock_irqsave(&rio_mmap_lock, flags);
  360. rc = mport->ops->map_inb(mport, local, rbase, size, rflags);
  361. spin_unlock_irqrestore(&rio_mmap_lock, flags);
  362. return rc;
  363. }
  364. EXPORT_SYMBOL_GPL(rio_map_inb_region);
  365. /**
  366. * rio_unmap_inb_region -- Unmap the inbound memory region
  367. * @mport: Master port
  368. * @lstart: physical address of memory region to be unmapped
  369. */
  370. void rio_unmap_inb_region(struct rio_mport *mport, dma_addr_t lstart)
  371. {
  372. unsigned long flags;
  373. if (!mport->ops->unmap_inb)
  374. return;
  375. spin_lock_irqsave(&rio_mmap_lock, flags);
  376. mport->ops->unmap_inb(mport, lstart);
  377. spin_unlock_irqrestore(&rio_mmap_lock, flags);
  378. }
  379. EXPORT_SYMBOL_GPL(rio_unmap_inb_region);
  380. /**
  381. * rio_mport_get_physefb - Helper function that returns register offset
  382. * for Physical Layer Extended Features Block.
  383. * @port: Master port to issue transaction
  384. * @local: Indicate a local master port or remote device access
  385. * @destid: Destination ID of the device
  386. * @hopcount: Number of switch hops to the device
  387. */
  388. u32
  389. rio_mport_get_physefb(struct rio_mport *port, int local,
  390. u16 destid, u8 hopcount)
  391. {
  392. u32 ext_ftr_ptr;
  393. u32 ftr_header;
  394. ext_ftr_ptr = rio_mport_get_efb(port, local, destid, hopcount, 0);
  395. while (ext_ftr_ptr) {
  396. if (local)
  397. rio_local_read_config_32(port, ext_ftr_ptr,
  398. &ftr_header);
  399. else
  400. rio_mport_read_config_32(port, destid, hopcount,
  401. ext_ftr_ptr, &ftr_header);
  402. ftr_header = RIO_GET_BLOCK_ID(ftr_header);
  403. switch (ftr_header) {
  404. case RIO_EFB_SER_EP_ID_V13P:
  405. case RIO_EFB_SER_EP_REC_ID_V13P:
  406. case RIO_EFB_SER_EP_FREE_ID_V13P:
  407. case RIO_EFB_SER_EP_ID:
  408. case RIO_EFB_SER_EP_REC_ID:
  409. case RIO_EFB_SER_EP_FREE_ID:
  410. case RIO_EFB_SER_EP_FREC_ID:
  411. return ext_ftr_ptr;
  412. default:
  413. break;
  414. }
  415. ext_ftr_ptr = rio_mport_get_efb(port, local, destid,
  416. hopcount, ext_ftr_ptr);
  417. }
  418. return ext_ftr_ptr;
  419. }
  420. /**
  421. * rio_get_comptag - Begin or continue searching for a RIO device by component tag
  422. * @comp_tag: RIO component tag to match
  423. * @from: Previous RIO device found in search, or %NULL for new search
  424. *
  425. * Iterates through the list of known RIO devices. If a RIO device is
  426. * found with a matching @comp_tag, a pointer to its device
  427. * structure is returned. Otherwise, %NULL is returned. A new search
  428. * is initiated by passing %NULL to the @from argument. Otherwise, if
  429. * @from is not %NULL, searches continue from next device on the global
  430. * list.
  431. */
  432. struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from)
  433. {
  434. struct list_head *n;
  435. struct rio_dev *rdev;
  436. spin_lock(&rio_global_list_lock);
  437. n = from ? from->global_list.next : rio_devices.next;
  438. while (n && (n != &rio_devices)) {
  439. rdev = rio_dev_g(n);
  440. if (rdev->comp_tag == comp_tag)
  441. goto exit;
  442. n = n->next;
  443. }
  444. rdev = NULL;
  445. exit:
  446. spin_unlock(&rio_global_list_lock);
  447. return rdev;
  448. }
  449. /**
  450. * rio_set_port_lockout - Sets/clears LOCKOUT bit (RIO EM 1.3) for a switch port.
  451. * @rdev: Pointer to RIO device control structure
  452. * @pnum: Switch port number to set LOCKOUT bit
  453. * @lock: Operation : set (=1) or clear (=0)
  454. */
  455. int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
  456. {
  457. u32 regval;
  458. rio_read_config_32(rdev,
  459. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
  460. &regval);
  461. if (lock)
  462. regval |= RIO_PORT_N_CTL_LOCKOUT;
  463. else
  464. regval &= ~RIO_PORT_N_CTL_LOCKOUT;
  465. rio_write_config_32(rdev,
  466. rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
  467. regval);
  468. return 0;
  469. }
  470. /**
  471. * rio_chk_dev_route - Validate route to the specified device.
  472. * @rdev: RIO device failed to respond
  473. * @nrdev: Last active device on the route to rdev
  474. * @npnum: nrdev's port number on the route to rdev
  475. *
  476. * Follows a route to the specified RIO device to determine the last available
  477. * device (and corresponding RIO port) on the route.
  478. */
  479. static int
  480. rio_chk_dev_route(struct rio_dev *rdev, struct rio_dev **nrdev, int *npnum)
  481. {
  482. u32 result;
  483. int p_port, rc = -EIO;
  484. struct rio_dev *prev = NULL;
  485. /* Find switch with failed RIO link */
  486. while (rdev->prev && (rdev->prev->pef & RIO_PEF_SWITCH)) {
  487. if (!rio_read_config_32(rdev->prev, RIO_DEV_ID_CAR, &result)) {
  488. prev = rdev->prev;
  489. break;
  490. }
  491. rdev = rdev->prev;
  492. }
  493. if (prev == NULL)
  494. goto err_out;
  495. p_port = prev->rswitch->route_table[rdev->destid];
  496. if (p_port != RIO_INVALID_ROUTE) {
  497. pr_debug("RIO: link failed on [%s]-P%d\n",
  498. rio_name(prev), p_port);
  499. *nrdev = prev;
  500. *npnum = p_port;
  501. rc = 0;
  502. } else
  503. pr_debug("RIO: failed to trace route to %s\n", rio_name(rdev));
  504. err_out:
  505. return rc;
  506. }
  507. /**
  508. * rio_mport_chk_dev_access - Validate access to the specified device.
  509. * @mport: Master port to send transactions
  510. * @destid: Device destination ID in network
  511. * @hopcount: Number of hops into the network
  512. */
  513. int
  514. rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid, u8 hopcount)
  515. {
  516. int i = 0;
  517. u32 tmp;
  518. while (rio_mport_read_config_32(mport, destid, hopcount,
  519. RIO_DEV_ID_CAR, &tmp)) {
  520. i++;
  521. if (i == RIO_MAX_CHK_RETRY)
  522. return -EIO;
  523. mdelay(1);
  524. }
  525. return 0;
  526. }
  527. /**
  528. * rio_chk_dev_access - Validate access to the specified device.
  529. * @rdev: Pointer to RIO device control structure
  530. */
  531. static int rio_chk_dev_access(struct rio_dev *rdev)
  532. {
  533. return rio_mport_chk_dev_access(rdev->net->hport,
  534. rdev->destid, rdev->hopcount);
  535. }
  536. /**
  537. * rio_get_input_status - Sends a Link-Request/Input-Status control symbol and
  538. * returns link-response (if requested).
  539. * @rdev: RIO devive to issue Input-status command
  540. * @pnum: Device port number to issue the command
  541. * @lnkresp: Response from a link partner
  542. */
  543. static int
  544. rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp)
  545. {
  546. u32 regval;
  547. int checkcount;
  548. if (lnkresp) {
  549. /* Read from link maintenance response register
  550. * to clear valid bit */
  551. rio_read_config_32(rdev,
  552. rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
  553. &regval);
  554. udelay(50);
  555. }
  556. /* Issue Input-status command */
  557. rio_write_config_32(rdev,
  558. rdev->phys_efptr + RIO_PORT_N_MNT_REQ_CSR(pnum),
  559. RIO_MNT_REQ_CMD_IS);
  560. /* Exit if the response is not expected */
  561. if (lnkresp == NULL)
  562. return 0;
  563. checkcount = 3;
  564. while (checkcount--) {
  565. udelay(50);
  566. rio_read_config_32(rdev,
  567. rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
  568. &regval);
  569. if (regval & RIO_PORT_N_MNT_RSP_RVAL) {
  570. *lnkresp = regval;
  571. return 0;
  572. }
  573. }
  574. return -EIO;
  575. }
  576. /**
  577. * rio_clr_err_stopped - Clears port Error-stopped states.
  578. * @rdev: Pointer to RIO device control structure
  579. * @pnum: Switch port number to clear errors
  580. * @err_status: port error status (if 0 reads register from device)
  581. */
  582. static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)
  583. {
  584. struct rio_dev *nextdev = rdev->rswitch->nextdev[pnum];
  585. u32 regval;
  586. u32 far_ackid, far_linkstat, near_ackid;
  587. if (err_status == 0)
  588. rio_read_config_32(rdev,
  589. rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
  590. &err_status);
  591. if (err_status & RIO_PORT_N_ERR_STS_PW_OUT_ES) {
  592. pr_debug("RIO_EM: servicing Output Error-Stopped state\n");
  593. /*
  594. * Send a Link-Request/Input-Status control symbol
  595. */
  596. if (rio_get_input_status(rdev, pnum, &regval)) {
  597. pr_debug("RIO_EM: Input-status response timeout\n");
  598. goto rd_err;
  599. }
  600. pr_debug("RIO_EM: SP%d Input-status response=0x%08x\n",
  601. pnum, regval);
  602. far_ackid = (regval & RIO_PORT_N_MNT_RSP_ASTAT) >> 5;
  603. far_linkstat = regval & RIO_PORT_N_MNT_RSP_LSTAT;
  604. rio_read_config_32(rdev,
  605. rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
  606. &regval);
  607. pr_debug("RIO_EM: SP%d_ACK_STS_CSR=0x%08x\n", pnum, regval);
  608. near_ackid = (regval & RIO_PORT_N_ACK_INBOUND) >> 24;
  609. pr_debug("RIO_EM: SP%d far_ackID=0x%02x far_linkstat=0x%02x" \
  610. " near_ackID=0x%02x\n",
  611. pnum, far_ackid, far_linkstat, near_ackid);
  612. /*
  613. * If required, synchronize ackIDs of near and
  614. * far sides.
  615. */
  616. if ((far_ackid != ((regval & RIO_PORT_N_ACK_OUTSTAND) >> 8)) ||
  617. (far_ackid != (regval & RIO_PORT_N_ACK_OUTBOUND))) {
  618. /* Align near outstanding/outbound ackIDs with
  619. * far inbound.
  620. */
  621. rio_write_config_32(rdev,
  622. rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
  623. (near_ackid << 24) |
  624. (far_ackid << 8) | far_ackid);
  625. /* Align far outstanding/outbound ackIDs with
  626. * near inbound.
  627. */
  628. far_ackid++;
  629. if (nextdev)
  630. rio_write_config_32(nextdev,
  631. nextdev->phys_efptr +
  632. RIO_PORT_N_ACK_STS_CSR(RIO_GET_PORT_NUM(nextdev->swpinfo)),
  633. (far_ackid << 24) |
  634. (near_ackid << 8) | near_ackid);
  635. else
  636. pr_debug("RIO_EM: Invalid nextdev pointer (NULL)\n");
  637. }
  638. rd_err:
  639. rio_read_config_32(rdev,
  640. rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
  641. &err_status);
  642. pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
  643. }
  644. if ((err_status & RIO_PORT_N_ERR_STS_PW_INP_ES) && nextdev) {
  645. pr_debug("RIO_EM: servicing Input Error-Stopped state\n");
  646. rio_get_input_status(nextdev,
  647. RIO_GET_PORT_NUM(nextdev->swpinfo), NULL);
  648. udelay(50);
  649. rio_read_config_32(rdev,
  650. rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
  651. &err_status);
  652. pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
  653. }
  654. return (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
  655. RIO_PORT_N_ERR_STS_PW_INP_ES)) ? 1 : 0;
  656. }
  657. /**
  658. * rio_inb_pwrite_handler - process inbound port-write message
  659. * @pw_msg: pointer to inbound port-write message
  660. *
  661. * Processes an inbound port-write message. Returns 0 if the request
  662. * has been satisfied.
  663. */
  664. int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
  665. {
  666. struct rio_dev *rdev;
  667. u32 err_status, em_perrdet, em_ltlerrdet;
  668. int rc, portnum;
  669. rdev = rio_get_comptag((pw_msg->em.comptag & RIO_CTAG_UDEVID), NULL);
  670. if (rdev == NULL) {
  671. /* Device removed or enumeration error */
  672. pr_debug("RIO: %s No matching device for CTag 0x%08x\n",
  673. __func__, pw_msg->em.comptag);
  674. return -EIO;
  675. }
  676. pr_debug("RIO: Port-Write message from %s\n", rio_name(rdev));
  677. #ifdef DEBUG_PW
  678. {
  679. u32 i;
  680. for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32);) {
  681. pr_debug("0x%02x: %08x %08x %08x %08x\n",
  682. i*4, pw_msg->raw[i], pw_msg->raw[i + 1],
  683. pw_msg->raw[i + 2], pw_msg->raw[i + 3]);
  684. i += 4;
  685. }
  686. }
  687. #endif
  688. /* Call an external service function (if such is registered
  689. * for this device). This may be the service for endpoints that send
  690. * device-specific port-write messages. End-point messages expected
  691. * to be handled completely by EP specific device driver.
  692. * For switches rc==0 signals that no standard processing required.
  693. */
  694. if (rdev->pwcback != NULL) {
  695. rc = rdev->pwcback(rdev, pw_msg, 0);
  696. if (rc == 0)
  697. return 0;
  698. }
  699. portnum = pw_msg->em.is_port & 0xFF;
  700. /* Check if device and route to it are functional:
  701. * Sometimes devices may send PW message(s) just before being
  702. * powered down (or link being lost).
  703. */
  704. if (rio_chk_dev_access(rdev)) {
  705. pr_debug("RIO: device access failed - get link partner\n");
  706. /* Scan route to the device and identify failed link.
  707. * This will replace device and port reported in PW message.
  708. * PW message should not be used after this point.
  709. */
  710. if (rio_chk_dev_route(rdev, &rdev, &portnum)) {
  711. pr_err("RIO: Route trace for %s failed\n",
  712. rio_name(rdev));
  713. return -EIO;
  714. }
  715. pw_msg = NULL;
  716. }
  717. /* For End-point devices processing stops here */
  718. if (!(rdev->pef & RIO_PEF_SWITCH))
  719. return 0;
  720. if (rdev->phys_efptr == 0) {
  721. pr_err("RIO_PW: Bad switch initialization for %s\n",
  722. rio_name(rdev));
  723. return 0;
  724. }
  725. /*
  726. * Process the port-write notification from switch
  727. */
  728. if (rdev->rswitch->em_handle)
  729. rdev->rswitch->em_handle(rdev, portnum);
  730. rio_read_config_32(rdev,
  731. rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
  732. &err_status);
  733. pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status);
  734. if (err_status & RIO_PORT_N_ERR_STS_PORT_OK) {
  735. if (!(rdev->rswitch->port_ok & (1 << portnum))) {
  736. rdev->rswitch->port_ok |= (1 << portnum);
  737. rio_set_port_lockout(rdev, portnum, 0);
  738. /* Schedule Insertion Service */
  739. pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n",
  740. rio_name(rdev), portnum);
  741. }
  742. /* Clear error-stopped states (if reported).
  743. * Depending on the link partner state, two attempts
  744. * may be needed for successful recovery.
  745. */
  746. if (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
  747. RIO_PORT_N_ERR_STS_PW_INP_ES)) {
  748. if (rio_clr_err_stopped(rdev, portnum, err_status))
  749. rio_clr_err_stopped(rdev, portnum, 0);
  750. }
  751. } else { /* if (err_status & RIO_PORT_N_ERR_STS_PORT_UNINIT) */
  752. if (rdev->rswitch->port_ok & (1 << portnum)) {
  753. rdev->rswitch->port_ok &= ~(1 << portnum);
  754. rio_set_port_lockout(rdev, portnum, 1);
  755. rio_write_config_32(rdev,
  756. rdev->phys_efptr +
  757. RIO_PORT_N_ACK_STS_CSR(portnum),
  758. RIO_PORT_N_ACK_CLEAR);
  759. /* Schedule Extraction Service */
  760. pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n",
  761. rio_name(rdev), portnum);
  762. }
  763. }
  764. rio_read_config_32(rdev,
  765. rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
  766. if (em_perrdet) {
  767. pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
  768. portnum, em_perrdet);
  769. /* Clear EM Port N Error Detect CSR */
  770. rio_write_config_32(rdev,
  771. rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0);
  772. }
  773. rio_read_config_32(rdev,
  774. rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
  775. if (em_ltlerrdet) {
  776. pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
  777. em_ltlerrdet);
  778. /* Clear EM L/T Layer Error Detect CSR */
  779. rio_write_config_32(rdev,
  780. rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0);
  781. }
  782. /* Clear remaining error bits and Port-Write Pending bit */
  783. rio_write_config_32(rdev,
  784. rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
  785. err_status);
  786. return 0;
  787. }
  788. EXPORT_SYMBOL_GPL(rio_inb_pwrite_handler);
  789. /**
  790. * rio_mport_get_efb - get pointer to next extended features block
  791. * @port: Master port to issue transaction
  792. * @local: Indicate a local master port or remote device access
  793. * @destid: Destination ID of the device
  794. * @hopcount: Number of switch hops to the device
  795. * @from: Offset of current Extended Feature block header (if 0 starts
  796. * from ExtFeaturePtr)
  797. */
  798. u32
  799. rio_mport_get_efb(struct rio_mport *port, int local, u16 destid,
  800. u8 hopcount, u32 from)
  801. {
  802. u32 reg_val;
  803. if (from == 0) {
  804. if (local)
  805. rio_local_read_config_32(port, RIO_ASM_INFO_CAR,
  806. &reg_val);
  807. else
  808. rio_mport_read_config_32(port, destid, hopcount,
  809. RIO_ASM_INFO_CAR, &reg_val);
  810. return reg_val & RIO_EXT_FTR_PTR_MASK;
  811. } else {
  812. if (local)
  813. rio_local_read_config_32(port, from, &reg_val);
  814. else
  815. rio_mport_read_config_32(port, destid, hopcount,
  816. from, &reg_val);
  817. return RIO_GET_BLOCK_ID(reg_val);
  818. }
  819. }
  820. /**
  821. * rio_mport_get_feature - query for devices' extended features
  822. * @port: Master port to issue transaction
  823. * @local: Indicate a local master port or remote device access
  824. * @destid: Destination ID of the device
  825. * @hopcount: Number of switch hops to the device
  826. * @ftr: Extended feature code
  827. *
  828. * Tell if a device supports a given RapidIO capability.
  829. * Returns the offset of the requested extended feature
  830. * block within the device's RIO configuration space or
  831. * 0 in case the device does not support it. Possible
  832. * values for @ftr:
  833. *
  834. * %RIO_EFB_PAR_EP_ID LP/LVDS EP Devices
  835. *
  836. * %RIO_EFB_PAR_EP_REC_ID LP/LVDS EP Recovery Devices
  837. *
  838. * %RIO_EFB_PAR_EP_FREE_ID LP/LVDS EP Free Devices
  839. *
  840. * %RIO_EFB_SER_EP_ID LP/Serial EP Devices
  841. *
  842. * %RIO_EFB_SER_EP_REC_ID LP/Serial EP Recovery Devices
  843. *
  844. * %RIO_EFB_SER_EP_FREE_ID LP/Serial EP Free Devices
  845. */
  846. u32
  847. rio_mport_get_feature(struct rio_mport * port, int local, u16 destid,
  848. u8 hopcount, int ftr)
  849. {
  850. u32 asm_info, ext_ftr_ptr, ftr_header;
  851. if (local)
  852. rio_local_read_config_32(port, RIO_ASM_INFO_CAR, &asm_info);
  853. else
  854. rio_mport_read_config_32(port, destid, hopcount,
  855. RIO_ASM_INFO_CAR, &asm_info);
  856. ext_ftr_ptr = asm_info & RIO_EXT_FTR_PTR_MASK;
  857. while (ext_ftr_ptr) {
  858. if (local)
  859. rio_local_read_config_32(port, ext_ftr_ptr,
  860. &ftr_header);
  861. else
  862. rio_mport_read_config_32(port, destid, hopcount,
  863. ext_ftr_ptr, &ftr_header);
  864. if (RIO_GET_BLOCK_ID(ftr_header) == ftr)
  865. return ext_ftr_ptr;
  866. if (!(ext_ftr_ptr = RIO_GET_BLOCK_PTR(ftr_header)))
  867. break;
  868. }
  869. return 0;
  870. }
  871. /**
  872. * rio_get_asm - Begin or continue searching for a RIO device by vid/did/asm_vid/asm_did
  873. * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
  874. * @did: RIO did to match or %RIO_ANY_ID to match all dids
  875. * @asm_vid: RIO asm_vid to match or %RIO_ANY_ID to match all asm_vids
  876. * @asm_did: RIO asm_did to match or %RIO_ANY_ID to match all asm_dids
  877. * @from: Previous RIO device found in search, or %NULL for new search
  878. *
  879. * Iterates through the list of known RIO devices. If a RIO device is
  880. * found with a matching @vid, @did, @asm_vid, @asm_did, the reference
  881. * count to the device is incrememted and a pointer to its device
  882. * structure is returned. Otherwise, %NULL is returned. A new search
  883. * is initiated by passing %NULL to the @from argument. Otherwise, if
  884. * @from is not %NULL, searches continue from next device on the global
  885. * list. The reference count for @from is always decremented if it is
  886. * not %NULL.
  887. */
  888. struct rio_dev *rio_get_asm(u16 vid, u16 did,
  889. u16 asm_vid, u16 asm_did, struct rio_dev *from)
  890. {
  891. struct list_head *n;
  892. struct rio_dev *rdev;
  893. WARN_ON(in_interrupt());
  894. spin_lock(&rio_global_list_lock);
  895. n = from ? from->global_list.next : rio_devices.next;
  896. while (n && (n != &rio_devices)) {
  897. rdev = rio_dev_g(n);
  898. if ((vid == RIO_ANY_ID || rdev->vid == vid) &&
  899. (did == RIO_ANY_ID || rdev->did == did) &&
  900. (asm_vid == RIO_ANY_ID || rdev->asm_vid == asm_vid) &&
  901. (asm_did == RIO_ANY_ID || rdev->asm_did == asm_did))
  902. goto exit;
  903. n = n->next;
  904. }
  905. rdev = NULL;
  906. exit:
  907. rio_dev_put(from);
  908. rdev = rio_dev_get(rdev);
  909. spin_unlock(&rio_global_list_lock);
  910. return rdev;
  911. }
  912. /**
  913. * rio_get_device - Begin or continue searching for a RIO device by vid/did
  914. * @vid: RIO vid to match or %RIO_ANY_ID to match all vids
  915. * @did: RIO did to match or %RIO_ANY_ID to match all dids
  916. * @from: Previous RIO device found in search, or %NULL for new search
  917. *
  918. * Iterates through the list of known RIO devices. If a RIO device is
  919. * found with a matching @vid and @did, the reference count to the
  920. * device is incrememted and a pointer to its device structure is returned.
  921. * Otherwise, %NULL is returned. A new search is initiated by passing %NULL
  922. * to the @from argument. Otherwise, if @from is not %NULL, searches
  923. * continue from next device on the global list. The reference count for
  924. * @from is always decremented if it is not %NULL.
  925. */
  926. struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from)
  927. {
  928. return rio_get_asm(vid, did, RIO_ANY_ID, RIO_ANY_ID, from);
  929. }
  930. /**
  931. * rio_std_route_add_entry - Add switch route table entry using standard
  932. * registers defined in RIO specification rev.1.3
  933. * @mport: Master port to issue transaction
  934. * @destid: Destination ID of the device
  935. * @hopcount: Number of switch hops to the device
  936. * @table: routing table ID (global or port-specific)
  937. * @route_destid: destID entry in the RT
  938. * @route_port: destination port for specified destID
  939. */
  940. int rio_std_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  941. u16 table, u16 route_destid, u8 route_port)
  942. {
  943. if (table == RIO_GLOBAL_TABLE) {
  944. rio_mport_write_config_32(mport, destid, hopcount,
  945. RIO_STD_RTE_CONF_DESTID_SEL_CSR,
  946. (u32)route_destid);
  947. rio_mport_write_config_32(mport, destid, hopcount,
  948. RIO_STD_RTE_CONF_PORT_SEL_CSR,
  949. (u32)route_port);
  950. }
  951. udelay(10);
  952. return 0;
  953. }
  954. /**
  955. * rio_std_route_get_entry - Read switch route table entry (port number)
  956. * associated with specified destID using standard registers defined in RIO
  957. * specification rev.1.3
  958. * @mport: Master port to issue transaction
  959. * @destid: Destination ID of the device
  960. * @hopcount: Number of switch hops to the device
  961. * @table: routing table ID (global or port-specific)
  962. * @route_destid: destID entry in the RT
  963. * @route_port: returned destination port for specified destID
  964. */
  965. int rio_std_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
  966. u16 table, u16 route_destid, u8 *route_port)
  967. {
  968. u32 result;
  969. if (table == RIO_GLOBAL_TABLE) {
  970. rio_mport_write_config_32(mport, destid, hopcount,
  971. RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
  972. rio_mport_read_config_32(mport, destid, hopcount,
  973. RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
  974. *route_port = (u8)result;
  975. }
  976. return 0;
  977. }
  978. /**
  979. * rio_std_route_clr_table - Clear swotch route table using standard registers
  980. * defined in RIO specification rev.1.3.
  981. * @mport: Master port to issue transaction
  982. * @destid: Destination ID of the device
  983. * @hopcount: Number of switch hops to the device
  984. * @table: routing table ID (global or port-specific)
  985. */
  986. int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
  987. u16 table)
  988. {
  989. u32 max_destid = 0xff;
  990. u32 i, pef, id_inc = 1, ext_cfg = 0;
  991. u32 port_sel = RIO_INVALID_ROUTE;
  992. if (table == RIO_GLOBAL_TABLE) {
  993. rio_mport_read_config_32(mport, destid, hopcount,
  994. RIO_PEF_CAR, &pef);
  995. if (mport->sys_size) {
  996. rio_mport_read_config_32(mport, destid, hopcount,
  997. RIO_SWITCH_RT_LIMIT,
  998. &max_destid);
  999. max_destid &= RIO_RT_MAX_DESTID;
  1000. }
  1001. if (pef & RIO_PEF_EXT_RT) {
  1002. ext_cfg = 0x80000000;
  1003. id_inc = 4;
  1004. port_sel = (RIO_INVALID_ROUTE << 24) |
  1005. (RIO_INVALID_ROUTE << 16) |
  1006. (RIO_INVALID_ROUTE << 8) |
  1007. RIO_INVALID_ROUTE;
  1008. }
  1009. for (i = 0; i <= max_destid;) {
  1010. rio_mport_write_config_32(mport, destid, hopcount,
  1011. RIO_STD_RTE_CONF_DESTID_SEL_CSR,
  1012. ext_cfg | i);
  1013. rio_mport_write_config_32(mport, destid, hopcount,
  1014. RIO_STD_RTE_CONF_PORT_SEL_CSR,
  1015. port_sel);
  1016. i += id_inc;
  1017. }
  1018. }
  1019. udelay(10);
  1020. return 0;
  1021. }
  1022. #ifdef CONFIG_RAPIDIO_DMA_ENGINE
  1023. static bool rio_chan_filter(struct dma_chan *chan, void *arg)
  1024. {
  1025. struct rio_dev *rdev = arg;
  1026. /* Check that DMA device belongs to the right MPORT */
  1027. return (rdev->net->hport ==
  1028. container_of(chan->device, struct rio_mport, dma));
  1029. }
  1030. /**
  1031. * rio_request_dma - request RapidIO capable DMA channel that supports
  1032. * specified target RapidIO device.
  1033. * @rdev: RIO device control structure
  1034. *
  1035. * Returns pointer to allocated DMA channel or NULL if failed.
  1036. */
  1037. struct dma_chan *rio_request_dma(struct rio_dev *rdev)
  1038. {
  1039. dma_cap_mask_t mask;
  1040. struct dma_chan *dchan;
  1041. dma_cap_zero(mask);
  1042. dma_cap_set(DMA_SLAVE, mask);
  1043. dchan = dma_request_channel(mask, rio_chan_filter, rdev);
  1044. return dchan;
  1045. }
  1046. EXPORT_SYMBOL_GPL(rio_request_dma);
  1047. /**
  1048. * rio_release_dma - release specified DMA channel
  1049. * @dchan: DMA channel to release
  1050. */
  1051. void rio_release_dma(struct dma_chan *dchan)
  1052. {
  1053. dma_release_channel(dchan);
  1054. }
  1055. EXPORT_SYMBOL_GPL(rio_release_dma);
  1056. /**
  1057. * rio_dma_prep_slave_sg - RapidIO specific wrapper
  1058. * for device_prep_slave_sg callback defined by DMAENGINE.
  1059. * @rdev: RIO device control structure
  1060. * @dchan: DMA channel to configure
  1061. * @data: RIO specific data descriptor
  1062. * @direction: DMA data transfer direction (TO or FROM the device)
  1063. * @flags: dmaengine defined flags
  1064. *
  1065. * Initializes RapidIO capable DMA channel for the specified data transfer.
  1066. * Uses DMA channel private extension to pass information related to remote
  1067. * target RIO device.
  1068. * Returns pointer to DMA transaction descriptor or NULL if failed.
  1069. */
  1070. struct dma_async_tx_descriptor *rio_dma_prep_slave_sg(struct rio_dev *rdev,
  1071. struct dma_chan *dchan, struct rio_dma_data *data,
  1072. enum dma_transfer_direction direction, unsigned long flags)
  1073. {
  1074. struct dma_async_tx_descriptor *txd = NULL;
  1075. struct rio_dma_ext rio_ext;
  1076. if (dchan->device->device_prep_slave_sg == NULL) {
  1077. pr_err("%s: prep_rio_sg == NULL\n", __func__);
  1078. return NULL;
  1079. }
  1080. rio_ext.destid = rdev->destid;
  1081. rio_ext.rio_addr_u = data->rio_addr_u;
  1082. rio_ext.rio_addr = data->rio_addr;
  1083. rio_ext.wr_type = data->wr_type;
  1084. txd = dmaengine_prep_rio_sg(dchan, data->sg, data->sg_len,
  1085. direction, flags, &rio_ext);
  1086. return txd;
  1087. }
  1088. EXPORT_SYMBOL_GPL(rio_dma_prep_slave_sg);
  1089. #endif /* CONFIG_RAPIDIO_DMA_ENGINE */
  1090. static void rio_fixup_device(struct rio_dev *dev)
  1091. {
  1092. }
  1093. static int __devinit rio_init(void)
  1094. {
  1095. struct rio_dev *dev = NULL;
  1096. while ((dev = rio_get_device(RIO_ANY_ID, RIO_ANY_ID, dev)) != NULL) {
  1097. rio_fixup_device(dev);
  1098. }
  1099. return 0;
  1100. }
  1101. static struct workqueue_struct *rio_wq;
  1102. struct rio_disc_work {
  1103. struct work_struct work;
  1104. struct rio_mport *mport;
  1105. };
  1106. static void __devinit disc_work_handler(struct work_struct *_work)
  1107. {
  1108. struct rio_disc_work *work;
  1109. work = container_of(_work, struct rio_disc_work, work);
  1110. pr_debug("RIO: discovery work for mport %d %s\n",
  1111. work->mport->id, work->mport->name);
  1112. rio_disc_mport(work->mport);
  1113. kfree(work);
  1114. }
  1115. int __devinit rio_init_mports(void)
  1116. {
  1117. struct rio_mport *port;
  1118. struct rio_disc_work *work;
  1119. int no_disc = 0;
  1120. list_for_each_entry(port, &rio_mports, node) {
  1121. if (port->host_deviceid >= 0)
  1122. rio_enum_mport(port);
  1123. else if (!no_disc) {
  1124. if (!rio_wq) {
  1125. rio_wq = alloc_workqueue("riodisc", 0, 0);
  1126. if (!rio_wq) {
  1127. pr_err("RIO: unable allocate rio_wq\n");
  1128. no_disc = 1;
  1129. continue;
  1130. }
  1131. }
  1132. work = kzalloc(sizeof *work, GFP_KERNEL);
  1133. if (!work) {
  1134. pr_err("RIO: no memory for work struct\n");
  1135. no_disc = 1;
  1136. continue;
  1137. }
  1138. work->mport = port;
  1139. INIT_WORK(&work->work, disc_work_handler);
  1140. queue_work(rio_wq, &work->work);
  1141. }
  1142. }
  1143. if (rio_wq) {
  1144. pr_debug("RIO: flush discovery workqueue\n");
  1145. flush_workqueue(rio_wq);
  1146. pr_debug("RIO: flush discovery workqueue finished\n");
  1147. destroy_workqueue(rio_wq);
  1148. }
  1149. rio_init();
  1150. return 0;
  1151. }
  1152. device_initcall_sync(rio_init_mports);
  1153. static int hdids[RIO_MAX_MPORTS + 1];
  1154. static int rio_get_hdid(int index)
  1155. {
  1156. if (!hdids[0] || hdids[0] <= index || index >= RIO_MAX_MPORTS)
  1157. return -1;
  1158. return hdids[index + 1];
  1159. }
  1160. static int rio_hdid_setup(char *str)
  1161. {
  1162. (void)get_options(str, ARRAY_SIZE(hdids), hdids);
  1163. return 1;
  1164. }
  1165. __setup("riohdid=", rio_hdid_setup);
  1166. int rio_register_mport(struct rio_mport *port)
  1167. {
  1168. if (next_portid >= RIO_MAX_MPORTS) {
  1169. pr_err("RIO: reached specified max number of mports\n");
  1170. return 1;
  1171. }
  1172. port->id = next_portid++;
  1173. port->host_deviceid = rio_get_hdid(port->id);
  1174. list_add_tail(&port->node, &rio_mports);
  1175. return 0;
  1176. }
  1177. EXPORT_SYMBOL_GPL(rio_local_get_device_id);
  1178. EXPORT_SYMBOL_GPL(rio_get_device);
  1179. EXPORT_SYMBOL_GPL(rio_get_asm);
  1180. EXPORT_SYMBOL_GPL(rio_request_inb_dbell);
  1181. EXPORT_SYMBOL_GPL(rio_release_inb_dbell);
  1182. EXPORT_SYMBOL_GPL(rio_request_outb_dbell);
  1183. EXPORT_SYMBOL_GPL(rio_release_outb_dbell);
  1184. EXPORT_SYMBOL_GPL(rio_request_inb_mbox);
  1185. EXPORT_SYMBOL_GPL(rio_release_inb_mbox);
  1186. EXPORT_SYMBOL_GPL(rio_request_outb_mbox);
  1187. EXPORT_SYMBOL_GPL(rio_release_outb_mbox);