xref: /openbmc/linux/drivers/rapidio/rio.h (revision e5cabeb3d60f9cd3e3950aff071319ae0e2d08d8)
1394b701cSMatt Porter /*
2394b701cSMatt Porter  * RapidIO interconnect services
3394b701cSMatt Porter  *
4394b701cSMatt Porter  * Copyright 2005 MontaVista Software, Inc.
5394b701cSMatt Porter  * Matt Porter <mporter@kernel.crashing.org>
6394b701cSMatt Porter  *
7394b701cSMatt Porter  * This program is free software; you can redistribute  it and/or modify it
8394b701cSMatt Porter  * under  the terms of  the GNU General  Public License as published by the
9394b701cSMatt Porter  * Free Software Foundation;  either version 2 of the  License, or (at your
10394b701cSMatt Porter  * option) any later version.
11394b701cSMatt Porter  */
12394b701cSMatt Porter 
13394b701cSMatt Porter #include <linux/device.h>
14394b701cSMatt Porter #include <linux/list.h>
15394b701cSMatt Porter #include <linux/rio.h>
16394b701cSMatt Porter 
17394b701cSMatt Porter /* Functions internal to the RIO core code */
18394b701cSMatt Porter 
19394b701cSMatt Porter extern u32 rio_mport_get_feature(struct rio_mport *mport, int local, u16 destid,
20394b701cSMatt Porter 				 u8 hopcount, int ftr);
21*e5cabeb3SAlexandre Bounine extern u32 rio_mport_get_physefb(struct rio_mport *port, int local,
22*e5cabeb3SAlexandre Bounine 				 u16 destid, u8 hopcount);
23*e5cabeb3SAlexandre Bounine extern u32 rio_mport_get_efb(struct rio_mport *port, int local, u16 destid,
24*e5cabeb3SAlexandre Bounine 			     u8 hopcount, u32 from);
25394b701cSMatt Porter extern int rio_create_sysfs_dev_files(struct rio_dev *rdev);
26394b701cSMatt Porter extern int rio_enum_mport(struct rio_mport *mport);
27394b701cSMatt Porter extern int rio_disc_mport(struct rio_mport *mport);
2807590ff0SAlexandre Bounine extern int rio_std_route_add_entry(struct rio_mport *mport, u16 destid,
2907590ff0SAlexandre Bounine 				   u8 hopcount, u16 table, u16 route_destid,
3007590ff0SAlexandre Bounine 				   u8 route_port);
3107590ff0SAlexandre Bounine extern int rio_std_route_get_entry(struct rio_mport *mport, u16 destid,
3207590ff0SAlexandre Bounine 				   u8 hopcount, u16 table, u16 route_destid,
3307590ff0SAlexandre Bounine 				   u8 *route_port);
3407590ff0SAlexandre Bounine extern int rio_std_route_clr_table(struct rio_mport *mport, u16 destid,
3507590ff0SAlexandre Bounine 				   u8 hopcount, u16 table);
36*e5cabeb3SAlexandre Bounine extern int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock);
37394b701cSMatt Porter 
38394b701cSMatt Porter /* Structures internal to the RIO core code */
39394b701cSMatt Porter extern struct device_attribute rio_dev_attrs[];
40394b701cSMatt Porter extern spinlock_t rio_global_list_lock;
41394b701cSMatt Porter 
42fa78cc51SMatt Porter extern struct rio_route_ops __start_rio_route_ops[];
43fa78cc51SMatt Porter extern struct rio_route_ops __end_rio_route_ops[];
44fa78cc51SMatt Porter 
45394b701cSMatt Porter /* Helpers internal to the RIO core code */
4607590ff0SAlexandre Bounine #define DECLARE_RIO_ROUTE_SECTION(section, name, vid, did, add_hook, get_hook, clr_hook) \
4707590ff0SAlexandre Bounine 	static const struct rio_route_ops __rio_route_##name __used \
4807590ff0SAlexandre Bounine 	__section(section) = { vid, did, add_hook, get_hook, clr_hook };
49394b701cSMatt Porter 
50394b701cSMatt Porter /**
51394b701cSMatt Porter  * DECLARE_RIO_ROUTE_OPS - Registers switch routing operations
52394b701cSMatt Porter  * @vid: RIO vendor ID
53394b701cSMatt Porter  * @did: RIO device ID
54394b701cSMatt Porter  * @add_hook: Callback that adds a route entry
55394b701cSMatt Porter  * @get_hook: Callback that gets a route entry
56394b701cSMatt Porter  *
57394b701cSMatt Porter  * Manipulating switch route tables in RIO is switch specific. This
58394b701cSMatt Porter  * registers a switch by vendor and device ID with two callbacks for
59394b701cSMatt Porter  * modifying and retrieving route entries in a switch. A &struct
60394b701cSMatt Porter  * rio_route_ops is initialized with the ops and placed into a
61394b701cSMatt Porter  * RIO-specific kernel section.
62394b701cSMatt Porter  */
6307590ff0SAlexandre Bounine #define DECLARE_RIO_ROUTE_OPS(vid, did, add_hook, get_hook, clr_hook)	\
6407590ff0SAlexandre Bounine 	DECLARE_RIO_ROUTE_SECTION(.rio_route_ops, vid##did,		\
6507590ff0SAlexandre Bounine 			vid, did, add_hook, get_hook, clr_hook)
66394b701cSMatt Porter 
67e0423236SZhang Wei #define RIO_GET_DID(size, x)	(size ? (x & 0xffff) : ((x & 0x00ff0000) >> 16))
68e0423236SZhang Wei #define RIO_SET_DID(size, x)	(size ? (x & 0xffff) : ((x & 0x000000ff) << 16))
69*e5cabeb3SAlexandre Bounine 
70*e5cabeb3SAlexandre Bounine /*
71*e5cabeb3SAlexandre Bounine  *   RapidIO Error Management
72*e5cabeb3SAlexandre Bounine  */
73*e5cabeb3SAlexandre Bounine extern struct rio_em_ops __start_rio_em_ops[];
74*e5cabeb3SAlexandre Bounine extern struct rio_em_ops __end_rio_em_ops[];
75*e5cabeb3SAlexandre Bounine 
76*e5cabeb3SAlexandre Bounine /* Helpers internal to the RIO core code */
77*e5cabeb3SAlexandre Bounine #define DECLARE_RIO_EM_SECTION(section, name, vid, did, init_hook, em_hook)  \
78*e5cabeb3SAlexandre Bounine 	static const struct rio_em_ops __rio_em_##name __used   \
79*e5cabeb3SAlexandre Bounine 	__section(section) = { vid, did, init_hook, em_hook };
80*e5cabeb3SAlexandre Bounine 
81*e5cabeb3SAlexandre Bounine /**
82*e5cabeb3SAlexandre Bounine  * DECLARE_RIO_EM_OPS - Registers switch EM operations
83*e5cabeb3SAlexandre Bounine  * @vid: RIO vendor ID
84*e5cabeb3SAlexandre Bounine  * @did: RIO device ID
85*e5cabeb3SAlexandre Bounine  * @init_hook: Callback that initializes device specific EM
86*e5cabeb3SAlexandre Bounine  * @em_hook: Callback that handles device specific EM
87*e5cabeb3SAlexandre Bounine  *
88*e5cabeb3SAlexandre Bounine  * A &struct rio_em_ops is initialized with the ops and placed into a
89*e5cabeb3SAlexandre Bounine  * RIO-specific kernel section.
90*e5cabeb3SAlexandre Bounine  */
91*e5cabeb3SAlexandre Bounine #define DECLARE_RIO_EM_OPS(vid, did, init_hook, em_hook)	\
92*e5cabeb3SAlexandre Bounine 	DECLARE_RIO_EM_SECTION(.rio_em_ops, vid##did,		\
93*e5cabeb3SAlexandre Bounine 			vid, did, init_hook, em_hook)
94