intr.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright(c) 2015, 2016 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #include <linux/pci.h>
  48. #include <linux/delay.h>
  49. #include "hfi.h"
  50. #include "common.h"
  51. #include "sdma.h"
  52. /**
  53. * format_hwmsg - format a single hwerror message
  54. * @msg message buffer
  55. * @msgl length of message buffer
  56. * @hwmsg message to add to message buffer
  57. */
  58. static void format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
  59. {
  60. strlcat(msg, "[", msgl);
  61. strlcat(msg, hwmsg, msgl);
  62. strlcat(msg, "]", msgl);
  63. }
  64. /**
  65. * hfi1_format_hwerrors - format hardware error messages for display
  66. * @hwerrs hardware errors bit vector
  67. * @hwerrmsgs hardware error descriptions
  68. * @nhwerrmsgs number of hwerrmsgs
  69. * @msg message buffer
  70. * @msgl message buffer length
  71. */
  72. void hfi1_format_hwerrors(u64 hwerrs, const struct hfi1_hwerror_msgs *hwerrmsgs,
  73. size_t nhwerrmsgs, char *msg, size_t msgl)
  74. {
  75. int i;
  76. for (i = 0; i < nhwerrmsgs; i++)
  77. if (hwerrs & hwerrmsgs[i].mask)
  78. format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
  79. }
  80. static void signal_ib_event(struct hfi1_pportdata *ppd, enum ib_event_type ev)
  81. {
  82. struct ib_event event;
  83. struct hfi1_devdata *dd = ppd->dd;
  84. /*
  85. * Only call ib_dispatch_event() if the IB device has been
  86. * registered. HFI1_INITED is set iff the driver has successfully
  87. * registered with the IB core.
  88. */
  89. if (!(dd->flags & HFI1_INITTED))
  90. return;
  91. event.device = &dd->verbs_dev.rdi.ibdev;
  92. event.element.port_num = ppd->port;
  93. event.event = ev;
  94. ib_dispatch_event(&event);
  95. }
  96. /*
  97. * Handle a linkup or link down notification.
  98. * This is called outside an interrupt.
  99. */
  100. void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup)
  101. {
  102. struct hfi1_pportdata *ppd = &dd->pport[0];
  103. enum ib_event_type ev;
  104. if (!(ppd->linkup ^ !!linkup))
  105. return; /* no change, nothing to do */
  106. if (linkup) {
  107. /*
  108. * Quick linkup and all link up on the simulator does not
  109. * trigger or implement:
  110. * - VerifyCap interrupt
  111. * - VerifyCap frames
  112. * But rather moves directly to LinkUp.
  113. *
  114. * Do the work of the VerifyCap interrupt handler,
  115. * handle_verify_cap(), but do not try moving the state to
  116. * LinkUp as we are already there.
  117. *
  118. * NOTE: This uses this device's vAU, vCU, and vl15_init for
  119. * the remote values. Both sides must be using the values.
  120. */
  121. if (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  122. set_up_vl15(dd, dd->vau, dd->vl15_init);
  123. assign_remote_cm_au_table(dd, dd->vcu);
  124. ppd->neighbor_guid =
  125. read_csr(dd, DC_DC8051_STS_REMOTE_GUID);
  126. ppd->neighbor_type =
  127. read_csr(dd, DC_DC8051_STS_REMOTE_NODE_TYPE) &
  128. DC_DC8051_STS_REMOTE_NODE_TYPE_VAL_MASK;
  129. ppd->neighbor_port_number =
  130. read_csr(dd, DC_DC8051_STS_REMOTE_PORT_NO) &
  131. DC_DC8051_STS_REMOTE_PORT_NO_VAL_SMASK;
  132. dd_dev_info(dd, "Neighbor GUID: %llx Neighbor type %d\n",
  133. ppd->neighbor_guid,
  134. ppd->neighbor_type);
  135. }
  136. /* physical link went up */
  137. ppd->linkup = 1;
  138. ppd->offline_disabled_reason =
  139. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
  140. /* link widths are not available until the link is fully up */
  141. get_linkup_link_widths(ppd);
  142. } else {
  143. /* physical link went down */
  144. ppd->linkup = 0;
  145. /* clear HW details of the previous connection */
  146. reset_link_credits(dd);
  147. /* freeze after a link down to guarantee a clean egress */
  148. start_freeze_handling(ppd, FREEZE_SELF | FREEZE_LINK_DOWN);
  149. ev = IB_EVENT_PORT_ERR;
  150. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LINKDOWN_BIT);
  151. /* if we are down, the neighbor is down */
  152. ppd->neighbor_normal = 0;
  153. /* notify IB of the link change */
  154. signal_ib_event(ppd, ev);
  155. }
  156. }
  157. /*
  158. * Handle receive or urgent interrupts for user contexts. This means a user
  159. * process was waiting for a packet to arrive, and didn't want to poll.
  160. */
  161. void handle_user_interrupt(struct hfi1_ctxtdata *rcd)
  162. {
  163. struct hfi1_devdata *dd = rcd->dd;
  164. unsigned long flags;
  165. spin_lock_irqsave(&dd->uctxt_lock, flags);
  166. if (!rcd->cnt)
  167. goto done;
  168. if (test_and_clear_bit(HFI1_CTXT_WAITING_RCV, &rcd->event_flags)) {
  169. wake_up_interruptible(&rcd->wait);
  170. hfi1_rcvctrl(dd, HFI1_RCVCTRL_INTRAVAIL_DIS, rcd->ctxt);
  171. } else if (test_and_clear_bit(HFI1_CTXT_WAITING_URG,
  172. &rcd->event_flags)) {
  173. rcd->urgent++;
  174. wake_up_interruptible(&rcd->wait);
  175. }
  176. done:
  177. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  178. }