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