blob: 5ff32d32c61c86f9058a2a74c16f069eb3305809 [file] [log] [blame]
Ralph Campbellf9315512010-05-23 21:44:54 -07001/*
Sebastian Sanchez5d18ee62018-05-02 06:43:55 -07002 * Copyright (c) 2012 - 2018 Intel Corporation. All rights reserved.
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +00003 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
Ralph Campbellf9315512010-05-23 21:44:54 -07004 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#include <rdma/ib_mad.h>
36#include <rdma/ib_user_verbs.h>
37#include <linux/io.h>
Paul Gortmakere4dd23d2011-05-27 15:35:46 -040038#include <linux/module.h>
Ralph Campbellf9315512010-05-23 21:44:54 -070039#include <linux/utsname.h>
40#include <linux/rculist.h>
41#include <linux/mm.h>
Mike Marciniszynaf061a62011-09-23 13:16:44 -040042#include <linux/random.h>
Mike Marciniszynd6f1c172015-07-21 08:36:07 -040043#include <linux/vmalloc.h>
Dennis Dalessandroeb636ac2016-01-22 12:44:36 -080044#include <rdma/rdma_vt.h>
Ralph Campbellf9315512010-05-23 21:44:54 -070045
46#include "qib.h"
47#include "qib_common.h"
48
Mike Marciniszynaf061a62011-09-23 13:16:44 -040049static unsigned int ib_qib_qp_table_size = 256;
Ralph Campbellf9315512010-05-23 21:44:54 -070050module_param_named(qp_table_size, ib_qib_qp_table_size, uint, S_IRUGO);
51MODULE_PARM_DESC(qp_table_size, "QP table size");
52
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -080053static unsigned int qib_lkey_table_size = 16;
54module_param_named(lkey_table_size, qib_lkey_table_size, uint,
Ralph Campbellf9315512010-05-23 21:44:54 -070055 S_IRUGO);
56MODULE_PARM_DESC(lkey_table_size,
57 "LKEY table size in bits (2^n, 1 <= n <= 23)");
58
59static unsigned int ib_qib_max_pds = 0xFFFF;
60module_param_named(max_pds, ib_qib_max_pds, uint, S_IRUGO);
61MODULE_PARM_DESC(max_pds,
62 "Maximum number of protection domains to support");
63
64static unsigned int ib_qib_max_ahs = 0xFFFF;
65module_param_named(max_ahs, ib_qib_max_ahs, uint, S_IRUGO);
66MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support");
67
68unsigned int ib_qib_max_cqes = 0x2FFFF;
69module_param_named(max_cqes, ib_qib_max_cqes, uint, S_IRUGO);
70MODULE_PARM_DESC(max_cqes,
71 "Maximum number of completion queue entries to support");
72
73unsigned int ib_qib_max_cqs = 0x1FFFF;
74module_param_named(max_cqs, ib_qib_max_cqs, uint, S_IRUGO);
75MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support");
76
77unsigned int ib_qib_max_qp_wrs = 0x3FFF;
78module_param_named(max_qp_wrs, ib_qib_max_qp_wrs, uint, S_IRUGO);
79MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support");
80
81unsigned int ib_qib_max_qps = 16384;
82module_param_named(max_qps, ib_qib_max_qps, uint, S_IRUGO);
83MODULE_PARM_DESC(max_qps, "Maximum number of QPs to support");
84
85unsigned int ib_qib_max_sges = 0x60;
86module_param_named(max_sges, ib_qib_max_sges, uint, S_IRUGO);
87MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support");
88
89unsigned int ib_qib_max_mcast_grps = 16384;
90module_param_named(max_mcast_grps, ib_qib_max_mcast_grps, uint, S_IRUGO);
91MODULE_PARM_DESC(max_mcast_grps,
92 "Maximum number of multicast groups to support");
93
94unsigned int ib_qib_max_mcast_qp_attached = 16;
95module_param_named(max_mcast_qp_attached, ib_qib_max_mcast_qp_attached,
96 uint, S_IRUGO);
97MODULE_PARM_DESC(max_mcast_qp_attached,
98 "Maximum number of attached QPs to support");
99
100unsigned int ib_qib_max_srqs = 1024;
101module_param_named(max_srqs, ib_qib_max_srqs, uint, S_IRUGO);
102MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support");
103
104unsigned int ib_qib_max_srq_sges = 128;
105module_param_named(max_srq_sges, ib_qib_max_srq_sges, uint, S_IRUGO);
106MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support");
107
108unsigned int ib_qib_max_srq_wrs = 0x1FFFF;
109module_param_named(max_srq_wrs, ib_qib_max_srq_wrs, uint, S_IRUGO);
110MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support");
111
112static unsigned int ib_qib_disable_sma;
113module_param_named(disable_sma, ib_qib_disable_sma, uint, S_IWUSR | S_IRUGO);
114MODULE_PARM_DESC(disable_sma, "Disable the SMA");
115
116/*
Mike Marciniszyn43a474a2017-03-20 17:25:04 -0700117 * Translate ib_wr_opcode into ib_wc_opcode.
118 */
119const enum ib_wc_opcode ib_qib_wc_opcode[] = {
120 [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
121 [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
122 [IB_WR_SEND] = IB_WC_SEND,
123 [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
124 [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
125 [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
126 [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD
127};
128
129/*
Ralph Campbellf9315512010-05-23 21:44:54 -0700130 * System image GUID.
131 */
132__be64 ib_qib_sys_image_guid;
133
Ralph Campbellf9315512010-05-23 21:44:54 -0700134/*
135 * Count the number of DMA descriptors needed to send length bytes of data.
136 * Don't modify the qib_sge_state to get the count.
137 * Return zero if any of the segments is not aligned.
138 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800139static u32 qib_count_sge(struct rvt_sge_state *ss, u32 length)
Ralph Campbellf9315512010-05-23 21:44:54 -0700140{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800141 struct rvt_sge *sg_list = ss->sg_list;
142 struct rvt_sge sge = ss->sge;
Ralph Campbellf9315512010-05-23 21:44:54 -0700143 u8 num_sge = ss->num_sge;
144 u32 ndesc = 1; /* count the header */
145
146 while (length) {
Michael J. Ruhl87fc34b2019-01-23 19:08:19 -0800147 u32 len = rvt_get_sge_length(&sge, length);
Ralph Campbellf9315512010-05-23 21:44:54 -0700148
Ralph Campbellf9315512010-05-23 21:44:54 -0700149 if (((long) sge.vaddr & (sizeof(u32) - 1)) ||
150 (len != length && (len & (sizeof(u32) - 1)))) {
151 ndesc = 0;
152 break;
153 }
154 ndesc++;
155 sge.vaddr += len;
156 sge.length -= len;
157 sge.sge_length -= len;
158 if (sge.sge_length == 0) {
159 if (--num_sge)
160 sge = *sg_list++;
161 } else if (sge.length == 0 && sge.mr->lkey) {
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800162 if (++sge.n >= RVT_SEGSZ) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700163 if (++sge.m >= sge.mr->mapsz)
164 break;
165 sge.n = 0;
166 }
167 sge.vaddr =
168 sge.mr->map[sge.m]->segs[sge.n].vaddr;
169 sge.length =
170 sge.mr->map[sge.m]->segs[sge.n].length;
171 }
172 length -= len;
173 }
174 return ndesc;
175}
176
177/*
178 * Copy from the SGEs to the data buffer.
179 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800180static void qib_copy_from_sge(void *data, struct rvt_sge_state *ss, u32 length)
Ralph Campbellf9315512010-05-23 21:44:54 -0700181{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800182 struct rvt_sge *sge = &ss->sge;
Ralph Campbellf9315512010-05-23 21:44:54 -0700183
184 while (length) {
Michael J. Ruhl87fc34b2019-01-23 19:08:19 -0800185 u32 len = rvt_get_sge_length(sge, length);
Ralph Campbellf9315512010-05-23 21:44:54 -0700186
Ralph Campbellf9315512010-05-23 21:44:54 -0700187 memcpy(data, sge->vaddr, len);
188 sge->vaddr += len;
189 sge->length -= len;
190 sge->sge_length -= len;
191 if (sge->sge_length == 0) {
192 if (--ss->num_sge)
193 *sge = *ss->sg_list++;
194 } else if (sge->length == 0 && sge->mr->lkey) {
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800195 if (++sge->n >= RVT_SEGSZ) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700196 if (++sge->m >= sge->mr->mapsz)
197 break;
198 sge->n = 0;
199 }
200 sge->vaddr =
201 sge->mr->map[sge->m]->segs[sge->n].vaddr;
202 sge->length =
203 sge->mr->map[sge->m]->segs[sge->n].length;
204 }
205 data += len;
206 length -= len;
207 }
208}
209
210/**
Ralph Campbellf9315512010-05-23 21:44:54 -0700211 * qib_qp_rcv - processing an incoming packet on a QP
212 * @rcd: the context pointer
213 * @hdr: the packet header
214 * @has_grh: true if the packet has a GRH
215 * @data: the packet data
216 * @tlen: the packet length
217 * @qp: the QP the packet came on
218 *
219 * This is called from qib_ib_rcv() to process an incoming packet
220 * for the given QP.
221 * Called at interrupt level.
222 */
Mike Marciniszyn261a4352016-09-06 04:35:05 -0700223static void qib_qp_rcv(struct qib_ctxtdata *rcd, struct ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800224 int has_grh, void *data, u32 tlen, struct rvt_qp *qp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700225{
226 struct qib_ibport *ibp = &rcd->ppd->ibport_data;
227
Ralph Campbella5210c12010-08-02 22:39:30 +0000228 spin_lock(&qp->r_lock);
229
Ralph Campbellf9315512010-05-23 21:44:54 -0700230 /* Check for valid receive state. */
Harish Chegondidb3ef0e2016-01-22 13:07:42 -0800231 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
Harish Chegondif24a6d42016-01-22 12:56:02 -0800232 ibp->rvp.n_pkt_drops++;
Ralph Campbella5210c12010-08-02 22:39:30 +0000233 goto unlock;
Ralph Campbellf9315512010-05-23 21:44:54 -0700234 }
235
236 switch (qp->ibqp.qp_type) {
237 case IB_QPT_SMI:
238 case IB_QPT_GSI:
239 if (ib_qib_disable_sma)
240 break;
241 /* FALLTHROUGH */
242 case IB_QPT_UD:
243 qib_ud_rcv(ibp, hdr, has_grh, data, tlen, qp);
244 break;
245
246 case IB_QPT_RC:
247 qib_rc_rcv(rcd, hdr, has_grh, data, tlen, qp);
248 break;
249
250 case IB_QPT_UC:
251 qib_uc_rcv(ibp, hdr, has_grh, data, tlen, qp);
252 break;
253
254 default:
255 break;
256 }
Ralph Campbella5210c12010-08-02 22:39:30 +0000257
258unlock:
259 spin_unlock(&qp->r_lock);
Ralph Campbellf9315512010-05-23 21:44:54 -0700260}
261
262/**
263 * qib_ib_rcv - process an incoming packet
264 * @rcd: the context pointer
265 * @rhdr: the header of the packet
266 * @data: the packet payload
267 * @tlen: the packet length
268 *
269 * This is called from qib_kreceive() to process an incoming packet at
270 * interrupt level. Tlen is the length of the header + data + CRC in bytes.
271 */
272void qib_ib_rcv(struct qib_ctxtdata *rcd, void *rhdr, void *data, u32 tlen)
273{
274 struct qib_pportdata *ppd = rcd->ppd;
275 struct qib_ibport *ibp = &ppd->ibport_data;
Mike Marciniszyn261a4352016-09-06 04:35:05 -0700276 struct ib_header *hdr = rhdr;
Harish Chegondi1cefc2c2016-02-03 14:20:19 -0800277 struct qib_devdata *dd = ppd->dd;
278 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
Mike Marciniszyn261a4352016-09-06 04:35:05 -0700279 struct ib_other_headers *ohdr;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800280 struct rvt_qp *qp;
Ralph Campbellf9315512010-05-23 21:44:54 -0700281 u32 qp_num;
282 int lnh;
283 u8 opcode;
284 u16 lid;
285
286 /* 24 == LRH+BTH+CRC */
287 if (unlikely(tlen < 24))
288 goto drop;
289
290 /* Check for a valid destination LID (see ch. 7.11.1). */
291 lid = be16_to_cpu(hdr->lrh[1]);
Dennis Dalessandro9ff198f2016-01-22 12:44:53 -0800292 if (lid < be16_to_cpu(IB_MULTICAST_LID_BASE)) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700293 lid &= ~((1 << ppd->lmc) - 1);
294 if (unlikely(lid != ppd->lid))
295 goto drop;
296 }
297
298 /* Check for GRH */
299 lnh = be16_to_cpu(hdr->lrh[0]) & 3;
300 if (lnh == QIB_LRH_BTH)
301 ohdr = &hdr->u.oth;
302 else if (lnh == QIB_LRH_GRH) {
303 u32 vtf;
304
305 ohdr = &hdr->u.l.oth;
306 if (hdr->u.l.grh.next_hdr != IB_GRH_NEXT_HDR)
307 goto drop;
308 vtf = be32_to_cpu(hdr->u.l.grh.version_tclass_flow);
309 if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
310 goto drop;
311 } else
312 goto drop;
313
Mike Marciniszynddb88762013-06-15 17:07:03 -0400314 opcode = (be32_to_cpu(ohdr->bth[0]) >> 24) & 0x7f;
315#ifdef CONFIG_DEBUG_FS
316 rcd->opstats->stats[opcode].n_bytes += tlen;
317 rcd->opstats->stats[opcode].n_packets++;
318#endif
Ralph Campbellf9315512010-05-23 21:44:54 -0700319
320 /* Get the destination QP number. */
Harish Chegondi70696ea2016-02-03 14:20:27 -0800321 qp_num = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
Ralph Campbellf9315512010-05-23 21:44:54 -0700322 if (qp_num == QIB_MULTICAST_QPN) {
Harish Chegondi18f6c582016-01-22 13:07:55 -0800323 struct rvt_mcast *mcast;
324 struct rvt_mcast_qp *p;
Ralph Campbellf9315512010-05-23 21:44:54 -0700325
326 if (lnh != QIB_LRH_GRH)
327 goto drop;
Michael J. Ruhlaad9ff92017-04-09 10:15:57 -0700328 mcast = rvt_mcast_find(&ibp->rvp, &hdr->u.l.grh.dgid, lid);
Ralph Campbellf9315512010-05-23 21:44:54 -0700329 if (mcast == NULL)
330 goto drop;
Mike Marciniszyn7d7632a2014-03-07 08:40:55 -0500331 this_cpu_inc(ibp->pmastats->n_multicast_rcv);
Ralph Campbellf9315512010-05-23 21:44:54 -0700332 list_for_each_entry_rcu(p, &mcast->qp_list, list)
333 qib_qp_rcv(rcd, hdr, 1, data, tlen, p->qp);
334 /*
Harish Chegondi18f6c582016-01-22 13:07:55 -0800335 * Notify rvt_multicast_detach() if it is waiting for us
Ralph Campbellf9315512010-05-23 21:44:54 -0700336 * to finish.
337 */
338 if (atomic_dec_return(&mcast->refcount) <= 1)
339 wake_up(&mcast->wait);
340 } else {
Harish Chegondi1cefc2c2016-02-03 14:20:19 -0800341 rcu_read_lock();
342 qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
343 if (!qp) {
344 rcu_read_unlock();
345 goto drop;
Mike Marciniszynaf061a62011-09-23 13:16:44 -0400346 }
Mike Marciniszyn7d7632a2014-03-07 08:40:55 -0500347 this_cpu_inc(ibp->pmastats->n_unicast_rcv);
Ralph Campbellf9315512010-05-23 21:44:54 -0700348 qib_qp_rcv(rcd, hdr, lnh == QIB_LRH_GRH, data, tlen, qp);
Harish Chegondi1cefc2c2016-02-03 14:20:19 -0800349 rcu_read_unlock();
Ralph Campbellf9315512010-05-23 21:44:54 -0700350 }
351 return;
352
353drop:
Harish Chegondif24a6d42016-01-22 12:56:02 -0800354 ibp->rvp.n_pkt_drops++;
Ralph Campbellf9315512010-05-23 21:44:54 -0700355}
356
357/*
358 * This is called from a timer to check for QPs
359 * which need kernel memory in order to send a packet.
360 */
Kees Cook4037c922017-10-04 17:45:35 -0700361static void mem_timer(struct timer_list *t)
Ralph Campbellf9315512010-05-23 21:44:54 -0700362{
Kees Cook4037c922017-10-04 17:45:35 -0700363 struct qib_ibdev *dev = from_timer(dev, t, mem_timer);
Ralph Campbellf9315512010-05-23 21:44:54 -0700364 struct list_head *list = &dev->memwait;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800365 struct rvt_qp *qp = NULL;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800366 struct qib_qp_priv *priv = NULL;
Ralph Campbellf9315512010-05-23 21:44:54 -0700367 unsigned long flags;
368
Harish Chegondicd182012016-01-22 12:56:14 -0800369 spin_lock_irqsave(&dev->rdi.pending_lock, flags);
Ralph Campbellf9315512010-05-23 21:44:54 -0700370 if (!list_empty(list)) {
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800371 priv = list_entry(list->next, struct qib_qp_priv, iowait);
372 qp = priv->owner;
373 list_del_init(&priv->iowait);
Sebastian Sanchez238b1862016-12-07 19:34:00 -0800374 rvt_get_qp(qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700375 if (!list_empty(list))
376 mod_timer(&dev->mem_timer, jiffies + 1);
377 }
Harish Chegondicd182012016-01-22 12:56:14 -0800378 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
Ralph Campbellf9315512010-05-23 21:44:54 -0700379
380 if (qp) {
381 spin_lock_irqsave(&qp->s_lock, flags);
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800382 if (qp->s_flags & RVT_S_WAIT_KMEM) {
383 qp->s_flags &= ~RVT_S_WAIT_KMEM;
Ralph Campbellf9315512010-05-23 21:44:54 -0700384 qib_schedule_send(qp);
385 }
386 spin_unlock_irqrestore(&qp->s_lock, flags);
Sebastian Sanchez238b1862016-12-07 19:34:00 -0800387 rvt_put_qp(qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700388 }
389}
390
Ralph Campbellf9315512010-05-23 21:44:54 -0700391#ifdef __LITTLE_ENDIAN
392static inline u32 get_upper_bits(u32 data, u32 shift)
393{
394 return data >> shift;
395}
396
397static inline u32 set_upper_bits(u32 data, u32 shift)
398{
399 return data << shift;
400}
401
402static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
403{
404 data <<= ((sizeof(u32) - n) * BITS_PER_BYTE);
405 data >>= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
406 return data;
407}
408#else
409static inline u32 get_upper_bits(u32 data, u32 shift)
410{
411 return data << shift;
412}
413
414static inline u32 set_upper_bits(u32 data, u32 shift)
415{
416 return data >> shift;
417}
418
419static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
420{
421 data >>= ((sizeof(u32) - n) * BITS_PER_BYTE);
422 data <<= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
423 return data;
424}
425#endif
426
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800427static void copy_io(u32 __iomem *piobuf, struct rvt_sge_state *ss,
Ralph Campbellf9315512010-05-23 21:44:54 -0700428 u32 length, unsigned flush_wc)
429{
430 u32 extra = 0;
431 u32 data = 0;
432 u32 last;
433
434 while (1) {
Michael J. Ruhl87fc34b2019-01-23 19:08:19 -0800435 u32 len = rvt_get_sge_length(&ss->sge, length);
Ralph Campbellf9315512010-05-23 21:44:54 -0700436 u32 off;
437
Ralph Campbellf9315512010-05-23 21:44:54 -0700438 /* If the source address is not aligned, try to align it. */
439 off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1);
440 if (off) {
441 u32 *addr = (u32 *)((unsigned long)ss->sge.vaddr &
442 ~(sizeof(u32) - 1));
443 u32 v = get_upper_bits(*addr, off * BITS_PER_BYTE);
444 u32 y;
445
446 y = sizeof(u32) - off;
447 if (len > y)
448 len = y;
449 if (len + extra >= sizeof(u32)) {
450 data |= set_upper_bits(v, extra *
451 BITS_PER_BYTE);
452 len = sizeof(u32) - extra;
453 if (len == length) {
454 last = data;
455 break;
456 }
457 __raw_writel(data, piobuf);
458 piobuf++;
459 extra = 0;
460 data = 0;
461 } else {
462 /* Clear unused upper bytes */
463 data |= clear_upper_bytes(v, len, extra);
464 if (len == length) {
465 last = data;
466 break;
467 }
468 extra += len;
469 }
470 } else if (extra) {
471 /* Source address is aligned. */
472 u32 *addr = (u32 *) ss->sge.vaddr;
473 int shift = extra * BITS_PER_BYTE;
474 int ushift = 32 - shift;
475 u32 l = len;
476
477 while (l >= sizeof(u32)) {
478 u32 v = *addr;
479
480 data |= set_upper_bits(v, shift);
481 __raw_writel(data, piobuf);
482 data = get_upper_bits(v, ushift);
483 piobuf++;
484 addr++;
485 l -= sizeof(u32);
486 }
487 /*
488 * We still have 'extra' number of bytes leftover.
489 */
490 if (l) {
491 u32 v = *addr;
492
493 if (l + extra >= sizeof(u32)) {
494 data |= set_upper_bits(v, shift);
495 len -= l + extra - sizeof(u32);
496 if (len == length) {
497 last = data;
498 break;
499 }
500 __raw_writel(data, piobuf);
501 piobuf++;
502 extra = 0;
503 data = 0;
504 } else {
505 /* Clear unused upper bytes */
506 data |= clear_upper_bytes(v, l, extra);
507 if (len == length) {
508 last = data;
509 break;
510 }
511 extra += l;
512 }
513 } else if (len == length) {
514 last = data;
515 break;
516 }
517 } else if (len == length) {
518 u32 w;
519
520 /*
521 * Need to round up for the last dword in the
522 * packet.
523 */
524 w = (len + 3) >> 2;
525 qib_pio_copy(piobuf, ss->sge.vaddr, w - 1);
526 piobuf += w - 1;
527 last = ((u32 *) ss->sge.vaddr)[w - 1];
528 break;
529 } else {
530 u32 w = len >> 2;
531
532 qib_pio_copy(piobuf, ss->sge.vaddr, w);
533 piobuf += w;
534
535 extra = len & (sizeof(u32) - 1);
536 if (extra) {
537 u32 v = ((u32 *) ss->sge.vaddr)[w];
538
539 /* Clear unused upper bytes */
540 data = clear_upper_bytes(v, extra, 0);
541 }
542 }
Brian Welty3fc4a092017-02-08 05:27:43 -0800543 rvt_update_sge(ss, len, false);
Ralph Campbellf9315512010-05-23 21:44:54 -0700544 length -= len;
545 }
546 /* Update address before sending packet. */
Brian Welty3fc4a092017-02-08 05:27:43 -0800547 rvt_update_sge(ss, length, false);
Ralph Campbellf9315512010-05-23 21:44:54 -0700548 if (flush_wc) {
549 /* must flush early everything before trigger word */
550 qib_flush_wc();
551 __raw_writel(last, piobuf);
552 /* be sure trigger word is written */
553 qib_flush_wc();
554 } else
555 __raw_writel(last, piobuf);
556}
557
Mike Marciniszyn48947102011-12-23 08:03:41 -0500558static noinline struct qib_verbs_txreq *__get_txreq(struct qib_ibdev *dev,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800559 struct rvt_qp *qp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700560{
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800561 struct qib_qp_priv *priv = qp->priv;
Ralph Campbellf9315512010-05-23 21:44:54 -0700562 struct qib_verbs_txreq *tx;
563 unsigned long flags;
564
565 spin_lock_irqsave(&qp->s_lock, flags);
Harish Chegondicd182012016-01-22 12:56:14 -0800566 spin_lock(&dev->rdi.pending_lock);
Ralph Campbellf9315512010-05-23 21:44:54 -0700567
568 if (!list_empty(&dev->txreq_free)) {
569 struct list_head *l = dev->txreq_free.next;
570
571 list_del(l);
Harish Chegondicd182012016-01-22 12:56:14 -0800572 spin_unlock(&dev->rdi.pending_lock);
Mike Marciniszyn48947102011-12-23 08:03:41 -0500573 spin_unlock_irqrestore(&qp->s_lock, flags);
Ralph Campbellf9315512010-05-23 21:44:54 -0700574 tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
Ralph Campbellf9315512010-05-23 21:44:54 -0700575 } else {
Harish Chegondidb3ef0e2016-01-22 13:07:42 -0800576 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK &&
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800577 list_empty(&priv->iowait)) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700578 dev->n_txwait++;
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800579 qp->s_flags |= RVT_S_WAIT_TX;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800580 list_add_tail(&priv->iowait, &dev->txwait);
Ralph Campbellf9315512010-05-23 21:44:54 -0700581 }
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800582 qp->s_flags &= ~RVT_S_BUSY;
Harish Chegondicd182012016-01-22 12:56:14 -0800583 spin_unlock(&dev->rdi.pending_lock);
Mike Marciniszyn48947102011-12-23 08:03:41 -0500584 spin_unlock_irqrestore(&qp->s_lock, flags);
585 tx = ERR_PTR(-EBUSY);
Ralph Campbellf9315512010-05-23 21:44:54 -0700586 }
Mike Marciniszyn48947102011-12-23 08:03:41 -0500587 return tx;
588}
Ralph Campbellf9315512010-05-23 21:44:54 -0700589
Mike Marciniszyn48947102011-12-23 08:03:41 -0500590static inline struct qib_verbs_txreq *get_txreq(struct qib_ibdev *dev,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800591 struct rvt_qp *qp)
Mike Marciniszyn48947102011-12-23 08:03:41 -0500592{
593 struct qib_verbs_txreq *tx;
594 unsigned long flags;
Ralph Campbellf9315512010-05-23 21:44:54 -0700595
Harish Chegondicd182012016-01-22 12:56:14 -0800596 spin_lock_irqsave(&dev->rdi.pending_lock, flags);
Mike Marciniszyn48947102011-12-23 08:03:41 -0500597 /* assume the list non empty */
598 if (likely(!list_empty(&dev->txreq_free))) {
599 struct list_head *l = dev->txreq_free.next;
600
601 list_del(l);
Harish Chegondicd182012016-01-22 12:56:14 -0800602 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
Mike Marciniszyn48947102011-12-23 08:03:41 -0500603 tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
604 } else {
605 /* call slow path to get the extra lock */
Harish Chegondicd182012016-01-22 12:56:14 -0800606 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
Mike Marciniszyn48947102011-12-23 08:03:41 -0500607 tx = __get_txreq(dev, qp);
608 }
Ralph Campbellf9315512010-05-23 21:44:54 -0700609 return tx;
610}
611
612void qib_put_txreq(struct qib_verbs_txreq *tx)
613{
614 struct qib_ibdev *dev;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800615 struct rvt_qp *qp;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800616 struct qib_qp_priv *priv;
Ralph Campbellf9315512010-05-23 21:44:54 -0700617 unsigned long flags;
618
619 qp = tx->qp;
620 dev = to_idev(qp->ibqp.device);
621
Ralph Campbellf9315512010-05-23 21:44:54 -0700622 if (tx->mr) {
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800623 rvt_put_mr(tx->mr);
Ralph Campbellf9315512010-05-23 21:44:54 -0700624 tx->mr = NULL;
625 }
626 if (tx->txreq.flags & QIB_SDMA_TXREQ_F_FREEBUF) {
627 tx->txreq.flags &= ~QIB_SDMA_TXREQ_F_FREEBUF;
628 dma_unmap_single(&dd_from_dev(dev)->pcidev->dev,
629 tx->txreq.addr, tx->hdr_dwords << 2,
630 DMA_TO_DEVICE);
631 kfree(tx->align_buf);
632 }
633
Harish Chegondicd182012016-01-22 12:56:14 -0800634 spin_lock_irqsave(&dev->rdi.pending_lock, flags);
Ralph Campbellf9315512010-05-23 21:44:54 -0700635
636 /* Put struct back on free list */
637 list_add(&tx->txreq.list, &dev->txreq_free);
638
639 if (!list_empty(&dev->txwait)) {
640 /* Wake up first QP wanting a free struct */
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800641 priv = list_entry(dev->txwait.next, struct qib_qp_priv,
642 iowait);
643 qp = priv->owner;
644 list_del_init(&priv->iowait);
Sebastian Sanchez238b1862016-12-07 19:34:00 -0800645 rvt_get_qp(qp);
Harish Chegondicd182012016-01-22 12:56:14 -0800646 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
Ralph Campbellf9315512010-05-23 21:44:54 -0700647
648 spin_lock_irqsave(&qp->s_lock, flags);
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800649 if (qp->s_flags & RVT_S_WAIT_TX) {
650 qp->s_flags &= ~RVT_S_WAIT_TX;
Ralph Campbellf9315512010-05-23 21:44:54 -0700651 qib_schedule_send(qp);
652 }
653 spin_unlock_irqrestore(&qp->s_lock, flags);
654
Sebastian Sanchez238b1862016-12-07 19:34:00 -0800655 rvt_put_qp(qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700656 } else
Harish Chegondicd182012016-01-22 12:56:14 -0800657 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
Ralph Campbellf9315512010-05-23 21:44:54 -0700658}
659
660/*
661 * This is called when there are send DMA descriptors that might be
662 * available.
663 *
664 * This is called with ppd->sdma_lock held.
665 */
666void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail)
667{
Bart Van Assche2055d1f2017-10-11 10:49:22 -0700668 struct rvt_qp *qp;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800669 struct qib_qp_priv *qpp, *nqpp;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800670 struct rvt_qp *qps[20];
Ralph Campbellf9315512010-05-23 21:44:54 -0700671 struct qib_ibdev *dev;
672 unsigned i, n;
673
674 n = 0;
675 dev = &ppd->dd->verbs_dev;
Harish Chegondicd182012016-01-22 12:56:14 -0800676 spin_lock(&dev->rdi.pending_lock);
Ralph Campbellf9315512010-05-23 21:44:54 -0700677
678 /* Search wait list for first QP wanting DMA descriptors. */
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800679 list_for_each_entry_safe(qpp, nqpp, &dev->dmawait, iowait) {
680 qp = qpp->owner;
Ralph Campbellf9315512010-05-23 21:44:54 -0700681 if (qp->port_num != ppd->port)
682 continue;
683 if (n == ARRAY_SIZE(qps))
684 break;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800685 if (qpp->s_tx->txreq.sg_count > avail)
Ralph Campbellf9315512010-05-23 21:44:54 -0700686 break;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800687 avail -= qpp->s_tx->txreq.sg_count;
688 list_del_init(&qpp->iowait);
Sebastian Sanchez238b1862016-12-07 19:34:00 -0800689 rvt_get_qp(qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700690 qps[n++] = qp;
691 }
692
Harish Chegondicd182012016-01-22 12:56:14 -0800693 spin_unlock(&dev->rdi.pending_lock);
Ralph Campbellf9315512010-05-23 21:44:54 -0700694
695 for (i = 0; i < n; i++) {
696 qp = qps[i];
697 spin_lock(&qp->s_lock);
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800698 if (qp->s_flags & RVT_S_WAIT_DMA_DESC) {
699 qp->s_flags &= ~RVT_S_WAIT_DMA_DESC;
Ralph Campbellf9315512010-05-23 21:44:54 -0700700 qib_schedule_send(qp);
701 }
702 spin_unlock(&qp->s_lock);
Sebastian Sanchez238b1862016-12-07 19:34:00 -0800703 rvt_put_qp(qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700704 }
705}
706
707/*
708 * This is called with ppd->sdma_lock held.
709 */
710static void sdma_complete(struct qib_sdma_txreq *cookie, int status)
711{
712 struct qib_verbs_txreq *tx =
713 container_of(cookie, struct qib_verbs_txreq, txreq);
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800714 struct rvt_qp *qp = tx->qp;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800715 struct qib_qp_priv *priv = qp->priv;
Ralph Campbellf9315512010-05-23 21:44:54 -0700716
717 spin_lock(&qp->s_lock);
718 if (tx->wqe)
Venkata Sandeep Dhanalakota116aa032018-09-26 10:44:42 -0700719 rvt_send_complete(qp, tx->wqe, IB_WC_SUCCESS);
Ralph Campbellf9315512010-05-23 21:44:54 -0700720 else if (qp->ibqp.qp_type == IB_QPT_RC) {
Mike Marciniszyn261a4352016-09-06 04:35:05 -0700721 struct ib_header *hdr;
Ralph Campbellf9315512010-05-23 21:44:54 -0700722
723 if (tx->txreq.flags & QIB_SDMA_TXREQ_F_FREEBUF)
724 hdr = &tx->align_buf->hdr;
725 else {
726 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
727
728 hdr = &dev->pio_hdrs[tx->hdr_inx].hdr;
729 }
730 qib_rc_send_complete(qp, hdr);
731 }
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800732 if (atomic_dec_and_test(&priv->s_dma_busy)) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700733 if (qp->state == IB_QPS_RESET)
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800734 wake_up(&priv->wait_dma);
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800735 else if (qp->s_flags & RVT_S_WAIT_DMA) {
736 qp->s_flags &= ~RVT_S_WAIT_DMA;
Ralph Campbellf9315512010-05-23 21:44:54 -0700737 qib_schedule_send(qp);
738 }
739 }
740 spin_unlock(&qp->s_lock);
741
742 qib_put_txreq(tx);
743}
744
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800745static int wait_kmem(struct qib_ibdev *dev, struct rvt_qp *qp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700746{
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800747 struct qib_qp_priv *priv = qp->priv;
Ralph Campbellf9315512010-05-23 21:44:54 -0700748 unsigned long flags;
749 int ret = 0;
750
751 spin_lock_irqsave(&qp->s_lock, flags);
Harish Chegondidb3ef0e2016-01-22 13:07:42 -0800752 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
Harish Chegondicd182012016-01-22 12:56:14 -0800753 spin_lock(&dev->rdi.pending_lock);
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800754 if (list_empty(&priv->iowait)) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700755 if (list_empty(&dev->memwait))
756 mod_timer(&dev->mem_timer, jiffies + 1);
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800757 qp->s_flags |= RVT_S_WAIT_KMEM;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800758 list_add_tail(&priv->iowait, &dev->memwait);
Ralph Campbellf9315512010-05-23 21:44:54 -0700759 }
Harish Chegondicd182012016-01-22 12:56:14 -0800760 spin_unlock(&dev->rdi.pending_lock);
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800761 qp->s_flags &= ~RVT_S_BUSY;
Ralph Campbellf9315512010-05-23 21:44:54 -0700762 ret = -EBUSY;
763 }
764 spin_unlock_irqrestore(&qp->s_lock, flags);
765
766 return ret;
767}
768
Mike Marciniszyn261a4352016-09-06 04:35:05 -0700769static int qib_verbs_send_dma(struct rvt_qp *qp, struct ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800770 u32 hdrwords, struct rvt_sge_state *ss, u32 len,
Ralph Campbellf9315512010-05-23 21:44:54 -0700771 u32 plen, u32 dwords)
772{
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800773 struct qib_qp_priv *priv = qp->priv;
Ralph Campbellf9315512010-05-23 21:44:54 -0700774 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
775 struct qib_devdata *dd = dd_from_dev(dev);
776 struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
777 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
778 struct qib_verbs_txreq *tx;
779 struct qib_pio_header *phdr;
780 u32 control;
781 u32 ndesc;
782 int ret;
783
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800784 tx = priv->s_tx;
Ralph Campbellf9315512010-05-23 21:44:54 -0700785 if (tx) {
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800786 priv->s_tx = NULL;
Ralph Campbellf9315512010-05-23 21:44:54 -0700787 /* resend previously constructed packet */
788 ret = qib_sdma_verbs_send(ppd, tx->ss, tx->dwords, tx);
789 goto bail;
790 }
791
Mike Marciniszyn48947102011-12-23 08:03:41 -0500792 tx = get_txreq(dev, qp);
793 if (IS_ERR(tx))
794 goto bail_tx;
Ralph Campbellf9315512010-05-23 21:44:54 -0700795
796 control = dd->f_setpbc_control(ppd, plen, qp->s_srate,
797 be16_to_cpu(hdr->lrh[0]) >> 12);
798 tx->qp = qp;
Ralph Campbellf9315512010-05-23 21:44:54 -0700799 tx->wqe = qp->s_wqe;
800 tx->mr = qp->s_rdma_mr;
801 if (qp->s_rdma_mr)
802 qp->s_rdma_mr = NULL;
803 tx->txreq.callback = sdma_complete;
804 if (dd->flags & QIB_HAS_SDMA_TIMEOUT)
805 tx->txreq.flags = QIB_SDMA_TXREQ_F_HEADTOHOST;
806 else
807 tx->txreq.flags = QIB_SDMA_TXREQ_F_INTREQ;
808 if (plen + 1 > dd->piosize2kmax_dwords)
809 tx->txreq.flags |= QIB_SDMA_TXREQ_F_USELARGEBUF;
810
811 if (len) {
812 /*
813 * Don't try to DMA if it takes more descriptors than
814 * the queue holds.
815 */
816 ndesc = qib_count_sge(ss, len);
817 if (ndesc >= ppd->sdma_descq_cnt)
818 ndesc = 0;
819 } else
820 ndesc = 1;
821 if (ndesc) {
822 phdr = &dev->pio_hdrs[tx->hdr_inx];
823 phdr->pbc[0] = cpu_to_le32(plen);
824 phdr->pbc[1] = cpu_to_le32(control);
825 memcpy(&phdr->hdr, hdr, hdrwords << 2);
826 tx->txreq.flags |= QIB_SDMA_TXREQ_F_FREEDESC;
827 tx->txreq.sg_count = ndesc;
828 tx->txreq.addr = dev->pio_hdrs_phys +
829 tx->hdr_inx * sizeof(struct qib_pio_header);
830 tx->hdr_dwords = hdrwords + 2; /* add PBC length */
831 ret = qib_sdma_verbs_send(ppd, ss, dwords, tx);
832 goto bail;
833 }
834
835 /* Allocate a buffer and copy the header and payload to it. */
836 tx->hdr_dwords = plen + 1;
837 phdr = kmalloc(tx->hdr_dwords << 2, GFP_ATOMIC);
838 if (!phdr)
839 goto err_tx;
840 phdr->pbc[0] = cpu_to_le32(plen);
841 phdr->pbc[1] = cpu_to_le32(control);
842 memcpy(&phdr->hdr, hdr, hdrwords << 2);
843 qib_copy_from_sge((u32 *) &phdr->hdr + hdrwords, ss, len);
844
845 tx->txreq.addr = dma_map_single(&dd->pcidev->dev, phdr,
846 tx->hdr_dwords << 2, DMA_TO_DEVICE);
847 if (dma_mapping_error(&dd->pcidev->dev, tx->txreq.addr))
848 goto map_err;
849 tx->align_buf = phdr;
850 tx->txreq.flags |= QIB_SDMA_TXREQ_F_FREEBUF;
851 tx->txreq.sg_count = 1;
852 ret = qib_sdma_verbs_send(ppd, NULL, 0, tx);
853 goto unaligned;
854
855map_err:
856 kfree(phdr);
857err_tx:
858 qib_put_txreq(tx);
859 ret = wait_kmem(dev, qp);
860unaligned:
Harish Chegondif24a6d42016-01-22 12:56:02 -0800861 ibp->rvp.n_unaligned++;
Ralph Campbellf9315512010-05-23 21:44:54 -0700862bail:
863 return ret;
Mike Marciniszyn48947102011-12-23 08:03:41 -0500864bail_tx:
865 ret = PTR_ERR(tx);
866 goto bail;
Ralph Campbellf9315512010-05-23 21:44:54 -0700867}
868
869/*
870 * If we are now in the error state, return zero to flush the
871 * send work request.
872 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800873static int no_bufs_available(struct rvt_qp *qp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700874{
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800875 struct qib_qp_priv *priv = qp->priv;
Ralph Campbellf9315512010-05-23 21:44:54 -0700876 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
877 struct qib_devdata *dd;
878 unsigned long flags;
879 int ret = 0;
880
881 /*
882 * Note that as soon as want_buffer() is called and
883 * possibly before it returns, qib_ib_piobufavail()
884 * could be called. Therefore, put QP on the I/O wait list before
885 * enabling the PIO avail interrupt.
886 */
887 spin_lock_irqsave(&qp->s_lock, flags);
Harish Chegondidb3ef0e2016-01-22 13:07:42 -0800888 if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
Harish Chegondicd182012016-01-22 12:56:14 -0800889 spin_lock(&dev->rdi.pending_lock);
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800890 if (list_empty(&priv->iowait)) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700891 dev->n_piowait++;
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800892 qp->s_flags |= RVT_S_WAIT_PIO;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800893 list_add_tail(&priv->iowait, &dev->piowait);
Ralph Campbellf9315512010-05-23 21:44:54 -0700894 dd = dd_from_dev(dev);
895 dd->f_wantpiobuf_intr(dd, 1);
896 }
Harish Chegondicd182012016-01-22 12:56:14 -0800897 spin_unlock(&dev->rdi.pending_lock);
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800898 qp->s_flags &= ~RVT_S_BUSY;
Ralph Campbellf9315512010-05-23 21:44:54 -0700899 ret = -EBUSY;
900 }
901 spin_unlock_irqrestore(&qp->s_lock, flags);
902 return ret;
903}
904
Mike Marciniszyn261a4352016-09-06 04:35:05 -0700905static int qib_verbs_send_pio(struct rvt_qp *qp, struct ib_header *ibhdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800906 u32 hdrwords, struct rvt_sge_state *ss, u32 len,
Ralph Campbellf9315512010-05-23 21:44:54 -0700907 u32 plen, u32 dwords)
908{
909 struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
910 struct qib_pportdata *ppd = dd->pport + qp->port_num - 1;
911 u32 *hdr = (u32 *) ibhdr;
912 u32 __iomem *piobuf_orig;
913 u32 __iomem *piobuf;
914 u64 pbc;
915 unsigned long flags;
916 unsigned flush_wc;
917 u32 control;
918 u32 pbufn;
919
920 control = dd->f_setpbc_control(ppd, plen, qp->s_srate,
921 be16_to_cpu(ibhdr->lrh[0]) >> 12);
922 pbc = ((u64) control << 32) | plen;
923 piobuf = dd->f_getsendbuf(ppd, pbc, &pbufn);
924 if (unlikely(piobuf == NULL))
925 return no_bufs_available(qp);
926
927 /*
928 * Write the pbc.
929 * We have to flush after the PBC for correctness on some cpus
930 * or WC buffer can be written out of order.
931 */
932 writeq(pbc, piobuf);
933 piobuf_orig = piobuf;
934 piobuf += 2;
935
936 flush_wc = dd->flags & QIB_PIO_FLUSH_WC;
937 if (len == 0) {
938 /*
939 * If there is just the header portion, must flush before
940 * writing last word of header for correctness, and after
941 * the last header word (trigger word).
942 */
943 if (flush_wc) {
944 qib_flush_wc();
945 qib_pio_copy(piobuf, hdr, hdrwords - 1);
946 qib_flush_wc();
947 __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords - 1);
948 qib_flush_wc();
949 } else
950 qib_pio_copy(piobuf, hdr, hdrwords);
951 goto done;
952 }
953
954 if (flush_wc)
955 qib_flush_wc();
956 qib_pio_copy(piobuf, hdr, hdrwords);
957 piobuf += hdrwords;
958
959 /* The common case is aligned and contained in one segment. */
960 if (likely(ss->num_sge == 1 && len <= ss->sge.length &&
961 !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) {
962 u32 *addr = (u32 *) ss->sge.vaddr;
963
964 /* Update address before sending packet. */
Brian Welty3fc4a092017-02-08 05:27:43 -0800965 rvt_update_sge(ss, len, false);
Ralph Campbellf9315512010-05-23 21:44:54 -0700966 if (flush_wc) {
967 qib_pio_copy(piobuf, addr, dwords - 1);
968 /* must flush early everything before trigger word */
969 qib_flush_wc();
970 __raw_writel(addr[dwords - 1], piobuf + dwords - 1);
971 /* be sure trigger word is written */
972 qib_flush_wc();
973 } else
974 qib_pio_copy(piobuf, addr, dwords);
975 goto done;
976 }
977 copy_io(piobuf, ss, len, flush_wc);
978done:
979 if (dd->flags & QIB_USE_SPCL_TRIG) {
980 u32 spcl_off = (pbufn >= dd->piobcnt2k) ? 2047 : 1023;
Mike Marciniszynda12c1f2015-01-16 11:23:31 -0500981
Ralph Campbellf9315512010-05-23 21:44:54 -0700982 qib_flush_wc();
983 __raw_writel(0xaebecede, piobuf_orig + spcl_off);
984 }
985 qib_sendbuf_done(dd, pbufn);
986 if (qp->s_rdma_mr) {
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800987 rvt_put_mr(qp->s_rdma_mr);
Ralph Campbellf9315512010-05-23 21:44:54 -0700988 qp->s_rdma_mr = NULL;
989 }
990 if (qp->s_wqe) {
991 spin_lock_irqsave(&qp->s_lock, flags);
Venkata Sandeep Dhanalakota116aa032018-09-26 10:44:42 -0700992 rvt_send_complete(qp, qp->s_wqe, IB_WC_SUCCESS);
Ralph Campbellf9315512010-05-23 21:44:54 -0700993 spin_unlock_irqrestore(&qp->s_lock, flags);
994 } else if (qp->ibqp.qp_type == IB_QPT_RC) {
995 spin_lock_irqsave(&qp->s_lock, flags);
996 qib_rc_send_complete(qp, ibhdr);
997 spin_unlock_irqrestore(&qp->s_lock, flags);
998 }
999 return 0;
1000}
1001
1002/**
1003 * qib_verbs_send - send a packet
1004 * @qp: the QP to send on
1005 * @hdr: the packet header
1006 * @hdrwords: the number of 32-bit words in the header
1007 * @ss: the SGE to send
1008 * @len: the length of the packet in bytes
1009 *
1010 * Return zero if packet is sent or queued OK.
Harish Chegondi01ba79d2016-01-22 12:56:46 -08001011 * Return non-zero and clear qp->s_flags RVT_S_BUSY otherwise.
Ralph Campbellf9315512010-05-23 21:44:54 -07001012 */
Mike Marciniszyn261a4352016-09-06 04:35:05 -07001013int qib_verbs_send(struct rvt_qp *qp, struct ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -08001014 u32 hdrwords, struct rvt_sge_state *ss, u32 len)
Ralph Campbellf9315512010-05-23 21:44:54 -07001015{
1016 struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
1017 u32 plen;
1018 int ret;
1019 u32 dwords = (len + 3) >> 2;
1020
1021 /*
1022 * Calculate the send buffer trigger address.
1023 * The +1 counts for the pbc control dword following the pbc length.
1024 */
1025 plen = hdrwords + dwords + 1;
1026
1027 /*
1028 * VL15 packets (IB_QPT_SMI) will always use PIO, so we
1029 * can defer SDMA restart until link goes ACTIVE without
1030 * worrying about just how we got there.
1031 */
1032 if (qp->ibqp.qp_type == IB_QPT_SMI ||
1033 !(dd->flags & QIB_HAS_SEND_DMA))
1034 ret = qib_verbs_send_pio(qp, hdr, hdrwords, ss, len,
1035 plen, dwords);
1036 else
1037 ret = qib_verbs_send_dma(qp, hdr, hdrwords, ss, len,
1038 plen, dwords);
1039
1040 return ret;
1041}
1042
1043int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
1044 u64 *rwords, u64 *spkts, u64 *rpkts,
1045 u64 *xmit_wait)
1046{
1047 int ret;
1048 struct qib_devdata *dd = ppd->dd;
1049
1050 if (!(dd->flags & QIB_PRESENT)) {
1051 /* no hardware, freeze, etc. */
1052 ret = -EINVAL;
1053 goto bail;
1054 }
1055 *swords = dd->f_portcntr(ppd, QIBPORTCNTR_WORDSEND);
1056 *rwords = dd->f_portcntr(ppd, QIBPORTCNTR_WORDRCV);
1057 *spkts = dd->f_portcntr(ppd, QIBPORTCNTR_PKTSEND);
1058 *rpkts = dd->f_portcntr(ppd, QIBPORTCNTR_PKTRCV);
1059 *xmit_wait = dd->f_portcntr(ppd, QIBPORTCNTR_SENDSTALL);
1060
1061 ret = 0;
1062
1063bail:
1064 return ret;
1065}
1066
1067/**
1068 * qib_get_counters - get various chip counters
1069 * @dd: the qlogic_ib device
1070 * @cntrs: counters are placed here
1071 *
1072 * Return the counters needed by recv_pma_get_portcounters().
1073 */
1074int qib_get_counters(struct qib_pportdata *ppd,
1075 struct qib_verbs_counters *cntrs)
1076{
1077 int ret;
1078
1079 if (!(ppd->dd->flags & QIB_PRESENT)) {
1080 /* no hardware, freeze, etc. */
1081 ret = -EINVAL;
1082 goto bail;
1083 }
1084 cntrs->symbol_error_counter =
1085 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBSYMBOLERR);
1086 cntrs->link_error_recovery_counter =
1087 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBLINKERRRECOV);
1088 /*
1089 * The link downed counter counts when the other side downs the
1090 * connection. We add in the number of times we downed the link
1091 * due to local link integrity errors to compensate.
1092 */
1093 cntrs->link_downed_counter =
1094 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBLINKDOWN);
1095 cntrs->port_rcv_errors =
1096 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXDROPPKT) +
1097 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RCVOVFL) +
1098 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERR_RLEN) +
1099 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_INVALIDRLEN) +
1100 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRLINK) +
1101 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRICRC) +
1102 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRVCRC) +
1103 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRLPCRC) +
1104 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_BADFORMAT);
1105 cntrs->port_rcv_errors +=
1106 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXLOCALPHYERR);
1107 cntrs->port_rcv_errors +=
1108 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXVLERR);
1109 cntrs->port_rcv_remphys_errors =
1110 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RCVEBP);
1111 cntrs->port_xmit_discards =
1112 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_UNSUPVL);
1113 cntrs->port_xmit_data = ppd->dd->f_portcntr(ppd,
1114 QIBPORTCNTR_WORDSEND);
1115 cntrs->port_rcv_data = ppd->dd->f_portcntr(ppd,
1116 QIBPORTCNTR_WORDRCV);
1117 cntrs->port_xmit_packets = ppd->dd->f_portcntr(ppd,
1118 QIBPORTCNTR_PKTSEND);
1119 cntrs->port_rcv_packets = ppd->dd->f_portcntr(ppd,
1120 QIBPORTCNTR_PKTRCV);
1121 cntrs->local_link_integrity_errors =
1122 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_LLI);
1123 cntrs->excessive_buffer_overrun_errors =
1124 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_EXCESSBUFOVFL);
1125 cntrs->vl15_dropped =
1126 ppd->dd->f_portcntr(ppd, QIBPORTCNTR_VL15PKTDROP);
1127
1128 ret = 0;
1129
1130bail:
1131 return ret;
1132}
1133
1134/**
1135 * qib_ib_piobufavail - callback when a PIO buffer is available
1136 * @dd: the device pointer
1137 *
1138 * This is called from qib_intr() at interrupt level when a PIO buffer is
1139 * available after qib_verbs_send() returned an error that no buffers were
1140 * available. Disable the interrupt if there are no more QPs waiting.
1141 */
1142void qib_ib_piobufavail(struct qib_devdata *dd)
1143{
1144 struct qib_ibdev *dev = &dd->verbs_dev;
1145 struct list_head *list;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -08001146 struct rvt_qp *qps[5];
1147 struct rvt_qp *qp;
Ralph Campbellf9315512010-05-23 21:44:54 -07001148 unsigned long flags;
1149 unsigned i, n;
Dennis Dalessandroffc26902016-01-22 12:45:11 -08001150 struct qib_qp_priv *priv;
Ralph Campbellf9315512010-05-23 21:44:54 -07001151
1152 list = &dev->piowait;
1153 n = 0;
1154
1155 /*
1156 * Note: checking that the piowait list is empty and clearing
1157 * the buffer available interrupt needs to be atomic or we
1158 * could end up with QPs on the wait list with the interrupt
1159 * disabled.
1160 */
Harish Chegondicd182012016-01-22 12:56:14 -08001161 spin_lock_irqsave(&dev->rdi.pending_lock, flags);
Ralph Campbellf9315512010-05-23 21:44:54 -07001162 while (!list_empty(list)) {
1163 if (n == ARRAY_SIZE(qps))
1164 goto full;
Dennis Dalessandroffc26902016-01-22 12:45:11 -08001165 priv = list_entry(list->next, struct qib_qp_priv, iowait);
1166 qp = priv->owner;
1167 list_del_init(&priv->iowait);
Sebastian Sanchez238b1862016-12-07 19:34:00 -08001168 rvt_get_qp(qp);
Ralph Campbellf9315512010-05-23 21:44:54 -07001169 qps[n++] = qp;
1170 }
1171 dd->f_wantpiobuf_intr(dd, 0);
1172full:
Harish Chegondicd182012016-01-22 12:56:14 -08001173 spin_unlock_irqrestore(&dev->rdi.pending_lock, flags);
Ralph Campbellf9315512010-05-23 21:44:54 -07001174
1175 for (i = 0; i < n; i++) {
1176 qp = qps[i];
1177
1178 spin_lock_irqsave(&qp->s_lock, flags);
Harish Chegondi01ba79d2016-01-22 12:56:46 -08001179 if (qp->s_flags & RVT_S_WAIT_PIO) {
1180 qp->s_flags &= ~RVT_S_WAIT_PIO;
Ralph Campbellf9315512010-05-23 21:44:54 -07001181 qib_schedule_send(qp);
1182 }
1183 spin_unlock_irqrestore(&qp->s_lock, flags);
1184
1185 /* Notify qib_destroy_qp() if it is waiting. */
Sebastian Sanchez238b1862016-12-07 19:34:00 -08001186 rvt_put_qp(qp);
Ralph Campbellf9315512010-05-23 21:44:54 -07001187 }
1188}
1189
Harish Chegondi530a5d82016-02-03 14:20:52 -08001190static int qib_query_port(struct rvt_dev_info *rdi, u8 port_num,
Ralph Campbellf9315512010-05-23 21:44:54 -07001191 struct ib_port_attr *props)
1192{
Harish Chegondi530a5d82016-02-03 14:20:52 -08001193 struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
1194 struct qib_devdata *dd = dd_from_dev(ibdev);
1195 struct qib_pportdata *ppd = &dd->pport[port_num - 1];
Ralph Campbellf9315512010-05-23 21:44:54 -07001196 enum ib_mtu mtu;
1197 u16 lid = ppd->lid;
1198
Or Gerlitzc4550c62017-01-24 13:02:39 +02001199 /* props being zeroed by the caller, avoid zeroing it here */
Ralph Campbellf9315512010-05-23 21:44:54 -07001200 props->lid = lid ? lid : be16_to_cpu(IB_LID_PERMISSIVE);
1201 props->lmc = ppd->lmc;
Ralph Campbellf9315512010-05-23 21:44:54 -07001202 props->state = dd->f_iblink_state(ppd->lastibcstat);
1203 props->phys_state = dd->f_ibphys_portstate(ppd->lastibcstat);
Ralph Campbellf9315512010-05-23 21:44:54 -07001204 props->gid_tbl_len = QIB_GUIDS_PER_PORT;
Ralph Campbellf9315512010-05-23 21:44:54 -07001205 props->active_width = ppd->link_width_active;
1206 /* See rate_show() */
1207 props->active_speed = ppd->link_speed_active;
1208 props->max_vl_num = qib_num_vls(ppd->vls_supported);
Ralph Campbellf9315512010-05-23 21:44:54 -07001209
1210 props->max_mtu = qib_ibmtu ? qib_ibmtu : IB_MTU_4096;
1211 switch (ppd->ibmtu) {
1212 case 4096:
1213 mtu = IB_MTU_4096;
1214 break;
1215 case 2048:
1216 mtu = IB_MTU_2048;
1217 break;
1218 case 1024:
1219 mtu = IB_MTU_1024;
1220 break;
1221 case 512:
1222 mtu = IB_MTU_512;
1223 break;
1224 case 256:
1225 mtu = IB_MTU_256;
1226 break;
1227 default:
1228 mtu = IB_MTU_2048;
1229 }
1230 props->active_mtu = mtu;
Ralph Campbellf9315512010-05-23 21:44:54 -07001231
1232 return 0;
1233}
1234
1235static int qib_modify_device(struct ib_device *device,
1236 int device_modify_mask,
1237 struct ib_device_modify *device_modify)
1238{
1239 struct qib_devdata *dd = dd_from_ibdev(device);
1240 unsigned i;
1241 int ret;
1242
1243 if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
1244 IB_DEVICE_MODIFY_NODE_DESC)) {
1245 ret = -EOPNOTSUPP;
1246 goto bail;
1247 }
1248
1249 if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC) {
Yuval Shaiabd99fde2016-08-25 10:57:07 -07001250 memcpy(device->node_desc, device_modify->node_desc,
1251 IB_DEVICE_NODE_DESC_MAX);
Ralph Campbellf9315512010-05-23 21:44:54 -07001252 for (i = 0; i < dd->num_pports; i++) {
1253 struct qib_ibport *ibp = &dd->pport[i].ibport_data;
1254
1255 qib_node_desc_chg(ibp);
1256 }
1257 }
1258
1259 if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) {
1260 ib_qib_sys_image_guid =
1261 cpu_to_be64(device_modify->sys_image_guid);
1262 for (i = 0; i < dd->num_pports; i++) {
1263 struct qib_ibport *ibp = &dd->pport[i].ibport_data;
1264
1265 qib_sys_guid_chg(ibp);
1266 }
1267 }
1268
1269 ret = 0;
1270
1271bail:
1272 return ret;
1273}
1274
Harish Chegondi20f333b2016-02-14 12:09:55 -08001275static int qib_shut_down_port(struct rvt_dev_info *rdi, u8 port_num)
Ralph Campbellf9315512010-05-23 21:44:54 -07001276{
Harish Chegondi530a5d82016-02-03 14:20:52 -08001277 struct qib_ibdev *ibdev = container_of(rdi, struct qib_ibdev, rdi);
1278 struct qib_devdata *dd = dd_from_dev(ibdev);
1279 struct qib_pportdata *ppd = &dd->pport[port_num - 1];
Ralph Campbellf9315512010-05-23 21:44:54 -07001280
Harish Chegondi530a5d82016-02-03 14:20:52 -08001281 qib_set_linkstate(ppd, QIB_IB_LINKDOWN);
1282
Ralph Campbellf9315512010-05-23 21:44:54 -07001283 return 0;
1284}
1285
Dennis Dalessandro23667542016-02-03 14:20:44 -08001286static int qib_get_guid_be(struct rvt_dev_info *rdi, struct rvt_ibport *rvp,
1287 int guid_index, __be64 *guid)
Ralph Campbellf9315512010-05-23 21:44:54 -07001288{
Dennis Dalessandro23667542016-02-03 14:20:44 -08001289 struct qib_ibport *ibp = container_of(rvp, struct qib_ibport, rvp);
1290 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
Ralph Campbellf9315512010-05-23 21:44:54 -07001291
Dennis Dalessandro23667542016-02-03 14:20:44 -08001292 if (guid_index == 0)
1293 *guid = ppd->guid;
1294 else if (guid_index < QIB_GUIDS_PER_PORT)
1295 *guid = ibp->guids[guid_index - 1];
1296 else
1297 return -EINVAL;
Ralph Campbellf9315512010-05-23 21:44:54 -07001298
Dennis Dalessandro23667542016-02-03 14:20:44 -08001299 return 0;
Ralph Campbellf9315512010-05-23 21:44:54 -07001300}
1301
Dasaratharaman Chandramouli90898852017-04-29 14:41:18 -04001302int qib_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr)
Ralph Campbellf9315512010-05-23 21:44:54 -07001303{
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001304 if (rdma_ah_get_sl(ah_attr) > 15)
Dennis Dalessandro96ab1ac2016-01-22 12:46:07 -08001305 return -EINVAL;
1306
Don Hiatt13c19222017-08-04 13:53:51 -07001307 if (rdma_ah_get_dlid(ah_attr) == 0)
1308 return -EINVAL;
1309 if (rdma_ah_get_dlid(ah_attr) >=
1310 be16_to_cpu(IB_MULTICAST_LID_BASE) &&
1311 rdma_ah_get_dlid(ah_attr) !=
1312 be16_to_cpu(IB_LID_PERMISSIVE) &&
1313 !(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH))
1314 return -EINVAL;
1315
Ralph Campbellf9315512010-05-23 21:44:54 -07001316 return 0;
Ralph Campbellf9315512010-05-23 21:44:54 -07001317}
1318
Harish Chegondi5418a5a2016-01-22 12:56:08 -08001319static void qib_notify_new_ah(struct ib_device *ibdev,
Dasaratharaman Chandramouli90898852017-04-29 14:41:18 -04001320 struct rdma_ah_attr *ah_attr,
Harish Chegondi5418a5a2016-01-22 12:56:08 -08001321 struct rvt_ah *ah)
1322{
1323 struct qib_ibport *ibp;
1324 struct qib_pportdata *ppd;
1325
1326 /*
1327 * Do not trust reading anything from rvt_ah at this point as it is not
1328 * done being setup. We can however modify things which we need to set.
1329 */
1330
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001331 ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr));
Harish Chegondi5418a5a2016-01-22 12:56:08 -08001332 ppd = ppd_from_ibp(ibp);
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001333 ah->vl = ibp->sl_to_vl[rdma_ah_get_sl(&ah->attr)];
Harish Chegondi5418a5a2016-01-22 12:56:08 -08001334 ah->log_pmtu = ilog2(ppd->ibmtu);
1335}
1336
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +00001337struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid)
1338{
Dasaratharaman Chandramouli90898852017-04-29 14:41:18 -04001339 struct rdma_ah_attr attr;
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +00001340 struct ib_ah *ah = ERR_PTR(-EINVAL);
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -08001341 struct rvt_qp *qp0;
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001342 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04001343 struct qib_devdata *dd = dd_from_ppd(ppd);
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001344 u8 port_num = ppd->port;
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +00001345
Mike Marciniszyn041af0b2015-01-16 10:50:32 -05001346 memset(&attr, 0, sizeof(attr));
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04001347 attr.type = rdma_ah_find_type(&dd->verbs_dev.rdi.ibdev, port_num);
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -04001348 rdma_ah_set_dlid(&attr, dlid);
1349 rdma_ah_set_port_num(&attr, port_num);
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +00001350 rcu_read_lock();
Harish Chegondif24a6d42016-01-22 12:56:02 -08001351 qp0 = rcu_dereference(ibp->rvp.qp[0]);
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +00001352 if (qp0)
Gal Pressmanb090c4e2018-12-12 11:09:05 +02001353 ah = rdma_create_ah(qp0->ibqp.pd, &attr, 0);
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +00001354 rcu_read_unlock();
1355 return ah;
1356}
1357
Ralph Campbellf9315512010-05-23 21:44:54 -07001358/**
Ralph Campbellf9315512010-05-23 21:44:54 -07001359 * qib_get_npkeys - return the size of the PKEY table for context 0
1360 * @dd: the qlogic_ib device
1361 */
1362unsigned qib_get_npkeys(struct qib_devdata *dd)
1363{
1364 return ARRAY_SIZE(dd->rcd[0]->pkeys);
1365}
1366
1367/*
1368 * Return the indexed PKEY from the port PKEY table.
1369 * No need to validate rcd[ctxt]; the port is setup if we are here.
1370 */
1371unsigned qib_get_pkey(struct qib_ibport *ibp, unsigned index)
1372{
1373 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1374 struct qib_devdata *dd = ppd->dd;
1375 unsigned ctxt = ppd->hw_pidx;
1376 unsigned ret;
1377
1378 /* dd->rcd null if mini_init or some init failures */
1379 if (!dd->rcd || index >= ARRAY_SIZE(dd->rcd[ctxt]->pkeys))
1380 ret = 0;
1381 else
1382 ret = dd->rcd[ctxt]->pkeys[index];
1383
1384 return ret;
1385}
1386
Ralph Campbellf9315512010-05-23 21:44:54 -07001387static void init_ibport(struct qib_pportdata *ppd)
1388{
1389 struct qib_verbs_counters cntrs;
1390 struct qib_ibport *ibp = &ppd->ibport_data;
1391
Harish Chegondif24a6d42016-01-22 12:56:02 -08001392 spin_lock_init(&ibp->rvp.lock);
Ralph Campbellf9315512010-05-23 21:44:54 -07001393 /* Set the prefix to the default value (see ch. 4.1.1) */
Harish Chegondif24a6d42016-01-22 12:56:02 -08001394 ibp->rvp.gid_prefix = IB_DEFAULT_GID_PREFIX;
1395 ibp->rvp.sm_lid = be16_to_cpu(IB_LID_PERMISSIVE);
1396 ibp->rvp.port_cap_flags = IB_PORT_SYS_IMAGE_GUID_SUP |
Ralph Campbellf9315512010-05-23 21:44:54 -07001397 IB_PORT_CLIENT_REG_SUP | IB_PORT_SL_MAP_SUP |
1398 IB_PORT_TRAP_SUP | IB_PORT_AUTO_MIGR_SUP |
1399 IB_PORT_DR_NOTICE_SUP | IB_PORT_CAP_MASK_NOTICE_SUP |
1400 IB_PORT_OTHER_LOCAL_CHANGES_SUP;
1401 if (ppd->dd->flags & QIB_HAS_LINK_LATENCY)
Harish Chegondif24a6d42016-01-22 12:56:02 -08001402 ibp->rvp.port_cap_flags |= IB_PORT_LINK_LATENCY_SUP;
1403 ibp->rvp.pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
1404 ibp->rvp.pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
1405 ibp->rvp.pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
1406 ibp->rvp.pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
1407 ibp->rvp.pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
Ralph Campbellf9315512010-05-23 21:44:54 -07001408
1409 /* Snapshot current HW counters to "clear" them. */
1410 qib_get_counters(ppd, &cntrs);
1411 ibp->z_symbol_error_counter = cntrs.symbol_error_counter;
1412 ibp->z_link_error_recovery_counter =
1413 cntrs.link_error_recovery_counter;
1414 ibp->z_link_downed_counter = cntrs.link_downed_counter;
1415 ibp->z_port_rcv_errors = cntrs.port_rcv_errors;
1416 ibp->z_port_rcv_remphys_errors = cntrs.port_rcv_remphys_errors;
1417 ibp->z_port_xmit_discards = cntrs.port_xmit_discards;
1418 ibp->z_port_xmit_data = cntrs.port_xmit_data;
1419 ibp->z_port_rcv_data = cntrs.port_rcv_data;
1420 ibp->z_port_xmit_packets = cntrs.port_xmit_packets;
1421 ibp->z_port_rcv_packets = cntrs.port_rcv_packets;
1422 ibp->z_local_link_integrity_errors =
1423 cntrs.local_link_integrity_errors;
1424 ibp->z_excessive_buffer_overrun_errors =
1425 cntrs.excessive_buffer_overrun_errors;
1426 ibp->z_vl15_dropped = cntrs.vl15_dropped;
Harish Chegondif24a6d42016-01-22 12:56:02 -08001427 RCU_INIT_POINTER(ibp->rvp.qp[0], NULL);
1428 RCU_INIT_POINTER(ibp->rvp.qp[1], NULL);
Ralph Campbellf9315512010-05-23 21:44:54 -07001429}
1430
1431/**
Harish Chegondi0aeddea2016-01-22 12:56:40 -08001432 * qib_fill_device_attr - Fill in rvt dev info device attributes.
1433 * @dd: the device data structure
1434 */
1435static void qib_fill_device_attr(struct qib_devdata *dd)
1436{
1437 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
1438
1439 memset(&rdi->dparms.props, 0, sizeof(rdi->dparms.props));
1440
1441 rdi->dparms.props.max_pd = ib_qib_max_pds;
1442 rdi->dparms.props.max_ah = ib_qib_max_ahs;
1443 rdi->dparms.props.device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
1444 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
1445 IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN |
1446 IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE;
1447 rdi->dparms.props.page_size_cap = PAGE_SIZE;
1448 rdi->dparms.props.vendor_id =
1449 QIB_SRC_OUI_1 << 16 | QIB_SRC_OUI_2 << 8 | QIB_SRC_OUI_3;
1450 rdi->dparms.props.vendor_part_id = dd->deviceid;
1451 rdi->dparms.props.hw_ver = dd->minrev;
1452 rdi->dparms.props.sys_image_guid = ib_qib_sys_image_guid;
1453 rdi->dparms.props.max_mr_size = ~0ULL;
1454 rdi->dparms.props.max_qp = ib_qib_max_qps;
1455 rdi->dparms.props.max_qp_wr = ib_qib_max_qp_wrs;
Steve Wise33023fb2018-06-18 08:05:26 -07001456 rdi->dparms.props.max_send_sge = ib_qib_max_sges;
1457 rdi->dparms.props.max_recv_sge = ib_qib_max_sges;
Harish Chegondi0aeddea2016-01-22 12:56:40 -08001458 rdi->dparms.props.max_sge_rd = ib_qib_max_sges;
1459 rdi->dparms.props.max_cq = ib_qib_max_cqs;
1460 rdi->dparms.props.max_cqe = ib_qib_max_cqes;
1461 rdi->dparms.props.max_ah = ib_qib_max_ahs;
1462 rdi->dparms.props.max_mr = rdi->lkey_table.max;
1463 rdi->dparms.props.max_fmr = rdi->lkey_table.max;
1464 rdi->dparms.props.max_map_per_fmr = 32767;
1465 rdi->dparms.props.max_qp_rd_atom = QIB_MAX_RDMA_ATOMIC;
1466 rdi->dparms.props.max_qp_init_rd_atom = 255;
1467 rdi->dparms.props.max_srq = ib_qib_max_srqs;
1468 rdi->dparms.props.max_srq_wr = ib_qib_max_srq_wrs;
1469 rdi->dparms.props.max_srq_sge = ib_qib_max_srq_sges;
1470 rdi->dparms.props.atomic_cap = IB_ATOMIC_GLOB;
1471 rdi->dparms.props.max_pkeys = qib_get_npkeys(dd);
1472 rdi->dparms.props.max_mcast_grp = ib_qib_max_mcast_grps;
1473 rdi->dparms.props.max_mcast_qp_attach = ib_qib_max_mcast_qp_attached;
1474 rdi->dparms.props.max_total_mcast_qp_attach =
1475 rdi->dparms.props.max_mcast_qp_attach *
1476 rdi->dparms.props.max_mcast_grp;
Mike Marciniszyn9ec4faa2016-07-01 16:02:18 -07001477 /* post send table */
1478 dd->verbs_dev.rdi.post_parms = qib_post_parms;
Venkata Sandeep Dhanalakota116aa032018-09-26 10:44:42 -07001479
1480 /* opcode translation table */
1481 dd->verbs_dev.rdi.wc_opcode = ib_qib_wc_opcode;
Harish Chegondi0aeddea2016-01-22 12:56:40 -08001482}
1483
Kamal Heib16b0ba92018-12-10 21:09:43 +02001484static const struct ib_device_ops qib_dev_ops = {
Parav Panditea4baf72018-12-18 14:28:30 +02001485 .init_port = qib_create_port_files,
Kamal Heib16b0ba92018-12-10 21:09:43 +02001486 .modify_device = qib_modify_device,
1487 .process_mad = qib_process_mad,
1488};
1489
Harish Chegondi0aeddea2016-01-22 12:56:40 -08001490/**
Ralph Campbellf9315512010-05-23 21:44:54 -07001491 * qib_register_ib_device - register our device with the infiniband core
1492 * @dd: the device data structure
1493 * Return the allocated qib_ibdev pointer or NULL on error.
1494 */
1495int qib_register_ib_device(struct qib_devdata *dd)
1496{
1497 struct qib_ibdev *dev = &dd->verbs_dev;
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -08001498 struct ib_device *ibdev = &dev->rdi.ibdev;
Ralph Campbellf9315512010-05-23 21:44:54 -07001499 struct qib_pportdata *ppd = dd->pport;
Harish Chegondi76fec3e2016-01-22 12:56:21 -08001500 unsigned i, ctxt;
Ralph Campbellf9315512010-05-23 21:44:54 -07001501 int ret;
1502
Mike Marciniszynaf061a62011-09-23 13:16:44 -04001503 get_random_bytes(&dev->qp_rnd, sizeof(dev->qp_rnd));
Ralph Campbellf9315512010-05-23 21:44:54 -07001504 for (i = 0; i < dd->num_pports; i++)
1505 init_ibport(ppd + i);
1506
1507 /* Only need to initialize non-zero fields. */
Kees Cook4037c922017-10-04 17:45:35 -07001508 timer_setup(&dev->mem_timer, mem_timer, 0);
Ralph Campbellf9315512010-05-23 21:44:54 -07001509
Ralph Campbellf9315512010-05-23 21:44:54 -07001510 INIT_LIST_HEAD(&dev->piowait);
1511 INIT_LIST_HEAD(&dev->dmawait);
1512 INIT_LIST_HEAD(&dev->txwait);
1513 INIT_LIST_HEAD(&dev->memwait);
1514 INIT_LIST_HEAD(&dev->txreq_free);
1515
1516 if (ppd->sdma_descq_cnt) {
1517 dev->pio_hdrs = dma_alloc_coherent(&dd->pcidev->dev,
1518 ppd->sdma_descq_cnt *
1519 sizeof(struct qib_pio_header),
1520 &dev->pio_hdrs_phys,
1521 GFP_KERNEL);
1522 if (!dev->pio_hdrs) {
1523 ret = -ENOMEM;
1524 goto err_hdrs;
1525 }
1526 }
1527
1528 for (i = 0; i < ppd->sdma_descq_cnt; i++) {
1529 struct qib_verbs_txreq *tx;
1530
Mike Marciniszyn041af0b2015-01-16 10:50:32 -05001531 tx = kzalloc(sizeof(*tx), GFP_KERNEL);
Ralph Campbellf9315512010-05-23 21:44:54 -07001532 if (!tx) {
1533 ret = -ENOMEM;
1534 goto err_tx;
1535 }
1536 tx->hdr_inx = i;
1537 list_add(&tx->txreq.list, &dev->txreq_free);
1538 }
1539
1540 /*
1541 * The system image GUID is supposed to be the same for all
1542 * IB HCAs in a single system but since there can be other
1543 * device types in the system, we can't be sure this is unique.
1544 */
1545 if (!ib_qib_sys_image_guid)
1546 ib_qib_sys_image_guid = ppd->guid;
1547
Ralph Campbellf9315512010-05-23 21:44:54 -07001548 ibdev->owner = THIS_MODULE;
1549 ibdev->node_guid = ppd->guid;
Ralph Campbellf9315512010-05-23 21:44:54 -07001550 ibdev->phys_port_cnt = dd->num_pports;
Bart Van Assche989ab352017-01-20 13:04:26 -08001551 ibdev->dev.parent = &dd->pcidev->dev;
Ralph Campbellf9315512010-05-23 21:44:54 -07001552
1553 snprintf(ibdev->node_desc, sizeof(ibdev->node_desc),
Vinit Agnihotrie2eed582013-03-14 18:13:41 +00001554 "Intel Infiniband HCA %s", init_utsname()->nodename);
Ralph Campbellf9315512010-05-23 21:44:54 -07001555
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -08001556 /*
1557 * Fill in rvt info object.
1558 */
Dennis Dalessandro6a9df402016-01-22 12:45:20 -08001559 dd->verbs_dev.rdi.driver_f.get_pci_dev = qib_get_pci_dev;
Dennis Dalessandro96ab1ac2016-01-22 12:46:07 -08001560 dd->verbs_dev.rdi.driver_f.check_ah = qib_check_ah;
Kaike Wand205a06a2018-09-26 10:26:44 -07001561 dd->verbs_dev.rdi.driver_f.setup_wqe = qib_check_send_wqe;
Harish Chegondi5418a5a2016-01-22 12:56:08 -08001562 dd->verbs_dev.rdi.driver_f.notify_new_ah = qib_notify_new_ah;
Harish Chegondi20f333b2016-02-14 12:09:55 -08001563 dd->verbs_dev.rdi.driver_f.alloc_qpn = qib_alloc_qpn;
1564 dd->verbs_dev.rdi.driver_f.qp_priv_alloc = qib_qp_priv_alloc;
1565 dd->verbs_dev.rdi.driver_f.qp_priv_free = qib_qp_priv_free;
Harish Chegondi47c7ea62016-01-22 12:56:52 -08001566 dd->verbs_dev.rdi.driver_f.free_all_qps = qib_free_all_qps;
Harish Chegondi20f333b2016-02-14 12:09:55 -08001567 dd->verbs_dev.rdi.driver_f.notify_qp_reset = qib_notify_qp_reset;
Harish Chegondidb3ef0e2016-01-22 13:07:42 -08001568 dd->verbs_dev.rdi.driver_f.do_send = qib_do_send;
1569 dd->verbs_dev.rdi.driver_f.schedule_send = qib_schedule_send;
Harish Chegondi20f333b2016-02-14 12:09:55 -08001570 dd->verbs_dev.rdi.driver_f.quiesce_qp = qib_quiesce_qp;
1571 dd->verbs_dev.rdi.driver_f.stop_send_queue = qib_stop_send_queue;
1572 dd->verbs_dev.rdi.driver_f.flush_qp_waiters = qib_flush_qp_waiters;
1573 dd->verbs_dev.rdi.driver_f.notify_error_qp = qib_notify_error_qp;
Venkata Sandeep Dhanalakotab4238e72017-02-08 05:27:25 -08001574 dd->verbs_dev.rdi.driver_f.notify_restart_rc = qib_restart_rc;
Harish Chegondi20f333b2016-02-14 12:09:55 -08001575 dd->verbs_dev.rdi.driver_f.mtu_to_path_mtu = qib_mtu_to_path_mtu;
1576 dd->verbs_dev.rdi.driver_f.mtu_from_qp = qib_mtu_from_qp;
1577 dd->verbs_dev.rdi.driver_f.get_pmtu_from_attr = qib_get_pmtu_from_attr;
Mike Marciniszyn46a80d62016-02-14 12:10:04 -08001578 dd->verbs_dev.rdi.driver_f.schedule_send_no_lock = _qib_schedule_send;
Harish Chegondi530a5d82016-02-03 14:20:52 -08001579 dd->verbs_dev.rdi.driver_f.query_port_state = qib_query_port;
Harish Chegondi20f333b2016-02-14 12:09:55 -08001580 dd->verbs_dev.rdi.driver_f.shut_down_port = qib_shut_down_port;
Harish Chegondi530a5d82016-02-03 14:20:52 -08001581 dd->verbs_dev.rdi.driver_f.cap_mask_chg = qib_cap_mask_chg;
Dennis Dalessandro611ac092016-02-14 12:10:45 -08001582 dd->verbs_dev.rdi.driver_f.notify_create_mad_agent =
1583 qib_notify_create_mad_agent;
1584 dd->verbs_dev.rdi.driver_f.notify_free_mad_agent =
1585 qib_notify_free_mad_agent;
Harish Chegondi47c7ea62016-01-22 12:56:52 -08001586
Harish Chegondi70696ea2016-02-03 14:20:27 -08001587 dd->verbs_dev.rdi.dparms.max_rdma_atomic = QIB_MAX_RDMA_ATOMIC;
Dennis Dalessandro23667542016-02-03 14:20:44 -08001588 dd->verbs_dev.rdi.driver_f.get_guid_be = qib_get_guid_be;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -08001589 dd->verbs_dev.rdi.dparms.lkey_table_size = qib_lkey_table_size;
Harish Chegondi47c7ea62016-01-22 12:56:52 -08001590 dd->verbs_dev.rdi.dparms.qp_table_size = ib_qib_qp_table_size;
1591 dd->verbs_dev.rdi.dparms.qpn_start = 1;
1592 dd->verbs_dev.rdi.dparms.qpn_res_start = QIB_KD_QP;
1593 dd->verbs_dev.rdi.dparms.qpn_res_end = QIB_KD_QP; /* Reserve one QP */
1594 dd->verbs_dev.rdi.dparms.qpn_inc = 1;
1595 dd->verbs_dev.rdi.dparms.qos_shift = 1;
Harish Chegondi034a3e72016-01-22 13:08:01 -08001596 dd->verbs_dev.rdi.dparms.psn_mask = QIB_PSN_MASK;
Harish Chegondi70696ea2016-02-03 14:20:27 -08001597 dd->verbs_dev.rdi.dparms.psn_shift = QIB_PSN_SHIFT;
1598 dd->verbs_dev.rdi.dparms.psn_modify_mask = QIB_PSN_MASK;
Harish Chegondi76fec3e2016-01-22 12:56:21 -08001599 dd->verbs_dev.rdi.dparms.nports = dd->num_pports;
1600 dd->verbs_dev.rdi.dparms.npkeys = qib_get_npkeys(dd);
Harish Chegondi4bb88e52016-01-22 13:07:36 -08001601 dd->verbs_dev.rdi.dparms.node = dd->assigned_node_id;
Harish Chegondi530a5d82016-02-03 14:20:52 -08001602 dd->verbs_dev.rdi.dparms.core_cap_flags = RDMA_CORE_PORT_IBA_IB;
1603 dd->verbs_dev.rdi.dparms.max_mad_size = IB_MGMT_MAD_SIZE;
Brian Welty019f1182018-09-26 10:44:33 -07001604 dd->verbs_dev.rdi.dparms.sge_copy_mode = RVT_SGE_COPY_MEMCPY;
Harish Chegondi530a5d82016-02-03 14:20:52 -08001605
Harish Chegondi0aeddea2016-01-22 12:56:40 -08001606 qib_fill_device_attr(dd);
1607
Harish Chegondi76fec3e2016-01-22 12:56:21 -08001608 ppd = dd->pport;
1609 for (i = 0; i < dd->num_pports; i++, ppd++) {
1610 ctxt = ppd->hw_pidx;
1611 rvt_init_port(&dd->verbs_dev.rdi,
1612 &ppd->ibport_data.rvp,
1613 i,
1614 dd->rcd[ctxt]->pkeys);
1615 }
Parav Pandit508a5232018-10-11 22:31:54 +03001616 rdma_set_device_sysfs_group(&dd->verbs_dev.rdi.ibdev, &qib_attr_group);
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -08001617
Kamal Heib16b0ba92018-12-10 21:09:43 +02001618 ib_set_device_ops(ibdev, &qib_dev_ops);
Matan Barak0ede73b2018-03-19 15:02:34 +02001619 ret = rvt_register_device(&dd->verbs_dev.rdi, RDMA_DRIVER_QIB);
Ralph Campbellf9315512010-05-23 21:44:54 -07001620 if (ret)
Dennis Dalessandro5196aa92016-01-22 13:07:30 -08001621 goto err_tx;
Ralph Campbellf9315512010-05-23 21:44:54 -07001622
Dennis Dalessandro5196aa92016-01-22 13:07:30 -08001623 return ret;
Ralph Campbellf9315512010-05-23 21:44:54 -07001624
Ralph Campbellf9315512010-05-23 21:44:54 -07001625err_tx:
1626 while (!list_empty(&dev->txreq_free)) {
1627 struct list_head *l = dev->txreq_free.next;
1628 struct qib_verbs_txreq *tx;
1629
1630 list_del(l);
1631 tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
1632 kfree(tx);
1633 }
1634 if (ppd->sdma_descq_cnt)
1635 dma_free_coherent(&dd->pcidev->dev,
1636 ppd->sdma_descq_cnt *
1637 sizeof(struct qib_pio_header),
1638 dev->pio_hdrs, dev->pio_hdrs_phys);
1639err_hdrs:
Ralph Campbellf9315512010-05-23 21:44:54 -07001640 qib_dev_err(dd, "cannot register verbs: %d!\n", -ret);
Ralph Campbellf9315512010-05-23 21:44:54 -07001641 return ret;
1642}
1643
1644void qib_unregister_ib_device(struct qib_devdata *dd)
1645{
1646 struct qib_ibdev *dev = &dd->verbs_dev;
Ralph Campbellf9315512010-05-23 21:44:54 -07001647
1648 qib_verbs_unregister_sysfs(dd);
1649
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -08001650 rvt_unregister_device(&dd->verbs_dev.rdi);
Ralph Campbellf9315512010-05-23 21:44:54 -07001651
1652 if (!list_empty(&dev->piowait))
1653 qib_dev_err(dd, "piowait list not empty!\n");
1654 if (!list_empty(&dev->dmawait))
1655 qib_dev_err(dd, "dmawait list not empty!\n");
1656 if (!list_empty(&dev->txwait))
1657 qib_dev_err(dd, "txwait list not empty!\n");
1658 if (!list_empty(&dev->memwait))
1659 qib_dev_err(dd, "memwait list not empty!\n");
Ralph Campbellf9315512010-05-23 21:44:54 -07001660
Ralph Campbellf9315512010-05-23 21:44:54 -07001661 del_timer_sync(&dev->mem_timer);
Ralph Campbellf9315512010-05-23 21:44:54 -07001662 while (!list_empty(&dev->txreq_free)) {
1663 struct list_head *l = dev->txreq_free.next;
1664 struct qib_verbs_txreq *tx;
1665
1666 list_del(l);
1667 tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
1668 kfree(tx);
1669 }
1670 if (dd->pport->sdma_descq_cnt)
1671 dma_free_coherent(&dd->pcidev->dev,
1672 dd->pport->sdma_descq_cnt *
1673 sizeof(struct qib_pio_header),
1674 dev->pio_hdrs, dev->pio_hdrs_phys);
Ralph Campbellf9315512010-05-23 21:44:54 -07001675}
Mike Marciniszyn551ace12012-07-19 13:03:56 +00001676
Mike Marciniszyn46a80d62016-02-14 12:10:04 -08001677/**
1678 * _qib_schedule_send - schedule progress
1679 * @qp - the qp
1680 *
1681 * This schedules progress w/o regard to the s_flags.
1682 *
1683 * It is only used in post send, which doesn't hold
1684 * the s_lock.
1685 */
Dennis Dalessandro5da0fc92018-09-28 07:17:09 -07001686bool _qib_schedule_send(struct rvt_qp *qp)
Mike Marciniszyn46a80d62016-02-14 12:10:04 -08001687{
1688 struct qib_ibport *ibp =
1689 to_iport(qp->ibqp.device, qp->port_num);
1690 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1691 struct qib_qp_priv *priv = qp->priv;
1692
Dennis Dalessandro5da0fc92018-09-28 07:17:09 -07001693 return queue_work(ppd->qib_wq, &priv->s_work);
Mike Marciniszyn46a80d62016-02-14 12:10:04 -08001694}
1695
1696/**
1697 * qib_schedule_send - schedule progress
1698 * @qp - the qp
1699 *
1700 * This schedules qp progress. The s_lock
1701 * should be held.
Mike Marciniszyn551ace12012-07-19 13:03:56 +00001702 */
Dennis Dalessandro5da0fc92018-09-28 07:17:09 -07001703bool qib_schedule_send(struct rvt_qp *qp)
Mike Marciniszyn551ace12012-07-19 13:03:56 +00001704{
Mike Marciniszyn46a80d62016-02-14 12:10:04 -08001705 if (qib_send_ok(qp))
Dennis Dalessandro5da0fc92018-09-28 07:17:09 -07001706 return _qib_schedule_send(qp);
1707 return false;
Mike Marciniszyn551ace12012-07-19 13:03:56 +00001708}