Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IBM eServer eHCA Infiniband device driver for Linux on POWER |
| 3 | * |
| 4 | * QP functions |
| 5 | * |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 6 | * Authors: Joachim Fenkes <fenkes@de.ibm.com> |
| 7 | * Stefan Roscher <stefan.roscher@de.ibm.com> |
| 8 | * Waleri Fomin <fomin@de.ibm.com> |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 9 | * Hoang-Nam Nguyen <hnguyen@de.ibm.com> |
| 10 | * Reinhard Ernst <rernst@de.ibm.com> |
| 11 | * Heiko J Schick <schickhj@de.ibm.com> |
| 12 | * |
| 13 | * Copyright (c) 2005 IBM Corporation |
| 14 | * |
| 15 | * All rights reserved. |
| 16 | * |
| 17 | * This source code is distributed under a dual license of GPL v2.0 and OpenIB |
| 18 | * BSD. |
| 19 | * |
| 20 | * OpenIB BSD License |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions are met: |
| 24 | * |
| 25 | * Redistributions of source code must retain the above copyright notice, this |
| 26 | * list of conditions and the following disclaimer. |
| 27 | * |
| 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. |
| 32 | * |
| 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. |
| 44 | */ |
| 45 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 46 | #include "ehca_classes.h" |
| 47 | #include "ehca_tools.h" |
| 48 | #include "ehca_qes.h" |
| 49 | #include "ehca_iverbs.h" |
| 50 | #include "hcp_if.h" |
| 51 | #include "hipz_fns.h" |
| 52 | |
| 53 | static struct kmem_cache *qp_cache; |
| 54 | |
| 55 | /* |
| 56 | * attributes not supported by query qp |
| 57 | */ |
| 58 | #define QP_ATTR_QUERY_NOT_SUPPORTED (IB_QP_MAX_DEST_RD_ATOMIC | \ |
| 59 | IB_QP_MAX_QP_RD_ATOMIC | \ |
| 60 | IB_QP_ACCESS_FLAGS | \ |
| 61 | IB_QP_EN_SQD_ASYNC_NOTIFY) |
| 62 | |
| 63 | /* |
| 64 | * ehca (internal) qp state values |
| 65 | */ |
| 66 | enum ehca_qp_state { |
| 67 | EHCA_QPS_RESET = 1, |
| 68 | EHCA_QPS_INIT = 2, |
| 69 | EHCA_QPS_RTR = 3, |
| 70 | EHCA_QPS_RTS = 5, |
| 71 | EHCA_QPS_SQD = 6, |
| 72 | EHCA_QPS_SQE = 8, |
| 73 | EHCA_QPS_ERR = 128 |
| 74 | }; |
| 75 | |
| 76 | /* |
| 77 | * qp state transitions as defined by IB Arch Rel 1.1 page 431 |
| 78 | */ |
| 79 | enum ib_qp_statetrans { |
| 80 | IB_QPST_ANY2RESET, |
| 81 | IB_QPST_ANY2ERR, |
| 82 | IB_QPST_RESET2INIT, |
| 83 | IB_QPST_INIT2RTR, |
| 84 | IB_QPST_INIT2INIT, |
| 85 | IB_QPST_RTR2RTS, |
| 86 | IB_QPST_RTS2SQD, |
| 87 | IB_QPST_RTS2RTS, |
| 88 | IB_QPST_SQD2RTS, |
| 89 | IB_QPST_SQE2RTS, |
| 90 | IB_QPST_SQD2SQD, |
| 91 | IB_QPST_MAX /* nr of transitions, this must be last!!! */ |
| 92 | }; |
| 93 | |
| 94 | /* |
| 95 | * ib2ehca_qp_state maps IB to ehca qp_state |
| 96 | * returns ehca qp state corresponding to given ib qp state |
| 97 | */ |
| 98 | static inline enum ehca_qp_state ib2ehca_qp_state(enum ib_qp_state ib_qp_state) |
| 99 | { |
| 100 | switch (ib_qp_state) { |
| 101 | case IB_QPS_RESET: |
| 102 | return EHCA_QPS_RESET; |
| 103 | case IB_QPS_INIT: |
| 104 | return EHCA_QPS_INIT; |
| 105 | case IB_QPS_RTR: |
| 106 | return EHCA_QPS_RTR; |
| 107 | case IB_QPS_RTS: |
| 108 | return EHCA_QPS_RTS; |
| 109 | case IB_QPS_SQD: |
| 110 | return EHCA_QPS_SQD; |
| 111 | case IB_QPS_SQE: |
| 112 | return EHCA_QPS_SQE; |
| 113 | case IB_QPS_ERR: |
| 114 | return EHCA_QPS_ERR; |
| 115 | default: |
| 116 | ehca_gen_err("invalid ib_qp_state=%x", ib_qp_state); |
| 117 | return -EINVAL; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * ehca2ib_qp_state maps ehca to IB qp_state |
| 123 | * returns ib qp state corresponding to given ehca qp state |
| 124 | */ |
| 125 | static inline enum ib_qp_state ehca2ib_qp_state(enum ehca_qp_state |
| 126 | ehca_qp_state) |
| 127 | { |
| 128 | switch (ehca_qp_state) { |
| 129 | case EHCA_QPS_RESET: |
| 130 | return IB_QPS_RESET; |
| 131 | case EHCA_QPS_INIT: |
| 132 | return IB_QPS_INIT; |
| 133 | case EHCA_QPS_RTR: |
| 134 | return IB_QPS_RTR; |
| 135 | case EHCA_QPS_RTS: |
| 136 | return IB_QPS_RTS; |
| 137 | case EHCA_QPS_SQD: |
| 138 | return IB_QPS_SQD; |
| 139 | case EHCA_QPS_SQE: |
| 140 | return IB_QPS_SQE; |
| 141 | case EHCA_QPS_ERR: |
| 142 | return IB_QPS_ERR; |
| 143 | default: |
| 144 | ehca_gen_err("invalid ehca_qp_state=%x", ehca_qp_state); |
| 145 | return -EINVAL; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * ehca_qp_type used as index for req_attr and opt_attr of |
| 151 | * struct ehca_modqp_statetrans |
| 152 | */ |
| 153 | enum ehca_qp_type { |
| 154 | QPT_RC = 0, |
| 155 | QPT_UC = 1, |
| 156 | QPT_UD = 2, |
| 157 | QPT_SQP = 3, |
| 158 | QPT_MAX |
| 159 | }; |
| 160 | |
| 161 | /* |
| 162 | * ib2ehcaqptype maps Ib to ehca qp_type |
| 163 | * returns ehca qp type corresponding to ib qp type |
| 164 | */ |
| 165 | static inline enum ehca_qp_type ib2ehcaqptype(enum ib_qp_type ibqptype) |
| 166 | { |
| 167 | switch (ibqptype) { |
| 168 | case IB_QPT_SMI: |
| 169 | case IB_QPT_GSI: |
| 170 | return QPT_SQP; |
| 171 | case IB_QPT_RC: |
| 172 | return QPT_RC; |
| 173 | case IB_QPT_UC: |
| 174 | return QPT_UC; |
| 175 | case IB_QPT_UD: |
| 176 | return QPT_UD; |
| 177 | default: |
| 178 | ehca_gen_err("Invalid ibqptype=%x", ibqptype); |
| 179 | return -EINVAL; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | static inline enum ib_qp_statetrans get_modqp_statetrans(int ib_fromstate, |
| 184 | int ib_tostate) |
| 185 | { |
| 186 | int index = -EINVAL; |
| 187 | switch (ib_tostate) { |
| 188 | case IB_QPS_RESET: |
| 189 | index = IB_QPST_ANY2RESET; |
| 190 | break; |
| 191 | case IB_QPS_INIT: |
| 192 | switch (ib_fromstate) { |
| 193 | case IB_QPS_RESET: |
| 194 | index = IB_QPST_RESET2INIT; |
| 195 | break; |
| 196 | case IB_QPS_INIT: |
| 197 | index = IB_QPST_INIT2INIT; |
| 198 | break; |
| 199 | } |
| 200 | break; |
| 201 | case IB_QPS_RTR: |
| 202 | if (ib_fromstate == IB_QPS_INIT) |
| 203 | index = IB_QPST_INIT2RTR; |
| 204 | break; |
| 205 | case IB_QPS_RTS: |
| 206 | switch (ib_fromstate) { |
| 207 | case IB_QPS_RTR: |
| 208 | index = IB_QPST_RTR2RTS; |
| 209 | break; |
| 210 | case IB_QPS_RTS: |
| 211 | index = IB_QPST_RTS2RTS; |
| 212 | break; |
| 213 | case IB_QPS_SQD: |
| 214 | index = IB_QPST_SQD2RTS; |
| 215 | break; |
| 216 | case IB_QPS_SQE: |
| 217 | index = IB_QPST_SQE2RTS; |
| 218 | break; |
| 219 | } |
| 220 | break; |
| 221 | case IB_QPS_SQD: |
| 222 | if (ib_fromstate == IB_QPS_RTS) |
| 223 | index = IB_QPST_RTS2SQD; |
| 224 | break; |
| 225 | case IB_QPS_SQE: |
| 226 | break; |
| 227 | case IB_QPS_ERR: |
| 228 | index = IB_QPST_ANY2ERR; |
| 229 | break; |
| 230 | default: |
| 231 | break; |
| 232 | } |
| 233 | return index; |
| 234 | } |
| 235 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 236 | /* |
| 237 | * ibqptype2servicetype returns hcp service type corresponding to given |
| 238 | * ib qp type used by create_qp() |
| 239 | */ |
| 240 | static inline int ibqptype2servicetype(enum ib_qp_type ibqptype) |
| 241 | { |
| 242 | switch (ibqptype) { |
| 243 | case IB_QPT_SMI: |
| 244 | case IB_QPT_GSI: |
| 245 | return ST_UD; |
| 246 | case IB_QPT_RC: |
| 247 | return ST_RC; |
| 248 | case IB_QPT_UC: |
| 249 | return ST_UC; |
| 250 | case IB_QPT_UD: |
| 251 | return ST_UD; |
| 252 | case IB_QPT_RAW_IPV6: |
| 253 | return -EINVAL; |
| 254 | case IB_QPT_RAW_ETY: |
| 255 | return -EINVAL; |
| 256 | default: |
| 257 | ehca_gen_err("Invalid ibqptype=%x", ibqptype); |
| 258 | return -EINVAL; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /* |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 263 | * init userspace queue info from ipz_queue data |
| 264 | */ |
| 265 | static inline void queue2resp(struct ipzu_queue_resp *resp, |
| 266 | struct ipz_queue *queue) |
| 267 | { |
| 268 | resp->qe_size = queue->qe_size; |
| 269 | resp->act_nr_of_sg = queue->act_nr_of_sg; |
| 270 | resp->queue_length = queue->queue_length; |
| 271 | resp->pagesize = queue->pagesize; |
| 272 | resp->toggle_state = queue->toggle_state; |
Stefan Roscher | 441633b9 | 2007-09-11 15:26:33 +0200 | [diff] [blame] | 273 | resp->offset = queue->offset; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /* |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 277 | * init_qp_queue initializes/constructs r/squeue and registers queue pages. |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 278 | */ |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 279 | static inline int init_qp_queue(struct ehca_shca *shca, |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 280 | struct ehca_pd *pd, |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 281 | struct ehca_qp *my_qp, |
| 282 | struct ipz_queue *queue, |
| 283 | int q_type, |
| 284 | u64 expected_hret, |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 285 | struct ehca_alloc_queue_parms *parms, |
| 286 | int wqe_size) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 287 | { |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 288 | int ret, cnt, ipz_rc, nr_q_pages; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 289 | void *vpage; |
| 290 | u64 rpage, h_ret; |
| 291 | struct ib_device *ib_dev = &shca->ib_device; |
| 292 | struct ipz_adapter_handle ipz_hca_handle = shca->ipz_hca_handle; |
| 293 | |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 294 | if (!parms->queue_size) |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 295 | return 0; |
| 296 | |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 297 | if (parms->is_small) { |
| 298 | nr_q_pages = 1; |
| 299 | ipz_rc = ipz_queue_ctor(pd, queue, nr_q_pages, |
| 300 | 128 << parms->page_size, |
| 301 | wqe_size, parms->act_nr_sges, 1); |
| 302 | } else { |
| 303 | nr_q_pages = parms->queue_size; |
| 304 | ipz_rc = ipz_queue_ctor(pd, queue, nr_q_pages, |
| 305 | EHCA_PAGESIZE, wqe_size, |
| 306 | parms->act_nr_sges, 0); |
| 307 | } |
| 308 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 309 | if (!ipz_rc) { |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 310 | ehca_err(ib_dev, "Cannot allocate page for queue. ipz_rc=%i", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 311 | ipz_rc); |
| 312 | return -EBUSY; |
| 313 | } |
| 314 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 315 | /* register queue pages */ |
| 316 | for (cnt = 0; cnt < nr_q_pages; cnt++) { |
| 317 | vpage = ipz_qpageit_get_inc(queue); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 318 | if (!vpage) { |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 319 | ehca_err(ib_dev, "ipz_qpageit_get_inc() " |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 320 | "failed p_vpage= %p", vpage); |
| 321 | ret = -EINVAL; |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 322 | goto init_qp_queue1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 323 | } |
| 324 | rpage = virt_to_abs(vpage); |
| 325 | |
| 326 | h_ret = hipz_h_register_rpage_qp(ipz_hca_handle, |
| 327 | my_qp->ipz_qp_handle, |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 328 | NULL, 0, q_type, |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 329 | rpage, parms->is_small ? 0 : 1, |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 330 | my_qp->galpas.kernel); |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 331 | if (cnt == (nr_q_pages - 1)) { /* last page! */ |
| 332 | if (h_ret != expected_hret) { |
| 333 | ehca_err(ib_dev, "hipz_qp_register_rpage() " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 334 | "h_ret=%li", h_ret); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 335 | ret = ehca2ib_return_code(h_ret); |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 336 | goto init_qp_queue1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 337 | } |
| 338 | vpage = ipz_qpageit_get_inc(&my_qp->ipz_rqueue); |
| 339 | if (vpage) { |
| 340 | ehca_err(ib_dev, "ipz_qpageit_get_inc() " |
| 341 | "should not succeed vpage=%p", vpage); |
| 342 | ret = -EINVAL; |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 343 | goto init_qp_queue1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 344 | } |
| 345 | } else { |
| 346 | if (h_ret != H_PAGE_REGISTERED) { |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 347 | ehca_err(ib_dev, "hipz_qp_register_rpage() " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 348 | "h_ret=%li", h_ret); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 349 | ret = ehca2ib_return_code(h_ret); |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 350 | goto init_qp_queue1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | } |
| 354 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 355 | ipz_qeit_reset(queue); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 356 | |
| 357 | return 0; |
| 358 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 359 | init_qp_queue1: |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 360 | ipz_queue_dtor(pd, queue); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 361 | return ret; |
| 362 | } |
| 363 | |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 364 | static inline int ehca_calc_wqe_size(int act_nr_sge, int is_llqp) |
| 365 | { |
| 366 | if (is_llqp) |
| 367 | return 128 << act_nr_sge; |
| 368 | else |
| 369 | return offsetof(struct ehca_wqe, |
| 370 | u.nud.sg_list[act_nr_sge]); |
| 371 | } |
| 372 | |
| 373 | static void ehca_determine_small_queue(struct ehca_alloc_queue_parms *queue, |
| 374 | int req_nr_sge, int is_llqp) |
| 375 | { |
| 376 | u32 wqe_size, q_size; |
| 377 | int act_nr_sge = req_nr_sge; |
| 378 | |
| 379 | if (!is_llqp) |
| 380 | /* round up #SGEs so WQE size is a power of 2 */ |
| 381 | for (act_nr_sge = 4; act_nr_sge <= 252; |
| 382 | act_nr_sge = 4 + 2 * act_nr_sge) |
| 383 | if (act_nr_sge >= req_nr_sge) |
| 384 | break; |
| 385 | |
| 386 | wqe_size = ehca_calc_wqe_size(act_nr_sge, is_llqp); |
| 387 | q_size = wqe_size * (queue->max_wr + 1); |
| 388 | |
| 389 | if (q_size <= 512) |
| 390 | queue->page_size = 2; |
| 391 | else if (q_size <= 1024) |
| 392 | queue->page_size = 3; |
| 393 | else |
| 394 | queue->page_size = 0; |
| 395 | |
| 396 | queue->is_small = (queue->page_size != 0); |
| 397 | } |
| 398 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 399 | /* |
| 400 | * Create an ib_qp struct that is either a QP or an SRQ, depending on |
| 401 | * the value of the is_srq parameter. If init_attr and srq_init_attr share |
| 402 | * fields, the field out of init_attr is used. |
| 403 | */ |
Joachim Fenkes | 0c10f7b | 2007-07-19 21:40:00 +0200 | [diff] [blame] | 404 | static struct ehca_qp *internal_create_qp( |
| 405 | struct ib_pd *pd, |
| 406 | struct ib_qp_init_attr *init_attr, |
| 407 | struct ib_srq_init_attr *srq_init_attr, |
| 408 | struct ib_udata *udata, int is_srq) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 409 | { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 410 | struct ehca_qp *my_qp; |
| 411 | struct ehca_pd *my_pd = container_of(pd, struct ehca_pd, ib_pd); |
| 412 | struct ehca_shca *shca = container_of(pd->device, struct ehca_shca, |
| 413 | ib_device); |
| 414 | struct ib_ucontext *context = NULL; |
| 415 | u64 h_ret; |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 416 | int is_llqp = 0, has_srq = 0; |
| 417 | int qp_type, max_send_sge, max_recv_sge, ret; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 418 | |
| 419 | /* h_call's out parameters */ |
| 420 | struct ehca_alloc_qp_parms parms; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 421 | u32 swqe_size = 0, rwqe_size = 0, ib_qp_num; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 422 | unsigned long flags; |
| 423 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 424 | memset(&parms, 0, sizeof(parms)); |
| 425 | qp_type = init_attr->qp_type; |
| 426 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 427 | if (init_attr->sq_sig_type != IB_SIGNAL_REQ_WR && |
| 428 | init_attr->sq_sig_type != IB_SIGNAL_ALL_WR) { |
| 429 | ehca_err(pd->device, "init_attr->sg_sig_type=%x not allowed", |
| 430 | init_attr->sq_sig_type); |
| 431 | return ERR_PTR(-EINVAL); |
| 432 | } |
| 433 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 434 | /* save LLQP info */ |
| 435 | if (qp_type & 0x80) { |
| 436 | is_llqp = 1; |
| 437 | parms.ext_type = EQPT_LLQP; |
| 438 | parms.ll_comp_flags = qp_type & LLQP_COMP_MASK; |
| 439 | } |
| 440 | qp_type &= 0x1F; |
Stefan Roscher | 472803d | 2007-07-09 15:26:31 +0200 | [diff] [blame] | 441 | init_attr->qp_type &= 0x1F; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 442 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 443 | /* handle SRQ base QPs */ |
| 444 | if (init_attr->srq) { |
| 445 | struct ehca_qp *my_srq = |
| 446 | container_of(init_attr->srq, struct ehca_qp, ib_srq); |
| 447 | |
| 448 | has_srq = 1; |
| 449 | parms.ext_type = EQPT_SRQBASE; |
| 450 | parms.srq_qpn = my_srq->real_qp_num; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 451 | } |
| 452 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 453 | if (is_llqp && has_srq) { |
| 454 | ehca_err(pd->device, "LLQPs can't have an SRQ"); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 455 | return ERR_PTR(-EINVAL); |
| 456 | } |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 457 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 458 | /* handle SRQs */ |
| 459 | if (is_srq) { |
| 460 | parms.ext_type = EQPT_SRQ; |
| 461 | parms.srq_limit = srq_init_attr->attr.srq_limit; |
| 462 | if (init_attr->cap.max_recv_sge > 3) { |
| 463 | ehca_err(pd->device, "no more than three SGEs " |
| 464 | "supported for SRQ pd=%p max_sge=%x", |
| 465 | pd, init_attr->cap.max_recv_sge); |
| 466 | return ERR_PTR(-EINVAL); |
| 467 | } |
| 468 | } |
| 469 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 470 | /* check QP type */ |
| 471 | if (qp_type != IB_QPT_UD && |
| 472 | qp_type != IB_QPT_UC && |
| 473 | qp_type != IB_QPT_RC && |
| 474 | qp_type != IB_QPT_SMI && |
| 475 | qp_type != IB_QPT_GSI) { |
| 476 | ehca_err(pd->device, "wrong QP Type=%x", qp_type); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 477 | return ERR_PTR(-EINVAL); |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Stefan Roscher | 472803d | 2007-07-09 15:26:31 +0200 | [diff] [blame] | 480 | if (is_llqp) { |
| 481 | switch (qp_type) { |
| 482 | case IB_QPT_RC: |
| 483 | if ((init_attr->cap.max_send_wr > 255) || |
| 484 | (init_attr->cap.max_recv_wr > 255)) { |
| 485 | ehca_err(pd->device, |
| 486 | "Invalid Number of max_sq_wr=%x " |
| 487 | "or max_rq_wr=%x for RC LLQP", |
| 488 | init_attr->cap.max_send_wr, |
| 489 | init_attr->cap.max_recv_wr); |
| 490 | return ERR_PTR(-EINVAL); |
| 491 | } |
| 492 | break; |
| 493 | case IB_QPT_UD: |
| 494 | if (!EHCA_BMASK_GET(HCA_CAP_UD_LL_QP, shca->hca_cap)) { |
| 495 | ehca_err(pd->device, "UD LLQP not supported " |
| 496 | "by this adapter"); |
| 497 | return ERR_PTR(-ENOSYS); |
| 498 | } |
| 499 | if (!(init_attr->cap.max_send_sge <= 5 |
| 500 | && init_attr->cap.max_send_sge >= 1 |
| 501 | && init_attr->cap.max_recv_sge <= 5 |
| 502 | && init_attr->cap.max_recv_sge >= 1)) { |
| 503 | ehca_err(pd->device, |
| 504 | "Invalid Number of max_send_sge=%x " |
| 505 | "or max_recv_sge=%x for UD LLQP", |
| 506 | init_attr->cap.max_send_sge, |
| 507 | init_attr->cap.max_recv_sge); |
| 508 | return ERR_PTR(-EINVAL); |
| 509 | } else if (init_attr->cap.max_send_wr > 255) { |
| 510 | ehca_err(pd->device, |
| 511 | "Invalid Number of " |
Joachim Fenkes | b708fba | 2007-09-11 15:33:40 +0200 | [diff] [blame] | 512 | "max_send_wr=%x for UD QP_TYPE=%x", |
Stefan Roscher | 472803d | 2007-07-09 15:26:31 +0200 | [diff] [blame] | 513 | init_attr->cap.max_send_wr, qp_type); |
| 514 | return ERR_PTR(-EINVAL); |
| 515 | } |
| 516 | break; |
| 517 | default: |
| 518 | ehca_err(pd->device, "unsupported LL QP Type=%x", |
| 519 | qp_type); |
| 520 | return ERR_PTR(-EINVAL); |
| 521 | break; |
| 522 | } |
Joachim Fenkes | b708fba | 2007-09-11 15:33:40 +0200 | [diff] [blame] | 523 | } else { |
| 524 | int max_sge = (qp_type == IB_QPT_UD || qp_type == IB_QPT_SMI |
| 525 | || qp_type == IB_QPT_GSI) ? 250 : 252; |
| 526 | |
| 527 | if (init_attr->cap.max_send_sge > max_sge |
| 528 | || init_attr->cap.max_recv_sge > max_sge) { |
| 529 | ehca_err(pd->device, "Invalid number of SGEs requested " |
| 530 | "send_sge=%x recv_sge=%x max_sge=%x", |
| 531 | init_attr->cap.max_send_sge, |
| 532 | init_attr->cap.max_recv_sge, max_sge); |
| 533 | return ERR_PTR(-EINVAL); |
| 534 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | if (pd->uobject && udata) |
| 538 | context = pd->uobject->context; |
| 539 | |
Robert P. J. Day | c376222 | 2007-02-10 01:45:03 -0800 | [diff] [blame] | 540 | my_qp = kmem_cache_zalloc(qp_cache, GFP_KERNEL); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 541 | if (!my_qp) { |
| 542 | ehca_err(pd->device, "pd=%p not enough memory to alloc qp", pd); |
| 543 | return ERR_PTR(-ENOMEM); |
| 544 | } |
| 545 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 546 | spin_lock_init(&my_qp->spinlock_s); |
| 547 | spin_lock_init(&my_qp->spinlock_r); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 548 | my_qp->qp_type = qp_type; |
| 549 | my_qp->ext_type = parms.ext_type; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 550 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 551 | if (init_attr->recv_cq) |
| 552 | my_qp->recv_cq = |
| 553 | container_of(init_attr->recv_cq, struct ehca_cq, ib_cq); |
| 554 | if (init_attr->send_cq) |
| 555 | my_qp->send_cq = |
| 556 | container_of(init_attr->send_cq, struct ehca_cq, ib_cq); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 557 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 558 | do { |
| 559 | if (!idr_pre_get(&ehca_qp_idr, GFP_KERNEL)) { |
| 560 | ret = -ENOMEM; |
| 561 | ehca_err(pd->device, "Can't reserve idr resources."); |
| 562 | goto create_qp_exit0; |
| 563 | } |
| 564 | |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 565 | write_lock_irqsave(&ehca_qp_idr_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 566 | ret = idr_get_new(&ehca_qp_idr, my_qp, &my_qp->token); |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 567 | write_unlock_irqrestore(&ehca_qp_idr_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 568 | } while (ret == -EAGAIN); |
| 569 | |
| 570 | if (ret) { |
| 571 | ret = -ENOMEM; |
| 572 | ehca_err(pd->device, "Can't allocate new idr entry."); |
| 573 | goto create_qp_exit0; |
| 574 | } |
| 575 | |
Stefan Roscher | 5281a4b | 2007-09-11 15:29:39 +0200 | [diff] [blame] | 576 | if (my_qp->token > 0x1FFFFFF) { |
| 577 | ret = -EINVAL; |
| 578 | ehca_err(pd->device, "Invalid number of qp"); |
| 579 | goto create_qp_exit1; |
| 580 | } |
| 581 | |
Joachim Fenkes | c0c84d5 | 2007-10-16 17:24:07 +0200 | [diff] [blame] | 582 | if (has_srq) |
| 583 | parms.srq_token = my_qp->token; |
| 584 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 585 | parms.servicetype = ibqptype2servicetype(qp_type); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 586 | if (parms.servicetype < 0) { |
| 587 | ret = -EINVAL; |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 588 | ehca_err(pd->device, "Invalid qp_type=%x", qp_type); |
Stefan Roscher | 5281a4b | 2007-09-11 15:29:39 +0200 | [diff] [blame] | 589 | goto create_qp_exit1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Joachim Fenkes | 2ec8e662 | 2008-01-17 15:07:24 +0100 | [diff] [blame] | 592 | /* Always signal by WQE so we can hide circ. WQEs */ |
| 593 | parms.sigtype = HCALL_SIGT_BY_WQE; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 594 | |
| 595 | /* UD_AV CIRCUMVENTION */ |
| 596 | max_send_sge = init_attr->cap.max_send_sge; |
| 597 | max_recv_sge = init_attr->cap.max_recv_sge; |
Stefan Roscher | 472803d | 2007-07-09 15:26:31 +0200 | [diff] [blame] | 598 | if (parms.servicetype == ST_UD && !is_llqp) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 599 | max_send_sge += 2; |
| 600 | max_recv_sge += 2; |
| 601 | } |
| 602 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 603 | parms.token = my_qp->token; |
| 604 | parms.eq_handle = shca->eq.ipz_eq_handle; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 605 | parms.pd = my_pd->fw_pd; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 606 | if (my_qp->send_cq) |
| 607 | parms.send_cq_handle = my_qp->send_cq->ipz_cq_handle; |
| 608 | if (my_qp->recv_cq) |
| 609 | parms.recv_cq_handle = my_qp->recv_cq->ipz_cq_handle; |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 610 | |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 611 | parms.squeue.max_wr = init_attr->cap.max_send_wr; |
| 612 | parms.rqueue.max_wr = init_attr->cap.max_recv_wr; |
| 613 | parms.squeue.max_sge = max_send_sge; |
| 614 | parms.rqueue.max_sge = max_recv_sge; |
| 615 | |
Joachim Fenkes | 2ec8e662 | 2008-01-17 15:07:24 +0100 | [diff] [blame] | 616 | /* RC QPs need one more SWQE for unsolicited ack circumvention */ |
| 617 | if (qp_type == IB_QPT_RC) |
| 618 | parms.squeue.max_wr++; |
| 619 | |
Stefan Roscher | 441633b9 | 2007-09-11 15:26:33 +0200 | [diff] [blame] | 620 | if (EHCA_BMASK_GET(HCA_CAP_MINI_QP, shca->hca_cap)) { |
Stefan Roscher | fecea0a | 2007-08-31 16:02:59 +0200 | [diff] [blame] | 621 | if (HAS_SQ(my_qp)) |
| 622 | ehca_determine_small_queue( |
| 623 | &parms.squeue, max_send_sge, is_llqp); |
| 624 | if (HAS_RQ(my_qp)) |
| 625 | ehca_determine_small_queue( |
| 626 | &parms.rqueue, max_recv_sge, is_llqp); |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 627 | parms.qp_storage = |
| 628 | (parms.squeue.is_small || parms.rqueue.is_small); |
| 629 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 630 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 631 | h_ret = hipz_h_alloc_resource_qp(shca->ipz_hca_handle, &parms); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 632 | if (h_ret != H_SUCCESS) { |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 633 | ehca_err(pd->device, "h_alloc_resource_qp() failed h_ret=%li", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 634 | h_ret); |
| 635 | ret = ehca2ib_return_code(h_ret); |
| 636 | goto create_qp_exit1; |
| 637 | } |
| 638 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 639 | ib_qp_num = my_qp->real_qp_num = parms.real_qp_num; |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 640 | my_qp->ipz_qp_handle = parms.qp_handle; |
| 641 | my_qp->galpas = parms.galpas; |
Hoang-Nam Nguyen | c55a0dd | 2007-05-09 13:48:11 +0200 | [diff] [blame] | 642 | |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 643 | swqe_size = ehca_calc_wqe_size(parms.squeue.act_nr_sges, is_llqp); |
| 644 | rwqe_size = ehca_calc_wqe_size(parms.rqueue.act_nr_sges, is_llqp); |
| 645 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 646 | switch (qp_type) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 647 | case IB_QPT_RC: |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 648 | if (is_llqp) { |
| 649 | parms.squeue.act_nr_sges = 1; |
| 650 | parms.rqueue.act_nr_sges = 1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 651 | } |
Joachim Fenkes | 2ec8e662 | 2008-01-17 15:07:24 +0100 | [diff] [blame] | 652 | /* hide the extra WQE */ |
| 653 | parms.squeue.act_nr_wqes--; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 654 | break; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 655 | case IB_QPT_UD: |
| 656 | case IB_QPT_GSI: |
| 657 | case IB_QPT_SMI: |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 658 | /* UD circumvention */ |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 659 | if (is_llqp) { |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 660 | parms.squeue.act_nr_sges = 1; |
| 661 | parms.rqueue.act_nr_sges = 1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 662 | } else { |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 663 | parms.squeue.act_nr_sges -= 2; |
| 664 | parms.rqueue.act_nr_sges -= 2; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 667 | if (IB_QPT_GSI == qp_type || IB_QPT_SMI == qp_type) { |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 668 | parms.squeue.act_nr_wqes = init_attr->cap.max_send_wr; |
| 669 | parms.rqueue.act_nr_wqes = init_attr->cap.max_recv_wr; |
| 670 | parms.squeue.act_nr_sges = init_attr->cap.max_send_sge; |
| 671 | parms.rqueue.act_nr_sges = init_attr->cap.max_recv_sge; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 672 | ib_qp_num = (qp_type == IB_QPT_SMI) ? 0 : 1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | break; |
| 676 | |
| 677 | default: |
| 678 | break; |
| 679 | } |
| 680 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 681 | /* initialize r/squeue and register queue pages */ |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 682 | if (HAS_SQ(my_qp)) { |
| 683 | ret = init_qp_queue( |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 684 | shca, my_pd, my_qp, &my_qp->ipz_squeue, 0, |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 685 | HAS_RQ(my_qp) ? H_PAGE_REGISTERED : H_SUCCESS, |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 686 | &parms.squeue, swqe_size); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 687 | if (ret) { |
| 688 | ehca_err(pd->device, "Couldn't initialize squeue " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 689 | "and pages ret=%i", ret); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 690 | goto create_qp_exit2; |
| 691 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 694 | if (HAS_RQ(my_qp)) { |
| 695 | ret = init_qp_queue( |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 696 | shca, my_pd, my_qp, &my_qp->ipz_rqueue, 1, |
| 697 | H_SUCCESS, &parms.rqueue, rwqe_size); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 698 | if (ret) { |
| 699 | ehca_err(pd->device, "Couldn't initialize rqueue " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 700 | "and pages ret=%i", ret); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 701 | goto create_qp_exit3; |
| 702 | } |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 703 | } |
| 704 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 705 | if (is_srq) { |
| 706 | my_qp->ib_srq.pd = &my_pd->ib_pd; |
| 707 | my_qp->ib_srq.device = my_pd->ib_pd.device; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 708 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 709 | my_qp->ib_srq.srq_context = init_attr->qp_context; |
| 710 | my_qp->ib_srq.event_handler = init_attr->event_handler; |
| 711 | } else { |
| 712 | my_qp->ib_qp.qp_num = ib_qp_num; |
| 713 | my_qp->ib_qp.pd = &my_pd->ib_pd; |
| 714 | my_qp->ib_qp.device = my_pd->ib_pd.device; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 715 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 716 | my_qp->ib_qp.recv_cq = init_attr->recv_cq; |
| 717 | my_qp->ib_qp.send_cq = init_attr->send_cq; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 718 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 719 | my_qp->ib_qp.qp_type = qp_type; |
| 720 | my_qp->ib_qp.srq = init_attr->srq; |
| 721 | |
| 722 | my_qp->ib_qp.qp_context = init_attr->qp_context; |
| 723 | my_qp->ib_qp.event_handler = init_attr->event_handler; |
| 724 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 725 | |
| 726 | init_attr->cap.max_inline_data = 0; /* not supported yet */ |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 727 | init_attr->cap.max_recv_sge = parms.rqueue.act_nr_sges; |
| 728 | init_attr->cap.max_recv_wr = parms.rqueue.act_nr_wqes; |
| 729 | init_attr->cap.max_send_sge = parms.squeue.act_nr_sges; |
| 730 | init_attr->cap.max_send_wr = parms.squeue.act_nr_wqes; |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 731 | my_qp->init_attr = *init_attr; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 732 | |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 733 | if (qp_type == IB_QPT_SMI || qp_type == IB_QPT_GSI) { |
| 734 | shca->sport[init_attr->port_num - 1].ibqp_sqp[qp_type] = |
| 735 | &my_qp->ib_qp; |
| 736 | if (ehca_nr_ports < 0) { |
| 737 | /* alloc array to cache subsequent modify qp parms |
| 738 | * for autodetect mode |
| 739 | */ |
| 740 | my_qp->mod_qp_parm = |
| 741 | kzalloc(EHCA_MOD_QP_PARM_MAX * |
| 742 | sizeof(*my_qp->mod_qp_parm), |
| 743 | GFP_KERNEL); |
| 744 | if (!my_qp->mod_qp_parm) { |
| 745 | ehca_err(pd->device, |
| 746 | "Could not alloc mod_qp_parm"); |
| 747 | goto create_qp_exit4; |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 752 | /* NOTE: define_apq0() not supported yet */ |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 753 | if (qp_type == IB_QPT_GSI) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 754 | h_ret = ehca_define_sqp(shca, my_qp, init_attr); |
| 755 | if (h_ret != H_SUCCESS) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 756 | ret = ehca2ib_return_code(h_ret); |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 757 | goto create_qp_exit5; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 760 | |
| 761 | if (my_qp->send_cq) { |
| 762 | ret = ehca_cq_assign_qp(my_qp->send_cq, my_qp); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 763 | if (ret) { |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 764 | ehca_err(pd->device, |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 765 | "Couldn't assign qp to send_cq ret=%i", ret); |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 766 | goto create_qp_exit5; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 767 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 768 | } |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 769 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 770 | /* copy queues, galpa data to user space */ |
| 771 | if (context && udata) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 772 | struct ehca_create_qp_resp resp; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 773 | memset(&resp, 0, sizeof(resp)); |
| 774 | |
| 775 | resp.qp_num = my_qp->real_qp_num; |
| 776 | resp.token = my_qp->token; |
| 777 | resp.qp_type = my_qp->qp_type; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 778 | resp.ext_type = my_qp->ext_type; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 779 | resp.qkey = my_qp->qkey; |
| 780 | resp.real_qp_num = my_qp->real_qp_num; |
Stefan Roscher | 441633b9 | 2007-09-11 15:26:33 +0200 | [diff] [blame] | 781 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 782 | if (HAS_SQ(my_qp)) |
| 783 | queue2resp(&resp.ipz_squeue, &my_qp->ipz_squeue); |
| 784 | if (HAS_RQ(my_qp)) |
| 785 | queue2resp(&resp.ipz_rqueue, &my_qp->ipz_rqueue); |
Hoang-Nam Nguyen | e390d3b | 2007-09-11 15:31:06 +0200 | [diff] [blame] | 786 | resp.fw_handle_ofs = (u32) |
| 787 | (my_qp->galpas.user.fw_handle & (PAGE_SIZE - 1)); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 788 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 789 | if (ib_copy_to_udata(udata, &resp, sizeof resp)) { |
| 790 | ehca_err(pd->device, "Copy to udata failed"); |
| 791 | ret = -EINVAL; |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 792 | goto create_qp_exit6; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 796 | return my_qp; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 797 | |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 798 | create_qp_exit6: |
Hoang-Nam Nguyen | 0c86e28 | 2008-01-17 15:03:55 +0100 | [diff] [blame] | 799 | ehca_cq_unassign_qp(my_qp->send_cq, my_qp->real_qp_num); |
| 800 | |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 801 | create_qp_exit5: |
| 802 | kfree(my_qp->mod_qp_parm); |
| 803 | |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 804 | create_qp_exit4: |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 805 | if (HAS_RQ(my_qp)) |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 806 | ipz_queue_dtor(my_pd, &my_qp->ipz_rqueue); |
Joachim Fenkes | 9a79fc0 | 2007-07-09 15:23:15 +0200 | [diff] [blame] | 807 | |
| 808 | create_qp_exit3: |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 809 | if (HAS_SQ(my_qp)) |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 810 | ipz_queue_dtor(my_pd, &my_qp->ipz_squeue); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 811 | |
| 812 | create_qp_exit2: |
| 813 | hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp); |
| 814 | |
| 815 | create_qp_exit1: |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 816 | write_lock_irqsave(&ehca_qp_idr_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 817 | idr_remove(&ehca_qp_idr, my_qp->token); |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 818 | write_unlock_irqrestore(&ehca_qp_idr_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 819 | |
| 820 | create_qp_exit0: |
| 821 | kmem_cache_free(qp_cache, my_qp); |
| 822 | return ERR_PTR(ret); |
| 823 | } |
| 824 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 825 | struct ib_qp *ehca_create_qp(struct ib_pd *pd, |
| 826 | struct ib_qp_init_attr *qp_init_attr, |
| 827 | struct ib_udata *udata) |
| 828 | { |
| 829 | struct ehca_qp *ret; |
| 830 | |
| 831 | ret = internal_create_qp(pd, qp_init_attr, NULL, udata, 0); |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 832 | return IS_ERR(ret) ? (struct ib_qp *)ret : &ret->ib_qp; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 833 | } |
| 834 | |
Joachim Fenkes | 0c10f7b | 2007-07-19 21:40:00 +0200 | [diff] [blame] | 835 | static int internal_destroy_qp(struct ib_device *dev, struct ehca_qp *my_qp, |
| 836 | struct ib_uobject *uobject); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 837 | |
| 838 | struct ib_srq *ehca_create_srq(struct ib_pd *pd, |
| 839 | struct ib_srq_init_attr *srq_init_attr, |
| 840 | struct ib_udata *udata) |
| 841 | { |
| 842 | struct ib_qp_init_attr qp_init_attr; |
| 843 | struct ehca_qp *my_qp; |
| 844 | struct ib_srq *ret; |
| 845 | struct ehca_shca *shca = container_of(pd->device, struct ehca_shca, |
| 846 | ib_device); |
| 847 | struct hcp_modify_qp_control_block *mqpcb; |
| 848 | u64 hret, update_mask; |
| 849 | |
| 850 | /* For common attributes, internal_create_qp() takes its info |
| 851 | * out of qp_init_attr, so copy all common attrs there. |
| 852 | */ |
| 853 | memset(&qp_init_attr, 0, sizeof(qp_init_attr)); |
| 854 | qp_init_attr.event_handler = srq_init_attr->event_handler; |
| 855 | qp_init_attr.qp_context = srq_init_attr->srq_context; |
| 856 | qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR; |
| 857 | qp_init_attr.qp_type = IB_QPT_RC; |
| 858 | qp_init_attr.cap.max_recv_wr = srq_init_attr->attr.max_wr; |
| 859 | qp_init_attr.cap.max_recv_sge = srq_init_attr->attr.max_sge; |
| 860 | |
| 861 | my_qp = internal_create_qp(pd, &qp_init_attr, srq_init_attr, udata, 1); |
| 862 | if (IS_ERR(my_qp)) |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 863 | return (struct ib_srq *)my_qp; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 864 | |
| 865 | /* copy back return values */ |
| 866 | srq_init_attr->attr.max_wr = qp_init_attr.cap.max_recv_wr; |
Joachim Fenkes | 1457edc | 2007-12-10 12:20:57 +0100 | [diff] [blame] | 867 | srq_init_attr->attr.max_sge = 3; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 868 | |
| 869 | /* drive SRQ into RTR state */ |
| 870 | mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL); |
| 871 | if (!mqpcb) { |
| 872 | ehca_err(pd->device, "Could not get zeroed page for mqpcb " |
| 873 | "ehca_qp=%p qp_num=%x ", my_qp, my_qp->real_qp_num); |
| 874 | ret = ERR_PTR(-ENOMEM); |
| 875 | goto create_srq1; |
| 876 | } |
| 877 | |
| 878 | mqpcb->qp_state = EHCA_QPS_INIT; |
| 879 | mqpcb->prim_phys_port = 1; |
| 880 | update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1); |
| 881 | hret = hipz_h_modify_qp(shca->ipz_hca_handle, |
| 882 | my_qp->ipz_qp_handle, |
| 883 | &my_qp->pf, |
| 884 | update_mask, |
| 885 | mqpcb, my_qp->galpas.kernel); |
| 886 | if (hret != H_SUCCESS) { |
Joe Perches | 908cf9a | 2007-11-19 17:48:11 -0800 | [diff] [blame] | 887 | ehca_err(pd->device, "Could not modify SRQ to INIT " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 888 | "ehca_qp=%p qp_num=%x h_ret=%li", |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 889 | my_qp, my_qp->real_qp_num, hret); |
| 890 | goto create_srq2; |
| 891 | } |
| 892 | |
| 893 | mqpcb->qp_enable = 1; |
| 894 | update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_ENABLE, 1); |
| 895 | hret = hipz_h_modify_qp(shca->ipz_hca_handle, |
| 896 | my_qp->ipz_qp_handle, |
| 897 | &my_qp->pf, |
| 898 | update_mask, |
| 899 | mqpcb, my_qp->galpas.kernel); |
| 900 | if (hret != H_SUCCESS) { |
Joe Perches | 908cf9a | 2007-11-19 17:48:11 -0800 | [diff] [blame] | 901 | ehca_err(pd->device, "Could not enable SRQ " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 902 | "ehca_qp=%p qp_num=%x h_ret=%li", |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 903 | my_qp, my_qp->real_qp_num, hret); |
| 904 | goto create_srq2; |
| 905 | } |
| 906 | |
| 907 | mqpcb->qp_state = EHCA_QPS_RTR; |
| 908 | update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1); |
| 909 | hret = hipz_h_modify_qp(shca->ipz_hca_handle, |
| 910 | my_qp->ipz_qp_handle, |
| 911 | &my_qp->pf, |
| 912 | update_mask, |
| 913 | mqpcb, my_qp->galpas.kernel); |
| 914 | if (hret != H_SUCCESS) { |
Joe Perches | 908cf9a | 2007-11-19 17:48:11 -0800 | [diff] [blame] | 915 | ehca_err(pd->device, "Could not modify SRQ to RTR " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 916 | "ehca_qp=%p qp_num=%x h_ret=%li", |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 917 | my_qp, my_qp->real_qp_num, hret); |
| 918 | goto create_srq2; |
| 919 | } |
| 920 | |
Hoang-Nam Nguyen | 03f72a5 | 2007-09-28 17:16:27 +0200 | [diff] [blame] | 921 | ehca_free_fw_ctrlblock(mqpcb); |
| 922 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 923 | return &my_qp->ib_srq; |
| 924 | |
| 925 | create_srq2: |
| 926 | ret = ERR_PTR(ehca2ib_return_code(hret)); |
| 927 | ehca_free_fw_ctrlblock(mqpcb); |
| 928 | |
| 929 | create_srq1: |
| 930 | internal_destroy_qp(pd->device, my_qp, my_qp->ib_srq.uobject); |
| 931 | |
| 932 | return ret; |
| 933 | } |
| 934 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 935 | /* |
| 936 | * prepare_sqe_rts called by internal_modify_qp() at trans sqe -> rts |
| 937 | * set purge bit of bad wqe and subsequent wqes to avoid reentering sqe |
| 938 | * returns total number of bad wqes in bad_wqe_cnt |
| 939 | */ |
| 940 | static int prepare_sqe_rts(struct ehca_qp *my_qp, struct ehca_shca *shca, |
| 941 | int *bad_wqe_cnt) |
| 942 | { |
| 943 | u64 h_ret; |
| 944 | struct ipz_queue *squeue; |
| 945 | void *bad_send_wqe_p, *bad_send_wqe_v; |
Hoang-Nam Nguyen | 2771e9e | 2006-11-20 23:54:12 +0100 | [diff] [blame] | 946 | u64 q_ofs; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 947 | struct ehca_wqe *wqe; |
| 948 | int qp_num = my_qp->ib_qp.qp_num; |
| 949 | |
| 950 | /* get send wqe pointer */ |
| 951 | h_ret = hipz_h_disable_and_get_wqe(shca->ipz_hca_handle, |
| 952 | my_qp->ipz_qp_handle, &my_qp->pf, |
| 953 | &bad_send_wqe_p, NULL, 2); |
| 954 | if (h_ret != H_SUCCESS) { |
| 955 | ehca_err(&shca->ib_device, "hipz_h_disable_and_get_wqe() failed" |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 956 | " ehca_qp=%p qp_num=%x h_ret=%li", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 957 | my_qp, qp_num, h_ret); |
| 958 | return ehca2ib_return_code(h_ret); |
| 959 | } |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 960 | bad_send_wqe_p = (void *)((u64)bad_send_wqe_p & (~(1L << 63))); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 961 | ehca_dbg(&shca->ib_device, "qp_num=%x bad_send_wqe_p=%p", |
| 962 | qp_num, bad_send_wqe_p); |
| 963 | /* convert wqe pointer to vadr */ |
| 964 | bad_send_wqe_v = abs_to_virt((u64)bad_send_wqe_p); |
| 965 | if (ehca_debug_level) |
| 966 | ehca_dmp(bad_send_wqe_v, 32, "qp_num=%x bad_wqe", qp_num); |
| 967 | squeue = &my_qp->ipz_squeue; |
Hoang-Nam Nguyen | 2771e9e | 2006-11-20 23:54:12 +0100 | [diff] [blame] | 968 | if (ipz_queue_abs_to_offset(squeue, (u64)bad_send_wqe_p, &q_ofs)) { |
| 969 | ehca_err(&shca->ib_device, "failed to get wqe offset qp_num=%x" |
| 970 | " bad_send_wqe_p=%p", qp_num, bad_send_wqe_p); |
| 971 | return -EFAULT; |
| 972 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 973 | |
| 974 | /* loop sets wqe's purge bit */ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 975 | wqe = (struct ehca_wqe *)ipz_qeit_calc(squeue, q_ofs); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 976 | *bad_wqe_cnt = 0; |
| 977 | while (wqe->optype != 0xff && wqe->wqef != 0xff) { |
| 978 | if (ehca_debug_level) |
| 979 | ehca_dmp(wqe, 32, "qp_num=%x wqe", qp_num); |
| 980 | wqe->nr_of_data_seg = 0; /* suppress data access */ |
| 981 | wqe->wqef = WQEF_PURGE; /* WQE to be purged */ |
Hoang-Nam Nguyen | 2771e9e | 2006-11-20 23:54:12 +0100 | [diff] [blame] | 982 | q_ofs = ipz_queue_advance_offset(squeue, q_ofs); |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 983 | wqe = (struct ehca_wqe *)ipz_qeit_calc(squeue, q_ofs); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 984 | *bad_wqe_cnt = (*bad_wqe_cnt)+1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 985 | } |
| 986 | /* |
| 987 | * bad wqe will be reprocessed and ignored when pol_cq() is called, |
| 988 | * i.e. nr of wqes with flush error status is one less |
| 989 | */ |
| 990 | ehca_dbg(&shca->ib_device, "qp_num=%x flusherr_wqe_cnt=%x", |
| 991 | qp_num, (*bad_wqe_cnt)-1); |
| 992 | wqe->wqef = 0; |
| 993 | |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | /* |
| 998 | * internal_modify_qp with circumvention to handle aqp0 properly |
| 999 | * smi_reset2init indicates if this is an internal reset-to-init-call for |
| 1000 | * smi. This flag must always be zero if called from ehca_modify_qp()! |
| 1001 | * This internal func was intorduced to avoid recursion of ehca_modify_qp()! |
| 1002 | */ |
| 1003 | static int internal_modify_qp(struct ib_qp *ibqp, |
| 1004 | struct ib_qp_attr *attr, |
| 1005 | int attr_mask, int smi_reset2init) |
| 1006 | { |
| 1007 | enum ib_qp_state qp_cur_state, qp_new_state; |
| 1008 | int cnt, qp_attr_idx, ret = 0; |
| 1009 | enum ib_qp_statetrans statetrans; |
| 1010 | struct hcp_modify_qp_control_block *mqpcb; |
| 1011 | struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp); |
| 1012 | struct ehca_shca *shca = |
| 1013 | container_of(ibqp->pd->device, struct ehca_shca, ib_device); |
| 1014 | u64 update_mask; |
| 1015 | u64 h_ret; |
| 1016 | int bad_wqe_cnt = 0; |
| 1017 | int squeue_locked = 0; |
Joachim Fenkes | 9844b71 | 2007-07-09 15:29:03 +0200 | [diff] [blame] | 1018 | unsigned long flags = 0; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1019 | |
| 1020 | /* do query_qp to obtain current attr values */ |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 1021 | mqpcb = ehca_alloc_fw_ctrlblock(GFP_ATOMIC); |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 1022 | if (!mqpcb) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1023 | ehca_err(ibqp->device, "Could not get zeroed page for mqpcb " |
| 1024 | "ehca_qp=%p qp_num=%x ", my_qp, ibqp->qp_num); |
| 1025 | return -ENOMEM; |
| 1026 | } |
| 1027 | |
| 1028 | h_ret = hipz_h_query_qp(shca->ipz_hca_handle, |
| 1029 | my_qp->ipz_qp_handle, |
| 1030 | &my_qp->pf, |
| 1031 | mqpcb, my_qp->galpas.kernel); |
| 1032 | if (h_ret != H_SUCCESS) { |
| 1033 | ehca_err(ibqp->device, "hipz_h_query_qp() failed " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 1034 | "ehca_qp=%p qp_num=%x h_ret=%li", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1035 | my_qp, ibqp->qp_num, h_ret); |
| 1036 | ret = ehca2ib_return_code(h_ret); |
| 1037 | goto modify_qp_exit1; |
| 1038 | } |
| 1039 | |
| 1040 | qp_cur_state = ehca2ib_qp_state(mqpcb->qp_state); |
| 1041 | |
| 1042 | if (qp_cur_state == -EINVAL) { /* invalid qp state */ |
| 1043 | ret = -EINVAL; |
| 1044 | ehca_err(ibqp->device, "Invalid current ehca_qp_state=%x " |
| 1045 | "ehca_qp=%p qp_num=%x", |
| 1046 | mqpcb->qp_state, my_qp, ibqp->qp_num); |
| 1047 | goto modify_qp_exit1; |
| 1048 | } |
| 1049 | /* |
| 1050 | * circumvention to set aqp0 initial state to init |
| 1051 | * as expected by IB spec |
| 1052 | */ |
| 1053 | if (smi_reset2init == 0 && |
| 1054 | ibqp->qp_type == IB_QPT_SMI && |
| 1055 | qp_cur_state == IB_QPS_RESET && |
| 1056 | (attr_mask & IB_QP_STATE) && |
| 1057 | attr->qp_state == IB_QPS_INIT) { /* RESET -> INIT */ |
| 1058 | struct ib_qp_attr smiqp_attr = { |
| 1059 | .qp_state = IB_QPS_INIT, |
| 1060 | .port_num = my_qp->init_attr.port_num, |
| 1061 | .pkey_index = 0, |
| 1062 | .qkey = 0 |
| 1063 | }; |
| 1064 | int smiqp_attr_mask = IB_QP_STATE | IB_QP_PORT | |
| 1065 | IB_QP_PKEY_INDEX | IB_QP_QKEY; |
| 1066 | int smirc = internal_modify_qp( |
| 1067 | ibqp, &smiqp_attr, smiqp_attr_mask, 1); |
| 1068 | if (smirc) { |
| 1069 | ehca_err(ibqp->device, "SMI RESET -> INIT failed. " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 1070 | "ehca_modify_qp() rc=%i", smirc); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1071 | ret = H_PARAMETER; |
| 1072 | goto modify_qp_exit1; |
| 1073 | } |
| 1074 | qp_cur_state = IB_QPS_INIT; |
| 1075 | ehca_dbg(ibqp->device, "SMI RESET -> INIT succeeded"); |
| 1076 | } |
| 1077 | /* is transmitted current state equal to "real" current state */ |
| 1078 | if ((attr_mask & IB_QP_CUR_STATE) && |
| 1079 | qp_cur_state != attr->cur_qp_state) { |
| 1080 | ret = -EINVAL; |
| 1081 | ehca_err(ibqp->device, |
| 1082 | "Invalid IB_QP_CUR_STATE attr->curr_qp_state=%x <>" |
| 1083 | " actual cur_qp_state=%x. ehca_qp=%p qp_num=%x", |
| 1084 | attr->cur_qp_state, qp_cur_state, my_qp, ibqp->qp_num); |
| 1085 | goto modify_qp_exit1; |
| 1086 | } |
| 1087 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 1088 | ehca_dbg(ibqp->device, "ehca_qp=%p qp_num=%x current qp_state=%x " |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1089 | "new qp_state=%x attribute_mask=%x", |
| 1090 | my_qp, ibqp->qp_num, qp_cur_state, attr->qp_state, attr_mask); |
| 1091 | |
| 1092 | qp_new_state = attr_mask & IB_QP_STATE ? attr->qp_state : qp_cur_state; |
| 1093 | if (!smi_reset2init && |
| 1094 | !ib_modify_qp_is_ok(qp_cur_state, qp_new_state, ibqp->qp_type, |
| 1095 | attr_mask)) { |
| 1096 | ret = -EINVAL; |
| 1097 | ehca_err(ibqp->device, |
| 1098 | "Invalid qp transition new_state=%x cur_state=%x " |
| 1099 | "ehca_qp=%p qp_num=%x attr_mask=%x", qp_new_state, |
| 1100 | qp_cur_state, my_qp, ibqp->qp_num, attr_mask); |
| 1101 | goto modify_qp_exit1; |
| 1102 | } |
| 1103 | |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 1104 | mqpcb->qp_state = ib2ehca_qp_state(qp_new_state); |
| 1105 | if (mqpcb->qp_state) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1106 | update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1); |
| 1107 | else { |
| 1108 | ret = -EINVAL; |
| 1109 | ehca_err(ibqp->device, "Invalid new qp state=%x " |
| 1110 | "ehca_qp=%p qp_num=%x", |
| 1111 | qp_new_state, my_qp, ibqp->qp_num); |
| 1112 | goto modify_qp_exit1; |
| 1113 | } |
| 1114 | |
| 1115 | /* retrieve state transition struct to get req and opt attrs */ |
| 1116 | statetrans = get_modqp_statetrans(qp_cur_state, qp_new_state); |
| 1117 | if (statetrans < 0) { |
| 1118 | ret = -EINVAL; |
| 1119 | ehca_err(ibqp->device, "<INVALID STATE CHANGE> qp_cur_state=%x " |
| 1120 | "new_qp_state=%x State_xsition=%x ehca_qp=%p " |
| 1121 | "qp_num=%x", qp_cur_state, qp_new_state, |
| 1122 | statetrans, my_qp, ibqp->qp_num); |
| 1123 | goto modify_qp_exit1; |
| 1124 | } |
| 1125 | |
| 1126 | qp_attr_idx = ib2ehcaqptype(ibqp->qp_type); |
| 1127 | |
| 1128 | if (qp_attr_idx < 0) { |
| 1129 | ret = qp_attr_idx; |
| 1130 | ehca_err(ibqp->device, |
| 1131 | "Invalid QP type=%x ehca_qp=%p qp_num=%x", |
| 1132 | ibqp->qp_type, my_qp, ibqp->qp_num); |
| 1133 | goto modify_qp_exit1; |
| 1134 | } |
| 1135 | |
| 1136 | ehca_dbg(ibqp->device, |
| 1137 | "ehca_qp=%p qp_num=%x <VALID STATE CHANGE> qp_state_xsit=%x", |
| 1138 | my_qp, ibqp->qp_num, statetrans); |
| 1139 | |
Stefan Roscher | 85f0031 | 2007-07-09 15:27:13 +0200 | [diff] [blame] | 1140 | /* eHCA2 rev2 and higher require the SEND_GRH_FLAG to be set |
| 1141 | * in non-LL UD QPs. |
| 1142 | */ |
| 1143 | if ((my_qp->qp_type == IB_QPT_UD) && |
| 1144 | (my_qp->ext_type != EQPT_LLQP) && |
| 1145 | (statetrans == IB_QPST_INIT2RTR) && |
| 1146 | (shca->hw_level >= 0x22)) { |
| 1147 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1); |
| 1148 | mqpcb->send_grh_flag = 1; |
| 1149 | } |
| 1150 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1151 | /* sqe -> rts: set purge bit of bad wqe before actual trans */ |
| 1152 | if ((my_qp->qp_type == IB_QPT_UD || |
| 1153 | my_qp->qp_type == IB_QPT_GSI || |
| 1154 | my_qp->qp_type == IB_QPT_SMI) && |
| 1155 | statetrans == IB_QPST_SQE2RTS) { |
| 1156 | /* mark next free wqe if kernel */ |
Hoang-Nam Nguyen | 4c34bdf | 2007-01-24 00:13:35 +0100 | [diff] [blame] | 1157 | if (!ibqp->uobject) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1158 | struct ehca_wqe *wqe; |
| 1159 | /* lock send queue */ |
Joachim Fenkes | 9844b71 | 2007-07-09 15:29:03 +0200 | [diff] [blame] | 1160 | spin_lock_irqsave(&my_qp->spinlock_s, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1161 | squeue_locked = 1; |
| 1162 | /* mark next free wqe */ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 1163 | wqe = (struct ehca_wqe *) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1164 | ipz_qeit_get(&my_qp->ipz_squeue); |
| 1165 | wqe->optype = wqe->wqef = 0xff; |
| 1166 | ehca_dbg(ibqp->device, "qp_num=%x next_free_wqe=%p", |
| 1167 | ibqp->qp_num, wqe); |
| 1168 | } |
| 1169 | ret = prepare_sqe_rts(my_qp, shca, &bad_wqe_cnt); |
| 1170 | if (ret) { |
| 1171 | ehca_err(ibqp->device, "prepare_sqe_rts() failed " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 1172 | "ehca_qp=%p qp_num=%x ret=%i", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1173 | my_qp, ibqp->qp_num, ret); |
| 1174 | goto modify_qp_exit2; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | /* |
| 1179 | * enable RDMA_Atomic_Control if reset->init und reliable con |
| 1180 | * this is necessary since gen2 does not provide that flag, |
| 1181 | * but pHyp requires it |
| 1182 | */ |
| 1183 | if (statetrans == IB_QPST_RESET2INIT && |
| 1184 | (ibqp->qp_type == IB_QPT_RC || ibqp->qp_type == IB_QPT_UC)) { |
| 1185 | mqpcb->rdma_atomic_ctrl = 3; |
| 1186 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RDMA_ATOMIC_CTRL, 1); |
| 1187 | } |
| 1188 | /* circ. pHyp requires #RDMA/Atomic Resp Res for UC INIT -> RTR */ |
| 1189 | if (statetrans == IB_QPST_INIT2RTR && |
| 1190 | (ibqp->qp_type == IB_QPT_UC) && |
| 1191 | !(attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)) { |
| 1192 | mqpcb->rdma_nr_atomic_resp_res = 1; /* default to 1 */ |
| 1193 | update_mask |= |
| 1194 | EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1); |
| 1195 | } |
| 1196 | |
| 1197 | if (attr_mask & IB_QP_PKEY_INDEX) { |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 1198 | if (attr->pkey_index >= 16) { |
| 1199 | ret = -EINVAL; |
| 1200 | ehca_err(ibqp->device, "Invalid pkey_index=%x. " |
| 1201 | "ehca_qp=%p qp_num=%x max_pkey_index=f", |
| 1202 | attr->pkey_index, my_qp, ibqp->qp_num); |
| 1203 | goto modify_qp_exit2; |
| 1204 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1205 | mqpcb->prim_p_key_idx = attr->pkey_index; |
| 1206 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_P_KEY_IDX, 1); |
| 1207 | } |
| 1208 | if (attr_mask & IB_QP_PORT) { |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 1209 | struct ehca_sport *sport; |
| 1210 | struct ehca_qp *aqp1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1211 | if (attr->port_num < 1 || attr->port_num > shca->num_ports) { |
| 1212 | ret = -EINVAL; |
| 1213 | ehca_err(ibqp->device, "Invalid port=%x. " |
| 1214 | "ehca_qp=%p qp_num=%x num_ports=%x", |
| 1215 | attr->port_num, my_qp, ibqp->qp_num, |
| 1216 | shca->num_ports); |
| 1217 | goto modify_qp_exit2; |
| 1218 | } |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 1219 | sport = &shca->sport[attr->port_num - 1]; |
| 1220 | if (!sport->ibqp_sqp[IB_QPT_GSI]) { |
| 1221 | /* should not occur */ |
| 1222 | ret = -EFAULT; |
| 1223 | ehca_err(ibqp->device, "AQP1 was not created for " |
| 1224 | "port=%x", attr->port_num); |
| 1225 | goto modify_qp_exit2; |
| 1226 | } |
| 1227 | aqp1 = container_of(sport->ibqp_sqp[IB_QPT_GSI], |
| 1228 | struct ehca_qp, ib_qp); |
| 1229 | if (ibqp->qp_type != IB_QPT_GSI && |
| 1230 | ibqp->qp_type != IB_QPT_SMI && |
| 1231 | aqp1->mod_qp_parm) { |
| 1232 | /* |
| 1233 | * firmware will reject this modify_qp() because |
| 1234 | * port is not activated/initialized fully |
| 1235 | */ |
| 1236 | ret = -EFAULT; |
| 1237 | ehca_warn(ibqp->device, "Couldn't modify qp port=%x: " |
| 1238 | "either port is being activated (try again) " |
| 1239 | "or cabling issue", attr->port_num); |
| 1240 | goto modify_qp_exit2; |
| 1241 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1242 | mqpcb->prim_phys_port = attr->port_num; |
| 1243 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_PHYS_PORT, 1); |
| 1244 | } |
| 1245 | if (attr_mask & IB_QP_QKEY) { |
| 1246 | mqpcb->qkey = attr->qkey; |
| 1247 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_QKEY, 1); |
| 1248 | } |
| 1249 | if (attr_mask & IB_QP_AV) { |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1250 | mqpcb->dlid = attr->ah_attr.dlid; |
| 1251 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DLID, 1); |
| 1252 | mqpcb->source_path_bits = attr->ah_attr.src_path_bits; |
| 1253 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS, 1); |
| 1254 | mqpcb->service_level = attr->ah_attr.sl; |
| 1255 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL, 1); |
| 1256 | |
Joachim Fenkes | 3fe2ed3 | 2007-11-22 12:26:26 +0200 | [diff] [blame] | 1257 | if (ehca_calc_ipd(shca, mqpcb->prim_phys_port, |
Joachim Fenkes | 51aaa54 | 2007-11-02 15:41:49 +0200 | [diff] [blame] | 1258 | attr->ah_attr.static_rate, |
| 1259 | &mqpcb->max_static_rate)) { |
| 1260 | ret = -EINVAL; |
| 1261 | goto modify_qp_exit2; |
| 1262 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1263 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE, 1); |
| 1264 | |
| 1265 | /* |
Joachim Fenkes | 92761cd | 2007-05-09 13:48:01 +0200 | [diff] [blame] | 1266 | * Always supply the GRH flag, even if it's zero, to give the |
| 1267 | * hypervisor a clear "yes" or "no" instead of a "perhaps" |
| 1268 | */ |
| 1269 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1); |
| 1270 | |
| 1271 | /* |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1272 | * only if GRH is TRUE we might consider SOURCE_GID_IDX |
| 1273 | * and DEST_GID otherwise phype will return H_ATTR_PARM!!! |
| 1274 | */ |
| 1275 | if (attr->ah_attr.ah_flags == IB_AH_GRH) { |
Joachim Fenkes | 92761cd | 2007-05-09 13:48:01 +0200 | [diff] [blame] | 1276 | mqpcb->send_grh_flag = 1; |
| 1277 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1278 | mqpcb->source_gid_idx = attr->ah_attr.grh.sgid_index; |
| 1279 | update_mask |= |
| 1280 | EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX, 1); |
| 1281 | |
| 1282 | for (cnt = 0; cnt < 16; cnt++) |
| 1283 | mqpcb->dest_gid.byte[cnt] = |
| 1284 | attr->ah_attr.grh.dgid.raw[cnt]; |
| 1285 | |
| 1286 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_GID, 1); |
| 1287 | mqpcb->flow_label = attr->ah_attr.grh.flow_label; |
| 1288 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL, 1); |
| 1289 | mqpcb->hop_limit = attr->ah_attr.grh.hop_limit; |
| 1290 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT, 1); |
| 1291 | mqpcb->traffic_class = attr->ah_attr.grh.traffic_class; |
| 1292 | update_mask |= |
| 1293 | EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS, 1); |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | if (attr_mask & IB_QP_PATH_MTU) { |
Joachim Fenkes | 2ec8e662 | 2008-01-17 15:07:24 +0100 | [diff] [blame] | 1298 | /* store ld(MTU) */ |
| 1299 | my_qp->mtu_shift = attr->path_mtu + 7; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1300 | mqpcb->path_mtu = attr->path_mtu; |
| 1301 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PATH_MTU, 1); |
| 1302 | } |
| 1303 | if (attr_mask & IB_QP_TIMEOUT) { |
| 1304 | mqpcb->timeout = attr->timeout; |
| 1305 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_TIMEOUT, 1); |
| 1306 | } |
| 1307 | if (attr_mask & IB_QP_RETRY_CNT) { |
| 1308 | mqpcb->retry_count = attr->retry_cnt; |
| 1309 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RETRY_COUNT, 1); |
| 1310 | } |
| 1311 | if (attr_mask & IB_QP_RNR_RETRY) { |
| 1312 | mqpcb->rnr_retry_count = attr->rnr_retry; |
| 1313 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RNR_RETRY_COUNT, 1); |
| 1314 | } |
| 1315 | if (attr_mask & IB_QP_RQ_PSN) { |
| 1316 | mqpcb->receive_psn = attr->rq_psn; |
| 1317 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RECEIVE_PSN, 1); |
| 1318 | } |
| 1319 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) { |
| 1320 | mqpcb->rdma_nr_atomic_resp_res = attr->max_dest_rd_atomic < 3 ? |
| 1321 | attr->max_dest_rd_atomic : 2; |
| 1322 | update_mask |= |
| 1323 | EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1); |
| 1324 | } |
| 1325 | if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) { |
| 1326 | mqpcb->rdma_atomic_outst_dest_qp = attr->max_rd_atomic < 3 ? |
| 1327 | attr->max_rd_atomic : 2; |
| 1328 | update_mask |= |
| 1329 | EHCA_BMASK_SET |
| 1330 | (MQPCB_MASK_RDMA_ATOMIC_OUTST_DEST_QP, 1); |
| 1331 | } |
| 1332 | if (attr_mask & IB_QP_ALT_PATH) { |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 1333 | if (attr->alt_port_num < 1 |
| 1334 | || attr->alt_port_num > shca->num_ports) { |
| 1335 | ret = -EINVAL; |
| 1336 | ehca_err(ibqp->device, "Invalid alt_port=%x. " |
| 1337 | "ehca_qp=%p qp_num=%x num_ports=%x", |
| 1338 | attr->alt_port_num, my_qp, ibqp->qp_num, |
| 1339 | shca->num_ports); |
| 1340 | goto modify_qp_exit2; |
| 1341 | } |
| 1342 | mqpcb->alt_phys_port = attr->alt_port_num; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1343 | |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 1344 | if (attr->alt_pkey_index >= 16) { |
| 1345 | ret = -EINVAL; |
| 1346 | ehca_err(ibqp->device, "Invalid alt_pkey_index=%x. " |
| 1347 | "ehca_qp=%p qp_num=%x max_pkey_index=f", |
| 1348 | attr->pkey_index, my_qp, ibqp->qp_num); |
| 1349 | goto modify_qp_exit2; |
| 1350 | } |
| 1351 | mqpcb->alt_p_key_idx = attr->alt_pkey_index; |
| 1352 | |
| 1353 | mqpcb->timeout_al = attr->alt_timeout; |
| 1354 | mqpcb->dlid_al = attr->alt_ah_attr.dlid; |
| 1355 | mqpcb->source_path_bits_al = attr->alt_ah_attr.src_path_bits; |
| 1356 | mqpcb->service_level_al = attr->alt_ah_attr.sl; |
| 1357 | |
Joachim Fenkes | 3fe2ed3 | 2007-11-22 12:26:26 +0200 | [diff] [blame] | 1358 | if (ehca_calc_ipd(shca, mqpcb->alt_phys_port, |
Joachim Fenkes | 51aaa54 | 2007-11-02 15:41:49 +0200 | [diff] [blame] | 1359 | attr->alt_ah_attr.static_rate, |
| 1360 | &mqpcb->max_static_rate_al)) { |
| 1361 | ret = -EINVAL; |
| 1362 | goto modify_qp_exit2; |
| 1363 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1364 | |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 1365 | /* OpenIB doesn't support alternate retry counts - copy them */ |
| 1366 | mqpcb->retry_count_al = mqpcb->retry_count; |
| 1367 | mqpcb->rnr_retry_count_al = mqpcb->rnr_retry_count; |
| 1368 | |
| 1369 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_ALT_PHYS_PORT, 1) |
| 1370 | | EHCA_BMASK_SET(MQPCB_MASK_ALT_P_KEY_IDX, 1) |
| 1371 | | EHCA_BMASK_SET(MQPCB_MASK_TIMEOUT_AL, 1) |
| 1372 | | EHCA_BMASK_SET(MQPCB_MASK_DLID_AL, 1) |
| 1373 | | EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS_AL, 1) |
| 1374 | | EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL_AL, 1) |
| 1375 | | EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE_AL, 1) |
| 1376 | | EHCA_BMASK_SET(MQPCB_MASK_RETRY_COUNT_AL, 1) |
| 1377 | | EHCA_BMASK_SET(MQPCB_MASK_RNR_RETRY_COUNT_AL, 1); |
| 1378 | |
| 1379 | /* |
| 1380 | * Always supply the GRH flag, even if it's zero, to give the |
| 1381 | * hypervisor a clear "yes" or "no" instead of a "perhaps" |
| 1382 | */ |
| 1383 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG_AL, 1); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1384 | |
| 1385 | /* |
| 1386 | * only if GRH is TRUE we might consider SOURCE_GID_IDX |
| 1387 | * and DEST_GID otherwise phype will return H_ATTR_PARM!!! |
| 1388 | */ |
| 1389 | if (attr->alt_ah_attr.ah_flags == IB_AH_GRH) { |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 1390 | mqpcb->send_grh_flag_al = 1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1391 | |
| 1392 | for (cnt = 0; cnt < 16; cnt++) |
| 1393 | mqpcb->dest_gid_al.byte[cnt] = |
| 1394 | attr->alt_ah_attr.grh.dgid.raw[cnt]; |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 1395 | mqpcb->source_gid_idx_al = |
| 1396 | attr->alt_ah_attr.grh.sgid_index; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1397 | mqpcb->flow_label_al = attr->alt_ah_attr.grh.flow_label; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1398 | mqpcb->hop_limit_al = attr->alt_ah_attr.grh.hop_limit; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1399 | mqpcb->traffic_class_al = |
| 1400 | attr->alt_ah_attr.grh.traffic_class; |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 1401 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1402 | update_mask |= |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 1403 | EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX_AL, 1) |
| 1404 | | EHCA_BMASK_SET(MQPCB_MASK_DEST_GID_AL, 1) |
| 1405 | | EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL_AL, 1) |
| 1406 | | EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT_AL, 1) | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1407 | EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS_AL, 1); |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | if (attr_mask & IB_QP_MIN_RNR_TIMER) { |
| 1412 | mqpcb->min_rnr_nak_timer_field = attr->min_rnr_timer; |
| 1413 | update_mask |= |
| 1414 | EHCA_BMASK_SET(MQPCB_MASK_MIN_RNR_NAK_TIMER_FIELD, 1); |
| 1415 | } |
| 1416 | |
| 1417 | if (attr_mask & IB_QP_SQ_PSN) { |
| 1418 | mqpcb->send_psn = attr->sq_psn; |
| 1419 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_PSN, 1); |
| 1420 | } |
| 1421 | |
| 1422 | if (attr_mask & IB_QP_DEST_QPN) { |
| 1423 | mqpcb->dest_qp_nr = attr->dest_qp_num; |
| 1424 | update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_QP_NR, 1); |
| 1425 | } |
| 1426 | |
| 1427 | if (attr_mask & IB_QP_PATH_MIG_STATE) { |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 1428 | if (attr->path_mig_state != IB_MIG_REARM |
| 1429 | && attr->path_mig_state != IB_MIG_MIGRATED) { |
| 1430 | ret = -EINVAL; |
| 1431 | ehca_err(ibqp->device, "Invalid mig_state=%x", |
| 1432 | attr->path_mig_state); |
| 1433 | goto modify_qp_exit2; |
| 1434 | } |
| 1435 | mqpcb->path_migration_state = attr->path_mig_state + 1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1436 | update_mask |= |
| 1437 | EHCA_BMASK_SET(MQPCB_MASK_PATH_MIGRATION_STATE, 1); |
| 1438 | } |
| 1439 | |
| 1440 | if (attr_mask & IB_QP_CAP) { |
| 1441 | mqpcb->max_nr_outst_send_wr = attr->cap.max_send_wr+1; |
| 1442 | update_mask |= |
| 1443 | EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_SEND_WR, 1); |
| 1444 | mqpcb->max_nr_outst_recv_wr = attr->cap.max_recv_wr+1; |
| 1445 | update_mask |= |
| 1446 | EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_RECV_WR, 1); |
| 1447 | /* no support for max_send/recv_sge yet */ |
| 1448 | } |
| 1449 | |
| 1450 | if (ehca_debug_level) |
| 1451 | ehca_dmp(mqpcb, 4*70, "qp_num=%x", ibqp->qp_num); |
| 1452 | |
| 1453 | h_ret = hipz_h_modify_qp(shca->ipz_hca_handle, |
| 1454 | my_qp->ipz_qp_handle, |
| 1455 | &my_qp->pf, |
| 1456 | update_mask, |
| 1457 | mqpcb, my_qp->galpas.kernel); |
| 1458 | |
| 1459 | if (h_ret != H_SUCCESS) { |
| 1460 | ret = ehca2ib_return_code(h_ret); |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 1461 | ehca_err(ibqp->device, "hipz_h_modify_qp() failed h_ret=%li " |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 1462 | "ehca_qp=%p qp_num=%x", h_ret, my_qp, ibqp->qp_num); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1463 | goto modify_qp_exit2; |
| 1464 | } |
| 1465 | |
| 1466 | if ((my_qp->qp_type == IB_QPT_UD || |
| 1467 | my_qp->qp_type == IB_QPT_GSI || |
| 1468 | my_qp->qp_type == IB_QPT_SMI) && |
| 1469 | statetrans == IB_QPST_SQE2RTS) { |
| 1470 | /* doorbell to reprocessing wqes */ |
| 1471 | iosync(); /* serialize GAL register access */ |
| 1472 | hipz_update_sqa(my_qp, bad_wqe_cnt-1); |
| 1473 | ehca_gen_dbg("doorbell for %x wqes", bad_wqe_cnt); |
| 1474 | } |
| 1475 | |
| 1476 | if (statetrans == IB_QPST_RESET2INIT || |
| 1477 | statetrans == IB_QPST_INIT2INIT) { |
| 1478 | mqpcb->qp_enable = 1; |
| 1479 | mqpcb->qp_state = EHCA_QPS_INIT; |
| 1480 | update_mask = 0; |
| 1481 | update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_ENABLE, 1); |
| 1482 | |
| 1483 | h_ret = hipz_h_modify_qp(shca->ipz_hca_handle, |
| 1484 | my_qp->ipz_qp_handle, |
| 1485 | &my_qp->pf, |
| 1486 | update_mask, |
| 1487 | mqpcb, |
| 1488 | my_qp->galpas.kernel); |
| 1489 | |
| 1490 | if (h_ret != H_SUCCESS) { |
| 1491 | ret = ehca2ib_return_code(h_ret); |
| 1492 | ehca_err(ibqp->device, "ENABLE in context of " |
| 1493 | "RESET_2_INIT failed! Maybe you didn't get " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 1494 | "a LID h_ret=%li ehca_qp=%p qp_num=%x", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1495 | h_ret, my_qp, ibqp->qp_num); |
| 1496 | goto modify_qp_exit2; |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | if (statetrans == IB_QPST_ANY2RESET) { |
| 1501 | ipz_qeit_reset(&my_qp->ipz_rqueue); |
| 1502 | ipz_qeit_reset(&my_qp->ipz_squeue); |
| 1503 | } |
| 1504 | |
| 1505 | if (attr_mask & IB_QP_QKEY) |
| 1506 | my_qp->qkey = attr->qkey; |
| 1507 | |
| 1508 | modify_qp_exit2: |
| 1509 | if (squeue_locked) { /* this means: sqe -> rts */ |
Joachim Fenkes | 9844b71 | 2007-07-09 15:29:03 +0200 | [diff] [blame] | 1510 | spin_unlock_irqrestore(&my_qp->spinlock_s, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1511 | my_qp->sqerr_purgeflag = 1; |
| 1512 | } |
| 1513 | |
| 1514 | modify_qp_exit1: |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 1515 | ehca_free_fw_ctrlblock(mqpcb); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1516 | |
| 1517 | return ret; |
| 1518 | } |
| 1519 | |
Ralph Campbell | 9bc57e2 | 2006-08-11 14:58:09 -0700 | [diff] [blame] | 1520 | int ehca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask, |
| 1521 | struct ib_udata *udata) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1522 | { |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 1523 | struct ehca_shca *shca = container_of(ibqp->device, struct ehca_shca, |
| 1524 | ib_device); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1525 | struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1526 | |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 1527 | /* The if-block below caches qp_attr to be modified for GSI and SMI |
| 1528 | * qps during the initialization by ib_mad. When the respective port |
| 1529 | * is activated, ie we got an event PORT_ACTIVE, we'll replay the |
| 1530 | * cached modify calls sequence, see ehca_recover_sqs() below. |
| 1531 | * Why that is required: |
| 1532 | * 1) If one port is connected, older code requires that port one |
| 1533 | * to be connected and module option nr_ports=1 to be given by |
| 1534 | * user, which is very inconvenient for end user. |
| 1535 | * 2) Firmware accepts modify_qp() only if respective port has become |
| 1536 | * active. Older code had a wait loop of 30sec create_qp()/ |
| 1537 | * define_aqp1(), which is not appropriate in practice. This |
| 1538 | * code now removes that wait loop, see define_aqp1(), and always |
| 1539 | * reports all ports to ib_mad resp. users. Only activated ports |
| 1540 | * will then usable for the users. |
| 1541 | */ |
| 1542 | if (ibqp->qp_type == IB_QPT_GSI || ibqp->qp_type == IB_QPT_SMI) { |
| 1543 | int port = my_qp->init_attr.port_num; |
| 1544 | struct ehca_sport *sport = &shca->sport[port - 1]; |
| 1545 | unsigned long flags; |
| 1546 | spin_lock_irqsave(&sport->mod_sqp_lock, flags); |
| 1547 | /* cache qp_attr only during init */ |
| 1548 | if (my_qp->mod_qp_parm) { |
| 1549 | struct ehca_mod_qp_parm *p; |
| 1550 | if (my_qp->mod_qp_parm_idx >= EHCA_MOD_QP_PARM_MAX) { |
| 1551 | ehca_err(&shca->ib_device, |
| 1552 | "mod_qp_parm overflow state=%x port=%x" |
| 1553 | " type=%x", attr->qp_state, |
| 1554 | my_qp->init_attr.port_num, |
| 1555 | ibqp->qp_type); |
| 1556 | spin_unlock_irqrestore(&sport->mod_sqp_lock, |
| 1557 | flags); |
| 1558 | return -EINVAL; |
| 1559 | } |
| 1560 | p = &my_qp->mod_qp_parm[my_qp->mod_qp_parm_idx]; |
| 1561 | p->mask = attr_mask; |
| 1562 | p->attr = *attr; |
| 1563 | my_qp->mod_qp_parm_idx++; |
| 1564 | ehca_dbg(&shca->ib_device, |
| 1565 | "Saved qp_attr for state=%x port=%x type=%x", |
| 1566 | attr->qp_state, my_qp->init_attr.port_num, |
| 1567 | ibqp->qp_type); |
| 1568 | spin_unlock_irqrestore(&sport->mod_sqp_lock, flags); |
| 1569 | return 0; |
| 1570 | } |
| 1571 | spin_unlock_irqrestore(&sport->mod_sqp_lock, flags); |
| 1572 | } |
| 1573 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1574 | return internal_modify_qp(ibqp, attr, attr_mask, 0); |
| 1575 | } |
| 1576 | |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 1577 | void ehca_recover_sqp(struct ib_qp *sqp) |
| 1578 | { |
| 1579 | struct ehca_qp *my_sqp = container_of(sqp, struct ehca_qp, ib_qp); |
| 1580 | int port = my_sqp->init_attr.port_num; |
| 1581 | struct ib_qp_attr attr; |
| 1582 | struct ehca_mod_qp_parm *qp_parm; |
| 1583 | int i, qp_parm_idx, ret; |
| 1584 | unsigned long flags, wr_cnt; |
| 1585 | |
| 1586 | if (!my_sqp->mod_qp_parm) |
| 1587 | return; |
| 1588 | ehca_dbg(sqp->device, "SQP port=%x qp_num=%x", port, sqp->qp_num); |
| 1589 | |
| 1590 | qp_parm = my_sqp->mod_qp_parm; |
| 1591 | qp_parm_idx = my_sqp->mod_qp_parm_idx; |
| 1592 | for (i = 0; i < qp_parm_idx; i++) { |
| 1593 | attr = qp_parm[i].attr; |
| 1594 | ret = internal_modify_qp(sqp, &attr, qp_parm[i].mask, 0); |
| 1595 | if (ret) { |
| 1596 | ehca_err(sqp->device, "Could not modify SQP port=%x " |
| 1597 | "qp_num=%x ret=%x", port, sqp->qp_num, ret); |
| 1598 | goto free_qp_parm; |
| 1599 | } |
| 1600 | ehca_dbg(sqp->device, "SQP port=%x qp_num=%x in state=%x", |
| 1601 | port, sqp->qp_num, attr.qp_state); |
| 1602 | } |
| 1603 | |
| 1604 | /* re-trigger posted recv wrs */ |
| 1605 | wr_cnt = my_sqp->ipz_rqueue.current_q_offset / |
| 1606 | my_sqp->ipz_rqueue.qe_size; |
| 1607 | if (wr_cnt) { |
| 1608 | spin_lock_irqsave(&my_sqp->spinlock_r, flags); |
| 1609 | hipz_update_rqa(my_sqp, wr_cnt); |
| 1610 | spin_unlock_irqrestore(&my_sqp->spinlock_r, flags); |
| 1611 | ehca_dbg(sqp->device, "doorbell port=%x qp_num=%x wr_cnt=%lx", |
| 1612 | port, sqp->qp_num, wr_cnt); |
| 1613 | } |
| 1614 | |
| 1615 | free_qp_parm: |
| 1616 | kfree(qp_parm); |
| 1617 | /* this prevents subsequent calls to modify_qp() to cache qp_attr */ |
| 1618 | my_sqp->mod_qp_parm = NULL; |
| 1619 | } |
| 1620 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1621 | int ehca_query_qp(struct ib_qp *qp, |
| 1622 | struct ib_qp_attr *qp_attr, |
| 1623 | int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr) |
| 1624 | { |
| 1625 | struct ehca_qp *my_qp = container_of(qp, struct ehca_qp, ib_qp); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1626 | struct ehca_shca *shca = container_of(qp->device, struct ehca_shca, |
| 1627 | ib_device); |
| 1628 | struct ipz_adapter_handle adapter_handle = shca->ipz_hca_handle; |
| 1629 | struct hcp_modify_qp_control_block *qpcb; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1630 | int cnt, ret = 0; |
| 1631 | u64 h_ret; |
| 1632 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1633 | if (qp_attr_mask & QP_ATTR_QUERY_NOT_SUPPORTED) { |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 1634 | ehca_err(qp->device, "Invalid attribute mask " |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1635 | "ehca_qp=%p qp_num=%x qp_attr_mask=%x ", |
| 1636 | my_qp, qp->qp_num, qp_attr_mask); |
| 1637 | return -EINVAL; |
| 1638 | } |
| 1639 | |
Hoang-Nam Nguyen | f2d9136 | 2007-01-09 18:04:14 +0100 | [diff] [blame] | 1640 | qpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1641 | if (!qpcb) { |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 1642 | ehca_err(qp->device, "Out of memory for qpcb " |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1643 | "ehca_qp=%p qp_num=%x", my_qp, qp->qp_num); |
| 1644 | return -ENOMEM; |
| 1645 | } |
| 1646 | |
| 1647 | h_ret = hipz_h_query_qp(adapter_handle, |
| 1648 | my_qp->ipz_qp_handle, |
| 1649 | &my_qp->pf, |
| 1650 | qpcb, my_qp->galpas.kernel); |
| 1651 | |
| 1652 | if (h_ret != H_SUCCESS) { |
| 1653 | ret = ehca2ib_return_code(h_ret); |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 1654 | ehca_err(qp->device, "hipz_h_query_qp() failed " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 1655 | "ehca_qp=%p qp_num=%x h_ret=%li", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1656 | my_qp, qp->qp_num, h_ret); |
| 1657 | goto query_qp_exit1; |
| 1658 | } |
| 1659 | |
| 1660 | qp_attr->cur_qp_state = ehca2ib_qp_state(qpcb->qp_state); |
| 1661 | qp_attr->qp_state = qp_attr->cur_qp_state; |
| 1662 | |
| 1663 | if (qp_attr->cur_qp_state == -EINVAL) { |
| 1664 | ret = -EINVAL; |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 1665 | ehca_err(qp->device, "Got invalid ehca_qp_state=%x " |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1666 | "ehca_qp=%p qp_num=%x", |
| 1667 | qpcb->qp_state, my_qp, qp->qp_num); |
| 1668 | goto query_qp_exit1; |
| 1669 | } |
| 1670 | |
| 1671 | if (qp_attr->qp_state == IB_QPS_SQD) |
| 1672 | qp_attr->sq_draining = 1; |
| 1673 | |
| 1674 | qp_attr->qkey = qpcb->qkey; |
| 1675 | qp_attr->path_mtu = qpcb->path_mtu; |
Joachim Fenkes | e90d0b3 | 2007-09-11 15:34:04 +0200 | [diff] [blame] | 1676 | qp_attr->path_mig_state = qpcb->path_migration_state - 1; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1677 | qp_attr->rq_psn = qpcb->receive_psn; |
| 1678 | qp_attr->sq_psn = qpcb->send_psn; |
| 1679 | qp_attr->min_rnr_timer = qpcb->min_rnr_nak_timer_field; |
| 1680 | qp_attr->cap.max_send_wr = qpcb->max_nr_outst_send_wr-1; |
| 1681 | qp_attr->cap.max_recv_wr = qpcb->max_nr_outst_recv_wr-1; |
| 1682 | /* UD_AV CIRCUMVENTION */ |
| 1683 | if (my_qp->qp_type == IB_QPT_UD) { |
| 1684 | qp_attr->cap.max_send_sge = |
| 1685 | qpcb->actual_nr_sges_in_sq_wqe - 2; |
| 1686 | qp_attr->cap.max_recv_sge = |
| 1687 | qpcb->actual_nr_sges_in_rq_wqe - 2; |
| 1688 | } else { |
| 1689 | qp_attr->cap.max_send_sge = |
| 1690 | qpcb->actual_nr_sges_in_sq_wqe; |
| 1691 | qp_attr->cap.max_recv_sge = |
| 1692 | qpcb->actual_nr_sges_in_rq_wqe; |
| 1693 | } |
| 1694 | |
| 1695 | qp_attr->cap.max_inline_data = my_qp->sq_max_inline_data_size; |
| 1696 | qp_attr->dest_qp_num = qpcb->dest_qp_nr; |
| 1697 | |
| 1698 | qp_attr->pkey_index = |
| 1699 | EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->prim_p_key_idx); |
| 1700 | |
| 1701 | qp_attr->port_num = |
| 1702 | EHCA_BMASK_GET(MQPCB_PRIM_PHYS_PORT, qpcb->prim_phys_port); |
| 1703 | |
| 1704 | qp_attr->timeout = qpcb->timeout; |
| 1705 | qp_attr->retry_cnt = qpcb->retry_count; |
| 1706 | qp_attr->rnr_retry = qpcb->rnr_retry_count; |
| 1707 | |
| 1708 | qp_attr->alt_pkey_index = |
| 1709 | EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->alt_p_key_idx); |
| 1710 | |
| 1711 | qp_attr->alt_port_num = qpcb->alt_phys_port; |
| 1712 | qp_attr->alt_timeout = qpcb->timeout_al; |
| 1713 | |
Hoang-Nam Nguyen | 15f001e | 2007-07-09 15:28:18 +0200 | [diff] [blame] | 1714 | qp_attr->max_dest_rd_atomic = qpcb->rdma_nr_atomic_resp_res; |
| 1715 | qp_attr->max_rd_atomic = qpcb->rdma_atomic_outst_dest_qp; |
| 1716 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1717 | /* primary av */ |
| 1718 | qp_attr->ah_attr.sl = qpcb->service_level; |
| 1719 | |
| 1720 | if (qpcb->send_grh_flag) { |
| 1721 | qp_attr->ah_attr.ah_flags = IB_AH_GRH; |
| 1722 | } |
| 1723 | |
| 1724 | qp_attr->ah_attr.static_rate = qpcb->max_static_rate; |
| 1725 | qp_attr->ah_attr.dlid = qpcb->dlid; |
| 1726 | qp_attr->ah_attr.src_path_bits = qpcb->source_path_bits; |
| 1727 | qp_attr->ah_attr.port_num = qp_attr->port_num; |
| 1728 | |
| 1729 | /* primary GRH */ |
| 1730 | qp_attr->ah_attr.grh.traffic_class = qpcb->traffic_class; |
| 1731 | qp_attr->ah_attr.grh.hop_limit = qpcb->hop_limit; |
| 1732 | qp_attr->ah_attr.grh.sgid_index = qpcb->source_gid_idx; |
| 1733 | qp_attr->ah_attr.grh.flow_label = qpcb->flow_label; |
| 1734 | |
| 1735 | for (cnt = 0; cnt < 16; cnt++) |
| 1736 | qp_attr->ah_attr.grh.dgid.raw[cnt] = |
| 1737 | qpcb->dest_gid.byte[cnt]; |
| 1738 | |
| 1739 | /* alternate AV */ |
| 1740 | qp_attr->alt_ah_attr.sl = qpcb->service_level_al; |
| 1741 | if (qpcb->send_grh_flag_al) { |
| 1742 | qp_attr->alt_ah_attr.ah_flags = IB_AH_GRH; |
| 1743 | } |
| 1744 | |
| 1745 | qp_attr->alt_ah_attr.static_rate = qpcb->max_static_rate_al; |
| 1746 | qp_attr->alt_ah_attr.dlid = qpcb->dlid_al; |
| 1747 | qp_attr->alt_ah_attr.src_path_bits = qpcb->source_path_bits_al; |
| 1748 | |
| 1749 | /* alternate GRH */ |
| 1750 | qp_attr->alt_ah_attr.grh.traffic_class = qpcb->traffic_class_al; |
| 1751 | qp_attr->alt_ah_attr.grh.hop_limit = qpcb->hop_limit_al; |
| 1752 | qp_attr->alt_ah_attr.grh.sgid_index = qpcb->source_gid_idx_al; |
| 1753 | qp_attr->alt_ah_attr.grh.flow_label = qpcb->flow_label_al; |
| 1754 | |
| 1755 | for (cnt = 0; cnt < 16; cnt++) |
| 1756 | qp_attr->alt_ah_attr.grh.dgid.raw[cnt] = |
| 1757 | qpcb->dest_gid_al.byte[cnt]; |
| 1758 | |
| 1759 | /* return init attributes given in ehca_create_qp */ |
| 1760 | if (qp_init_attr) |
| 1761 | *qp_init_attr = my_qp->init_attr; |
| 1762 | |
| 1763 | if (ehca_debug_level) |
| 1764 | ehca_dmp(qpcb, 4*70, "qp_num=%x", qp->qp_num); |
| 1765 | |
| 1766 | query_qp_exit1: |
Hoang-Nam Nguyen | 7e28db5 | 2006-11-07 00:56:39 +0100 | [diff] [blame] | 1767 | ehca_free_fw_ctrlblock(qpcb); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1768 | |
| 1769 | return ret; |
| 1770 | } |
| 1771 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1772 | int ehca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, |
| 1773 | enum ib_srq_attr_mask attr_mask, struct ib_udata *udata) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1774 | { |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1775 | struct ehca_qp *my_qp = |
| 1776 | container_of(ibsrq, struct ehca_qp, ib_srq); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1777 | struct ehca_shca *shca = |
| 1778 | container_of(ibsrq->pd->device, struct ehca_shca, ib_device); |
| 1779 | struct hcp_modify_qp_control_block *mqpcb; |
| 1780 | u64 update_mask; |
| 1781 | u64 h_ret; |
| 1782 | int ret = 0; |
| 1783 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1784 | mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL); |
| 1785 | if (!mqpcb) { |
| 1786 | ehca_err(ibsrq->device, "Could not get zeroed page for mqpcb " |
| 1787 | "ehca_qp=%p qp_num=%x ", my_qp, my_qp->real_qp_num); |
| 1788 | return -ENOMEM; |
| 1789 | } |
| 1790 | |
| 1791 | update_mask = 0; |
| 1792 | if (attr_mask & IB_SRQ_LIMIT) { |
| 1793 | attr_mask &= ~IB_SRQ_LIMIT; |
| 1794 | update_mask |= |
| 1795 | EHCA_BMASK_SET(MQPCB_MASK_CURR_SRQ_LIMIT, 1) |
| 1796 | | EHCA_BMASK_SET(MQPCB_MASK_QP_AFF_ASYN_EV_LOG_REG, 1); |
| 1797 | mqpcb->curr_srq_limit = |
| 1798 | EHCA_BMASK_SET(MQPCB_CURR_SRQ_LIMIT, attr->srq_limit); |
| 1799 | mqpcb->qp_aff_asyn_ev_log_reg = |
| 1800 | EHCA_BMASK_SET(QPX_AAELOG_RESET_SRQ_LIMIT, 1); |
| 1801 | } |
| 1802 | |
| 1803 | /* by now, all bits in attr_mask should have been cleared */ |
| 1804 | if (attr_mask) { |
| 1805 | ehca_err(ibsrq->device, "invalid attribute mask bits set " |
| 1806 | "attr_mask=%x", attr_mask); |
| 1807 | ret = -EINVAL; |
| 1808 | goto modify_srq_exit0; |
| 1809 | } |
| 1810 | |
| 1811 | if (ehca_debug_level) |
| 1812 | ehca_dmp(mqpcb, 4*70, "qp_num=%x", my_qp->real_qp_num); |
| 1813 | |
| 1814 | h_ret = hipz_h_modify_qp(shca->ipz_hca_handle, my_qp->ipz_qp_handle, |
| 1815 | NULL, update_mask, mqpcb, |
| 1816 | my_qp->galpas.kernel); |
| 1817 | |
| 1818 | if (h_ret != H_SUCCESS) { |
| 1819 | ret = ehca2ib_return_code(h_ret); |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 1820 | ehca_err(ibsrq->device, "hipz_h_modify_qp() failed h_ret=%li " |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1821 | "ehca_qp=%p qp_num=%x", |
| 1822 | h_ret, my_qp, my_qp->real_qp_num); |
| 1823 | } |
| 1824 | |
| 1825 | modify_srq_exit0: |
| 1826 | ehca_free_fw_ctrlblock(mqpcb); |
| 1827 | |
| 1828 | return ret; |
| 1829 | } |
| 1830 | |
| 1831 | int ehca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr) |
| 1832 | { |
| 1833 | struct ehca_qp *my_qp = container_of(srq, struct ehca_qp, ib_srq); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1834 | struct ehca_shca *shca = container_of(srq->device, struct ehca_shca, |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1835 | ib_device); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1836 | struct ipz_adapter_handle adapter_handle = shca->ipz_hca_handle; |
| 1837 | struct hcp_modify_qp_control_block *qpcb; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1838 | int ret = 0; |
| 1839 | u64 h_ret; |
| 1840 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1841 | qpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL); |
| 1842 | if (!qpcb) { |
| 1843 | ehca_err(srq->device, "Out of memory for qpcb " |
| 1844 | "ehca_qp=%p qp_num=%x", my_qp, my_qp->real_qp_num); |
| 1845 | return -ENOMEM; |
| 1846 | } |
| 1847 | |
| 1848 | h_ret = hipz_h_query_qp(adapter_handle, my_qp->ipz_qp_handle, |
| 1849 | NULL, qpcb, my_qp->galpas.kernel); |
| 1850 | |
| 1851 | if (h_ret != H_SUCCESS) { |
| 1852 | ret = ehca2ib_return_code(h_ret); |
| 1853 | ehca_err(srq->device, "hipz_h_query_qp() failed " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 1854 | "ehca_qp=%p qp_num=%x h_ret=%li", |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1855 | my_qp, my_qp->real_qp_num, h_ret); |
| 1856 | goto query_srq_exit1; |
| 1857 | } |
| 1858 | |
| 1859 | srq_attr->max_wr = qpcb->max_nr_outst_recv_wr - 1; |
Joachim Fenkes | 1457edc | 2007-12-10 12:20:57 +0100 | [diff] [blame] | 1860 | srq_attr->max_sge = 3; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1861 | srq_attr->srq_limit = EHCA_BMASK_GET( |
| 1862 | MQPCB_CURR_SRQ_LIMIT, qpcb->curr_srq_limit); |
| 1863 | |
| 1864 | if (ehca_debug_level) |
| 1865 | ehca_dmp(qpcb, 4*70, "qp_num=%x", my_qp->real_qp_num); |
| 1866 | |
| 1867 | query_srq_exit1: |
| 1868 | ehca_free_fw_ctrlblock(qpcb); |
| 1869 | |
| 1870 | return ret; |
| 1871 | } |
| 1872 | |
Joachim Fenkes | 0c10f7b | 2007-07-19 21:40:00 +0200 | [diff] [blame] | 1873 | static int internal_destroy_qp(struct ib_device *dev, struct ehca_qp *my_qp, |
| 1874 | struct ib_uobject *uobject) |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1875 | { |
| 1876 | struct ehca_shca *shca = container_of(dev, struct ehca_shca, ib_device); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1877 | struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd, |
| 1878 | ib_pd); |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 1879 | struct ehca_sport *sport = &shca->sport[my_qp->init_attr.port_num - 1]; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1880 | u32 qp_num = my_qp->real_qp_num; |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1881 | int ret; |
| 1882 | u64 h_ret; |
| 1883 | u8 port_num; |
| 1884 | enum ib_qp_type qp_type; |
| 1885 | unsigned long flags; |
| 1886 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1887 | if (uobject) { |
Hoang-Nam Nguyen | 4c34bdf | 2007-01-24 00:13:35 +0100 | [diff] [blame] | 1888 | if (my_qp->mm_count_galpa || |
| 1889 | my_qp->mm_count_rqueue || my_qp->mm_count_squeue) { |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1890 | ehca_err(dev, "Resources still referenced in " |
| 1891 | "user space qp_num=%x", qp_num); |
Hoang-Nam Nguyen | 4c34bdf | 2007-01-24 00:13:35 +0100 | [diff] [blame] | 1892 | return -EINVAL; |
| 1893 | } |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | if (my_qp->send_cq) { |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1897 | ret = ehca_cq_unassign_qp(my_qp->send_cq, qp_num); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1898 | if (ret) { |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1899 | ehca_err(dev, "Couldn't unassign qp from " |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 1900 | "send_cq ret=%i qp_num=%x cq_num=%x", ret, |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1901 | qp_num, my_qp->send_cq->cq_number); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1902 | return ret; |
| 1903 | } |
| 1904 | } |
| 1905 | |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 1906 | write_lock_irqsave(&ehca_qp_idr_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1907 | idr_remove(&ehca_qp_idr, my_qp->token); |
Joachim Fenkes | 26ed687 | 2007-07-09 15:31:10 +0200 | [diff] [blame] | 1908 | write_unlock_irqrestore(&ehca_qp_idr_lock, flags); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1909 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1910 | h_ret = hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp); |
| 1911 | if (h_ret != H_SUCCESS) { |
Joachim Fenkes | e372219 | 2007-09-11 15:32:22 +0200 | [diff] [blame] | 1912 | ehca_err(dev, "hipz_h_destroy_qp() failed h_ret=%li " |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1913 | "ehca_qp=%p qp_num=%x", h_ret, my_qp, qp_num); |
| 1914 | return ehca2ib_return_code(h_ret); |
| 1915 | } |
| 1916 | |
| 1917 | port_num = my_qp->init_attr.port_num; |
| 1918 | qp_type = my_qp->init_attr.qp_type; |
| 1919 | |
Hoang-Nam Nguyen | bbdd267 | 2008-01-17 15:05:45 +0100 | [diff] [blame] | 1920 | if (qp_type == IB_QPT_SMI || qp_type == IB_QPT_GSI) { |
| 1921 | spin_lock_irqsave(&sport->mod_sqp_lock, flags); |
| 1922 | kfree(my_qp->mod_qp_parm); |
| 1923 | my_qp->mod_qp_parm = NULL; |
| 1924 | shca->sport[port_num - 1].ibqp_sqp[qp_type] = NULL; |
| 1925 | spin_unlock_irqrestore(&sport->mod_sqp_lock, flags); |
| 1926 | } |
| 1927 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1928 | /* no support for IB_QPT_SMI yet */ |
| 1929 | if (qp_type == IB_QPT_GSI) { |
| 1930 | struct ib_event event; |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1931 | ehca_info(dev, "device %s: port %x is inactive.", |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1932 | shca->ib_device.name, port_num); |
| 1933 | event.device = &shca->ib_device; |
| 1934 | event.event = IB_EVENT_PORT_ERR; |
| 1935 | event.element.port_num = port_num; |
| 1936 | shca->sport[port_num - 1].port_state = IB_PORT_DOWN; |
| 1937 | ib_dispatch_event(&event); |
| 1938 | } |
| 1939 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1940 | if (HAS_RQ(my_qp)) |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 1941 | ipz_queue_dtor(my_pd, &my_qp->ipz_rqueue); |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1942 | if (HAS_SQ(my_qp)) |
Stefan Roscher | e2f81da | 2007-07-20 16:04:17 +0200 | [diff] [blame] | 1943 | ipz_queue_dtor(my_pd, &my_qp->ipz_squeue); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1944 | kmem_cache_free(qp_cache, my_qp); |
| 1945 | return 0; |
| 1946 | } |
| 1947 | |
Joachim Fenkes | a6a1294 | 2007-07-09 15:25:10 +0200 | [diff] [blame] | 1948 | int ehca_destroy_qp(struct ib_qp *qp) |
| 1949 | { |
| 1950 | return internal_destroy_qp(qp->device, |
| 1951 | container_of(qp, struct ehca_qp, ib_qp), |
| 1952 | qp->uobject); |
| 1953 | } |
| 1954 | |
| 1955 | int ehca_destroy_srq(struct ib_srq *srq) |
| 1956 | { |
| 1957 | return internal_destroy_qp(srq->device, |
| 1958 | container_of(srq, struct ehca_qp, ib_srq), |
| 1959 | srq->uobject); |
| 1960 | } |
| 1961 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1962 | int ehca_init_qp_cache(void) |
| 1963 | { |
| 1964 | qp_cache = kmem_cache_create("ehca_cache_qp", |
| 1965 | sizeof(struct ehca_qp), 0, |
| 1966 | SLAB_HWCACHE_ALIGN, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1967 | NULL); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 1968 | if (!qp_cache) |
| 1969 | return -ENOMEM; |
| 1970 | return 0; |
| 1971 | } |
| 1972 | |
| 1973 | void ehca_cleanup_qp_cache(void) |
| 1974 | { |
| 1975 | if (qp_cache) |
| 1976 | kmem_cache_destroy(qp_cache); |
| 1977 | } |