blob: 8887a71edb98b37e4e0ad248ba2930350046c6e3 [file] [log] [blame]
Mike Marciniszyn77241052015-07-30 15:17:43 -04001/*
Mitko Haralanova74d5302018-05-02 06:43:24 -07002 * Copyright(c) 2015 - 2018 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 <rdma/ib_mad.h>
49#include <rdma/ib_user_verbs.h>
50#include <linux/io.h>
51#include <linux/module.h>
52#include <linux/utsname.h>
53#include <linux/rculist.h>
54#include <linux/mm.h>
Mike Marciniszyn77241052015-07-30 15:17:43 -040055#include <linux/vmalloc.h>
Don Hiatt13c19222017-08-04 13:53:51 -070056#include <rdma/opa_addr.h>
Mike Marciniszyn77241052015-07-30 15:17:43 -040057
58#include "hfi.h"
59#include "common.h"
60#include "device.h"
61#include "trace.h"
62#include "qp.h"
Mike Marciniszyn45842ab2016-02-14 12:44:34 -080063#include "verbs_txreq.h"
Don Hiatt0181ce32017-03-20 17:26:14 -070064#include "debugfs.h"
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070065#include "vnic.h"
Mitko Haralanova74d5302018-05-02 06:43:24 -070066#include "fault.h"
Sebastian Sanchez5d18ee62018-05-02 06:43:55 -070067#include "affinity.h"
Mike Marciniszyn77241052015-07-30 15:17:43 -040068
Dennis Dalessandro895420d2016-01-19 14:42:28 -080069static unsigned int hfi1_lkey_table_size = 16;
Mike Marciniszyn77241052015-07-30 15:17:43 -040070module_param_named(lkey_table_size, hfi1_lkey_table_size, uint,
71 S_IRUGO);
72MODULE_PARM_DESC(lkey_table_size,
73 "LKEY table size in bits (2^n, 1 <= n <= 23)");
74
75static unsigned int hfi1_max_pds = 0xFFFF;
76module_param_named(max_pds, hfi1_max_pds, uint, S_IRUGO);
77MODULE_PARM_DESC(max_pds,
78 "Maximum number of protection domains to support");
79
80static unsigned int hfi1_max_ahs = 0xFFFF;
81module_param_named(max_ahs, hfi1_max_ahs, uint, S_IRUGO);
82MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support");
83
Jianxin Xiongf6aa78352016-09-25 07:41:18 -070084unsigned int hfi1_max_cqes = 0x2FFFFF;
Mike Marciniszyn77241052015-07-30 15:17:43 -040085module_param_named(max_cqes, hfi1_max_cqes, uint, S_IRUGO);
86MODULE_PARM_DESC(max_cqes,
87 "Maximum number of completion queue entries to support");
88
89unsigned int hfi1_max_cqs = 0x1FFFF;
90module_param_named(max_cqs, hfi1_max_cqs, uint, S_IRUGO);
91MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support");
92
93unsigned int hfi1_max_qp_wrs = 0x3FFF;
94module_param_named(max_qp_wrs, hfi1_max_qp_wrs, uint, S_IRUGO);
95MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support");
96
Jianxin Xiongf6aa78352016-09-25 07:41:18 -070097unsigned int hfi1_max_qps = 32768;
Mike Marciniszyn77241052015-07-30 15:17:43 -040098module_param_named(max_qps, hfi1_max_qps, uint, S_IRUGO);
99MODULE_PARM_DESC(max_qps, "Maximum number of QPs to support");
100
101unsigned int hfi1_max_sges = 0x60;
102module_param_named(max_sges, hfi1_max_sges, uint, S_IRUGO);
103MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support");
104
105unsigned int hfi1_max_mcast_grps = 16384;
106module_param_named(max_mcast_grps, hfi1_max_mcast_grps, uint, S_IRUGO);
107MODULE_PARM_DESC(max_mcast_grps,
108 "Maximum number of multicast groups to support");
109
110unsigned int hfi1_max_mcast_qp_attached = 16;
111module_param_named(max_mcast_qp_attached, hfi1_max_mcast_qp_attached,
112 uint, S_IRUGO);
113MODULE_PARM_DESC(max_mcast_qp_attached,
114 "Maximum number of attached QPs to support");
115
116unsigned int hfi1_max_srqs = 1024;
117module_param_named(max_srqs, hfi1_max_srqs, uint, S_IRUGO);
118MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support");
119
120unsigned int hfi1_max_srq_sges = 128;
121module_param_named(max_srq_sges, hfi1_max_srq_sges, uint, S_IRUGO);
122MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support");
123
124unsigned int hfi1_max_srq_wrs = 0x1FFFF;
125module_param_named(max_srq_wrs, hfi1_max_srq_wrs, uint, S_IRUGO);
126MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support");
127
Mike Marciniszynd0e859c2016-03-07 11:35:46 -0800128unsigned short piothreshold = 256;
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800129module_param(piothreshold, ushort, S_IRUGO);
130MODULE_PARM_DESC(piothreshold, "size used to determine sdma vs. pio");
131
Dean Luick528ee9f2016-03-05 08:50:43 -0800132static unsigned int sge_copy_mode;
133module_param(sge_copy_mode, uint, S_IRUGO);
134MODULE_PARM_DESC(sge_copy_mode,
135 "Verbs copy mode: 0 use memcpy, 1 use cacheless copy, 2 adapt based on WSS");
136
Mike Marciniszyn77241052015-07-30 15:17:43 -0400137static void verbs_sdma_complete(
138 struct sdma_txreq *cookie,
Mike Marciniszyna545f532016-02-14 12:45:53 -0800139 int status);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400140
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800141static int pio_wait(struct rvt_qp *qp,
142 struct send_context *sc,
143 struct hfi1_pkt_state *ps,
144 u32 flag);
145
Jubin John64ffd862015-10-26 10:28:47 -0400146/* Length of buffer to create verbs txreq cache name */
147#define TXREQ_NAME_LEN 24
148
Don Hiattf8195f32017-10-09 12:38:19 -0700149/* 16B trailing buffer */
150static const u8 trail_buf[MAX_16B_PADDING];
151
Brian Welty019f1182018-09-26 10:44:33 -0700152static uint wss_threshold = 80;
Dean Luick528ee9f2016-03-05 08:50:43 -0800153module_param(wss_threshold, uint, S_IRUGO);
154MODULE_PARM_DESC(wss_threshold, "Percentage (1-100) of LLC to use as a threshold for a cacheless copy");
155static uint wss_clean_period = 256;
156module_param(wss_clean_period, uint, S_IRUGO);
157MODULE_PARM_DESC(wss_clean_period, "Count of verbs copies before an entry in the page copy table is cleaned");
158
Mike Marciniszyn77241052015-07-30 15:17:43 -0400159/*
Mike Marciniszyn43a474a2017-03-20 17:25:04 -0700160 * Translate ib_wr_opcode into ib_wc_opcode.
161 */
162const enum ib_wc_opcode ib_hfi1_wc_opcode[] = {
163 [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
164 [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
165 [IB_WR_SEND] = IB_WC_SEND,
166 [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
167 [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
168 [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
169 [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD,
170 [IB_WR_SEND_WITH_INV] = IB_WC_SEND,
171 [IB_WR_LOCAL_INV] = IB_WC_LOCAL_INV,
172 [IB_WR_REG_MR] = IB_WC_REG_MR
173};
174
175/*
Mike Marciniszyn77241052015-07-30 15:17:43 -0400176 * Length of header by opcode, 0 --> not supported
177 */
178const u8 hdr_len_by_opcode[256] = {
179 /* RC */
180 [IB_OPCODE_RC_SEND_FIRST] = 12 + 8,
181 [IB_OPCODE_RC_SEND_MIDDLE] = 12 + 8,
182 [IB_OPCODE_RC_SEND_LAST] = 12 + 8,
183 [IB_OPCODE_RC_SEND_LAST_WITH_IMMEDIATE] = 12 + 8 + 4,
184 [IB_OPCODE_RC_SEND_ONLY] = 12 + 8,
185 [IB_OPCODE_RC_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 4,
186 [IB_OPCODE_RC_RDMA_WRITE_FIRST] = 12 + 8 + 16,
187 [IB_OPCODE_RC_RDMA_WRITE_MIDDLE] = 12 + 8,
188 [IB_OPCODE_RC_RDMA_WRITE_LAST] = 12 + 8,
189 [IB_OPCODE_RC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = 12 + 8 + 4,
190 [IB_OPCODE_RC_RDMA_WRITE_ONLY] = 12 + 8 + 16,
191 [IB_OPCODE_RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = 12 + 8 + 20,
192 [IB_OPCODE_RC_RDMA_READ_REQUEST] = 12 + 8 + 16,
193 [IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST] = 12 + 8 + 4,
194 [IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE] = 12 + 8,
195 [IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST] = 12 + 8 + 4,
196 [IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY] = 12 + 8 + 4,
197 [IB_OPCODE_RC_ACKNOWLEDGE] = 12 + 8 + 4,
Mike Marciniszyn37aab622016-09-30 20:11:15 -0700198 [IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE] = 12 + 8 + 4 + 8,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400199 [IB_OPCODE_RC_COMPARE_SWAP] = 12 + 8 + 28,
200 [IB_OPCODE_RC_FETCH_ADD] = 12 + 8 + 28,
Jianxin Xiongbdd8a982016-05-24 12:50:17 -0700201 [IB_OPCODE_RC_SEND_LAST_WITH_INVALIDATE] = 12 + 8 + 4,
202 [IB_OPCODE_RC_SEND_ONLY_WITH_INVALIDATE] = 12 + 8 + 4,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400203 /* UC */
204 [IB_OPCODE_UC_SEND_FIRST] = 12 + 8,
205 [IB_OPCODE_UC_SEND_MIDDLE] = 12 + 8,
206 [IB_OPCODE_UC_SEND_LAST] = 12 + 8,
207 [IB_OPCODE_UC_SEND_LAST_WITH_IMMEDIATE] = 12 + 8 + 4,
208 [IB_OPCODE_UC_SEND_ONLY] = 12 + 8,
209 [IB_OPCODE_UC_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 4,
210 [IB_OPCODE_UC_RDMA_WRITE_FIRST] = 12 + 8 + 16,
211 [IB_OPCODE_UC_RDMA_WRITE_MIDDLE] = 12 + 8,
212 [IB_OPCODE_UC_RDMA_WRITE_LAST] = 12 + 8,
213 [IB_OPCODE_UC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = 12 + 8 + 4,
214 [IB_OPCODE_UC_RDMA_WRITE_ONLY] = 12 + 8 + 16,
215 [IB_OPCODE_UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = 12 + 8 + 20,
216 /* UD */
217 [IB_OPCODE_UD_SEND_ONLY] = 12 + 8 + 8,
218 [IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 12
219};
220
221static const opcode_handler opcode_handler_tbl[256] = {
222 /* RC */
223 [IB_OPCODE_RC_SEND_FIRST] = &hfi1_rc_rcv,
224 [IB_OPCODE_RC_SEND_MIDDLE] = &hfi1_rc_rcv,
225 [IB_OPCODE_RC_SEND_LAST] = &hfi1_rc_rcv,
226 [IB_OPCODE_RC_SEND_LAST_WITH_IMMEDIATE] = &hfi1_rc_rcv,
227 [IB_OPCODE_RC_SEND_ONLY] = &hfi1_rc_rcv,
228 [IB_OPCODE_RC_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_rc_rcv,
229 [IB_OPCODE_RC_RDMA_WRITE_FIRST] = &hfi1_rc_rcv,
230 [IB_OPCODE_RC_RDMA_WRITE_MIDDLE] = &hfi1_rc_rcv,
231 [IB_OPCODE_RC_RDMA_WRITE_LAST] = &hfi1_rc_rcv,
232 [IB_OPCODE_RC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = &hfi1_rc_rcv,
233 [IB_OPCODE_RC_RDMA_WRITE_ONLY] = &hfi1_rc_rcv,
234 [IB_OPCODE_RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = &hfi1_rc_rcv,
235 [IB_OPCODE_RC_RDMA_READ_REQUEST] = &hfi1_rc_rcv,
236 [IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST] = &hfi1_rc_rcv,
237 [IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE] = &hfi1_rc_rcv,
238 [IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST] = &hfi1_rc_rcv,
239 [IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY] = &hfi1_rc_rcv,
240 [IB_OPCODE_RC_ACKNOWLEDGE] = &hfi1_rc_rcv,
241 [IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE] = &hfi1_rc_rcv,
242 [IB_OPCODE_RC_COMPARE_SWAP] = &hfi1_rc_rcv,
243 [IB_OPCODE_RC_FETCH_ADD] = &hfi1_rc_rcv,
Jianxin Xionga2df0c82016-07-25 13:38:31 -0700244 [IB_OPCODE_RC_SEND_LAST_WITH_INVALIDATE] = &hfi1_rc_rcv,
245 [IB_OPCODE_RC_SEND_ONLY_WITH_INVALIDATE] = &hfi1_rc_rcv,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400246 /* UC */
247 [IB_OPCODE_UC_SEND_FIRST] = &hfi1_uc_rcv,
248 [IB_OPCODE_UC_SEND_MIDDLE] = &hfi1_uc_rcv,
249 [IB_OPCODE_UC_SEND_LAST] = &hfi1_uc_rcv,
250 [IB_OPCODE_UC_SEND_LAST_WITH_IMMEDIATE] = &hfi1_uc_rcv,
251 [IB_OPCODE_UC_SEND_ONLY] = &hfi1_uc_rcv,
252 [IB_OPCODE_UC_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_uc_rcv,
253 [IB_OPCODE_UC_RDMA_WRITE_FIRST] = &hfi1_uc_rcv,
254 [IB_OPCODE_UC_RDMA_WRITE_MIDDLE] = &hfi1_uc_rcv,
255 [IB_OPCODE_UC_RDMA_WRITE_LAST] = &hfi1_uc_rcv,
256 [IB_OPCODE_UC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = &hfi1_uc_rcv,
257 [IB_OPCODE_UC_RDMA_WRITE_ONLY] = &hfi1_uc_rcv,
258 [IB_OPCODE_UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = &hfi1_uc_rcv,
259 /* UD */
260 [IB_OPCODE_UD_SEND_ONLY] = &hfi1_ud_rcv,
261 [IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_ud_rcv,
262 /* CNP */
263 [IB_OPCODE_CNP] = &hfi1_cnp_rcv
264};
265
Mike Marciniszynb374e062016-09-25 07:40:58 -0700266#define OPMASK 0x1f
267
268static const u32 pio_opmask[BIT(3)] = {
269 /* RC */
270 [IB_OPCODE_RC >> 5] =
271 BIT(RC_OP(SEND_ONLY) & OPMASK) |
272 BIT(RC_OP(SEND_ONLY_WITH_IMMEDIATE) & OPMASK) |
273 BIT(RC_OP(RDMA_WRITE_ONLY) & OPMASK) |
274 BIT(RC_OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE) & OPMASK) |
275 BIT(RC_OP(RDMA_READ_REQUEST) & OPMASK) |
276 BIT(RC_OP(ACKNOWLEDGE) & OPMASK) |
277 BIT(RC_OP(ATOMIC_ACKNOWLEDGE) & OPMASK) |
278 BIT(RC_OP(COMPARE_SWAP) & OPMASK) |
279 BIT(RC_OP(FETCH_ADD) & OPMASK),
280 /* UC */
281 [IB_OPCODE_UC >> 5] =
282 BIT(UC_OP(SEND_ONLY) & OPMASK) |
283 BIT(UC_OP(SEND_ONLY_WITH_IMMEDIATE) & OPMASK) |
284 BIT(UC_OP(RDMA_WRITE_ONLY) & OPMASK) |
285 BIT(UC_OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE) & OPMASK),
286};
287
Mike Marciniszyn77241052015-07-30 15:17:43 -0400288/*
289 * System image GUID.
290 */
291__be64 ib_hfi1_sys_image_guid;
292
Mike Marciniszyn77241052015-07-30 15:17:43 -0400293/*
294 * Make sure the QP is ready and able to accept the given opcode.
295 */
Don Hiatt90397462017-05-12 09:20:20 -0700296static inline opcode_handler qp_ok(struct hfi1_packet *packet)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400297{
Dennis Dalessandro83693bd2016-01-19 14:43:33 -0800298 if (!(ib_rvt_state_ops[packet->qp->state] & RVT_PROCESS_RECV_OK))
Jakub Pawlak71e68e32016-07-01 16:02:02 -0700299 return NULL;
Don Hiatt90397462017-05-12 09:20:20 -0700300 if (((packet->opcode & RVT_OPCODE_QP_MASK) ==
301 packet->qp->allowed_ops) ||
302 (packet->opcode == IB_OPCODE_CNP))
303 return opcode_handler_tbl[packet->opcode];
Jakub Pawlak71e68e32016-07-01 16:02:02 -0700304
305 return NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400306}
307
Don Hiatt243d9f42017-03-20 17:26:20 -0700308static u64 hfi1_fault_tx(struct rvt_qp *qp, u8 opcode, u64 pbc)
309{
310#ifdef CONFIG_FAULT_INJECTION
Kaike Wan6b6cf932019-01-23 19:30:51 -0800311 if ((opcode & IB_OPCODE_MSP) == IB_OPCODE_MSP) {
Don Hiatt243d9f42017-03-20 17:26:20 -0700312 /*
313 * In order to drop non-IB traffic we
314 * set PbcInsertHrc to NONE (0x2).
315 * The packet will still be delivered
316 * to the receiving node but a
317 * KHdrHCRCErr (KDETH packet with a bad
318 * HCRC) will be triggered and the
319 * packet will not be delivered to the
320 * correct context.
321 */
Kaike Wan6b6cf932019-01-23 19:30:51 -0800322 pbc &= ~PBC_INSERT_HCRC_SMASK;
Don Hiatt243d9f42017-03-20 17:26:20 -0700323 pbc |= (u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT;
Kaike Wan6b6cf932019-01-23 19:30:51 -0800324 } else {
Don Hiatt243d9f42017-03-20 17:26:20 -0700325 /*
326 * In order to drop regular verbs
327 * traffic we set the PbcTestEbp
328 * flag. The packet will still be
329 * delivered to the receiving node but
330 * a 'late ebp error' will be
331 * triggered and will be dropped.
332 */
333 pbc |= PBC_TEST_EBP;
Kaike Wan6b6cf932019-01-23 19:30:51 -0800334 }
Don Hiatt243d9f42017-03-20 17:26:20 -0700335#endif
336 return pbc;
337}
338
Don Hiatt5786adf32017-08-04 13:54:10 -0700339static int hfi1_do_pkey_check(struct hfi1_packet *packet)
340{
341 struct hfi1_ctxtdata *rcd = packet->rcd;
342 struct hfi1_pportdata *ppd = rcd->ppd;
343 struct hfi1_16b_header *hdr = packet->hdr;
344 u16 pkey;
345
346 /* Pkey check needed only for bypass packets */
347 if (packet->etype != RHF_RCV_TYPE_BYPASS)
348 return 0;
349
350 /* Perform pkey check */
351 pkey = hfi1_16B_get_pkey(hdr);
352 return ingress_pkey_check(ppd, pkey, packet->sc,
353 packet->qp->s_pkey_index,
354 packet->slid, true);
355}
356
Don Hiatt90397462017-05-12 09:20:20 -0700357static inline void hfi1_handle_packet(struct hfi1_packet *packet,
358 bool is_mcast)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400359{
Don Hiatt90397462017-05-12 09:20:20 -0700360 u32 qp_num;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400361 struct hfi1_ctxtdata *rcd = packet->rcd;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400362 struct hfi1_pportdata *ppd = rcd->ppd;
Sebastian Sanchezf3e862c2017-02-08 05:26:25 -0800363 struct hfi1_ibport *ibp = rcd_to_iport(rcd);
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800364 struct rvt_dev_info *rdi = &ppd->dd->verbs_dev.rdi;
Jakub Pawlak71e68e32016-07-01 16:02:02 -0700365 opcode_handler packet_handler;
Dean Luickb77d7132015-10-26 10:28:43 -0400366 unsigned long flags;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400367
Don Hiatt90397462017-05-12 09:20:20 -0700368 inc_opstats(packet->tlen, &rcd->opstats->stats[packet->opcode]);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400369
Don Hiatt90397462017-05-12 09:20:20 -0700370 if (unlikely(is_mcast)) {
Dennis Dalessandro0facc5a2016-01-19 14:43:39 -0800371 struct rvt_mcast *mcast;
372 struct rvt_mcast_qp *p;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400373
Don Hiatt90397462017-05-12 09:20:20 -0700374 if (!packet->grh)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400375 goto drop;
Don Hiatt90397462017-05-12 09:20:20 -0700376 mcast = rvt_mcast_find(&ibp->rvp,
377 &packet->grh->dgid,
Don Hiatt72c07e22017-08-04 13:53:58 -0700378 opa_get_lid(packet->dlid, 9B));
Jubin Johnd125a6c2016-02-14 20:19:49 -0800379 if (!mcast)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400380 goto drop;
381 list_for_each_entry_rcu(p, &mcast->qp_list, list) {
382 packet->qp = p->qp;
Don Hiatt5786adf32017-08-04 13:54:10 -0700383 if (hfi1_do_pkey_check(packet))
384 goto drop;
Dean Luickb77d7132015-10-26 10:28:43 -0400385 spin_lock_irqsave(&packet->qp->r_lock, flags);
Don Hiatt90397462017-05-12 09:20:20 -0700386 packet_handler = qp_ok(packet);
Jakub Pawlak71e68e32016-07-01 16:02:02 -0700387 if (likely(packet_handler))
388 packet_handler(packet);
389 else
390 ibp->rvp.n_pkt_drops++;
Dean Luickb77d7132015-10-26 10:28:43 -0400391 spin_unlock_irqrestore(&packet->qp->r_lock, flags);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400392 }
393 /*
Dennis Dalessandro0facc5a2016-01-19 14:43:39 -0800394 * Notify rvt_multicast_detach() if it is waiting for us
Mike Marciniszyn77241052015-07-30 15:17:43 -0400395 * to finish.
396 */
397 if (atomic_dec_return(&mcast->refcount) <= 1)
398 wake_up(&mcast->wait);
399 } else {
Don Hiatt90397462017-05-12 09:20:20 -0700400 /* Get the destination QP number. */
Don Hiatt81cd3892018-05-15 18:28:15 -0700401 if (packet->etype == RHF_RCV_TYPE_BYPASS &&
402 hfi1_16B_get_l4(packet->hdr) == OPA_16B_L4_FM)
403 qp_num = hfi1_16B_get_dest_qpn(packet->mgmt);
404 else
405 qp_num = ib_bth_get_qpn(packet->ohdr);
406
Mike Marciniszyn77241052015-07-30 15:17:43 -0400407 rcu_read_lock();
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800408 packet->qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
Don Hiatt5786adf32017-08-04 13:54:10 -0700409 if (!packet->qp)
410 goto unlock_drop;
411
412 if (hfi1_do_pkey_check(packet))
413 goto unlock_drop;
414
Dean Luickb77d7132015-10-26 10:28:43 -0400415 spin_lock_irqsave(&packet->qp->r_lock, flags);
Don Hiatt90397462017-05-12 09:20:20 -0700416 packet_handler = qp_ok(packet);
Jakub Pawlak71e68e32016-07-01 16:02:02 -0700417 if (likely(packet_handler))
418 packet_handler(packet);
419 else
420 ibp->rvp.n_pkt_drops++;
Dean Luickb77d7132015-10-26 10:28:43 -0400421 spin_unlock_irqrestore(&packet->qp->r_lock, flags);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400422 rcu_read_unlock();
423 }
424 return;
Don Hiatt5786adf32017-08-04 13:54:10 -0700425unlock_drop:
426 rcu_read_unlock();
Mike Marciniszyn77241052015-07-30 15:17:43 -0400427drop:
Dennis Dalessandro4eb06882016-01-19 14:42:39 -0800428 ibp->rvp.n_pkt_drops++;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400429}
430
Don Hiatt90397462017-05-12 09:20:20 -0700431/**
432 * hfi1_ib_rcv - process an incoming packet
433 * @packet: data packet information
434 *
435 * This is called to process an incoming packet at interrupt level.
436 */
437void hfi1_ib_rcv(struct hfi1_packet *packet)
438{
439 struct hfi1_ctxtdata *rcd = packet->rcd;
Don Hiatt90397462017-05-12 09:20:20 -0700440
Don Hiatt72c07e22017-08-04 13:53:58 -0700441 trace_input_ibhdr(rcd->dd, packet, !!(rhf_dc_info(packet->rhf)));
442 hfi1_handle_packet(packet, hfi1_check_mcast(packet->dlid));
443}
Don Hiatt90397462017-05-12 09:20:20 -0700444
Don Hiatt72c07e22017-08-04 13:53:58 -0700445void hfi1_16B_rcv(struct hfi1_packet *packet)
446{
447 struct hfi1_ctxtdata *rcd = packet->rcd;
448
449 trace_input_ibhdr(rcd->dd, packet, false);
450 hfi1_handle_packet(packet, hfi1_check_mcast(packet->dlid));
Don Hiatt90397462017-05-12 09:20:20 -0700451}
452
Mike Marciniszyn77241052015-07-30 15:17:43 -0400453/*
454 * This is called from a timer to check for QPs
455 * which need kernel memory in order to send a packet.
456 */
Kees Cook80641352017-10-16 15:51:54 -0700457static void mem_timer(struct timer_list *t)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400458{
Kees Cook80641352017-10-16 15:51:54 -0700459 struct hfi1_ibdev *dev = from_timer(dev, t, mem_timer);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400460 struct list_head *list = &dev->memwait;
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800461 struct rvt_qp *qp = NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400462 struct iowait *wait;
463 unsigned long flags;
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800464 struct hfi1_qp_priv *priv;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400465
466 write_seqlock_irqsave(&dev->iowait_lock, flags);
467 if (!list_empty(list)) {
468 wait = list_first_entry(list, struct iowait, list);
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800469 qp = iowait_to_qp(wait);
470 priv = qp->priv;
471 list_del_init(&priv->s_iowait.list);
Mike Marciniszyn4e045572016-10-10 06:14:28 -0700472 priv->s_iowait.lock = NULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400473 /* refcount held until actual wake up */
474 if (!list_empty(list))
475 mod_timer(&dev->mem_timer, jiffies + 1);
476 }
477 write_sequnlock_irqrestore(&dev->iowait_lock, flags);
478
479 if (qp)
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800480 hfi1_qp_wakeup(qp, RVT_S_WAIT_KMEM);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400481}
482
Mike Marciniszyn77241052015-07-30 15:17:43 -0400483/*
484 * This is called with progress side lock held.
485 */
486/* New API */
487static void verbs_sdma_complete(
488 struct sdma_txreq *cookie,
Mike Marciniszyna545f532016-02-14 12:45:53 -0800489 int status)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400490{
491 struct verbs_txreq *tx =
492 container_of(cookie, struct verbs_txreq, txreq);
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800493 struct rvt_qp *qp = tx->qp;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400494
495 spin_lock(&qp->s_lock);
Jubin Johne4909742016-02-14 20:22:00 -0800496 if (tx->wqe) {
Venkata Sandeep Dhanalakota116aa032018-09-26 10:44:42 -0700497 rvt_send_complete(qp, tx->wqe, IB_WC_SUCCESS);
Jubin Johne4909742016-02-14 20:22:00 -0800498 } else if (qp->ibqp.qp_type == IB_QPT_RC) {
Don Hiatt30e07412017-08-04 13:54:04 -0700499 struct hfi1_opa_header *hdr;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400500
501 hdr = &tx->phdr.hdr;
502 hfi1_rc_send_complete(qp, hdr);
503 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400504 spin_unlock(&qp->s_lock);
505
506 hfi1_put_txreq(tx);
507}
508
Kaike Wan838b6fd2019-01-23 19:30:07 -0800509void hfi1_wait_kmem(struct rvt_qp *qp)
510{
511 struct hfi1_qp_priv *priv = qp->priv;
512 struct ib_qp *ibqp = &qp->ibqp;
513 struct ib_device *ibdev = ibqp->device;
514 struct hfi1_ibdev *dev = to_idev(ibdev);
515
516 if (list_empty(&priv->s_iowait.list)) {
517 if (list_empty(&dev->memwait))
518 mod_timer(&dev->mem_timer, jiffies + 1);
519 qp->s_flags |= RVT_S_WAIT_KMEM;
520 list_add_tail(&priv->s_iowait.list, &dev->memwait);
521 priv->s_iowait.lock = &dev->iowait_lock;
522 trace_hfi1_qpsleep(qp, RVT_S_WAIT_KMEM);
523 rvt_get_qp(qp);
524 }
525}
526
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800527static int wait_kmem(struct hfi1_ibdev *dev,
528 struct rvt_qp *qp,
529 struct hfi1_pkt_state *ps)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400530{
531 unsigned long flags;
532 int ret = 0;
533
534 spin_lock_irqsave(&qp->s_lock, flags);
Dennis Dalessandro83693bd2016-01-19 14:43:33 -0800535 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400536 write_seqlock(&dev->iowait_lock);
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800537 list_add_tail(&ps->s_txreq->txreq.list,
Dennis Dalessandro5da0fc92018-09-28 07:17:09 -0700538 &ps->wait->tx_head);
Kaike Wan838b6fd2019-01-23 19:30:07 -0800539 hfi1_wait_kmem(qp);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400540 write_sequnlock(&dev->iowait_lock);
Dennis Dalessandro5da0fc92018-09-28 07:17:09 -0700541 hfi1_qp_unbusy(qp, ps->wait);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400542 ret = -EBUSY;
543 }
544 spin_unlock_irqrestore(&qp->s_lock, flags);
545
546 return ret;
547}
548
549/*
550 * This routine calls txadds for each sg entry.
551 *
552 * Add failures will revert the sge cursor
553 */
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800554static noinline int build_verbs_ulp_payload(
Mike Marciniszyn77241052015-07-30 15:17:43 -0400555 struct sdma_engine *sde,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400556 u32 length,
557 struct verbs_txreq *tx)
558{
Mitko Haralanovb777f152016-12-07 19:33:27 -0800559 struct rvt_sge_state *ss = tx->ss;
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800560 struct rvt_sge *sg_list = ss->sg_list;
561 struct rvt_sge sge = ss->sge;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400562 u8 num_sge = ss->num_sge;
563 u32 len;
564 int ret = 0;
565
566 while (length) {
Michael J. Ruhl87fc34b2019-01-23 19:08:19 -0800567 len = rvt_get_sge_length(&ss->sge, length);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400568 WARN_ON_ONCE(len == 0);
569 ret = sdma_txadd_kvaddr(
570 sde->dd,
571 &tx->txreq,
572 ss->sge.vaddr,
573 len);
574 if (ret)
575 goto bail_txadd;
Brian Welty1198fce2017-02-08 05:27:37 -0800576 rvt_update_sge(ss, len, false);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400577 length -= len;
578 }
579 return ret;
580bail_txadd:
581 /* unwind cursor */
582 ss->sge = sge;
583 ss->num_sge = num_sge;
584 ss->sg_list = sg_list;
585 return ret;
586}
587
Mike Marciniszyn1b311f82017-10-23 06:06:08 -0700588/**
589 * update_tx_opstats - record stats by opcode
590 * @qp; the qp
591 * @ps: transmit packet state
592 * @plen: the plen in dwords
593 *
594 * This is a routine to record the tx opstats after a
595 * packet has been presented to the egress mechanism.
596 */
597static void update_tx_opstats(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
598 u32 plen)
599{
600#ifdef CONFIG_DEBUG_FS
601 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
602 struct hfi1_opcode_stats_perctx *s = get_cpu_ptr(dd->tx_opstats);
603
604 inc_opstats(plen * 4, &s->stats[ps->opcode]);
605 put_cpu_ptr(s);
606#endif
607}
608
Mike Marciniszyn77241052015-07-30 15:17:43 -0400609/*
610 * Build the number of DMA descriptors needed to send length bytes of data.
611 *
612 * NOTE: DMA mapping is held in the tx until completed in the ring or
613 * the tx desc is freed without having been submitted to the ring
614 *
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800615 * This routine ensures all the helper routine calls succeed.
Mike Marciniszyn77241052015-07-30 15:17:43 -0400616 */
617/* New API */
618static int build_verbs_tx_desc(
619 struct sdma_engine *sde,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400620 u32 length,
621 struct verbs_txreq *tx,
Dasaratharaman Chandramoulia9b6b3b2016-07-25 13:40:16 -0700622 struct hfi1_ahg_info *ahg_info,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400623 u64 pbc)
624{
625 int ret = 0;
Don Hiattd4d602e2016-07-25 13:40:22 -0700626 struct hfi1_sdma_header *phdr = &tx->phdr;
Mitko Haralanov96362582018-02-01 10:46:07 -0800627 u16 hdrbytes = (tx->hdr_dwords + sizeof(pbc) / 4) << 2;
Don Hiatt566d53a2017-08-04 13:54:47 -0700628 u8 extra_bytes = 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400629
Don Hiatt566d53a2017-08-04 13:54:47 -0700630 if (tx->phdr.hdr.hdr_type) {
631 /*
632 * hdrbytes accounts for PBC. Need to subtract 8 bytes
633 * before calculating padding.
634 */
635 extra_bytes = hfi1_get_16b_padding(hdrbytes - 8, length) +
636 (SIZE_OF_CRC << 2) + SIZE_OF_LT;
Don Hiatt566d53a2017-08-04 13:54:47 -0700637 }
Dasaratharaman Chandramoulia9b6b3b2016-07-25 13:40:16 -0700638 if (!ahg_info->ahgcount) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400639 ret = sdma_txinit_ahg(
640 &tx->txreq,
Dasaratharaman Chandramoulia9b6b3b2016-07-25 13:40:16 -0700641 ahg_info->tx_flags,
Don Hiatt566d53a2017-08-04 13:54:47 -0700642 hdrbytes + length +
643 extra_bytes,
Dasaratharaman Chandramoulia9b6b3b2016-07-25 13:40:16 -0700644 ahg_info->ahgidx,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400645 0,
646 NULL,
647 0,
648 verbs_sdma_complete);
649 if (ret)
650 goto bail_txadd;
651 phdr->pbc = cpu_to_le64(pbc);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400652 ret = sdma_txadd_kvaddr(
653 sde->dd,
654 &tx->txreq,
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800655 phdr,
656 hdrbytes);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400657 if (ret)
658 goto bail_txadd;
659 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400660 ret = sdma_txinit_ahg(
661 &tx->txreq,
Dasaratharaman Chandramoulia9b6b3b2016-07-25 13:40:16 -0700662 ahg_info->tx_flags,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400663 length,
Dasaratharaman Chandramoulia9b6b3b2016-07-25 13:40:16 -0700664 ahg_info->ahgidx,
665 ahg_info->ahgcount,
666 ahg_info->ahgdesc,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400667 hdrbytes,
668 verbs_sdma_complete);
669 if (ret)
670 goto bail_txadd;
671 }
Mitko Haralanovb777f152016-12-07 19:33:27 -0800672 /* add the ulp payload - if any. tx->ss can be NULL for acks */
Don Hiatt566d53a2017-08-04 13:54:47 -0700673 if (tx->ss) {
Mitko Haralanovb777f152016-12-07 19:33:27 -0800674 ret = build_verbs_ulp_payload(sde, length, tx);
Don Hiatt566d53a2017-08-04 13:54:47 -0700675 if (ret)
676 goto bail_txadd;
677 }
678
679 /* add icrc, lt byte, and padding to flit */
Don Hiattf8195f32017-10-09 12:38:19 -0700680 if (extra_bytes)
Don Hiatt566d53a2017-08-04 13:54:47 -0700681 ret = sdma_txadd_kvaddr(sde->dd, &tx->txreq,
Don Hiattf8195f32017-10-09 12:38:19 -0700682 (void *)trail_buf, extra_bytes);
Don Hiatt566d53a2017-08-04 13:54:47 -0700683
Mike Marciniszyn77241052015-07-30 15:17:43 -0400684bail_txadd:
685 return ret;
686}
687
Kaike Wan6b6cf932019-01-23 19:30:51 -0800688static u64 update_hcrc(u8 opcode, u64 pbc)
689{
690 if ((opcode & IB_OPCODE_TID_RDMA) == IB_OPCODE_TID_RDMA) {
691 pbc &= ~PBC_INSERT_HCRC_SMASK;
692 pbc |= (u64)PBC_IHCRC_LKDETH << PBC_INSERT_HCRC_SHIFT;
693 }
694 return pbc;
695}
696
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800697int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
Dennis Dalessandrod46e5142015-11-11 00:34:37 -0500698 u64 pbc)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400699{
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800700 struct hfi1_qp_priv *priv = qp->priv;
Dasaratharaman Chandramoulia9b6b3b2016-07-25 13:40:16 -0700701 struct hfi1_ahg_info *ahg_info = priv->s_ahg;
Mitko Haralanov96362582018-02-01 10:46:07 -0800702 u32 hdrwords = ps->s_txreq->hdr_dwords;
Don Hiatte922ae02016-12-07 19:33:00 -0800703 u32 len = ps->s_txreq->s_cur_size;
Don Hiatt566d53a2017-08-04 13:54:47 -0700704 u32 plen;
Dennis Dalessandrod46e5142015-11-11 00:34:37 -0500705 struct hfi1_ibdev *dev = ps->dev;
706 struct hfi1_pportdata *ppd = ps->ppd;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400707 struct verbs_txreq *tx;
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800708 u8 sc5 = priv->s_sc;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400709 int ret;
Don Hiatt566d53a2017-08-04 13:54:47 -0700710 u32 dwords;
Don Hiatt566d53a2017-08-04 13:54:47 -0700711
712 if (ps->s_txreq->phdr.hdr.hdr_type) {
713 u8 extra_bytes = hfi1_get_16b_padding((hdrwords << 2), len);
714
715 dwords = (len + extra_bytes + (SIZE_OF_CRC << 2) +
716 SIZE_OF_LT) >> 2;
Don Hiatt566d53a2017-08-04 13:54:47 -0700717 } else {
718 dwords = (len + 3) >> 2;
719 }
Mitko Haralanov96362582018-02-01 10:46:07 -0800720 plen = hdrwords + dwords + sizeof(pbc) / 4;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400721
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800722 tx = ps->s_txreq;
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800723 if (!sdma_txreq_built(&tx->txreq)) {
724 if (likely(pbc == 0)) {
725 u32 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5);
Don Hiatt243d9f42017-03-20 17:26:20 -0700726
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800727 /* No vl15 here */
Don Hiatt566d53a2017-08-04 13:54:47 -0700728 /* set PBC_DC_INFO bit (aka SC[4]) in pbc */
729 if (ps->s_txreq->phdr.hdr.hdr_type)
730 pbc |= PBC_PACKET_BYPASS |
731 PBC_INSERT_BYPASS_ICRC;
732 else
733 pbc |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT);
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800734
Mitko Haralanova74d5302018-05-02 06:43:24 -0700735 if (unlikely(hfi1_dbg_should_fault_tx(qp, ps->opcode)))
Don Hiatt566d53a2017-08-04 13:54:47 -0700736 pbc = hfi1_fault_tx(qp, ps->opcode, pbc);
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800737 pbc = create_pbc(ppd,
Don Hiatt243d9f42017-03-20 17:26:20 -0700738 pbc,
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800739 qp->srate_mbps,
740 vl,
741 plen);
Kaike Wan6b6cf932019-01-23 19:30:51 -0800742
743 /* Update HCRC based on packet opcode */
744 pbc = update_hcrc(ps->opcode, pbc);
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800745 }
746 tx->wqe = qp->s_wqe;
Mitko Haralanovb777f152016-12-07 19:33:27 -0800747 ret = build_verbs_tx_desc(tx->sde, len, tx, ahg_info, pbc);
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800748 if (unlikely(ret))
749 goto bail_build;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400750 }
Dennis Dalessandro5da0fc92018-09-28 07:17:09 -0700751 ret = sdma_send_txreq(tx->sde, ps->wait, &tx->txreq, ps->pkts_sent);
Mike Marciniszyn5326dfb2016-03-07 11:35:24 -0800752 if (unlikely(ret < 0)) {
753 if (ret == -ECOMM)
754 goto bail_ecomm;
755 return ret;
756 }
Mike Marciniszyn1b311f82017-10-23 06:06:08 -0700757
758 update_tx_opstats(qp, ps, plen);
Mike Marciniszyn1db78ee2016-03-07 11:35:19 -0800759 trace_sdma_output_ibhdr(dd_from_ibdev(qp->ibqp.device),
Don Hiatt228d2af2017-05-12 09:20:08 -0700760 &ps->s_txreq->phdr.hdr, ib_is_sc5(sc5));
Mike Marciniszyn77241052015-07-30 15:17:43 -0400761 return ret;
762
Mike Marciniszyn77241052015-07-30 15:17:43 -0400763bail_ecomm:
764 /* The current one got "sent" */
765 return 0;
766bail_build:
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800767 ret = wait_kmem(dev, qp, ps);
768 if (!ret) {
769 /* free txreq - bad state */
770 hfi1_put_txreq(ps->s_txreq);
771 ps->s_txreq = NULL;
772 }
773 return ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400774}
775
776/*
777 * If we are now in the error state, return zero to flush the
778 * send work request.
779 */
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800780static int pio_wait(struct rvt_qp *qp,
781 struct send_context *sc,
782 struct hfi1_pkt_state *ps,
783 u32 flag)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400784{
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800785 struct hfi1_qp_priv *priv = qp->priv;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400786 struct hfi1_devdata *dd = sc->dd;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400787 unsigned long flags;
788 int ret = 0;
789
790 /*
791 * Note that as soon as want_buffer() is called and
792 * possibly before it returns, sc_piobufavail()
793 * could be called. Therefore, put QP on the I/O wait list before
794 * enabling the PIO avail interrupt.
795 */
796 spin_lock_irqsave(&qp->s_lock, flags);
Dennis Dalessandro83693bd2016-01-19 14:43:33 -0800797 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
Mike Marciniszyn9aefcabe2018-11-28 10:33:00 -0800798 write_seqlock(&sc->waitlock);
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800799 list_add_tail(&ps->s_txreq->txreq.list,
Dennis Dalessandro5da0fc92018-09-28 07:17:09 -0700800 &ps->wait->tx_head);
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800801 if (list_empty(&priv->s_iowait.list)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400802 struct hfi1_ibdev *dev = &dd->verbs_dev;
803 int was_empty;
804
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800805 dev->n_piowait += !!(flag & RVT_S_WAIT_PIO);
Mike Marciniszyn2e2ba092018-06-04 11:44:02 -0700806 dev->n_piodrain += !!(flag & HFI1_S_WAIT_PIO_DRAIN);
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800807 qp->s_flags |= flag;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400808 was_empty = list_empty(&sc->piowait);
Kaike Wanbcad2912017-07-24 07:45:37 -0700809 iowait_queue(ps->pkts_sent, &priv->s_iowait,
810 &sc->piowait);
Mike Marciniszyn9aefcabe2018-11-28 10:33:00 -0800811 priv->s_iowait.lock = &sc->waitlock;
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800812 trace_hfi1_qpsleep(qp, RVT_S_WAIT_PIO);
Mike Marciniszyn4d6f85c2016-09-06 04:34:35 -0700813 rvt_get_qp(qp);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400814 /* counting: only call wantpiobuf_intr if first user */
815 if (was_empty)
816 hfi1_sc_wantpiobuf_intr(sc, 1);
817 }
Mike Marciniszyn9aefcabe2018-11-28 10:33:00 -0800818 write_sequnlock(&sc->waitlock);
Dennis Dalessandro5da0fc92018-09-28 07:17:09 -0700819 hfi1_qp_unbusy(qp, ps->wait);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400820 ret = -EBUSY;
821 }
822 spin_unlock_irqrestore(&qp->s_lock, flags);
823 return ret;
824}
825
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800826static void verbs_pio_complete(void *arg, int code)
827{
828 struct rvt_qp *qp = (struct rvt_qp *)arg;
829 struct hfi1_qp_priv *priv = qp->priv;
830
831 if (iowait_pio_dec(&priv->s_iowait))
832 iowait_drain_wakeup(&priv->s_iowait);
833}
834
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800835int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
Dennis Dalessandrod46e5142015-11-11 00:34:37 -0500836 u64 pbc)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400837{
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800838 struct hfi1_qp_priv *priv = qp->priv;
Mitko Haralanov96362582018-02-01 10:46:07 -0800839 u32 hdrwords = ps->s_txreq->hdr_dwords;
Mitko Haralanovb777f152016-12-07 19:33:27 -0800840 struct rvt_sge_state *ss = ps->s_txreq->ss;
Don Hiatte922ae02016-12-07 19:33:00 -0800841 u32 len = ps->s_txreq->s_cur_size;
Don Hiatt566d53a2017-08-04 13:54:47 -0700842 u32 dwords;
843 u32 plen;
Dennis Dalessandrod46e5142015-11-11 00:34:37 -0500844 struct hfi1_pportdata *ppd = ps->ppd;
Don Hiatt566d53a2017-08-04 13:54:47 -0700845 u32 *hdr;
Mike Marciniszyn4f8cc5c2016-02-14 12:45:27 -0800846 u8 sc5;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400847 unsigned long flags = 0;
848 struct send_context *sc;
849 struct pio_buf *pbuf;
850 int wc_status = IB_WC_SUCCESS;
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800851 int ret = 0;
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800852 pio_release_cb cb = NULL;
Don Hiatt566d53a2017-08-04 13:54:47 -0700853 u8 extra_bytes = 0;
854
855 if (ps->s_txreq->phdr.hdr.hdr_type) {
856 u8 pad_size = hfi1_get_16b_padding((hdrwords << 2), len);
857
858 extra_bytes = pad_size + (SIZE_OF_CRC << 2) + SIZE_OF_LT;
859 dwords = (len + extra_bytes) >> 2;
860 hdr = (u32 *)&ps->s_txreq->phdr.hdr.opah;
Don Hiatt566d53a2017-08-04 13:54:47 -0700861 } else {
862 dwords = (len + 3) >> 2;
863 hdr = (u32 *)&ps->s_txreq->phdr.hdr.ibh;
864 }
Mitko Haralanov96362582018-02-01 10:46:07 -0800865 plen = hdrwords + dwords + sizeof(pbc) / 4;
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800866
867 /* only RC/UC use complete */
868 switch (qp->ibqp.qp_type) {
869 case IB_QPT_RC:
870 case IB_QPT_UC:
871 cb = verbs_pio_complete;
872 break;
873 default:
874 break;
875 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400876
877 /* vl15 special case taken care of in ud.c */
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800878 sc5 = priv->s_sc;
Mike Marciniszyncef504c2016-03-07 11:35:35 -0800879 sc = ps->s_txreq->psc;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400880
Mike Marciniszyn77241052015-07-30 15:17:43 -0400881 if (likely(pbc == 0)) {
Mike Marciniszyn4f8cc5c2016-02-14 12:45:27 -0800882 u8 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5);
Don Hiatt243d9f42017-03-20 17:26:20 -0700883
Don Hiatt566d53a2017-08-04 13:54:47 -0700884 /* set PBC_DC_INFO bit (aka SC[4]) in pbc */
885 if (ps->s_txreq->phdr.hdr.hdr_type)
886 pbc |= PBC_PACKET_BYPASS | PBC_INSERT_BYPASS_ICRC;
887 else
888 pbc |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT);
Mitko Haralanova74d5302018-05-02 06:43:24 -0700889
890 if (unlikely(hfi1_dbg_should_fault_tx(qp, ps->opcode)))
Don Hiatt566d53a2017-08-04 13:54:47 -0700891 pbc = hfi1_fault_tx(qp, ps->opcode, pbc);
Don Hiatt243d9f42017-03-20 17:26:20 -0700892 pbc = create_pbc(ppd, pbc, qp->srate_mbps, vl, plen);
Kaike Wan6b6cf932019-01-23 19:30:51 -0800893
894 /* Update HCRC based on packet opcode */
895 pbc = update_hcrc(ps->opcode, pbc);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400896 }
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800897 if (cb)
898 iowait_pio_inc(&priv->s_iowait);
899 pbuf = sc_buffer_alloc(sc, plen, cb, qp);
Jubin Johnd125a6c2016-02-14 20:19:49 -0800900 if (unlikely(!pbuf)) {
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800901 if (cb)
902 verbs_pio_complete(qp, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400903 if (ppd->host_link_state != HLS_UP_ACTIVE) {
904 /*
905 * If we have filled the PIO buffers to capacity and are
906 * not in an active state this request is not going to
907 * go out to so just complete it with an error or else a
908 * ULP or the core may be stuck waiting.
909 */
910 hfi1_cdbg(
911 PIO,
912 "alloc failed. state not active, completing");
913 wc_status = IB_WC_GENERAL_ERR;
914 goto pio_bail;
915 } else {
916 /*
917 * This is a normal occurrence. The PIO buffs are full
918 * up but we are still happily sending, well we could be
919 * so lets continue to queue the request.
920 */
921 hfi1_cdbg(PIO, "alloc failed. state active, queuing");
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800922 ret = pio_wait(qp, sc, ps, RVT_S_WAIT_PIO);
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800923 if (!ret)
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800924 /* txreq not queued - free */
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800925 goto bail;
926 /* tx consumed in wait */
927 return ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400928 }
929 }
930
Don Hiatt566d53a2017-08-04 13:54:47 -0700931 if (dwords == 0) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400932 pio_copy(ppd->dd, pbuf, pbc, hdr, hdrwords);
933 } else {
Don Hiatt566d53a2017-08-04 13:54:47 -0700934 seg_pio_copy_start(pbuf, pbc,
935 hdr, hdrwords * 4);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400936 if (ss) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400937 while (len) {
938 void *addr = ss->sge.vaddr;
Michael J. Ruhl87fc34b2019-01-23 19:08:19 -0800939 u32 slen = rvt_get_sge_length(&ss->sge, len);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400940
Brian Welty1198fce2017-02-08 05:27:37 -0800941 rvt_update_sge(ss, slen, false);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400942 seg_pio_copy_mid(pbuf, addr, slen);
943 len -= slen;
944 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400945 }
Don Hiattf8195f32017-10-09 12:38:19 -0700946 /* add icrc, lt byte, and padding to flit */
947 if (extra_bytes)
948 seg_pio_copy_mid(pbuf, trail_buf, extra_bytes);
Don Hiatt566d53a2017-08-04 13:54:47 -0700949
Don Hiatt566d53a2017-08-04 13:54:47 -0700950 seg_pio_copy_end(pbuf);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400951 }
952
Mike Marciniszyn1b311f82017-10-23 06:06:08 -0700953 update_tx_opstats(qp, ps, plen);
Mike Marciniszyn1db78ee2016-03-07 11:35:19 -0800954 trace_pio_output_ibhdr(dd_from_ibdev(qp->ibqp.device),
Don Hiatt228d2af2017-05-12 09:20:08 -0700955 &ps->s_txreq->phdr.hdr, ib_is_sc5(sc5));
Mike Marciniszyn77241052015-07-30 15:17:43 -0400956
Mike Marciniszyn77241052015-07-30 15:17:43 -0400957pio_bail:
958 if (qp->s_wqe) {
959 spin_lock_irqsave(&qp->s_lock, flags);
Venkata Sandeep Dhanalakota116aa032018-09-26 10:44:42 -0700960 rvt_send_complete(qp, qp->s_wqe, wc_status);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400961 spin_unlock_irqrestore(&qp->s_lock, flags);
962 } else if (qp->ibqp.qp_type == IB_QPT_RC) {
963 spin_lock_irqsave(&qp->s_lock, flags);
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800964 hfi1_rc_send_complete(qp, &ps->s_txreq->phdr.hdr);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400965 spin_unlock_irqrestore(&qp->s_lock, flags);
966 }
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800967
968 ret = 0;
969
970bail:
971 hfi1_put_txreq(ps->s_txreq);
972 return ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400973}
Geliang Tangb91cc572015-09-21 23:39:08 +0800974
Mike Marciniszyn77241052015-07-30 15:17:43 -0400975/*
976 * egress_pkey_matches_entry - return 1 if the pkey matches ent (ent
Sebastian Sancheze38d1e42016-04-12 11:22:21 -0700977 * being an entry from the partition key table), return 0
Mike Marciniszyn77241052015-07-30 15:17:43 -0400978 * otherwise. Use the matching criteria for egress partition keys
979 * specified in the OPAv1 spec., section 9.1l.7.
980 */
981static inline int egress_pkey_matches_entry(u16 pkey, u16 ent)
982{
983 u16 mkey = pkey & PKEY_LOW_15_MASK;
Sebastian Sancheze38d1e42016-04-12 11:22:21 -0700984 u16 mentry = ent & PKEY_LOW_15_MASK;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400985
Sebastian Sancheze38d1e42016-04-12 11:22:21 -0700986 if (mkey == mentry) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400987 /*
988 * If pkey[15] is set (full partition member),
989 * is bit 15 in the corresponding table element
990 * clear (limited member)?
991 */
992 if (pkey & PKEY_MEMBER_MASK)
993 return !!(ent & PKEY_MEMBER_MASK);
994 return 1;
995 }
996 return 0;
997}
998
Sebastian Sancheze38d1e42016-04-12 11:22:21 -0700999/**
1000 * egress_pkey_check - check P_KEY of a packet
Don Hiatt566d53a2017-08-04 13:54:47 -07001001 * @ppd: Physical IB port data
1002 * @slid: SLID for packet
1003 * @bkey: PKEY for header
1004 * @sc5: SC for packet
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001005 * @s_pkey_index: It will be used for look up optimization for kernel contexts
1006 * only. If it is negative value, then it means user contexts is calling this
1007 * function.
1008 *
1009 * It checks if hdr's pkey is valid.
1010 *
1011 * Return: 0 on success, otherwise, 1
Mike Marciniszyn77241052015-07-30 15:17:43 -04001012 */
Don Hiatt566d53a2017-08-04 13:54:47 -07001013int egress_pkey_check(struct hfi1_pportdata *ppd, u32 slid, u16 pkey,
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001014 u8 sc5, int8_t s_pkey_index)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001015{
Mike Marciniszyn77241052015-07-30 15:17:43 -04001016 struct hfi1_devdata *dd;
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001017 int i;
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001018 int is_user_ctxt_mechanism = (s_pkey_index < 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001019
1020 if (!(ppd->part_enforce & HFI1_PART_ENFORCE_OUT))
1021 return 0;
1022
Mike Marciniszyn77241052015-07-30 15:17:43 -04001023 /* If SC15, pkey[0:14] must be 0x7fff */
1024 if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
1025 goto bad;
1026
Mike Marciniszyn77241052015-07-30 15:17:43 -04001027 /* Is the pkey = 0x0, or 0x8000? */
1028 if ((pkey & PKEY_LOW_15_MASK) == 0)
1029 goto bad;
1030
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001031 /*
1032 * For the kernel contexts only, if a qp is passed into the function,
1033 * the most likely matching pkey has index qp->s_pkey_index
1034 */
1035 if (!is_user_ctxt_mechanism &&
1036 egress_pkey_matches_entry(pkey, ppd->pkeys[s_pkey_index])) {
1037 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001038 }
1039
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001040 for (i = 0; i < MAX_PKEY_VALUES; i++) {
1041 if (egress_pkey_matches_entry(pkey, ppd->pkeys[i]))
1042 return 0;
1043 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04001044bad:
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001045 /*
1046 * For the user-context mechanism, the P_KEY check would only happen
1047 * once per SDMA request, not once per packet. Therefore, there's no
1048 * need to increment the counter for the user-context mechanism.
1049 */
1050 if (!is_user_ctxt_mechanism) {
1051 incr_cntr64(&ppd->port_xmit_constraint_errors);
1052 dd = ppd->dd;
1053 if (!(dd->err_info_xmit_constraint.status &
1054 OPA_EI_STATUS_SMASK)) {
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001055 dd->err_info_xmit_constraint.status |=
1056 OPA_EI_STATUS_SMASK;
1057 dd->err_info_xmit_constraint.slid = slid;
1058 dd->err_info_xmit_constraint.pkey = pkey;
1059 }
Mike Marciniszyn77241052015-07-30 15:17:43 -04001060 }
1061 return 1;
1062}
1063
1064/**
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001065 * get_send_routine - choose an egress routine
1066 *
1067 * Choose an egress routine based on QP type
1068 * and size
1069 */
1070static inline send_routine get_send_routine(struct rvt_qp *qp,
Don Hiatt566d53a2017-08-04 13:54:47 -07001071 struct hfi1_pkt_state *ps)
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001072{
1073 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
1074 struct hfi1_qp_priv *priv = qp->priv;
Don Hiatt566d53a2017-08-04 13:54:47 -07001075 struct verbs_txreq *tx = ps->s_txreq;
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001076
1077 if (unlikely(!(dd->flags & HFI1_HAS_SEND_DMA)))
1078 return dd->process_pio_send;
1079 switch (qp->ibqp.qp_type) {
1080 case IB_QPT_SMI:
1081 return dd->process_pio_send;
1082 case IB_QPT_GSI:
1083 case IB_QPT_UD:
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001084 break;
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001085 case IB_QPT_UC:
Mike Marciniszynb374e062016-09-25 07:40:58 -07001086 case IB_QPT_RC: {
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001087 if (piothreshold &&
Don Hiatte922ae02016-12-07 19:33:00 -08001088 tx->s_cur_size <= min(piothreshold, qp->pmtu) &&
Don Hiatt566d53a2017-08-04 13:54:47 -07001089 (BIT(ps->opcode & OPMASK) & pio_opmask[ps->opcode >> 5]) &&
Mike Marciniszyn47177f12016-03-07 11:35:41 -08001090 iowait_sdma_pending(&priv->s_iowait) == 0 &&
1091 !sdma_txreq_built(&tx->txreq))
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001092 return dd->process_pio_send;
1093 break;
Mike Marciniszynb374e062016-09-25 07:40:58 -07001094 }
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001095 default:
1096 break;
1097 }
1098 return dd->process_dma_send;
1099}
1100
1101/**
Mike Marciniszyn77241052015-07-30 15:17:43 -04001102 * hfi1_verbs_send - send a packet
1103 * @qp: the QP to send on
Dennis Dalessandrod46e5142015-11-11 00:34:37 -05001104 * @ps: the state of the packet to send
Mike Marciniszyn77241052015-07-30 15:17:43 -04001105 *
1106 * Return zero if packet is sent or queued OK.
Dennis Dalessandro54d10c12016-01-19 14:43:01 -08001107 * Return non-zero and clear qp->s_flags RVT_S_BUSY otherwise.
Mike Marciniszyn77241052015-07-30 15:17:43 -04001108 */
Dennis Dalessandro895420d2016-01-19 14:42:28 -08001109int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001110{
1111 struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
Mike Marciniszyn47177f12016-03-07 11:35:41 -08001112 struct hfi1_qp_priv *priv = qp->priv;
Don Hiatt81cd3892018-05-15 18:28:15 -07001113 struct ib_other_headers *ohdr = NULL;
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001114 send_routine sr;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001115 int ret;
Don Hiatt566d53a2017-08-04 13:54:47 -07001116 u16 pkey;
1117 u32 slid;
Don Hiatt81cd3892018-05-15 18:28:15 -07001118 u8 l4 = 0;
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001119
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001120 /* locate the pkey within the headers */
Don Hiatt566d53a2017-08-04 13:54:47 -07001121 if (ps->s_txreq->phdr.hdr.hdr_type) {
1122 struct hfi1_16b_header *hdr = &ps->s_txreq->phdr.hdr.opah;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001123
Don Hiatt81cd3892018-05-15 18:28:15 -07001124 l4 = hfi1_16B_get_l4(hdr);
1125 if (l4 == OPA_16B_L4_IB_LOCAL)
Don Hiatt566d53a2017-08-04 13:54:47 -07001126 ohdr = &hdr->u.oth;
Don Hiatt81cd3892018-05-15 18:28:15 -07001127 else if (l4 == OPA_16B_L4_IB_GLOBAL)
1128 ohdr = &hdr->u.l.oth;
1129
Don Hiatt566d53a2017-08-04 13:54:47 -07001130 slid = hfi1_16B_get_slid(hdr);
1131 pkey = hfi1_16B_get_pkey(hdr);
1132 } else {
1133 struct ib_header *hdr = &ps->s_txreq->phdr.hdr.ibh;
1134 u8 lnh = ib_get_lnh(hdr);
1135
1136 if (lnh == HFI1_LRH_GRH)
1137 ohdr = &hdr->u.l.oth;
1138 else
1139 ohdr = &hdr->u.oth;
1140 slid = ib_get_slid(hdr);
1141 pkey = ib_bth_get_pkey(ohdr);
1142 }
1143
Don Hiatt81cd3892018-05-15 18:28:15 -07001144 if (likely(l4 != OPA_16B_L4_FM))
1145 ps->opcode = ib_bth_get_opcode(ohdr);
1146 else
1147 ps->opcode = IB_OPCODE_UD_SEND_ONLY;
1148
Don Hiatt566d53a2017-08-04 13:54:47 -07001149 sr = get_send_routine(qp, ps);
1150 ret = egress_pkey_check(dd->pport, slid, pkey,
1151 priv->s_sc, qp->s_pkey_index);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001152 if (unlikely(ret)) {
1153 /*
1154 * The value we are returning here does not get propagated to
1155 * the verbs caller. Thus we need to complete the request with
1156 * error otherwise the caller could be sitting waiting on the
1157 * completion event. Only do this for PIO. SDMA has its own
1158 * mechanism for handling the errors. So for SDMA we can just
1159 * return.
1160 */
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001161 if (sr == dd->process_pio_send) {
1162 unsigned long flags;
1163
Mike Marciniszyn77241052015-07-30 15:17:43 -04001164 hfi1_cdbg(PIO, "%s() Failed. Completing with err",
1165 __func__);
1166 spin_lock_irqsave(&qp->s_lock, flags);
Venkata Sandeep Dhanalakota116aa032018-09-26 10:44:42 -07001167 rvt_send_complete(qp, qp->s_wqe, IB_WC_GENERAL_ERR);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001168 spin_unlock_irqrestore(&qp->s_lock, flags);
1169 }
1170 return -EINVAL;
1171 }
Mike Marciniszyn47177f12016-03-07 11:35:41 -08001172 if (sr == dd->process_dma_send && iowait_pio_pending(&priv->s_iowait))
1173 return pio_wait(qp,
1174 ps->s_txreq->psc,
1175 ps,
Mike Marciniszyn2e2ba092018-06-04 11:44:02 -07001176 HFI1_S_WAIT_PIO_DRAIN);
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001177 return sr(qp, ps, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001178}
1179
Harish Chegondi94d51712016-01-19 14:43:17 -08001180/**
1181 * hfi1_fill_device_attr - Fill in rvt dev info device attributes.
1182 * @dd: the device data structure
1183 */
1184static void hfi1_fill_device_attr(struct hfi1_devdata *dd)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001185{
Harish Chegondi94d51712016-01-19 14:43:17 -08001186 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07001187 u32 ver = dd->dc8051_ver;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001188
Harish Chegondi94d51712016-01-19 14:43:17 -08001189 memset(&rdi->dparms.props, 0, sizeof(rdi->dparms.props));
Mike Marciniszyn77241052015-07-30 15:17:43 -04001190
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07001191 rdi->dparms.props.fw_ver = ((u64)(dc8051_ver_maj(ver)) << 32) |
1192 ((u64)(dc8051_ver_min(ver)) << 16) |
1193 (u64)dc8051_ver_patch(ver);
1194
Harish Chegondi94d51712016-01-19 14:43:17 -08001195 rdi->dparms.props.device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
1196 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
1197 IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN |
Jianxin Xiongc72cfe32016-07-25 13:38:43 -07001198 IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE |
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001199 IB_DEVICE_MEM_MGT_EXTENSIONS |
1200 IB_DEVICE_RDMA_NETDEV_OPA_VNIC;
Harish Chegondi94d51712016-01-19 14:43:17 -08001201 rdi->dparms.props.page_size_cap = PAGE_SIZE;
1202 rdi->dparms.props.vendor_id = dd->oui1 << 16 | dd->oui2 << 8 | dd->oui3;
1203 rdi->dparms.props.vendor_part_id = dd->pcidev->device;
1204 rdi->dparms.props.hw_ver = dd->minrev;
1205 rdi->dparms.props.sys_image_guid = ib_hfi1_sys_image_guid;
Jianxin Xiongc72cfe32016-07-25 13:38:43 -07001206 rdi->dparms.props.max_mr_size = U64_MAX;
1207 rdi->dparms.props.max_fast_reg_page_list_len = UINT_MAX;
Harish Chegondi94d51712016-01-19 14:43:17 -08001208 rdi->dparms.props.max_qp = hfi1_max_qps;
1209 rdi->dparms.props.max_qp_wr = hfi1_max_qp_wrs;
Steve Wise33023fb2018-06-18 08:05:26 -07001210 rdi->dparms.props.max_send_sge = hfi1_max_sges;
1211 rdi->dparms.props.max_recv_sge = hfi1_max_sges;
Harish Chegondi94d51712016-01-19 14:43:17 -08001212 rdi->dparms.props.max_sge_rd = hfi1_max_sges;
1213 rdi->dparms.props.max_cq = hfi1_max_cqs;
1214 rdi->dparms.props.max_ah = hfi1_max_ahs;
1215 rdi->dparms.props.max_cqe = hfi1_max_cqes;
1216 rdi->dparms.props.max_mr = rdi->lkey_table.max;
1217 rdi->dparms.props.max_fmr = rdi->lkey_table.max;
1218 rdi->dparms.props.max_map_per_fmr = 32767;
1219 rdi->dparms.props.max_pd = hfi1_max_pds;
1220 rdi->dparms.props.max_qp_rd_atom = HFI1_MAX_RDMA_ATOMIC;
1221 rdi->dparms.props.max_qp_init_rd_atom = 255;
1222 rdi->dparms.props.max_srq = hfi1_max_srqs;
1223 rdi->dparms.props.max_srq_wr = hfi1_max_srq_wrs;
1224 rdi->dparms.props.max_srq_sge = hfi1_max_srq_sges;
1225 rdi->dparms.props.atomic_cap = IB_ATOMIC_GLOB;
1226 rdi->dparms.props.max_pkeys = hfi1_get_npkeys(dd);
1227 rdi->dparms.props.max_mcast_grp = hfi1_max_mcast_grps;
1228 rdi->dparms.props.max_mcast_qp_attach = hfi1_max_mcast_qp_attached;
1229 rdi->dparms.props.max_total_mcast_qp_attach =
1230 rdi->dparms.props.max_mcast_qp_attach *
1231 rdi->dparms.props.max_mcast_grp;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001232}
1233
1234static inline u16 opa_speed_to_ib(u16 in)
1235{
1236 u16 out = 0;
1237
1238 if (in & OPA_LINK_SPEED_25G)
1239 out |= IB_SPEED_EDR;
1240 if (in & OPA_LINK_SPEED_12_5G)
1241 out |= IB_SPEED_FDR;
1242
1243 return out;
1244}
1245
1246/*
1247 * Convert a single OPA link width (no multiple flags) to an IB value.
1248 * A zero OPA link width means link down, which means the IB width value
1249 * is a don't care.
1250 */
1251static inline u16 opa_width_to_ib(u16 in)
1252{
1253 switch (in) {
1254 case OPA_LINK_WIDTH_1X:
1255 /* map 2x and 3x to 1x as they don't exist in IB */
1256 case OPA_LINK_WIDTH_2X:
1257 case OPA_LINK_WIDTH_3X:
1258 return IB_WIDTH_1X;
1259 default: /* link down or unknown, return our largest width */
1260 case OPA_LINK_WIDTH_4X:
1261 return IB_WIDTH_4X;
1262 }
1263}
1264
Harish Chegondi45b59ee2016-02-03 14:36:49 -08001265static int query_port(struct rvt_dev_info *rdi, u8 port_num,
Mike Marciniszyn77241052015-07-30 15:17:43 -04001266 struct ib_port_attr *props)
1267{
Harish Chegondi45b59ee2016-02-03 14:36:49 -08001268 struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi);
1269 struct hfi1_devdata *dd = dd_from_dev(verbs_dev);
1270 struct hfi1_pportdata *ppd = &dd->pport[port_num - 1];
Dasaratharaman Chandramouli51e658f52017-08-04 13:54:35 -07001271 u32 lid = ppd->lid;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001272
Or Gerlitzc4550c62017-01-24 13:02:39 +02001273 /* props being zeroed by the caller, avoid zeroing it here */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001274 props->lid = lid ? lid : 0;
1275 props->lmc = ppd->lmc;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001276 /* OPA logical states match IB logical states */
1277 props->state = driver_lstate(ppd);
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -07001278 props->phys_state = driver_pstate(ppd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001279 props->gid_tbl_len = HFI1_GUIDS_PER_PORT;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001280 props->active_width = (u8)opa_width_to_ib(ppd->link_width_active);
1281 /* see rate_show() in ib core/sysfs.c */
1282 props->active_speed = (u8)opa_speed_to_ib(ppd->link_speed_active);
1283 props->max_vl_num = ppd->vls_supported;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001284
1285 /* Once we are a "first class" citizen and have added the OPA MTUs to
1286 * the core we can advertise the larger MTU enum to the ULPs, for now
1287 * advertise only 4K.
1288 *
1289 * Those applications which are either OPA aware or pass the MTU enum
1290 * from the Path Records to us will get the new 8k MTU. Those that
1291 * attempt to process the MTU enum may fail in various ways.
1292 */
1293 props->max_mtu = mtu_to_enum((!valid_ib_mtu(hfi1_max_mtu) ?
1294 4096 : hfi1_max_mtu), IB_MTU_4096);
1295 props->active_mtu = !valid_ib_mtu(ppd->ibmtu) ? props->max_mtu :
Jan Sokolowski69a3ffa2017-11-14 04:34:45 -08001296 mtu_to_enum(ppd->ibmtu, IB_MTU_4096);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001297
1298 return 0;
1299}
1300
1301static int modify_device(struct ib_device *device,
1302 int device_modify_mask,
1303 struct ib_device_modify *device_modify)
1304{
1305 struct hfi1_devdata *dd = dd_from_ibdev(device);
1306 unsigned i;
1307 int ret;
1308
1309 if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
1310 IB_DEVICE_MODIFY_NODE_DESC)) {
1311 ret = -EOPNOTSUPP;
1312 goto bail;
1313 }
1314
1315 if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC) {
Yuval Shaiabd99fde2016-08-25 10:57:07 -07001316 memcpy(device->node_desc, device_modify->node_desc,
1317 IB_DEVICE_NODE_DESC_MAX);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001318 for (i = 0; i < dd->num_pports; i++) {
1319 struct hfi1_ibport *ibp = &dd->pport[i].ibport_data;
1320
1321 hfi1_node_desc_chg(ibp);
1322 }
1323 }
1324
1325 if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) {
1326 ib_hfi1_sys_image_guid =
1327 cpu_to_be64(device_modify->sys_image_guid);
1328 for (i = 0; i < dd->num_pports; i++) {
1329 struct hfi1_ibport *ibp = &dd->pport[i].ibport_data;
1330
1331 hfi1_sys_guid_chg(ibp);
1332 }
1333 }
1334
1335 ret = 0;
1336
1337bail:
1338 return ret;
1339}
1340
Harish Chegondi45b59ee2016-02-03 14:36:49 -08001341static int shut_down_port(struct rvt_dev_info *rdi, u8 port_num)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001342{
Harish Chegondi45b59ee2016-02-03 14:36:49 -08001343 struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi);
1344 struct hfi1_devdata *dd = dd_from_dev(verbs_dev);
1345 struct hfi1_pportdata *ppd = &dd->pport[port_num - 1];
1346 int ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001347
Harish Chegondi45b59ee2016-02-03 14:36:49 -08001348 set_link_down_reason(ppd, OPA_LINKDOWN_REASON_UNKNOWN, 0,
1349 OPA_LINKDOWN_REASON_UNKNOWN);
1350 ret = set_link_state(ppd, HLS_DN_DOWNDEF);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001351 return ret;
1352}
1353
Dennis Dalessandro25131462016-02-03 14:36:40 -08001354static int hfi1_get_guid_be(struct rvt_dev_info *rdi, struct rvt_ibport *rvp,
1355 int guid_index, __be64 *guid)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001356{
Dennis Dalessandro25131462016-02-03 14:36:40 -08001357 struct hfi1_ibport *ibp = container_of(rvp, struct hfi1_ibport, rvp);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001358
Jakub Pawlaka6cd5f02016-10-17 04:19:30 -07001359 if (guid_index >= HFI1_GUIDS_PER_PORT)
Dennis Dalessandro25131462016-02-03 14:36:40 -08001360 return -EINVAL;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001361
Jakub Pawlaka6cd5f02016-10-17 04:19:30 -07001362 *guid = get_sguid(ibp, guid_index);
Dennis Dalessandro25131462016-02-03 14:36:40 -08001363 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001364}
1365
Mike Marciniszyn77241052015-07-30 15:17:43 -04001366/*
1367 * convert ah port,sl to sc
1368 */
Dasaratharaman Chandramouli90898852017-04-29 14:41:18 -04001369u8 ah_to_sc(struct ib_device *ibdev, struct rdma_ah_attr *ah)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001370{
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001371 struct hfi1_ibport *ibp = to_iport(ibdev, rdma_ah_get_port_num(ah));
Mike Marciniszyn77241052015-07-30 15:17:43 -04001372
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001373 return ibp->sl_to_sc[rdma_ah_get_sl(ah)];
Mike Marciniszyn77241052015-07-30 15:17:43 -04001374}
1375
Dasaratharaman Chandramouli90898852017-04-29 14:41:18 -04001376static int hfi1_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001377{
1378 struct hfi1_ibport *ibp;
1379 struct hfi1_pportdata *ppd;
1380 struct hfi1_devdata *dd;
1381 u8 sc5;
Ira Weiny0dbfaa92018-09-20 12:58:46 -07001382 u8 sl;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001383
Don Hiatt13c19222017-08-04 13:53:51 -07001384 if (hfi1_check_mcast(rdma_ah_get_dlid(ah_attr)) &&
1385 !(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH))
1386 return -EINVAL;
1387
Mike Marciniszyn77241052015-07-30 15:17:43 -04001388 /* test the mapping for validity */
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001389 ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr));
Mike Marciniszyn77241052015-07-30 15:17:43 -04001390 ppd = ppd_from_ibp(ibp);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001391 dd = dd_from_ppd(ppd);
Ira Weiny0dbfaa92018-09-20 12:58:46 -07001392
1393 sl = rdma_ah_get_sl(ah_attr);
1394 if (sl >= ARRAY_SIZE(ibp->sl_to_sc))
1395 return -EINVAL;
1396
1397 sc5 = ibp->sl_to_sc[sl];
Mike Marciniszyn77241052015-07-30 15:17:43 -04001398 if (sc_to_vlt(dd, sc5) > num_vls && sc_to_vlt(dd, sc5) != 0xf)
Dennis Dalessandro15723f02016-01-19 14:42:17 -08001399 return -EINVAL;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001400 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001401}
1402
Dennis Dalessandro8f1764fa2016-01-19 14:42:22 -08001403static void hfi1_notify_new_ah(struct ib_device *ibdev,
Dasaratharaman Chandramouli90898852017-04-29 14:41:18 -04001404 struct rdma_ah_attr *ah_attr,
Dennis Dalessandro8f1764fa2016-01-19 14:42:22 -08001405 struct rvt_ah *ah)
1406{
1407 struct hfi1_ibport *ibp;
1408 struct hfi1_pportdata *ppd;
1409 struct hfi1_devdata *dd;
1410 u8 sc5;
Don Hiattd98bb7f2017-08-04 13:54:16 -07001411 struct rdma_ah_attr *attr = &ah->attr;
Dennis Dalessandro8f1764fa2016-01-19 14:42:22 -08001412
1413 /*
1414 * Do not trust reading anything from rvt_ah at this point as it is not
1415 * done being setup. We can however modify things which we need to set.
1416 */
1417
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001418 ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr));
Dennis Dalessandro8f1764fa2016-01-19 14:42:22 -08001419 ppd = ppd_from_ibp(ibp);
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001420 sc5 = ibp->sl_to_sc[rdma_ah_get_sl(&ah->attr)];
Don Hiattd98bb7f2017-08-04 13:54:16 -07001421 hfi1_update_ah_attr(ibdev, attr);
1422 hfi1_make_opa_lid(attr);
Dennis Dalessandro8f1764fa2016-01-19 14:42:22 -08001423 dd = dd_from_ppd(ppd);
1424 ah->vl = sc_to_vlt(dd, sc5);
1425 if (ah->vl < num_vls || ah->vl == 15)
1426 ah->log_pmtu = ilog2(dd->vld[ah->vl].mtu);
1427}
1428
Mike Marciniszyn77241052015-07-30 15:17:43 -04001429/**
Mike Marciniszyn77241052015-07-30 15:17:43 -04001430 * hfi1_get_npkeys - return the size of the PKEY table for context 0
1431 * @dd: the hfi1_ib device
1432 */
1433unsigned hfi1_get_npkeys(struct hfi1_devdata *dd)
1434{
1435 return ARRAY_SIZE(dd->pport[0].pkeys);
1436}
1437
Mike Marciniszyn77241052015-07-30 15:17:43 -04001438static void init_ibport(struct hfi1_pportdata *ppd)
1439{
1440 struct hfi1_ibport *ibp = &ppd->ibport_data;
1441 size_t sz = ARRAY_SIZE(ibp->sl_to_sc);
1442 int i;
1443
1444 for (i = 0; i < sz; i++) {
1445 ibp->sl_to_sc[i] = i;
1446 ibp->sc_to_sl[i] = i;
1447 }
1448
Michael J. Ruhlbf90aad2017-07-24 07:46:12 -07001449 for (i = 0; i < RVT_MAX_TRAP_LISTS ; i++)
1450 INIT_LIST_HEAD(&ibp->rvp.trap_lists[i].list);
Kees Cook80641352017-10-16 15:51:54 -07001451 timer_setup(&ibp->rvp.trap_timer, hfi1_handle_trap_timer, 0);
Michael J. Ruhlbf90aad2017-07-24 07:46:12 -07001452
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08001453 spin_lock_init(&ibp->rvp.lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001454 /* Set the prefix to the default value (see ch. 4.1.1) */
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08001455 ibp->rvp.gid_prefix = IB_DEFAULT_GID_PREFIX;
1456 ibp->rvp.sm_lid = 0;
Vishwanathapura, Niranjanacb493662017-06-01 17:04:02 -07001457 /*
1458 * Below should only set bits defined in OPA PortInfo.CapabilityMask
1459 * and PortInfo.CapabilityMask3
1460 */
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08001461 ibp->rvp.port_cap_flags = IB_PORT_AUTO_MIGR_SUP |
Mike Marciniszyn77241052015-07-30 15:17:43 -04001462 IB_PORT_CAP_MASK_NOTICE_SUP;
Vishwanathapura, Niranjanacb493662017-06-01 17:04:02 -07001463 ibp->rvp.port_cap3_flags = OPA_CAP_MASK3_IsSharedSpaceSupported;
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08001464 ibp->rvp.pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
1465 ibp->rvp.pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
1466 ibp->rvp.pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
1467 ibp->rvp.pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
1468 ibp->rvp.pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001469
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08001470 RCU_INIT_POINTER(ibp->rvp.qp[0], NULL);
1471 RCU_INIT_POINTER(ibp->rvp.qp[1], NULL);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001472}
1473
Leon Romanovsky9abb0d12017-06-27 16:49:53 +03001474static void hfi1_get_dev_fw_str(struct ib_device *ibdev, char *str)
Ira Weiny939b6ca2016-06-15 02:22:08 -04001475{
1476 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
1477 struct hfi1_ibdev *dev = dev_from_rdi(rdi);
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07001478 u32 ver = dd_from_dev(dev)->dc8051_ver;
Ira Weiny939b6ca2016-06-15 02:22:08 -04001479
Leon Romanovsky9abb0d12017-06-27 16:49:53 +03001480 snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u", dc8051_ver_maj(ver),
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07001481 dc8051_ver_min(ver), dc8051_ver_patch(ver));
Ira Weiny939b6ca2016-06-15 02:22:08 -04001482}
1483
Jianxin Xiongb7481942016-12-07 19:32:53 -08001484static const char * const driver_cntr_names[] = {
1485 /* must be element 0*/
1486 "DRIVER_KernIntr",
1487 "DRIVER_ErrorIntr",
1488 "DRIVER_Tx_Errs",
1489 "DRIVER_Rcv_Errs",
1490 "DRIVER_HW_Errs",
1491 "DRIVER_NoPIOBufs",
1492 "DRIVER_CtxtsOpen",
1493 "DRIVER_RcvLen_Errs",
1494 "DRIVER_EgrBufFull",
1495 "DRIVER_EgrHdrFull"
1496};
1497
Tadeusz Struk62eed662017-03-20 17:25:35 -07001498static DEFINE_MUTEX(cntr_names_lock); /* protects the *_cntr_names bufers */
Jianxin Xiongb7481942016-12-07 19:32:53 -08001499static const char **dev_cntr_names;
1500static const char **port_cntr_names;
Piotr Stankiewicz36d84212018-11-28 06:44:46 -08001501int num_driver_cntrs = ARRAY_SIZE(driver_cntr_names);
Jianxin Xiongb7481942016-12-07 19:32:53 -08001502static int num_dev_cntrs;
1503static int num_port_cntrs;
1504static int cntr_names_initialized;
1505
1506/*
1507 * Convert a list of names separated by '\n' into an array of NULL terminated
1508 * strings. Optionally some entries can be reserved in the array to hold extra
1509 * external strings.
1510 */
1511static int init_cntr_names(const char *names_in,
Arnd Bergmann64b2ae72017-02-14 22:23:07 +01001512 const size_t names_len,
Jianxin Xiongb7481942016-12-07 19:32:53 -08001513 int num_extra_names,
1514 int *num_cntrs,
1515 const char ***cntr_names)
1516{
1517 char *names_out, *p, **q;
1518 int i, n;
1519
1520 n = 0;
1521 for (i = 0; i < names_len; i++)
1522 if (names_in[i] == '\n')
1523 n++;
1524
1525 names_out = kmalloc((n + num_extra_names) * sizeof(char *) + names_len,
1526 GFP_KERNEL);
1527 if (!names_out) {
1528 *num_cntrs = 0;
1529 *cntr_names = NULL;
1530 return -ENOMEM;
1531 }
1532
1533 p = names_out + (n + num_extra_names) * sizeof(char *);
1534 memcpy(p, names_in, names_len);
1535
1536 q = (char **)names_out;
1537 for (i = 0; i < n; i++) {
1538 q[i] = p;
1539 p = strchr(p, '\n');
1540 *p++ = '\0';
1541 }
1542
1543 *num_cntrs = n;
1544 *cntr_names = (const char **)names_out;
1545 return 0;
1546}
1547
1548static struct rdma_hw_stats *alloc_hw_stats(struct ib_device *ibdev,
1549 u8 port_num)
1550{
1551 int i, err;
1552
Tadeusz Struk62eed662017-03-20 17:25:35 -07001553 mutex_lock(&cntr_names_lock);
Jianxin Xiongb7481942016-12-07 19:32:53 -08001554 if (!cntr_names_initialized) {
1555 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1556
1557 err = init_cntr_names(dd->cntrnames,
1558 dd->cntrnameslen,
1559 num_driver_cntrs,
1560 &num_dev_cntrs,
1561 &dev_cntr_names);
Tadeusz Struk62eed662017-03-20 17:25:35 -07001562 if (err) {
1563 mutex_unlock(&cntr_names_lock);
Jianxin Xiongb7481942016-12-07 19:32:53 -08001564 return NULL;
Tadeusz Struk62eed662017-03-20 17:25:35 -07001565 }
Jianxin Xiongb7481942016-12-07 19:32:53 -08001566
1567 for (i = 0; i < num_driver_cntrs; i++)
1568 dev_cntr_names[num_dev_cntrs + i] =
1569 driver_cntr_names[i];
1570
1571 err = init_cntr_names(dd->portcntrnames,
1572 dd->portcntrnameslen,
1573 0,
1574 &num_port_cntrs,
1575 &port_cntr_names);
1576 if (err) {
1577 kfree(dev_cntr_names);
1578 dev_cntr_names = NULL;
Tadeusz Struk62eed662017-03-20 17:25:35 -07001579 mutex_unlock(&cntr_names_lock);
Jianxin Xiongb7481942016-12-07 19:32:53 -08001580 return NULL;
1581 }
1582 cntr_names_initialized = 1;
1583 }
Tadeusz Struk62eed662017-03-20 17:25:35 -07001584 mutex_unlock(&cntr_names_lock);
Jianxin Xiongb7481942016-12-07 19:32:53 -08001585
1586 if (!port_num)
1587 return rdma_alloc_hw_stats_struct(
1588 dev_cntr_names,
1589 num_dev_cntrs + num_driver_cntrs,
1590 RDMA_HW_STATS_DEFAULT_LIFESPAN);
1591 else
1592 return rdma_alloc_hw_stats_struct(
1593 port_cntr_names,
1594 num_port_cntrs,
1595 RDMA_HW_STATS_DEFAULT_LIFESPAN);
1596}
1597
1598static u64 hfi1_sps_ints(void)
1599{
1600 unsigned long flags;
1601 struct hfi1_devdata *dd;
1602 u64 sps_ints = 0;
1603
1604 spin_lock_irqsave(&hfi1_devs_lock, flags);
1605 list_for_each_entry(dd, &hfi1_dev_list, list) {
1606 sps_ints += get_all_cpu_total(dd->int_counter);
1607 }
1608 spin_unlock_irqrestore(&hfi1_devs_lock, flags);
1609 return sps_ints;
1610}
1611
1612static int get_hw_stats(struct ib_device *ibdev, struct rdma_hw_stats *stats,
1613 u8 port, int index)
1614{
1615 u64 *values;
1616 int count;
1617
1618 if (!port) {
1619 u64 *stats = (u64 *)&hfi1_stats;
1620 int i;
1621
1622 hfi1_read_cntrs(dd_from_ibdev(ibdev), NULL, &values);
1623 values[num_dev_cntrs] = hfi1_sps_ints();
1624 for (i = 1; i < num_driver_cntrs; i++)
1625 values[num_dev_cntrs + i] = stats[i];
1626 count = num_dev_cntrs + num_driver_cntrs;
1627 } else {
1628 struct hfi1_ibport *ibp = to_iport(ibdev, port);
1629
1630 hfi1_read_portcntrs(ppd_from_ibp(ibp), NULL, &values);
1631 count = num_port_cntrs;
1632 }
1633
1634 memcpy(stats->value, values, count * sizeof(u64));
1635 return count;
1636}
1637
Kamal Heibe3c320c2018-12-10 21:09:34 +02001638static const struct ib_device_ops hfi1_dev_ops = {
1639 .alloc_hw_stats = alloc_hw_stats,
1640 .alloc_rdma_netdev = hfi1_vnic_alloc_rn,
1641 .get_dev_fw_str = hfi1_get_dev_fw_str,
1642 .get_hw_stats = get_hw_stats,
Parav Panditea4baf72018-12-18 14:28:30 +02001643 .init_port = hfi1_create_port_files,
Kamal Heibe3c320c2018-12-10 21:09:34 +02001644 .modify_device = modify_device,
1645 /* keep process mad in the driver */
1646 .process_mad = hfi1_process_mad,
1647};
1648
Mike Marciniszyn77241052015-07-30 15:17:43 -04001649/**
1650 * hfi1_register_ib_device - register our device with the infiniband core
1651 * @dd: the device data structure
1652 * Return 0 if successful, errno if unsuccessful.
1653 */
1654int hfi1_register_ib_device(struct hfi1_devdata *dd)
1655{
1656 struct hfi1_ibdev *dev = &dd->verbs_dev;
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -08001657 struct ib_device *ibdev = &dev->rdi.ibdev;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001658 struct hfi1_pportdata *ppd = dd->pport;
Jakub Pawlaka6cd5f02016-10-17 04:19:30 -07001659 struct hfi1_ibport *ibp = &ppd->ibport_data;
Dennis Dalessandro895420d2016-01-19 14:42:28 -08001660 unsigned i;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001661 int ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001662
Mike Marciniszyn77241052015-07-30 15:17:43 -04001663 for (i = 0; i < dd->num_pports; i++)
1664 init_ibport(ppd + i);
1665
1666 /* Only need to initialize non-zero fields. */
Dennis Dalessandro4f87ccf2016-01-19 14:41:50 -08001667
Kees Cook80641352017-10-16 15:51:54 -07001668 timer_setup(&dev->mem_timer, mem_timer, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001669
Mike Marciniszyn77241052015-07-30 15:17:43 -04001670 seqlock_init(&dev->iowait_lock);
Mike Marciniszyn4e045572016-10-10 06:14:28 -07001671 seqlock_init(&dev->txwait_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001672 INIT_LIST_HEAD(&dev->txwait);
1673 INIT_LIST_HEAD(&dev->memwait);
1674
Mike Marciniszyn45842ab2016-02-14 12:44:34 -08001675 ret = verbs_txreq_init(dev);
1676 if (ret)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001677 goto err_verbs_txreq;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001678
Jakub Pawlaka6cd5f02016-10-17 04:19:30 -07001679 /* Use first-port GUID as node guid */
1680 ibdev->node_guid = get_sguid(ibp, HFI1_PORT_GUID_INDEX);
1681
Mike Marciniszyn77241052015-07-30 15:17:43 -04001682 /*
1683 * The system image GUID is supposed to be the same for all
1684 * HFIs in a single system but since there can be other
1685 * device types in the system, we can't be sure this is unique.
1686 */
1687 if (!ib_hfi1_sys_image_guid)
Jakub Pawlaka6cd5f02016-10-17 04:19:30 -07001688 ib_hfi1_sys_image_guid = ibdev->node_guid;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001689 ibdev->owner = THIS_MODULE;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001690 ibdev->phys_port_cnt = dd->num_pports;
Bart Van Assche30677712017-01-20 13:04:17 -08001691 ibdev->dev.parent = &dd->pcidev->dev;
Dennis Dalessandro43316292016-01-19 14:44:01 -08001692
Kamal Heibe3c320c2018-12-10 21:09:34 +02001693 ib_set_device_ops(ibdev, &hfi1_dev_ops);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001694
Bart Van Assche522628e2018-07-10 11:32:16 -07001695 strlcpy(ibdev->node_desc, init_utsname()->nodename,
Mike Marciniszyn77241052015-07-30 15:17:43 -04001696 sizeof(ibdev->node_desc));
1697
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -08001698 /*
1699 * Fill in rvt info object.
1700 */
Dennis Dalessandro49dbb6c2016-01-19 14:42:06 -08001701 dd->verbs_dev.rdi.driver_f.get_pci_dev = get_pci_dev;
Dennis Dalessandro15723f02016-01-19 14:42:17 -08001702 dd->verbs_dev.rdi.driver_f.check_ah = hfi1_check_ah;
Dennis Dalessandro8f1764fa2016-01-19 14:42:22 -08001703 dd->verbs_dev.rdi.driver_f.notify_new_ah = hfi1_notify_new_ah;
Dennis Dalessandro25131462016-02-03 14:36:40 -08001704 dd->verbs_dev.rdi.driver_f.get_guid_be = hfi1_get_guid_be;
Harish Chegondi45b59ee2016-02-03 14:36:49 -08001705 dd->verbs_dev.rdi.driver_f.query_port_state = query_port;
1706 dd->verbs_dev.rdi.driver_f.shut_down_port = shut_down_port;
1707 dd->verbs_dev.rdi.driver_f.cap_mask_chg = hfi1_cap_mask_chg;
Harish Chegondi94d51712016-01-19 14:43:17 -08001708 /*
1709 * Fill in rvt info device attributes.
1710 */
1711 hfi1_fill_device_attr(dd);
Dennis Dalessandroa2c2d602016-01-19 14:43:12 -08001712
1713 /* queue pair */
Dennis Dalessandroa2c2d602016-01-19 14:43:12 -08001714 dd->verbs_dev.rdi.dparms.qp_table_size = hfi1_qp_table_size;
1715 dd->verbs_dev.rdi.dparms.qpn_start = 0;
1716 dd->verbs_dev.rdi.dparms.qpn_inc = 1;
1717 dd->verbs_dev.rdi.dparms.qos_shift = dd->qos_shift;
1718 dd->verbs_dev.rdi.dparms.qpn_res_start = kdeth_qp << 16;
1719 dd->verbs_dev.rdi.dparms.qpn_res_end =
Dennis Dalessandroabd712d2016-01-19 14:43:22 -08001720 dd->verbs_dev.rdi.dparms.qpn_res_start + 65535;
Dennis Dalessandroec4274f2016-01-19 14:43:44 -08001721 dd->verbs_dev.rdi.dparms.max_rdma_atomic = HFI1_MAX_RDMA_ATOMIC;
1722 dd->verbs_dev.rdi.dparms.psn_mask = PSN_MASK;
1723 dd->verbs_dev.rdi.dparms.psn_shift = PSN_SHIFT;
1724 dd->verbs_dev.rdi.dparms.psn_modify_mask = PSN_MODIFY_MASK;
Dasaratharaman Chandramouli72214032017-08-04 13:54:53 -07001725 dd->verbs_dev.rdi.dparms.core_cap_flags = RDMA_CORE_PORT_INTEL_OPA |
1726 RDMA_CORE_CAP_OPA_AH;
Harish Chegondi45b59ee2016-02-03 14:36:49 -08001727 dd->verbs_dev.rdi.dparms.max_mad_size = OPA_MGMT_MAD_SIZE;
1728
Dennis Dalessandroa2c2d602016-01-19 14:43:12 -08001729 dd->verbs_dev.rdi.driver_f.qp_priv_alloc = qp_priv_alloc;
Mike Marciniszyn5190f052018-11-28 10:22:31 -08001730 dd->verbs_dev.rdi.driver_f.qp_priv_init = hfi1_qp_priv_init;
Dennis Dalessandroa2c2d602016-01-19 14:43:12 -08001731 dd->verbs_dev.rdi.driver_f.qp_priv_free = qp_priv_free;
1732 dd->verbs_dev.rdi.driver_f.free_all_qps = free_all_qps;
1733 dd->verbs_dev.rdi.driver_f.notify_qp_reset = notify_qp_reset;
Mike Marciniszynb6eac932017-04-09 10:16:35 -07001734 dd->verbs_dev.rdi.driver_f.do_send = hfi1_do_send_from_rvt;
Dennis Dalessandro83693bd2016-01-19 14:43:33 -08001735 dd->verbs_dev.rdi.driver_f.schedule_send = hfi1_schedule_send;
Mike Marciniszyn46a80d62016-02-14 12:10:04 -08001736 dd->verbs_dev.rdi.driver_f.schedule_send_no_lock = _hfi1_schedule_send;
Dennis Dalessandroec4274f2016-01-19 14:43:44 -08001737 dd->verbs_dev.rdi.driver_f.get_pmtu_from_attr = get_pmtu_from_attr;
1738 dd->verbs_dev.rdi.driver_f.notify_error_qp = notify_error_qp;
1739 dd->verbs_dev.rdi.driver_f.flush_qp_waiters = flush_qp_waiters;
1740 dd->verbs_dev.rdi.driver_f.stop_send_queue = stop_send_queue;
1741 dd->verbs_dev.rdi.driver_f.quiesce_qp = quiesce_qp;
1742 dd->verbs_dev.rdi.driver_f.notify_error_qp = notify_error_qp;
1743 dd->verbs_dev.rdi.driver_f.mtu_from_qp = mtu_from_qp;
1744 dd->verbs_dev.rdi.driver_f.mtu_to_path_mtu = mtu_to_path_mtu;
1745 dd->verbs_dev.rdi.driver_f.check_modify_qp = hfi1_check_modify_qp;
1746 dd->verbs_dev.rdi.driver_f.modify_qp = hfi1_modify_qp;
Venkata Sandeep Dhanalakota56acbbf2017-02-08 05:27:19 -08001747 dd->verbs_dev.rdi.driver_f.notify_restart_rc = hfi1_restart_rc;
Kaike Wand205a06a2018-09-26 10:26:44 -07001748 dd->verbs_dev.rdi.driver_f.setup_wqe = hfi1_setup_wqe;
Sebastian Sanchez5d18ee62018-05-02 06:43:55 -07001749 dd->verbs_dev.rdi.driver_f.comp_vect_cpu_lookup =
1750 hfi1_comp_vect_mappings_lookup;
Dennis Dalessandroa2c2d602016-01-19 14:43:12 -08001751
Dennis Dalessandroabd712d2016-01-19 14:43:22 -08001752 /* completeion queue */
Sebastian Sanchez5d18ee62018-05-02 06:43:55 -07001753 dd->verbs_dev.rdi.ibdev.num_comp_vectors = dd->comp_vect_possible_cpus;
Mitko Haralanov27807392016-02-03 14:33:31 -08001754 dd->verbs_dev.rdi.dparms.node = dd->node;
Dennis Dalessandroabd712d2016-01-19 14:43:22 -08001755
Dennis Dalessandroa2c2d602016-01-19 14:43:12 -08001756 /* misc settings */
Dennis Dalessandroabd712d2016-01-19 14:43:22 -08001757 dd->verbs_dev.rdi.flags = 0; /* Let rdmavt handle it all */
Dennis Dalessandro895420d2016-01-19 14:42:28 -08001758 dd->verbs_dev.rdi.dparms.lkey_table_size = hfi1_lkey_table_size;
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08001759 dd->verbs_dev.rdi.dparms.nports = dd->num_pports;
1760 dd->verbs_dev.rdi.dparms.npkeys = hfi1_get_npkeys(dd);
Brian Welty019f1182018-09-26 10:44:33 -07001761 dd->verbs_dev.rdi.dparms.sge_copy_mode = sge_copy_mode;
1762 dd->verbs_dev.rdi.dparms.wss_threshold = wss_threshold;
1763 dd->verbs_dev.rdi.dparms.wss_clean_period = wss_clean_period;
Kaike Wan48a615d2019-01-23 19:21:11 -08001764 dd->verbs_dev.rdi.dparms.reserved_operations = 1;
Kaike Wanddf922c2019-01-23 19:21:01 -08001765 dd->verbs_dev.rdi.dparms.extra_rdma_atomic = 1;
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08001766
Mike Marciniszyn1ac57c52016-07-01 16:02:13 -07001767 /* post send table */
1768 dd->verbs_dev.rdi.post_parms = hfi1_post_parms;
1769
Venkata Sandeep Dhanalakota116aa032018-09-26 10:44:42 -07001770 /* opcode translation table */
1771 dd->verbs_dev.rdi.wc_opcode = ib_hfi1_wc_opcode;
1772
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08001773 ppd = dd->pport;
1774 for (i = 0; i < dd->num_pports; i++, ppd++)
1775 rvt_init_port(&dd->verbs_dev.rdi,
1776 &ppd->ibport_data.rvp,
1777 i,
1778 ppd->pkeys);
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -08001779
Parav Pandit508a5232018-10-11 22:31:54 +03001780 rdma_set_device_sysfs_group(&dd->verbs_dev.rdi.ibdev,
1781 &ib_hfi1_attr_group);
1782
Matan Barak0ede73b2018-03-19 15:02:34 +02001783 ret = rvt_register_device(&dd->verbs_dev.rdi, RDMA_DRIVER_HFI1);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001784 if (ret)
Dennis Dalessandro9c4a3112016-01-19 14:44:11 -08001785 goto err_verbs_txreq;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001786
1787 ret = hfi1_verbs_register_sysfs(dd);
1788 if (ret)
1789 goto err_class;
1790
Dennis Dalessandro9c4a3112016-01-19 14:44:11 -08001791 return ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001792
1793err_class:
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -08001794 rvt_unregister_device(&dd->verbs_dev.rdi);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001795err_verbs_txreq:
Mike Marciniszyn45842ab2016-02-14 12:44:34 -08001796 verbs_txreq_exit(dev);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001797 dd_dev_err(dd, "cannot register verbs: %d!\n", -ret);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001798 return ret;
1799}
1800
1801void hfi1_unregister_ib_device(struct hfi1_devdata *dd)
1802{
1803 struct hfi1_ibdev *dev = &dd->verbs_dev;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001804
1805 hfi1_verbs_unregister_sysfs(dd);
1806
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -08001807 rvt_unregister_device(&dd->verbs_dev.rdi);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001808
1809 if (!list_empty(&dev->txwait))
1810 dd_dev_err(dd, "txwait list not empty!\n");
1811 if (!list_empty(&dev->memwait))
1812 dd_dev_err(dd, "memwait list not empty!\n");
Mike Marciniszyn77241052015-07-30 15:17:43 -04001813
Mike Marciniszyn77241052015-07-30 15:17:43 -04001814 del_timer_sync(&dev->mem_timer);
Mike Marciniszyn45842ab2016-02-14 12:44:34 -08001815 verbs_txreq_exit(dev);
Jianxin Xiongb7481942016-12-07 19:32:53 -08001816
Tadeusz Struk62eed662017-03-20 17:25:35 -07001817 mutex_lock(&cntr_names_lock);
Jianxin Xiongb7481942016-12-07 19:32:53 -08001818 kfree(dev_cntr_names);
1819 kfree(port_cntr_names);
Tadeusz Struk62eed662017-03-20 17:25:35 -07001820 dev_cntr_names = NULL;
1821 port_cntr_names = NULL;
Jianxin Xiongb7481942016-12-07 19:32:53 -08001822 cntr_names_initialized = 0;
Tadeusz Struk62eed662017-03-20 17:25:35 -07001823 mutex_unlock(&cntr_names_lock);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001824}
1825
Mike Marciniszyn77241052015-07-30 15:17:43 -04001826void hfi1_cnp_rcv(struct hfi1_packet *packet)
1827{
Sebastian Sanchezf3e862c2017-02-08 05:26:25 -08001828 struct hfi1_ibport *ibp = rcd_to_iport(packet->rcd);
Arthur Kepner977940b2015-11-04 21:10:10 -05001829 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
Mike Marciniszyn261a4352016-09-06 04:35:05 -07001830 struct ib_header *hdr = packet->hdr;
Dennis Dalessandro895420d2016-01-19 14:42:28 -08001831 struct rvt_qp *qp = packet->qp;
Arthur Kepner977940b2015-11-04 21:10:10 -05001832 u32 lqpn, rqpn = 0;
1833 u16 rlid = 0;
Dasaratharaman Chandramoulib736a462016-07-25 13:40:34 -07001834 u8 sl, sc5, svc_type;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001835
Arthur Kepner977940b2015-11-04 21:10:10 -05001836 switch (packet->qp->ibqp.qp_type) {
1837 case IB_QPT_UC:
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001838 rlid = rdma_ah_get_dlid(&qp->remote_ah_attr);
Arthur Kepner977940b2015-11-04 21:10:10 -05001839 rqpn = qp->remote_qpn;
1840 svc_type = IB_CC_SVCTYPE_UC;
1841 break;
1842 case IB_QPT_RC:
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001843 rlid = rdma_ah_get_dlid(&qp->remote_ah_attr);
Arthur Kepner977940b2015-11-04 21:10:10 -05001844 rqpn = qp->remote_qpn;
1845 svc_type = IB_CC_SVCTYPE_RC;
1846 break;
1847 case IB_QPT_SMI:
1848 case IB_QPT_GSI:
1849 case IB_QPT_UD:
1850 svc_type = IB_CC_SVCTYPE_UD;
1851 break;
1852 default:
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08001853 ibp->rvp.n_pkt_drops++;
Arthur Kepner977940b2015-11-04 21:10:10 -05001854 return;
1855 }
1856
Dasaratharaman Chandramouliaad559c2017-04-09 10:16:15 -07001857 sc5 = hfi1_9B_get_sc5(hdr, packet->rhf);
Arthur Kepner977940b2015-11-04 21:10:10 -05001858 sl = ibp->sc_to_sl[sc5];
1859 lqpn = qp->ibqp.qp_num;
1860
1861 process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001862}