xref: /linux/include/linux/rio.h (revision 3bdbb62fe97537252b22f700009863eeb51aa750)
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 #include <linux/types.h>
1870a50ebdSMatt Porter #include <linux/ioport.h>
1970a50ebdSMatt Porter #include <linux/list.h>
2070a50ebdSMatt Porter #include <linux/errno.h>
2170a50ebdSMatt Porter #include <linux/device.h>
2270a50ebdSMatt Porter #include <linux/rio_regs.h>
23*3bdbb62fSAlexandre Bounine #include <linux/mod_devicetable.h>
24e42d98ebSAlexandre Bounine #ifdef CONFIG_RAPIDIO_DMA_ENGINE
25e42d98ebSAlexandre Bounine #include <linux/dmaengine.h>
26e42d98ebSAlexandre Bounine #endif
2770a50ebdSMatt Porter 
2870a50ebdSMatt Porter #define RIO_NO_HOPCOUNT		-1
29c70555b0SAlexandre Bounine #define RIO_INVALID_DESTID	0xffff
3070a50ebdSMatt Porter 
31569fccb6SAlexandre Bounine #define RIO_MAX_MPORTS		8
3270a50ebdSMatt Porter #define RIO_MAX_MPORT_RESOURCES	16
3370a50ebdSMatt Porter #define RIO_MAX_DEV_RESOURCES	16
34ed43f44fSAlexandre Bounine #define RIO_MAX_MPORT_NAME	40
3570a50ebdSMatt Porter 
3670a50ebdSMatt Porter #define RIO_GLOBAL_TABLE	0xff	/* Indicates access of a switch's
3770a50ebdSMatt Porter 					   global routing table if it
3870a50ebdSMatt Porter 					   has multiple (or per port)
3970a50ebdSMatt Porter 					   tables */
4070a50ebdSMatt Porter 
4170a50ebdSMatt Porter #define RIO_INVALID_ROUTE	0xff	/* Indicates that a route table
4270a50ebdSMatt Porter 					   entry is invalid (no route
4370a50ebdSMatt Porter 					   exists for the device ID) */
4470a50ebdSMatt Porter 
45e0423236SZhang Wei #define RIO_MAX_ROUTE_ENTRIES(size)	(size ? (1 << 16) : (1 << 8))
46e0423236SZhang Wei #define RIO_ANY_DESTID(size)		(size ? 0xffff : 0xff)
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
67fdb8d561SChad Reese  *	2	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 
73e5cabeb3SAlexandre Bounine #define RIO_PW_MSG_SIZE		64
74e5cabeb3SAlexandre Bounine 
75e6536927SAlexandre Bounine /*
76e6536927SAlexandre Bounine  * A component tag value (stored in the component tag CSR) is used as device's
77e6536927SAlexandre Bounine  * unique identifier assigned during enumeration. Besides being used for
78e6536927SAlexandre Bounine  * identifying switches (which do not have device ID register), it also is used
79e6536927SAlexandre Bounine  * by error management notification and therefore has to be assigned
80e6536927SAlexandre Bounine  * to endpoints as well.
81e6536927SAlexandre Bounine  */
82e6536927SAlexandre Bounine #define RIO_CTAG_RESRVD	0xfffe0000 /* Reserved */
83e6536927SAlexandre Bounine #define RIO_CTAG_UDEVID	0x0001ffff /* Unique device identifier */
84e6536927SAlexandre Bounine 
8570a50ebdSMatt Porter extern struct bus_type rio_bus_type;
862c70f022SAlexandre Bounine extern struct device rio_bus;
8770a50ebdSMatt Porter 
8870a50ebdSMatt Porter struct rio_mport;
89ded05782SAlexandre Bounine struct rio_dev;
90e5cabeb3SAlexandre Bounine union rio_pw_msg;
9170a50ebdSMatt Porter 
9270a50ebdSMatt Porter /**
93ded05782SAlexandre Bounine  * struct rio_switch - RIO switch info
94ded05782SAlexandre Bounine  * @node: Node in global list of switches
95ded05782SAlexandre Bounine  * @switchid: Switch ID that is unique across a network
96ded05782SAlexandre Bounine  * @route_table: Copy of switch routing table
97ded05782SAlexandre Bounine  * @port_ok: Status of each port (one bit per port) - OK=1 or UNINIT=0
982ec3ba69SAlexandre Bounine  * @ops: pointer to switch-specific operations
992ec3ba69SAlexandre Bounine  * @lock: lock to serialize operations updates
100ded05782SAlexandre Bounine  * @nextdev: Array of per-port pointers to the next attached device
101ded05782SAlexandre Bounine  */
102ded05782SAlexandre Bounine struct rio_switch {
103ded05782SAlexandre Bounine 	struct list_head node;
104ded05782SAlexandre Bounine 	u16 switchid;
105ded05782SAlexandre Bounine 	u8 *route_table;
106ded05782SAlexandre Bounine 	u32 port_ok;
1072ec3ba69SAlexandre Bounine 	struct rio_switch_ops *ops;
1082ec3ba69SAlexandre Bounine 	spinlock_t lock;
1092ec3ba69SAlexandre Bounine 	struct rio_dev *nextdev[0];
1102ec3ba69SAlexandre Bounine };
1112ec3ba69SAlexandre Bounine 
1122ec3ba69SAlexandre Bounine /**
1132ec3ba69SAlexandre Bounine  * struct rio_switch_ops - Per-switch operations
1142ec3ba69SAlexandre Bounine  * @owner: The module owner of this structure
1152ec3ba69SAlexandre Bounine  * @add_entry: Callback for switch-specific route add function
1162ec3ba69SAlexandre Bounine  * @get_entry: Callback for switch-specific route get function
1172ec3ba69SAlexandre Bounine  * @clr_table: Callback for switch-specific clear route table function
1182ec3ba69SAlexandre Bounine  * @set_domain: Callback for switch-specific domain setting function
1192ec3ba69SAlexandre Bounine  * @get_domain: Callback for switch-specific domain get function
1202ec3ba69SAlexandre Bounine  * @em_init: Callback for switch-specific error management init function
1212ec3ba69SAlexandre Bounine  * @em_handle: Callback for switch-specific error management handler function
1222ec3ba69SAlexandre Bounine  *
1232ec3ba69SAlexandre Bounine  * Defines the operations that are necessary to initialize/control
1242ec3ba69SAlexandre Bounine  * a particular RIO switch device.
1252ec3ba69SAlexandre Bounine  */
1262ec3ba69SAlexandre Bounine struct rio_switch_ops {
1272ec3ba69SAlexandre Bounine 	struct module *owner;
128ded05782SAlexandre Bounine 	int (*add_entry) (struct rio_mport *mport, u16 destid, u8 hopcount,
129ded05782SAlexandre Bounine 			  u16 table, u16 route_destid, u8 route_port);
130ded05782SAlexandre Bounine 	int (*get_entry) (struct rio_mport *mport, u16 destid, u8 hopcount,
131ded05782SAlexandre Bounine 			  u16 table, u16 route_destid, u8 *route_port);
132ded05782SAlexandre Bounine 	int (*clr_table) (struct rio_mport *mport, u16 destid, u8 hopcount,
133ded05782SAlexandre Bounine 			  u16 table);
134ded05782SAlexandre Bounine 	int (*set_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
135ded05782SAlexandre Bounine 			   u8 sw_domain);
136ded05782SAlexandre Bounine 	int (*get_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
137ded05782SAlexandre Bounine 			   u8 *sw_domain);
138ded05782SAlexandre Bounine 	int (*em_init) (struct rio_dev *dev);
139ded05782SAlexandre Bounine 	int (*em_handle) (struct rio_dev *dev, u8 swport);
140ded05782SAlexandre Bounine };
141ded05782SAlexandre Bounine 
142ded05782SAlexandre Bounine /**
14370a50ebdSMatt Porter  * struct rio_dev - RIO device info
14470a50ebdSMatt Porter  * @global_list: Node in list of all RIO devices
14570a50ebdSMatt Porter  * @net_list: Node in list of RIO devices in a network
14670a50ebdSMatt Porter  * @net: Network this device is a part of
1472ec3ba69SAlexandre Bounine  * @do_enum: Enumeration flag
14870a50ebdSMatt Porter  * @did: Device ID
14970a50ebdSMatt Porter  * @vid: Vendor ID
15070a50ebdSMatt Porter  * @device_rev: Device revision
15170a50ebdSMatt Porter  * @asm_did: Assembly device ID
15270a50ebdSMatt Porter  * @asm_vid: Assembly vendor ID
15370a50ebdSMatt Porter  * @asm_rev: Assembly revision
15470a50ebdSMatt Porter  * @efptr: Extended feature pointer
15570a50ebdSMatt Porter  * @pef: Processing element features
15670a50ebdSMatt Porter  * @swpinfo: Switch port info
15770a50ebdSMatt Porter  * @src_ops: Source operation capabilities
15870a50ebdSMatt Porter  * @dst_ops: Destination operation capabilities
15997ef6f74SRandy Dunlap  * @comp_tag: RIO component tag
16097ef6f74SRandy Dunlap  * @phys_efptr: RIO device extended features pointer
16197ef6f74SRandy Dunlap  * @em_efptr: RIO Error Management features pointer
162fa78cc51SMatt Porter  * @dma_mask: Mask of bits of RIO address this device implements
16370a50ebdSMatt Porter  * @driver: Driver claiming this device
16470a50ebdSMatt Porter  * @dev: Device model device
16570a50ebdSMatt Porter  * @riores: RIO resources this device owns
16697ef6f74SRandy Dunlap  * @pwcback: port-write callback function for this device
167a93192a5SAlexandre Bounine  * @destid: Network destination ID (or associated destid for switch)
168a93192a5SAlexandre Bounine  * @hopcount: Hopcount to this device
16968fe4df5SAlexandre Bounine  * @prev: Previous RIO device connected to the current one
170ded05782SAlexandre Bounine  * @rswitch: struct rio_switch (if valid for this device)
17170a50ebdSMatt Porter  */
17270a50ebdSMatt Porter struct rio_dev {
17370a50ebdSMatt Porter 	struct list_head global_list;	/* node in list of all RIO devices */
17470a50ebdSMatt Porter 	struct list_head net_list;	/* node in per net list */
17570a50ebdSMatt Porter 	struct rio_net *net;	/* RIO net this device resides in */
1762ec3ba69SAlexandre Bounine 	bool do_enum;
17770a50ebdSMatt Porter 	u16 did;
17870a50ebdSMatt Porter 	u16 vid;
17970a50ebdSMatt Porter 	u32 device_rev;
18070a50ebdSMatt Porter 	u16 asm_did;
18170a50ebdSMatt Porter 	u16 asm_vid;
18270a50ebdSMatt Porter 	u16 asm_rev;
18370a50ebdSMatt Porter 	u16 efptr;
18470a50ebdSMatt Porter 	u32 pef;
185ae05cbd5SAlexandre Bounine 	u32 swpinfo;
18670a50ebdSMatt Porter 	u32 src_ops;
18770a50ebdSMatt Porter 	u32 dst_ops;
188e5cabeb3SAlexandre Bounine 	u32 comp_tag;
189e5cabeb3SAlexandre Bounine 	u32 phys_efptr;
190e5cabeb3SAlexandre Bounine 	u32 em_efptr;
191fa78cc51SMatt Porter 	u64 dma_mask;
19270a50ebdSMatt Porter 	struct rio_driver *driver;	/* RIO driver claiming this device */
19370a50ebdSMatt Porter 	struct device dev;	/* LDM device structure */
19470a50ebdSMatt Porter 	struct resource riores[RIO_MAX_DEV_RESOURCES];
195e5cabeb3SAlexandre Bounine 	int (*pwcback) (struct rio_dev *rdev, union rio_pw_msg *msg, int step);
19670a50ebdSMatt Porter 	u16 destid;
197a93192a5SAlexandre Bounine 	u8 hopcount;
19868fe4df5SAlexandre Bounine 	struct rio_dev *prev;
199ded05782SAlexandre Bounine 	struct rio_switch rswitch[0];	/* RIO switch info */
20070a50ebdSMatt Porter };
20170a50ebdSMatt Porter 
20270a50ebdSMatt Porter #define rio_dev_g(n) list_entry(n, struct rio_dev, global_list)
20370a50ebdSMatt Porter #define rio_dev_f(n) list_entry(n, struct rio_dev, net_list)
20470a50ebdSMatt Porter #define	to_rio_dev(n) container_of(n, struct rio_dev, dev)
205ded05782SAlexandre Bounine #define sw_to_rio_dev(n) container_of(n, struct rio_dev, rswitch[0])
20670a50ebdSMatt Porter 
20770a50ebdSMatt Porter /**
20870a50ebdSMatt Porter  * struct rio_msg - RIO message event
20970a50ebdSMatt Porter  * @res: Mailbox resource
21070a50ebdSMatt Porter  * @mcback: Message event callback
21170a50ebdSMatt Porter  */
21270a50ebdSMatt Porter struct rio_msg {
21370a50ebdSMatt Porter 	struct resource *res;
2146978bbc0SMatt Porter 	void (*mcback) (struct rio_mport * mport, void *dev_id, int mbox, int slot);
21570a50ebdSMatt Porter };
21670a50ebdSMatt Porter 
21770a50ebdSMatt Porter /**
21870a50ebdSMatt Porter  * struct rio_dbell - RIO doorbell event
21970a50ebdSMatt Porter  * @node: Node in list of doorbell events
22070a50ebdSMatt Porter  * @res: Doorbell resource
22170a50ebdSMatt Porter  * @dinb: Doorbell event callback
2226978bbc0SMatt Porter  * @dev_id: Device specific pointer to pass on event
22370a50ebdSMatt Porter  */
22470a50ebdSMatt Porter struct rio_dbell {
22570a50ebdSMatt Porter 	struct list_head node;
22670a50ebdSMatt Porter 	struct resource *res;
2276978bbc0SMatt Porter 	void (*dinb) (struct rio_mport *mport, void *dev_id, u16 src, u16 dst, u16 info);
2286978bbc0SMatt Porter 	void *dev_id;
22970a50ebdSMatt Porter };
23070a50ebdSMatt Porter 
23161b26917SZhang Wei enum rio_phy_type {
23261b26917SZhang Wei 	RIO_PHY_PARALLEL,
23361b26917SZhang Wei 	RIO_PHY_SERIAL,
23461b26917SZhang Wei };
23561b26917SZhang Wei 
23670a50ebdSMatt Porter /**
23770a50ebdSMatt Porter  * struct rio_mport - RIO master port info
23870a50ebdSMatt Porter  * @dbells: List of doorbell events
23970a50ebdSMatt Porter  * @node: Node in global list of master ports
24070a50ebdSMatt Porter  * @nnode: Node in network list of master ports
24170a50ebdSMatt Porter  * @iores: I/O mem resource that this master port interface owns
24270a50ebdSMatt Porter  * @riores: RIO resources that this master port interfaces owns
24370a50ebdSMatt Porter  * @inb_msg: RIO inbound message event descriptors
24470a50ebdSMatt Porter  * @outb_msg: RIO outbound message event descriptors
24570a50ebdSMatt Porter  * @host_deviceid: Host device ID associated with this master port
24670a50ebdSMatt Porter  * @ops: configuration space functions
24770a50ebdSMatt Porter  * @id: Port ID, unique among all ports
24870a50ebdSMatt Porter  * @index: Port index, unique among all port interfaces of the same type
2499941d945SRandy Dunlap  * @sys_size: RapidIO common transport system size
2509941d945SRandy Dunlap  * @phy_type: RapidIO phy type
251af84ca38SAlexandre Bounine  * @phys_efptr: RIO port extended features pointer
25270a50ebdSMatt Porter  * @name: Port name string
253ad1e9380SZhang Wei  * @priv: Master port private data
254fe50c927SAlexandre Bounine  * @dma: DMA device associated with mport
255a11650e1SAlexandre Bounine  * @nscan: RapidIO network enumeration/discovery operations
25670a50ebdSMatt Porter  */
25770a50ebdSMatt Porter struct rio_mport {
25870a50ebdSMatt Porter 	struct list_head dbells;	/* list of doorbell events */
25970a50ebdSMatt Porter 	struct list_head node;	/* node in global list of ports */
26070a50ebdSMatt Porter 	struct list_head nnode;	/* node in net list of ports */
26170a50ebdSMatt Porter 	struct resource iores;
26270a50ebdSMatt Porter 	struct resource riores[RIO_MAX_MPORT_RESOURCES];
26370a50ebdSMatt Porter 	struct rio_msg inb_msg[RIO_MAX_MBOX];
26470a50ebdSMatt Porter 	struct rio_msg outb_msg[RIO_MAX_MBOX];
26570a50ebdSMatt Porter 	int host_deviceid;	/* Host device ID */
266f8f06269SAlexandre Bounine 	struct rio_ops *ops;	/* low-level architecture-dependent routines */
26770a50ebdSMatt Porter 	unsigned char id;	/* port ID, unique among all ports */
26870a50ebdSMatt Porter 	unsigned char index;	/* port index, unique among all port
26970a50ebdSMatt Porter 				   interfaces of the same type */
270e0423236SZhang Wei 	unsigned int sys_size;	/* RapidIO common transport system size.
271e0423236SZhang Wei 				 * 0 - Small size. 256 devices.
272e0423236SZhang Wei 				 * 1 - Large size, 65536 devices.
273e0423236SZhang Wei 				 */
27461b26917SZhang Wei 	enum rio_phy_type phy_type;	/* RapidIO phy type */
275af84ca38SAlexandre Bounine 	u32 phys_efptr;
276ed43f44fSAlexandre Bounine 	unsigned char name[RIO_MAX_MPORT_NAME];
277ad1e9380SZhang Wei 	void *priv;		/* Master port private data */
278e42d98ebSAlexandre Bounine #ifdef CONFIG_RAPIDIO_DMA_ENGINE
279e42d98ebSAlexandre Bounine 	struct dma_device	dma;
280e42d98ebSAlexandre Bounine #endif
281a11650e1SAlexandre Bounine 	struct rio_scan *nscan;
28270a50ebdSMatt Porter };
28370a50ebdSMatt Porter 
284bc8fcfeaSAlexandre Bounine /*
285bc8fcfeaSAlexandre Bounine  * Enumeration/discovery control flags
286bc8fcfeaSAlexandre Bounine  */
287bc8fcfeaSAlexandre Bounine #define RIO_SCAN_ENUM_NO_WAIT	0x00000001 /* Do not wait for enum completed */
288bc8fcfeaSAlexandre Bounine 
289de74e00aSAlexandre Bounine struct rio_id_table {
290de74e00aSAlexandre Bounine 	u16 start;	/* logical minimal id */
291de74e00aSAlexandre Bounine 	u32 max;	/* max number of IDs in table */
292de74e00aSAlexandre Bounine 	spinlock_t lock;
293de74e00aSAlexandre Bounine 	unsigned long *table;
294de74e00aSAlexandre Bounine };
295de74e00aSAlexandre Bounine 
29670a50ebdSMatt Porter /**
29770a50ebdSMatt Porter  * struct rio_net - RIO network info
29870a50ebdSMatt Porter  * @node: Node in global list of RIO networks
29970a50ebdSMatt Porter  * @devices: List of devices in this network
3002ca3cb50SRandy Dunlap  * @switches: List of switches in this netowrk
30170a50ebdSMatt Porter  * @mports: List of master ports accessing this network
30270a50ebdSMatt Porter  * @hport: Default port for accessing this network
30370a50ebdSMatt Porter  * @id: RIO network ID
3042ca3cb50SRandy Dunlap  * @destid_table: destID allocation table
30570a50ebdSMatt Porter  */
30670a50ebdSMatt Porter struct rio_net {
30770a50ebdSMatt Porter 	struct list_head node;	/* node in list of networks */
30870a50ebdSMatt Porter 	struct list_head devices;	/* list of devices in this net */
309a7071efcSAlexandre Bounine 	struct list_head switches;	/* list of switches in this net */
31070a50ebdSMatt Porter 	struct list_head mports;	/* list of ports accessing net */
31170a50ebdSMatt Porter 	struct rio_mport *hport;	/* primary port for accessing net */
31270a50ebdSMatt Porter 	unsigned char id;	/* RIO network ID */
313de74e00aSAlexandre Bounine 	struct rio_id_table destid_table;  /* destID allocation table */
31470a50ebdSMatt Porter };
31570a50ebdSMatt Porter 
31670a50ebdSMatt Porter /* Low-level architecture-dependent routines */
31770a50ebdSMatt Porter 
31870a50ebdSMatt Porter /**
31970a50ebdSMatt Porter  * struct rio_ops - Low-level RIO configuration space operations
32070a50ebdSMatt Porter  * @lcread: Callback to perform local (master port) read of config space.
32170a50ebdSMatt Porter  * @lcwrite: Callback to perform local (master port) write of config space.
32270a50ebdSMatt Porter  * @cread: Callback to perform network read of config space.
32370a50ebdSMatt Porter  * @cwrite: Callback to perform network write of config space.
32470a50ebdSMatt Porter  * @dsend: Callback to send a doorbell message.
325e5cabeb3SAlexandre Bounine  * @pwenable: Callback to enable/disable port-write message handling.
326f8f06269SAlexandre Bounine  * @open_outb_mbox: Callback to initialize outbound mailbox.
327f8f06269SAlexandre Bounine  * @close_outb_mbox: Callback to shut down outbound mailbox.
328f8f06269SAlexandre Bounine  * @open_inb_mbox: Callback to initialize inbound mailbox.
329f8f06269SAlexandre Bounine  * @close_inb_mbox: Callback to	shut down inbound mailbox.
330f8f06269SAlexandre Bounine  * @add_outb_message: Callback to add a message to an outbound mailbox queue.
331f8f06269SAlexandre Bounine  * @add_inb_buffer: Callback to	add a buffer to an inbound mailbox queue.
332f8f06269SAlexandre Bounine  * @get_inb_message: Callback to get a message from an inbound mailbox queue.
333da1589f0SAlexandre Bounine  * @map_inb: Callback to map RapidIO address region into local memory space.
334da1589f0SAlexandre Bounine  * @unmap_inb: Callback to unmap RapidIO address region mapped with map_inb().
33570a50ebdSMatt Porter  */
33670a50ebdSMatt Porter struct rio_ops {
337ad1e9380SZhang Wei 	int (*lcread) (struct rio_mport *mport, int index, u32 offset, int len,
33870a50ebdSMatt Porter 			u32 *data);
339ad1e9380SZhang Wei 	int (*lcwrite) (struct rio_mport *mport, int index, u32 offset, int len,
34070a50ebdSMatt Porter 			u32 data);
341ad1e9380SZhang Wei 	int (*cread) (struct rio_mport *mport, int index, u16 destid,
342ad1e9380SZhang Wei 			u8 hopcount, u32 offset, int len, u32 *data);
343ad1e9380SZhang Wei 	int (*cwrite) (struct rio_mport *mport, int index, u16 destid,
344ad1e9380SZhang Wei 			u8 hopcount, u32 offset, int len, u32 data);
345ad1e9380SZhang Wei 	int (*dsend) (struct rio_mport *mport, int index, u16 destid, u16 data);
346e5cabeb3SAlexandre Bounine 	int (*pwenable) (struct rio_mport *mport, int enable);
347f8f06269SAlexandre Bounine 	int (*open_outb_mbox)(struct rio_mport *mport, void *dev_id,
348f8f06269SAlexandre Bounine 			      int mbox, int entries);
349f8f06269SAlexandre Bounine 	void (*close_outb_mbox)(struct rio_mport *mport, int mbox);
350f8f06269SAlexandre Bounine 	int  (*open_inb_mbox)(struct rio_mport *mport, void *dev_id,
351f8f06269SAlexandre Bounine 			     int mbox, int entries);
352f8f06269SAlexandre Bounine 	void (*close_inb_mbox)(struct rio_mport *mport, int mbox);
353f8f06269SAlexandre Bounine 	int  (*add_outb_message)(struct rio_mport *mport, struct rio_dev *rdev,
354f8f06269SAlexandre Bounine 				 int mbox, void *buffer, size_t len);
355f8f06269SAlexandre Bounine 	int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
356f8f06269SAlexandre Bounine 	void *(*get_inb_message)(struct rio_mport *mport, int mbox);
357da1589f0SAlexandre Bounine 	int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
358da1589f0SAlexandre Bounine 			u64 rstart, u32 size, u32 flags);
359da1589f0SAlexandre Bounine 	void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
36070a50ebdSMatt Porter };
36170a50ebdSMatt Porter 
36270a50ebdSMatt Porter #define RIO_RESOURCE_MEM	0x00000100
36370a50ebdSMatt Porter #define RIO_RESOURCE_DOORBELL	0x00000200
36470a50ebdSMatt Porter #define RIO_RESOURCE_MAILBOX	0x00000400
36570a50ebdSMatt Porter 
36670a50ebdSMatt Porter #define RIO_RESOURCE_CACHEABLE	0x00010000
36770a50ebdSMatt Porter #define RIO_RESOURCE_PCI	0x00020000
36870a50ebdSMatt Porter 
36970a50ebdSMatt Porter #define RIO_RESOURCE_BUSY	0x80000000
37070a50ebdSMatt Porter 
37170a50ebdSMatt Porter /**
37270a50ebdSMatt Porter  * struct rio_driver - RIO driver info
37370a50ebdSMatt Porter  * @node: Node in list of drivers
37470a50ebdSMatt Porter  * @name: RIO driver name
37570a50ebdSMatt Porter  * @id_table: RIO device ids to be associated with this driver
37670a50ebdSMatt Porter  * @probe: RIO device inserted
37770a50ebdSMatt Porter  * @remove: RIO device removed
37870a50ebdSMatt Porter  * @suspend: RIO device suspended
37970a50ebdSMatt Porter  * @resume: RIO device awakened
38070a50ebdSMatt Porter  * @enable_wake: RIO device enable wake event
38170a50ebdSMatt Porter  * @driver: LDM driver struct
38270a50ebdSMatt Porter  *
38370a50ebdSMatt Porter  * Provides info on a RIO device driver for insertion/removal and
38470a50ebdSMatt Porter  * power management purposes.
38570a50ebdSMatt Porter  */
38670a50ebdSMatt Porter struct rio_driver {
38770a50ebdSMatt Porter 	struct list_head node;
38870a50ebdSMatt Porter 	char *name;
38970a50ebdSMatt Porter 	const struct rio_device_id *id_table;
39070a50ebdSMatt Porter 	int (*probe) (struct rio_dev * dev, const struct rio_device_id * id);
39170a50ebdSMatt Porter 	void (*remove) (struct rio_dev * dev);
39270a50ebdSMatt Porter 	int (*suspend) (struct rio_dev * dev, u32 state);
39370a50ebdSMatt Porter 	int (*resume) (struct rio_dev * dev);
39470a50ebdSMatt Porter 	int (*enable_wake) (struct rio_dev * dev, u32 state, int enable);
39570a50ebdSMatt Porter 	struct device_driver driver;
39670a50ebdSMatt Porter };
39770a50ebdSMatt Porter 
39870a50ebdSMatt Porter #define	to_rio_driver(drv) container_of(drv,struct rio_driver, driver)
39970a50ebdSMatt Porter 
400e5cabeb3SAlexandre Bounine union rio_pw_msg {
401e5cabeb3SAlexandre Bounine 	struct {
402e5cabeb3SAlexandre Bounine 		u32 comptag;	/* Component Tag CSR */
403e5cabeb3SAlexandre Bounine 		u32 errdetect;	/* Port N Error Detect CSR */
404e5cabeb3SAlexandre Bounine 		u32 is_port;	/* Implementation specific + PortID */
405e5cabeb3SAlexandre Bounine 		u32 ltlerrdet;	/* LTL Error Detect CSR */
406e5cabeb3SAlexandre Bounine 		u32 padding[12];
407e5cabeb3SAlexandre Bounine 	} em;
408e5cabeb3SAlexandre Bounine 	u32 raw[RIO_PW_MSG_SIZE/sizeof(u32)];
409e5cabeb3SAlexandre Bounine };
410e5cabeb3SAlexandre Bounine 
411e42d98ebSAlexandre Bounine #ifdef CONFIG_RAPIDIO_DMA_ENGINE
412e42d98ebSAlexandre Bounine 
413fe50c927SAlexandre Bounine /*
414e42d98ebSAlexandre Bounine  * enum rio_write_type - RIO write transaction types used in DMA transfers
415e42d98ebSAlexandre Bounine  *
416e42d98ebSAlexandre Bounine  * Note: RapidIO specification defines write (NWRITE) and
417e42d98ebSAlexandre Bounine  * write-with-response (NWRITE_R) data transfer operations.
418e42d98ebSAlexandre Bounine  * Existing DMA controllers that service RapidIO may use one of these operations
419e42d98ebSAlexandre Bounine  * for entire data transfer or their combination with only the last data packet
420e42d98ebSAlexandre Bounine  * requires response.
421e42d98ebSAlexandre Bounine  */
422e42d98ebSAlexandre Bounine enum rio_write_type {
423e42d98ebSAlexandre Bounine 	RDW_DEFAULT,		/* default method used by DMA driver */
424e42d98ebSAlexandre Bounine 	RDW_ALL_NWRITE,		/* all packets use NWRITE */
425e42d98ebSAlexandre Bounine 	RDW_ALL_NWRITE_R,	/* all packets use NWRITE_R */
426e42d98ebSAlexandre Bounine 	RDW_LAST_NWRITE_R,	/* last packet uses NWRITE_R, others - NWRITE */
427e42d98ebSAlexandre Bounine };
428e42d98ebSAlexandre Bounine 
429e42d98ebSAlexandre Bounine struct rio_dma_ext {
430e42d98ebSAlexandre Bounine 	u16 destid;
431e42d98ebSAlexandre Bounine 	u64 rio_addr;	/* low 64-bits of 66-bit RapidIO address */
432e42d98ebSAlexandre Bounine 	u8  rio_addr_u;  /* upper 2-bits of 66-bit RapidIO address */
433e42d98ebSAlexandre Bounine 	enum rio_write_type wr_type; /* preferred RIO write operation type */
434e42d98ebSAlexandre Bounine };
435e42d98ebSAlexandre Bounine 
436e42d98ebSAlexandre Bounine struct rio_dma_data {
437e42d98ebSAlexandre Bounine 	/* Local data (as scatterlist) */
438e42d98ebSAlexandre Bounine 	struct scatterlist	*sg;	/* I/O scatter list */
439e42d98ebSAlexandre Bounine 	unsigned int		sg_len;	/* size of scatter list */
440e42d98ebSAlexandre Bounine 	/* Remote device address (flat buffer) */
441e42d98ebSAlexandre Bounine 	u64 rio_addr;	/* low 64-bits of 66-bit RapidIO address */
442e42d98ebSAlexandre Bounine 	u8  rio_addr_u;  /* upper 2-bits of 66-bit RapidIO address */
443e42d98ebSAlexandre Bounine 	enum rio_write_type wr_type; /* preferred RIO write operation type */
444e42d98ebSAlexandre Bounine };
445e42d98ebSAlexandre Bounine 
446e42d98ebSAlexandre Bounine static inline struct rio_mport *dma_to_mport(struct dma_device *ddev)
447e42d98ebSAlexandre Bounine {
448e42d98ebSAlexandre Bounine 	return container_of(ddev, struct rio_mport, dma);
449e42d98ebSAlexandre Bounine }
450e42d98ebSAlexandre Bounine #endif /* CONFIG_RAPIDIO_DMA_ENGINE */
451e42d98ebSAlexandre Bounine 
452a11650e1SAlexandre Bounine /**
453a11650e1SAlexandre Bounine  * struct rio_scan - RIO enumeration and discovery operations
4549edbc30bSAlexandre Bounine  * @owner: The module owner of this structure
455a11650e1SAlexandre Bounine  * @enumerate: Callback to perform RapidIO fabric enumeration.
456a11650e1SAlexandre Bounine  * @discover: Callback to perform RapidIO fabric discovery.
457a11650e1SAlexandre Bounine  */
458a11650e1SAlexandre Bounine struct rio_scan {
4599edbc30bSAlexandre Bounine 	struct module *owner;
460bc8fcfeaSAlexandre Bounine 	int (*enumerate)(struct rio_mport *mport, u32 flags);
461bc8fcfeaSAlexandre Bounine 	int (*discover)(struct rio_mport *mport, u32 flags);
462a11650e1SAlexandre Bounine };
463a11650e1SAlexandre Bounine 
4649edbc30bSAlexandre Bounine /**
4659edbc30bSAlexandre Bounine  * struct rio_scan_node - list node to register RapidIO enumeration and
4669edbc30bSAlexandre Bounine  * discovery methods with RapidIO core.
4679edbc30bSAlexandre Bounine  * @mport_id: ID of an mport (net) serviced by this enumerator
4689edbc30bSAlexandre Bounine  * @node: node in global list of registered enumerators
4699edbc30bSAlexandre Bounine  * @ops: RIO enumeration and discovery operations
4709edbc30bSAlexandre Bounine  */
4719edbc30bSAlexandre Bounine struct rio_scan_node {
4729edbc30bSAlexandre Bounine 	int mport_id;
4739edbc30bSAlexandre Bounine 	struct list_head node;
4749edbc30bSAlexandre Bounine 	struct rio_scan *ops;
4759edbc30bSAlexandre Bounine };
4769edbc30bSAlexandre Bounine 
47770a50ebdSMatt Porter /* Architecture and hardware-specific functions */
47859f99965SAlexandre Bounine extern int rio_register_mport(struct rio_mport *);
4796978bbc0SMatt Porter extern int rio_open_inb_mbox(struct rio_mport *, void *, int, int);
48070a50ebdSMatt Porter extern void rio_close_inb_mbox(struct rio_mport *, int);
4816978bbc0SMatt Porter extern int rio_open_outb_mbox(struct rio_mport *, void *, int, int);
48270a50ebdSMatt Porter extern void rio_close_outb_mbox(struct rio_mport *, int);
48370a50ebdSMatt Porter 
48470a50ebdSMatt Porter #endif				/* LINUX_RIO_H */
485