blob: 2ac0c0f79e74b239470fdd048655355fe00093e1 [file] [log] [blame]
Ralph Campbellf9315512010-05-23 21:44:54 -07001/*
Mike Marciniszynf7cf9a62013-06-15 17:06:58 -04002 * Copyright (c) 2012, 2013 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 <linux/err.h>
36#include <linux/vmalloc.h>
Dennis Dalessandro869a2a92016-01-22 12:45:02 -080037#include <rdma/rdma_vt.h>
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -040038#ifdef CONFIG_DEBUG_FS
39#include <linux/seq_file.h>
40#endif
Ralph Campbellf9315512010-05-23 21:44:54 -070041
42#include "qib.h"
43
Harish Chegondi898fa522016-01-22 12:56:27 -080044static inline unsigned mk_qpn(struct rvt_qpn_table *qpt,
45 struct rvt_qpn_map *map, unsigned off)
Ralph Campbellf9315512010-05-23 21:44:54 -070046{
Harish Chegondi898fa522016-01-22 12:56:27 -080047 return (map - qpt->map) * RVT_BITS_PER_PAGE + off;
Ralph Campbellf9315512010-05-23 21:44:54 -070048}
49
Harish Chegondi898fa522016-01-22 12:56:27 -080050static inline unsigned find_next_offset(struct rvt_qpn_table *qpt,
51 struct rvt_qpn_map *map, unsigned off,
Dennis Dalessandro84b3adc2016-09-25 07:41:05 -070052 unsigned n, u16 qpt_mask)
Ralph Campbellf9315512010-05-23 21:44:54 -070053{
Harish Chegondi898fa522016-01-22 12:56:27 -080054 if (qpt_mask) {
Ralph Campbellf9315512010-05-23 21:44:54 -070055 off++;
Harish Chegondi898fa522016-01-22 12:56:27 -080056 if (((off & qpt_mask) >> 1) >= n)
57 off = (off | qpt_mask) + 2;
58 } else {
59 off = find_next_zero_bit(map->page, RVT_BITS_PER_PAGE, off);
60 }
Ralph Campbellf9315512010-05-23 21:44:54 -070061 return off;
62}
63
Mike Marciniszyn9ec4faa2016-07-01 16:02:18 -070064const struct rvt_operation_params qib_post_parms[RVT_OPERATION_MAX] = {
65[IB_WR_RDMA_WRITE] = {
66 .length = sizeof(struct ib_rdma_wr),
67 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
68},
69
70[IB_WR_RDMA_READ] = {
71 .length = sizeof(struct ib_rdma_wr),
72 .qpt_support = BIT(IB_QPT_RC),
73 .flags = RVT_OPERATION_ATOMIC,
74},
75
76[IB_WR_ATOMIC_CMP_AND_SWP] = {
77 .length = sizeof(struct ib_atomic_wr),
78 .qpt_support = BIT(IB_QPT_RC),
79 .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE,
80},
81
82[IB_WR_ATOMIC_FETCH_AND_ADD] = {
83 .length = sizeof(struct ib_atomic_wr),
84 .qpt_support = BIT(IB_QPT_RC),
85 .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE,
86},
87
88[IB_WR_RDMA_WRITE_WITH_IMM] = {
89 .length = sizeof(struct ib_rdma_wr),
90 .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
91},
92
93[IB_WR_SEND] = {
94 .length = sizeof(struct ib_send_wr),
95 .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) |
96 BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
97},
98
99[IB_WR_SEND_WITH_IMM] = {
100 .length = sizeof(struct ib_send_wr),
101 .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) |
102 BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
103},
104
105};
106
Harish Chegondi898fa522016-01-22 12:56:27 -0800107static void get_map_page(struct rvt_qpn_table *qpt, struct rvt_qpn_map *map,
Vinit Agnihotrifbbeb862016-01-11 12:57:25 -0500108 gfp_t gfp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700109{
Vinit Agnihotrifbbeb862016-01-11 12:57:25 -0500110 unsigned long page = get_zeroed_page(gfp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700111
112 /*
113 * Free the page if someone raced with us installing it.
114 */
115
116 spin_lock(&qpt->lock);
117 if (map->page)
118 free_page(page);
119 else
120 map->page = (void *)page;
121 spin_unlock(&qpt->lock);
122}
123
124/*
125 * Allocate the next available QPN or
126 * zero/one for QP type IB_QPT_SMI/IB_QPT_GSI.
127 */
Harish Chegondi20f333b2016-02-14 12:09:55 -0800128int qib_alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
129 enum ib_qp_type type, u8 port, gfp_t gfp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700130{
131 u32 i, offset, max_scan, qpn;
Harish Chegondi898fa522016-01-22 12:56:27 -0800132 struct rvt_qpn_map *map;
Ralph Campbellf9315512010-05-23 21:44:54 -0700133 u32 ret;
Harish Chegondi47c7ea62016-01-22 12:56:52 -0800134 struct qib_ibdev *verbs_dev = container_of(rdi, struct qib_ibdev, rdi);
135 struct qib_devdata *dd = container_of(verbs_dev, struct qib_devdata,
136 verbs_dev);
Dennis Dalessandro84b3adc2016-09-25 07:41:05 -0700137 u16 qpt_mask = dd->qpn_mask;
Ralph Campbellf9315512010-05-23 21:44:54 -0700138
139 if (type == IB_QPT_SMI || type == IB_QPT_GSI) {
140 unsigned n;
141
142 ret = type == IB_QPT_GSI;
143 n = 1 << (ret + 2 * (port - 1));
144 spin_lock(&qpt->lock);
145 if (qpt->flags & n)
146 ret = -EINVAL;
147 else
148 qpt->flags |= n;
149 spin_unlock(&qpt->lock);
150 goto bail;
151 }
152
Mike Marciniszyn7c3edd32011-01-10 17:42:22 -0800153 qpn = qpt->last + 2;
Harish Chegondi898fa522016-01-22 12:56:27 -0800154 if (qpn >= RVT_QPN_MAX)
Ralph Campbellf9315512010-05-23 21:44:54 -0700155 qpn = 2;
Harish Chegondi898fa522016-01-22 12:56:27 -0800156 if (qpt_mask && ((qpn & qpt_mask) >> 1) >= dd->n_krcv_queues)
157 qpn = (qpn | qpt_mask) + 2;
158 offset = qpn & RVT_BITS_PER_PAGE_MASK;
159 map = &qpt->map[qpn / RVT_BITS_PER_PAGE];
Ralph Campbellf9315512010-05-23 21:44:54 -0700160 max_scan = qpt->nmaps - !offset;
161 for (i = 0;;) {
162 if (unlikely(!map->page)) {
Vinit Agnihotrifbbeb862016-01-11 12:57:25 -0500163 get_map_page(qpt, map, gfp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700164 if (unlikely(!map->page))
165 break;
166 }
167 do {
168 if (!test_and_set_bit(offset, map->page)) {
169 qpt->last = qpn;
170 ret = qpn;
171 goto bail;
172 }
Mike Marciniszyn2528ea62011-01-10 17:42:21 -0800173 offset = find_next_offset(qpt, map, offset,
Dennis Dalessandro84b3adc2016-09-25 07:41:05 -0700174 dd->n_krcv_queues, qpt_mask);
Ralph Campbellf9315512010-05-23 21:44:54 -0700175 qpn = mk_qpn(qpt, map, offset);
176 /*
177 * This test differs from alloc_pidmap().
178 * If find_next_offset() does find a zero
179 * bit, we don't need to check for QPN
180 * wrapping around past our starting QPN.
181 * We just need to be sure we don't loop
182 * forever.
183 */
Harish Chegondi898fa522016-01-22 12:56:27 -0800184 } while (offset < RVT_BITS_PER_PAGE && qpn < RVT_QPN_MAX);
Ralph Campbellf9315512010-05-23 21:44:54 -0700185 /*
186 * In order to keep the number of pages allocated to a
187 * minimum, we scan the all existing pages before increasing
188 * the size of the bitmap table.
189 */
190 if (++i > max_scan) {
Harish Chegondi898fa522016-01-22 12:56:27 -0800191 if (qpt->nmaps == RVT_QPNMAP_ENTRIES)
Ralph Campbellf9315512010-05-23 21:44:54 -0700192 break;
193 map = &qpt->map[qpt->nmaps++];
Mike Marciniszyn2528ea62011-01-10 17:42:21 -0800194 offset = 0;
Ralph Campbellf9315512010-05-23 21:44:54 -0700195 } else if (map < &qpt->map[qpt->nmaps]) {
196 ++map;
Mike Marciniszyn2528ea62011-01-10 17:42:21 -0800197 offset = 0;
Ralph Campbellf9315512010-05-23 21:44:54 -0700198 } else {
199 map = &qpt->map[0];
Mike Marciniszyn2528ea62011-01-10 17:42:21 -0800200 offset = 2;
Ralph Campbellf9315512010-05-23 21:44:54 -0700201 }
202 qpn = mk_qpn(qpt, map, offset);
203 }
204
205 ret = -ENOMEM;
206
207bail:
208 return ret;
209}
210
Ralph Campbellf9315512010-05-23 21:44:54 -0700211/**
212 * qib_free_all_qps - check for QPs still in use
Ralph Campbellf9315512010-05-23 21:44:54 -0700213 */
Harish Chegondi47c7ea62016-01-22 12:56:52 -0800214unsigned qib_free_all_qps(struct rvt_dev_info *rdi)
Ralph Campbellf9315512010-05-23 21:44:54 -0700215{
Harish Chegondi47c7ea62016-01-22 12:56:52 -0800216 struct qib_ibdev *verbs_dev = container_of(rdi, struct qib_ibdev, rdi);
217 struct qib_devdata *dd = container_of(verbs_dev, struct qib_devdata,
218 verbs_dev);
Ralph Campbellf9315512010-05-23 21:44:54 -0700219 unsigned n, qp_inuse = 0;
220
221 for (n = 0; n < dd->num_pports; n++) {
222 struct qib_ibport *ibp = &dd->pport[n].ibport_data;
223
Mike Marciniszynaf061a62011-09-23 13:16:44 -0400224 rcu_read_lock();
Harish Chegondif24a6d42016-01-22 12:56:02 -0800225 if (rcu_dereference(ibp->rvp.qp[0]))
Ralph Campbellf9315512010-05-23 21:44:54 -0700226 qp_inuse++;
Harish Chegondif24a6d42016-01-22 12:56:02 -0800227 if (rcu_dereference(ibp->rvp.qp[1]))
Ralph Campbellf9315512010-05-23 21:44:54 -0700228 qp_inuse++;
Mike Marciniszynaf061a62011-09-23 13:16:44 -0400229 rcu_read_unlock();
Ralph Campbellf9315512010-05-23 21:44:54 -0700230 }
Ralph Campbellf9315512010-05-23 21:44:54 -0700231 return qp_inuse;
232}
233
Harish Chegondi20f333b2016-02-14 12:09:55 -0800234void qib_notify_qp_reset(struct rvt_qp *qp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700235{
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800236 struct qib_qp_priv *priv = qp->priv;
Harish Chegondi47c7ea62016-01-22 12:56:52 -0800237
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800238 atomic_set(&priv->s_dma_busy, 0);
Ralph Campbellf9315512010-05-23 21:44:54 -0700239}
240
Harish Chegondi20f333b2016-02-14 12:09:55 -0800241void qib_notify_error_qp(struct rvt_qp *qp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700242{
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800243 struct qib_qp_priv *priv = qp->priv;
Ralph Campbellf9315512010-05-23 21:44:54 -0700244 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
Mike Marciniszyn16028f22011-01-10 17:42:20 -0800245
Harish Chegondicd182012016-01-22 12:56:14 -0800246 spin_lock(&dev->rdi.pending_lock);
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800247 if (!list_empty(&priv->iowait) && !(qp->s_flags & RVT_S_BUSY)) {
248 qp->s_flags &= ~RVT_S_ANY_WAIT_IO;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800249 list_del_init(&priv->iowait);
Ralph Campbellf9315512010-05-23 21:44:54 -0700250 }
Harish Chegondicd182012016-01-22 12:56:14 -0800251 spin_unlock(&dev->rdi.pending_lock);
Ralph Campbellf9315512010-05-23 21:44:54 -0700252
Harish Chegondi01ba79d2016-01-22 12:56:46 -0800253 if (!(qp->s_flags & RVT_S_BUSY)) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700254 qp->s_hdrwords = 0;
255 if (qp->s_rdma_mr) {
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800256 rvt_put_mr(qp->s_rdma_mr);
Ralph Campbellf9315512010-05-23 21:44:54 -0700257 qp->s_rdma_mr = NULL;
258 }
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800259 if (priv->s_tx) {
260 qib_put_txreq(priv->s_tx);
261 priv->s_tx = NULL;
Ralph Campbellf9315512010-05-23 21:44:54 -0700262 }
263 }
Ralph Campbellf9315512010-05-23 21:44:54 -0700264}
265
Harish Chegondi70696ea2016-02-03 14:20:27 -0800266static int mtu_to_enum(u32 mtu)
Ralph Campbellf9315512010-05-23 21:44:54 -0700267{
Harish Chegondi70696ea2016-02-03 14:20:27 -0800268 int enum_mtu;
Ralph Campbellf9315512010-05-23 21:44:54 -0700269
Harish Chegondi70696ea2016-02-03 14:20:27 -0800270 switch (mtu) {
271 case 4096:
272 enum_mtu = IB_MTU_4096;
Ralph Campbellf9315512010-05-23 21:44:54 -0700273 break;
Harish Chegondi70696ea2016-02-03 14:20:27 -0800274 case 2048:
275 enum_mtu = IB_MTU_2048;
Ralph Campbellf9315512010-05-23 21:44:54 -0700276 break;
Harish Chegondi70696ea2016-02-03 14:20:27 -0800277 case 1024:
278 enum_mtu = IB_MTU_1024;
Ralph Campbellf9315512010-05-23 21:44:54 -0700279 break;
Harish Chegondi70696ea2016-02-03 14:20:27 -0800280 case 512:
281 enum_mtu = IB_MTU_512;
Ralph Campbellf9315512010-05-23 21:44:54 -0700282 break;
Harish Chegondi70696ea2016-02-03 14:20:27 -0800283 case 256:
284 enum_mtu = IB_MTU_256;
Ralph Campbellf9315512010-05-23 21:44:54 -0700285 break;
Ralph Campbellf9315512010-05-23 21:44:54 -0700286 default:
Harish Chegondi70696ea2016-02-03 14:20:27 -0800287 enum_mtu = IB_MTU_2048;
Ralph Campbellf9315512010-05-23 21:44:54 -0700288 }
Harish Chegondi70696ea2016-02-03 14:20:27 -0800289 return enum_mtu;
290}
Ralph Campbellf9315512010-05-23 21:44:54 -0700291
Harish Chegondi20f333b2016-02-14 12:09:55 -0800292int qib_get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp,
293 struct ib_qp_attr *attr)
Harish Chegondi70696ea2016-02-03 14:20:27 -0800294{
295 int mtu, pmtu, pidx = qp->port_num - 1;
296 struct qib_ibdev *verbs_dev = container_of(rdi, struct qib_ibdev, rdi);
297 struct qib_devdata *dd = container_of(verbs_dev, struct qib_devdata,
298 verbs_dev);
299 mtu = ib_mtu_enum_to_int(attr->path_mtu);
300 if (mtu == -1)
301 return -EINVAL;
Ralph Campbellf9315512010-05-23 21:44:54 -0700302
Harish Chegondi70696ea2016-02-03 14:20:27 -0800303 if (mtu > dd->pport[pidx].ibmtu)
304 pmtu = mtu_to_enum(dd->pport[pidx].ibmtu);
305 else
306 pmtu = attr->path_mtu;
307 return pmtu;
308}
Ralph Campbellf9315512010-05-23 21:44:54 -0700309
Harish Chegondi20f333b2016-02-14 12:09:55 -0800310int qib_mtu_to_path_mtu(u32 mtu)
Harish Chegondi70696ea2016-02-03 14:20:27 -0800311{
312 return mtu_to_enum(mtu);
313}
Ralph Campbellf9315512010-05-23 21:44:54 -0700314
Harish Chegondi20f333b2016-02-14 12:09:55 -0800315u32 qib_mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu)
Harish Chegondi70696ea2016-02-03 14:20:27 -0800316{
317 return ib_mtu_enum_to_int(pmtu);
Ralph Campbellf9315512010-05-23 21:44:54 -0700318}
319
Harish Chegondi20f333b2016-02-14 12:09:55 -0800320void *qib_qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp, gfp_t gfp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700321{
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800322 struct qib_qp_priv *priv;
Ralph Campbellf9315512010-05-23 21:44:54 -0700323
Harish Chegondi47c7ea62016-01-22 12:56:52 -0800324 priv = kzalloc(sizeof(*priv), gfp);
325 if (!priv)
326 return ERR_PTR(-ENOMEM);
327 priv->owner = qp;
Vinit Agnihotrifbbeb862016-01-11 12:57:25 -0500328
Harish Chegondi47c7ea62016-01-22 12:56:52 -0800329 priv->s_hdr = kzalloc(sizeof(*priv->s_hdr), gfp);
330 if (!priv->s_hdr) {
331 kfree(priv);
332 return ERR_PTR(-ENOMEM);
Ralph Campbellf9315512010-05-23 21:44:54 -0700333 }
Harish Chegondi47c7ea62016-01-22 12:56:52 -0800334 init_waitqueue_head(&priv->wait_dma);
Harish Chegondidb3ef0e2016-01-22 13:07:42 -0800335 INIT_WORK(&priv->s_work, _qib_do_send);
Harish Chegondi47c7ea62016-01-22 12:56:52 -0800336 INIT_LIST_HEAD(&priv->iowait);
Ralph Campbellf9315512010-05-23 21:44:54 -0700337
Harish Chegondi47c7ea62016-01-22 12:56:52 -0800338 return priv;
339}
Ralph Campbellf9315512010-05-23 21:44:54 -0700340
Harish Chegondi20f333b2016-02-14 12:09:55 -0800341void qib_qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp)
Harish Chegondi47c7ea62016-01-22 12:56:52 -0800342{
343 struct qib_qp_priv *priv = qp->priv;
Vinit Agnihotrifbbeb862016-01-11 12:57:25 -0500344
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800345 kfree(priv->s_hdr);
346 kfree(priv);
Ralph Campbellf9315512010-05-23 21:44:54 -0700347}
348
Harish Chegondi20f333b2016-02-14 12:09:55 -0800349void qib_stop_send_queue(struct rvt_qp *qp)
Harish Chegondi70696ea2016-02-03 14:20:27 -0800350{
351 struct qib_qp_priv *priv = qp->priv;
352
353 cancel_work_sync(&priv->s_work);
354}
355
Harish Chegondi20f333b2016-02-14 12:09:55 -0800356void qib_quiesce_qp(struct rvt_qp *qp)
Harish Chegondi70696ea2016-02-03 14:20:27 -0800357{
358 struct qib_qp_priv *priv = qp->priv;
359
360 wait_event(priv->wait_dma, !atomic_read(&priv->s_dma_busy));
361 if (priv->s_tx) {
362 qib_put_txreq(priv->s_tx);
363 priv->s_tx = NULL;
364 }
365}
366
Harish Chegondi20f333b2016-02-14 12:09:55 -0800367void qib_flush_qp_waiters(struct rvt_qp *qp)
Harish Chegondi70696ea2016-02-03 14:20:27 -0800368{
369 struct qib_qp_priv *priv = qp->priv;
370 struct qib_ibdev *dev = to_idev(qp->ibqp.device);
371
372 spin_lock(&dev->rdi.pending_lock);
373 if (!list_empty(&priv->iowait))
374 list_del_init(&priv->iowait);
375 spin_unlock(&dev->rdi.pending_lock);
376}
377
Ralph Campbellf9315512010-05-23 21:44:54 -0700378/**
Mike Marciniszyn46a80d62016-02-14 12:10:04 -0800379 * qib_check_send_wqe - validate wr/wqe
380 * @qp - The qp
381 * @wqe - The built wqe
382 *
383 * validate wr/wqe. This is called
384 * prior to inserting the wqe into
385 * the ring but after the wqe has been
386 * setup.
387 *
Mike Marciniszyn91702b42016-02-14 12:45:44 -0800388 * Returns 1 to force direct progress, 0 otherwise, -EINVAL on failure
Mike Marciniszyn46a80d62016-02-14 12:10:04 -0800389 */
390int qib_check_send_wqe(struct rvt_qp *qp,
391 struct rvt_swqe *wqe)
392{
393 struct rvt_ah *ah;
Mike Marciniszyn91702b42016-02-14 12:45:44 -0800394 int ret = 0;
Mike Marciniszyn46a80d62016-02-14 12:10:04 -0800395
396 switch (qp->ibqp.qp_type) {
397 case IB_QPT_RC:
398 case IB_QPT_UC:
399 if (wqe->length > 0x80000000U)
400 return -EINVAL;
401 break;
402 case IB_QPT_SMI:
403 case IB_QPT_GSI:
404 case IB_QPT_UD:
405 ah = ibah_to_rvtah(wqe->ud_wr.ah);
406 if (wqe->length > (1 << ah->log_pmtu))
407 return -EINVAL;
Mike Marciniszyn91702b42016-02-14 12:45:44 -0800408 /* progress hint */
409 ret = 1;
Mike Marciniszyn46a80d62016-02-14 12:10:04 -0800410 break;
411 default:
412 break;
413 }
Mike Marciniszyn91702b42016-02-14 12:45:44 -0800414 return ret;
Mike Marciniszyn46a80d62016-02-14 12:10:04 -0800415}
416
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400417#ifdef CONFIG_DEBUG_FS
418
419struct qib_qp_iter {
420 struct qib_ibdev *dev;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800421 struct rvt_qp *qp;
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400422 int n;
423};
424
425struct qib_qp_iter *qib_qp_iter_init(struct qib_ibdev *dev)
426{
427 struct qib_qp_iter *iter;
428
429 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
430 if (!iter)
431 return NULL;
432
433 iter->dev = dev;
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400434
435 return iter;
436}
437
438int qib_qp_iter_next(struct qib_qp_iter *iter)
439{
440 struct qib_ibdev *dev = iter->dev;
441 int n = iter->n;
442 int ret = 1;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800443 struct rvt_qp *pqp = iter->qp;
444 struct rvt_qp *qp;
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400445
Harish Chegondi898fa522016-01-22 12:56:27 -0800446 for (; n < dev->rdi.qp_dev->qp_table_size; n++) {
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400447 if (pqp)
448 qp = rcu_dereference(pqp->next);
449 else
Harish Chegondi898fa522016-01-22 12:56:27 -0800450 qp = rcu_dereference(dev->rdi.qp_dev->qp_table[n]);
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400451 pqp = qp;
452 if (qp) {
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400453 iter->qp = qp;
454 iter->n = n;
455 return 0;
456 }
457 }
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400458 return ret;
459}
460
461static const char * const qp_type_str[] = {
462 "SMI", "GSI", "RC", "UC", "UD",
463};
464
465void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter)
466{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800467 struct rvt_swqe *wqe;
468 struct rvt_qp *qp = iter->qp;
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800469 struct qib_qp_priv *priv = qp->priv;
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400470
Harish Chegondidb3ef0e2016-01-22 13:07:42 -0800471 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400472 seq_printf(s,
473 "N %d QP%u %s %u %u %u f=%x %u %u %u %u %u PSN %x %x %x %x %x (%u %u %u %u %u %u) QP%u LID %x\n",
474 iter->n,
475 qp->ibqp.qp_num,
476 qp_type_str[qp->ibqp.qp_type],
477 qp->state,
478 wqe->wr.opcode,
479 qp->s_hdrwords,
480 qp->s_flags,
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800481 atomic_read(&priv->s_dma_busy),
482 !list_empty(&priv->iowait),
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400483 qp->timeout,
484 wqe->ssn,
485 qp->s_lsn,
486 qp->s_last_psn,
487 qp->s_psn, qp->s_next_psn,
488 qp->s_sending_psn, qp->s_sending_hpsn,
489 qp->s_last, qp->s_acked, qp->s_cur,
490 qp->s_tail, qp->s_head, qp->s_size,
491 qp->remote_qpn,
492 qp->remote_ah_attr.dlid);
493}
494
495#endif