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