1
2
3
4
5
6#include <linux/pci.h>
7#include <linux/delay.h>
8#include <linux/bitmap.h>
9
10#include "hfi.h"
11#include "common.h"
12#include "sdma.h"
13
14#define LINK_UP_DELAY 500
15
16static void set_mgmt_allowed(struct hfi1_pportdata *ppd)
17{
18 u32 frame;
19 struct hfi1_devdata *dd = ppd->dd;
20
21 if (ppd->neighbor_type == NEIGHBOR_TYPE_HFI) {
22 ppd->mgmt_allowed = 1;
23 } else {
24 read_8051_config(dd, REMOTE_LNI_INFO, GENERAL_CONFIG, &frame);
25 ppd->mgmt_allowed = (frame >> MGMT_ALLOWED_SHIFT)
26 & MGMT_ALLOWED_MASK;
27 }
28}
29
30
31
32
33
34
35
36
37static void add_full_mgmt_pkey(struct hfi1_pportdata *ppd)
38{
39 struct hfi1_devdata *dd = ppd->dd;
40
41
42 if (!((ppd->pkeys[2] == 0) || (ppd->pkeys[2] == FULL_MGMT_P_KEY)))
43 dd_dev_warn(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n",
44 __func__, ppd->pkeys[2], FULL_MGMT_P_KEY);
45 ppd->pkeys[2] = FULL_MGMT_P_KEY;
46 (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
47 hfi1_event_pkey_change(ppd->dd, ppd->port);
48}
49
50
51
52
53
54
55
56static void format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
57{
58 strlcat(msg, "[", msgl);
59 strlcat(msg, hwmsg, msgl);
60 strlcat(msg, "]", msgl);
61}
62
63
64
65
66
67
68
69
70
71void hfi1_format_hwerrors(u64 hwerrs, const struct hfi1_hwerror_msgs *hwerrmsgs,
72 size_t nhwerrmsgs, char *msg, size_t msgl)
73{
74 int i;
75
76 for (i = 0; i < nhwerrmsgs; i++)
77 if (hwerrs & hwerrmsgs[i].mask)
78 format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
79}
80
81static void signal_ib_event(struct hfi1_pportdata *ppd, enum ib_event_type ev)
82{
83 struct ib_event event;
84 struct hfi1_devdata *dd = ppd->dd;
85
86
87
88
89
90
91 if (!(dd->flags & HFI1_INITTED))
92 return;
93 event.device = &dd->verbs_dev.rdi.ibdev;
94 event.element.port_num = ppd->port;
95 event.event = ev;
96 ib_dispatch_event(&event);
97}
98
99
100
101
102
103
104
105
106
107
108
109
110void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup)
111{
112 struct hfi1_pportdata *ppd = &dd->pport[0];
113 enum ib_event_type ev;
114
115 if (!(ppd->linkup ^ !!linkup))
116 return;
117
118 if (linkup) {
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 if (quick_linkup || dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
134 set_up_vau(dd, dd->vau);
135 set_up_vl15(dd, dd->vl15_init);
136 assign_remote_cm_au_table(dd, dd->vcu);
137 }
138
139 ppd->neighbor_guid =
140 read_csr(dd, 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 ppd->neighbor_fm_security =
148 read_csr(dd, DC_DC8051_STS_REMOTE_FM_SECURITY) &
149 DC_DC8051_STS_LOCAL_FM_SECURITY_DISABLED_MASK;
150 dd_dev_info(dd,
151 "Neighbor Guid %llx, Type %d, Port Num %d\n",
152 ppd->neighbor_guid, ppd->neighbor_type,
153 ppd->neighbor_port_number);
154
155
156 udelay(LINK_UP_DELAY);
157
158
159
160
161
162 set_mgmt_allowed(ppd);
163
164 if (ppd->mgmt_allowed)
165 add_full_mgmt_pkey(ppd);
166
167
168 ppd->linkup = 1;
169 ppd->offline_disabled_reason =
170 HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE);
171
172
173 get_linkup_link_widths(ppd);
174
175 } else {
176
177 ppd->linkup = 0;
178
179
180 ppd->actual_vls_operational = 0;
181 reset_link_credits(dd);
182
183
184 start_freeze_handling(ppd, FREEZE_SELF | FREEZE_LINK_DOWN);
185
186 ev = IB_EVENT_PORT_ERR;
187
188 hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LINKDOWN_BIT);
189
190
191 ppd->neighbor_normal = 0;
192
193
194 signal_ib_event(ppd, ev);
195 }
196}
197
198
199
200
201
202void handle_user_interrupt(struct hfi1_ctxtdata *rcd)
203{
204 struct hfi1_devdata *dd = rcd->dd;
205 unsigned long flags;
206
207 spin_lock_irqsave(&dd->uctxt_lock, flags);
208 if (bitmap_empty(rcd->in_use_ctxts, HFI1_MAX_SHARED_CTXTS))
209 goto done;
210
211 if (test_and_clear_bit(HFI1_CTXT_WAITING_RCV, &rcd->event_flags)) {
212 wake_up_interruptible(&rcd->wait);
213 hfi1_rcvctrl(dd, HFI1_RCVCTRL_INTRAVAIL_DIS, rcd);
214 } else if (test_and_clear_bit(HFI1_CTXT_WAITING_URG,
215 &rcd->event_flags)) {
216 rcd->urgent++;
217 wake_up_interruptible(&rcd->wait);
218 }
219done:
220 spin_unlock_irqrestore(&dd->uctxt_lock, flags);
221}
222