]>
Commit | Line | Data |
---|---|---|
77241056 | 1 | /* |
a74d5307 | 2 | * Copyright(c) 2015-2018 Intel Corporation. |
77241056 MM |
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 | * | |
77241056 MM |
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 | * | |
77241056 MM |
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/spinlock.h> | |
49 | #include <linux/pci.h> | |
50 | #include <linux/io.h> | |
51 | #include <linux/delay.h> | |
52 | #include <linux/netdevice.h> | |
53 | #include <linux/vmalloc.h> | |
54 | #include <linux/module.h> | |
55 | #include <linux/prefetch.h> | |
8859b4a6 | 56 | #include <rdma/ib_verbs.h> |
77241056 MM |
57 | |
58 | #include "hfi.h" | |
59 | #include "trace.h" | |
60 | #include "qp.h" | |
61 | #include "sdma.h" | |
0181ce31 | 62 | #include "debugfs.h" |
d4829ea6 | 63 | #include "vnic.h" |
a74d5307 | 64 | #include "fault.h" |
77241056 MM |
65 | |
66 | #undef pr_fmt | |
67 | #define pr_fmt(fmt) DRIVER_NAME ": " fmt | |
68 | ||
69 | /* | |
70 | * The size has to be longer than this string, so we can append | |
71 | * board/chip information to it in the initialization code. | |
72 | */ | |
73 | const char ib_hfi1_version[] = HFI1_DRIVER_VERSION "\n"; | |
74 | ||
75 | DEFINE_SPINLOCK(hfi1_devs_lock); | |
76 | LIST_HEAD(hfi1_dev_list); | |
77 | DEFINE_MUTEX(hfi1_mutex); /* general driver use */ | |
78 | ||
79 | unsigned int hfi1_max_mtu = HFI1_DEFAULT_MAX_MTU; | |
80 | module_param_named(max_mtu, hfi1_max_mtu, uint, S_IRUGO); | |
ef699e84 SS |
81 | MODULE_PARM_DESC(max_mtu, "Set max MTU bytes, default is " __stringify( |
82 | HFI1_DEFAULT_MAX_MTU)); | |
77241056 MM |
83 | |
84 | unsigned int hfi1_cu = 1; | |
85 | module_param_named(cu, hfi1_cu, uint, S_IRUGO); | |
86 | MODULE_PARM_DESC(cu, "Credit return units"); | |
87 | ||
88 | unsigned long hfi1_cap_mask = HFI1_CAP_MASK_DEFAULT; | |
f4cd8765 MR |
89 | static int hfi1_caps_set(const char *val, const struct kernel_param *kp); |
90 | static int hfi1_caps_get(char *buffer, const struct kernel_param *kp); | |
77241056 MM |
91 | static const struct kernel_param_ops cap_ops = { |
92 | .set = hfi1_caps_set, | |
93 | .get = hfi1_caps_get | |
94 | }; | |
95 | module_param_cb(cap_mask, &cap_ops, &hfi1_cap_mask, S_IWUSR | S_IRUGO); | |
96 | MODULE_PARM_DESC(cap_mask, "Bit mask of enabled/disabled HW features"); | |
97 | ||
98 | MODULE_LICENSE("Dual BSD/GPL"); | |
99 | MODULE_DESCRIPTION("Intel Omni-Path Architecture driver"); | |
77241056 MM |
100 | |
101 | /* | |
102 | * MAX_PKT_RCV is the max # if packets processed per receive interrupt. | |
103 | */ | |
104 | #define MAX_PKT_RECV 64 | |
a82a7fcd MM |
105 | /* |
106 | * MAX_PKT_THREAD_RCV is the max # of packets processed before | |
107 | * the qp_wait_list queue is flushed. | |
108 | */ | |
109 | #define MAX_PKT_RECV_THREAD (MAX_PKT_RECV * 4) | |
77241056 MM |
110 | #define EGR_HEAD_UPDATE_THRESHOLD 16 |
111 | ||
112 | struct hfi1_ib_stats hfi1_stats; | |
113 | ||
114 | static int hfi1_caps_set(const char *val, const struct kernel_param *kp) | |
115 | { | |
116 | int ret = 0; | |
117 | unsigned long *cap_mask_ptr = (unsigned long *)kp->arg, | |
118 | cap_mask = *cap_mask_ptr, value, diff, | |
119 | write_mask = ((HFI1_CAP_WRITABLE_MASK << HFI1_CAP_USER_SHIFT) | | |
120 | HFI1_CAP_WRITABLE_MASK); | |
121 | ||
122 | ret = kstrtoul(val, 0, &value); | |
123 | if (ret) { | |
124 | pr_warn("Invalid module parameter value for 'cap_mask'\n"); | |
125 | goto done; | |
126 | } | |
127 | /* Get the changed bits (except the locked bit) */ | |
128 | diff = value ^ (cap_mask & ~HFI1_CAP_LOCKED_SMASK); | |
129 | ||
130 | /* Remove any bits that are not allowed to change after driver load */ | |
131 | if (HFI1_CAP_LOCKED() && (diff & ~write_mask)) { | |
132 | pr_warn("Ignoring non-writable capability bits %#lx\n", | |
133 | diff & ~write_mask); | |
134 | diff &= write_mask; | |
135 | } | |
136 | ||
137 | /* Mask off any reserved bits */ | |
138 | diff &= ~HFI1_CAP_RESERVED_MASK; | |
139 | /* Clear any previously set and changing bits */ | |
140 | cap_mask &= ~diff; | |
141 | /* Update the bits with the new capability */ | |
142 | cap_mask |= (value & diff); | |
143 | /* Check for any kernel/user restrictions */ | |
144 | diff = (cap_mask & (HFI1_CAP_MUST_HAVE_KERN << HFI1_CAP_USER_SHIFT)) ^ | |
145 | ((cap_mask & HFI1_CAP_MUST_HAVE_KERN) << HFI1_CAP_USER_SHIFT); | |
146 | cap_mask &= ~diff; | |
147 | /* Set the bitmask to the final set */ | |
148 | *cap_mask_ptr = cap_mask; | |
149 | done: | |
150 | return ret; | |
151 | } | |
152 | ||
153 | static int hfi1_caps_get(char *buffer, const struct kernel_param *kp) | |
154 | { | |
155 | unsigned long cap_mask = *(unsigned long *)kp->arg; | |
156 | ||
157 | cap_mask &= ~HFI1_CAP_LOCKED_SMASK; | |
158 | cap_mask |= ((cap_mask & HFI1_CAP_K2U) << HFI1_CAP_USER_SHIFT); | |
159 | ||
160 | return scnprintf(buffer, PAGE_SIZE, "0x%lx", cap_mask); | |
161 | } | |
162 | ||
49dbb6cf DD |
163 | struct pci_dev *get_pci_dev(struct rvt_dev_info *rdi) |
164 | { | |
165 | struct hfi1_ibdev *ibdev = container_of(rdi, struct hfi1_ibdev, rdi); | |
166 | struct hfi1_devdata *dd = container_of(ibdev, | |
167 | struct hfi1_devdata, verbs_dev); | |
168 | return dd->pcidev; | |
169 | } | |
170 | ||
77241056 MM |
171 | /* |
172 | * Return count of units with at least one port ACTIVE. | |
173 | */ | |
174 | int hfi1_count_active_units(void) | |
175 | { | |
176 | struct hfi1_devdata *dd; | |
177 | struct hfi1_pportdata *ppd; | |
178 | unsigned long flags; | |
179 | int pidx, nunits_active = 0; | |
180 | ||
181 | spin_lock_irqsave(&hfi1_devs_lock, flags); | |
182 | list_for_each_entry(dd, &hfi1_dev_list, list) { | |
cb51c5d2 | 183 | if (!(dd->flags & HFI1_PRESENT) || !dd->kregbase1) |
77241056 MM |
184 | continue; |
185 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { | |
186 | ppd = dd->pport + pidx; | |
187 | if (ppd->lid && ppd->linkup) { | |
188 | nunits_active++; | |
189 | break; | |
190 | } | |
191 | } | |
192 | } | |
193 | spin_unlock_irqrestore(&hfi1_devs_lock, flags); | |
194 | return nunits_active; | |
195 | } | |
196 | ||
77241056 MM |
197 | /* |
198 | * Get address of eager buffer from it's index (allocated in chunks, not | |
199 | * contiguous). | |
200 | */ | |
201 | static inline void *get_egrbuf(const struct hfi1_ctxtdata *rcd, u64 rhf, | |
202 | u8 *update) | |
203 | { | |
204 | u32 idx = rhf_egr_index(rhf), offset = rhf_egr_buf_offset(rhf); | |
205 | ||
206 | *update |= !(idx & (rcd->egrbufs.threshold - 1)) && !offset; | |
207 | return (void *)(((u64)(rcd->egrbufs.rcvtids[idx].addr)) + | |
208 | (offset * RCV_BUF_BLOCK_SIZE)); | |
209 | } | |
210 | ||
40442b30 | 211 | static inline void *hfi1_get_header(struct hfi1_ctxtdata *rcd, |
9039746c DH |
212 | __le32 *rhf_addr) |
213 | { | |
214 | u32 offset = rhf_hdrq_offset(rhf_to_cpu(rhf_addr)); | |
215 | ||
40442b30 | 216 | return (void *)(rhf_addr - rcd->rhf_offset + offset); |
9039746c DH |
217 | } |
218 | ||
40442b30 | 219 | static inline struct ib_header *hfi1_get_msgheader(struct hfi1_ctxtdata *rcd, |
9039746c DH |
220 | __le32 *rhf_addr) |
221 | { | |
40442b30 | 222 | return (struct ib_header *)hfi1_get_header(rcd, rhf_addr); |
9039746c DH |
223 | } |
224 | ||
72c07e2b | 225 | static inline struct hfi1_16b_header |
40442b30 | 226 | *hfi1_get_16B_header(struct hfi1_ctxtdata *rcd, |
72c07e2b DH |
227 | __le32 *rhf_addr) |
228 | { | |
40442b30 | 229 | return (struct hfi1_16b_header *)hfi1_get_header(rcd, rhf_addr); |
72c07e2b DH |
230 | } |
231 | ||
77241056 MM |
232 | /* |
233 | * Validate and encode the a given RcvArray Buffer size. | |
234 | * The function will check whether the given size falls within | |
235 | * allowed size ranges for the respective type and, optionally, | |
236 | * return the proper encoding. | |
237 | */ | |
a82a7fcd | 238 | int hfi1_rcvbuf_validate(u32 size, u8 type, u16 *encoded) |
77241056 | 239 | { |
f5389660 | 240 | if (unlikely(!PAGE_ALIGNED(size))) |
77241056 MM |
241 | return 0; |
242 | if (unlikely(size < MIN_EAGER_BUFFER)) | |
243 | return 0; | |
244 | if (size > | |
245 | (type == PT_EAGER ? MAX_EAGER_BUFFER : MAX_EXPECTED_BUFFER)) | |
246 | return 0; | |
247 | if (encoded) | |
248 | *encoded = ilog2(size / PAGE_SIZE) + 1; | |
249 | return 1; | |
250 | } | |
251 | ||
252 | static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd, | |
253 | struct hfi1_packet *packet) | |
254 | { | |
261a4351 | 255 | struct ib_header *rhdr = packet->hdr; |
77241056 | 256 | u32 rte = rhf_rcv_type_err(packet->rhf); |
5786adf3 | 257 | u32 mlid_base; |
f3e862cb | 258 | struct hfi1_ibport *ibp = rcd_to_iport(rcd); |
ec4274f1 | 259 | struct hfi1_devdata *dd = ppd->dd; |
aca7f4fc SS |
260 | struct hfi1_ibdev *verbs_dev = &dd->verbs_dev; |
261 | struct rvt_dev_info *rdi = &verbs_dev->rdi; | |
262 | ||
263 | if ((packet->rhf & RHF_DC_ERR) && | |
264 | hfi1_dbg_fault_suppress_err(verbs_dev)) | |
265 | return; | |
77241056 MM |
266 | |
267 | if (packet->rhf & (RHF_VCRC_ERR | RHF_ICRC_ERR)) | |
268 | return; | |
269 | ||
5786adf3 | 270 | if (packet->etype == RHF_RCV_TYPE_BYPASS) { |
9039746c | 271 | goto drop; |
5786adf3 DH |
272 | } else { |
273 | u8 lnh = ib_get_lnh(rhdr); | |
274 | ||
275 | mlid_base = be16_to_cpu(IB_MULTICAST_LID_BASE); | |
276 | if (lnh == HFI1_LRH_BTH) { | |
277 | packet->ohdr = &rhdr->u.oth; | |
278 | } else if (lnh == HFI1_LRH_GRH) { | |
279 | packet->ohdr = &rhdr->u.l.oth; | |
280 | packet->grh = &rhdr->u.l.grh; | |
281 | } else { | |
282 | goto drop; | |
283 | } | |
9039746c DH |
284 | } |
285 | ||
77241056 MM |
286 | if (packet->rhf & RHF_TID_ERR) { |
287 | /* For TIDERR and RC QPs preemptively schedule a NAK */ | |
77241056 | 288 | u32 tlen = rhf_pkt_len(packet->rhf); /* in bytes */ |
9039746c | 289 | u32 dlid = ib_get_dlid(rhdr); |
77241056 | 290 | u32 qp_num; |
77241056 MM |
291 | |
292 | /* Sanity check packet */ | |
293 | if (tlen < 24) | |
294 | goto drop; | |
295 | ||
296 | /* Check for GRH */ | |
5786adf3 | 297 | if (packet->grh) { |
77241056 | 298 | u32 vtf; |
9039746c | 299 | struct ib_grh *grh = packet->grh; |
77241056 | 300 | |
9039746c | 301 | if (grh->next_hdr != IB_GRH_NEXT_HDR) |
77241056 | 302 | goto drop; |
9039746c | 303 | vtf = be32_to_cpu(grh->version_tclass_flow); |
77241056 MM |
304 | if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION) |
305 | goto drop; | |
e490974e | 306 | } |
9039746c | 307 | |
77241056 | 308 | /* Get the destination QP number. */ |
9039746c DH |
309 | qp_num = ib_bth_get_qpn(packet->ohdr); |
310 | if (dlid < mlid_base) { | |
895420dd | 311 | struct rvt_qp *qp; |
b77d713a | 312 | unsigned long flags; |
77241056 MM |
313 | |
314 | rcu_read_lock(); | |
ec4274f1 | 315 | qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num); |
77241056 MM |
316 | if (!qp) { |
317 | rcu_read_unlock(); | |
318 | goto drop; | |
319 | } | |
320 | ||
321 | /* | |
322 | * Handle only RC QPs - for other QP types drop error | |
323 | * packet. | |
324 | */ | |
b77d713a | 325 | spin_lock_irqsave(&qp->r_lock, flags); |
77241056 MM |
326 | |
327 | /* Check for valid receive state. */ | |
83693bd1 DD |
328 | if (!(ib_rvt_state_ops[qp->state] & |
329 | RVT_PROCESS_RECV_OK)) { | |
4eb06882 | 330 | ibp->rvp.n_pkt_drops++; |
77241056 MM |
331 | } |
332 | ||
333 | switch (qp->ibqp.qp_type) { | |
334 | case IB_QPT_RC: | |
9039746c | 335 | hfi1_rc_hdrerr(rcd, packet, qp); |
77241056 MM |
336 | break; |
337 | default: | |
338 | /* For now don't handle any other QP types */ | |
339 | break; | |
340 | } | |
341 | ||
b77d713a | 342 | spin_unlock_irqrestore(&qp->r_lock, flags); |
77241056 MM |
343 | rcu_read_unlock(); |
344 | } /* Unicast QP */ | |
345 | } /* Valid packet with TIDErr */ | |
346 | ||
347 | /* handle "RcvTypeErr" flags */ | |
348 | switch (rte) { | |
349 | case RHF_RTE_ERROR_OP_CODE_ERR: | |
350 | { | |
77241056 | 351 | void *ebuf = NULL; |
9039746c | 352 | u8 opcode; |
77241056 MM |
353 | |
354 | if (rhf_use_egr_bfr(packet->rhf)) | |
355 | ebuf = packet->ebuf; | |
356 | ||
d125a6c6 | 357 | if (!ebuf) |
77241056 MM |
358 | goto drop; /* this should never happen */ |
359 | ||
9039746c | 360 | opcode = ib_bth_get_opcode(packet->ohdr); |
77241056 MM |
361 | if (opcode == IB_OPCODE_CNP) { |
362 | /* | |
363 | * Only in pre-B0 h/w is the CNP_OPCODE handled | |
80e4898e | 364 | * via this code path. |
77241056 | 365 | */ |
895420dd | 366 | struct rvt_qp *qp = NULL; |
77241056 MM |
367 | u32 lqpn, rqpn; |
368 | u16 rlid; | |
369 | u8 svc_type, sl, sc5; | |
370 | ||
aad559c2 | 371 | sc5 = hfi1_9B_get_sc5(rhdr, packet->rhf); |
77241056 MM |
372 | sl = ibp->sc_to_sl[sc5]; |
373 | ||
9039746c | 374 | lqpn = ib_bth_get_qpn(packet->ohdr); |
77241056 | 375 | rcu_read_lock(); |
ec4274f1 | 376 | qp = rvt_lookup_qpn(rdi, &ibp->rvp, lqpn); |
d125a6c6 | 377 | if (!qp) { |
77241056 MM |
378 | rcu_read_unlock(); |
379 | goto drop; | |
380 | } | |
381 | ||
382 | switch (qp->ibqp.qp_type) { | |
383 | case IB_QPT_UD: | |
384 | rlid = 0; | |
385 | rqpn = 0; | |
386 | svc_type = IB_CC_SVCTYPE_UD; | |
387 | break; | |
388 | case IB_QPT_UC: | |
cb427057 | 389 | rlid = ib_get_slid(rhdr); |
77241056 MM |
390 | rqpn = qp->remote_qpn; |
391 | svc_type = IB_CC_SVCTYPE_UC; | |
392 | break; | |
393 | default: | |
41904439 | 394 | rcu_read_unlock(); |
77241056 MM |
395 | goto drop; |
396 | } | |
397 | ||
398 | process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type); | |
399 | rcu_read_unlock(); | |
400 | } | |
401 | ||
402 | packet->rhf &= ~RHF_RCV_TYPE_ERR_SMASK; | |
403 | break; | |
404 | } | |
405 | default: | |
406 | break; | |
407 | } | |
408 | ||
409 | drop: | |
410 | return; | |
411 | } | |
412 | ||
413 | static inline void init_packet(struct hfi1_ctxtdata *rcd, | |
17fb4f29 | 414 | struct hfi1_packet *packet) |
77241056 | 415 | { |
77241056 MM |
416 | packet->rsize = rcd->rcvhdrqentsize; /* words */ |
417 | packet->maxcnt = rcd->rcvhdrq_cnt * packet->rsize; /* words */ | |
418 | packet->rcd = rcd; | |
419 | packet->updegr = 0; | |
420 | packet->etail = -1; | |
f4f30031 | 421 | packet->rhf_addr = get_rhf_addr(rcd); |
77241056 MM |
422 | packet->rhf = rhf_to_cpu(packet->rhf_addr); |
423 | packet->rhqoff = rcd->head; | |
424 | packet->numpkt = 0; | |
77241056 MM |
425 | } |
426 | ||
e2fdbc23 BVA |
427 | /* We support only two types - 9B and 16B for now */ |
428 | static const hfi1_handle_cnp hfi1_handle_cnp_tbl[2] = { | |
429 | [HFI1_PKT_TYPE_9B] = &return_cnp, | |
430 | [HFI1_PKT_TYPE_16B] = &return_cnp_16B | |
431 | }; | |
432 | ||
fe4dd423 MH |
433 | /** |
434 | * hfi1_process_ecn_slowpath - Process FECN or BECN bits | |
435 | * @qp: The packet's destination QP | |
436 | * @pkt: The packet itself. | |
437 | * @prescan: Is the caller the RXQ prescan | |
438 | * | |
439 | * Process the packet's FECN or BECN bits. By now, the packet | |
440 | * has already been evaluated whether processing of those bit should | |
441 | * be done. | |
442 | * The significance of the @prescan argument is that if the caller | |
443 | * is the RXQ prescan, a CNP will be send out instead of waiting for the | |
444 | * normal packet processing to send an ACK with BECN set (or a CNP). | |
445 | */ | |
446 | bool hfi1_process_ecn_slowpath(struct rvt_qp *qp, struct hfi1_packet *pkt, | |
447 | bool prescan) | |
77241056 MM |
448 | { |
449 | struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); | |
f59fb9e0 | 450 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); |
261a4351 | 451 | struct ib_other_headers *ohdr = pkt->ohdr; |
9039746c | 452 | struct ib_grh *grh = pkt->grh; |
fe4dd423 | 453 | u32 rqpn = 0; |
f59fb9e0 MM |
454 | u16 pkey; |
455 | u32 rlid, slid, dlid = 0; | |
fe4dd423 MH |
456 | u8 hdr_type, sc, svc_type, opcode; |
457 | bool is_mcast = false, ignore_fecn = false, do_cnp = false, | |
458 | fecn, becn; | |
5fd2b562 | 459 | |
f59fb9e0 | 460 | /* can be called from prescan */ |
88733e3b | 461 | if (pkt->etype == RHF_RCV_TYPE_BYPASS) { |
88733e3b DH |
462 | pkey = hfi1_16B_get_pkey(pkt->hdr); |
463 | sc = hfi1_16B_get_sc(pkt->hdr); | |
f59fb9e0 MM |
464 | dlid = hfi1_16B_get_dlid(pkt->hdr); |
465 | slid = hfi1_16B_get_slid(pkt->hdr); | |
fe4dd423 MH |
466 | is_mcast = hfi1_is_16B_mcast(dlid); |
467 | opcode = ib_bth_get_opcode(ohdr); | |
88733e3b | 468 | hdr_type = HFI1_PKT_TYPE_16B; |
fe4dd423 MH |
469 | fecn = hfi1_16B_get_fecn(pkt->hdr); |
470 | becn = hfi1_16B_get_becn(pkt->hdr); | |
88733e3b | 471 | } else { |
88733e3b DH |
472 | pkey = ib_bth_get_pkey(ohdr); |
473 | sc = hfi1_9B_get_sc5(pkt->hdr, pkt->rhf); | |
fe4dd423 MH |
474 | dlid = qp->ibqp.qp_type != IB_QPT_UD ? ib_get_dlid(pkt->hdr) : |
475 | ppd->lid; | |
f59fb9e0 | 476 | slid = ib_get_slid(pkt->hdr); |
fe4dd423 MH |
477 | is_mcast = (dlid > be16_to_cpu(IB_MULTICAST_LID_BASE)) && |
478 | (dlid != be16_to_cpu(IB_LID_PERMISSIVE)); | |
479 | opcode = ib_bth_get_opcode(ohdr); | |
88733e3b | 480 | hdr_type = HFI1_PKT_TYPE_9B; |
fe4dd423 MH |
481 | fecn = ib_bth_get_fecn(ohdr); |
482 | becn = ib_bth_get_becn(ohdr); | |
88733e3b DH |
483 | } |
484 | ||
77241056 | 485 | switch (qp->ibqp.qp_type) { |
f59fb9e0 | 486 | case IB_QPT_UD: |
f59fb9e0 MM |
487 | rlid = slid; |
488 | rqpn = ib_get_sqpn(pkt->ohdr); | |
489 | svc_type = IB_CC_SVCTYPE_UD; | |
490 | break; | |
977940b8 AK |
491 | case IB_QPT_SMI: |
492 | case IB_QPT_GSI: | |
f59fb9e0 | 493 | rlid = slid; |
88733e3b | 494 | rqpn = ib_get_sqpn(pkt->ohdr); |
77241056 MM |
495 | svc_type = IB_CC_SVCTYPE_UD; |
496 | break; | |
977940b8 | 497 | case IB_QPT_UC: |
d8966fcd | 498 | rlid = rdma_ah_get_dlid(&qp->remote_ah_attr); |
977940b8 AK |
499 | rqpn = qp->remote_qpn; |
500 | svc_type = IB_CC_SVCTYPE_UC; | |
501 | break; | |
502 | case IB_QPT_RC: | |
d8966fcd | 503 | rlid = rdma_ah_get_dlid(&qp->remote_ah_attr); |
977940b8 AK |
504 | rqpn = qp->remote_qpn; |
505 | svc_type = IB_CC_SVCTYPE_RC; | |
506 | break; | |
77241056 | 507 | default: |
fe4dd423 | 508 | return false; |
77241056 MM |
509 | } |
510 | ||
fe4dd423 MH |
511 | ignore_fecn = is_mcast || (opcode == IB_OPCODE_CNP) || |
512 | (opcode == IB_OPCODE_RC_ACKNOWLEDGE); | |
513 | /* | |
514 | * ACKNOWLEDGE packets do not get a CNP but this will be | |
515 | * guarded by ignore_fecn above. | |
516 | */ | |
517 | do_cnp = prescan || | |
518 | (opcode >= IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST && | |
519 | opcode <= IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE); | |
520 | ||
88733e3b | 521 | /* Call appropriate CNP handler */ |
fe4dd423 | 522 | if (!ignore_fecn && do_cnp && fecn) |
88733e3b DH |
523 | hfi1_handle_cnp_tbl[hdr_type](ibp, qp, rqpn, pkey, |
524 | dlid, rlid, sc, grh); | |
77241056 | 525 | |
fe4dd423 MH |
526 | if (becn) { |
527 | u32 lqpn = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK; | |
5fd2b562 | 528 | u8 sl = ibp->sc_to_sl[sc]; |
77241056 | 529 | |
977940b8 | 530 | process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type); |
77241056 | 531 | } |
fe4dd423 | 532 | return !ignore_fecn && fecn; |
77241056 MM |
533 | } |
534 | ||
535 | struct ps_mdata { | |
536 | struct hfi1_ctxtdata *rcd; | |
537 | u32 rsize; | |
538 | u32 maxcnt; | |
539 | u32 ps_head; | |
540 | u32 ps_tail; | |
541 | u32 ps_seq; | |
542 | }; | |
543 | ||
544 | static inline void init_ps_mdata(struct ps_mdata *mdata, | |
545 | struct hfi1_packet *packet) | |
546 | { | |
547 | struct hfi1_ctxtdata *rcd = packet->rcd; | |
548 | ||
549 | mdata->rcd = rcd; | |
550 | mdata->rsize = packet->rsize; | |
551 | mdata->maxcnt = packet->maxcnt; | |
3e7ccca0 | 552 | mdata->ps_head = packet->rhqoff; |
77241056 | 553 | |
82c2611d | 554 | if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) { |
3e7ccca0 | 555 | mdata->ps_tail = get_rcvhdrtail(rcd); |
82c2611d NV |
556 | if (rcd->ctxt == HFI1_CTRL_CTXT) |
557 | mdata->ps_seq = rcd->seq_cnt; | |
558 | else | |
559 | mdata->ps_seq = 0; /* not used with DMA_RTAIL */ | |
77241056 MM |
560 | } else { |
561 | mdata->ps_tail = 0; /* used only with DMA_RTAIL*/ | |
562 | mdata->ps_seq = rcd->seq_cnt; | |
563 | } | |
564 | } | |
565 | ||
82c2611d NV |
566 | static inline int ps_done(struct ps_mdata *mdata, u64 rhf, |
567 | struct hfi1_ctxtdata *rcd) | |
77241056 | 568 | { |
82c2611d | 569 | if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) |
77241056 MM |
570 | return mdata->ps_head == mdata->ps_tail; |
571 | return mdata->ps_seq != rhf_rcv_seq(rhf); | |
572 | } | |
573 | ||
82c2611d NV |
574 | static inline int ps_skip(struct ps_mdata *mdata, u64 rhf, |
575 | struct hfi1_ctxtdata *rcd) | |
576 | { | |
577 | /* | |
578 | * Control context can potentially receive an invalid rhf. | |
579 | * Drop such packets. | |
580 | */ | |
581 | if ((rcd->ctxt == HFI1_CTRL_CTXT) && (mdata->ps_head != mdata->ps_tail)) | |
582 | return mdata->ps_seq != rhf_rcv_seq(rhf); | |
583 | ||
584 | return 0; | |
585 | } | |
586 | ||
587 | static inline void update_ps_mdata(struct ps_mdata *mdata, | |
588 | struct hfi1_ctxtdata *rcd) | |
77241056 | 589 | { |
77241056 | 590 | mdata->ps_head += mdata->rsize; |
3e7ccca0 | 591 | if (mdata->ps_head >= mdata->maxcnt) |
77241056 | 592 | mdata->ps_head = 0; |
82c2611d NV |
593 | |
594 | /* Control context must do seq counting */ | |
595 | if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) || | |
596 | (rcd->ctxt == HFI1_CTRL_CTXT)) { | |
77241056 MM |
597 | if (++mdata->ps_seq > 13) |
598 | mdata->ps_seq = 1; | |
599 | } | |
600 | } | |
601 | ||
602 | /* | |
603 | * prescan_rxq - search through the receive queue looking for packets | |
604 | * containing Excplicit Congestion Notifications (FECNs, or BECNs). | |
605 | * When an ECN is found, process the Congestion Notification, and toggle | |
606 | * it off. | |
6c9e50f8 VM |
607 | * This is declared as a macro to allow quick checking of the port to avoid |
608 | * the overhead of a function call if not enabled. | |
77241056 | 609 | */ |
6c9e50f8 VM |
610 | #define prescan_rxq(rcd, packet) \ |
611 | do { \ | |
612 | if (rcd->ppd->cc_prescan) \ | |
613 | __prescan_rxq(packet); \ | |
614 | } while (0) | |
615 | static void __prescan_rxq(struct hfi1_packet *packet) | |
77241056 MM |
616 | { |
617 | struct hfi1_ctxtdata *rcd = packet->rcd; | |
618 | struct ps_mdata mdata; | |
619 | ||
77241056 MM |
620 | init_ps_mdata(&mdata, packet); |
621 | ||
622 | while (1) { | |
f3e862cb | 623 | struct hfi1_ibport *ibp = rcd_to_iport(rcd); |
50e5dcbe | 624 | __le32 *rhf_addr = (__le32 *)rcd->rcvhdrq + mdata.ps_head + |
40442b30 | 625 | packet->rcd->rhf_offset; |
895420dd | 626 | struct rvt_qp *qp; |
261a4351 | 627 | struct ib_header *hdr; |
40442b30 | 628 | struct rvt_dev_info *rdi = &rcd->dd->verbs_dev.rdi; |
77241056 | 629 | u64 rhf = rhf_to_cpu(rhf_addr); |
977940b8 | 630 | u32 etype = rhf_rcv_type(rhf), qpn, bth1; |
77241056 MM |
631 | u8 lnh; |
632 | ||
82c2611d | 633 | if (ps_done(&mdata, rhf, rcd)) |
77241056 MM |
634 | break; |
635 | ||
82c2611d NV |
636 | if (ps_skip(&mdata, rhf, rcd)) |
637 | goto next; | |
638 | ||
77241056 MM |
639 | if (etype != RHF_RCV_TYPE_IB) |
640 | goto next; | |
641 | ||
40442b30 | 642 | packet->hdr = hfi1_get_msgheader(packet->rcd, rhf_addr); |
f2d8a0b3 | 643 | hdr = packet->hdr; |
cb427057 | 644 | lnh = ib_get_lnh(hdr); |
77241056 | 645 | |
f2d8a0b3 DC |
646 | if (lnh == HFI1_LRH_BTH) { |
647 | packet->ohdr = &hdr->u.oth; | |
9039746c | 648 | packet->grh = NULL; |
f2d8a0b3 DC |
649 | } else if (lnh == HFI1_LRH_GRH) { |
650 | packet->ohdr = &hdr->u.l.oth; | |
9039746c | 651 | packet->grh = &hdr->u.l.grh; |
f2d8a0b3 | 652 | } else { |
77241056 | 653 | goto next; /* just in case */ |
f2d8a0b3 | 654 | } |
5fd2b562 | 655 | |
fe4dd423 | 656 | if (!hfi1_may_ecn(packet)) |
77241056 MM |
657 | goto next; |
658 | ||
fe4dd423 | 659 | bth1 = be32_to_cpu(packet->ohdr->bth[1]); |
ec4274f1 | 660 | qpn = bth1 & RVT_QPN_MASK; |
77241056 | 661 | rcu_read_lock(); |
ec4274f1 | 662 | qp = rvt_lookup_qpn(rdi, &ibp->rvp, qpn); |
77241056 | 663 | |
d125a6c6 | 664 | if (!qp) { |
77241056 MM |
665 | rcu_read_unlock(); |
666 | goto next; | |
667 | } | |
668 | ||
fe4dd423 | 669 | hfi1_process_ecn_slowpath(qp, packet, true); |
77241056 | 670 | rcu_read_unlock(); |
977940b8 AK |
671 | |
672 | /* turn off BECN, FECN */ | |
3d591099 | 673 | bth1 &= ~(IB_FECN_SMASK | IB_BECN_SMASK); |
f2d8a0b3 | 674 | packet->ohdr->bth[1] = cpu_to_be32(bth1); |
77241056 | 675 | next: |
82c2611d | 676 | update_ps_mdata(&mdata, rcd); |
77241056 MM |
677 | } |
678 | } | |
82c2611d | 679 | |
bdaf96f6 | 680 | static void process_rcv_qp_work(struct hfi1_packet *packet) |
a82a7fcd MM |
681 | { |
682 | struct rvt_qp *qp, *nqp; | |
bdaf96f6 | 683 | struct hfi1_ctxtdata *rcd = packet->rcd; |
a82a7fcd MM |
684 | |
685 | /* | |
686 | * Iterate over all QPs waiting to respond. | |
687 | * The list won't change since the IRQ is only run on one CPU. | |
688 | */ | |
689 | list_for_each_entry_safe(qp, nqp, &rcd->qp_wait_list, rspwait) { | |
690 | list_del_init(&qp->rspwait); | |
691 | if (qp->r_flags & RVT_R_RSP_NAK) { | |
692 | qp->r_flags &= ~RVT_R_RSP_NAK; | |
bdaf96f6 SS |
693 | packet->qp = qp; |
694 | hfi1_send_rc_ack(packet, 0); | |
a82a7fcd MM |
695 | } |
696 | if (qp->r_flags & RVT_R_RSP_SEND) { | |
697 | unsigned long flags; | |
698 | ||
699 | qp->r_flags &= ~RVT_R_RSP_SEND; | |
700 | spin_lock_irqsave(&qp->s_lock, flags); | |
701 | if (ib_rvt_state_ops[qp->state] & | |
702 | RVT_PROCESS_OR_FLUSH_SEND) | |
703 | hfi1_schedule_send(qp); | |
704 | spin_unlock_irqrestore(&qp->s_lock, flags); | |
705 | } | |
706 | rvt_put_qp(qp); | |
707 | } | |
708 | } | |
709 | ||
710 | static noinline int max_packet_exceeded(struct hfi1_packet *packet, int thread) | |
711 | { | |
712 | if (thread) { | |
713 | if ((packet->numpkt & (MAX_PKT_RECV_THREAD - 1)) == 0) | |
714 | /* allow defered processing */ | |
bdaf96f6 | 715 | process_rcv_qp_work(packet); |
a82a7fcd MM |
716 | cond_resched(); |
717 | return RCV_PKT_OK; | |
718 | } else { | |
719 | this_cpu_inc(*packet->rcd->dd->rcv_limit); | |
720 | return RCV_PKT_LIMIT; | |
721 | } | |
722 | } | |
723 | ||
724 | static inline int check_max_packet(struct hfi1_packet *packet, int thread) | |
82c2611d NV |
725 | { |
726 | int ret = RCV_PKT_OK; | |
727 | ||
a82a7fcd MM |
728 | if (unlikely((packet->numpkt & (MAX_PKT_RECV - 1)) == 0)) |
729 | ret = max_packet_exceeded(packet, thread); | |
730 | return ret; | |
731 | } | |
732 | ||
733 | static noinline int skip_rcv_packet(struct hfi1_packet *packet, int thread) | |
734 | { | |
735 | int ret; | |
736 | ||
82c2611d NV |
737 | /* Set up for the next packet */ |
738 | packet->rhqoff += packet->rsize; | |
739 | if (packet->rhqoff >= packet->maxcnt) | |
740 | packet->rhqoff = 0; | |
741 | ||
742 | packet->numpkt++; | |
a82a7fcd | 743 | ret = check_max_packet(packet, thread); |
82c2611d NV |
744 | |
745 | packet->rhf_addr = (__le32 *)packet->rcd->rcvhdrq + packet->rhqoff + | |
40442b30 | 746 | packet->rcd->rhf_offset; |
82c2611d NV |
747 | packet->rhf = rhf_to_cpu(packet->rhf_addr); |
748 | ||
749 | return ret; | |
750 | } | |
77241056 | 751 | |
f4f30031 | 752 | static inline int process_rcv_packet(struct hfi1_packet *packet, int thread) |
77241056 | 753 | { |
a82a7fcd | 754 | int ret; |
77241056 | 755 | |
77241056 | 756 | packet->etype = rhf_rcv_type(packet->rhf); |
9039746c | 757 | |
77241056 MM |
758 | /* total length */ |
759 | packet->tlen = rhf_pkt_len(packet->rhf); /* in bytes */ | |
760 | /* retrieve eager buffer details */ | |
761 | packet->ebuf = NULL; | |
762 | if (rhf_use_egr_bfr(packet->rhf)) { | |
763 | packet->etail = rhf_egr_index(packet->rhf); | |
764 | packet->ebuf = get_egrbuf(packet->rcd, packet->rhf, | |
765 | &packet->updegr); | |
766 | /* | |
767 | * Prefetch the contents of the eager buffer. It is | |
768 | * OK to send a negative length to prefetch_range(). | |
769 | * The +2 is the size of the RHF. | |
770 | */ | |
771 | prefetch_range(packet->ebuf, | |
17fb4f29 JJ |
772 | packet->tlen - ((packet->rcd->rcvhdrqentsize - |
773 | (rhf_hdrq_offset(packet->rhf) | |
774 | + 2)) * 4)); | |
77241056 MM |
775 | } |
776 | ||
777 | /* | |
778 | * Call a type specific handler for the packet. We | |
779 | * should be able to trust that etype won't be beyond | |
780 | * the range of valid indexes. If so something is really | |
781 | * wrong and we can probably just let things come | |
782 | * crashing down. There is no need to eat another | |
783 | * comparison in this performance critical code. | |
784 | */ | |
b0ba3c18 | 785 | packet->rcd->rhf_rcv_function_map[packet->etype](packet); |
77241056 MM |
786 | packet->numpkt++; |
787 | ||
788 | /* Set up for the next packet */ | |
789 | packet->rhqoff += packet->rsize; | |
790 | if (packet->rhqoff >= packet->maxcnt) | |
791 | packet->rhqoff = 0; | |
792 | ||
a82a7fcd | 793 | ret = check_max_packet(packet, thread); |
77241056 | 794 | |
50e5dcbe | 795 | packet->rhf_addr = (__le32 *)packet->rcd->rcvhdrq + packet->rhqoff + |
40442b30 | 796 | packet->rcd->rhf_offset; |
77241056 MM |
797 | packet->rhf = rhf_to_cpu(packet->rhf_addr); |
798 | ||
799 | return ret; | |
800 | } | |
801 | ||
802 | static inline void process_rcv_update(int last, struct hfi1_packet *packet) | |
803 | { | |
804 | /* | |
805 | * Update head regs etc., every 16 packets, if not last pkt, | |
806 | * to help prevent rcvhdrq overflows, when many packets | |
807 | * are processed and queue is nearly full. | |
808 | * Don't request an interrupt for intermediate updates. | |
809 | */ | |
810 | if (!last && !(packet->numpkt & 0xf)) { | |
811 | update_usrhead(packet->rcd, packet->rhqoff, packet->updegr, | |
812 | packet->etail, 0, 0); | |
813 | packet->updegr = 0; | |
814 | } | |
9039746c | 815 | packet->grh = NULL; |
77241056 MM |
816 | } |
817 | ||
818 | static inline void finish_packet(struct hfi1_packet *packet) | |
819 | { | |
77241056 MM |
820 | /* |
821 | * Nothing we need to free for the packet. | |
822 | * | |
823 | * The only thing we need to do is a final update and call for an | |
824 | * interrupt | |
825 | */ | |
826 | update_usrhead(packet->rcd, packet->rcd->head, packet->updegr, | |
827 | packet->etail, rcv_intr_dynamic, packet->numpkt); | |
77241056 MM |
828 | } |
829 | ||
77241056 MM |
830 | /* |
831 | * Handle receive interrupts when using the no dma rtail option. | |
832 | */ | |
f4f30031 | 833 | int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread) |
77241056 MM |
834 | { |
835 | u32 seq; | |
f4f30031 | 836 | int last = RCV_PKT_OK; |
77241056 MM |
837 | struct hfi1_packet packet; |
838 | ||
839 | init_packet(rcd, &packet); | |
840 | seq = rhf_rcv_seq(packet.rhf); | |
f4f30031 DL |
841 | if (seq != rcd->seq_cnt) { |
842 | last = RCV_PKT_DONE; | |
77241056 | 843 | goto bail; |
f4f30031 | 844 | } |
77241056 | 845 | |
6c9e50f8 | 846 | prescan_rxq(rcd, &packet); |
77241056 | 847 | |
f4f30031 DL |
848 | while (last == RCV_PKT_OK) { |
849 | last = process_rcv_packet(&packet, thread); | |
77241056 MM |
850 | seq = rhf_rcv_seq(packet.rhf); |
851 | if (++rcd->seq_cnt > 13) | |
852 | rcd->seq_cnt = 1; | |
853 | if (seq != rcd->seq_cnt) | |
f4f30031 | 854 | last = RCV_PKT_DONE; |
77241056 MM |
855 | process_rcv_update(last, &packet); |
856 | } | |
bdaf96f6 | 857 | process_rcv_qp_work(&packet); |
a82a7fcd | 858 | rcd->head = packet.rhqoff; |
77241056 MM |
859 | bail: |
860 | finish_packet(&packet); | |
f4f30031 | 861 | return last; |
77241056 MM |
862 | } |
863 | ||
f4f30031 | 864 | int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd, int thread) |
77241056 MM |
865 | { |
866 | u32 hdrqtail; | |
f4f30031 | 867 | int last = RCV_PKT_OK; |
77241056 MM |
868 | struct hfi1_packet packet; |
869 | ||
870 | init_packet(rcd, &packet); | |
871 | hdrqtail = get_rcvhdrtail(rcd); | |
f4f30031 DL |
872 | if (packet.rhqoff == hdrqtail) { |
873 | last = RCV_PKT_DONE; | |
77241056 | 874 | goto bail; |
f4f30031 | 875 | } |
77241056 MM |
876 | smp_rmb(); /* prevent speculative reads of dma'ed hdrq */ |
877 | ||
6c9e50f8 | 878 | prescan_rxq(rcd, &packet); |
77241056 | 879 | |
f4f30031 DL |
880 | while (last == RCV_PKT_OK) { |
881 | last = process_rcv_packet(&packet, thread); | |
77241056 | 882 | if (packet.rhqoff == hdrqtail) |
f4f30031 | 883 | last = RCV_PKT_DONE; |
77241056 MM |
884 | process_rcv_update(last, &packet); |
885 | } | |
bdaf96f6 | 886 | process_rcv_qp_work(&packet); |
a82a7fcd | 887 | rcd->head = packet.rhqoff; |
77241056 MM |
888 | bail: |
889 | finish_packet(&packet); | |
f4f30031 | 890 | return last; |
77241056 MM |
891 | } |
892 | ||
e6f7622d | 893 | static inline void set_nodma_rtail(struct hfi1_devdata *dd, u16 ctxt) |
77241056 | 894 | { |
d295dbeb | 895 | struct hfi1_ctxtdata *rcd; |
e6f7622d | 896 | u16 i; |
77241056 | 897 | |
2280740f VN |
898 | /* |
899 | * For dynamically allocated kernel contexts (like vnic) switch | |
900 | * interrupt handler only for that context. Otherwise, switch | |
901 | * interrupt handler for all statically allocated kernel contexts. | |
902 | */ | |
903 | if (ctxt >= dd->first_dyn_alloc_ctxt) { | |
d59075ad | 904 | rcd = hfi1_rcd_get_by_index_safe(dd, ctxt); |
d295dbeb MR |
905 | if (rcd) { |
906 | rcd->do_interrupt = | |
907 | &handle_receive_interrupt_nodma_rtail; | |
908 | hfi1_rcd_put(rcd); | |
909 | } | |
2280740f VN |
910 | return; |
911 | } | |
912 | ||
d295dbeb MR |
913 | for (i = HFI1_CTRL_CTXT + 1; i < dd->first_dyn_alloc_ctxt; i++) { |
914 | rcd = hfi1_rcd_get_by_index(dd, i); | |
915 | if (rcd) | |
916 | rcd->do_interrupt = | |
917 | &handle_receive_interrupt_nodma_rtail; | |
918 | hfi1_rcd_put(rcd); | |
919 | } | |
77241056 MM |
920 | } |
921 | ||
e6f7622d | 922 | static inline void set_dma_rtail(struct hfi1_devdata *dd, u16 ctxt) |
77241056 | 923 | { |
d295dbeb | 924 | struct hfi1_ctxtdata *rcd; |
e6f7622d | 925 | u16 i; |
77241056 | 926 | |
2280740f VN |
927 | /* |
928 | * For dynamically allocated kernel contexts (like vnic) switch | |
929 | * interrupt handler only for that context. Otherwise, switch | |
930 | * interrupt handler for all statically allocated kernel contexts. | |
931 | */ | |
932 | if (ctxt >= dd->first_dyn_alloc_ctxt) { | |
d59075ad | 933 | rcd = hfi1_rcd_get_by_index_safe(dd, ctxt); |
d295dbeb MR |
934 | if (rcd) { |
935 | rcd->do_interrupt = | |
936 | &handle_receive_interrupt_dma_rtail; | |
937 | hfi1_rcd_put(rcd); | |
938 | } | |
2280740f VN |
939 | return; |
940 | } | |
941 | ||
d295dbeb MR |
942 | for (i = HFI1_CTRL_CTXT + 1; i < dd->first_dyn_alloc_ctxt; i++) { |
943 | rcd = hfi1_rcd_get_by_index(dd, i); | |
944 | if (rcd) | |
945 | rcd->do_interrupt = | |
946 | &handle_receive_interrupt_dma_rtail; | |
947 | hfi1_rcd_put(rcd); | |
948 | } | |
77241056 MM |
949 | } |
950 | ||
fb9036dd JS |
951 | void set_all_slowpath(struct hfi1_devdata *dd) |
952 | { | |
d295dbeb | 953 | struct hfi1_ctxtdata *rcd; |
e6f7622d | 954 | u16 i; |
fb9036dd JS |
955 | |
956 | /* HFI1_CTRL_CTXT must always use the slow path interrupt handler */ | |
2280740f | 957 | for (i = HFI1_CTRL_CTXT + 1; i < dd->num_rcv_contexts; i++) { |
d295dbeb MR |
958 | rcd = hfi1_rcd_get_by_index(dd, i); |
959 | if (!rcd) | |
960 | continue; | |
cc9a97ea | 961 | if (i < dd->first_dyn_alloc_ctxt || rcd->is_vnic) |
2280740f | 962 | rcd->do_interrupt = &handle_receive_interrupt; |
cc9a97ea | 963 | |
d295dbeb | 964 | hfi1_rcd_put(rcd); |
2280740f | 965 | } |
fb9036dd JS |
966 | } |
967 | ||
968 | static inline int set_armed_to_active(struct hfi1_ctxtdata *rcd, | |
c867caaf | 969 | struct hfi1_packet *packet, |
fb9036dd JS |
970 | struct hfi1_devdata *dd) |
971 | { | |
972 | struct work_struct *lsaw = &rcd->ppd->linkstate_active_work; | |
69b9f4a4 | 973 | u8 etype = rhf_rcv_type(packet->rhf); |
9039746c | 974 | u8 sc = SC15_PACKET; |
fb9036dd | 975 | |
9039746c | 976 | if (etype == RHF_RCV_TYPE_IB) { |
40442b30 | 977 | struct ib_header *hdr = hfi1_get_msgheader(packet->rcd, |
9039746c DH |
978 | packet->rhf_addr); |
979 | sc = hfi1_9B_get_sc5(hdr, packet->rhf); | |
72c07e2b DH |
980 | } else if (etype == RHF_RCV_TYPE_BYPASS) { |
981 | struct hfi1_16b_header *hdr = hfi1_get_16B_header( | |
40442b30 | 982 | packet->rcd, |
72c07e2b DH |
983 | packet->rhf_addr); |
984 | sc = hfi1_16B_get_sc(hdr); | |
9039746c DH |
985 | } |
986 | if (sc != SC15_PACKET) { | |
bec7c79c | 987 | int hwstate = driver_lstate(rcd->ppd); |
fb9036dd | 988 | |
bec7c79c BJ |
989 | if (hwstate != IB_PORT_ACTIVE) { |
990 | dd_dev_info(dd, | |
991 | "Unexpected link state %s\n", | |
992 | opa_lstate_name(hwstate)); | |
fb9036dd JS |
993 | return 0; |
994 | } | |
995 | ||
71d47008 | 996 | queue_work(rcd->ppd->link_wq, lsaw); |
fb9036dd JS |
997 | return 1; |
998 | } | |
999 | return 0; | |
1000 | } | |
1001 | ||
77241056 MM |
1002 | /* |
1003 | * handle_receive_interrupt - receive a packet | |
1004 | * @rcd: the context | |
1005 | * | |
1006 | * Called from interrupt handler for errors or receive interrupt. | |
1007 | * This is the slow path interrupt handler. | |
1008 | */ | |
f4f30031 | 1009 | int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread) |
77241056 | 1010 | { |
77241056 MM |
1011 | struct hfi1_devdata *dd = rcd->dd; |
1012 | u32 hdrqtail; | |
82c2611d | 1013 | int needset, last = RCV_PKT_OK; |
77241056 | 1014 | struct hfi1_packet packet; |
82c2611d NV |
1015 | int skip_pkt = 0; |
1016 | ||
1017 | /* Control context will always use the slow path interrupt handler */ | |
1018 | needset = (rcd->ctxt == HFI1_CTRL_CTXT) ? 0 : 1; | |
77241056 MM |
1019 | |
1020 | init_packet(rcd, &packet); | |
1021 | ||
82c2611d | 1022 | if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) { |
77241056 MM |
1023 | u32 seq = rhf_rcv_seq(packet.rhf); |
1024 | ||
f4f30031 DL |
1025 | if (seq != rcd->seq_cnt) { |
1026 | last = RCV_PKT_DONE; | |
77241056 | 1027 | goto bail; |
f4f30031 | 1028 | } |
77241056 MM |
1029 | hdrqtail = 0; |
1030 | } else { | |
1031 | hdrqtail = get_rcvhdrtail(rcd); | |
f4f30031 DL |
1032 | if (packet.rhqoff == hdrqtail) { |
1033 | last = RCV_PKT_DONE; | |
77241056 | 1034 | goto bail; |
f4f30031 | 1035 | } |
77241056 | 1036 | smp_rmb(); /* prevent speculative reads of dma'ed hdrq */ |
82c2611d NV |
1037 | |
1038 | /* | |
1039 | * Control context can potentially receive an invalid | |
1040 | * rhf. Drop such packets. | |
1041 | */ | |
1042 | if (rcd->ctxt == HFI1_CTRL_CTXT) { | |
1043 | u32 seq = rhf_rcv_seq(packet.rhf); | |
1044 | ||
1045 | if (seq != rcd->seq_cnt) | |
1046 | skip_pkt = 1; | |
1047 | } | |
77241056 MM |
1048 | } |
1049 | ||
6c9e50f8 | 1050 | prescan_rxq(rcd, &packet); |
77241056 | 1051 | |
f4f30031 | 1052 | while (last == RCV_PKT_OK) { |
17fb4f29 JJ |
1053 | if (unlikely(dd->do_drop && |
1054 | atomic_xchg(&dd->drop_packet, DROP_PACKET_OFF) == | |
1055 | DROP_PACKET_ON)) { | |
77241056 MM |
1056 | dd->do_drop = 0; |
1057 | ||
1058 | /* On to the next packet */ | |
1059 | packet.rhqoff += packet.rsize; | |
50e5dcbe | 1060 | packet.rhf_addr = (__le32 *)rcd->rcvhdrq + |
77241056 | 1061 | packet.rhqoff + |
40442b30 | 1062 | rcd->rhf_offset; |
77241056 MM |
1063 | packet.rhf = rhf_to_cpu(packet.rhf_addr); |
1064 | ||
82c2611d NV |
1065 | } else if (skip_pkt) { |
1066 | last = skip_rcv_packet(&packet, thread); | |
1067 | skip_pkt = 0; | |
77241056 | 1068 | } else { |
fb9036dd JS |
1069 | /* Auto activate link on non-SC15 packet receive */ |
1070 | if (unlikely(rcd->ppd->host_link_state == | |
1071 | HLS_UP_ARMED) && | |
c867caaf | 1072 | set_armed_to_active(rcd, &packet, dd)) |
fb9036dd | 1073 | goto bail; |
f4f30031 | 1074 | last = process_rcv_packet(&packet, thread); |
77241056 MM |
1075 | } |
1076 | ||
82c2611d | 1077 | if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) { |
77241056 MM |
1078 | u32 seq = rhf_rcv_seq(packet.rhf); |
1079 | ||
1080 | if (++rcd->seq_cnt > 13) | |
1081 | rcd->seq_cnt = 1; | |
1082 | if (seq != rcd->seq_cnt) | |
f4f30031 | 1083 | last = RCV_PKT_DONE; |
77241056 | 1084 | if (needset) { |
17fb4f29 | 1085 | dd_dev_info(dd, "Switching to NO_DMA_RTAIL\n"); |
2280740f | 1086 | set_nodma_rtail(dd, rcd->ctxt); |
77241056 MM |
1087 | needset = 0; |
1088 | } | |
1089 | } else { | |
1090 | if (packet.rhqoff == hdrqtail) | |
f4f30031 | 1091 | last = RCV_PKT_DONE; |
82c2611d NV |
1092 | /* |
1093 | * Control context can potentially receive an invalid | |
1094 | * rhf. Drop such packets. | |
1095 | */ | |
1096 | if (rcd->ctxt == HFI1_CTRL_CTXT) { | |
1097 | u32 seq = rhf_rcv_seq(packet.rhf); | |
1098 | ||
1099 | if (++rcd->seq_cnt > 13) | |
1100 | rcd->seq_cnt = 1; | |
1101 | if (!last && (seq != rcd->seq_cnt)) | |
1102 | skip_pkt = 1; | |
1103 | } | |
1104 | ||
77241056 MM |
1105 | if (needset) { |
1106 | dd_dev_info(dd, | |
1107 | "Switching to DMA_RTAIL\n"); | |
2280740f | 1108 | set_dma_rtail(dd, rcd->ctxt); |
77241056 MM |
1109 | needset = 0; |
1110 | } | |
1111 | } | |
1112 | ||
1113 | process_rcv_update(last, &packet); | |
1114 | } | |
1115 | ||
bdaf96f6 | 1116 | process_rcv_qp_work(&packet); |
a82a7fcd | 1117 | rcd->head = packet.rhqoff; |
77241056 MM |
1118 | |
1119 | bail: | |
1120 | /* | |
1121 | * Always write head at end, and setup rcv interrupt, even | |
1122 | * if no packets were processed. | |
1123 | */ | |
1124 | finish_packet(&packet); | |
f4f30031 | 1125 | return last; |
77241056 MM |
1126 | } |
1127 | ||
fb9036dd JS |
1128 | /* |
1129 | * We may discover in the interrupt that the hardware link state has | |
1130 | * changed from ARMED to ACTIVE (due to the arrival of a non-SC15 packet), | |
1131 | * and we need to update the driver's notion of the link state. We cannot | |
1132 | * run set_link_state from interrupt context, so we queue this function on | |
1133 | * a workqueue. | |
1134 | * | |
1135 | * We delay the regular interrupt processing until after the state changes | |
1136 | * so that the link will be in the correct state by the time any application | |
1137 | * we wake up attempts to send a reply to any message it received. | |
1138 | * (Subsequent receive interrupts may possibly force the wakeup before we | |
1139 | * update the link state.) | |
1140 | * | |
1141 | * The rcd is freed in hfi1_free_ctxtdata after hfi1_postinit_cleanup invokes | |
1142 | * dd->f_cleanup(dd) to disable the interrupt handler and flush workqueues, | |
1143 | * so we're safe from use-after-free of the rcd. | |
1144 | */ | |
1145 | void receive_interrupt_work(struct work_struct *work) | |
1146 | { | |
1147 | struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata, | |
1148 | linkstate_active_work); | |
1149 | struct hfi1_devdata *dd = ppd->dd; | |
d295dbeb | 1150 | struct hfi1_ctxtdata *rcd; |
e6f7622d | 1151 | u16 i; |
fb9036dd JS |
1152 | |
1153 | /* Received non-SC15 packet implies neighbor_normal */ | |
1154 | ppd->neighbor_normal = 1; | |
1155 | set_link_state(ppd, HLS_UP_ACTIVE); | |
1156 | ||
1157 | /* | |
2280740f VN |
1158 | * Interrupt all statically allocated kernel contexts that could |
1159 | * have had an interrupt during auto activation. | |
fb9036dd | 1160 | */ |
d295dbeb MR |
1161 | for (i = HFI1_CTRL_CTXT; i < dd->first_dyn_alloc_ctxt; i++) { |
1162 | rcd = hfi1_rcd_get_by_index(dd, i); | |
1163 | if (rcd) | |
1164 | force_recv_intr(rcd); | |
1165 | hfi1_rcd_put(rcd); | |
1166 | } | |
fb9036dd JS |
1167 | } |
1168 | ||
77241056 MM |
1169 | /* |
1170 | * Convert a given MTU size to the on-wire MAD packet enumeration. | |
1171 | * Return -1 if the size is invalid. | |
1172 | */ | |
1173 | int mtu_to_enum(u32 mtu, int default_if_bad) | |
1174 | { | |
1175 | switch (mtu) { | |
1176 | case 0: return OPA_MTU_0; | |
1177 | case 256: return OPA_MTU_256; | |
1178 | case 512: return OPA_MTU_512; | |
1179 | case 1024: return OPA_MTU_1024; | |
1180 | case 2048: return OPA_MTU_2048; | |
1181 | case 4096: return OPA_MTU_4096; | |
1182 | case 8192: return OPA_MTU_8192; | |
1183 | case 10240: return OPA_MTU_10240; | |
1184 | } | |
1185 | return default_if_bad; | |
1186 | } | |
1187 | ||
1188 | u16 enum_to_mtu(int mtu) | |
1189 | { | |
1190 | switch (mtu) { | |
1191 | case OPA_MTU_0: return 0; | |
1192 | case OPA_MTU_256: return 256; | |
1193 | case OPA_MTU_512: return 512; | |
1194 | case OPA_MTU_1024: return 1024; | |
1195 | case OPA_MTU_2048: return 2048; | |
1196 | case OPA_MTU_4096: return 4096; | |
1197 | case OPA_MTU_8192: return 8192; | |
1198 | case OPA_MTU_10240: return 10240; | |
1199 | default: return 0xffff; | |
1200 | } | |
1201 | } | |
1202 | ||
1203 | /* | |
1204 | * set_mtu - set the MTU | |
1205 | * @ppd: the per port data | |
1206 | * | |
1207 | * We can handle "any" incoming size, the issue here is whether we | |
1208 | * need to restrict our outgoing size. We do not deal with what happens | |
1209 | * to programs that are already running when the size changes. | |
1210 | */ | |
1211 | int set_mtu(struct hfi1_pportdata *ppd) | |
1212 | { | |
1213 | struct hfi1_devdata *dd = ppd->dd; | |
1214 | int i, drain, ret = 0, is_up = 0; | |
1215 | ||
1216 | ppd->ibmtu = 0; | |
1217 | for (i = 0; i < ppd->vls_supported; i++) | |
1218 | if (ppd->ibmtu < dd->vld[i].mtu) | |
1219 | ppd->ibmtu = dd->vld[i].mtu; | |
1220 | ppd->ibmaxlen = ppd->ibmtu + lrh_max_header_bytes(ppd->dd); | |
1221 | ||
1222 | mutex_lock(&ppd->hls_lock); | |
d0d236ea JJ |
1223 | if (ppd->host_link_state == HLS_UP_INIT || |
1224 | ppd->host_link_state == HLS_UP_ARMED || | |
1225 | ppd->host_link_state == HLS_UP_ACTIVE) | |
77241056 MM |
1226 | is_up = 1; |
1227 | ||
1228 | drain = !is_ax(dd) && is_up; | |
1229 | ||
1230 | if (drain) | |
1231 | /* | |
1232 | * MTU is specified per-VL. To ensure that no packet gets | |
1233 | * stuck (due, e.g., to the MTU for the packet's VL being | |
1234 | * reduced), empty the per-VL FIFOs before adjusting MTU. | |
1235 | */ | |
1236 | ret = stop_drain_data_vls(dd); | |
1237 | ||
1238 | if (ret) { | |
1239 | dd_dev_err(dd, "%s: cannot stop/drain VLs - refusing to change per-VL MTUs\n", | |
1240 | __func__); | |
1241 | goto err; | |
1242 | } | |
1243 | ||
1244 | hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_MTU, 0); | |
1245 | ||
1246 | if (drain) | |
1247 | open_fill_data_vls(dd); /* reopen all VLs */ | |
1248 | ||
1249 | err: | |
1250 | mutex_unlock(&ppd->hls_lock); | |
1251 | ||
1252 | return ret; | |
1253 | } | |
1254 | ||
1255 | int hfi1_set_lid(struct hfi1_pportdata *ppd, u32 lid, u8 lmc) | |
1256 | { | |
1257 | struct hfi1_devdata *dd = ppd->dd; | |
1258 | ||
1259 | ppd->lid = lid; | |
1260 | ppd->lmc = lmc; | |
1261 | hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_LIDLMC, 0); | |
1262 | ||
cde10afa | 1263 | dd_dev_info(dd, "port %u: got a lid: 0x%x\n", ppd->port, lid); |
77241056 MM |
1264 | |
1265 | return 0; | |
1266 | } | |
1267 | ||
91ab4ed3 EH |
1268 | void shutdown_led_override(struct hfi1_pportdata *ppd) |
1269 | { | |
1270 | struct hfi1_devdata *dd = ppd->dd; | |
1271 | ||
409b1462 | 1272 | /* |
2243472e EH |
1273 | * This pairs with the memory barrier in hfi1_start_led_override to |
1274 | * ensure that we read the correct state of LED beaconing represented | |
1275 | * by led_override_timer_active | |
409b1462 | 1276 | */ |
2243472e | 1277 | smp_rmb(); |
91ab4ed3 EH |
1278 | if (atomic_read(&ppd->led_override_timer_active)) { |
1279 | del_timer_sync(&ppd->led_override_timer); | |
1280 | atomic_set(&ppd->led_override_timer_active, 0); | |
2243472e EH |
1281 | /* Ensure the atomic_set is visible to all CPUs */ |
1282 | smp_wmb(); | |
91ab4ed3 EH |
1283 | } |
1284 | ||
2243472e EH |
1285 | /* Hand control of the LED to the DC for normal operation */ |
1286 | write_csr(dd, DCC_CFG_LED_CNTRL, 0); | |
91ab4ed3 | 1287 | } |
77241056 | 1288 | |
8064135e | 1289 | static void run_led_override(struct timer_list *t) |
77241056 | 1290 | { |
8064135e | 1291 | struct hfi1_pportdata *ppd = from_timer(ppd, t, led_override_timer); |
77241056 | 1292 | struct hfi1_devdata *dd = ppd->dd; |
91ab4ed3 EH |
1293 | unsigned long timeout; |
1294 | int phase_idx; | |
77241056 MM |
1295 | |
1296 | if (!(dd->flags & HFI1_INITTED)) | |
1297 | return; | |
1298 | ||
91ab4ed3 | 1299 | phase_idx = ppd->led_override_phase & 1; |
77241056 | 1300 | |
91ab4ed3 EH |
1301 | setextled(dd, phase_idx); |
1302 | ||
1303 | timeout = ppd->led_override_vals[phase_idx]; | |
2243472e | 1304 | |
91ab4ed3 EH |
1305 | /* Set up for next phase */ |
1306 | ppd->led_override_phase = !ppd->led_override_phase; | |
77241056 | 1307 | |
2243472e | 1308 | mod_timer(&ppd->led_override_timer, jiffies + timeout); |
77241056 MM |
1309 | } |
1310 | ||
91ab4ed3 EH |
1311 | /* |
1312 | * To have the LED blink in a particular pattern, provide timeon and timeoff | |
2243472e EH |
1313 | * in milliseconds. |
1314 | * To turn off custom blinking and return to normal operation, use | |
1315 | * shutdown_led_override() | |
91ab4ed3 | 1316 | */ |
2243472e EH |
1317 | void hfi1_start_led_override(struct hfi1_pportdata *ppd, unsigned int timeon, |
1318 | unsigned int timeoff) | |
77241056 | 1319 | { |
2243472e | 1320 | if (!(ppd->dd->flags & HFI1_INITTED)) |
77241056 MM |
1321 | return; |
1322 | ||
91ab4ed3 EH |
1323 | /* Convert to jiffies for direct use in timer */ |
1324 | ppd->led_override_vals[0] = msecs_to_jiffies(timeoff); | |
1325 | ppd->led_override_vals[1] = msecs_to_jiffies(timeon); | |
77241056 | 1326 | |
2243472e EH |
1327 | /* Arbitrarily start from LED on phase */ |
1328 | ppd->led_override_phase = 1; | |
77241056 MM |
1329 | |
1330 | /* | |
1331 | * If the timer has not already been started, do so. Use a "quick" | |
2243472e | 1332 | * timeout so the handler will be called soon to look at our request. |
77241056 | 1333 | */ |
2243472e | 1334 | if (!timer_pending(&ppd->led_override_timer)) { |
8064135e | 1335 | timer_setup(&ppd->led_override_timer, run_led_override, 0); |
77241056 MM |
1336 | ppd->led_override_timer.expires = jiffies + 1; |
1337 | add_timer(&ppd->led_override_timer); | |
2243472e EH |
1338 | atomic_set(&ppd->led_override_timer_active, 1); |
1339 | /* Ensure the atomic_set is visible to all CPUs */ | |
1340 | smp_wmb(); | |
77241056 MM |
1341 | } |
1342 | } | |
1343 | ||
1344 | /** | |
1345 | * hfi1_reset_device - reset the chip if possible | |
1346 | * @unit: the device to reset | |
1347 | * | |
1348 | * Whether or not reset is successful, we attempt to re-initialize the chip | |
1349 | * (that is, much like a driver unload/reload). We clear the INITTED flag | |
1350 | * so that the various entry points will fail until we reinitialize. For | |
1351 | * now, we only allow this if no user contexts are open that use chip resources | |
1352 | */ | |
1353 | int hfi1_reset_device(int unit) | |
1354 | { | |
e6f7622d | 1355 | int ret; |
77241056 MM |
1356 | struct hfi1_devdata *dd = hfi1_lookup(unit); |
1357 | struct hfi1_pportdata *ppd; | |
77241056 MM |
1358 | int pidx; |
1359 | ||
1360 | if (!dd) { | |
1361 | ret = -ENODEV; | |
1362 | goto bail; | |
1363 | } | |
1364 | ||
1365 | dd_dev_info(dd, "Reset on unit %u requested\n", unit); | |
1366 | ||
cb51c5d2 | 1367 | if (!dd->kregbase1 || !(dd->flags & HFI1_PRESENT)) { |
77241056 | 1368 | dd_dev_info(dd, |
17fb4f29 JJ |
1369 | "Invalid unit number %u or not initialized or not present\n", |
1370 | unit); | |
77241056 MM |
1371 | ret = -ENXIO; |
1372 | goto bail; | |
1373 | } | |
1374 | ||
d295dbeb MR |
1375 | /* If there are any user/vnic contexts, we cannot reset */ |
1376 | mutex_lock(&hfi1_mutex); | |
77241056 | 1377 | if (dd->rcd) |
d295dbeb MR |
1378 | if (hfi1_stats.sps_ctxts) { |
1379 | mutex_unlock(&hfi1_mutex); | |
77241056 MM |
1380 | ret = -EBUSY; |
1381 | goto bail; | |
1382 | } | |
d295dbeb | 1383 | mutex_unlock(&hfi1_mutex); |
77241056 MM |
1384 | |
1385 | for (pidx = 0; pidx < dd->num_pports; ++pidx) { | |
1386 | ppd = dd->pport + pidx; | |
77241056 | 1387 | |
91ab4ed3 | 1388 | shutdown_led_override(ppd); |
77241056 MM |
1389 | } |
1390 | if (dd->flags & HFI1_HAS_SEND_DMA) | |
1391 | sdma_exit(dd); | |
1392 | ||
1393 | hfi1_reset_cpu_counters(dd); | |
1394 | ||
1395 | ret = hfi1_init(dd, 1); | |
1396 | ||
1397 | if (ret) | |
1398 | dd_dev_err(dd, | |
17fb4f29 JJ |
1399 | "Reinitialize unit %u after reset failed with %d\n", |
1400 | unit, ret); | |
77241056 MM |
1401 | else |
1402 | dd_dev_info(dd, "Reinitialized unit %u after resetting\n", | |
17fb4f29 | 1403 | unit); |
77241056 MM |
1404 | |
1405 | bail: | |
1406 | return ret; | |
1407 | } | |
1408 | ||
9039746c DH |
1409 | static inline void hfi1_setup_ib_header(struct hfi1_packet *packet) |
1410 | { | |
1411 | packet->hdr = (struct hfi1_ib_message_header *) | |
40442b30 | 1412 | hfi1_get_msgheader(packet->rcd, |
9039746c DH |
1413 | packet->rhf_addr); |
1414 | packet->hlen = (u8 *)packet->rhf_addr - (u8 *)packet->hdr; | |
1415 | } | |
1416 | ||
5786adf3 DH |
1417 | static int hfi1_bypass_ingress_pkt_check(struct hfi1_packet *packet) |
1418 | { | |
1419 | struct hfi1_pportdata *ppd = packet->rcd->ppd; | |
1420 | ||
1421 | /* slid and dlid cannot be 0 */ | |
1422 | if ((!packet->slid) || (!packet->dlid)) | |
1423 | return -EINVAL; | |
1424 | ||
1425 | /* Compare port lid with incoming packet dlid */ | |
1426 | if ((!(hfi1_is_16B_mcast(packet->dlid))) && | |
1427 | (packet->dlid != | |
1428 | opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE), 16B))) { | |
ff8b67fc | 1429 | if ((packet->dlid & ~((1 << ppd->lmc) - 1)) != ppd->lid) |
5786adf3 DH |
1430 | return -EINVAL; |
1431 | } | |
1432 | ||
1433 | /* No multicast packets with SC15 */ | |
1434 | if ((hfi1_is_16B_mcast(packet->dlid)) && (packet->sc == 0xF)) | |
1435 | return -EINVAL; | |
1436 | ||
1437 | /* Packets with permissive DLID always on SC15 */ | |
1438 | if ((packet->dlid == opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE), | |
1439 | 16B)) && | |
1440 | (packet->sc != 0xF)) | |
1441 | return -EINVAL; | |
1442 | ||
1443 | return 0; | |
1444 | } | |
1445 | ||
9039746c DH |
1446 | static int hfi1_setup_9B_packet(struct hfi1_packet *packet) |
1447 | { | |
1448 | struct hfi1_ibport *ibp = rcd_to_iport(packet->rcd); | |
1449 | struct ib_header *hdr; | |
1450 | u8 lnh; | |
1451 | ||
1452 | hfi1_setup_ib_header(packet); | |
1453 | hdr = packet->hdr; | |
1454 | ||
1455 | lnh = ib_get_lnh(hdr); | |
1456 | if (lnh == HFI1_LRH_BTH) { | |
1457 | packet->ohdr = &hdr->u.oth; | |
1458 | packet->grh = NULL; | |
1459 | } else if (lnh == HFI1_LRH_GRH) { | |
1460 | u32 vtf; | |
1461 | ||
1462 | packet->ohdr = &hdr->u.l.oth; | |
1463 | packet->grh = &hdr->u.l.grh; | |
1464 | if (packet->grh->next_hdr != IB_GRH_NEXT_HDR) | |
1465 | goto drop; | |
1466 | vtf = be32_to_cpu(packet->grh->version_tclass_flow); | |
1467 | if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION) | |
1468 | goto drop; | |
1469 | } else { | |
1470 | goto drop; | |
1471 | } | |
1472 | ||
1473 | /* Query commonly used fields from packet header */ | |
72c07e2b | 1474 | packet->payload = packet->ebuf; |
9039746c DH |
1475 | packet->opcode = ib_bth_get_opcode(packet->ohdr); |
1476 | packet->slid = ib_get_slid(hdr); | |
1477 | packet->dlid = ib_get_dlid(hdr); | |
72c07e2b DH |
1478 | if (unlikely((packet->dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) && |
1479 | (packet->dlid != be16_to_cpu(IB_LID_PERMISSIVE)))) | |
1480 | packet->dlid += opa_get_mcast_base(OPA_MCAST_NR) - | |
1481 | be16_to_cpu(IB_MULTICAST_LID_BASE); | |
9039746c DH |
1482 | packet->sl = ib_get_sl(hdr); |
1483 | packet->sc = hfi1_9B_get_sc5(hdr, packet->rhf); | |
1484 | packet->pad = ib_bth_get_pad(packet->ohdr); | |
1485 | packet->extra_byte = 0; | |
6d6b8848 SS |
1486 | packet->pkey = ib_bth_get_pkey(packet->ohdr); |
1487 | packet->migrated = ib_bth_is_migration(packet->ohdr); | |
9039746c DH |
1488 | |
1489 | return 0; | |
1490 | drop: | |
1491 | ibp->rvp.n_pkt_drops++; | |
1492 | return -EINVAL; | |
1493 | } | |
1494 | ||
72c07e2b DH |
1495 | static int hfi1_setup_bypass_packet(struct hfi1_packet *packet) |
1496 | { | |
1497 | /* | |
1498 | * Bypass packets have a different header/payload split | |
1499 | * compared to an IB packet. | |
1500 | * Current split is set such that 16 bytes of the actual | |
1501 | * header is in the header buffer and the remining is in | |
1502 | * the eager buffer. We chose 16 since hfi1 driver only | |
1503 | * supports 16B bypass packets and we will be able to | |
1504 | * receive the entire LRH with such a split. | |
1505 | */ | |
1506 | ||
1507 | struct hfi1_ctxtdata *rcd = packet->rcd; | |
1508 | struct hfi1_pportdata *ppd = rcd->ppd; | |
1509 | struct hfi1_ibport *ibp = &ppd->ibport_data; | |
1510 | u8 l4; | |
72c07e2b DH |
1511 | |
1512 | packet->hdr = (struct hfi1_16b_header *) | |
40442b30 | 1513 | hfi1_get_16B_header(packet->rcd, |
72c07e2b | 1514 | packet->rhf_addr); |
72c07e2b DH |
1515 | l4 = hfi1_16B_get_l4(packet->hdr); |
1516 | if (l4 == OPA_16B_L4_IB_LOCAL) { | |
72c07e2b DH |
1517 | packet->ohdr = packet->ebuf; |
1518 | packet->grh = NULL; | |
81cd3891 DH |
1519 | packet->opcode = ib_bth_get_opcode(packet->ohdr); |
1520 | packet->pad = hfi1_16B_bth_get_pad(packet->ohdr); | |
1521 | /* hdr_len_by_opcode already has an IB LRH factored in */ | |
1522 | packet->hlen = hdr_len_by_opcode[packet->opcode] + | |
1523 | (LRH_16B_BYTES - LRH_9B_BYTES); | |
1524 | packet->migrated = opa_bth_is_migration(packet->ohdr); | |
72c07e2b DH |
1525 | } else if (l4 == OPA_16B_L4_IB_GLOBAL) { |
1526 | u32 vtf; | |
81cd3891 | 1527 | u8 grh_len = sizeof(struct ib_grh); |
72c07e2b | 1528 | |
72c07e2b DH |
1529 | packet->ohdr = packet->ebuf + grh_len; |
1530 | packet->grh = packet->ebuf; | |
81cd3891 DH |
1531 | packet->opcode = ib_bth_get_opcode(packet->ohdr); |
1532 | packet->pad = hfi1_16B_bth_get_pad(packet->ohdr); | |
1533 | /* hdr_len_by_opcode already has an IB LRH factored in */ | |
1534 | packet->hlen = hdr_len_by_opcode[packet->opcode] + | |
1535 | (LRH_16B_BYTES - LRH_9B_BYTES) + grh_len; | |
1536 | packet->migrated = opa_bth_is_migration(packet->ohdr); | |
1537 | ||
72c07e2b DH |
1538 | if (packet->grh->next_hdr != IB_GRH_NEXT_HDR) |
1539 | goto drop; | |
1540 | vtf = be32_to_cpu(packet->grh->version_tclass_flow); | |
1541 | if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION) | |
1542 | goto drop; | |
81cd3891 DH |
1543 | } else if (l4 == OPA_16B_L4_FM) { |
1544 | packet->mgmt = packet->ebuf; | |
1545 | packet->ohdr = NULL; | |
1546 | packet->grh = NULL; | |
1547 | packet->opcode = IB_OPCODE_UD_SEND_ONLY; | |
1548 | packet->pad = OPA_16B_L4_FM_PAD; | |
1549 | packet->hlen = OPA_16B_L4_FM_HLEN; | |
1550 | packet->migrated = false; | |
72c07e2b DH |
1551 | } else { |
1552 | goto drop; | |
1553 | } | |
1554 | ||
1555 | /* Query commonly used fields from packet header */ | |
78d3633b | 1556 | packet->payload = packet->ebuf + packet->hlen - LRH_16B_BYTES; |
72c07e2b DH |
1557 | packet->slid = hfi1_16B_get_slid(packet->hdr); |
1558 | packet->dlid = hfi1_16B_get_dlid(packet->hdr); | |
1559 | if (unlikely(hfi1_is_16B_mcast(packet->dlid))) | |
1560 | packet->dlid += opa_get_mcast_base(OPA_MCAST_NR) - | |
1561 | opa_get_lid(opa_get_mcast_base(OPA_MCAST_NR), | |
1562 | 16B); | |
1563 | packet->sc = hfi1_16B_get_sc(packet->hdr); | |
1564 | packet->sl = ibp->sc_to_sl[packet->sc]; | |
72c07e2b | 1565 | packet->extra_byte = SIZE_OF_LT; |
6d6b8848 | 1566 | packet->pkey = hfi1_16B_get_pkey(packet->hdr); |
72c07e2b | 1567 | |
5786adf3 DH |
1568 | if (hfi1_bypass_ingress_pkt_check(packet)) |
1569 | goto drop; | |
1570 | ||
72c07e2b DH |
1571 | return 0; |
1572 | drop: | |
1573 | hfi1_cdbg(PKT, "%s: packet dropped\n", __func__); | |
1574 | ibp->rvp.n_pkt_drops++; | |
1575 | return -EINVAL; | |
1576 | } | |
1577 | ||
22d136d7 | 1578 | static void show_eflags_errs(struct hfi1_packet *packet) |
77241056 MM |
1579 | { |
1580 | struct hfi1_ctxtdata *rcd = packet->rcd; | |
1581 | u32 rte = rhf_rcv_type_err(packet->rhf); | |
1582 | ||
22d136d7 KW |
1583 | dd_dev_err(rcd->dd, |
1584 | "receive context %d: rhf 0x%016llx, errs [ %s%s%s%s%s%s%s%s] rte 0x%x\n", | |
1585 | rcd->ctxt, packet->rhf, | |
1586 | packet->rhf & RHF_K_HDR_LEN_ERR ? "k_hdr_len " : "", | |
1587 | packet->rhf & RHF_DC_UNC_ERR ? "dc_unc " : "", | |
1588 | packet->rhf & RHF_DC_ERR ? "dc " : "", | |
1589 | packet->rhf & RHF_TID_ERR ? "tid " : "", | |
1590 | packet->rhf & RHF_LEN_ERR ? "len " : "", | |
1591 | packet->rhf & RHF_ECC_ERR ? "ecc " : "", | |
1592 | packet->rhf & RHF_VCRC_ERR ? "vcrc " : "", | |
1593 | packet->rhf & RHF_ICRC_ERR ? "icrc " : "", | |
1594 | rte); | |
1595 | } | |
1596 | ||
1597 | void handle_eflags(struct hfi1_packet *packet) | |
1598 | { | |
1599 | struct hfi1_ctxtdata *rcd = packet->rcd; | |
1600 | ||
77241056 | 1601 | rcv_hdrerr(rcd, rcd->ppd, packet); |
a03a03e9 | 1602 | if (rhf_err_flags(packet->rhf)) |
22d136d7 | 1603 | show_eflags_errs(packet); |
77241056 MM |
1604 | } |
1605 | ||
1606 | /* | |
1607 | * The following functions are called by the interrupt handler. They are type | |
1608 | * specific handlers for each packet type. | |
1609 | */ | |
b0ba3c18 | 1610 | static int process_receive_ib(struct hfi1_packet *packet) |
77241056 | 1611 | { |
a74d5307 | 1612 | if (hfi1_setup_9B_packet(packet)) |
0181ce31 DH |
1613 | return RHF_RCV_CONTINUE; |
1614 | ||
a74d5307 | 1615 | if (unlikely(hfi1_dbg_should_fault_rx(packet))) |
9039746c DH |
1616 | return RHF_RCV_CONTINUE; |
1617 | ||
6197a815 | 1618 | trace_hfi1_rcvhdr(packet); |
243d9f43 | 1619 | |
77241056 MM |
1620 | if (unlikely(rhf_err_flags(packet->rhf))) { |
1621 | handle_eflags(packet); | |
1622 | return RHF_RCV_CONTINUE; | |
1623 | } | |
1624 | ||
1625 | hfi1_ib_rcv(packet); | |
1626 | return RHF_RCV_CONTINUE; | |
1627 | } | |
1628 | ||
d4829ea6 VN |
1629 | static inline bool hfi1_is_vnic_packet(struct hfi1_packet *packet) |
1630 | { | |
1631 | /* Packet received in VNIC context via RSM */ | |
1632 | if (packet->rcd->is_vnic) | |
1633 | return true; | |
1634 | ||
72c07e2b DH |
1635 | if ((hfi1_16B_get_l2(packet->ebuf) == OPA_16B_L2_TYPE) && |
1636 | (hfi1_16B_get_l4(packet->ebuf) == OPA_16B_L4_ETHR)) | |
d4829ea6 VN |
1637 | return true; |
1638 | ||
1639 | return false; | |
1640 | } | |
1641 | ||
b0ba3c18 | 1642 | static int process_receive_bypass(struct hfi1_packet *packet) |
77241056 | 1643 | { |
505efe3e JP |
1644 | struct hfi1_devdata *dd = packet->rcd->dd; |
1645 | ||
72c07e2b | 1646 | if (hfi1_is_vnic_packet(packet)) { |
d4829ea6 VN |
1647 | hfi1_vnic_bypass_rcv(packet); |
1648 | return RHF_RCV_CONTINUE; | |
1649 | } | |
77241056 | 1650 | |
72c07e2b DH |
1651 | if (hfi1_setup_bypass_packet(packet)) |
1652 | return RHF_RCV_CONTINUE; | |
1653 | ||
6197a815 DH |
1654 | trace_hfi1_rcvhdr(packet); |
1655 | ||
72c07e2b DH |
1656 | if (unlikely(rhf_err_flags(packet->rhf))) { |
1657 | handle_eflags(packet); | |
1658 | return RHF_RCV_CONTINUE; | |
1659 | } | |
505efe3e | 1660 | |
72c07e2b DH |
1661 | if (hfi1_16B_get_l2(packet->hdr) == 0x2) { |
1662 | hfi1_16B_rcv(packet); | |
1663 | } else { | |
1664 | dd_dev_err(dd, | |
1665 | "Bypass packets other than 16B are not supported in normal operation. Dropping\n"); | |
1666 | incr_cntr64(&dd->sw_rcv_bypass_packet_errors); | |
1667 | if (!(dd->err_info_rcvport.status_and_code & | |
1668 | OPA_EI_STATUS_SMASK)) { | |
1669 | u64 *flits = packet->ebuf; | |
1670 | ||
1671 | if (flits && !(packet->rhf & RHF_LEN_ERR)) { | |
1672 | dd->err_info_rcvport.packet_flit1 = flits[0]; | |
1673 | dd->err_info_rcvport.packet_flit2 = | |
1674 | packet->tlen > sizeof(flits[0]) ? | |
1675 | flits[1] : 0; | |
1676 | } | |
1677 | dd->err_info_rcvport.status_and_code |= | |
1678 | (OPA_EI_STATUS_SMASK | BAD_L2_ERR); | |
505efe3e | 1679 | } |
505efe3e | 1680 | } |
77241056 MM |
1681 | return RHF_RCV_CONTINUE; |
1682 | } | |
1683 | ||
b0ba3c18 | 1684 | static int process_receive_error(struct hfi1_packet *packet) |
77241056 | 1685 | { |
243d9f43 DH |
1686 | /* KHdrHCRCErr -- KDETH packet with a bad HCRC */ |
1687 | if (unlikely( | |
1688 | hfi1_dbg_fault_suppress_err(&packet->rcd->dd->verbs_dev) && | |
a74d5307 MH |
1689 | (rhf_rcv_type_err(packet->rhf) == RHF_RCV_TYPE_ERROR || |
1690 | packet->rhf & RHF_DC_ERR))) | |
243d9f43 DH |
1691 | return RHF_RCV_CONTINUE; |
1692 | ||
9039746c | 1693 | hfi1_setup_ib_header(packet); |
77241056 MM |
1694 | handle_eflags(packet); |
1695 | ||
1696 | if (unlikely(rhf_err_flags(packet->rhf))) | |
1697 | dd_dev_err(packet->rcd->dd, | |
1698 | "Unhandled error packet received. Dropping.\n"); | |
1699 | ||
1700 | return RHF_RCV_CONTINUE; | |
1701 | } | |
1702 | ||
b0ba3c18 | 1703 | static int kdeth_process_expected(struct hfi1_packet *packet) |
77241056 | 1704 | { |
a74d5307 MH |
1705 | hfi1_setup_9B_packet(packet); |
1706 | if (unlikely(hfi1_dbg_should_fault_rx(packet))) | |
0181ce31 | 1707 | return RHF_RCV_CONTINUE; |
9039746c | 1708 | |
22d136d7 KW |
1709 | if (unlikely(rhf_err_flags(packet->rhf))) { |
1710 | struct hfi1_ctxtdata *rcd = packet->rcd; | |
77241056 | 1711 | |
22d136d7 KW |
1712 | if (hfi1_handle_kdeth_eflags(rcd, rcd->ppd, packet)) |
1713 | return RHF_RCV_CONTINUE; | |
1714 | } | |
1715 | ||
1716 | hfi1_kdeth_expected_rcv(packet); | |
77241056 MM |
1717 | return RHF_RCV_CONTINUE; |
1718 | } | |
1719 | ||
b0ba3c18 | 1720 | static int kdeth_process_eager(struct hfi1_packet *packet) |
77241056 | 1721 | { |
a74d5307 MH |
1722 | hfi1_setup_9B_packet(packet); |
1723 | if (unlikely(hfi1_dbg_should_fault_rx(packet))) | |
1724 | return RHF_RCV_CONTINUE; | |
77241056 | 1725 | |
22d136d7 KW |
1726 | trace_hfi1_rcvhdr(packet); |
1727 | if (unlikely(rhf_err_flags(packet->rhf))) { | |
1728 | struct hfi1_ctxtdata *rcd = packet->rcd; | |
1729 | ||
1730 | show_eflags_errs(packet); | |
1731 | if (hfi1_handle_kdeth_eflags(rcd, rcd->ppd, packet)) | |
1732 | return RHF_RCV_CONTINUE; | |
1733 | } | |
1734 | ||
1735 | hfi1_kdeth_eager_rcv(packet); | |
77241056 MM |
1736 | return RHF_RCV_CONTINUE; |
1737 | } | |
1738 | ||
b0ba3c18 | 1739 | static int process_receive_invalid(struct hfi1_packet *packet) |
77241056 MM |
1740 | { |
1741 | dd_dev_err(packet->rcd->dd, "Invalid packet type %d. Dropping\n", | |
17fb4f29 | 1742 | rhf_rcv_type(packet->rhf)); |
77241056 MM |
1743 | return RHF_RCV_CONTINUE; |
1744 | } | |
bf808b50 KW |
1745 | |
1746 | void seqfile_dump_rcd(struct seq_file *s, struct hfi1_ctxtdata *rcd) | |
1747 | { | |
1748 | struct hfi1_packet packet; | |
1749 | struct ps_mdata mdata; | |
1750 | ||
1751 | seq_printf(s, "Rcd %u: RcvHdr cnt %u entsize %u %s head %llu tail %llu\n", | |
1752 | rcd->ctxt, rcd->rcvhdrq_cnt, rcd->rcvhdrqentsize, | |
1753 | HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ? | |
1754 | "dma_rtail" : "nodma_rtail", | |
1755 | read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD) & | |
1756 | RCV_HDR_HEAD_HEAD_MASK, | |
1757 | read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL)); | |
1758 | ||
1759 | init_packet(rcd, &packet); | |
1760 | init_ps_mdata(&mdata, &packet); | |
1761 | ||
1762 | while (1) { | |
bf808b50 | 1763 | __le32 *rhf_addr = (__le32 *)rcd->rcvhdrq + mdata.ps_head + |
40442b30 | 1764 | rcd->rhf_offset; |
bf808b50 KW |
1765 | struct ib_header *hdr; |
1766 | u64 rhf = rhf_to_cpu(rhf_addr); | |
1767 | u32 etype = rhf_rcv_type(rhf), qpn; | |
1768 | u8 opcode; | |
1769 | u32 psn; | |
1770 | u8 lnh; | |
1771 | ||
1772 | if (ps_done(&mdata, rhf, rcd)) | |
1773 | break; | |
1774 | ||
1775 | if (ps_skip(&mdata, rhf, rcd)) | |
1776 | goto next; | |
1777 | ||
1778 | if (etype > RHF_RCV_TYPE_IB) | |
1779 | goto next; | |
1780 | ||
40442b30 | 1781 | packet.hdr = hfi1_get_msgheader(rcd, rhf_addr); |
bf808b50 KW |
1782 | hdr = packet.hdr; |
1783 | ||
1784 | lnh = be16_to_cpu(hdr->lrh[0]) & 3; | |
1785 | ||
1786 | if (lnh == HFI1_LRH_BTH) | |
1787 | packet.ohdr = &hdr->u.oth; | |
1788 | else if (lnh == HFI1_LRH_GRH) | |
1789 | packet.ohdr = &hdr->u.l.oth; | |
1790 | else | |
1791 | goto next; /* just in case */ | |
1792 | ||
1793 | opcode = (be32_to_cpu(packet.ohdr->bth[0]) >> 24); | |
1794 | qpn = be32_to_cpu(packet.ohdr->bth[1]) & RVT_QPN_MASK; | |
1795 | psn = mask_psn(be32_to_cpu(packet.ohdr->bth[2])); | |
1796 | ||
1797 | seq_printf(s, "\tEnt %u: opcode 0x%x, qpn 0x%x, psn 0x%x\n", | |
1798 | mdata.ps_head, opcode, qpn, psn); | |
1799 | next: | |
1800 | update_ps_mdata(&mdata, rcd); | |
1801 | } | |
1802 | } | |
b0ba3c18 MM |
1803 | |
1804 | const rhf_rcv_function_ptr normal_rhf_rcv_functions[] = { | |
1805 | [RHF_RCV_TYPE_EXPECTED] = kdeth_process_expected, | |
1806 | [RHF_RCV_TYPE_EAGER] = kdeth_process_eager, | |
1807 | [RHF_RCV_TYPE_IB] = process_receive_ib, | |
1808 | [RHF_RCV_TYPE_ERROR] = process_receive_error, | |
1809 | [RHF_RCV_TYPE_BYPASS] = process_receive_bypass, | |
1810 | [RHF_RCV_TYPE_INVALID5] = process_receive_invalid, | |
1811 | [RHF_RCV_TYPE_INVALID6] = process_receive_invalid, | |
1812 | [RHF_RCV_TYPE_INVALID7] = process_receive_invalid, | |
1813 | }; |