highlevel.c 19 KB

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