2 * IBM eServer eHCA Infiniband device driver for Linux on POWER
6 * Authors: Joachim Fenkes <fenkes@de.ibm.com>
7 * Stefan Roscher <stefan.roscher@de.ibm.com>
8 * Waleri Fomin <fomin@de.ibm.com>
9 * Hoang-Nam Nguyen <hnguyen@de.ibm.com>
10 * Reinhard Ernst <rernst@de.ibm.com>
11 * Heiko J Schick <schickhj@de.ibm.com>
13 * Copyright (c) 2005 IBM Corporation
15 * All rights reserved.
17 * This source code is distributed under a dual license of GPL v2.0 and OpenIB
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions are met:
25 * Redistributions of source code must retain the above copyright notice, this
26 * list of conditions and the following disclaimer.
28 * Redistributions in binary form must reproduce the above copyright notice,
29 * this list of conditions and the following disclaimer in the documentation
30 * and/or other materials
31 * provided with the distribution.
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
37 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
40 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
41 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGE.
47 #include <asm/current.h>
49 #include "ehca_classes.h"
50 #include "ehca_tools.h"
52 #include "ehca_iverbs.h"
56 static struct kmem_cache *qp_cache;
59 * attributes not supported by query qp
61 #define QP_ATTR_QUERY_NOT_SUPPORTED (IB_QP_MAX_DEST_RD_ATOMIC | \
62 IB_QP_MAX_QP_RD_ATOMIC | \
63 IB_QP_ACCESS_FLAGS | \
64 IB_QP_EN_SQD_ASYNC_NOTIFY)
67 * ehca (internal) qp state values
80 * qp state transitions as defined by IB Arch Rel 1.1 page 431
82 enum ib_qp_statetrans {
94 IB_QPST_MAX /* nr of transitions, this must be last!!! */
98 * ib2ehca_qp_state maps IB to ehca qp_state
99 * returns ehca qp state corresponding to given ib qp state
101 static inline enum ehca_qp_state ib2ehca_qp_state(enum ib_qp_state ib_qp_state)
103 switch (ib_qp_state) {
105 return EHCA_QPS_RESET;
107 return EHCA_QPS_INIT;
119 ehca_gen_err("invalid ib_qp_state=%x", ib_qp_state);
125 * ehca2ib_qp_state maps ehca to IB qp_state
126 * returns ib qp state corresponding to given ehca qp state
128 static inline enum ib_qp_state ehca2ib_qp_state(enum ehca_qp_state
131 switch (ehca_qp_state) {
147 ehca_gen_err("invalid ehca_qp_state=%x", ehca_qp_state);
153 * ehca_qp_type used as index for req_attr and opt_attr of
154 * struct ehca_modqp_statetrans
165 * ib2ehcaqptype maps Ib to ehca qp_type
166 * returns ehca qp type corresponding to ib qp type
168 static inline enum ehca_qp_type ib2ehcaqptype(enum ib_qp_type ibqptype)
181 ehca_gen_err("Invalid ibqptype=%x", ibqptype);
186 static inline enum ib_qp_statetrans get_modqp_statetrans(int ib_fromstate,
190 switch (ib_tostate) {
192 index = IB_QPST_ANY2RESET;
195 switch (ib_fromstate) {
197 index = IB_QPST_RESET2INIT;
200 index = IB_QPST_INIT2INIT;
205 if (ib_fromstate == IB_QPS_INIT)
206 index = IB_QPST_INIT2RTR;
209 switch (ib_fromstate) {
211 index = IB_QPST_RTR2RTS;
214 index = IB_QPST_RTS2RTS;
217 index = IB_QPST_SQD2RTS;
220 index = IB_QPST_SQE2RTS;
225 if (ib_fromstate == IB_QPS_RTS)
226 index = IB_QPST_RTS2SQD;
231 index = IB_QPST_ANY2ERR;
240 * ibqptype2servicetype returns hcp service type corresponding to given
241 * ib qp type used by create_qp()
243 static inline int ibqptype2servicetype(enum ib_qp_type ibqptype)
255 case IB_QPT_RAW_IPV6:
260 ehca_gen_err("Invalid ibqptype=%x", ibqptype);
266 * init userspace queue info from ipz_queue data
268 static inline void queue2resp(struct ipzu_queue_resp *resp,
269 struct ipz_queue *queue)
271 resp->qe_size = queue->qe_size;
272 resp->act_nr_of_sg = queue->act_nr_of_sg;
273 resp->queue_length = queue->queue_length;
274 resp->pagesize = queue->pagesize;
275 resp->toggle_state = queue->toggle_state;
279 * init_qp_queue initializes/constructs r/squeue and registers queue pages.
281 static inline int init_qp_queue(struct ehca_shca *shca,
282 struct ehca_qp *my_qp,
283 struct ipz_queue *queue,
290 int ret, cnt, ipz_rc;
293 struct ib_device *ib_dev = &shca->ib_device;
294 struct ipz_adapter_handle ipz_hca_handle = shca->ipz_hca_handle;
299 ipz_rc = ipz_queue_ctor(queue, nr_q_pages, EHCA_PAGESIZE,
302 ehca_err(ib_dev, "Cannot allocate page for queue. ipz_rc=%x",
307 /* register queue pages */
308 for (cnt = 0; cnt < nr_q_pages; cnt++) {
309 vpage = ipz_qpageit_get_inc(queue);
311 ehca_err(ib_dev, "ipz_qpageit_get_inc() "
312 "failed p_vpage= %p", vpage);
316 rpage = virt_to_abs(vpage);
318 h_ret = hipz_h_register_rpage_qp(ipz_hca_handle,
319 my_qp->ipz_qp_handle,
322 my_qp->galpas.kernel);
323 if (cnt == (nr_q_pages - 1)) { /* last page! */
324 if (h_ret != expected_hret) {
325 ehca_err(ib_dev, "hipz_qp_register_rpage() "
326 "h_ret= %lx ", h_ret);
327 ret = ehca2ib_return_code(h_ret);
330 vpage = ipz_qpageit_get_inc(&my_qp->ipz_rqueue);
332 ehca_err(ib_dev, "ipz_qpageit_get_inc() "
333 "should not succeed vpage=%p", vpage);
338 if (h_ret != H_PAGE_REGISTERED) {
339 ehca_err(ib_dev, "hipz_qp_register_rpage() "
340 "h_ret= %lx ", h_ret);
341 ret = ehca2ib_return_code(h_ret);
347 ipz_qeit_reset(queue);
352 ipz_queue_dtor(queue);
357 * Create an ib_qp struct that is either a QP or an SRQ, depending on
358 * the value of the is_srq parameter. If init_attr and srq_init_attr share
359 * fields, the field out of init_attr is used.
361 struct ehca_qp *internal_create_qp(struct ib_pd *pd,
362 struct ib_qp_init_attr *init_attr,
363 struct ib_srq_init_attr *srq_init_attr,
364 struct ib_udata *udata, int is_srq)
366 static int da_rc_msg_size[] = { 128, 256, 512, 1024, 2048, 4096 };
367 static int da_ud_sq_msg_size[]={ 128, 384, 896, 1920, 3968 };
368 struct ehca_qp *my_qp;
369 struct ehca_pd *my_pd = container_of(pd, struct ehca_pd, ib_pd);
370 struct ehca_shca *shca = container_of(pd->device, struct ehca_shca,
372 struct ib_ucontext *context = NULL;
374 int is_llqp = 0, has_srq = 0;
375 int qp_type, max_send_sge, max_recv_sge, ret;
377 /* h_call's out parameters */
378 struct ehca_alloc_qp_parms parms;
379 u32 swqe_size = 0, rwqe_size = 0, ib_qp_num;
382 memset(&parms, 0, sizeof(parms));
383 qp_type = init_attr->qp_type;
385 if (init_attr->sq_sig_type != IB_SIGNAL_REQ_WR &&
386 init_attr->sq_sig_type != IB_SIGNAL_ALL_WR) {
387 ehca_err(pd->device, "init_attr->sg_sig_type=%x not allowed",
388 init_attr->sq_sig_type);
389 return ERR_PTR(-EINVAL);
393 if (qp_type & 0x80) {
395 parms.ext_type = EQPT_LLQP;
396 parms.ll_comp_flags = qp_type & LLQP_COMP_MASK;
400 /* handle SRQ base QPs */
401 if (init_attr->srq) {
402 struct ehca_qp *my_srq =
403 container_of(init_attr->srq, struct ehca_qp, ib_srq);
406 parms.ext_type = EQPT_SRQBASE;
407 parms.srq_qpn = my_srq->real_qp_num;
408 parms.srq_token = my_srq->token;
411 if (is_llqp && has_srq) {
412 ehca_err(pd->device, "LLQPs can't have an SRQ");
413 return ERR_PTR(-EINVAL);
418 parms.ext_type = EQPT_SRQ;
419 parms.srq_limit = srq_init_attr->attr.srq_limit;
420 if (init_attr->cap.max_recv_sge > 3) {
421 ehca_err(pd->device, "no more than three SGEs "
422 "supported for SRQ pd=%p max_sge=%x",
423 pd, init_attr->cap.max_recv_sge);
424 return ERR_PTR(-EINVAL);
429 if (qp_type != IB_QPT_UD &&
430 qp_type != IB_QPT_UC &&
431 qp_type != IB_QPT_RC &&
432 qp_type != IB_QPT_SMI &&
433 qp_type != IB_QPT_GSI) {
434 ehca_err(pd->device, "wrong QP Type=%x", qp_type);
435 return ERR_PTR(-EINVAL);
438 if (is_llqp && (qp_type != IB_QPT_RC && qp_type != IB_QPT_UD)) {
439 ehca_err(pd->device, "unsupported LL QP Type=%x", qp_type);
440 return ERR_PTR(-EINVAL);
441 } else if (is_llqp && qp_type == IB_QPT_RC &&
442 (init_attr->cap.max_send_wr > 255 ||
443 init_attr->cap.max_recv_wr > 255 )) {
444 ehca_err(pd->device, "Invalid Number of max_sq_wr=%x "
445 "or max_rq_wr=%x for RC LLQP",
446 init_attr->cap.max_send_wr,
447 init_attr->cap.max_recv_wr);
448 return ERR_PTR(-EINVAL);
449 } else if (is_llqp && qp_type == IB_QPT_UD &&
450 init_attr->cap.max_send_wr > 255) {
452 "Invalid Number of max_send_wr=%x for UD QP_TYPE=%x",
453 init_attr->cap.max_send_wr, qp_type);
454 return ERR_PTR(-EINVAL);
457 if (pd->uobject && udata)
458 context = pd->uobject->context;
460 my_qp = kmem_cache_zalloc(qp_cache, GFP_KERNEL);
462 ehca_err(pd->device, "pd=%p not enough memory to alloc qp", pd);
463 return ERR_PTR(-ENOMEM);
466 spin_lock_init(&my_qp->spinlock_s);
467 spin_lock_init(&my_qp->spinlock_r);
468 my_qp->qp_type = qp_type;
469 my_qp->ext_type = parms.ext_type;
471 if (init_attr->recv_cq)
473 container_of(init_attr->recv_cq, struct ehca_cq, ib_cq);
474 if (init_attr->send_cq)
476 container_of(init_attr->send_cq, struct ehca_cq, ib_cq);
479 if (!idr_pre_get(&ehca_qp_idr, GFP_KERNEL)) {
481 ehca_err(pd->device, "Can't reserve idr resources.");
482 goto create_qp_exit0;
485 spin_lock_irqsave(&ehca_qp_idr_lock, flags);
486 ret = idr_get_new(&ehca_qp_idr, my_qp, &my_qp->token);
487 spin_unlock_irqrestore(&ehca_qp_idr_lock, flags);
489 } while (ret == -EAGAIN);
493 ehca_err(pd->device, "Can't allocate new idr entry.");
494 goto create_qp_exit0;
497 parms.servicetype = ibqptype2servicetype(qp_type);
498 if (parms.servicetype < 0) {
500 ehca_err(pd->device, "Invalid qp_type=%x", qp_type);
501 goto create_qp_exit0;
504 if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR)
505 parms.sigtype = HCALL_SIGT_EVERY;
507 parms.sigtype = HCALL_SIGT_BY_WQE;
509 /* UD_AV CIRCUMVENTION */
510 max_send_sge = init_attr->cap.max_send_sge;
511 max_recv_sge = init_attr->cap.max_recv_sge;
512 if (parms.servicetype == ST_UD) {
517 parms.token = my_qp->token;
518 parms.eq_handle = shca->eq.ipz_eq_handle;
519 parms.pd = my_pd->fw_pd;
521 parms.send_cq_handle = my_qp->send_cq->ipz_cq_handle;
523 parms.recv_cq_handle = my_qp->recv_cq->ipz_cq_handle;
525 parms.max_send_wr = init_attr->cap.max_send_wr;
526 parms.max_recv_wr = init_attr->cap.max_recv_wr;
527 parms.max_send_sge = max_send_sge;
528 parms.max_recv_sge = max_recv_sge;
530 h_ret = hipz_h_alloc_resource_qp(shca->ipz_hca_handle, &parms);
531 if (h_ret != H_SUCCESS) {
532 ehca_err(pd->device, "h_alloc_resource_qp() failed h_ret=%lx",
534 ret = ehca2ib_return_code(h_ret);
535 goto create_qp_exit1;
538 ib_qp_num = my_qp->real_qp_num = parms.real_qp_num;
539 my_qp->ipz_qp_handle = parms.qp_handle;
540 my_qp->galpas = parms.galpas;
545 swqe_size = offsetof(struct ehca_wqe, u.nud.sg_list[
546 (parms.act_nr_send_sges)]);
547 rwqe_size = offsetof(struct ehca_wqe, u.nud.sg_list[
548 (parms.act_nr_recv_sges)]);
549 } else { /* for LLQP we need to use msg size, not wqe size */
550 swqe_size = da_rc_msg_size[max_send_sge];
551 rwqe_size = da_rc_msg_size[max_recv_sge];
552 parms.act_nr_send_sges = 1;
553 parms.act_nr_recv_sges = 1;
557 swqe_size = offsetof(struct ehca_wqe,
558 u.nud.sg_list[parms.act_nr_send_sges]);
559 rwqe_size = offsetof(struct ehca_wqe,
560 u.nud.sg_list[parms.act_nr_recv_sges]);
566 /* UD circumvention */
567 parms.act_nr_recv_sges -= 2;
568 parms.act_nr_send_sges -= 2;
570 swqe_size = da_ud_sq_msg_size[max_send_sge];
571 rwqe_size = da_rc_msg_size[max_recv_sge];
572 parms.act_nr_send_sges = 1;
573 parms.act_nr_recv_sges = 1;
575 swqe_size = offsetof(struct ehca_wqe,
576 u.ud_av.sg_list[parms.act_nr_send_sges]);
577 rwqe_size = offsetof(struct ehca_wqe,
578 u.ud_av.sg_list[parms.act_nr_recv_sges]);
581 if (IB_QPT_GSI == qp_type || IB_QPT_SMI == qp_type) {
582 parms.act_nr_send_wqes = init_attr->cap.max_send_wr;
583 parms.act_nr_recv_wqes = init_attr->cap.max_recv_wr;
584 parms.act_nr_send_sges = init_attr->cap.max_send_sge;
585 parms.act_nr_recv_sges = init_attr->cap.max_recv_sge;
586 ib_qp_num = (qp_type == IB_QPT_SMI) ? 0 : 1;
595 /* initialize r/squeue and register queue pages */
598 shca, my_qp, &my_qp->ipz_squeue, 0,
599 HAS_RQ(my_qp) ? H_PAGE_REGISTERED : H_SUCCESS,
600 parms.nr_sq_pages, swqe_size,
601 parms.act_nr_send_sges);
603 ehca_err(pd->device, "Couldn't initialize squeue "
604 "and pages ret=%x", ret);
605 goto create_qp_exit2;
611 shca, my_qp, &my_qp->ipz_rqueue, 1,
612 H_SUCCESS, parms.nr_rq_pages, rwqe_size,
613 parms.act_nr_recv_sges);
615 ehca_err(pd->device, "Couldn't initialize rqueue "
616 "and pages ret=%x", ret);
617 goto create_qp_exit3;
622 my_qp->ib_srq.pd = &my_pd->ib_pd;
623 my_qp->ib_srq.device = my_pd->ib_pd.device;
625 my_qp->ib_srq.srq_context = init_attr->qp_context;
626 my_qp->ib_srq.event_handler = init_attr->event_handler;
628 my_qp->ib_qp.qp_num = ib_qp_num;
629 my_qp->ib_qp.pd = &my_pd->ib_pd;
630 my_qp->ib_qp.device = my_pd->ib_pd.device;
632 my_qp->ib_qp.recv_cq = init_attr->recv_cq;
633 my_qp->ib_qp.send_cq = init_attr->send_cq;
635 my_qp->ib_qp.qp_type = qp_type;
636 my_qp->ib_qp.srq = init_attr->srq;
638 my_qp->ib_qp.qp_context = init_attr->qp_context;
639 my_qp->ib_qp.event_handler = init_attr->event_handler;
642 init_attr->cap.max_inline_data = 0; /* not supported yet */
643 init_attr->cap.max_recv_sge = parms.act_nr_recv_sges;
644 init_attr->cap.max_recv_wr = parms.act_nr_recv_wqes;
645 init_attr->cap.max_send_sge = parms.act_nr_send_sges;
646 init_attr->cap.max_send_wr = parms.act_nr_send_wqes;
647 my_qp->init_attr = *init_attr;
649 /* NOTE: define_apq0() not supported yet */
650 if (qp_type == IB_QPT_GSI) {
651 h_ret = ehca_define_sqp(shca, my_qp, init_attr);
652 if (h_ret != H_SUCCESS) {
653 ehca_err(pd->device, "ehca_define_sqp() failed rc=%lx",
655 ret = ehca2ib_return_code(h_ret);
656 goto create_qp_exit4;
660 if (my_qp->send_cq) {
661 ret = ehca_cq_assign_qp(my_qp->send_cq, my_qp);
663 ehca_err(pd->device, "Couldn't assign qp to send_cq ret=%x",
665 goto create_qp_exit4;
669 /* copy queues, galpa data to user space */
670 if (context && udata) {
671 struct ehca_create_qp_resp resp;
672 memset(&resp, 0, sizeof(resp));
674 resp.qp_num = my_qp->real_qp_num;
675 resp.token = my_qp->token;
676 resp.qp_type = my_qp->qp_type;
677 resp.ext_type = my_qp->ext_type;
678 resp.qkey = my_qp->qkey;
679 resp.real_qp_num = my_qp->real_qp_num;
681 queue2resp(&resp.ipz_squeue, &my_qp->ipz_squeue);
683 queue2resp(&resp.ipz_rqueue, &my_qp->ipz_rqueue);
685 if (ib_copy_to_udata(udata, &resp, sizeof resp)) {
686 ehca_err(pd->device, "Copy to udata failed");
688 goto create_qp_exit4;
696 ipz_queue_dtor(&my_qp->ipz_rqueue);
700 ipz_queue_dtor(&my_qp->ipz_squeue);
703 hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp);
706 spin_lock_irqsave(&ehca_qp_idr_lock, flags);
707 idr_remove(&ehca_qp_idr, my_qp->token);
708 spin_unlock_irqrestore(&ehca_qp_idr_lock, flags);
711 kmem_cache_free(qp_cache, my_qp);
715 struct ib_qp *ehca_create_qp(struct ib_pd *pd,
716 struct ib_qp_init_attr *qp_init_attr,
717 struct ib_udata *udata)
721 ret = internal_create_qp(pd, qp_init_attr, NULL, udata, 0);
722 return IS_ERR(ret) ? (struct ib_qp *) ret : &ret->ib_qp;
725 int internal_destroy_qp(struct ib_device *dev, struct ehca_qp *my_qp,
726 struct ib_uobject *uobject);
728 struct ib_srq *ehca_create_srq(struct ib_pd *pd,
729 struct ib_srq_init_attr *srq_init_attr,
730 struct ib_udata *udata)
732 struct ib_qp_init_attr qp_init_attr;
733 struct ehca_qp *my_qp;
735 struct ehca_shca *shca = container_of(pd->device, struct ehca_shca,
737 struct hcp_modify_qp_control_block *mqpcb;
738 u64 hret, update_mask;
740 /* For common attributes, internal_create_qp() takes its info
741 * out of qp_init_attr, so copy all common attrs there.
743 memset(&qp_init_attr, 0, sizeof(qp_init_attr));
744 qp_init_attr.event_handler = srq_init_attr->event_handler;
745 qp_init_attr.qp_context = srq_init_attr->srq_context;
746 qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR;
747 qp_init_attr.qp_type = IB_QPT_RC;
748 qp_init_attr.cap.max_recv_wr = srq_init_attr->attr.max_wr;
749 qp_init_attr.cap.max_recv_sge = srq_init_attr->attr.max_sge;
751 my_qp = internal_create_qp(pd, &qp_init_attr, srq_init_attr, udata, 1);
753 return (struct ib_srq *) my_qp;
755 /* copy back return values */
756 srq_init_attr->attr.max_wr = qp_init_attr.cap.max_recv_wr;
757 srq_init_attr->attr.max_sge = qp_init_attr.cap.max_recv_sge;
759 /* drive SRQ into RTR state */
760 mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
762 ehca_err(pd->device, "Could not get zeroed page for mqpcb "
763 "ehca_qp=%p qp_num=%x ", my_qp, my_qp->real_qp_num);
764 ret = ERR_PTR(-ENOMEM);
768 mqpcb->qp_state = EHCA_QPS_INIT;
769 mqpcb->prim_phys_port = 1;
770 update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
771 hret = hipz_h_modify_qp(shca->ipz_hca_handle,
772 my_qp->ipz_qp_handle,
775 mqpcb, my_qp->galpas.kernel);
776 if (hret != H_SUCCESS) {
777 ehca_err(pd->device, "Could not modify SRQ to INIT"
778 "ehca_qp=%p qp_num=%x hret=%lx",
779 my_qp, my_qp->real_qp_num, hret);
783 mqpcb->qp_enable = 1;
784 update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_ENABLE, 1);
785 hret = hipz_h_modify_qp(shca->ipz_hca_handle,
786 my_qp->ipz_qp_handle,
789 mqpcb, my_qp->galpas.kernel);
790 if (hret != H_SUCCESS) {
791 ehca_err(pd->device, "Could not enable SRQ"
792 "ehca_qp=%p qp_num=%x hret=%lx",
793 my_qp, my_qp->real_qp_num, hret);
797 mqpcb->qp_state = EHCA_QPS_RTR;
798 update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
799 hret = hipz_h_modify_qp(shca->ipz_hca_handle,
800 my_qp->ipz_qp_handle,
803 mqpcb, my_qp->galpas.kernel);
804 if (hret != H_SUCCESS) {
805 ehca_err(pd->device, "Could not modify SRQ to RTR"
806 "ehca_qp=%p qp_num=%x hret=%lx",
807 my_qp, my_qp->real_qp_num, hret);
811 return &my_qp->ib_srq;
814 ret = ERR_PTR(ehca2ib_return_code(hret));
815 ehca_free_fw_ctrlblock(mqpcb);
818 internal_destroy_qp(pd->device, my_qp, my_qp->ib_srq.uobject);
824 * prepare_sqe_rts called by internal_modify_qp() at trans sqe -> rts
825 * set purge bit of bad wqe and subsequent wqes to avoid reentering sqe
826 * returns total number of bad wqes in bad_wqe_cnt
828 static int prepare_sqe_rts(struct ehca_qp *my_qp, struct ehca_shca *shca,
832 struct ipz_queue *squeue;
833 void *bad_send_wqe_p, *bad_send_wqe_v;
835 struct ehca_wqe *wqe;
836 int qp_num = my_qp->ib_qp.qp_num;
838 /* get send wqe pointer */
839 h_ret = hipz_h_disable_and_get_wqe(shca->ipz_hca_handle,
840 my_qp->ipz_qp_handle, &my_qp->pf,
841 &bad_send_wqe_p, NULL, 2);
842 if (h_ret != H_SUCCESS) {
843 ehca_err(&shca->ib_device, "hipz_h_disable_and_get_wqe() failed"
844 " ehca_qp=%p qp_num=%x h_ret=%lx",
845 my_qp, qp_num, h_ret);
846 return ehca2ib_return_code(h_ret);
848 bad_send_wqe_p = (void*)((u64)bad_send_wqe_p & (~(1L<<63)));
849 ehca_dbg(&shca->ib_device, "qp_num=%x bad_send_wqe_p=%p",
850 qp_num, bad_send_wqe_p);
851 /* convert wqe pointer to vadr */
852 bad_send_wqe_v = abs_to_virt((u64)bad_send_wqe_p);
853 if (ehca_debug_level)
854 ehca_dmp(bad_send_wqe_v, 32, "qp_num=%x bad_wqe", qp_num);
855 squeue = &my_qp->ipz_squeue;
856 if (ipz_queue_abs_to_offset(squeue, (u64)bad_send_wqe_p, &q_ofs)) {
857 ehca_err(&shca->ib_device, "failed to get wqe offset qp_num=%x"
858 " bad_send_wqe_p=%p", qp_num, bad_send_wqe_p);
862 /* loop sets wqe's purge bit */
863 wqe = (struct ehca_wqe*)ipz_qeit_calc(squeue, q_ofs);
865 while (wqe->optype != 0xff && wqe->wqef != 0xff) {
866 if (ehca_debug_level)
867 ehca_dmp(wqe, 32, "qp_num=%x wqe", qp_num);
868 wqe->nr_of_data_seg = 0; /* suppress data access */
869 wqe->wqef = WQEF_PURGE; /* WQE to be purged */
870 q_ofs = ipz_queue_advance_offset(squeue, q_ofs);
871 wqe = (struct ehca_wqe*)ipz_qeit_calc(squeue, q_ofs);
872 *bad_wqe_cnt = (*bad_wqe_cnt)+1;
875 * bad wqe will be reprocessed and ignored when pol_cq() is called,
876 * i.e. nr of wqes with flush error status is one less
878 ehca_dbg(&shca->ib_device, "qp_num=%x flusherr_wqe_cnt=%x",
879 qp_num, (*bad_wqe_cnt)-1);
886 * internal_modify_qp with circumvention to handle aqp0 properly
887 * smi_reset2init indicates if this is an internal reset-to-init-call for
888 * smi. This flag must always be zero if called from ehca_modify_qp()!
889 * This internal func was intorduced to avoid recursion of ehca_modify_qp()!
891 static int internal_modify_qp(struct ib_qp *ibqp,
892 struct ib_qp_attr *attr,
893 int attr_mask, int smi_reset2init)
895 enum ib_qp_state qp_cur_state, qp_new_state;
896 int cnt, qp_attr_idx, ret = 0;
897 enum ib_qp_statetrans statetrans;
898 struct hcp_modify_qp_control_block *mqpcb;
899 struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
900 struct ehca_shca *shca =
901 container_of(ibqp->pd->device, struct ehca_shca, ib_device);
905 int squeue_locked = 0;
906 unsigned long spl_flags = 0;
908 /* do query_qp to obtain current attr values */
909 mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
911 ehca_err(ibqp->device, "Could not get zeroed page for mqpcb "
912 "ehca_qp=%p qp_num=%x ", my_qp, ibqp->qp_num);
916 h_ret = hipz_h_query_qp(shca->ipz_hca_handle,
917 my_qp->ipz_qp_handle,
919 mqpcb, my_qp->galpas.kernel);
920 if (h_ret != H_SUCCESS) {
921 ehca_err(ibqp->device, "hipz_h_query_qp() failed "
922 "ehca_qp=%p qp_num=%x h_ret=%lx",
923 my_qp, ibqp->qp_num, h_ret);
924 ret = ehca2ib_return_code(h_ret);
925 goto modify_qp_exit1;
928 qp_cur_state = ehca2ib_qp_state(mqpcb->qp_state);
930 if (qp_cur_state == -EINVAL) { /* invalid qp state */
932 ehca_err(ibqp->device, "Invalid current ehca_qp_state=%x "
933 "ehca_qp=%p qp_num=%x",
934 mqpcb->qp_state, my_qp, ibqp->qp_num);
935 goto modify_qp_exit1;
938 * circumvention to set aqp0 initial state to init
939 * as expected by IB spec
941 if (smi_reset2init == 0 &&
942 ibqp->qp_type == IB_QPT_SMI &&
943 qp_cur_state == IB_QPS_RESET &&
944 (attr_mask & IB_QP_STATE) &&
945 attr->qp_state == IB_QPS_INIT) { /* RESET -> INIT */
946 struct ib_qp_attr smiqp_attr = {
947 .qp_state = IB_QPS_INIT,
948 .port_num = my_qp->init_attr.port_num,
952 int smiqp_attr_mask = IB_QP_STATE | IB_QP_PORT |
953 IB_QP_PKEY_INDEX | IB_QP_QKEY;
954 int smirc = internal_modify_qp(
955 ibqp, &smiqp_attr, smiqp_attr_mask, 1);
957 ehca_err(ibqp->device, "SMI RESET -> INIT failed. "
958 "ehca_modify_qp() rc=%x", smirc);
960 goto modify_qp_exit1;
962 qp_cur_state = IB_QPS_INIT;
963 ehca_dbg(ibqp->device, "SMI RESET -> INIT succeeded");
965 /* is transmitted current state equal to "real" current state */
966 if ((attr_mask & IB_QP_CUR_STATE) &&
967 qp_cur_state != attr->cur_qp_state) {
969 ehca_err(ibqp->device,
970 "Invalid IB_QP_CUR_STATE attr->curr_qp_state=%x <>"
971 " actual cur_qp_state=%x. ehca_qp=%p qp_num=%x",
972 attr->cur_qp_state, qp_cur_state, my_qp, ibqp->qp_num);
973 goto modify_qp_exit1;
976 ehca_dbg(ibqp->device,"ehca_qp=%p qp_num=%x current qp_state=%x "
977 "new qp_state=%x attribute_mask=%x",
978 my_qp, ibqp->qp_num, qp_cur_state, attr->qp_state, attr_mask);
980 qp_new_state = attr_mask & IB_QP_STATE ? attr->qp_state : qp_cur_state;
981 if (!smi_reset2init &&
982 !ib_modify_qp_is_ok(qp_cur_state, qp_new_state, ibqp->qp_type,
985 ehca_err(ibqp->device,
986 "Invalid qp transition new_state=%x cur_state=%x "
987 "ehca_qp=%p qp_num=%x attr_mask=%x", qp_new_state,
988 qp_cur_state, my_qp, ibqp->qp_num, attr_mask);
989 goto modify_qp_exit1;
992 if ((mqpcb->qp_state = ib2ehca_qp_state(qp_new_state)))
993 update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
996 ehca_err(ibqp->device, "Invalid new qp state=%x "
997 "ehca_qp=%p qp_num=%x",
998 qp_new_state, my_qp, ibqp->qp_num);
999 goto modify_qp_exit1;
1002 /* retrieve state transition struct to get req and opt attrs */
1003 statetrans = get_modqp_statetrans(qp_cur_state, qp_new_state);
1004 if (statetrans < 0) {
1006 ehca_err(ibqp->device, "<INVALID STATE CHANGE> qp_cur_state=%x "
1007 "new_qp_state=%x State_xsition=%x ehca_qp=%p "
1008 "qp_num=%x", qp_cur_state, qp_new_state,
1009 statetrans, my_qp, ibqp->qp_num);
1010 goto modify_qp_exit1;
1013 qp_attr_idx = ib2ehcaqptype(ibqp->qp_type);
1015 if (qp_attr_idx < 0) {
1017 ehca_err(ibqp->device,
1018 "Invalid QP type=%x ehca_qp=%p qp_num=%x",
1019 ibqp->qp_type, my_qp, ibqp->qp_num);
1020 goto modify_qp_exit1;
1023 ehca_dbg(ibqp->device,
1024 "ehca_qp=%p qp_num=%x <VALID STATE CHANGE> qp_state_xsit=%x",
1025 my_qp, ibqp->qp_num, statetrans);
1027 /* sqe -> rts: set purge bit of bad wqe before actual trans */
1028 if ((my_qp->qp_type == IB_QPT_UD ||
1029 my_qp->qp_type == IB_QPT_GSI ||
1030 my_qp->qp_type == IB_QPT_SMI) &&
1031 statetrans == IB_QPST_SQE2RTS) {
1032 /* mark next free wqe if kernel */
1033 if (!ibqp->uobject) {
1034 struct ehca_wqe *wqe;
1035 /* lock send queue */
1036 spin_lock_irqsave(&my_qp->spinlock_s, spl_flags);
1038 /* mark next free wqe */
1039 wqe = (struct ehca_wqe*)
1040 ipz_qeit_get(&my_qp->ipz_squeue);
1041 wqe->optype = wqe->wqef = 0xff;
1042 ehca_dbg(ibqp->device, "qp_num=%x next_free_wqe=%p",
1045 ret = prepare_sqe_rts(my_qp, shca, &bad_wqe_cnt);
1047 ehca_err(ibqp->device, "prepare_sqe_rts() failed "
1048 "ehca_qp=%p qp_num=%x ret=%x",
1049 my_qp, ibqp->qp_num, ret);
1050 goto modify_qp_exit2;
1055 * enable RDMA_Atomic_Control if reset->init und reliable con
1056 * this is necessary since gen2 does not provide that flag,
1057 * but pHyp requires it
1059 if (statetrans == IB_QPST_RESET2INIT &&
1060 (ibqp->qp_type == IB_QPT_RC || ibqp->qp_type == IB_QPT_UC)) {
1061 mqpcb->rdma_atomic_ctrl = 3;
1062 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RDMA_ATOMIC_CTRL, 1);
1064 /* circ. pHyp requires #RDMA/Atomic Resp Res for UC INIT -> RTR */
1065 if (statetrans == IB_QPST_INIT2RTR &&
1066 (ibqp->qp_type == IB_QPT_UC) &&
1067 !(attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)) {
1068 mqpcb->rdma_nr_atomic_resp_res = 1; /* default to 1 */
1070 EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1);
1073 if (attr_mask & IB_QP_PKEY_INDEX) {
1074 mqpcb->prim_p_key_idx = attr->pkey_index;
1075 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_P_KEY_IDX, 1);
1077 if (attr_mask & IB_QP_PORT) {
1078 if (attr->port_num < 1 || attr->port_num > shca->num_ports) {
1080 ehca_err(ibqp->device, "Invalid port=%x. "
1081 "ehca_qp=%p qp_num=%x num_ports=%x",
1082 attr->port_num, my_qp, ibqp->qp_num,
1084 goto modify_qp_exit2;
1086 mqpcb->prim_phys_port = attr->port_num;
1087 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_PHYS_PORT, 1);
1089 if (attr_mask & IB_QP_QKEY) {
1090 mqpcb->qkey = attr->qkey;
1091 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_QKEY, 1);
1093 if (attr_mask & IB_QP_AV) {
1094 int ah_mult = ib_rate_to_mult(attr->ah_attr.static_rate);
1095 int ehca_mult = ib_rate_to_mult(shca->sport[my_qp->
1096 init_attr.port_num].rate);
1098 mqpcb->dlid = attr->ah_attr.dlid;
1099 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DLID, 1);
1100 mqpcb->source_path_bits = attr->ah_attr.src_path_bits;
1101 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS, 1);
1102 mqpcb->service_level = attr->ah_attr.sl;
1103 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL, 1);
1105 if (ah_mult < ehca_mult)
1106 mqpcb->max_static_rate = (ah_mult > 0) ?
1107 ((ehca_mult - 1) / ah_mult) : 0;
1109 mqpcb->max_static_rate = 0;
1110 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE, 1);
1113 * Always supply the GRH flag, even if it's zero, to give the
1114 * hypervisor a clear "yes" or "no" instead of a "perhaps"
1116 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1);
1119 * only if GRH is TRUE we might consider SOURCE_GID_IDX
1120 * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
1122 if (attr->ah_attr.ah_flags == IB_AH_GRH) {
1123 mqpcb->send_grh_flag = 1;
1125 mqpcb->source_gid_idx = attr->ah_attr.grh.sgid_index;
1127 EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX, 1);
1129 for (cnt = 0; cnt < 16; cnt++)
1130 mqpcb->dest_gid.byte[cnt] =
1131 attr->ah_attr.grh.dgid.raw[cnt];
1133 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_GID, 1);
1134 mqpcb->flow_label = attr->ah_attr.grh.flow_label;
1135 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL, 1);
1136 mqpcb->hop_limit = attr->ah_attr.grh.hop_limit;
1137 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT, 1);
1138 mqpcb->traffic_class = attr->ah_attr.grh.traffic_class;
1140 EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS, 1);
1144 if (attr_mask & IB_QP_PATH_MTU) {
1145 mqpcb->path_mtu = attr->path_mtu;
1146 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PATH_MTU, 1);
1148 if (attr_mask & IB_QP_TIMEOUT) {
1149 mqpcb->timeout = attr->timeout;
1150 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_TIMEOUT, 1);
1152 if (attr_mask & IB_QP_RETRY_CNT) {
1153 mqpcb->retry_count = attr->retry_cnt;
1154 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RETRY_COUNT, 1);
1156 if (attr_mask & IB_QP_RNR_RETRY) {
1157 mqpcb->rnr_retry_count = attr->rnr_retry;
1158 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RNR_RETRY_COUNT, 1);
1160 if (attr_mask & IB_QP_RQ_PSN) {
1161 mqpcb->receive_psn = attr->rq_psn;
1162 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RECEIVE_PSN, 1);
1164 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
1165 mqpcb->rdma_nr_atomic_resp_res = attr->max_dest_rd_atomic < 3 ?
1166 attr->max_dest_rd_atomic : 2;
1168 EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1);
1170 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) {
1171 mqpcb->rdma_atomic_outst_dest_qp = attr->max_rd_atomic < 3 ?
1172 attr->max_rd_atomic : 2;
1175 (MQPCB_MASK_RDMA_ATOMIC_OUTST_DEST_QP, 1);
1177 if (attr_mask & IB_QP_ALT_PATH) {
1178 int ah_mult = ib_rate_to_mult(attr->alt_ah_attr.static_rate);
1179 int ehca_mult = ib_rate_to_mult(
1180 shca->sport[my_qp->init_attr.port_num].rate);
1182 mqpcb->dlid_al = attr->alt_ah_attr.dlid;
1183 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DLID_AL, 1);
1184 mqpcb->source_path_bits_al = attr->alt_ah_attr.src_path_bits;
1186 EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS_AL, 1);
1187 mqpcb->service_level_al = attr->alt_ah_attr.sl;
1188 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL_AL, 1);
1190 if (ah_mult < ehca_mult)
1191 mqpcb->max_static_rate = (ah_mult > 0) ?
1192 ((ehca_mult - 1) / ah_mult) : 0;
1194 mqpcb->max_static_rate_al = 0;
1196 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE_AL, 1);
1199 * only if GRH is TRUE we might consider SOURCE_GID_IDX
1200 * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
1202 if (attr->alt_ah_attr.ah_flags == IB_AH_GRH) {
1203 mqpcb->send_grh_flag_al = 1 << 31;
1205 EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG_AL, 1);
1206 mqpcb->source_gid_idx_al =
1207 attr->alt_ah_attr.grh.sgid_index;
1209 EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX_AL, 1);
1211 for (cnt = 0; cnt < 16; cnt++)
1212 mqpcb->dest_gid_al.byte[cnt] =
1213 attr->alt_ah_attr.grh.dgid.raw[cnt];
1216 EHCA_BMASK_SET(MQPCB_MASK_DEST_GID_AL, 1);
1217 mqpcb->flow_label_al = attr->alt_ah_attr.grh.flow_label;
1219 EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL_AL, 1);
1220 mqpcb->hop_limit_al = attr->alt_ah_attr.grh.hop_limit;
1222 EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT_AL, 1);
1223 mqpcb->traffic_class_al =
1224 attr->alt_ah_attr.grh.traffic_class;
1226 EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS_AL, 1);
1230 if (attr_mask & IB_QP_MIN_RNR_TIMER) {
1231 mqpcb->min_rnr_nak_timer_field = attr->min_rnr_timer;
1233 EHCA_BMASK_SET(MQPCB_MASK_MIN_RNR_NAK_TIMER_FIELD, 1);
1236 if (attr_mask & IB_QP_SQ_PSN) {
1237 mqpcb->send_psn = attr->sq_psn;
1238 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_PSN, 1);
1241 if (attr_mask & IB_QP_DEST_QPN) {
1242 mqpcb->dest_qp_nr = attr->dest_qp_num;
1243 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_QP_NR, 1);
1246 if (attr_mask & IB_QP_PATH_MIG_STATE) {
1247 mqpcb->path_migration_state = attr->path_mig_state;
1249 EHCA_BMASK_SET(MQPCB_MASK_PATH_MIGRATION_STATE, 1);
1252 if (attr_mask & IB_QP_CAP) {
1253 mqpcb->max_nr_outst_send_wr = attr->cap.max_send_wr+1;
1255 EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_SEND_WR, 1);
1256 mqpcb->max_nr_outst_recv_wr = attr->cap.max_recv_wr+1;
1258 EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_RECV_WR, 1);
1259 /* no support for max_send/recv_sge yet */
1262 if (ehca_debug_level)
1263 ehca_dmp(mqpcb, 4*70, "qp_num=%x", ibqp->qp_num);
1265 h_ret = hipz_h_modify_qp(shca->ipz_hca_handle,
1266 my_qp->ipz_qp_handle,
1269 mqpcb, my_qp->galpas.kernel);
1271 if (h_ret != H_SUCCESS) {
1272 ret = ehca2ib_return_code(h_ret);
1273 ehca_err(ibqp->device, "hipz_h_modify_qp() failed rc=%lx "
1274 "ehca_qp=%p qp_num=%x",h_ret, my_qp, ibqp->qp_num);
1275 goto modify_qp_exit2;
1278 if ((my_qp->qp_type == IB_QPT_UD ||
1279 my_qp->qp_type == IB_QPT_GSI ||
1280 my_qp->qp_type == IB_QPT_SMI) &&
1281 statetrans == IB_QPST_SQE2RTS) {
1282 /* doorbell to reprocessing wqes */
1283 iosync(); /* serialize GAL register access */
1284 hipz_update_sqa(my_qp, bad_wqe_cnt-1);
1285 ehca_gen_dbg("doorbell for %x wqes", bad_wqe_cnt);
1288 if (statetrans == IB_QPST_RESET2INIT ||
1289 statetrans == IB_QPST_INIT2INIT) {
1290 mqpcb->qp_enable = 1;
1291 mqpcb->qp_state = EHCA_QPS_INIT;
1293 update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_ENABLE, 1);
1295 h_ret = hipz_h_modify_qp(shca->ipz_hca_handle,
1296 my_qp->ipz_qp_handle,
1300 my_qp->galpas.kernel);
1302 if (h_ret != H_SUCCESS) {
1303 ret = ehca2ib_return_code(h_ret);
1304 ehca_err(ibqp->device, "ENABLE in context of "
1305 "RESET_2_INIT failed! Maybe you didn't get "
1306 "a LID h_ret=%lx ehca_qp=%p qp_num=%x",
1307 h_ret, my_qp, ibqp->qp_num);
1308 goto modify_qp_exit2;
1312 if (statetrans == IB_QPST_ANY2RESET) {
1313 ipz_qeit_reset(&my_qp->ipz_rqueue);
1314 ipz_qeit_reset(&my_qp->ipz_squeue);
1317 if (attr_mask & IB_QP_QKEY)
1318 my_qp->qkey = attr->qkey;
1321 if (squeue_locked) { /* this means: sqe -> rts */
1322 spin_unlock_irqrestore(&my_qp->spinlock_s, spl_flags);
1323 my_qp->sqerr_purgeflag = 1;
1327 ehca_free_fw_ctrlblock(mqpcb);
1332 int ehca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
1333 struct ib_udata *udata)
1335 struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
1336 struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
1338 u32 cur_pid = current->tgid;
1340 if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
1341 my_pd->ownpid != cur_pid) {
1342 ehca_err(ibqp->pd->device, "Invalid caller pid=%x ownpid=%x",
1343 cur_pid, my_pd->ownpid);
1347 return internal_modify_qp(ibqp, attr, attr_mask, 0);
1350 int ehca_query_qp(struct ib_qp *qp,
1351 struct ib_qp_attr *qp_attr,
1352 int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr)
1354 struct ehca_qp *my_qp = container_of(qp, struct ehca_qp, ib_qp);
1355 struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
1357 struct ehca_shca *shca = container_of(qp->device, struct ehca_shca,
1359 struct ipz_adapter_handle adapter_handle = shca->ipz_hca_handle;
1360 struct hcp_modify_qp_control_block *qpcb;
1361 u32 cur_pid = current->tgid;
1365 if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
1366 my_pd->ownpid != cur_pid) {
1367 ehca_err(qp->device, "Invalid caller pid=%x ownpid=%x",
1368 cur_pid, my_pd->ownpid);
1372 if (qp_attr_mask & QP_ATTR_QUERY_NOT_SUPPORTED) {
1373 ehca_err(qp->device,"Invalid attribute mask "
1374 "ehca_qp=%p qp_num=%x qp_attr_mask=%x ",
1375 my_qp, qp->qp_num, qp_attr_mask);
1379 qpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
1381 ehca_err(qp->device,"Out of memory for qpcb "
1382 "ehca_qp=%p qp_num=%x", my_qp, qp->qp_num);
1386 h_ret = hipz_h_query_qp(adapter_handle,
1387 my_qp->ipz_qp_handle,
1389 qpcb, my_qp->galpas.kernel);
1391 if (h_ret != H_SUCCESS) {
1392 ret = ehca2ib_return_code(h_ret);
1393 ehca_err(qp->device,"hipz_h_query_qp() failed "
1394 "ehca_qp=%p qp_num=%x h_ret=%lx",
1395 my_qp, qp->qp_num, h_ret);
1396 goto query_qp_exit1;
1399 qp_attr->cur_qp_state = ehca2ib_qp_state(qpcb->qp_state);
1400 qp_attr->qp_state = qp_attr->cur_qp_state;
1402 if (qp_attr->cur_qp_state == -EINVAL) {
1404 ehca_err(qp->device,"Got invalid ehca_qp_state=%x "
1405 "ehca_qp=%p qp_num=%x",
1406 qpcb->qp_state, my_qp, qp->qp_num);
1407 goto query_qp_exit1;
1410 if (qp_attr->qp_state == IB_QPS_SQD)
1411 qp_attr->sq_draining = 1;
1413 qp_attr->qkey = qpcb->qkey;
1414 qp_attr->path_mtu = qpcb->path_mtu;
1415 qp_attr->path_mig_state = qpcb->path_migration_state;
1416 qp_attr->rq_psn = qpcb->receive_psn;
1417 qp_attr->sq_psn = qpcb->send_psn;
1418 qp_attr->min_rnr_timer = qpcb->min_rnr_nak_timer_field;
1419 qp_attr->cap.max_send_wr = qpcb->max_nr_outst_send_wr-1;
1420 qp_attr->cap.max_recv_wr = qpcb->max_nr_outst_recv_wr-1;
1421 /* UD_AV CIRCUMVENTION */
1422 if (my_qp->qp_type == IB_QPT_UD) {
1423 qp_attr->cap.max_send_sge =
1424 qpcb->actual_nr_sges_in_sq_wqe - 2;
1425 qp_attr->cap.max_recv_sge =
1426 qpcb->actual_nr_sges_in_rq_wqe - 2;
1428 qp_attr->cap.max_send_sge =
1429 qpcb->actual_nr_sges_in_sq_wqe;
1430 qp_attr->cap.max_recv_sge =
1431 qpcb->actual_nr_sges_in_rq_wqe;
1434 qp_attr->cap.max_inline_data = my_qp->sq_max_inline_data_size;
1435 qp_attr->dest_qp_num = qpcb->dest_qp_nr;
1437 qp_attr->pkey_index =
1438 EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->prim_p_key_idx);
1441 EHCA_BMASK_GET(MQPCB_PRIM_PHYS_PORT, qpcb->prim_phys_port);
1443 qp_attr->timeout = qpcb->timeout;
1444 qp_attr->retry_cnt = qpcb->retry_count;
1445 qp_attr->rnr_retry = qpcb->rnr_retry_count;
1447 qp_attr->alt_pkey_index =
1448 EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->alt_p_key_idx);
1450 qp_attr->alt_port_num = qpcb->alt_phys_port;
1451 qp_attr->alt_timeout = qpcb->timeout_al;
1454 qp_attr->ah_attr.sl = qpcb->service_level;
1456 if (qpcb->send_grh_flag) {
1457 qp_attr->ah_attr.ah_flags = IB_AH_GRH;
1460 qp_attr->ah_attr.static_rate = qpcb->max_static_rate;
1461 qp_attr->ah_attr.dlid = qpcb->dlid;
1462 qp_attr->ah_attr.src_path_bits = qpcb->source_path_bits;
1463 qp_attr->ah_attr.port_num = qp_attr->port_num;
1466 qp_attr->ah_attr.grh.traffic_class = qpcb->traffic_class;
1467 qp_attr->ah_attr.grh.hop_limit = qpcb->hop_limit;
1468 qp_attr->ah_attr.grh.sgid_index = qpcb->source_gid_idx;
1469 qp_attr->ah_attr.grh.flow_label = qpcb->flow_label;
1471 for (cnt = 0; cnt < 16; cnt++)
1472 qp_attr->ah_attr.grh.dgid.raw[cnt] =
1473 qpcb->dest_gid.byte[cnt];
1476 qp_attr->alt_ah_attr.sl = qpcb->service_level_al;
1477 if (qpcb->send_grh_flag_al) {
1478 qp_attr->alt_ah_attr.ah_flags = IB_AH_GRH;
1481 qp_attr->alt_ah_attr.static_rate = qpcb->max_static_rate_al;
1482 qp_attr->alt_ah_attr.dlid = qpcb->dlid_al;
1483 qp_attr->alt_ah_attr.src_path_bits = qpcb->source_path_bits_al;
1486 qp_attr->alt_ah_attr.grh.traffic_class = qpcb->traffic_class_al;
1487 qp_attr->alt_ah_attr.grh.hop_limit = qpcb->hop_limit_al;
1488 qp_attr->alt_ah_attr.grh.sgid_index = qpcb->source_gid_idx_al;
1489 qp_attr->alt_ah_attr.grh.flow_label = qpcb->flow_label_al;
1491 for (cnt = 0; cnt < 16; cnt++)
1492 qp_attr->alt_ah_attr.grh.dgid.raw[cnt] =
1493 qpcb->dest_gid_al.byte[cnt];
1495 /* return init attributes given in ehca_create_qp */
1497 *qp_init_attr = my_qp->init_attr;
1499 if (ehca_debug_level)
1500 ehca_dmp(qpcb, 4*70, "qp_num=%x", qp->qp_num);
1503 ehca_free_fw_ctrlblock(qpcb);
1508 int ehca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
1509 enum ib_srq_attr_mask attr_mask, struct ib_udata *udata)
1511 struct ehca_qp *my_qp =
1512 container_of(ibsrq, struct ehca_qp, ib_srq);
1513 struct ehca_pd *my_pd =
1514 container_of(ibsrq->pd, struct ehca_pd, ib_pd);
1515 struct ehca_shca *shca =
1516 container_of(ibsrq->pd->device, struct ehca_shca, ib_device);
1517 struct hcp_modify_qp_control_block *mqpcb;
1522 u32 cur_pid = current->tgid;
1523 if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
1524 my_pd->ownpid != cur_pid) {
1525 ehca_err(ibsrq->pd->device, "Invalid caller pid=%x ownpid=%x",
1526 cur_pid, my_pd->ownpid);
1530 mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
1532 ehca_err(ibsrq->device, "Could not get zeroed page for mqpcb "
1533 "ehca_qp=%p qp_num=%x ", my_qp, my_qp->real_qp_num);
1538 if (attr_mask & IB_SRQ_LIMIT) {
1539 attr_mask &= ~IB_SRQ_LIMIT;
1541 EHCA_BMASK_SET(MQPCB_MASK_CURR_SRQ_LIMIT, 1)
1542 | EHCA_BMASK_SET(MQPCB_MASK_QP_AFF_ASYN_EV_LOG_REG, 1);
1543 mqpcb->curr_srq_limit =
1544 EHCA_BMASK_SET(MQPCB_CURR_SRQ_LIMIT, attr->srq_limit);
1545 mqpcb->qp_aff_asyn_ev_log_reg =
1546 EHCA_BMASK_SET(QPX_AAELOG_RESET_SRQ_LIMIT, 1);
1549 /* by now, all bits in attr_mask should have been cleared */
1551 ehca_err(ibsrq->device, "invalid attribute mask bits set "
1552 "attr_mask=%x", attr_mask);
1554 goto modify_srq_exit0;
1557 if (ehca_debug_level)
1558 ehca_dmp(mqpcb, 4*70, "qp_num=%x", my_qp->real_qp_num);
1560 h_ret = hipz_h_modify_qp(shca->ipz_hca_handle, my_qp->ipz_qp_handle,
1561 NULL, update_mask, mqpcb,
1562 my_qp->galpas.kernel);
1564 if (h_ret != H_SUCCESS) {
1565 ret = ehca2ib_return_code(h_ret);
1566 ehca_err(ibsrq->device, "hipz_h_modify_qp() failed rc=%lx "
1567 "ehca_qp=%p qp_num=%x",
1568 h_ret, my_qp, my_qp->real_qp_num);
1572 ehca_free_fw_ctrlblock(mqpcb);
1577 int ehca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr)
1579 struct ehca_qp *my_qp = container_of(srq, struct ehca_qp, ib_srq);
1580 struct ehca_pd *my_pd = container_of(srq->pd, struct ehca_pd, ib_pd);
1581 struct ehca_shca *shca = container_of(srq->device, struct ehca_shca,
1583 struct ipz_adapter_handle adapter_handle = shca->ipz_hca_handle;
1584 struct hcp_modify_qp_control_block *qpcb;
1585 u32 cur_pid = current->tgid;
1589 if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
1590 my_pd->ownpid != cur_pid) {
1591 ehca_err(srq->device, "Invalid caller pid=%x ownpid=%x",
1592 cur_pid, my_pd->ownpid);
1596 qpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
1598 ehca_err(srq->device, "Out of memory for qpcb "
1599 "ehca_qp=%p qp_num=%x", my_qp, my_qp->real_qp_num);
1603 h_ret = hipz_h_query_qp(adapter_handle, my_qp->ipz_qp_handle,
1604 NULL, qpcb, my_qp->galpas.kernel);
1606 if (h_ret != H_SUCCESS) {
1607 ret = ehca2ib_return_code(h_ret);
1608 ehca_err(srq->device, "hipz_h_query_qp() failed "
1609 "ehca_qp=%p qp_num=%x h_ret=%lx",
1610 my_qp, my_qp->real_qp_num, h_ret);
1611 goto query_srq_exit1;
1614 srq_attr->max_wr = qpcb->max_nr_outst_recv_wr - 1;
1615 srq_attr->srq_limit = EHCA_BMASK_GET(
1616 MQPCB_CURR_SRQ_LIMIT, qpcb->curr_srq_limit);
1618 if (ehca_debug_level)
1619 ehca_dmp(qpcb, 4*70, "qp_num=%x", my_qp->real_qp_num);
1622 ehca_free_fw_ctrlblock(qpcb);
1627 int internal_destroy_qp(struct ib_device *dev, struct ehca_qp *my_qp,
1628 struct ib_uobject *uobject)
1630 struct ehca_shca *shca = container_of(dev, struct ehca_shca, ib_device);
1631 struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
1633 u32 cur_pid = current->tgid;
1634 u32 qp_num = my_qp->real_qp_num;
1638 enum ib_qp_type qp_type;
1639 unsigned long flags;
1642 if (my_qp->mm_count_galpa ||
1643 my_qp->mm_count_rqueue || my_qp->mm_count_squeue) {
1644 ehca_err(dev, "Resources still referenced in "
1645 "user space qp_num=%x", qp_num);
1648 if (my_pd->ownpid != cur_pid) {
1649 ehca_err(dev, "Invalid caller pid=%x ownpid=%x",
1650 cur_pid, my_pd->ownpid);
1655 if (my_qp->send_cq) {
1656 ret = ehca_cq_unassign_qp(my_qp->send_cq, qp_num);
1658 ehca_err(dev, "Couldn't unassign qp from "
1659 "send_cq ret=%x qp_num=%x cq_num=%x", ret,
1660 qp_num, my_qp->send_cq->cq_number);
1665 spin_lock_irqsave(&ehca_qp_idr_lock, flags);
1666 idr_remove(&ehca_qp_idr, my_qp->token);
1667 spin_unlock_irqrestore(&ehca_qp_idr_lock, flags);
1669 h_ret = hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp);
1670 if (h_ret != H_SUCCESS) {
1671 ehca_err(dev, "hipz_h_destroy_qp() failed rc=%lx "
1672 "ehca_qp=%p qp_num=%x", h_ret, my_qp, qp_num);
1673 return ehca2ib_return_code(h_ret);
1676 port_num = my_qp->init_attr.port_num;
1677 qp_type = my_qp->init_attr.qp_type;
1679 /* no support for IB_QPT_SMI yet */
1680 if (qp_type == IB_QPT_GSI) {
1681 struct ib_event event;
1682 ehca_info(dev, "device %s: port %x is inactive.",
1683 shca->ib_device.name, port_num);
1684 event.device = &shca->ib_device;
1685 event.event = IB_EVENT_PORT_ERR;
1686 event.element.port_num = port_num;
1687 shca->sport[port_num - 1].port_state = IB_PORT_DOWN;
1688 ib_dispatch_event(&event);
1692 ipz_queue_dtor(&my_qp->ipz_rqueue);
1694 ipz_queue_dtor(&my_qp->ipz_squeue);
1695 kmem_cache_free(qp_cache, my_qp);
1699 int ehca_destroy_qp(struct ib_qp *qp)
1701 return internal_destroy_qp(qp->device,
1702 container_of(qp, struct ehca_qp, ib_qp),
1706 int ehca_destroy_srq(struct ib_srq *srq)
1708 return internal_destroy_qp(srq->device,
1709 container_of(srq, struct ehca_qp, ib_srq),
1713 int ehca_init_qp_cache(void)
1715 qp_cache = kmem_cache_create("ehca_cache_qp",
1716 sizeof(struct ehca_qp), 0,
1724 void ehca_cleanup_qp_cache(void)
1727 kmem_cache_destroy(qp_cache);