xref: /linux/include/linux/rio.h (revision 6978bbc097c2f665c336927a9d56ae39ef75fa56)
170a50ebdSMatt Porter /*
270a50ebdSMatt Porter  * RapidIO interconnect services
370a50ebdSMatt Porter  * (RapidIO Interconnect Specification, http://www.rapidio.org)
470a50ebdSMatt Porter  *
570a50ebdSMatt Porter  * Copyright 2005 MontaVista Software, Inc.
670a50ebdSMatt Porter  * Matt Porter <mporter@kernel.crashing.org>
770a50ebdSMatt Porter  *
870a50ebdSMatt Porter  * This program is free software; you can redistribute  it and/or modify it
970a50ebdSMatt Porter  * under  the terms of  the GNU General  Public License as published by the
1070a50ebdSMatt Porter  * Free Software Foundation;  either version 2 of the  License, or (at your
1170a50ebdSMatt Porter  * option) any later version.
1270a50ebdSMatt Porter  */
1370a50ebdSMatt Porter 
1470a50ebdSMatt Porter #ifndef LINUX_RIO_H
1570a50ebdSMatt Porter #define LINUX_RIO_H
1670a50ebdSMatt Porter 
1770a50ebdSMatt Porter #ifdef __KERNEL__
1870a50ebdSMatt Porter 
1970a50ebdSMatt Porter #include <linux/types.h>
2070a50ebdSMatt Porter #include <linux/config.h>
2170a50ebdSMatt Porter #include <linux/ioport.h>
2270a50ebdSMatt Porter #include <linux/list.h>
2370a50ebdSMatt Porter #include <linux/errno.h>
2470a50ebdSMatt Porter #include <linux/device.h>
2570a50ebdSMatt Porter #include <linux/rio_regs.h>
2670a50ebdSMatt Porter 
2770a50ebdSMatt Porter #define RIO_ANY_DESTID		0xff
2870a50ebdSMatt Porter #define RIO_NO_HOPCOUNT		-1
2970a50ebdSMatt Porter 
3070a50ebdSMatt Porter #define RIO_MAX_MPORT_RESOURCES	16
3170a50ebdSMatt Porter #define RIO_MAX_DEV_RESOURCES	16
3270a50ebdSMatt Porter 
3370a50ebdSMatt Porter #define RIO_GLOBAL_TABLE	0xff	/* Indicates access of a switch's
3470a50ebdSMatt Porter 					   global routing table if it
3570a50ebdSMatt Porter 					   has multiple (or per port)
3670a50ebdSMatt Porter 					   tables */
3770a50ebdSMatt Porter 
3870a50ebdSMatt Porter #define RIO_INVALID_ROUTE	0xff	/* Indicates that a route table
3970a50ebdSMatt Porter 					   entry is invalid (no route
4070a50ebdSMatt Porter 					   exists for the device ID) */
4170a50ebdSMatt Porter 
4270a50ebdSMatt Porter #ifdef CONFIG_RAPIDIO_8_BIT_TRANSPORT
4370a50ebdSMatt Porter #define RIO_MAX_ROUTE_ENTRIES	(1 << 8)
4470a50ebdSMatt Porter #else
4570a50ebdSMatt Porter #define RIO_MAX_ROUTE_ENTRIES	(1 << 16)
4670a50ebdSMatt Porter #endif
4770a50ebdSMatt Porter 
4870a50ebdSMatt Porter #define RIO_MAX_MBOX		4
4970a50ebdSMatt Porter #define RIO_MAX_MSG_SIZE	0x1000
5070a50ebdSMatt Porter 
5170a50ebdSMatt Porter /*
5270a50ebdSMatt Porter  * Error values that may be returned by RIO functions.
5370a50ebdSMatt Porter  */
5470a50ebdSMatt Porter #define RIO_SUCCESSFUL			0x00
5570a50ebdSMatt Porter #define RIO_BAD_SIZE			0x81
5670a50ebdSMatt Porter 
5770a50ebdSMatt Porter /*
5870a50ebdSMatt Porter  * For RIO devices, the region numbers are assigned this way:
5970a50ebdSMatt Porter  *
6070a50ebdSMatt Porter  *	0	RapidIO outbound doorbells
6170a50ebdSMatt Porter  *      1-15	RapidIO memory regions
6270a50ebdSMatt Porter  *
6370a50ebdSMatt Porter  * For RIO master ports, the region number are assigned this way:
6470a50ebdSMatt Porter  *
6570a50ebdSMatt Porter  *	0	RapidIO inbound doorbells
6670a50ebdSMatt Porter  *	1	RapidIO inbound mailboxes
6770a50ebdSMatt Porter  *	1	RapidIO outbound mailboxes
6870a50ebdSMatt Porter  */
6970a50ebdSMatt Porter #define RIO_DOORBELL_RESOURCE	0
7070a50ebdSMatt Porter #define RIO_INB_MBOX_RESOURCE	1
7170a50ebdSMatt Porter #define RIO_OUTB_MBOX_RESOURCE	2
7270a50ebdSMatt Porter 
7370a50ebdSMatt Porter extern struct bus_type rio_bus_type;
7470a50ebdSMatt Porter extern struct list_head rio_devices;	/* list of all devices */
7570a50ebdSMatt Porter 
7670a50ebdSMatt Porter struct rio_mport;
7770a50ebdSMatt Porter 
7870a50ebdSMatt Porter /**
7970a50ebdSMatt Porter  * struct rio_dev - RIO device info
8070a50ebdSMatt Porter  * @global_list: Node in list of all RIO devices
8170a50ebdSMatt Porter  * @net_list: Node in list of RIO devices in a network
8270a50ebdSMatt Porter  * @net: Network this device is a part of
8370a50ebdSMatt Porter  * @did: Device ID
8470a50ebdSMatt Porter  * @vid: Vendor ID
8570a50ebdSMatt Porter  * @device_rev: Device revision
8670a50ebdSMatt Porter  * @asm_did: Assembly device ID
8770a50ebdSMatt Porter  * @asm_vid: Assembly vendor ID
8870a50ebdSMatt Porter  * @asm_rev: Assembly revision
8970a50ebdSMatt Porter  * @efptr: Extended feature pointer
9070a50ebdSMatt Porter  * @pef: Processing element features
9170a50ebdSMatt Porter  * @swpinfo: Switch port info
9270a50ebdSMatt Porter  * @src_ops: Source operation capabilities
9370a50ebdSMatt Porter  * @dst_ops: Destination operation capabilities
94fa78cc51SMatt Porter  * @dma_mask: Mask of bits of RIO address this device implements
9570a50ebdSMatt Porter  * @rswitch: Pointer to &struct rio_switch if valid for this device
9670a50ebdSMatt Porter  * @driver: Driver claiming this device
9770a50ebdSMatt Porter  * @dev: Device model device
9870a50ebdSMatt Porter  * @riores: RIO resources this device owns
9970a50ebdSMatt Porter  * @destid: Network destination ID
10070a50ebdSMatt Porter  */
10170a50ebdSMatt Porter struct rio_dev {
10270a50ebdSMatt Porter 	struct list_head global_list;	/* node in list of all RIO devices */
10370a50ebdSMatt Porter 	struct list_head net_list;	/* node in per net list */
10470a50ebdSMatt Porter 	struct rio_net *net;	/* RIO net this device resides in */
10570a50ebdSMatt Porter 	u16 did;
10670a50ebdSMatt Porter 	u16 vid;
10770a50ebdSMatt Porter 	u32 device_rev;
10870a50ebdSMatt Porter 	u16 asm_did;
10970a50ebdSMatt Porter 	u16 asm_vid;
11070a50ebdSMatt Porter 	u16 asm_rev;
11170a50ebdSMatt Porter 	u16 efptr;
11270a50ebdSMatt Porter 	u32 pef;
11370a50ebdSMatt Porter 	u32 swpinfo;		/* Only used for switches */
11470a50ebdSMatt Porter 	u32 src_ops;
11570a50ebdSMatt Porter 	u32 dst_ops;
116fa78cc51SMatt Porter 	u64 dma_mask;
11770a50ebdSMatt Porter 	struct rio_switch *rswitch;	/* RIO switch info */
11870a50ebdSMatt Porter 	struct rio_driver *driver;	/* RIO driver claiming this device */
11970a50ebdSMatt Porter 	struct device dev;	/* LDM device structure */
12070a50ebdSMatt Porter 	struct resource riores[RIO_MAX_DEV_RESOURCES];
12170a50ebdSMatt Porter 	u16 destid;
12270a50ebdSMatt Porter };
12370a50ebdSMatt Porter 
12470a50ebdSMatt Porter #define rio_dev_g(n) list_entry(n, struct rio_dev, global_list)
12570a50ebdSMatt Porter #define rio_dev_f(n) list_entry(n, struct rio_dev, net_list)
12670a50ebdSMatt Porter #define	to_rio_dev(n) container_of(n, struct rio_dev, dev)
12770a50ebdSMatt Porter 
12870a50ebdSMatt Porter /**
12970a50ebdSMatt Porter  * struct rio_msg - RIO message event
13070a50ebdSMatt Porter  * @res: Mailbox resource
13170a50ebdSMatt Porter  * @mcback: Message event callback
13270a50ebdSMatt Porter  */
13370a50ebdSMatt Porter struct rio_msg {
13470a50ebdSMatt Porter 	struct resource *res;
135*6978bbc0SMatt Porter 	void (*mcback) (struct rio_mport * mport, void *dev_id, int mbox, int slot);
13670a50ebdSMatt Porter };
13770a50ebdSMatt Porter 
13870a50ebdSMatt Porter /**
13970a50ebdSMatt Porter  * struct rio_dbell - RIO doorbell event
14070a50ebdSMatt Porter  * @node: Node in list of doorbell events
14170a50ebdSMatt Porter  * @res: Doorbell resource
14270a50ebdSMatt Porter  * @dinb: Doorbell event callback
143*6978bbc0SMatt Porter  * @dev_id: Device specific pointer to pass on event
14470a50ebdSMatt Porter  */
14570a50ebdSMatt Porter struct rio_dbell {
14670a50ebdSMatt Porter 	struct list_head node;
14770a50ebdSMatt Porter 	struct resource *res;
148*6978bbc0SMatt Porter 	void (*dinb) (struct rio_mport *mport, void *dev_id, u16 src, u16 dst, u16 info);
149*6978bbc0SMatt Porter 	void *dev_id;
15070a50ebdSMatt Porter };
15170a50ebdSMatt Porter 
15270a50ebdSMatt Porter /**
15370a50ebdSMatt Porter  * struct rio_mport - RIO master port info
15470a50ebdSMatt Porter  * @dbells: List of doorbell events
15570a50ebdSMatt Porter  * @node: Node in global list of master ports
15670a50ebdSMatt Porter  * @nnode: Node in network list of master ports
15770a50ebdSMatt Porter  * @iores: I/O mem resource that this master port interface owns
15870a50ebdSMatt Porter  * @riores: RIO resources that this master port interfaces owns
15970a50ebdSMatt Porter  * @inb_msg: RIO inbound message event descriptors
16070a50ebdSMatt Porter  * @outb_msg: RIO outbound message event descriptors
16170a50ebdSMatt Porter  * @host_deviceid: Host device ID associated with this master port
16270a50ebdSMatt Porter  * @ops: configuration space functions
16370a50ebdSMatt Porter  * @id: Port ID, unique among all ports
16470a50ebdSMatt Porter  * @index: Port index, unique among all port interfaces of the same type
16570a50ebdSMatt Porter  * @name: Port name string
16670a50ebdSMatt Porter  */
16770a50ebdSMatt Porter struct rio_mport {
16870a50ebdSMatt Porter 	struct list_head dbells;	/* list of doorbell events */
16970a50ebdSMatt Porter 	struct list_head node;	/* node in global list of ports */
17070a50ebdSMatt Porter 	struct list_head nnode;	/* node in net list of ports */
17170a50ebdSMatt Porter 	struct resource iores;
17270a50ebdSMatt Porter 	struct resource riores[RIO_MAX_MPORT_RESOURCES];
17370a50ebdSMatt Porter 	struct rio_msg inb_msg[RIO_MAX_MBOX];
17470a50ebdSMatt Porter 	struct rio_msg outb_msg[RIO_MAX_MBOX];
17570a50ebdSMatt Porter 	int host_deviceid;	/* Host device ID */
17670a50ebdSMatt Porter 	struct rio_ops *ops;	/* maintenance transaction functions */
17770a50ebdSMatt Porter 	unsigned char id;	/* port ID, unique among all ports */
17870a50ebdSMatt Porter 	unsigned char index;	/* port index, unique among all port
17970a50ebdSMatt Porter 				   interfaces of the same type */
18070a50ebdSMatt Porter 	unsigned char name[40];
18170a50ebdSMatt Porter };
18270a50ebdSMatt Porter 
18370a50ebdSMatt Porter /**
18470a50ebdSMatt Porter  * struct rio_net - RIO network info
18570a50ebdSMatt Porter  * @node: Node in global list of RIO networks
18670a50ebdSMatt Porter  * @devices: List of devices in this network
18770a50ebdSMatt Porter  * @mports: List of master ports accessing this network
18870a50ebdSMatt Porter  * @hport: Default port for accessing this network
18970a50ebdSMatt Porter  * @id: RIO network ID
19070a50ebdSMatt Porter  */
19170a50ebdSMatt Porter struct rio_net {
19270a50ebdSMatt Porter 	struct list_head node;	/* node in list of networks */
19370a50ebdSMatt Porter 	struct list_head devices;	/* list of devices in this net */
19470a50ebdSMatt Porter 	struct list_head mports;	/* list of ports accessing net */
19570a50ebdSMatt Porter 	struct rio_mport *hport;	/* primary port for accessing net */
19670a50ebdSMatt Porter 	unsigned char id;	/* RIO network ID */
19770a50ebdSMatt Porter };
19870a50ebdSMatt Porter 
19970a50ebdSMatt Porter /**
20070a50ebdSMatt Porter  * struct rio_switch - RIO switch info
20170a50ebdSMatt Porter  * @node: Node in global list of switches
20270a50ebdSMatt Porter  * @switchid: Switch ID that is unique across a network
20370a50ebdSMatt Porter  * @hopcount: Hopcount to this switch
20470a50ebdSMatt Porter  * @destid: Associated destid in the path
20570a50ebdSMatt Porter  * @route_table: Copy of switch routing table
20670a50ebdSMatt Porter  * @add_entry: Callback for switch-specific route add function
20770a50ebdSMatt Porter  * @get_entry: Callback for switch-specific route get function
20870a50ebdSMatt Porter  */
20970a50ebdSMatt Porter struct rio_switch {
21070a50ebdSMatt Porter 	struct list_head node;
21170a50ebdSMatt Porter 	u16 switchid;
21270a50ebdSMatt Porter 	u16 hopcount;
21370a50ebdSMatt Porter 	u16 destid;
21470a50ebdSMatt Porter 	u8 route_table[RIO_MAX_ROUTE_ENTRIES];
21570a50ebdSMatt Porter 	int (*add_entry) (struct rio_mport * mport, u16 destid, u8 hopcount,
21670a50ebdSMatt Porter 			  u16 table, u16 route_destid, u8 route_port);
21770a50ebdSMatt Porter 	int (*get_entry) (struct rio_mport * mport, u16 destid, u8 hopcount,
21870a50ebdSMatt Porter 			  u16 table, u16 route_destid, u8 * route_port);
21970a50ebdSMatt Porter };
22070a50ebdSMatt Porter 
22170a50ebdSMatt Porter /* Low-level architecture-dependent routines */
22270a50ebdSMatt Porter 
22370a50ebdSMatt Porter /**
22470a50ebdSMatt Porter  * struct rio_ops - Low-level RIO configuration space operations
22570a50ebdSMatt Porter  * @lcread: Callback to perform local (master port) read of config space.
22670a50ebdSMatt Porter  * @lcwrite: Callback to perform local (master port) write of config space.
22770a50ebdSMatt Porter  * @cread: Callback to perform network read of config space.
22870a50ebdSMatt Porter  * @cwrite: Callback to perform network write of config space.
22970a50ebdSMatt Porter  * @dsend: Callback to send a doorbell message.
23070a50ebdSMatt Porter  */
23170a50ebdSMatt Porter struct rio_ops {
23270a50ebdSMatt Porter 	int (*lcread) (int index, u32 offset, int len, u32 * data);
23370a50ebdSMatt Porter 	int (*lcwrite) (int index, u32 offset, int len, u32 data);
23470a50ebdSMatt Porter 	int (*cread) (int index, u16 destid, u8 hopcount, u32 offset, int len,
23570a50ebdSMatt Porter 		      u32 * data);
23670a50ebdSMatt Porter 	int (*cwrite) (int index, u16 destid, u8 hopcount, u32 offset, int len,
23770a50ebdSMatt Porter 		       u32 data);
23870a50ebdSMatt Porter 	int (*dsend) (int index, u16 destid, u16 data);
23970a50ebdSMatt Porter };
24070a50ebdSMatt Porter 
24170a50ebdSMatt Porter #define RIO_RESOURCE_MEM	0x00000100
24270a50ebdSMatt Porter #define RIO_RESOURCE_DOORBELL	0x00000200
24370a50ebdSMatt Porter #define RIO_RESOURCE_MAILBOX	0x00000400
24470a50ebdSMatt Porter 
24570a50ebdSMatt Porter #define RIO_RESOURCE_CACHEABLE	0x00010000
24670a50ebdSMatt Porter #define RIO_RESOURCE_PCI	0x00020000
24770a50ebdSMatt Porter 
24870a50ebdSMatt Porter #define RIO_RESOURCE_BUSY	0x80000000
24970a50ebdSMatt Porter 
25070a50ebdSMatt Porter /**
25170a50ebdSMatt Porter  * struct rio_driver - RIO driver info
25270a50ebdSMatt Porter  * @node: Node in list of drivers
25370a50ebdSMatt Porter  * @name: RIO driver name
25470a50ebdSMatt Porter  * @id_table: RIO device ids to be associated with this driver
25570a50ebdSMatt Porter  * @probe: RIO device inserted
25670a50ebdSMatt Porter  * @remove: RIO device removed
25770a50ebdSMatt Porter  * @suspend: RIO device suspended
25870a50ebdSMatt Porter  * @resume: RIO device awakened
25970a50ebdSMatt Porter  * @enable_wake: RIO device enable wake event
26070a50ebdSMatt Porter  * @driver: LDM driver struct
26170a50ebdSMatt Porter  *
26270a50ebdSMatt Porter  * Provides info on a RIO device driver for insertion/removal and
26370a50ebdSMatt Porter  * power management purposes.
26470a50ebdSMatt Porter  */
26570a50ebdSMatt Porter struct rio_driver {
26670a50ebdSMatt Porter 	struct list_head node;
26770a50ebdSMatt Porter 	char *name;
26870a50ebdSMatt Porter 	const struct rio_device_id *id_table;
26970a50ebdSMatt Porter 	int (*probe) (struct rio_dev * dev, const struct rio_device_id * id);
27070a50ebdSMatt Porter 	void (*remove) (struct rio_dev * dev);
27170a50ebdSMatt Porter 	int (*suspend) (struct rio_dev * dev, u32 state);
27270a50ebdSMatt Porter 	int (*resume) (struct rio_dev * dev);
27370a50ebdSMatt Porter 	int (*enable_wake) (struct rio_dev * dev, u32 state, int enable);
27470a50ebdSMatt Porter 	struct device_driver driver;
27570a50ebdSMatt Porter };
27670a50ebdSMatt Porter 
27770a50ebdSMatt Porter #define	to_rio_driver(drv) container_of(drv,struct rio_driver, driver)
27870a50ebdSMatt Porter 
27970a50ebdSMatt Porter /**
28070a50ebdSMatt Porter  * struct rio_device_id - RIO device identifier
28170a50ebdSMatt Porter  * @did: RIO device ID
28270a50ebdSMatt Porter  * @vid: RIO vendor ID
28370a50ebdSMatt Porter  * @asm_did: RIO assembly device ID
28470a50ebdSMatt Porter  * @asm_vid: RIO assembly vendor ID
28570a50ebdSMatt Porter  *
28670a50ebdSMatt Porter  * Identifies a RIO device based on both the device/vendor IDs and
28770a50ebdSMatt Porter  * the assembly device/vendor IDs.
28870a50ebdSMatt Porter  */
28970a50ebdSMatt Porter struct rio_device_id {
29070a50ebdSMatt Porter 	u16 did, vid;
29170a50ebdSMatt Porter 	u16 asm_did, asm_vid;
29270a50ebdSMatt Porter };
29370a50ebdSMatt Porter 
29470a50ebdSMatt Porter /**
29570a50ebdSMatt Porter  * struct rio_route_ops - Per-switch route operations
29670a50ebdSMatt Porter  * @vid: RIO vendor ID
29770a50ebdSMatt Porter  * @did: RIO device ID
29870a50ebdSMatt Porter  * @add_hook: Callback that adds a route entry
29970a50ebdSMatt Porter  * @get_hook: Callback that gets a route entry
30070a50ebdSMatt Porter  *
30170a50ebdSMatt Porter  * Defines the operations that are necessary to manipulate the route
30270a50ebdSMatt Porter  * tables for a particular RIO switch device.
30370a50ebdSMatt Porter  */
30470a50ebdSMatt Porter struct rio_route_ops {
30570a50ebdSMatt Porter 	u16 vid, did;
30670a50ebdSMatt Porter 	int (*add_hook) (struct rio_mport * mport, u16 destid, u8 hopcount,
30770a50ebdSMatt Porter 			 u16 table, u16 route_destid, u8 route_port);
30870a50ebdSMatt Porter 	int (*get_hook) (struct rio_mport * mport, u16 destid, u8 hopcount,
30970a50ebdSMatt Porter 			 u16 table, u16 route_destid, u8 * route_port);
31070a50ebdSMatt Porter };
31170a50ebdSMatt Porter 
31270a50ebdSMatt Porter /* Architecture and hardware-specific functions */
31370a50ebdSMatt Porter extern int rio_init_mports(void);
31470a50ebdSMatt Porter extern void rio_register_mport(struct rio_mport *);
31570a50ebdSMatt Porter extern int rio_hw_add_outb_message(struct rio_mport *, struct rio_dev *, int,
31670a50ebdSMatt Porter 				   void *, size_t);
31770a50ebdSMatt Porter extern int rio_hw_add_inb_buffer(struct rio_mport *, int, void *);
31870a50ebdSMatt Porter extern void *rio_hw_get_inb_message(struct rio_mport *, int);
319*6978bbc0SMatt Porter extern int rio_open_inb_mbox(struct rio_mport *, void *, int, int);
32070a50ebdSMatt Porter extern void rio_close_inb_mbox(struct rio_mport *, int);
321*6978bbc0SMatt Porter extern int rio_open_outb_mbox(struct rio_mport *, void *, int, int);
32270a50ebdSMatt Porter extern void rio_close_outb_mbox(struct rio_mport *, int);
32370a50ebdSMatt Porter 
32470a50ebdSMatt Porter #endif				/* __KERNEL__ */
32570a50ebdSMatt Porter #endif				/* LINUX_RIO_H */
326