2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 * $Id: mthca_qp.c 1355 2004-12-17 15:23:43Z roland $
38 #include <linux/init.h>
44 #include "mthca_dev.h"
45 #include "mthca_cmd.h"
46 #include "mthca_memfree.h"
49 MTHCA_MAX_DIRECT_QP_SIZE = 4 * PAGE_SIZE,
50 MTHCA_ACK_REQ_FREQ = 10,
51 MTHCA_FLIGHT_LIMIT = 9,
52 MTHCA_UD_HEADER_SIZE = 72, /* largest UD header possible */
53 MTHCA_INLINE_HEADER_SIZE = 4, /* data segment overhead for inline */
54 MTHCA_INLINE_CHUNK_SIZE = 16 /* inline data segment chunk */
58 MTHCA_QP_STATE_RST = 0,
59 MTHCA_QP_STATE_INIT = 1,
60 MTHCA_QP_STATE_RTR = 2,
61 MTHCA_QP_STATE_RTS = 3,
62 MTHCA_QP_STATE_SQE = 4,
63 MTHCA_QP_STATE_SQD = 5,
64 MTHCA_QP_STATE_ERR = 6,
65 MTHCA_QP_STATE_DRAINING = 7
77 MTHCA_QP_PM_MIGRATED = 0x3,
78 MTHCA_QP_PM_ARMED = 0x0,
79 MTHCA_QP_PM_REARM = 0x1
83 /* qp_context flags */
84 MTHCA_QP_BIT_DE = 1 << 8,
86 MTHCA_QP_BIT_SRE = 1 << 15,
87 MTHCA_QP_BIT_SWE = 1 << 14,
88 MTHCA_QP_BIT_SAE = 1 << 13,
89 MTHCA_QP_BIT_SIC = 1 << 4,
90 MTHCA_QP_BIT_SSC = 1 << 3,
92 MTHCA_QP_BIT_RRE = 1 << 15,
93 MTHCA_QP_BIT_RWE = 1 << 14,
94 MTHCA_QP_BIT_RAE = 1 << 13,
95 MTHCA_QP_BIT_RIC = 1 << 4,
96 MTHCA_QP_BIT_RSC = 1 << 3
99 struct mthca_qp_path {
108 u32 sl_tclass_flowlabel;
110 } __attribute__((packed));
112 struct mthca_qp_context {
114 u32 tavor_sched_queue; /* Reserved on Arbel */
116 u8 rq_size_stride; /* Reserved on Tavor */
117 u8 sq_size_stride; /* Reserved on Tavor */
118 u8 rlkey_arbel_sched_queue; /* Reserved on Tavor */
123 struct mthca_qp_path pri_path;
124 struct mthca_qp_path alt_path;
133 u32 snd_wqe_base_l; /* Next send WQE on Tavor */
134 u32 snd_db_index; /* (debugging only entries) */
141 u32 rcv_wqe_base_l; /* Next recv WQE on Tavor */
142 u32 rcv_db_index; /* (debugging only entries) */
146 u16 rq_wqe_counter; /* reserved on Tavor */
147 u16 sq_wqe_counter; /* reserved on Tavor */
149 } __attribute__((packed));
151 struct mthca_qp_param {
154 struct mthca_qp_context context;
156 } __attribute__((packed));
159 MTHCA_QP_OPTPAR_ALT_ADDR_PATH = 1 << 0,
160 MTHCA_QP_OPTPAR_RRE = 1 << 1,
161 MTHCA_QP_OPTPAR_RAE = 1 << 2,
162 MTHCA_QP_OPTPAR_RWE = 1 << 3,
163 MTHCA_QP_OPTPAR_PKEY_INDEX = 1 << 4,
164 MTHCA_QP_OPTPAR_Q_KEY = 1 << 5,
165 MTHCA_QP_OPTPAR_RNR_TIMEOUT = 1 << 6,
166 MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH = 1 << 7,
167 MTHCA_QP_OPTPAR_SRA_MAX = 1 << 8,
168 MTHCA_QP_OPTPAR_RRA_MAX = 1 << 9,
169 MTHCA_QP_OPTPAR_PM_STATE = 1 << 10,
170 MTHCA_QP_OPTPAR_PORT_NUM = 1 << 11,
171 MTHCA_QP_OPTPAR_RETRY_COUNT = 1 << 12,
172 MTHCA_QP_OPTPAR_ALT_RNR_RETRY = 1 << 13,
173 MTHCA_QP_OPTPAR_ACK_TIMEOUT = 1 << 14,
174 MTHCA_QP_OPTPAR_RNR_RETRY = 1 << 15,
175 MTHCA_QP_OPTPAR_SCHED_QUEUE = 1 << 16
179 MTHCA_NEXT_DBD = 1 << 7,
180 MTHCA_NEXT_FENCE = 1 << 6,
181 MTHCA_NEXT_CQ_UPDATE = 1 << 3,
182 MTHCA_NEXT_EVENT_GEN = 1 << 2,
183 MTHCA_NEXT_SOLICIT = 1 << 1,
185 MTHCA_MLX_VL15 = 1 << 17,
186 MTHCA_MLX_SLR = 1 << 16
190 MTHCA_INVAL_LKEY = 0x100
193 struct mthca_next_seg {
194 u32 nda_op; /* [31:6] next WQE [4:0] next opcode */
195 u32 ee_nds; /* [31:8] next EE [7] DBD [6] F [5:0] next WQE size */
196 u32 flags; /* [3] CQ [2] Event [1] Solicit */
197 u32 imm; /* immediate data */
200 struct mthca_tavor_ud_seg {
210 struct mthca_arbel_ud_seg {
217 struct mthca_bind_seg {
218 u32 flags; /* [31] Atomic [30] rem write [29] rem read */
226 struct mthca_raddr_seg {
232 struct mthca_atomic_seg {
237 struct mthca_data_seg {
243 struct mthca_mlx_seg {
246 u32 flags; /* [17] VL15 [16] SLR [14:12] static rate
247 [11:8] SL [3] C [2] E */
252 static const u8 mthca_opcode[] = {
253 [IB_WR_SEND] = MTHCA_OPCODE_SEND,
254 [IB_WR_SEND_WITH_IMM] = MTHCA_OPCODE_SEND_IMM,
255 [IB_WR_RDMA_WRITE] = MTHCA_OPCODE_RDMA_WRITE,
256 [IB_WR_RDMA_WRITE_WITH_IMM] = MTHCA_OPCODE_RDMA_WRITE_IMM,
257 [IB_WR_RDMA_READ] = MTHCA_OPCODE_RDMA_READ,
258 [IB_WR_ATOMIC_CMP_AND_SWP] = MTHCA_OPCODE_ATOMIC_CS,
259 [IB_WR_ATOMIC_FETCH_AND_ADD] = MTHCA_OPCODE_ATOMIC_FA,
262 static int is_sqp(struct mthca_dev *dev, struct mthca_qp *qp)
264 return qp->qpn >= dev->qp_table.sqp_start &&
265 qp->qpn <= dev->qp_table.sqp_start + 3;
268 static int is_qp0(struct mthca_dev *dev, struct mthca_qp *qp)
270 return qp->qpn >= dev->qp_table.sqp_start &&
271 qp->qpn <= dev->qp_table.sqp_start + 1;
274 static void *get_recv_wqe(struct mthca_qp *qp, int n)
277 return qp->queue.direct.buf + (n << qp->rq.wqe_shift);
279 return qp->queue.page_list[(n << qp->rq.wqe_shift) >> PAGE_SHIFT].buf +
280 ((n << qp->rq.wqe_shift) & (PAGE_SIZE - 1));
283 static void *get_send_wqe(struct mthca_qp *qp, int n)
286 return qp->queue.direct.buf + qp->send_wqe_offset +
287 (n << qp->sq.wqe_shift);
289 return qp->queue.page_list[(qp->send_wqe_offset +
290 (n << qp->sq.wqe_shift)) >>
292 ((qp->send_wqe_offset + (n << qp->sq.wqe_shift)) &
296 void mthca_qp_event(struct mthca_dev *dev, u32 qpn,
297 enum ib_event_type event_type)
300 struct ib_event event;
302 spin_lock(&dev->qp_table.lock);
303 qp = mthca_array_get(&dev->qp_table.qp, qpn & (dev->limits.num_qps - 1));
305 atomic_inc(&qp->refcount);
306 spin_unlock(&dev->qp_table.lock);
309 mthca_warn(dev, "Async event for bogus QP %08x\n", qpn);
313 event.device = &dev->ib_dev;
314 event.event = event_type;
315 event.element.qp = &qp->ibqp;
316 if (qp->ibqp.event_handler)
317 qp->ibqp.event_handler(&event, qp->ibqp.qp_context);
319 if (atomic_dec_and_test(&qp->refcount))
323 static int to_mthca_state(enum ib_qp_state ib_state)
326 case IB_QPS_RESET: return MTHCA_QP_STATE_RST;
327 case IB_QPS_INIT: return MTHCA_QP_STATE_INIT;
328 case IB_QPS_RTR: return MTHCA_QP_STATE_RTR;
329 case IB_QPS_RTS: return MTHCA_QP_STATE_RTS;
330 case IB_QPS_SQD: return MTHCA_QP_STATE_SQD;
331 case IB_QPS_SQE: return MTHCA_QP_STATE_SQE;
332 case IB_QPS_ERR: return MTHCA_QP_STATE_ERR;
337 enum { RC, UC, UD, RD, RDEE, MLX, NUM_TRANS };
339 static int to_mthca_st(int transport)
342 case RC: return MTHCA_QP_ST_RC;
343 case UC: return MTHCA_QP_ST_UC;
344 case UD: return MTHCA_QP_ST_UD;
345 case RD: return MTHCA_QP_ST_RD;
346 case MLX: return MTHCA_QP_ST_MLX;
351 static const struct {
353 u32 req_param[NUM_TRANS];
354 u32 opt_param[NUM_TRANS];
355 } state_table[IB_QPS_ERR + 1][IB_QPS_ERR + 1] = {
357 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
358 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
360 .trans = MTHCA_TRANS_RST2INIT,
362 [UD] = (IB_QP_PKEY_INDEX |
365 [UC] = (IB_QP_PKEY_INDEX |
368 [RC] = (IB_QP_PKEY_INDEX |
371 [MLX] = (IB_QP_PKEY_INDEX |
374 /* bug-for-bug compatibility with VAPI: */
381 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
382 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
384 .trans = MTHCA_TRANS_INIT2INIT,
386 [UD] = (IB_QP_PKEY_INDEX |
389 [UC] = (IB_QP_PKEY_INDEX |
392 [RC] = (IB_QP_PKEY_INDEX |
395 [MLX] = (IB_QP_PKEY_INDEX |
400 .trans = MTHCA_TRANS_INIT2RTR,
406 IB_QP_MAX_DEST_RD_ATOMIC),
411 IB_QP_MAX_DEST_RD_ATOMIC |
412 IB_QP_MIN_RNR_TIMER),
415 [UD] = (IB_QP_PKEY_INDEX |
417 [UC] = (IB_QP_ALT_PATH |
420 [RC] = (IB_QP_ALT_PATH |
423 [MLX] = (IB_QP_PKEY_INDEX |
429 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
430 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
432 .trans = MTHCA_TRANS_RTR2RTS,
435 [UC] = (IB_QP_SQ_PSN |
436 IB_QP_MAX_QP_RD_ATOMIC),
437 [RC] = (IB_QP_TIMEOUT |
441 IB_QP_MAX_QP_RD_ATOMIC),
442 [MLX] = IB_QP_SQ_PSN,
445 [UD] = (IB_QP_CUR_STATE |
447 [UC] = (IB_QP_CUR_STATE |
451 IB_QP_PATH_MIG_STATE),
452 [RC] = (IB_QP_CUR_STATE |
456 IB_QP_MIN_RNR_TIMER |
457 IB_QP_PATH_MIG_STATE),
458 [MLX] = (IB_QP_CUR_STATE |
464 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
465 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
467 .trans = MTHCA_TRANS_RTS2RTS,
469 [UD] = (IB_QP_CUR_STATE |
471 [UC] = (IB_QP_ACCESS_FLAGS |
473 IB_QP_PATH_MIG_STATE),
474 [RC] = (IB_QP_ACCESS_FLAGS |
476 IB_QP_PATH_MIG_STATE |
477 IB_QP_MIN_RNR_TIMER),
478 [MLX] = (IB_QP_CUR_STATE |
483 .trans = MTHCA_TRANS_RTS2SQD,
487 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
488 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
490 .trans = MTHCA_TRANS_SQD2RTS,
492 [UD] = (IB_QP_CUR_STATE |
494 [UC] = (IB_QP_CUR_STATE |
497 IB_QP_PATH_MIG_STATE),
498 [RC] = (IB_QP_CUR_STATE |
501 IB_QP_MIN_RNR_TIMER |
502 IB_QP_PATH_MIG_STATE),
503 [MLX] = (IB_QP_CUR_STATE |
508 .trans = MTHCA_TRANS_SQD2SQD,
510 [UD] = (IB_QP_PKEY_INDEX |
513 IB_QP_MAX_QP_RD_ATOMIC |
514 IB_QP_MAX_DEST_RD_ATOMIC |
519 IB_QP_PATH_MIG_STATE),
524 IB_QP_MAX_QP_RD_ATOMIC |
525 IB_QP_MAX_DEST_RD_ATOMIC |
530 IB_QP_MIN_RNR_TIMER |
531 IB_QP_PATH_MIG_STATE),
532 [MLX] = (IB_QP_PKEY_INDEX |
538 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
539 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
541 .trans = MTHCA_TRANS_SQERR2RTS,
543 [UD] = (IB_QP_CUR_STATE |
545 [UC] = (IB_QP_CUR_STATE),
546 [RC] = (IB_QP_CUR_STATE |
547 IB_QP_MIN_RNR_TIMER),
548 [MLX] = (IB_QP_CUR_STATE |
554 [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
555 [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR }
559 static void store_attrs(struct mthca_sqp *sqp, struct ib_qp_attr *attr,
562 if (attr_mask & IB_QP_PKEY_INDEX)
563 sqp->pkey_index = attr->pkey_index;
564 if (attr_mask & IB_QP_QKEY)
565 sqp->qkey = attr->qkey;
566 if (attr_mask & IB_QP_SQ_PSN)
567 sqp->send_psn = attr->sq_psn;
570 static void init_port(struct mthca_dev *dev, int port)
574 struct mthca_init_ib_param param;
576 memset(¶m, 0, sizeof param);
580 param.vl_cap = dev->limits.vl_cap;
581 param.mtu_cap = dev->limits.mtu_cap;
582 param.gid_cap = dev->limits.gid_table_len;
583 param.pkey_cap = dev->limits.pkey_table_len;
585 err = mthca_INIT_IB(dev, ¶m, port, &status);
587 mthca_warn(dev, "INIT_IB failed, return code %d.\n", err);
589 mthca_warn(dev, "INIT_IB returned status %02x.\n", status);
592 int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
594 struct mthca_dev *dev = to_mdev(ibqp->device);
595 struct mthca_qp *qp = to_mqp(ibqp);
596 enum ib_qp_state cur_state, new_state;
597 struct mthca_mailbox *mailbox;
598 struct mthca_qp_param *qp_param;
599 struct mthca_qp_context *qp_context;
600 u32 req_param, opt_param;
604 if (attr_mask & IB_QP_CUR_STATE) {
605 if (attr->cur_qp_state != IB_QPS_RTR &&
606 attr->cur_qp_state != IB_QPS_RTS &&
607 attr->cur_qp_state != IB_QPS_SQD &&
608 attr->cur_qp_state != IB_QPS_SQE)
611 cur_state = attr->cur_qp_state;
613 spin_lock_irq(&qp->sq.lock);
614 spin_lock(&qp->rq.lock);
615 cur_state = qp->state;
616 spin_unlock(&qp->rq.lock);
617 spin_unlock_irq(&qp->sq.lock);
620 if (attr_mask & IB_QP_STATE) {
621 if (attr->qp_state < 0 || attr->qp_state > IB_QPS_ERR)
623 new_state = attr->qp_state;
625 new_state = cur_state;
627 if (state_table[cur_state][new_state].trans == MTHCA_TRANS_INVALID) {
628 mthca_dbg(dev, "Illegal QP transition "
629 "%d->%d\n", cur_state, new_state);
633 req_param = state_table[cur_state][new_state].req_param[qp->transport];
634 opt_param = state_table[cur_state][new_state].opt_param[qp->transport];
636 if ((req_param & attr_mask) != req_param) {
637 mthca_dbg(dev, "QP transition "
638 "%d->%d missing req attr 0x%08x\n",
639 cur_state, new_state,
640 req_param & ~attr_mask);
644 if (attr_mask & ~(req_param | opt_param | IB_QP_STATE)) {
645 mthca_dbg(dev, "QP transition (transport %d) "
646 "%d->%d has extra attr 0x%08x\n",
648 cur_state, new_state,
649 attr_mask & ~(req_param | opt_param |
654 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
656 return PTR_ERR(mailbox);
657 qp_param = mailbox->buf;
658 qp_context = &qp_param->context;
659 memset(qp_param, 0, sizeof *qp_param);
661 qp_context->flags = cpu_to_be32((to_mthca_state(new_state) << 28) |
662 (to_mthca_st(qp->transport) << 16));
663 qp_context->flags |= cpu_to_be32(MTHCA_QP_BIT_DE);
664 if (!(attr_mask & IB_QP_PATH_MIG_STATE))
665 qp_context->flags |= cpu_to_be32(MTHCA_QP_PM_MIGRATED << 11);
667 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PM_STATE);
668 switch (attr->path_mig_state) {
669 case IB_MIG_MIGRATED:
670 qp_context->flags |= cpu_to_be32(MTHCA_QP_PM_MIGRATED << 11);
673 qp_context->flags |= cpu_to_be32(MTHCA_QP_PM_REARM << 11);
676 qp_context->flags |= cpu_to_be32(MTHCA_QP_PM_ARMED << 11);
681 /* leave tavor_sched_queue as 0 */
683 if (qp->transport == MLX || qp->transport == UD)
684 qp_context->mtu_msgmax = (IB_MTU_2048 << 5) | 11;
685 else if (attr_mask & IB_QP_PATH_MTU)
686 qp_context->mtu_msgmax = (attr->path_mtu << 5) | 31;
688 if (mthca_is_memfree(dev)) {
689 qp_context->rq_size_stride =
690 ((ffs(qp->rq.max) - 1) << 3) | (qp->rq.wqe_shift - 4);
691 qp_context->sq_size_stride =
692 ((ffs(qp->sq.max) - 1) << 3) | (qp->sq.wqe_shift - 4);
695 /* leave arbel_sched_queue as 0 */
697 if (qp->ibqp.uobject)
698 qp_context->usr_page =
699 cpu_to_be32(to_mucontext(qp->ibqp.uobject->context)->uar.index);
701 qp_context->usr_page = cpu_to_be32(dev->driver_uar.index);
702 qp_context->local_qpn = cpu_to_be32(qp->qpn);
703 if (attr_mask & IB_QP_DEST_QPN) {
704 qp_context->remote_qpn = cpu_to_be32(attr->dest_qp_num);
707 if (qp->transport == MLX)
708 qp_context->pri_path.port_pkey |=
709 cpu_to_be32(to_msqp(qp)->port << 24);
711 if (attr_mask & IB_QP_PORT) {
712 qp_context->pri_path.port_pkey |=
713 cpu_to_be32(attr->port_num << 24);
714 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PORT_NUM);
718 if (attr_mask & IB_QP_PKEY_INDEX) {
719 qp_context->pri_path.port_pkey |=
720 cpu_to_be32(attr->pkey_index);
721 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PKEY_INDEX);
724 if (attr_mask & IB_QP_RNR_RETRY) {
725 qp_context->pri_path.rnr_retry = attr->rnr_retry << 5;
726 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RNR_RETRY);
729 if (attr_mask & IB_QP_AV) {
730 qp_context->pri_path.g_mylmc = attr->ah_attr.src_path_bits & 0x7f;
731 qp_context->pri_path.rlid = cpu_to_be16(attr->ah_attr.dlid);
732 qp_context->pri_path.static_rate = !!attr->ah_attr.static_rate;
733 if (attr->ah_attr.ah_flags & IB_AH_GRH) {
734 qp_context->pri_path.g_mylmc |= 1 << 7;
735 qp_context->pri_path.mgid_index = attr->ah_attr.grh.sgid_index;
736 qp_context->pri_path.hop_limit = attr->ah_attr.grh.hop_limit;
737 qp_context->pri_path.sl_tclass_flowlabel =
738 cpu_to_be32((attr->ah_attr.sl << 28) |
739 (attr->ah_attr.grh.traffic_class << 20) |
740 (attr->ah_attr.grh.flow_label));
741 memcpy(qp_context->pri_path.rgid,
742 attr->ah_attr.grh.dgid.raw, 16);
744 qp_context->pri_path.sl_tclass_flowlabel =
745 cpu_to_be32(attr->ah_attr.sl << 28);
747 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH);
750 if (attr_mask & IB_QP_TIMEOUT) {
751 qp_context->pri_path.ackto = attr->timeout;
752 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_ACK_TIMEOUT);
758 qp_context->pd = cpu_to_be32(to_mpd(ibqp->pd)->pd_num);
759 /* leave wqe_base as 0 (we always create an MR based at 0 for WQs) */
760 qp_context->wqe_lkey = cpu_to_be32(qp->mr.ibmr.lkey);
761 qp_context->params1 = cpu_to_be32((MTHCA_ACK_REQ_FREQ << 28) |
762 (MTHCA_FLIGHT_LIMIT << 24) |
766 if (qp->sq_policy == IB_SIGNAL_ALL_WR)
767 qp_context->params1 |= cpu_to_be32(MTHCA_QP_BIT_SSC);
768 if (attr_mask & IB_QP_RETRY_CNT) {
769 qp_context->params1 |= cpu_to_be32(attr->retry_cnt << 16);
770 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RETRY_COUNT);
773 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) {
774 qp_context->params1 |= cpu_to_be32(min(attr->max_rd_atomic ?
775 ffs(attr->max_rd_atomic) - 1 : 0,
777 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_SRA_MAX);
780 if (attr_mask & IB_QP_SQ_PSN)
781 qp_context->next_send_psn = cpu_to_be32(attr->sq_psn);
782 qp_context->cqn_snd = cpu_to_be32(to_mcq(ibqp->send_cq)->cqn);
784 if (mthca_is_memfree(dev)) {
785 qp_context->snd_wqe_base_l = cpu_to_be32(qp->send_wqe_offset);
786 qp_context->snd_db_index = cpu_to_be32(qp->sq.db_index);
789 if (attr_mask & IB_QP_ACCESS_FLAGS) {
791 * Only enable RDMA/atomics if we have responder
792 * resources set to a non-zero value.
794 if (qp->resp_depth) {
795 qp_context->params2 |=
796 cpu_to_be32(attr->qp_access_flags & IB_ACCESS_REMOTE_WRITE ?
797 MTHCA_QP_BIT_RWE : 0);
798 qp_context->params2 |=
799 cpu_to_be32(attr->qp_access_flags & IB_ACCESS_REMOTE_READ ?
800 MTHCA_QP_BIT_RRE : 0);
801 qp_context->params2 |=
802 cpu_to_be32(attr->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC ?
803 MTHCA_QP_BIT_RAE : 0);
806 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RWE |
807 MTHCA_QP_OPTPAR_RRE |
808 MTHCA_QP_OPTPAR_RAE);
810 qp->atomic_rd_en = attr->qp_access_flags;
813 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
816 if (qp->resp_depth && !attr->max_dest_rd_atomic) {
818 * Lowering our responder resources to zero.
819 * Turn off RDMA/atomics as responder.
820 * (RWE/RRE/RAE in params2 already zero)
822 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RWE |
823 MTHCA_QP_OPTPAR_RRE |
824 MTHCA_QP_OPTPAR_RAE);
827 if (!qp->resp_depth && attr->max_dest_rd_atomic) {
829 * Increasing our responder resources from
830 * zero. Turn on RDMA/atomics as appropriate.
832 qp_context->params2 |=
833 cpu_to_be32(qp->atomic_rd_en & IB_ACCESS_REMOTE_WRITE ?
834 MTHCA_QP_BIT_RWE : 0);
835 qp_context->params2 |=
836 cpu_to_be32(qp->atomic_rd_en & IB_ACCESS_REMOTE_READ ?
837 MTHCA_QP_BIT_RRE : 0);
838 qp_context->params2 |=
839 cpu_to_be32(qp->atomic_rd_en & IB_ACCESS_REMOTE_ATOMIC ?
840 MTHCA_QP_BIT_RAE : 0);
842 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RWE |
843 MTHCA_QP_OPTPAR_RRE |
844 MTHCA_QP_OPTPAR_RAE);
848 1 << rra_max < attr->max_dest_rd_atomic &&
849 rra_max < dev->qp_table.rdb_shift;
853 qp_context->params2 |= cpu_to_be32(rra_max << 21);
854 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RRA_MAX);
856 qp->resp_depth = attr->max_dest_rd_atomic;
859 qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RSC);
861 if (attr_mask & IB_QP_MIN_RNR_TIMER) {
862 qp_context->rnr_nextrecvpsn |= cpu_to_be32(attr->min_rnr_timer << 24);
863 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RNR_TIMEOUT);
865 if (attr_mask & IB_QP_RQ_PSN)
866 qp_context->rnr_nextrecvpsn |= cpu_to_be32(attr->rq_psn);
868 qp_context->ra_buff_indx =
869 cpu_to_be32(dev->qp_table.rdb_base +
870 ((qp->qpn & (dev->limits.num_qps - 1)) * MTHCA_RDB_ENTRY_SIZE <<
871 dev->qp_table.rdb_shift));
873 qp_context->cqn_rcv = cpu_to_be32(to_mcq(ibqp->recv_cq)->cqn);
875 if (mthca_is_memfree(dev))
876 qp_context->rcv_db_index = cpu_to_be32(qp->rq.db_index);
878 if (attr_mask & IB_QP_QKEY) {
879 qp_context->qkey = cpu_to_be32(attr->qkey);
880 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_Q_KEY);
883 err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans,
884 qp->qpn, 0, mailbox, 0, &status);
886 mthca_warn(dev, "modify QP %d returned status %02x.\n",
887 state_table[cur_state][new_state].trans, status);
892 qp->state = new_state;
894 mthca_free_mailbox(dev, mailbox);
897 store_attrs(to_msqp(qp), attr, attr_mask);
900 * If we are moving QP0 to RTR, bring the IB link up; if we
901 * are moving QP0 to RESET or ERROR, bring the link back down.
903 if (is_qp0(dev, qp)) {
904 if (cur_state != IB_QPS_RTR &&
905 new_state == IB_QPS_RTR)
906 init_port(dev, to_msqp(qp)->port);
908 if (cur_state != IB_QPS_RESET &&
909 cur_state != IB_QPS_ERR &&
910 (new_state == IB_QPS_RESET ||
911 new_state == IB_QPS_ERR))
912 mthca_CLOSE_IB(dev, to_msqp(qp)->port, &status);
919 * Allocate and register buffer for WQEs. qp->rq.max, sq.max,
920 * rq.max_gs and sq.max_gs must all be assigned.
921 * mthca_alloc_wqe_buf will calculate rq.wqe_shift and
922 * sq.wqe_shift (as well as send_wqe_offset, is_direct, and
925 static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
933 u64 *dma_list = NULL;
936 size = sizeof (struct mthca_next_seg) +
937 qp->rq.max_gs * sizeof (struct mthca_data_seg);
939 for (qp->rq.wqe_shift = 6; 1 << qp->rq.wqe_shift < size;
943 size = sizeof (struct mthca_next_seg) +
944 qp->sq.max_gs * sizeof (struct mthca_data_seg);
945 switch (qp->transport) {
947 size += 2 * sizeof (struct mthca_data_seg);
950 if (mthca_is_memfree(dev))
951 size += sizeof (struct mthca_arbel_ud_seg);
953 size += sizeof (struct mthca_tavor_ud_seg);
956 /* bind seg is as big as atomic + raddr segs */
957 size += sizeof (struct mthca_bind_seg);
960 for (qp->sq.wqe_shift = 6; 1 << qp->sq.wqe_shift < size;
964 qp->send_wqe_offset = ALIGN(qp->rq.max << qp->rq.wqe_shift,
965 1 << qp->sq.wqe_shift);
968 * If this is a userspace QP, we don't actually have to
969 * allocate anything. All we need is to calculate the WQE
970 * sizes and the send_wqe_offset, so we're done now.
972 if (pd->ibpd.uobject)
975 size = PAGE_ALIGN(qp->send_wqe_offset +
976 (qp->sq.max << qp->sq.wqe_shift));
978 qp->wrid = kmalloc((qp->rq.max + qp->sq.max) * sizeof (u64),
983 if (size <= MTHCA_MAX_DIRECT_QP_SIZE) {
986 shift = get_order(size) + PAGE_SHIFT;
989 mthca_dbg(dev, "Creating direct QP of size %d (shift %d)\n",
992 qp->queue.direct.buf = dma_alloc_coherent(&dev->pdev->dev, size,
994 if (!qp->queue.direct.buf)
997 pci_unmap_addr_set(&qp->queue.direct, mapping, t);
999 memset(qp->queue.direct.buf, 0, size);
1001 while (t & ((1 << shift) - 1)) {
1006 dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
1010 for (i = 0; i < npages; ++i)
1011 dma_list[i] = t + i * (1 << shift);
1014 npages = size / PAGE_SIZE;
1018 mthca_dbg(dev, "Creating indirect QP with %d pages\n", npages);
1020 dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
1024 qp->queue.page_list = kmalloc(npages *
1025 sizeof *qp->queue.page_list,
1027 if (!qp->queue.page_list)
1030 for (i = 0; i < npages; ++i) {
1031 qp->queue.page_list[i].buf =
1032 dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,
1034 if (!qp->queue.page_list[i].buf)
1037 memset(qp->queue.page_list[i].buf, 0, PAGE_SIZE);
1039 pci_unmap_addr_set(&qp->queue.page_list[i], mapping, t);
1044 err = mthca_mr_alloc_phys(dev, pd->pd_num, dma_list, shift,
1046 MTHCA_MPT_FLAG_LOCAL_READ,
1055 if (qp->is_direct) {
1056 dma_free_coherent(&dev->pdev->dev, size, qp->queue.direct.buf,
1057 pci_unmap_addr(&qp->queue.direct, mapping));
1059 for (i = 0; i < npages; ++i) {
1060 if (qp->queue.page_list[i].buf)
1061 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
1062 qp->queue.page_list[i].buf,
1063 pci_unmap_addr(&qp->queue.page_list[i],
1074 static void mthca_free_wqe_buf(struct mthca_dev *dev,
1075 struct mthca_qp *qp)
1078 int size = PAGE_ALIGN(qp->send_wqe_offset +
1079 (qp->sq.max << qp->sq.wqe_shift));
1081 if (qp->is_direct) {
1082 dma_free_coherent(&dev->pdev->dev, size, qp->queue.direct.buf,
1083 pci_unmap_addr(&qp->queue.direct, mapping));
1085 for (i = 0; i < size / PAGE_SIZE; ++i) {
1086 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
1087 qp->queue.page_list[i].buf,
1088 pci_unmap_addr(&qp->queue.page_list[i],
1096 static int mthca_map_memfree(struct mthca_dev *dev,
1097 struct mthca_qp *qp)
1101 if (mthca_is_memfree(dev)) {
1102 ret = mthca_table_get(dev, dev->qp_table.qp_table, qp->qpn);
1106 ret = mthca_table_get(dev, dev->qp_table.eqp_table, qp->qpn);
1110 ret = mthca_table_get(dev, dev->qp_table.rdb_table,
1111 qp->qpn << dev->qp_table.rdb_shift);
1120 mthca_table_put(dev, dev->qp_table.eqp_table, qp->qpn);
1123 mthca_table_put(dev, dev->qp_table.qp_table, qp->qpn);
1128 static void mthca_unmap_memfree(struct mthca_dev *dev,
1129 struct mthca_qp *qp)
1131 mthca_table_put(dev, dev->qp_table.rdb_table,
1132 qp->qpn << dev->qp_table.rdb_shift);
1133 mthca_table_put(dev, dev->qp_table.eqp_table, qp->qpn);
1134 mthca_table_put(dev, dev->qp_table.qp_table, qp->qpn);
1137 static int mthca_alloc_memfree(struct mthca_dev *dev,
1138 struct mthca_qp *qp)
1142 if (mthca_is_memfree(dev)) {
1143 qp->rq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_RQ,
1144 qp->qpn, &qp->rq.db);
1145 if (qp->rq.db_index < 0)
1148 qp->sq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_SQ,
1149 qp->qpn, &qp->sq.db);
1150 if (qp->sq.db_index < 0)
1151 mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index);
1157 static void mthca_free_memfree(struct mthca_dev *dev,
1158 struct mthca_qp *qp)
1160 if (mthca_is_memfree(dev)) {
1161 mthca_free_db(dev, MTHCA_DB_TYPE_SQ, qp->sq.db_index);
1162 mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index);
1166 static void mthca_wq_init(struct mthca_wq* wq)
1168 spin_lock_init(&wq->lock);
1170 wq->last_comp = wq->max - 1;
1176 static int mthca_alloc_qp_common(struct mthca_dev *dev,
1177 struct mthca_pd *pd,
1178 struct mthca_cq *send_cq,
1179 struct mthca_cq *recv_cq,
1180 enum ib_sig_type send_policy,
1181 struct mthca_qp *qp)
1186 atomic_set(&qp->refcount, 1);
1187 qp->state = IB_QPS_RESET;
1188 qp->atomic_rd_en = 0;
1190 qp->sq_policy = send_policy;
1191 mthca_wq_init(&qp->sq);
1192 mthca_wq_init(&qp->rq);
1194 ret = mthca_map_memfree(dev, qp);
1198 ret = mthca_alloc_wqe_buf(dev, pd, qp);
1200 mthca_unmap_memfree(dev, qp);
1205 * If this is a userspace QP, we're done now. The doorbells
1206 * will be allocated and buffers will be initialized in
1209 if (pd->ibpd.uobject)
1212 ret = mthca_alloc_memfree(dev, qp);
1214 mthca_free_wqe_buf(dev, qp);
1215 mthca_unmap_memfree(dev, qp);
1219 if (mthca_is_memfree(dev)) {
1220 struct mthca_next_seg *next;
1221 struct mthca_data_seg *scatter;
1222 int size = (sizeof (struct mthca_next_seg) +
1223 qp->rq.max_gs * sizeof (struct mthca_data_seg)) / 16;
1225 for (i = 0; i < qp->rq.max; ++i) {
1226 next = get_recv_wqe(qp, i);
1227 next->nda_op = cpu_to_be32(((i + 1) & (qp->rq.max - 1)) <<
1229 next->ee_nds = cpu_to_be32(size);
1231 for (scatter = (void *) (next + 1);
1232 (void *) scatter < (void *) next + (1 << qp->rq.wqe_shift);
1234 scatter->lkey = cpu_to_be32(MTHCA_INVAL_LKEY);
1237 for (i = 0; i < qp->sq.max; ++i) {
1238 next = get_send_wqe(qp, i);
1239 next->nda_op = cpu_to_be32((((i + 1) & (qp->sq.max - 1)) <<
1241 qp->send_wqe_offset);
1248 static int mthca_set_qp_size(struct mthca_dev *dev, struct ib_qp_cap *cap,
1249 struct mthca_qp *qp)
1251 /* Sanity check QP size before proceeding */
1252 if (cap->max_send_wr > 65536 || cap->max_recv_wr > 65536 ||
1253 cap->max_send_sge > 64 || cap->max_recv_sge > 64)
1256 if (mthca_is_memfree(dev)) {
1257 qp->rq.max = cap->max_recv_wr ?
1258 roundup_pow_of_two(cap->max_recv_wr) : 0;
1259 qp->sq.max = cap->max_send_wr ?
1260 roundup_pow_of_two(cap->max_send_wr) : 0;
1262 qp->rq.max = cap->max_recv_wr;
1263 qp->sq.max = cap->max_send_wr;
1266 qp->rq.max_gs = cap->max_recv_sge;
1267 qp->sq.max_gs = max_t(int, cap->max_send_sge,
1268 ALIGN(cap->max_inline_data + MTHCA_INLINE_HEADER_SIZE,
1269 MTHCA_INLINE_CHUNK_SIZE) /
1270 sizeof (struct mthca_data_seg));
1273 * For MLX transport we need 2 extra S/G entries:
1274 * one for the header and one for the checksum at the end
1276 if ((qp->transport == MLX && qp->sq.max_gs + 2 > dev->limits.max_sg) ||
1277 qp->sq.max_gs > dev->limits.max_sg || qp->rq.max_gs > dev->limits.max_sg)
1283 int mthca_alloc_qp(struct mthca_dev *dev,
1284 struct mthca_pd *pd,
1285 struct mthca_cq *send_cq,
1286 struct mthca_cq *recv_cq,
1287 enum ib_qp_type type,
1288 enum ib_sig_type send_policy,
1289 struct ib_qp_cap *cap,
1290 struct mthca_qp *qp)
1294 err = mthca_set_qp_size(dev, cap, qp);
1299 case IB_QPT_RC: qp->transport = RC; break;
1300 case IB_QPT_UC: qp->transport = UC; break;
1301 case IB_QPT_UD: qp->transport = UD; break;
1302 default: return -EINVAL;
1305 qp->qpn = mthca_alloc(&dev->qp_table.alloc);
1309 err = mthca_alloc_qp_common(dev, pd, send_cq, recv_cq,
1312 mthca_free(&dev->qp_table.alloc, qp->qpn);
1316 spin_lock_irq(&dev->qp_table.lock);
1317 mthca_array_set(&dev->qp_table.qp,
1318 qp->qpn & (dev->limits.num_qps - 1), qp);
1319 spin_unlock_irq(&dev->qp_table.lock);
1324 int mthca_alloc_sqp(struct mthca_dev *dev,
1325 struct mthca_pd *pd,
1326 struct mthca_cq *send_cq,
1327 struct mthca_cq *recv_cq,
1328 enum ib_sig_type send_policy,
1329 struct ib_qp_cap *cap,
1332 struct mthca_sqp *sqp)
1334 u32 mqpn = qpn * 2 + dev->qp_table.sqp_start + port - 1;
1337 err = mthca_set_qp_size(dev, cap, &sqp->qp);
1341 sqp->header_buf_size = sqp->qp.sq.max * MTHCA_UD_HEADER_SIZE;
1342 sqp->header_buf = dma_alloc_coherent(&dev->pdev->dev, sqp->header_buf_size,
1343 &sqp->header_dma, GFP_KERNEL);
1344 if (!sqp->header_buf)
1347 spin_lock_irq(&dev->qp_table.lock);
1348 if (mthca_array_get(&dev->qp_table.qp, mqpn))
1351 mthca_array_set(&dev->qp_table.qp, mqpn, sqp);
1352 spin_unlock_irq(&dev->qp_table.lock);
1359 sqp->qp.transport = MLX;
1361 err = mthca_alloc_qp_common(dev, pd, send_cq, recv_cq,
1362 send_policy, &sqp->qp);
1366 atomic_inc(&pd->sqp_count);
1372 * Lock CQs here, so that CQ polling code can do QP lookup
1373 * without taking a lock.
1375 spin_lock_irq(&send_cq->lock);
1376 if (send_cq != recv_cq)
1377 spin_lock(&recv_cq->lock);
1379 spin_lock(&dev->qp_table.lock);
1380 mthca_array_clear(&dev->qp_table.qp, mqpn);
1381 spin_unlock(&dev->qp_table.lock);
1383 if (send_cq != recv_cq)
1384 spin_unlock(&recv_cq->lock);
1385 spin_unlock_irq(&send_cq->lock);
1388 dma_free_coherent(&dev->pdev->dev, sqp->header_buf_size,
1389 sqp->header_buf, sqp->header_dma);
1394 void mthca_free_qp(struct mthca_dev *dev,
1395 struct mthca_qp *qp)
1398 struct mthca_cq *send_cq;
1399 struct mthca_cq *recv_cq;
1401 send_cq = to_mcq(qp->ibqp.send_cq);
1402 recv_cq = to_mcq(qp->ibqp.recv_cq);
1405 * Lock CQs here, so that CQ polling code can do QP lookup
1406 * without taking a lock.
1408 spin_lock_irq(&send_cq->lock);
1409 if (send_cq != recv_cq)
1410 spin_lock(&recv_cq->lock);
1412 spin_lock(&dev->qp_table.lock);
1413 mthca_array_clear(&dev->qp_table.qp,
1414 qp->qpn & (dev->limits.num_qps - 1));
1415 spin_unlock(&dev->qp_table.lock);
1417 if (send_cq != recv_cq)
1418 spin_unlock(&recv_cq->lock);
1419 spin_unlock_irq(&send_cq->lock);
1421 atomic_dec(&qp->refcount);
1422 wait_event(qp->wait, !atomic_read(&qp->refcount));
1424 if (qp->state != IB_QPS_RESET)
1425 mthca_MODIFY_QP(dev, MTHCA_TRANS_ANY2RST, qp->qpn, 0, NULL, 0, &status);
1428 * If this is a userspace QP, the buffers, MR, CQs and so on
1429 * will be cleaned up in userspace, so all we have to do is
1430 * unref the mem-free tables and free the QPN in our table.
1432 if (!qp->ibqp.uobject) {
1433 mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn);
1434 if (qp->ibqp.send_cq != qp->ibqp.recv_cq)
1435 mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq)->cqn, qp->qpn);
1437 mthca_free_mr(dev, &qp->mr);
1438 mthca_free_memfree(dev, qp);
1439 mthca_free_wqe_buf(dev, qp);
1442 mthca_unmap_memfree(dev, qp);
1444 if (is_sqp(dev, qp)) {
1445 atomic_dec(&(to_mpd(qp->ibqp.pd)->sqp_count));
1446 dma_free_coherent(&dev->pdev->dev,
1447 to_msqp(qp)->header_buf_size,
1448 to_msqp(qp)->header_buf,
1449 to_msqp(qp)->header_dma);
1451 mthca_free(&dev->qp_table.alloc, qp->qpn);
1454 /* Create UD header for an MLX send and build a data segment for it */
1455 static int build_mlx_header(struct mthca_dev *dev, struct mthca_sqp *sqp,
1456 int ind, struct ib_send_wr *wr,
1457 struct mthca_mlx_seg *mlx,
1458 struct mthca_data_seg *data)
1463 ib_ud_header_init(256, /* assume a MAD */
1464 sqp->ud_header.grh_present,
1467 err = mthca_read_ah(dev, to_mah(wr->wr.ud.ah), &sqp->ud_header);
1470 mlx->flags &= ~cpu_to_be32(MTHCA_NEXT_SOLICIT | 1);
1471 mlx->flags |= cpu_to_be32((!sqp->qp.ibqp.qp_num ? MTHCA_MLX_VL15 : 0) |
1472 (sqp->ud_header.lrh.destination_lid == 0xffff ?
1473 MTHCA_MLX_SLR : 0) |
1474 (sqp->ud_header.lrh.service_level << 8));
1475 mlx->rlid = sqp->ud_header.lrh.destination_lid;
1478 switch (wr->opcode) {
1480 sqp->ud_header.bth.opcode = IB_OPCODE_UD_SEND_ONLY;
1481 sqp->ud_header.immediate_present = 0;
1483 case IB_WR_SEND_WITH_IMM:
1484 sqp->ud_header.bth.opcode = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE;
1485 sqp->ud_header.immediate_present = 1;
1486 sqp->ud_header.immediate_data = wr->imm_data;
1492 sqp->ud_header.lrh.virtual_lane = !sqp->qp.ibqp.qp_num ? 15 : 0;
1493 if (sqp->ud_header.lrh.destination_lid == 0xffff)
1494 sqp->ud_header.lrh.source_lid = 0xffff;
1495 sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED);
1496 if (!sqp->qp.ibqp.qp_num)
1497 ib_get_cached_pkey(&dev->ib_dev, sqp->port,
1499 &sqp->ud_header.bth.pkey);
1501 ib_get_cached_pkey(&dev->ib_dev, sqp->port,
1502 wr->wr.ud.pkey_index,
1503 &sqp->ud_header.bth.pkey);
1504 cpu_to_be16s(&sqp->ud_header.bth.pkey);
1505 sqp->ud_header.bth.destination_qpn = cpu_to_be32(wr->wr.ud.remote_qpn);
1506 sqp->ud_header.bth.psn = cpu_to_be32((sqp->send_psn++) & ((1 << 24) - 1));
1507 sqp->ud_header.deth.qkey = cpu_to_be32(wr->wr.ud.remote_qkey & 0x80000000 ?
1508 sqp->qkey : wr->wr.ud.remote_qkey);
1509 sqp->ud_header.deth.source_qpn = cpu_to_be32(sqp->qp.ibqp.qp_num);
1511 header_size = ib_ud_header_pack(&sqp->ud_header,
1513 ind * MTHCA_UD_HEADER_SIZE);
1515 data->byte_count = cpu_to_be32(header_size);
1516 data->lkey = cpu_to_be32(to_mpd(sqp->qp.ibqp.pd)->ntmr.ibmr.lkey);
1517 data->addr = cpu_to_be64(sqp->header_dma +
1518 ind * MTHCA_UD_HEADER_SIZE);
1523 static inline int mthca_wq_overflow(struct mthca_wq *wq, int nreq,
1524 struct ib_cq *ib_cq)
1527 struct mthca_cq *cq;
1529 cur = wq->head - wq->tail;
1530 if (likely(cur + nreq < wq->max))
1534 spin_lock(&cq->lock);
1535 cur = wq->head - wq->tail;
1536 spin_unlock(&cq->lock);
1538 return cur + nreq >= wq->max;
1541 int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1542 struct ib_send_wr **bad_wr)
1544 struct mthca_dev *dev = to_mdev(ibqp->device);
1545 struct mthca_qp *qp = to_mqp(ibqp);
1548 unsigned long flags;
1558 spin_lock_irqsave(&qp->sq.lock, flags);
1560 /* XXX check that state is OK to post send */
1562 ind = qp->sq.next_ind;
1564 for (nreq = 0; wr; ++nreq, wr = wr->next) {
1565 if (mthca_wq_overflow(&qp->sq, nreq, qp->ibqp.send_cq)) {
1566 mthca_err(dev, "SQ %06x full (%u head, %u tail,"
1567 " %d max, %d nreq)\n", qp->qpn,
1568 qp->sq.head, qp->sq.tail,
1575 wqe = get_send_wqe(qp, ind);
1576 prev_wqe = qp->sq.last;
1579 ((struct mthca_next_seg *) wqe)->nda_op = 0;
1580 ((struct mthca_next_seg *) wqe)->ee_nds = 0;
1581 ((struct mthca_next_seg *) wqe)->flags =
1582 ((wr->send_flags & IB_SEND_SIGNALED) ?
1583 cpu_to_be32(MTHCA_NEXT_CQ_UPDATE) : 0) |
1584 ((wr->send_flags & IB_SEND_SOLICITED) ?
1585 cpu_to_be32(MTHCA_NEXT_SOLICIT) : 0) |
1587 if (wr->opcode == IB_WR_SEND_WITH_IMM ||
1588 wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM)
1589 ((struct mthca_next_seg *) wqe)->imm = wr->imm_data;
1591 wqe += sizeof (struct mthca_next_seg);
1592 size = sizeof (struct mthca_next_seg) / 16;
1594 switch (qp->transport) {
1596 switch (wr->opcode) {
1597 case IB_WR_ATOMIC_CMP_AND_SWP:
1598 case IB_WR_ATOMIC_FETCH_AND_ADD:
1599 ((struct mthca_raddr_seg *) wqe)->raddr =
1600 cpu_to_be64(wr->wr.atomic.remote_addr);
1601 ((struct mthca_raddr_seg *) wqe)->rkey =
1602 cpu_to_be32(wr->wr.atomic.rkey);
1603 ((struct mthca_raddr_seg *) wqe)->reserved = 0;
1605 wqe += sizeof (struct mthca_raddr_seg);
1607 if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
1608 ((struct mthca_atomic_seg *) wqe)->swap_add =
1609 cpu_to_be64(wr->wr.atomic.swap);
1610 ((struct mthca_atomic_seg *) wqe)->compare =
1611 cpu_to_be64(wr->wr.atomic.compare_add);
1613 ((struct mthca_atomic_seg *) wqe)->swap_add =
1614 cpu_to_be64(wr->wr.atomic.compare_add);
1615 ((struct mthca_atomic_seg *) wqe)->compare = 0;
1618 wqe += sizeof (struct mthca_atomic_seg);
1619 size += sizeof (struct mthca_raddr_seg) / 16 +
1620 sizeof (struct mthca_atomic_seg);
1623 case IB_WR_RDMA_WRITE:
1624 case IB_WR_RDMA_WRITE_WITH_IMM:
1625 case IB_WR_RDMA_READ:
1626 ((struct mthca_raddr_seg *) wqe)->raddr =
1627 cpu_to_be64(wr->wr.rdma.remote_addr);
1628 ((struct mthca_raddr_seg *) wqe)->rkey =
1629 cpu_to_be32(wr->wr.rdma.rkey);
1630 ((struct mthca_raddr_seg *) wqe)->reserved = 0;
1631 wqe += sizeof (struct mthca_raddr_seg);
1632 size += sizeof (struct mthca_raddr_seg) / 16;
1636 /* No extra segments required for sends */
1643 switch (wr->opcode) {
1644 case IB_WR_RDMA_WRITE:
1645 case IB_WR_RDMA_WRITE_WITH_IMM:
1646 ((struct mthca_raddr_seg *) wqe)->raddr =
1647 cpu_to_be64(wr->wr.rdma.remote_addr);
1648 ((struct mthca_raddr_seg *) wqe)->rkey =
1649 cpu_to_be32(wr->wr.rdma.rkey);
1650 ((struct mthca_raddr_seg *) wqe)->reserved = 0;
1651 wqe += sizeof (struct mthca_raddr_seg);
1652 size += sizeof (struct mthca_raddr_seg) / 16;
1656 /* No extra segments required for sends */
1663 ((struct mthca_tavor_ud_seg *) wqe)->lkey =
1664 cpu_to_be32(to_mah(wr->wr.ud.ah)->key);
1665 ((struct mthca_tavor_ud_seg *) wqe)->av_addr =
1666 cpu_to_be64(to_mah(wr->wr.ud.ah)->avdma);
1667 ((struct mthca_tavor_ud_seg *) wqe)->dqpn =
1668 cpu_to_be32(wr->wr.ud.remote_qpn);
1669 ((struct mthca_tavor_ud_seg *) wqe)->qkey =
1670 cpu_to_be32(wr->wr.ud.remote_qkey);
1672 wqe += sizeof (struct mthca_tavor_ud_seg);
1673 size += sizeof (struct mthca_tavor_ud_seg) / 16;
1677 err = build_mlx_header(dev, to_msqp(qp), ind, wr,
1678 wqe - sizeof (struct mthca_next_seg),
1684 wqe += sizeof (struct mthca_data_seg);
1685 size += sizeof (struct mthca_data_seg) / 16;
1689 if (wr->num_sge > qp->sq.max_gs) {
1690 mthca_err(dev, "too many gathers\n");
1696 for (i = 0; i < wr->num_sge; ++i) {
1697 ((struct mthca_data_seg *) wqe)->byte_count =
1698 cpu_to_be32(wr->sg_list[i].length);
1699 ((struct mthca_data_seg *) wqe)->lkey =
1700 cpu_to_be32(wr->sg_list[i].lkey);
1701 ((struct mthca_data_seg *) wqe)->addr =
1702 cpu_to_be64(wr->sg_list[i].addr);
1703 wqe += sizeof (struct mthca_data_seg);
1704 size += sizeof (struct mthca_data_seg) / 16;
1707 /* Add one more inline data segment for ICRC */
1708 if (qp->transport == MLX) {
1709 ((struct mthca_data_seg *) wqe)->byte_count =
1710 cpu_to_be32((1 << 31) | 4);
1711 ((u32 *) wqe)[1] = 0;
1712 wqe += sizeof (struct mthca_data_seg);
1713 size += sizeof (struct mthca_data_seg) / 16;
1716 qp->wrid[ind + qp->rq.max] = wr->wr_id;
1718 if (wr->opcode >= ARRAY_SIZE(mthca_opcode)) {
1719 mthca_err(dev, "opcode invalid\n");
1726 ((struct mthca_next_seg *) prev_wqe)->nda_op =
1727 cpu_to_be32(((ind << qp->sq.wqe_shift) +
1728 qp->send_wqe_offset) |
1729 mthca_opcode[wr->opcode]);
1731 ((struct mthca_next_seg *) prev_wqe)->ee_nds =
1732 cpu_to_be32((size0 ? 0 : MTHCA_NEXT_DBD) | size);
1737 op0 = mthca_opcode[wr->opcode];
1741 if (unlikely(ind >= qp->sq.max))
1749 doorbell[0] = cpu_to_be32(((qp->sq.next_ind << qp->sq.wqe_shift) +
1750 qp->send_wqe_offset) | f0 | op0);
1751 doorbell[1] = cpu_to_be32((qp->qpn << 8) | size0);
1755 mthca_write64(doorbell,
1756 dev->kar + MTHCA_SEND_DOORBELL,
1757 MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
1760 qp->sq.next_ind = ind;
1761 qp->sq.head += nreq;
1763 spin_unlock_irqrestore(&qp->sq.lock, flags);
1767 int mthca_tavor_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
1768 struct ib_recv_wr **bad_wr)
1770 struct mthca_dev *dev = to_mdev(ibqp->device);
1771 struct mthca_qp *qp = to_mqp(ibqp);
1772 unsigned long flags;
1782 spin_lock_irqsave(&qp->rq.lock, flags);
1784 /* XXX check that state is OK to post receive */
1786 ind = qp->rq.next_ind;
1788 for (nreq = 0; wr; ++nreq, wr = wr->next) {
1789 if (mthca_wq_overflow(&qp->rq, nreq, qp->ibqp.recv_cq)) {
1790 mthca_err(dev, "RQ %06x full (%u head, %u tail,"
1791 " %d max, %d nreq)\n", qp->qpn,
1792 qp->rq.head, qp->rq.tail,
1799 wqe = get_recv_wqe(qp, ind);
1800 prev_wqe = qp->rq.last;
1803 ((struct mthca_next_seg *) wqe)->nda_op = 0;
1804 ((struct mthca_next_seg *) wqe)->ee_nds =
1805 cpu_to_be32(MTHCA_NEXT_DBD);
1806 ((struct mthca_next_seg *) wqe)->flags = 0;
1808 wqe += sizeof (struct mthca_next_seg);
1809 size = sizeof (struct mthca_next_seg) / 16;
1811 if (unlikely(wr->num_sge > qp->rq.max_gs)) {
1817 for (i = 0; i < wr->num_sge; ++i) {
1818 ((struct mthca_data_seg *) wqe)->byte_count =
1819 cpu_to_be32(wr->sg_list[i].length);
1820 ((struct mthca_data_seg *) wqe)->lkey =
1821 cpu_to_be32(wr->sg_list[i].lkey);
1822 ((struct mthca_data_seg *) wqe)->addr =
1823 cpu_to_be64(wr->sg_list[i].addr);
1824 wqe += sizeof (struct mthca_data_seg);
1825 size += sizeof (struct mthca_data_seg) / 16;
1828 qp->wrid[ind] = wr->wr_id;
1830 if (likely(prev_wqe)) {
1831 ((struct mthca_next_seg *) prev_wqe)->nda_op =
1832 cpu_to_be32((ind << qp->rq.wqe_shift) | 1);
1834 ((struct mthca_next_seg *) prev_wqe)->ee_nds =
1835 cpu_to_be32(MTHCA_NEXT_DBD | size);
1842 if (unlikely(ind >= qp->rq.max))
1850 doorbell[0] = cpu_to_be32((qp->rq.next_ind << qp->rq.wqe_shift) | size0);
1851 doorbell[1] = cpu_to_be32((qp->qpn << 8) | nreq);
1855 mthca_write64(doorbell,
1856 dev->kar + MTHCA_RECEIVE_DOORBELL,
1857 MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
1860 qp->rq.next_ind = ind;
1861 qp->rq.head += nreq;
1863 spin_unlock_irqrestore(&qp->rq.lock, flags);
1867 int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1868 struct ib_send_wr **bad_wr)
1870 struct mthca_dev *dev = to_mdev(ibqp->device);
1871 struct mthca_qp *qp = to_mqp(ibqp);
1874 unsigned long flags;
1884 spin_lock_irqsave(&qp->sq.lock, flags);
1886 /* XXX check that state is OK to post send */
1888 ind = qp->sq.head & (qp->sq.max - 1);
1890 for (nreq = 0; wr; ++nreq, wr = wr->next) {
1891 if (mthca_wq_overflow(&qp->sq, nreq, qp->ibqp.send_cq)) {
1892 mthca_err(dev, "SQ %06x full (%u head, %u tail,"
1893 " %d max, %d nreq)\n", qp->qpn,
1894 qp->sq.head, qp->sq.tail,
1901 wqe = get_send_wqe(qp, ind);
1902 prev_wqe = qp->sq.last;
1905 ((struct mthca_next_seg *) wqe)->flags =
1906 ((wr->send_flags & IB_SEND_SIGNALED) ?
1907 cpu_to_be32(MTHCA_NEXT_CQ_UPDATE) : 0) |
1908 ((wr->send_flags & IB_SEND_SOLICITED) ?
1909 cpu_to_be32(MTHCA_NEXT_SOLICIT) : 0) |
1911 if (wr->opcode == IB_WR_SEND_WITH_IMM ||
1912 wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM)
1913 ((struct mthca_next_seg *) wqe)->imm = wr->imm_data;
1915 wqe += sizeof (struct mthca_next_seg);
1916 size = sizeof (struct mthca_next_seg) / 16;
1918 switch (qp->transport) {
1920 switch (wr->opcode) {
1921 case IB_WR_ATOMIC_CMP_AND_SWP:
1922 case IB_WR_ATOMIC_FETCH_AND_ADD:
1923 ((struct mthca_raddr_seg *) wqe)->raddr =
1924 cpu_to_be64(wr->wr.atomic.remote_addr);
1925 ((struct mthca_raddr_seg *) wqe)->rkey =
1926 cpu_to_be32(wr->wr.atomic.rkey);
1927 ((struct mthca_raddr_seg *) wqe)->reserved = 0;
1929 wqe += sizeof (struct mthca_raddr_seg);
1931 if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
1932 ((struct mthca_atomic_seg *) wqe)->swap_add =
1933 cpu_to_be64(wr->wr.atomic.swap);
1934 ((struct mthca_atomic_seg *) wqe)->compare =
1935 cpu_to_be64(wr->wr.atomic.compare_add);
1937 ((struct mthca_atomic_seg *) wqe)->swap_add =
1938 cpu_to_be64(wr->wr.atomic.compare_add);
1939 ((struct mthca_atomic_seg *) wqe)->compare = 0;
1942 wqe += sizeof (struct mthca_atomic_seg);
1943 size += sizeof (struct mthca_raddr_seg) / 16 +
1944 sizeof (struct mthca_atomic_seg);
1947 case IB_WR_RDMA_READ:
1948 case IB_WR_RDMA_WRITE:
1949 case IB_WR_RDMA_WRITE_WITH_IMM:
1950 ((struct mthca_raddr_seg *) wqe)->raddr =
1951 cpu_to_be64(wr->wr.rdma.remote_addr);
1952 ((struct mthca_raddr_seg *) wqe)->rkey =
1953 cpu_to_be32(wr->wr.rdma.rkey);
1954 ((struct mthca_raddr_seg *) wqe)->reserved = 0;
1955 wqe += sizeof (struct mthca_raddr_seg);
1956 size += sizeof (struct mthca_raddr_seg) / 16;
1960 /* No extra segments required for sends */
1967 switch (wr->opcode) {
1968 case IB_WR_RDMA_WRITE:
1969 case IB_WR_RDMA_WRITE_WITH_IMM:
1970 ((struct mthca_raddr_seg *) wqe)->raddr =
1971 cpu_to_be64(wr->wr.rdma.remote_addr);
1972 ((struct mthca_raddr_seg *) wqe)->rkey =
1973 cpu_to_be32(wr->wr.rdma.rkey);
1974 ((struct mthca_raddr_seg *) wqe)->reserved = 0;
1975 wqe += sizeof (struct mthca_raddr_seg);
1976 size += sizeof (struct mthca_raddr_seg) / 16;
1980 /* No extra segments required for sends */
1987 memcpy(((struct mthca_arbel_ud_seg *) wqe)->av,
1988 to_mah(wr->wr.ud.ah)->av, MTHCA_AV_SIZE);
1989 ((struct mthca_arbel_ud_seg *) wqe)->dqpn =
1990 cpu_to_be32(wr->wr.ud.remote_qpn);
1991 ((struct mthca_arbel_ud_seg *) wqe)->qkey =
1992 cpu_to_be32(wr->wr.ud.remote_qkey);
1994 wqe += sizeof (struct mthca_arbel_ud_seg);
1995 size += sizeof (struct mthca_arbel_ud_seg) / 16;
1999 err = build_mlx_header(dev, to_msqp(qp), ind, wr,
2000 wqe - sizeof (struct mthca_next_seg),
2006 wqe += sizeof (struct mthca_data_seg);
2007 size += sizeof (struct mthca_data_seg) / 16;
2011 if (wr->num_sge > qp->sq.max_gs) {
2012 mthca_err(dev, "too many gathers\n");
2018 for (i = 0; i < wr->num_sge; ++i) {
2019 ((struct mthca_data_seg *) wqe)->byte_count =
2020 cpu_to_be32(wr->sg_list[i].length);
2021 ((struct mthca_data_seg *) wqe)->lkey =
2022 cpu_to_be32(wr->sg_list[i].lkey);
2023 ((struct mthca_data_seg *) wqe)->addr =
2024 cpu_to_be64(wr->sg_list[i].addr);
2025 wqe += sizeof (struct mthca_data_seg);
2026 size += sizeof (struct mthca_data_seg) / 16;
2029 /* Add one more inline data segment for ICRC */
2030 if (qp->transport == MLX) {
2031 ((struct mthca_data_seg *) wqe)->byte_count =
2032 cpu_to_be32((1 << 31) | 4);
2033 ((u32 *) wqe)[1] = 0;
2034 wqe += sizeof (struct mthca_data_seg);
2035 size += sizeof (struct mthca_data_seg) / 16;
2038 qp->wrid[ind + qp->rq.max] = wr->wr_id;
2040 if (wr->opcode >= ARRAY_SIZE(mthca_opcode)) {
2041 mthca_err(dev, "opcode invalid\n");
2047 if (likely(prev_wqe)) {
2048 ((struct mthca_next_seg *) prev_wqe)->nda_op =
2049 cpu_to_be32(((ind << qp->sq.wqe_shift) +
2050 qp->send_wqe_offset) |
2051 mthca_opcode[wr->opcode]);
2053 ((struct mthca_next_seg *) prev_wqe)->ee_nds =
2054 cpu_to_be32(MTHCA_NEXT_DBD | size);
2059 op0 = mthca_opcode[wr->opcode];
2063 if (unlikely(ind >= qp->sq.max))
2071 doorbell[0] = cpu_to_be32((nreq << 24) |
2072 ((qp->sq.head & 0xffff) << 8) |
2074 doorbell[1] = cpu_to_be32((qp->qpn << 8) | size0);
2076 qp->sq.head += nreq;
2079 * Make sure that descriptors are written before
2083 *qp->sq.db = cpu_to_be32(qp->sq.head & 0xffff);
2086 * Make sure doorbell record is written before we
2087 * write MMIO send doorbell.
2090 mthca_write64(doorbell,
2091 dev->kar + MTHCA_SEND_DOORBELL,
2092 MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
2095 spin_unlock_irqrestore(&qp->sq.lock, flags);
2099 int mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
2100 struct ib_recv_wr **bad_wr)
2102 struct mthca_dev *dev = to_mdev(ibqp->device);
2103 struct mthca_qp *qp = to_mqp(ibqp);
2104 unsigned long flags;
2111 spin_lock_irqsave(&qp->rq.lock, flags);
2113 /* XXX check that state is OK to post receive */
2115 ind = qp->rq.head & (qp->rq.max - 1);
2117 for (nreq = 0; wr; ++nreq, wr = wr->next) {
2118 if (mthca_wq_overflow(&qp->rq, nreq, qp->ibqp.recv_cq)) {
2119 mthca_err(dev, "RQ %06x full (%u head, %u tail,"
2120 " %d max, %d nreq)\n", qp->qpn,
2121 qp->rq.head, qp->rq.tail,
2128 wqe = get_recv_wqe(qp, ind);
2130 ((struct mthca_next_seg *) wqe)->flags = 0;
2132 wqe += sizeof (struct mthca_next_seg);
2134 if (unlikely(wr->num_sge > qp->rq.max_gs)) {
2140 for (i = 0; i < wr->num_sge; ++i) {
2141 ((struct mthca_data_seg *) wqe)->byte_count =
2142 cpu_to_be32(wr->sg_list[i].length);
2143 ((struct mthca_data_seg *) wqe)->lkey =
2144 cpu_to_be32(wr->sg_list[i].lkey);
2145 ((struct mthca_data_seg *) wqe)->addr =
2146 cpu_to_be64(wr->sg_list[i].addr);
2147 wqe += sizeof (struct mthca_data_seg);
2150 if (i < qp->rq.max_gs) {
2151 ((struct mthca_data_seg *) wqe)->byte_count = 0;
2152 ((struct mthca_data_seg *) wqe)->lkey = cpu_to_be32(MTHCA_INVAL_LKEY);
2153 ((struct mthca_data_seg *) wqe)->addr = 0;
2156 qp->wrid[ind] = wr->wr_id;
2159 if (unlikely(ind >= qp->rq.max))
2164 qp->rq.head += nreq;
2167 * Make sure that descriptors are written before
2171 *qp->rq.db = cpu_to_be32(qp->rq.head & 0xffff);
2174 spin_unlock_irqrestore(&qp->rq.lock, flags);
2178 int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,
2179 int index, int *dbd, u32 *new_wqe)
2181 struct mthca_next_seg *next;
2184 next = get_send_wqe(qp, index);
2186 next = get_recv_wqe(qp, index);
2188 if (mthca_is_memfree(dev))
2191 *dbd = !!(next->ee_nds & cpu_to_be32(MTHCA_NEXT_DBD));
2192 if (next->ee_nds & cpu_to_be32(0x3f))
2193 *new_wqe = (next->nda_op & cpu_to_be32(~0x3f)) |
2194 (next->ee_nds & cpu_to_be32(0x3f));
2201 int __devinit mthca_init_qp_table(struct mthca_dev *dev)
2207 spin_lock_init(&dev->qp_table.lock);
2210 * We reserve 2 extra QPs per port for the special QPs. The
2211 * special QP for port 1 has to be even, so round up.
2213 dev->qp_table.sqp_start = (dev->limits.reserved_qps + 1) & ~1UL;
2214 err = mthca_alloc_init(&dev->qp_table.alloc,
2215 dev->limits.num_qps,
2217 dev->qp_table.sqp_start +
2218 MTHCA_MAX_PORTS * 2);
2222 err = mthca_array_init(&dev->qp_table.qp,
2223 dev->limits.num_qps);
2225 mthca_alloc_cleanup(&dev->qp_table.alloc);
2229 for (i = 0; i < 2; ++i) {
2230 err = mthca_CONF_SPECIAL_QP(dev, i ? IB_QPT_GSI : IB_QPT_SMI,
2231 dev->qp_table.sqp_start + i * 2,
2236 mthca_warn(dev, "CONF_SPECIAL_QP returned "
2237 "status %02x, aborting.\n",
2246 for (i = 0; i < 2; ++i)
2247 mthca_CONF_SPECIAL_QP(dev, i, 0, &status);
2249 mthca_array_cleanup(&dev->qp_table.qp, dev->limits.num_qps);
2250 mthca_alloc_cleanup(&dev->qp_table.alloc);
2255 void __devexit mthca_cleanup_qp_table(struct mthca_dev *dev)
2260 for (i = 0; i < 2; ++i)
2261 mthca_CONF_SPECIAL_QP(dev, i, 0, &status);
2263 mthca_alloc_cleanup(&dev->qp_table.alloc);