Commit b53c7583e26746ef6f66c866841e10450150ed8e
Committed by
Paul Mackerras
1 parent
aab0d375e0
Exists in
master
and in
7 other branches
rapidio: struct device - replace bus_id with dev_name(), dev_set_name()
Cc: Matt Porter <mporter@kernel.crashing.org> Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Paul Mackerras <paulus@samba.org>
Showing 2 changed files with 6 additions and 6 deletions Inline Diff
drivers/rapidio/rio-scan.c
1 | /* | 1 | /* |
2 | * RapidIO enumeration and discovery support | 2 | * RapidIO enumeration and discovery support |
3 | * | 3 | * |
4 | * Copyright 2005 MontaVista Software, Inc. | 4 | * Copyright 2005 MontaVista Software, Inc. |
5 | * Matt Porter <mporter@kernel.crashing.org> | 5 | * Matt Porter <mporter@kernel.crashing.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify it | 7 | * This program is free software; you can redistribute it and/or modify it |
8 | * under the terms of the GNU General Public License as published by the | 8 | * under the terms of the GNU General Public License as published by the |
9 | * Free Software Foundation; either version 2 of the License, or (at your | 9 | * Free Software Foundation; either version 2 of the License, or (at your |
10 | * option) any later version. | 10 | * option) any later version. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/types.h> | 13 | #include <linux/types.h> |
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | 15 | ||
16 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
17 | #include <linux/dma-mapping.h> | 17 | #include <linux/dma-mapping.h> |
18 | #include <linux/init.h> | 18 | #include <linux/init.h> |
19 | #include <linux/rio.h> | 19 | #include <linux/rio.h> |
20 | #include <linux/rio_drv.h> | 20 | #include <linux/rio_drv.h> |
21 | #include <linux/rio_ids.h> | 21 | #include <linux/rio_ids.h> |
22 | #include <linux/rio_regs.h> | 22 | #include <linux/rio_regs.h> |
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/spinlock.h> | 24 | #include <linux/spinlock.h> |
25 | #include <linux/timer.h> | 25 | #include <linux/timer.h> |
26 | #include <linux/jiffies.h> | 26 | #include <linux/jiffies.h> |
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | 28 | ||
29 | #include "rio.h" | 29 | #include "rio.h" |
30 | 30 | ||
31 | LIST_HEAD(rio_devices); | 31 | LIST_HEAD(rio_devices); |
32 | static LIST_HEAD(rio_switches); | 32 | static LIST_HEAD(rio_switches); |
33 | 33 | ||
34 | #define RIO_ENUM_CMPL_MAGIC 0xdeadbeef | 34 | #define RIO_ENUM_CMPL_MAGIC 0xdeadbeef |
35 | 35 | ||
36 | static void rio_enum_timeout(unsigned long); | 36 | static void rio_enum_timeout(unsigned long); |
37 | 37 | ||
38 | DEFINE_SPINLOCK(rio_global_list_lock); | 38 | DEFINE_SPINLOCK(rio_global_list_lock); |
39 | 39 | ||
40 | static int next_destid = 0; | 40 | static int next_destid = 0; |
41 | static int next_switchid = 0; | 41 | static int next_switchid = 0; |
42 | static int next_net = 0; | 42 | static int next_net = 0; |
43 | 43 | ||
44 | static struct timer_list rio_enum_timer = | 44 | static struct timer_list rio_enum_timer = |
45 | TIMER_INITIALIZER(rio_enum_timeout, 0, 0); | 45 | TIMER_INITIALIZER(rio_enum_timeout, 0, 0); |
46 | 46 | ||
47 | static int rio_mport_phys_table[] = { | 47 | static int rio_mport_phys_table[] = { |
48 | RIO_EFB_PAR_EP_ID, | 48 | RIO_EFB_PAR_EP_ID, |
49 | RIO_EFB_PAR_EP_REC_ID, | 49 | RIO_EFB_PAR_EP_REC_ID, |
50 | RIO_EFB_SER_EP_ID, | 50 | RIO_EFB_SER_EP_ID, |
51 | RIO_EFB_SER_EP_REC_ID, | 51 | RIO_EFB_SER_EP_REC_ID, |
52 | -1, | 52 | -1, |
53 | }; | 53 | }; |
54 | 54 | ||
55 | static int rio_sport_phys_table[] = { | 55 | static int rio_sport_phys_table[] = { |
56 | RIO_EFB_PAR_EP_FREE_ID, | 56 | RIO_EFB_PAR_EP_FREE_ID, |
57 | RIO_EFB_SER_EP_FREE_ID, | 57 | RIO_EFB_SER_EP_FREE_ID, |
58 | -1, | 58 | -1, |
59 | }; | 59 | }; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * rio_get_device_id - Get the base/extended device id for a device | 62 | * rio_get_device_id - Get the base/extended device id for a device |
63 | * @port: RIO master port | 63 | * @port: RIO master port |
64 | * @destid: Destination ID of device | 64 | * @destid: Destination ID of device |
65 | * @hopcount: Hopcount to device | 65 | * @hopcount: Hopcount to device |
66 | * | 66 | * |
67 | * Reads the base/extended device id from a device. Returns the | 67 | * Reads the base/extended device id from a device. Returns the |
68 | * 8/16-bit device ID. | 68 | * 8/16-bit device ID. |
69 | */ | 69 | */ |
70 | static u16 rio_get_device_id(struct rio_mport *port, u16 destid, u8 hopcount) | 70 | static u16 rio_get_device_id(struct rio_mport *port, u16 destid, u8 hopcount) |
71 | { | 71 | { |
72 | u32 result; | 72 | u32 result; |
73 | 73 | ||
74 | rio_mport_read_config_32(port, destid, hopcount, RIO_DID_CSR, &result); | 74 | rio_mport_read_config_32(port, destid, hopcount, RIO_DID_CSR, &result); |
75 | 75 | ||
76 | return RIO_GET_DID(port->sys_size, result); | 76 | return RIO_GET_DID(port->sys_size, result); |
77 | } | 77 | } |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * rio_set_device_id - Set the base/extended device id for a device | 80 | * rio_set_device_id - Set the base/extended device id for a device |
81 | * @port: RIO master port | 81 | * @port: RIO master port |
82 | * @destid: Destination ID of device | 82 | * @destid: Destination ID of device |
83 | * @hopcount: Hopcount to device | 83 | * @hopcount: Hopcount to device |
84 | * @did: Device ID value to be written | 84 | * @did: Device ID value to be written |
85 | * | 85 | * |
86 | * Writes the base/extended device id from a device. | 86 | * Writes the base/extended device id from a device. |
87 | */ | 87 | */ |
88 | static void rio_set_device_id(struct rio_mport *port, u16 destid, u8 hopcount, u16 did) | 88 | static void rio_set_device_id(struct rio_mport *port, u16 destid, u8 hopcount, u16 did) |
89 | { | 89 | { |
90 | rio_mport_write_config_32(port, destid, hopcount, RIO_DID_CSR, | 90 | rio_mport_write_config_32(port, destid, hopcount, RIO_DID_CSR, |
91 | RIO_SET_DID(port->sys_size, did)); | 91 | RIO_SET_DID(port->sys_size, did)); |
92 | } | 92 | } |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * rio_local_set_device_id - Set the base/extended device id for a port | 95 | * rio_local_set_device_id - Set the base/extended device id for a port |
96 | * @port: RIO master port | 96 | * @port: RIO master port |
97 | * @did: Device ID value to be written | 97 | * @did: Device ID value to be written |
98 | * | 98 | * |
99 | * Writes the base/extended device id from a device. | 99 | * Writes the base/extended device id from a device. |
100 | */ | 100 | */ |
101 | static void rio_local_set_device_id(struct rio_mport *port, u16 did) | 101 | static void rio_local_set_device_id(struct rio_mport *port, u16 did) |
102 | { | 102 | { |
103 | rio_local_write_config_32(port, RIO_DID_CSR, RIO_SET_DID(port->sys_size, | 103 | rio_local_write_config_32(port, RIO_DID_CSR, RIO_SET_DID(port->sys_size, |
104 | did)); | 104 | did)); |
105 | } | 105 | } |
106 | 106 | ||
107 | /** | 107 | /** |
108 | * rio_clear_locks- Release all host locks and signal enumeration complete | 108 | * rio_clear_locks- Release all host locks and signal enumeration complete |
109 | * @port: Master port to issue transaction | 109 | * @port: Master port to issue transaction |
110 | * | 110 | * |
111 | * Marks the component tag CSR on each device with the enumeration | 111 | * Marks the component tag CSR on each device with the enumeration |
112 | * complete flag. When complete, it then release the host locks on | 112 | * complete flag. When complete, it then release the host locks on |
113 | * each device. Returns 0 on success or %-EINVAL on failure. | 113 | * each device. Returns 0 on success or %-EINVAL on failure. |
114 | */ | 114 | */ |
115 | static int rio_clear_locks(struct rio_mport *port) | 115 | static int rio_clear_locks(struct rio_mport *port) |
116 | { | 116 | { |
117 | struct rio_dev *rdev; | 117 | struct rio_dev *rdev; |
118 | u32 result; | 118 | u32 result; |
119 | int ret = 0; | 119 | int ret = 0; |
120 | 120 | ||
121 | /* Write component tag CSR magic complete value */ | 121 | /* Write component tag CSR magic complete value */ |
122 | rio_local_write_config_32(port, RIO_COMPONENT_TAG_CSR, | 122 | rio_local_write_config_32(port, RIO_COMPONENT_TAG_CSR, |
123 | RIO_ENUM_CMPL_MAGIC); | 123 | RIO_ENUM_CMPL_MAGIC); |
124 | list_for_each_entry(rdev, &rio_devices, global_list) | 124 | list_for_each_entry(rdev, &rio_devices, global_list) |
125 | rio_write_config_32(rdev, RIO_COMPONENT_TAG_CSR, | 125 | rio_write_config_32(rdev, RIO_COMPONENT_TAG_CSR, |
126 | RIO_ENUM_CMPL_MAGIC); | 126 | RIO_ENUM_CMPL_MAGIC); |
127 | 127 | ||
128 | /* Release host device id locks */ | 128 | /* Release host device id locks */ |
129 | rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR, | 129 | rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR, |
130 | port->host_deviceid); | 130 | port->host_deviceid); |
131 | rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result); | 131 | rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result); |
132 | if ((result & 0xffff) != 0xffff) { | 132 | if ((result & 0xffff) != 0xffff) { |
133 | printk(KERN_INFO | 133 | printk(KERN_INFO |
134 | "RIO: badness when releasing host lock on master port, result %8.8x\n", | 134 | "RIO: badness when releasing host lock on master port, result %8.8x\n", |
135 | result); | 135 | result); |
136 | ret = -EINVAL; | 136 | ret = -EINVAL; |
137 | } | 137 | } |
138 | list_for_each_entry(rdev, &rio_devices, global_list) { | 138 | list_for_each_entry(rdev, &rio_devices, global_list) { |
139 | rio_write_config_32(rdev, RIO_HOST_DID_LOCK_CSR, | 139 | rio_write_config_32(rdev, RIO_HOST_DID_LOCK_CSR, |
140 | port->host_deviceid); | 140 | port->host_deviceid); |
141 | rio_read_config_32(rdev, RIO_HOST_DID_LOCK_CSR, &result); | 141 | rio_read_config_32(rdev, RIO_HOST_DID_LOCK_CSR, &result); |
142 | if ((result & 0xffff) != 0xffff) { | 142 | if ((result & 0xffff) != 0xffff) { |
143 | printk(KERN_INFO | 143 | printk(KERN_INFO |
144 | "RIO: badness when releasing host lock on vid %4.4x did %4.4x\n", | 144 | "RIO: badness when releasing host lock on vid %4.4x did %4.4x\n", |
145 | rdev->vid, rdev->did); | 145 | rdev->vid, rdev->did); |
146 | ret = -EINVAL; | 146 | ret = -EINVAL; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | return ret; | 150 | return ret; |
151 | } | 151 | } |
152 | 152 | ||
153 | /** | 153 | /** |
154 | * rio_enum_host- Set host lock and initialize host destination ID | 154 | * rio_enum_host- Set host lock and initialize host destination ID |
155 | * @port: Master port to issue transaction | 155 | * @port: Master port to issue transaction |
156 | * | 156 | * |
157 | * Sets the local host master port lock and destination ID register | 157 | * Sets the local host master port lock and destination ID register |
158 | * with the host device ID value. The host device ID value is provided | 158 | * with the host device ID value. The host device ID value is provided |
159 | * by the platform. Returns %0 on success or %-1 on failure. | 159 | * by the platform. Returns %0 on success or %-1 on failure. |
160 | */ | 160 | */ |
161 | static int rio_enum_host(struct rio_mport *port) | 161 | static int rio_enum_host(struct rio_mport *port) |
162 | { | 162 | { |
163 | u32 result; | 163 | u32 result; |
164 | 164 | ||
165 | /* Set master port host device id lock */ | 165 | /* Set master port host device id lock */ |
166 | rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR, | 166 | rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR, |
167 | port->host_deviceid); | 167 | port->host_deviceid); |
168 | 168 | ||
169 | rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result); | 169 | rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result); |
170 | if ((result & 0xffff) != port->host_deviceid) | 170 | if ((result & 0xffff) != port->host_deviceid) |
171 | return -1; | 171 | return -1; |
172 | 172 | ||
173 | /* Set master port destid and init destid ctr */ | 173 | /* Set master port destid and init destid ctr */ |
174 | rio_local_set_device_id(port, port->host_deviceid); | 174 | rio_local_set_device_id(port, port->host_deviceid); |
175 | 175 | ||
176 | if (next_destid == port->host_deviceid) | 176 | if (next_destid == port->host_deviceid) |
177 | next_destid++; | 177 | next_destid++; |
178 | 178 | ||
179 | return 0; | 179 | return 0; |
180 | } | 180 | } |
181 | 181 | ||
182 | /** | 182 | /** |
183 | * rio_device_has_destid- Test if a device contains a destination ID register | 183 | * rio_device_has_destid- Test if a device contains a destination ID register |
184 | * @port: Master port to issue transaction | 184 | * @port: Master port to issue transaction |
185 | * @src_ops: RIO device source operations | 185 | * @src_ops: RIO device source operations |
186 | * @dst_ops: RIO device destination operations | 186 | * @dst_ops: RIO device destination operations |
187 | * | 187 | * |
188 | * Checks the provided @src_ops and @dst_ops for the necessary transaction | 188 | * Checks the provided @src_ops and @dst_ops for the necessary transaction |
189 | * capabilities that indicate whether or not a device will implement a | 189 | * capabilities that indicate whether or not a device will implement a |
190 | * destination ID register. Returns 1 if true or 0 if false. | 190 | * destination ID register. Returns 1 if true or 0 if false. |
191 | */ | 191 | */ |
192 | static int rio_device_has_destid(struct rio_mport *port, int src_ops, | 192 | static int rio_device_has_destid(struct rio_mport *port, int src_ops, |
193 | int dst_ops) | 193 | int dst_ops) |
194 | { | 194 | { |
195 | u32 mask = RIO_OPS_READ | RIO_OPS_WRITE | RIO_OPS_ATOMIC_TST_SWP | RIO_OPS_ATOMIC_INC | RIO_OPS_ATOMIC_DEC | RIO_OPS_ATOMIC_SET | RIO_OPS_ATOMIC_CLR; | 195 | u32 mask = RIO_OPS_READ | RIO_OPS_WRITE | RIO_OPS_ATOMIC_TST_SWP | RIO_OPS_ATOMIC_INC | RIO_OPS_ATOMIC_DEC | RIO_OPS_ATOMIC_SET | RIO_OPS_ATOMIC_CLR; |
196 | 196 | ||
197 | return !!((src_ops | dst_ops) & mask); | 197 | return !!((src_ops | dst_ops) & mask); |
198 | } | 198 | } |
199 | 199 | ||
200 | /** | 200 | /** |
201 | * rio_release_dev- Frees a RIO device struct | 201 | * rio_release_dev- Frees a RIO device struct |
202 | * @dev: LDM device associated with a RIO device struct | 202 | * @dev: LDM device associated with a RIO device struct |
203 | * | 203 | * |
204 | * Gets the RIO device struct associated a RIO device struct. | 204 | * Gets the RIO device struct associated a RIO device struct. |
205 | * The RIO device struct is freed. | 205 | * The RIO device struct is freed. |
206 | */ | 206 | */ |
207 | static void rio_release_dev(struct device *dev) | 207 | static void rio_release_dev(struct device *dev) |
208 | { | 208 | { |
209 | struct rio_dev *rdev; | 209 | struct rio_dev *rdev; |
210 | 210 | ||
211 | rdev = to_rio_dev(dev); | 211 | rdev = to_rio_dev(dev); |
212 | kfree(rdev); | 212 | kfree(rdev); |
213 | } | 213 | } |
214 | 214 | ||
215 | /** | 215 | /** |
216 | * rio_is_switch- Tests if a RIO device has switch capabilities | 216 | * rio_is_switch- Tests if a RIO device has switch capabilities |
217 | * @rdev: RIO device | 217 | * @rdev: RIO device |
218 | * | 218 | * |
219 | * Gets the RIO device Processing Element Features register | 219 | * Gets the RIO device Processing Element Features register |
220 | * contents and tests for switch capabilities. Returns 1 if | 220 | * contents and tests for switch capabilities. Returns 1 if |
221 | * the device is a switch or 0 if it is not a switch. | 221 | * the device is a switch or 0 if it is not a switch. |
222 | * The RIO device struct is freed. | 222 | * The RIO device struct is freed. |
223 | */ | 223 | */ |
224 | static int rio_is_switch(struct rio_dev *rdev) | 224 | static int rio_is_switch(struct rio_dev *rdev) |
225 | { | 225 | { |
226 | if (rdev->pef & RIO_PEF_SWITCH) | 226 | if (rdev->pef & RIO_PEF_SWITCH) |
227 | return 1; | 227 | return 1; |
228 | return 0; | 228 | return 0; |
229 | } | 229 | } |
230 | 230 | ||
231 | /** | 231 | /** |
232 | * rio_route_set_ops- Sets routing operations for a particular vendor switch | 232 | * rio_route_set_ops- Sets routing operations for a particular vendor switch |
233 | * @rdev: RIO device | 233 | * @rdev: RIO device |
234 | * | 234 | * |
235 | * Searches the RIO route ops table for known switch types. If the vid | 235 | * Searches the RIO route ops table for known switch types. If the vid |
236 | * and did match a switch table entry, then set the add_entry() and | 236 | * and did match a switch table entry, then set the add_entry() and |
237 | * get_entry() ops to the table entry values. | 237 | * get_entry() ops to the table entry values. |
238 | */ | 238 | */ |
239 | static void rio_route_set_ops(struct rio_dev *rdev) | 239 | static void rio_route_set_ops(struct rio_dev *rdev) |
240 | { | 240 | { |
241 | struct rio_route_ops *cur = __start_rio_route_ops; | 241 | struct rio_route_ops *cur = __start_rio_route_ops; |
242 | struct rio_route_ops *end = __end_rio_route_ops; | 242 | struct rio_route_ops *end = __end_rio_route_ops; |
243 | 243 | ||
244 | while (cur < end) { | 244 | while (cur < end) { |
245 | if ((cur->vid == rdev->vid) && (cur->did == rdev->did)) { | 245 | if ((cur->vid == rdev->vid) && (cur->did == rdev->did)) { |
246 | pr_debug("RIO: adding routing ops for %s\n", rio_name(rdev)); | 246 | pr_debug("RIO: adding routing ops for %s\n", rio_name(rdev)); |
247 | rdev->rswitch->add_entry = cur->add_hook; | 247 | rdev->rswitch->add_entry = cur->add_hook; |
248 | rdev->rswitch->get_entry = cur->get_hook; | 248 | rdev->rswitch->get_entry = cur->get_hook; |
249 | } | 249 | } |
250 | cur++; | 250 | cur++; |
251 | } | 251 | } |
252 | 252 | ||
253 | if (!rdev->rswitch->add_entry || !rdev->rswitch->get_entry) | 253 | if (!rdev->rswitch->add_entry || !rdev->rswitch->get_entry) |
254 | printk(KERN_ERR "RIO: missing routing ops for %s\n", | 254 | printk(KERN_ERR "RIO: missing routing ops for %s\n", |
255 | rio_name(rdev)); | 255 | rio_name(rdev)); |
256 | } | 256 | } |
257 | 257 | ||
258 | /** | 258 | /** |
259 | * rio_add_device- Adds a RIO device to the device model | 259 | * rio_add_device- Adds a RIO device to the device model |
260 | * @rdev: RIO device | 260 | * @rdev: RIO device |
261 | * | 261 | * |
262 | * Adds the RIO device to the global device list and adds the RIO | 262 | * Adds the RIO device to the global device list and adds the RIO |
263 | * device to the RIO device list. Creates the generic sysfs nodes | 263 | * device to the RIO device list. Creates the generic sysfs nodes |
264 | * for an RIO device. | 264 | * for an RIO device. |
265 | */ | 265 | */ |
266 | static void __devinit rio_add_device(struct rio_dev *rdev) | 266 | static void __devinit rio_add_device(struct rio_dev *rdev) |
267 | { | 267 | { |
268 | device_add(&rdev->dev); | 268 | device_add(&rdev->dev); |
269 | 269 | ||
270 | spin_lock(&rio_global_list_lock); | 270 | spin_lock(&rio_global_list_lock); |
271 | list_add_tail(&rdev->global_list, &rio_devices); | 271 | list_add_tail(&rdev->global_list, &rio_devices); |
272 | spin_unlock(&rio_global_list_lock); | 272 | spin_unlock(&rio_global_list_lock); |
273 | 273 | ||
274 | rio_create_sysfs_dev_files(rdev); | 274 | rio_create_sysfs_dev_files(rdev); |
275 | } | 275 | } |
276 | 276 | ||
277 | /** | 277 | /** |
278 | * rio_setup_device- Allocates and sets up a RIO device | 278 | * rio_setup_device- Allocates and sets up a RIO device |
279 | * @net: RIO network | 279 | * @net: RIO network |
280 | * @port: Master port to send transactions | 280 | * @port: Master port to send transactions |
281 | * @destid: Current destination ID | 281 | * @destid: Current destination ID |
282 | * @hopcount: Current hopcount | 282 | * @hopcount: Current hopcount |
283 | * @do_enum: Enumeration/Discovery mode flag | 283 | * @do_enum: Enumeration/Discovery mode flag |
284 | * | 284 | * |
285 | * Allocates a RIO device and configures fields based on configuration | 285 | * Allocates a RIO device and configures fields based on configuration |
286 | * space contents. If device has a destination ID register, a destination | 286 | * space contents. If device has a destination ID register, a destination |
287 | * ID is either assigned in enumeration mode or read from configuration | 287 | * ID is either assigned in enumeration mode or read from configuration |
288 | * space in discovery mode. If the device has switch capabilities, then | 288 | * space in discovery mode. If the device has switch capabilities, then |
289 | * a switch is allocated and configured appropriately. Returns a pointer | 289 | * a switch is allocated and configured appropriately. Returns a pointer |
290 | * to a RIO device on success or NULL on failure. | 290 | * to a RIO device on success or NULL on failure. |
291 | * | 291 | * |
292 | */ | 292 | */ |
293 | static struct rio_dev *rio_setup_device(struct rio_net *net, | 293 | static struct rio_dev *rio_setup_device(struct rio_net *net, |
294 | struct rio_mport *port, u16 destid, | 294 | struct rio_mport *port, u16 destid, |
295 | u8 hopcount, int do_enum) | 295 | u8 hopcount, int do_enum) |
296 | { | 296 | { |
297 | struct rio_dev *rdev; | 297 | struct rio_dev *rdev; |
298 | struct rio_switch *rswitch; | 298 | struct rio_switch *rswitch; |
299 | int result, rdid; | 299 | int result, rdid; |
300 | 300 | ||
301 | rdev = kzalloc(sizeof(struct rio_dev), GFP_KERNEL); | 301 | rdev = kzalloc(sizeof(struct rio_dev), GFP_KERNEL); |
302 | if (!rdev) | 302 | if (!rdev) |
303 | goto out; | 303 | goto out; |
304 | 304 | ||
305 | rdev->net = net; | 305 | rdev->net = net; |
306 | rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR, | 306 | rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR, |
307 | &result); | 307 | &result); |
308 | rdev->did = result >> 16; | 308 | rdev->did = result >> 16; |
309 | rdev->vid = result & 0xffff; | 309 | rdev->vid = result & 0xffff; |
310 | rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_INFO_CAR, | 310 | rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_INFO_CAR, |
311 | &rdev->device_rev); | 311 | &rdev->device_rev); |
312 | rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_ID_CAR, | 312 | rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_ID_CAR, |
313 | &result); | 313 | &result); |
314 | rdev->asm_did = result >> 16; | 314 | rdev->asm_did = result >> 16; |
315 | rdev->asm_vid = result & 0xffff; | 315 | rdev->asm_vid = result & 0xffff; |
316 | rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR, | 316 | rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR, |
317 | &result); | 317 | &result); |
318 | rdev->asm_rev = result >> 16; | 318 | rdev->asm_rev = result >> 16; |
319 | rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR, | 319 | rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR, |
320 | &rdev->pef); | 320 | &rdev->pef); |
321 | if (rdev->pef & RIO_PEF_EXT_FEATURES) | 321 | if (rdev->pef & RIO_PEF_EXT_FEATURES) |
322 | rdev->efptr = result & 0xffff; | 322 | rdev->efptr = result & 0xffff; |
323 | 323 | ||
324 | rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR, | 324 | rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR, |
325 | &rdev->src_ops); | 325 | &rdev->src_ops); |
326 | rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR, | 326 | rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR, |
327 | &rdev->dst_ops); | 327 | &rdev->dst_ops); |
328 | 328 | ||
329 | if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) { | 329 | if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) { |
330 | if (do_enum) { | 330 | if (do_enum) { |
331 | rio_set_device_id(port, destid, hopcount, next_destid); | 331 | rio_set_device_id(port, destid, hopcount, next_destid); |
332 | rdev->destid = next_destid++; | 332 | rdev->destid = next_destid++; |
333 | if (next_destid == port->host_deviceid) | 333 | if (next_destid == port->host_deviceid) |
334 | next_destid++; | 334 | next_destid++; |
335 | } else | 335 | } else |
336 | rdev->destid = rio_get_device_id(port, destid, hopcount); | 336 | rdev->destid = rio_get_device_id(port, destid, hopcount); |
337 | } else | 337 | } else |
338 | /* Switch device has an associated destID */ | 338 | /* Switch device has an associated destID */ |
339 | rdev->destid = RIO_INVALID_DESTID; | 339 | rdev->destid = RIO_INVALID_DESTID; |
340 | 340 | ||
341 | /* If a PE has both switch and other functions, show it as a switch */ | 341 | /* If a PE has both switch and other functions, show it as a switch */ |
342 | if (rio_is_switch(rdev)) { | 342 | if (rio_is_switch(rdev)) { |
343 | rio_mport_read_config_32(port, destid, hopcount, | 343 | rio_mport_read_config_32(port, destid, hopcount, |
344 | RIO_SWP_INFO_CAR, &rdev->swpinfo); | 344 | RIO_SWP_INFO_CAR, &rdev->swpinfo); |
345 | rswitch = kmalloc(sizeof(struct rio_switch), GFP_KERNEL); | 345 | rswitch = kmalloc(sizeof(struct rio_switch), GFP_KERNEL); |
346 | if (!rswitch) { | 346 | if (!rswitch) { |
347 | kfree(rdev); | 347 | kfree(rdev); |
348 | rdev = NULL; | 348 | rdev = NULL; |
349 | goto out; | 349 | goto out; |
350 | } | 350 | } |
351 | rswitch->switchid = next_switchid; | 351 | rswitch->switchid = next_switchid; |
352 | rswitch->hopcount = hopcount; | 352 | rswitch->hopcount = hopcount; |
353 | rswitch->destid = destid; | 353 | rswitch->destid = destid; |
354 | rswitch->route_table = kzalloc(sizeof(u8)* | 354 | rswitch->route_table = kzalloc(sizeof(u8)* |
355 | RIO_MAX_ROUTE_ENTRIES(port->sys_size), | 355 | RIO_MAX_ROUTE_ENTRIES(port->sys_size), |
356 | GFP_KERNEL); | 356 | GFP_KERNEL); |
357 | if (!rswitch->route_table) { | 357 | if (!rswitch->route_table) { |
358 | kfree(rdev); | 358 | kfree(rdev); |
359 | rdev = NULL; | 359 | rdev = NULL; |
360 | kfree(rswitch); | 360 | kfree(rswitch); |
361 | goto out; | 361 | goto out; |
362 | } | 362 | } |
363 | /* Initialize switch route table */ | 363 | /* Initialize switch route table */ |
364 | for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES(port->sys_size); | 364 | for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES(port->sys_size); |
365 | rdid++) | 365 | rdid++) |
366 | rswitch->route_table[rdid] = RIO_INVALID_ROUTE; | 366 | rswitch->route_table[rdid] = RIO_INVALID_ROUTE; |
367 | rdev->rswitch = rswitch; | 367 | rdev->rswitch = rswitch; |
368 | sprintf(rio_name(rdev), "%02x:s:%04x", rdev->net->id, | 368 | dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id, |
369 | rdev->rswitch->switchid); | 369 | rdev->rswitch->switchid); |
370 | rio_route_set_ops(rdev); | 370 | rio_route_set_ops(rdev); |
371 | 371 | ||
372 | list_add_tail(&rswitch->node, &rio_switches); | 372 | list_add_tail(&rswitch->node, &rio_switches); |
373 | 373 | ||
374 | } else | 374 | } else |
375 | sprintf(rio_name(rdev), "%02x:e:%04x", rdev->net->id, | 375 | dev_set_name(&rdev->dev, "%02x:e:%04x", rdev->net->id, |
376 | rdev->destid); | 376 | rdev->destid); |
377 | 377 | ||
378 | rdev->dev.bus = &rio_bus_type; | 378 | rdev->dev.bus = &rio_bus_type; |
379 | 379 | ||
380 | device_initialize(&rdev->dev); | 380 | device_initialize(&rdev->dev); |
381 | rdev->dev.release = rio_release_dev; | 381 | rdev->dev.release = rio_release_dev; |
382 | rio_dev_get(rdev); | 382 | rio_dev_get(rdev); |
383 | 383 | ||
384 | rdev->dma_mask = DMA_32BIT_MASK; | 384 | rdev->dma_mask = DMA_32BIT_MASK; |
385 | rdev->dev.dma_mask = &rdev->dma_mask; | 385 | rdev->dev.dma_mask = &rdev->dma_mask; |
386 | rdev->dev.coherent_dma_mask = DMA_32BIT_MASK; | 386 | rdev->dev.coherent_dma_mask = DMA_32BIT_MASK; |
387 | 387 | ||
388 | if ((rdev->pef & RIO_PEF_INB_DOORBELL) && | 388 | if ((rdev->pef & RIO_PEF_INB_DOORBELL) && |
389 | (rdev->dst_ops & RIO_DST_OPS_DOORBELL)) | 389 | (rdev->dst_ops & RIO_DST_OPS_DOORBELL)) |
390 | rio_init_dbell_res(&rdev->riores[RIO_DOORBELL_RESOURCE], | 390 | rio_init_dbell_res(&rdev->riores[RIO_DOORBELL_RESOURCE], |
391 | 0, 0xffff); | 391 | 0, 0xffff); |
392 | 392 | ||
393 | rio_add_device(rdev); | 393 | rio_add_device(rdev); |
394 | 394 | ||
395 | out: | 395 | out: |
396 | return rdev; | 396 | return rdev; |
397 | } | 397 | } |
398 | 398 | ||
399 | /** | 399 | /** |
400 | * rio_sport_is_active- Tests if a switch port has an active connection. | 400 | * rio_sport_is_active- Tests if a switch port has an active connection. |
401 | * @port: Master port to send transaction | 401 | * @port: Master port to send transaction |
402 | * @destid: Associated destination ID for switch | 402 | * @destid: Associated destination ID for switch |
403 | * @hopcount: Hopcount to reach switch | 403 | * @hopcount: Hopcount to reach switch |
404 | * @sport: Switch port number | 404 | * @sport: Switch port number |
405 | * | 405 | * |
406 | * Reads the port error status CSR for a particular switch port to | 406 | * Reads the port error status CSR for a particular switch port to |
407 | * determine if the port has an active link. Returns | 407 | * determine if the port has an active link. Returns |
408 | * %PORT_N_ERR_STS_PORT_OK if the port is active or %0 if it is | 408 | * %PORT_N_ERR_STS_PORT_OK if the port is active or %0 if it is |
409 | * inactive. | 409 | * inactive. |
410 | */ | 410 | */ |
411 | static int | 411 | static int |
412 | rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport) | 412 | rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport) |
413 | { | 413 | { |
414 | u32 result; | 414 | u32 result; |
415 | u32 ext_ftr_ptr; | 415 | u32 ext_ftr_ptr; |
416 | 416 | ||
417 | int *entry = rio_sport_phys_table; | 417 | int *entry = rio_sport_phys_table; |
418 | 418 | ||
419 | do { | 419 | do { |
420 | if ((ext_ftr_ptr = | 420 | if ((ext_ftr_ptr = |
421 | rio_mport_get_feature(port, 0, destid, hopcount, *entry))) | 421 | rio_mport_get_feature(port, 0, destid, hopcount, *entry))) |
422 | 422 | ||
423 | break; | 423 | break; |
424 | } while (*++entry >= 0); | 424 | } while (*++entry >= 0); |
425 | 425 | ||
426 | if (ext_ftr_ptr) | 426 | if (ext_ftr_ptr) |
427 | rio_mport_read_config_32(port, destid, hopcount, | 427 | rio_mport_read_config_32(port, destid, hopcount, |
428 | ext_ftr_ptr + | 428 | ext_ftr_ptr + |
429 | RIO_PORT_N_ERR_STS_CSR(sport), | 429 | RIO_PORT_N_ERR_STS_CSR(sport), |
430 | &result); | 430 | &result); |
431 | 431 | ||
432 | return (result & PORT_N_ERR_STS_PORT_OK); | 432 | return (result & PORT_N_ERR_STS_PORT_OK); |
433 | } | 433 | } |
434 | 434 | ||
435 | /** | 435 | /** |
436 | * rio_route_add_entry- Add a route entry to a switch routing table | 436 | * rio_route_add_entry- Add a route entry to a switch routing table |
437 | * @mport: Master port to send transaction | 437 | * @mport: Master port to send transaction |
438 | * @rswitch: Switch device | 438 | * @rswitch: Switch device |
439 | * @table: Routing table ID | 439 | * @table: Routing table ID |
440 | * @route_destid: Destination ID to be routed | 440 | * @route_destid: Destination ID to be routed |
441 | * @route_port: Port number to be routed | 441 | * @route_port: Port number to be routed |
442 | * | 442 | * |
443 | * Calls the switch specific add_entry() method to add a route entry | 443 | * Calls the switch specific add_entry() method to add a route entry |
444 | * on a switch. The route table can be specified using the @table | 444 | * on a switch. The route table can be specified using the @table |
445 | * argument if a switch has per port routing tables or the normal | 445 | * argument if a switch has per port routing tables or the normal |
446 | * use is to specific all tables (or the global table) by passing | 446 | * use is to specific all tables (or the global table) by passing |
447 | * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL | 447 | * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL |
448 | * on failure. | 448 | * on failure. |
449 | */ | 449 | */ |
450 | static int rio_route_add_entry(struct rio_mport *mport, struct rio_switch *rswitch, | 450 | static int rio_route_add_entry(struct rio_mport *mport, struct rio_switch *rswitch, |
451 | u16 table, u16 route_destid, u8 route_port) | 451 | u16 table, u16 route_destid, u8 route_port) |
452 | { | 452 | { |
453 | return rswitch->add_entry(mport, rswitch->destid, | 453 | return rswitch->add_entry(mport, rswitch->destid, |
454 | rswitch->hopcount, table, | 454 | rswitch->hopcount, table, |
455 | route_destid, route_port); | 455 | route_destid, route_port); |
456 | } | 456 | } |
457 | 457 | ||
458 | /** | 458 | /** |
459 | * rio_route_get_entry- Read a route entry in a switch routing table | 459 | * rio_route_get_entry- Read a route entry in a switch routing table |
460 | * @mport: Master port to send transaction | 460 | * @mport: Master port to send transaction |
461 | * @rswitch: Switch device | 461 | * @rswitch: Switch device |
462 | * @table: Routing table ID | 462 | * @table: Routing table ID |
463 | * @route_destid: Destination ID to be routed | 463 | * @route_destid: Destination ID to be routed |
464 | * @route_port: Pointer to read port number into | 464 | * @route_port: Pointer to read port number into |
465 | * | 465 | * |
466 | * Calls the switch specific get_entry() method to read a route entry | 466 | * Calls the switch specific get_entry() method to read a route entry |
467 | * in a switch. The route table can be specified using the @table | 467 | * in a switch. The route table can be specified using the @table |
468 | * argument if a switch has per port routing tables or the normal | 468 | * argument if a switch has per port routing tables or the normal |
469 | * use is to specific all tables (or the global table) by passing | 469 | * use is to specific all tables (or the global table) by passing |
470 | * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL | 470 | * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL |
471 | * on failure. | 471 | * on failure. |
472 | */ | 472 | */ |
473 | static int | 473 | static int |
474 | rio_route_get_entry(struct rio_mport *mport, struct rio_switch *rswitch, u16 table, | 474 | rio_route_get_entry(struct rio_mport *mport, struct rio_switch *rswitch, u16 table, |
475 | u16 route_destid, u8 * route_port) | 475 | u16 route_destid, u8 * route_port) |
476 | { | 476 | { |
477 | return rswitch->get_entry(mport, rswitch->destid, | 477 | return rswitch->get_entry(mport, rswitch->destid, |
478 | rswitch->hopcount, table, | 478 | rswitch->hopcount, table, |
479 | route_destid, route_port); | 479 | route_destid, route_port); |
480 | } | 480 | } |
481 | 481 | ||
482 | /** | 482 | /** |
483 | * rio_get_host_deviceid_lock- Reads the Host Device ID Lock CSR on a device | 483 | * rio_get_host_deviceid_lock- Reads the Host Device ID Lock CSR on a device |
484 | * @port: Master port to send transaction | 484 | * @port: Master port to send transaction |
485 | * @hopcount: Number of hops to the device | 485 | * @hopcount: Number of hops to the device |
486 | * | 486 | * |
487 | * Used during enumeration to read the Host Device ID Lock CSR on a | 487 | * Used during enumeration to read the Host Device ID Lock CSR on a |
488 | * RIO device. Returns the value of the lock register. | 488 | * RIO device. Returns the value of the lock register. |
489 | */ | 489 | */ |
490 | static u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount) | 490 | static u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount) |
491 | { | 491 | { |
492 | u32 result; | 492 | u32 result; |
493 | 493 | ||
494 | rio_mport_read_config_32(port, RIO_ANY_DESTID(port->sys_size), hopcount, | 494 | rio_mport_read_config_32(port, RIO_ANY_DESTID(port->sys_size), hopcount, |
495 | RIO_HOST_DID_LOCK_CSR, &result); | 495 | RIO_HOST_DID_LOCK_CSR, &result); |
496 | 496 | ||
497 | return (u16) (result & 0xffff); | 497 | return (u16) (result & 0xffff); |
498 | } | 498 | } |
499 | 499 | ||
500 | /** | 500 | /** |
501 | * rio_get_swpinfo_inport- Gets the ingress port number | 501 | * rio_get_swpinfo_inport- Gets the ingress port number |
502 | * @mport: Master port to send transaction | 502 | * @mport: Master port to send transaction |
503 | * @destid: Destination ID associated with the switch | 503 | * @destid: Destination ID associated with the switch |
504 | * @hopcount: Number of hops to the device | 504 | * @hopcount: Number of hops to the device |
505 | * | 505 | * |
506 | * Returns port number being used to access the switch device. | 506 | * Returns port number being used to access the switch device. |
507 | */ | 507 | */ |
508 | static u8 | 508 | static u8 |
509 | rio_get_swpinfo_inport(struct rio_mport *mport, u16 destid, u8 hopcount) | 509 | rio_get_swpinfo_inport(struct rio_mport *mport, u16 destid, u8 hopcount) |
510 | { | 510 | { |
511 | u32 result; | 511 | u32 result; |
512 | 512 | ||
513 | rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR, | 513 | rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR, |
514 | &result); | 514 | &result); |
515 | 515 | ||
516 | return (u8) (result & 0xff); | 516 | return (u8) (result & 0xff); |
517 | } | 517 | } |
518 | 518 | ||
519 | /** | 519 | /** |
520 | * rio_get_swpinfo_tports- Gets total number of ports on the switch | 520 | * rio_get_swpinfo_tports- Gets total number of ports on the switch |
521 | * @mport: Master port to send transaction | 521 | * @mport: Master port to send transaction |
522 | * @destid: Destination ID associated with the switch | 522 | * @destid: Destination ID associated with the switch |
523 | * @hopcount: Number of hops to the device | 523 | * @hopcount: Number of hops to the device |
524 | * | 524 | * |
525 | * Returns total numbers of ports implemented by the switch device. | 525 | * Returns total numbers of ports implemented by the switch device. |
526 | */ | 526 | */ |
527 | static u8 rio_get_swpinfo_tports(struct rio_mport *mport, u16 destid, | 527 | static u8 rio_get_swpinfo_tports(struct rio_mport *mport, u16 destid, |
528 | u8 hopcount) | 528 | u8 hopcount) |
529 | { | 529 | { |
530 | u32 result; | 530 | u32 result; |
531 | 531 | ||
532 | rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR, | 532 | rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR, |
533 | &result); | 533 | &result); |
534 | 534 | ||
535 | return RIO_GET_TOTAL_PORTS(result); | 535 | return RIO_GET_TOTAL_PORTS(result); |
536 | } | 536 | } |
537 | 537 | ||
538 | /** | 538 | /** |
539 | * rio_net_add_mport- Add a master port to a RIO network | 539 | * rio_net_add_mport- Add a master port to a RIO network |
540 | * @net: RIO network | 540 | * @net: RIO network |
541 | * @port: Master port to add | 541 | * @port: Master port to add |
542 | * | 542 | * |
543 | * Adds a master port to the network list of associated master | 543 | * Adds a master port to the network list of associated master |
544 | * ports.. | 544 | * ports.. |
545 | */ | 545 | */ |
546 | static void rio_net_add_mport(struct rio_net *net, struct rio_mport *port) | 546 | static void rio_net_add_mport(struct rio_net *net, struct rio_mport *port) |
547 | { | 547 | { |
548 | spin_lock(&rio_global_list_lock); | 548 | spin_lock(&rio_global_list_lock); |
549 | list_add_tail(&port->nnode, &net->mports); | 549 | list_add_tail(&port->nnode, &net->mports); |
550 | spin_unlock(&rio_global_list_lock); | 550 | spin_unlock(&rio_global_list_lock); |
551 | } | 551 | } |
552 | 552 | ||
553 | /** | 553 | /** |
554 | * rio_enum_peer- Recursively enumerate a RIO network through a master port | 554 | * rio_enum_peer- Recursively enumerate a RIO network through a master port |
555 | * @net: RIO network being enumerated | 555 | * @net: RIO network being enumerated |
556 | * @port: Master port to send transactions | 556 | * @port: Master port to send transactions |
557 | * @hopcount: Number of hops into the network | 557 | * @hopcount: Number of hops into the network |
558 | * | 558 | * |
559 | * Recursively enumerates a RIO network. Transactions are sent via the | 559 | * Recursively enumerates a RIO network. Transactions are sent via the |
560 | * master port passed in @port. | 560 | * master port passed in @port. |
561 | */ | 561 | */ |
562 | static int rio_enum_peer(struct rio_net *net, struct rio_mport *port, | 562 | static int rio_enum_peer(struct rio_net *net, struct rio_mport *port, |
563 | u8 hopcount) | 563 | u8 hopcount) |
564 | { | 564 | { |
565 | int port_num; | 565 | int port_num; |
566 | int num_ports; | 566 | int num_ports; |
567 | int cur_destid; | 567 | int cur_destid; |
568 | int sw_destid; | 568 | int sw_destid; |
569 | int sw_inport; | 569 | int sw_inport; |
570 | struct rio_dev *rdev; | 570 | struct rio_dev *rdev; |
571 | u16 destid; | 571 | u16 destid; |
572 | int tmp; | 572 | int tmp; |
573 | 573 | ||
574 | if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) { | 574 | if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) { |
575 | pr_debug("RIO: PE already discovered by this host\n"); | 575 | pr_debug("RIO: PE already discovered by this host\n"); |
576 | /* | 576 | /* |
577 | * Already discovered by this host. Add it as another | 577 | * Already discovered by this host. Add it as another |
578 | * master port for the current network. | 578 | * master port for the current network. |
579 | */ | 579 | */ |
580 | rio_net_add_mport(net, port); | 580 | rio_net_add_mport(net, port); |
581 | return 0; | 581 | return 0; |
582 | } | 582 | } |
583 | 583 | ||
584 | /* Attempt to acquire device lock */ | 584 | /* Attempt to acquire device lock */ |
585 | rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size), | 585 | rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size), |
586 | hopcount, | 586 | hopcount, |
587 | RIO_HOST_DID_LOCK_CSR, port->host_deviceid); | 587 | RIO_HOST_DID_LOCK_CSR, port->host_deviceid); |
588 | while ((tmp = rio_get_host_deviceid_lock(port, hopcount)) | 588 | while ((tmp = rio_get_host_deviceid_lock(port, hopcount)) |
589 | < port->host_deviceid) { | 589 | < port->host_deviceid) { |
590 | /* Delay a bit */ | 590 | /* Delay a bit */ |
591 | mdelay(1); | 591 | mdelay(1); |
592 | /* Attempt to acquire device lock again */ | 592 | /* Attempt to acquire device lock again */ |
593 | rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size), | 593 | rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size), |
594 | hopcount, | 594 | hopcount, |
595 | RIO_HOST_DID_LOCK_CSR, | 595 | RIO_HOST_DID_LOCK_CSR, |
596 | port->host_deviceid); | 596 | port->host_deviceid); |
597 | } | 597 | } |
598 | 598 | ||
599 | if (rio_get_host_deviceid_lock(port, hopcount) > port->host_deviceid) { | 599 | if (rio_get_host_deviceid_lock(port, hopcount) > port->host_deviceid) { |
600 | pr_debug( | 600 | pr_debug( |
601 | "RIO: PE locked by a higher priority host...retreating\n"); | 601 | "RIO: PE locked by a higher priority host...retreating\n"); |
602 | return -1; | 602 | return -1; |
603 | } | 603 | } |
604 | 604 | ||
605 | /* Setup new RIO device */ | 605 | /* Setup new RIO device */ |
606 | rdev = rio_setup_device(net, port, RIO_ANY_DESTID(port->sys_size), | 606 | rdev = rio_setup_device(net, port, RIO_ANY_DESTID(port->sys_size), |
607 | hopcount, 1); | 607 | hopcount, 1); |
608 | if (rdev) { | 608 | if (rdev) { |
609 | /* Add device to the global and bus/net specific list. */ | 609 | /* Add device to the global and bus/net specific list. */ |
610 | list_add_tail(&rdev->net_list, &net->devices); | 610 | list_add_tail(&rdev->net_list, &net->devices); |
611 | } else | 611 | } else |
612 | return -1; | 612 | return -1; |
613 | 613 | ||
614 | if (rio_is_switch(rdev)) { | 614 | if (rio_is_switch(rdev)) { |
615 | next_switchid++; | 615 | next_switchid++; |
616 | sw_inport = rio_get_swpinfo_inport(port, | 616 | sw_inport = rio_get_swpinfo_inport(port, |
617 | RIO_ANY_DESTID(port->sys_size), hopcount); | 617 | RIO_ANY_DESTID(port->sys_size), hopcount); |
618 | rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE, | 618 | rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE, |
619 | port->host_deviceid, sw_inport); | 619 | port->host_deviceid, sw_inport); |
620 | rdev->rswitch->route_table[port->host_deviceid] = sw_inport; | 620 | rdev->rswitch->route_table[port->host_deviceid] = sw_inport; |
621 | 621 | ||
622 | for (destid = 0; destid < next_destid; destid++) { | 622 | for (destid = 0; destid < next_destid; destid++) { |
623 | if (destid == port->host_deviceid) | 623 | if (destid == port->host_deviceid) |
624 | continue; | 624 | continue; |
625 | rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE, | 625 | rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE, |
626 | destid, sw_inport); | 626 | destid, sw_inport); |
627 | rdev->rswitch->route_table[destid] = sw_inport; | 627 | rdev->rswitch->route_table[destid] = sw_inport; |
628 | } | 628 | } |
629 | 629 | ||
630 | num_ports = | 630 | num_ports = |
631 | rio_get_swpinfo_tports(port, RIO_ANY_DESTID(port->sys_size), | 631 | rio_get_swpinfo_tports(port, RIO_ANY_DESTID(port->sys_size), |
632 | hopcount); | 632 | hopcount); |
633 | pr_debug( | 633 | pr_debug( |
634 | "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n", | 634 | "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n", |
635 | rio_name(rdev), rdev->vid, rdev->did, num_ports); | 635 | rio_name(rdev), rdev->vid, rdev->did, num_ports); |
636 | sw_destid = next_destid; | 636 | sw_destid = next_destid; |
637 | for (port_num = 0; port_num < num_ports; port_num++) { | 637 | for (port_num = 0; port_num < num_ports; port_num++) { |
638 | if (sw_inport == port_num) | 638 | if (sw_inport == port_num) |
639 | continue; | 639 | continue; |
640 | 640 | ||
641 | cur_destid = next_destid; | 641 | cur_destid = next_destid; |
642 | 642 | ||
643 | if (rio_sport_is_active | 643 | if (rio_sport_is_active |
644 | (port, RIO_ANY_DESTID(port->sys_size), hopcount, | 644 | (port, RIO_ANY_DESTID(port->sys_size), hopcount, |
645 | port_num)) { | 645 | port_num)) { |
646 | pr_debug( | 646 | pr_debug( |
647 | "RIO: scanning device on port %d\n", | 647 | "RIO: scanning device on port %d\n", |
648 | port_num); | 648 | port_num); |
649 | rio_route_add_entry(port, rdev->rswitch, | 649 | rio_route_add_entry(port, rdev->rswitch, |
650 | RIO_GLOBAL_TABLE, | 650 | RIO_GLOBAL_TABLE, |
651 | RIO_ANY_DESTID(port->sys_size), | 651 | RIO_ANY_DESTID(port->sys_size), |
652 | port_num); | 652 | port_num); |
653 | 653 | ||
654 | if (rio_enum_peer(net, port, hopcount + 1) < 0) | 654 | if (rio_enum_peer(net, port, hopcount + 1) < 0) |
655 | return -1; | 655 | return -1; |
656 | 656 | ||
657 | /* Update routing tables */ | 657 | /* Update routing tables */ |
658 | if (next_destid > cur_destid) { | 658 | if (next_destid > cur_destid) { |
659 | for (destid = cur_destid; | 659 | for (destid = cur_destid; |
660 | destid < next_destid; destid++) { | 660 | destid < next_destid; destid++) { |
661 | if (destid == port->host_deviceid) | 661 | if (destid == port->host_deviceid) |
662 | continue; | 662 | continue; |
663 | rio_route_add_entry(port, rdev->rswitch, | 663 | rio_route_add_entry(port, rdev->rswitch, |
664 | RIO_GLOBAL_TABLE, | 664 | RIO_GLOBAL_TABLE, |
665 | destid, | 665 | destid, |
666 | port_num); | 666 | port_num); |
667 | rdev->rswitch-> | 667 | rdev->rswitch-> |
668 | route_table[destid] = | 668 | route_table[destid] = |
669 | port_num; | 669 | port_num; |
670 | } | 670 | } |
671 | } | 671 | } |
672 | } | 672 | } |
673 | } | 673 | } |
674 | 674 | ||
675 | /* Check for empty switch */ | 675 | /* Check for empty switch */ |
676 | if (next_destid == sw_destid) { | 676 | if (next_destid == sw_destid) { |
677 | next_destid++; | 677 | next_destid++; |
678 | if (next_destid == port->host_deviceid) | 678 | if (next_destid == port->host_deviceid) |
679 | next_destid++; | 679 | next_destid++; |
680 | } | 680 | } |
681 | 681 | ||
682 | rdev->rswitch->destid = sw_destid; | 682 | rdev->rswitch->destid = sw_destid; |
683 | } else | 683 | } else |
684 | pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n", | 684 | pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n", |
685 | rio_name(rdev), rdev->vid, rdev->did); | 685 | rio_name(rdev), rdev->vid, rdev->did); |
686 | 686 | ||
687 | return 0; | 687 | return 0; |
688 | } | 688 | } |
689 | 689 | ||
690 | /** | 690 | /** |
691 | * rio_enum_complete- Tests if enumeration of a network is complete | 691 | * rio_enum_complete- Tests if enumeration of a network is complete |
692 | * @port: Master port to send transaction | 692 | * @port: Master port to send transaction |
693 | * | 693 | * |
694 | * Tests the Component Tag CSR for presence of the magic enumeration | 694 | * Tests the Component Tag CSR for presence of the magic enumeration |
695 | * complete flag. Return %1 if enumeration is complete or %0 if | 695 | * complete flag. Return %1 if enumeration is complete or %0 if |
696 | * enumeration is incomplete. | 696 | * enumeration is incomplete. |
697 | */ | 697 | */ |
698 | static int rio_enum_complete(struct rio_mport *port) | 698 | static int rio_enum_complete(struct rio_mport *port) |
699 | { | 699 | { |
700 | u32 tag_csr; | 700 | u32 tag_csr; |
701 | int ret = 0; | 701 | int ret = 0; |
702 | 702 | ||
703 | rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr); | 703 | rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr); |
704 | 704 | ||
705 | if (tag_csr == RIO_ENUM_CMPL_MAGIC) | 705 | if (tag_csr == RIO_ENUM_CMPL_MAGIC) |
706 | ret = 1; | 706 | ret = 1; |
707 | 707 | ||
708 | return ret; | 708 | return ret; |
709 | } | 709 | } |
710 | 710 | ||
711 | /** | 711 | /** |
712 | * rio_disc_peer- Recursively discovers a RIO network through a master port | 712 | * rio_disc_peer- Recursively discovers a RIO network through a master port |
713 | * @net: RIO network being discovered | 713 | * @net: RIO network being discovered |
714 | * @port: Master port to send transactions | 714 | * @port: Master port to send transactions |
715 | * @destid: Current destination ID in network | 715 | * @destid: Current destination ID in network |
716 | * @hopcount: Number of hops into the network | 716 | * @hopcount: Number of hops into the network |
717 | * | 717 | * |
718 | * Recursively discovers a RIO network. Transactions are sent via the | 718 | * Recursively discovers a RIO network. Transactions are sent via the |
719 | * master port passed in @port. | 719 | * master port passed in @port. |
720 | */ | 720 | */ |
721 | static int | 721 | static int |
722 | rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid, | 722 | rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid, |
723 | u8 hopcount) | 723 | u8 hopcount) |
724 | { | 724 | { |
725 | u8 port_num, route_port; | 725 | u8 port_num, route_port; |
726 | int num_ports; | 726 | int num_ports; |
727 | struct rio_dev *rdev; | 727 | struct rio_dev *rdev; |
728 | u16 ndestid; | 728 | u16 ndestid; |
729 | 729 | ||
730 | /* Setup new RIO device */ | 730 | /* Setup new RIO device */ |
731 | if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) { | 731 | if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) { |
732 | /* Add device to the global and bus/net specific list. */ | 732 | /* Add device to the global and bus/net specific list. */ |
733 | list_add_tail(&rdev->net_list, &net->devices); | 733 | list_add_tail(&rdev->net_list, &net->devices); |
734 | } else | 734 | } else |
735 | return -1; | 735 | return -1; |
736 | 736 | ||
737 | if (rio_is_switch(rdev)) { | 737 | if (rio_is_switch(rdev)) { |
738 | next_switchid++; | 738 | next_switchid++; |
739 | 739 | ||
740 | /* Associated destid is how we accessed this switch */ | 740 | /* Associated destid is how we accessed this switch */ |
741 | rdev->rswitch->destid = destid; | 741 | rdev->rswitch->destid = destid; |
742 | 742 | ||
743 | num_ports = rio_get_swpinfo_tports(port, destid, hopcount); | 743 | num_ports = rio_get_swpinfo_tports(port, destid, hopcount); |
744 | pr_debug( | 744 | pr_debug( |
745 | "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n", | 745 | "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n", |
746 | rio_name(rdev), rdev->vid, rdev->did, num_ports); | 746 | rio_name(rdev), rdev->vid, rdev->did, num_ports); |
747 | for (port_num = 0; port_num < num_ports; port_num++) { | 747 | for (port_num = 0; port_num < num_ports; port_num++) { |
748 | if (rio_get_swpinfo_inport(port, destid, hopcount) == | 748 | if (rio_get_swpinfo_inport(port, destid, hopcount) == |
749 | port_num) | 749 | port_num) |
750 | continue; | 750 | continue; |
751 | 751 | ||
752 | if (rio_sport_is_active | 752 | if (rio_sport_is_active |
753 | (port, destid, hopcount, port_num)) { | 753 | (port, destid, hopcount, port_num)) { |
754 | pr_debug( | 754 | pr_debug( |
755 | "RIO: scanning device on port %d\n", | 755 | "RIO: scanning device on port %d\n", |
756 | port_num); | 756 | port_num); |
757 | for (ndestid = 0; | 757 | for (ndestid = 0; |
758 | ndestid < RIO_ANY_DESTID(port->sys_size); | 758 | ndestid < RIO_ANY_DESTID(port->sys_size); |
759 | ndestid++) { | 759 | ndestid++) { |
760 | rio_route_get_entry(port, rdev->rswitch, | 760 | rio_route_get_entry(port, rdev->rswitch, |
761 | RIO_GLOBAL_TABLE, | 761 | RIO_GLOBAL_TABLE, |
762 | ndestid, | 762 | ndestid, |
763 | &route_port); | 763 | &route_port); |
764 | if (route_port == port_num) | 764 | if (route_port == port_num) |
765 | break; | 765 | break; |
766 | } | 766 | } |
767 | 767 | ||
768 | if (rio_disc_peer | 768 | if (rio_disc_peer |
769 | (net, port, ndestid, hopcount + 1) < 0) | 769 | (net, port, ndestid, hopcount + 1) < 0) |
770 | return -1; | 770 | return -1; |
771 | } | 771 | } |
772 | } | 772 | } |
773 | } else | 773 | } else |
774 | pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n", | 774 | pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n", |
775 | rio_name(rdev), rdev->vid, rdev->did); | 775 | rio_name(rdev), rdev->vid, rdev->did); |
776 | 776 | ||
777 | return 0; | 777 | return 0; |
778 | } | 778 | } |
779 | 779 | ||
780 | /** | 780 | /** |
781 | * rio_mport_is_active- Tests if master port link is active | 781 | * rio_mport_is_active- Tests if master port link is active |
782 | * @port: Master port to test | 782 | * @port: Master port to test |
783 | * | 783 | * |
784 | * Reads the port error status CSR for the master port to | 784 | * Reads the port error status CSR for the master port to |
785 | * determine if the port has an active link. Returns | 785 | * determine if the port has an active link. Returns |
786 | * %PORT_N_ERR_STS_PORT_OK if the master port is active | 786 | * %PORT_N_ERR_STS_PORT_OK if the master port is active |
787 | * or %0 if it is inactive. | 787 | * or %0 if it is inactive. |
788 | */ | 788 | */ |
789 | static int rio_mport_is_active(struct rio_mport *port) | 789 | static int rio_mport_is_active(struct rio_mport *port) |
790 | { | 790 | { |
791 | u32 result = 0; | 791 | u32 result = 0; |
792 | u32 ext_ftr_ptr; | 792 | u32 ext_ftr_ptr; |
793 | int *entry = rio_mport_phys_table; | 793 | int *entry = rio_mport_phys_table; |
794 | 794 | ||
795 | do { | 795 | do { |
796 | if ((ext_ftr_ptr = | 796 | if ((ext_ftr_ptr = |
797 | rio_mport_get_feature(port, 1, 0, 0, *entry))) | 797 | rio_mport_get_feature(port, 1, 0, 0, *entry))) |
798 | break; | 798 | break; |
799 | } while (*++entry >= 0); | 799 | } while (*++entry >= 0); |
800 | 800 | ||
801 | if (ext_ftr_ptr) | 801 | if (ext_ftr_ptr) |
802 | rio_local_read_config_32(port, | 802 | rio_local_read_config_32(port, |
803 | ext_ftr_ptr + | 803 | ext_ftr_ptr + |
804 | RIO_PORT_N_ERR_STS_CSR(port->index), | 804 | RIO_PORT_N_ERR_STS_CSR(port->index), |
805 | &result); | 805 | &result); |
806 | 806 | ||
807 | return (result & PORT_N_ERR_STS_PORT_OK); | 807 | return (result & PORT_N_ERR_STS_PORT_OK); |
808 | } | 808 | } |
809 | 809 | ||
810 | /** | 810 | /** |
811 | * rio_alloc_net- Allocate and configure a new RIO network | 811 | * rio_alloc_net- Allocate and configure a new RIO network |
812 | * @port: Master port associated with the RIO network | 812 | * @port: Master port associated with the RIO network |
813 | * | 813 | * |
814 | * Allocates a RIO network structure, initializes per-network | 814 | * Allocates a RIO network structure, initializes per-network |
815 | * list heads, and adds the associated master port to the | 815 | * list heads, and adds the associated master port to the |
816 | * network list of associated master ports. Returns a | 816 | * network list of associated master ports. Returns a |
817 | * RIO network pointer on success or %NULL on failure. | 817 | * RIO network pointer on success or %NULL on failure. |
818 | */ | 818 | */ |
819 | static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port) | 819 | static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port) |
820 | { | 820 | { |
821 | struct rio_net *net; | 821 | struct rio_net *net; |
822 | 822 | ||
823 | net = kzalloc(sizeof(struct rio_net), GFP_KERNEL); | 823 | net = kzalloc(sizeof(struct rio_net), GFP_KERNEL); |
824 | if (net) { | 824 | if (net) { |
825 | INIT_LIST_HEAD(&net->node); | 825 | INIT_LIST_HEAD(&net->node); |
826 | INIT_LIST_HEAD(&net->devices); | 826 | INIT_LIST_HEAD(&net->devices); |
827 | INIT_LIST_HEAD(&net->mports); | 827 | INIT_LIST_HEAD(&net->mports); |
828 | list_add_tail(&port->nnode, &net->mports); | 828 | list_add_tail(&port->nnode, &net->mports); |
829 | net->hport = port; | 829 | net->hport = port; |
830 | net->id = next_net++; | 830 | net->id = next_net++; |
831 | } | 831 | } |
832 | return net; | 832 | return net; |
833 | } | 833 | } |
834 | 834 | ||
835 | /** | 835 | /** |
836 | * rio_update_route_tables- Updates route tables in switches | 836 | * rio_update_route_tables- Updates route tables in switches |
837 | * @port: Master port associated with the RIO network | 837 | * @port: Master port associated with the RIO network |
838 | * | 838 | * |
839 | * For each enumerated device, ensure that each switch in a system | 839 | * For each enumerated device, ensure that each switch in a system |
840 | * has correct routing entries. Add routes for devices that where | 840 | * has correct routing entries. Add routes for devices that where |
841 | * unknown dirung the first enumeration pass through the switch. | 841 | * unknown dirung the first enumeration pass through the switch. |
842 | */ | 842 | */ |
843 | static void rio_update_route_tables(struct rio_mport *port) | 843 | static void rio_update_route_tables(struct rio_mport *port) |
844 | { | 844 | { |
845 | struct rio_dev *rdev; | 845 | struct rio_dev *rdev; |
846 | struct rio_switch *rswitch; | 846 | struct rio_switch *rswitch; |
847 | u8 sport; | 847 | u8 sport; |
848 | u16 destid; | 848 | u16 destid; |
849 | 849 | ||
850 | list_for_each_entry(rdev, &rio_devices, global_list) { | 850 | list_for_each_entry(rdev, &rio_devices, global_list) { |
851 | 851 | ||
852 | destid = (rio_is_switch(rdev))?rdev->rswitch->destid:rdev->destid; | 852 | destid = (rio_is_switch(rdev))?rdev->rswitch->destid:rdev->destid; |
853 | 853 | ||
854 | list_for_each_entry(rswitch, &rio_switches, node) { | 854 | list_for_each_entry(rswitch, &rio_switches, node) { |
855 | 855 | ||
856 | if (rio_is_switch(rdev) && (rdev->rswitch == rswitch)) | 856 | if (rio_is_switch(rdev) && (rdev->rswitch == rswitch)) |
857 | continue; | 857 | continue; |
858 | 858 | ||
859 | if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) { | 859 | if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) { |
860 | 860 | ||
861 | sport = rio_get_swpinfo_inport(port, | 861 | sport = rio_get_swpinfo_inport(port, |
862 | rswitch->destid, rswitch->hopcount); | 862 | rswitch->destid, rswitch->hopcount); |
863 | 863 | ||
864 | if (rswitch->add_entry) { | 864 | if (rswitch->add_entry) { |
865 | rio_route_add_entry(port, rswitch, RIO_GLOBAL_TABLE, destid, sport); | 865 | rio_route_add_entry(port, rswitch, RIO_GLOBAL_TABLE, destid, sport); |
866 | rswitch->route_table[destid] = sport; | 866 | rswitch->route_table[destid] = sport; |
867 | } | 867 | } |
868 | } | 868 | } |
869 | } | 869 | } |
870 | } | 870 | } |
871 | } | 871 | } |
872 | 872 | ||
873 | /** | 873 | /** |
874 | * rio_enum_mport- Start enumeration through a master port | 874 | * rio_enum_mport- Start enumeration through a master port |
875 | * @mport: Master port to send transactions | 875 | * @mport: Master port to send transactions |
876 | * | 876 | * |
877 | * Starts the enumeration process. If somebody has enumerated our | 877 | * Starts the enumeration process. If somebody has enumerated our |
878 | * master port device, then give up. If not and we have an active | 878 | * master port device, then give up. If not and we have an active |
879 | * link, then start recursive peer enumeration. Returns %0 if | 879 | * link, then start recursive peer enumeration. Returns %0 if |
880 | * enumeration succeeds or %-EBUSY if enumeration fails. | 880 | * enumeration succeeds or %-EBUSY if enumeration fails. |
881 | */ | 881 | */ |
882 | int __devinit rio_enum_mport(struct rio_mport *mport) | 882 | int __devinit rio_enum_mport(struct rio_mport *mport) |
883 | { | 883 | { |
884 | struct rio_net *net = NULL; | 884 | struct rio_net *net = NULL; |
885 | int rc = 0; | 885 | int rc = 0; |
886 | 886 | ||
887 | printk(KERN_INFO "RIO: enumerate master port %d, %s\n", mport->id, | 887 | printk(KERN_INFO "RIO: enumerate master port %d, %s\n", mport->id, |
888 | mport->name); | 888 | mport->name); |
889 | /* If somebody else enumerated our master port device, bail. */ | 889 | /* If somebody else enumerated our master port device, bail. */ |
890 | if (rio_enum_host(mport) < 0) { | 890 | if (rio_enum_host(mport) < 0) { |
891 | printk(KERN_INFO | 891 | printk(KERN_INFO |
892 | "RIO: master port %d device has been enumerated by a remote host\n", | 892 | "RIO: master port %d device has been enumerated by a remote host\n", |
893 | mport->id); | 893 | mport->id); |
894 | rc = -EBUSY; | 894 | rc = -EBUSY; |
895 | goto out; | 895 | goto out; |
896 | } | 896 | } |
897 | 897 | ||
898 | /* If master port has an active link, allocate net and enum peers */ | 898 | /* If master port has an active link, allocate net and enum peers */ |
899 | if (rio_mport_is_active(mport)) { | 899 | if (rio_mport_is_active(mport)) { |
900 | if (!(net = rio_alloc_net(mport))) { | 900 | if (!(net = rio_alloc_net(mport))) { |
901 | printk(KERN_ERR "RIO: failed to allocate new net\n"); | 901 | printk(KERN_ERR "RIO: failed to allocate new net\n"); |
902 | rc = -ENOMEM; | 902 | rc = -ENOMEM; |
903 | goto out; | 903 | goto out; |
904 | } | 904 | } |
905 | if (rio_enum_peer(net, mport, 0) < 0) { | 905 | if (rio_enum_peer(net, mport, 0) < 0) { |
906 | /* A higher priority host won enumeration, bail. */ | 906 | /* A higher priority host won enumeration, bail. */ |
907 | printk(KERN_INFO | 907 | printk(KERN_INFO |
908 | "RIO: master port %d device has lost enumeration to a remote host\n", | 908 | "RIO: master port %d device has lost enumeration to a remote host\n", |
909 | mport->id); | 909 | mport->id); |
910 | rio_clear_locks(mport); | 910 | rio_clear_locks(mport); |
911 | rc = -EBUSY; | 911 | rc = -EBUSY; |
912 | goto out; | 912 | goto out; |
913 | } | 913 | } |
914 | rio_update_route_tables(mport); | 914 | rio_update_route_tables(mport); |
915 | rio_clear_locks(mport); | 915 | rio_clear_locks(mport); |
916 | } else { | 916 | } else { |
917 | printk(KERN_INFO "RIO: master port %d link inactive\n", | 917 | printk(KERN_INFO "RIO: master port %d link inactive\n", |
918 | mport->id); | 918 | mport->id); |
919 | rc = -EINVAL; | 919 | rc = -EINVAL; |
920 | } | 920 | } |
921 | 921 | ||
922 | out: | 922 | out: |
923 | return rc; | 923 | return rc; |
924 | } | 924 | } |
925 | 925 | ||
926 | /** | 926 | /** |
927 | * rio_build_route_tables- Generate route tables from switch route entries | 927 | * rio_build_route_tables- Generate route tables from switch route entries |
928 | * | 928 | * |
929 | * For each switch device, generate a route table by copying existing | 929 | * For each switch device, generate a route table by copying existing |
930 | * route entries from the switch. | 930 | * route entries from the switch. |
931 | */ | 931 | */ |
932 | static void rio_build_route_tables(void) | 932 | static void rio_build_route_tables(void) |
933 | { | 933 | { |
934 | struct rio_dev *rdev; | 934 | struct rio_dev *rdev; |
935 | int i; | 935 | int i; |
936 | u8 sport; | 936 | u8 sport; |
937 | 937 | ||
938 | list_for_each_entry(rdev, &rio_devices, global_list) | 938 | list_for_each_entry(rdev, &rio_devices, global_list) |
939 | if (rio_is_switch(rdev)) | 939 | if (rio_is_switch(rdev)) |
940 | for (i = 0; | 940 | for (i = 0; |
941 | i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size); | 941 | i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size); |
942 | i++) { | 942 | i++) { |
943 | if (rio_route_get_entry | 943 | if (rio_route_get_entry |
944 | (rdev->net->hport, rdev->rswitch, RIO_GLOBAL_TABLE, | 944 | (rdev->net->hport, rdev->rswitch, RIO_GLOBAL_TABLE, |
945 | i, &sport) < 0) | 945 | i, &sport) < 0) |
946 | continue; | 946 | continue; |
947 | rdev->rswitch->route_table[i] = sport; | 947 | rdev->rswitch->route_table[i] = sport; |
948 | } | 948 | } |
949 | } | 949 | } |
950 | 950 | ||
951 | /** | 951 | /** |
952 | * rio_enum_timeout- Signal that enumeration timed out | 952 | * rio_enum_timeout- Signal that enumeration timed out |
953 | * @data: Address of timeout flag. | 953 | * @data: Address of timeout flag. |
954 | * | 954 | * |
955 | * When the enumeration complete timer expires, set a flag that | 955 | * When the enumeration complete timer expires, set a flag that |
956 | * signals to the discovery process that enumeration did not | 956 | * signals to the discovery process that enumeration did not |
957 | * complete in a sane amount of time. | 957 | * complete in a sane amount of time. |
958 | */ | 958 | */ |
959 | static void rio_enum_timeout(unsigned long data) | 959 | static void rio_enum_timeout(unsigned long data) |
960 | { | 960 | { |
961 | /* Enumeration timed out, set flag */ | 961 | /* Enumeration timed out, set flag */ |
962 | *(int *)data = 1; | 962 | *(int *)data = 1; |
963 | } | 963 | } |
964 | 964 | ||
965 | /** | 965 | /** |
966 | * rio_disc_mport- Start discovery through a master port | 966 | * rio_disc_mport- Start discovery through a master port |
967 | * @mport: Master port to send transactions | 967 | * @mport: Master port to send transactions |
968 | * | 968 | * |
969 | * Starts the discovery process. If we have an active link, | 969 | * Starts the discovery process. If we have an active link, |
970 | * then wait for the signal that enumeration is complete. | 970 | * then wait for the signal that enumeration is complete. |
971 | * When enumeration completion is signaled, start recursive | 971 | * When enumeration completion is signaled, start recursive |
972 | * peer discovery. Returns %0 if discovery succeeds or %-EBUSY | 972 | * peer discovery. Returns %0 if discovery succeeds or %-EBUSY |
973 | * on failure. | 973 | * on failure. |
974 | */ | 974 | */ |
975 | int __devinit rio_disc_mport(struct rio_mport *mport) | 975 | int __devinit rio_disc_mport(struct rio_mport *mport) |
976 | { | 976 | { |
977 | struct rio_net *net = NULL; | 977 | struct rio_net *net = NULL; |
978 | int enum_timeout_flag = 0; | 978 | int enum_timeout_flag = 0; |
979 | 979 | ||
980 | printk(KERN_INFO "RIO: discover master port %d, %s\n", mport->id, | 980 | printk(KERN_INFO "RIO: discover master port %d, %s\n", mport->id, |
981 | mport->name); | 981 | mport->name); |
982 | 982 | ||
983 | /* If master port has an active link, allocate net and discover peers */ | 983 | /* If master port has an active link, allocate net and discover peers */ |
984 | if (rio_mport_is_active(mport)) { | 984 | if (rio_mport_is_active(mport)) { |
985 | if (!(net = rio_alloc_net(mport))) { | 985 | if (!(net = rio_alloc_net(mport))) { |
986 | printk(KERN_ERR "RIO: Failed to allocate new net\n"); | 986 | printk(KERN_ERR "RIO: Failed to allocate new net\n"); |
987 | goto bail; | 987 | goto bail; |
988 | } | 988 | } |
989 | 989 | ||
990 | pr_debug("RIO: wait for enumeration complete..."); | 990 | pr_debug("RIO: wait for enumeration complete..."); |
991 | 991 | ||
992 | rio_enum_timer.expires = | 992 | rio_enum_timer.expires = |
993 | jiffies + CONFIG_RAPIDIO_DISC_TIMEOUT * HZ; | 993 | jiffies + CONFIG_RAPIDIO_DISC_TIMEOUT * HZ; |
994 | rio_enum_timer.data = (unsigned long)&enum_timeout_flag; | 994 | rio_enum_timer.data = (unsigned long)&enum_timeout_flag; |
995 | add_timer(&rio_enum_timer); | 995 | add_timer(&rio_enum_timer); |
996 | while (!rio_enum_complete(mport)) { | 996 | while (!rio_enum_complete(mport)) { |
997 | mdelay(1); | 997 | mdelay(1); |
998 | if (enum_timeout_flag) { | 998 | if (enum_timeout_flag) { |
999 | del_timer_sync(&rio_enum_timer); | 999 | del_timer_sync(&rio_enum_timer); |
1000 | goto timeout; | 1000 | goto timeout; |
1001 | } | 1001 | } |
1002 | } | 1002 | } |
1003 | del_timer_sync(&rio_enum_timer); | 1003 | del_timer_sync(&rio_enum_timer); |
1004 | 1004 | ||
1005 | pr_debug("done\n"); | 1005 | pr_debug("done\n"); |
1006 | if (rio_disc_peer(net, mport, RIO_ANY_DESTID(mport->sys_size), | 1006 | if (rio_disc_peer(net, mport, RIO_ANY_DESTID(mport->sys_size), |
1007 | 0) < 0) { | 1007 | 0) < 0) { |
1008 | printk(KERN_INFO | 1008 | printk(KERN_INFO |
1009 | "RIO: master port %d device has failed discovery\n", | 1009 | "RIO: master port %d device has failed discovery\n", |
1010 | mport->id); | 1010 | mport->id); |
1011 | goto bail; | 1011 | goto bail; |
1012 | } | 1012 | } |
1013 | 1013 | ||
1014 | rio_build_route_tables(); | 1014 | rio_build_route_tables(); |
1015 | } | 1015 | } |
1016 | 1016 | ||
1017 | return 0; | 1017 | return 0; |
1018 | 1018 | ||
1019 | timeout: | 1019 | timeout: |
1020 | pr_debug("timeout\n"); | 1020 | pr_debug("timeout\n"); |
1021 | bail: | 1021 | bail: |
1022 | return -EBUSY; | 1022 | return -EBUSY; |
1023 | } | 1023 | } |
1024 | 1024 |
include/linux/rio_drv.h
1 | /* | 1 | /* |
2 | * RapidIO driver services | 2 | * RapidIO driver services |
3 | * | 3 | * |
4 | * Copyright 2005 MontaVista Software, Inc. | 4 | * Copyright 2005 MontaVista Software, Inc. |
5 | * Matt Porter <mporter@kernel.crashing.org> | 5 | * Matt Porter <mporter@kernel.crashing.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify it | 7 | * This program is free software; you can redistribute it and/or modify it |
8 | * under the terms of the GNU General Public License as published by the | 8 | * under the terms of the GNU General Public License as published by the |
9 | * Free Software Foundation; either version 2 of the License, or (at your | 9 | * Free Software Foundation; either version 2 of the License, or (at your |
10 | * option) any later version. | 10 | * option) any later version. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #ifndef LINUX_RIO_DRV_H | 13 | #ifndef LINUX_RIO_DRV_H |
14 | #define LINUX_RIO_DRV_H | 14 | #define LINUX_RIO_DRV_H |
15 | 15 | ||
16 | #include <linux/types.h> | 16 | #include <linux/types.h> |
17 | #include <linux/ioport.h> | 17 | #include <linux/ioport.h> |
18 | #include <linux/list.h> | 18 | #include <linux/list.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/device.h> | 20 | #include <linux/device.h> |
21 | #include <linux/string.h> | 21 | #include <linux/string.h> |
22 | #include <linux/rio.h> | 22 | #include <linux/rio.h> |
23 | 23 | ||
24 | extern int __rio_local_read_config_32(struct rio_mport *port, u32 offset, | 24 | extern int __rio_local_read_config_32(struct rio_mport *port, u32 offset, |
25 | u32 * data); | 25 | u32 * data); |
26 | extern int __rio_local_write_config_32(struct rio_mport *port, u32 offset, | 26 | extern int __rio_local_write_config_32(struct rio_mport *port, u32 offset, |
27 | u32 data); | 27 | u32 data); |
28 | extern int __rio_local_read_config_16(struct rio_mport *port, u32 offset, | 28 | extern int __rio_local_read_config_16(struct rio_mport *port, u32 offset, |
29 | u16 * data); | 29 | u16 * data); |
30 | extern int __rio_local_write_config_16(struct rio_mport *port, u32 offset, | 30 | extern int __rio_local_write_config_16(struct rio_mport *port, u32 offset, |
31 | u16 data); | 31 | u16 data); |
32 | extern int __rio_local_read_config_8(struct rio_mport *port, u32 offset, | 32 | extern int __rio_local_read_config_8(struct rio_mport *port, u32 offset, |
33 | u8 * data); | 33 | u8 * data); |
34 | extern int __rio_local_write_config_8(struct rio_mport *port, u32 offset, | 34 | extern int __rio_local_write_config_8(struct rio_mport *port, u32 offset, |
35 | u8 data); | 35 | u8 data); |
36 | 36 | ||
37 | extern int rio_mport_read_config_32(struct rio_mport *port, u16 destid, | 37 | extern int rio_mport_read_config_32(struct rio_mport *port, u16 destid, |
38 | u8 hopcount, u32 offset, u32 * data); | 38 | u8 hopcount, u32 offset, u32 * data); |
39 | extern int rio_mport_write_config_32(struct rio_mport *port, u16 destid, | 39 | extern int rio_mport_write_config_32(struct rio_mport *port, u16 destid, |
40 | u8 hopcount, u32 offset, u32 data); | 40 | u8 hopcount, u32 offset, u32 data); |
41 | extern int rio_mport_read_config_16(struct rio_mport *port, u16 destid, | 41 | extern int rio_mport_read_config_16(struct rio_mport *port, u16 destid, |
42 | u8 hopcount, u32 offset, u16 * data); | 42 | u8 hopcount, u32 offset, u16 * data); |
43 | extern int rio_mport_write_config_16(struct rio_mport *port, u16 destid, | 43 | extern int rio_mport_write_config_16(struct rio_mport *port, u16 destid, |
44 | u8 hopcount, u32 offset, u16 data); | 44 | u8 hopcount, u32 offset, u16 data); |
45 | extern int rio_mport_read_config_8(struct rio_mport *port, u16 destid, | 45 | extern int rio_mport_read_config_8(struct rio_mport *port, u16 destid, |
46 | u8 hopcount, u32 offset, u8 * data); | 46 | u8 hopcount, u32 offset, u8 * data); |
47 | extern int rio_mport_write_config_8(struct rio_mport *port, u16 destid, | 47 | extern int rio_mport_write_config_8(struct rio_mport *port, u16 destid, |
48 | u8 hopcount, u32 offset, u8 data); | 48 | u8 hopcount, u32 offset, u8 data); |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * rio_local_read_config_32 - Read 32 bits from local configuration space | 51 | * rio_local_read_config_32 - Read 32 bits from local configuration space |
52 | * @port: Master port | 52 | * @port: Master port |
53 | * @offset: Offset into local configuration space | 53 | * @offset: Offset into local configuration space |
54 | * @data: Pointer to read data into | 54 | * @data: Pointer to read data into |
55 | * | 55 | * |
56 | * Reads 32 bits of data from the specified offset within the local | 56 | * Reads 32 bits of data from the specified offset within the local |
57 | * device's configuration space. | 57 | * device's configuration space. |
58 | */ | 58 | */ |
59 | static inline int rio_local_read_config_32(struct rio_mport *port, u32 offset, | 59 | static inline int rio_local_read_config_32(struct rio_mport *port, u32 offset, |
60 | u32 * data) | 60 | u32 * data) |
61 | { | 61 | { |
62 | return __rio_local_read_config_32(port, offset, data); | 62 | return __rio_local_read_config_32(port, offset, data); |
63 | } | 63 | } |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * rio_local_write_config_32 - Write 32 bits to local configuration space | 66 | * rio_local_write_config_32 - Write 32 bits to local configuration space |
67 | * @port: Master port | 67 | * @port: Master port |
68 | * @offset: Offset into local configuration space | 68 | * @offset: Offset into local configuration space |
69 | * @data: Data to be written | 69 | * @data: Data to be written |
70 | * | 70 | * |
71 | * Writes 32 bits of data to the specified offset within the local | 71 | * Writes 32 bits of data to the specified offset within the local |
72 | * device's configuration space. | 72 | * device's configuration space. |
73 | */ | 73 | */ |
74 | static inline int rio_local_write_config_32(struct rio_mport *port, u32 offset, | 74 | static inline int rio_local_write_config_32(struct rio_mport *port, u32 offset, |
75 | u32 data) | 75 | u32 data) |
76 | { | 76 | { |
77 | return __rio_local_write_config_32(port, offset, data); | 77 | return __rio_local_write_config_32(port, offset, data); |
78 | } | 78 | } |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * rio_local_read_config_16 - Read 16 bits from local configuration space | 81 | * rio_local_read_config_16 - Read 16 bits from local configuration space |
82 | * @port: Master port | 82 | * @port: Master port |
83 | * @offset: Offset into local configuration space | 83 | * @offset: Offset into local configuration space |
84 | * @data: Pointer to read data into | 84 | * @data: Pointer to read data into |
85 | * | 85 | * |
86 | * Reads 16 bits of data from the specified offset within the local | 86 | * Reads 16 bits of data from the specified offset within the local |
87 | * device's configuration space. | 87 | * device's configuration space. |
88 | */ | 88 | */ |
89 | static inline int rio_local_read_config_16(struct rio_mport *port, u32 offset, | 89 | static inline int rio_local_read_config_16(struct rio_mport *port, u32 offset, |
90 | u16 * data) | 90 | u16 * data) |
91 | { | 91 | { |
92 | return __rio_local_read_config_16(port, offset, data); | 92 | return __rio_local_read_config_16(port, offset, data); |
93 | } | 93 | } |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * rio_local_write_config_16 - Write 16 bits to local configuration space | 96 | * rio_local_write_config_16 - Write 16 bits to local configuration space |
97 | * @port: Master port | 97 | * @port: Master port |
98 | * @offset: Offset into local configuration space | 98 | * @offset: Offset into local configuration space |
99 | * @data: Data to be written | 99 | * @data: Data to be written |
100 | * | 100 | * |
101 | * Writes 16 bits of data to the specified offset within the local | 101 | * Writes 16 bits of data to the specified offset within the local |
102 | * device's configuration space. | 102 | * device's configuration space. |
103 | */ | 103 | */ |
104 | 104 | ||
105 | static inline int rio_local_write_config_16(struct rio_mport *port, u32 offset, | 105 | static inline int rio_local_write_config_16(struct rio_mport *port, u32 offset, |
106 | u16 data) | 106 | u16 data) |
107 | { | 107 | { |
108 | return __rio_local_write_config_16(port, offset, data); | 108 | return __rio_local_write_config_16(port, offset, data); |
109 | } | 109 | } |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * rio_local_read_config_8 - Read 8 bits from local configuration space | 112 | * rio_local_read_config_8 - Read 8 bits from local configuration space |
113 | * @port: Master port | 113 | * @port: Master port |
114 | * @offset: Offset into local configuration space | 114 | * @offset: Offset into local configuration space |
115 | * @data: Pointer to read data into | 115 | * @data: Pointer to read data into |
116 | * | 116 | * |
117 | * Reads 8 bits of data from the specified offset within the local | 117 | * Reads 8 bits of data from the specified offset within the local |
118 | * device's configuration space. | 118 | * device's configuration space. |
119 | */ | 119 | */ |
120 | static inline int rio_local_read_config_8(struct rio_mport *port, u32 offset, | 120 | static inline int rio_local_read_config_8(struct rio_mport *port, u32 offset, |
121 | u8 * data) | 121 | u8 * data) |
122 | { | 122 | { |
123 | return __rio_local_read_config_8(port, offset, data); | 123 | return __rio_local_read_config_8(port, offset, data); |
124 | } | 124 | } |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * rio_local_write_config_8 - Write 8 bits to local configuration space | 127 | * rio_local_write_config_8 - Write 8 bits to local configuration space |
128 | * @port: Master port | 128 | * @port: Master port |
129 | * @offset: Offset into local configuration space | 129 | * @offset: Offset into local configuration space |
130 | * @data: Data to be written | 130 | * @data: Data to be written |
131 | * | 131 | * |
132 | * Writes 8 bits of data to the specified offset within the local | 132 | * Writes 8 bits of data to the specified offset within the local |
133 | * device's configuration space. | 133 | * device's configuration space. |
134 | */ | 134 | */ |
135 | static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset, | 135 | static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset, |
136 | u8 data) | 136 | u8 data) |
137 | { | 137 | { |
138 | return __rio_local_write_config_8(port, offset, data); | 138 | return __rio_local_write_config_8(port, offset, data); |
139 | } | 139 | } |
140 | 140 | ||
141 | /** | 141 | /** |
142 | * rio_read_config_32 - Read 32 bits from configuration space | 142 | * rio_read_config_32 - Read 32 bits from configuration space |
143 | * @rdev: RIO device | 143 | * @rdev: RIO device |
144 | * @offset: Offset into device configuration space | 144 | * @offset: Offset into device configuration space |
145 | * @data: Pointer to read data into | 145 | * @data: Pointer to read data into |
146 | * | 146 | * |
147 | * Reads 32 bits of data from the specified offset within the | 147 | * Reads 32 bits of data from the specified offset within the |
148 | * RIO device's configuration space. | 148 | * RIO device's configuration space. |
149 | */ | 149 | */ |
150 | static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset, | 150 | static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset, |
151 | u32 * data) | 151 | u32 * data) |
152 | { | 152 | { |
153 | u8 hopcount = 0xff; | 153 | u8 hopcount = 0xff; |
154 | u16 destid = rdev->destid; | 154 | u16 destid = rdev->destid; |
155 | 155 | ||
156 | if (rdev->rswitch) { | 156 | if (rdev->rswitch) { |
157 | destid = rdev->rswitch->destid; | 157 | destid = rdev->rswitch->destid; |
158 | hopcount = rdev->rswitch->hopcount; | 158 | hopcount = rdev->rswitch->hopcount; |
159 | } | 159 | } |
160 | 160 | ||
161 | return rio_mport_read_config_32(rdev->net->hport, destid, hopcount, | 161 | return rio_mport_read_config_32(rdev->net->hport, destid, hopcount, |
162 | offset, data); | 162 | offset, data); |
163 | }; | 163 | }; |
164 | 164 | ||
165 | /** | 165 | /** |
166 | * rio_write_config_32 - Write 32 bits to configuration space | 166 | * rio_write_config_32 - Write 32 bits to configuration space |
167 | * @rdev: RIO device | 167 | * @rdev: RIO device |
168 | * @offset: Offset into device configuration space | 168 | * @offset: Offset into device configuration space |
169 | * @data: Data to be written | 169 | * @data: Data to be written |
170 | * | 170 | * |
171 | * Writes 32 bits of data to the specified offset within the | 171 | * Writes 32 bits of data to the specified offset within the |
172 | * RIO device's configuration space. | 172 | * RIO device's configuration space. |
173 | */ | 173 | */ |
174 | static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset, | 174 | static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset, |
175 | u32 data) | 175 | u32 data) |
176 | { | 176 | { |
177 | u8 hopcount = 0xff; | 177 | u8 hopcount = 0xff; |
178 | u16 destid = rdev->destid; | 178 | u16 destid = rdev->destid; |
179 | 179 | ||
180 | if (rdev->rswitch) { | 180 | if (rdev->rswitch) { |
181 | destid = rdev->rswitch->destid; | 181 | destid = rdev->rswitch->destid; |
182 | hopcount = rdev->rswitch->hopcount; | 182 | hopcount = rdev->rswitch->hopcount; |
183 | } | 183 | } |
184 | 184 | ||
185 | return rio_mport_write_config_32(rdev->net->hport, destid, hopcount, | 185 | return rio_mport_write_config_32(rdev->net->hport, destid, hopcount, |
186 | offset, data); | 186 | offset, data); |
187 | }; | 187 | }; |
188 | 188 | ||
189 | /** | 189 | /** |
190 | * rio_read_config_16 - Read 16 bits from configuration space | 190 | * rio_read_config_16 - Read 16 bits from configuration space |
191 | * @rdev: RIO device | 191 | * @rdev: RIO device |
192 | * @offset: Offset into device configuration space | 192 | * @offset: Offset into device configuration space |
193 | * @data: Pointer to read data into | 193 | * @data: Pointer to read data into |
194 | * | 194 | * |
195 | * Reads 16 bits of data from the specified offset within the | 195 | * Reads 16 bits of data from the specified offset within the |
196 | * RIO device's configuration space. | 196 | * RIO device's configuration space. |
197 | */ | 197 | */ |
198 | static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset, | 198 | static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset, |
199 | u16 * data) | 199 | u16 * data) |
200 | { | 200 | { |
201 | u8 hopcount = 0xff; | 201 | u8 hopcount = 0xff; |
202 | u16 destid = rdev->destid; | 202 | u16 destid = rdev->destid; |
203 | 203 | ||
204 | if (rdev->rswitch) { | 204 | if (rdev->rswitch) { |
205 | destid = rdev->rswitch->destid; | 205 | destid = rdev->rswitch->destid; |
206 | hopcount = rdev->rswitch->hopcount; | 206 | hopcount = rdev->rswitch->hopcount; |
207 | } | 207 | } |
208 | 208 | ||
209 | return rio_mport_read_config_16(rdev->net->hport, destid, hopcount, | 209 | return rio_mport_read_config_16(rdev->net->hport, destid, hopcount, |
210 | offset, data); | 210 | offset, data); |
211 | }; | 211 | }; |
212 | 212 | ||
213 | /** | 213 | /** |
214 | * rio_write_config_16 - Write 16 bits to configuration space | 214 | * rio_write_config_16 - Write 16 bits to configuration space |
215 | * @rdev: RIO device | 215 | * @rdev: RIO device |
216 | * @offset: Offset into device configuration space | 216 | * @offset: Offset into device configuration space |
217 | * @data: Data to be written | 217 | * @data: Data to be written |
218 | * | 218 | * |
219 | * Writes 16 bits of data to the specified offset within the | 219 | * Writes 16 bits of data to the specified offset within the |
220 | * RIO device's configuration space. | 220 | * RIO device's configuration space. |
221 | */ | 221 | */ |
222 | static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset, | 222 | static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset, |
223 | u16 data) | 223 | u16 data) |
224 | { | 224 | { |
225 | u8 hopcount = 0xff; | 225 | u8 hopcount = 0xff; |
226 | u16 destid = rdev->destid; | 226 | u16 destid = rdev->destid; |
227 | 227 | ||
228 | if (rdev->rswitch) { | 228 | if (rdev->rswitch) { |
229 | destid = rdev->rswitch->destid; | 229 | destid = rdev->rswitch->destid; |
230 | hopcount = rdev->rswitch->hopcount; | 230 | hopcount = rdev->rswitch->hopcount; |
231 | } | 231 | } |
232 | 232 | ||
233 | return rio_mport_write_config_16(rdev->net->hport, destid, hopcount, | 233 | return rio_mport_write_config_16(rdev->net->hport, destid, hopcount, |
234 | offset, data); | 234 | offset, data); |
235 | }; | 235 | }; |
236 | 236 | ||
237 | /** | 237 | /** |
238 | * rio_read_config_8 - Read 8 bits from configuration space | 238 | * rio_read_config_8 - Read 8 bits from configuration space |
239 | * @rdev: RIO device | 239 | * @rdev: RIO device |
240 | * @offset: Offset into device configuration space | 240 | * @offset: Offset into device configuration space |
241 | * @data: Pointer to read data into | 241 | * @data: Pointer to read data into |
242 | * | 242 | * |
243 | * Reads 8 bits of data from the specified offset within the | 243 | * Reads 8 bits of data from the specified offset within the |
244 | * RIO device's configuration space. | 244 | * RIO device's configuration space. |
245 | */ | 245 | */ |
246 | static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data) | 246 | static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data) |
247 | { | 247 | { |
248 | u8 hopcount = 0xff; | 248 | u8 hopcount = 0xff; |
249 | u16 destid = rdev->destid; | 249 | u16 destid = rdev->destid; |
250 | 250 | ||
251 | if (rdev->rswitch) { | 251 | if (rdev->rswitch) { |
252 | destid = rdev->rswitch->destid; | 252 | destid = rdev->rswitch->destid; |
253 | hopcount = rdev->rswitch->hopcount; | 253 | hopcount = rdev->rswitch->hopcount; |
254 | } | 254 | } |
255 | 255 | ||
256 | return rio_mport_read_config_8(rdev->net->hport, destid, hopcount, | 256 | return rio_mport_read_config_8(rdev->net->hport, destid, hopcount, |
257 | offset, data); | 257 | offset, data); |
258 | }; | 258 | }; |
259 | 259 | ||
260 | /** | 260 | /** |
261 | * rio_write_config_8 - Write 8 bits to configuration space | 261 | * rio_write_config_8 - Write 8 bits to configuration space |
262 | * @rdev: RIO device | 262 | * @rdev: RIO device |
263 | * @offset: Offset into device configuration space | 263 | * @offset: Offset into device configuration space |
264 | * @data: Data to be written | 264 | * @data: Data to be written |
265 | * | 265 | * |
266 | * Writes 8 bits of data to the specified offset within the | 266 | * Writes 8 bits of data to the specified offset within the |
267 | * RIO device's configuration space. | 267 | * RIO device's configuration space. |
268 | */ | 268 | */ |
269 | static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data) | 269 | static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data) |
270 | { | 270 | { |
271 | u8 hopcount = 0xff; | 271 | u8 hopcount = 0xff; |
272 | u16 destid = rdev->destid; | 272 | u16 destid = rdev->destid; |
273 | 273 | ||
274 | if (rdev->rswitch) { | 274 | if (rdev->rswitch) { |
275 | destid = rdev->rswitch->destid; | 275 | destid = rdev->rswitch->destid; |
276 | hopcount = rdev->rswitch->hopcount; | 276 | hopcount = rdev->rswitch->hopcount; |
277 | } | 277 | } |
278 | 278 | ||
279 | return rio_mport_write_config_8(rdev->net->hport, destid, hopcount, | 279 | return rio_mport_write_config_8(rdev->net->hport, destid, hopcount, |
280 | offset, data); | 280 | offset, data); |
281 | }; | 281 | }; |
282 | 282 | ||
283 | extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid, | 283 | extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid, |
284 | u16 data); | 284 | u16 data); |
285 | 285 | ||
286 | /** | 286 | /** |
287 | * rio_send_doorbell - Send a doorbell message to a device | 287 | * rio_send_doorbell - Send a doorbell message to a device |
288 | * @rdev: RIO device | 288 | * @rdev: RIO device |
289 | * @data: Doorbell message data | 289 | * @data: Doorbell message data |
290 | * | 290 | * |
291 | * Send a doorbell message to a RIO device. The doorbell message | 291 | * Send a doorbell message to a RIO device. The doorbell message |
292 | * has a 16-bit info field provided by the @data argument. | 292 | * has a 16-bit info field provided by the @data argument. |
293 | */ | 293 | */ |
294 | static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data) | 294 | static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data) |
295 | { | 295 | { |
296 | return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data); | 296 | return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data); |
297 | }; | 297 | }; |
298 | 298 | ||
299 | /** | 299 | /** |
300 | * rio_init_mbox_res - Initialize a RIO mailbox resource | 300 | * rio_init_mbox_res - Initialize a RIO mailbox resource |
301 | * @res: resource struct | 301 | * @res: resource struct |
302 | * @start: start of mailbox range | 302 | * @start: start of mailbox range |
303 | * @end: end of mailbox range | 303 | * @end: end of mailbox range |
304 | * | 304 | * |
305 | * This function is used to initialize the fields of a resource | 305 | * This function is used to initialize the fields of a resource |
306 | * for use as a mailbox resource. It initializes a range of | 306 | * for use as a mailbox resource. It initializes a range of |
307 | * mailboxes using the start and end arguments. | 307 | * mailboxes using the start and end arguments. |
308 | */ | 308 | */ |
309 | static inline void rio_init_mbox_res(struct resource *res, int start, int end) | 309 | static inline void rio_init_mbox_res(struct resource *res, int start, int end) |
310 | { | 310 | { |
311 | memset(res, 0, sizeof(struct resource)); | 311 | memset(res, 0, sizeof(struct resource)); |
312 | res->start = start; | 312 | res->start = start; |
313 | res->end = end; | 313 | res->end = end; |
314 | res->flags = RIO_RESOURCE_MAILBOX; | 314 | res->flags = RIO_RESOURCE_MAILBOX; |
315 | } | 315 | } |
316 | 316 | ||
317 | /** | 317 | /** |
318 | * rio_init_dbell_res - Initialize a RIO doorbell resource | 318 | * rio_init_dbell_res - Initialize a RIO doorbell resource |
319 | * @res: resource struct | 319 | * @res: resource struct |
320 | * @start: start of doorbell range | 320 | * @start: start of doorbell range |
321 | * @end: end of doorbell range | 321 | * @end: end of doorbell range |
322 | * | 322 | * |
323 | * This function is used to initialize the fields of a resource | 323 | * This function is used to initialize the fields of a resource |
324 | * for use as a doorbell resource. It initializes a range of | 324 | * for use as a doorbell resource. It initializes a range of |
325 | * doorbell messages using the start and end arguments. | 325 | * doorbell messages using the start and end arguments. |
326 | */ | 326 | */ |
327 | static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end) | 327 | static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end) |
328 | { | 328 | { |
329 | memset(res, 0, sizeof(struct resource)); | 329 | memset(res, 0, sizeof(struct resource)); |
330 | res->start = start; | 330 | res->start = start; |
331 | res->end = end; | 331 | res->end = end; |
332 | res->flags = RIO_RESOURCE_DOORBELL; | 332 | res->flags = RIO_RESOURCE_DOORBELL; |
333 | } | 333 | } |
334 | 334 | ||
335 | /** | 335 | /** |
336 | * RIO_DEVICE - macro used to describe a specific RIO device | 336 | * RIO_DEVICE - macro used to describe a specific RIO device |
337 | * @dev: the 16 bit RIO device ID | 337 | * @dev: the 16 bit RIO device ID |
338 | * @ven: the 16 bit RIO vendor ID | 338 | * @ven: the 16 bit RIO vendor ID |
339 | * | 339 | * |
340 | * This macro is used to create a struct rio_device_id that matches a | 340 | * This macro is used to create a struct rio_device_id that matches a |
341 | * specific device. The assembly vendor and assembly device fields | 341 | * specific device. The assembly vendor and assembly device fields |
342 | * will be set to %RIO_ANY_ID. | 342 | * will be set to %RIO_ANY_ID. |
343 | */ | 343 | */ |
344 | #define RIO_DEVICE(dev,ven) \ | 344 | #define RIO_DEVICE(dev,ven) \ |
345 | .did = (dev), .vid = (ven), \ | 345 | .did = (dev), .vid = (ven), \ |
346 | .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID | 346 | .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID |
347 | 347 | ||
348 | /* Mailbox management */ | 348 | /* Mailbox management */ |
349 | extern int rio_request_outb_mbox(struct rio_mport *, void *, int, int, | 349 | extern int rio_request_outb_mbox(struct rio_mport *, void *, int, int, |
350 | void (*)(struct rio_mport *, void *,int, int)); | 350 | void (*)(struct rio_mport *, void *,int, int)); |
351 | extern int rio_release_outb_mbox(struct rio_mport *, int); | 351 | extern int rio_release_outb_mbox(struct rio_mport *, int); |
352 | 352 | ||
353 | /** | 353 | /** |
354 | * rio_add_outb_message - Add RIO message to an outbound mailbox queue | 354 | * rio_add_outb_message - Add RIO message to an outbound mailbox queue |
355 | * @mport: RIO master port containing the outbound queue | 355 | * @mport: RIO master port containing the outbound queue |
356 | * @rdev: RIO device the message is be sent to | 356 | * @rdev: RIO device the message is be sent to |
357 | * @mbox: The outbound mailbox queue | 357 | * @mbox: The outbound mailbox queue |
358 | * @buffer: Pointer to the message buffer | 358 | * @buffer: Pointer to the message buffer |
359 | * @len: Length of the message buffer | 359 | * @len: Length of the message buffer |
360 | * | 360 | * |
361 | * Adds a RIO message buffer to an outbound mailbox queue for | 361 | * Adds a RIO message buffer to an outbound mailbox queue for |
362 | * transmission. Returns 0 on success. | 362 | * transmission. Returns 0 on success. |
363 | */ | 363 | */ |
364 | static inline int rio_add_outb_message(struct rio_mport *mport, | 364 | static inline int rio_add_outb_message(struct rio_mport *mport, |
365 | struct rio_dev *rdev, int mbox, | 365 | struct rio_dev *rdev, int mbox, |
366 | void *buffer, size_t len) | 366 | void *buffer, size_t len) |
367 | { | 367 | { |
368 | return rio_hw_add_outb_message(mport, rdev, mbox, buffer, len); | 368 | return rio_hw_add_outb_message(mport, rdev, mbox, buffer, len); |
369 | } | 369 | } |
370 | 370 | ||
371 | extern int rio_request_inb_mbox(struct rio_mport *, void *, int, int, | 371 | extern int rio_request_inb_mbox(struct rio_mport *, void *, int, int, |
372 | void (*)(struct rio_mport *, void *, int, int)); | 372 | void (*)(struct rio_mport *, void *, int, int)); |
373 | extern int rio_release_inb_mbox(struct rio_mport *, int); | 373 | extern int rio_release_inb_mbox(struct rio_mport *, int); |
374 | 374 | ||
375 | /** | 375 | /** |
376 | * rio_add_inb_buffer - Add buffer to an inbound mailbox queue | 376 | * rio_add_inb_buffer - Add buffer to an inbound mailbox queue |
377 | * @mport: Master port containing the inbound mailbox | 377 | * @mport: Master port containing the inbound mailbox |
378 | * @mbox: The inbound mailbox number | 378 | * @mbox: The inbound mailbox number |
379 | * @buffer: Pointer to the message buffer | 379 | * @buffer: Pointer to the message buffer |
380 | * | 380 | * |
381 | * Adds a buffer to an inbound mailbox queue for reception. Returns | 381 | * Adds a buffer to an inbound mailbox queue for reception. Returns |
382 | * 0 on success. | 382 | * 0 on success. |
383 | */ | 383 | */ |
384 | static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox, | 384 | static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox, |
385 | void *buffer) | 385 | void *buffer) |
386 | { | 386 | { |
387 | return rio_hw_add_inb_buffer(mport, mbox, buffer); | 387 | return rio_hw_add_inb_buffer(mport, mbox, buffer); |
388 | } | 388 | } |
389 | 389 | ||
390 | /** | 390 | /** |
391 | * rio_get_inb_message - Get A RIO message from an inbound mailbox queue | 391 | * rio_get_inb_message - Get A RIO message from an inbound mailbox queue |
392 | * @mport: Master port containing the inbound mailbox | 392 | * @mport: Master port containing the inbound mailbox |
393 | * @mbox: The inbound mailbox number | 393 | * @mbox: The inbound mailbox number |
394 | * @buffer: Pointer to the message buffer | 394 | * @buffer: Pointer to the message buffer |
395 | * | 395 | * |
396 | * Get a RIO message from an inbound mailbox queue. Returns 0 on success. | 396 | * Get a RIO message from an inbound mailbox queue. Returns 0 on success. |
397 | */ | 397 | */ |
398 | static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox) | 398 | static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox) |
399 | { | 399 | { |
400 | return rio_hw_get_inb_message(mport, mbox); | 400 | return rio_hw_get_inb_message(mport, mbox); |
401 | } | 401 | } |
402 | 402 | ||
403 | /* Doorbell management */ | 403 | /* Doorbell management */ |
404 | extern int rio_request_inb_dbell(struct rio_mport *, void *, u16, u16, | 404 | extern int rio_request_inb_dbell(struct rio_mport *, void *, u16, u16, |
405 | void (*)(struct rio_mport *, void *, u16, u16, u16)); | 405 | void (*)(struct rio_mport *, void *, u16, u16, u16)); |
406 | extern int rio_release_inb_dbell(struct rio_mport *, u16, u16); | 406 | extern int rio_release_inb_dbell(struct rio_mport *, u16, u16); |
407 | extern struct resource *rio_request_outb_dbell(struct rio_dev *, u16, u16); | 407 | extern struct resource *rio_request_outb_dbell(struct rio_dev *, u16, u16); |
408 | extern int rio_release_outb_dbell(struct rio_dev *, struct resource *); | 408 | extern int rio_release_outb_dbell(struct rio_dev *, struct resource *); |
409 | 409 | ||
410 | /* Memory region management */ | 410 | /* Memory region management */ |
411 | int rio_claim_resource(struct rio_dev *, int); | 411 | int rio_claim_resource(struct rio_dev *, int); |
412 | int rio_request_regions(struct rio_dev *, char *); | 412 | int rio_request_regions(struct rio_dev *, char *); |
413 | void rio_release_regions(struct rio_dev *); | 413 | void rio_release_regions(struct rio_dev *); |
414 | int rio_request_region(struct rio_dev *, int, char *); | 414 | int rio_request_region(struct rio_dev *, int, char *); |
415 | void rio_release_region(struct rio_dev *, int); | 415 | void rio_release_region(struct rio_dev *, int); |
416 | 416 | ||
417 | /* LDM support */ | 417 | /* LDM support */ |
418 | int rio_register_driver(struct rio_driver *); | 418 | int rio_register_driver(struct rio_driver *); |
419 | void rio_unregister_driver(struct rio_driver *); | 419 | void rio_unregister_driver(struct rio_driver *); |
420 | struct rio_dev *rio_dev_get(struct rio_dev *); | 420 | struct rio_dev *rio_dev_get(struct rio_dev *); |
421 | void rio_dev_put(struct rio_dev *); | 421 | void rio_dev_put(struct rio_dev *); |
422 | 422 | ||
423 | /** | 423 | /** |
424 | * rio_name - Get the unique RIO device identifier | 424 | * rio_name - Get the unique RIO device identifier |
425 | * @rdev: RIO device | 425 | * @rdev: RIO device |
426 | * | 426 | * |
427 | * Get the unique RIO device identifier. Returns the device | 427 | * Get the unique RIO device identifier. Returns the device |
428 | * identifier string. | 428 | * identifier string. |
429 | */ | 429 | */ |
430 | static inline char *rio_name(struct rio_dev *rdev) | 430 | static inline const char *rio_name(struct rio_dev *rdev) |
431 | { | 431 | { |
432 | return rdev->dev.bus_id; | 432 | return dev_name(&rdev->dev); |
433 | } | 433 | } |
434 | 434 | ||
435 | /** | 435 | /** |
436 | * rio_get_drvdata - Get RIO driver specific data | 436 | * rio_get_drvdata - Get RIO driver specific data |
437 | * @rdev: RIO device | 437 | * @rdev: RIO device |
438 | * | 438 | * |
439 | * Get RIO driver specific data. Returns a pointer to the | 439 | * Get RIO driver specific data. Returns a pointer to the |
440 | * driver specific data. | 440 | * driver specific data. |
441 | */ | 441 | */ |
442 | static inline void *rio_get_drvdata(struct rio_dev *rdev) | 442 | static inline void *rio_get_drvdata(struct rio_dev *rdev) |
443 | { | 443 | { |
444 | return dev_get_drvdata(&rdev->dev); | 444 | return dev_get_drvdata(&rdev->dev); |
445 | } | 445 | } |
446 | 446 | ||
447 | /** | 447 | /** |
448 | * rio_set_drvdata - Set RIO driver specific data | 448 | * rio_set_drvdata - Set RIO driver specific data |
449 | * @rdev: RIO device | 449 | * @rdev: RIO device |
450 | * @data: Pointer to driver specific data | 450 | * @data: Pointer to driver specific data |
451 | * | 451 | * |
452 | * Set RIO driver specific data. device struct driver data pointer | 452 | * Set RIO driver specific data. device struct driver data pointer |
453 | * is set to the @data argument. | 453 | * is set to the @data argument. |
454 | */ | 454 | */ |
455 | static inline void rio_set_drvdata(struct rio_dev *rdev, void *data) | 455 | static inline void rio_set_drvdata(struct rio_dev *rdev, void *data) |
456 | { | 456 | { |
457 | dev_set_drvdata(&rdev->dev, data); | 457 | dev_set_drvdata(&rdev->dev, data); |
458 | } | 458 | } |
459 | 459 | ||
460 | /* Misc driver helpers */ | 460 | /* Misc driver helpers */ |
461 | extern u16 rio_local_get_device_id(struct rio_mport *port); | 461 | extern u16 rio_local_get_device_id(struct rio_mport *port); |
462 | extern struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from); | 462 | extern struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from); |
463 | extern struct rio_dev *rio_get_asm(u16 vid, u16 did, u16 asm_vid, u16 asm_did, | 463 | extern struct rio_dev *rio_get_asm(u16 vid, u16 did, u16 asm_vid, u16 asm_did, |
464 | struct rio_dev *from); | 464 | struct rio_dev *from); |
465 | 465 | ||
466 | #endif /* LINUX_RIO_DRV_H */ | 466 | #endif /* LINUX_RIO_DRV_H */ |
467 | 467 |