intr.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 <linux/bitmap.h>
  50. #include "hfi.h"
  51. #include "common.h"
  52. #include "sdma.h"
  53. #define LINK_UP_DELAY 500 /* in microseconds */
  54. static void set_mgmt_allowed(struct hfi1_pportdata *ppd)
  55. {
  56. u32 frame;
  57. struct hfi1_devdata *dd = ppd->dd;
  58. if (ppd->neighbor_type == NEIGHBOR_TYPE_HFI) {
  59. ppd->mgmt_allowed = 1;
  60. } else {
  61. read_8051_config(dd, REMOTE_LNI_INFO, GENERAL_CONFIG, &frame);
  62. ppd->mgmt_allowed = (frame >> MGMT_ALLOWED_SHIFT)
  63. & MGMT_ALLOWED_MASK;
  64. }
  65. }
  66. /*
  67. * Our neighbor has indicated that we are allowed to act as a fabric
  68. * manager, so place the full management partition key in the second
  69. * (0-based) pkey array position. Note that we should already have
  70. * the limited management partition key in array element 1, and also
  71. * that the port is not yet up when add_full_mgmt_pkey() is invoked.
  72. */
  73. static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
  74. {
  75. struct hfi1_devdata *dd = ppd->dd;
  76. /* Sanity check - ppd->pkeys[2] should be 0, or already initialized */
  77. if (!((ppd->pkeys[2] == 0) || (ppd->pkeys[2] == FULL_MGMT_P_KEY)))
  78. dd_dev_warn(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n",
  79. __func__, ppd->pkeys[2], FULL_MGMT_P_KEY);
  80. ppd->pkeys[2] = FULL_MGMT_P_KEY;
  81. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  82. hfi1_event_pkey_change(ppd->dd, ppd->port);
  83. }
  84. /**
  85. * format_hwmsg - format a single hwerror message
  86. * @msg message buffer
  87. * @msgl length of message buffer
  88. * @hwmsg message to add to message buffer
  89. */
  90. static void format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
  91. {
  92. strlcat(msg, "[", msgl);
  93. strlcat(msg, hwmsg, msgl);
  94. strlcat(msg, "]", msgl);
  95. }
  96. /**
  97. * hfi1_format_hwerrors - format hardware error messages for display
  98. * @hwerrs hardware errors bit vector
  99. * @hwerrmsgs hardware error descriptions
  100. * @nhwerrmsgs number of hwerrmsgs
  101. * @msg message buffer
  102. * @msgl message buffer length
  103. */
  104. void hfi1_format_hwerrors(u64 hwerrs, const struct hfi1_hwerror_msgs *hwerrmsgs,
  105. size_t nhwerrmsgs, char *msg, size_t msgl)
  106. {
  107. int i;
  108. for (i = 0; i < nhwerrmsgs; i++)
  109. if (hwerrs & hwerrmsgs[i].mask)
  110. format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
  111. }
  112. static void signal_ib_event(struct hfi1_pportdata *ppd, enum ib_event_type ev)
  113. {
  114. struct ib_event event;
  115. struct hfi1_devdata *dd = ppd->dd;
  116. /*
  117. * Only call ib_dispatch_event() if the IB device has been
  118. * registered. HFI1_INITED is set iff the driver has successfully
  119. * registered with the IB core.
  120. */
  121. if (!(dd->flags & HFI1_INITTED))
  122. return;
  123. event.device = &dd->verbs_dev.rdi.ibdev;
  124. event.element.port_num = ppd->port;
  125. event.event = ev;
  126. ib_dispatch_event(&event);
  127. }
  128. /**
  129. * handle_linkup_change - finish linkup/down state changes
  130. * @dd: valid device
  131. * @linkup: link state information
  132. *
  133. * Handle a linkup or link down notification.
  134. * The HW needs time to finish its link up state change. Give it that chance.
  135. *
  136. * This is called outside an interrupt.
  137. *
  138. */
  139. void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup)
  140. {
  141. struct hfi1_pportdata *ppd = &dd->pport[0];
  142. enum ib_event_type ev;
  143. if (!(ppd->linkup ^ !!linkup))
  144. return; /* no change, nothing to do */
  145. if (linkup) {
  146. /*
  147. * Quick linkup and all link up on the simulator does not
  148. * trigger or implement:
  149. * - VerifyCap interrupt
  150. * - VerifyCap frames
  151. * But rather moves directly to LinkUp.
  152. *
  153. * Do the work of the VerifyCap interrupt handler,
  154. * handle_verify_cap(), but do not try moving the state to
  155. * LinkUp as we are already there.
  156. *
  157. * NOTE: This uses this device's vAU, vCU, and vl15_init for
  158. * the remote values. Both sides must be using the values.
  159. */
  160. if (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
  161. set_up_vau(dd, dd->vau);
  162. set_up_vl15(dd, dd->vl15_init);
  163. assign_remote_cm_au_table(dd, dd->vcu);
  164. }
  165. ppd->neighbor_guid =
  166. read_csr(dd, DC_DC8051_STS_REMOTE_GUID);
  167. ppd->neighbor_type =
  168. read_csr(dd, DC_DC8051_STS_REMOTE_NODE_TYPE) &
  169. DC_DC8051_STS_REMOTE_NODE_TYPE_VAL_MASK;
  170. ppd->neighbor_port_number =
  171. read_csr(dd, DC_DC8051_STS_REMOTE_PORT_NO) &
  172. DC_DC8051_STS_REMOTE_PORT_NO_VAL_SMASK;
  173. ppd->neighbor_fm_security =
  174. read_csr(dd, DC_DC8051_STS_REMOTE_FM_SECURITY) &
  175. DC_DC8051_STS_LOCAL_FM_SECURITY_DISABLED_MASK;
  176. dd_dev_info(dd,
  177. "Neighbor Guid %llx, Type %d, Port Num %d\n",
  178. ppd->neighbor_guid, ppd->neighbor_type,
  179. ppd->neighbor_port_number);
  180. /* HW needs LINK_UP_DELAY to settle, give it that chance */
  181. udelay(LINK_UP_DELAY);
  182. /*
  183. * 'MgmtAllowed' information, which is exchanged during
  184. * LNI, is available at this point.
  185. */
  186. set_mgmt_allowed(ppd);
  187. if (ppd->mgmt_allowed)
  188. add_full_mgmt_pkey(ppd);
  189. /* physical link went up */
  190. ppd->linkup = 1;
  191. ppd->offline_disabled_reason =
  192. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
  193. /* link widths are not available until the link is fully up */
  194. get_linkup_link_widths(ppd);
  195. } else {
  196. /* physical link went down */
  197. ppd->linkup = 0;
  198. /* clear HW details of the previous connection */
  199. ppd->actual_vls_operational = 0;
  200. reset_link_credits(dd);
  201. /* freeze after a link down to guarantee a clean egress */
  202. start_freeze_handling(ppd, FREEZE_SELF | FREEZE_LINK_DOWN);
  203. ev = IB_EVENT_PORT_ERR;
  204. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LINKDOWN_BIT);
  205. /* if we are down, the neighbor is down */
  206. ppd->neighbor_normal = 0;
  207. /* notify IB of the link change */
  208. signal_ib_event(ppd, ev);
  209. }
  210. }
  211. /*
  212. * Handle receive or urgent interrupts for user contexts. This means a user
  213. * process was waiting for a packet to arrive, and didn't want to poll.
  214. */
  215. void handle_user_interrupt(struct hfi1_ctxtdata *rcd)
  216. {
  217. struct hfi1_devdata *dd = rcd->dd;
  218. unsigned long flags;
  219. spin_lock_irqsave(&dd->uctxt_lock, flags);
  220. if (bitmap_empty(rcd->in_use_ctxts, HFI1_MAX_SHARED_CTXTS))
  221. goto done;
  222. if (test_and_clear_bit(HFI1_CTXT_WAITING_RCV, &rcd->event_flags)) {
  223. wake_up_interruptible(&rcd->wait);
  224. hfi1_rcvctrl(dd, HFI1_RCVCTRL_INTRAVAIL_DIS, rcd);
  225. } else if (test_and_clear_bit(HFI1_CTXT_WAITING_URG,
  226. &rcd->event_flags)) {
  227. rcd->urgent++;
  228. wake_up_interruptible(&rcd->wait);
  229. }
  230. done:
  231. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  232. }