xref: /linux/include/linux/rio.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
270a50ebdSMatt Porter /*
370a50ebdSMatt Porter  * RapidIO interconnect services
470a50ebdSMatt Porter  * (RapidIO Interconnect Specification, http://www.rapidio.org)
570a50ebdSMatt Porter  *
670a50ebdSMatt Porter  * Copyright 2005 MontaVista Software, Inc.
770a50ebdSMatt Porter  * Matt Porter <mporter@kernel.crashing.org>
870a50ebdSMatt Porter  */
970a50ebdSMatt Porter 
1070a50ebdSMatt Porter #ifndef LINUX_RIO_H
1170a50ebdSMatt Porter #define LINUX_RIO_H
1270a50ebdSMatt Porter 
1370a50ebdSMatt Porter #include <linux/types.h>
1470a50ebdSMatt Porter #include <linux/ioport.h>
1570a50ebdSMatt Porter #include <linux/list.h>
1670a50ebdSMatt Porter #include <linux/errno.h>
1770a50ebdSMatt Porter #include <linux/device.h>
1870a50ebdSMatt Porter #include <linux/rio_regs.h>
193bdbb62fSAlexandre Bounine #include <linux/mod_devicetable.h>
20e42d98ebSAlexandre Bounine #ifdef CONFIG_RAPIDIO_DMA_ENGINE
21e42d98ebSAlexandre Bounine #include <linux/dmaengine.h>
22e42d98ebSAlexandre Bounine #endif
2370a50ebdSMatt Porter 
2470a50ebdSMatt Porter #define RIO_NO_HOPCOUNT		-1
25c70555b0SAlexandre Bounine #define RIO_INVALID_DESTID	0xffff
2670a50ebdSMatt Porter 
27569fccb6SAlexandre Bounine #define RIO_MAX_MPORTS		8
2870a50ebdSMatt Porter #define RIO_MAX_MPORT_RESOURCES	16
2970a50ebdSMatt Porter #define RIO_MAX_DEV_RESOURCES	16
30ed43f44fSAlexandre Bounine #define RIO_MAX_MPORT_NAME	40
3170a50ebdSMatt Porter 
3270a50ebdSMatt Porter #define RIO_GLOBAL_TABLE	0xff	/* Indicates access of a switch's
3370a50ebdSMatt Porter 					   global routing table if it
3470a50ebdSMatt Porter 					   has multiple (or per port)
3570a50ebdSMatt Porter 					   tables */
3670a50ebdSMatt Porter 
3770a50ebdSMatt Porter #define RIO_INVALID_ROUTE	0xff	/* Indicates that a route table
3870a50ebdSMatt Porter 					   entry is invalid (no route
3970a50ebdSMatt Porter 					   exists for the device ID) */
4070a50ebdSMatt Porter 
41e0423236SZhang Wei #define RIO_MAX_ROUTE_ENTRIES(size)	(size ? (1 << 16) : (1 << 8))
42e0423236SZhang Wei #define RIO_ANY_DESTID(size)		(size ? 0xffff : 0xff)
4370a50ebdSMatt Porter 
4470a50ebdSMatt Porter #define RIO_MAX_MBOX		4
4570a50ebdSMatt Porter #define RIO_MAX_MSG_SIZE	0x1000
4670a50ebdSMatt Porter 
4770a50ebdSMatt Porter /*
4870a50ebdSMatt Porter  * Error values that may be returned by RIO functions.
4970a50ebdSMatt Porter  */
5070a50ebdSMatt Porter #define RIO_SUCCESSFUL			0x00
5170a50ebdSMatt Porter #define RIO_BAD_SIZE			0x81
5270a50ebdSMatt Porter 
5370a50ebdSMatt Porter /*
5470a50ebdSMatt Porter  * For RIO devices, the region numbers are assigned this way:
5570a50ebdSMatt Porter  *
5670a50ebdSMatt Porter  *	0	RapidIO outbound doorbells
5770a50ebdSMatt Porter  *      1-15	RapidIO memory regions
5870a50ebdSMatt Porter  *
5970a50ebdSMatt Porter  * For RIO master ports, the region number are assigned this way:
6070a50ebdSMatt Porter  *
6170a50ebdSMatt Porter  *	0	RapidIO inbound doorbells
6270a50ebdSMatt Porter  *	1	RapidIO inbound mailboxes
63fdb8d561SChad Reese  *	2	RapidIO outbound mailboxes
6470a50ebdSMatt Porter  */
6570a50ebdSMatt Porter #define RIO_DOORBELL_RESOURCE	0
6670a50ebdSMatt Porter #define RIO_INB_MBOX_RESOURCE	1
6770a50ebdSMatt Porter #define RIO_OUTB_MBOX_RESOURCE	2
6870a50ebdSMatt Porter 
69e5cabeb3SAlexandre Bounine #define RIO_PW_MSG_SIZE		64
70e5cabeb3SAlexandre Bounine 
71e6536927SAlexandre Bounine /*
72e6536927SAlexandre Bounine  * A component tag value (stored in the component tag CSR) is used as device's
73e6536927SAlexandre Bounine  * unique identifier assigned during enumeration. Besides being used for
74e6536927SAlexandre Bounine  * identifying switches (which do not have device ID register), it also is used
75e6536927SAlexandre Bounine  * by error management notification and therefore has to be assigned
76e6536927SAlexandre Bounine  * to endpoints as well.
77e6536927SAlexandre Bounine  */
78e6536927SAlexandre Bounine #define RIO_CTAG_RESRVD	0xfffe0000 /* Reserved */
79e6536927SAlexandre Bounine #define RIO_CTAG_UDEVID	0x0001ffff /* Unique device identifier */
80e6536927SAlexandre Bounine 
8170a50ebdSMatt Porter extern struct bus_type rio_bus_type;
822aaf308bSAlexandre Bounine extern struct class rio_mport_class;
8370a50ebdSMatt Porter 
8470a50ebdSMatt Porter struct rio_mport;
85ded05782SAlexandre Bounine struct rio_dev;
86e5cabeb3SAlexandre Bounine union rio_pw_msg;
8770a50ebdSMatt Porter 
8870a50ebdSMatt Porter /**
89ded05782SAlexandre Bounine  * struct rio_switch - RIO switch info
90ded05782SAlexandre Bounine  * @node: Node in global list of switches
91ded05782SAlexandre Bounine  * @route_table: Copy of switch routing table
92ded05782SAlexandre Bounine  * @port_ok: Status of each port (one bit per port) - OK=1 or UNINIT=0
932ec3ba69SAlexandre Bounine  * @ops: pointer to switch-specific operations
942ec3ba69SAlexandre Bounine  * @lock: lock to serialize operations updates
95ded05782SAlexandre Bounine  * @nextdev: Array of per-port pointers to the next attached device
96ded05782SAlexandre Bounine  */
97ded05782SAlexandre Bounine struct rio_switch {
98ded05782SAlexandre Bounine 	struct list_head node;
99ded05782SAlexandre Bounine 	u8 *route_table;
100ded05782SAlexandre Bounine 	u32 port_ok;
1012ec3ba69SAlexandre Bounine 	struct rio_switch_ops *ops;
1022ec3ba69SAlexandre Bounine 	spinlock_t lock;
103a1c4b924SGustavo A. R. Silva 	struct rio_dev *nextdev[];
1042ec3ba69SAlexandre Bounine };
1052ec3ba69SAlexandre Bounine 
1062ec3ba69SAlexandre Bounine /**
1072ec3ba69SAlexandre Bounine  * struct rio_switch_ops - Per-switch operations
1082ec3ba69SAlexandre Bounine  * @owner: The module owner of this structure
1092ec3ba69SAlexandre Bounine  * @add_entry: Callback for switch-specific route add function
1102ec3ba69SAlexandre Bounine  * @get_entry: Callback for switch-specific route get function
1112ec3ba69SAlexandre Bounine  * @clr_table: Callback for switch-specific clear route table function
1122ec3ba69SAlexandre Bounine  * @set_domain: Callback for switch-specific domain setting function
1132ec3ba69SAlexandre Bounine  * @get_domain: Callback for switch-specific domain get function
1142ec3ba69SAlexandre Bounine  * @em_init: Callback for switch-specific error management init function
1152ec3ba69SAlexandre Bounine  * @em_handle: Callback for switch-specific error management handler function
1162ec3ba69SAlexandre Bounine  *
1172ec3ba69SAlexandre Bounine  * Defines the operations that are necessary to initialize/control
1182ec3ba69SAlexandre Bounine  * a particular RIO switch device.
1192ec3ba69SAlexandre Bounine  */
1202ec3ba69SAlexandre Bounine struct rio_switch_ops {
1212ec3ba69SAlexandre Bounine 	struct module *owner;
122ded05782SAlexandre Bounine 	int (*add_entry) (struct rio_mport *mport, u16 destid, u8 hopcount,
123ded05782SAlexandre Bounine 			  u16 table, u16 route_destid, u8 route_port);
124ded05782SAlexandre Bounine 	int (*get_entry) (struct rio_mport *mport, u16 destid, u8 hopcount,
125ded05782SAlexandre Bounine 			  u16 table, u16 route_destid, u8 *route_port);
126ded05782SAlexandre Bounine 	int (*clr_table) (struct rio_mport *mport, u16 destid, u8 hopcount,
127ded05782SAlexandre Bounine 			  u16 table);
128ded05782SAlexandre Bounine 	int (*set_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
129ded05782SAlexandre Bounine 			   u8 sw_domain);
130ded05782SAlexandre Bounine 	int (*get_domain) (struct rio_mport *mport, u16 destid, u8 hopcount,
131ded05782SAlexandre Bounine 			   u8 *sw_domain);
132ded05782SAlexandre Bounine 	int (*em_init) (struct rio_dev *dev);
133ded05782SAlexandre Bounine 	int (*em_handle) (struct rio_dev *dev, u8 swport);
134ded05782SAlexandre Bounine };
135ded05782SAlexandre Bounine 
136b77a2030SAlexandre Bounine enum rio_device_state {
137b77a2030SAlexandre Bounine 	RIO_DEVICE_INITIALIZING,
138b77a2030SAlexandre Bounine 	RIO_DEVICE_RUNNING,
139b77a2030SAlexandre Bounine 	RIO_DEVICE_GONE,
140b77a2030SAlexandre Bounine 	RIO_DEVICE_SHUTDOWN,
141b77a2030SAlexandre Bounine };
142b77a2030SAlexandre Bounine 
143ded05782SAlexandre Bounine /**
14470a50ebdSMatt Porter  * struct rio_dev - RIO device info
14570a50ebdSMatt Porter  * @global_list: Node in list of all RIO devices
14670a50ebdSMatt Porter  * @net_list: Node in list of RIO devices in a network
14770a50ebdSMatt Porter  * @net: Network this device is a part of
1482ec3ba69SAlexandre Bounine  * @do_enum: Enumeration flag
14970a50ebdSMatt Porter  * @did: Device ID
15070a50ebdSMatt Porter  * @vid: Vendor ID
15170a50ebdSMatt Porter  * @device_rev: Device revision
15270a50ebdSMatt Porter  * @asm_did: Assembly device ID
15370a50ebdSMatt Porter  * @asm_vid: Assembly vendor ID
15470a50ebdSMatt Porter  * @asm_rev: Assembly revision
15570a50ebdSMatt Porter  * @efptr: Extended feature pointer
15670a50ebdSMatt Porter  * @pef: Processing element features
15770a50ebdSMatt Porter  * @swpinfo: Switch port info
15870a50ebdSMatt Porter  * @src_ops: Source operation capabilities
15970a50ebdSMatt Porter  * @dst_ops: Destination operation capabilities
16097ef6f74SRandy Dunlap  * @comp_tag: RIO component tag
16197ef6f74SRandy Dunlap  * @phys_efptr: RIO device extended features pointer
1621ae842deSAlexandre Bounine  * @phys_rmap: LP-Serial Register Map Type (1 or 2)
16397ef6f74SRandy Dunlap  * @em_efptr: RIO Error Management features pointer
164fa78cc51SMatt Porter  * @dma_mask: Mask of bits of RIO address this device implements
16570a50ebdSMatt Porter  * @driver: Driver claiming this device
16670a50ebdSMatt Porter  * @dev: Device model device
16770a50ebdSMatt Porter  * @riores: RIO resources this device owns
16897ef6f74SRandy Dunlap  * @pwcback: port-write callback function for this device
169a93192a5SAlexandre Bounine  * @destid: Network destination ID (or associated destid for switch)
170a93192a5SAlexandre Bounine  * @hopcount: Hopcount to this device
17168fe4df5SAlexandre Bounine  * @prev: Previous RIO device connected to the current one
172b77a2030SAlexandre Bounine  * @state: device state
173ded05782SAlexandre Bounine  * @rswitch: struct rio_switch (if valid for this device)
17470a50ebdSMatt Porter  */
17570a50ebdSMatt Porter struct rio_dev {
17670a50ebdSMatt Porter 	struct list_head global_list;	/* node in list of all RIO devices */
17770a50ebdSMatt Porter 	struct list_head net_list;	/* node in per net list */
17870a50ebdSMatt Porter 	struct rio_net *net;	/* RIO net this device resides in */
1792ec3ba69SAlexandre Bounine 	bool do_enum;
18070a50ebdSMatt Porter 	u16 did;
18170a50ebdSMatt Porter 	u16 vid;
18270a50ebdSMatt Porter 	u32 device_rev;
18370a50ebdSMatt Porter 	u16 asm_did;
18470a50ebdSMatt Porter 	u16 asm_vid;
18570a50ebdSMatt Porter 	u16 asm_rev;
18670a50ebdSMatt Porter 	u16 efptr;
18770a50ebdSMatt Porter 	u32 pef;
188ae05cbd5SAlexandre Bounine 	u32 swpinfo;
18970a50ebdSMatt Porter 	u32 src_ops;
19070a50ebdSMatt Porter 	u32 dst_ops;
191e5cabeb3SAlexandre Bounine 	u32 comp_tag;
192e5cabeb3SAlexandre Bounine 	u32 phys_efptr;
1931ae842deSAlexandre Bounine 	u32 phys_rmap;
194e5cabeb3SAlexandre Bounine 	u32 em_efptr;
195fa78cc51SMatt Porter 	u64 dma_mask;
19670a50ebdSMatt Porter 	struct rio_driver *driver;	/* RIO driver claiming this device */
19770a50ebdSMatt Porter 	struct device dev;	/* LDM device structure */
19870a50ebdSMatt Porter 	struct resource riores[RIO_MAX_DEV_RESOURCES];
199e5cabeb3SAlexandre Bounine 	int (*pwcback) (struct rio_dev *rdev, union rio_pw_msg *msg, int step);
20070a50ebdSMatt Porter 	u16 destid;
201a93192a5SAlexandre Bounine 	u8 hopcount;
20268fe4df5SAlexandre Bounine 	struct rio_dev *prev;
203b77a2030SAlexandre Bounine 	atomic_t state;
204a1c4b924SGustavo A. R. Silva 	struct rio_switch rswitch[];	/* RIO switch info */
20570a50ebdSMatt Porter };
20670a50ebdSMatt Porter 
20770a50ebdSMatt Porter #define rio_dev_g(n) list_entry(n, struct rio_dev, global_list)
20870a50ebdSMatt Porter #define rio_dev_f(n) list_entry(n, struct rio_dev, net_list)
20970a50ebdSMatt Porter #define	to_rio_dev(n) container_of(n, struct rio_dev, dev)
210ded05782SAlexandre Bounine #define sw_to_rio_dev(n) container_of(n, struct rio_dev, rswitch[0])
2112aaf308bSAlexandre Bounine #define	to_rio_mport(n) container_of(n, struct rio_mport, dev)
212e6b585caSAlexandre Bounine #define	to_rio_net(n) container_of(n, struct rio_net, dev)
21370a50ebdSMatt Porter 
21470a50ebdSMatt Porter /**
21570a50ebdSMatt Porter  * struct rio_msg - RIO message event
21670a50ebdSMatt Porter  * @res: Mailbox resource
21770a50ebdSMatt Porter  * @mcback: Message event callback
21870a50ebdSMatt Porter  */
21970a50ebdSMatt Porter struct rio_msg {
22070a50ebdSMatt Porter 	struct resource *res;
2216978bbc0SMatt Porter 	void (*mcback) (struct rio_mport * mport, void *dev_id, int mbox, int slot);
22270a50ebdSMatt Porter };
22370a50ebdSMatt Porter 
22470a50ebdSMatt Porter /**
22570a50ebdSMatt Porter  * struct rio_dbell - RIO doorbell event
22670a50ebdSMatt Porter  * @node: Node in list of doorbell events
22770a50ebdSMatt Porter  * @res: Doorbell resource
22870a50ebdSMatt Porter  * @dinb: Doorbell event callback
2296978bbc0SMatt Porter  * @dev_id: Device specific pointer to pass on event
23070a50ebdSMatt Porter  */
23170a50ebdSMatt Porter struct rio_dbell {
23270a50ebdSMatt Porter 	struct list_head node;
23370a50ebdSMatt Porter 	struct resource *res;
2346978bbc0SMatt Porter 	void (*dinb) (struct rio_mport *mport, void *dev_id, u16 src, u16 dst, u16 info);
2356978bbc0SMatt Porter 	void *dev_id;
23670a50ebdSMatt Porter };
23770a50ebdSMatt Porter 
23870a50ebdSMatt Porter /**
23970a50ebdSMatt Porter  * struct rio_mport - RIO master port info
24070a50ebdSMatt Porter  * @dbells: List of doorbell events
2419a0b0627SAlexandre Bounine  * @pwrites: List of portwrite events
24270a50ebdSMatt Porter  * @node: Node in global list of master ports
24370a50ebdSMatt Porter  * @nnode: Node in network list of master ports
244e6b585caSAlexandre Bounine  * @net: RIO net this mport is attached to
245a7b4c636SAlexandre Bounine  * @lock: lock to synchronize lists manipulations
24670a50ebdSMatt Porter  * @iores: I/O mem resource that this master port interface owns
24770a50ebdSMatt Porter  * @riores: RIO resources that this master port interfaces owns
24870a50ebdSMatt Porter  * @inb_msg: RIO inbound message event descriptors
24970a50ebdSMatt Porter  * @outb_msg: RIO outbound message event descriptors
25070a50ebdSMatt Porter  * @host_deviceid: Host device ID associated with this master port
25170a50ebdSMatt Porter  * @ops: configuration space functions
25270a50ebdSMatt Porter  * @id: Port ID, unique among all ports
25370a50ebdSMatt Porter  * @index: Port index, unique among all port interfaces of the same type
2549941d945SRandy Dunlap  * @sys_size: RapidIO common transport system size
255af84ca38SAlexandre Bounine  * @phys_efptr: RIO port extended features pointer
2561ae842deSAlexandre Bounine  * @phys_rmap: LP-Serial EFB Register Mapping type (1 or 2).
25770a50ebdSMatt Porter  * @name: Port name string
2582aaf308bSAlexandre Bounine  * @dev: device structure associated with an mport
259ad1e9380SZhang Wei  * @priv: Master port private data
260fe50c927SAlexandre Bounine  * @dma: DMA device associated with mport
261a11650e1SAlexandre Bounine  * @nscan: RapidIO network enumeration/discovery operations
262b77a2030SAlexandre Bounine  * @state: mport device state
263b6cb95e8SAlexandre Bounine  * @pwe_refcnt: port-write enable ref counter to track enable/disable requests
26470a50ebdSMatt Porter  */
26570a50ebdSMatt Porter struct rio_mport {
26670a50ebdSMatt Porter 	struct list_head dbells;	/* list of doorbell events */
2679a0b0627SAlexandre Bounine 	struct list_head pwrites;	/* list of portwrite events */
26870a50ebdSMatt Porter 	struct list_head node;	/* node in global list of ports */
26970a50ebdSMatt Porter 	struct list_head nnode;	/* node in net list of ports */
270e6b585caSAlexandre Bounine 	struct rio_net *net;	/* RIO net this mport is attached to */
271a7b4c636SAlexandre Bounine 	struct mutex lock;
27270a50ebdSMatt Porter 	struct resource iores;
27370a50ebdSMatt Porter 	struct resource riores[RIO_MAX_MPORT_RESOURCES];
27470a50ebdSMatt Porter 	struct rio_msg inb_msg[RIO_MAX_MBOX];
27570a50ebdSMatt Porter 	struct rio_msg outb_msg[RIO_MAX_MBOX];
27670a50ebdSMatt Porter 	int host_deviceid;	/* Host device ID */
277f8f06269SAlexandre Bounine 	struct rio_ops *ops;	/* low-level architecture-dependent routines */
27870a50ebdSMatt Porter 	unsigned char id;	/* port ID, unique among all ports */
27970a50ebdSMatt Porter 	unsigned char index;	/* port index, unique among all port
28070a50ebdSMatt Porter 				   interfaces of the same type */
281e0423236SZhang Wei 	unsigned int sys_size;	/* RapidIO common transport system size.
282e0423236SZhang Wei 				 * 0 - Small size. 256 devices.
283e0423236SZhang Wei 				 * 1 - Large size, 65536 devices.
284e0423236SZhang Wei 				 */
285af84ca38SAlexandre Bounine 	u32 phys_efptr;
2861ae842deSAlexandre Bounine 	u32 phys_rmap;
287ed43f44fSAlexandre Bounine 	unsigned char name[RIO_MAX_MPORT_NAME];
2882aaf308bSAlexandre Bounine 	struct device dev;
289ad1e9380SZhang Wei 	void *priv;		/* Master port private data */
290e42d98ebSAlexandre Bounine #ifdef CONFIG_RAPIDIO_DMA_ENGINE
291e42d98ebSAlexandre Bounine 	struct dma_device	dma;
292e42d98ebSAlexandre Bounine #endif
293a11650e1SAlexandre Bounine 	struct rio_scan *nscan;
294b77a2030SAlexandre Bounine 	atomic_t state;
295b6cb95e8SAlexandre Bounine 	unsigned int pwe_refcnt;
29670a50ebdSMatt Porter };
29770a50ebdSMatt Porter 
rio_mport_is_running(struct rio_mport * mport)298b77a2030SAlexandre Bounine static inline int rio_mport_is_running(struct rio_mport *mport)
299b77a2030SAlexandre Bounine {
300b77a2030SAlexandre Bounine 	return atomic_read(&mport->state) == RIO_DEVICE_RUNNING;
301b77a2030SAlexandre Bounine }
302b77a2030SAlexandre Bounine 
303bc8fcfeaSAlexandre Bounine /*
304bc8fcfeaSAlexandre Bounine  * Enumeration/discovery control flags
305bc8fcfeaSAlexandre Bounine  */
306bc8fcfeaSAlexandre Bounine #define RIO_SCAN_ENUM_NO_WAIT	0x00000001 /* Do not wait for enum completed */
307bc8fcfeaSAlexandre Bounine 
30870a50ebdSMatt Porter /**
30970a50ebdSMatt Porter  * struct rio_net - RIO network info
31070a50ebdSMatt Porter  * @node: Node in global list of RIO networks
31170a50ebdSMatt Porter  * @devices: List of devices in this network
31276679286SMasanari Iida  * @switches: List of switches in this network
31370a50ebdSMatt Porter  * @mports: List of master ports accessing this network
31470a50ebdSMatt Porter  * @hport: Default port for accessing this network
31570a50ebdSMatt Porter  * @id: RIO network ID
316e6b585caSAlexandre Bounine  * @dev: Device object
317e6b585caSAlexandre Bounine  * @enum_data: private data specific to a network enumerator
318e6b585caSAlexandre Bounine  * @release: enumerator-specific release callback
31970a50ebdSMatt Porter  */
32070a50ebdSMatt Porter struct rio_net {
32170a50ebdSMatt Porter 	struct list_head node;	/* node in list of networks */
32270a50ebdSMatt Porter 	struct list_head devices;	/* list of devices in this net */
323a7071efcSAlexandre Bounine 	struct list_head switches;	/* list of switches in this net */
32470a50ebdSMatt Porter 	struct list_head mports;	/* list of ports accessing net */
32570a50ebdSMatt Porter 	struct rio_mport *hport;	/* primary port for accessing net */
32670a50ebdSMatt Porter 	unsigned char id;	/* RIO network ID */
327e6b585caSAlexandre Bounine 	struct device dev;
328e6b585caSAlexandre Bounine 	void *enum_data;	/* private data for enumerator of the network */
329e6b585caSAlexandre Bounine 	void (*release)(struct rio_net *net);
33070a50ebdSMatt Porter };
33170a50ebdSMatt Porter 
3328b189fdbSAlexandre Bounine enum rio_link_speed {
3338b189fdbSAlexandre Bounine 	RIO_LINK_DOWN = 0, /* SRIO Link not initialized */
3348b189fdbSAlexandre Bounine 	RIO_LINK_125 = 1, /* 1.25 GBaud  */
3358b189fdbSAlexandre Bounine 	RIO_LINK_250 = 2, /* 2.5 GBaud   */
3368b189fdbSAlexandre Bounine 	RIO_LINK_312 = 3, /* 3.125 GBaud */
3378b189fdbSAlexandre Bounine 	RIO_LINK_500 = 4, /* 5.0 GBaud   */
3388b189fdbSAlexandre Bounine 	RIO_LINK_625 = 5  /* 6.25 GBaud  */
3398b189fdbSAlexandre Bounine };
3408b189fdbSAlexandre Bounine 
3418b189fdbSAlexandre Bounine enum rio_link_width {
3428b189fdbSAlexandre Bounine 	RIO_LINK_1X  = 0,
3438b189fdbSAlexandre Bounine 	RIO_LINK_1XR = 1,
3448b189fdbSAlexandre Bounine 	RIO_LINK_2X  = 3,
3458b189fdbSAlexandre Bounine 	RIO_LINK_4X  = 2,
3468b189fdbSAlexandre Bounine 	RIO_LINK_8X  = 4,
3478b189fdbSAlexandre Bounine 	RIO_LINK_16X = 5
3488b189fdbSAlexandre Bounine };
3498b189fdbSAlexandre Bounine 
3508b189fdbSAlexandre Bounine enum rio_mport_flags {
3518b189fdbSAlexandre Bounine 	RIO_MPORT_DMA	 = (1 << 0), /* supports DMA data transfers */
3528b189fdbSAlexandre Bounine 	RIO_MPORT_DMA_SG = (1 << 1), /* DMA supports HW SG mode */
3538b189fdbSAlexandre Bounine 	RIO_MPORT_IBSG	 = (1 << 2), /* inbound mapping supports SG */
3548b189fdbSAlexandre Bounine };
3558b189fdbSAlexandre Bounine 
3568b189fdbSAlexandre Bounine /**
3578b189fdbSAlexandre Bounine  * struct rio_mport_attr - RIO mport device attributes
3588b189fdbSAlexandre Bounine  * @flags: mport device capability flags
3598b189fdbSAlexandre Bounine  * @link_speed: SRIO link speed value (as defined by RapidIO specification)
3608b189fdbSAlexandre Bounine  * @link_width:	SRIO link width value (as defined by RapidIO specification)
3618b189fdbSAlexandre Bounine  * @dma_max_sge: number of SG list entries that can be handled by DMA channel(s)
3628b189fdbSAlexandre Bounine  * @dma_max_size: max number of bytes in single DMA transfer (SG entry)
3638b189fdbSAlexandre Bounine  * @dma_align: alignment shift for DMA operations (as for other DMA operations)
3648b189fdbSAlexandre Bounine  */
3658b189fdbSAlexandre Bounine struct rio_mport_attr {
3668b189fdbSAlexandre Bounine 	int flags;
3678b189fdbSAlexandre Bounine 	int link_speed;
3688b189fdbSAlexandre Bounine 	int link_width;
3698b189fdbSAlexandre Bounine 
3708b189fdbSAlexandre Bounine 	/* DMA capability info: valid only if RIO_MPORT_DMA flag is set */
3718b189fdbSAlexandre Bounine 	int dma_max_sge;
3728b189fdbSAlexandre Bounine 	int dma_max_size;
3738b189fdbSAlexandre Bounine 	int dma_align;
3748b189fdbSAlexandre Bounine };
3758b189fdbSAlexandre Bounine 
37670a50ebdSMatt Porter /* Low-level architecture-dependent routines */
37770a50ebdSMatt Porter 
37870a50ebdSMatt Porter /**
37970a50ebdSMatt Porter  * struct rio_ops - Low-level RIO configuration space operations
38070a50ebdSMatt Porter  * @lcread: Callback to perform local (master port) read of config space.
38170a50ebdSMatt Porter  * @lcwrite: Callback to perform local (master port) write of config space.
38270a50ebdSMatt Porter  * @cread: Callback to perform network read of config space.
38370a50ebdSMatt Porter  * @cwrite: Callback to perform network write of config space.
38470a50ebdSMatt Porter  * @dsend: Callback to send a doorbell message.
385e5cabeb3SAlexandre Bounine  * @pwenable: Callback to enable/disable port-write message handling.
386f8f06269SAlexandre Bounine  * @open_outb_mbox: Callback to initialize outbound mailbox.
387f8f06269SAlexandre Bounine  * @close_outb_mbox: Callback to shut down outbound mailbox.
388f8f06269SAlexandre Bounine  * @open_inb_mbox: Callback to initialize inbound mailbox.
389f8f06269SAlexandre Bounine  * @close_inb_mbox: Callback to	shut down inbound mailbox.
390f8f06269SAlexandre Bounine  * @add_outb_message: Callback to add a message to an outbound mailbox queue.
391f8f06269SAlexandre Bounine  * @add_inb_buffer: Callback to	add a buffer to an inbound mailbox queue.
392f8f06269SAlexandre Bounine  * @get_inb_message: Callback to get a message from an inbound mailbox queue.
393da1589f0SAlexandre Bounine  * @map_inb: Callback to map RapidIO address region into local memory space.
394da1589f0SAlexandre Bounine  * @unmap_inb: Callback to unmap RapidIO address region mapped with map_inb().
3958b189fdbSAlexandre Bounine  * @query_mport: Callback to query mport device attributes.
39693bdaca5SAlexandre Bounine  * @map_outb: Callback to map outbound address region into local memory space.
39793bdaca5SAlexandre Bounine  * @unmap_outb: Callback to unmap outbound RapidIO address region.
39870a50ebdSMatt Porter  */
39970a50ebdSMatt Porter struct rio_ops {
400ad1e9380SZhang Wei 	int (*lcread) (struct rio_mport *mport, int index, u32 offset, int len,
40170a50ebdSMatt Porter 			u32 *data);
402ad1e9380SZhang Wei 	int (*lcwrite) (struct rio_mport *mport, int index, u32 offset, int len,
40370a50ebdSMatt Porter 			u32 data);
404ad1e9380SZhang Wei 	int (*cread) (struct rio_mport *mport, int index, u16 destid,
405ad1e9380SZhang Wei 			u8 hopcount, u32 offset, int len, u32 *data);
406ad1e9380SZhang Wei 	int (*cwrite) (struct rio_mport *mport, int index, u16 destid,
407ad1e9380SZhang Wei 			u8 hopcount, u32 offset, int len, u32 data);
408ad1e9380SZhang Wei 	int (*dsend) (struct rio_mport *mport, int index, u16 destid, u16 data);
409e5cabeb3SAlexandre Bounine 	int (*pwenable) (struct rio_mport *mport, int enable);
410f8f06269SAlexandre Bounine 	int (*open_outb_mbox)(struct rio_mport *mport, void *dev_id,
411f8f06269SAlexandre Bounine 			      int mbox, int entries);
412f8f06269SAlexandre Bounine 	void (*close_outb_mbox)(struct rio_mport *mport, int mbox);
413f8f06269SAlexandre Bounine 	int  (*open_inb_mbox)(struct rio_mport *mport, void *dev_id,
414f8f06269SAlexandre Bounine 			     int mbox, int entries);
415f8f06269SAlexandre Bounine 	void (*close_inb_mbox)(struct rio_mport *mport, int mbox);
416f8f06269SAlexandre Bounine 	int  (*add_outb_message)(struct rio_mport *mport, struct rio_dev *rdev,
417f8f06269SAlexandre Bounine 				 int mbox, void *buffer, size_t len);
418f8f06269SAlexandre Bounine 	int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
419f8f06269SAlexandre Bounine 	void *(*get_inb_message)(struct rio_mport *mport, int mbox);
420da1589f0SAlexandre Bounine 	int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
421a057a52eSAlexandre Bounine 			u64 rstart, u64 size, u32 flags);
422da1589f0SAlexandre Bounine 	void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
4238b189fdbSAlexandre Bounine 	int (*query_mport)(struct rio_mport *mport,
4248b189fdbSAlexandre Bounine 			   struct rio_mport_attr *attr);
42593bdaca5SAlexandre Bounine 	int (*map_outb)(struct rio_mport *mport, u16 destid, u64 rstart,
42693bdaca5SAlexandre Bounine 			u32 size, u32 flags, dma_addr_t *laddr);
42793bdaca5SAlexandre Bounine 	void (*unmap_outb)(struct rio_mport *mport, u16 destid, u64 rstart);
42870a50ebdSMatt Porter };
42970a50ebdSMatt Porter 
43070a50ebdSMatt Porter #define RIO_RESOURCE_MEM	0x00000100
43170a50ebdSMatt Porter #define RIO_RESOURCE_DOORBELL	0x00000200
43270a50ebdSMatt Porter #define RIO_RESOURCE_MAILBOX	0x00000400
43370a50ebdSMatt Porter 
43470a50ebdSMatt Porter #define RIO_RESOURCE_CACHEABLE	0x00010000
43570a50ebdSMatt Porter #define RIO_RESOURCE_PCI	0x00020000
43670a50ebdSMatt Porter 
43770a50ebdSMatt Porter #define RIO_RESOURCE_BUSY	0x80000000
43870a50ebdSMatt Porter 
43970a50ebdSMatt Porter /**
44070a50ebdSMatt Porter  * struct rio_driver - RIO driver info
44170a50ebdSMatt Porter  * @node: Node in list of drivers
44270a50ebdSMatt Porter  * @name: RIO driver name
44370a50ebdSMatt Porter  * @id_table: RIO device ids to be associated with this driver
44470a50ebdSMatt Porter  * @probe: RIO device inserted
44570a50ebdSMatt Porter  * @remove: RIO device removed
44683dc2cbcSAlexandre Bounine  * @shutdown: shutdown notification callback
44770a50ebdSMatt Porter  * @suspend: RIO device suspended
44870a50ebdSMatt Porter  * @resume: RIO device awakened
44970a50ebdSMatt Porter  * @enable_wake: RIO device enable wake event
45070a50ebdSMatt Porter  * @driver: LDM driver struct
45170a50ebdSMatt Porter  *
45270a50ebdSMatt Porter  * Provides info on a RIO device driver for insertion/removal and
45370a50ebdSMatt Porter  * power management purposes.
45470a50ebdSMatt Porter  */
45570a50ebdSMatt Porter struct rio_driver {
45670a50ebdSMatt Porter 	struct list_head node;
45770a50ebdSMatt Porter 	char *name;
45870a50ebdSMatt Porter 	const struct rio_device_id *id_table;
45970a50ebdSMatt Porter 	int (*probe) (struct rio_dev * dev, const struct rio_device_id * id);
46070a50ebdSMatt Porter 	void (*remove) (struct rio_dev * dev);
46183dc2cbcSAlexandre Bounine 	void (*shutdown)(struct rio_dev *dev);
46270a50ebdSMatt Porter 	int (*suspend) (struct rio_dev * dev, u32 state);
46370a50ebdSMatt Porter 	int (*resume) (struct rio_dev * dev);
46470a50ebdSMatt Porter 	int (*enable_wake) (struct rio_dev * dev, u32 state, int enable);
46570a50ebdSMatt Porter 	struct device_driver driver;
46670a50ebdSMatt Porter };
46770a50ebdSMatt Porter 
468*d69d8048SGreg Kroah-Hartman #define	to_rio_driver(drv) container_of_const(drv,struct rio_driver, driver)
46970a50ebdSMatt Porter 
470e5cabeb3SAlexandre Bounine union rio_pw_msg {
471e5cabeb3SAlexandre Bounine 	struct {
472e5cabeb3SAlexandre Bounine 		u32 comptag;	/* Component Tag CSR */
473e5cabeb3SAlexandre Bounine 		u32 errdetect;	/* Port N Error Detect CSR */
474e5cabeb3SAlexandre Bounine 		u32 is_port;	/* Implementation specific + PortID */
475e5cabeb3SAlexandre Bounine 		u32 ltlerrdet;	/* LTL Error Detect CSR */
476e5cabeb3SAlexandre Bounine 		u32 padding[12];
477e5cabeb3SAlexandre Bounine 	} em;
478e5cabeb3SAlexandre Bounine 	u32 raw[RIO_PW_MSG_SIZE/sizeof(u32)];
479e5cabeb3SAlexandre Bounine };
480e5cabeb3SAlexandre Bounine 
481e42d98ebSAlexandre Bounine #ifdef CONFIG_RAPIDIO_DMA_ENGINE
482e42d98ebSAlexandre Bounine 
483fe50c927SAlexandre Bounine /*
484e42d98ebSAlexandre Bounine  * enum rio_write_type - RIO write transaction types used in DMA transfers
485e42d98ebSAlexandre Bounine  *
486e42d98ebSAlexandre Bounine  * Note: RapidIO specification defines write (NWRITE) and
487e42d98ebSAlexandre Bounine  * write-with-response (NWRITE_R) data transfer operations.
488e42d98ebSAlexandre Bounine  * Existing DMA controllers that service RapidIO may use one of these operations
489e42d98ebSAlexandre Bounine  * for entire data transfer or their combination with only the last data packet
490e42d98ebSAlexandre Bounine  * requires response.
491e42d98ebSAlexandre Bounine  */
492e42d98ebSAlexandre Bounine enum rio_write_type {
493e42d98ebSAlexandre Bounine 	RDW_DEFAULT,		/* default method used by DMA driver */
494e42d98ebSAlexandre Bounine 	RDW_ALL_NWRITE,		/* all packets use NWRITE */
495e42d98ebSAlexandre Bounine 	RDW_ALL_NWRITE_R,	/* all packets use NWRITE_R */
496e42d98ebSAlexandre Bounine 	RDW_LAST_NWRITE_R,	/* last packet uses NWRITE_R, others - NWRITE */
497e42d98ebSAlexandre Bounine };
498e42d98ebSAlexandre Bounine 
499e42d98ebSAlexandre Bounine struct rio_dma_ext {
500e42d98ebSAlexandre Bounine 	u16 destid;
501e42d98ebSAlexandre Bounine 	u64 rio_addr;	/* low 64-bits of 66-bit RapidIO address */
502e42d98ebSAlexandre Bounine 	u8  rio_addr_u;  /* upper 2-bits of 66-bit RapidIO address */
503e42d98ebSAlexandre Bounine 	enum rio_write_type wr_type; /* preferred RIO write operation type */
504e42d98ebSAlexandre Bounine };
505e42d98ebSAlexandre Bounine 
506e42d98ebSAlexandre Bounine struct rio_dma_data {
507e42d98ebSAlexandre Bounine 	/* Local data (as scatterlist) */
508e42d98ebSAlexandre Bounine 	struct scatterlist	*sg;	/* I/O scatter list */
509e42d98ebSAlexandre Bounine 	unsigned int		sg_len;	/* size of scatter list */
510e42d98ebSAlexandre Bounine 	/* Remote device address (flat buffer) */
511e42d98ebSAlexandre Bounine 	u64 rio_addr;	/* low 64-bits of 66-bit RapidIO address */
512e42d98ebSAlexandre Bounine 	u8  rio_addr_u;  /* upper 2-bits of 66-bit RapidIO address */
513e42d98ebSAlexandre Bounine 	enum rio_write_type wr_type; /* preferred RIO write operation type */
514e42d98ebSAlexandre Bounine };
515e42d98ebSAlexandre Bounine 
dma_to_mport(struct dma_device * ddev)516e42d98ebSAlexandre Bounine static inline struct rio_mport *dma_to_mport(struct dma_device *ddev)
517e42d98ebSAlexandre Bounine {
518e42d98ebSAlexandre Bounine 	return container_of(ddev, struct rio_mport, dma);
519e42d98ebSAlexandre Bounine }
520e42d98ebSAlexandre Bounine #endif /* CONFIG_RAPIDIO_DMA_ENGINE */
521e42d98ebSAlexandre Bounine 
522a11650e1SAlexandre Bounine /**
523a11650e1SAlexandre Bounine  * struct rio_scan - RIO enumeration and discovery operations
5249edbc30bSAlexandre Bounine  * @owner: The module owner of this structure
525a11650e1SAlexandre Bounine  * @enumerate: Callback to perform RapidIO fabric enumeration.
526a11650e1SAlexandre Bounine  * @discover: Callback to perform RapidIO fabric discovery.
527a11650e1SAlexandre Bounine  */
528a11650e1SAlexandre Bounine struct rio_scan {
5299edbc30bSAlexandre Bounine 	struct module *owner;
530bc8fcfeaSAlexandre Bounine 	int (*enumerate)(struct rio_mport *mport, u32 flags);
531bc8fcfeaSAlexandre Bounine 	int (*discover)(struct rio_mport *mport, u32 flags);
532a11650e1SAlexandre Bounine };
533a11650e1SAlexandre Bounine 
5349edbc30bSAlexandre Bounine /**
5359edbc30bSAlexandre Bounine  * struct rio_scan_node - list node to register RapidIO enumeration and
5369edbc30bSAlexandre Bounine  * discovery methods with RapidIO core.
5379edbc30bSAlexandre Bounine  * @mport_id: ID of an mport (net) serviced by this enumerator
5389edbc30bSAlexandre Bounine  * @node: node in global list of registered enumerators
5399edbc30bSAlexandre Bounine  * @ops: RIO enumeration and discovery operations
5409edbc30bSAlexandre Bounine  */
5419edbc30bSAlexandre Bounine struct rio_scan_node {
5429edbc30bSAlexandre Bounine 	int mport_id;
5439edbc30bSAlexandre Bounine 	struct list_head node;
5449edbc30bSAlexandre Bounine 	struct rio_scan *ops;
5459edbc30bSAlexandre Bounine };
5469edbc30bSAlexandre Bounine 
54770a50ebdSMatt Porter /* Architecture and hardware-specific functions */
548b77a2030SAlexandre Bounine extern int rio_mport_initialize(struct rio_mport *);
54959f99965SAlexandre Bounine extern int rio_register_mport(struct rio_mport *);
550b77a2030SAlexandre Bounine extern int rio_unregister_mport(struct rio_mport *);
5516978bbc0SMatt Porter extern int rio_open_inb_mbox(struct rio_mport *, void *, int, int);
55270a50ebdSMatt Porter extern void rio_close_inb_mbox(struct rio_mport *, int);
5536978bbc0SMatt Porter extern int rio_open_outb_mbox(struct rio_mport *, void *, int, int);
55470a50ebdSMatt Porter extern void rio_close_outb_mbox(struct rio_mport *, int);
5558b189fdbSAlexandre Bounine extern int rio_query_mport(struct rio_mport *port,
5568b189fdbSAlexandre Bounine 			   struct rio_mport_attr *mport_attr);
55770a50ebdSMatt Porter 
55870a50ebdSMatt Porter #endif				/* LINUX_RIO_H */
559