rio.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. #define RIO_PW_MSG_SIZE 64
  57. extern struct bus_type rio_bus_type;
  58. extern struct device rio_bus;
  59. extern struct list_head rio_devices; /* list of all devices */
  60. struct rio_mport;
  61. union rio_pw_msg;
  62. /**
  63. * struct rio_dev - RIO device info
  64. * @global_list: Node in list of all RIO devices
  65. * @net_list: Node in list of RIO devices in a network
  66. * @net: Network this device is a part of
  67. * @did: Device ID
  68. * @vid: Vendor ID
  69. * @device_rev: Device revision
  70. * @asm_did: Assembly device ID
  71. * @asm_vid: Assembly vendor ID
  72. * @asm_rev: Assembly revision
  73. * @efptr: Extended feature pointer
  74. * @pef: Processing element features
  75. * @swpinfo: Switch port info
  76. * @src_ops: Source operation capabilities
  77. * @dst_ops: Destination operation capabilities
  78. * @comp_tag: RIO component tag
  79. * @phys_efptr: RIO device extended features pointer
  80. * @em_efptr: RIO Error Management features pointer
  81. * @dma_mask: Mask of bits of RIO address this device implements
  82. * @rswitch: Pointer to &struct rio_switch if valid for this device
  83. * @driver: Driver claiming this device
  84. * @dev: Device model device
  85. * @riores: RIO resources this device owns
  86. * @pwcback: port-write callback function for this device
  87. * @destid: Network destination ID
  88. */
  89. struct rio_dev {
  90. struct list_head global_list; /* node in list of all RIO devices */
  91. struct list_head net_list; /* node in per net list */
  92. struct rio_net *net; /* RIO net this device resides in */
  93. u16 did;
  94. u16 vid;
  95. u32 device_rev;
  96. u16 asm_did;
  97. u16 asm_vid;
  98. u16 asm_rev;
  99. u16 efptr;
  100. u32 pef;
  101. u32 swpinfo; /* Only used for switches */
  102. u32 src_ops;
  103. u32 dst_ops;
  104. u32 comp_tag;
  105. u32 phys_efptr;
  106. u32 em_efptr;
  107. u64 dma_mask;
  108. struct rio_switch *rswitch; /* RIO switch info */
  109. struct rio_driver *driver; /* RIO driver claiming this device */
  110. struct device dev; /* LDM device structure */
  111. struct resource riores[RIO_MAX_DEV_RESOURCES];
  112. int (*pwcback) (struct rio_dev *rdev, union rio_pw_msg *msg, int step);
  113. u16 destid;
  114. };
  115. #define rio_dev_g(n) list_entry(n, struct rio_dev, global_list)
  116. #define rio_dev_f(n) list_entry(n, struct rio_dev, net_list)
  117. #define to_rio_dev(n) container_of(n, struct rio_dev, dev)
  118. /**
  119. * struct rio_msg - RIO message event
  120. * @res: Mailbox resource
  121. * @mcback: Message event callback
  122. */
  123. struct rio_msg {
  124. struct resource *res;
  125. void (*mcback) (struct rio_mport * mport, void *dev_id, int mbox, int slot);
  126. };
  127. /**
  128. * struct rio_dbell - RIO doorbell event
  129. * @node: Node in list of doorbell events
  130. * @res: Doorbell resource
  131. * @dinb: Doorbell event callback
  132. * @dev_id: Device specific pointer to pass on event
  133. */
  134. struct rio_dbell {
  135. struct list_head node;
  136. struct resource *res;
  137. void (*dinb) (struct rio_mport *mport, void *dev_id, u16 src, u16 dst, u16 info);
  138. void *dev_id;
  139. };
  140. enum rio_phy_type {
  141. RIO_PHY_PARALLEL,
  142. RIO_PHY_SERIAL,
  143. };
  144. /**
  145. * struct rio_mport - RIO master port info
  146. * @dbells: List of doorbell events
  147. * @node: Node in global list of master ports
  148. * @nnode: Node in network list of master ports
  149. * @iores: I/O mem resource that this master port interface owns
  150. * @riores: RIO resources that this master port interfaces owns
  151. * @inb_msg: RIO inbound message event descriptors
  152. * @outb_msg: RIO outbound message event descriptors
  153. * @host_deviceid: Host device ID associated with this master port
  154. * @ops: configuration space functions
  155. * @id: Port ID, unique among all ports
  156. * @index: Port index, unique among all port interfaces of the same type
  157. * @sys_size: RapidIO common transport system size
  158. * @phy_type: RapidIO phy type
  159. * @name: Port name string
  160. * @priv: Master port private data
  161. */
  162. struct rio_mport {
  163. struct list_head dbells; /* list of doorbell events */
  164. struct list_head node; /* node in global list of ports */
  165. struct list_head nnode; /* node in net list of ports */
  166. struct resource iores;
  167. struct resource riores[RIO_MAX_MPORT_RESOURCES];
  168. struct rio_msg inb_msg[RIO_MAX_MBOX];
  169. struct rio_msg outb_msg[RIO_MAX_MBOX];
  170. int host_deviceid; /* Host device ID */
  171. struct rio_ops *ops; /* maintenance transaction functions */
  172. unsigned char id; /* port ID, unique among all ports */
  173. unsigned char index; /* port index, unique among all port
  174. interfaces of the same type */
  175. unsigned int sys_size; /* RapidIO common transport system size.
  176. * 0 - Small size. 256 devices.
  177. * 1 - Large size, 65536 devices.
  178. */
  179. enum rio_phy_type phy_type; /* RapidIO phy type */
  180. unsigned char name[40];
  181. void *priv; /* Master port private data */
  182. };
  183. /**
  184. * struct rio_net - RIO network info
  185. * @node: Node in global list of RIO networks
  186. * @devices: List of devices in this network
  187. * @mports: List of master ports accessing this network
  188. * @hport: Default port for accessing this network
  189. * @id: RIO network ID
  190. */
  191. struct rio_net {
  192. struct list_head node; /* node in list of networks */
  193. struct list_head devices; /* list of devices in this net */
  194. struct list_head mports; /* list of ports accessing net */
  195. struct rio_mport *hport; /* primary port for accessing net */
  196. unsigned char id; /* RIO network ID */
  197. };
  198. /**
  199. * struct rio_switch - RIO switch info
  200. * @node: Node in global list of switches
  201. * @switchid: Switch ID that is unique across a network
  202. * @hopcount: Hopcount to this switch
  203. * @destid: Associated destid in the path
  204. * @route_table: Copy of switch routing table
  205. * @port_ok: Status of each port (one bit per port) - OK=1 or UNINIT=0
  206. * @add_entry: Callback for switch-specific route add function
  207. * @get_entry: Callback for switch-specific route get function
  208. * @clr_table: Callback for switch-specific clear route table function
  209. * @set_domain: Callback for switch-specific domain setting function
  210. * @get_domain: Callback for switch-specific domain get function
  211. * @em_init: Callback for switch-specific error management initialization function
  212. * @em_handle: Callback for switch-specific error management handler function
  213. */
  214. struct rio_switch {
  215. struct list_head node;
  216. u16 switchid;
  217. u16 hopcount;
  218. u16 destid;
  219. u8 *route_table;
  220. u32 port_ok;
  221. int (*add_entry) (struct rio_mport * mport, u16 destid, u8 hopcount,
  222. u16 table, u16 route_destid, u8 route_port);
  223. int (*get_entry) (struct rio_mport * mport, u16 destid, u8 hopcount,
  224. u16 table, u16 route_destid, u8 * route_port);
  225. int (*clr_table) (struct rio_mport *mport, u16 destid, u8 hopcount,
  226. u16 table);
  227. int (*set_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
  228. u8 sw_domain);
  229. int (*get_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
  230. u8 *sw_domain);
  231. int (*em_init) (struct rio_dev *dev);
  232. int (*em_handle) (struct rio_dev *dev, u8 swport);
  233. };
  234. /* Low-level architecture-dependent routines */
  235. /**
  236. * struct rio_ops - Low-level RIO configuration space operations
  237. * @lcread: Callback to perform local (master port) read of config space.
  238. * @lcwrite: Callback to perform local (master port) write of config space.
  239. * @cread: Callback to perform network read of config space.
  240. * @cwrite: Callback to perform network write of config space.
  241. * @dsend: Callback to send a doorbell message.
  242. * @pwenable: Callback to enable/disable port-write message handling.
  243. */
  244. struct rio_ops {
  245. int (*lcread) (struct rio_mport *mport, int index, u32 offset, int len,
  246. u32 *data);
  247. int (*lcwrite) (struct rio_mport *mport, int index, u32 offset, int len,
  248. u32 data);
  249. int (*cread) (struct rio_mport *mport, int index, u16 destid,
  250. u8 hopcount, u32 offset, int len, u32 *data);
  251. int (*cwrite) (struct rio_mport *mport, int index, u16 destid,
  252. u8 hopcount, u32 offset, int len, u32 data);
  253. int (*dsend) (struct rio_mport *mport, int index, u16 destid, u16 data);
  254. int (*pwenable) (struct rio_mport *mport, int enable);
  255. };
  256. #define RIO_RESOURCE_MEM 0x00000100
  257. #define RIO_RESOURCE_DOORBELL 0x00000200
  258. #define RIO_RESOURCE_MAILBOX 0x00000400
  259. #define RIO_RESOURCE_CACHEABLE 0x00010000
  260. #define RIO_RESOURCE_PCI 0x00020000
  261. #define RIO_RESOURCE_BUSY 0x80000000
  262. /**
  263. * struct rio_driver - RIO driver info
  264. * @node: Node in list of drivers
  265. * @name: RIO driver name
  266. * @id_table: RIO device ids to be associated with this driver
  267. * @probe: RIO device inserted
  268. * @remove: RIO device removed
  269. * @suspend: RIO device suspended
  270. * @resume: RIO device awakened
  271. * @enable_wake: RIO device enable wake event
  272. * @driver: LDM driver struct
  273. *
  274. * Provides info on a RIO device driver for insertion/removal and
  275. * power management purposes.
  276. */
  277. struct rio_driver {
  278. struct list_head node;
  279. char *name;
  280. const struct rio_device_id *id_table;
  281. int (*probe) (struct rio_dev * dev, const struct rio_device_id * id);
  282. void (*remove) (struct rio_dev * dev);
  283. int (*suspend) (struct rio_dev * dev, u32 state);
  284. int (*resume) (struct rio_dev * dev);
  285. int (*enable_wake) (struct rio_dev * dev, u32 state, int enable);
  286. struct device_driver driver;
  287. };
  288. #define to_rio_driver(drv) container_of(drv,struct rio_driver, driver)
  289. /**
  290. * struct rio_device_id - RIO device identifier
  291. * @did: RIO device ID
  292. * @vid: RIO vendor ID
  293. * @asm_did: RIO assembly device ID
  294. * @asm_vid: RIO assembly vendor ID
  295. *
  296. * Identifies a RIO device based on both the device/vendor IDs and
  297. * the assembly device/vendor IDs.
  298. */
  299. struct rio_device_id {
  300. u16 did, vid;
  301. u16 asm_did, asm_vid;
  302. };
  303. /**
  304. * struct rio_switch_ops - Per-switch operations
  305. * @vid: RIO vendor ID
  306. * @did: RIO device ID
  307. * @init_hook: Callback that performs switch device initialization
  308. *
  309. * Defines the operations that are necessary to initialize/control
  310. * a particular RIO switch device.
  311. */
  312. struct rio_switch_ops {
  313. u16 vid, did;
  314. int (*init_hook) (struct rio_dev *rdev, int do_enum);
  315. };
  316. union rio_pw_msg {
  317. struct {
  318. u32 comptag; /* Component Tag CSR */
  319. u32 errdetect; /* Port N Error Detect CSR */
  320. u32 is_port; /* Implementation specific + PortID */
  321. u32 ltlerrdet; /* LTL Error Detect CSR */
  322. u32 padding[12];
  323. } em;
  324. u32 raw[RIO_PW_MSG_SIZE/sizeof(u32)];
  325. };
  326. /* Architecture and hardware-specific functions */
  327. extern int rio_init_mports(void);
  328. extern void rio_register_mport(struct rio_mport *);
  329. extern int rio_hw_add_outb_message(struct rio_mport *, struct rio_dev *, int,
  330. void *, size_t);
  331. extern int rio_hw_add_inb_buffer(struct rio_mport *, int, void *);
  332. extern void *rio_hw_get_inb_message(struct rio_mport *, int);
  333. extern int rio_open_inb_mbox(struct rio_mport *, void *, int, int);
  334. extern void rio_close_inb_mbox(struct rio_mport *, int);
  335. extern int rio_open_outb_mbox(struct rio_mport *, void *, int, int);
  336. extern void rio_close_outb_mbox(struct rio_mport *, int);
  337. #endif /* LINUX_RIO_H */