blob: e04c7619f9fecf6adc21699c9c816e8419904056 [file] [log] [blame]
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001/*
Bryan O'Sullivan759d5762006-07-01 04:35:49 -07002 * Copyright (c) 2006 QLogic, Inc. 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>
36#include <linux/utsname.h>
37
38#include "ipath_kernel.h"
39#include "ipath_verbs.h"
40#include "ips_common.h"
41
42/* Not static, because we don't want the compiler removing it */
43const char ipath_verbs_version[] = "ipath_verbs " IPATH_IDSTR;
44
Roland Dreierac2ae4c2006-04-19 11:40:12 -070045static unsigned int ib_ipath_qp_table_size = 251;
Bryan O'Sullivan65221082006-03-29 15:23:38 -080046module_param_named(qp_table_size, ib_ipath_qp_table_size, uint, S_IRUGO);
47MODULE_PARM_DESC(qp_table_size, "QP table size");
48
49unsigned int ib_ipath_lkey_table_size = 12;
50module_param_named(lkey_table_size, ib_ipath_lkey_table_size, uint,
51 S_IRUGO);
52MODULE_PARM_DESC(lkey_table_size,
53 "LKEY table size in bits (2^n, 1 <= n <= 23)");
54
55unsigned int ib_ipath_debug; /* debug mask */
56module_param_named(debug, ib_ipath_debug, uint, S_IWUSR | S_IRUGO);
57MODULE_PARM_DESC(debug, "Verbs debug mask");
58
59MODULE_LICENSE("GPL");
Bryan O'Sullivan759d5762006-07-01 04:35:49 -070060MODULE_AUTHOR("QLogic <support@pathscale.com>");
61MODULE_DESCRIPTION("QLogic InfiniPath driver");
Bryan O'Sullivan65221082006-03-29 15:23:38 -080062
63const int ib_ipath_state_ops[IB_QPS_ERR + 1] = {
64 [IB_QPS_RESET] = 0,
65 [IB_QPS_INIT] = IPATH_POST_RECV_OK,
66 [IB_QPS_RTR] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
67 [IB_QPS_RTS] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
68 IPATH_POST_SEND_OK | IPATH_PROCESS_SEND_OK,
69 [IB_QPS_SQD] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
70 IPATH_POST_SEND_OK,
71 [IB_QPS_SQE] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
72 [IB_QPS_ERR] = 0,
73};
74
75/*
76 * Translate ib_wr_opcode into ib_wc_opcode.
77 */
78const enum ib_wc_opcode ib_ipath_wc_opcode[] = {
79 [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
80 [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
81 [IB_WR_SEND] = IB_WC_SEND,
82 [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
83 [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
84 [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
85 [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD
86};
87
88/*
89 * System image GUID.
90 */
Roland Dreierac2ae4c2006-04-19 11:40:12 -070091static __be64 sys_image_guid;
Bryan O'Sullivan65221082006-03-29 15:23:38 -080092
93/**
94 * ipath_copy_sge - copy data to SGE memory
95 * @ss: the SGE state
96 * @data: the data to copy
97 * @length: the length of the data
98 */
99void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length)
100{
101 struct ipath_sge *sge = &ss->sge;
102
103 while (length) {
104 u32 len = sge->length;
105
106 BUG_ON(len == 0);
107 if (len > length)
108 len = length;
109 memcpy(sge->vaddr, data, len);
110 sge->vaddr += len;
111 sge->length -= len;
112 sge->sge_length -= len;
113 if (sge->sge_length == 0) {
114 if (--ss->num_sge)
115 *sge = *ss->sg_list++;
116 } else if (sge->length == 0 && sge->mr != NULL) {
117 if (++sge->n >= IPATH_SEGSZ) {
118 if (++sge->m >= sge->mr->mapsz)
119 break;
120 sge->n = 0;
121 }
122 sge->vaddr =
123 sge->mr->map[sge->m]->segs[sge->n].vaddr;
124 sge->length =
125 sge->mr->map[sge->m]->segs[sge->n].length;
126 }
127 data += len;
128 length -= len;
129 }
130}
131
132/**
133 * ipath_skip_sge - skip over SGE memory - XXX almost dup of prev func
134 * @ss: the SGE state
135 * @length: the number of bytes to skip
136 */
137void ipath_skip_sge(struct ipath_sge_state *ss, u32 length)
138{
139 struct ipath_sge *sge = &ss->sge;
140
141 while (length > sge->sge_length) {
142 length -= sge->sge_length;
143 ss->sge = *ss->sg_list++;
144 }
145 while (length) {
146 u32 len = sge->length;
147
148 BUG_ON(len == 0);
149 if (len > length)
150 len = length;
151 sge->vaddr += len;
152 sge->length -= len;
153 sge->sge_length -= len;
154 if (sge->sge_length == 0) {
155 if (--ss->num_sge)
156 *sge = *ss->sg_list++;
157 } else if (sge->length == 0 && sge->mr != NULL) {
158 if (++sge->n >= IPATH_SEGSZ) {
159 if (++sge->m >= sge->mr->mapsz)
160 break;
161 sge->n = 0;
162 }
163 sge->vaddr =
164 sge->mr->map[sge->m]->segs[sge->n].vaddr;
165 sge->length =
166 sge->mr->map[sge->m]->segs[sge->n].length;
167 }
168 length -= len;
169 }
170}
171
172/**
173 * ipath_post_send - post a send on a QP
174 * @ibqp: the QP to post the send on
175 * @wr: the list of work requests to post
176 * @bad_wr: the first bad WR is put here
177 *
178 * This may be called from interrupt context.
179 */
180static int ipath_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
181 struct ib_send_wr **bad_wr)
182{
183 struct ipath_qp *qp = to_iqp(ibqp);
184 int err = 0;
185
186 /* Check that state is OK to post send. */
187 if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_SEND_OK)) {
188 *bad_wr = wr;
189 err = -EINVAL;
190 goto bail;
191 }
192
193 for (; wr; wr = wr->next) {
194 switch (qp->ibqp.qp_type) {
195 case IB_QPT_UC:
196 case IB_QPT_RC:
Bryan O'Sullivanddd4bb22006-07-01 04:35:50 -0700197 err = ipath_post_ruc_send(qp, wr);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800198 break;
199
200 case IB_QPT_SMI:
201 case IB_QPT_GSI:
202 case IB_QPT_UD:
203 err = ipath_post_ud_send(qp, wr);
204 break;
205
206 default:
207 err = -EINVAL;
208 }
209 if (err) {
210 *bad_wr = wr;
211 break;
212 }
213 }
214
215bail:
216 return err;
217}
218
219/**
220 * ipath_post_receive - post a receive on a QP
221 * @ibqp: the QP to post the receive on
222 * @wr: the WR to post
223 * @bad_wr: the first bad WR is put here
224 *
225 * This may be called from interrupt context.
226 */
227static int ipath_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
228 struct ib_recv_wr **bad_wr)
229{
230 struct ipath_qp *qp = to_iqp(ibqp);
231 unsigned long flags;
232 int ret;
233
234 /* Check that state is OK to post receive. */
235 if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_RECV_OK)) {
236 *bad_wr = wr;
237 ret = -EINVAL;
238 goto bail;
239 }
240
241 for (; wr; wr = wr->next) {
242 struct ipath_rwqe *wqe;
243 u32 next;
244 int i, j;
245
246 if (wr->num_sge > qp->r_rq.max_sge) {
247 *bad_wr = wr;
248 ret = -ENOMEM;
249 goto bail;
250 }
251
252 spin_lock_irqsave(&qp->r_rq.lock, flags);
253 next = qp->r_rq.head + 1;
254 if (next >= qp->r_rq.size)
255 next = 0;
256 if (next == qp->r_rq.tail) {
257 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
258 *bad_wr = wr;
259 ret = -ENOMEM;
260 goto bail;
261 }
262
263 wqe = get_rwqe_ptr(&qp->r_rq, qp->r_rq.head);
264 wqe->wr_id = wr->wr_id;
265 wqe->sg_list[0].mr = NULL;
266 wqe->sg_list[0].vaddr = NULL;
267 wqe->sg_list[0].length = 0;
268 wqe->sg_list[0].sge_length = 0;
269 wqe->length = 0;
270 for (i = 0, j = 0; i < wr->num_sge; i++) {
271 /* Check LKEY */
272 if (to_ipd(qp->ibqp.pd)->user &&
273 wr->sg_list[i].lkey == 0) {
274 spin_unlock_irqrestore(&qp->r_rq.lock,
275 flags);
276 *bad_wr = wr;
277 ret = -EINVAL;
278 goto bail;
279 }
280 if (wr->sg_list[i].length == 0)
281 continue;
282 if (!ipath_lkey_ok(
283 &to_idev(qp->ibqp.device)->lk_table,
284 &wqe->sg_list[j], &wr->sg_list[i],
285 IB_ACCESS_LOCAL_WRITE)) {
286 spin_unlock_irqrestore(&qp->r_rq.lock,
287 flags);
288 *bad_wr = wr;
289 ret = -EINVAL;
290 goto bail;
291 }
292 wqe->length += wr->sg_list[i].length;
293 j++;
294 }
295 wqe->num_sge = j;
296 qp->r_rq.head = next;
297 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
298 }
299 ret = 0;
300
301bail:
302 return ret;
303}
304
305/**
306 * ipath_qp_rcv - processing an incoming packet on a QP
307 * @dev: the device the packet came on
308 * @hdr: the packet header
309 * @has_grh: true if the packet has a GRH
310 * @data: the packet data
311 * @tlen: the packet length
312 * @qp: the QP the packet came on
313 *
314 * This is called from ipath_ib_rcv() to process an incoming packet
315 * for the given QP.
316 * Called at interrupt level.
317 */
318static void ipath_qp_rcv(struct ipath_ibdev *dev,
319 struct ipath_ib_header *hdr, int has_grh,
320 void *data, u32 tlen, struct ipath_qp *qp)
321{
322 /* Check for valid receive state. */
323 if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) {
324 dev->n_pkt_drops++;
325 return;
326 }
327
328 switch (qp->ibqp.qp_type) {
329 case IB_QPT_SMI:
330 case IB_QPT_GSI:
331 case IB_QPT_UD:
332 ipath_ud_rcv(dev, hdr, has_grh, data, tlen, qp);
333 break;
334
335 case IB_QPT_RC:
336 ipath_rc_rcv(dev, hdr, has_grh, data, tlen, qp);
337 break;
338
339 case IB_QPT_UC:
340 ipath_uc_rcv(dev, hdr, has_grh, data, tlen, qp);
341 break;
342
343 default:
344 break;
345 }
346}
347
348/**
349 * ipath_ib_rcv - process and incoming packet
350 * @arg: the device pointer
351 * @rhdr: the header of the packet
352 * @data: the packet data
353 * @tlen: the packet length
354 *
355 * This is called from ipath_kreceive() to process an incoming packet at
356 * interrupt level. Tlen is the length of the header + data + CRC in bytes.
357 */
358static void ipath_ib_rcv(void *arg, void *rhdr, void *data, u32 tlen)
359{
360 struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
361 struct ipath_ib_header *hdr = rhdr;
362 struct ipath_other_headers *ohdr;
363 struct ipath_qp *qp;
364 u32 qp_num;
365 int lnh;
366 u8 opcode;
367 u16 lid;
368
369 if (unlikely(dev == NULL))
370 goto bail;
371
372 if (unlikely(tlen < 24)) { /* LRH+BTH+CRC */
373 dev->rcv_errors++;
374 goto bail;
375 }
376
377 /* Check for a valid destination LID (see ch. 7.11.1). */
378 lid = be16_to_cpu(hdr->lrh[1]);
379 if (lid < IPS_MULTICAST_LID_BASE) {
380 lid &= ~((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
381 if (unlikely(lid != ipath_layer_get_lid(dev->dd))) {
382 dev->rcv_errors++;
383 goto bail;
384 }
385 }
386
387 /* Check for GRH */
388 lnh = be16_to_cpu(hdr->lrh[0]) & 3;
389 if (lnh == IPS_LRH_BTH)
390 ohdr = &hdr->u.oth;
391 else if (lnh == IPS_LRH_GRH)
392 ohdr = &hdr->u.l.oth;
393 else {
394 dev->rcv_errors++;
395 goto bail;
396 }
397
398 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
399 dev->opstats[opcode].n_bytes += tlen;
400 dev->opstats[opcode].n_packets++;
401
402 /* Get the destination QP number. */
403 qp_num = be32_to_cpu(ohdr->bth[1]) & IPS_QPN_MASK;
404 if (qp_num == IPS_MULTICAST_QPN) {
405 struct ipath_mcast *mcast;
406 struct ipath_mcast_qp *p;
407
408 mcast = ipath_mcast_find(&hdr->u.l.grh.dgid);
409 if (mcast == NULL) {
410 dev->n_pkt_drops++;
411 goto bail;
412 }
413 dev->n_multicast_rcv++;
414 list_for_each_entry_rcu(p, &mcast->qp_list, list)
415 ipath_qp_rcv(dev, hdr, lnh == IPS_LRH_GRH, data,
416 tlen, p->qp);
417 /*
418 * Notify ipath_multicast_detach() if it is waiting for us
419 * to finish.
420 */
421 if (atomic_dec_return(&mcast->refcount) <= 1)
422 wake_up(&mcast->wait);
423 } else {
424 qp = ipath_lookup_qpn(&dev->qp_table, qp_num);
425 if (qp) {
426 dev->n_unicast_rcv++;
427 ipath_qp_rcv(dev, hdr, lnh == IPS_LRH_GRH, data,
428 tlen, qp);
429 /*
430 * Notify ipath_destroy_qp() if it is waiting
431 * for us to finish.
432 */
433 if (atomic_dec_and_test(&qp->refcount))
434 wake_up(&qp->wait);
435 } else
436 dev->n_pkt_drops++;
437 }
438
439bail:;
440}
441
442/**
443 * ipath_ib_timer - verbs timer
444 * @arg: the device pointer
445 *
446 * This is called from ipath_do_rcv_timer() at interrupt level to check for
447 * QPs which need retransmits and to collect performance numbers.
448 */
449static void ipath_ib_timer(void *arg)
450{
451 struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
452 struct ipath_qp *resend = NULL;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800453 struct list_head *last;
454 struct ipath_qp *qp;
455 unsigned long flags;
456
457 if (dev == NULL)
458 return;
459
460 spin_lock_irqsave(&dev->pending_lock, flags);
461 /* Start filling the next pending queue. */
462 if (++dev->pending_index >= ARRAY_SIZE(dev->pending))
463 dev->pending_index = 0;
464 /* Save any requests still in the new queue, they have timed out. */
465 last = &dev->pending[dev->pending_index];
466 while (!list_empty(last)) {
467 qp = list_entry(last->next, struct ipath_qp, timerwait);
Bryan O'Sullivan94b8d9f2006-05-23 11:32:32 -0700468 list_del_init(&qp->timerwait);
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -0700469 qp->timer_next = resend;
470 resend = qp;
471 atomic_inc(&qp->refcount);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800472 }
473 last = &dev->rnrwait;
474 if (!list_empty(last)) {
475 qp = list_entry(last->next, struct ipath_qp, timerwait);
476 if (--qp->s_rnr_timeout == 0) {
477 do {
Bryan O'Sullivan94b8d9f2006-05-23 11:32:32 -0700478 list_del_init(&qp->timerwait);
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -0700479 tasklet_hi_schedule(&qp->s_task);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800480 if (list_empty(last))
481 break;
482 qp = list_entry(last->next, struct ipath_qp,
483 timerwait);
484 } while (qp->s_rnr_timeout == 0);
485 }
486 }
487 /*
488 * We should only be in the started state if pma_sample_start != 0
489 */
490 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED &&
491 --dev->pma_sample_start == 0) {
492 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
493 ipath_layer_snapshot_counters(dev->dd, &dev->ipath_sword,
494 &dev->ipath_rword,
495 &dev->ipath_spkts,
496 &dev->ipath_rpkts,
497 &dev->ipath_xmit_wait);
498 }
499 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
500 if (dev->pma_sample_interval == 0) {
501 u64 ta, tb, tc, td, te;
502
503 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
504 ipath_layer_snapshot_counters(dev->dd, &ta, &tb,
505 &tc, &td, &te);
506
507 dev->ipath_sword = ta - dev->ipath_sword;
508 dev->ipath_rword = tb - dev->ipath_rword;
509 dev->ipath_spkts = tc - dev->ipath_spkts;
510 dev->ipath_rpkts = td - dev->ipath_rpkts;
511 dev->ipath_xmit_wait = te - dev->ipath_xmit_wait;
512 }
513 else
514 dev->pma_sample_interval--;
515 }
516 spin_unlock_irqrestore(&dev->pending_lock, flags);
517
518 /* XXX What if timer fires again while this is running? */
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -0700519 for (qp = resend; qp != NULL; qp = qp->timer_next) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800520 struct ib_wc wc;
521
522 spin_lock_irqsave(&qp->s_lock, flags);
523 if (qp->s_last != qp->s_tail && qp->state == IB_QPS_RTS) {
524 dev->n_timeouts++;
525 ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
526 }
527 spin_unlock_irqrestore(&qp->s_lock, flags);
528
529 /* Notify ipath_destroy_qp() if it is waiting. */
530 if (atomic_dec_and_test(&qp->refcount))
531 wake_up(&qp->wait);
532 }
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800533}
534
535/**
536 * ipath_ib_piobufavail - callback when a PIO buffer is available
537 * @arg: the device pointer
538 *
539 * This is called from ipath_intr() at interrupt level when a PIO buffer is
540 * available after ipath_verbs_send() returned an error that no buffers were
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -0700541 * available. Return 1 if we consumed all the PIO buffers and we still have
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800542 * QPs waiting for buffers (for now, just do a tasklet_hi_schedule and
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -0700543 * return zero).
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800544 */
545static int ipath_ib_piobufavail(void *arg)
546{
547 struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
548 struct ipath_qp *qp;
549 unsigned long flags;
550
551 if (dev == NULL)
552 goto bail;
553
554 spin_lock_irqsave(&dev->pending_lock, flags);
555 while (!list_empty(&dev->piowait)) {
556 qp = list_entry(dev->piowait.next, struct ipath_qp,
557 piowait);
Bryan O'Sullivan94b8d9f2006-05-23 11:32:32 -0700558 list_del_init(&qp->piowait);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800559 tasklet_hi_schedule(&qp->s_task);
560 }
561 spin_unlock_irqrestore(&dev->pending_lock, flags);
562
563bail:
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -0700564 return 0;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800565}
566
567static int ipath_query_device(struct ib_device *ibdev,
568 struct ib_device_attr *props)
569{
570 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800571
572 memset(props, 0, sizeof(*props));
573
574 props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
575 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
576 IB_DEVICE_SYS_IMAGE_GUID;
Bryan O'Sullivane8a88f02006-07-01 04:35:57 -0700577 props->vendor_id = ipath_layer_get_vendorid(dev->dd);
578 props->vendor_part_id = ipath_layer_get_deviceid(dev->dd);
579 props->hw_ver = ipath_layer_get_pcirev(dev->dd);
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800580
581 props->sys_image_guid = dev->sys_image_guid;
582
583 props->max_mr_size = ~0ull;
584 props->max_qp = 0xffff;
585 props->max_qp_wr = 0xffff;
586 props->max_sge = 255;
587 props->max_cq = 0xffff;
588 props->max_cqe = 0xffff;
589 props->max_mr = 0xffff;
590 props->max_pd = 0xffff;
591 props->max_qp_rd_atom = 1;
592 props->max_qp_init_rd_atom = 1;
593 /* props->max_res_rd_atom */
594 props->max_srq = 0xffff;
595 props->max_srq_wr = 0xffff;
596 props->max_srq_sge = 255;
597 /* props->local_ca_ack_delay */
598 props->atomic_cap = IB_ATOMIC_HCA;
599 props->max_pkeys = ipath_layer_get_npkeys(dev->dd);
600 props->max_mcast_grp = 0xffff;
601 props->max_mcast_qp_attach = 0xffff;
602 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
603 props->max_mcast_grp;
604
605 return 0;
606}
607
608const u8 ipath_cvt_physportstate[16] = {
609 [INFINIPATH_IBCS_LT_STATE_DISABLED] = 3,
610 [INFINIPATH_IBCS_LT_STATE_LINKUP] = 5,
611 [INFINIPATH_IBCS_LT_STATE_POLLACTIVE] = 2,
612 [INFINIPATH_IBCS_LT_STATE_POLLQUIET] = 2,
613 [INFINIPATH_IBCS_LT_STATE_SLEEPDELAY] = 1,
614 [INFINIPATH_IBCS_LT_STATE_SLEEPQUIET] = 1,
615 [INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE] = 4,
616 [INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG] = 4,
617 [INFINIPATH_IBCS_LT_STATE_CFGWAITRMT] = 4,
618 [INFINIPATH_IBCS_LT_STATE_CFGIDLE] = 4,
619 [INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN] = 6,
620 [INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT] = 6,
621 [INFINIPATH_IBCS_LT_STATE_RECOVERIDLE] = 6,
622};
623
624static int ipath_query_port(struct ib_device *ibdev,
625 u8 port, struct ib_port_attr *props)
626{
627 struct ipath_ibdev *dev = to_idev(ibdev);
628 enum ib_mtu mtu;
629 u16 lid = ipath_layer_get_lid(dev->dd);
630 u64 ibcstat;
631
632 memset(props, 0, sizeof(*props));
633 props->lid = lid ? lid : __constant_be16_to_cpu(IB_LID_PERMISSIVE);
634 props->lmc = dev->mkeyprot_resv_lmc & 7;
635 props->sm_lid = dev->sm_lid;
636 props->sm_sl = dev->sm_sl;
637 ibcstat = ipath_layer_get_lastibcstat(dev->dd);
638 props->state = ((ibcstat >> 4) & 0x3) + 1;
639 /* See phys_state_show() */
640 props->phys_state = ipath_cvt_physportstate[
641 ipath_layer_get_lastibcstat(dev->dd) & 0xf];
642 props->port_cap_flags = dev->port_cap_flags;
643 props->gid_tbl_len = 1;
644 props->max_msg_sz = 4096;
645 props->pkey_tbl_len = ipath_layer_get_npkeys(dev->dd);
646 props->bad_pkey_cntr = ipath_layer_get_cr_errpkey(dev->dd) -
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -0700647 dev->z_pkey_violations;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800648 props->qkey_viol_cntr = dev->qkey_violations;
649 props->active_width = IB_WIDTH_4X;
650 /* See rate_show() */
651 props->active_speed = 1; /* Regular 10Mbs speed. */
652 props->max_vl_num = 1; /* VLCap = VL0 */
653 props->init_type_reply = 0;
654
655 props->max_mtu = IB_MTU_4096;
656 switch (ipath_layer_get_ibmtu(dev->dd)) {
657 case 4096:
658 mtu = IB_MTU_4096;
659 break;
660 case 2048:
661 mtu = IB_MTU_2048;
662 break;
663 case 1024:
664 mtu = IB_MTU_1024;
665 break;
666 case 512:
667 mtu = IB_MTU_512;
668 break;
669 case 256:
670 mtu = IB_MTU_256;
671 break;
672 default:
673 mtu = IB_MTU_2048;
674 }
675 props->active_mtu = mtu;
676 props->subnet_timeout = dev->subnet_timeout;
677
678 return 0;
679}
680
681static int ipath_modify_device(struct ib_device *device,
682 int device_modify_mask,
683 struct ib_device_modify *device_modify)
684{
685 int ret;
686
687 if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
688 IB_DEVICE_MODIFY_NODE_DESC)) {
689 ret = -EOPNOTSUPP;
690 goto bail;
691 }
692
693 if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC)
694 memcpy(device->node_desc, device_modify->node_desc, 64);
695
696 if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
697 to_idev(device)->sys_image_guid =
698 cpu_to_be64(device_modify->sys_image_guid);
699
700 ret = 0;
701
702bail:
703 return ret;
704}
705
706static int ipath_modify_port(struct ib_device *ibdev,
707 u8 port, int port_modify_mask,
708 struct ib_port_modify *props)
709{
710 struct ipath_ibdev *dev = to_idev(ibdev);
711
712 dev->port_cap_flags |= props->set_port_cap_mask;
713 dev->port_cap_flags &= ~props->clr_port_cap_mask;
714 if (port_modify_mask & IB_PORT_SHUTDOWN)
715 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
716 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
717 dev->qkey_violations = 0;
718 return 0;
719}
720
721static int ipath_query_gid(struct ib_device *ibdev, u8 port,
722 int index, union ib_gid *gid)
723{
724 struct ipath_ibdev *dev = to_idev(ibdev);
725 int ret;
726
727 if (index >= 1) {
728 ret = -EINVAL;
729 goto bail;
730 }
731 gid->global.subnet_prefix = dev->gid_prefix;
732 gid->global.interface_id = ipath_layer_get_guid(dev->dd);
733
734 ret = 0;
735
736bail:
737 return ret;
738}
739
740static struct ib_pd *ipath_alloc_pd(struct ib_device *ibdev,
741 struct ib_ucontext *context,
742 struct ib_udata *udata)
743{
744 struct ipath_pd *pd;
745 struct ib_pd *ret;
746
747 pd = kmalloc(sizeof *pd, GFP_KERNEL);
748 if (!pd) {
749 ret = ERR_PTR(-ENOMEM);
750 goto bail;
751 }
752
753 /* ib_alloc_pd() will initialize pd->ibpd. */
754 pd->user = udata != NULL;
755
756 ret = &pd->ibpd;
757
758bail:
759 return ret;
760}
761
762static int ipath_dealloc_pd(struct ib_pd *ibpd)
763{
764 struct ipath_pd *pd = to_ipd(ibpd);
765
766 kfree(pd);
767
768 return 0;
769}
770
771/**
772 * ipath_create_ah - create an address handle
773 * @pd: the protection domain
774 * @ah_attr: the attributes of the AH
775 *
776 * This may be called from interrupt context.
777 */
778static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
779 struct ib_ah_attr *ah_attr)
780{
781 struct ipath_ah *ah;
782 struct ib_ah *ret;
783
784 /* A multicast address requires a GRH (see ch. 8.4.1). */
785 if (ah_attr->dlid >= IPS_MULTICAST_LID_BASE &&
786 ah_attr->dlid != IPS_PERMISSIVE_LID &&
787 !(ah_attr->ah_flags & IB_AH_GRH)) {
788 ret = ERR_PTR(-EINVAL);
789 goto bail;
790 }
791
Bryan O'Sullivan4a45b7d2006-07-01 04:35:55 -0700792 if (ah_attr->dlid == 0) {
793 ret = ERR_PTR(-EINVAL);
794 goto bail;
795 }
796
797 if (ah_attr->port_num != 1 ||
798 ah_attr->port_num > pd->device->phys_port_cnt) {
799 ret = ERR_PTR(-EINVAL);
800 goto bail;
801 }
802
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800803 ah = kmalloc(sizeof *ah, GFP_ATOMIC);
804 if (!ah) {
805 ret = ERR_PTR(-ENOMEM);
806 goto bail;
807 }
808
809 /* ib_create_ah() will initialize ah->ibah. */
810 ah->attr = *ah_attr;
811
812 ret = &ah->ibah;
813
814bail:
815 return ret;
816}
817
818/**
819 * ipath_destroy_ah - destroy an address handle
820 * @ibah: the AH to destroy
821 *
822 * This may be called from interrupt context.
823 */
824static int ipath_destroy_ah(struct ib_ah *ibah)
825{
826 struct ipath_ah *ah = to_iah(ibah);
827
828 kfree(ah);
829
830 return 0;
831}
832
833static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
834{
835 struct ipath_ah *ah = to_iah(ibah);
836
837 *ah_attr = ah->attr;
838
839 return 0;
840}
841
842static int ipath_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
843 u16 *pkey)
844{
845 struct ipath_ibdev *dev = to_idev(ibdev);
846 int ret;
847
848 if (index >= ipath_layer_get_npkeys(dev->dd)) {
849 ret = -EINVAL;
850 goto bail;
851 }
852
853 *pkey = ipath_layer_get_pkey(dev->dd, index);
854 ret = 0;
855
856bail:
857 return ret;
858}
859
860
861/**
862 * ipath_alloc_ucontext - allocate a ucontest
863 * @ibdev: the infiniband device
864 * @udata: not used by the InfiniPath driver
865 */
866
867static struct ib_ucontext *ipath_alloc_ucontext(struct ib_device *ibdev,
868 struct ib_udata *udata)
869{
870 struct ipath_ucontext *context;
871 struct ib_ucontext *ret;
872
873 context = kmalloc(sizeof *context, GFP_KERNEL);
874 if (!context) {
875 ret = ERR_PTR(-ENOMEM);
876 goto bail;
877 }
878
879 ret = &context->ibucontext;
880
881bail:
882 return ret;
883}
884
885static int ipath_dealloc_ucontext(struct ib_ucontext *context)
886{
887 kfree(to_iucontext(context));
888 return 0;
889}
890
891static int ipath_verbs_register_sysfs(struct ib_device *dev);
892
893/**
894 * ipath_register_ib_device - register our device with the infiniband core
895 * @unit: the device number to register
896 * @dd: the device data structure
897 * Return the allocated ipath_ibdev pointer or NULL on error.
898 */
899static void *ipath_register_ib_device(int unit, struct ipath_devdata *dd)
900{
901 struct ipath_ibdev *idev;
902 struct ib_device *dev;
903 int ret;
904
905 idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
906 if (idev == NULL)
907 goto bail;
908
909 dev = &idev->ibdev;
910
911 /* Only need to initialize non-zero fields. */
912 spin_lock_init(&idev->qp_table.lock);
913 spin_lock_init(&idev->lk_table.lock);
914 idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE);
915 /* Set the prefix to the default value (see ch. 4.1.1) */
916 idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL);
917
918 ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size);
919 if (ret)
920 goto err_qp;
921
922 /*
923 * The top ib_ipath_lkey_table_size bits are used to index the
924 * table. The lower 8 bits can be owned by the user (copied from
925 * the LKEY). The remaining bits act as a generation number or tag.
926 */
927 idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
928 idev->lk_table.table = kzalloc(idev->lk_table.max *
929 sizeof(*idev->lk_table.table),
930 GFP_KERNEL);
931 if (idev->lk_table.table == NULL) {
932 ret = -ENOMEM;
933 goto err_lk;
934 }
935 spin_lock_init(&idev->pending_lock);
936 INIT_LIST_HEAD(&idev->pending[0]);
937 INIT_LIST_HEAD(&idev->pending[1]);
938 INIT_LIST_HEAD(&idev->pending[2]);
939 INIT_LIST_HEAD(&idev->piowait);
940 INIT_LIST_HEAD(&idev->rnrwait);
941 idev->pending_index = 0;
942 idev->port_cap_flags =
943 IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
944 idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
945 idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
946 idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
947 idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
948 idev->pma_counter_select[5] = IB_PMA_PORT_XMIT_WAIT;
949 idev->link_width_enabled = 3; /* 1x or 4x */
950
951 /*
952 * The system image GUID is supposed to be the same for all
953 * IB HCAs in a single system but since there can be other
954 * device types in the system, we can't be sure this is unique.
955 */
956 if (!sys_image_guid)
957 sys_image_guid = ipath_layer_get_guid(dd);
958 idev->sys_image_guid = sys_image_guid;
959 idev->ib_unit = unit;
960 idev->dd = dd;
961
962 strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX);
Bryan O'Sullivan41c75a12006-05-23 11:32:36 -0700963 dev->owner = THIS_MODULE;
Bryan O'Sullivan65221082006-03-29 15:23:38 -0800964 dev->node_guid = ipath_layer_get_guid(dd);
965 dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION;
966 dev->uverbs_cmd_mask =
967 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
968 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
969 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
970 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
971 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
972 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
973 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
974 (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
975 (1ull << IB_USER_VERBS_CMD_REG_MR) |
976 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
977 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
978 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
979 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
980 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
981 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
982 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
983 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
984 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
985 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
986 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
987 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
988 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
989 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
990 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
991 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
992 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
993 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
994 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
995 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
996 dev->node_type = IB_NODE_CA;
997 dev->phys_port_cnt = 1;
998 dev->dma_device = ipath_layer_get_device(dd);
999 dev->class_dev.dev = dev->dma_device;
1000 dev->query_device = ipath_query_device;
1001 dev->modify_device = ipath_modify_device;
1002 dev->query_port = ipath_query_port;
1003 dev->modify_port = ipath_modify_port;
1004 dev->query_pkey = ipath_query_pkey;
1005 dev->query_gid = ipath_query_gid;
1006 dev->alloc_ucontext = ipath_alloc_ucontext;
1007 dev->dealloc_ucontext = ipath_dealloc_ucontext;
1008 dev->alloc_pd = ipath_alloc_pd;
1009 dev->dealloc_pd = ipath_dealloc_pd;
1010 dev->create_ah = ipath_create_ah;
1011 dev->destroy_ah = ipath_destroy_ah;
1012 dev->query_ah = ipath_query_ah;
1013 dev->create_srq = ipath_create_srq;
1014 dev->modify_srq = ipath_modify_srq;
1015 dev->query_srq = ipath_query_srq;
1016 dev->destroy_srq = ipath_destroy_srq;
1017 dev->create_qp = ipath_create_qp;
1018 dev->modify_qp = ipath_modify_qp;
1019 dev->query_qp = ipath_query_qp;
1020 dev->destroy_qp = ipath_destroy_qp;
1021 dev->post_send = ipath_post_send;
1022 dev->post_recv = ipath_post_receive;
1023 dev->post_srq_recv = ipath_post_srq_receive;
1024 dev->create_cq = ipath_create_cq;
1025 dev->destroy_cq = ipath_destroy_cq;
1026 dev->resize_cq = ipath_resize_cq;
1027 dev->poll_cq = ipath_poll_cq;
1028 dev->req_notify_cq = ipath_req_notify_cq;
1029 dev->get_dma_mr = ipath_get_dma_mr;
1030 dev->reg_phys_mr = ipath_reg_phys_mr;
1031 dev->reg_user_mr = ipath_reg_user_mr;
1032 dev->dereg_mr = ipath_dereg_mr;
1033 dev->alloc_fmr = ipath_alloc_fmr;
1034 dev->map_phys_fmr = ipath_map_phys_fmr;
1035 dev->unmap_fmr = ipath_unmap_fmr;
1036 dev->dealloc_fmr = ipath_dealloc_fmr;
1037 dev->attach_mcast = ipath_multicast_attach;
1038 dev->detach_mcast = ipath_multicast_detach;
1039 dev->process_mad = ipath_process_mad;
1040
1041 snprintf(dev->node_desc, sizeof(dev->node_desc),
1042 IPATH_IDSTR " %s kernel_SMA", system_utsname.nodename);
1043
1044 ret = ib_register_device(dev);
1045 if (ret)
1046 goto err_reg;
1047
1048 if (ipath_verbs_register_sysfs(dev))
1049 goto err_class;
1050
1051 ipath_layer_enable_timer(dd);
1052
1053 goto bail;
1054
1055err_class:
1056 ib_unregister_device(dev);
1057err_reg:
1058 kfree(idev->lk_table.table);
1059err_lk:
1060 kfree(idev->qp_table.table);
1061err_qp:
1062 ib_dealloc_device(dev);
1063 _VERBS_ERROR("ib_ipath%d cannot register verbs (%d)!\n",
1064 unit, -ret);
1065 idev = NULL;
1066
1067bail:
1068 return idev;
1069}
1070
1071static void ipath_unregister_ib_device(void *arg)
1072{
1073 struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
1074 struct ib_device *ibdev = &dev->ibdev;
1075
1076 ipath_layer_disable_timer(dev->dd);
1077
1078 ib_unregister_device(ibdev);
1079
1080 if (!list_empty(&dev->pending[0]) ||
1081 !list_empty(&dev->pending[1]) ||
1082 !list_empty(&dev->pending[2]))
1083 _VERBS_ERROR("ipath%d pending list not empty!\n",
1084 dev->ib_unit);
1085 if (!list_empty(&dev->piowait))
1086 _VERBS_ERROR("ipath%d piowait list not empty!\n",
1087 dev->ib_unit);
1088 if (!list_empty(&dev->rnrwait))
1089 _VERBS_ERROR("ipath%d rnrwait list not empty!\n",
1090 dev->ib_unit);
1091 if (!ipath_mcast_tree_empty())
1092 _VERBS_ERROR("ipath%d multicast table memory leak!\n",
1093 dev->ib_unit);
1094 /*
1095 * Note that ipath_unregister_ib_device() can be called before all
1096 * the QPs are destroyed!
1097 */
1098 ipath_free_all_qps(&dev->qp_table);
1099 kfree(dev->qp_table.table);
1100 kfree(dev->lk_table.table);
1101 ib_dealloc_device(ibdev);
1102}
1103
Roland Dreierac2ae4c2006-04-19 11:40:12 -07001104static int __init ipath_verbs_init(void)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001105{
1106 return ipath_verbs_register(ipath_register_ib_device,
1107 ipath_unregister_ib_device,
1108 ipath_ib_piobufavail, ipath_ib_rcv,
1109 ipath_ib_timer);
1110}
1111
Roland Dreierac2ae4c2006-04-19 11:40:12 -07001112static void __exit ipath_verbs_cleanup(void)
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001113{
1114 ipath_verbs_unregister();
1115}
1116
1117static ssize_t show_rev(struct class_device *cdev, char *buf)
1118{
Roland Dreier5494c222006-04-19 11:40:12 -07001119 struct ipath_ibdev *dev =
1120 container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001121
Bryan O'Sullivane8a88f02006-07-01 04:35:57 -07001122 return sprintf(buf, "%x\n", ipath_layer_get_pcirev(dev->dd));
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001123}
1124
1125static ssize_t show_hca(struct class_device *cdev, char *buf)
1126{
Roland Dreier5494c222006-04-19 11:40:12 -07001127 struct ipath_ibdev *dev =
1128 container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
1129 int ret;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001130
Roland Dreier5494c222006-04-19 11:40:12 -07001131 ret = ipath_layer_get_boardname(dev->dd, buf, 128);
1132 if (ret < 0)
1133 goto bail;
1134 strcat(buf, "\n");
1135 ret = strlen(buf);
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001136
1137bail:
1138 return ret;
1139}
1140
1141static ssize_t show_stats(struct class_device *cdev, char *buf)
1142{
Roland Dreier5494c222006-04-19 11:40:12 -07001143 struct ipath_ibdev *dev =
1144 container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
1145 int i;
1146 int len;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001147
Roland Dreier5494c222006-04-19 11:40:12 -07001148 len = sprintf(buf,
1149 "RC resends %d\n"
Bryan O'Sullivan9b2017f2006-04-24 14:23:06 -07001150 "RC no QACK %d\n"
Roland Dreier5494c222006-04-19 11:40:12 -07001151 "RC ACKs %d\n"
1152 "RC SEQ NAKs %d\n"
1153 "RC RDMA seq %d\n"
1154 "RC RNR NAKs %d\n"
1155 "RC OTH NAKs %d\n"
1156 "RC timeouts %d\n"
1157 "RC RDMA dup %d\n"
1158 "piobuf wait %d\n"
1159 "no piobuf %d\n"
1160 "PKT drops %d\n"
1161 "WQE errs %d\n",
1162 dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
1163 dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
1164 dev->n_other_naks, dev->n_timeouts,
1165 dev->n_rdma_dup_busy, dev->n_piowait,
1166 dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs);
1167 for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001168 const struct ipath_opcode_stats *si = &dev->opstats[i];
1169
Roland Dreier5494c222006-04-19 11:40:12 -07001170 if (!si->n_packets && !si->n_bytes)
1171 continue;
1172 len += sprintf(buf + len, "%02x %llu/%llu\n", i,
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001173 (unsigned long long) si->n_packets,
Roland Dreier5494c222006-04-19 11:40:12 -07001174 (unsigned long long) si->n_bytes);
1175 }
1176 return len;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001177}
1178
1179static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
1180static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
1181static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
1182static CLASS_DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
1183
1184static struct class_device_attribute *ipath_class_attributes[] = {
Roland Dreier5494c222006-04-19 11:40:12 -07001185 &class_device_attr_hw_rev,
1186 &class_device_attr_hca_type,
1187 &class_device_attr_board_id,
1188 &class_device_attr_stats
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001189};
1190
1191static int ipath_verbs_register_sysfs(struct ib_device *dev)
1192{
Roland Dreier5494c222006-04-19 11:40:12 -07001193 int i;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001194 int ret;
1195
Roland Dreier5494c222006-04-19 11:40:12 -07001196 for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i)
1197 if (class_device_create_file(&dev->class_dev,
1198 ipath_class_attributes[i])) {
1199 ret = 1;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001200 goto bail;
1201 }
1202
Roland Dreier5494c222006-04-19 11:40:12 -07001203 ret = 0;
Bryan O'Sullivan65221082006-03-29 15:23:38 -08001204
1205bail:
1206 return ret;
1207}
1208
1209module_init(ipath_verbs_init);
1210module_exit(ipath_verbs_cleanup);