ehca_eq.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * IBM eServer eHCA Infiniband device driver for Linux on POWER
  3. *
  4. * Event queue handling
  5. *
  6. * Authors: Waleri Fomin <fomin@de.ibm.com>
  7. * Khadija Souissi <souissi@de.ibm.com>
  8. * Reinhard Ernst <rernst@de.ibm.com>
  9. * Heiko J Schick <schickhj@de.ibm.com>
  10. * Hoang-Nam Nguyen <hnguyen@de.ibm.com>
  11. *
  12. *
  13. * Copyright (c) 2005 IBM Corporation
  14. *
  15. * All rights reserved.
  16. *
  17. * This source code is distributed under a dual license of GPL v2.0 and OpenIB
  18. * BSD.
  19. *
  20. * OpenIB BSD License
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions are met:
  24. *
  25. * Redistributions of source code must retain the above copyright notice, this
  26. * list of conditions and the following disclaimer.
  27. *
  28. * Redistributions in binary form must reproduce the above copyright notice,
  29. * this list of conditions and the following disclaimer in the documentation
  30. * and/or other materials
  31. * provided with the distribution.
  32. *
  33. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  34. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  35. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  37. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  38. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  39. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  40. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  41. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  43. * POSSIBILITY OF SUCH DAMAGE.
  44. */
  45. #include "ehca_classes.h"
  46. #include "ehca_irq.h"
  47. #include "ehca_iverbs.h"
  48. #include "ehca_qes.h"
  49. #include "hcp_if.h"
  50. #include "ipz_pt_fn.h"
  51. int ehca_create_eq(struct ehca_shca *shca,
  52. struct ehca_eq *eq,
  53. const enum ehca_eq_type type, const u32 length)
  54. {
  55. int ret;
  56. u64 h_ret;
  57. u32 nr_pages;
  58. u32 i;
  59. void *vpage;
  60. struct ib_device *ib_dev = &shca->ib_device;
  61. spin_lock_init(&eq->spinlock);
  62. spin_lock_init(&eq->irq_spinlock);
  63. eq->is_initialized = 0;
  64. if (type != EHCA_EQ && type != EHCA_NEQ) {
  65. ehca_err(ib_dev, "Invalid EQ type %x. eq=%p", type, eq);
  66. return -EINVAL;
  67. }
  68. if (!length) {
  69. ehca_err(ib_dev, "EQ length must not be zero. eq=%p", eq);
  70. return -EINVAL;
  71. }
  72. h_ret = hipz_h_alloc_resource_eq(shca->ipz_hca_handle,
  73. &eq->pf,
  74. type,
  75. length,
  76. &eq->ipz_eq_handle,
  77. &eq->length,
  78. &nr_pages, &eq->ist);
  79. if (h_ret != H_SUCCESS) {
  80. ehca_err(ib_dev, "Can't allocate EQ/NEQ. eq=%p", eq);
  81. return -EINVAL;
  82. }
  83. ret = ipz_queue_ctor(NULL, &eq->ipz_queue, nr_pages,
  84. EHCA_PAGESIZE, sizeof(struct ehca_eqe), 0, 0);
  85. if (!ret) {
  86. ehca_err(ib_dev, "Can't allocate EQ pages eq=%p", eq);
  87. goto create_eq_exit1;
  88. }
  89. for (i = 0; i < nr_pages; i++) {
  90. u64 rpage;
  91. vpage = ipz_qpageit_get_inc(&eq->ipz_queue);
  92. if (!vpage)
  93. goto create_eq_exit2;
  94. rpage = virt_to_abs(vpage);
  95. h_ret = hipz_h_register_rpage_eq(shca->ipz_hca_handle,
  96. eq->ipz_eq_handle,
  97. &eq->pf,
  98. 0, 0, rpage, 1);
  99. if (i == (nr_pages - 1)) {
  100. /* last page */
  101. vpage = ipz_qpageit_get_inc(&eq->ipz_queue);
  102. if (h_ret != H_SUCCESS || vpage)
  103. goto create_eq_exit2;
  104. } else {
  105. if (h_ret != H_PAGE_REGISTERED)
  106. goto create_eq_exit2;
  107. }
  108. }
  109. ipz_qeit_reset(&eq->ipz_queue);
  110. /* register interrupt handlers and initialize work queues */
  111. if (type == EHCA_EQ) {
  112. tasklet_init(&eq->interrupt_task, ehca_tasklet_eq, (long)shca);
  113. ret = ibmebus_request_irq(eq->ist, ehca_interrupt_eq,
  114. 0, "ehca_eq",
  115. (void *)shca);
  116. if (ret < 0)
  117. ehca_err(ib_dev, "Can't map interrupt handler.");
  118. } else if (type == EHCA_NEQ) {
  119. tasklet_init(&eq->interrupt_task, ehca_tasklet_neq, (long)shca);
  120. ret = ibmebus_request_irq(eq->ist, ehca_interrupt_neq,
  121. 0, "ehca_neq",
  122. (void *)shca);
  123. if (ret < 0)
  124. ehca_err(ib_dev, "Can't map interrupt handler.");
  125. }
  126. eq->is_initialized = 1;
  127. return 0;
  128. create_eq_exit2:
  129. ipz_queue_dtor(NULL, &eq->ipz_queue);
  130. create_eq_exit1:
  131. hipz_h_destroy_eq(shca->ipz_hca_handle, eq);
  132. return -EINVAL;
  133. }
  134. void *ehca_poll_eq(struct ehca_shca *shca, struct ehca_eq *eq)
  135. {
  136. unsigned long flags;
  137. void *eqe;
  138. spin_lock_irqsave(&eq->spinlock, flags);
  139. eqe = ipz_eqit_eq_get_inc_valid(&eq->ipz_queue);
  140. spin_unlock_irqrestore(&eq->spinlock, flags);
  141. return eqe;
  142. }
  143. int ehca_destroy_eq(struct ehca_shca *shca, struct ehca_eq *eq)
  144. {
  145. unsigned long flags;
  146. u64 h_ret;
  147. ibmebus_free_irq(eq->ist, (void *)shca);
  148. spin_lock_irqsave(&shca_list_lock, flags);
  149. eq->is_initialized = 0;
  150. spin_unlock_irqrestore(&shca_list_lock, flags);
  151. tasklet_kill(&eq->interrupt_task);
  152. h_ret = hipz_h_destroy_eq(shca->ipz_hca_handle, eq);
  153. if (h_ret != H_SUCCESS) {
  154. ehca_err(&shca->ib_device, "Can't free EQ resources.");
  155. return -EINVAL;
  156. }
  157. ipz_queue_dtor(NULL, &eq->ipz_queue);
  158. return 0;
  159. }