| 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* Returns a per host/driver data structure that was previously stored by | 
 | 74 |  * hpsb_create_hostinfo. */ | 
 | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* If size is zero, then the return here is only valid for error checking */ | 
 | 83 | void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, | 
 | 84 | 			   size_t data_size) | 
 | 85 | { | 
 | 86 | 	struct hl_host_info *hi; | 
 | 87 | 	void *data; | 
 | 88 | 	unsigned long flags; | 
 | 89 |  | 
 | 90 | 	hi = hl_get_hostinfo(hl, host); | 
 | 91 | 	if (hi) { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 92 | 		HPSB_ERR("%s called hpsb_create_hostinfo when hostinfo already" | 
 | 93 | 			 " exists", hl->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | 		return NULL; | 
 | 95 | 	} | 
 | 96 |  | 
| Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 97 | 	hi = kzalloc(sizeof(*hi) + data_size, GFP_ATOMIC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | 	if (!hi) | 
 | 99 | 		return NULL; | 
 | 100 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | 	if (data_size) { | 
 | 102 | 		data = hi->data = hi + 1; | 
 | 103 | 		hi->size = data_size; | 
 | 104 | 	} else | 
 | 105 | 		data = hi; | 
 | 106 |  | 
 | 107 | 	hi->host = host; | 
 | 108 |  | 
 | 109 | 	write_lock_irqsave(&hl->host_info_lock, flags); | 
 | 110 | 	list_add_tail(&hi->list, &hl->host_info_list); | 
 | 111 | 	write_unlock_irqrestore(&hl->host_info_lock, flags); | 
 | 112 |  | 
 | 113 | 	return data; | 
 | 114 | } | 
 | 115 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, | 
 | 117 | 		      void *data) | 
 | 118 | { | 
 | 119 | 	struct hl_host_info *hi; | 
 | 120 |  | 
 | 121 | 	hi = hl_get_hostinfo(hl, host); | 
 | 122 | 	if (hi) { | 
 | 123 | 		if (!hi->size && !hi->data) { | 
 | 124 | 			hi->data = data; | 
 | 125 | 			return 0; | 
 | 126 | 		} else | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 127 | 			HPSB_ERR("%s called hpsb_set_hostinfo when hostinfo " | 
 | 128 | 				 "already has data", hl->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | 	} else | 
 | 130 | 		HPSB_ERR("%s called hpsb_set_hostinfo when no hostinfo exists", | 
 | 131 | 			 hl->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | 	return -EINVAL; | 
 | 133 | } | 
 | 134 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host) | 
 | 136 | { | 
 | 137 | 	struct hl_host_info *hi; | 
 | 138 |  | 
 | 139 | 	hi = hl_get_hostinfo(hl, host); | 
 | 140 | 	if (hi) { | 
 | 141 | 		unsigned long flags; | 
 | 142 | 		write_lock_irqsave(&hl->host_info_lock, flags); | 
 | 143 | 		list_del(&hi->list); | 
 | 144 | 		write_unlock_irqrestore(&hl->host_info_lock, flags); | 
 | 145 | 		kfree(hi); | 
 | 146 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | 	return; | 
 | 148 | } | 
 | 149 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 150 | void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host, | 
 | 151 | 			   unsigned long key) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { | 
 | 153 | 	struct hl_host_info *hi; | 
 | 154 |  | 
 | 155 | 	hi = hl_get_hostinfo(hl, host); | 
 | 156 | 	if (hi) | 
 | 157 | 		hi->key = key; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | 	return; | 
 | 159 | } | 
 | 160 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key) | 
 | 162 | { | 
 | 163 | 	struct hl_host_info *hi; | 
 | 164 | 	void *data = NULL; | 
 | 165 |  | 
 | 166 | 	if (!hl) | 
 | 167 | 		return NULL; | 
 | 168 |  | 
 | 169 | 	read_lock(&hl->host_info_lock); | 
 | 170 | 	list_for_each_entry(hi, &hl->host_info_list, list) { | 
 | 171 | 		if (hi->key == key) { | 
 | 172 | 			data = hi->data; | 
 | 173 | 			break; | 
 | 174 | 		} | 
 | 175 | 	} | 
 | 176 | 	read_unlock(&hl->host_info_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | 	return data; | 
 | 178 | } | 
 | 179 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | static int highlevel_for_each_host_reg(struct hpsb_host *host, void *__data) | 
 | 181 | { | 
 | 182 | 	struct hpsb_highlevel *hl = __data; | 
 | 183 |  | 
 | 184 | 	hl->add_host(host); | 
 | 185 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 186 | 	if (host->update_config_rom && hpsb_update_config_rom_image(host) < 0) | 
 | 187 | 		HPSB_ERR("Failed to generate Configuration ROM image for host " | 
 | 188 | 			 "%s-%d", hl->name, host->id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | 	return 0; | 
 | 190 | } | 
 | 191 |  | 
 | 192 | void hpsb_register_highlevel(struct hpsb_highlevel *hl) | 
 | 193 | { | 
| Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 194 | 	unsigned long flags; | 
 | 195 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 196 | 	INIT_LIST_HEAD(&hl->addr_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | 	INIT_LIST_HEAD(&hl->host_info_list); | 
 | 198 |  | 
 | 199 | 	rwlock_init(&hl->host_info_lock); | 
 | 200 |  | 
 | 201 | 	down_write(&hl_drivers_sem); | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 202 | 	list_add_tail(&hl->hl_list, &hl_drivers); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | 	up_write(&hl_drivers_sem); | 
 | 204 |  | 
| Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 205 | 	write_lock_irqsave(&hl_irqs_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | 	list_add_tail(&hl->irq_list, &hl_irqs); | 
| Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 207 | 	write_unlock_irqrestore(&hl_irqs_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 |  | 
 | 209 | 	if (hl->add_host) | 
 | 210 | 		nodemgr_for_each_host(hl, highlevel_for_each_host_reg); | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 211 | 	return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } | 
 | 213 |  | 
 | 214 | static void __delete_addr(struct hpsb_address_serve *as) | 
 | 215 | { | 
 | 216 | 	list_del(&as->host_list); | 
 | 217 | 	list_del(&as->hl_list); | 
 | 218 | 	kfree(as); | 
 | 219 | } | 
 | 220 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 221 | static void __unregister_host(struct hpsb_highlevel *hl, struct hpsb_host *host, | 
 | 222 | 			      int update_cr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | { | 
 | 224 | 	unsigned long flags; | 
 | 225 | 	struct list_head *lh, *next; | 
 | 226 | 	struct hpsb_address_serve *as; | 
 | 227 |  | 
 | 228 | 	/* First, let the highlevel driver unreg */ | 
 | 229 | 	if (hl->remove_host) | 
 | 230 | 		hl->remove_host(host); | 
 | 231 |  | 
 | 232 | 	/* Remove any addresses that are matched for this highlevel driver | 
 | 233 | 	 * and this particular host. */ | 
 | 234 | 	write_lock_irqsave(&addr_space_lock, flags); | 
 | 235 | 	list_for_each_safe (lh, next, &hl->addr_list) { | 
 | 236 | 		as = list_entry(lh, struct hpsb_address_serve, hl_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | 		if (as->host == host) | 
 | 238 | 			__delete_addr(as); | 
 | 239 | 	} | 
 | 240 | 	write_unlock_irqrestore(&addr_space_lock, flags); | 
 | 241 |  | 
 | 242 | 	/* Now update the config-rom to reflect anything removed by the | 
 | 243 | 	 * highlevel driver. */ | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 244 | 	if (update_cr && host->update_config_rom && | 
 | 245 | 	    hpsb_update_config_rom_image(host) < 0) | 
 | 246 | 		HPSB_ERR("Failed to generate Configuration ROM image for host " | 
 | 247 | 			 "%s-%d", hl->name, host->id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 249 | 	/* Finally remove all the host info associated between these two. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | 	hpsb_destroy_hostinfo(hl, host); | 
 | 251 | } | 
 | 252 |  | 
 | 253 | static int highlevel_for_each_host_unreg(struct hpsb_host *host, void *__data) | 
 | 254 | { | 
 | 255 | 	struct hpsb_highlevel *hl = __data; | 
 | 256 |  | 
 | 257 | 	__unregister_host(hl, host, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | 	return 0; | 
 | 259 | } | 
 | 260 |  | 
 | 261 | void hpsb_unregister_highlevel(struct hpsb_highlevel *hl) | 
 | 262 | { | 
| Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 263 | 	unsigned long flags; | 
 | 264 |  | 
 | 265 | 	write_lock_irqsave(&hl_irqs_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | 	list_del(&hl->irq_list); | 
| Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 267 | 	write_unlock_irqrestore(&hl_irqs_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 |  | 
 | 269 | 	down_write(&hl_drivers_sem); | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 270 | 	list_del(&hl->hl_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | 	up_write(&hl_drivers_sem); | 
 | 272 |  | 
 | 273 | 	nodemgr_for_each_host(hl, highlevel_for_each_host_unreg); | 
 | 274 | } | 
 | 275 |  | 
 | 276 | u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl, | 
 | 277 | 					 struct hpsb_host *host, | 
 | 278 | 					 struct hpsb_address_ops *ops, | 
 | 279 | 					 u64 size, u64 alignment, | 
 | 280 | 					 u64 start, u64 end) | 
 | 281 | { | 
 | 282 | 	struct hpsb_address_serve *as, *a1, *a2; | 
 | 283 | 	struct list_head *entry; | 
| Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 284 | 	u64 retval = CSR1212_INVALID_ADDR_SPACE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | 	unsigned long flags; | 
 | 286 | 	u64 align_mask = ~(alignment - 1); | 
 | 287 |  | 
 | 288 | 	if ((alignment & 3) || (alignment > 0x800000000000ULL) || | 
| Akinobu Mita | 37d5411 | 2006-03-26 01:39:56 -0800 | [diff] [blame] | 289 | 	    (hweight64(alignment) != 1)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | 		HPSB_ERR("%s called with invalid alignment: 0x%048llx", | 
 | 291 | 			 __FUNCTION__, (unsigned long long)alignment); | 
 | 292 | 		return retval; | 
 | 293 | 	} | 
 | 294 |  | 
| Ben Collins | 8aef63f | 2006-06-12 18:13:21 -0400 | [diff] [blame] | 295 | 	/* default range, | 
 | 296 | 	 * 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] | 297 | 	if (start == CSR1212_INVALID_ADDR_SPACE && | 
 | 298 | 	    end   == CSR1212_INVALID_ADDR_SPACE) { | 
| Ben Collins | 8aef63f | 2006-06-12 18:13:21 -0400 | [diff] [blame] | 299 | 		start = host->middle_addr_space; | 
| Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 300 | 		end   = CSR1212_ALL_SPACE_END; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | 	} | 
 | 302 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 303 | 	if (((start|end) & ~align_mask) || (start >= end) || | 
 | 304 | 	    (end > CSR1212_ALL_SPACE_END)) { | 
 | 305 | 		HPSB_ERR("%s called with invalid addresses " | 
 | 306 | 			 "(start = %012Lx  end = %012Lx)", __FUNCTION__, | 
 | 307 | 			 (unsigned long long)start,(unsigned long long)end); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | 		return retval; | 
 | 309 | 	} | 
 | 310 |  | 
| Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 311 | 	as = kmalloc(sizeof(*as), GFP_KERNEL); | 
 | 312 | 	if (!as) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | 		return retval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 |  | 
 | 315 | 	INIT_LIST_HEAD(&as->host_list); | 
 | 316 | 	INIT_LIST_HEAD(&as->hl_list); | 
 | 317 | 	as->op = ops; | 
 | 318 | 	as->host = host; | 
 | 319 |  | 
 | 320 | 	write_lock_irqsave(&addr_space_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | 	list_for_each(entry, &host->addr_space) { | 
 | 322 | 		u64 a1sa, a1ea; | 
 | 323 | 		u64 a2sa, a2ea; | 
 | 324 |  | 
 | 325 | 		a1 = list_entry(entry, struct hpsb_address_serve, host_list); | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 326 | 		a2 = list_entry(entry->next, struct hpsb_address_serve, | 
 | 327 | 				host_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 |  | 
 | 329 | 		a1sa = a1->start & align_mask; | 
 | 330 | 		a1ea = (a1->end + alignment -1) & align_mask; | 
 | 331 | 		a2sa = a2->start & align_mask; | 
 | 332 | 		a2ea = (a2->end + alignment -1) & align_mask; | 
 | 333 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 334 | 		if ((a2sa - a1ea >= size) && (a2sa - start >= size) && | 
 | 335 | 		    (a2sa > start)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | 			as->start = max(start, a1ea); | 
 | 337 | 			as->end = as->start + size; | 
 | 338 | 			list_add(&as->host_list, entry); | 
 | 339 | 			list_add_tail(&as->hl_list, &hl->addr_list); | 
 | 340 | 			retval = as->start; | 
 | 341 | 			break; | 
 | 342 | 		} | 
 | 343 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | 	write_unlock_irqrestore(&addr_space_lock, flags); | 
 | 345 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 346 | 	if (retval == CSR1212_INVALID_ADDR_SPACE) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | 		kfree(as); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | 	return retval; | 
 | 349 | } | 
 | 350 |  | 
 | 351 | int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 352 | 			    struct hpsb_address_ops *ops, u64 start, u64 end) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 354 | 	struct hpsb_address_serve *as; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | 	struct list_head *lh; | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 356 | 	int retval = 0; | 
 | 357 | 	unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 359 | 	if (((start|end) & 3) || (start >= end) || | 
 | 360 | 	    (end > CSR1212_ALL_SPACE_END)) { | 
 | 361 | 		HPSB_ERR("%s called with invalid addresses", __FUNCTION__); | 
 | 362 | 		return 0; | 
 | 363 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 |  | 
| Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 365 | 	as = kmalloc(sizeof(*as), GFP_ATOMIC); | 
 | 366 | 	if (!as) | 
 | 367 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 369 | 	INIT_LIST_HEAD(&as->host_list); | 
 | 370 | 	INIT_LIST_HEAD(&as->hl_list); | 
 | 371 | 	as->op = ops; | 
 | 372 | 	as->start = start; | 
 | 373 | 	as->end = end; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | 	as->host = host; | 
 | 375 |  | 
 | 376 | 	write_lock_irqsave(&addr_space_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | 	list_for_each(lh, &host->addr_space) { | 
 | 378 | 		struct hpsb_address_serve *as_this = | 
 | 379 | 			list_entry(lh, struct hpsb_address_serve, host_list); | 
 | 380 | 		struct hpsb_address_serve *as_next = | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 381 | 			list_entry(lh->next, struct hpsb_address_serve, | 
 | 382 | 				   host_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 |  | 
 | 384 | 		if (as_this->end > as->start) | 
 | 385 | 			break; | 
 | 386 |  | 
 | 387 | 		if (as_next->start >= as->end) { | 
 | 388 | 			list_add(&as->host_list, lh); | 
 | 389 | 			list_add_tail(&as->hl_list, &hl->addr_list); | 
 | 390 | 			retval = 1; | 
 | 391 | 			break; | 
 | 392 | 		} | 
 | 393 | 	} | 
 | 394 | 	write_unlock_irqrestore(&addr_space_lock, flags); | 
 | 395 |  | 
 | 396 | 	if (retval == 0) | 
 | 397 | 		kfree(as); | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 398 | 	return retval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } | 
 | 400 |  | 
 | 401 | int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 402 | 			      u64 start) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 404 | 	int retval = 0; | 
 | 405 | 	struct hpsb_address_serve *as; | 
 | 406 | 	struct list_head *lh, *next; | 
 | 407 | 	unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 409 | 	write_lock_irqsave(&addr_space_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | 	list_for_each_safe (lh, next, &hl->addr_list) { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 411 | 		as = list_entry(lh, struct hpsb_address_serve, hl_list); | 
 | 412 | 		if (as->start == start && as->host == host) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | 			__delete_addr(as); | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 414 | 			retval = 1; | 
 | 415 | 			break; | 
 | 416 | 		} | 
 | 417 | 	} | 
 | 418 | 	write_unlock_irqrestore(&addr_space_lock, flags); | 
 | 419 | 	return retval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } | 
 | 421 |  | 
 | 422 | int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 423 | 			unsigned int channel) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 425 | 	if (channel > 63) { | 
 | 426 | 		HPSB_ERR("%s called with invalid channel", __FUNCTION__); | 
 | 427 | 		return -EINVAL; | 
 | 428 | 	} | 
 | 429 | 	if (host->iso_listen_count[channel]++ == 0) | 
 | 430 | 		return host->driver->devctl(host, ISO_LISTEN_CHANNEL, channel); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | 	return 0; | 
 | 432 | } | 
 | 433 |  | 
 | 434 | void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 435 | 			   unsigned int channel) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 437 | 	if (channel > 63) { | 
 | 438 | 		HPSB_ERR("%s called with invalid channel", __FUNCTION__); | 
 | 439 | 		return; | 
 | 440 | 	} | 
 | 441 | 	if (--host->iso_listen_count[channel] == 0) | 
 | 442 | 		host->driver->devctl(host, ISO_UNLISTEN_CHANNEL, channel); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } | 
 | 444 |  | 
 | 445 | static void init_hpsb_highlevel(struct hpsb_host *host) | 
 | 446 | { | 
 | 447 | 	INIT_LIST_HEAD(&dummy_zero_addr.host_list); | 
 | 448 | 	INIT_LIST_HEAD(&dummy_zero_addr.hl_list); | 
 | 449 | 	INIT_LIST_HEAD(&dummy_max_addr.host_list); | 
 | 450 | 	INIT_LIST_HEAD(&dummy_max_addr.hl_list); | 
 | 451 |  | 
 | 452 | 	dummy_zero_addr.op = dummy_max_addr.op = &dummy_ops; | 
 | 453 |  | 
 | 454 | 	dummy_zero_addr.start = dummy_zero_addr.end = 0; | 
 | 455 | 	dummy_max_addr.start = dummy_max_addr.end = ((u64) 1) << 48; | 
 | 456 |  | 
 | 457 | 	list_add_tail(&dummy_zero_addr.host_list, &host->addr_space); | 
 | 458 | 	list_add_tail(&dummy_max_addr.host_list, &host->addr_space); | 
 | 459 | } | 
 | 460 |  | 
 | 461 | void highlevel_add_host(struct hpsb_host *host) | 
 | 462 | { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 463 | 	struct hpsb_highlevel *hl; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 |  | 
 | 465 | 	init_hpsb_highlevel(host); | 
 | 466 |  | 
 | 467 | 	down_read(&hl_drivers_sem); | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 468 | 	list_for_each_entry(hl, &hl_drivers, hl_list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | 		if (hl->add_host) | 
 | 470 | 			hl->add_host(host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | 	} | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 472 | 	up_read(&hl_drivers_sem); | 
 | 473 | 	if (host->update_config_rom && hpsb_update_config_rom_image(host) < 0) | 
 | 474 | 		HPSB_ERR("Failed to generate Configuration ROM image for host " | 
 | 475 | 			 "%s-%d", hl->name, host->id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } | 
 | 477 |  | 
 | 478 | void highlevel_remove_host(struct hpsb_host *host) | 
 | 479 | { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 480 | 	struct hpsb_highlevel *hl; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 |  | 
 | 482 | 	down_read(&hl_drivers_sem); | 
 | 483 | 	list_for_each_entry(hl, &hl_drivers, hl_list) | 
 | 484 | 		__unregister_host(hl, host, 0); | 
 | 485 | 	up_read(&hl_drivers_sem); | 
 | 486 | } | 
 | 487 |  | 
 | 488 | void highlevel_host_reset(struct hpsb_host *host) | 
 | 489 | { | 
| Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 490 | 	unsigned long flags; | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 491 | 	struct hpsb_highlevel *hl; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 |  | 
| Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 493 | 	read_lock_irqsave(&hl_irqs_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | 	list_for_each_entry(hl, &hl_irqs, irq_list) { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 495 | 		if (hl->host_reset) | 
 | 496 | 			hl->host_reset(host); | 
 | 497 | 	} | 
| Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 498 | 	read_unlock_irqrestore(&hl_irqs_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } | 
 | 500 |  | 
 | 501 | void highlevel_iso_receive(struct hpsb_host *host, void *data, size_t length) | 
 | 502 | { | 
| Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 503 | 	unsigned long flags; | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 504 | 	struct hpsb_highlevel *hl; | 
 | 505 | 	int channel = (((quadlet_t *)data)[0] >> 8) & 0x3f; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 507 | 	read_lock_irqsave(&hl_irqs_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | 	list_for_each_entry(hl, &hl_irqs, irq_list) { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 509 | 		if (hl->iso_receive) | 
 | 510 | 			hl->iso_receive(host, channel, data, length); | 
 | 511 | 	} | 
 | 512 | 	read_unlock_irqrestore(&hl_irqs_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } | 
 | 514 |  | 
 | 515 | void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction, | 
 | 516 | 			   void *data, size_t length) | 
 | 517 | { | 
| Ben Collins | 4451519 | 2006-06-12 18:16:01 -0400 | [diff] [blame] | 518 | 	unsigned long flags; | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 519 | 	struct hpsb_highlevel *hl; | 
 | 520 | 	int cts = ((quadlet_t *)data)[0] >> 4; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 522 | 	read_lock_irqsave(&hl_irqs_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | 	list_for_each_entry(hl, &hl_irqs, irq_list) { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 524 | 		if (hl->fcp_request) | 
 | 525 | 			hl->fcp_request(host, nodeid, direction, cts, data, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | 					length); | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 527 | 	} | 
 | 528 | 	read_unlock_irqrestore(&hl_irqs_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } | 
 | 530 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 531 | int highlevel_read(struct hpsb_host *host, int nodeid, void *data, u64 addr, | 
 | 532 | 		   unsigned int length, u16 flags) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 534 | 	struct hpsb_address_serve *as; | 
 | 535 | 	unsigned int partlength; | 
 | 536 | 	int rcode = RCODE_ADDRESS_ERROR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 538 | 	read_lock(&addr_space_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | 	list_for_each_entry(as, &host->addr_space, host_list) { | 
 | 540 | 		if (as->start > addr) | 
 | 541 | 			break; | 
 | 542 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 543 | 		if (as->end > addr) { | 
 | 544 | 			partlength = min(as->end - addr, (u64) length); | 
| 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 | 			if (as->op->read) | 
 | 547 | 				rcode = as->op->read(host, nodeid, data, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | 						     addr, partlength, flags); | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 549 | 			else | 
 | 550 | 				rcode = RCODE_TYPE_ERROR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 |  | 
 | 552 | 			data += partlength; | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 553 | 			length -= partlength; | 
 | 554 | 			addr += partlength; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 556 | 			if ((rcode != RCODE_COMPLETE) || !length) | 
 | 557 | 				break; | 
 | 558 | 		} | 
 | 559 | 	} | 
 | 560 | 	read_unlock(&addr_space_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 562 | 	if (length && (rcode == RCODE_COMPLETE)) | 
 | 563 | 		rcode = RCODE_ADDRESS_ERROR; | 
 | 564 | 	return rcode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } | 
 | 566 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 567 | int highlevel_write(struct hpsb_host *host, int nodeid, int destid, void *data, | 
 | 568 | 		    u64 addr, 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->write) | 
 | 583 | 				rcode = as->op->write(host, nodeid, destid, | 
 | 584 | 						      data, addr, partlength, | 
 | 585 | 						      flags); | 
 | 586 | 			else | 
 | 587 | 				rcode = RCODE_TYPE_ERROR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 |  | 
 | 589 | 			data += partlength; | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 590 | 			length -= partlength; | 
 | 591 | 			addr += partlength; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 593 | 			if ((rcode != RCODE_COMPLETE) || !length) | 
 | 594 | 				break; | 
 | 595 | 		} | 
 | 596 | 	} | 
 | 597 | 	read_unlock(&addr_space_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 599 | 	if (length && (rcode == RCODE_COMPLETE)) | 
 | 600 | 		rcode = RCODE_ADDRESS_ERROR; | 
 | 601 | 	return rcode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } | 
 | 603 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store, | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 605 | 		   u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, | 
 | 606 | 		   u16 flags) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | { | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 608 | 	struct hpsb_address_serve *as; | 
 | 609 | 	int rcode = RCODE_ADDRESS_ERROR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 611 | 	read_lock(&addr_space_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | 	list_for_each_entry(as, &host->addr_space, host_list) { | 
 | 613 | 		if (as->start > addr) | 
 | 614 | 			break; | 
 | 615 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 616 | 		if (as->end > addr) { | 
 | 617 | 			if (as->op->lock) | 
 | 618 | 				rcode = as->op->lock(host, nodeid, store, addr, | 
 | 619 | 						     data, arg, ext_tcode, | 
 | 620 | 						     flags); | 
 | 621 | 			else | 
 | 622 | 				rcode = RCODE_TYPE_ERROR; | 
 | 623 | 			break; | 
 | 624 | 		} | 
 | 625 | 	} | 
 | 626 | 	read_unlock(&addr_space_lock); | 
 | 627 | 	return rcode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } | 
 | 629 |  | 
 | 630 | int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store, | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 631 | 		     u64 addr, octlet_t data, octlet_t arg, int ext_tcode, | 
 | 632 | 		     u16 flags) | 
| 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 | 	struct hpsb_address_serve *as; | 
 | 635 | 	int rcode = RCODE_ADDRESS_ERROR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 637 | 	read_lock(&addr_space_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 |  | 
 | 639 | 	list_for_each_entry(as, &host->addr_space, host_list) { | 
 | 640 | 		if (as->start > addr) | 
 | 641 | 			break; | 
 | 642 |  | 
| Ben Collins | 2c4b69b | 2006-06-12 18:16:16 -0400 | [diff] [blame] | 643 | 		if (as->end > addr) { | 
 | 644 | 			if (as->op->lock64) | 
 | 645 | 				rcode = as->op->lock64(host, nodeid, store, | 
 | 646 | 						       addr, data, arg, | 
 | 647 | 						       ext_tcode, flags); | 
 | 648 | 			else | 
 | 649 | 				rcode = RCODE_TYPE_ERROR; | 
 | 650 | 			break; | 
 | 651 | 		} | 
 | 652 | 	} | 
 | 653 | 	read_unlock(&addr_space_lock); | 
 | 654 | 	return rcode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |