These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / staging / rdma / hfi1 / intr.c
1 /*
2  *
3  * This file is provided under a dual BSD/GPLv2 license.  When using or
4  * redistributing this file, you may do so under either license.
5  *
6  * GPL LICENSE SUMMARY
7  *
8  * Copyright(c) 2015 Intel Corporation.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of version 2 of the GNU General Public License as
12  * published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * BSD LICENSE
20  *
21  * Copyright(c) 2015 Intel Corporation.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  *
27  *  - Redistributions of source code must retain the above copyright
28  *    notice, this list of conditions and the following disclaimer.
29  *  - Redistributions in binary form must reproduce the above copyright
30  *    notice, this list of conditions and the following disclaimer in
31  *    the documentation and/or other materials provided with the
32  *    distribution.
33  *  - Neither the name of Intel Corporation nor the names of its
34  *    contributors may be used to endorse or promote products derived
35  *    from this software without specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  *
49  */
50
51 #include <linux/pci.h>
52 #include <linux/delay.h>
53
54 #include "hfi.h"
55 #include "common.h"
56 #include "sdma.h"
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.ibdev;
102         event.element.port_num = ppd->port;
103         event.event = ev;
104         ib_dispatch_event(&event);
105 }
106
107 /*
108  * Handle a linkup or link down notification.
109  * This is called outside an interrupt.
110  */
111 void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup)
112 {
113         struct hfi1_pportdata *ppd = &dd->pport[0];
114         enum ib_event_type ev;
115
116         if (!(ppd->linkup ^ !!linkup))
117                 return; /* no change, nothing to do */
118
119         if (linkup) {
120                 /*
121                  * Quick linkup and all link up on the simulator does not
122                  * trigger or implement:
123                  *      - VerifyCap interrupt
124                  *      - VerifyCap frames
125                  * But rather moves directly to LinkUp.
126                  *
127                  * Do the work of the VerifyCap interrupt handler,
128                  * handle_verify_cap(), but do not try moving the state to
129                  * LinkUp as we are already there.
130                  *
131                  * NOTE: This uses this device's vAU, vCU, and vl15_init for
132                  * the remote values.  Both sides must be using the values.
133                  */
134                 if (quick_linkup
135                             || dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
136                         set_up_vl15(dd, dd->vau, dd->vl15_init);
137                         assign_remote_cm_au_table(dd, dd->vcu);
138                         ppd->neighbor_guid =
139                                 read_csr(dd,
140                                         DC_DC8051_STS_REMOTE_GUID);
141                         ppd->neighbor_type =
142                                 read_csr(dd, DC_DC8051_STS_REMOTE_NODE_TYPE) &
143                                         DC_DC8051_STS_REMOTE_NODE_TYPE_VAL_MASK;
144                         ppd->neighbor_port_number =
145                                 read_csr(dd, DC_DC8051_STS_REMOTE_PORT_NO) &
146                                         DC_DC8051_STS_REMOTE_PORT_NO_VAL_SMASK;
147                         dd_dev_info(dd,
148                                 "Neighbor GUID: %llx Neighbor type %d\n",
149                                 ppd->neighbor_guid,
150                                 ppd->neighbor_type);
151                 }
152
153                 /* physical link went up */
154                 ppd->linkup = 1;
155                 ppd->offline_disabled_reason = OPA_LINKDOWN_REASON_NONE;
156
157                 /* link widths are not available until the link is fully up */
158                 get_linkup_link_widths(ppd);
159
160         } else {
161                 /* physical link went down */
162                 ppd->linkup = 0;
163
164                 /* clear HW details of the previous connection */
165                 reset_link_credits(dd);
166
167                 /* freeze after a link down to guarantee a clean egress */
168                 start_freeze_handling(ppd, FREEZE_SELF|FREEZE_LINK_DOWN);
169
170                 ev = IB_EVENT_PORT_ERR;
171
172                 hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LINKDOWN_BIT);
173
174                 /* if we are down, the neighbor is down */
175                 ppd->neighbor_normal = 0;
176
177                 /* notify IB of the link change */
178                 signal_ib_event(ppd, ev);
179         }
180
181
182 }
183
184 /*
185  * Handle receive or urgent interrupts for user contexts.  This means a user
186  * process was waiting for a packet to arrive, and didn't want to poll.
187  */
188 void handle_user_interrupt(struct hfi1_ctxtdata *rcd)
189 {
190         struct hfi1_devdata *dd = rcd->dd;
191         unsigned long flags;
192
193         spin_lock_irqsave(&dd->uctxt_lock, flags);
194         if (!rcd->cnt)
195                 goto done;
196
197         if (test_and_clear_bit(HFI1_CTXT_WAITING_RCV, &rcd->event_flags)) {
198                 wake_up_interruptible(&rcd->wait);
199                 hfi1_rcvctrl(dd, HFI1_RCVCTRL_INTRAVAIL_DIS, rcd->ctxt);
200         } else if (test_and_clear_bit(HFI1_CTXT_WAITING_URG,
201                                                         &rcd->event_flags)) {
202                 rcd->urgent++;
203                 wake_up_interruptible(&rcd->wait);
204         }
205 done:
206         spin_unlock_irqrestore(&dd->uctxt_lock, flags);
207 }