Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IEEE 1394 for Linux |
| 3 | * |
| 4 | * Copyright (C) 1999 Andreas E. Bombe |
| 5 | * |
| 6 | * This code is licensed under the GPL. See the file COPYING in the root |
| 7 | * directory of the kernel sources for details. |
| 8 | * |
| 9 | * |
| 10 | * Contributions: |
| 11 | * |
| 12 | * Christian Toegel <christian.toegel@gmx.at> |
| 13 | * unregister address space |
| 14 | * |
| 15 | * Manfred Weihs <weihs@ict.tuwien.ac.at> |
| 16 | * unregister address space |
| 17 | * |
| 18 | */ |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/slab.h> |
| 21 | #include <linux/list.h> |
| 22 | #include <linux/bitops.h> |
| 23 | |
| 24 | #include "ieee1394.h" |
| 25 | #include "ieee1394_types.h" |
| 26 | #include "hosts.h" |
| 27 | #include "ieee1394_core.h" |
| 28 | #include "highlevel.h" |
| 29 | #include "nodemgr.h" |
| 30 | |
| 31 | |
| 32 | struct hl_host_info { |
| 33 | struct list_head list; |
| 34 | struct hpsb_host *host; |
| 35 | size_t size; |
| 36 | unsigned long key; |
| 37 | void *data; |
| 38 | }; |
| 39 | |
| 40 | |
| 41 | static LIST_HEAD(hl_drivers); |
| 42 | static DECLARE_RWSEM(hl_drivers_sem); |
| 43 | |
| 44 | static LIST_HEAD(hl_irqs); |
| 45 | static DEFINE_RWLOCK(hl_irqs_lock); |
| 46 | |
| 47 | static DEFINE_RWLOCK(addr_space_lock); |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | static struct hl_host_info *hl_get_hostinfo(struct hpsb_highlevel *hl, |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 51 | struct hpsb_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
| 53 | struct hl_host_info *hi = NULL; |
| 54 | |
| 55 | if (!hl || !host) |
| 56 | return NULL; |
| 57 | |
| 58 | read_lock(&hl->host_info_lock); |
| 59 | list_for_each_entry(hi, &hl->host_info_list, list) { |
| 60 | if (hi->host == host) { |
| 61 | read_unlock(&hl->host_info_lock); |
| 62 | return hi; |
| 63 | } |
| 64 | } |
| 65 | read_unlock(&hl->host_info_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return NULL; |
| 67 | } |
| 68 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 69 | /** |
| 70 | * hpsb_get_hostinfo - retrieve a hostinfo pointer bound to this driver/host |
| 71 | * |
| 72 | * Returns a per @host and @hl driver data structure that was previously stored |
| 73 | * by hpsb_create_hostinfo. |
| 74 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host) |
| 76 | { |
| 77 | struct hl_host_info *hi = hl_get_hostinfo(hl, host); |
| 78 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 79 | return hi ? hi->data : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 82 | /** |
| 83 | * hpsb_create_hostinfo - allocate a hostinfo pointer bound to this driver/host |
| 84 | * |
| 85 | * Allocate a hostinfo pointer backed by memory with @data_size and bind it to |
| 86 | * to this @hl driver and @host. If @data_size is zero, then the return here is |
| 87 | * only valid for error checking. |
| 88 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, |
| 90 | size_t data_size) |
| 91 | { |
| 92 | struct hl_host_info *hi; |
| 93 | void *data; |
| 94 | unsigned long flags; |
| 95 | |
| 96 | hi = hl_get_hostinfo(hl, host); |
| 97 | if (hi) { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 98 | HPSB_ERR("%s called hpsb_create_hostinfo when hostinfo already" |
| 99 | " exists", hl->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | return NULL; |
| 101 | } |
| 102 | |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 103 | hi = kzalloc(sizeof(*hi) + data_size, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | if (!hi) |
| 105 | return NULL; |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | if (data_size) { |
| 108 | data = hi->data = hi + 1; |
| 109 | hi->size = data_size; |
| 110 | } else |
| 111 | data = hi; |
| 112 | |
| 113 | hi->host = host; |
| 114 | |
| 115 | write_lock_irqsave(&hl->host_info_lock, flags); |
| 116 | list_add_tail(&hi->list, &hl->host_info_list); |
| 117 | write_unlock_irqrestore(&hl->host_info_lock, flags); |
| 118 | |
| 119 | return data; |
| 120 | } |
| 121 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 122 | /** |
| 123 | * hpsb_set_hostinfo - set the hostinfo pointer to something useful |
| 124 | * |
| 125 | * Usually follows a call to hpsb_create_hostinfo, where the size is 0. |
| 126 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, |
| 128 | void *data) |
| 129 | { |
| 130 | struct hl_host_info *hi; |
| 131 | |
| 132 | hi = hl_get_hostinfo(hl, host); |
| 133 | if (hi) { |
| 134 | if (!hi->size && !hi->data) { |
| 135 | hi->data = data; |
| 136 | return 0; |
| 137 | } else |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 138 | HPSB_ERR("%s called hpsb_set_hostinfo when hostinfo " |
| 139 | "already has data", hl->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } else |
| 141 | HPSB_ERR("%s called hpsb_set_hostinfo when no hostinfo exists", |
| 142 | hl->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return -EINVAL; |
| 144 | } |
| 145 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 146 | /** |
| 147 | * hpsb_destroy_hostinfo - free and remove a hostinfo pointer |
| 148 | * |
| 149 | * Free and remove the hostinfo pointer bound to this @hl driver and @host. |
| 150 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host) |
| 152 | { |
| 153 | struct hl_host_info *hi; |
| 154 | |
| 155 | hi = hl_get_hostinfo(hl, host); |
| 156 | if (hi) { |
| 157 | unsigned long flags; |
| 158 | write_lock_irqsave(&hl->host_info_lock, flags); |
| 159 | list_del(&hi->list); |
| 160 | write_unlock_irqrestore(&hl->host_info_lock, flags); |
| 161 | kfree(hi); |
| 162 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | return; |
| 164 | } |
| 165 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 166 | /** |
| 167 | * hpsb_set_hostinfo_key - set an alternate lookup key for an hostinfo |
| 168 | * |
| 169 | * Sets an alternate lookup key for the hostinfo bound to this @hl driver and |
| 170 | * @host. |
| 171 | */ |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 172 | void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host, |
| 173 | unsigned long key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
| 175 | struct hl_host_info *hi; |
| 176 | |
| 177 | hi = hl_get_hostinfo(hl, host); |
| 178 | if (hi) |
| 179 | hi->key = key; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return; |
| 181 | } |
| 182 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 183 | /** |
| 184 | * hpsb_get_hostinfo_bykey - retrieve a hostinfo pointer by its alternate key |
| 185 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key) |
| 187 | { |
| 188 | struct hl_host_info *hi; |
| 189 | void *data = NULL; |
| 190 | |
| 191 | if (!hl) |
| 192 | return NULL; |
| 193 | |
| 194 | read_lock(&hl->host_info_lock); |
| 195 | list_for_each_entry(hi, &hl->host_info_list, list) { |
| 196 | if (hi->key == key) { |
| 197 | data = hi->data; |
| 198 | break; |
| 199 | } |
| 200 | } |
| 201 | read_unlock(&hl->host_info_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | return data; |
| 203 | } |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | static int highlevel_for_each_host_reg(struct hpsb_host *host, void *__data) |
| 206 | { |
| 207 | struct hpsb_highlevel *hl = __data; |
| 208 | |
| 209 | hl->add_host(host); |
| 210 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 211 | if (host->update_config_rom && hpsb_update_config_rom_image(host) < 0) |
| 212 | HPSB_ERR("Failed to generate Configuration ROM image for host " |
| 213 | "%s-%d", hl->name, host->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | return 0; |
| 215 | } |
| 216 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 217 | /** |
| 218 | * hpsb_register_highlevel - register highlevel driver |
| 219 | * |
| 220 | * The name pointer in @hl has to stay valid at all times because the string is |
| 221 | * not copied. |
| 222 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | void hpsb_register_highlevel(struct hpsb_highlevel *hl) |
| 224 | { |
Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 225 | unsigned long flags; |
| 226 | |
Stefan Richter | 055a7da | 2008-05-19 22:07:28 +0200 | [diff] [blame] | 227 | hpsb_init_highlevel(hl); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 228 | INIT_LIST_HEAD(&hl->addr_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | down_write(&hl_drivers_sem); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 231 | list_add_tail(&hl->hl_list, &hl_drivers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | up_write(&hl_drivers_sem); |
| 233 | |
Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 234 | write_lock_irqsave(&hl_irqs_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | list_add_tail(&hl->irq_list, &hl_irqs); |
Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 236 | write_unlock_irqrestore(&hl_irqs_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | if (hl->add_host) |
| 239 | nodemgr_for_each_host(hl, highlevel_for_each_host_reg); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 240 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | static void __delete_addr(struct hpsb_address_serve *as) |
| 244 | { |
| 245 | list_del(&as->host_list); |
| 246 | list_del(&as->hl_list); |
| 247 | kfree(as); |
| 248 | } |
| 249 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 250 | static void __unregister_host(struct hpsb_highlevel *hl, struct hpsb_host *host, |
| 251 | int update_cr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
| 253 | unsigned long flags; |
| 254 | struct list_head *lh, *next; |
| 255 | struct hpsb_address_serve *as; |
| 256 | |
| 257 | /* First, let the highlevel driver unreg */ |
| 258 | if (hl->remove_host) |
| 259 | hl->remove_host(host); |
| 260 | |
| 261 | /* Remove any addresses that are matched for this highlevel driver |
| 262 | * and this particular host. */ |
| 263 | write_lock_irqsave(&addr_space_lock, flags); |
| 264 | list_for_each_safe (lh, next, &hl->addr_list) { |
| 265 | as = list_entry(lh, struct hpsb_address_serve, hl_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | if (as->host == host) |
| 267 | __delete_addr(as); |
| 268 | } |
| 269 | write_unlock_irqrestore(&addr_space_lock, flags); |
| 270 | |
| 271 | /* Now update the config-rom to reflect anything removed by the |
| 272 | * highlevel driver. */ |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 273 | if (update_cr && host->update_config_rom && |
| 274 | hpsb_update_config_rom_image(host) < 0) |
| 275 | HPSB_ERR("Failed to generate Configuration ROM image for host " |
| 276 | "%s-%d", hl->name, host->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 278 | /* Finally remove all the host info associated between these two. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | hpsb_destroy_hostinfo(hl, host); |
| 280 | } |
| 281 | |
| 282 | static int highlevel_for_each_host_unreg(struct hpsb_host *host, void *__data) |
| 283 | { |
| 284 | struct hpsb_highlevel *hl = __data; |
| 285 | |
| 286 | __unregister_host(hl, host, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 290 | /** |
| 291 | * hpsb_unregister_highlevel - unregister highlevel driver |
| 292 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | void hpsb_unregister_highlevel(struct hpsb_highlevel *hl) |
| 294 | { |
Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 295 | unsigned long flags; |
| 296 | |
| 297 | write_lock_irqsave(&hl_irqs_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | list_del(&hl->irq_list); |
Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 299 | write_unlock_irqrestore(&hl_irqs_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | down_write(&hl_drivers_sem); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 302 | list_del(&hl->hl_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | up_write(&hl_drivers_sem); |
| 304 | |
| 305 | nodemgr_for_each_host(hl, highlevel_for_each_host_unreg); |
| 306 | } |
| 307 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 308 | /** |
| 309 | * hpsb_allocate_and_register_addrspace - alloc' and reg' a host address space |
| 310 | * |
| 311 | * @start and @end are 48 bit pointers and have to be quadlet aligned. |
| 312 | * @end points to the first address behind the handled addresses. This |
| 313 | * function can be called multiple times for a single hpsb_highlevel @hl to |
| 314 | * implement sparse register sets. The requested region must not overlap any |
| 315 | * previously allocated region, otherwise registering will fail. |
| 316 | * |
| 317 | * It returns true for successful allocation. Address spaces can be |
| 318 | * unregistered with hpsb_unregister_addrspace. All remaining address spaces |
| 319 | * are automatically deallocated together with the hpsb_highlevel @hl. |
| 320 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl, |
| 322 | struct hpsb_host *host, |
| 323 | struct hpsb_address_ops *ops, |
| 324 | u64 size, u64 alignment, |
| 325 | u64 start, u64 end) |
| 326 | { |
| 327 | struct hpsb_address_serve *as, *a1, *a2; |
| 328 | struct list_head *entry; |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 329 | u64 retval = CSR1212_INVALID_ADDR_SPACE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | unsigned long flags; |
| 331 | u64 align_mask = ~(alignment - 1); |
| 332 | |
| 333 | if ((alignment & 3) || (alignment > 0x800000000000ULL) || |
Akinobu Mita | 37d5411 | 2006-03-26 01:39:56 -0800 | [diff] [blame] | 334 | (hweight64(alignment) != 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | HPSB_ERR("%s called with invalid alignment: 0x%048llx", |
Harvey Harrison | b1ce1fd | 2008-03-05 18:24:54 -0800 | [diff] [blame] | 336 | __func__, (unsigned long long)alignment); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | return retval; |
| 338 | } |
| 339 | |
Ben Collins | 8aef63f | 2006-06-12 18:13:21 -0400 | [diff] [blame] | 340 | /* default range, |
| 341 | * avoids controller's posted write area (see OHCI 1.1 clause 1.5) */ |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 342 | if (start == CSR1212_INVALID_ADDR_SPACE && |
| 343 | end == CSR1212_INVALID_ADDR_SPACE) { |
Ben Collins | 8aef63f | 2006-06-12 18:13:21 -0400 | [diff] [blame] | 344 | start = host->middle_addr_space; |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 345 | end = CSR1212_ALL_SPACE_END; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 348 | if (((start|end) & ~align_mask) || (start >= end) || |
| 349 | (end > CSR1212_ALL_SPACE_END)) { |
| 350 | HPSB_ERR("%s called with invalid addresses " |
Harvey Harrison | b1ce1fd | 2008-03-05 18:24:54 -0800 | [diff] [blame] | 351 | "(start = %012Lx end = %012Lx)", __func__, |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 352 | (unsigned long long)start,(unsigned long long)end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return retval; |
| 354 | } |
| 355 | |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 356 | as = kmalloc(sizeof(*as), GFP_KERNEL); |
| 357 | if (!as) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | INIT_LIST_HEAD(&as->host_list); |
| 361 | INIT_LIST_HEAD(&as->hl_list); |
| 362 | as->op = ops; |
| 363 | as->host = host; |
| 364 | |
| 365 | write_lock_irqsave(&addr_space_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | list_for_each(entry, &host->addr_space) { |
| 367 | u64 a1sa, a1ea; |
| 368 | u64 a2sa, a2ea; |
| 369 | |
| 370 | a1 = list_entry(entry, struct hpsb_address_serve, host_list); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 371 | a2 = list_entry(entry->next, struct hpsb_address_serve, |
| 372 | host_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | a1sa = a1->start & align_mask; |
| 375 | a1ea = (a1->end + alignment -1) & align_mask; |
| 376 | a2sa = a2->start & align_mask; |
| 377 | a2ea = (a2->end + alignment -1) & align_mask; |
| 378 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 379 | if ((a2sa - a1ea >= size) && (a2sa - start >= size) && |
| 380 | (a2sa > start)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | as->start = max(start, a1ea); |
| 382 | as->end = as->start + size; |
| 383 | list_add(&as->host_list, entry); |
| 384 | list_add_tail(&as->hl_list, &hl->addr_list); |
| 385 | retval = as->start; |
| 386 | break; |
| 387 | } |
| 388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | write_unlock_irqrestore(&addr_space_lock, flags); |
| 390 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 391 | if (retval == CSR1212_INVALID_ADDR_SPACE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | kfree(as); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | return retval; |
| 394 | } |
| 395 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 396 | /** |
| 397 | * hpsb_register_addrspace - register a host address space |
| 398 | * |
| 399 | * @start and @end are 48 bit pointers and have to be quadlet aligned. |
| 400 | * @end points to the first address behind the handled addresses. This |
| 401 | * function can be called multiple times for a single hpsb_highlevel @hl to |
| 402 | * implement sparse register sets. The requested region must not overlap any |
| 403 | * previously allocated region, otherwise registering will fail. |
| 404 | * |
| 405 | * It returns true for successful allocation. Address spaces can be |
| 406 | * unregistered with hpsb_unregister_addrspace. All remaining address spaces |
| 407 | * are automatically deallocated together with the hpsb_highlevel @hl. |
| 408 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 410 | struct hpsb_address_ops *ops, u64 start, u64 end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 412 | struct hpsb_address_serve *as; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | struct list_head *lh; |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 414 | int retval = 0; |
| 415 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 417 | if (((start|end) & 3) || (start >= end) || |
| 418 | (end > CSR1212_ALL_SPACE_END)) { |
Harvey Harrison | b1ce1fd | 2008-03-05 18:24:54 -0800 | [diff] [blame] | 419 | HPSB_ERR("%s called with invalid addresses", __func__); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 420 | return 0; |
| 421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 423 | as = kmalloc(sizeof(*as), GFP_ATOMIC); |
| 424 | if (!as) |
| 425 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 427 | INIT_LIST_HEAD(&as->host_list); |
| 428 | INIT_LIST_HEAD(&as->hl_list); |
| 429 | as->op = ops; |
| 430 | as->start = start; |
| 431 | as->end = end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | as->host = host; |
| 433 | |
| 434 | write_lock_irqsave(&addr_space_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | list_for_each(lh, &host->addr_space) { |
| 436 | struct hpsb_address_serve *as_this = |
| 437 | list_entry(lh, struct hpsb_address_serve, host_list); |
| 438 | struct hpsb_address_serve *as_next = |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 439 | list_entry(lh->next, struct hpsb_address_serve, |
| 440 | host_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | if (as_this->end > as->start) |
| 443 | break; |
| 444 | |
| 445 | if (as_next->start >= as->end) { |
| 446 | list_add(&as->host_list, lh); |
| 447 | list_add_tail(&as->hl_list, &hl->addr_list); |
| 448 | retval = 1; |
| 449 | break; |
| 450 | } |
| 451 | } |
| 452 | write_unlock_irqrestore(&addr_space_lock, flags); |
| 453 | |
| 454 | if (retval == 0) |
| 455 | kfree(as); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 456 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 460 | u64 start) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 462 | int retval = 0; |
| 463 | struct hpsb_address_serve *as; |
| 464 | struct list_head *lh, *next; |
| 465 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 467 | write_lock_irqsave(&addr_space_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | list_for_each_safe (lh, next, &hl->addr_list) { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 469 | as = list_entry(lh, struct hpsb_address_serve, hl_list); |
| 470 | if (as->start == start && as->host == host) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | __delete_addr(as); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 472 | retval = 1; |
| 473 | break; |
| 474 | } |
| 475 | } |
| 476 | write_unlock_irqrestore(&addr_space_lock, flags); |
| 477 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Stefan Richter | e47c1fe | 2008-11-26 01:34:25 +0100 | [diff] [blame] | 480 | static struct hpsb_address_ops dummy_ops; |
| 481 | |
| 482 | /* dummy address spaces as lower and upper bounds of the host's a.s. list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | static void init_hpsb_highlevel(struct hpsb_host *host) |
| 484 | { |
Stefan Richter | e47c1fe | 2008-11-26 01:34:25 +0100 | [diff] [blame] | 485 | INIT_LIST_HEAD(&host->dummy_zero_addr.host_list); |
| 486 | INIT_LIST_HEAD(&host->dummy_zero_addr.hl_list); |
| 487 | INIT_LIST_HEAD(&host->dummy_max_addr.host_list); |
| 488 | INIT_LIST_HEAD(&host->dummy_max_addr.hl_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Stefan Richter | e47c1fe | 2008-11-26 01:34:25 +0100 | [diff] [blame] | 490 | host->dummy_zero_addr.op = host->dummy_max_addr.op = &dummy_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Stefan Richter | e47c1fe | 2008-11-26 01:34:25 +0100 | [diff] [blame] | 492 | host->dummy_zero_addr.start = host->dummy_zero_addr.end = 0; |
| 493 | host->dummy_max_addr.start = host->dummy_max_addr.end = ((u64) 1) << 48; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Stefan Richter | e47c1fe | 2008-11-26 01:34:25 +0100 | [diff] [blame] | 495 | list_add_tail(&host->dummy_zero_addr.host_list, &host->addr_space); |
| 496 | list_add_tail(&host->dummy_max_addr.host_list, &host->addr_space); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | void highlevel_add_host(struct hpsb_host *host) |
| 500 | { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 501 | struct hpsb_highlevel *hl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
| 503 | init_hpsb_highlevel(host); |
| 504 | |
| 505 | down_read(&hl_drivers_sem); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 506 | list_for_each_entry(hl, &hl_drivers, hl_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | if (hl->add_host) |
| 508 | hl->add_host(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 510 | up_read(&hl_drivers_sem); |
| 511 | if (host->update_config_rom && hpsb_update_config_rom_image(host) < 0) |
| 512 | HPSB_ERR("Failed to generate Configuration ROM image for host " |
| 513 | "%s-%d", hl->name, host->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | void highlevel_remove_host(struct hpsb_host *host) |
| 517 | { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 518 | struct hpsb_highlevel *hl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
| 520 | down_read(&hl_drivers_sem); |
| 521 | list_for_each_entry(hl, &hl_drivers, hl_list) |
| 522 | __unregister_host(hl, host, 0); |
| 523 | up_read(&hl_drivers_sem); |
| 524 | } |
| 525 | |
| 526 | void highlevel_host_reset(struct hpsb_host *host) |
| 527 | { |
Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 528 | unsigned long flags; |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 529 | struct hpsb_highlevel *hl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 531 | read_lock_irqsave(&hl_irqs_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | list_for_each_entry(hl, &hl_irqs, irq_list) { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 533 | if (hl->host_reset) |
| 534 | hl->host_reset(host); |
| 535 | } |
Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 536 | read_unlock_irqrestore(&hl_irqs_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction, |
| 540 | void *data, size_t length) |
| 541 | { |
Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 542 | unsigned long flags; |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 543 | struct hpsb_highlevel *hl; |
| 544 | int cts = ((quadlet_t *)data)[0] >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 546 | read_lock_irqsave(&hl_irqs_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | list_for_each_entry(hl, &hl_irqs, irq_list) { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 548 | if (hl->fcp_request) |
| 549 | hl->fcp_request(host, nodeid, direction, cts, data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | length); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 551 | } |
| 552 | read_unlock_irqrestore(&hl_irqs_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 555 | /* |
| 556 | * highlevel_read, highlevel_write, highlevel_lock, highlevel_lock64: |
| 557 | * |
| 558 | * These functions are called to handle transactions. They are called when a |
| 559 | * packet arrives. The flags argument contains the second word of the first |
| 560 | * header quadlet of the incoming packet (containing transaction label, retry |
| 561 | * code, transaction code and priority). These functions either return a |
| 562 | * response code or a negative number. In the first case a response will be |
| 563 | * generated. In the latter case, no response will be sent and the driver which |
| 564 | * handled the request will send the response itself. |
| 565 | */ |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 566 | int highlevel_read(struct hpsb_host *host, int nodeid, void *data, u64 addr, |
| 567 | unsigned int length, u16 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 569 | struct hpsb_address_serve *as; |
| 570 | unsigned int partlength; |
| 571 | int rcode = RCODE_ADDRESS_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 573 | read_lock(&addr_space_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | list_for_each_entry(as, &host->addr_space, host_list) { |
| 575 | if (as->start > addr) |
| 576 | break; |
| 577 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 578 | if (as->end > addr) { |
| 579 | partlength = min(as->end - addr, (u64) length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 581 | if (as->op->read) |
| 582 | rcode = as->op->read(host, nodeid, data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | addr, partlength, flags); |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 584 | else |
| 585 | rcode = RCODE_TYPE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
| 587 | data += partlength; |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 588 | length -= partlength; |
| 589 | addr += partlength; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 591 | if ((rcode != RCODE_COMPLETE) || !length) |
| 592 | break; |
| 593 | } |
| 594 | } |
| 595 | read_unlock(&addr_space_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 597 | if (length && (rcode == RCODE_COMPLETE)) |
| 598 | rcode = RCODE_ADDRESS_ERROR; |
| 599 | return rcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 602 | int highlevel_write(struct hpsb_host *host, int nodeid, int destid, void *data, |
| 603 | u64 addr, unsigned int length, u16 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 605 | struct hpsb_address_serve *as; |
| 606 | unsigned int partlength; |
| 607 | int rcode = RCODE_ADDRESS_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 609 | read_lock(&addr_space_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | list_for_each_entry(as, &host->addr_space, host_list) { |
| 611 | if (as->start > addr) |
| 612 | break; |
| 613 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 614 | if (as->end > addr) { |
| 615 | partlength = min(as->end - addr, (u64) length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 617 | if (as->op->write) |
| 618 | rcode = as->op->write(host, nodeid, destid, |
| 619 | data, addr, partlength, |
| 620 | flags); |
| 621 | else |
| 622 | rcode = RCODE_TYPE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
| 624 | data += partlength; |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 625 | length -= partlength; |
| 626 | addr += partlength; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 628 | if ((rcode != RCODE_COMPLETE) || !length) |
| 629 | break; |
| 630 | } |
| 631 | } |
| 632 | read_unlock(&addr_space_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 634 | if (length && (rcode == RCODE_COMPLETE)) |
| 635 | rcode = RCODE_ADDRESS_ERROR; |
| 636 | return rcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store, |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 640 | u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, |
| 641 | u16 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 643 | struct hpsb_address_serve *as; |
| 644 | int rcode = RCODE_ADDRESS_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 646 | read_lock(&addr_space_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | list_for_each_entry(as, &host->addr_space, host_list) { |
| 648 | if (as->start > addr) |
| 649 | break; |
| 650 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 651 | if (as->end > addr) { |
| 652 | if (as->op->lock) |
| 653 | rcode = as->op->lock(host, nodeid, store, addr, |
| 654 | data, arg, ext_tcode, |
| 655 | flags); |
| 656 | else |
| 657 | rcode = RCODE_TYPE_ERROR; |
| 658 | break; |
| 659 | } |
| 660 | } |
| 661 | read_unlock(&addr_space_lock); |
| 662 | return rcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store, |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 666 | u64 addr, octlet_t data, octlet_t arg, int ext_tcode, |
| 667 | u16 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | { |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 669 | struct hpsb_address_serve *as; |
| 670 | int rcode = RCODE_ADDRESS_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 672 | read_lock(&addr_space_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | list_for_each_entry(as, &host->addr_space, host_list) { |
| 675 | if (as->start > addr) |
| 676 | break; |
| 677 | |
Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 678 | if (as->end > addr) { |
| 679 | if (as->op->lock64) |
| 680 | rcode = as->op->lock64(host, nodeid, store, |
| 681 | addr, data, arg, |
| 682 | ext_tcode, flags); |
| 683 | else |
| 684 | rcode = RCODE_TYPE_ERROR; |
| 685 | break; |
| 686 | } |
| 687 | } |
| 688 | read_unlock(&addr_space_lock); |
| 689 | return rcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | } |