2 * IBM eServer eHCA Infiniband device driver for Linux on POWER
6 * Authors: Waleri Fomin <fomin@de.ibm.com>
7 * Hoang-Nam Nguyen <hnguyen@de.ibm.com>
8 * Reinhard Ernst <rernst@de.ibm.com>
9 * Heiko J Schick <schickhj@de.ibm.com>
11 * Copyright (c) 2005 IBM Corporation
13 * All rights reserved.
15 * This source code is distributed under a dual license of GPL v2.0 and OpenIB
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are met:
23 * Redistributions of source code must retain the above copyright notice, this
24 * list of conditions and the following disclaimer.
26 * Redistributions in binary form must reproduce the above copyright notice,
27 * this list of conditions and the following disclaimer in the documentation
28 * and/or other materials
29 * provided with the distribution.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
35 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGE.
45 #include <asm/current.h>
47 #include "ehca_classes.h"
48 #include "ehca_tools.h"
50 #include "ehca_iverbs.h"
54 static struct kmem_cache *qp_cache;
57 * attributes not supported by query qp
59 #define QP_ATTR_QUERY_NOT_SUPPORTED (IB_QP_MAX_DEST_RD_ATOMIC | \
60 IB_QP_MAX_QP_RD_ATOMIC | \
61 IB_QP_ACCESS_FLAGS | \
62 IB_QP_EN_SQD_ASYNC_NOTIFY)
65 * ehca (internal) qp state values
78 * qp state transitions as defined by IB Arch Rel 1.1 page 431
80 enum ib_qp_statetrans {
92 IB_QPST_MAX /* nr of transitions, this must be last!!! */
96 * ib2ehca_qp_state maps IB to ehca qp_state
97 * returns ehca qp state corresponding to given ib qp state
99 static inline enum ehca_qp_state ib2ehca_qp_state(enum ib_qp_state ib_qp_state)
101 switch (ib_qp_state) {
103 return EHCA_QPS_RESET;
105 return EHCA_QPS_INIT;
117 ehca_gen_err("invalid ib_qp_state=%x", ib_qp_state);
123 * ehca2ib_qp_state maps ehca to IB qp_state
124 * returns ib qp state corresponding to given ehca qp state
126 static inline enum ib_qp_state ehca2ib_qp_state(enum ehca_qp_state
129 switch (ehca_qp_state) {
145 ehca_gen_err("invalid ehca_qp_state=%x", ehca_qp_state);
151 * ehca_qp_type used as index for req_attr and opt_attr of
152 * struct ehca_modqp_statetrans
163 * ib2ehcaqptype maps Ib to ehca qp_type
164 * returns ehca qp type corresponding to ib qp type
166 static inline enum ehca_qp_type ib2ehcaqptype(enum ib_qp_type ibqptype)
179 ehca_gen_err("Invalid ibqptype=%x", ibqptype);
184 static inline enum ib_qp_statetrans get_modqp_statetrans(int ib_fromstate,
188 switch (ib_tostate) {
190 index = IB_QPST_ANY2RESET;
193 switch (ib_fromstate) {
195 index = IB_QPST_RESET2INIT;
198 index = IB_QPST_INIT2INIT;
203 if (ib_fromstate == IB_QPS_INIT)
204 index = IB_QPST_INIT2RTR;
207 switch (ib_fromstate) {
209 index = IB_QPST_RTR2RTS;
212 index = IB_QPST_RTS2RTS;
215 index = IB_QPST_SQD2RTS;
218 index = IB_QPST_SQE2RTS;
223 if (ib_fromstate == IB_QPS_RTS)
224 index = IB_QPST_RTS2SQD;
229 index = IB_QPST_ANY2ERR;
237 enum ehca_service_type {
245 * ibqptype2servicetype returns hcp service type corresponding to given
246 * ib qp type used by create_qp()
248 static inline int ibqptype2servicetype(enum ib_qp_type ibqptype)
260 case IB_QPT_RAW_IPV6:
265 ehca_gen_err("Invalid ibqptype=%x", ibqptype);
271 * init_qp_queues initializes/constructs r/squeue and registers queue pages.
273 static inline int init_qp_queues(struct ehca_shca *shca,
274 struct ehca_qp *my_qp,
279 int nr_send_sges, int nr_receive_sges)
281 int ret, cnt, ipz_rc;
284 struct ib_device *ib_dev = &shca->ib_device;
285 struct ipz_adapter_handle ipz_hca_handle = shca->ipz_hca_handle;
287 ipz_rc = ipz_queue_ctor(&my_qp->ipz_squeue,
289 EHCA_PAGESIZE, swqe_size, nr_send_sges);
291 ehca_err(ib_dev,"Cannot allocate page for squeue. ipz_rc=%x",
296 ipz_rc = ipz_queue_ctor(&my_qp->ipz_rqueue,
298 EHCA_PAGESIZE, rwqe_size, nr_receive_sges);
300 ehca_err(ib_dev, "Cannot allocate page for rqueue. ipz_rc=%x",
303 goto init_qp_queues0;
305 /* register SQ pages */
306 for (cnt = 0; cnt < nr_sq_pages; cnt++) {
307 vpage = ipz_qpageit_get_inc(&my_qp->ipz_squeue);
309 ehca_err(ib_dev, "SQ ipz_qpageit_get_inc() "
310 "failed p_vpage= %p", vpage);
312 goto init_qp_queues1;
314 rpage = virt_to_abs(vpage);
316 h_ret = hipz_h_register_rpage_qp(ipz_hca_handle,
317 my_qp->ipz_qp_handle,
320 my_qp->galpas.kernel);
321 if (h_ret < H_SUCCESS) {
322 ehca_err(ib_dev, "SQ hipz_qp_register_rpage()"
323 " failed rc=%lx", h_ret);
324 ret = ehca2ib_return_code(h_ret);
325 goto init_qp_queues1;
329 ipz_qeit_reset(&my_qp->ipz_squeue);
331 /* register RQ pages */
332 for (cnt = 0; cnt < nr_rq_pages; cnt++) {
333 vpage = ipz_qpageit_get_inc(&my_qp->ipz_rqueue);
335 ehca_err(ib_dev, "RQ ipz_qpageit_get_inc() "
336 "failed p_vpage = %p", vpage);
338 goto init_qp_queues1;
341 rpage = virt_to_abs(vpage);
343 h_ret = hipz_h_register_rpage_qp(ipz_hca_handle,
344 my_qp->ipz_qp_handle,
346 rpage, 1,my_qp->galpas.kernel);
347 if (h_ret < H_SUCCESS) {
348 ehca_err(ib_dev, "RQ hipz_qp_register_rpage() failed "
350 ret = ehca2ib_return_code(h_ret);
351 goto init_qp_queues1;
353 if (cnt == (nr_rq_pages - 1)) { /* last page! */
354 if (h_ret != H_SUCCESS) {
355 ehca_err(ib_dev, "RQ hipz_qp_register_rpage() "
356 "h_ret= %lx ", h_ret);
357 ret = ehca2ib_return_code(h_ret);
358 goto init_qp_queues1;
360 vpage = ipz_qpageit_get_inc(&my_qp->ipz_rqueue);
362 ehca_err(ib_dev, "ipz_qpageit_get_inc() "
363 "should not succeed vpage=%p", vpage);
365 goto init_qp_queues1;
368 if (h_ret != H_PAGE_REGISTERED) {
369 ehca_err(ib_dev, "RQ hipz_qp_register_rpage() "
370 "h_ret= %lx ", h_ret);
371 ret = ehca2ib_return_code(h_ret);
372 goto init_qp_queues1;
377 ipz_qeit_reset(&my_qp->ipz_rqueue);
382 ipz_queue_dtor(&my_qp->ipz_rqueue);
384 ipz_queue_dtor(&my_qp->ipz_squeue);
388 struct ib_qp *ehca_create_qp(struct ib_pd *pd,
389 struct ib_qp_init_attr *init_attr,
390 struct ib_udata *udata)
392 static int da_rc_msg_size[]={ 128, 256, 512, 1024, 2048, 4096 };
393 static int da_ud_sq_msg_size[]={ 128, 384, 896, 1920, 3968 };
394 struct ehca_qp *my_qp;
395 struct ehca_pd *my_pd = container_of(pd, struct ehca_pd, ib_pd);
396 struct ehca_shca *shca = container_of(pd->device, struct ehca_shca,
398 struct ib_ucontext *context = NULL;
400 int max_send_sge, max_recv_sge, ret;
402 /* h_call's out parameters */
403 struct ehca_alloc_qp_parms parms;
404 u32 swqe_size = 0, rwqe_size = 0;
405 u8 daqp_completion, isdaqp;
408 if (init_attr->sq_sig_type != IB_SIGNAL_REQ_WR &&
409 init_attr->sq_sig_type != IB_SIGNAL_ALL_WR) {
410 ehca_err(pd->device, "init_attr->sg_sig_type=%x not allowed",
411 init_attr->sq_sig_type);
412 return ERR_PTR(-EINVAL);
415 /* save daqp completion bits */
416 daqp_completion = init_attr->qp_type & 0x60;
418 isdaqp = (init_attr->qp_type & 0x80) ? 1 : 0;
419 init_attr->qp_type = init_attr->qp_type & 0x1F;
421 if (init_attr->qp_type != IB_QPT_UD &&
422 init_attr->qp_type != IB_QPT_SMI &&
423 init_attr->qp_type != IB_QPT_GSI &&
424 init_attr->qp_type != IB_QPT_UC &&
425 init_attr->qp_type != IB_QPT_RC) {
426 ehca_err(pd->device, "wrong QP Type=%x", init_attr->qp_type);
427 return ERR_PTR(-EINVAL);
429 if ((init_attr->qp_type != IB_QPT_RC && init_attr->qp_type != IB_QPT_UD)
431 ehca_err(pd->device, "unsupported LL QP Type=%x",
433 return ERR_PTR(-EINVAL);
434 } else if (init_attr->qp_type == IB_QPT_RC && isdaqp &&
435 (init_attr->cap.max_send_wr > 255 ||
436 init_attr->cap.max_recv_wr > 255 )) {
437 ehca_err(pd->device, "Invalid Number of max_sq_wr =%x "
438 "or max_rq_wr=%x for QP Type=%x",
439 init_attr->cap.max_send_wr,
440 init_attr->cap.max_recv_wr,init_attr->qp_type);
441 return ERR_PTR(-EINVAL);
442 } else if (init_attr->qp_type == IB_QPT_UD && isdaqp &&
443 init_attr->cap.max_send_wr > 255) {
445 "Invalid Number of max_send_wr=%x for UD QP_TYPE=%x",
446 init_attr->cap.max_send_wr, init_attr->qp_type);
447 return ERR_PTR(-EINVAL);
450 if (pd->uobject && udata)
451 context = pd->uobject->context;
453 my_qp = kmem_cache_zalloc(qp_cache, GFP_KERNEL);
455 ehca_err(pd->device, "pd=%p not enough memory to alloc qp", pd);
456 return ERR_PTR(-ENOMEM);
459 memset (&parms, 0, sizeof(struct ehca_alloc_qp_parms));
460 spin_lock_init(&my_qp->spinlock_s);
461 spin_lock_init(&my_qp->spinlock_r);
464 container_of(init_attr->recv_cq, struct ehca_cq, ib_cq);
466 container_of(init_attr->send_cq, struct ehca_cq, ib_cq);
468 my_qp->init_attr = *init_attr;
471 if (!idr_pre_get(&ehca_qp_idr, GFP_KERNEL)) {
473 ehca_err(pd->device, "Can't reserve idr resources.");
474 goto create_qp_exit0;
477 spin_lock_irqsave(&ehca_qp_idr_lock, flags);
478 ret = idr_get_new(&ehca_qp_idr, my_qp, &my_qp->token);
479 spin_unlock_irqrestore(&ehca_qp_idr_lock, flags);
481 } while (ret == -EAGAIN);
485 ehca_err(pd->device, "Can't allocate new idr entry.");
486 goto create_qp_exit0;
489 parms.servicetype = ibqptype2servicetype(init_attr->qp_type);
490 if (parms.servicetype < 0) {
492 ehca_err(pd->device, "Invalid qp_type=%x", init_attr->qp_type);
493 goto create_qp_exit0;
496 if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR)
497 parms.sigtype = HCALL_SIGT_EVERY;
499 parms.sigtype = HCALL_SIGT_BY_WQE;
501 /* UD_AV CIRCUMVENTION */
502 max_send_sge = init_attr->cap.max_send_sge;
503 max_recv_sge = init_attr->cap.max_recv_sge;
504 if (IB_QPT_UD == init_attr->qp_type ||
505 IB_QPT_GSI == init_attr->qp_type ||
506 IB_QPT_SMI == init_attr->qp_type) {
511 parms.ipz_eq_handle = shca->eq.ipz_eq_handle;
512 parms.daqp_ctrl = isdaqp | daqp_completion;
513 parms.pd = my_pd->fw_pd;
514 parms.max_recv_sge = max_recv_sge;
515 parms.max_send_sge = max_send_sge;
517 h_ret = hipz_h_alloc_resource_qp(shca->ipz_hca_handle, my_qp, &parms);
519 if (h_ret != H_SUCCESS) {
520 ehca_err(pd->device, "h_alloc_resource_qp() failed h_ret=%lx",
522 ret = ehca2ib_return_code(h_ret);
523 goto create_qp_exit1;
526 switch (init_attr->qp_type) {
529 swqe_size = offsetof(struct ehca_wqe, u.nud.sg_list[
530 (parms.act_nr_send_sges)]);
531 rwqe_size = offsetof(struct ehca_wqe, u.nud.sg_list[
532 (parms.act_nr_recv_sges)]);
533 } else { /* for daqp we need to use msg size, not wqe size */
534 swqe_size = da_rc_msg_size[max_send_sge];
535 rwqe_size = da_rc_msg_size[max_recv_sge];
536 parms.act_nr_send_sges = 1;
537 parms.act_nr_recv_sges = 1;
541 swqe_size = offsetof(struct ehca_wqe,
542 u.nud.sg_list[parms.act_nr_send_sges]);
543 rwqe_size = offsetof(struct ehca_wqe,
544 u.nud.sg_list[parms.act_nr_recv_sges]);
550 /* UD circumvention */
551 parms.act_nr_recv_sges -= 2;
552 parms.act_nr_send_sges -= 2;
554 swqe_size = da_ud_sq_msg_size[max_send_sge];
555 rwqe_size = da_rc_msg_size[max_recv_sge];
556 parms.act_nr_send_sges = 1;
557 parms.act_nr_recv_sges = 1;
559 swqe_size = offsetof(struct ehca_wqe,
560 u.ud_av.sg_list[parms.act_nr_send_sges]);
561 rwqe_size = offsetof(struct ehca_wqe,
562 u.ud_av.sg_list[parms.act_nr_recv_sges]);
565 if (IB_QPT_GSI == init_attr->qp_type ||
566 IB_QPT_SMI == init_attr->qp_type) {
567 parms.act_nr_send_wqes = init_attr->cap.max_send_wr;
568 parms.act_nr_recv_wqes = init_attr->cap.max_recv_wr;
569 parms.act_nr_send_sges = init_attr->cap.max_send_sge;
570 parms.act_nr_recv_sges = init_attr->cap.max_recv_sge;
572 (init_attr->qp_type == IB_QPT_SMI) ? 0 : 1;
581 /* initializes r/squeue and registers queue pages */
582 ret = init_qp_queues(shca, my_qp,
583 parms.nr_sq_pages, parms.nr_rq_pages,
584 swqe_size, rwqe_size,
585 parms.act_nr_send_sges, parms.act_nr_recv_sges);
588 "Couldn't initialize r/squeue and pages ret=%x", ret);
589 goto create_qp_exit2;
592 my_qp->ib_qp.pd = &my_pd->ib_pd;
593 my_qp->ib_qp.device = my_pd->ib_pd.device;
595 my_qp->ib_qp.recv_cq = init_attr->recv_cq;
596 my_qp->ib_qp.send_cq = init_attr->send_cq;
598 my_qp->ib_qp.qp_num = my_qp->real_qp_num;
599 my_qp->ib_qp.qp_type = init_attr->qp_type;
601 my_qp->qp_type = init_attr->qp_type;
602 my_qp->ib_qp.srq = init_attr->srq;
604 my_qp->ib_qp.qp_context = init_attr->qp_context;
605 my_qp->ib_qp.event_handler = init_attr->event_handler;
607 init_attr->cap.max_inline_data = 0; /* not supported yet */
608 init_attr->cap.max_recv_sge = parms.act_nr_recv_sges;
609 init_attr->cap.max_recv_wr = parms.act_nr_recv_wqes;
610 init_attr->cap.max_send_sge = parms.act_nr_send_sges;
611 init_attr->cap.max_send_wr = parms.act_nr_send_wqes;
613 /* NOTE: define_apq0() not supported yet */
614 if (init_attr->qp_type == IB_QPT_GSI) {
615 h_ret = ehca_define_sqp(shca, my_qp, init_attr);
616 if (h_ret != H_SUCCESS) {
617 ehca_err(pd->device, "ehca_define_sqp() failed rc=%lx",
619 ret = ehca2ib_return_code(h_ret);
620 goto create_qp_exit3;
623 if (init_attr->send_cq) {
624 struct ehca_cq *cq = container_of(init_attr->send_cq,
625 struct ehca_cq, ib_cq);
626 ret = ehca_cq_assign_qp(cq, my_qp);
628 ehca_err(pd->device, "Couldn't assign qp to send_cq ret=%x",
630 goto create_qp_exit3;
634 /* copy queues, galpa data to user space */
635 if (context && udata) {
636 struct ipz_queue *ipz_rqueue = &my_qp->ipz_rqueue;
637 struct ipz_queue *ipz_squeue = &my_qp->ipz_squeue;
638 struct ehca_create_qp_resp resp;
639 memset(&resp, 0, sizeof(resp));
641 resp.qp_num = my_qp->real_qp_num;
642 resp.token = my_qp->token;
643 resp.qp_type = my_qp->qp_type;
644 resp.qkey = my_qp->qkey;
645 resp.real_qp_num = my_qp->real_qp_num;
646 /* rqueue properties */
647 resp.ipz_rqueue.qe_size = ipz_rqueue->qe_size;
648 resp.ipz_rqueue.act_nr_of_sg = ipz_rqueue->act_nr_of_sg;
649 resp.ipz_rqueue.queue_length = ipz_rqueue->queue_length;
650 resp.ipz_rqueue.pagesize = ipz_rqueue->pagesize;
651 resp.ipz_rqueue.toggle_state = ipz_rqueue->toggle_state;
652 /* squeue properties */
653 resp.ipz_squeue.qe_size = ipz_squeue->qe_size;
654 resp.ipz_squeue.act_nr_of_sg = ipz_squeue->act_nr_of_sg;
655 resp.ipz_squeue.queue_length = ipz_squeue->queue_length;
656 resp.ipz_squeue.pagesize = ipz_squeue->pagesize;
657 resp.ipz_squeue.toggle_state = ipz_squeue->toggle_state;
658 if (ib_copy_to_udata(udata, &resp, sizeof resp)) {
659 ehca_err(pd->device, "Copy to udata failed");
661 goto create_qp_exit3;
665 return &my_qp->ib_qp;
668 ipz_queue_dtor(&my_qp->ipz_rqueue);
669 ipz_queue_dtor(&my_qp->ipz_squeue);
672 hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp);
675 spin_lock_irqsave(&ehca_qp_idr_lock, flags);
676 idr_remove(&ehca_qp_idr, my_qp->token);
677 spin_unlock_irqrestore(&ehca_qp_idr_lock, flags);
680 kmem_cache_free(qp_cache, my_qp);
685 * prepare_sqe_rts called by internal_modify_qp() at trans sqe -> rts
686 * set purge bit of bad wqe and subsequent wqes to avoid reentering sqe
687 * returns total number of bad wqes in bad_wqe_cnt
689 static int prepare_sqe_rts(struct ehca_qp *my_qp, struct ehca_shca *shca,
693 struct ipz_queue *squeue;
694 void *bad_send_wqe_p, *bad_send_wqe_v;
696 struct ehca_wqe *wqe;
697 int qp_num = my_qp->ib_qp.qp_num;
699 /* get send wqe pointer */
700 h_ret = hipz_h_disable_and_get_wqe(shca->ipz_hca_handle,
701 my_qp->ipz_qp_handle, &my_qp->pf,
702 &bad_send_wqe_p, NULL, 2);
703 if (h_ret != H_SUCCESS) {
704 ehca_err(&shca->ib_device, "hipz_h_disable_and_get_wqe() failed"
705 " ehca_qp=%p qp_num=%x h_ret=%lx",
706 my_qp, qp_num, h_ret);
707 return ehca2ib_return_code(h_ret);
709 bad_send_wqe_p = (void*)((u64)bad_send_wqe_p & (~(1L<<63)));
710 ehca_dbg(&shca->ib_device, "qp_num=%x bad_send_wqe_p=%p",
711 qp_num, bad_send_wqe_p);
712 /* convert wqe pointer to vadr */
713 bad_send_wqe_v = abs_to_virt((u64)bad_send_wqe_p);
714 if (ehca_debug_level)
715 ehca_dmp(bad_send_wqe_v, 32, "qp_num=%x bad_wqe", qp_num);
716 squeue = &my_qp->ipz_squeue;
717 if (ipz_queue_abs_to_offset(squeue, (u64)bad_send_wqe_p, &q_ofs)) {
718 ehca_err(&shca->ib_device, "failed to get wqe offset qp_num=%x"
719 " bad_send_wqe_p=%p", qp_num, bad_send_wqe_p);
723 /* loop sets wqe's purge bit */
724 wqe = (struct ehca_wqe*)ipz_qeit_calc(squeue, q_ofs);
726 while (wqe->optype != 0xff && wqe->wqef != 0xff) {
727 if (ehca_debug_level)
728 ehca_dmp(wqe, 32, "qp_num=%x wqe", qp_num);
729 wqe->nr_of_data_seg = 0; /* suppress data access */
730 wqe->wqef = WQEF_PURGE; /* WQE to be purged */
731 q_ofs = ipz_queue_advance_offset(squeue, q_ofs);
732 wqe = (struct ehca_wqe*)ipz_qeit_calc(squeue, q_ofs);
733 *bad_wqe_cnt = (*bad_wqe_cnt)+1;
736 * bad wqe will be reprocessed and ignored when pol_cq() is called,
737 * i.e. nr of wqes with flush error status is one less
739 ehca_dbg(&shca->ib_device, "qp_num=%x flusherr_wqe_cnt=%x",
740 qp_num, (*bad_wqe_cnt)-1);
747 * internal_modify_qp with circumvention to handle aqp0 properly
748 * smi_reset2init indicates if this is an internal reset-to-init-call for
749 * smi. This flag must always be zero if called from ehca_modify_qp()!
750 * This internal func was intorduced to avoid recursion of ehca_modify_qp()!
752 static int internal_modify_qp(struct ib_qp *ibqp,
753 struct ib_qp_attr *attr,
754 int attr_mask, int smi_reset2init)
756 enum ib_qp_state qp_cur_state, qp_new_state;
757 int cnt, qp_attr_idx, ret = 0;
758 enum ib_qp_statetrans statetrans;
759 struct hcp_modify_qp_control_block *mqpcb;
760 struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
761 struct ehca_shca *shca =
762 container_of(ibqp->pd->device, struct ehca_shca, ib_device);
766 int squeue_locked = 0;
767 unsigned long spl_flags = 0;
769 /* do query_qp to obtain current attr values */
770 mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
772 ehca_err(ibqp->device, "Could not get zeroed page for mqpcb "
773 "ehca_qp=%p qp_num=%x ", my_qp, ibqp->qp_num);
777 h_ret = hipz_h_query_qp(shca->ipz_hca_handle,
778 my_qp->ipz_qp_handle,
780 mqpcb, my_qp->galpas.kernel);
781 if (h_ret != H_SUCCESS) {
782 ehca_err(ibqp->device, "hipz_h_query_qp() failed "
783 "ehca_qp=%p qp_num=%x h_ret=%lx",
784 my_qp, ibqp->qp_num, h_ret);
785 ret = ehca2ib_return_code(h_ret);
786 goto modify_qp_exit1;
789 qp_cur_state = ehca2ib_qp_state(mqpcb->qp_state);
791 if (qp_cur_state == -EINVAL) { /* invalid qp state */
793 ehca_err(ibqp->device, "Invalid current ehca_qp_state=%x "
794 "ehca_qp=%p qp_num=%x",
795 mqpcb->qp_state, my_qp, ibqp->qp_num);
796 goto modify_qp_exit1;
799 * circumvention to set aqp0 initial state to init
800 * as expected by IB spec
802 if (smi_reset2init == 0 &&
803 ibqp->qp_type == IB_QPT_SMI &&
804 qp_cur_state == IB_QPS_RESET &&
805 (attr_mask & IB_QP_STATE) &&
806 attr->qp_state == IB_QPS_INIT) { /* RESET -> INIT */
807 struct ib_qp_attr smiqp_attr = {
808 .qp_state = IB_QPS_INIT,
809 .port_num = my_qp->init_attr.port_num,
813 int smiqp_attr_mask = IB_QP_STATE | IB_QP_PORT |
814 IB_QP_PKEY_INDEX | IB_QP_QKEY;
815 int smirc = internal_modify_qp(
816 ibqp, &smiqp_attr, smiqp_attr_mask, 1);
818 ehca_err(ibqp->device, "SMI RESET -> INIT failed. "
819 "ehca_modify_qp() rc=%x", smirc);
821 goto modify_qp_exit1;
823 qp_cur_state = IB_QPS_INIT;
824 ehca_dbg(ibqp->device, "SMI RESET -> INIT succeeded");
826 /* is transmitted current state equal to "real" current state */
827 if ((attr_mask & IB_QP_CUR_STATE) &&
828 qp_cur_state != attr->cur_qp_state) {
830 ehca_err(ibqp->device,
831 "Invalid IB_QP_CUR_STATE attr->curr_qp_state=%x <>"
832 " actual cur_qp_state=%x. ehca_qp=%p qp_num=%x",
833 attr->cur_qp_state, qp_cur_state, my_qp, ibqp->qp_num);
834 goto modify_qp_exit1;
837 ehca_dbg(ibqp->device,"ehca_qp=%p qp_num=%x current qp_state=%x "
838 "new qp_state=%x attribute_mask=%x",
839 my_qp, ibqp->qp_num, qp_cur_state, attr->qp_state, attr_mask);
841 qp_new_state = attr_mask & IB_QP_STATE ? attr->qp_state : qp_cur_state;
842 if (!smi_reset2init &&
843 !ib_modify_qp_is_ok(qp_cur_state, qp_new_state, ibqp->qp_type,
846 ehca_err(ibqp->device,
847 "Invalid qp transition new_state=%x cur_state=%x "
848 "ehca_qp=%p qp_num=%x attr_mask=%x", qp_new_state,
849 qp_cur_state, my_qp, ibqp->qp_num, attr_mask);
850 goto modify_qp_exit1;
853 if ((mqpcb->qp_state = ib2ehca_qp_state(qp_new_state)))
854 update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
857 ehca_err(ibqp->device, "Invalid new qp state=%x "
858 "ehca_qp=%p qp_num=%x",
859 qp_new_state, my_qp, ibqp->qp_num);
860 goto modify_qp_exit1;
863 /* retrieve state transition struct to get req and opt attrs */
864 statetrans = get_modqp_statetrans(qp_cur_state, qp_new_state);
865 if (statetrans < 0) {
867 ehca_err(ibqp->device, "<INVALID STATE CHANGE> qp_cur_state=%x "
868 "new_qp_state=%x State_xsition=%x ehca_qp=%p "
869 "qp_num=%x", qp_cur_state, qp_new_state,
870 statetrans, my_qp, ibqp->qp_num);
871 goto modify_qp_exit1;
874 qp_attr_idx = ib2ehcaqptype(ibqp->qp_type);
876 if (qp_attr_idx < 0) {
878 ehca_err(ibqp->device,
879 "Invalid QP type=%x ehca_qp=%p qp_num=%x",
880 ibqp->qp_type, my_qp, ibqp->qp_num);
881 goto modify_qp_exit1;
884 ehca_dbg(ibqp->device,
885 "ehca_qp=%p qp_num=%x <VALID STATE CHANGE> qp_state_xsit=%x",
886 my_qp, ibqp->qp_num, statetrans);
888 /* sqe -> rts: set purge bit of bad wqe before actual trans */
889 if ((my_qp->qp_type == IB_QPT_UD ||
890 my_qp->qp_type == IB_QPT_GSI ||
891 my_qp->qp_type == IB_QPT_SMI) &&
892 statetrans == IB_QPST_SQE2RTS) {
893 /* mark next free wqe if kernel */
894 if (!ibqp->uobject) {
895 struct ehca_wqe *wqe;
896 /* lock send queue */
897 spin_lock_irqsave(&my_qp->spinlock_s, spl_flags);
899 /* mark next free wqe */
900 wqe = (struct ehca_wqe*)
901 ipz_qeit_get(&my_qp->ipz_squeue);
902 wqe->optype = wqe->wqef = 0xff;
903 ehca_dbg(ibqp->device, "qp_num=%x next_free_wqe=%p",
906 ret = prepare_sqe_rts(my_qp, shca, &bad_wqe_cnt);
908 ehca_err(ibqp->device, "prepare_sqe_rts() failed "
909 "ehca_qp=%p qp_num=%x ret=%x",
910 my_qp, ibqp->qp_num, ret);
911 goto modify_qp_exit2;
916 * enable RDMA_Atomic_Control if reset->init und reliable con
917 * this is necessary since gen2 does not provide that flag,
918 * but pHyp requires it
920 if (statetrans == IB_QPST_RESET2INIT &&
921 (ibqp->qp_type == IB_QPT_RC || ibqp->qp_type == IB_QPT_UC)) {
922 mqpcb->rdma_atomic_ctrl = 3;
923 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RDMA_ATOMIC_CTRL, 1);
925 /* circ. pHyp requires #RDMA/Atomic Resp Res for UC INIT -> RTR */
926 if (statetrans == IB_QPST_INIT2RTR &&
927 (ibqp->qp_type == IB_QPT_UC) &&
928 !(attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)) {
929 mqpcb->rdma_nr_atomic_resp_res = 1; /* default to 1 */
931 EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1);
934 if (attr_mask & IB_QP_PKEY_INDEX) {
935 mqpcb->prim_p_key_idx = attr->pkey_index;
936 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_P_KEY_IDX, 1);
938 if (attr_mask & IB_QP_PORT) {
939 if (attr->port_num < 1 || attr->port_num > shca->num_ports) {
941 ehca_err(ibqp->device, "Invalid port=%x. "
942 "ehca_qp=%p qp_num=%x num_ports=%x",
943 attr->port_num, my_qp, ibqp->qp_num,
945 goto modify_qp_exit2;
947 mqpcb->prim_phys_port = attr->port_num;
948 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_PHYS_PORT, 1);
950 if (attr_mask & IB_QP_QKEY) {
951 mqpcb->qkey = attr->qkey;
952 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_QKEY, 1);
954 if (attr_mask & IB_QP_AV) {
955 int ah_mult = ib_rate_to_mult(attr->ah_attr.static_rate);
956 int ehca_mult = ib_rate_to_mult(shca->sport[my_qp->
957 init_attr.port_num].rate);
959 mqpcb->dlid = attr->ah_attr.dlid;
960 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DLID, 1);
961 mqpcb->source_path_bits = attr->ah_attr.src_path_bits;
962 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS, 1);
963 mqpcb->service_level = attr->ah_attr.sl;
964 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL, 1);
966 if (ah_mult < ehca_mult)
967 mqpcb->max_static_rate = (ah_mult > 0) ?
968 ((ehca_mult - 1) / ah_mult) : 0;
970 mqpcb->max_static_rate = 0;
972 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE, 1);
975 * only if GRH is TRUE we might consider SOURCE_GID_IDX
976 * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
978 if (attr->ah_attr.ah_flags == IB_AH_GRH) {
979 mqpcb->send_grh_flag = 1 << 31;
981 EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1);
982 mqpcb->source_gid_idx = attr->ah_attr.grh.sgid_index;
984 EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX, 1);
986 for (cnt = 0; cnt < 16; cnt++)
987 mqpcb->dest_gid.byte[cnt] =
988 attr->ah_attr.grh.dgid.raw[cnt];
990 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_GID, 1);
991 mqpcb->flow_label = attr->ah_attr.grh.flow_label;
992 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL, 1);
993 mqpcb->hop_limit = attr->ah_attr.grh.hop_limit;
994 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT, 1);
995 mqpcb->traffic_class = attr->ah_attr.grh.traffic_class;
997 EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS, 1);
1001 if (attr_mask & IB_QP_PATH_MTU) {
1002 mqpcb->path_mtu = attr->path_mtu;
1003 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PATH_MTU, 1);
1005 if (attr_mask & IB_QP_TIMEOUT) {
1006 mqpcb->timeout = attr->timeout;
1007 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_TIMEOUT, 1);
1009 if (attr_mask & IB_QP_RETRY_CNT) {
1010 mqpcb->retry_count = attr->retry_cnt;
1011 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RETRY_COUNT, 1);
1013 if (attr_mask & IB_QP_RNR_RETRY) {
1014 mqpcb->rnr_retry_count = attr->rnr_retry;
1015 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RNR_RETRY_COUNT, 1);
1017 if (attr_mask & IB_QP_RQ_PSN) {
1018 mqpcb->receive_psn = attr->rq_psn;
1019 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RECEIVE_PSN, 1);
1021 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
1022 mqpcb->rdma_nr_atomic_resp_res = attr->max_dest_rd_atomic < 3 ?
1023 attr->max_dest_rd_atomic : 2;
1025 EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1);
1027 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) {
1028 mqpcb->rdma_atomic_outst_dest_qp = attr->max_rd_atomic < 3 ?
1029 attr->max_rd_atomic : 2;
1032 (MQPCB_MASK_RDMA_ATOMIC_OUTST_DEST_QP, 1);
1034 if (attr_mask & IB_QP_ALT_PATH) {
1035 int ah_mult = ib_rate_to_mult(attr->alt_ah_attr.static_rate);
1036 int ehca_mult = ib_rate_to_mult(
1037 shca->sport[my_qp->init_attr.port_num].rate);
1039 mqpcb->dlid_al = attr->alt_ah_attr.dlid;
1040 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DLID_AL, 1);
1041 mqpcb->source_path_bits_al = attr->alt_ah_attr.src_path_bits;
1043 EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS_AL, 1);
1044 mqpcb->service_level_al = attr->alt_ah_attr.sl;
1045 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL_AL, 1);
1047 if (ah_mult < ehca_mult)
1048 mqpcb->max_static_rate = (ah_mult > 0) ?
1049 ((ehca_mult - 1) / ah_mult) : 0;
1051 mqpcb->max_static_rate_al = 0;
1053 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE_AL, 1);
1056 * only if GRH is TRUE we might consider SOURCE_GID_IDX
1057 * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
1059 if (attr->alt_ah_attr.ah_flags == IB_AH_GRH) {
1060 mqpcb->send_grh_flag_al = 1 << 31;
1062 EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG_AL, 1);
1063 mqpcb->source_gid_idx_al =
1064 attr->alt_ah_attr.grh.sgid_index;
1066 EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX_AL, 1);
1068 for (cnt = 0; cnt < 16; cnt++)
1069 mqpcb->dest_gid_al.byte[cnt] =
1070 attr->alt_ah_attr.grh.dgid.raw[cnt];
1073 EHCA_BMASK_SET(MQPCB_MASK_DEST_GID_AL, 1);
1074 mqpcb->flow_label_al = attr->alt_ah_attr.grh.flow_label;
1076 EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL_AL, 1);
1077 mqpcb->hop_limit_al = attr->alt_ah_attr.grh.hop_limit;
1079 EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT_AL, 1);
1080 mqpcb->traffic_class_al =
1081 attr->alt_ah_attr.grh.traffic_class;
1083 EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS_AL, 1);
1087 if (attr_mask & IB_QP_MIN_RNR_TIMER) {
1088 mqpcb->min_rnr_nak_timer_field = attr->min_rnr_timer;
1090 EHCA_BMASK_SET(MQPCB_MASK_MIN_RNR_NAK_TIMER_FIELD, 1);
1093 if (attr_mask & IB_QP_SQ_PSN) {
1094 mqpcb->send_psn = attr->sq_psn;
1095 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_PSN, 1);
1098 if (attr_mask & IB_QP_DEST_QPN) {
1099 mqpcb->dest_qp_nr = attr->dest_qp_num;
1100 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_QP_NR, 1);
1103 if (attr_mask & IB_QP_PATH_MIG_STATE) {
1104 mqpcb->path_migration_state = attr->path_mig_state;
1106 EHCA_BMASK_SET(MQPCB_MASK_PATH_MIGRATION_STATE, 1);
1109 if (attr_mask & IB_QP_CAP) {
1110 mqpcb->max_nr_outst_send_wr = attr->cap.max_send_wr+1;
1112 EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_SEND_WR, 1);
1113 mqpcb->max_nr_outst_recv_wr = attr->cap.max_recv_wr+1;
1115 EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_RECV_WR, 1);
1116 /* no support for max_send/recv_sge yet */
1119 if (ehca_debug_level)
1120 ehca_dmp(mqpcb, 4*70, "qp_num=%x", ibqp->qp_num);
1122 h_ret = hipz_h_modify_qp(shca->ipz_hca_handle,
1123 my_qp->ipz_qp_handle,
1126 mqpcb, my_qp->galpas.kernel);
1128 if (h_ret != H_SUCCESS) {
1129 ret = ehca2ib_return_code(h_ret);
1130 ehca_err(ibqp->device, "hipz_h_modify_qp() failed rc=%lx "
1131 "ehca_qp=%p qp_num=%x",h_ret, my_qp, ibqp->qp_num);
1132 goto modify_qp_exit2;
1135 if ((my_qp->qp_type == IB_QPT_UD ||
1136 my_qp->qp_type == IB_QPT_GSI ||
1137 my_qp->qp_type == IB_QPT_SMI) &&
1138 statetrans == IB_QPST_SQE2RTS) {
1139 /* doorbell to reprocessing wqes */
1140 iosync(); /* serialize GAL register access */
1141 hipz_update_sqa(my_qp, bad_wqe_cnt-1);
1142 ehca_gen_dbg("doorbell for %x wqes", bad_wqe_cnt);
1145 if (statetrans == IB_QPST_RESET2INIT ||
1146 statetrans == IB_QPST_INIT2INIT) {
1147 mqpcb->qp_enable = 1;
1148 mqpcb->qp_state = EHCA_QPS_INIT;
1150 update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_ENABLE, 1);
1152 h_ret = hipz_h_modify_qp(shca->ipz_hca_handle,
1153 my_qp->ipz_qp_handle,
1157 my_qp->galpas.kernel);
1159 if (h_ret != H_SUCCESS) {
1160 ret = ehca2ib_return_code(h_ret);
1161 ehca_err(ibqp->device, "ENABLE in context of "
1162 "RESET_2_INIT failed! Maybe you didn't get "
1163 "a LID h_ret=%lx ehca_qp=%p qp_num=%x",
1164 h_ret, my_qp, ibqp->qp_num);
1165 goto modify_qp_exit2;
1169 if (statetrans == IB_QPST_ANY2RESET) {
1170 ipz_qeit_reset(&my_qp->ipz_rqueue);
1171 ipz_qeit_reset(&my_qp->ipz_squeue);
1174 if (attr_mask & IB_QP_QKEY)
1175 my_qp->qkey = attr->qkey;
1178 if (squeue_locked) { /* this means: sqe -> rts */
1179 spin_unlock_irqrestore(&my_qp->spinlock_s, spl_flags);
1180 my_qp->sqerr_purgeflag = 1;
1184 ehca_free_fw_ctrlblock(mqpcb);
1189 int ehca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
1190 struct ib_udata *udata)
1192 struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
1193 struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
1195 u32 cur_pid = current->tgid;
1197 if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
1198 my_pd->ownpid != cur_pid) {
1199 ehca_err(ibqp->pd->device, "Invalid caller pid=%x ownpid=%x",
1200 cur_pid, my_pd->ownpid);
1204 return internal_modify_qp(ibqp, attr, attr_mask, 0);
1207 int ehca_query_qp(struct ib_qp *qp,
1208 struct ib_qp_attr *qp_attr,
1209 int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr)
1211 struct ehca_qp *my_qp = container_of(qp, struct ehca_qp, ib_qp);
1212 struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
1214 struct ehca_shca *shca = container_of(qp->device, struct ehca_shca,
1216 struct ipz_adapter_handle adapter_handle = shca->ipz_hca_handle;
1217 struct hcp_modify_qp_control_block *qpcb;
1218 u32 cur_pid = current->tgid;
1222 if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
1223 my_pd->ownpid != cur_pid) {
1224 ehca_err(qp->device, "Invalid caller pid=%x ownpid=%x",
1225 cur_pid, my_pd->ownpid);
1229 if (qp_attr_mask & QP_ATTR_QUERY_NOT_SUPPORTED) {
1230 ehca_err(qp->device,"Invalid attribute mask "
1231 "ehca_qp=%p qp_num=%x qp_attr_mask=%x ",
1232 my_qp, qp->qp_num, qp_attr_mask);
1236 qpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
1238 ehca_err(qp->device,"Out of memory for qpcb "
1239 "ehca_qp=%p qp_num=%x", my_qp, qp->qp_num);
1243 h_ret = hipz_h_query_qp(adapter_handle,
1244 my_qp->ipz_qp_handle,
1246 qpcb, my_qp->galpas.kernel);
1248 if (h_ret != H_SUCCESS) {
1249 ret = ehca2ib_return_code(h_ret);
1250 ehca_err(qp->device,"hipz_h_query_qp() failed "
1251 "ehca_qp=%p qp_num=%x h_ret=%lx",
1252 my_qp, qp->qp_num, h_ret);
1253 goto query_qp_exit1;
1256 qp_attr->cur_qp_state = ehca2ib_qp_state(qpcb->qp_state);
1257 qp_attr->qp_state = qp_attr->cur_qp_state;
1259 if (qp_attr->cur_qp_state == -EINVAL) {
1261 ehca_err(qp->device,"Got invalid ehca_qp_state=%x "
1262 "ehca_qp=%p qp_num=%x",
1263 qpcb->qp_state, my_qp, qp->qp_num);
1264 goto query_qp_exit1;
1267 if (qp_attr->qp_state == IB_QPS_SQD)
1268 qp_attr->sq_draining = 1;
1270 qp_attr->qkey = qpcb->qkey;
1271 qp_attr->path_mtu = qpcb->path_mtu;
1272 qp_attr->path_mig_state = qpcb->path_migration_state;
1273 qp_attr->rq_psn = qpcb->receive_psn;
1274 qp_attr->sq_psn = qpcb->send_psn;
1275 qp_attr->min_rnr_timer = qpcb->min_rnr_nak_timer_field;
1276 qp_attr->cap.max_send_wr = qpcb->max_nr_outst_send_wr-1;
1277 qp_attr->cap.max_recv_wr = qpcb->max_nr_outst_recv_wr-1;
1278 /* UD_AV CIRCUMVENTION */
1279 if (my_qp->qp_type == IB_QPT_UD) {
1280 qp_attr->cap.max_send_sge =
1281 qpcb->actual_nr_sges_in_sq_wqe - 2;
1282 qp_attr->cap.max_recv_sge =
1283 qpcb->actual_nr_sges_in_rq_wqe - 2;
1285 qp_attr->cap.max_send_sge =
1286 qpcb->actual_nr_sges_in_sq_wqe;
1287 qp_attr->cap.max_recv_sge =
1288 qpcb->actual_nr_sges_in_rq_wqe;
1291 qp_attr->cap.max_inline_data = my_qp->sq_max_inline_data_size;
1292 qp_attr->dest_qp_num = qpcb->dest_qp_nr;
1294 qp_attr->pkey_index =
1295 EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->prim_p_key_idx);
1298 EHCA_BMASK_GET(MQPCB_PRIM_PHYS_PORT, qpcb->prim_phys_port);
1300 qp_attr->timeout = qpcb->timeout;
1301 qp_attr->retry_cnt = qpcb->retry_count;
1302 qp_attr->rnr_retry = qpcb->rnr_retry_count;
1304 qp_attr->alt_pkey_index =
1305 EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->alt_p_key_idx);
1307 qp_attr->alt_port_num = qpcb->alt_phys_port;
1308 qp_attr->alt_timeout = qpcb->timeout_al;
1311 qp_attr->ah_attr.sl = qpcb->service_level;
1313 if (qpcb->send_grh_flag) {
1314 qp_attr->ah_attr.ah_flags = IB_AH_GRH;
1317 qp_attr->ah_attr.static_rate = qpcb->max_static_rate;
1318 qp_attr->ah_attr.dlid = qpcb->dlid;
1319 qp_attr->ah_attr.src_path_bits = qpcb->source_path_bits;
1320 qp_attr->ah_attr.port_num = qp_attr->port_num;
1323 qp_attr->ah_attr.grh.traffic_class = qpcb->traffic_class;
1324 qp_attr->ah_attr.grh.hop_limit = qpcb->hop_limit;
1325 qp_attr->ah_attr.grh.sgid_index = qpcb->source_gid_idx;
1326 qp_attr->ah_attr.grh.flow_label = qpcb->flow_label;
1328 for (cnt = 0; cnt < 16; cnt++)
1329 qp_attr->ah_attr.grh.dgid.raw[cnt] =
1330 qpcb->dest_gid.byte[cnt];
1333 qp_attr->alt_ah_attr.sl = qpcb->service_level_al;
1334 if (qpcb->send_grh_flag_al) {
1335 qp_attr->alt_ah_attr.ah_flags = IB_AH_GRH;
1338 qp_attr->alt_ah_attr.static_rate = qpcb->max_static_rate_al;
1339 qp_attr->alt_ah_attr.dlid = qpcb->dlid_al;
1340 qp_attr->alt_ah_attr.src_path_bits = qpcb->source_path_bits_al;
1343 qp_attr->alt_ah_attr.grh.traffic_class = qpcb->traffic_class_al;
1344 qp_attr->alt_ah_attr.grh.hop_limit = qpcb->hop_limit_al;
1345 qp_attr->alt_ah_attr.grh.sgid_index = qpcb->source_gid_idx_al;
1346 qp_attr->alt_ah_attr.grh.flow_label = qpcb->flow_label_al;
1348 for (cnt = 0; cnt < 16; cnt++)
1349 qp_attr->alt_ah_attr.grh.dgid.raw[cnt] =
1350 qpcb->dest_gid_al.byte[cnt];
1352 /* return init attributes given in ehca_create_qp */
1354 *qp_init_attr = my_qp->init_attr;
1356 if (ehca_debug_level)
1357 ehca_dmp(qpcb, 4*70, "qp_num=%x", qp->qp_num);
1360 ehca_free_fw_ctrlblock(qpcb);
1365 int ehca_destroy_qp(struct ib_qp *ibqp)
1367 struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
1368 struct ehca_shca *shca = container_of(ibqp->device, struct ehca_shca,
1370 struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
1372 u32 cur_pid = current->tgid;
1373 u32 qp_num = ibqp->qp_num;
1377 enum ib_qp_type qp_type;
1378 unsigned long flags;
1380 if (ibqp->uobject) {
1381 if (my_qp->mm_count_galpa ||
1382 my_qp->mm_count_rqueue || my_qp->mm_count_squeue) {
1383 ehca_err(ibqp->device, "Resources still referenced in "
1384 "user space qp_num=%x", ibqp->qp_num);
1387 if (my_pd->ownpid != cur_pid) {
1388 ehca_err(ibqp->device, "Invalid caller pid=%x ownpid=%x",
1389 cur_pid, my_pd->ownpid);
1394 if (my_qp->send_cq) {
1395 ret = ehca_cq_unassign_qp(my_qp->send_cq,
1396 my_qp->real_qp_num);
1398 ehca_err(ibqp->device, "Couldn't unassign qp from "
1399 "send_cq ret=%x qp_num=%x cq_num=%x", ret,
1400 my_qp->ib_qp.qp_num, my_qp->send_cq->cq_number);
1405 spin_lock_irqsave(&ehca_qp_idr_lock, flags);
1406 idr_remove(&ehca_qp_idr, my_qp->token);
1407 spin_unlock_irqrestore(&ehca_qp_idr_lock, flags);
1409 h_ret = hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp);
1410 if (h_ret != H_SUCCESS) {
1411 ehca_err(ibqp->device, "hipz_h_destroy_qp() failed rc=%lx "
1412 "ehca_qp=%p qp_num=%x", h_ret, my_qp, qp_num);
1413 return ehca2ib_return_code(h_ret);
1416 port_num = my_qp->init_attr.port_num;
1417 qp_type = my_qp->init_attr.qp_type;
1419 /* no support for IB_QPT_SMI yet */
1420 if (qp_type == IB_QPT_GSI) {
1421 struct ib_event event;
1422 ehca_info(ibqp->device, "device %s: port %x is inactive.",
1423 shca->ib_device.name, port_num);
1424 event.device = &shca->ib_device;
1425 event.event = IB_EVENT_PORT_ERR;
1426 event.element.port_num = port_num;
1427 shca->sport[port_num - 1].port_state = IB_PORT_DOWN;
1428 ib_dispatch_event(&event);
1431 ipz_queue_dtor(&my_qp->ipz_rqueue);
1432 ipz_queue_dtor(&my_qp->ipz_squeue);
1433 kmem_cache_free(qp_cache, my_qp);
1437 int ehca_init_qp_cache(void)
1439 qp_cache = kmem_cache_create("ehca_cache_qp",
1440 sizeof(struct ehca_qp), 0,
1448 void ehca_cleanup_qp_cache(void)
1451 kmem_cache_destroy(qp_cache);