rio.h 10 KB

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