rio.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #ifndef LINUX_RIO_H
  14. #define LINUX_RIO_H
  15. #include <linux/types.h>
  16. #include <linux/ioport.h>
  17. #include <linux/list.h>
  18. #include <linux/errno.h>
  19. #include <linux/device.h>
  20. #include <linux/rio_regs.h>
  21. #ifdef CONFIG_RAPIDIO_DMA_ENGINE
  22. #include <linux/dmaengine.h>
  23. #endif
  24. #define RIO_NO_HOPCOUNT -1
  25. #define RIO_INVALID_DESTID 0xffff
  26. #define RIO_MAX_MPORTS 8
  27. #define RIO_MAX_MPORT_RESOURCES 16
  28. #define RIO_MAX_DEV_RESOURCES 16
  29. #define RIO_MAX_MPORT_NAME 40
  30. #define RIO_GLOBAL_TABLE 0xff /* Indicates access of a switch's
  31. global routing table if it
  32. has multiple (or per port)
  33. tables */
  34. #define RIO_INVALID_ROUTE 0xff /* Indicates that a route table
  35. entry is invalid (no route
  36. exists for the device ID) */
  37. #define RIO_MAX_ROUTE_ENTRIES(size) (size ? (1 << 16) : (1 << 8))
  38. #define RIO_ANY_DESTID(size) (size ? 0xffff : 0xff)
  39. #define RIO_MAX_MBOX 4
  40. #define RIO_MAX_MSG_SIZE 0x1000
  41. /*
  42. * Error values that may be returned by RIO functions.
  43. */
  44. #define RIO_SUCCESSFUL 0x00
  45. #define RIO_BAD_SIZE 0x81
  46. /*
  47. * For RIO devices, the region numbers are assigned this way:
  48. *
  49. * 0 RapidIO outbound doorbells
  50. * 1-15 RapidIO memory regions
  51. *
  52. * For RIO master ports, the region number are assigned this way:
  53. *
  54. * 0 RapidIO inbound doorbells
  55. * 1 RapidIO inbound mailboxes
  56. * 2 RapidIO outbound mailboxes
  57. */
  58. #define RIO_DOORBELL_RESOURCE 0
  59. #define RIO_INB_MBOX_RESOURCE 1
  60. #define RIO_OUTB_MBOX_RESOURCE 2
  61. #define RIO_PW_MSG_SIZE 64
  62. /*
  63. * A component tag value (stored in the component tag CSR) is used as device's
  64. * unique identifier assigned during enumeration. Besides being used for
  65. * identifying switches (which do not have device ID register), it also is used
  66. * by error management notification and therefore has to be assigned
  67. * to endpoints as well.
  68. */
  69. #define RIO_CTAG_RESRVD 0xfffe0000 /* Reserved */
  70. #define RIO_CTAG_UDEVID 0x0001ffff /* Unique device identifier */
  71. extern struct bus_type rio_bus_type;
  72. extern struct device rio_bus;
  73. struct rio_mport;
  74. struct rio_dev;
  75. union rio_pw_msg;
  76. /**
  77. * struct rio_switch - RIO switch info
  78. * @node: Node in global list of switches
  79. * @switchid: Switch ID that is unique across a network
  80. * @route_table: Copy of switch routing table
  81. * @port_ok: Status of each port (one bit per port) - OK=1 or UNINIT=0
  82. * @add_entry: Callback for switch-specific route add function
  83. * @get_entry: Callback for switch-specific route get function
  84. * @clr_table: Callback for switch-specific clear route table function
  85. * @set_domain: Callback for switch-specific domain setting function
  86. * @get_domain: Callback for switch-specific domain get function
  87. * @em_init: Callback for switch-specific error management init function
  88. * @em_handle: Callback for switch-specific error management handler function
  89. * @sw_sysfs: Callback that initializes switch-specific sysfs attributes
  90. * @nextdev: Array of per-port pointers to the next attached device
  91. */
  92. struct rio_switch {
  93. struct list_head node;
  94. u16 switchid;
  95. u8 *route_table;
  96. u32 port_ok;
  97. int (*add_entry) (struct rio_mport *mport, u16 destid, u8 hopcount,
  98. u16 table, u16 route_destid, u8 route_port);
  99. int (*get_entry) (struct rio_mport *mport, u16 destid, u8 hopcount,
  100. u16 table, u16 route_destid, u8 *route_port);
  101. int (*clr_table) (struct rio_mport *mport, u16 destid, u8 hopcount,
  102. u16 table);
  103. int (*set_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
  104. u8 sw_domain);
  105. int (*get_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
  106. u8 *sw_domain);
  107. int (*em_init) (struct rio_dev *dev);
  108. int (*em_handle) (struct rio_dev *dev, u8 swport);
  109. int (*sw_sysfs) (struct rio_dev *dev, int create);
  110. struct rio_dev *nextdev[0];
  111. };
  112. /**
  113. * struct rio_dev - RIO device info
  114. * @global_list: Node in list of all RIO devices
  115. * @net_list: Node in list of RIO devices in a network
  116. * @net: Network this device is a part of
  117. * @did: Device ID
  118. * @vid: Vendor ID
  119. * @device_rev: Device revision
  120. * @asm_did: Assembly device ID
  121. * @asm_vid: Assembly vendor ID
  122. * @asm_rev: Assembly revision
  123. * @efptr: Extended feature pointer
  124. * @pef: Processing element features
  125. * @swpinfo: Switch port info
  126. * @src_ops: Source operation capabilities
  127. * @dst_ops: Destination operation capabilities
  128. * @comp_tag: RIO component tag
  129. * @phys_efptr: RIO device extended features pointer
  130. * @em_efptr: RIO Error Management features pointer
  131. * @dma_mask: Mask of bits of RIO address this device implements
  132. * @driver: Driver claiming this device
  133. * @dev: Device model device
  134. * @riores: RIO resources this device owns
  135. * @pwcback: port-write callback function for this device
  136. * @destid: Network destination ID (or associated destid for switch)
  137. * @hopcount: Hopcount to this device
  138. * @prev: Previous RIO device connected to the current one
  139. * @rswitch: struct rio_switch (if valid for this device)
  140. */
  141. struct rio_dev {
  142. struct list_head global_list; /* node in list of all RIO devices */
  143. struct list_head net_list; /* node in per net list */
  144. struct rio_net *net; /* RIO net this device resides in */
  145. u16 did;
  146. u16 vid;
  147. u32 device_rev;
  148. u16 asm_did;
  149. u16 asm_vid;
  150. u16 asm_rev;
  151. u16 efptr;
  152. u32 pef;
  153. u32 swpinfo;
  154. u32 src_ops;
  155. u32 dst_ops;
  156. u32 comp_tag;
  157. u32 phys_efptr;
  158. u32 em_efptr;
  159. u64 dma_mask;
  160. struct rio_driver *driver; /* RIO driver claiming this device */
  161. struct device dev; /* LDM device structure */
  162. struct resource riores[RIO_MAX_DEV_RESOURCES];
  163. int (*pwcback) (struct rio_dev *rdev, union rio_pw_msg *msg, int step);
  164. u16 destid;
  165. u8 hopcount;
  166. struct rio_dev *prev;
  167. struct rio_switch rswitch[0]; /* RIO switch info */
  168. };
  169. #define rio_dev_g(n) list_entry(n, struct rio_dev, global_list)
  170. #define rio_dev_f(n) list_entry(n, struct rio_dev, net_list)
  171. #define to_rio_dev(n) container_of(n, struct rio_dev, dev)
  172. #define sw_to_rio_dev(n) container_of(n, struct rio_dev, rswitch[0])
  173. /**
  174. * struct rio_msg - RIO message event
  175. * @res: Mailbox resource
  176. * @mcback: Message event callback
  177. */
  178. struct rio_msg {
  179. struct resource *res;
  180. void (*mcback) (struct rio_mport * mport, void *dev_id, int mbox, int slot);
  181. };
  182. /**
  183. * struct rio_dbell - RIO doorbell event
  184. * @node: Node in list of doorbell events
  185. * @res: Doorbell resource
  186. * @dinb: Doorbell event callback
  187. * @dev_id: Device specific pointer to pass on event
  188. */
  189. struct rio_dbell {
  190. struct list_head node;
  191. struct resource *res;
  192. void (*dinb) (struct rio_mport *mport, void *dev_id, u16 src, u16 dst, u16 info);
  193. void *dev_id;
  194. };
  195. enum rio_phy_type {
  196. RIO_PHY_PARALLEL,
  197. RIO_PHY_SERIAL,
  198. };
  199. /**
  200. * struct rio_mport - RIO master port info
  201. * @dbells: List of doorbell events
  202. * @node: Node in global list of master ports
  203. * @nnode: Node in network list of master ports
  204. * @iores: I/O mem resource that this master port interface owns
  205. * @riores: RIO resources that this master port interfaces owns
  206. * @inb_msg: RIO inbound message event descriptors
  207. * @outb_msg: RIO outbound message event descriptors
  208. * @host_deviceid: Host device ID associated with this master port
  209. * @ops: configuration space functions
  210. * @id: Port ID, unique among all ports
  211. * @index: Port index, unique among all port interfaces of the same type
  212. * @sys_size: RapidIO common transport system size
  213. * @phy_type: RapidIO phy type
  214. * @phys_efptr: RIO port extended features pointer
  215. * @name: Port name string
  216. * @priv: Master port private data
  217. * @dma: DMA device associated with mport
  218. * @nscan: RapidIO network enumeration/discovery operations
  219. */
  220. struct rio_mport {
  221. struct list_head dbells; /* list of doorbell events */
  222. struct list_head node; /* node in global list of ports */
  223. struct list_head nnode; /* node in net list of ports */
  224. struct resource iores;
  225. struct resource riores[RIO_MAX_MPORT_RESOURCES];
  226. struct rio_msg inb_msg[RIO_MAX_MBOX];
  227. struct rio_msg outb_msg[RIO_MAX_MBOX];
  228. int host_deviceid; /* Host device ID */
  229. struct rio_ops *ops; /* low-level architecture-dependent routines */
  230. unsigned char id; /* port ID, unique among all ports */
  231. unsigned char index; /* port index, unique among all port
  232. interfaces of the same type */
  233. unsigned int sys_size; /* RapidIO common transport system size.
  234. * 0 - Small size. 256 devices.
  235. * 1 - Large size, 65536 devices.
  236. */
  237. enum rio_phy_type phy_type; /* RapidIO phy type */
  238. u32 phys_efptr;
  239. unsigned char name[RIO_MAX_MPORT_NAME];
  240. void *priv; /* Master port private data */
  241. #ifdef CONFIG_RAPIDIO_DMA_ENGINE
  242. struct dma_device dma;
  243. #endif
  244. struct rio_scan *nscan;
  245. };
  246. /*
  247. * Enumeration/discovery control flags
  248. */
  249. #define RIO_SCAN_ENUM_NO_WAIT 0x00000001 /* Do not wait for enum completed */
  250. struct rio_id_table {
  251. u16 start; /* logical minimal id */
  252. u32 max; /* max number of IDs in table */
  253. spinlock_t lock;
  254. unsigned long *table;
  255. };
  256. /**
  257. * struct rio_net - RIO network info
  258. * @node: Node in global list of RIO networks
  259. * @devices: List of devices in this network
  260. * @switches: List of switches in this netowrk
  261. * @mports: List of master ports accessing this network
  262. * @hport: Default port for accessing this network
  263. * @id: RIO network ID
  264. * @destid_table: destID allocation table
  265. */
  266. struct rio_net {
  267. struct list_head node; /* node in list of networks */
  268. struct list_head devices; /* list of devices in this net */
  269. struct list_head switches; /* list of switches in this net */
  270. struct list_head mports; /* list of ports accessing net */
  271. struct rio_mport *hport; /* primary port for accessing net */
  272. unsigned char id; /* RIO network ID */
  273. struct rio_id_table destid_table; /* destID allocation table */
  274. };
  275. /* Definitions used by switch sysfs initialization callback */
  276. #define RIO_SW_SYSFS_CREATE 1 /* Create switch attributes */
  277. #define RIO_SW_SYSFS_REMOVE 0 /* Remove switch attributes */
  278. /* Low-level architecture-dependent routines */
  279. /**
  280. * struct rio_ops - Low-level RIO configuration space operations
  281. * @lcread: Callback to perform local (master port) read of config space.
  282. * @lcwrite: Callback to perform local (master port) write of config space.
  283. * @cread: Callback to perform network read of config space.
  284. * @cwrite: Callback to perform network write of config space.
  285. * @dsend: Callback to send a doorbell message.
  286. * @pwenable: Callback to enable/disable port-write message handling.
  287. * @open_outb_mbox: Callback to initialize outbound mailbox.
  288. * @close_outb_mbox: Callback to shut down outbound mailbox.
  289. * @open_inb_mbox: Callback to initialize inbound mailbox.
  290. * @close_inb_mbox: Callback to shut down inbound mailbox.
  291. * @add_outb_message: Callback to add a message to an outbound mailbox queue.
  292. * @add_inb_buffer: Callback to add a buffer to an inbound mailbox queue.
  293. * @get_inb_message: Callback to get a message from an inbound mailbox queue.
  294. * @map_inb: Callback to map RapidIO address region into local memory space.
  295. * @unmap_inb: Callback to unmap RapidIO address region mapped with map_inb().
  296. */
  297. struct rio_ops {
  298. int (*lcread) (struct rio_mport *mport, int index, u32 offset, int len,
  299. u32 *data);
  300. int (*lcwrite) (struct rio_mport *mport, int index, u32 offset, int len,
  301. u32 data);
  302. int (*cread) (struct rio_mport *mport, int index, u16 destid,
  303. u8 hopcount, u32 offset, int len, u32 *data);
  304. int (*cwrite) (struct rio_mport *mport, int index, u16 destid,
  305. u8 hopcount, u32 offset, int len, u32 data);
  306. int (*dsend) (struct rio_mport *mport, int index, u16 destid, u16 data);
  307. int (*pwenable) (struct rio_mport *mport, int enable);
  308. int (*open_outb_mbox)(struct rio_mport *mport, void *dev_id,
  309. int mbox, int entries);
  310. void (*close_outb_mbox)(struct rio_mport *mport, int mbox);
  311. int (*open_inb_mbox)(struct rio_mport *mport, void *dev_id,
  312. int mbox, int entries);
  313. void (*close_inb_mbox)(struct rio_mport *mport, int mbox);
  314. int (*add_outb_message)(struct rio_mport *mport, struct rio_dev *rdev,
  315. int mbox, void *buffer, size_t len);
  316. int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
  317. void *(*get_inb_message)(struct rio_mport *mport, int mbox);
  318. int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
  319. u64 rstart, u32 size, u32 flags);
  320. void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
  321. };
  322. #define RIO_RESOURCE_MEM 0x00000100
  323. #define RIO_RESOURCE_DOORBELL 0x00000200
  324. #define RIO_RESOURCE_MAILBOX 0x00000400
  325. #define RIO_RESOURCE_CACHEABLE 0x00010000
  326. #define RIO_RESOURCE_PCI 0x00020000
  327. #define RIO_RESOURCE_BUSY 0x80000000
  328. /**
  329. * struct rio_driver - RIO driver info
  330. * @node: Node in list of drivers
  331. * @name: RIO driver name
  332. * @id_table: RIO device ids to be associated with this driver
  333. * @probe: RIO device inserted
  334. * @remove: RIO device removed
  335. * @suspend: RIO device suspended
  336. * @resume: RIO device awakened
  337. * @enable_wake: RIO device enable wake event
  338. * @driver: LDM driver struct
  339. *
  340. * Provides info on a RIO device driver for insertion/removal and
  341. * power management purposes.
  342. */
  343. struct rio_driver {
  344. struct list_head node;
  345. char *name;
  346. const struct rio_device_id *id_table;
  347. int (*probe) (struct rio_dev * dev, const struct rio_device_id * id);
  348. void (*remove) (struct rio_dev * dev);
  349. int (*suspend) (struct rio_dev * dev, u32 state);
  350. int (*resume) (struct rio_dev * dev);
  351. int (*enable_wake) (struct rio_dev * dev, u32 state, int enable);
  352. struct device_driver driver;
  353. };
  354. #define to_rio_driver(drv) container_of(drv,struct rio_driver, driver)
  355. /**
  356. * struct rio_device_id - RIO device identifier
  357. * @did: RIO device ID
  358. * @vid: RIO vendor ID
  359. * @asm_did: RIO assembly device ID
  360. * @asm_vid: RIO assembly vendor ID
  361. *
  362. * Identifies a RIO device based on both the device/vendor IDs and
  363. * the assembly device/vendor IDs.
  364. */
  365. struct rio_device_id {
  366. u16 did, vid;
  367. u16 asm_did, asm_vid;
  368. };
  369. /**
  370. * struct rio_switch_ops - Per-switch operations
  371. * @vid: RIO vendor ID
  372. * @did: RIO device ID
  373. * @init_hook: Callback that performs switch device initialization
  374. *
  375. * Defines the operations that are necessary to initialize/control
  376. * a particular RIO switch device.
  377. */
  378. struct rio_switch_ops {
  379. u16 vid, did;
  380. int (*init_hook) (struct rio_dev *rdev, int do_enum);
  381. };
  382. union rio_pw_msg {
  383. struct {
  384. u32 comptag; /* Component Tag CSR */
  385. u32 errdetect; /* Port N Error Detect CSR */
  386. u32 is_port; /* Implementation specific + PortID */
  387. u32 ltlerrdet; /* LTL Error Detect CSR */
  388. u32 padding[12];
  389. } em;
  390. u32 raw[RIO_PW_MSG_SIZE/sizeof(u32)];
  391. };
  392. #ifdef CONFIG_RAPIDIO_DMA_ENGINE
  393. /*
  394. * enum rio_write_type - RIO write transaction types used in DMA transfers
  395. *
  396. * Note: RapidIO specification defines write (NWRITE) and
  397. * write-with-response (NWRITE_R) data transfer operations.
  398. * Existing DMA controllers that service RapidIO may use one of these operations
  399. * for entire data transfer or their combination with only the last data packet
  400. * requires response.
  401. */
  402. enum rio_write_type {
  403. RDW_DEFAULT, /* default method used by DMA driver */
  404. RDW_ALL_NWRITE, /* all packets use NWRITE */
  405. RDW_ALL_NWRITE_R, /* all packets use NWRITE_R */
  406. RDW_LAST_NWRITE_R, /* last packet uses NWRITE_R, others - NWRITE */
  407. };
  408. struct rio_dma_ext {
  409. u16 destid;
  410. u64 rio_addr; /* low 64-bits of 66-bit RapidIO address */
  411. u8 rio_addr_u; /* upper 2-bits of 66-bit RapidIO address */
  412. enum rio_write_type wr_type; /* preferred RIO write operation type */
  413. };
  414. struct rio_dma_data {
  415. /* Local data (as scatterlist) */
  416. struct scatterlist *sg; /* I/O scatter list */
  417. unsigned int sg_len; /* size of scatter list */
  418. /* Remote device address (flat buffer) */
  419. u64 rio_addr; /* low 64-bits of 66-bit RapidIO address */
  420. u8 rio_addr_u; /* upper 2-bits of 66-bit RapidIO address */
  421. enum rio_write_type wr_type; /* preferred RIO write operation type */
  422. };
  423. static inline struct rio_mport *dma_to_mport(struct dma_device *ddev)
  424. {
  425. return container_of(ddev, struct rio_mport, dma);
  426. }
  427. #endif /* CONFIG_RAPIDIO_DMA_ENGINE */
  428. /**
  429. * struct rio_scan - RIO enumeration and discovery operations
  430. * @enumerate: Callback to perform RapidIO fabric enumeration.
  431. * @discover: Callback to perform RapidIO fabric discovery.
  432. */
  433. struct rio_scan {
  434. int (*enumerate)(struct rio_mport *mport, u32 flags);
  435. int (*discover)(struct rio_mport *mport, u32 flags);
  436. };
  437. /* Architecture and hardware-specific functions */
  438. extern int rio_register_mport(struct rio_mport *);
  439. extern int rio_open_inb_mbox(struct rio_mport *, void *, int, int);
  440. extern void rio_close_inb_mbox(struct rio_mport *, int);
  441. extern int rio_open_outb_mbox(struct rio_mport *, void *, int, int);
  442. extern void rio_close_outb_mbox(struct rio_mport *, int);
  443. #endif /* LINUX_RIO_H */