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