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