blob: addc68e83606fe92552b09a7cf43b768ffc9a327 [file] [log] [blame]
Mike Marciniszyn77241052015-07-30 15:17:43 -04001/*
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -07002 * Copyright(c) 2015-2017 Intel Corporation.
Mike Marciniszyn77241052015-07-30 15:17:43 -04003 *
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 *
Mike Marciniszyn77241052015-07-30 15:17:43 -04009 * 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 *
Mike Marciniszyn77241052015-07-30 15:17:43 -040020 * 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>
Dennis Dalessandro8859b4a2016-01-19 14:42:11 -080056#include <rdma/ib_verbs.h>
Mike Marciniszyn77241052015-07-30 15:17:43 -040057
58#include "hfi.h"
59#include "trace.h"
60#include "qp.h"
61#include "sdma.h"
Don Hiatt0181ce32017-03-20 17:26:14 -070062#include "debugfs.h"
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -070063#include "vnic.h"
Mike Marciniszyn77241052015-07-30 15:17:43 -040064
65#undef pr_fmt
66#define pr_fmt(fmt) DRIVER_NAME ": " fmt
67
68/*
69 * The size has to be longer than this string, so we can append
70 * board/chip information to it in the initialization code.
71 */
72const char ib_hfi1_version[] = HFI1_DRIVER_VERSION "\n";
73
74DEFINE_SPINLOCK(hfi1_devs_lock);
75LIST_HEAD(hfi1_dev_list);
76DEFINE_MUTEX(hfi1_mutex); /* general driver use */
77
78unsigned int hfi1_max_mtu = HFI1_DEFAULT_MAX_MTU;
79module_param_named(max_mtu, hfi1_max_mtu, uint, S_IRUGO);
Sebastian Sanchezef699e82016-04-12 11:17:09 -070080MODULE_PARM_DESC(max_mtu, "Set max MTU bytes, default is " __stringify(
81 HFI1_DEFAULT_MAX_MTU));
Mike Marciniszyn77241052015-07-30 15:17:43 -040082
83unsigned int hfi1_cu = 1;
84module_param_named(cu, hfi1_cu, uint, S_IRUGO);
85MODULE_PARM_DESC(cu, "Credit return units");
86
87unsigned long hfi1_cap_mask = HFI1_CAP_MASK_DEFAULT;
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -070088static int hfi1_caps_set(const char *val, const struct kernel_param *kp);
89static int hfi1_caps_get(char *buffer, const struct kernel_param *kp);
Mike Marciniszyn77241052015-07-30 15:17:43 -040090static const struct kernel_param_ops cap_ops = {
91 .set = hfi1_caps_set,
92 .get = hfi1_caps_get
93};
94module_param_cb(cap_mask, &cap_ops, &hfi1_cap_mask, S_IWUSR | S_IRUGO);
95MODULE_PARM_DESC(cap_mask, "Bit mask of enabled/disabled HW features");
96
97MODULE_LICENSE("Dual BSD/GPL");
98MODULE_DESCRIPTION("Intel Omni-Path Architecture driver");
Mike Marciniszyn77241052015-07-30 15:17:43 -040099
100/*
101 * MAX_PKT_RCV is the max # if packets processed per receive interrupt.
102 */
103#define MAX_PKT_RECV 64
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800104/*
105 * MAX_PKT_THREAD_RCV is the max # of packets processed before
106 * the qp_wait_list queue is flushed.
107 */
108#define MAX_PKT_RECV_THREAD (MAX_PKT_RECV * 4)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400109#define EGR_HEAD_UPDATE_THRESHOLD 16
110
111struct hfi1_ib_stats hfi1_stats;
112
113static int hfi1_caps_set(const char *val, const struct kernel_param *kp)
114{
115 int ret = 0;
116 unsigned long *cap_mask_ptr = (unsigned long *)kp->arg,
117 cap_mask = *cap_mask_ptr, value, diff,
118 write_mask = ((HFI1_CAP_WRITABLE_MASK << HFI1_CAP_USER_SHIFT) |
119 HFI1_CAP_WRITABLE_MASK);
120
121 ret = kstrtoul(val, 0, &value);
122 if (ret) {
123 pr_warn("Invalid module parameter value for 'cap_mask'\n");
124 goto done;
125 }
126 /* Get the changed bits (except the locked bit) */
127 diff = value ^ (cap_mask & ~HFI1_CAP_LOCKED_SMASK);
128
129 /* Remove any bits that are not allowed to change after driver load */
130 if (HFI1_CAP_LOCKED() && (diff & ~write_mask)) {
131 pr_warn("Ignoring non-writable capability bits %#lx\n",
132 diff & ~write_mask);
133 diff &= write_mask;
134 }
135
136 /* Mask off any reserved bits */
137 diff &= ~HFI1_CAP_RESERVED_MASK;
138 /* Clear any previously set and changing bits */
139 cap_mask &= ~diff;
140 /* Update the bits with the new capability */
141 cap_mask |= (value & diff);
142 /* Check for any kernel/user restrictions */
143 diff = (cap_mask & (HFI1_CAP_MUST_HAVE_KERN << HFI1_CAP_USER_SHIFT)) ^
144 ((cap_mask & HFI1_CAP_MUST_HAVE_KERN) << HFI1_CAP_USER_SHIFT);
145 cap_mask &= ~diff;
146 /* Set the bitmask to the final set */
147 *cap_mask_ptr = cap_mask;
148done:
149 return ret;
150}
151
152static int hfi1_caps_get(char *buffer, const struct kernel_param *kp)
153{
154 unsigned long cap_mask = *(unsigned long *)kp->arg;
155
156 cap_mask &= ~HFI1_CAP_LOCKED_SMASK;
157 cap_mask |= ((cap_mask & HFI1_CAP_K2U) << HFI1_CAP_USER_SHIFT);
158
159 return scnprintf(buffer, PAGE_SIZE, "0x%lx", cap_mask);
160}
161
Dennis Dalessandro49dbb6c2016-01-19 14:42:06 -0800162struct pci_dev *get_pci_dev(struct rvt_dev_info *rdi)
163{
164 struct hfi1_ibdev *ibdev = container_of(rdi, struct hfi1_ibdev, rdi);
165 struct hfi1_devdata *dd = container_of(ibdev,
166 struct hfi1_devdata, verbs_dev);
167 return dd->pcidev;
168}
169
Mike Marciniszyn77241052015-07-30 15:17:43 -0400170/*
171 * Return count of units with at least one port ACTIVE.
172 */
173int hfi1_count_active_units(void)
174{
175 struct hfi1_devdata *dd;
176 struct hfi1_pportdata *ppd;
177 unsigned long flags;
178 int pidx, nunits_active = 0;
179
180 spin_lock_irqsave(&hfi1_devs_lock, flags);
181 list_for_each_entry(dd, &hfi1_dev_list, list) {
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -0700182 if (!(dd->flags & HFI1_PRESENT) || !dd->kregbase1)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400183 continue;
184 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
185 ppd = dd->pport + pidx;
186 if (ppd->lid && ppd->linkup) {
187 nunits_active++;
188 break;
189 }
190 }
191 }
192 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
193 return nunits_active;
194}
195
196/*
Mike Marciniszyn77241052015-07-30 15:17:43 -0400197 * Get address of eager buffer from it's index (allocated in chunks, not
198 * contiguous).
199 */
200static inline void *get_egrbuf(const struct hfi1_ctxtdata *rcd, u64 rhf,
201 u8 *update)
202{
203 u32 idx = rhf_egr_index(rhf), offset = rhf_egr_buf_offset(rhf);
204
205 *update |= !(idx & (rcd->egrbufs.threshold - 1)) && !offset;
206 return (void *)(((u64)(rcd->egrbufs.rcvtids[idx].addr)) +
207 (offset * RCV_BUF_BLOCK_SIZE));
208}
209
Don Hiatt90397462017-05-12 09:20:20 -0700210static inline void *hfi1_get_header(struct hfi1_devdata *dd,
211 __le32 *rhf_addr)
212{
213 u32 offset = rhf_hdrq_offset(rhf_to_cpu(rhf_addr));
214
215 return (void *)(rhf_addr - dd->rhf_offset + offset);
216}
217
218static inline struct ib_header *hfi1_get_msgheader(struct hfi1_devdata *dd,
219 __le32 *rhf_addr)
220{
221 return (struct ib_header *)hfi1_get_header(dd, rhf_addr);
222}
223
Don Hiatt72c07e22017-08-04 13:53:58 -0700224static inline struct hfi1_16b_header
225 *hfi1_get_16B_header(struct hfi1_devdata *dd,
226 __le32 *rhf_addr)
227{
228 return (struct hfi1_16b_header *)hfi1_get_header(dd, rhf_addr);
229}
230
Mike Marciniszyn77241052015-07-30 15:17:43 -0400231/*
232 * Validate and encode the a given RcvArray Buffer size.
233 * The function will check whether the given size falls within
234 * allowed size ranges for the respective type and, optionally,
235 * return the proper encoding.
236 */
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800237int hfi1_rcvbuf_validate(u32 size, u8 type, u16 *encoded)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400238{
Amitoj Kaur Chawlaf5389662016-03-04 22:40:17 +0530239 if (unlikely(!PAGE_ALIGNED(size)))
Mike Marciniszyn77241052015-07-30 15:17:43 -0400240 return 0;
241 if (unlikely(size < MIN_EAGER_BUFFER))
242 return 0;
243 if (size >
244 (type == PT_EAGER ? MAX_EAGER_BUFFER : MAX_EXPECTED_BUFFER))
245 return 0;
246 if (encoded)
247 *encoded = ilog2(size / PAGE_SIZE) + 1;
248 return 1;
249}
250
251static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
252 struct hfi1_packet *packet)
253{
Mike Marciniszyn261a4352016-09-06 04:35:05 -0700254 struct ib_header *rhdr = packet->hdr;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400255 u32 rte = rhf_rcv_type_err(packet->rhf);
Don Hiatt5786adf32017-08-04 13:54:10 -0700256 u32 mlid_base;
Sebastian Sanchezf3e862c2017-02-08 05:26:25 -0800257 struct hfi1_ibport *ibp = rcd_to_iport(rcd);
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800258 struct hfi1_devdata *dd = ppd->dd;
Sebastian Sanchezaca7f4f2018-02-01 10:46:46 -0800259 struct hfi1_ibdev *verbs_dev = &dd->verbs_dev;
260 struct rvt_dev_info *rdi = &verbs_dev->rdi;
261
262 if ((packet->rhf & RHF_DC_ERR) &&
263 hfi1_dbg_fault_suppress_err(verbs_dev))
264 return;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400265
266 if (packet->rhf & (RHF_VCRC_ERR | RHF_ICRC_ERR))
267 return;
268
Don Hiatt5786adf32017-08-04 13:54:10 -0700269 if (packet->etype == RHF_RCV_TYPE_BYPASS) {
Don Hiatt90397462017-05-12 09:20:20 -0700270 goto drop;
Don Hiatt5786adf32017-08-04 13:54:10 -0700271 } else {
272 u8 lnh = ib_get_lnh(rhdr);
273
274 mlid_base = be16_to_cpu(IB_MULTICAST_LID_BASE);
275 if (lnh == HFI1_LRH_BTH) {
276 packet->ohdr = &rhdr->u.oth;
277 } else if (lnh == HFI1_LRH_GRH) {
278 packet->ohdr = &rhdr->u.l.oth;
279 packet->grh = &rhdr->u.l.grh;
280 } else {
281 goto drop;
282 }
Don Hiatt90397462017-05-12 09:20:20 -0700283 }
284
Mike Marciniszyn77241052015-07-30 15:17:43 -0400285 if (packet->rhf & RHF_TID_ERR) {
286 /* For TIDERR and RC QPs preemptively schedule a NAK */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400287 u32 tlen = rhf_pkt_len(packet->rhf); /* in bytes */
Don Hiatt90397462017-05-12 09:20:20 -0700288 u32 dlid = ib_get_dlid(rhdr);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400289 u32 qp_num;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400290
291 /* Sanity check packet */
292 if (tlen < 24)
293 goto drop;
294
295 /* Check for GRH */
Don Hiatt5786adf32017-08-04 13:54:10 -0700296 if (packet->grh) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400297 u32 vtf;
Don Hiatt90397462017-05-12 09:20:20 -0700298 struct ib_grh *grh = packet->grh;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400299
Don Hiatt90397462017-05-12 09:20:20 -0700300 if (grh->next_hdr != IB_GRH_NEXT_HDR)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400301 goto drop;
Don Hiatt90397462017-05-12 09:20:20 -0700302 vtf = be32_to_cpu(grh->version_tclass_flow);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400303 if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
304 goto drop;
Jubin Johne4909742016-02-14 20:22:00 -0800305 }
Don Hiatt90397462017-05-12 09:20:20 -0700306
Mike Marciniszyn77241052015-07-30 15:17:43 -0400307 /* Get the destination QP number. */
Don Hiatt90397462017-05-12 09:20:20 -0700308 qp_num = ib_bth_get_qpn(packet->ohdr);
309 if (dlid < mlid_base) {
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800310 struct rvt_qp *qp;
Dean Luickb77d7132015-10-26 10:28:43 -0400311 unsigned long flags;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400312
313 rcu_read_lock();
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800314 qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400315 if (!qp) {
316 rcu_read_unlock();
317 goto drop;
318 }
319
320 /*
321 * Handle only RC QPs - for other QP types drop error
322 * packet.
323 */
Dean Luickb77d7132015-10-26 10:28:43 -0400324 spin_lock_irqsave(&qp->r_lock, flags);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400325
326 /* Check for valid receive state. */
Dennis Dalessandro83693bd2016-01-19 14:43:33 -0800327 if (!(ib_rvt_state_ops[qp->state] &
328 RVT_PROCESS_RECV_OK)) {
Dennis Dalessandro4eb06882016-01-19 14:42:39 -0800329 ibp->rvp.n_pkt_drops++;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400330 }
331
332 switch (qp->ibqp.qp_type) {
333 case IB_QPT_RC:
Don Hiatt90397462017-05-12 09:20:20 -0700334 hfi1_rc_hdrerr(rcd, packet, qp);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400335 break;
336 default:
337 /* For now don't handle any other QP types */
338 break;
339 }
340
Dean Luickb77d7132015-10-26 10:28:43 -0400341 spin_unlock_irqrestore(&qp->r_lock, flags);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400342 rcu_read_unlock();
343 } /* Unicast QP */
344 } /* Valid packet with TIDErr */
345
346 /* handle "RcvTypeErr" flags */
347 switch (rte) {
348 case RHF_RTE_ERROR_OP_CODE_ERR:
349 {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400350 void *ebuf = NULL;
Don Hiatt90397462017-05-12 09:20:20 -0700351 u8 opcode;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400352
353 if (rhf_use_egr_bfr(packet->rhf))
354 ebuf = packet->ebuf;
355
Jubin Johnd125a6c2016-02-14 20:19:49 -0800356 if (!ebuf)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400357 goto drop; /* this should never happen */
358
Don Hiatt90397462017-05-12 09:20:20 -0700359 opcode = ib_bth_get_opcode(packet->ohdr);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400360 if (opcode == IB_OPCODE_CNP) {
361 /*
362 * Only in pre-B0 h/w is the CNP_OPCODE handled
Edward Mascarenhas80e48982015-12-21 21:57:44 -0500363 * via this code path.
Mike Marciniszyn77241052015-07-30 15:17:43 -0400364 */
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800365 struct rvt_qp *qp = NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400366 u32 lqpn, rqpn;
367 u16 rlid;
368 u8 svc_type, sl, sc5;
369
Dasaratharaman Chandramouliaad559c2017-04-09 10:16:15 -0700370 sc5 = hfi1_9B_get_sc5(rhdr, packet->rhf);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400371 sl = ibp->sc_to_sl[sc5];
372
Don Hiatt90397462017-05-12 09:20:20 -0700373 lqpn = ib_bth_get_qpn(packet->ohdr);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400374 rcu_read_lock();
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800375 qp = rvt_lookup_qpn(rdi, &ibp->rvp, lqpn);
Jubin Johnd125a6c2016-02-14 20:19:49 -0800376 if (!qp) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400377 rcu_read_unlock();
378 goto drop;
379 }
380
381 switch (qp->ibqp.qp_type) {
382 case IB_QPT_UD:
383 rlid = 0;
384 rqpn = 0;
385 svc_type = IB_CC_SVCTYPE_UD;
386 break;
387 case IB_QPT_UC:
Don Hiattcb4270572017-04-09 10:16:22 -0700388 rlid = ib_get_slid(rhdr);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400389 rqpn = qp->remote_qpn;
390 svc_type = IB_CC_SVCTYPE_UC;
391 break;
392 default:
393 goto drop;
394 }
395
396 process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type);
397 rcu_read_unlock();
398 }
399
400 packet->rhf &= ~RHF_RCV_TYPE_ERR_SMASK;
401 break;
402 }
403 default:
404 break;
405 }
406
407drop:
408 return;
409}
410
411static inline void init_packet(struct hfi1_ctxtdata *rcd,
Jubin John17fb4f22016-02-14 20:21:52 -0800412 struct hfi1_packet *packet)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400413{
Mike Marciniszyn77241052015-07-30 15:17:43 -0400414 packet->rsize = rcd->rcvhdrqentsize; /* words */
415 packet->maxcnt = rcd->rcvhdrq_cnt * packet->rsize; /* words */
416 packet->rcd = rcd;
417 packet->updegr = 0;
418 packet->etail = -1;
Dean Luickf4f30031c2015-10-26 10:28:44 -0400419 packet->rhf_addr = get_rhf_addr(rcd);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400420 packet->rhf = rhf_to_cpu(packet->rhf_addr);
421 packet->rhqoff = rcd->head;
422 packet->numpkt = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400423}
424
Bart Van Asschee2fdbc22017-10-11 10:48:59 -0700425/* We support only two types - 9B and 16B for now */
426static const hfi1_handle_cnp hfi1_handle_cnp_tbl[2] = {
427 [HFI1_PKT_TYPE_9B] = &return_cnp,
428 [HFI1_PKT_TYPE_16B] = &return_cnp_16B
429};
430
Mitko Haralanov5fd2b562016-07-25 13:38:07 -0700431void hfi1_process_ecn_slowpath(struct rvt_qp *qp, struct hfi1_packet *pkt,
432 bool do_cnp)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400433{
434 struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
Mike Marciniszyn261a4352016-09-06 04:35:05 -0700435 struct ib_other_headers *ohdr = pkt->ohdr;
Don Hiatt90397462017-05-12 09:20:20 -0700436 struct ib_grh *grh = pkt->grh;
Mitko Haralanov5fd2b562016-07-25 13:38:07 -0700437 u32 rqpn = 0, bth1;
Don Hiatt88733e32017-08-04 13:54:23 -0700438 u16 pkey, rlid, dlid = ib_get_dlid(pkt->hdr);
439 u8 hdr_type, sc, svc_type;
Mitko Haralanov5fd2b562016-07-25 13:38:07 -0700440 bool is_mcast = false;
441
Don Hiatt88733e32017-08-04 13:54:23 -0700442 if (pkt->etype == RHF_RCV_TYPE_BYPASS) {
443 is_mcast = hfi1_is_16B_mcast(dlid);
444 pkey = hfi1_16B_get_pkey(pkt->hdr);
445 sc = hfi1_16B_get_sc(pkt->hdr);
446 hdr_type = HFI1_PKT_TYPE_16B;
447 } else {
448 is_mcast = (dlid > be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
449 (dlid != be16_to_cpu(IB_LID_PERMISSIVE));
450 pkey = ib_bth_get_pkey(ohdr);
451 sc = hfi1_9B_get_sc5(pkt->hdr, pkt->rhf);
452 hdr_type = HFI1_PKT_TYPE_9B;
453 }
454
Mike Marciniszyn77241052015-07-30 15:17:43 -0400455 switch (qp->ibqp.qp_type) {
Arthur Kepner977940b2015-11-04 21:10:10 -0500456 case IB_QPT_SMI:
457 case IB_QPT_GSI:
Mike Marciniszyn77241052015-07-30 15:17:43 -0400458 case IB_QPT_UD:
Don Hiatt88733e32017-08-04 13:54:23 -0700459 rlid = ib_get_slid(pkt->hdr);
460 rqpn = ib_get_sqpn(pkt->ohdr);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400461 svc_type = IB_CC_SVCTYPE_UD;
462 break;
Arthur Kepner977940b2015-11-04 21:10:10 -0500463 case IB_QPT_UC:
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -0400464 rlid = rdma_ah_get_dlid(&qp->remote_ah_attr);
Arthur Kepner977940b2015-11-04 21:10:10 -0500465 rqpn = qp->remote_qpn;
466 svc_type = IB_CC_SVCTYPE_UC;
467 break;
468 case IB_QPT_RC:
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -0400469 rlid = rdma_ah_get_dlid(&qp->remote_ah_attr);
Arthur Kepner977940b2015-11-04 21:10:10 -0500470 rqpn = qp->remote_qpn;
471 svc_type = IB_CC_SVCTYPE_RC;
472 break;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400473 default:
474 return;
475 }
476
Mitko Haralanov5fd2b562016-07-25 13:38:07 -0700477 bth1 = be32_to_cpu(ohdr->bth[1]);
Don Hiatt88733e32017-08-04 13:54:23 -0700478 /* Call appropriate CNP handler */
479 if (do_cnp && (bth1 & IB_FECN_SMASK))
480 hfi1_handle_cnp_tbl[hdr_type](ibp, qp, rqpn, pkey,
481 dlid, rlid, sc, grh);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400482
Don Hiatt3d591092017-04-09 10:16:28 -0700483 if (!is_mcast && (bth1 & IB_BECN_SMASK)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400484 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800485 u32 lqpn = bth1 & RVT_QPN_MASK;
Mitko Haralanov5fd2b562016-07-25 13:38:07 -0700486 u8 sl = ibp->sc_to_sl[sc];
Mike Marciniszyn77241052015-07-30 15:17:43 -0400487
Arthur Kepner977940b2015-11-04 21:10:10 -0500488 process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400489 }
Mitko Haralanov5fd2b562016-07-25 13:38:07 -0700490
Mike Marciniszyn77241052015-07-30 15:17:43 -0400491}
492
493struct ps_mdata {
494 struct hfi1_ctxtdata *rcd;
495 u32 rsize;
496 u32 maxcnt;
497 u32 ps_head;
498 u32 ps_tail;
499 u32 ps_seq;
500};
501
502static inline void init_ps_mdata(struct ps_mdata *mdata,
503 struct hfi1_packet *packet)
504{
505 struct hfi1_ctxtdata *rcd = packet->rcd;
506
507 mdata->rcd = rcd;
508 mdata->rsize = packet->rsize;
509 mdata->maxcnt = packet->maxcnt;
Arthur Kepner3e7ccca2015-11-04 21:10:09 -0500510 mdata->ps_head = packet->rhqoff;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400511
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500512 if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
Arthur Kepner3e7ccca2015-11-04 21:10:09 -0500513 mdata->ps_tail = get_rcvhdrtail(rcd);
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500514 if (rcd->ctxt == HFI1_CTRL_CTXT)
515 mdata->ps_seq = rcd->seq_cnt;
516 else
517 mdata->ps_seq = 0; /* not used with DMA_RTAIL */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400518 } else {
519 mdata->ps_tail = 0; /* used only with DMA_RTAIL*/
520 mdata->ps_seq = rcd->seq_cnt;
521 }
522}
523
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500524static inline int ps_done(struct ps_mdata *mdata, u64 rhf,
525 struct hfi1_ctxtdata *rcd)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400526{
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500527 if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL))
Mike Marciniszyn77241052015-07-30 15:17:43 -0400528 return mdata->ps_head == mdata->ps_tail;
529 return mdata->ps_seq != rhf_rcv_seq(rhf);
530}
531
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500532static inline int ps_skip(struct ps_mdata *mdata, u64 rhf,
533 struct hfi1_ctxtdata *rcd)
534{
535 /*
536 * Control context can potentially receive an invalid rhf.
537 * Drop such packets.
538 */
539 if ((rcd->ctxt == HFI1_CTRL_CTXT) && (mdata->ps_head != mdata->ps_tail))
540 return mdata->ps_seq != rhf_rcv_seq(rhf);
541
542 return 0;
543}
544
545static inline void update_ps_mdata(struct ps_mdata *mdata,
546 struct hfi1_ctxtdata *rcd)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400547{
Mike Marciniszyn77241052015-07-30 15:17:43 -0400548 mdata->ps_head += mdata->rsize;
Arthur Kepner3e7ccca2015-11-04 21:10:09 -0500549 if (mdata->ps_head >= mdata->maxcnt)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400550 mdata->ps_head = 0;
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500551
552 /* Control context must do seq counting */
553 if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ||
554 (rcd->ctxt == HFI1_CTRL_CTXT)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400555 if (++mdata->ps_seq > 13)
556 mdata->ps_seq = 1;
557 }
558}
559
560/*
561 * prescan_rxq - search through the receive queue looking for packets
562 * containing Excplicit Congestion Notifications (FECNs, or BECNs).
563 * When an ECN is found, process the Congestion Notification, and toggle
564 * it off.
Vennila Megavannan6c9e50f2016-02-03 14:32:57 -0800565 * This is declared as a macro to allow quick checking of the port to avoid
566 * the overhead of a function call if not enabled.
Mike Marciniszyn77241052015-07-30 15:17:43 -0400567 */
Vennila Megavannan6c9e50f2016-02-03 14:32:57 -0800568#define prescan_rxq(rcd, packet) \
569 do { \
570 if (rcd->ppd->cc_prescan) \
571 __prescan_rxq(packet); \
572 } while (0)
573static void __prescan_rxq(struct hfi1_packet *packet)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400574{
575 struct hfi1_ctxtdata *rcd = packet->rcd;
576 struct ps_mdata mdata;
577
Mike Marciniszyn77241052015-07-30 15:17:43 -0400578 init_ps_mdata(&mdata, packet);
579
580 while (1) {
581 struct hfi1_devdata *dd = rcd->dd;
Sebastian Sanchezf3e862c2017-02-08 05:26:25 -0800582 struct hfi1_ibport *ibp = rcd_to_iport(rcd);
Jubin John50e5dcb2016-02-14 20:19:41 -0800583 __le32 *rhf_addr = (__le32 *)rcd->rcvhdrq + mdata.ps_head +
Mike Marciniszyn77241052015-07-30 15:17:43 -0400584 dd->rhf_offset;
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800585 struct rvt_qp *qp;
Mike Marciniszyn261a4352016-09-06 04:35:05 -0700586 struct ib_header *hdr;
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800587 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400588 u64 rhf = rhf_to_cpu(rhf_addr);
Arthur Kepner977940b2015-11-04 21:10:10 -0500589 u32 etype = rhf_rcv_type(rhf), qpn, bth1;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400590 int is_ecn = 0;
591 u8 lnh;
592
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500593 if (ps_done(&mdata, rhf, rcd))
Mike Marciniszyn77241052015-07-30 15:17:43 -0400594 break;
595
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500596 if (ps_skip(&mdata, rhf, rcd))
597 goto next;
598
Mike Marciniszyn77241052015-07-30 15:17:43 -0400599 if (etype != RHF_RCV_TYPE_IB)
600 goto next;
601
Dasaratharaman Chandramoulif2d8a0b2016-10-25 13:12:23 -0700602 packet->hdr = hfi1_get_msgheader(dd, rhf_addr);
603 hdr = packet->hdr;
Don Hiattcb4270572017-04-09 10:16:22 -0700604 lnh = ib_get_lnh(hdr);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400605
Dasaratharaman Chandramoulif2d8a0b2016-10-25 13:12:23 -0700606 if (lnh == HFI1_LRH_BTH) {
607 packet->ohdr = &hdr->u.oth;
Don Hiatt90397462017-05-12 09:20:20 -0700608 packet->grh = NULL;
Dasaratharaman Chandramoulif2d8a0b2016-10-25 13:12:23 -0700609 } else if (lnh == HFI1_LRH_GRH) {
610 packet->ohdr = &hdr->u.l.oth;
Don Hiatt90397462017-05-12 09:20:20 -0700611 packet->grh = &hdr->u.l.grh;
Dasaratharaman Chandramoulif2d8a0b2016-10-25 13:12:23 -0700612 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400613 goto next; /* just in case */
Dasaratharaman Chandramoulif2d8a0b2016-10-25 13:12:23 -0700614 }
Mitko Haralanov5fd2b562016-07-25 13:38:07 -0700615
Dasaratharaman Chandramoulif2d8a0b2016-10-25 13:12:23 -0700616 bth1 = be32_to_cpu(packet->ohdr->bth[1]);
Don Hiatt3d591092017-04-09 10:16:28 -0700617 is_ecn = !!(bth1 & (IB_FECN_SMASK | IB_BECN_SMASK));
Mike Marciniszyn77241052015-07-30 15:17:43 -0400618
619 if (!is_ecn)
620 goto next;
621
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800622 qpn = bth1 & RVT_QPN_MASK;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400623 rcu_read_lock();
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800624 qp = rvt_lookup_qpn(rdi, &ibp->rvp, qpn);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400625
Jubin Johnd125a6c2016-02-14 20:19:49 -0800626 if (!qp) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400627 rcu_read_unlock();
628 goto next;
629 }
630
Mitko Haralanov5fd2b562016-07-25 13:38:07 -0700631 process_ecn(qp, packet, true);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400632 rcu_read_unlock();
Arthur Kepner977940b2015-11-04 21:10:10 -0500633
634 /* turn off BECN, FECN */
Don Hiatt3d591092017-04-09 10:16:28 -0700635 bth1 &= ~(IB_FECN_SMASK | IB_BECN_SMASK);
Dasaratharaman Chandramoulif2d8a0b2016-10-25 13:12:23 -0700636 packet->ohdr->bth[1] = cpu_to_be32(bth1);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400637next:
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500638 update_ps_mdata(&mdata, rcd);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400639 }
640}
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500641
Sebastian Sanchezbdaf96f2018-02-01 10:46:31 -0800642static void process_rcv_qp_work(struct hfi1_packet *packet)
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800643{
644 struct rvt_qp *qp, *nqp;
Sebastian Sanchezbdaf96f2018-02-01 10:46:31 -0800645 struct hfi1_ctxtdata *rcd = packet->rcd;
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800646
647 /*
648 * Iterate over all QPs waiting to respond.
649 * The list won't change since the IRQ is only run on one CPU.
650 */
651 list_for_each_entry_safe(qp, nqp, &rcd->qp_wait_list, rspwait) {
652 list_del_init(&qp->rspwait);
653 if (qp->r_flags & RVT_R_RSP_NAK) {
654 qp->r_flags &= ~RVT_R_RSP_NAK;
Sebastian Sanchezbdaf96f2018-02-01 10:46:31 -0800655 packet->qp = qp;
656 hfi1_send_rc_ack(packet, 0);
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800657 }
658 if (qp->r_flags & RVT_R_RSP_SEND) {
659 unsigned long flags;
660
661 qp->r_flags &= ~RVT_R_RSP_SEND;
662 spin_lock_irqsave(&qp->s_lock, flags);
663 if (ib_rvt_state_ops[qp->state] &
664 RVT_PROCESS_OR_FLUSH_SEND)
665 hfi1_schedule_send(qp);
666 spin_unlock_irqrestore(&qp->s_lock, flags);
667 }
668 rvt_put_qp(qp);
669 }
670}
671
672static noinline int max_packet_exceeded(struct hfi1_packet *packet, int thread)
673{
674 if (thread) {
675 if ((packet->numpkt & (MAX_PKT_RECV_THREAD - 1)) == 0)
676 /* allow defered processing */
Sebastian Sanchezbdaf96f2018-02-01 10:46:31 -0800677 process_rcv_qp_work(packet);
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800678 cond_resched();
679 return RCV_PKT_OK;
680 } else {
681 this_cpu_inc(*packet->rcd->dd->rcv_limit);
682 return RCV_PKT_LIMIT;
683 }
684}
685
686static inline int check_max_packet(struct hfi1_packet *packet, int thread)
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500687{
688 int ret = RCV_PKT_OK;
689
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800690 if (unlikely((packet->numpkt & (MAX_PKT_RECV - 1)) == 0))
691 ret = max_packet_exceeded(packet, thread);
692 return ret;
693}
694
695static noinline int skip_rcv_packet(struct hfi1_packet *packet, int thread)
696{
697 int ret;
698
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500699 /* Set up for the next packet */
700 packet->rhqoff += packet->rsize;
701 if (packet->rhqoff >= packet->maxcnt)
702 packet->rhqoff = 0;
703
704 packet->numpkt++;
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800705 ret = check_max_packet(packet, thread);
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500706
707 packet->rhf_addr = (__le32 *)packet->rcd->rcvhdrq + packet->rhqoff +
708 packet->rcd->dd->rhf_offset;
709 packet->rhf = rhf_to_cpu(packet->rhf_addr);
710
711 return ret;
712}
Mike Marciniszyn77241052015-07-30 15:17:43 -0400713
Dean Luickf4f30031c2015-10-26 10:28:44 -0400714static inline int process_rcv_packet(struct hfi1_packet *packet, int thread)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400715{
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800716 int ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400717
Mike Marciniszyn77241052015-07-30 15:17:43 -0400718 packet->etype = rhf_rcv_type(packet->rhf);
Don Hiatt90397462017-05-12 09:20:20 -0700719
Mike Marciniszyn77241052015-07-30 15:17:43 -0400720 /* total length */
721 packet->tlen = rhf_pkt_len(packet->rhf); /* in bytes */
722 /* retrieve eager buffer details */
723 packet->ebuf = NULL;
724 if (rhf_use_egr_bfr(packet->rhf)) {
725 packet->etail = rhf_egr_index(packet->rhf);
726 packet->ebuf = get_egrbuf(packet->rcd, packet->rhf,
727 &packet->updegr);
728 /*
729 * Prefetch the contents of the eager buffer. It is
730 * OK to send a negative length to prefetch_range().
731 * The +2 is the size of the RHF.
732 */
733 prefetch_range(packet->ebuf,
Jubin John17fb4f22016-02-14 20:21:52 -0800734 packet->tlen - ((packet->rcd->rcvhdrqentsize -
735 (rhf_hdrq_offset(packet->rhf)
736 + 2)) * 4));
Mike Marciniszyn77241052015-07-30 15:17:43 -0400737 }
738
739 /*
740 * Call a type specific handler for the packet. We
741 * should be able to trust that etype won't be beyond
742 * the range of valid indexes. If so something is really
743 * wrong and we can probably just let things come
744 * crashing down. There is no need to eat another
745 * comparison in this performance critical code.
746 */
747 packet->rcd->dd->rhf_rcv_function_map[packet->etype](packet);
748 packet->numpkt++;
749
750 /* Set up for the next packet */
751 packet->rhqoff += packet->rsize;
752 if (packet->rhqoff >= packet->maxcnt)
753 packet->rhqoff = 0;
754
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800755 ret = check_max_packet(packet, thread);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400756
Jubin John50e5dcb2016-02-14 20:19:41 -0800757 packet->rhf_addr = (__le32 *)packet->rcd->rcvhdrq + packet->rhqoff +
Mike Marciniszyn77241052015-07-30 15:17:43 -0400758 packet->rcd->dd->rhf_offset;
759 packet->rhf = rhf_to_cpu(packet->rhf_addr);
760
761 return ret;
762}
763
764static inline void process_rcv_update(int last, struct hfi1_packet *packet)
765{
766 /*
767 * Update head regs etc., every 16 packets, if not last pkt,
768 * to help prevent rcvhdrq overflows, when many packets
769 * are processed and queue is nearly full.
770 * Don't request an interrupt for intermediate updates.
771 */
772 if (!last && !(packet->numpkt & 0xf)) {
773 update_usrhead(packet->rcd, packet->rhqoff, packet->updegr,
774 packet->etail, 0, 0);
775 packet->updegr = 0;
776 }
Don Hiatt90397462017-05-12 09:20:20 -0700777 packet->grh = NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400778}
779
780static inline void finish_packet(struct hfi1_packet *packet)
781{
Mike Marciniszyn77241052015-07-30 15:17:43 -0400782 /*
783 * Nothing we need to free for the packet.
784 *
785 * The only thing we need to do is a final update and call for an
786 * interrupt
787 */
788 update_usrhead(packet->rcd, packet->rcd->head, packet->updegr,
789 packet->etail, rcv_intr_dynamic, packet->numpkt);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400790}
791
Mike Marciniszyn77241052015-07-30 15:17:43 -0400792/*
793 * Handle receive interrupts when using the no dma rtail option.
794 */
Dean Luickf4f30031c2015-10-26 10:28:44 -0400795int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400796{
797 u32 seq;
Dean Luickf4f30031c2015-10-26 10:28:44 -0400798 int last = RCV_PKT_OK;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400799 struct hfi1_packet packet;
800
801 init_packet(rcd, &packet);
802 seq = rhf_rcv_seq(packet.rhf);
Dean Luickf4f30031c2015-10-26 10:28:44 -0400803 if (seq != rcd->seq_cnt) {
804 last = RCV_PKT_DONE;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400805 goto bail;
Dean Luickf4f30031c2015-10-26 10:28:44 -0400806 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400807
Vennila Megavannan6c9e50f2016-02-03 14:32:57 -0800808 prescan_rxq(rcd, &packet);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400809
Dean Luickf4f30031c2015-10-26 10:28:44 -0400810 while (last == RCV_PKT_OK) {
811 last = process_rcv_packet(&packet, thread);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400812 seq = rhf_rcv_seq(packet.rhf);
813 if (++rcd->seq_cnt > 13)
814 rcd->seq_cnt = 1;
815 if (seq != rcd->seq_cnt)
Dean Luickf4f30031c2015-10-26 10:28:44 -0400816 last = RCV_PKT_DONE;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400817 process_rcv_update(last, &packet);
818 }
Sebastian Sanchezbdaf96f2018-02-01 10:46:31 -0800819 process_rcv_qp_work(&packet);
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800820 rcd->head = packet.rhqoff;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400821bail:
822 finish_packet(&packet);
Dean Luickf4f30031c2015-10-26 10:28:44 -0400823 return last;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400824}
825
Dean Luickf4f30031c2015-10-26 10:28:44 -0400826int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd, int thread)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400827{
828 u32 hdrqtail;
Dean Luickf4f30031c2015-10-26 10:28:44 -0400829 int last = RCV_PKT_OK;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400830 struct hfi1_packet packet;
831
832 init_packet(rcd, &packet);
833 hdrqtail = get_rcvhdrtail(rcd);
Dean Luickf4f30031c2015-10-26 10:28:44 -0400834 if (packet.rhqoff == hdrqtail) {
835 last = RCV_PKT_DONE;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400836 goto bail;
Dean Luickf4f30031c2015-10-26 10:28:44 -0400837 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400838 smp_rmb(); /* prevent speculative reads of dma'ed hdrq */
839
Vennila Megavannan6c9e50f2016-02-03 14:32:57 -0800840 prescan_rxq(rcd, &packet);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400841
Dean Luickf4f30031c2015-10-26 10:28:44 -0400842 while (last == RCV_PKT_OK) {
843 last = process_rcv_packet(&packet, thread);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400844 if (packet.rhqoff == hdrqtail)
Dean Luickf4f30031c2015-10-26 10:28:44 -0400845 last = RCV_PKT_DONE;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400846 process_rcv_update(last, &packet);
847 }
Sebastian Sanchezbdaf96f2018-02-01 10:46:31 -0800848 process_rcv_qp_work(&packet);
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -0800849 rcd->head = packet.rhqoff;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400850bail:
851 finish_packet(&packet);
Dean Luickf4f30031c2015-10-26 10:28:44 -0400852 return last;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400853}
854
Michael J. Ruhle6f76222017-07-24 07:45:55 -0700855static inline void set_nodma_rtail(struct hfi1_devdata *dd, u16 ctxt)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400856{
Michael J. Ruhld295dbe2017-08-04 13:52:44 -0700857 struct hfi1_ctxtdata *rcd;
Michael J. Ruhle6f76222017-07-24 07:45:55 -0700858 u16 i;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400859
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700860 /*
861 * For dynamically allocated kernel contexts (like vnic) switch
862 * interrupt handler only for that context. Otherwise, switch
863 * interrupt handler for all statically allocated kernel contexts.
864 */
865 if (ctxt >= dd->first_dyn_alloc_ctxt) {
Michael J. Ruhld59075a2017-09-26 07:01:16 -0700866 rcd = hfi1_rcd_get_by_index_safe(dd, ctxt);
Michael J. Ruhld295dbe2017-08-04 13:52:44 -0700867 if (rcd) {
868 rcd->do_interrupt =
869 &handle_receive_interrupt_nodma_rtail;
870 hfi1_rcd_put(rcd);
871 }
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700872 return;
873 }
874
Michael J. Ruhld295dbe2017-08-04 13:52:44 -0700875 for (i = HFI1_CTRL_CTXT + 1; i < dd->first_dyn_alloc_ctxt; i++) {
876 rcd = hfi1_rcd_get_by_index(dd, i);
877 if (rcd)
878 rcd->do_interrupt =
879 &handle_receive_interrupt_nodma_rtail;
880 hfi1_rcd_put(rcd);
881 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400882}
883
Michael J. Ruhle6f76222017-07-24 07:45:55 -0700884static inline void set_dma_rtail(struct hfi1_devdata *dd, u16 ctxt)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400885{
Michael J. Ruhld295dbe2017-08-04 13:52:44 -0700886 struct hfi1_ctxtdata *rcd;
Michael J. Ruhle6f76222017-07-24 07:45:55 -0700887 u16 i;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400888
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700889 /*
890 * For dynamically allocated kernel contexts (like vnic) switch
891 * interrupt handler only for that context. Otherwise, switch
892 * interrupt handler for all statically allocated kernel contexts.
893 */
894 if (ctxt >= dd->first_dyn_alloc_ctxt) {
Michael J. Ruhld59075a2017-09-26 07:01:16 -0700895 rcd = hfi1_rcd_get_by_index_safe(dd, ctxt);
Michael J. Ruhld295dbe2017-08-04 13:52:44 -0700896 if (rcd) {
897 rcd->do_interrupt =
898 &handle_receive_interrupt_dma_rtail;
899 hfi1_rcd_put(rcd);
900 }
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700901 return;
902 }
903
Michael J. Ruhld295dbe2017-08-04 13:52:44 -0700904 for (i = HFI1_CTRL_CTXT + 1; i < dd->first_dyn_alloc_ctxt; i++) {
905 rcd = hfi1_rcd_get_by_index(dd, i);
906 if (rcd)
907 rcd->do_interrupt =
908 &handle_receive_interrupt_dma_rtail;
909 hfi1_rcd_put(rcd);
910 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400911}
912
Jim Snowfb9036d2016-01-11 18:32:21 -0500913void set_all_slowpath(struct hfi1_devdata *dd)
914{
Michael J. Ruhld295dbe2017-08-04 13:52:44 -0700915 struct hfi1_ctxtdata *rcd;
Michael J. Ruhle6f76222017-07-24 07:45:55 -0700916 u16 i;
Jim Snowfb9036d2016-01-11 18:32:21 -0500917
918 /* HFI1_CTRL_CTXT must always use the slow path interrupt handler */
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700919 for (i = HFI1_CTRL_CTXT + 1; i < dd->num_rcv_contexts; i++) {
Michael J. Ruhld295dbe2017-08-04 13:52:44 -0700920 rcd = hfi1_rcd_get_by_index(dd, i);
921 if (!rcd)
922 continue;
Niranjana Vishwanathapuracc9a97e2017-11-06 06:38:52 -0800923 if (i < dd->first_dyn_alloc_ctxt || rcd->is_vnic)
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700924 rcd->do_interrupt = &handle_receive_interrupt;
Niranjana Vishwanathapuracc9a97e2017-11-06 06:38:52 -0800925
Michael J. Ruhld295dbe2017-08-04 13:52:44 -0700926 hfi1_rcd_put(rcd);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700927 }
Jim Snowfb9036d2016-01-11 18:32:21 -0500928}
929
930static inline int set_armed_to_active(struct hfi1_ctxtdata *rcd,
Mike Marciniszync867caa2016-08-09 11:19:55 -0400931 struct hfi1_packet *packet,
Jim Snowfb9036d2016-01-11 18:32:21 -0500932 struct hfi1_devdata *dd)
933{
934 struct work_struct *lsaw = &rcd->ppd->linkstate_active_work;
Mike Marciniszyn69b9f4a2016-08-09 11:19:56 -0400935 u8 etype = rhf_rcv_type(packet->rhf);
Don Hiatt90397462017-05-12 09:20:20 -0700936 u8 sc = SC15_PACKET;
Jim Snowfb9036d2016-01-11 18:32:21 -0500937
Don Hiatt90397462017-05-12 09:20:20 -0700938 if (etype == RHF_RCV_TYPE_IB) {
939 struct ib_header *hdr = hfi1_get_msgheader(packet->rcd->dd,
940 packet->rhf_addr);
941 sc = hfi1_9B_get_sc5(hdr, packet->rhf);
Don Hiatt72c07e22017-08-04 13:53:58 -0700942 } else if (etype == RHF_RCV_TYPE_BYPASS) {
943 struct hfi1_16b_header *hdr = hfi1_get_16B_header(
944 packet->rcd->dd,
945 packet->rhf_addr);
946 sc = hfi1_16B_get_sc(hdr);
Don Hiatt90397462017-05-12 09:20:20 -0700947 }
948 if (sc != SC15_PACKET) {
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -0700949 int hwstate = driver_lstate(rcd->ppd);
Jim Snowfb9036d2016-01-11 18:32:21 -0500950
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -0700951 if (hwstate != IB_PORT_ACTIVE) {
952 dd_dev_info(dd,
953 "Unexpected link state %s\n",
954 opa_lstate_name(hwstate));
Jim Snowfb9036d2016-01-11 18:32:21 -0500955 return 0;
956 }
957
Sebastian Sanchez71d47002017-07-29 08:43:49 -0700958 queue_work(rcd->ppd->link_wq, lsaw);
Jim Snowfb9036d2016-01-11 18:32:21 -0500959 return 1;
960 }
961 return 0;
962}
963
Mike Marciniszyn77241052015-07-30 15:17:43 -0400964/*
965 * handle_receive_interrupt - receive a packet
966 * @rcd: the context
967 *
968 * Called from interrupt handler for errors or receive interrupt.
969 * This is the slow path interrupt handler.
970 */
Dean Luickf4f30031c2015-10-26 10:28:44 -0400971int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400972{
Mike Marciniszyn77241052015-07-30 15:17:43 -0400973 struct hfi1_devdata *dd = rcd->dd;
974 u32 hdrqtail;
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500975 int needset, last = RCV_PKT_OK;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400976 struct hfi1_packet packet;
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500977 int skip_pkt = 0;
978
979 /* Control context will always use the slow path interrupt handler */
980 needset = (rcd->ctxt == HFI1_CTRL_CTXT) ? 0 : 1;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400981
982 init_packet(rcd, &packet);
983
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500984 if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400985 u32 seq = rhf_rcv_seq(packet.rhf);
986
Dean Luickf4f30031c2015-10-26 10:28:44 -0400987 if (seq != rcd->seq_cnt) {
988 last = RCV_PKT_DONE;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400989 goto bail;
Dean Luickf4f30031c2015-10-26 10:28:44 -0400990 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400991 hdrqtail = 0;
992 } else {
993 hdrqtail = get_rcvhdrtail(rcd);
Dean Luickf4f30031c2015-10-26 10:28:44 -0400994 if (packet.rhqoff == hdrqtail) {
995 last = RCV_PKT_DONE;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400996 goto bail;
Dean Luickf4f30031c2015-10-26 10:28:44 -0400997 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400998 smp_rmb(); /* prevent speculative reads of dma'ed hdrq */
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500999
1000 /*
1001 * Control context can potentially receive an invalid
1002 * rhf. Drop such packets.
1003 */
1004 if (rcd->ctxt == HFI1_CTRL_CTXT) {
1005 u32 seq = rhf_rcv_seq(packet.rhf);
1006
1007 if (seq != rcd->seq_cnt)
1008 skip_pkt = 1;
1009 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04001010 }
1011
Vennila Megavannan6c9e50f2016-02-03 14:32:57 -08001012 prescan_rxq(rcd, &packet);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001013
Dean Luickf4f30031c2015-10-26 10:28:44 -04001014 while (last == RCV_PKT_OK) {
Jubin John17fb4f22016-02-14 20:21:52 -08001015 if (unlikely(dd->do_drop &&
1016 atomic_xchg(&dd->drop_packet, DROP_PACKET_OFF) ==
1017 DROP_PACKET_ON)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04001018 dd->do_drop = 0;
1019
1020 /* On to the next packet */
1021 packet.rhqoff += packet.rsize;
Jubin John50e5dcb2016-02-14 20:19:41 -08001022 packet.rhf_addr = (__le32 *)rcd->rcvhdrq +
Mike Marciniszyn77241052015-07-30 15:17:43 -04001023 packet.rhqoff +
1024 dd->rhf_offset;
1025 packet.rhf = rhf_to_cpu(packet.rhf_addr);
1026
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05001027 } else if (skip_pkt) {
1028 last = skip_rcv_packet(&packet, thread);
1029 skip_pkt = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001030 } else {
Jim Snowfb9036d2016-01-11 18:32:21 -05001031 /* Auto activate link on non-SC15 packet receive */
1032 if (unlikely(rcd->ppd->host_link_state ==
1033 HLS_UP_ARMED) &&
Mike Marciniszync867caa2016-08-09 11:19:55 -04001034 set_armed_to_active(rcd, &packet, dd))
Jim Snowfb9036d2016-01-11 18:32:21 -05001035 goto bail;
Dean Luickf4f30031c2015-10-26 10:28:44 -04001036 last = process_rcv_packet(&packet, thread);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001037 }
1038
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05001039 if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04001040 u32 seq = rhf_rcv_seq(packet.rhf);
1041
1042 if (++rcd->seq_cnt > 13)
1043 rcd->seq_cnt = 1;
1044 if (seq != rcd->seq_cnt)
Dean Luickf4f30031c2015-10-26 10:28:44 -04001045 last = RCV_PKT_DONE;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001046 if (needset) {
Jubin John17fb4f22016-02-14 20:21:52 -08001047 dd_dev_info(dd, "Switching to NO_DMA_RTAIL\n");
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001048 set_nodma_rtail(dd, rcd->ctxt);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001049 needset = 0;
1050 }
1051 } else {
1052 if (packet.rhqoff == hdrqtail)
Dean Luickf4f30031c2015-10-26 10:28:44 -04001053 last = RCV_PKT_DONE;
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -05001054 /*
1055 * Control context can potentially receive an invalid
1056 * rhf. Drop such packets.
1057 */
1058 if (rcd->ctxt == HFI1_CTRL_CTXT) {
1059 u32 seq = rhf_rcv_seq(packet.rhf);
1060
1061 if (++rcd->seq_cnt > 13)
1062 rcd->seq_cnt = 1;
1063 if (!last && (seq != rcd->seq_cnt))
1064 skip_pkt = 1;
1065 }
1066
Mike Marciniszyn77241052015-07-30 15:17:43 -04001067 if (needset) {
1068 dd_dev_info(dd,
1069 "Switching to DMA_RTAIL\n");
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001070 set_dma_rtail(dd, rcd->ctxt);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001071 needset = 0;
1072 }
1073 }
1074
1075 process_rcv_update(last, &packet);
1076 }
1077
Sebastian Sanchezbdaf96f2018-02-01 10:46:31 -08001078 process_rcv_qp_work(&packet);
Mike Marciniszyna82a7fc2017-02-08 05:26:02 -08001079 rcd->head = packet.rhqoff;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001080
1081bail:
1082 /*
1083 * Always write head at end, and setup rcv interrupt, even
1084 * if no packets were processed.
1085 */
1086 finish_packet(&packet);
Dean Luickf4f30031c2015-10-26 10:28:44 -04001087 return last;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001088}
1089
1090/*
Jim Snowfb9036d2016-01-11 18:32:21 -05001091 * We may discover in the interrupt that the hardware link state has
1092 * changed from ARMED to ACTIVE (due to the arrival of a non-SC15 packet),
1093 * and we need to update the driver's notion of the link state. We cannot
1094 * run set_link_state from interrupt context, so we queue this function on
1095 * a workqueue.
1096 *
1097 * We delay the regular interrupt processing until after the state changes
1098 * so that the link will be in the correct state by the time any application
1099 * we wake up attempts to send a reply to any message it received.
1100 * (Subsequent receive interrupts may possibly force the wakeup before we
1101 * update the link state.)
1102 *
1103 * The rcd is freed in hfi1_free_ctxtdata after hfi1_postinit_cleanup invokes
1104 * dd->f_cleanup(dd) to disable the interrupt handler and flush workqueues,
1105 * so we're safe from use-after-free of the rcd.
1106 */
1107void receive_interrupt_work(struct work_struct *work)
1108{
1109 struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
1110 linkstate_active_work);
1111 struct hfi1_devdata *dd = ppd->dd;
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07001112 struct hfi1_ctxtdata *rcd;
Michael J. Ruhle6f76222017-07-24 07:45:55 -07001113 u16 i;
Jim Snowfb9036d2016-01-11 18:32:21 -05001114
1115 /* Received non-SC15 packet implies neighbor_normal */
1116 ppd->neighbor_normal = 1;
1117 set_link_state(ppd, HLS_UP_ACTIVE);
1118
1119 /*
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001120 * Interrupt all statically allocated kernel contexts that could
1121 * have had an interrupt during auto activation.
Jim Snowfb9036d2016-01-11 18:32:21 -05001122 */
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07001123 for (i = HFI1_CTRL_CTXT; i < dd->first_dyn_alloc_ctxt; i++) {
1124 rcd = hfi1_rcd_get_by_index(dd, i);
1125 if (rcd)
1126 force_recv_intr(rcd);
1127 hfi1_rcd_put(rcd);
1128 }
Jim Snowfb9036d2016-01-11 18:32:21 -05001129}
1130
1131/*
Mike Marciniszyn77241052015-07-30 15:17:43 -04001132 * Convert a given MTU size to the on-wire MAD packet enumeration.
1133 * Return -1 if the size is invalid.
1134 */
1135int mtu_to_enum(u32 mtu, int default_if_bad)
1136{
1137 switch (mtu) {
1138 case 0: return OPA_MTU_0;
1139 case 256: return OPA_MTU_256;
1140 case 512: return OPA_MTU_512;
1141 case 1024: return OPA_MTU_1024;
1142 case 2048: return OPA_MTU_2048;
1143 case 4096: return OPA_MTU_4096;
1144 case 8192: return OPA_MTU_8192;
1145 case 10240: return OPA_MTU_10240;
1146 }
1147 return default_if_bad;
1148}
1149
1150u16 enum_to_mtu(int mtu)
1151{
1152 switch (mtu) {
1153 case OPA_MTU_0: return 0;
1154 case OPA_MTU_256: return 256;
1155 case OPA_MTU_512: return 512;
1156 case OPA_MTU_1024: return 1024;
1157 case OPA_MTU_2048: return 2048;
1158 case OPA_MTU_4096: return 4096;
1159 case OPA_MTU_8192: return 8192;
1160 case OPA_MTU_10240: return 10240;
1161 default: return 0xffff;
1162 }
1163}
1164
1165/*
1166 * set_mtu - set the MTU
1167 * @ppd: the per port data
1168 *
1169 * We can handle "any" incoming size, the issue here is whether we
1170 * need to restrict our outgoing size. We do not deal with what happens
1171 * to programs that are already running when the size changes.
1172 */
1173int set_mtu(struct hfi1_pportdata *ppd)
1174{
1175 struct hfi1_devdata *dd = ppd->dd;
1176 int i, drain, ret = 0, is_up = 0;
1177
1178 ppd->ibmtu = 0;
1179 for (i = 0; i < ppd->vls_supported; i++)
1180 if (ppd->ibmtu < dd->vld[i].mtu)
1181 ppd->ibmtu = dd->vld[i].mtu;
1182 ppd->ibmaxlen = ppd->ibmtu + lrh_max_header_bytes(ppd->dd);
1183
1184 mutex_lock(&ppd->hls_lock);
Jubin Johnd0d236e2016-02-14 20:20:15 -08001185 if (ppd->host_link_state == HLS_UP_INIT ||
1186 ppd->host_link_state == HLS_UP_ARMED ||
1187 ppd->host_link_state == HLS_UP_ACTIVE)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001188 is_up = 1;
1189
1190 drain = !is_ax(dd) && is_up;
1191
1192 if (drain)
1193 /*
1194 * MTU is specified per-VL. To ensure that no packet gets
1195 * stuck (due, e.g., to the MTU for the packet's VL being
1196 * reduced), empty the per-VL FIFOs before adjusting MTU.
1197 */
1198 ret = stop_drain_data_vls(dd);
1199
1200 if (ret) {
1201 dd_dev_err(dd, "%s: cannot stop/drain VLs - refusing to change per-VL MTUs\n",
1202 __func__);
1203 goto err;
1204 }
1205
1206 hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_MTU, 0);
1207
1208 if (drain)
1209 open_fill_data_vls(dd); /* reopen all VLs */
1210
1211err:
1212 mutex_unlock(&ppd->hls_lock);
1213
1214 return ret;
1215}
1216
1217int hfi1_set_lid(struct hfi1_pportdata *ppd, u32 lid, u8 lmc)
1218{
1219 struct hfi1_devdata *dd = ppd->dd;
1220
1221 ppd->lid = lid;
1222 ppd->lmc = lmc;
1223 hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_LIDLMC, 0);
1224
Jakub Pawlakcde10af2016-05-12 10:23:35 -07001225 dd_dev_info(dd, "port %u: got a lid: 0x%x\n", ppd->port, lid);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001226
1227 return 0;
1228}
1229
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001230void shutdown_led_override(struct hfi1_pportdata *ppd)
1231{
1232 struct hfi1_devdata *dd = ppd->dd;
1233
Easwar Hariharan409b1462016-02-26 13:33:28 -08001234 /*
Easwar Hariharan22434722016-03-07 11:35:03 -08001235 * This pairs with the memory barrier in hfi1_start_led_override to
1236 * ensure that we read the correct state of LED beaconing represented
1237 * by led_override_timer_active
Easwar Hariharan409b1462016-02-26 13:33:28 -08001238 */
Easwar Hariharan22434722016-03-07 11:35:03 -08001239 smp_rmb();
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001240 if (atomic_read(&ppd->led_override_timer_active)) {
1241 del_timer_sync(&ppd->led_override_timer);
1242 atomic_set(&ppd->led_override_timer_active, 0);
Easwar Hariharan22434722016-03-07 11:35:03 -08001243 /* Ensure the atomic_set is visible to all CPUs */
1244 smp_wmb();
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001245 }
1246
Easwar Hariharan22434722016-03-07 11:35:03 -08001247 /* Hand control of the LED to the DC for normal operation */
1248 write_csr(dd, DCC_CFG_LED_CNTRL, 0);
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001249}
Mike Marciniszyn77241052015-07-30 15:17:43 -04001250
Kees Cook80641352017-10-16 15:51:54 -07001251static void run_led_override(struct timer_list *t)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001252{
Kees Cook80641352017-10-16 15:51:54 -07001253 struct hfi1_pportdata *ppd = from_timer(ppd, t, led_override_timer);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001254 struct hfi1_devdata *dd = ppd->dd;
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001255 unsigned long timeout;
1256 int phase_idx;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001257
1258 if (!(dd->flags & HFI1_INITTED))
1259 return;
1260
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001261 phase_idx = ppd->led_override_phase & 1;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001262
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001263 setextled(dd, phase_idx);
1264
1265 timeout = ppd->led_override_vals[phase_idx];
Easwar Hariharan22434722016-03-07 11:35:03 -08001266
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001267 /* Set up for next phase */
1268 ppd->led_override_phase = !ppd->led_override_phase;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001269
Easwar Hariharan22434722016-03-07 11:35:03 -08001270 mod_timer(&ppd->led_override_timer, jiffies + timeout);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001271}
1272
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001273/*
1274 * To have the LED blink in a particular pattern, provide timeon and timeoff
Easwar Hariharan22434722016-03-07 11:35:03 -08001275 * in milliseconds.
1276 * To turn off custom blinking and return to normal operation, use
1277 * shutdown_led_override()
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001278 */
Easwar Hariharan22434722016-03-07 11:35:03 -08001279void hfi1_start_led_override(struct hfi1_pportdata *ppd, unsigned int timeon,
1280 unsigned int timeoff)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001281{
Easwar Hariharan22434722016-03-07 11:35:03 -08001282 if (!(ppd->dd->flags & HFI1_INITTED))
Mike Marciniszyn77241052015-07-30 15:17:43 -04001283 return;
1284
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001285 /* Convert to jiffies for direct use in timer */
1286 ppd->led_override_vals[0] = msecs_to_jiffies(timeoff);
1287 ppd->led_override_vals[1] = msecs_to_jiffies(timeon);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001288
Easwar Hariharan22434722016-03-07 11:35:03 -08001289 /* Arbitrarily start from LED on phase */
1290 ppd->led_override_phase = 1;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001291
1292 /*
1293 * If the timer has not already been started, do so. Use a "quick"
Easwar Hariharan22434722016-03-07 11:35:03 -08001294 * timeout so the handler will be called soon to look at our request.
Mike Marciniszyn77241052015-07-30 15:17:43 -04001295 */
Easwar Hariharan22434722016-03-07 11:35:03 -08001296 if (!timer_pending(&ppd->led_override_timer)) {
Kees Cook80641352017-10-16 15:51:54 -07001297 timer_setup(&ppd->led_override_timer, run_led_override, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001298 ppd->led_override_timer.expires = jiffies + 1;
1299 add_timer(&ppd->led_override_timer);
Easwar Hariharan22434722016-03-07 11:35:03 -08001300 atomic_set(&ppd->led_override_timer_active, 1);
1301 /* Ensure the atomic_set is visible to all CPUs */
1302 smp_wmb();
Mike Marciniszyn77241052015-07-30 15:17:43 -04001303 }
1304}
1305
1306/**
1307 * hfi1_reset_device - reset the chip if possible
1308 * @unit: the device to reset
1309 *
1310 * Whether or not reset is successful, we attempt to re-initialize the chip
1311 * (that is, much like a driver unload/reload). We clear the INITTED flag
1312 * so that the various entry points will fail until we reinitialize. For
1313 * now, we only allow this if no user contexts are open that use chip resources
1314 */
1315int hfi1_reset_device(int unit)
1316{
Michael J. Ruhle6f76222017-07-24 07:45:55 -07001317 int ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001318 struct hfi1_devdata *dd = hfi1_lookup(unit);
1319 struct hfi1_pportdata *ppd;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001320 int pidx;
1321
1322 if (!dd) {
1323 ret = -ENODEV;
1324 goto bail;
1325 }
1326
1327 dd_dev_info(dd, "Reset on unit %u requested\n", unit);
1328
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07001329 if (!dd->kregbase1 || !(dd->flags & HFI1_PRESENT)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -04001330 dd_dev_info(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08001331 "Invalid unit number %u or not initialized or not present\n",
1332 unit);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001333 ret = -ENXIO;
1334 goto bail;
1335 }
1336
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07001337 /* If there are any user/vnic contexts, we cannot reset */
1338 mutex_lock(&hfi1_mutex);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001339 if (dd->rcd)
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07001340 if (hfi1_stats.sps_ctxts) {
1341 mutex_unlock(&hfi1_mutex);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001342 ret = -EBUSY;
1343 goto bail;
1344 }
Michael J. Ruhld295dbe2017-08-04 13:52:44 -07001345 mutex_unlock(&hfi1_mutex);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001346
1347 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
1348 ppd = dd->pport + pidx;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001349
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001350 shutdown_led_override(ppd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001351 }
1352 if (dd->flags & HFI1_HAS_SEND_DMA)
1353 sdma_exit(dd);
1354
1355 hfi1_reset_cpu_counters(dd);
1356
1357 ret = hfi1_init(dd, 1);
1358
1359 if (ret)
1360 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -08001361 "Reinitialize unit %u after reset failed with %d\n",
1362 unit, ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001363 else
1364 dd_dev_info(dd, "Reinitialized unit %u after resetting\n",
Jubin John17fb4f22016-02-14 20:21:52 -08001365 unit);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001366
1367bail:
1368 return ret;
1369}
1370
Don Hiatt90397462017-05-12 09:20:20 -07001371static inline void hfi1_setup_ib_header(struct hfi1_packet *packet)
1372{
1373 packet->hdr = (struct hfi1_ib_message_header *)
1374 hfi1_get_msgheader(packet->rcd->dd,
1375 packet->rhf_addr);
1376 packet->hlen = (u8 *)packet->rhf_addr - (u8 *)packet->hdr;
1377}
1378
Don Hiatt5786adf32017-08-04 13:54:10 -07001379static int hfi1_bypass_ingress_pkt_check(struct hfi1_packet *packet)
1380{
1381 struct hfi1_pportdata *ppd = packet->rcd->ppd;
1382
1383 /* slid and dlid cannot be 0 */
1384 if ((!packet->slid) || (!packet->dlid))
1385 return -EINVAL;
1386
1387 /* Compare port lid with incoming packet dlid */
1388 if ((!(hfi1_is_16B_mcast(packet->dlid))) &&
1389 (packet->dlid !=
1390 opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE), 16B))) {
1391 if (packet->dlid != ppd->lid)
1392 return -EINVAL;
1393 }
1394
1395 /* No multicast packets with SC15 */
1396 if ((hfi1_is_16B_mcast(packet->dlid)) && (packet->sc == 0xF))
1397 return -EINVAL;
1398
1399 /* Packets with permissive DLID always on SC15 */
1400 if ((packet->dlid == opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE),
1401 16B)) &&
1402 (packet->sc != 0xF))
1403 return -EINVAL;
1404
1405 return 0;
1406}
1407
Don Hiatt90397462017-05-12 09:20:20 -07001408static int hfi1_setup_9B_packet(struct hfi1_packet *packet)
1409{
1410 struct hfi1_ibport *ibp = rcd_to_iport(packet->rcd);
1411 struct ib_header *hdr;
1412 u8 lnh;
1413
1414 hfi1_setup_ib_header(packet);
1415 hdr = packet->hdr;
1416
1417 lnh = ib_get_lnh(hdr);
1418 if (lnh == HFI1_LRH_BTH) {
1419 packet->ohdr = &hdr->u.oth;
1420 packet->grh = NULL;
1421 } else if (lnh == HFI1_LRH_GRH) {
1422 u32 vtf;
1423
1424 packet->ohdr = &hdr->u.l.oth;
1425 packet->grh = &hdr->u.l.grh;
1426 if (packet->grh->next_hdr != IB_GRH_NEXT_HDR)
1427 goto drop;
1428 vtf = be32_to_cpu(packet->grh->version_tclass_flow);
1429 if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
1430 goto drop;
1431 } else {
1432 goto drop;
1433 }
1434
1435 /* Query commonly used fields from packet header */
Don Hiatt72c07e22017-08-04 13:53:58 -07001436 packet->payload = packet->ebuf;
Don Hiatt90397462017-05-12 09:20:20 -07001437 packet->opcode = ib_bth_get_opcode(packet->ohdr);
1438 packet->slid = ib_get_slid(hdr);
1439 packet->dlid = ib_get_dlid(hdr);
Don Hiatt72c07e22017-08-04 13:53:58 -07001440 if (unlikely((packet->dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
1441 (packet->dlid != be16_to_cpu(IB_LID_PERMISSIVE))))
1442 packet->dlid += opa_get_mcast_base(OPA_MCAST_NR) -
1443 be16_to_cpu(IB_MULTICAST_LID_BASE);
Don Hiatt90397462017-05-12 09:20:20 -07001444 packet->sl = ib_get_sl(hdr);
1445 packet->sc = hfi1_9B_get_sc5(hdr, packet->rhf);
1446 packet->pad = ib_bth_get_pad(packet->ohdr);
1447 packet->extra_byte = 0;
Sebastian Sanchez6d6b8842018-02-01 10:46:23 -08001448 packet->pkey = ib_bth_get_pkey(packet->ohdr);
1449 packet->migrated = ib_bth_is_migration(packet->ohdr);
Don Hiatt90397462017-05-12 09:20:20 -07001450
1451 return 0;
1452drop:
1453 ibp->rvp.n_pkt_drops++;
1454 return -EINVAL;
1455}
1456
Don Hiatt72c07e22017-08-04 13:53:58 -07001457static int hfi1_setup_bypass_packet(struct hfi1_packet *packet)
1458{
1459 /*
1460 * Bypass packets have a different header/payload split
1461 * compared to an IB packet.
1462 * Current split is set such that 16 bytes of the actual
1463 * header is in the header buffer and the remining is in
1464 * the eager buffer. We chose 16 since hfi1 driver only
1465 * supports 16B bypass packets and we will be able to
1466 * receive the entire LRH with such a split.
1467 */
1468
1469 struct hfi1_ctxtdata *rcd = packet->rcd;
1470 struct hfi1_pportdata *ppd = rcd->ppd;
1471 struct hfi1_ibport *ibp = &ppd->ibport_data;
1472 u8 l4;
1473 u8 grh_len;
1474
1475 packet->hdr = (struct hfi1_16b_header *)
1476 hfi1_get_16B_header(packet->rcd->dd,
1477 packet->rhf_addr);
1478 packet->hlen = (u8 *)packet->rhf_addr - (u8 *)packet->hdr;
1479
1480 l4 = hfi1_16B_get_l4(packet->hdr);
1481 if (l4 == OPA_16B_L4_IB_LOCAL) {
1482 grh_len = 0;
1483 packet->ohdr = packet->ebuf;
1484 packet->grh = NULL;
1485 } else if (l4 == OPA_16B_L4_IB_GLOBAL) {
1486 u32 vtf;
1487
1488 grh_len = sizeof(struct ib_grh);
1489 packet->ohdr = packet->ebuf + grh_len;
1490 packet->grh = packet->ebuf;
1491 if (packet->grh->next_hdr != IB_GRH_NEXT_HDR)
1492 goto drop;
1493 vtf = be32_to_cpu(packet->grh->version_tclass_flow);
1494 if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
1495 goto drop;
1496 } else {
1497 goto drop;
1498 }
1499
1500 /* Query commonly used fields from packet header */
1501 packet->opcode = ib_bth_get_opcode(packet->ohdr);
Mike Marciniszyn78d36332018-02-01 10:52:35 -08001502 /* hdr_len_by_opcode already has an IB LRH factored in */
1503 packet->hlen = hdr_len_by_opcode[packet->opcode] +
1504 (LRH_16B_BYTES - LRH_9B_BYTES) + grh_len;
1505 packet->payload = packet->ebuf + packet->hlen - LRH_16B_BYTES;
Don Hiatt72c07e22017-08-04 13:53:58 -07001506 packet->slid = hfi1_16B_get_slid(packet->hdr);
1507 packet->dlid = hfi1_16B_get_dlid(packet->hdr);
1508 if (unlikely(hfi1_is_16B_mcast(packet->dlid)))
1509 packet->dlid += opa_get_mcast_base(OPA_MCAST_NR) -
1510 opa_get_lid(opa_get_mcast_base(OPA_MCAST_NR),
1511 16B);
1512 packet->sc = hfi1_16B_get_sc(packet->hdr);
1513 packet->sl = ibp->sc_to_sl[packet->sc];
1514 packet->pad = hfi1_16B_bth_get_pad(packet->ohdr);
1515 packet->extra_byte = SIZE_OF_LT;
Sebastian Sanchez6d6b8842018-02-01 10:46:23 -08001516 packet->pkey = hfi1_16B_get_pkey(packet->hdr);
1517 packet->migrated = opa_bth_is_migration(packet->ohdr);
Don Hiatt72c07e22017-08-04 13:53:58 -07001518
Don Hiatt5786adf32017-08-04 13:54:10 -07001519 if (hfi1_bypass_ingress_pkt_check(packet))
1520 goto drop;
1521
Don Hiatt72c07e22017-08-04 13:53:58 -07001522 return 0;
1523drop:
1524 hfi1_cdbg(PKT, "%s: packet dropped\n", __func__);
1525 ibp->rvp.n_pkt_drops++;
1526 return -EINVAL;
1527}
1528
Mike Marciniszyn77241052015-07-30 15:17:43 -04001529void handle_eflags(struct hfi1_packet *packet)
1530{
1531 struct hfi1_ctxtdata *rcd = packet->rcd;
1532 u32 rte = rhf_rcv_type_err(packet->rhf);
1533
Mike Marciniszyn77241052015-07-30 15:17:43 -04001534 rcv_hdrerr(rcd, rcd->ppd, packet);
Ignacio Hernandeza03a03e2015-11-06 20:07:03 -05001535 if (rhf_err_flags(packet->rhf))
1536 dd_dev_err(rcd->dd,
1537 "receive context %d: rhf 0x%016llx, errs [ %s%s%s%s%s%s%s%s] rte 0x%x\n",
1538 rcd->ctxt, packet->rhf,
1539 packet->rhf & RHF_K_HDR_LEN_ERR ? "k_hdr_len " : "",
1540 packet->rhf & RHF_DC_UNC_ERR ? "dc_unc " : "",
1541 packet->rhf & RHF_DC_ERR ? "dc " : "",
1542 packet->rhf & RHF_TID_ERR ? "tid " : "",
1543 packet->rhf & RHF_LEN_ERR ? "len " : "",
1544 packet->rhf & RHF_ECC_ERR ? "ecc " : "",
1545 packet->rhf & RHF_VCRC_ERR ? "vcrc " : "",
1546 packet->rhf & RHF_ICRC_ERR ? "icrc " : "",
1547 rte);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001548}
1549
1550/*
1551 * The following functions are called by the interrupt handler. They are type
1552 * specific handlers for each packet type.
1553 */
1554int process_receive_ib(struct hfi1_packet *packet)
1555{
Don Hiatt0181ce32017-03-20 17:26:14 -07001556 if (unlikely(hfi1_dbg_fault_packet(packet)))
1557 return RHF_RCV_CONTINUE;
1558
Don Hiatt90397462017-05-12 09:20:20 -07001559 if (hfi1_setup_9B_packet(packet))
1560 return RHF_RCV_CONTINUE;
1561
Don Hiatt6197a812018-02-01 12:38:48 -08001562 trace_hfi1_rcvhdr(packet);
Don Hiatt243d9f42017-03-20 17:26:20 -07001563
Mike Marciniszyn77241052015-07-30 15:17:43 -04001564 if (unlikely(rhf_err_flags(packet->rhf))) {
1565 handle_eflags(packet);
1566 return RHF_RCV_CONTINUE;
1567 }
1568
1569 hfi1_ib_rcv(packet);
1570 return RHF_RCV_CONTINUE;
1571}
1572
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -07001573static inline bool hfi1_is_vnic_packet(struct hfi1_packet *packet)
1574{
1575 /* Packet received in VNIC context via RSM */
1576 if (packet->rcd->is_vnic)
1577 return true;
1578
Don Hiatt72c07e22017-08-04 13:53:58 -07001579 if ((hfi1_16B_get_l2(packet->ebuf) == OPA_16B_L2_TYPE) &&
1580 (hfi1_16B_get_l4(packet->ebuf) == OPA_16B_L4_ETHR))
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -07001581 return true;
1582
1583 return false;
1584}
1585
Mike Marciniszyn77241052015-07-30 15:17:43 -04001586int process_receive_bypass(struct hfi1_packet *packet)
1587{
Jakub Pawlak505efe32016-10-25 13:12:17 -07001588 struct hfi1_devdata *dd = packet->rcd->dd;
1589
Don Hiatt72c07e22017-08-04 13:53:58 -07001590 if (hfi1_is_vnic_packet(packet)) {
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -07001591 hfi1_vnic_bypass_rcv(packet);
1592 return RHF_RCV_CONTINUE;
1593 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04001594
Don Hiatt72c07e22017-08-04 13:53:58 -07001595 if (hfi1_setup_bypass_packet(packet))
1596 return RHF_RCV_CONTINUE;
Jakub Pawlak505efe32016-10-25 13:12:17 -07001597
Don Hiatt6197a812018-02-01 12:38:48 -08001598 trace_hfi1_rcvhdr(packet);
1599
Don Hiatt72c07e22017-08-04 13:53:58 -07001600 if (unlikely(rhf_err_flags(packet->rhf))) {
1601 handle_eflags(packet);
1602 return RHF_RCV_CONTINUE;
1603 }
1604
1605 if (hfi1_16B_get_l2(packet->hdr) == 0x2) {
1606 hfi1_16B_rcv(packet);
1607 } else {
1608 dd_dev_err(dd,
1609 "Bypass packets other than 16B are not supported in normal operation. Dropping\n");
1610 incr_cntr64(&dd->sw_rcv_bypass_packet_errors);
1611 if (!(dd->err_info_rcvport.status_and_code &
1612 OPA_EI_STATUS_SMASK)) {
1613 u64 *flits = packet->ebuf;
1614
1615 if (flits && !(packet->rhf & RHF_LEN_ERR)) {
1616 dd->err_info_rcvport.packet_flit1 = flits[0];
1617 dd->err_info_rcvport.packet_flit2 =
1618 packet->tlen > sizeof(flits[0]) ?
1619 flits[1] : 0;
1620 }
1621 dd->err_info_rcvport.status_and_code |=
1622 (OPA_EI_STATUS_SMASK | BAD_L2_ERR);
Jakub Pawlak505efe32016-10-25 13:12:17 -07001623 }
Jakub Pawlak505efe32016-10-25 13:12:17 -07001624 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04001625 return RHF_RCV_CONTINUE;
1626}
1627
1628int process_receive_error(struct hfi1_packet *packet)
1629{
Don Hiatt243d9f42017-03-20 17:26:20 -07001630 /* KHdrHCRCErr -- KDETH packet with a bad HCRC */
1631 if (unlikely(
1632 hfi1_dbg_fault_suppress_err(&packet->rcd->dd->verbs_dev) &&
1633 rhf_rcv_type_err(packet->rhf) == 3))
1634 return RHF_RCV_CONTINUE;
1635
Don Hiatt90397462017-05-12 09:20:20 -07001636 hfi1_setup_ib_header(packet);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001637 handle_eflags(packet);
1638
1639 if (unlikely(rhf_err_flags(packet->rhf)))
1640 dd_dev_err(packet->rcd->dd,
1641 "Unhandled error packet received. Dropping.\n");
1642
1643 return RHF_RCV_CONTINUE;
1644}
1645
1646int kdeth_process_expected(struct hfi1_packet *packet)
1647{
Don Hiatt0181ce32017-03-20 17:26:14 -07001648 if (unlikely(hfi1_dbg_fault_packet(packet)))
1649 return RHF_RCV_CONTINUE;
Don Hiatt90397462017-05-12 09:20:20 -07001650
1651 hfi1_setup_ib_header(packet);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001652 if (unlikely(rhf_err_flags(packet->rhf)))
1653 handle_eflags(packet);
1654
1655 dd_dev_err(packet->rcd->dd,
1656 "Unhandled expected packet received. Dropping.\n");
1657 return RHF_RCV_CONTINUE;
1658}
1659
1660int kdeth_process_eager(struct hfi1_packet *packet)
1661{
Don Hiatt90397462017-05-12 09:20:20 -07001662 hfi1_setup_ib_header(packet);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001663 if (unlikely(rhf_err_flags(packet->rhf)))
1664 handle_eflags(packet);
Don Hiatt0181ce32017-03-20 17:26:14 -07001665 if (unlikely(hfi1_dbg_fault_packet(packet)))
1666 return RHF_RCV_CONTINUE;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001667
1668 dd_dev_err(packet->rcd->dd,
1669 "Unhandled eager packet received. Dropping.\n");
1670 return RHF_RCV_CONTINUE;
1671}
1672
1673int process_receive_invalid(struct hfi1_packet *packet)
1674{
1675 dd_dev_err(packet->rcd->dd, "Invalid packet type %d. Dropping\n",
Jubin John17fb4f22016-02-14 20:21:52 -08001676 rhf_rcv_type(packet->rhf));
Mike Marciniszyn77241052015-07-30 15:17:43 -04001677 return RHF_RCV_CONTINUE;
1678}
Kaike Wanbf808b52017-08-13 08:09:04 -07001679
1680void seqfile_dump_rcd(struct seq_file *s, struct hfi1_ctxtdata *rcd)
1681{
1682 struct hfi1_packet packet;
1683 struct ps_mdata mdata;
1684
1685 seq_printf(s, "Rcd %u: RcvHdr cnt %u entsize %u %s head %llu tail %llu\n",
1686 rcd->ctxt, rcd->rcvhdrq_cnt, rcd->rcvhdrqentsize,
1687 HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ?
1688 "dma_rtail" : "nodma_rtail",
1689 read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD) &
1690 RCV_HDR_HEAD_HEAD_MASK,
1691 read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL));
1692
1693 init_packet(rcd, &packet);
1694 init_ps_mdata(&mdata, &packet);
1695
1696 while (1) {
1697 struct hfi1_devdata *dd = rcd->dd;
1698 __le32 *rhf_addr = (__le32 *)rcd->rcvhdrq + mdata.ps_head +
1699 dd->rhf_offset;
1700 struct ib_header *hdr;
1701 u64 rhf = rhf_to_cpu(rhf_addr);
1702 u32 etype = rhf_rcv_type(rhf), qpn;
1703 u8 opcode;
1704 u32 psn;
1705 u8 lnh;
1706
1707 if (ps_done(&mdata, rhf, rcd))
1708 break;
1709
1710 if (ps_skip(&mdata, rhf, rcd))
1711 goto next;
1712
1713 if (etype > RHF_RCV_TYPE_IB)
1714 goto next;
1715
1716 packet.hdr = hfi1_get_msgheader(dd, rhf_addr);
1717 hdr = packet.hdr;
1718
1719 lnh = be16_to_cpu(hdr->lrh[0]) & 3;
1720
1721 if (lnh == HFI1_LRH_BTH)
1722 packet.ohdr = &hdr->u.oth;
1723 else if (lnh == HFI1_LRH_GRH)
1724 packet.ohdr = &hdr->u.l.oth;
1725 else
1726 goto next; /* just in case */
1727
1728 opcode = (be32_to_cpu(packet.ohdr->bth[0]) >> 24);
1729 qpn = be32_to_cpu(packet.ohdr->bth[1]) & RVT_QPN_MASK;
1730 psn = mask_psn(be32_to_cpu(packet.ohdr->bth[2]));
1731
1732 seq_printf(s, "\tEnt %u: opcode 0x%x, qpn 0x%x, psn 0x%x\n",
1733 mdata.ps_head, opcode, qpn, psn);
1734next:
1735 update_ps_mdata(&mdata, rcd);
1736 }
1737}