blob: 5d830d87ebcaf2d18031641e7d9498f3b45a33aa [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>
Franck Bui-Huu82524742008-05-12 21:21:05 +020038#include <linux/rculist.h>
Bryan O'Sullivan65221082006-03-29 15:23:38 -080039
40#include "ipath_kernel.h"
41#include "ipath_verbs.h"
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -070042#include "ipath_common.h"
Bryan O'Sullivan65221082006-03-29 15:23:38 -080043
Roland Dreierac2ae4c2006-04-19 11:40:12 -070044static unsigned int ib_ipath_qp_table_size = 251;
Bryan O'Sullivan65221082006-03-29 15:23:38 -080045module_param_named(qp_table_size, ib_ipath_qp_table_size, uint, S_IRUGO);
46MODULE_PARM_DESC(qp_table_size, "QP table size");
47
48unsigned int ib_ipath_lkey_table_size = 12;
49module_param_named(lkey_table_size, ib_ipath_lkey_table_size, uint,
50 S_IRUGO);
51MODULE_PARM_DESC(lkey_table_size,
52 "LKEY table size in bits (2^n, 1 <= n <= 23)");
53
Bryan O'Sullivanfe625462006-07-01 04:35:58 -070054static unsigned int ib_ipath_max_pds = 0xFFFF;
55module_param_named(max_pds, ib_ipath_max_pds, uint, S_IWUSR | S_IRUGO);
56MODULE_PARM_DESC(max_pds,
57 "Maximum number of protection domains to support");
58
59static unsigned int ib_ipath_max_ahs = 0xFFFF;
60module_param_named(max_ahs, ib_ipath_max_ahs, uint, S_IWUSR | S_IRUGO);
61MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support");
62
63unsigned int ib_ipath_max_cqes = 0x2FFFF;
64module_param_named(max_cqes, ib_ipath_max_cqes, uint, S_IWUSR | S_IRUGO);
65MODULE_PARM_DESC(max_cqes,
66 "Maximum number of completion queue entries to support");
67
68unsigned int ib_ipath_max_cqs = 0x1FFFF;
69module_param_named(max_cqs, ib_ipath_max_cqs, uint, S_IWUSR | S_IRUGO);
70MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support");
71
72unsigned int ib_ipath_max_qp_wrs = 0x3FFF;
73module_param_named(max_qp_wrs, ib_ipath_max_qp_wrs, uint,
74 S_IWUSR | S_IRUGO);
75MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support");
76
Bryan O'Sullivan0b81e4f2006-08-25 11:24:43 -070077unsigned int ib_ipath_max_qps = 16384;
78module_param_named(max_qps, ib_ipath_max_qps, uint, S_IWUSR | S_IRUGO);
79MODULE_PARM_DESC(max_qps, "Maximum number of QPs to support");
80
Bryan O'Sullivanfe625462006-07-01 04:35:58 -070081unsigned int ib_ipath_max_sges = 0x60;
82module_param_named(max_sges, ib_ipath_max_sges, uint, S_IWUSR | S_IRUGO);
83MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support");
84
85unsigned int ib_ipath_max_mcast_grps = 16384;
86module_param_named(max_mcast_grps, ib_ipath_max_mcast_grps, uint,
87 S_IWUSR | S_IRUGO);
88MODULE_PARM_DESC(max_mcast_grps,
89 "Maximum number of multicast groups to support");
90
91unsigned int ib_ipath_max_mcast_qp_attached = 16;
92module_param_named(max_mcast_qp_attached, ib_ipath_max_mcast_qp_attached,
93 uint, S_IWUSR | S_IRUGO);
94MODULE_PARM_DESC(max_mcast_qp_attached,
95 "Maximum number of attached QPs to support");
96
97unsigned int ib_ipath_max_srqs = 1024;
98module_param_named(max_srqs, ib_ipath_max_srqs, uint, S_IWUSR | S_IRUGO);
99MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support");
100
101unsigned int ib_ipath_max_srq_sges = 128;
102module_param_named(max_srq_sges, ib_ipath_max_srq_sges,
103 uint, S_IWUSR | S_IRUGO);
104MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support");
105
106unsigned int ib_ipath_max_srq_wrs = 0x1FFFF;
107module_param_named(max_srq_wrs, ib_ipath_max_srq_wrs,
108 uint, S_IWUSR | S_IRUGO);
109MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support");
110
Bryan O'Sullivand821f022006-08-25 11:24:45 -0700111static unsigned int ib_ipath_disable_sma;
112module_param_named(disable_sma, ib_ipath_disable_sma, uint, S_IWUSR | S_IRUGO);
Paul Bolle98628742008-04-21 18:19:13 -0700113MODULE_PARM_DESC(disable_sma, "Disable the SMA");
Bryan O'Sullivand821f022006-08-25 11:24:45 -0700114
Ralph Campbelle509be82008-05-13 11:41:29 -0700115/*
116 * Note that it is OK to post send work requests in the SQE and ERR
117 * states; ipath_do_send() will process them and generate error
118 * completions as per IB 1.2 C10-96.
119 */
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800120const int ib_ipath_state_ops[IB_QPS_ERR + 1] = {
121 [IB_QPS_RESET] = 0,
122 [IB_QPS_INIT] = IPATH_POST_RECV_OK,
123 [IB_QPS_RTR] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
124 [IB_QPS_RTS] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
Ralph Campbelle509be82008-05-13 11:41:29 -0700125 IPATH_POST_SEND_OK | IPATH_PROCESS_SEND_OK |
126 IPATH_PROCESS_NEXT_SEND_OK,
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800127 [IB_QPS_SQD] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
Ralph Campbelle509be82008-05-13 11:41:29 -0700128 IPATH_POST_SEND_OK | IPATH_PROCESS_SEND_OK,
129 [IB_QPS_SQE] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
130 IPATH_POST_SEND_OK | IPATH_FLUSH_SEND,
131 [IB_QPS_ERR] = IPATH_POST_RECV_OK | IPATH_FLUSH_RECV |
132 IPATH_POST_SEND_OK | IPATH_FLUSH_SEND,
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800133};
134
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700135struct ipath_ucontext {
136 struct ib_ucontext ibucontext;
137};
138
139static inline struct ipath_ucontext *to_iucontext(struct ib_ucontext
140 *ibucontext)
141{
142 return container_of(ibucontext, struct ipath_ucontext, ibucontext);
143}
144
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800145/*
146 * Translate ib_wr_opcode into ib_wc_opcode.
147 */
148const enum ib_wc_opcode ib_ipath_wc_opcode[] = {
149 [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
150 [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
151 [IB_WR_SEND] = IB_WC_SEND,
152 [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
153 [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
154 [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
155 [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD
156};
157
158/*
159 * System image GUID.
160 */
Roland Dreierac2ae4c2006-04-19 11:40:12 -0700161static __be64 sys_image_guid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800162
163/**
164 * ipath_copy_sge - copy data to SGE memory
165 * @ss: the SGE state
166 * @data: the data to copy
167 * @length: the length of the data
168 */
169void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length)
170{
171 struct ipath_sge *sge = &ss->sge;
172
173 while (length) {
174 u32 len = sge->length;
175
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800176 if (len > length)
177 len = length;
Ralph Campbell30d149a2007-06-18 14:24:44 -0700178 if (len > sge->sge_length)
179 len = sge->sge_length;
180 BUG_ON(len == 0);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800181 memcpy(sge->vaddr, data, len);
182 sge->vaddr += len;
183 sge->length -= len;
184 sge->sge_length -= len;
185 if (sge->sge_length == 0) {
186 if (--ss->num_sge)
187 *sge = *ss->sg_list++;
188 } else if (sge->length == 0 && sge->mr != NULL) {
189 if (++sge->n >= IPATH_SEGSZ) {
190 if (++sge->m >= sge->mr->mapsz)
191 break;
192 sge->n = 0;
193 }
194 sge->vaddr =
195 sge->mr->map[sge->m]->segs[sge->n].vaddr;
196 sge->length =
197 sge->mr->map[sge->m]->segs[sge->n].length;
198 }
199 data += len;
200 length -= len;
201 }
202}
203
204/**
205 * ipath_skip_sge - skip over SGE memory - XXX almost dup of prev func
206 * @ss: the SGE state
207 * @length: the number of bytes to skip
208 */
209void ipath_skip_sge(struct ipath_sge_state *ss, u32 length)
210{
211 struct ipath_sge *sge = &ss->sge;
212
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800213 while (length) {
214 u32 len = sge->length;
215
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800216 if (len > length)
217 len = length;
Ralph Campbell30d149a2007-06-18 14:24:44 -0700218 if (len > sge->sge_length)
219 len = sge->sge_length;
220 BUG_ON(len == 0);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800221 sge->vaddr += len;
222 sge->length -= len;
223 sge->sge_length -= len;
224 if (sge->sge_length == 0) {
225 if (--ss->num_sge)
226 *sge = *ss->sg_list++;
227 } else if (sge->length == 0 && sge->mr != NULL) {
228 if (++sge->n >= IPATH_SEGSZ) {
229 if (++sge->m >= sge->mr->mapsz)
230 break;
231 sge->n = 0;
232 }
233 sge->vaddr =
234 sge->mr->map[sge->m]->segs[sge->n].vaddr;
235 sge->length =
236 sge->mr->map[sge->m]->segs[sge->n].length;
237 }
238 length -= len;
239 }
240}
241
Dave Olson124b4dc2008-04-16 21:09:32 -0700242/*
243 * Count the number of DMA descriptors needed to send length bytes of data.
244 * Don't modify the ipath_sge_state to get the count.
245 * Return zero if any of the segments is not aligned.
246 */
247static u32 ipath_count_sge(struct ipath_sge_state *ss, u32 length)
248{
249 struct ipath_sge *sg_list = ss->sg_list;
250 struct ipath_sge sge = ss->sge;
251 u8 num_sge = ss->num_sge;
252 u32 ndesc = 1; /* count the header */
253
254 while (length) {
255 u32 len = sge.length;
256
257 if (len > length)
258 len = length;
259 if (len > sge.sge_length)
260 len = sge.sge_length;
261 BUG_ON(len == 0);
262 if (((long) sge.vaddr & (sizeof(u32) - 1)) ||
263 (len != length && (len & (sizeof(u32) - 1)))) {
264 ndesc = 0;
265 break;
266 }
267 ndesc++;
268 sge.vaddr += len;
269 sge.length -= len;
270 sge.sge_length -= len;
271 if (sge.sge_length == 0) {
272 if (--num_sge)
273 sge = *sg_list++;
274 } else if (sge.length == 0 && sge.mr != NULL) {
275 if (++sge.n >= IPATH_SEGSZ) {
276 if (++sge.m >= sge.mr->mapsz)
277 break;
278 sge.n = 0;
279 }
280 sge.vaddr =
281 sge.mr->map[sge.m]->segs[sge.n].vaddr;
282 sge.length =
283 sge.mr->map[sge.m]->segs[sge.n].length;
284 }
285 length -= len;
286 }
287 return ndesc;
288}
289
290/*
291 * Copy from the SGEs to the data buffer.
292 */
293static void ipath_copy_from_sge(void *data, struct ipath_sge_state *ss,
294 u32 length)
295{
296 struct ipath_sge *sge = &ss->sge;
297
298 while (length) {
299 u32 len = sge->length;
300
301 if (len > length)
302 len = length;
303 if (len > sge->sge_length)
304 len = sge->sge_length;
305 BUG_ON(len == 0);
306 memcpy(data, sge->vaddr, len);
307 sge->vaddr += len;
308 sge->length -= len;
309 sge->sge_length -= len;
310 if (sge->sge_length == 0) {
311 if (--ss->num_sge)
312 *sge = *ss->sg_list++;
313 } else if (sge->length == 0 && sge->mr != NULL) {
314 if (++sge->n >= IPATH_SEGSZ) {
315 if (++sge->m >= sge->mr->mapsz)
316 break;
317 sge->n = 0;
318 }
319 sge->vaddr =
320 sge->mr->map[sge->m]->segs[sge->n].vaddr;
321 sge->length =
322 sge->mr->map[sge->m]->segs[sge->n].length;
323 }
324 data += len;
325 length -= len;
326 }
327}
328
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800329/**
Ralph Campbell4ee97182007-07-25 11:08:28 -0700330 * ipath_post_one_send - post one RC, UC, or UD send work request
331 * @qp: the QP to post on
332 * @wr: the work request to send
333 */
334static int ipath_post_one_send(struct ipath_qp *qp, struct ib_send_wr *wr)
335{
336 struct ipath_swqe *wqe;
337 u32 next;
338 int i;
339 int j;
340 int acc;
341 int ret;
342 unsigned long flags;
343
344 spin_lock_irqsave(&qp->s_lock, flags);
345
346 /* Check that state is OK to post send. */
Ralph Campbelle509be82008-05-13 11:41:29 -0700347 if (unlikely(!(ib_ipath_state_ops[qp->state] & IPATH_POST_SEND_OK)))
348 goto bail_inval;
Ralph Campbell4ee97182007-07-25 11:08:28 -0700349
350 /* IB spec says that num_sge == 0 is OK. */
351 if (wr->num_sge > qp->s_max_sge)
352 goto bail_inval;
353
354 /*
355 * Don't allow RDMA reads or atomic operations on UC or
356 * undefined operations.
357 * Make sure buffer is large enough to hold the result for atomics.
358 */
359 if (qp->ibqp.qp_type == IB_QPT_UC) {
360 if ((unsigned) wr->opcode >= IB_WR_RDMA_READ)
361 goto bail_inval;
362 } else if (qp->ibqp.qp_type == IB_QPT_UD) {
363 /* Check UD opcode */
364 if (wr->opcode != IB_WR_SEND &&
365 wr->opcode != IB_WR_SEND_WITH_IMM)
366 goto bail_inval;
367 /* Check UD destination address PD */
368 if (qp->ibqp.pd != wr->wr.ud.ah->pd)
369 goto bail_inval;
370 } else if ((unsigned) wr->opcode > IB_WR_ATOMIC_FETCH_AND_ADD)
371 goto bail_inval;
372 else if (wr->opcode >= IB_WR_ATOMIC_CMP_AND_SWP &&
373 (wr->num_sge == 0 ||
374 wr->sg_list[0].length < sizeof(u64) ||
375 wr->sg_list[0].addr & (sizeof(u64) - 1)))
376 goto bail_inval;
377 else if (wr->opcode >= IB_WR_RDMA_READ && !qp->s_max_rd_atomic)
378 goto bail_inval;
379
380 next = qp->s_head + 1;
381 if (next >= qp->s_size)
382 next = 0;
Ralph Campbell4187b912007-11-14 13:34:14 -0800383 if (next == qp->s_last) {
384 ret = -ENOMEM;
385 goto bail;
386 }
Ralph Campbell4ee97182007-07-25 11:08:28 -0700387
388 wqe = get_swqe_ptr(qp, qp->s_head);
389 wqe->wr = *wr;
Ralph Campbell4ee97182007-07-25 11:08:28 -0700390 wqe->length = 0;
391 if (wr->num_sge) {
392 acc = wr->opcode >= IB_WR_RDMA_READ ?
393 IB_ACCESS_LOCAL_WRITE : 0;
394 for (i = 0, j = 0; i < wr->num_sge; i++) {
395 u32 length = wr->sg_list[i].length;
396 int ok;
397
398 if (length == 0)
399 continue;
400 ok = ipath_lkey_ok(qp, &wqe->sg_list[j],
401 &wr->sg_list[i], acc);
402 if (!ok)
403 goto bail_inval;
404 wqe->length += length;
405 j++;
406 }
407 wqe->wr.num_sge = j;
408 }
409 if (qp->ibqp.qp_type == IB_QPT_UC ||
410 qp->ibqp.qp_type == IB_QPT_RC) {
411 if (wqe->length > 0x80000000U)
412 goto bail_inval;
413 } else if (wqe->length > to_idev(qp->ibqp.device)->dd->ipath_ibmtu)
414 goto bail_inval;
Ralph Campbell6e87d152008-05-07 10:57:14 -0700415 wqe->ssn = qp->s_ssn++;
Ralph Campbell4ee97182007-07-25 11:08:28 -0700416 qp->s_head = next;
417
418 ret = 0;
419 goto bail;
420
421bail_inval:
422 ret = -EINVAL;
423bail:
424 spin_unlock_irqrestore(&qp->s_lock, flags);
425 return ret;
426}
427
428/**
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800429 * ipath_post_send - post a send on a QP
430 * @ibqp: the QP to post the send on
431 * @wr: the list of work requests to post
432 * @bad_wr: the first bad WR is put here
433 *
434 * This may be called from interrupt context.
435 */
436static int ipath_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
437 struct ib_send_wr **bad_wr)
438{
439 struct ipath_qp *qp = to_iqp(ibqp);
440 int err = 0;
441
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800442 for (; wr; wr = wr->next) {
Ralph Campbell4ee97182007-07-25 11:08:28 -0700443 err = ipath_post_one_send(qp, wr);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800444 if (err) {
445 *bad_wr = wr;
Ralph Campbell4ee97182007-07-25 11:08:28 -0700446 goto bail;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800447 }
448 }
449
Ralph Campbell4ee97182007-07-25 11:08:28 -0700450 /* Try to do the send work in the caller's context. */
451 ipath_do_send((unsigned long) qp);
452
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800453bail:
454 return err;
455}
456
457/**
458 * ipath_post_receive - post a receive on a QP
459 * @ibqp: the QP to post the receive on
460 * @wr: the WR to post
461 * @bad_wr: the first bad WR is put here
462 *
463 * This may be called from interrupt context.
464 */
465static int ipath_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
466 struct ib_recv_wr **bad_wr)
467{
468 struct ipath_qp *qp = to_iqp(ibqp);
Ralph Campbell373d9912006-09-22 15:22:26 -0700469 struct ipath_rwq *wq = qp->r_rq.wq;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800470 unsigned long flags;
471 int ret;
472
473 /* Check that state is OK to post receive. */
Ralph Campbell373d9912006-09-22 15:22:26 -0700474 if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_RECV_OK) || !wq) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800475 *bad_wr = wr;
476 ret = -EINVAL;
477 goto bail;
478 }
479
480 for (; wr; wr = wr->next) {
481 struct ipath_rwqe *wqe;
482 u32 next;
Ralph Campbell373d9912006-09-22 15:22:26 -0700483 int i;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800484
Ralph Campbell373d9912006-09-22 15:22:26 -0700485 if ((unsigned) wr->num_sge > qp->r_rq.max_sge) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800486 *bad_wr = wr;
Ralph Campbell4187b912007-11-14 13:34:14 -0800487 ret = -EINVAL;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800488 goto bail;
489 }
490
491 spin_lock_irqsave(&qp->r_rq.lock, flags);
Ralph Campbell373d9912006-09-22 15:22:26 -0700492 next = wq->head + 1;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800493 if (next >= qp->r_rq.size)
494 next = 0;
Ralph Campbell373d9912006-09-22 15:22:26 -0700495 if (next == wq->tail) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800496 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
497 *bad_wr = wr;
498 ret = -ENOMEM;
499 goto bail;
500 }
501
Ralph Campbell373d9912006-09-22 15:22:26 -0700502 wqe = get_rwqe_ptr(&qp->r_rq, wq->head);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800503 wqe->wr_id = wr->wr_id;
Ralph Campbell373d9912006-09-22 15:22:26 -0700504 wqe->num_sge = wr->num_sge;
505 for (i = 0; i < wr->num_sge; i++)
506 wqe->sg_list[i] = wr->sg_list[i];
Ralph Campbell4fc570b2007-07-06 12:48:23 -0700507 /* Make sure queue entry is written before the head index. */
508 smp_wmb();
Ralph Campbell373d9912006-09-22 15:22:26 -0700509 wq->head = next;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800510 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
511 }
512 ret = 0;
513
514bail:
515 return ret;
516}
517
518/**
519 * ipath_qp_rcv - processing an incoming packet on a QP
520 * @dev: the device the packet came on
521 * @hdr: the packet header
522 * @has_grh: true if the packet has a GRH
523 * @data: the packet data
524 * @tlen: the packet length
525 * @qp: the QP the packet came on
526 *
527 * This is called from ipath_ib_rcv() to process an incoming packet
528 * for the given QP.
529 * Called at interrupt level.
530 */
531static void ipath_qp_rcv(struct ipath_ibdev *dev,
532 struct ipath_ib_header *hdr, int has_grh,
533 void *data, u32 tlen, struct ipath_qp *qp)
534{
535 /* Check for valid receive state. */
536 if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) {
537 dev->n_pkt_drops++;
538 return;
539 }
540
541 switch (qp->ibqp.qp_type) {
542 case IB_QPT_SMI:
543 case IB_QPT_GSI:
Bryan O'Sullivand821f022006-08-25 11:24:45 -0700544 if (ib_ipath_disable_sma)
545 break;
546 /* FALLTHROUGH */
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800547 case IB_QPT_UD:
548 ipath_ud_rcv(dev, hdr, has_grh, data, tlen, qp);
549 break;
550
551 case IB_QPT_RC:
552 ipath_rc_rcv(dev, hdr, has_grh, data, tlen, qp);
553 break;
554
555 case IB_QPT_UC:
556 ipath_uc_rcv(dev, hdr, has_grh, data, tlen, qp);
557 break;
558
559 default:
560 break;
561 }
562}
563
564/**
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -0700565 * ipath_ib_rcv - process an incoming packet
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800566 * @arg: the device pointer
567 * @rhdr: the header of the packet
568 * @data: the packet data
569 * @tlen: the packet length
570 *
571 * This is called from ipath_kreceive() to process an incoming packet at
572 * interrupt level. Tlen is the length of the header + data + CRC in bytes.
573 */
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -0700574void ipath_ib_rcv(struct ipath_ibdev *dev, void *rhdr, void *data,
575 u32 tlen)
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800576{
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800577 struct ipath_ib_header *hdr = rhdr;
578 struct ipath_other_headers *ohdr;
579 struct ipath_qp *qp;
580 u32 qp_num;
581 int lnh;
582 u8 opcode;
583 u16 lid;
584
585 if (unlikely(dev == NULL))
586 goto bail;
587
588 if (unlikely(tlen < 24)) { /* LRH+BTH+CRC */
589 dev->rcv_errors++;
590 goto bail;
591 }
592
593 /* Check for a valid destination LID (see ch. 7.11.1). */
594 lid = be16_to_cpu(hdr->lrh[1]);
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700595 if (lid < IPATH_MULTICAST_LID_BASE) {
Ralph Campbell542869a2007-09-13 11:42:52 -0700596 lid &= ~((1 << dev->dd->ipath_lmc) - 1);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700597 if (unlikely(lid != dev->dd->ipath_lid)) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800598 dev->rcv_errors++;
599 goto bail;
600 }
601 }
602
603 /* Check for GRH */
604 lnh = be16_to_cpu(hdr->lrh[0]) & 3;
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700605 if (lnh == IPATH_LRH_BTH)
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800606 ohdr = &hdr->u.oth;
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700607 else if (lnh == IPATH_LRH_GRH)
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800608 ohdr = &hdr->u.l.oth;
609 else {
610 dev->rcv_errors++;
611 goto bail;
612 }
613
614 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
615 dev->opstats[opcode].n_bytes += tlen;
616 dev->opstats[opcode].n_packets++;
617
618 /* Get the destination QP number. */
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700619 qp_num = be32_to_cpu(ohdr->bth[1]) & IPATH_QPN_MASK;
620 if (qp_num == IPATH_MULTICAST_QPN) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800621 struct ipath_mcast *mcast;
622 struct ipath_mcast_qp *p;
623
Bryan O'Sullivan5a7d4ee2007-03-15 14:45:03 -0700624 if (lnh != IPATH_LRH_GRH) {
625 dev->n_pkt_drops++;
626 goto bail;
627 }
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800628 mcast = ipath_mcast_find(&hdr->u.l.grh.dgid);
629 if (mcast == NULL) {
630 dev->n_pkt_drops++;
631 goto bail;
632 }
633 dev->n_multicast_rcv++;
634 list_for_each_entry_rcu(p, &mcast->qp_list, list)
Bryan O'Sullivan5a7d4ee2007-03-15 14:45:03 -0700635 ipath_qp_rcv(dev, hdr, 1, data, tlen, p->qp);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800636 /*
637 * Notify ipath_multicast_detach() if it is waiting for us
638 * to finish.
639 */
640 if (atomic_dec_return(&mcast->refcount) <= 1)
641 wake_up(&mcast->wait);
642 } else {
643 qp = ipath_lookup_qpn(&dev->qp_table, qp_num);
644 if (qp) {
645 dev->n_unicast_rcv++;
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700646 ipath_qp_rcv(dev, hdr, lnh == IPATH_LRH_GRH, data,
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800647 tlen, qp);
648 /*
649 * Notify ipath_destroy_qp() if it is waiting
650 * for us to finish.
651 */
652 if (atomic_dec_and_test(&qp->refcount))
653 wake_up(&qp->wait);
654 } else
655 dev->n_pkt_drops++;
656 }
657
658bail:;
659}
660
661/**
662 * ipath_ib_timer - verbs timer
663 * @arg: the device pointer
664 *
665 * This is called from ipath_do_rcv_timer() at interrupt level to check for
666 * QPs which need retransmits and to collect performance numbers.
667 */
Roland Dreierda9aec72007-07-17 18:37:43 -0700668static void ipath_ib_timer(struct ipath_ibdev *dev)
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800669{
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800670 struct ipath_qp *resend = NULL;
Ralph Campbelle509be82008-05-13 11:41:29 -0700671 struct ipath_qp *rnr = NULL;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800672 struct list_head *last;
673 struct ipath_qp *qp;
674 unsigned long flags;
675
676 if (dev == NULL)
677 return;
678
679 spin_lock_irqsave(&dev->pending_lock, flags);
680 /* Start filling the next pending queue. */
681 if (++dev->pending_index >= ARRAY_SIZE(dev->pending))
682 dev->pending_index = 0;
683 /* Save any requests still in the new queue, they have timed out. */
684 last = &dev->pending[dev->pending_index];
685 while (!list_empty(last)) {
686 qp = list_entry(last->next, struct ipath_qp, timerwait);
Bryan O'Sullivan94b8d9f2006-05-23 11:32:32 -0700687 list_del_init(&qp->timerwait);
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -0700688 qp->timer_next = resend;
689 resend = qp;
690 atomic_inc(&qp->refcount);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800691 }
692 last = &dev->rnrwait;
693 if (!list_empty(last)) {
694 qp = list_entry(last->next, struct ipath_qp, timerwait);
695 if (--qp->s_rnr_timeout == 0) {
696 do {
Bryan O'Sullivan94b8d9f2006-05-23 11:32:32 -0700697 list_del_init(&qp->timerwait);
Ralph Campbelle509be82008-05-13 11:41:29 -0700698 qp->timer_next = rnr;
699 rnr = qp;
700 atomic_inc(&qp->refcount);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800701 if (list_empty(last))
702 break;
703 qp = list_entry(last->next, struct ipath_qp,
704 timerwait);
705 } while (qp->s_rnr_timeout == 0);
706 }
707 }
708 /*
709 * We should only be in the started state if pma_sample_start != 0
710 */
711 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED &&
712 --dev->pma_sample_start == 0) {
713 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700714 ipath_snapshot_counters(dev->dd, &dev->ipath_sword,
715 &dev->ipath_rword,
716 &dev->ipath_spkts,
717 &dev->ipath_rpkts,
718 &dev->ipath_xmit_wait);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800719 }
720 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
721 if (dev->pma_sample_interval == 0) {
722 u64 ta, tb, tc, td, te;
723
724 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700725 ipath_snapshot_counters(dev->dd, &ta, &tb,
726 &tc, &td, &te);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800727
728 dev->ipath_sword = ta - dev->ipath_sword;
729 dev->ipath_rword = tb - dev->ipath_rword;
730 dev->ipath_spkts = tc - dev->ipath_spkts;
731 dev->ipath_rpkts = td - dev->ipath_rpkts;
732 dev->ipath_xmit_wait = te - dev->ipath_xmit_wait;
733 }
734 else
735 dev->pma_sample_interval--;
736 }
737 spin_unlock_irqrestore(&dev->pending_lock, flags);
738
739 /* XXX What if timer fires again while this is running? */
Ralph Campbelle509be82008-05-13 11:41:29 -0700740 while (resend != NULL) {
741 qp = resend;
742 resend = qp->timer_next;
743
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800744 spin_lock_irqsave(&qp->s_lock, flags);
Ralph Campbelle509be82008-05-13 11:41:29 -0700745 if (qp->s_last != qp->s_tail &&
746 ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800747 dev->n_timeouts++;
Ralph Campbell53dc1ca2008-05-13 11:40:25 -0700748 ipath_restart_rc(qp, qp->s_last_psn + 1);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800749 }
750 spin_unlock_irqrestore(&qp->s_lock, flags);
751
752 /* Notify ipath_destroy_qp() if it is waiting. */
753 if (atomic_dec_and_test(&qp->refcount))
754 wake_up(&qp->wait);
755 }
Ralph Campbelle509be82008-05-13 11:41:29 -0700756 while (rnr != NULL) {
757 qp = rnr;
758 rnr = qp->timer_next;
759
760 spin_lock_irqsave(&qp->s_lock, flags);
761 if (ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK)
762 ipath_schedule_send(qp);
763 spin_unlock_irqrestore(&qp->s_lock, flags);
764
765 /* Notify ipath_destroy_qp() if it is waiting. */
766 if (atomic_dec_and_test(&qp->refcount))
767 wake_up(&qp->wait);
768 }
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800769}
770
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700771static void update_sge(struct ipath_sge_state *ss, u32 length)
772{
773 struct ipath_sge *sge = &ss->sge;
774
775 sge->vaddr += length;
776 sge->length -= length;
777 sge->sge_length -= length;
778 if (sge->sge_length == 0) {
779 if (--ss->num_sge)
780 *sge = *ss->sg_list++;
781 } else if (sge->length == 0 && sge->mr != NULL) {
782 if (++sge->n >= IPATH_SEGSZ) {
783 if (++sge->m >= sge->mr->mapsz)
784 return;
785 sge->n = 0;
786 }
787 sge->vaddr = sge->mr->map[sge->m]->segs[sge->n].vaddr;
788 sge->length = sge->mr->map[sge->m]->segs[sge->n].length;
789 }
790}
791
792#ifdef __LITTLE_ENDIAN
793static inline u32 get_upper_bits(u32 data, u32 shift)
794{
795 return data >> shift;
796}
797
798static inline u32 set_upper_bits(u32 data, u32 shift)
799{
800 return data << shift;
801}
802
803static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
804{
805 data <<= ((sizeof(u32) - n) * BITS_PER_BYTE);
806 data >>= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
807 return data;
808}
809#else
810static inline u32 get_upper_bits(u32 data, u32 shift)
811{
812 return data << shift;
813}
814
815static inline u32 set_upper_bits(u32 data, u32 shift)
816{
817 return data >> shift;
818}
819
820static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
821{
822 data >>= ((sizeof(u32) - n) * BITS_PER_BYTE);
823 data <<= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
824 return data;
825}
826#endif
827
828static void copy_io(u32 __iomem *piobuf, struct ipath_sge_state *ss,
Ralph Campbell210d6ca2007-07-24 13:55:39 -0700829 u32 length, unsigned flush_wc)
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700830{
831 u32 extra = 0;
832 u32 data = 0;
833 u32 last;
834
835 while (1) {
836 u32 len = ss->sge.length;
837 u32 off;
838
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700839 if (len > length)
840 len = length;
841 if (len > ss->sge.sge_length)
842 len = ss->sge.sge_length;
Ralph Campbell4ee97182007-07-25 11:08:28 -0700843 BUG_ON(len == 0);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700844 /* If the source address is not aligned, try to align it. */
845 off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1);
846 if (off) {
847 u32 *addr = (u32 *)((unsigned long)ss->sge.vaddr &
848 ~(sizeof(u32) - 1));
849 u32 v = get_upper_bits(*addr, off * BITS_PER_BYTE);
850 u32 y;
851
852 y = sizeof(u32) - off;
853 if (len > y)
854 len = y;
855 if (len + extra >= sizeof(u32)) {
856 data |= set_upper_bits(v, extra *
857 BITS_PER_BYTE);
858 len = sizeof(u32) - extra;
859 if (len == length) {
860 last = data;
861 break;
862 }
863 __raw_writel(data, piobuf);
864 piobuf++;
865 extra = 0;
866 data = 0;
867 } else {
868 /* Clear unused upper bytes */
869 data |= clear_upper_bytes(v, len, extra);
870 if (len == length) {
871 last = data;
872 break;
873 }
874 extra += len;
875 }
876 } else if (extra) {
877 /* Source address is aligned. */
878 u32 *addr = (u32 *) ss->sge.vaddr;
879 int shift = extra * BITS_PER_BYTE;
880 int ushift = 32 - shift;
881 u32 l = len;
882
883 while (l >= sizeof(u32)) {
884 u32 v = *addr;
885
886 data |= set_upper_bits(v, shift);
887 __raw_writel(data, piobuf);
888 data = get_upper_bits(v, ushift);
889 piobuf++;
890 addr++;
891 l -= sizeof(u32);
892 }
893 /*
894 * We still have 'extra' number of bytes leftover.
895 */
896 if (l) {
897 u32 v = *addr;
898
899 if (l + extra >= sizeof(u32)) {
900 data |= set_upper_bits(v, shift);
901 len -= l + extra - sizeof(u32);
902 if (len == length) {
903 last = data;
904 break;
905 }
906 __raw_writel(data, piobuf);
907 piobuf++;
908 extra = 0;
909 data = 0;
910 } else {
911 /* Clear unused upper bytes */
912 data |= clear_upper_bytes(v, l,
913 extra);
914 if (len == length) {
915 last = data;
916 break;
917 }
918 extra += l;
919 }
920 } else if (len == length) {
921 last = data;
922 break;
923 }
924 } else if (len == length) {
925 u32 w;
926
927 /*
928 * Need to round up for the last dword in the
929 * packet.
930 */
931 w = (len + 3) >> 2;
932 __iowrite32_copy(piobuf, ss->sge.vaddr, w - 1);
933 piobuf += w - 1;
934 last = ((u32 *) ss->sge.vaddr)[w - 1];
935 break;
936 } else {
937 u32 w = len >> 2;
938
939 __iowrite32_copy(piobuf, ss->sge.vaddr, w);
940 piobuf += w;
941
942 extra = len & (sizeof(u32) - 1);
943 if (extra) {
944 u32 v = ((u32 *) ss->sge.vaddr)[w];
945
946 /* Clear unused upper bytes */
947 data = clear_upper_bytes(v, extra, 0);
948 }
949 }
950 update_sge(ss, len);
951 length -= len;
952 }
953 /* Update address before sending packet. */
954 update_sge(ss, length);
Ralph Campbell210d6ca2007-07-24 13:55:39 -0700955 if (flush_wc) {
956 /* must flush early everything before trigger word */
957 ipath_flush_wc();
958 __raw_writel(last, piobuf);
959 /* be sure trigger word is written */
960 ipath_flush_wc();
961 } else
962 __raw_writel(last, piobuf);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700963}
964
Dave Olson124b4dc2008-04-16 21:09:32 -0700965/*
966 * Convert IB rate to delay multiplier.
967 */
968unsigned ipath_ib_rate_to_mult(enum ib_rate rate)
969{
970 switch (rate) {
971 case IB_RATE_2_5_GBPS: return 8;
972 case IB_RATE_5_GBPS: return 4;
973 case IB_RATE_10_GBPS: return 2;
974 case IB_RATE_20_GBPS: return 1;
975 default: return 0;
976 }
977}
978
979/*
980 * Convert delay multiplier to IB rate
981 */
982static enum ib_rate ipath_mult_to_ib_rate(unsigned mult)
983{
984 switch (mult) {
985 case 8: return IB_RATE_2_5_GBPS;
986 case 4: return IB_RATE_5_GBPS;
987 case 2: return IB_RATE_10_GBPS;
988 case 1: return IB_RATE_20_GBPS;
989 default: return IB_RATE_PORT_CURRENT;
990 }
991}
992
993static inline struct ipath_verbs_txreq *get_txreq(struct ipath_ibdev *dev)
994{
995 struct ipath_verbs_txreq *tx = NULL;
996 unsigned long flags;
997
998 spin_lock_irqsave(&dev->pending_lock, flags);
999 if (!list_empty(&dev->txreq_free)) {
1000 struct list_head *l = dev->txreq_free.next;
1001
1002 list_del(l);
1003 tx = list_entry(l, struct ipath_verbs_txreq, txreq.list);
1004 }
1005 spin_unlock_irqrestore(&dev->pending_lock, flags);
1006 return tx;
1007}
1008
1009static inline void put_txreq(struct ipath_ibdev *dev,
1010 struct ipath_verbs_txreq *tx)
1011{
1012 unsigned long flags;
1013
1014 spin_lock_irqsave(&dev->pending_lock, flags);
1015 list_add(&tx->txreq.list, &dev->txreq_free);
1016 spin_unlock_irqrestore(&dev->pending_lock, flags);
1017}
1018
1019static void sdma_complete(void *cookie, int status)
1020{
1021 struct ipath_verbs_txreq *tx = cookie;
1022 struct ipath_qp *qp = tx->qp;
1023 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
Ralph Campbelle509be82008-05-13 11:41:29 -07001024 unsigned int flags;
1025 enum ib_wc_status ibs = status == IPATH_SDMA_TXREQ_S_OK ?
1026 IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR;
Dave Olson124b4dc2008-04-16 21:09:32 -07001027
Ralph Campbelle509be82008-05-13 11:41:29 -07001028 if (atomic_dec_and_test(&qp->s_dma_busy)) {
1029 spin_lock_irqsave(&qp->s_lock, flags);
1030 if (tx->wqe)
1031 ipath_send_complete(qp, tx->wqe, ibs);
1032 if ((ib_ipath_state_ops[qp->state] & IPATH_FLUSH_SEND &&
1033 qp->s_last != qp->s_head) ||
1034 (qp->s_flags & IPATH_S_WAIT_DMA))
1035 ipath_schedule_send(qp);
1036 spin_unlock_irqrestore(&qp->s_lock, flags);
1037 wake_up(&qp->wait_dma);
1038 } else if (tx->wqe) {
1039 spin_lock_irqsave(&qp->s_lock, flags);
Dave Olson124b4dc2008-04-16 21:09:32 -07001040 ipath_send_complete(qp, tx->wqe, ibs);
Ralph Campbelle509be82008-05-13 11:41:29 -07001041 spin_unlock_irqrestore(&qp->s_lock, flags);
Dave Olson124b4dc2008-04-16 21:09:32 -07001042 }
1043
1044 if (tx->txreq.flags & IPATH_SDMA_TXREQ_F_FREEBUF)
1045 kfree(tx->txreq.map_addr);
1046 put_txreq(dev, tx);
1047
1048 if (atomic_dec_and_test(&qp->refcount))
1049 wake_up(&qp->wait);
1050}
1051
Ralph Campbelle509be82008-05-13 11:41:29 -07001052static void decrement_dma_busy(struct ipath_qp *qp)
1053{
1054 unsigned int flags;
1055
1056 if (atomic_dec_and_test(&qp->s_dma_busy)) {
1057 spin_lock_irqsave(&qp->s_lock, flags);
1058 if ((ib_ipath_state_ops[qp->state] & IPATH_FLUSH_SEND &&
1059 qp->s_last != qp->s_head) ||
1060 (qp->s_flags & IPATH_S_WAIT_DMA))
1061 ipath_schedule_send(qp);
1062 spin_unlock_irqrestore(&qp->s_lock, flags);
1063 wake_up(&qp->wait_dma);
1064 }
1065}
1066
Dave Olson124b4dc2008-04-16 21:09:32 -07001067/*
1068 * Compute the number of clock cycles of delay before sending the next packet.
1069 * The multipliers reflect the number of clocks for the fastest rate so
1070 * one tick at 4xDDR is 8 ticks at 1xSDR.
1071 * If the destination port will take longer to receive a packet than
1072 * the outgoing link can send it, we need to delay sending the next packet
1073 * by the difference in time it takes the receiver to receive and the sender
1074 * to send this packet.
1075 * Note that this delay is always correct for UC and RC but not always
1076 * optimal for UD. For UD, the destination HCA can be different for each
1077 * packet, in which case, we could send packets to a different destination
1078 * while "waiting" for the delay. The overhead for doing this without
1079 * HW support is more than just paying the cost of delaying some packets
1080 * unnecessarily.
1081 */
1082static inline unsigned ipath_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult)
1083{
1084 return (rcv_mult > snd_mult) ?
1085 (plen * (rcv_mult - snd_mult) + 1) >> 1 : 0;
1086}
1087
1088static int ipath_verbs_send_dma(struct ipath_qp *qp,
1089 struct ipath_ib_header *hdr, u32 hdrwords,
1090 struct ipath_sge_state *ss, u32 len,
1091 u32 plen, u32 dwords)
1092{
1093 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
1094 struct ipath_devdata *dd = dev->dd;
1095 struct ipath_verbs_txreq *tx;
1096 u32 *piobuf;
1097 u32 control;
1098 u32 ndesc;
1099 int ret;
1100
1101 tx = qp->s_tx;
1102 if (tx) {
1103 qp->s_tx = NULL;
1104 /* resend previously constructed packet */
Ralph Campbelle509be82008-05-13 11:41:29 -07001105 atomic_inc(&qp->s_dma_busy);
Dave Olson124b4dc2008-04-16 21:09:32 -07001106 ret = ipath_sdma_verbs_send(dd, tx->ss, tx->len, tx);
Ralph Campbelle509be82008-05-13 11:41:29 -07001107 if (ret) {
Dave Olson124b4dc2008-04-16 21:09:32 -07001108 qp->s_tx = tx;
Ralph Campbelle509be82008-05-13 11:41:29 -07001109 decrement_dma_busy(qp);
1110 }
Dave Olson124b4dc2008-04-16 21:09:32 -07001111 goto bail;
1112 }
1113
1114 tx = get_txreq(dev);
1115 if (!tx) {
1116 ret = -EBUSY;
1117 goto bail;
1118 }
1119
1120 /*
1121 * Get the saved delay count we computed for the previous packet
1122 * and save the delay count for this packet to be used next time
1123 * we get here.
1124 */
1125 control = qp->s_pkt_delay;
1126 qp->s_pkt_delay = ipath_pkt_delay(plen, dd->delay_mult, qp->s_dmult);
1127
1128 tx->qp = qp;
1129 atomic_inc(&qp->refcount);
1130 tx->wqe = qp->s_wqe;
1131 tx->txreq.callback = sdma_complete;
1132 tx->txreq.callback_cookie = tx;
1133 tx->txreq.flags = IPATH_SDMA_TXREQ_F_HEADTOHOST |
1134 IPATH_SDMA_TXREQ_F_INTREQ | IPATH_SDMA_TXREQ_F_FREEDESC;
1135 if (plen + 1 >= IPATH_SMALLBUF_DWORDS)
1136 tx->txreq.flags |= IPATH_SDMA_TXREQ_F_USELARGEBUF;
1137
1138 /* VL15 packets bypass credit check */
1139 if ((be16_to_cpu(hdr->lrh[0]) >> 12) == 15) {
1140 control |= 1ULL << 31;
1141 tx->txreq.flags |= IPATH_SDMA_TXREQ_F_VL15;
1142 }
1143
1144 if (len) {
1145 /*
1146 * Don't try to DMA if it takes more descriptors than
1147 * the queue holds.
1148 */
1149 ndesc = ipath_count_sge(ss, len);
1150 if (ndesc >= dd->ipath_sdma_descq_cnt)
1151 ndesc = 0;
1152 } else
1153 ndesc = 1;
1154 if (ndesc) {
1155 tx->hdr.pbc[0] = cpu_to_le32(plen);
1156 tx->hdr.pbc[1] = cpu_to_le32(control);
1157 memcpy(&tx->hdr.hdr, hdr, hdrwords << 2);
1158 tx->txreq.sg_count = ndesc;
1159 tx->map_len = (hdrwords + 2) << 2;
1160 tx->txreq.map_addr = &tx->hdr;
Ralph Campbelle509be82008-05-13 11:41:29 -07001161 atomic_inc(&qp->s_dma_busy);
Dave Olson124b4dc2008-04-16 21:09:32 -07001162 ret = ipath_sdma_verbs_send(dd, ss, dwords, tx);
1163 if (ret) {
1164 /* save ss and length in dwords */
1165 tx->ss = ss;
1166 tx->len = dwords;
1167 qp->s_tx = tx;
Ralph Campbelle509be82008-05-13 11:41:29 -07001168 decrement_dma_busy(qp);
Dave Olson124b4dc2008-04-16 21:09:32 -07001169 }
1170 goto bail;
1171 }
1172
1173 /* Allocate a buffer and copy the header and payload to it. */
1174 tx->map_len = (plen + 1) << 2;
1175 piobuf = kmalloc(tx->map_len, GFP_ATOMIC);
1176 if (unlikely(piobuf == NULL)) {
1177 ret = -EBUSY;
1178 goto err_tx;
1179 }
1180 tx->txreq.map_addr = piobuf;
1181 tx->txreq.flags |= IPATH_SDMA_TXREQ_F_FREEBUF;
1182 tx->txreq.sg_count = 1;
1183
1184 *piobuf++ = (__force u32) cpu_to_le32(plen);
1185 *piobuf++ = (__force u32) cpu_to_le32(control);
1186 memcpy(piobuf, hdr, hdrwords << 2);
1187 ipath_copy_from_sge(piobuf + hdrwords, ss, len);
1188
Ralph Campbelle509be82008-05-13 11:41:29 -07001189 atomic_inc(&qp->s_dma_busy);
Dave Olson124b4dc2008-04-16 21:09:32 -07001190 ret = ipath_sdma_verbs_send(dd, NULL, 0, tx);
1191 /*
1192 * If we couldn't queue the DMA request, save the info
1193 * and try again later rather than destroying the
1194 * buffer and undoing the side effects of the copy.
1195 */
1196 if (ret) {
1197 tx->ss = NULL;
1198 tx->len = 0;
1199 qp->s_tx = tx;
Ralph Campbelle509be82008-05-13 11:41:29 -07001200 decrement_dma_busy(qp);
Dave Olson124b4dc2008-04-16 21:09:32 -07001201 }
1202 dev->n_unaligned++;
1203 goto bail;
1204
1205err_tx:
1206 if (atomic_dec_and_test(&qp->refcount))
1207 wake_up(&qp->wait);
1208 put_txreq(dev, tx);
1209bail:
1210 return ret;
1211}
1212
1213static int ipath_verbs_send_pio(struct ipath_qp *qp,
1214 struct ipath_ib_header *ibhdr, u32 hdrwords,
Ralph Campbell4ee97182007-07-25 11:08:28 -07001215 struct ipath_sge_state *ss, u32 len,
1216 u32 plen, u32 dwords)
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001217{
Ralph Campbell4ee97182007-07-25 11:08:28 -07001218 struct ipath_devdata *dd = to_idev(qp->ibqp.device)->dd;
Dave Olson124b4dc2008-04-16 21:09:32 -07001219 u32 *hdr = (u32 *) ibhdr;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001220 u32 __iomem *piobuf;
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001221 unsigned flush_wc;
Dave Olson124b4dc2008-04-16 21:09:32 -07001222 u32 control;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001223 int ret;
Ralph Campbelle509be82008-05-13 11:41:29 -07001224 unsigned int flags;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001225
Ralph Campbellc4b4d162008-04-16 21:09:26 -07001226 piobuf = ipath_getpiobuf(dd, plen, NULL);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001227 if (unlikely(piobuf == NULL)) {
1228 ret = -EBUSY;
1229 goto bail;
1230 }
1231
1232 /*
Dave Olson124b4dc2008-04-16 21:09:32 -07001233 * Get the saved delay count we computed for the previous packet
1234 * and save the delay count for this packet to be used next time
1235 * we get here.
1236 */
1237 control = qp->s_pkt_delay;
1238 qp->s_pkt_delay = ipath_pkt_delay(plen, dd->delay_mult, qp->s_dmult);
1239
1240 /* VL15 packets bypass credit check */
1241 if ((be16_to_cpu(ibhdr->lrh[0]) >> 12) == 15)
1242 control |= 1ULL << 31;
1243
1244 /*
1245 * Write the length to the control qword plus any needed flags.
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001246 * We have to flush after the PBC for correctness on some cpus
1247 * or WC buffer can be written out of order.
1248 */
Dave Olson124b4dc2008-04-16 21:09:32 -07001249 writeq(((u64) control << 32) | plen, piobuf);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001250 piobuf += 2;
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001251
1252 flush_wc = dd->ipath_flags & IPATH_PIO_FLUSH_WC;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001253 if (len == 0) {
1254 /*
1255 * If there is just the header portion, must flush before
1256 * writing last word of header for correctness, and after
1257 * the last header word (trigger word).
1258 */
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001259 if (flush_wc) {
1260 ipath_flush_wc();
1261 __iowrite32_copy(piobuf, hdr, hdrwords - 1);
1262 ipath_flush_wc();
1263 __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords - 1);
1264 ipath_flush_wc();
1265 } else
1266 __iowrite32_copy(piobuf, hdr, hdrwords);
1267 goto done;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001268 }
1269
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001270 if (flush_wc)
1271 ipath_flush_wc();
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001272 __iowrite32_copy(piobuf, hdr, hdrwords);
1273 piobuf += hdrwords;
1274
1275 /* The common case is aligned and contained in one segment. */
1276 if (likely(ss->num_sge == 1 && len <= ss->sge.length &&
1277 !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) {
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001278 u32 *addr = (u32 *) ss->sge.vaddr;
1279
1280 /* Update address before sending packet. */
1281 update_sge(ss, len);
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001282 if (flush_wc) {
1283 __iowrite32_copy(piobuf, addr, dwords - 1);
1284 /* must flush early everything before trigger word */
1285 ipath_flush_wc();
1286 __raw_writel(addr[dwords - 1], piobuf + dwords - 1);
1287 /* be sure trigger word is written */
1288 ipath_flush_wc();
1289 } else
1290 __iowrite32_copy(piobuf, addr, dwords);
1291 goto done;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001292 }
Ralph Campbell210d6ca2007-07-24 13:55:39 -07001293 copy_io(piobuf, ss, len, flush_wc);
1294done:
Ralph Campbelle509be82008-05-13 11:41:29 -07001295 if (qp->s_wqe) {
1296 spin_lock_irqsave(&qp->s_lock, flags);
Ralph Campbell4ee97182007-07-25 11:08:28 -07001297 ipath_send_complete(qp, qp->s_wqe, IB_WC_SUCCESS);
Ralph Campbelle509be82008-05-13 11:41:29 -07001298 spin_unlock_irqrestore(&qp->s_lock, flags);
1299 }
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001300 ret = 0;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001301bail:
1302 return ret;
1303}
1304
Ralph Campbell4ee97182007-07-25 11:08:28 -07001305/**
1306 * ipath_verbs_send - send a packet
1307 * @qp: the QP to send on
1308 * @hdr: the packet header
Dave Olson9e2ef36b2008-01-06 21:02:34 -08001309 * @hdrwords: the number of 32-bit words in the header
Ralph Campbell4ee97182007-07-25 11:08:28 -07001310 * @ss: the SGE to send
1311 * @len: the length of the packet in bytes
1312 */
1313int ipath_verbs_send(struct ipath_qp *qp, struct ipath_ib_header *hdr,
1314 u32 hdrwords, struct ipath_sge_state *ss, u32 len)
1315{
Ralph Campbell49739b32007-09-19 16:47:31 -07001316 struct ipath_devdata *dd = to_idev(qp->ibqp.device)->dd;
Ralph Campbell4ee97182007-07-25 11:08:28 -07001317 u32 plen;
1318 int ret;
1319 u32 dwords = (len + 3) >> 2;
1320
Dave Olson9e2ef36b2008-01-06 21:02:34 -08001321 /*
1322 * Calculate the send buffer trigger address.
1323 * The +1 counts for the pbc control dword following the pbc length.
1324 */
Ralph Campbell4ee97182007-07-25 11:08:28 -07001325 plen = hdrwords + dwords + 1;
1326
Dave Olson124b4dc2008-04-16 21:09:32 -07001327 /*
1328 * VL15 packets (IB_QPT_SMI) will always use PIO, so we
1329 * can defer SDMA restart until link goes ACTIVE without
1330 * worrying about just how we got there.
1331 */
Ralph Campbelle509be82008-05-13 11:41:29 -07001332 if (qp->ibqp.qp_type == IB_QPT_SMI ||
1333 !(dd->ipath_flags & IPATH_HAS_SEND_DMA))
Dave Olson124b4dc2008-04-16 21:09:32 -07001334 ret = ipath_verbs_send_pio(qp, hdr, hdrwords, ss, len,
1335 plen, dwords);
Dave Olson124b4dc2008-04-16 21:09:32 -07001336 else
Ralph Campbelle509be82008-05-13 11:41:29 -07001337 ret = ipath_verbs_send_dma(qp, hdr, hdrwords, ss, len,
Dave Olson124b4dc2008-04-16 21:09:32 -07001338 plen, dwords);
Ralph Campbell4ee97182007-07-25 11:08:28 -07001339
1340 return ret;
1341}
1342
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001343int ipath_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
1344 u64 *rwords, u64 *spkts, u64 *rpkts,
1345 u64 *xmit_wait)
1346{
1347 int ret;
1348
1349 if (!(dd->ipath_flags & IPATH_INITTED)) {
1350 /* no hardware, freeze, etc. */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001351 ret = -EINVAL;
1352 goto bail;
1353 }
1354 *swords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
1355 *rwords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
1356 *spkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
1357 *rpkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
1358 *xmit_wait = ipath_snap_cntr(dd, dd->ipath_cregs->cr_sendstallcnt);
1359
1360 ret = 0;
1361
1362bail:
1363 return ret;
1364}
1365
1366/**
1367 * ipath_get_counters - get various chip counters
1368 * @dd: the infinipath device
1369 * @cntrs: counters are placed here
1370 *
1371 * Return the counters needed by recv_pma_get_portcounters().
1372 */
1373int ipath_get_counters(struct ipath_devdata *dd,
1374 struct ipath_verbs_counters *cntrs)
1375{
Ralph Campbell4ee97182007-07-25 11:08:28 -07001376 struct ipath_cregs const *crp = dd->ipath_cregs;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001377 int ret;
1378
1379 if (!(dd->ipath_flags & IPATH_INITTED)) {
1380 /* no hardware, freeze, etc. */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001381 ret = -EINVAL;
1382 goto bail;
1383 }
1384 cntrs->symbol_error_counter =
Ralph Campbell4ee97182007-07-25 11:08:28 -07001385 ipath_snap_cntr(dd, crp->cr_ibsymbolerrcnt);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001386 cntrs->link_error_recovery_counter =
Ralph Campbell4ee97182007-07-25 11:08:28 -07001387 ipath_snap_cntr(dd, crp->cr_iblinkerrrecovcnt);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001388 /*
1389 * The link downed counter counts when the other side downs the
1390 * connection. We add in the number of times we downed the link
1391 * due to local link integrity errors to compensate.
1392 */
1393 cntrs->link_downed_counter =
Ralph Campbell4ee97182007-07-25 11:08:28 -07001394 ipath_snap_cntr(dd, crp->cr_iblinkdowncnt);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001395 cntrs->port_rcv_errors =
Ralph Campbell4ee97182007-07-25 11:08:28 -07001396 ipath_snap_cntr(dd, crp->cr_rxdroppktcnt) +
1397 ipath_snap_cntr(dd, crp->cr_rcvovflcnt) +
1398 ipath_snap_cntr(dd, crp->cr_portovflcnt) +
1399 ipath_snap_cntr(dd, crp->cr_err_rlencnt) +
1400 ipath_snap_cntr(dd, crp->cr_invalidrlencnt) +
1401 ipath_snap_cntr(dd, crp->cr_errlinkcnt) +
1402 ipath_snap_cntr(dd, crp->cr_erricrccnt) +
1403 ipath_snap_cntr(dd, crp->cr_errvcrccnt) +
1404 ipath_snap_cntr(dd, crp->cr_errlpcrccnt) +
1405 ipath_snap_cntr(dd, crp->cr_badformatcnt) +
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001406 dd->ipath_rxfc_unsupvl_errs;
Dave Olson124b4dc2008-04-16 21:09:32 -07001407 if (crp->cr_rxotherlocalphyerrcnt)
1408 cntrs->port_rcv_errors +=
1409 ipath_snap_cntr(dd, crp->cr_rxotherlocalphyerrcnt);
1410 if (crp->cr_rxvlerrcnt)
1411 cntrs->port_rcv_errors +=
1412 ipath_snap_cntr(dd, crp->cr_rxvlerrcnt);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001413 cntrs->port_rcv_remphys_errors =
Ralph Campbell4ee97182007-07-25 11:08:28 -07001414 ipath_snap_cntr(dd, crp->cr_rcvebpcnt);
1415 cntrs->port_xmit_discards = ipath_snap_cntr(dd, crp->cr_unsupvlcnt);
1416 cntrs->port_xmit_data = ipath_snap_cntr(dd, crp->cr_wordsendcnt);
1417 cntrs->port_rcv_data = ipath_snap_cntr(dd, crp->cr_wordrcvcnt);
1418 cntrs->port_xmit_packets = ipath_snap_cntr(dd, crp->cr_pktsendcnt);
1419 cntrs->port_rcv_packets = ipath_snap_cntr(dd, crp->cr_pktrcvcnt);
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001420 cntrs->local_link_integrity_errors =
Dave Olson124b4dc2008-04-16 21:09:32 -07001421 crp->cr_locallinkintegrityerrcnt ?
1422 ipath_snap_cntr(dd, crp->cr_locallinkintegrityerrcnt) :
1423 ((dd->ipath_flags & IPATH_GPIO_ERRINTRS) ?
1424 dd->ipath_lli_errs : dd->ipath_lli_errors);
1425 cntrs->excessive_buffer_overrun_errors =
1426 crp->cr_excessbufferovflcnt ?
1427 ipath_snap_cntr(dd, crp->cr_excessbufferovflcnt) :
1428 dd->ipath_overrun_thresh_errs;
1429 cntrs->vl15_dropped = crp->cr_vl15droppedpktcnt ?
1430 ipath_snap_cntr(dd, crp->cr_vl15droppedpktcnt) : 0;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001431
1432 ret = 0;
1433
1434bail:
1435 return ret;
1436}
1437
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001438/**
1439 * ipath_ib_piobufavail - callback when a PIO buffer is available
1440 * @arg: the device pointer
1441 *
1442 * This is called from ipath_intr() at interrupt level when a PIO buffer is
1443 * available after ipath_verbs_send() returned an error that no buffers were
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -07001444 * available. Return 1 if we consumed all the PIO buffers and we still have
Ralph Campbelle509be82008-05-13 11:41:29 -07001445 * QPs waiting for buffers (for now, just restart the send tasklet and
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -07001446 * return zero).
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001447 */
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07001448int ipath_ib_piobufavail(struct ipath_ibdev *dev)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001449{
Ralph Campbelle509be82008-05-13 11:41:29 -07001450 struct list_head *list;
1451 struct ipath_qp *qplist;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001452 struct ipath_qp *qp;
1453 unsigned long flags;
1454
1455 if (dev == NULL)
1456 goto bail;
1457
Ralph Campbelle509be82008-05-13 11:41:29 -07001458 list = &dev->piowait;
1459 qplist = NULL;
1460
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001461 spin_lock_irqsave(&dev->pending_lock, flags);
Ralph Campbelle509be82008-05-13 11:41:29 -07001462 while (!list_empty(list)) {
1463 qp = list_entry(list->next, struct ipath_qp, piowait);
Bryan O'Sullivan94b8d9f2006-05-23 11:32:32 -07001464 list_del_init(&qp->piowait);
Ralph Campbelle509be82008-05-13 11:41:29 -07001465 qp->pio_next = qplist;
1466 qplist = qp;
1467 atomic_inc(&qp->refcount);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001468 }
1469 spin_unlock_irqrestore(&dev->pending_lock, flags);
1470
Ralph Campbelle509be82008-05-13 11:41:29 -07001471 while (qplist != NULL) {
1472 qp = qplist;
1473 qplist = qp->pio_next;
1474
1475 spin_lock_irqsave(&qp->s_lock, flags);
1476 if (ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK)
1477 ipath_schedule_send(qp);
1478 spin_unlock_irqrestore(&qp->s_lock, flags);
1479
1480 /* Notify ipath_destroy_qp() if it is waiting. */
1481 if (atomic_dec_and_test(&qp->refcount))
1482 wake_up(&qp->wait);
1483 }
1484
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001485bail:
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -07001486 return 0;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001487}
1488
1489static int ipath_query_device(struct ib_device *ibdev,
1490 struct ib_device_attr *props)
1491{
1492 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001493
1494 memset(props, 0, sizeof(*props));
1495
1496 props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
1497 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
1498 IB_DEVICE_SYS_IMAGE_GUID;
Ralph Campbellc9f79bd2006-07-17 18:19:54 -07001499 props->page_size_cap = PAGE_SIZE;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001500 props->vendor_id = dev->dd->ipath_vendorid;
1501 props->vendor_part_id = dev->dd->ipath_deviceid;
1502 props->hw_ver = dev->dd->ipath_pcirev;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001503
1504 props->sys_image_guid = dev->sys_image_guid;
1505
1506 props->max_mr_size = ~0ull;
Bryan O'Sullivan0b81e4f2006-08-25 11:24:43 -07001507 props->max_qp = ib_ipath_max_qps;
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001508 props->max_qp_wr = ib_ipath_max_qp_wrs;
1509 props->max_sge = ib_ipath_max_sges;
1510 props->max_cq = ib_ipath_max_cqs;
1511 props->max_ah = ib_ipath_max_ahs;
1512 props->max_cqe = ib_ipath_max_cqes;
1513 props->max_mr = dev->lk_table.max;
Robert Walshfdc72152007-06-18 14:24:36 -07001514 props->max_fmr = dev->lk_table.max;
1515 props->max_map_per_fmr = 32767;
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001516 props->max_pd = ib_ipath_max_pds;
Ralph Campbell3859e392007-03-15 14:44:51 -07001517 props->max_qp_rd_atom = IPATH_MAX_RDMA_ATOMIC;
1518 props->max_qp_init_rd_atom = 255;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001519 /* props->max_res_rd_atom */
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001520 props->max_srq = ib_ipath_max_srqs;
1521 props->max_srq_wr = ib_ipath_max_srq_wrs;
1522 props->max_srq_sge = ib_ipath_max_srq_sges;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001523 /* props->local_ca_ack_delay */
Ralph Campbell3859e392007-03-15 14:44:51 -07001524 props->atomic_cap = IB_ATOMIC_GLOB;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001525 props->max_pkeys = ipath_get_npkeys(dev->dd);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001526 props->max_mcast_grp = ib_ipath_max_mcast_grps;
1527 props->max_mcast_qp_attach = ib_ipath_max_mcast_qp_attached;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001528 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
1529 props->max_mcast_grp;
1530
1531 return 0;
1532}
1533
Ralph Campbell3d68ea32008-01-10 00:50:41 -08001534const u8 ipath_cvt_physportstate[32] = {
1535 [INFINIPATH_IBCS_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
1536 [INFINIPATH_IBCS_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
1537 [INFINIPATH_IBCS_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
1538 [INFINIPATH_IBCS_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
1539 [INFINIPATH_IBCS_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
1540 [INFINIPATH_IBCS_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
1541 [INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE] =
1542 IB_PHYSPORTSTATE_CFG_TRAIN,
1543 [INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG] =
1544 IB_PHYSPORTSTATE_CFG_TRAIN,
1545 [INFINIPATH_IBCS_LT_STATE_CFGWAITRMT] =
1546 IB_PHYSPORTSTATE_CFG_TRAIN,
1547 [INFINIPATH_IBCS_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_TRAIN,
1548 [INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN] =
1549 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
1550 [INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT] =
1551 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
1552 [INFINIPATH_IBCS_LT_STATE_RECOVERIDLE] =
1553 IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
1554 [0x10] = IB_PHYSPORTSTATE_CFG_TRAIN,
1555 [0x11] = IB_PHYSPORTSTATE_CFG_TRAIN,
1556 [0x12] = IB_PHYSPORTSTATE_CFG_TRAIN,
1557 [0x13] = IB_PHYSPORTSTATE_CFG_TRAIN,
1558 [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
1559 [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
1560 [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
1561 [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001562};
1563
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001564u32 ipath_get_cr_errpkey(struct ipath_devdata *dd)
1565{
1566 return ipath_read_creg32(dd, dd->ipath_cregs->cr_errpkey);
1567}
1568
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001569static int ipath_query_port(struct ib_device *ibdev,
1570 u8 port, struct ib_port_attr *props)
1571{
1572 struct ipath_ibdev *dev = to_idev(ibdev);
Ralph Campbell4ee97182007-07-25 11:08:28 -07001573 struct ipath_devdata *dd = dev->dd;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001574 enum ib_mtu mtu;
Ralph Campbell4ee97182007-07-25 11:08:28 -07001575 u16 lid = dd->ipath_lid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001576 u64 ibcstat;
1577
1578 memset(props, 0, sizeof(*props));
1579 props->lid = lid ? lid : __constant_be16_to_cpu(IB_LID_PERMISSIVE);
Ralph Campbell542869a2007-09-13 11:42:52 -07001580 props->lmc = dd->ipath_lmc;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001581 props->sm_lid = dev->sm_lid;
1582 props->sm_sl = dev->sm_sl;
Ralph Campbell4ee97182007-07-25 11:08:28 -07001583 ibcstat = dd->ipath_lastibcstat;
Ralph Campbella51a2512008-04-16 21:09:24 -07001584 /* map LinkState to IB portinfo values. */
1585 props->state = ipath_ib_linkstate(dd, ibcstat) + 1;
1586
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001587 /* See phys_state_show() */
Ralph Campbell3d68ea32008-01-10 00:50:41 -08001588 props->phys_state = /* MEA: assumes shift == 0 */
1589 ipath_cvt_physportstate[dd->ipath_lastibcstat &
1590 dd->ibcs_lts_mask];
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001591 props->port_cap_flags = dev->port_cap_flags;
1592 props->gid_tbl_len = 1;
Bryan O'Sullivanc100f622006-07-01 04:36:07 -07001593 props->max_msg_sz = 0x80000000;
Ralph Campbell4ee97182007-07-25 11:08:28 -07001594 props->pkey_tbl_len = ipath_get_npkeys(dd);
1595 props->bad_pkey_cntr = ipath_get_cr_errpkey(dd) -
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001596 dev->z_pkey_violations;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001597 props->qkey_viol_cntr = dev->qkey_violations;
Ralph Campbella51a2512008-04-16 21:09:24 -07001598 props->active_width = dd->ipath_link_width_active;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001599 /* See rate_show() */
Ralph Campbella51a2512008-04-16 21:09:24 -07001600 props->active_speed = dd->ipath_link_speed_active;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001601 props->max_vl_num = 1; /* VLCap = VL0 */
1602 props->init_type_reply = 0;
1603
Dave Olson826d8012008-04-16 21:01:12 -07001604 props->max_mtu = ipath_mtu4096 ? IB_MTU_4096 : IB_MTU_2048;
Ralph Campbell4ee97182007-07-25 11:08:28 -07001605 switch (dd->ipath_ibmtu) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001606 case 4096:
1607 mtu = IB_MTU_4096;
1608 break;
1609 case 2048:
1610 mtu = IB_MTU_2048;
1611 break;
1612 case 1024:
1613 mtu = IB_MTU_1024;
1614 break;
1615 case 512:
1616 mtu = IB_MTU_512;
1617 break;
1618 case 256:
1619 mtu = IB_MTU_256;
1620 break;
1621 default:
1622 mtu = IB_MTU_2048;
1623 }
1624 props->active_mtu = mtu;
1625 props->subnet_timeout = dev->subnet_timeout;
1626
1627 return 0;
1628}
1629
1630static int ipath_modify_device(struct ib_device *device,
1631 int device_modify_mask,
1632 struct ib_device_modify *device_modify)
1633{
1634 int ret;
1635
1636 if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
1637 IB_DEVICE_MODIFY_NODE_DESC)) {
1638 ret = -EOPNOTSUPP;
1639 goto bail;
1640 }
1641
1642 if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC)
1643 memcpy(device->node_desc, device_modify->node_desc, 64);
1644
1645 if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
1646 to_idev(device)->sys_image_guid =
1647 cpu_to_be64(device_modify->sys_image_guid);
1648
1649 ret = 0;
1650
1651bail:
1652 return ret;
1653}
1654
1655static int ipath_modify_port(struct ib_device *ibdev,
1656 u8 port, int port_modify_mask,
1657 struct ib_port_modify *props)
1658{
1659 struct ipath_ibdev *dev = to_idev(ibdev);
1660
1661 dev->port_cap_flags |= props->set_port_cap_mask;
1662 dev->port_cap_flags &= ~props->clr_port_cap_mask;
1663 if (port_modify_mask & IB_PORT_SHUTDOWN)
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001664 ipath_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001665 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
1666 dev->qkey_violations = 0;
1667 return 0;
1668}
1669
1670static int ipath_query_gid(struct ib_device *ibdev, u8 port,
1671 int index, union ib_gid *gid)
1672{
1673 struct ipath_ibdev *dev = to_idev(ibdev);
1674 int ret;
1675
1676 if (index >= 1) {
1677 ret = -EINVAL;
1678 goto bail;
1679 }
1680 gid->global.subnet_prefix = dev->gid_prefix;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001681 gid->global.interface_id = dev->dd->ipath_guid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001682
1683 ret = 0;
1684
1685bail:
1686 return ret;
1687}
1688
1689static struct ib_pd *ipath_alloc_pd(struct ib_device *ibdev,
1690 struct ib_ucontext *context,
1691 struct ib_udata *udata)
1692{
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001693 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001694 struct ipath_pd *pd;
1695 struct ib_pd *ret;
1696
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001697 /*
1698 * This is actually totally arbitrary. Some correctness tests
1699 * assume there's a maximum number of PDs that can be allocated.
1700 * We don't actually have this limit, but we fail the test if
1701 * we allow allocations of more than we report for this value.
1702 */
1703
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001704 pd = kmalloc(sizeof *pd, GFP_KERNEL);
1705 if (!pd) {
1706 ret = ERR_PTR(-ENOMEM);
1707 goto bail;
1708 }
1709
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001710 spin_lock(&dev->n_pds_lock);
1711 if (dev->n_pds_allocated == ib_ipath_max_pds) {
1712 spin_unlock(&dev->n_pds_lock);
1713 kfree(pd);
1714 ret = ERR_PTR(-ENOMEM);
1715 goto bail;
1716 }
1717
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001718 dev->n_pds_allocated++;
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001719 spin_unlock(&dev->n_pds_lock);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001720
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001721 /* ib_alloc_pd() will initialize pd->ibpd. */
1722 pd->user = udata != NULL;
1723
1724 ret = &pd->ibpd;
1725
1726bail:
1727 return ret;
1728}
1729
1730static int ipath_dealloc_pd(struct ib_pd *ibpd)
1731{
1732 struct ipath_pd *pd = to_ipd(ibpd);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001733 struct ipath_ibdev *dev = to_idev(ibpd->device);
1734
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001735 spin_lock(&dev->n_pds_lock);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001736 dev->n_pds_allocated--;
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001737 spin_unlock(&dev->n_pds_lock);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001738
1739 kfree(pd);
1740
1741 return 0;
1742}
1743
1744/**
1745 * ipath_create_ah - create an address handle
1746 * @pd: the protection domain
1747 * @ah_attr: the attributes of the AH
1748 *
1749 * This may be called from interrupt context.
1750 */
1751static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
1752 struct ib_ah_attr *ah_attr)
1753{
1754 struct ipath_ah *ah;
1755 struct ib_ah *ret;
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001756 struct ipath_ibdev *dev = to_idev(pd->device);
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001757 unsigned long flags;
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001758
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001759 /* A multicast address requires a GRH (see ch. 8.4.1). */
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -07001760 if (ah_attr->dlid >= IPATH_MULTICAST_LID_BASE &&
1761 ah_attr->dlid != IPATH_PERMISSIVE_LID &&
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001762 !(ah_attr->ah_flags & IB_AH_GRH)) {
1763 ret = ERR_PTR(-EINVAL);
1764 goto bail;
1765 }
1766
Bryan O'Sullivan4a45b7d2006-07-01 04:35:55 -07001767 if (ah_attr->dlid == 0) {
1768 ret = ERR_PTR(-EINVAL);
1769 goto bail;
1770 }
1771
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001772 if (ah_attr->port_num < 1 ||
Bryan O'Sullivan4a45b7d2006-07-01 04:35:55 -07001773 ah_attr->port_num > pd->device->phys_port_cnt) {
1774 ret = ERR_PTR(-EINVAL);
1775 goto bail;
1776 }
1777
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001778 ah = kmalloc(sizeof *ah, GFP_ATOMIC);
1779 if (!ah) {
1780 ret = ERR_PTR(-ENOMEM);
1781 goto bail;
1782 }
1783
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001784 spin_lock_irqsave(&dev->n_ahs_lock, flags);
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001785 if (dev->n_ahs_allocated == ib_ipath_max_ahs) {
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001786 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07001787 kfree(ah);
1788 ret = ERR_PTR(-ENOMEM);
1789 goto bail;
1790 }
1791
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001792 dev->n_ahs_allocated++;
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001793 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001794
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001795 /* ib_create_ah() will initialize ah->ibah. */
1796 ah->attr = *ah_attr;
Dave Olson124b4dc2008-04-16 21:09:32 -07001797 ah->attr.static_rate = ipath_ib_rate_to_mult(ah_attr->static_rate);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001798
1799 ret = &ah->ibah;
1800
1801bail:
1802 return ret;
1803}
1804
1805/**
1806 * ipath_destroy_ah - destroy an address handle
1807 * @ibah: the AH to destroy
1808 *
1809 * This may be called from interrupt context.
1810 */
1811static int ipath_destroy_ah(struct ib_ah *ibah)
1812{
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001813 struct ipath_ibdev *dev = to_idev(ibah->device);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001814 struct ipath_ah *ah = to_iah(ibah);
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001815 unsigned long flags;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001816
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001817 spin_lock_irqsave(&dev->n_ahs_lock, flags);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001818 dev->n_ahs_allocated--;
Bryan O'Sullivan3d27b002006-09-28 09:00:24 -07001819 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
Bryan O'Sullivanfe625462006-07-01 04:35:58 -07001820
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001821 kfree(ah);
1822
1823 return 0;
1824}
1825
1826static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
1827{
1828 struct ipath_ah *ah = to_iah(ibah);
1829
1830 *ah_attr = ah->attr;
Dave Olson124b4dc2008-04-16 21:09:32 -07001831 ah_attr->static_rate = ipath_mult_to_ib_rate(ah->attr.static_rate);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001832
1833 return 0;
1834}
1835
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001836/**
1837 * ipath_get_npkeys - return the size of the PKEY table for port 0
1838 * @dd: the infinipath device
1839 */
1840unsigned ipath_get_npkeys(struct ipath_devdata *dd)
1841{
1842 return ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys);
1843}
1844
1845/**
1846 * ipath_get_pkey - return the indexed PKEY from the port 0 PKEY table
1847 * @dd: the infinipath device
1848 * @index: the PKEY index
1849 */
1850unsigned ipath_get_pkey(struct ipath_devdata *dd, unsigned index)
1851{
1852 unsigned ret;
1853
1854 if (index >= ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys))
1855 ret = 0;
1856 else
1857 ret = dd->ipath_pd[0]->port_pkeys[index];
1858
1859 return ret;
1860}
1861
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001862static int ipath_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
1863 u16 *pkey)
1864{
1865 struct ipath_ibdev *dev = to_idev(ibdev);
1866 int ret;
1867
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001868 if (index >= ipath_get_npkeys(dev->dd)) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001869 ret = -EINVAL;
1870 goto bail;
1871 }
1872
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001873 *pkey = ipath_get_pkey(dev->dd, index);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001874 ret = 0;
1875
1876bail:
1877 return ret;
1878}
1879
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001880/**
1881 * ipath_alloc_ucontext - allocate a ucontest
1882 * @ibdev: the infiniband device
1883 * @udata: not used by the InfiniPath driver
1884 */
1885
1886static struct ib_ucontext *ipath_alloc_ucontext(struct ib_device *ibdev,
1887 struct ib_udata *udata)
1888{
1889 struct ipath_ucontext *context;
1890 struct ib_ucontext *ret;
1891
1892 context = kmalloc(sizeof *context, GFP_KERNEL);
1893 if (!context) {
1894 ret = ERR_PTR(-ENOMEM);
1895 goto bail;
1896 }
1897
1898 ret = &context->ibucontext;
1899
1900bail:
1901 return ret;
1902}
1903
1904static int ipath_dealloc_ucontext(struct ib_ucontext *context)
1905{
1906 kfree(to_iucontext(context));
1907 return 0;
1908}
1909
1910static int ipath_verbs_register_sysfs(struct ib_device *dev);
1911
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001912static void __verbs_timer(unsigned long arg)
1913{
1914 struct ipath_devdata *dd = (struct ipath_devdata *) arg;
1915
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001916 /* Handle verbs layer timeouts. */
1917 ipath_ib_timer(dd->verbs_dev);
1918
1919 mod_timer(&dd->verbs_timer, jiffies + 1);
1920}
1921
1922static int enable_timer(struct ipath_devdata *dd)
1923{
1924 /*
1925 * Early chips had a design flaw where the chip and kernel idea
1926 * of the tail register don't always agree, and therefore we won't
1927 * get an interrupt on the next packet received.
1928 * If the board supports per packet receive interrupts, use it.
1929 * Otherwise, the timer function periodically checks for packets
1930 * to cover this case.
1931 * Either way, the timer is needed for verbs layer related
1932 * processing.
1933 */
1934 if (dd->ipath_flags & IPATH_GPIO_INTR) {
1935 ipath_write_kreg(dd, dd->ipath_kregs->kr_debugportselect,
1936 0x2074076542310ULL);
1937 /* Enable GPIO bit 2 interrupt */
Arthur Jones8f140b42007-05-10 12:10:49 -07001938 dd->ipath_gpio_mask |= (u64) (1 << IPATH_GPIO_PORT0_BIT);
1939 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
1940 dd->ipath_gpio_mask);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001941 }
1942
1943 init_timer(&dd->verbs_timer);
1944 dd->verbs_timer.function = __verbs_timer;
1945 dd->verbs_timer.data = (unsigned long)dd;
1946 dd->verbs_timer.expires = jiffies + 1;
1947 add_timer(&dd->verbs_timer);
1948
1949 return 0;
1950}
1951
1952static int disable_timer(struct ipath_devdata *dd)
1953{
1954 /* Disable GPIO bit 2 interrupt */
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001955 if (dd->ipath_flags & IPATH_GPIO_INTR) {
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001956 /* Disable GPIO bit 2 interrupt */
Arthur Jones8f140b42007-05-10 12:10:49 -07001957 dd->ipath_gpio_mask &= ~((u64) (1 << IPATH_GPIO_PORT0_BIT));
1958 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
1959 dd->ipath_gpio_mask);
Bryan O'Sullivan2c9446a2006-09-28 09:00:00 -07001960 /*
1961 * We might want to undo changes to debugportselect,
1962 * but how?
1963 */
1964 }
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001965
1966 del_timer_sync(&dd->verbs_timer);
1967
1968 return 0;
1969}
1970
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001971/**
1972 * ipath_register_ib_device - register our device with the infiniband core
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001973 * @dd: the device data structure
1974 * Return the allocated ipath_ibdev pointer or NULL on error.
1975 */
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07001976int ipath_register_ib_device(struct ipath_devdata *dd)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001977{
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001978 struct ipath_verbs_counters cntrs;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001979 struct ipath_ibdev *idev;
1980 struct ib_device *dev;
Dave Olson124b4dc2008-04-16 21:09:32 -07001981 struct ipath_verbs_txreq *tx;
1982 unsigned i;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001983 int ret;
1984
1985 idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07001986 if (idev == NULL) {
1987 ret = -ENOMEM;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001988 goto bail;
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07001989 }
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001990
1991 dev = &idev->ibdev;
1992
Dave Olson124b4dc2008-04-16 21:09:32 -07001993 if (dd->ipath_sdma_descq_cnt) {
1994 tx = kmalloc(dd->ipath_sdma_descq_cnt * sizeof *tx,
1995 GFP_KERNEL);
1996 if (tx == NULL) {
1997 ret = -ENOMEM;
1998 goto err_tx;
1999 }
2000 } else
2001 tx = NULL;
2002 idev->txreq_bufs = tx;
2003
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002004 /* Only need to initialize non-zero fields. */
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07002005 spin_lock_init(&idev->n_pds_lock);
2006 spin_lock_init(&idev->n_ahs_lock);
2007 spin_lock_init(&idev->n_cqs_lock);
Bryan O'Sullivan0b81e4f2006-08-25 11:24:43 -07002008 spin_lock_init(&idev->n_qps_lock);
Bryan O'Sullivanc27fef22006-08-25 11:24:27 -07002009 spin_lock_init(&idev->n_srqs_lock);
2010 spin_lock_init(&idev->n_mcast_grps_lock);
2011
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002012 spin_lock_init(&idev->qp_table.lock);
2013 spin_lock_init(&idev->lk_table.lock);
2014 idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE);
2015 /* Set the prefix to the default value (see ch. 4.1.1) */
2016 idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL);
2017
2018 ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size);
2019 if (ret)
2020 goto err_qp;
2021
2022 /*
2023 * The top ib_ipath_lkey_table_size bits are used to index the
2024 * table. The lower 8 bits can be owned by the user (copied from
2025 * the LKEY). The remaining bits act as a generation number or tag.
2026 */
2027 idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
2028 idev->lk_table.table = kzalloc(idev->lk_table.max *
2029 sizeof(*idev->lk_table.table),
2030 GFP_KERNEL);
2031 if (idev->lk_table.table == NULL) {
2032 ret = -ENOMEM;
2033 goto err_lk;
2034 }
Robert Walsh6b66b2d2007-04-27 21:07:23 -07002035 INIT_LIST_HEAD(&idev->pending_mmaps);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002036 spin_lock_init(&idev->pending_lock);
Robert Walsh6b66b2d2007-04-27 21:07:23 -07002037 idev->mmap_offset = PAGE_SIZE;
2038 spin_lock_init(&idev->mmap_offset_lock);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002039 INIT_LIST_HEAD(&idev->pending[0]);
2040 INIT_LIST_HEAD(&idev->pending[1]);
2041 INIT_LIST_HEAD(&idev->pending[2]);
2042 INIT_LIST_HEAD(&idev->piowait);
2043 INIT_LIST_HEAD(&idev->rnrwait);
Dave Olson124b4dc2008-04-16 21:09:32 -07002044 INIT_LIST_HEAD(&idev->txreq_free);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002045 idev->pending_index = 0;
2046 idev->port_cap_flags =
2047 IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
Ralph Campbella51a2512008-04-16 21:09:24 -07002048 if (dd->ipath_flags & IPATH_HAS_LINK_LATENCY)
2049 idev->port_cap_flags |= IB_PORT_LINK_LATENCY_SUP;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002050 idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
2051 idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
2052 idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
2053 idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
Roland Dreier53533e12006-11-29 15:33:07 -08002054 idev->pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002055
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07002056 /* Snapshot current HW counters to "clear" them. */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002057 ipath_get_counters(dd, &cntrs);
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07002058 idev->z_symbol_error_counter = cntrs.symbol_error_counter;
2059 idev->z_link_error_recovery_counter =
2060 cntrs.link_error_recovery_counter;
2061 idev->z_link_downed_counter = cntrs.link_downed_counter;
2062 idev->z_port_rcv_errors = cntrs.port_rcv_errors;
2063 idev->z_port_rcv_remphys_errors =
2064 cntrs.port_rcv_remphys_errors;
2065 idev->z_port_xmit_discards = cntrs.port_xmit_discards;
2066 idev->z_port_xmit_data = cntrs.port_xmit_data;
2067 idev->z_port_rcv_data = cntrs.port_rcv_data;
2068 idev->z_port_xmit_packets = cntrs.port_xmit_packets;
2069 idev->z_port_rcv_packets = cntrs.port_rcv_packets;
2070 idev->z_local_link_integrity_errors =
2071 cntrs.local_link_integrity_errors;
2072 idev->z_excessive_buffer_overrun_errors =
2073 cntrs.excessive_buffer_overrun_errors;
Ralph Campbell6c719ca2008-01-06 21:02:33 -08002074 idev->z_vl15_dropped = cntrs.vl15_dropped;
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07002075
Dave Olson124b4dc2008-04-16 21:09:32 -07002076 for (i = 0; i < dd->ipath_sdma_descq_cnt; i++, tx++)
2077 list_add(&tx->txreq.list, &idev->txreq_free);
2078
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002079 /*
2080 * The system image GUID is supposed to be the same for all
2081 * IB HCAs in a single system but since there can be other
2082 * device types in the system, we can't be sure this is unique.
2083 */
2084 if (!sys_image_guid)
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002085 sys_image_guid = dd->ipath_guid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002086 idev->sys_image_guid = sys_image_guid;
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07002087 idev->ib_unit = dd->ipath_unit;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002088 idev->dd = dd;
2089
2090 strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX);
Bryan O'Sullivan41c75a12006-05-23 11:32:36 -07002091 dev->owner = THIS_MODULE;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002092 dev->node_guid = dd->ipath_guid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002093 dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION;
2094 dev->uverbs_cmd_mask =
2095 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
2096 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
2097 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
2098 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
2099 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
2100 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
2101 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
2102 (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
2103 (1ull << IB_USER_VERBS_CMD_REG_MR) |
2104 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
2105 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
2106 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
2107 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
2108 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
2109 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
2110 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
2111 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
2112 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
2113 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
2114 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
2115 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
2116 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
2117 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
2118 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
2119 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
2120 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
2121 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
2122 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
2123 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
Tom Tucker07ebafb2006-08-03 16:02:42 -05002124 dev->node_type = RDMA_NODE_IB_CA;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002125 dev->phys_port_cnt = 1;
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03002126 dev->num_comp_vectors = 1;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002127 dev->dma_device = &dd->pcidev->dev;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002128 dev->query_device = ipath_query_device;
2129 dev->modify_device = ipath_modify_device;
2130 dev->query_port = ipath_query_port;
2131 dev->modify_port = ipath_modify_port;
2132 dev->query_pkey = ipath_query_pkey;
2133 dev->query_gid = ipath_query_gid;
2134 dev->alloc_ucontext = ipath_alloc_ucontext;
2135 dev->dealloc_ucontext = ipath_dealloc_ucontext;
2136 dev->alloc_pd = ipath_alloc_pd;
2137 dev->dealloc_pd = ipath_dealloc_pd;
2138 dev->create_ah = ipath_create_ah;
2139 dev->destroy_ah = ipath_destroy_ah;
2140 dev->query_ah = ipath_query_ah;
2141 dev->create_srq = ipath_create_srq;
2142 dev->modify_srq = ipath_modify_srq;
2143 dev->query_srq = ipath_query_srq;
2144 dev->destroy_srq = ipath_destroy_srq;
2145 dev->create_qp = ipath_create_qp;
2146 dev->modify_qp = ipath_modify_qp;
2147 dev->query_qp = ipath_query_qp;
2148 dev->destroy_qp = ipath_destroy_qp;
2149 dev->post_send = ipath_post_send;
2150 dev->post_recv = ipath_post_receive;
2151 dev->post_srq_recv = ipath_post_srq_receive;
2152 dev->create_cq = ipath_create_cq;
2153 dev->destroy_cq = ipath_destroy_cq;
2154 dev->resize_cq = ipath_resize_cq;
2155 dev->poll_cq = ipath_poll_cq;
2156 dev->req_notify_cq = ipath_req_notify_cq;
2157 dev->get_dma_mr = ipath_get_dma_mr;
2158 dev->reg_phys_mr = ipath_reg_phys_mr;
2159 dev->reg_user_mr = ipath_reg_user_mr;
2160 dev->dereg_mr = ipath_dereg_mr;
2161 dev->alloc_fmr = ipath_alloc_fmr;
2162 dev->map_phys_fmr = ipath_map_phys_fmr;
2163 dev->unmap_fmr = ipath_unmap_fmr;
2164 dev->dealloc_fmr = ipath_dealloc_fmr;
2165 dev->attach_mcast = ipath_multicast_attach;
2166 dev->detach_mcast = ipath_multicast_detach;
2167 dev->process_mad = ipath_process_mad;
Ralph Campbell373d9912006-09-22 15:22:26 -07002168 dev->mmap = ipath_mmap;
Ralph Campbellf2cbb662006-12-12 14:28:28 -08002169 dev->dma_ops = &ipath_dma_mapping_ops;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002170
2171 snprintf(dev->node_desc, sizeof(dev->node_desc),
Serge E. Hallyn96b644b2006-10-02 02:18:13 -07002172 IPATH_IDSTR " %s", init_utsname()->nodename);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002173
2174 ret = ib_register_device(dev);
2175 if (ret)
2176 goto err_reg;
2177
2178 if (ipath_verbs_register_sysfs(dev))
2179 goto err_class;
2180
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002181 enable_timer(dd);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002182
2183 goto bail;
2184
2185err_class:
2186 ib_unregister_device(dev);
2187err_reg:
2188 kfree(idev->lk_table.table);
2189err_lk:
2190 kfree(idev->qp_table.table);
2191err_qp:
Dave Olson124b4dc2008-04-16 21:09:32 -07002192 kfree(idev->txreq_bufs);
2193err_tx:
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002194 ib_dealloc_device(dev);
Bryan O'Sullivanb55f4f02006-08-25 11:24:33 -07002195 ipath_dev_err(dd, "cannot register verbs: %d!\n", -ret);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002196 idev = NULL;
2197
2198bail:
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07002199 dd->verbs_dev = idev;
2200 return ret;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002201}
2202
Bryan O'Sullivanb1c1b6a2006-08-25 11:24:31 -07002203void ipath_unregister_ib_device(struct ipath_ibdev *dev)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002204{
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002205 struct ib_device *ibdev = &dev->ibdev;
Ralph Campbelle509be82008-05-13 11:41:29 -07002206 u32 qps_inuse;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002207
2208 ib_unregister_device(ibdev);
2209
Ralph Campbelle509be82008-05-13 11:41:29 -07002210 disable_timer(dev->dd);
2211
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002212 if (!list_empty(&dev->pending[0]) ||
2213 !list_empty(&dev->pending[1]) ||
2214 !list_empty(&dev->pending[2]))
Bryan O'Sullivanb55f4f02006-08-25 11:24:33 -07002215 ipath_dev_err(dev->dd, "pending list not empty!\n");
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002216 if (!list_empty(&dev->piowait))
Bryan O'Sullivanb55f4f02006-08-25 11:24:33 -07002217 ipath_dev_err(dev->dd, "piowait list not empty!\n");
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002218 if (!list_empty(&dev->rnrwait))
Bryan O'Sullivanb55f4f02006-08-25 11:24:33 -07002219 ipath_dev_err(dev->dd, "rnrwait list not empty!\n");
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002220 if (!ipath_mcast_tree_empty())
Bryan O'Sullivanb55f4f02006-08-25 11:24:33 -07002221 ipath_dev_err(dev->dd, "multicast table memory leak!\n");
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002222 /*
2223 * Note that ipath_unregister_ib_device() can be called before all
2224 * the QPs are destroyed!
2225 */
Ralph Campbelle509be82008-05-13 11:41:29 -07002226 qps_inuse = ipath_free_all_qps(&dev->qp_table);
2227 if (qps_inuse)
2228 ipath_dev_err(dev->dd, "QP memory leak! %u still in use\n",
2229 qps_inuse);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002230 kfree(dev->qp_table.table);
2231 kfree(dev->lk_table.table);
Dave Olson124b4dc2008-04-16 21:09:32 -07002232 kfree(dev->txreq_bufs);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002233 ib_dealloc_device(ibdev);
2234}
2235
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002236static ssize_t show_rev(struct device *device, struct device_attribute *attr,
2237 char *buf)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002238{
Roland Dreier5494c222006-04-19 11:40:12 -07002239 struct ipath_ibdev *dev =
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002240 container_of(device, struct ipath_ibdev, ibdev.dev);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002241
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002242 return sprintf(buf, "%x\n", dev->dd->ipath_pcirev);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002243}
2244
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002245static ssize_t show_hca(struct device *device, struct device_attribute *attr,
2246 char *buf)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002247{
Roland Dreier5494c222006-04-19 11:40:12 -07002248 struct ipath_ibdev *dev =
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002249 container_of(device, struct ipath_ibdev, ibdev.dev);
Roland Dreier5494c222006-04-19 11:40:12 -07002250 int ret;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002251
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07002252 ret = dev->dd->ipath_f_get_boardname(dev->dd, buf, 128);
Roland Dreier5494c222006-04-19 11:40:12 -07002253 if (ret < 0)
2254 goto bail;
2255 strcat(buf, "\n");
2256 ret = strlen(buf);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002257
2258bail:
2259 return ret;
2260}
2261
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002262static ssize_t show_stats(struct device *device, struct device_attribute *attr,
2263 char *buf)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002264{
Roland Dreier5494c222006-04-19 11:40:12 -07002265 struct ipath_ibdev *dev =
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002266 container_of(device, struct ipath_ibdev, ibdev.dev);
Roland Dreier5494c222006-04-19 11:40:12 -07002267 int i;
2268 int len;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002269
Roland Dreier5494c222006-04-19 11:40:12 -07002270 len = sprintf(buf,
2271 "RC resends %d\n"
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -07002272 "RC no QACK %d\n"
Roland Dreier5494c222006-04-19 11:40:12 -07002273 "RC ACKs %d\n"
2274 "RC SEQ NAKs %d\n"
2275 "RC RDMA seq %d\n"
2276 "RC RNR NAKs %d\n"
2277 "RC OTH NAKs %d\n"
2278 "RC timeouts %d\n"
2279 "RC RDMA dup %d\n"
2280 "piobuf wait %d\n"
Dave Olson124b4dc2008-04-16 21:09:32 -07002281 "unaligned %d\n"
Roland Dreier5494c222006-04-19 11:40:12 -07002282 "PKT drops %d\n"
2283 "WQE errs %d\n",
2284 dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
2285 dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
2286 dev->n_other_naks, dev->n_timeouts,
Ralph Campbelle509be82008-05-13 11:41:29 -07002287 dev->n_rdma_dup_busy, dev->n_piowait, dev->n_unaligned,
Dave Olson124b4dc2008-04-16 21:09:32 -07002288 dev->n_pkt_drops, dev->n_wqe_errs);
Roland Dreier5494c222006-04-19 11:40:12 -07002289 for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002290 const struct ipath_opcode_stats *si = &dev->opstats[i];
2291
Roland Dreier5494c222006-04-19 11:40:12 -07002292 if (!si->n_packets && !si->n_bytes)
2293 continue;
2294 len += sprintf(buf + len, "%02x %llu/%llu\n", i,
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002295 (unsigned long long) si->n_packets,
Roland Dreier5494c222006-04-19 11:40:12 -07002296 (unsigned long long) si->n_bytes);
2297 }
2298 return len;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002299}
2300
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002301static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
2302static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
2303static DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
2304static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002305
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002306static struct device_attribute *ipath_class_attributes[] = {
2307 &dev_attr_hw_rev,
2308 &dev_attr_hca_type,
2309 &dev_attr_board_id,
2310 &dev_attr_stats
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002311};
2312
2313static int ipath_verbs_register_sysfs(struct ib_device *dev)
2314{
Roland Dreier5494c222006-04-19 11:40:12 -07002315 int i;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002316 int ret;
2317
Roland Dreier5494c222006-04-19 11:40:12 -07002318 for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i)
Tony Jonesf4e91eb2008-02-22 00:13:36 +01002319 if (device_create_file(&dev->dev,
2320 ipath_class_attributes[i])) {
Roland Dreier5494c222006-04-19 11:40:12 -07002321 ret = 1;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002322 goto bail;
2323 }
2324
Roland Dreier5494c222006-04-19 11:40:12 -07002325 ret = 0;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08002326
2327bail:
2328 return ret;
2329}