blob: e0ec540042bfc8e098e3abd9e27e15549c834527 [file] [log] [blame]
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001/*
Ralph Campbelle7eacd32008-04-16 21:09:32 -07002 * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.
Bryan O'Sullivan65221082006-03-29 15:23:38 -08003 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#include <rdma/ib_mad.h>
35#include <rdma/ib_user_verbs.h>
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -070036#include <linux/io.h>
Bryan O'Sullivan65221082006-03-29 15:23:38 -080037#include <linux/utsname.h>
38
39#include "ipath_kernel.h"
40#include "ipath_verbs.h"
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -070041#include "ipath_common.h"
Bryan O'Sullivan65221082006-03-29 15:23:38 -080042
Roland Dreierac2ae4c2006-04-19 11:40:12 -070043static unsigned int ib_ipath_qp_table_size = 251;
Bryan O'Sullivan65221082006-03-29 15:23:38 -080044module_param_named(qp_table_size, ib_ipath_qp_table_size, uint, S_IRUGO);
45MODULE_PARM_DESC(qp_table_size, "QP table size");
46
47unsigned int ib_ipath_lkey_table_size = 12;
48module_param_named(lkey_table_size, ib_ipath_lkey_table_size, uint,
49 S_IRUGO);
50MODULE_PARM_DESC(lkey_table_size,
51 "LKEY table size in bits (2^n, 1 <= n <= 23)");
52
Bryan O'Sullivanfe625462006-07-01 04:35:58 -070053static unsigned int ib_ipath_max_pds = 0xFFFF;
54module_param_named(max_pds, ib_ipath_max_pds, uint, S_IWUSR | S_IRUGO);
55MODULE_PARM_DESC(max_pds,
56 "Maximum number of protection domains to support");
57
58static unsigned int ib_ipath_max_ahs = 0xFFFF;
59module_param_named(max_ahs, ib_ipath_max_ahs, uint, S_IWUSR | S_IRUGO);
60MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support");
61
62unsigned int ib_ipath_max_cqes = 0x2FFFF;
63module_param_named(max_cqes, ib_ipath_max_cqes, uint, S_IWUSR | S_IRUGO);
64MODULE_PARM_DESC(max_cqes,
65 "Maximum number of completion queue entries to support");
66
67unsigned int ib_ipath_max_cqs = 0x1FFFF;
68module_param_named(max_cqs, ib_ipath_max_cqs, uint, S_IWUSR | S_IRUGO);
69MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support");
70
71unsigned int ib_ipath_max_qp_wrs = 0x3FFF;
72module_param_named(max_qp_wrs, ib_ipath_max_qp_wrs, uint,
73 S_IWUSR | S_IRUGO);
74MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support");
75
Bryan O'Sullivan0b81e4f2006-08-25 11:24:43 -070076unsigned int ib_ipath_max_qps = 16384;
77module_param_named(max_qps, ib_ipath_max_qps, uint, S_IWUSR | S_IRUGO);
78MODULE_PARM_DESC(max_qps, "Maximum number of QPs to support");
79
Bryan O'Sullivanfe625462006-07-01 04:35:58 -070080unsigned int ib_ipath_max_sges = 0x60;
81module_param_named(max_sges, ib_ipath_max_sges, uint, S_IWUSR | S_IRUGO);
82MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support");
83
84unsigned int ib_ipath_max_mcast_grps = 16384;
85module_param_named(max_mcast_grps, ib_ipath_max_mcast_grps, uint,
86 S_IWUSR | S_IRUGO);
87MODULE_PARM_DESC(max_mcast_grps,
88 "Maximum number of multicast groups to support");
89
90unsigned int ib_ipath_max_mcast_qp_attached = 16;
91module_param_named(max_mcast_qp_attached, ib_ipath_max_mcast_qp_attached,
92 uint, S_IWUSR | S_IRUGO);
93MODULE_PARM_DESC(max_mcast_qp_attached,
94 "Maximum number of attached QPs to support");
95
96unsigned int ib_ipath_max_srqs = 1024;
97module_param_named(max_srqs, ib_ipath_max_srqs, uint, S_IWUSR | S_IRUGO);
98MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support");
99
100unsigned int ib_ipath_max_srq_sges = 128;
101module_param_named(max_srq_sges, ib_ipath_max_srq_sges,
102 uint, S_IWUSR | S_IRUGO);
103MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support");
104
105unsigned int ib_ipath_max_srq_wrs = 0x1FFFF;
106module_param_named(max_srq_wrs, ib_ipath_max_srq_wrs,
107 uint, S_IWUSR | S_IRUGO);
108MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support");
109
Bryan O'Sullivand821f022006-08-25 11:24:45 -0700110static unsigned int ib_ipath_disable_sma;
111module_param_named(disable_sma, ib_ipath_disable_sma, uint, S_IWUSR | S_IRUGO);
Paul Bolle98628742008-04-21 18:19:13 -0700112MODULE_PARM_DESC(disable_sma, "Disable the SMA");
Bryan O'Sullivand821f022006-08-25 11:24:45 -0700113
Ralph Campbelle509be82008-05-13 11:41:29 -0700114/*
115 * Note that it is OK to post send work requests in the SQE and ERR
116 * states; ipath_do_send() will process them and generate error
117 * completions as per IB 1.2 C10-96.
118 */
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800119const int ib_ipath_state_ops[IB_QPS_ERR + 1] = {
120 [IB_QPS_RESET] = 0,
121 [IB_QPS_INIT] = IPATH_POST_RECV_OK,
122 [IB_QPS_RTR] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
123 [IB_QPS_RTS] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
Ralph Campbelle509be82008-05-13 11:41:29 -0700124 IPATH_POST_SEND_OK | IPATH_PROCESS_SEND_OK |
125 IPATH_PROCESS_NEXT_SEND_OK,
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800126 [IB_QPS_SQD] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
Ralph Campbelle509be82008-05-13 11:41:29 -0700127 IPATH_POST_SEND_OK | IPATH_PROCESS_SEND_OK,
128 [IB_QPS_SQE] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
129 IPATH_POST_SEND_OK | IPATH_FLUSH_SEND,
130 [IB_QPS_ERR] = IPATH_POST_RECV_OK | IPATH_FLUSH_RECV |
131 IPATH_POST_SEND_OK | IPATH_FLUSH_SEND,
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800132};
133
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700134struct ipath_ucontext {
135 struct ib_ucontext ibucontext;
136};
137
138static inline struct ipath_ucontext *to_iucontext(struct ib_ucontext
139 *ibucontext)
140{
141 return container_of(ibucontext, struct ipath_ucontext, ibucontext);
142}
143
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800144/*
145 * Translate ib_wr_opcode into ib_wc_opcode.
146 */
147const enum ib_wc_opcode ib_ipath_wc_opcode[] = {
148 [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
149 [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
150 [IB_WR_SEND] = IB_WC_SEND,
151 [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
152 [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
153 [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
154 [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD
155};
156
157/*
158 * System image GUID.
159 */
Roland Dreierac2ae4c2006-04-19 11:40:12 -0700160static __be64 sys_image_guid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800161
162/**
163 * ipath_copy_sge - copy data to SGE memory
164 * @ss: the SGE state
165 * @data: the data to copy
166 * @length: the length of the data
167 */
168void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length)
169{
170 struct ipath_sge *sge = &ss->sge;
171
172 while (length) {
173 u32 len = sge->length;
174
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800175 if (len > length)
176 len = length;
Ralph Campbell30d149a2007-06-18 14:24:44 -0700177 if (len > sge->sge_length)
178 len = sge->sge_length;
179 BUG_ON(len == 0);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800180 memcpy(sge->vaddr, data, len);
181 sge->vaddr += len;
182 sge->length -= len;
183 sge->sge_length -= len;
184 if (sge->sge_length == 0) {
185 if (--ss->num_sge)
186 *sge = *ss->sg_list++;
187 } else if (sge->length == 0 && sge->mr != NULL) {
188 if (++sge->n >= IPATH_SEGSZ) {
189 if (++sge->m >= sge->mr->mapsz)
190 break;
191 sge->n = 0;
192 }
193 sge->vaddr =
194 sge->mr->map[sge->m]->segs[sge->n].vaddr;
195 sge->length =
196 sge->mr->map[sge->m]->segs[sge->n].length;
197 }
198 data += len;
199 length -= len;
200 }
201}
202
203/**
204 * ipath_skip_sge - skip over SGE memory - XXX almost dup of prev func
205 * @ss: the SGE state
206 * @length: the number of bytes to skip
207 */
208void ipath_skip_sge(struct ipath_sge_state *ss, u32 length)
209{
210 struct ipath_sge *sge = &ss->sge;
211
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800212 while (length) {
213 u32 len = sge->length;
214
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800215 if (len > length)
216 len = length;
Ralph Campbell30d149a2007-06-18 14:24:44 -0700217 if (len > sge->sge_length)
218 len = sge->sge_length;
219 BUG_ON(len == 0);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800220 sge->vaddr += len;
221 sge->length -= len;
222 sge->sge_length -= len;
223 if (sge->sge_length == 0) {
224 if (--ss->num_sge)
225 *sge = *ss->sg_list++;
226 } else if (sge->length == 0 && sge->mr != NULL) {
227 if (++sge->n >= IPATH_SEGSZ) {
228 if (++sge->m >= sge->mr->mapsz)
229 break;
230 sge->n = 0;
231 }
232 sge->vaddr =
233 sge->mr->map[sge->m]->segs[sge->n].vaddr;
234 sge->length =
235 sge->mr->map[sge->m]->segs[sge->n].length;
236 }
237 length -= len;
238 }
239}
240
Dave Olson124b4dc2008-04-16 21:09:32 -0700241/*
242 * Count the number of DMA descriptors needed to send length bytes of data.
243 * Don't modify the ipath_sge_state to get the count.
244 * Return zero if any of the segments is not aligned.
245 */
246static u32 ipath_count_sge(struct ipath_sge_state *ss, u32 length)
247{
248 struct ipath_sge *sg_list = ss->sg_list;
249 struct ipath_sge sge = ss->sge;
250 u8 num_sge = ss->num_sge;
251 u32 ndesc = 1; /* count the header */
252
253 while (length) {
254 u32 len = sge.length;
255
256 if (len > length)
257 len = length;
258 if (len > sge.sge_length)
259 len = sge.sge_length;
260 BUG_ON(len == 0);
261 if (((long) sge.vaddr & (sizeof(u32) - 1)) ||
262 (len != length && (len & (sizeof(u32) - 1)))) {
263 ndesc = 0;
264 break;
265 }
266 ndesc++;
267 sge.vaddr += len;
268 sge.length -= len;
269 sge.sge_length -= len;
270 if (sge.sge_length == 0) {
271 if (--num_sge)
272 sge = *sg_list++;
273 } else if (sge.length == 0 && sge.mr != NULL) {
274 if (++sge.n >= IPATH_SEGSZ) {
275 if (++sge.m >= sge.mr->mapsz)
276 break;
277 sge.n = 0;
278 }
279 sge.vaddr =
280 sge.mr->map[sge.m]->segs[sge.n].vaddr;
281 sge.length =
282 sge.mr->map[sge.m]->segs[sge.n].length;
283 }
284 length -= len;
285 }
286 return ndesc;
287}
288
289/*
290 * Copy from the SGEs to the data buffer.
291 */
292static void ipath_copy_from_sge(void *data, struct ipath_sge_state *ss,
293 u32 length)
294{
295 struct ipath_sge *sge = &ss->sge;
296
297 while (length) {
298 u32 len = sge->length;
299
300 if (len > length)
301 len = length;
302 if (len > sge->sge_length)
303 len = sge->sge_length;
304 BUG_ON(len == 0);
305 memcpy(data, sge->vaddr, len);
306 sge->vaddr += len;
307 sge->length -= len;
308 sge->sge_length -= len;
309 if (sge->sge_length == 0) {
310 if (--ss->num_sge)
311 *sge = *ss->sg_list++;
312 } else if (sge->length == 0 && sge->mr != NULL) {
313 if (++sge->n >= IPATH_SEGSZ) {
314 if (++sge->m >= sge->mr->mapsz)
315 break;
316 sge->n = 0;
317 }
318 sge->vaddr =
319 sge->mr->map[sge->m]->segs[sge->n].vaddr;
320 sge->length =
321 sge->mr->map[sge->m]->segs[sge->n].length;
322 }
323 data += len;
324 length -= len;
325 }
326}
327
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800328/**
Ralph Campbell4ee97182007-07-25 11:08:28 -0700329 * ipath_post_one_send - post one RC, UC, or UD send work request
330 * @qp: the QP to post on
331 * @wr: the work request to send
332 */
333static int ipath_post_one_send(struct ipath_qp *qp, struct ib_send_wr *wr)
334{
335 struct ipath_swqe *wqe;
336 u32 next;
337 int i;
338 int j;
339 int acc;
340 int ret;
341 unsigned long flags;
342
343 spin_lock_irqsave(&qp->s_lock, flags);
344
345 /* Check that state is OK to post send. */
Ralph Campbelle509be82008-05-13 11:41:29 -0700346 if (unlikely(!(ib_ipath_state_ops[qp->state] & IPATH_POST_SEND_OK)))
347 goto bail_inval;
Ralph Campbell4ee97182007-07-25 11:08:28 -0700348
349 /* IB spec says that num_sge == 0 is OK. */
350 if (wr->num_sge > qp->s_max_sge)
351 goto bail_inval;
352
353 /*
354 * Don't allow RDMA reads or atomic operations on UC or
355 * undefined operations.
356 * Make sure buffer is large enough to hold the result for atomics.
357 */
358 if (qp->ibqp.qp_type == IB_QPT_UC) {
359 if ((unsigned) wr->opcode >= IB_WR_RDMA_READ)
360 goto bail_inval;
361 } else if (qp->ibqp.qp_type == IB_QPT_UD) {
362 /* Check UD opcode */
363 if (wr->opcode != IB_WR_SEND &&
364 wr->opcode != IB_WR_SEND_WITH_IMM)
365 goto bail_inval;
366 /* Check UD destination address PD */
367 if (qp->ibqp.pd != wr->wr.ud.ah->pd)
368 goto bail_inval;
369 } else if ((unsigned) wr->opcode > IB_WR_ATOMIC_FETCH_AND_ADD)
370 goto bail_inval;
371 else if (wr->opcode >= IB_WR_ATOMIC_CMP_AND_SWP &&
372 (wr->num_sge == 0 ||
373 wr->sg_list[0].length < sizeof(u64) ||
374 wr->sg_list[0].addr & (sizeof(u64) - 1)))
375 goto bail_inval;
376 else if (wr->opcode >= IB_WR_RDMA_READ && !qp->s_max_rd_atomic)
377 goto bail_inval;
378
379 next = qp->s_head + 1;
380 if (next >= qp->s_size)
381 next = 0;
Ralph Campbell4187b912007-11-14 13:34:14 -0800382 if (next == qp->s_last) {
383 ret = -ENOMEM;
384 goto bail;
385 }
Ralph Campbell4ee97182007-07-25 11:08:28 -0700386
387 wqe = get_swqe_ptr(qp, qp->s_head);
388 wqe->wr = *wr;
Ralph Campbell4ee97182007-07-25 11:08:28 -0700389 wqe->length = 0;
390 if (wr->num_sge) {
391 acc = wr->opcode >= IB_WR_RDMA_READ ?
392 IB_ACCESS_LOCAL_WRITE : 0;
393 for (i = 0, j = 0; i < wr->num_sge; i++) {
394 u32 length = wr->sg_list[i].length;
395 int ok;
396
397 if (length == 0)
398 continue;
399 ok = ipath_lkey_ok(qp, &wqe->sg_list[j],
400 &wr->sg_list[i], acc);
401 if (!ok)
402 goto bail_inval;
403 wqe->length += length;
404 j++;
405 }
406 wqe->wr.num_sge = j;
407 }
408 if (qp->ibqp.qp_type == IB_QPT_UC ||
409 qp->ibqp.qp_type == IB_QPT_RC) {
410 if (wqe->length > 0x80000000U)
411 goto bail_inval;
412 } else if (wqe->length > to_idev(qp->ibqp.device)->dd->ipath_ibmtu)
413 goto bail_inval;
Ralph Campbell6e87d152008-05-07 10:57:14 -0700414 wqe->ssn = qp->s_ssn++;
Ralph Campbell4ee97182007-07-25 11:08:28 -0700415 qp->s_head = next;
416
417 ret = 0;
418 goto bail;
419
420bail_inval:
421 ret = -EINVAL;
422bail:
423 spin_unlock_irqrestore(&qp->s_lock, flags);
424 return ret;
425}
426
427/**
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800428 * ipath_post_send - post a send on a QP
429 * @ibqp: the QP to post the send on
430 * @wr: the list of work requests to post
431 * @bad_wr: the first bad WR is put here
432 *
433 * This may be called from interrupt context.
434 */
435static int ipath_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
436 struct ib_send_wr **bad_wr)
437{
438 struct ipath_qp *qp = to_iqp(ibqp);
439 int err = 0;
440
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800441 for (; wr; wr = wr->next) {
Ralph Campbell4ee97182007-07-25 11:08:28 -0700442 err = ipath_post_one_send(qp, wr);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800443 if (err) {
444 *bad_wr = wr;
Ralph Campbell4ee97182007-07-25 11:08:28 -0700445 goto bail;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800446 }
447 }
448
Ralph Campbell4ee97182007-07-25 11:08:28 -0700449 /* Try to do the send work in the caller's context. */
450 ipath_do_send((unsigned long) qp);
451
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800452bail:
453 return err;
454}
455
456/**
457 * ipath_post_receive - post a receive on a QP
458 * @ibqp: the QP to post the receive on
459 * @wr: the WR to post
460 * @bad_wr: the first bad WR is put here
461 *
462 * This may be called from interrupt context.
463 */
464static int ipath_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
465 struct ib_recv_wr **bad_wr)
466{
467 struct ipath_qp *qp = to_iqp(ibqp);
Ralph Campbell373d9912006-09-22 15:22:26 -0700468 struct ipath_rwq *wq = qp->r_rq.wq;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800469 unsigned long flags;
470 int ret;
471
472 /* Check that state is OK to post receive. */
Ralph Campbell373d9912006-09-22 15:22:26 -0700473 if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_RECV_OK) || !wq) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800474 *bad_wr = wr;
475 ret = -EINVAL;
476 goto bail;
477 }
478
479 for (; wr; wr = wr->next) {
480 struct ipath_rwqe *wqe;
481 u32 next;
Ralph Campbell373d9912006-09-22 15:22:26 -0700482 int i;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800483
Ralph Campbell373d9912006-09-22 15:22:26 -0700484 if ((unsigned) wr->num_sge > qp->r_rq.max_sge) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800485 *bad_wr = wr;
Ralph Campbell4187b912007-11-14 13:34:14 -0800486 ret = -EINVAL;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800487 goto bail;
488 }
489
490 spin_lock_irqsave(&qp->r_rq.lock, flags);
Ralph Campbell373d9912006-09-22 15:22:26 -0700491 next = wq->head + 1;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800492 if (next >= qp->r_rq.size)
493 next = 0;
Ralph Campbell373d9912006-09-22 15:22:26 -0700494 if (next == wq->tail) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800495 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
496 *bad_wr = wr;
497 ret = -ENOMEM;
498 goto bail;
499 }
500
Ralph Campbell373d9912006-09-22 15:22:26 -0700501 wqe = get_rwqe_ptr(&qp->r_rq, wq->head);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800502 wqe->wr_id = wr->wr_id;
Ralph Campbell373d9912006-09-22 15:22:26 -0700503 wqe->num_sge = wr->num_sge;
504 for (i = 0; i < wr->num_sge; i++)
505 wqe->sg_list[i] = wr->sg_list[i];
Ralph Campbell4fc570b2007-07-06 12:48:23 -0700506 /* Make sure queue entry is written before the head index. */
507 smp_wmb();
Ralph Campbell373d9912006-09-22 15:22:26 -0700508 wq->head = next;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800509 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
510 }
511 ret = 0;
512
513bail:
514 return ret;
515}
516
517/**
518 * ipath_qp_rcv - processing an incoming packet on a QP
519 * @dev: the device the packet came on
520 * @hdr: the packet header
521 * @has_grh: true if the packet has a GRH
522 * @data: the packet data
523 * @tlen: the packet length
524 * @qp: the QP the packet came on
525 *
526 * This is called from ipath_ib_rcv() to process an incoming packet
527 * for the given QP.
528 * Called at interrupt level.
529 */
530static void ipath_qp_rcv(struct ipath_ibdev *dev,
531 struct ipath_ib_header *hdr, int has_grh,
532 void *data, u32 tlen, struct ipath_qp *qp)
533{
534 /* Check for valid receive state. */
535 if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) {
536 dev->n_pkt_drops++;
537 return;
538 }
539
540 switch (qp->ibqp.qp_type) {
541 case IB_QPT_SMI:
542 case IB_QPT_GSI:
Bryan O'Sullivand821f022006-08-25 11:24:45 -0700543 if (ib_ipath_disable_sma)
544 break;
545 /* FALLTHROUGH */
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800546 case IB_QPT_UD:
547 ipath_ud_rcv(dev, hdr, has_grh, data, tlen, qp);
548 break;
549
550 case IB_QPT_RC:
551 ipath_rc_rcv(dev, hdr, has_grh, data, tlen, qp);
552 break;
553
554 case IB_QPT_UC:
555 ipath_uc_rcv(dev, hdr, has_grh, data, tlen, qp);
556 break;
557
558 default:
559 break;
560 }
561}
562
563/**
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -0700564 * ipath_ib_rcv - process an incoming packet
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800565 * @arg: the device pointer
566 * @rhdr: the header of the packet
567 * @data: the packet data
568 * @tlen: the packet length
569 *
570 * This is called from ipath_kreceive() to process an incoming packet at
571 * interrupt level. Tlen is the length of the header + data + CRC in bytes.
572 */
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -0700573void ipath_ib_rcv(struct ipath_ibdev *dev, void *rhdr, void *data,
574 u32 tlen)
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800575{
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800576 struct ipath_ib_header *hdr = rhdr;
577 struct ipath_other_headers *ohdr;
578 struct ipath_qp *qp;
579 u32 qp_num;
580 int lnh;
581 u8 opcode;
582 u16 lid;
583
584 if (unlikely(dev == NULL))
585 goto bail;
586
587 if (unlikely(tlen < 24)) { /* LRH+BTH+CRC */
588 dev->rcv_errors++;
589 goto bail;
590 }
591
592 /* Check for a valid destination LID (see ch. 7.11.1). */
593 lid = be16_to_cpu(hdr->lrh[1]);
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700594 if (lid < IPATH_MULTICAST_LID_BASE) {
Ralph Campbell542869a2007-09-13 11:42:52 -0700595 lid &= ~((1 << dev->dd->ipath_lmc) - 1);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700596 if (unlikely(lid != dev->dd->ipath_lid)) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800597 dev->rcv_errors++;
598 goto bail;
599 }
600 }
601
602 /* Check for GRH */
603 lnh = be16_to_cpu(hdr->lrh[0]) & 3;
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700604 if (lnh == IPATH_LRH_BTH)
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800605 ohdr = &hdr->u.oth;
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700606 else if (lnh == IPATH_LRH_GRH)
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800607 ohdr = &hdr->u.l.oth;
608 else {
609 dev->rcv_errors++;
610 goto bail;
611 }
612
613 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
614 dev->opstats[opcode].n_bytes += tlen;
615 dev->opstats[opcode].n_packets++;
616
617 /* Get the destination QP number. */
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700618 qp_num = be32_to_cpu(ohdr->bth[1]) & IPATH_QPN_MASK;
619 if (qp_num == IPATH_MULTICAST_QPN) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800620 struct ipath_mcast *mcast;
621 struct ipath_mcast_qp *p;
622
Bryan O'Sullivan5a7d4ee2007-03-15 14:45:03 -0700623 if (lnh != IPATH_LRH_GRH) {
624 dev->n_pkt_drops++;
625 goto bail;
626 }
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800627 mcast = ipath_mcast_find(&hdr->u.l.grh.dgid);
628 if (mcast == NULL) {
629 dev->n_pkt_drops++;
630 goto bail;
631 }
632 dev->n_multicast_rcv++;
633 list_for_each_entry_rcu(p, &mcast->qp_list, list)
Bryan O'Sullivan5a7d4ee2007-03-15 14:45:03 -0700634 ipath_qp_rcv(dev, hdr, 1, data, tlen, p->qp);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800635 /*
636 * Notify ipath_multicast_detach() if it is waiting for us
637 * to finish.
638 */
639 if (atomic_dec_return(&mcast->refcount) <= 1)
640 wake_up(&mcast->wait);
641 } else {
642 qp = ipath_lookup_qpn(&dev->qp_table, qp_num);
643 if (qp) {
644 dev->n_unicast_rcv++;
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700645 ipath_qp_rcv(dev, hdr, lnh == IPATH_LRH_GRH, data,
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800646 tlen, qp);
647 /*
648 * Notify ipath_destroy_qp() if it is waiting
649 * for us to finish.
650 */
651 if (atomic_dec_and_test(&qp->refcount))
652 wake_up(&qp->wait);
653 } else
654 dev->n_pkt_drops++;
655 }
656
657bail:;
658}
659
660/**
661 * ipath_ib_timer - verbs timer
662 * @arg: the device pointer
663 *
664 * This is called from ipath_do_rcv_timer() at interrupt level to check for
665 * QPs which need retransmits and to collect performance numbers.
666 */
Roland Dreierda9aec72007-07-17 18:37:43 -0700667static void ipath_ib_timer(struct ipath_ibdev *dev)
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800668{
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800669 struct ipath_qp *resend = NULL;
Ralph Campbelle509be82008-05-13 11:41:29 -0700670 struct ipath_qp *rnr = NULL;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800671 struct list_head *last;
672 struct ipath_qp *qp;
673 unsigned long flags;
674
675 if (dev == NULL)
676 return;
677
678 spin_lock_irqsave(&dev->pending_lock, flags);
679 /* Start filling the next pending queue. */
680 if (++dev->pending_index >= ARRAY_SIZE(dev->pending))
681 dev->pending_index = 0;
682 /* Save any requests still in the new queue, they have timed out. */
683 last = &dev->pending[dev->pending_index];
684 while (!list_empty(last)) {
685 qp = list_entry(last->next, struct ipath_qp, timerwait);
Bryan O'Sullivan94b8d9f2006-05-23 11:32:32 -0700686 list_del_init(&qp->timerwait);
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -0700687 qp->timer_next = resend;
688 resend = qp;
689 atomic_inc(&qp->refcount);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800690 }
691 last = &dev->rnrwait;
692 if (!list_empty(last)) {
693 qp = list_entry(last->next, struct ipath_qp, timerwait);
694 if (--qp->s_rnr_timeout == 0) {
695 do {
Bryan O'Sullivan94b8d9f2006-05-23 11:32:32 -0700696 list_del_init(&qp->timerwait);
Ralph Campbelle509be82008-05-13 11:41:29 -0700697 qp->timer_next = rnr;
698 rnr = qp;
699 atomic_inc(&qp->refcount);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800700 if (list_empty(last))
701 break;
702 qp = list_entry(last->next, struct ipath_qp,
703 timerwait);
704 } while (qp->s_rnr_timeout == 0);
705 }
706 }
707 /*
708 * We should only be in the started state if pma_sample_start != 0
709 */
710 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED &&
711 --dev->pma_sample_start == 0) {
712 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700713 ipath_snapshot_counters(dev->dd, &dev->ipath_sword,
714 &dev->ipath_rword,
715 &dev->ipath_spkts,
716 &dev->ipath_rpkts,
717 &dev->ipath_xmit_wait);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800718 }
719 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
720 if (dev->pma_sample_interval == 0) {
721 u64 ta, tb, tc, td, te;
722
723 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700724 ipath_snapshot_counters(dev->dd, &ta, &tb,
725 &tc, &td, &te);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800726
727 dev->ipath_sword = ta - dev->ipath_sword;
728 dev->ipath_rword = tb - dev->ipath_rword;
729 dev->ipath_spkts = tc - dev->ipath_spkts;
730 dev->ipath_rpkts = td - dev->ipath_rpkts;
731 dev->ipath_xmit_wait = te - dev->ipath_xmit_wait;
732 }
733 else
734 dev->pma_sample_interval--;
735 }
736 spin_unlock_irqrestore(&dev->pending_lock, flags);
737
738 /* XXX What if timer fires again while this is running? */
Ralph Campbelle509be82008-05-13 11:41:29 -0700739 while (resend != NULL) {
740 qp = resend;
741 resend = qp->timer_next;
742
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800743 spin_lock_irqsave(&qp->s_lock, flags);
Ralph Campbelle509be82008-05-13 11:41:29 -0700744 if (qp->s_last != qp->s_tail &&
745 ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800746 dev->n_timeouts++;
Ralph Campbell53dc1ca2008-05-13 11:40:25 -0700747 ipath_restart_rc(qp, qp->s_last_psn + 1);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800748 }
749 spin_unlock_irqrestore(&qp->s_lock, flags);
750
751 /* Notify ipath_destroy_qp() if it is waiting. */
752 if (atomic_dec_and_test(&qp->refcount))
753 wake_up(&qp->wait);
754 }
Ralph Campbelle509be82008-05-13 11:41:29 -0700755 while (rnr != NULL) {
756 qp = rnr;
757 rnr = qp->timer_next;
758
759 spin_lock_irqsave(&qp->s_lock, flags);
760 if (ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK)
761 ipath_schedule_send(qp);
762 spin_unlock_irqrestore(&qp->s_lock, flags);
763
764 /* Notify ipath_destroy_qp() if it is waiting. */
765 if (atomic_dec_and_test(&qp->refcount))
766 wake_up(&qp->wait);
767 }
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800768}
769
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700770static void update_sge(struct ipath_sge_state *ss, u32 length)
771{
772 struct ipath_sge *sge = &ss->sge;
773
774 sge->vaddr += length;
775 sge->length -= length;
776 sge->sge_length -= length;
777 if (sge->sge_length == 0) {
778 if (--ss->num_sge)
779 *sge = *ss->sg_list++;
780 } else if (sge->length == 0 && sge->mr != NULL) {
781 if (++sge->n >= IPATH_SEGSZ) {
782 if (++sge->m >= sge->mr->mapsz)
783 return;
784 sge->n = 0;
785 }
786 sge->vaddr = sge->mr->map[sge->m]->segs[sge->n].vaddr;
787 sge->length = sge->mr->map[sge->m]->segs[sge->n].length;
788 }
789}
790
791#ifdef __LITTLE_ENDIAN
792static inline u32 get_upper_bits(u32 data, u32 shift)
793{
794 return data >> shift;
795}
796
797static inline u32 set_upper_bits(u32 data, u32 shift)
798{
799 return data << shift;
800}
801
802static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
803{
804 data <<= ((sizeof(u32) - n) * BITS_PER_BYTE);
805 data >>= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
806 return data;
807}
808#else
809static inline u32 get_upper_bits(u32 data, u32 shift)
810{
811 return data << shift;
812}
813
814static inline u32 set_upper_bits(u32 data, u32 shift)
815{
816 return data >> shift;
817}
818
819static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
820{
821 data >>= ((sizeof(u32) - n) * BITS_PER_BYTE);
822 data <<= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
823 return data;
824}
825#endif
826
827static void copy_io(u32 __iomem *piobuf, struct ipath_sge_state *ss,
Ralph Campbell210d6ca2007-07-24 13:55:39 -0700828 u32 length, unsigned flush_wc)
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700829{
830 u32 extra = 0;
831 u32 data = 0;
832 u32 last;
833
834 while (1) {
835 u32 len = ss->sge.length;
836 u32 off;
837
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700838 if (len > length)
839 len = length;
840 if (len > ss->sge.sge_length)
841 len = ss->sge.sge_length;
Ralph Campbell4ee97182007-07-25 11:08:28 -0700842 BUG_ON(len == 0);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700843 /* If the source address is not aligned, try to align it. */
844 off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1);
845 if (off) {
846 u32 *addr = (u32 *)((unsigned long)ss->sge.vaddr &
847 ~(sizeof(u32) - 1));
848 u32 v = get_upper_bits(*addr, off * BITS_PER_BYTE);
849 u32 y;
850
851 y = sizeof(u32) - off;
852 if (len > y)
853 len = y;
854 if (len + extra >= sizeof(u32)) {
855 data |= set_upper_bits(v, extra *
856 BITS_PER_BYTE);
857 len = sizeof(u32) - extra;
858 if (len == length) {
859 last = data;
860 break;
861 }
862 __raw_writel(data, piobuf);
863 piobuf++;
864 extra = 0;
865 data = 0;
866 } else {
867 /* Clear unused upper bytes */
868 data |= clear_upper_bytes(v, len, extra);
869 if (len == length) {
870 last = data;
871 break;
872 }
873 extra += len;
874 }
875 } else if (extra) {
876 /* Source address is aligned. */
877 u32 *addr = (u32 *) ss->sge.vaddr;
878 int shift = extra * BITS_PER_BYTE;
879 int ushift = 32 - shift;
880 u32 l = len;
881
882 while (l >= sizeof(u32)) {
883 u32 v = *addr;
884
885 data |= set_upper_bits(v, shift);
886 __raw_writel(data, piobuf);
887 data = get_upper_bits(v, ushift);
888 piobuf++;
889 addr++;
890 l -= sizeof(u32);
891 }
892 /*
893 * We still have 'extra' number of bytes leftover.
894 */
895 if (l) {
896 u32 v = *addr;
897
898 if (l + extra >= sizeof(u32)) {
899 data |= set_upper_bits(v, shift);
900 len -= l + extra - sizeof(u32);
901 if (len == length) {
902 last = data;
903 break;
904 }
905 __raw_writel(data, piobuf);
906 piobuf++;
907 extra = 0;
908 data = 0;
909 } else {
910 /* Clear unused upper bytes */
911 data |= clear_upper_bytes(v, l,
912 extra);
913 if (len == length) {
914 last = data;
915 break;
916 }
917 extra += l;
918 }
919 } else if (len == length) {
920 last = data;
921 break;
922 }
923 } else if (len == length) {
924 u32 w;
925
926 /*
927 * Need to round up for the last dword in the
928 * packet.
929 */
930 w = (len + 3) >> 2;
931 __iowrite32_copy(piobuf, ss->sge.vaddr, w - 1);
932 piobuf += w - 1;
933 last = ((u32 *) ss->sge.vaddr)[w - 1];
934 break;
935 } else {
936 u32 w = len >> 2;
937
938 __iowrite32_copy(piobuf, ss->sge.vaddr, w);
939 piobuf += w;
940
941 extra = len & (sizeof(u32) - 1);
942 if (extra) {
943 u32 v = ((u32 *) ss->sge.vaddr)[w];
944
945 /* Clear unused upper bytes */
946 data = clear_upper_bytes(v, extra, 0);
947 }
948 }
949 update_sge(ss, len);
950 length -= len;
951 }
952 /* Update address before sending packet. */
953 update_sge(ss, length);
Ralph Campbell210d6ca2007-07-24 13:55:39 -0700954 if (flush_wc) {
955 /* must flush early everything before trigger word */
956 ipath_flush_wc();
957 __raw_writel(last, piobuf);
958 /* be sure trigger word is written */
959 ipath_flush_wc();
960 } else
961 __raw_writel(last, piobuf);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700962}
963
Dave Olson124b4dc2008-04-16 21:09:32 -0700964/*
965 * Convert IB rate to delay multiplier.
966 */
967unsigned ipath_ib_rate_to_mult(enum ib_rate rate)
968{
969 switch (rate) {
970 case IB_RATE_2_5_GBPS: return 8;
971 case IB_RATE_5_GBPS: return 4;
972 case IB_RATE_10_GBPS: return 2;
973 case IB_RATE_20_GBPS: return 1;
974 default: return 0;
975 }
976}
977
978/*
979 * Convert delay multiplier to IB rate
980 */
981static enum ib_rate ipath_mult_to_ib_rate(unsigned mult)
982{
983 switch (mult) {
984 case 8: return IB_RATE_2_5_GBPS;
985 case 4: return IB_RATE_5_GBPS;
986 case 2: return IB_RATE_10_GBPS;
987 case 1: return IB_RATE_20_GBPS;
988 default: return IB_RATE_PORT_CURRENT;
989 }
990}
991
992static inline struct ipath_verbs_txreq *get_txreq(struct ipath_ibdev *dev)
993{
994 struct ipath_verbs_txreq *tx = NULL;
995 unsigned long flags;
996
997 spin_lock_irqsave(&dev->pending_lock, flags);
998 if (!list_empty(&dev->txreq_free)) {
999 struct list_head *l = dev->txreq_free.next;
1000
1001 list_del(l);
1002 tx = list_entry(l, struct ipath_verbs_txreq, txreq.list);
1003 }
1004 spin_unlock_irqrestore(&dev->pending_lock, flags);
1005 return tx;
1006}
1007
1008static inline void put_txreq(struct ipath_ibdev *dev,
1009 struct ipath_verbs_txreq *tx)
1010{
1011 unsigned long flags;
1012
1013 spin_lock_irqsave(&dev->pending_lock, flags);
1014 list_add(&tx->txreq.list, &dev->txreq_free);
1015 spin_unlock_irqrestore(&dev->pending_lock, flags);
1016}
1017
1018static void sdma_complete(void *cookie, int status)
1019{
1020 struct ipath_verbs_txreq *tx = cookie;
1021 struct ipath_qp *qp = tx->qp;
1022 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
Ralph Campbelle509be82008-05-13 11:41:29 -07001023 unsigned int flags;
1024 enum ib_wc_status ibs = status == IPATH_SDMA_TXREQ_S_OK ?
1025 IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR;
Dave Olson124b4dc2008-04-16 21:09:32 -07001026
Ralph Campbelle509be82008-05-13 11:41:29 -07001027 if (atomic_dec_and_test(&qp->s_dma_busy)) {
1028 spin_lock_irqsave(&qp->s_lock, flags);
1029 if (tx->wqe)
1030 ipath_send_complete(qp, tx->wqe, ibs);
1031 if ((ib_ipath_state_ops[qp->state] & IPATH_FLUSH_SEND &&
1032 qp->s_last != qp->s_head) ||
1033 (qp->s_flags & IPATH_S_WAIT_DMA))
1034 ipath_schedule_send(qp);
1035 spin_unlock_irqrestore(&qp->s_lock, flags);
1036 wake_up(&qp->wait_dma);
1037 } else if (tx->wqe) {
1038 spin_lock_irqsave(&qp->s_lock, flags);
Dave Olson124b4dc2008-04-16 21:09:32 -07001039 ipath_send_complete(qp, tx->wqe, ibs);
Ralph Campbelle509be82008-05-13 11:41:29 -07001040 spin_unlock_irqrestore(&qp->s_lock, flags);
Dave Olson124b4dc2008-04-16 21:09:32 -07001041 }
1042
1043 if (tx->txreq.flags & IPATH_SDMA_TXREQ_F_FREEBUF)
1044 kfree(tx->txreq.map_addr);
1045 put_txreq(dev, tx);
1046
1047 if (atomic_dec_and_test(&qp->refcount))
1048 wake_up(&qp->wait);
1049}
1050
Ralph Campbelle509be82008-05-13 11:41:29 -07001051static void decrement_dma_busy(struct ipath_qp *qp)
1052{
1053 unsigned int flags;
1054
1055 if (atomic_dec_and_test(&qp->s_dma_busy)) {
1056 spin_lock_irqsave(&qp->s_lock, flags);
1057 if ((ib_ipath_state_ops[qp->state] & IPATH_FLUSH_SEND &&
1058 qp->s_last != qp->s_head) ||
1059 (qp->s_flags & IPATH_S_WAIT_DMA))
1060 ipath_schedule_send(qp);
1061 spin_unlock_irqrestore(&qp->s_lock, flags);
1062 wake_up(&qp->wait_dma);
1063 }
1064}
1065
Dave Olson124b4dc2008-04-16 21:09:32 -07001066/*
1067 * Compute the number of clock cycles of delay before sending the next packet.
1068 * The multipliers reflect the number of clocks for the fastest rate so
1069 * one tick at 4xDDR is 8 ticks at 1xSDR.
1070 * If the destination port will take longer to receive a packet than
1071 * the outgoing link can send it, we need to delay sending the next packet
1072 * by the difference in time it takes the receiver to receive and the sender
1073 * to send this packet.
1074 * Note that this delay is always correct for UC and RC but not always
1075 * optimal for UD. For UD, the destination HCA can be different for each
1076 * packet, in which case, we could send packets to a different destination
1077 * while "waiting" for the delay. The overhead for doing this without
1078 * HW support is more than just paying the cost of delaying some packets
1079 * unnecessarily.
1080 */
1081static inline unsigned ipath_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult)
1082{
1083 return (rcv_mult > snd_mult) ?
1084 (plen * (rcv_mult - snd_mult) + 1) >> 1 : 0;
1085}
1086
1087static int ipath_verbs_send_dma(struct ipath_qp *qp,
1088 struct ipath_ib_header *hdr, u32 hdrwords,
1089 struct ipath_sge_state *ss, u32 len,
1090 u32 plen, u32 dwords)
1091{
1092 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
1093 struct ipath_devdata *dd = dev->dd;
1094 struct ipath_verbs_txreq *tx;
1095 u32 *piobuf;
1096 u32 control;
1097 u32 ndesc;
1098 int ret;
1099
1100 tx = qp->s_tx;
1101 if (tx) {
1102 qp->s_tx = NULL;
1103 /* resend previously constructed packet */
Ralph Campbelle509be82008-05-13 11:41:29 -07001104 atomic_inc(&qp->s_dma_busy);
Dave Olson124b4dc2008-04-16 21:09:32 -07001105 ret = ipath_sdma_verbs_send(dd, tx->ss, tx->len, tx);
Ralph Campbelle509be82008-05-13 11:41:29 -07001106 if (ret) {
Dave Olson124b4dc2008-04-16 21:09:32 -07001107 qp->s_tx = tx;
Ralph Campbelle509be82008-05-13 11:41:29 -07001108 decrement_dma_busy(qp);
1109 }
Dave Olson124b4dc2008-04-16 21:09:32 -07001110 goto bail;
1111 }
1112
1113 tx = get_txreq(dev);
1114 if (!tx) {
1115 ret = -EBUSY;
1116 goto bail;
1117 }
1118
1119 /*
1120 * Get the saved delay count we computed for the previous packet
1121 * and save the delay count for this packet to be used next time
1122 * we get here.
1123 */
1124 control = qp->s_pkt_delay;
1125 qp->s_pkt_delay = ipath_pkt_delay(plen, dd->delay_mult, qp->s_dmult);
1126
1127 tx->qp = qp;
1128 atomic_inc(&qp->refcount);
1129 tx->wqe = qp->s_wqe;
1130 tx->txreq.callback = sdma_complete;
1131 tx->txreq.callback_cookie = tx;
1132 tx->txreq.flags = IPATH_SDMA_TXREQ_F_HEADTOHOST |
1133 IPATH_SDMA_TXREQ_F_INTREQ | IPATH_SDMA_TXREQ_F_FREEDESC;
1134 if (plen + 1 >= IPATH_SMALLBUF_DWORDS)
1135 tx->txreq.flags |= IPATH_SDMA_TXREQ_F_USELARGEBUF;
1136
1137 /* VL15 packets bypass credit check */
1138 if ((be16_to_cpu(hdr->lrh[0]) >> 12) == 15) {
1139 control |= 1ULL << 31;
1140 tx->txreq.flags |= IPATH_SDMA_TXREQ_F_VL15;
1141 }
1142
1143 if (len) {
1144 /*
1145 * Don't try to DMA if it takes more descriptors than
1146 * the queue holds.
1147 */
1148 ndesc = ipath_count_sge(ss, len);
1149 if (ndesc >= dd->ipath_sdma_descq_cnt)
1150 ndesc = 0;
1151 } else
1152 ndesc = 1;
1153 if (ndesc) {
1154 tx->hdr.pbc[0] = cpu_to_le32(plen);
1155 tx->hdr.pbc[1] = cpu_to_le32(control);
1156 memcpy(&tx->hdr.hdr, hdr, hdrwords << 2);
1157 tx->txreq.sg_count = ndesc;
1158 tx->map_len = (hdrwords + 2) << 2;
1159 tx->txreq.map_addr = &tx->hdr;
Ralph Campbelle509be82008-05-13 11:41:29 -07001160 atomic_inc(&qp->s_dma_busy);
Dave Olson124b4dc2008-04-16 21:09:32 -07001161 ret = ipath_sdma_verbs_send(dd, ss, dwords, tx);
1162 if (ret) {
1163 /* save ss and length in dwords */
1164 tx->ss = ss;
1165 tx->len = dwords;
1166 qp->s_tx = tx;
Ralph Campbelle509be82008-05-13 11:41:29 -07001167 decrement_dma_busy(qp);
Dave Olson124b4dc2008-04-16 21:09:32 -07001168 }
1169 goto bail;
1170 }
1171
1172 /* Allocate a buffer and copy the header and payload to it. */
1173 tx->map_len = (plen + 1) << 2;
1174 piobuf = kmalloc(tx->map_len, GFP_ATOMIC);
1175 if (unlikely(piobuf == NULL)) {
1176 ret = -EBUSY;
1177 goto err_tx;
1178 }
1179 tx->txreq.map_addr = piobuf;
1180 tx->txreq.flags |= IPATH_SDMA_TXREQ_F_FREEBUF;
1181 tx->txreq.sg_count = 1;
1182
1183 *piobuf++ = (__force u32) cpu_to_le32(plen);
1184 *piobuf++ = (__force u32) cpu_to_le32(control);
1185 memcpy(piobuf, hdr, hdrwords << 2);
1186 ipath_copy_from_sge(piobuf + hdrwords, ss, len);
1187
Ralph Campbelle509be82008-05-13 11:41:29 -07001188 atomic_inc(&qp->s_dma_busy);
Dave Olson124b4dc2008-04-16 21:09:32 -07001189 ret = ipath_sdma_verbs_send(dd, NULL, 0, tx);
1190 /*
1191 * If we couldn't queue the DMA request, save the info
1192 * and try again later rather than destroying the
1193 * buffer and undoing the side effects of the copy.
1194 */
1195 if (ret) {
1196 tx->ss = NULL;
1197 tx->len = 0;
1198 qp->s_tx = tx;
Ralph Campbelle509be82008-05-13 11:41:29 -07001199 decrement_dma_busy(qp);
Dave Olson124b4dc2008-04-16 21:09:32 -07001200 }
1201 dev->n_unaligned++;
1202 goto bail;
1203
1204err_tx:
1205 if (atomic_dec_and_test(&qp->refcount))
1206 wake_up(&qp->wait);
1207 put_txreq(dev, tx);
1208bail:
1209 return ret;
1210}
1211
1212static int ipath_verbs_send_pio(struct ipath_qp *qp,
1213 struct ipath_ib_header *ibhdr, u32 hdrwords,
Ralph Campbell4ee97182007-07-25 11:08:28 -07001214 struct ipath_sge_state *ss, u32 len,
1215 u32 plen, u32 dwords)
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001216{
Ralph Campbell4ee97182007-07-25 11:08:28 -07001217 struct ipath_devdata *dd = to_idev(qp->ibqp.device)->dd;
Dave Olson124b4dc2008-04-16 21:09:32 -07001218 u32 *hdr = (u32 *) ibhdr;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001219 u32 __iomem *piobuf;
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001220 unsigned flush_wc;
Dave Olson124b4dc2008-04-16 21:09:32 -07001221 u32 control;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001222 int ret;
Ralph Campbelle509be82008-05-13 11:41:29 -07001223 unsigned int flags;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001224
Ralph Campbellc4b4d162008-04-16 21:09:26 -07001225 piobuf = ipath_getpiobuf(dd, plen, NULL);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001226 if (unlikely(piobuf == NULL)) {
1227 ret = -EBUSY;
1228 goto bail;
1229 }
1230
1231 /*
Dave Olson124b4dc2008-04-16 21:09:32 -07001232 * Get the saved delay count we computed for the previous packet
1233 * and save the delay count for this packet to be used next time
1234 * we get here.
1235 */
1236 control = qp->s_pkt_delay;
1237 qp->s_pkt_delay = ipath_pkt_delay(plen, dd->delay_mult, qp->s_dmult);
1238
1239 /* VL15 packets bypass credit check */
1240 if ((be16_to_cpu(ibhdr->lrh[0]) >> 12) == 15)
1241 control |= 1ULL << 31;
1242
1243 /*
1244 * Write the length to the control qword plus any needed flags.
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001245 * We have to flush after the PBC for correctness on some cpus
1246 * or WC buffer can be written out of order.
1247 */
Dave Olson124b4dc2008-04-16 21:09:32 -07001248 writeq(((u64) control << 32) | plen, piobuf);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001249 piobuf += 2;
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001250
1251 flush_wc = dd->ipath_flags & IPATH_PIO_FLUSH_WC;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001252 if (len == 0) {
1253 /*
1254 * If there is just the header portion, must flush before
1255 * writing last word of header for correctness, and after
1256 * the last header word (trigger word).
1257 */
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001258 if (flush_wc) {
1259 ipath_flush_wc();
1260 __iowrite32_copy(piobuf, hdr, hdrwords - 1);
1261 ipath_flush_wc();
1262 __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords - 1);
1263 ipath_flush_wc();
1264 } else
1265 __iowrite32_copy(piobuf, hdr, hdrwords);
1266 goto done;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001267 }
1268
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001269 if (flush_wc)
1270 ipath_flush_wc();
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001271 __iowrite32_copy(piobuf, hdr, hdrwords);
1272 piobuf += hdrwords;
1273
1274 /* The common case is aligned and contained in one segment. */
1275 if (likely(ss->num_sge == 1 && len <= ss->sge.length &&
1276 !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) {
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001277 u32 *addr = (u32 *) ss->sge.vaddr;
1278
1279 /* Update address before sending packet. */
1280 update_sge(ss, len);
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001281 if (flush_wc) {
1282 __iowrite32_copy(piobuf, addr, dwords - 1);
1283 /* must flush early everything before trigger word */
1284 ipath_flush_wc();
1285 __raw_writel(addr[dwords - 1], piobuf + dwords - 1);
1286 /* be sure trigger word is written */
1287 ipath_flush_wc();
1288 } else
1289 __iowrite32_copy(piobuf, addr, dwords);
1290 goto done;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001291 }
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001292 copy_io(piobuf, ss, len, flush_wc);
1293done:
Ralph Campbelle509be82008-05-13 11:41:29 -07001294 if (qp->s_wqe) {
1295 spin_lock_irqsave(&qp->s_lock, flags);
Ralph Campbell4ee97182007-07-25 11:08:28 -07001296 ipath_send_complete(qp, qp->s_wqe, IB_WC_SUCCESS);
Ralph Campbelle509be82008-05-13 11:41:29 -07001297 spin_unlock_irqrestore(&qp->s_lock, flags);
1298 }
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001299 ret = 0;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001300bail:
1301 return ret;
1302}
1303
Ralph Campbell4ee97182007-07-25 11:08:28 -07001304/**
1305 * ipath_verbs_send - send a packet
1306 * @qp: the QP to send on
1307 * @hdr: the packet header
Dave Olson9e2ef36b2008-01-06 21:02:34 -08001308 * @hdrwords: the number of 32-bit words in the header
Ralph Campbell4ee97182007-07-25 11:08:28 -07001309 * @ss: the SGE to send
1310 * @len: the length of the packet in bytes
1311 */
1312int ipath_verbs_send(struct ipath_qp *qp, struct ipath_ib_header *hdr,
1313 u32 hdrwords, struct ipath_sge_state *ss, u32 len)
1314{
Ralph Campbell49739b32007-09-19 16:47:31 -07001315 struct ipath_devdata *dd = to_idev(qp->ibqp.device)->dd;
Ralph Campbell4ee97182007-07-25 11:08:28 -07001316 u32 plen;
1317 int ret;
1318 u32 dwords = (len + 3) >> 2;
1319
Dave Olson9e2ef36b2008-01-06 21:02:34 -08001320 /*
1321 * Calculate the send buffer trigger address.
1322 * The +1 counts for the pbc control dword following the pbc length.
1323 */
Ralph Campbell4ee97182007-07-25 11:08:28 -07001324 plen = hdrwords + dwords + 1;
1325
Dave Olson124b4dc2008-04-16 21:09:32 -07001326 /*
1327 * VL15 packets (IB_QPT_SMI) will always use PIO, so we
1328 * can defer SDMA restart until link goes ACTIVE without
1329 * worrying about just how we got there.
1330 */
Ralph Campbelle509be82008-05-13 11:41:29 -07001331 if (qp->ibqp.qp_type == IB_QPT_SMI ||
1332 !(dd->ipath_flags & IPATH_HAS_SEND_DMA))
Dave Olson124b4dc2008-04-16 21:09:32 -07001333 ret = ipath_verbs_send_pio(qp, hdr, hdrwords, ss, len,
1334 plen, dwords);
Dave Olson124b4dc2008-04-16 21:09:32 -07001335 else
Ralph Campbelle509be82008-05-13 11:41:29 -07001336 ret = ipath_verbs_send_dma(qp, hdr, hdrwords, ss, len,
Dave Olson124b4dc2008-04-16 21:09:32 -07001337 plen, dwords);
Ralph Campbell4ee97182007-07-25 11:08:28 -07001338
1339 return ret;
1340}
1341
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001342int ipath_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
1343 u64 *rwords, u64 *spkts, u64 *rpkts,
1344 u64 *xmit_wait)
1345{
1346 int ret;
1347
1348 if (!(dd->ipath_flags & IPATH_INITTED)) {
1349 /* no hardware, freeze, etc. */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001350 ret = -EINVAL;
1351 goto bail;
1352 }
1353 *swords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
1354 *rwords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
1355 *spkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
1356 *rpkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
1357 *xmit_wait = ipath_snap_cntr(dd, dd->ipath_cregs->cr_sendstallcnt);
1358
1359 ret = 0;
1360
1361bail:
1362 return ret;
1363}
1364
1365/**
1366 * ipath_get_counters - get various chip counters
1367 * @dd: the infinipath device
1368 * @cntrs: counters are placed here
1369 *
1370 * Return the counters needed by recv_pma_get_portcounters().
1371 */
1372int ipath_get_counters(struct ipath_devdata *dd,
1373 struct ipath_verbs_counters *cntrs)
1374{
Ralph Campbell4ee97182007-07-25 11:08:28 -07001375 struct ipath_cregs const *crp = dd->ipath_cregs;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001376 int ret;
1377
1378 if (!(dd->ipath_flags & IPATH_INITTED)) {
1379 /* no hardware, freeze, etc. */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001380 ret = -EINVAL;
1381 goto bail;
1382 }
1383 cntrs->symbol_error_counter =
Ralph Campbell4ee97182007-07-25 11:08:28 -07001384 ipath_snap_cntr(dd, crp->cr_ibsymbolerrcnt);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001385 cntrs->link_error_recovery_counter =
Ralph Campbell4ee97182007-07-25 11:08:28 -07001386 ipath_snap_cntr(dd, crp->cr_iblinkerrrecovcnt);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001387 /*
1388 * The link downed counter counts when the other side downs the
1389 * connection. We add in the number of times we downed the link
1390 * due to local link integrity errors to compensate.
1391 */
1392 cntrs->link_downed_counter =
Ralph Campbell4ee97182007-07-25 11:08:28 -07001393 ipath_snap_cntr(dd, crp->cr_iblinkdowncnt);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001394 cntrs->port_rcv_errors =
Ralph Campbell4ee97182007-07-25 11:08:28 -07001395 ipath_snap_cntr(dd, crp->cr_rxdroppktcnt) +
1396 ipath_snap_cntr(dd, crp->cr_rcvovflcnt) +
1397 ipath_snap_cntr(dd, crp->cr_portovflcnt) +
1398 ipath_snap_cntr(dd, crp->cr_err_rlencnt) +
1399 ipath_snap_cntr(dd, crp->cr_invalidrlencnt) +
1400 ipath_snap_cntr(dd, crp->cr_errlinkcnt) +
1401 ipath_snap_cntr(dd, crp->cr_erricrccnt) +
1402 ipath_snap_cntr(dd, crp->cr_errvcrccnt) +
1403 ipath_snap_cntr(dd, crp->cr_errlpcrccnt) +
1404 ipath_snap_cntr(dd, crp->cr_badformatcnt) +
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001405 dd->ipath_rxfc_unsupvl_errs;
Dave Olson124b4dc2008-04-16 21:09:32 -07001406 if (crp->cr_rxotherlocalphyerrcnt)
1407 cntrs->port_rcv_errors +=
1408 ipath_snap_cntr(dd, crp->cr_rxotherlocalphyerrcnt);
1409 if (crp->cr_rxvlerrcnt)
1410 cntrs->port_rcv_errors +=
1411 ipath_snap_cntr(dd, crp->cr_rxvlerrcnt);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001412 cntrs->port_rcv_remphys_errors =
Ralph Campbell4ee97182007-07-25 11:08:28 -07001413 ipath_snap_cntr(dd, crp->cr_rcvebpcnt);
1414 cntrs->port_xmit_discards = ipath_snap_cntr(dd, crp->cr_unsupvlcnt);
1415 cntrs->port_xmit_data = ipath_snap_cntr(dd, crp->cr_wordsendcnt);
1416 cntrs->port_rcv_data = ipath_snap_cntr(dd, crp->cr_wordrcvcnt);
1417 cntrs->port_xmit_packets = ipath_snap_cntr(dd, crp->cr_pktsendcnt);
1418 cntrs->port_rcv_packets = ipath_snap_cntr(dd, crp->cr_pktrcvcnt);
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001419 cntrs->local_link_integrity_errors =
Dave Olson124b4dc2008-04-16 21:09:32 -07001420 crp->cr_locallinkintegrityerrcnt ?
1421 ipath_snap_cntr(dd, crp->cr_locallinkintegrityerrcnt) :
1422 ((dd->ipath_flags & IPATH_GPIO_ERRINTRS) ?
1423 dd->ipath_lli_errs : dd->ipath_lli_errors);
1424 cntrs->excessive_buffer_overrun_errors =
1425 crp->cr_excessbufferovflcnt ?
1426 ipath_snap_cntr(dd, crp->cr_excessbufferovflcnt) :
1427 dd->ipath_overrun_thresh_errs;
1428 cntrs->vl15_dropped = crp->cr_vl15droppedpktcnt ?
1429 ipath_snap_cntr(dd, crp->cr_vl15droppedpktcnt) : 0;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001430
1431 ret = 0;
1432
1433bail:
1434 return ret;
1435}
1436
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001437/**
1438 * ipath_ib_piobufavail - callback when a PIO buffer is available
1439 * @arg: the device pointer
1440 *
1441 * This is called from ipath_intr() at interrupt level when a PIO buffer is
1442 * available after ipath_verbs_send() returned an error that no buffers were
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -07001443 * available. Return 1 if we consumed all the PIO buffers and we still have
Ralph Campbelle509be82008-05-13 11:41:29 -07001444 * QPs waiting for buffers (for now, just restart the send tasklet and
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -07001445 * return zero).
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001446 */
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07001447int ipath_ib_piobufavail(struct ipath_ibdev *dev)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001448{
Ralph Campbelle509be82008-05-13 11:41:29 -07001449 struct list_head *list;
1450 struct ipath_qp *qplist;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001451 struct ipath_qp *qp;
1452 unsigned long flags;
1453
1454 if (dev == NULL)
1455 goto bail;
1456
Ralph Campbelle509be82008-05-13 11:41:29 -07001457 list = &dev->piowait;
1458 qplist = NULL;
1459
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001460 spin_lock_irqsave(&dev->pending_lock, flags);
Ralph Campbelle509be82008-05-13 11:41:29 -07001461 while (!list_empty(list)) {
1462 qp = list_entry(list->next, struct ipath_qp, piowait);
Bryan O'Sullivan94b8d9f2006-05-23 11:32:32 -07001463 list_del_init(&qp->piowait);
Ralph Campbelle509be82008-05-13 11:41:29 -07001464 qp->pio_next = qplist;
1465 qplist = qp;
1466 atomic_inc(&qp->refcount);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001467 }
1468 spin_unlock_irqrestore(&dev->pending_lock, flags);
1469
Ralph Campbelle509be82008-05-13 11:41:29 -07001470 while (qplist != NULL) {
1471 qp = qplist;
1472 qplist = qp->pio_next;
1473
1474 spin_lock_irqsave(&qp->s_lock, flags);
1475 if (ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK)
1476 ipath_schedule_send(qp);
1477 spin_unlock_irqrestore(&qp->s_lock, flags);
1478
1479 /* Notify ipath_destroy_qp() if it is waiting. */
1480 if (atomic_dec_and_test(&qp->refcount))
1481 wake_up(&qp->wait);
1482 }
1483
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001484bail:
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -07001485 return 0;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001486}
1487
1488static int ipath_query_device(struct ib_device *ibdev,
1489 struct ib_device_attr *props)
1490{
1491 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001492
1493 memset(props, 0, sizeof(*props));
1494
1495 props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
1496 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
1497 IB_DEVICE_SYS_IMAGE_GUID;
Ralph Campbellc9f79bd2006-07-17 18:19:54 -07001498 props->page_size_cap = PAGE_SIZE;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001499 props->vendor_id = dev->dd->ipath_vendorid;
1500 props->vendor_part_id = dev->dd->ipath_deviceid;
1501 props->hw_ver = dev->dd->ipath_pcirev;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001502
1503 props->sys_image_guid = dev->sys_image_guid;
1504
1505 props->max_mr_size = ~0ull;
Bryan O'Sullivan0b81e4f2006-08-25 11:24:43 -07001506 props->max_qp = ib_ipath_max_qps;
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001507 props->max_qp_wr = ib_ipath_max_qp_wrs;
1508 props->max_sge = ib_ipath_max_sges;
1509 props->max_cq = ib_ipath_max_cqs;
1510 props->max_ah = ib_ipath_max_ahs;
1511 props->max_cqe = ib_ipath_max_cqes;
1512 props->max_mr = dev->lk_table.max;
Robert Walshfdc72152007-06-18 14:24:36 -07001513 props->max_fmr = dev->lk_table.max;
1514 props->max_map_per_fmr = 32767;
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001515 props->max_pd = ib_ipath_max_pds;
Ralph Campbell3859e392007-03-15 14:44:51 -07001516 props->max_qp_rd_atom = IPATH_MAX_RDMA_ATOMIC;
1517 props->max_qp_init_rd_atom = 255;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001518 /* props->max_res_rd_atom */
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001519 props->max_srq = ib_ipath_max_srqs;
1520 props->max_srq_wr = ib_ipath_max_srq_wrs;
1521 props->max_srq_sge = ib_ipath_max_srq_sges;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001522 /* props->local_ca_ack_delay */
Ralph Campbell3859e392007-03-15 14:44:51 -07001523 props->atomic_cap = IB_ATOMIC_GLOB;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001524 props->max_pkeys = ipath_get_npkeys(dev->dd);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001525 props->max_mcast_grp = ib_ipath_max_mcast_grps;
1526 props->max_mcast_qp_attach = ib_ipath_max_mcast_qp_attached;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001527 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
1528 props->max_mcast_grp;
1529
1530 return 0;
1531}
1532
Ralph Campbell3d68ea32008-01-10 00:50:41 -08001533const u8 ipath_cvt_physportstate[32] = {
1534 [INFINIPATH_IBCS_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
1535 [INFINIPATH_IBCS_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
1536 [INFINIPATH_IBCS_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
1537 [INFINIPATH_IBCS_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
1538 [INFINIPATH_IBCS_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
1539 [INFINIPATH_IBCS_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
1540 [INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE] =
1541 IB_PHYSPORTSTATE_CFG_TRAIN,
1542 [INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG] =
1543 IB_PHYSPORTSTATE_CFG_TRAIN,
1544 [INFINIPATH_IBCS_LT_STATE_CFGWAITRMT] =
1545 IB_PHYSPORTSTATE_CFG_TRAIN,
1546 [INFINIPATH_IBCS_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_TRAIN,
1547 [INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN] =
1548 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
1549 [INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT] =
1550 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
1551 [INFINIPATH_IBCS_LT_STATE_RECOVERIDLE] =
1552 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
1553 [0x10] = IB_PHYSPORTSTATE_CFG_TRAIN,
1554 [0x11] = IB_PHYSPORTSTATE_CFG_TRAIN,
1555 [0x12] = IB_PHYSPORTSTATE_CFG_TRAIN,
1556 [0x13] = IB_PHYSPORTSTATE_CFG_TRAIN,
1557 [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
1558 [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
1559 [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
1560 [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001561};
1562
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001563u32 ipath_get_cr_errpkey(struct ipath_devdata *dd)
1564{
1565 return ipath_read_creg32(dd, dd->ipath_cregs->cr_errpkey);
1566}
1567
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001568static int ipath_query_port(struct ib_device *ibdev,
1569 u8 port, struct ib_port_attr *props)
1570{
1571 struct ipath_ibdev *dev = to_idev(ibdev);
Ralph Campbell4ee97182007-07-25 11:08:28 -07001572 struct ipath_devdata *dd = dev->dd;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001573 enum ib_mtu mtu;
Ralph Campbell4ee97182007-07-25 11:08:28 -07001574 u16 lid = dd->ipath_lid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001575 u64 ibcstat;
1576
1577 memset(props, 0, sizeof(*props));
1578 props->lid = lid ? lid : __constant_be16_to_cpu(IB_LID_PERMISSIVE);
Ralph Campbell542869a2007-09-13 11:42:52 -07001579 props->lmc = dd->ipath_lmc;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001580 props->sm_lid = dev->sm_lid;
1581 props->sm_sl = dev->sm_sl;
Ralph Campbell4ee97182007-07-25 11:08:28 -07001582 ibcstat = dd->ipath_lastibcstat;
Ralph Campbella51a2512008-04-16 21:09:24 -07001583 /* map LinkState to IB portinfo values. */
1584 props->state = ipath_ib_linkstate(dd, ibcstat) + 1;
1585
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001586 /* See phys_state_show() */
Ralph Campbell3d68ea32008-01-10 00:50:41 -08001587 props->phys_state = /* MEA: assumes shift == 0 */
1588 ipath_cvt_physportstate[dd->ipath_lastibcstat &
1589 dd->ibcs_lts_mask];
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001590 props->port_cap_flags = dev->port_cap_flags;
1591 props->gid_tbl_len = 1;
Bryan O'Sullivanc100f622006-07-01 04:36:07 -07001592 props->max_msg_sz = 0x80000000;
Ralph Campbell4ee97182007-07-25 11:08:28 -07001593 props->pkey_tbl_len = ipath_get_npkeys(dd);
1594 props->bad_pkey_cntr = ipath_get_cr_errpkey(dd) -
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001595 dev->z_pkey_violations;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001596 props->qkey_viol_cntr = dev->qkey_violations;
Ralph Campbella51a2512008-04-16 21:09:24 -07001597 props->active_width = dd->ipath_link_width_active;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001598 /* See rate_show() */
Ralph Campbella51a2512008-04-16 21:09:24 -07001599 props->active_speed = dd->ipath_link_speed_active;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001600 props->max_vl_num = 1; /* VLCap = VL0 */
1601 props->init_type_reply = 0;
1602
Dave Olson826d8012008-04-16 21:01:12 -07001603 props->max_mtu = ipath_mtu4096 ? IB_MTU_4096 : IB_MTU_2048;
Ralph Campbell4ee97182007-07-25 11:08:28 -07001604 switch (dd->ipath_ibmtu) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001605 case 4096:
1606 mtu = IB_MTU_4096;
1607 break;
1608 case 2048:
1609 mtu = IB_MTU_2048;
1610 break;
1611 case 1024:
1612 mtu = IB_MTU_1024;
1613 break;
1614 case 512:
1615 mtu = IB_MTU_512;
1616 break;
1617 case 256:
1618 mtu = IB_MTU_256;
1619 break;
1620 default:
1621 mtu = IB_MTU_2048;
1622 }
1623 props->active_mtu = mtu;
1624 props->subnet_timeout = dev->subnet_timeout;
1625
1626 return 0;
1627}
1628
1629static int ipath_modify_device(struct ib_device *device,
1630 int device_modify_mask,
1631 struct ib_device_modify *device_modify)
1632{
1633 int ret;
1634
1635 if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
1636 IB_DEVICE_MODIFY_NODE_DESC)) {
1637 ret = -EOPNOTSUPP;
1638 goto bail;
1639 }
1640
1641 if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC)
1642 memcpy(device->node_desc, device_modify->node_desc, 64);
1643
1644 if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
1645 to_idev(device)->sys_image_guid =
1646 cpu_to_be64(device_modify->sys_image_guid);
1647
1648 ret = 0;
1649
1650bail:
1651 return ret;
1652}
1653
1654static int ipath_modify_port(struct ib_device *ibdev,
1655 u8 port, int port_modify_mask,
1656 struct ib_port_modify *props)
1657{
1658 struct ipath_ibdev *dev = to_idev(ibdev);
1659
1660 dev->port_cap_flags |= props->set_port_cap_mask;
1661 dev->port_cap_flags &= ~props->clr_port_cap_mask;
1662 if (port_modify_mask & IB_PORT_SHUTDOWN)
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001663 ipath_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001664 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
1665 dev->qkey_violations = 0;
1666 return 0;
1667}
1668
1669static int ipath_query_gid(struct ib_device *ibdev, u8 port,
1670 int index, union ib_gid *gid)
1671{
1672 struct ipath_ibdev *dev = to_idev(ibdev);
1673 int ret;
1674
1675 if (index >= 1) {
1676 ret = -EINVAL;
1677 goto bail;
1678 }
1679 gid->global.subnet_prefix = dev->gid_prefix;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001680 gid->global.interface_id = dev->dd->ipath_guid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001681
1682 ret = 0;
1683
1684bail:
1685 return ret;
1686}
1687
1688static struct ib_pd *ipath_alloc_pd(struct ib_device *ibdev,
1689 struct ib_ucontext *context,
1690 struct ib_udata *udata)
1691{
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001692 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001693 struct ipath_pd *pd;
1694 struct ib_pd *ret;
1695
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001696 /*
1697 * This is actually totally arbitrary. Some correctness tests
1698 * assume there's a maximum number of PDs that can be allocated.
1699 * We don't actually have this limit, but we fail the test if
1700 * we allow allocations of more than we report for this value.
1701 */
1702
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001703 pd = kmalloc(sizeof *pd, GFP_KERNEL);
1704 if (!pd) {
1705 ret = ERR_PTR(-ENOMEM);
1706 goto bail;
1707 }
1708
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001709 spin_lock(&dev->n_pds_lock);
1710 if (dev->n_pds_allocated == ib_ipath_max_pds) {
1711 spin_unlock(&dev->n_pds_lock);
1712 kfree(pd);
1713 ret = ERR_PTR(-ENOMEM);
1714 goto bail;
1715 }
1716
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001717 dev->n_pds_allocated++;
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001718 spin_unlock(&dev->n_pds_lock);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001719
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001720 /* ib_alloc_pd() will initialize pd->ibpd. */
1721 pd->user = udata != NULL;
1722
1723 ret = &pd->ibpd;
1724
1725bail:
1726 return ret;
1727}
1728
1729static int ipath_dealloc_pd(struct ib_pd *ibpd)
1730{
1731 struct ipath_pd *pd = to_ipd(ibpd);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001732 struct ipath_ibdev *dev = to_idev(ibpd->device);
1733
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001734 spin_lock(&dev->n_pds_lock);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001735 dev->n_pds_allocated--;
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001736 spin_unlock(&dev->n_pds_lock);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001737
1738 kfree(pd);
1739
1740 return 0;
1741}
1742
1743/**
1744 * ipath_create_ah - create an address handle
1745 * @pd: the protection domain
1746 * @ah_attr: the attributes of the AH
1747 *
1748 * This may be called from interrupt context.
1749 */
1750static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
1751 struct ib_ah_attr *ah_attr)
1752{
1753 struct ipath_ah *ah;
1754 struct ib_ah *ret;
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001755 struct ipath_ibdev *dev = to_idev(pd->device);
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001756 unsigned long flags;
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001757
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001758 /* A multicast address requires a GRH (see ch. 8.4.1). */
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -07001759 if (ah_attr->dlid >= IPATH_MULTICAST_LID_BASE &&
1760 ah_attr->dlid != IPATH_PERMISSIVE_LID &&
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001761 !(ah_attr->ah_flags & IB_AH_GRH)) {
1762 ret = ERR_PTR(-EINVAL);
1763 goto bail;
1764 }
1765
Bryan O'Sullivan4a45b7d2006-07-01 04:35:55 -07001766 if (ah_attr->dlid == 0) {
1767 ret = ERR_PTR(-EINVAL);
1768 goto bail;
1769 }
1770
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001771 if (ah_attr->port_num < 1 ||
Bryan O'Sullivan4a45b7d2006-07-01 04:35:55 -07001772 ah_attr->port_num > pd->device->phys_port_cnt) {
1773 ret = ERR_PTR(-EINVAL);
1774 goto bail;
1775 }
1776
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001777 ah = kmalloc(sizeof *ah, GFP_ATOMIC);
1778 if (!ah) {
1779 ret = ERR_PTR(-ENOMEM);
1780 goto bail;
1781 }
1782
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001783 spin_lock_irqsave(&dev->n_ahs_lock, flags);
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001784 if (dev->n_ahs_allocated == ib_ipath_max_ahs) {
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001785 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001786 kfree(ah);
1787 ret = ERR_PTR(-ENOMEM);
1788 goto bail;
1789 }
1790
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001791 dev->n_ahs_allocated++;
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001792 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001793
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001794 /* ib_create_ah() will initialize ah->ibah. */
1795 ah->attr = *ah_attr;
Dave Olson124b4dc2008-04-16 21:09:32 -07001796 ah->attr.static_rate = ipath_ib_rate_to_mult(ah_attr->static_rate);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001797
1798 ret = &ah->ibah;
1799
1800bail:
1801 return ret;
1802}
1803
1804/**
1805 * ipath_destroy_ah - destroy an address handle
1806 * @ibah: the AH to destroy
1807 *
1808 * This may be called from interrupt context.
1809 */
1810static int ipath_destroy_ah(struct ib_ah *ibah)
1811{
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001812 struct ipath_ibdev *dev = to_idev(ibah->device);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001813 struct ipath_ah *ah = to_iah(ibah);
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001814 unsigned long flags;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001815
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001816 spin_lock_irqsave(&dev->n_ahs_lock, flags);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001817 dev->n_ahs_allocated--;
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001818 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001819
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001820 kfree(ah);
1821
1822 return 0;
1823}
1824
1825static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
1826{
1827 struct ipath_ah *ah = to_iah(ibah);
1828
1829 *ah_attr = ah->attr;
Dave Olson124b4dc2008-04-16 21:09:32 -07001830 ah_attr->static_rate = ipath_mult_to_ib_rate(ah->attr.static_rate);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001831
1832 return 0;
1833}
1834
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001835/**
1836 * ipath_get_npkeys - return the size of the PKEY table for port 0
1837 * @dd: the infinipath device
1838 */
1839unsigned ipath_get_npkeys(struct ipath_devdata *dd)
1840{
1841 return ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys);
1842}
1843
1844/**
1845 * ipath_get_pkey - return the indexed PKEY from the port 0 PKEY table
1846 * @dd: the infinipath device
1847 * @index: the PKEY index
1848 */
1849unsigned ipath_get_pkey(struct ipath_devdata *dd, unsigned index)
1850{
1851 unsigned ret;
1852
1853 if (index >= ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys))
1854 ret = 0;
1855 else
1856 ret = dd->ipath_pd[0]->port_pkeys[index];
1857
1858 return ret;
1859}
1860
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001861static int ipath_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
1862 u16 *pkey)
1863{
1864 struct ipath_ibdev *dev = to_idev(ibdev);
1865 int ret;
1866
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001867 if (index >= ipath_get_npkeys(dev->dd)) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001868 ret = -EINVAL;
1869 goto bail;
1870 }
1871
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001872 *pkey = ipath_get_pkey(dev->dd, index);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001873 ret = 0;
1874
1875bail:
1876 return ret;
1877}
1878
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001879/**
1880 * ipath_alloc_ucontext - allocate a ucontest
1881 * @ibdev: the infiniband device
1882 * @udata: not used by the InfiniPath driver
1883 */
1884
1885static struct ib_ucontext *ipath_alloc_ucontext(struct ib_device *ibdev,
1886 struct ib_udata *udata)
1887{
1888 struct ipath_ucontext *context;
1889 struct ib_ucontext *ret;
1890
1891 context = kmalloc(sizeof *context, GFP_KERNEL);
1892 if (!context) {
1893 ret = ERR_PTR(-ENOMEM);
1894 goto bail;
1895 }
1896
1897 ret = &context->ibucontext;
1898
1899bail:
1900 return ret;
1901}
1902
1903static int ipath_dealloc_ucontext(struct ib_ucontext *context)
1904{
1905 kfree(to_iucontext(context));
1906 return 0;
1907}
1908
1909static int ipath_verbs_register_sysfs(struct ib_device *dev);
1910
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001911static void __verbs_timer(unsigned long arg)
1912{
1913 struct ipath_devdata *dd = (struct ipath_devdata *) arg;
1914
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001915 /* Handle verbs layer timeouts. */
1916 ipath_ib_timer(dd->verbs_dev);
1917
1918 mod_timer(&dd->verbs_timer, jiffies + 1);
1919}
1920
1921static int enable_timer(struct ipath_devdata *dd)
1922{
1923 /*
1924 * Early chips had a design flaw where the chip and kernel idea
1925 * of the tail register don't always agree, and therefore we won't
1926 * get an interrupt on the next packet received.
1927 * If the board supports per packet receive interrupts, use it.
1928 * Otherwise, the timer function periodically checks for packets
1929 * to cover this case.
1930 * Either way, the timer is needed for verbs layer related
1931 * processing.
1932 */
1933 if (dd->ipath_flags & IPATH_GPIO_INTR) {
1934 ipath_write_kreg(dd, dd->ipath_kregs->kr_debugportselect,
1935 0x2074076542310ULL);
1936 /* Enable GPIO bit 2 interrupt */
Arthur Jones8f140b42007-05-10 12:10:49 -07001937 dd->ipath_gpio_mask |= (u64) (1 << IPATH_GPIO_PORT0_BIT);
1938 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
1939 dd->ipath_gpio_mask);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001940 }
1941
1942 init_timer(&dd->verbs_timer);
1943 dd->verbs_timer.function = __verbs_timer;
1944 dd->verbs_timer.data = (unsigned long)dd;
1945 dd->verbs_timer.expires = jiffies + 1;
1946 add_timer(&dd->verbs_timer);
1947
1948 return 0;
1949}
1950
1951static int disable_timer(struct ipath_devdata *dd)
1952{
1953 /* Disable GPIO bit 2 interrupt */
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001954 if (dd->ipath_flags & IPATH_GPIO_INTR) {
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001955 /* Disable GPIO bit 2 interrupt */
Arthur Jones8f140b42007-05-10 12:10:49 -07001956 dd->ipath_gpio_mask &= ~((u64) (1 << IPATH_GPIO_PORT0_BIT));
1957 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
1958 dd->ipath_gpio_mask);
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001959 /*
1960 * We might want to undo changes to debugportselect,
1961 * but how?
1962 */
1963 }
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001964
1965 del_timer_sync(&dd->verbs_timer);
1966
1967 return 0;
1968}
1969
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001970/**
1971 * ipath_register_ib_device - register our device with the infiniband core
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001972 * @dd: the device data structure
1973 * Return the allocated ipath_ibdev pointer or NULL on error.
1974 */
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07001975int ipath_register_ib_device(struct ipath_devdata *dd)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001976{
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001977 struct ipath_verbs_counters cntrs;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001978 struct ipath_ibdev *idev;
1979 struct ib_device *dev;
Dave Olson124b4dc2008-04-16 21:09:32 -07001980 struct ipath_verbs_txreq *tx;
1981 unsigned i;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001982 int ret;
1983
1984 idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07001985 if (idev == NULL) {
1986 ret = -ENOMEM;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001987 goto bail;
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07001988 }
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001989
1990 dev = &idev->ibdev;
1991
Dave Olson124b4dc2008-04-16 21:09:32 -07001992 if (dd->ipath_sdma_descq_cnt) {
1993 tx = kmalloc(dd->ipath_sdma_descq_cnt * sizeof *tx,
1994 GFP_KERNEL);
1995 if (tx == NULL) {
1996 ret = -ENOMEM;
1997 goto err_tx;
1998 }
1999 } else
2000 tx = NULL;
2001 idev->txreq_bufs = tx;
2002
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002003 /* Only need to initialize non-zero fields. */
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07002004 spin_lock_init(&idev->n_pds_lock);
2005 spin_lock_init(&idev->n_ahs_lock);
2006 spin_lock_init(&idev->n_cqs_lock);
Bryan O'Sullivan0b81e4f2006-08-25 11:24:43 -07002007 spin_lock_init(&idev->n_qps_lock);
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07002008 spin_lock_init(&idev->n_srqs_lock);
2009 spin_lock_init(&idev->n_mcast_grps_lock);
2010
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002011 spin_lock_init(&idev->qp_table.lock);
2012 spin_lock_init(&idev->lk_table.lock);
2013 idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE);
2014 /* Set the prefix to the default value (see ch. 4.1.1) */
2015 idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL);
2016
2017 ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size);
2018 if (ret)
2019 goto err_qp;
2020
2021 /*
2022 * The top ib_ipath_lkey_table_size bits are used to index the
2023 * table. The lower 8 bits can be owned by the user (copied from
2024 * the LKEY). The remaining bits act as a generation number or tag.
2025 */
2026 idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
2027 idev->lk_table.table = kzalloc(idev->lk_table.max *
2028 sizeof(*idev->lk_table.table),
2029 GFP_KERNEL);
2030 if (idev->lk_table.table == NULL) {
2031 ret = -ENOMEM;
2032 goto err_lk;
2033 }
Robert Walsh6b66b2da2007-04-27 21:07:23 -07002034 INIT_LIST_HEAD(&idev->pending_mmaps);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002035 spin_lock_init(&idev->pending_lock);
Robert Walsh6b66b2da2007-04-27 21:07:23 -07002036 idev->mmap_offset = PAGE_SIZE;
2037 spin_lock_init(&idev->mmap_offset_lock);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002038 INIT_LIST_HEAD(&idev->pending[0]);
2039 INIT_LIST_HEAD(&idev->pending[1]);
2040 INIT_LIST_HEAD(&idev->pending[2]);
2041 INIT_LIST_HEAD(&idev->piowait);
2042 INIT_LIST_HEAD(&idev->rnrwait);
Dave Olson124b4dc2008-04-16 21:09:32 -07002043 INIT_LIST_HEAD(&idev->txreq_free);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002044 idev->pending_index = 0;
2045 idev->port_cap_flags =
2046 IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
Ralph Campbella51a2512008-04-16 21:09:24 -07002047 if (dd->ipath_flags & IPATH_HAS_LINK_LATENCY)
2048 idev->port_cap_flags |= IB_PORT_LINK_LATENCY_SUP;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002049 idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
2050 idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
2051 idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
2052 idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
Roland Dreier53533e12006-11-29 15:33:07 -08002053 idev->pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002054
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07002055 /* Snapshot current HW counters to "clear" them. */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002056 ipath_get_counters(dd, &cntrs);
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07002057 idev->z_symbol_error_counter = cntrs.symbol_error_counter;
2058 idev->z_link_error_recovery_counter =
2059 cntrs.link_error_recovery_counter;
2060 idev->z_link_downed_counter = cntrs.link_downed_counter;
2061 idev->z_port_rcv_errors = cntrs.port_rcv_errors;
2062 idev->z_port_rcv_remphys_errors =
2063 cntrs.port_rcv_remphys_errors;
2064 idev->z_port_xmit_discards = cntrs.port_xmit_discards;
2065 idev->z_port_xmit_data = cntrs.port_xmit_data;
2066 idev->z_port_rcv_data = cntrs.port_rcv_data;
2067 idev->z_port_xmit_packets = cntrs.port_xmit_packets;
2068 idev->z_port_rcv_packets = cntrs.port_rcv_packets;
2069 idev->z_local_link_integrity_errors =
2070 cntrs.local_link_integrity_errors;
2071 idev->z_excessive_buffer_overrun_errors =
2072 cntrs.excessive_buffer_overrun_errors;
Ralph Campbell6c719ca2008-01-06 21:02:33 -08002073 idev->z_vl15_dropped = cntrs.vl15_dropped;
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07002074
Dave Olson124b4dc2008-04-16 21:09:32 -07002075 for (i = 0; i < dd->ipath_sdma_descq_cnt; i++, tx++)
2076 list_add(&tx->txreq.list, &idev->txreq_free);
2077
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002078 /*
2079 * The system image GUID is supposed to be the same for all
2080 * IB HCAs in a single system but since there can be other
2081 * device types in the system, we can't be sure this is unique.
2082 */
2083 if (!sys_image_guid)
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002084 sys_image_guid = dd->ipath_guid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002085 idev->sys_image_guid = sys_image_guid;
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07002086 idev->ib_unit = dd->ipath_unit;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002087 idev->dd = dd;
2088
2089 strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX);
Bryan O'Sullivan41c75a12006-05-23 11:32:36 -07002090 dev->owner = THIS_MODULE;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002091 dev->node_guid = dd->ipath_guid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002092 dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION;
2093 dev->uverbs_cmd_mask =
2094 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
2095 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
2096 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
2097 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
2098 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
2099 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
2100 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
2101 (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
2102 (1ull << IB_USER_VERBS_CMD_REG_MR) |
2103 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
2104 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
2105 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
2106 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
2107 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
2108 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
2109 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
2110 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
2111 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
2112 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
2113 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
2114 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
2115 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
2116 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
2117 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
2118 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
2119 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
2120 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
2121 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
2122 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
Tom Tucker07ebafb2006-08-03 16:02:42 -05002123 dev->node_type = RDMA_NODE_IB_CA;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002124 dev->phys_port_cnt = 1;
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03002125 dev->num_comp_vectors = 1;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002126 dev->dma_device = &dd->pcidev->dev;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002127 dev->query_device = ipath_query_device;
2128 dev->modify_device = ipath_modify_device;
2129 dev->query_port = ipath_query_port;
2130 dev->modify_port = ipath_modify_port;
2131 dev->query_pkey = ipath_query_pkey;
2132 dev->query_gid = ipath_query_gid;
2133 dev->alloc_ucontext = ipath_alloc_ucontext;
2134 dev->dealloc_ucontext = ipath_dealloc_ucontext;
2135 dev->alloc_pd = ipath_alloc_pd;
2136 dev->dealloc_pd = ipath_dealloc_pd;
2137 dev->create_ah = ipath_create_ah;
2138 dev->destroy_ah = ipath_destroy_ah;
2139 dev->query_ah = ipath_query_ah;
2140 dev->create_srq = ipath_create_srq;
2141 dev->modify_srq = ipath_modify_srq;
2142 dev->query_srq = ipath_query_srq;
2143 dev->destroy_srq = ipath_destroy_srq;
2144 dev->create_qp = ipath_create_qp;
2145 dev->modify_qp = ipath_modify_qp;
2146 dev->query_qp = ipath_query_qp;
2147 dev->destroy_qp = ipath_destroy_qp;
2148 dev->post_send = ipath_post_send;
2149 dev->post_recv = ipath_post_receive;
2150 dev->post_srq_recv = ipath_post_srq_receive;
2151 dev->create_cq = ipath_create_cq;
2152 dev->destroy_cq = ipath_destroy_cq;
2153 dev->resize_cq = ipath_resize_cq;
2154 dev->poll_cq = ipath_poll_cq;
2155 dev->req_notify_cq = ipath_req_notify_cq;
2156 dev->get_dma_mr = ipath_get_dma_mr;
2157 dev->reg_phys_mr = ipath_reg_phys_mr;
2158 dev->reg_user_mr = ipath_reg_user_mr;
2159 dev->dereg_mr = ipath_dereg_mr;
2160 dev->alloc_fmr = ipath_alloc_fmr;
2161 dev->map_phys_fmr = ipath_map_phys_fmr;
2162 dev->unmap_fmr = ipath_unmap_fmr;
2163 dev->dealloc_fmr = ipath_dealloc_fmr;
2164 dev->attach_mcast = ipath_multicast_attach;
2165 dev->detach_mcast = ipath_multicast_detach;
2166 dev->process_mad = ipath_process_mad;
Ralph Campbell373d9912006-09-22 15:22:26 -07002167 dev->mmap = ipath_mmap;
Ralph Campbellf2cbb662006-12-12 14:28:28 -08002168 dev->dma_ops = &ipath_dma_mapping_ops;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002169
2170 snprintf(dev->node_desc, sizeof(dev->node_desc),
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07002171 IPATH_IDSTR " %s", init_utsname()->nodename);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002172
2173 ret = ib_register_device(dev);
2174 if (ret)
2175 goto err_reg;
2176
2177 if (ipath_verbs_register_sysfs(dev))
2178 goto err_class;
2179
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002180 enable_timer(dd);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002181
2182 goto bail;
2183
2184err_class:
2185 ib_unregister_device(dev);
2186err_reg:
2187 kfree(idev->lk_table.table);
2188err_lk:
2189 kfree(idev->qp_table.table);
2190err_qp:
Dave Olson124b4dc2008-04-16 21:09:32 -07002191 kfree(idev->txreq_bufs);
2192err_tx:
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002193 ib_dealloc_device(dev);
Bryan O'Sullivanb55f4f02006-08-25 11:24:33 -07002194 ipath_dev_err(dd, "cannot register verbs: %d!\n", -ret);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002195 idev = NULL;
2196
2197bail:
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07002198 dd->verbs_dev = idev;
2199 return ret;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002200}
2201
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07002202void ipath_unregister_ib_device(struct ipath_ibdev *dev)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002203{
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002204 struct ib_device *ibdev = &dev->ibdev;
Ralph Campbelle509be82008-05-13 11:41:29 -07002205 u32 qps_inuse;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002206
2207 ib_unregister_device(ibdev);
2208
Ralph Campbelle509be82008-05-13 11:41:29 -07002209 disable_timer(dev->dd);
2210
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002211 if (!list_empty(&dev->pending[0]) ||
2212 !list_empty(&dev->pending[1]) ||
2213 !list_empty(&dev->pending[2]))
Bryan O'Sullivanb55f4f02006-08-25 11:24:33 -07002214 ipath_dev_err(dev->dd, "pending list not empty!\n");
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002215 if (!list_empty(&dev->piowait))
Bryan O'Sullivanb55f4f02006-08-25 11:24:33 -07002216 ipath_dev_err(dev->dd, "piowait list not empty!\n");
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002217 if (!list_empty(&dev->rnrwait))
Bryan O'Sullivanb55f4f02006-08-25 11:24:33 -07002218 ipath_dev_err(dev->dd, "rnrwait list not empty!\n");
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002219 if (!ipath_mcast_tree_empty())
Bryan O'Sullivanb55f4f02006-08-25 11:24:33 -07002220 ipath_dev_err(dev->dd, "multicast table memory leak!\n");
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002221 /*
2222 * Note that ipath_unregister_ib_device() can be called before all
2223 * the QPs are destroyed!
2224 */
Ralph Campbelle509be82008-05-13 11:41:29 -07002225 qps_inuse = ipath_free_all_qps(&dev->qp_table);
2226 if (qps_inuse)
2227 ipath_dev_err(dev->dd, "QP memory leak! %u still in use\n",
2228 qps_inuse);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002229 kfree(dev->qp_table.table);
2230 kfree(dev->lk_table.table);
Dave Olson124b4dc2008-04-16 21:09:32 -07002231 kfree(dev->txreq_bufs);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002232 ib_dealloc_device(ibdev);
2233}
2234
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002235static ssize_t show_rev(struct device *device, struct device_attribute *attr,
2236 char *buf)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002237{
Roland Dreier5494c222006-04-19 11:40:12 -07002238 struct ipath_ibdev *dev =
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002239 container_of(device, struct ipath_ibdev, ibdev.dev);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002240
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002241 return sprintf(buf, "%x\n", dev->dd->ipath_pcirev);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002242}
2243
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002244static ssize_t show_hca(struct device *device, struct device_attribute *attr,
2245 char *buf)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002246{
Roland Dreier5494c222006-04-19 11:40:12 -07002247 struct ipath_ibdev *dev =
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002248 container_of(device, struct ipath_ibdev, ibdev.dev);
Roland Dreier5494c222006-04-19 11:40:12 -07002249 int ret;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002250
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002251 ret = dev->dd->ipath_f_get_boardname(dev->dd, buf, 128);
Roland Dreier5494c222006-04-19 11:40:12 -07002252 if (ret < 0)
2253 goto bail;
2254 strcat(buf, "\n");
2255 ret = strlen(buf);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002256
2257bail:
2258 return ret;
2259}
2260
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002261static ssize_t show_stats(struct device *device, struct device_attribute *attr,
2262 char *buf)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002263{
Roland Dreier5494c222006-04-19 11:40:12 -07002264 struct ipath_ibdev *dev =
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002265 container_of(device, struct ipath_ibdev, ibdev.dev);
Roland Dreier5494c222006-04-19 11:40:12 -07002266 int i;
2267 int len;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002268
Roland Dreier5494c222006-04-19 11:40:12 -07002269 len = sprintf(buf,
2270 "RC resends %d\n"
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -07002271 "RC no QACK %d\n"
Roland Dreier5494c222006-04-19 11:40:12 -07002272 "RC ACKs %d\n"
2273 "RC SEQ NAKs %d\n"
2274 "RC RDMA seq %d\n"
2275 "RC RNR NAKs %d\n"
2276 "RC OTH NAKs %d\n"
2277 "RC timeouts %d\n"
2278 "RC RDMA dup %d\n"
2279 "piobuf wait %d\n"
Dave Olson124b4dc2008-04-16 21:09:32 -07002280 "unaligned %d\n"
Roland Dreier5494c222006-04-19 11:40:12 -07002281 "PKT drops %d\n"
2282 "WQE errs %d\n",
2283 dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
2284 dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
2285 dev->n_other_naks, dev->n_timeouts,
Ralph Campbelle509be82008-05-13 11:41:29 -07002286 dev->n_rdma_dup_busy, dev->n_piowait, dev->n_unaligned,
Dave Olson124b4dc2008-04-16 21:09:32 -07002287 dev->n_pkt_drops, dev->n_wqe_errs);
Roland Dreier5494c222006-04-19 11:40:12 -07002288 for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002289 const struct ipath_opcode_stats *si = &dev->opstats[i];
2290
Roland Dreier5494c222006-04-19 11:40:12 -07002291 if (!si->n_packets && !si->n_bytes)
2292 continue;
2293 len += sprintf(buf + len, "%02x %llu/%llu\n", i,
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002294 (unsigned long long) si->n_packets,
Roland Dreier5494c222006-04-19 11:40:12 -07002295 (unsigned long long) si->n_bytes);
2296 }
2297 return len;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002298}
2299
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002300static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
2301static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
2302static DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
2303static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002304
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002305static struct device_attribute *ipath_class_attributes[] = {
2306 &dev_attr_hw_rev,
2307 &dev_attr_hca_type,
2308 &dev_attr_board_id,
2309 &dev_attr_stats
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002310};
2311
2312static int ipath_verbs_register_sysfs(struct ib_device *dev)
2313{
Roland Dreier5494c222006-04-19 11:40:12 -07002314 int i;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002315 int ret;
2316
Roland Dreier5494c222006-04-19 11:40:12 -07002317 for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i)
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002318 if (device_create_file(&dev->dev,
2319 ipath_class_attributes[i])) {
Roland Dreier5494c222006-04-19 11:40:12 -07002320 ret = 1;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002321 goto bail;
2322 }
2323
Roland Dreier5494c222006-04-19 11:40:12 -07002324 ret = 0;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002325
2326bail:
2327 return ret;
2328}