rio.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. #define RIO_NO_HOPCOUNT -1
  22. #define RIO_INVALID_DESTID 0xffff
  23. #define RIO_MAX_MPORT_RESOURCES 16
  24. #define RIO_MAX_DEV_RESOURCES 16
  25. #define RIO_GLOBAL_TABLE 0xff /* Indicates access of a switch's
  26. global routing table if it
  27. has multiple (or per port)
  28. tables */
  29. #define RIO_INVALID_ROUTE 0xff /* Indicates that a route table
  30. entry is invalid (no route
  31. exists for the device ID) */
  32. #define RIO_MAX_ROUTE_ENTRIES(size) (size ? (1 << 16) : (1 << 8))
  33. #define RIO_ANY_DESTID(size) (size ? 0xffff : 0xff)
  34. #define RIO_MAX_MBOX 4
  35. #define RIO_MAX_MSG_SIZE 0x1000
  36. /*
  37. * Error values that may be returned by RIO functions.
  38. */
  39. #define RIO_SUCCESSFUL 0x00
  40. #define RIO_BAD_SIZE 0x81
  41. /*
  42. * For RIO devices, the region numbers are assigned this way:
  43. *
  44. * 0 RapidIO outbound doorbells
  45. * 1-15 RapidIO memory regions
  46. *
  47. * For RIO master ports, the region number are assigned this way:
  48. *
  49. * 0 RapidIO inbound doorbells
  50. * 1 RapidIO inbound mailboxes
  51. * 1 RapidIO outbound mailboxes
  52. */
  53. #define RIO_DOORBELL_RESOURCE 0
  54. #define RIO_INB_MBOX_RESOURCE 1
  55. #define RIO_OUTB_MBOX_RESOURCE 2
  56. extern struct bus_type rio_bus_type;
  57. extern struct list_head rio_devices; /* list of all devices */
  58. struct rio_mport;
  59. /**
  60. * struct rio_dev - RIO device info
  61. * @global_list: Node in list of all RIO devices
  62. * @net_list: Node in list of RIO devices in a network
  63. * @net: Network this device is a part of
  64. * @did: Device ID
  65. * @vid: Vendor ID
  66. * @device_rev: Device revision
  67. * @asm_did: Assembly device ID
  68. * @asm_vid: Assembly vendor ID
  69. * @asm_rev: Assembly revision
  70. * @efptr: Extended feature pointer
  71. * @pef: Processing element features
  72. * @swpinfo: Switch port info
  73. * @src_ops: Source operation capabilities
  74. * @dst_ops: Destination operation capabilities
  75. * @dma_mask: Mask of bits of RIO address this device implements
  76. * @rswitch: Pointer to &struct rio_switch if valid for this device
  77. * @driver: Driver claiming this device
  78. * @dev: Device model device
  79. * @riores: RIO resources this device owns
  80. * @destid: Network destination ID
  81. */
  82. struct rio_dev {
  83. struct list_head global_list; /* node in list of all RIO devices */
  84. struct list_head net_list; /* node in per net list */
  85. struct rio_net *net; /* RIO net this device resides in */
  86. u16 did;
  87. u16 vid;
  88. u32 device_rev;
  89. u16 asm_did;
  90. u16 asm_vid;
  91. u16 asm_rev;
  92. u16 efptr;
  93. u32 pef;
  94. u32 swpinfo; /* Only used for switches */
  95. u32 src_ops;
  96. u32 dst_ops;
  97. u64 dma_mask;
  98. struct rio_switch *rswitch; /* RIO switch info */
  99. struct rio_driver *driver; /* RIO driver claiming this device */
  100. struct device dev; /* LDM device structure */
  101. struct resource riores[RIO_MAX_DEV_RESOURCES];
  102. u16 destid;
  103. };
  104. #define rio_dev_g(n) list_entry(n, struct rio_dev, global_list)
  105. #define rio_dev_f(n) list_entry(n, struct rio_dev, net_list)
  106. #define to_rio_dev(n) container_of(n, struct rio_dev, dev)
  107. /**
  108. * struct rio_msg - RIO message event
  109. * @res: Mailbox resource
  110. * @mcback: Message event callback
  111. */
  112. struct rio_msg {
  113. struct resource *res;
  114. void (*mcback) (struct rio_mport * mport, void *dev_id, int mbox, int slot);
  115. };
  116. /**
  117. * struct rio_dbell - RIO doorbell event
  118. * @node: Node in list of doorbell events
  119. * @res: Doorbell resource
  120. * @dinb: Doorbell event callback
  121. * @dev_id: Device specific pointer to pass on event
  122. */
  123. struct rio_dbell {
  124. struct list_head node;
  125. struct resource *res;
  126. void (*dinb) (struct rio_mport *mport, void *dev_id, u16 src, u16 dst, u16 info);
  127. void *dev_id;
  128. };
  129. enum rio_phy_type {
  130. RIO_PHY_PARALLEL,
  131. RIO_PHY_SERIAL,
  132. };
  133. /**
  134. * struct rio_mport - RIO master port info
  135. * @dbells: List of doorbell events
  136. * @node: Node in global list of master ports
  137. * @nnode: Node in network list of master ports
  138. * @iores: I/O mem resource that this master port interface owns
  139. * @riores: RIO resources that this master port interfaces owns
  140. * @inb_msg: RIO inbound message event descriptors
  141. * @outb_msg: RIO outbound message event descriptors
  142. * @host_deviceid: Host device ID associated with this master port
  143. * @ops: configuration space functions
  144. * @id: Port ID, unique among all ports
  145. * @index: Port index, unique among all port interfaces of the same type
  146. * @sys_size: RapidIO common transport system size
  147. * @phy_type: RapidIO phy type
  148. * @name: Port name string
  149. * @priv: Master port private data
  150. */
  151. struct rio_mport {
  152. struct list_head dbells; /* list of doorbell events */
  153. struct list_head node; /* node in global list of ports */
  154. struct list_head nnode; /* node in net list of ports */
  155. struct resource iores;
  156. struct resource riores[RIO_MAX_MPORT_RESOURCES];
  157. struct rio_msg inb_msg[RIO_MAX_MBOX];
  158. struct rio_msg outb_msg[RIO_MAX_MBOX];
  159. int host_deviceid; /* Host device ID */
  160. struct rio_ops *ops; /* maintenance transaction functions */
  161. unsigned char id; /* port ID, unique among all ports */
  162. unsigned char index; /* port index, unique among all port
  163. interfaces of the same type */
  164. unsigned int sys_size; /* RapidIO common transport system size.
  165. * 0 - Small size. 256 devices.
  166. * 1 - Large size, 65536 devices.
  167. */
  168. enum rio_phy_type phy_type; /* RapidIO phy type */
  169. unsigned char name[40];
  170. void *priv; /* Master port private data */
  171. };
  172. /**
  173. * struct rio_net - RIO network info
  174. * @node: Node in global list of RIO networks
  175. * @devices: List of devices in this network
  176. * @mports: List of master ports accessing this network
  177. * @hport: Default port for accessing this network
  178. * @id: RIO network ID
  179. */
  180. struct rio_net {
  181. struct list_head node; /* node in list of networks */
  182. struct list_head devices; /* list of devices in this net */
  183. struct list_head mports; /* list of ports accessing net */
  184. struct rio_mport *hport; /* primary port for accessing net */
  185. unsigned char id; /* RIO network ID */
  186. };
  187. /**
  188. * struct rio_switch - RIO switch info
  189. * @node: Node in global list of switches
  190. * @switchid: Switch ID that is unique across a network
  191. * @hopcount: Hopcount to this switch
  192. * @destid: Associated destid in the path
  193. * @route_table: Copy of switch routing table
  194. * @add_entry: Callback for switch-specific route add function
  195. * @get_entry: Callback for switch-specific route get function
  196. */
  197. struct rio_switch {
  198. struct list_head node;
  199. u16 switchid;
  200. u16 hopcount;
  201. u16 destid;
  202. u8 *route_table;
  203. int (*add_entry) (struct rio_mport * mport, u16 destid, u8 hopcount,
  204. u16 table, u16 route_destid, u8 route_port);
  205. int (*get_entry) (struct rio_mport * mport, u16 destid, u8 hopcount,
  206. u16 table, u16 route_destid, u8 * route_port);
  207. };
  208. /* Low-level architecture-dependent routines */
  209. /**
  210. * struct rio_ops - Low-level RIO configuration space operations
  211. * @lcread: Callback to perform local (master port) read of config space.
  212. * @lcwrite: Callback to perform local (master port) write of config space.
  213. * @cread: Callback to perform network read of config space.
  214. * @cwrite: Callback to perform network write of config space.
  215. * @dsend: Callback to send a doorbell message.
  216. */
  217. struct rio_ops {
  218. int (*lcread) (struct rio_mport *mport, int index, u32 offset, int len,
  219. u32 *data);
  220. int (*lcwrite) (struct rio_mport *mport, int index, u32 offset, int len,
  221. u32 data);
  222. int (*cread) (struct rio_mport *mport, int index, u16 destid,
  223. u8 hopcount, u32 offset, int len, u32 *data);
  224. int (*cwrite) (struct rio_mport *mport, int index, u16 destid,
  225. u8 hopcount, u32 offset, int len, u32 data);
  226. int (*dsend) (struct rio_mport *mport, int index, u16 destid, u16 data);
  227. };
  228. #define RIO_RESOURCE_MEM 0x00000100
  229. #define RIO_RESOURCE_DOORBELL 0x00000200
  230. #define RIO_RESOURCE_MAILBOX 0x00000400
  231. #define RIO_RESOURCE_CACHEABLE 0x00010000
  232. #define RIO_RESOURCE_PCI 0x00020000
  233. #define RIO_RESOURCE_BUSY 0x80000000
  234. /**
  235. * struct rio_driver - RIO driver info
  236. * @node: Node in list of drivers
  237. * @name: RIO driver name
  238. * @id_table: RIO device ids to be associated with this driver
  239. * @probe: RIO device inserted
  240. * @remove: RIO device removed
  241. * @suspend: RIO device suspended
  242. * @resume: RIO device awakened
  243. * @enable_wake: RIO device enable wake event
  244. * @driver: LDM driver struct
  245. *
  246. * Provides info on a RIO device driver for insertion/removal and
  247. * power management purposes.
  248. */
  249. struct rio_driver {
  250. struct list_head node;
  251. char *name;
  252. const struct rio_device_id *id_table;
  253. int (*probe) (struct rio_dev * dev, const struct rio_device_id * id);
  254. void (*remove) (struct rio_dev * dev);
  255. int (*suspend) (struct rio_dev * dev, u32 state);
  256. int (*resume) (struct rio_dev * dev);
  257. int (*enable_wake) (struct rio_dev * dev, u32 state, int enable);
  258. struct device_driver driver;
  259. };
  260. #define to_rio_driver(drv) container_of(drv,struct rio_driver, driver)
  261. /**
  262. * struct rio_device_id - RIO device identifier
  263. * @did: RIO device ID
  264. * @vid: RIO vendor ID
  265. * @asm_did: RIO assembly device ID
  266. * @asm_vid: RIO assembly vendor ID
  267. *
  268. * Identifies a RIO device based on both the device/vendor IDs and
  269. * the assembly device/vendor IDs.
  270. */
  271. struct rio_device_id {
  272. u16 did, vid;
  273. u16 asm_did, asm_vid;
  274. };
  275. /**
  276. * struct rio_route_ops - Per-switch route operations
  277. * @vid: RIO vendor ID
  278. * @did: RIO device ID
  279. * @add_hook: Callback that adds a route entry
  280. * @get_hook: Callback that gets a route entry
  281. *
  282. * Defines the operations that are necessary to manipulate the route
  283. * tables for a particular RIO switch device.
  284. */
  285. struct rio_route_ops {
  286. u16 vid, did;
  287. int (*add_hook) (struct rio_mport * mport, u16 destid, u8 hopcount,
  288. u16 table, u16 route_destid, u8 route_port);
  289. int (*get_hook) (struct rio_mport * mport, u16 destid, u8 hopcount,
  290. u16 table, u16 route_destid, u8 * route_port);
  291. };
  292. /* Architecture and hardware-specific functions */
  293. extern int rio_init_mports(void);
  294. extern void rio_register_mport(struct rio_mport *);
  295. extern int rio_hw_add_outb_message(struct rio_mport *, struct rio_dev *, int,
  296. void *, size_t);
  297. extern int rio_hw_add_inb_buffer(struct rio_mport *, int, void *);
  298. extern void *rio_hw_get_inb_message(struct rio_mport *, int);
  299. extern int rio_open_inb_mbox(struct rio_mport *, void *, int, int);
  300. extern void rio_close_inb_mbox(struct rio_mport *, int);
  301. extern int rio_open_outb_mbox(struct rio_mport *, void *, int, int);
  302. extern void rio_close_outb_mbox(struct rio_mport *, int);
  303. #endif /* LINUX_RIO_H */