2
* Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation.
4
* Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
6
* This software is available to you under a choice of one of two
7
* licenses. You may choose to be licensed under the terms of the GNU
8
* General Public License (GPL) Version 2, available from the file
9
* COPYING in the main directory of this source tree, or the
10
* OpenIB.org BSD license below:
12
* Redistribution and use in source and binary forms, with or
13
* without modification, are permitted provided that the following
16
* - Redistributions of source code must retain the above
17
* copyright notice, this list of conditions and the following
20
* - Redistributions in binary form must reproduce the above
21
* copyright notice, this list of conditions and the following
22
* disclaimer in the documentation and/or other materials
23
* provided with the distribution.
25
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
#include <rdma/ib_mad.h>
36
#include <rdma/ib_user_verbs.h>
38
#include <linux/utsname.h>
39
#include <linux/rculist.h>
43
#include "qib_common.h"
45
static unsigned int ib_qib_qp_table_size = 251;
46
module_param_named(qp_table_size, ib_qib_qp_table_size, uint, S_IRUGO);
47
MODULE_PARM_DESC(qp_table_size, "QP table size");
49
unsigned int ib_qib_lkey_table_size = 16;
50
module_param_named(lkey_table_size, ib_qib_lkey_table_size, uint,
52
MODULE_PARM_DESC(lkey_table_size,
53
"LKEY table size in bits (2^n, 1 <= n <= 23)");
55
static unsigned int ib_qib_max_pds = 0xFFFF;
56
module_param_named(max_pds, ib_qib_max_pds, uint, S_IRUGO);
57
MODULE_PARM_DESC(max_pds,
58
"Maximum number of protection domains to support");
60
static unsigned int ib_qib_max_ahs = 0xFFFF;
61
module_param_named(max_ahs, ib_qib_max_ahs, uint, S_IRUGO);
62
MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support");
64
unsigned int ib_qib_max_cqes = 0x2FFFF;
65
module_param_named(max_cqes, ib_qib_max_cqes, uint, S_IRUGO);
66
MODULE_PARM_DESC(max_cqes,
67
"Maximum number of completion queue entries to support");
69
unsigned int ib_qib_max_cqs = 0x1FFFF;
70
module_param_named(max_cqs, ib_qib_max_cqs, uint, S_IRUGO);
71
MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support");
73
unsigned int ib_qib_max_qp_wrs = 0x3FFF;
74
module_param_named(max_qp_wrs, ib_qib_max_qp_wrs, uint, S_IRUGO);
75
MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support");
77
unsigned int ib_qib_max_qps = 16384;
78
module_param_named(max_qps, ib_qib_max_qps, uint, S_IRUGO);
79
MODULE_PARM_DESC(max_qps, "Maximum number of QPs to support");
81
unsigned int ib_qib_max_sges = 0x60;
82
module_param_named(max_sges, ib_qib_max_sges, uint, S_IRUGO);
83
MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support");
85
unsigned int ib_qib_max_mcast_grps = 16384;
86
module_param_named(max_mcast_grps, ib_qib_max_mcast_grps, uint, S_IRUGO);
87
MODULE_PARM_DESC(max_mcast_grps,
88
"Maximum number of multicast groups to support");
90
unsigned int ib_qib_max_mcast_qp_attached = 16;
91
module_param_named(max_mcast_qp_attached, ib_qib_max_mcast_qp_attached,
93
MODULE_PARM_DESC(max_mcast_qp_attached,
94
"Maximum number of attached QPs to support");
96
unsigned int ib_qib_max_srqs = 1024;
97
module_param_named(max_srqs, ib_qib_max_srqs, uint, S_IRUGO);
98
MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support");
100
unsigned int ib_qib_max_srq_sges = 128;
101
module_param_named(max_srq_sges, ib_qib_max_srq_sges, uint, S_IRUGO);
102
MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support");
104
unsigned int ib_qib_max_srq_wrs = 0x1FFFF;
105
module_param_named(max_srq_wrs, ib_qib_max_srq_wrs, uint, S_IRUGO);
106
MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support");
108
static unsigned int ib_qib_disable_sma;
109
module_param_named(disable_sma, ib_qib_disable_sma, uint, S_IWUSR | S_IRUGO);
110
MODULE_PARM_DESC(disable_sma, "Disable the SMA");
113
* Note that it is OK to post send work requests in the SQE and ERR
114
* states; qib_do_send() will process them and generate error
115
* completions as per IB 1.2 C10-96.
117
const int ib_qib_state_ops[IB_QPS_ERR + 1] = {
119
[IB_QPS_INIT] = QIB_POST_RECV_OK,
120
[IB_QPS_RTR] = QIB_POST_RECV_OK | QIB_PROCESS_RECV_OK,
121
[IB_QPS_RTS] = QIB_POST_RECV_OK | QIB_PROCESS_RECV_OK |
122
QIB_POST_SEND_OK | QIB_PROCESS_SEND_OK |
123
QIB_PROCESS_NEXT_SEND_OK,
124
[IB_QPS_SQD] = QIB_POST_RECV_OK | QIB_PROCESS_RECV_OK |
125
QIB_POST_SEND_OK | QIB_PROCESS_SEND_OK,
126
[IB_QPS_SQE] = QIB_POST_RECV_OK | QIB_PROCESS_RECV_OK |
127
QIB_POST_SEND_OK | QIB_FLUSH_SEND,
128
[IB_QPS_ERR] = QIB_POST_RECV_OK | QIB_FLUSH_RECV |
129
QIB_POST_SEND_OK | QIB_FLUSH_SEND,
132
struct qib_ucontext {
133
struct ib_ucontext ibucontext;
136
static inline struct qib_ucontext *to_iucontext(struct ib_ucontext
139
return container_of(ibucontext, struct qib_ucontext, ibucontext);
143
* Translate ib_wr_opcode into ib_wc_opcode.
145
const enum ib_wc_opcode ib_qib_wc_opcode[] = {
146
[IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
147
[IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
148
[IB_WR_SEND] = IB_WC_SEND,
149
[IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
150
[IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
151
[IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
152
[IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD
158
__be64 ib_qib_sys_image_guid;
161
* qib_copy_sge - copy data to SGE memory
163
* @data: the data to copy
164
* @length: the length of the data
166
void qib_copy_sge(struct qib_sge_state *ss, void *data, u32 length, int release)
168
struct qib_sge *sge = &ss->sge;
171
u32 len = sge->length;
175
if (len > sge->sge_length)
176
len = sge->sge_length;
178
memcpy(sge->vaddr, data, len);
181
sge->sge_length -= len;
182
if (sge->sge_length == 0) {
184
atomic_dec(&sge->mr->refcount);
186
*sge = *ss->sg_list++;
187
} else if (sge->length == 0 && sge->mr->lkey) {
188
if (++sge->n >= QIB_SEGSZ) {
189
if (++sge->m >= sge->mr->mapsz)
194
sge->mr->map[sge->m]->segs[sge->n].vaddr;
196
sge->mr->map[sge->m]->segs[sge->n].length;
204
* qib_skip_sge - skip over SGE memory - XXX almost dup of prev func
206
* @length: the number of bytes to skip
208
void qib_skip_sge(struct qib_sge_state *ss, u32 length, int release)
210
struct qib_sge *sge = &ss->sge;
213
u32 len = sge->length;
217
if (len > sge->sge_length)
218
len = sge->sge_length;
222
sge->sge_length -= len;
223
if (sge->sge_length == 0) {
225
atomic_dec(&sge->mr->refcount);
227
*sge = *ss->sg_list++;
228
} else if (sge->length == 0 && sge->mr->lkey) {
229
if (++sge->n >= QIB_SEGSZ) {
230
if (++sge->m >= sge->mr->mapsz)
235
sge->mr->map[sge->m]->segs[sge->n].vaddr;
237
sge->mr->map[sge->m]->segs[sge->n].length;
244
* Count the number of DMA descriptors needed to send length bytes of data.
245
* Don't modify the qib_sge_state to get the count.
246
* Return zero if any of the segments is not aligned.
248
static u32 qib_count_sge(struct qib_sge_state *ss, u32 length)
250
struct qib_sge *sg_list = ss->sg_list;
251
struct qib_sge sge = ss->sge;
252
u8 num_sge = ss->num_sge;
253
u32 ndesc = 1; /* count the header */
256
u32 len = sge.length;
260
if (len > sge.sge_length)
261
len = sge.sge_length;
263
if (((long) sge.vaddr & (sizeof(u32) - 1)) ||
264
(len != length && (len & (sizeof(u32) - 1)))) {
271
sge.sge_length -= len;
272
if (sge.sge_length == 0) {
275
} else if (sge.length == 0 && sge.mr->lkey) {
276
if (++sge.n >= QIB_SEGSZ) {
277
if (++sge.m >= sge.mr->mapsz)
282
sge.mr->map[sge.m]->segs[sge.n].vaddr;
284
sge.mr->map[sge.m]->segs[sge.n].length;
292
* Copy from the SGEs to the data buffer.
294
static void qib_copy_from_sge(void *data, struct qib_sge_state *ss, u32 length)
296
struct qib_sge *sge = &ss->sge;
299
u32 len = sge->length;
303
if (len > sge->sge_length)
304
len = sge->sge_length;
306
memcpy(data, sge->vaddr, len);
309
sge->sge_length -= len;
310
if (sge->sge_length == 0) {
312
*sge = *ss->sg_list++;
313
} else if (sge->length == 0 && sge->mr->lkey) {
314
if (++sge->n >= QIB_SEGSZ) {
315
if (++sge->m >= sge->mr->mapsz)
320
sge->mr->map[sge->m]->segs[sge->n].vaddr;
322
sge->mr->map[sge->m]->segs[sge->n].length;
330
* qib_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
334
static int qib_post_one_send(struct qib_qp *qp, struct ib_send_wr *wr)
336
struct qib_swqe *wqe;
343
struct qib_lkey_table *rkt;
346
spin_lock_irqsave(&qp->s_lock, flags);
348
/* Check that state is OK to post send. */
349
if (unlikely(!(ib_qib_state_ops[qp->state] & QIB_POST_SEND_OK)))
352
/* IB spec says that num_sge == 0 is OK. */
353
if (wr->num_sge > qp->s_max_sge)
357
* Don't allow RDMA reads or atomic operations on UC or
358
* undefined operations.
359
* Make sure buffer is large enough to hold the result for atomics.
361
if (wr->opcode == IB_WR_FAST_REG_MR) {
362
if (qib_fast_reg_mr(qp, wr))
364
} else if (qp->ibqp.qp_type == IB_QPT_UC) {
365
if ((unsigned) wr->opcode >= IB_WR_RDMA_READ)
367
} else if (qp->ibqp.qp_type != IB_QPT_RC) {
368
/* Check IB_QPT_SMI, IB_QPT_GSI, IB_QPT_UD opcode */
369
if (wr->opcode != IB_WR_SEND &&
370
wr->opcode != IB_WR_SEND_WITH_IMM)
372
/* Check UD destination address PD */
373
if (qp->ibqp.pd != wr->wr.ud.ah->pd)
375
} else if ((unsigned) wr->opcode > IB_WR_ATOMIC_FETCH_AND_ADD)
377
else if (wr->opcode >= IB_WR_ATOMIC_CMP_AND_SWP &&
379
wr->sg_list[0].length < sizeof(u64) ||
380
wr->sg_list[0].addr & (sizeof(u64) - 1)))
382
else if (wr->opcode >= IB_WR_RDMA_READ && !qp->s_max_rd_atomic)
385
next = qp->s_head + 1;
386
if (next >= qp->s_size)
388
if (next == qp->s_last) {
393
rkt = &to_idev(qp->ibqp.device)->lk_table;
394
pd = to_ipd(qp->ibqp.pd);
395
wqe = get_swqe_ptr(qp, qp->s_head);
400
acc = wr->opcode >= IB_WR_RDMA_READ ?
401
IB_ACCESS_LOCAL_WRITE : 0;
402
for (i = 0; i < wr->num_sge; i++) {
403
u32 length = wr->sg_list[i].length;
408
ok = qib_lkey_ok(rkt, pd, &wqe->sg_list[j],
409
&wr->sg_list[i], acc);
411
goto bail_inval_free;
412
wqe->length += length;
417
if (qp->ibqp.qp_type == IB_QPT_UC ||
418
qp->ibqp.qp_type == IB_QPT_RC) {
419
if (wqe->length > 0x80000000U)
420
goto bail_inval_free;
421
} else if (wqe->length > (dd_from_ibdev(qp->ibqp.device)->pport +
422
qp->port_num - 1)->ibmtu)
423
goto bail_inval_free;
425
atomic_inc(&to_iah(wr->wr.ud.ah)->refcount);
426
wqe->ssn = qp->s_ssn++;
434
struct qib_sge *sge = &wqe->sg_list[--j];
436
atomic_dec(&sge->mr->refcount);
441
spin_unlock_irqrestore(&qp->s_lock, flags);
446
* qib_post_send - post a send on a QP
447
* @ibqp: the QP to post the send on
448
* @wr: the list of work requests to post
449
* @bad_wr: the first bad WR is put here
451
* This may be called from interrupt context.
453
static int qib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
454
struct ib_send_wr **bad_wr)
456
struct qib_qp *qp = to_iqp(ibqp);
459
for (; wr; wr = wr->next) {
460
err = qib_post_one_send(qp, wr);
467
/* Try to do the send work in the caller's context. */
468
qib_do_send(&qp->s_work);
475
* qib_post_receive - post a receive on a QP
476
* @ibqp: the QP to post the receive on
477
* @wr: the WR to post
478
* @bad_wr: the first bad WR is put here
480
* This may be called from interrupt context.
482
static int qib_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
483
struct ib_recv_wr **bad_wr)
485
struct qib_qp *qp = to_iqp(ibqp);
486
struct qib_rwq *wq = qp->r_rq.wq;
490
/* Check that state is OK to post receive. */
491
if (!(ib_qib_state_ops[qp->state] & QIB_POST_RECV_OK) || !wq) {
497
for (; wr; wr = wr->next) {
498
struct qib_rwqe *wqe;
502
if ((unsigned) wr->num_sge > qp->r_rq.max_sge) {
508
spin_lock_irqsave(&qp->r_rq.lock, flags);
510
if (next >= qp->r_rq.size)
512
if (next == wq->tail) {
513
spin_unlock_irqrestore(&qp->r_rq.lock, flags);
519
wqe = get_rwqe_ptr(&qp->r_rq, wq->head);
520
wqe->wr_id = wr->wr_id;
521
wqe->num_sge = wr->num_sge;
522
for (i = 0; i < wr->num_sge; i++)
523
wqe->sg_list[i] = wr->sg_list[i];
524
/* Make sure queue entry is written before the head index. */
527
spin_unlock_irqrestore(&qp->r_rq.lock, flags);
536
* qib_qp_rcv - processing an incoming packet on a QP
537
* @rcd: the context pointer
538
* @hdr: the packet header
539
* @has_grh: true if the packet has a GRH
540
* @data: the packet data
541
* @tlen: the packet length
542
* @qp: the QP the packet came on
544
* This is called from qib_ib_rcv() to process an incoming packet
546
* Called at interrupt level.
548
static void qib_qp_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
549
int has_grh, void *data, u32 tlen, struct qib_qp *qp)
551
struct qib_ibport *ibp = &rcd->ppd->ibport_data;
553
/* Check for valid receive state. */
554
if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK)) {
559
switch (qp->ibqp.qp_type) {
562
if (ib_qib_disable_sma)
566
qib_ud_rcv(ibp, hdr, has_grh, data, tlen, qp);
570
qib_rc_rcv(rcd, hdr, has_grh, data, tlen, qp);
574
qib_uc_rcv(ibp, hdr, has_grh, data, tlen, qp);
583
* qib_ib_rcv - process an incoming packet
584
* @rcd: the context pointer
585
* @rhdr: the header of the packet
586
* @data: the packet payload
587
* @tlen: the packet length
589
* This is called from qib_kreceive() to process an incoming packet at
590
* interrupt level. Tlen is the length of the header + data + CRC in bytes.
592
void qib_ib_rcv(struct qib_ctxtdata *rcd, void *rhdr, void *data, u32 tlen)
594
struct qib_pportdata *ppd = rcd->ppd;
595
struct qib_ibport *ibp = &ppd->ibport_data;
596
struct qib_ib_header *hdr = rhdr;
597
struct qib_other_headers *ohdr;
604
/* 24 == LRH+BTH+CRC */
605
if (unlikely(tlen < 24))
608
/* Check for a valid destination LID (see ch. 7.11.1). */
609
lid = be16_to_cpu(hdr->lrh[1]);
610
if (lid < QIB_MULTICAST_LID_BASE) {
611
lid &= ~((1 << ppd->lmc) - 1);
612
if (unlikely(lid != ppd->lid))
617
lnh = be16_to_cpu(hdr->lrh[0]) & 3;
618
if (lnh == QIB_LRH_BTH)
620
else if (lnh == QIB_LRH_GRH) {
623
ohdr = &hdr->u.l.oth;
624
if (hdr->u.l.grh.next_hdr != IB_GRH_NEXT_HDR)
626
vtf = be32_to_cpu(hdr->u.l.grh.version_tclass_flow);
627
if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
632
opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
633
ibp->opstats[opcode & 0x7f].n_bytes += tlen;
634
ibp->opstats[opcode & 0x7f].n_packets++;
636
/* Get the destination QP number. */
637
qp_num = be32_to_cpu(ohdr->bth[1]) & QIB_QPN_MASK;
638
if (qp_num == QIB_MULTICAST_QPN) {
639
struct qib_mcast *mcast;
640
struct qib_mcast_qp *p;
642
if (lnh != QIB_LRH_GRH)
644
mcast = qib_mcast_find(ibp, &hdr->u.l.grh.dgid);
647
ibp->n_multicast_rcv++;
648
list_for_each_entry_rcu(p, &mcast->qp_list, list)
649
qib_qp_rcv(rcd, hdr, 1, data, tlen, p->qp);
651
* Notify qib_multicast_detach() if it is waiting for us
654
if (atomic_dec_return(&mcast->refcount) <= 1)
655
wake_up(&mcast->wait);
657
qp = qib_lookup_qpn(ibp, qp_num);
660
ibp->n_unicast_rcv++;
661
qib_qp_rcv(rcd, hdr, lnh == QIB_LRH_GRH, data, tlen, qp);
663
* Notify qib_destroy_qp() if it is waiting
666
if (atomic_dec_and_test(&qp->refcount))
676
* This is called from a timer to check for QPs
677
* which need kernel memory in order to send a packet.
679
static void mem_timer(unsigned long data)
681
struct qib_ibdev *dev = (struct qib_ibdev *) data;
682
struct list_head *list = &dev->memwait;
683
struct qib_qp *qp = NULL;
686
spin_lock_irqsave(&dev->pending_lock, flags);
687
if (!list_empty(list)) {
688
qp = list_entry(list->next, struct qib_qp, iowait);
689
list_del_init(&qp->iowait);
690
atomic_inc(&qp->refcount);
691
if (!list_empty(list))
692
mod_timer(&dev->mem_timer, jiffies + 1);
694
spin_unlock_irqrestore(&dev->pending_lock, flags);
697
spin_lock_irqsave(&qp->s_lock, flags);
698
if (qp->s_flags & QIB_S_WAIT_KMEM) {
699
qp->s_flags &= ~QIB_S_WAIT_KMEM;
700
qib_schedule_send(qp);
702
spin_unlock_irqrestore(&qp->s_lock, flags);
703
if (atomic_dec_and_test(&qp->refcount))
708
static void update_sge(struct qib_sge_state *ss, u32 length)
710
struct qib_sge *sge = &ss->sge;
712
sge->vaddr += length;
713
sge->length -= length;
714
sge->sge_length -= length;
715
if (sge->sge_length == 0) {
717
*sge = *ss->sg_list++;
718
} else if (sge->length == 0 && sge->mr->lkey) {
719
if (++sge->n >= QIB_SEGSZ) {
720
if (++sge->m >= sge->mr->mapsz)
724
sge->vaddr = sge->mr->map[sge->m]->segs[sge->n].vaddr;
725
sge->length = sge->mr->map[sge->m]->segs[sge->n].length;
729
#ifdef __LITTLE_ENDIAN
730
static inline u32 get_upper_bits(u32 data, u32 shift)
732
return data >> shift;
735
static inline u32 set_upper_bits(u32 data, u32 shift)
737
return data << shift;
740
static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
742
data <<= ((sizeof(u32) - n) * BITS_PER_BYTE);
743
data >>= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
747
static inline u32 get_upper_bits(u32 data, u32 shift)
749
return data << shift;
752
static inline u32 set_upper_bits(u32 data, u32 shift)
754
return data >> shift;
757
static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
759
data >>= ((sizeof(u32) - n) * BITS_PER_BYTE);
760
data <<= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
765
static void copy_io(u32 __iomem *piobuf, struct qib_sge_state *ss,
766
u32 length, unsigned flush_wc)
773
u32 len = ss->sge.length;
778
if (len > ss->sge.sge_length)
779
len = ss->sge.sge_length;
781
/* If the source address is not aligned, try to align it. */
782
off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1);
784
u32 *addr = (u32 *)((unsigned long)ss->sge.vaddr &
786
u32 v = get_upper_bits(*addr, off * BITS_PER_BYTE);
789
y = sizeof(u32) - off;
792
if (len + extra >= sizeof(u32)) {
793
data |= set_upper_bits(v, extra *
795
len = sizeof(u32) - extra;
800
__raw_writel(data, piobuf);
805
/* Clear unused upper bytes */
806
data |= clear_upper_bytes(v, len, extra);
814
/* Source address is aligned. */
815
u32 *addr = (u32 *) ss->sge.vaddr;
816
int shift = extra * BITS_PER_BYTE;
817
int ushift = 32 - shift;
820
while (l >= sizeof(u32)) {
823
data |= set_upper_bits(v, shift);
824
__raw_writel(data, piobuf);
825
data = get_upper_bits(v, ushift);
831
* We still have 'extra' number of bytes leftover.
836
if (l + extra >= sizeof(u32)) {
837
data |= set_upper_bits(v, shift);
838
len -= l + extra - sizeof(u32);
843
__raw_writel(data, piobuf);
848
/* Clear unused upper bytes */
849
data |= clear_upper_bytes(v, l, extra);
856
} else if (len == length) {
860
} else if (len == length) {
864
* Need to round up for the last dword in the
868
qib_pio_copy(piobuf, ss->sge.vaddr, w - 1);
870
last = ((u32 *) ss->sge.vaddr)[w - 1];
875
qib_pio_copy(piobuf, ss->sge.vaddr, w);
878
extra = len & (sizeof(u32) - 1);
880
u32 v = ((u32 *) ss->sge.vaddr)[w];
882
/* Clear unused upper bytes */
883
data = clear_upper_bytes(v, extra, 0);
889
/* Update address before sending packet. */
890
update_sge(ss, length);
892
/* must flush early everything before trigger word */
894
__raw_writel(last, piobuf);
895
/* be sure trigger word is written */
898
__raw_writel(last, piobuf);
901
static struct qib_verbs_txreq *get_txreq(struct qib_ibdev *dev,
902
struct qib_qp *qp, int *retp)
904
struct qib_verbs_txreq *tx;
907
spin_lock_irqsave(&qp->s_lock, flags);
908
spin_lock(&dev->pending_lock);
910
if (!list_empty(&dev->txreq_free)) {
911
struct list_head *l = dev->txreq_free.next;
914
tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
917
if (ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK &&
918
list_empty(&qp->iowait)) {
920
qp->s_flags |= QIB_S_WAIT_TX;
921
list_add_tail(&qp->iowait, &dev->txwait);
924
qp->s_flags &= ~QIB_S_BUSY;
928
spin_unlock(&dev->pending_lock);
929
spin_unlock_irqrestore(&qp->s_lock, flags);
934
void qib_put_txreq(struct qib_verbs_txreq *tx)
936
struct qib_ibdev *dev;
941
dev = to_idev(qp->ibqp.device);
943
if (atomic_dec_and_test(&qp->refcount))
946
atomic_dec(&tx->mr->refcount);
949
if (tx->txreq.flags & QIB_SDMA_TXREQ_F_FREEBUF) {
950
tx->txreq.flags &= ~QIB_SDMA_TXREQ_F_FREEBUF;
951
dma_unmap_single(&dd_from_dev(dev)->pcidev->dev,
952
tx->txreq.addr, tx->hdr_dwords << 2,
954
kfree(tx->align_buf);
957
spin_lock_irqsave(&dev->pending_lock, flags);
959
/* Put struct back on free list */
960
list_add(&tx->txreq.list, &dev->txreq_free);
962
if (!list_empty(&dev->txwait)) {
963
/* Wake up first QP wanting a free struct */
964
qp = list_entry(dev->txwait.next, struct qib_qp, iowait);
965
list_del_init(&qp->iowait);
966
atomic_inc(&qp->refcount);
967
spin_unlock_irqrestore(&dev->pending_lock, flags);
969
spin_lock_irqsave(&qp->s_lock, flags);
970
if (qp->s_flags & QIB_S_WAIT_TX) {
971
qp->s_flags &= ~QIB_S_WAIT_TX;
972
qib_schedule_send(qp);
974
spin_unlock_irqrestore(&qp->s_lock, flags);
976
if (atomic_dec_and_test(&qp->refcount))
979
spin_unlock_irqrestore(&dev->pending_lock, flags);
983
* This is called when there are send DMA descriptors that might be
986
* This is called with ppd->sdma_lock held.
988
void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail)
990
struct qib_qp *qp, *nqp;
991
struct qib_qp *qps[20];
992
struct qib_ibdev *dev;
996
dev = &ppd->dd->verbs_dev;
997
spin_lock(&dev->pending_lock);
999
/* Search wait list for first QP wanting DMA descriptors. */
1000
list_for_each_entry_safe(qp, nqp, &dev->dmawait, iowait) {
1001
if (qp->port_num != ppd->port)
1003
if (n == ARRAY_SIZE(qps))
1005
if (qp->s_tx->txreq.sg_count > avail)
1007
avail -= qp->s_tx->txreq.sg_count;
1008
list_del_init(&qp->iowait);
1009
atomic_inc(&qp->refcount);
1013
spin_unlock(&dev->pending_lock);
1015
for (i = 0; i < n; i++) {
1017
spin_lock(&qp->s_lock);
1018
if (qp->s_flags & QIB_S_WAIT_DMA_DESC) {
1019
qp->s_flags &= ~QIB_S_WAIT_DMA_DESC;
1020
qib_schedule_send(qp);
1022
spin_unlock(&qp->s_lock);
1023
if (atomic_dec_and_test(&qp->refcount))
1029
* This is called with ppd->sdma_lock held.
1031
static void sdma_complete(struct qib_sdma_txreq *cookie, int status)
1033
struct qib_verbs_txreq *tx =
1034
container_of(cookie, struct qib_verbs_txreq, txreq);
1035
struct qib_qp *qp = tx->qp;
1037
spin_lock(&qp->s_lock);
1039
qib_send_complete(qp, tx->wqe, IB_WC_SUCCESS);
1040
else if (qp->ibqp.qp_type == IB_QPT_RC) {
1041
struct qib_ib_header *hdr;
1043
if (tx->txreq.flags & QIB_SDMA_TXREQ_F_FREEBUF)
1044
hdr = &tx->align_buf->hdr;
1046
struct qib_ibdev *dev = to_idev(qp->ibqp.device);
1048
hdr = &dev->pio_hdrs[tx->hdr_inx].hdr;
1050
qib_rc_send_complete(qp, hdr);
1052
if (atomic_dec_and_test(&qp->s_dma_busy)) {
1053
if (qp->state == IB_QPS_RESET)
1054
wake_up(&qp->wait_dma);
1055
else if (qp->s_flags & QIB_S_WAIT_DMA) {
1056
qp->s_flags &= ~QIB_S_WAIT_DMA;
1057
qib_schedule_send(qp);
1060
spin_unlock(&qp->s_lock);
1065
static int wait_kmem(struct qib_ibdev *dev, struct qib_qp *qp)
1067
unsigned long flags;
1070
spin_lock_irqsave(&qp->s_lock, flags);
1071
if (ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK) {
1072
spin_lock(&dev->pending_lock);
1073
if (list_empty(&qp->iowait)) {
1074
if (list_empty(&dev->memwait))
1075
mod_timer(&dev->mem_timer, jiffies + 1);
1076
qp->s_flags |= QIB_S_WAIT_KMEM;
1077
list_add_tail(&qp->iowait, &dev->memwait);
1079
spin_unlock(&dev->pending_lock);
1080
qp->s_flags &= ~QIB_S_BUSY;
1083
spin_unlock_irqrestore(&qp->s_lock, flags);
1088
static int qib_verbs_send_dma(struct qib_qp *qp, struct qib_ib_header *hdr,
1089
u32 hdrwords, struct qib_sge_state *ss, u32 len,
1090
u32 plen, u32 dwords)
1092
struct qib_ibdev *dev = to_idev(qp->ibqp.device);
1093
struct qib_devdata *dd = dd_from_dev(dev);
1094
struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
1095
struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1096
struct qib_verbs_txreq *tx;
1097
struct qib_pio_header *phdr;
1105
/* resend previously constructed packet */
1106
ret = qib_sdma_verbs_send(ppd, tx->ss, tx->dwords, tx);
1110
tx = get_txreq(dev, qp, &ret);
1114
control = dd->f_setpbc_control(ppd, plen, qp->s_srate,
1115
be16_to_cpu(hdr->lrh[0]) >> 12);
1117
atomic_inc(&qp->refcount);
1118
tx->wqe = qp->s_wqe;
1119
tx->mr = qp->s_rdma_mr;
1121
qp->s_rdma_mr = NULL;
1122
tx->txreq.callback = sdma_complete;
1123
if (dd->flags & QIB_HAS_SDMA_TIMEOUT)
1124
tx->txreq.flags = QIB_SDMA_TXREQ_F_HEADTOHOST;
1126
tx->txreq.flags = QIB_SDMA_TXREQ_F_INTREQ;
1127
if (plen + 1 > dd->piosize2kmax_dwords)
1128
tx->txreq.flags |= QIB_SDMA_TXREQ_F_USELARGEBUF;
1132
* Don't try to DMA if it takes more descriptors than
1135
ndesc = qib_count_sge(ss, len);
1136
if (ndesc >= ppd->sdma_descq_cnt)
1141
phdr = &dev->pio_hdrs[tx->hdr_inx];
1142
phdr->pbc[0] = cpu_to_le32(plen);
1143
phdr->pbc[1] = cpu_to_le32(control);
1144
memcpy(&phdr->hdr, hdr, hdrwords << 2);
1145
tx->txreq.flags |= QIB_SDMA_TXREQ_F_FREEDESC;
1146
tx->txreq.sg_count = ndesc;
1147
tx->txreq.addr = dev->pio_hdrs_phys +
1148
tx->hdr_inx * sizeof(struct qib_pio_header);
1149
tx->hdr_dwords = hdrwords + 2; /* add PBC length */
1150
ret = qib_sdma_verbs_send(ppd, ss, dwords, tx);
1154
/* Allocate a buffer and copy the header and payload to it. */
1155
tx->hdr_dwords = plen + 1;
1156
phdr = kmalloc(tx->hdr_dwords << 2, GFP_ATOMIC);
1159
phdr->pbc[0] = cpu_to_le32(plen);
1160
phdr->pbc[1] = cpu_to_le32(control);
1161
memcpy(&phdr->hdr, hdr, hdrwords << 2);
1162
qib_copy_from_sge((u32 *) &phdr->hdr + hdrwords, ss, len);
1164
tx->txreq.addr = dma_map_single(&dd->pcidev->dev, phdr,
1165
tx->hdr_dwords << 2, DMA_TO_DEVICE);
1166
if (dma_mapping_error(&dd->pcidev->dev, tx->txreq.addr))
1168
tx->align_buf = phdr;
1169
tx->txreq.flags |= QIB_SDMA_TXREQ_F_FREEBUF;
1170
tx->txreq.sg_count = 1;
1171
ret = qib_sdma_verbs_send(ppd, NULL, 0, tx);
1178
ret = wait_kmem(dev, qp);
1186
* If we are now in the error state, return zero to flush the
1187
* send work request.
1189
static int no_bufs_available(struct qib_qp *qp)
1191
struct qib_ibdev *dev = to_idev(qp->ibqp.device);
1192
struct qib_devdata *dd;
1193
unsigned long flags;
1197
* Note that as soon as want_buffer() is called and
1198
* possibly before it returns, qib_ib_piobufavail()
1199
* could be called. Therefore, put QP on the I/O wait list before
1200
* enabling the PIO avail interrupt.
1202
spin_lock_irqsave(&qp->s_lock, flags);
1203
if (ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK) {
1204
spin_lock(&dev->pending_lock);
1205
if (list_empty(&qp->iowait)) {
1207
qp->s_flags |= QIB_S_WAIT_PIO;
1208
list_add_tail(&qp->iowait, &dev->piowait);
1209
dd = dd_from_dev(dev);
1210
dd->f_wantpiobuf_intr(dd, 1);
1212
spin_unlock(&dev->pending_lock);
1213
qp->s_flags &= ~QIB_S_BUSY;
1216
spin_unlock_irqrestore(&qp->s_lock, flags);
1220
static int qib_verbs_send_pio(struct qib_qp *qp, struct qib_ib_header *ibhdr,
1221
u32 hdrwords, struct qib_sge_state *ss, u32 len,
1222
u32 plen, u32 dwords)
1224
struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
1225
struct qib_pportdata *ppd = dd->pport + qp->port_num - 1;
1226
u32 *hdr = (u32 *) ibhdr;
1227
u32 __iomem *piobuf_orig;
1228
u32 __iomem *piobuf;
1230
unsigned long flags;
1235
control = dd->f_setpbc_control(ppd, plen, qp->s_srate,
1236
be16_to_cpu(ibhdr->lrh[0]) >> 12);
1237
pbc = ((u64) control << 32) | plen;
1238
piobuf = dd->f_getsendbuf(ppd, pbc, &pbufn);
1239
if (unlikely(piobuf == NULL))
1240
return no_bufs_available(qp);
1244
* We have to flush after the PBC for correctness on some cpus
1245
* or WC buffer can be written out of order.
1247
writeq(pbc, piobuf);
1248
piobuf_orig = piobuf;
1251
flush_wc = dd->flags & QIB_PIO_FLUSH_WC;
1254
* If there is just the header portion, must flush before
1255
* writing last word of header for correctness, and after
1256
* the last header word (trigger word).
1260
qib_pio_copy(piobuf, hdr, hdrwords - 1);
1262
__raw_writel(hdr[hdrwords - 1], piobuf + hdrwords - 1);
1265
qib_pio_copy(piobuf, hdr, hdrwords);
1271
qib_pio_copy(piobuf, hdr, hdrwords);
1274
/* The common case is aligned and contained in one segment. */
1275
if (likely(ss->num_sge == 1 && len <= ss->sge.length &&
1276
!((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) {
1277
u32 *addr = (u32 *) ss->sge.vaddr;
1279
/* Update address before sending packet. */
1280
update_sge(ss, len);
1282
qib_pio_copy(piobuf, addr, dwords - 1);
1283
/* must flush early everything before trigger word */
1285
__raw_writel(addr[dwords - 1], piobuf + dwords - 1);
1286
/* be sure trigger word is written */
1289
qib_pio_copy(piobuf, addr, dwords);
1292
copy_io(piobuf, ss, len, flush_wc);
1294
if (dd->flags & QIB_USE_SPCL_TRIG) {
1295
u32 spcl_off = (pbufn >= dd->piobcnt2k) ? 2047 : 1023;
1297
__raw_writel(0xaebecede, piobuf_orig + spcl_off);
1299
qib_sendbuf_done(dd, pbufn);
1300
if (qp->s_rdma_mr) {
1301
atomic_dec(&qp->s_rdma_mr->refcount);
1302
qp->s_rdma_mr = NULL;
1305
spin_lock_irqsave(&qp->s_lock, flags);
1306
qib_send_complete(qp, qp->s_wqe, IB_WC_SUCCESS);
1307
spin_unlock_irqrestore(&qp->s_lock, flags);
1308
} else if (qp->ibqp.qp_type == IB_QPT_RC) {
1309
spin_lock_irqsave(&qp->s_lock, flags);
1310
qib_rc_send_complete(qp, ibhdr);
1311
spin_unlock_irqrestore(&qp->s_lock, flags);
1317
* qib_verbs_send - send a packet
1318
* @qp: the QP to send on
1319
* @hdr: the packet header
1320
* @hdrwords: the number of 32-bit words in the header
1321
* @ss: the SGE to send
1322
* @len: the length of the packet in bytes
1324
* Return zero if packet is sent or queued OK.
1325
* Return non-zero and clear qp->s_flags QIB_S_BUSY otherwise.
1327
int qib_verbs_send(struct qib_qp *qp, struct qib_ib_header *hdr,
1328
u32 hdrwords, struct qib_sge_state *ss, u32 len)
1330
struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
1333
u32 dwords = (len + 3) >> 2;
1336
* Calculate the send buffer trigger address.
1337
* The +1 counts for the pbc control dword following the pbc length.
1339
plen = hdrwords + dwords + 1;
1342
* VL15 packets (IB_QPT_SMI) will always use PIO, so we
1343
* can defer SDMA restart until link goes ACTIVE without
1344
* worrying about just how we got there.
1346
if (qp->ibqp.qp_type == IB_QPT_SMI ||
1347
!(dd->flags & QIB_HAS_SEND_DMA))
1348
ret = qib_verbs_send_pio(qp, hdr, hdrwords, ss, len,
1351
ret = qib_verbs_send_dma(qp, hdr, hdrwords, ss, len,
1357
int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
1358
u64 *rwords, u64 *spkts, u64 *rpkts,
1362
struct qib_devdata *dd = ppd->dd;
1364
if (!(dd->flags & QIB_PRESENT)) {
1365
/* no hardware, freeze, etc. */
1369
*swords = dd->f_portcntr(ppd, QIBPORTCNTR_WORDSEND);
1370
*rwords = dd->f_portcntr(ppd, QIBPORTCNTR_WORDRCV);
1371
*spkts = dd->f_portcntr(ppd, QIBPORTCNTR_PKTSEND);
1372
*rpkts = dd->f_portcntr(ppd, QIBPORTCNTR_PKTRCV);
1373
*xmit_wait = dd->f_portcntr(ppd, QIBPORTCNTR_SENDSTALL);
1382
* qib_get_counters - get various chip counters
1383
* @dd: the qlogic_ib device
1384
* @cntrs: counters are placed here
1386
* Return the counters needed by recv_pma_get_portcounters().
1388
int qib_get_counters(struct qib_pportdata *ppd,
1389
struct qib_verbs_counters *cntrs)
1393
if (!(ppd->dd->flags & QIB_PRESENT)) {
1394
/* no hardware, freeze, etc. */
1398
cntrs->symbol_error_counter =
1399
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBSYMBOLERR);
1400
cntrs->link_error_recovery_counter =
1401
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBLINKERRRECOV);
1403
* The link downed counter counts when the other side downs the
1404
* connection. We add in the number of times we downed the link
1405
* due to local link integrity errors to compensate.
1407
cntrs->link_downed_counter =
1408
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_IBLINKDOWN);
1409
cntrs->port_rcv_errors =
1410
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXDROPPKT) +
1411
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RCVOVFL) +
1412
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERR_RLEN) +
1413
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_INVALIDRLEN) +
1414
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRLINK) +
1415
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRICRC) +
1416
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRVCRC) +
1417
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_ERRLPCRC) +
1418
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_BADFORMAT);
1419
cntrs->port_rcv_errors +=
1420
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXLOCALPHYERR);
1421
cntrs->port_rcv_errors +=
1422
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RXVLERR);
1423
cntrs->port_rcv_remphys_errors =
1424
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_RCVEBP);
1425
cntrs->port_xmit_discards =
1426
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_UNSUPVL);
1427
cntrs->port_xmit_data = ppd->dd->f_portcntr(ppd,
1428
QIBPORTCNTR_WORDSEND);
1429
cntrs->port_rcv_data = ppd->dd->f_portcntr(ppd,
1430
QIBPORTCNTR_WORDRCV);
1431
cntrs->port_xmit_packets = ppd->dd->f_portcntr(ppd,
1432
QIBPORTCNTR_PKTSEND);
1433
cntrs->port_rcv_packets = ppd->dd->f_portcntr(ppd,
1434
QIBPORTCNTR_PKTRCV);
1435
cntrs->local_link_integrity_errors =
1436
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_LLI);
1437
cntrs->excessive_buffer_overrun_errors =
1438
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_EXCESSBUFOVFL);
1439
cntrs->vl15_dropped =
1440
ppd->dd->f_portcntr(ppd, QIBPORTCNTR_VL15PKTDROP);
1449
* qib_ib_piobufavail - callback when a PIO buffer is available
1450
* @dd: the device pointer
1452
* This is called from qib_intr() at interrupt level when a PIO buffer is
1453
* available after qib_verbs_send() returned an error that no buffers were
1454
* available. Disable the interrupt if there are no more QPs waiting.
1456
void qib_ib_piobufavail(struct qib_devdata *dd)
1458
struct qib_ibdev *dev = &dd->verbs_dev;
1459
struct list_head *list;
1460
struct qib_qp *qps[5];
1462
unsigned long flags;
1465
list = &dev->piowait;
1469
* Note: checking that the piowait list is empty and clearing
1470
* the buffer available interrupt needs to be atomic or we
1471
* could end up with QPs on the wait list with the interrupt
1474
spin_lock_irqsave(&dev->pending_lock, flags);
1475
while (!list_empty(list)) {
1476
if (n == ARRAY_SIZE(qps))
1478
qp = list_entry(list->next, struct qib_qp, iowait);
1479
list_del_init(&qp->iowait);
1480
atomic_inc(&qp->refcount);
1483
dd->f_wantpiobuf_intr(dd, 0);
1485
spin_unlock_irqrestore(&dev->pending_lock, flags);
1487
for (i = 0; i < n; i++) {
1490
spin_lock_irqsave(&qp->s_lock, flags);
1491
if (qp->s_flags & QIB_S_WAIT_PIO) {
1492
qp->s_flags &= ~QIB_S_WAIT_PIO;
1493
qib_schedule_send(qp);
1495
spin_unlock_irqrestore(&qp->s_lock, flags);
1497
/* Notify qib_destroy_qp() if it is waiting. */
1498
if (atomic_dec_and_test(&qp->refcount))
1503
static int qib_query_device(struct ib_device *ibdev,
1504
struct ib_device_attr *props)
1506
struct qib_devdata *dd = dd_from_ibdev(ibdev);
1507
struct qib_ibdev *dev = to_idev(ibdev);
1509
memset(props, 0, sizeof(*props));
1511
props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
1512
IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
1513
IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN |
1514
IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE;
1515
props->page_size_cap = PAGE_SIZE;
1517
QIB_SRC_OUI_1 << 16 | QIB_SRC_OUI_2 << 8 | QIB_SRC_OUI_3;
1518
props->vendor_part_id = dd->deviceid;
1519
props->hw_ver = dd->minrev;
1520
props->sys_image_guid = ib_qib_sys_image_guid;
1521
props->max_mr_size = ~0ULL;
1522
props->max_qp = ib_qib_max_qps;
1523
props->max_qp_wr = ib_qib_max_qp_wrs;
1524
props->max_sge = ib_qib_max_sges;
1525
props->max_cq = ib_qib_max_cqs;
1526
props->max_ah = ib_qib_max_ahs;
1527
props->max_cqe = ib_qib_max_cqes;
1528
props->max_mr = dev->lk_table.max;
1529
props->max_fmr = dev->lk_table.max;
1530
props->max_map_per_fmr = 32767;
1531
props->max_pd = ib_qib_max_pds;
1532
props->max_qp_rd_atom = QIB_MAX_RDMA_ATOMIC;
1533
props->max_qp_init_rd_atom = 255;
1534
/* props->max_res_rd_atom */
1535
props->max_srq = ib_qib_max_srqs;
1536
props->max_srq_wr = ib_qib_max_srq_wrs;
1537
props->max_srq_sge = ib_qib_max_srq_sges;
1538
/* props->local_ca_ack_delay */
1539
props->atomic_cap = IB_ATOMIC_GLOB;
1540
props->max_pkeys = qib_get_npkeys(dd);
1541
props->max_mcast_grp = ib_qib_max_mcast_grps;
1542
props->max_mcast_qp_attach = ib_qib_max_mcast_qp_attached;
1543
props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
1544
props->max_mcast_grp;
1549
static int qib_query_port(struct ib_device *ibdev, u8 port,
1550
struct ib_port_attr *props)
1552
struct qib_devdata *dd = dd_from_ibdev(ibdev);
1553
struct qib_ibport *ibp = to_iport(ibdev, port);
1554
struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1558
memset(props, 0, sizeof(*props));
1559
props->lid = lid ? lid : be16_to_cpu(IB_LID_PERMISSIVE);
1560
props->lmc = ppd->lmc;
1561
props->sm_lid = ibp->sm_lid;
1562
props->sm_sl = ibp->sm_sl;
1563
props->state = dd->f_iblink_state(ppd->lastibcstat);
1564
props->phys_state = dd->f_ibphys_portstate(ppd->lastibcstat);
1565
props->port_cap_flags = ibp->port_cap_flags;
1566
props->gid_tbl_len = QIB_GUIDS_PER_PORT;
1567
props->max_msg_sz = 0x80000000;
1568
props->pkey_tbl_len = qib_get_npkeys(dd);
1569
props->bad_pkey_cntr = ibp->pkey_violations;
1570
props->qkey_viol_cntr = ibp->qkey_violations;
1571
props->active_width = ppd->link_width_active;
1572
/* See rate_show() */
1573
props->active_speed = ppd->link_speed_active;
1574
props->max_vl_num = qib_num_vls(ppd->vls_supported);
1575
props->init_type_reply = 0;
1577
props->max_mtu = qib_ibmtu ? qib_ibmtu : IB_MTU_4096;
1578
switch (ppd->ibmtu) {
1597
props->active_mtu = mtu;
1598
props->subnet_timeout = ibp->subnet_timeout;
1603
static int qib_modify_device(struct ib_device *device,
1604
int device_modify_mask,
1605
struct ib_device_modify *device_modify)
1607
struct qib_devdata *dd = dd_from_ibdev(device);
1611
if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
1612
IB_DEVICE_MODIFY_NODE_DESC)) {
1617
if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC) {
1618
memcpy(device->node_desc, device_modify->node_desc, 64);
1619
for (i = 0; i < dd->num_pports; i++) {
1620
struct qib_ibport *ibp = &dd->pport[i].ibport_data;
1622
qib_node_desc_chg(ibp);
1626
if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) {
1627
ib_qib_sys_image_guid =
1628
cpu_to_be64(device_modify->sys_image_guid);
1629
for (i = 0; i < dd->num_pports; i++) {
1630
struct qib_ibport *ibp = &dd->pport[i].ibport_data;
1632
qib_sys_guid_chg(ibp);
1642
static int qib_modify_port(struct ib_device *ibdev, u8 port,
1643
int port_modify_mask, struct ib_port_modify *props)
1645
struct qib_ibport *ibp = to_iport(ibdev, port);
1646
struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1648
ibp->port_cap_flags |= props->set_port_cap_mask;
1649
ibp->port_cap_flags &= ~props->clr_port_cap_mask;
1650
if (props->set_port_cap_mask || props->clr_port_cap_mask)
1651
qib_cap_mask_chg(ibp);
1652
if (port_modify_mask & IB_PORT_SHUTDOWN)
1653
qib_set_linkstate(ppd, QIB_IB_LINKDOWN);
1654
if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
1655
ibp->qkey_violations = 0;
1659
static int qib_query_gid(struct ib_device *ibdev, u8 port,
1660
int index, union ib_gid *gid)
1662
struct qib_devdata *dd = dd_from_ibdev(ibdev);
1665
if (!port || port > dd->num_pports)
1668
struct qib_ibport *ibp = to_iport(ibdev, port);
1669
struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1671
gid->global.subnet_prefix = ibp->gid_prefix;
1673
gid->global.interface_id = ppd->guid;
1674
else if (index < QIB_GUIDS_PER_PORT)
1675
gid->global.interface_id = ibp->guids[index - 1];
1683
static struct ib_pd *qib_alloc_pd(struct ib_device *ibdev,
1684
struct ib_ucontext *context,
1685
struct ib_udata *udata)
1687
struct qib_ibdev *dev = to_idev(ibdev);
1692
* This is actually totally arbitrary. Some correctness tests
1693
* assume there's a maximum number of PDs that can be allocated.
1694
* We don't actually have this limit, but we fail the test if
1695
* we allow allocations of more than we report for this value.
1698
pd = kmalloc(sizeof *pd, GFP_KERNEL);
1700
ret = ERR_PTR(-ENOMEM);
1704
spin_lock(&dev->n_pds_lock);
1705
if (dev->n_pds_allocated == ib_qib_max_pds) {
1706
spin_unlock(&dev->n_pds_lock);
1708
ret = ERR_PTR(-ENOMEM);
1712
dev->n_pds_allocated++;
1713
spin_unlock(&dev->n_pds_lock);
1715
/* ib_alloc_pd() will initialize pd->ibpd. */
1716
pd->user = udata != NULL;
1724
static int qib_dealloc_pd(struct ib_pd *ibpd)
1726
struct qib_pd *pd = to_ipd(ibpd);
1727
struct qib_ibdev *dev = to_idev(ibpd->device);
1729
spin_lock(&dev->n_pds_lock);
1730
dev->n_pds_allocated--;
1731
spin_unlock(&dev->n_pds_lock);
1738
int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr)
1740
/* A multicast address requires a GRH (see ch. 8.4.1). */
1741
if (ah_attr->dlid >= QIB_MULTICAST_LID_BASE &&
1742
ah_attr->dlid != QIB_PERMISSIVE_LID &&
1743
!(ah_attr->ah_flags & IB_AH_GRH))
1745
if ((ah_attr->ah_flags & IB_AH_GRH) &&
1746
ah_attr->grh.sgid_index >= QIB_GUIDS_PER_PORT)
1748
if (ah_attr->dlid == 0)
1750
if (ah_attr->port_num < 1 ||
1751
ah_attr->port_num > ibdev->phys_port_cnt)
1753
if (ah_attr->static_rate != IB_RATE_PORT_CURRENT &&
1754
ib_rate_to_mult(ah_attr->static_rate) < 0)
1756
if (ah_attr->sl > 15)
1764
* qib_create_ah - create an address handle
1765
* @pd: the protection domain
1766
* @ah_attr: the attributes of the AH
1768
* This may be called from interrupt context.
1770
static struct ib_ah *qib_create_ah(struct ib_pd *pd,
1771
struct ib_ah_attr *ah_attr)
1775
struct qib_ibdev *dev = to_idev(pd->device);
1776
unsigned long flags;
1778
if (qib_check_ah(pd->device, ah_attr)) {
1779
ret = ERR_PTR(-EINVAL);
1783
ah = kmalloc(sizeof *ah, GFP_ATOMIC);
1785
ret = ERR_PTR(-ENOMEM);
1789
spin_lock_irqsave(&dev->n_ahs_lock, flags);
1790
if (dev->n_ahs_allocated == ib_qib_max_ahs) {
1791
spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1793
ret = ERR_PTR(-ENOMEM);
1797
dev->n_ahs_allocated++;
1798
spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1800
/* ib_create_ah() will initialize ah->ibah. */
1801
ah->attr = *ah_attr;
1802
atomic_set(&ah->refcount, 0);
1811
* qib_destroy_ah - destroy an address handle
1812
* @ibah: the AH to destroy
1814
* This may be called from interrupt context.
1816
static int qib_destroy_ah(struct ib_ah *ibah)
1818
struct qib_ibdev *dev = to_idev(ibah->device);
1819
struct qib_ah *ah = to_iah(ibah);
1820
unsigned long flags;
1822
if (atomic_read(&ah->refcount) != 0)
1825
spin_lock_irqsave(&dev->n_ahs_lock, flags);
1826
dev->n_ahs_allocated--;
1827
spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
1834
static int qib_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
1836
struct qib_ah *ah = to_iah(ibah);
1838
if (qib_check_ah(ibah->device, ah_attr))
1841
ah->attr = *ah_attr;
1846
static int qib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
1848
struct qib_ah *ah = to_iah(ibah);
1850
*ah_attr = ah->attr;
1856
* qib_get_npkeys - return the size of the PKEY table for context 0
1857
* @dd: the qlogic_ib device
1859
unsigned qib_get_npkeys(struct qib_devdata *dd)
1861
return ARRAY_SIZE(dd->rcd[0]->pkeys);
1865
* Return the indexed PKEY from the port PKEY table.
1866
* No need to validate rcd[ctxt]; the port is setup if we are here.
1868
unsigned qib_get_pkey(struct qib_ibport *ibp, unsigned index)
1870
struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1871
struct qib_devdata *dd = ppd->dd;
1872
unsigned ctxt = ppd->hw_pidx;
1875
/* dd->rcd null if mini_init or some init failures */
1876
if (!dd->rcd || index >= ARRAY_SIZE(dd->rcd[ctxt]->pkeys))
1879
ret = dd->rcd[ctxt]->pkeys[index];
1884
static int qib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
1887
struct qib_devdata *dd = dd_from_ibdev(ibdev);
1890
if (index >= qib_get_npkeys(dd)) {
1895
*pkey = qib_get_pkey(to_iport(ibdev, port), index);
1903
* qib_alloc_ucontext - allocate a ucontest
1904
* @ibdev: the infiniband device
1905
* @udata: not used by the QLogic_IB driver
1908
static struct ib_ucontext *qib_alloc_ucontext(struct ib_device *ibdev,
1909
struct ib_udata *udata)
1911
struct qib_ucontext *context;
1912
struct ib_ucontext *ret;
1914
context = kmalloc(sizeof *context, GFP_KERNEL);
1916
ret = ERR_PTR(-ENOMEM);
1920
ret = &context->ibucontext;
1926
static int qib_dealloc_ucontext(struct ib_ucontext *context)
1928
kfree(to_iucontext(context));
1932
static void init_ibport(struct qib_pportdata *ppd)
1934
struct qib_verbs_counters cntrs;
1935
struct qib_ibport *ibp = &ppd->ibport_data;
1937
spin_lock_init(&ibp->lock);
1938
/* Set the prefix to the default value (see ch. 4.1.1) */
1939
ibp->gid_prefix = IB_DEFAULT_GID_PREFIX;
1940
ibp->sm_lid = be16_to_cpu(IB_LID_PERMISSIVE);
1941
ibp->port_cap_flags = IB_PORT_SYS_IMAGE_GUID_SUP |
1942
IB_PORT_CLIENT_REG_SUP | IB_PORT_SL_MAP_SUP |
1943
IB_PORT_TRAP_SUP | IB_PORT_AUTO_MIGR_SUP |
1944
IB_PORT_DR_NOTICE_SUP | IB_PORT_CAP_MASK_NOTICE_SUP |
1945
IB_PORT_OTHER_LOCAL_CHANGES_SUP;
1946
if (ppd->dd->flags & QIB_HAS_LINK_LATENCY)
1947
ibp->port_cap_flags |= IB_PORT_LINK_LATENCY_SUP;
1948
ibp->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
1949
ibp->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
1950
ibp->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
1951
ibp->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
1952
ibp->pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
1954
/* Snapshot current HW counters to "clear" them. */
1955
qib_get_counters(ppd, &cntrs);
1956
ibp->z_symbol_error_counter = cntrs.symbol_error_counter;
1957
ibp->z_link_error_recovery_counter =
1958
cntrs.link_error_recovery_counter;
1959
ibp->z_link_downed_counter = cntrs.link_downed_counter;
1960
ibp->z_port_rcv_errors = cntrs.port_rcv_errors;
1961
ibp->z_port_rcv_remphys_errors = cntrs.port_rcv_remphys_errors;
1962
ibp->z_port_xmit_discards = cntrs.port_xmit_discards;
1963
ibp->z_port_xmit_data = cntrs.port_xmit_data;
1964
ibp->z_port_rcv_data = cntrs.port_rcv_data;
1965
ibp->z_port_xmit_packets = cntrs.port_xmit_packets;
1966
ibp->z_port_rcv_packets = cntrs.port_rcv_packets;
1967
ibp->z_local_link_integrity_errors =
1968
cntrs.local_link_integrity_errors;
1969
ibp->z_excessive_buffer_overrun_errors =
1970
cntrs.excessive_buffer_overrun_errors;
1971
ibp->z_vl15_dropped = cntrs.vl15_dropped;
1975
* qib_register_ib_device - register our device with the infiniband core
1976
* @dd: the device data structure
1977
* Return the allocated qib_ibdev pointer or NULL on error.
1979
int qib_register_ib_device(struct qib_devdata *dd)
1981
struct qib_ibdev *dev = &dd->verbs_dev;
1982
struct ib_device *ibdev = &dev->ibdev;
1983
struct qib_pportdata *ppd = dd->pport;
1984
unsigned i, lk_tab_size;
1987
dev->qp_table_size = ib_qib_qp_table_size;
1988
dev->qp_table = kzalloc(dev->qp_table_size * sizeof *dev->qp_table,
1990
if (!dev->qp_table) {
1995
for (i = 0; i < dd->num_pports; i++)
1996
init_ibport(ppd + i);
1998
/* Only need to initialize non-zero fields. */
1999
spin_lock_init(&dev->qpt_lock);
2000
spin_lock_init(&dev->n_pds_lock);
2001
spin_lock_init(&dev->n_ahs_lock);
2002
spin_lock_init(&dev->n_cqs_lock);
2003
spin_lock_init(&dev->n_qps_lock);
2004
spin_lock_init(&dev->n_srqs_lock);
2005
spin_lock_init(&dev->n_mcast_grps_lock);
2006
init_timer(&dev->mem_timer);
2007
dev->mem_timer.function = mem_timer;
2008
dev->mem_timer.data = (unsigned long) dev;
2010
qib_init_qpn_table(dd, &dev->qpn_table);
2013
* The top ib_qib_lkey_table_size bits are used to index the
2014
* table. The lower 8 bits can be owned by the user (copied from
2015
* the LKEY). The remaining bits act as a generation number or tag.
2017
spin_lock_init(&dev->lk_table.lock);
2018
dev->lk_table.max = 1 << ib_qib_lkey_table_size;
2019
lk_tab_size = dev->lk_table.max * sizeof(*dev->lk_table.table);
2020
dev->lk_table.table = (struct qib_mregion **)
2021
__get_free_pages(GFP_KERNEL, get_order(lk_tab_size));
2022
if (dev->lk_table.table == NULL) {
2026
memset(dev->lk_table.table, 0, lk_tab_size);
2027
INIT_LIST_HEAD(&dev->pending_mmaps);
2028
spin_lock_init(&dev->pending_lock);
2029
dev->mmap_offset = PAGE_SIZE;
2030
spin_lock_init(&dev->mmap_offset_lock);
2031
INIT_LIST_HEAD(&dev->piowait);
2032
INIT_LIST_HEAD(&dev->dmawait);
2033
INIT_LIST_HEAD(&dev->txwait);
2034
INIT_LIST_HEAD(&dev->memwait);
2035
INIT_LIST_HEAD(&dev->txreq_free);
2037
if (ppd->sdma_descq_cnt) {
2038
dev->pio_hdrs = dma_alloc_coherent(&dd->pcidev->dev,
2039
ppd->sdma_descq_cnt *
2040
sizeof(struct qib_pio_header),
2041
&dev->pio_hdrs_phys,
2043
if (!dev->pio_hdrs) {
2049
for (i = 0; i < ppd->sdma_descq_cnt; i++) {
2050
struct qib_verbs_txreq *tx;
2052
tx = kzalloc(sizeof *tx, GFP_KERNEL);
2058
list_add(&tx->txreq.list, &dev->txreq_free);
2062
* The system image GUID is supposed to be the same for all
2063
* IB HCAs in a single system but since there can be other
2064
* device types in the system, we can't be sure this is unique.
2066
if (!ib_qib_sys_image_guid)
2067
ib_qib_sys_image_guid = ppd->guid;
2069
strlcpy(ibdev->name, "qib%d", IB_DEVICE_NAME_MAX);
2070
ibdev->owner = THIS_MODULE;
2071
ibdev->node_guid = ppd->guid;
2072
ibdev->uverbs_abi_ver = QIB_UVERBS_ABI_VERSION;
2073
ibdev->uverbs_cmd_mask =
2074
(1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
2075
(1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
2076
(1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
2077
(1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
2078
(1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
2079
(1ull << IB_USER_VERBS_CMD_CREATE_AH) |
2080
(1ull << IB_USER_VERBS_CMD_MODIFY_AH) |
2081
(1ull << IB_USER_VERBS_CMD_QUERY_AH) |
2082
(1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
2083
(1ull << IB_USER_VERBS_CMD_REG_MR) |
2084
(1ull << IB_USER_VERBS_CMD_DEREG_MR) |
2085
(1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
2086
(1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
2087
(1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
2088
(1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
2089
(1ull << IB_USER_VERBS_CMD_POLL_CQ) |
2090
(1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
2091
(1ull << IB_USER_VERBS_CMD_CREATE_QP) |
2092
(1ull << IB_USER_VERBS_CMD_QUERY_QP) |
2093
(1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
2094
(1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
2095
(1ull << IB_USER_VERBS_CMD_POST_SEND) |
2096
(1ull << IB_USER_VERBS_CMD_POST_RECV) |
2097
(1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
2098
(1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
2099
(1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
2100
(1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
2101
(1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
2102
(1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
2103
(1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
2104
ibdev->node_type = RDMA_NODE_IB_CA;
2105
ibdev->phys_port_cnt = dd->num_pports;
2106
ibdev->num_comp_vectors = 1;
2107
ibdev->dma_device = &dd->pcidev->dev;
2108
ibdev->query_device = qib_query_device;
2109
ibdev->modify_device = qib_modify_device;
2110
ibdev->query_port = qib_query_port;
2111
ibdev->modify_port = qib_modify_port;
2112
ibdev->query_pkey = qib_query_pkey;
2113
ibdev->query_gid = qib_query_gid;
2114
ibdev->alloc_ucontext = qib_alloc_ucontext;
2115
ibdev->dealloc_ucontext = qib_dealloc_ucontext;
2116
ibdev->alloc_pd = qib_alloc_pd;
2117
ibdev->dealloc_pd = qib_dealloc_pd;
2118
ibdev->create_ah = qib_create_ah;
2119
ibdev->destroy_ah = qib_destroy_ah;
2120
ibdev->modify_ah = qib_modify_ah;
2121
ibdev->query_ah = qib_query_ah;
2122
ibdev->create_srq = qib_create_srq;
2123
ibdev->modify_srq = qib_modify_srq;
2124
ibdev->query_srq = qib_query_srq;
2125
ibdev->destroy_srq = qib_destroy_srq;
2126
ibdev->create_qp = qib_create_qp;
2127
ibdev->modify_qp = qib_modify_qp;
2128
ibdev->query_qp = qib_query_qp;
2129
ibdev->destroy_qp = qib_destroy_qp;
2130
ibdev->post_send = qib_post_send;
2131
ibdev->post_recv = qib_post_receive;
2132
ibdev->post_srq_recv = qib_post_srq_receive;
2133
ibdev->create_cq = qib_create_cq;
2134
ibdev->destroy_cq = qib_destroy_cq;
2135
ibdev->resize_cq = qib_resize_cq;
2136
ibdev->poll_cq = qib_poll_cq;
2137
ibdev->req_notify_cq = qib_req_notify_cq;
2138
ibdev->get_dma_mr = qib_get_dma_mr;
2139
ibdev->reg_phys_mr = qib_reg_phys_mr;
2140
ibdev->reg_user_mr = qib_reg_user_mr;
2141
ibdev->dereg_mr = qib_dereg_mr;
2142
ibdev->alloc_fast_reg_mr = qib_alloc_fast_reg_mr;
2143
ibdev->alloc_fast_reg_page_list = qib_alloc_fast_reg_page_list;
2144
ibdev->free_fast_reg_page_list = qib_free_fast_reg_page_list;
2145
ibdev->alloc_fmr = qib_alloc_fmr;
2146
ibdev->map_phys_fmr = qib_map_phys_fmr;
2147
ibdev->unmap_fmr = qib_unmap_fmr;
2148
ibdev->dealloc_fmr = qib_dealloc_fmr;
2149
ibdev->attach_mcast = qib_multicast_attach;
2150
ibdev->detach_mcast = qib_multicast_detach;
2151
ibdev->process_mad = qib_process_mad;
2152
ibdev->mmap = qib_mmap;
2153
ibdev->dma_ops = &qib_dma_mapping_ops;
2155
snprintf(ibdev->node_desc, sizeof(ibdev->node_desc),
2156
QIB_IDSTR " %s", init_utsname()->nodename);
2158
ret = ib_register_device(ibdev, qib_create_port_files);
2162
ret = qib_create_agents(dev);
2166
if (qib_verbs_register_sysfs(dd))
2172
qib_free_agents(dev);
2174
ib_unregister_device(ibdev);
2177
while (!list_empty(&dev->txreq_free)) {
2178
struct list_head *l = dev->txreq_free.next;
2179
struct qib_verbs_txreq *tx;
2182
tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
2185
if (ppd->sdma_descq_cnt)
2186
dma_free_coherent(&dd->pcidev->dev,
2187
ppd->sdma_descq_cnt *
2188
sizeof(struct qib_pio_header),
2189
dev->pio_hdrs, dev->pio_hdrs_phys);
2191
free_pages((unsigned long) dev->lk_table.table, get_order(lk_tab_size));
2193
kfree(dev->qp_table);
2195
qib_dev_err(dd, "cannot register verbs: %d!\n", -ret);
2200
void qib_unregister_ib_device(struct qib_devdata *dd)
2202
struct qib_ibdev *dev = &dd->verbs_dev;
2203
struct ib_device *ibdev = &dev->ibdev;
2205
unsigned lk_tab_size;
2207
qib_verbs_unregister_sysfs(dd);
2209
qib_free_agents(dev);
2211
ib_unregister_device(ibdev);
2213
if (!list_empty(&dev->piowait))
2214
qib_dev_err(dd, "piowait list not empty!\n");
2215
if (!list_empty(&dev->dmawait))
2216
qib_dev_err(dd, "dmawait list not empty!\n");
2217
if (!list_empty(&dev->txwait))
2218
qib_dev_err(dd, "txwait list not empty!\n");
2219
if (!list_empty(&dev->memwait))
2220
qib_dev_err(dd, "memwait list not empty!\n");
2222
qib_dev_err(dd, "DMA MR not NULL!\n");
2224
qps_inuse = qib_free_all_qps(dd);
2226
qib_dev_err(dd, "QP memory leak! %u still in use\n",
2229
del_timer_sync(&dev->mem_timer);
2230
qib_free_qpn_table(&dev->qpn_table);
2231
while (!list_empty(&dev->txreq_free)) {
2232
struct list_head *l = dev->txreq_free.next;
2233
struct qib_verbs_txreq *tx;
2236
tx = list_entry(l, struct qib_verbs_txreq, txreq.list);
2239
if (dd->pport->sdma_descq_cnt)
2240
dma_free_coherent(&dd->pcidev->dev,
2241
dd->pport->sdma_descq_cnt *
2242
sizeof(struct qib_pio_header),
2243
dev->pio_hdrs, dev->pio_hdrs_phys);
2244
lk_tab_size = dev->lk_table.max * sizeof(*dev->lk_table.table);
2245
free_pages((unsigned long) dev->lk_table.table,
2246
get_order(lk_tab_size));
2247
kfree(dev->qp_table);