xref: /OK3568_Linux_fs/kernel/drivers/infiniband/hw/hfi1/intr.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright(c) 2015, 2016 Intel Corporation.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This file is provided under a dual BSD/GPLv2 license.  When using or
5*4882a593Smuzhiyun  * redistributing this file, you may do so under either license.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * GPL LICENSE SUMMARY
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun  * it under the terms of version 2 of the GNU General Public License as
11*4882a593Smuzhiyun  * published by the Free Software Foundation.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun  * WITHOUT ANY WARRANTY; without even the implied warranty of
15*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16*4882a593Smuzhiyun  * General Public License for more details.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * BSD LICENSE
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
21*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
22*4882a593Smuzhiyun  * are met:
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  *  - Redistributions of source code must retain the above copyright
25*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer.
26*4882a593Smuzhiyun  *  - Redistributions in binary form must reproduce the above copyright
27*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer in
28*4882a593Smuzhiyun  *    the documentation and/or other materials provided with the
29*4882a593Smuzhiyun  *    distribution.
30*4882a593Smuzhiyun  *  - Neither the name of Intel Corporation nor the names of its
31*4882a593Smuzhiyun  *    contributors may be used to endorse or promote products derived
32*4882a593Smuzhiyun  *    from this software without specific prior written permission.
33*4882a593Smuzhiyun  *
34*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45*4882a593Smuzhiyun  *
46*4882a593Smuzhiyun  */
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #include <linux/pci.h>
49*4882a593Smuzhiyun #include <linux/delay.h>
50*4882a593Smuzhiyun #include <linux/bitmap.h>
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #include "hfi.h"
53*4882a593Smuzhiyun #include "common.h"
54*4882a593Smuzhiyun #include "sdma.h"
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #define LINK_UP_DELAY  500  /* in microseconds */
57*4882a593Smuzhiyun 
set_mgmt_allowed(struct hfi1_pportdata * ppd)58*4882a593Smuzhiyun static void set_mgmt_allowed(struct hfi1_pportdata *ppd)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun 	u32 frame;
61*4882a593Smuzhiyun 	struct hfi1_devdata *dd = ppd->dd;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	if (ppd->neighbor_type == NEIGHBOR_TYPE_HFI) {
64*4882a593Smuzhiyun 		ppd->mgmt_allowed = 1;
65*4882a593Smuzhiyun 	} else {
66*4882a593Smuzhiyun 		read_8051_config(dd, REMOTE_LNI_INFO, GENERAL_CONFIG, &frame);
67*4882a593Smuzhiyun 		ppd->mgmt_allowed = (frame >> MGMT_ALLOWED_SHIFT)
68*4882a593Smuzhiyun 		& MGMT_ALLOWED_MASK;
69*4882a593Smuzhiyun 	}
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /*
73*4882a593Smuzhiyun  * Our neighbor has indicated that we are allowed to act as a fabric
74*4882a593Smuzhiyun  * manager, so place the full management partition key in the second
75*4882a593Smuzhiyun  * (0-based) pkey array position. Note that we should already have
76*4882a593Smuzhiyun  * the limited management partition key in array element 1, and also
77*4882a593Smuzhiyun  * that the port is not yet up when add_full_mgmt_pkey() is invoked.
78*4882a593Smuzhiyun  */
add_full_mgmt_pkey(struct hfi1_pportdata * ppd)79*4882a593Smuzhiyun static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun 	struct hfi1_devdata *dd = ppd->dd;
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	/* Sanity check - ppd->pkeys[2] should be 0, or already initialized */
84*4882a593Smuzhiyun 	if (!((ppd->pkeys[2] == 0) || (ppd->pkeys[2] == FULL_MGMT_P_KEY)))
85*4882a593Smuzhiyun 		dd_dev_warn(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n",
86*4882a593Smuzhiyun 			    __func__, ppd->pkeys[2], FULL_MGMT_P_KEY);
87*4882a593Smuzhiyun 	ppd->pkeys[2] = FULL_MGMT_P_KEY;
88*4882a593Smuzhiyun 	(void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
89*4882a593Smuzhiyun 	hfi1_event_pkey_change(ppd->dd, ppd->port);
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /**
93*4882a593Smuzhiyun  * format_hwmsg - format a single hwerror message
94*4882a593Smuzhiyun  * @msg message buffer
95*4882a593Smuzhiyun  * @msgl length of message buffer
96*4882a593Smuzhiyun  * @hwmsg message to add to message buffer
97*4882a593Smuzhiyun  */
format_hwmsg(char * msg,size_t msgl,const char * hwmsg)98*4882a593Smuzhiyun static void format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
99*4882a593Smuzhiyun {
100*4882a593Smuzhiyun 	strlcat(msg, "[", msgl);
101*4882a593Smuzhiyun 	strlcat(msg, hwmsg, msgl);
102*4882a593Smuzhiyun 	strlcat(msg, "]", msgl);
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /**
106*4882a593Smuzhiyun  * hfi1_format_hwerrors - format hardware error messages for display
107*4882a593Smuzhiyun  * @hwerrs hardware errors bit vector
108*4882a593Smuzhiyun  * @hwerrmsgs hardware error descriptions
109*4882a593Smuzhiyun  * @nhwerrmsgs number of hwerrmsgs
110*4882a593Smuzhiyun  * @msg message buffer
111*4882a593Smuzhiyun  * @msgl message buffer length
112*4882a593Smuzhiyun  */
hfi1_format_hwerrors(u64 hwerrs,const struct hfi1_hwerror_msgs * hwerrmsgs,size_t nhwerrmsgs,char * msg,size_t msgl)113*4882a593Smuzhiyun void hfi1_format_hwerrors(u64 hwerrs, const struct hfi1_hwerror_msgs *hwerrmsgs,
114*4882a593Smuzhiyun 			  size_t nhwerrmsgs, char *msg, size_t msgl)
115*4882a593Smuzhiyun {
116*4882a593Smuzhiyun 	int i;
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun 	for (i = 0; i < nhwerrmsgs; i++)
119*4882a593Smuzhiyun 		if (hwerrs & hwerrmsgs[i].mask)
120*4882a593Smuzhiyun 			format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun 
signal_ib_event(struct hfi1_pportdata * ppd,enum ib_event_type ev)123*4882a593Smuzhiyun static void signal_ib_event(struct hfi1_pportdata *ppd, enum ib_event_type ev)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun 	struct ib_event event;
126*4882a593Smuzhiyun 	struct hfi1_devdata *dd = ppd->dd;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	/*
129*4882a593Smuzhiyun 	 * Only call ib_dispatch_event() if the IB device has been
130*4882a593Smuzhiyun 	 * registered.  HFI1_INITED is set iff the driver has successfully
131*4882a593Smuzhiyun 	 * registered with the IB core.
132*4882a593Smuzhiyun 	 */
133*4882a593Smuzhiyun 	if (!(dd->flags & HFI1_INITTED))
134*4882a593Smuzhiyun 		return;
135*4882a593Smuzhiyun 	event.device = &dd->verbs_dev.rdi.ibdev;
136*4882a593Smuzhiyun 	event.element.port_num = ppd->port;
137*4882a593Smuzhiyun 	event.event = ev;
138*4882a593Smuzhiyun 	ib_dispatch_event(&event);
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun /**
142*4882a593Smuzhiyun  * handle_linkup_change - finish linkup/down state changes
143*4882a593Smuzhiyun  * @dd: valid device
144*4882a593Smuzhiyun  * @linkup: link state information
145*4882a593Smuzhiyun  *
146*4882a593Smuzhiyun  * Handle a linkup or link down notification.
147*4882a593Smuzhiyun  * The HW needs time to finish its link up state change. Give it that chance.
148*4882a593Smuzhiyun  *
149*4882a593Smuzhiyun  * This is called outside an interrupt.
150*4882a593Smuzhiyun  *
151*4882a593Smuzhiyun  */
handle_linkup_change(struct hfi1_devdata * dd,u32 linkup)152*4882a593Smuzhiyun void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup)
153*4882a593Smuzhiyun {
154*4882a593Smuzhiyun 	struct hfi1_pportdata *ppd = &dd->pport[0];
155*4882a593Smuzhiyun 	enum ib_event_type ev;
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	if (!(ppd->linkup ^ !!linkup))
158*4882a593Smuzhiyun 		return;	/* no change, nothing to do */
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun 	if (linkup) {
161*4882a593Smuzhiyun 		/*
162*4882a593Smuzhiyun 		 * Quick linkup and all link up on the simulator does not
163*4882a593Smuzhiyun 		 * trigger or implement:
164*4882a593Smuzhiyun 		 *	- VerifyCap interrupt
165*4882a593Smuzhiyun 		 *	- VerifyCap frames
166*4882a593Smuzhiyun 		 * But rather moves directly to LinkUp.
167*4882a593Smuzhiyun 		 *
168*4882a593Smuzhiyun 		 * Do the work of the VerifyCap interrupt handler,
169*4882a593Smuzhiyun 		 * handle_verify_cap(), but do not try moving the state to
170*4882a593Smuzhiyun 		 * LinkUp as we are already there.
171*4882a593Smuzhiyun 		 *
172*4882a593Smuzhiyun 		 * NOTE: This uses this device's vAU, vCU, and vl15_init for
173*4882a593Smuzhiyun 		 * the remote values.  Both sides must be using the values.
174*4882a593Smuzhiyun 		 */
175*4882a593Smuzhiyun 		if (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
176*4882a593Smuzhiyun 			set_up_vau(dd, dd->vau);
177*4882a593Smuzhiyun 			set_up_vl15(dd, dd->vl15_init);
178*4882a593Smuzhiyun 			assign_remote_cm_au_table(dd, dd->vcu);
179*4882a593Smuzhiyun 		}
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun 		ppd->neighbor_guid =
182*4882a593Smuzhiyun 			read_csr(dd, DC_DC8051_STS_REMOTE_GUID);
183*4882a593Smuzhiyun 		ppd->neighbor_type =
184*4882a593Smuzhiyun 			read_csr(dd, DC_DC8051_STS_REMOTE_NODE_TYPE) &
185*4882a593Smuzhiyun 				 DC_DC8051_STS_REMOTE_NODE_TYPE_VAL_MASK;
186*4882a593Smuzhiyun 		ppd->neighbor_port_number =
187*4882a593Smuzhiyun 			read_csr(dd, DC_DC8051_STS_REMOTE_PORT_NO) &
188*4882a593Smuzhiyun 				 DC_DC8051_STS_REMOTE_PORT_NO_VAL_SMASK;
189*4882a593Smuzhiyun 		ppd->neighbor_fm_security =
190*4882a593Smuzhiyun 			read_csr(dd, DC_DC8051_STS_REMOTE_FM_SECURITY) &
191*4882a593Smuzhiyun 				 DC_DC8051_STS_LOCAL_FM_SECURITY_DISABLED_MASK;
192*4882a593Smuzhiyun 		dd_dev_info(dd,
193*4882a593Smuzhiyun 			    "Neighbor Guid %llx, Type %d, Port Num %d\n",
194*4882a593Smuzhiyun 			    ppd->neighbor_guid, ppd->neighbor_type,
195*4882a593Smuzhiyun 			    ppd->neighbor_port_number);
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun 		/* HW needs LINK_UP_DELAY to settle, give it that chance */
198*4882a593Smuzhiyun 		udelay(LINK_UP_DELAY);
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun 		/*
201*4882a593Smuzhiyun 		 * 'MgmtAllowed' information, which is exchanged during
202*4882a593Smuzhiyun 		 * LNI, is available at this point.
203*4882a593Smuzhiyun 		 */
204*4882a593Smuzhiyun 		set_mgmt_allowed(ppd);
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun 		if (ppd->mgmt_allowed)
207*4882a593Smuzhiyun 			add_full_mgmt_pkey(ppd);
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 		/* physical link went up */
210*4882a593Smuzhiyun 		ppd->linkup = 1;
211*4882a593Smuzhiyun 		ppd->offline_disabled_reason =
212*4882a593Smuzhiyun 			HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun 		/* link widths are not available until the link is fully up */
215*4882a593Smuzhiyun 		get_linkup_link_widths(ppd);
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun 	} else {
218*4882a593Smuzhiyun 		/* physical link went down */
219*4882a593Smuzhiyun 		ppd->linkup = 0;
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun 		/* clear HW details of the previous connection */
222*4882a593Smuzhiyun 		ppd->actual_vls_operational = 0;
223*4882a593Smuzhiyun 		reset_link_credits(dd);
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun 		/* freeze after a link down to guarantee a clean egress */
226*4882a593Smuzhiyun 		start_freeze_handling(ppd, FREEZE_SELF | FREEZE_LINK_DOWN);
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun 		ev = IB_EVENT_PORT_ERR;
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun 		hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LINKDOWN_BIT);
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 		/* if we are down, the neighbor is down */
233*4882a593Smuzhiyun 		ppd->neighbor_normal = 0;
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 		/* notify IB of the link change */
236*4882a593Smuzhiyun 		signal_ib_event(ppd, ev);
237*4882a593Smuzhiyun 	}
238*4882a593Smuzhiyun }
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun /*
241*4882a593Smuzhiyun  * Handle receive or urgent interrupts for user contexts.  This means a user
242*4882a593Smuzhiyun  * process was waiting for a packet to arrive, and didn't want to poll.
243*4882a593Smuzhiyun  */
handle_user_interrupt(struct hfi1_ctxtdata * rcd)244*4882a593Smuzhiyun void handle_user_interrupt(struct hfi1_ctxtdata *rcd)
245*4882a593Smuzhiyun {
246*4882a593Smuzhiyun 	struct hfi1_devdata *dd = rcd->dd;
247*4882a593Smuzhiyun 	unsigned long flags;
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun 	spin_lock_irqsave(&dd->uctxt_lock, flags);
250*4882a593Smuzhiyun 	if (bitmap_empty(rcd->in_use_ctxts, HFI1_MAX_SHARED_CTXTS))
251*4882a593Smuzhiyun 		goto done;
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 	if (test_and_clear_bit(HFI1_CTXT_WAITING_RCV, &rcd->event_flags)) {
254*4882a593Smuzhiyun 		wake_up_interruptible(&rcd->wait);
255*4882a593Smuzhiyun 		hfi1_rcvctrl(dd, HFI1_RCVCTRL_INTRAVAIL_DIS, rcd);
256*4882a593Smuzhiyun 	} else if (test_and_clear_bit(HFI1_CTXT_WAITING_URG,
257*4882a593Smuzhiyun 							&rcd->event_flags)) {
258*4882a593Smuzhiyun 		rcd->urgent++;
259*4882a593Smuzhiyun 		wake_up_interruptible(&rcd->wait);
260*4882a593Smuzhiyun 	}
261*4882a593Smuzhiyun done:
262*4882a593Smuzhiyun 	spin_unlock_irqrestore(&dd->uctxt_lock, flags);
263*4882a593Smuzhiyun }
264