Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1 | /* |
Bryan O'Sullivan | 759d576 | 2006-07-01 04:35:49 -0700 | [diff] [blame^] | 2 | * Copyright (c) 2006 QLogic, Inc. All rights reserved. |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 3 | * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. |
| 4 | * |
| 5 | * This software is available to you under a choice of one of two |
| 6 | * licenses. You may choose to be licensed under the terms of the GNU |
| 7 | * General Public License (GPL) Version 2, available from the file |
| 8 | * COPYING in the main directory of this source tree, or the |
| 9 | * OpenIB.org BSD license below: |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or |
| 12 | * without modification, are permitted provided that the following |
| 13 | * conditions are met: |
| 14 | * |
| 15 | * - Redistributions of source code must retain the above |
| 16 | * copyright notice, this list of conditions and the following |
| 17 | * disclaimer. |
| 18 | * |
| 19 | * - Redistributions in binary form must reproduce the above |
| 20 | * copyright notice, this list of conditions and the following |
| 21 | * disclaimer in the documentation and/or other materials |
| 22 | * provided with the distribution. |
| 23 | * |
| 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 25 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 26 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 27 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 28 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 29 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 30 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 | * SOFTWARE. |
| 32 | */ |
| 33 | |
| 34 | #include "ipath_verbs.h" |
| 35 | |
| 36 | /* |
| 37 | * Convert the AETH RNR timeout code into the number of milliseconds. |
| 38 | */ |
| 39 | const u32 ib_ipath_rnr_table[32] = { |
| 40 | 656, /* 0 */ |
| 41 | 1, /* 1 */ |
| 42 | 1, /* 2 */ |
| 43 | 1, /* 3 */ |
| 44 | 1, /* 4 */ |
| 45 | 1, /* 5 */ |
| 46 | 1, /* 6 */ |
| 47 | 1, /* 7 */ |
| 48 | 1, /* 8 */ |
| 49 | 1, /* 9 */ |
| 50 | 1, /* A */ |
| 51 | 1, /* B */ |
| 52 | 1, /* C */ |
| 53 | 1, /* D */ |
| 54 | 2, /* E */ |
| 55 | 2, /* F */ |
| 56 | 3, /* 10 */ |
| 57 | 4, /* 11 */ |
| 58 | 6, /* 12 */ |
| 59 | 8, /* 13 */ |
| 60 | 11, /* 14 */ |
| 61 | 16, /* 15 */ |
| 62 | 21, /* 16 */ |
| 63 | 31, /* 17 */ |
| 64 | 41, /* 18 */ |
| 65 | 62, /* 19 */ |
| 66 | 82, /* 1A */ |
| 67 | 123, /* 1B */ |
| 68 | 164, /* 1C */ |
| 69 | 246, /* 1D */ |
| 70 | 328, /* 1E */ |
| 71 | 492 /* 1F */ |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * ipath_insert_rnr_queue - put QP on the RNR timeout list for the device |
| 76 | * @qp: the QP |
| 77 | * |
| 78 | * XXX Use a simple list for now. We might need a priority |
| 79 | * queue if we have lots of QPs waiting for RNR timeouts |
| 80 | * but that should be rare. |
| 81 | */ |
| 82 | void ipath_insert_rnr_queue(struct ipath_qp *qp) |
| 83 | { |
| 84 | struct ipath_ibdev *dev = to_idev(qp->ibqp.device); |
| 85 | unsigned long flags; |
| 86 | |
| 87 | spin_lock_irqsave(&dev->pending_lock, flags); |
| 88 | if (list_empty(&dev->rnrwait)) |
| 89 | list_add(&qp->timerwait, &dev->rnrwait); |
| 90 | else { |
| 91 | struct list_head *l = &dev->rnrwait; |
| 92 | struct ipath_qp *nqp = list_entry(l->next, struct ipath_qp, |
| 93 | timerwait); |
| 94 | |
| 95 | while (qp->s_rnr_timeout >= nqp->s_rnr_timeout) { |
| 96 | qp->s_rnr_timeout -= nqp->s_rnr_timeout; |
| 97 | l = l->next; |
| 98 | if (l->next == &dev->rnrwait) |
| 99 | break; |
| 100 | nqp = list_entry(l->next, struct ipath_qp, |
| 101 | timerwait); |
| 102 | } |
| 103 | list_add(&qp->timerwait, l); |
| 104 | } |
| 105 | spin_unlock_irqrestore(&dev->pending_lock, flags); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * ipath_get_rwqe - copy the next RWQE into the QP's RWQE |
| 110 | * @qp: the QP |
| 111 | * @wr_id_only: update wr_id only, not SGEs |
| 112 | * |
| 113 | * Return 0 if no RWQE is available, otherwise return 1. |
| 114 | * |
| 115 | * Called at interrupt level with the QP r_rq.lock held. |
| 116 | */ |
| 117 | int ipath_get_rwqe(struct ipath_qp *qp, int wr_id_only) |
| 118 | { |
| 119 | struct ipath_rq *rq; |
| 120 | struct ipath_srq *srq; |
| 121 | struct ipath_rwqe *wqe; |
| 122 | int ret; |
| 123 | |
| 124 | if (!qp->ibqp.srq) { |
| 125 | rq = &qp->r_rq; |
| 126 | if (unlikely(rq->tail == rq->head)) { |
| 127 | ret = 0; |
| 128 | goto bail; |
| 129 | } |
| 130 | wqe = get_rwqe_ptr(rq, rq->tail); |
| 131 | qp->r_wr_id = wqe->wr_id; |
| 132 | if (!wr_id_only) { |
| 133 | qp->r_sge.sge = wqe->sg_list[0]; |
| 134 | qp->r_sge.sg_list = wqe->sg_list + 1; |
| 135 | qp->r_sge.num_sge = wqe->num_sge; |
| 136 | qp->r_len = wqe->length; |
| 137 | } |
| 138 | if (++rq->tail >= rq->size) |
| 139 | rq->tail = 0; |
| 140 | ret = 1; |
| 141 | goto bail; |
| 142 | } |
| 143 | |
| 144 | srq = to_isrq(qp->ibqp.srq); |
| 145 | rq = &srq->rq; |
| 146 | spin_lock(&rq->lock); |
| 147 | if (unlikely(rq->tail == rq->head)) { |
| 148 | spin_unlock(&rq->lock); |
| 149 | ret = 0; |
| 150 | goto bail; |
| 151 | } |
| 152 | wqe = get_rwqe_ptr(rq, rq->tail); |
| 153 | qp->r_wr_id = wqe->wr_id; |
| 154 | if (!wr_id_only) { |
| 155 | qp->r_sge.sge = wqe->sg_list[0]; |
| 156 | qp->r_sge.sg_list = wqe->sg_list + 1; |
| 157 | qp->r_sge.num_sge = wqe->num_sge; |
| 158 | qp->r_len = wqe->length; |
| 159 | } |
| 160 | if (++rq->tail >= rq->size) |
| 161 | rq->tail = 0; |
| 162 | if (srq->ibsrq.event_handler) { |
| 163 | struct ib_event ev; |
| 164 | u32 n; |
| 165 | |
| 166 | if (rq->head < rq->tail) |
| 167 | n = rq->size + rq->head - rq->tail; |
| 168 | else |
| 169 | n = rq->head - rq->tail; |
| 170 | if (n < srq->limit) { |
| 171 | srq->limit = 0; |
| 172 | spin_unlock(&rq->lock); |
| 173 | ev.device = qp->ibqp.device; |
| 174 | ev.element.srq = qp->ibqp.srq; |
| 175 | ev.event = IB_EVENT_SRQ_LIMIT_REACHED; |
| 176 | srq->ibsrq.event_handler(&ev, |
| 177 | srq->ibsrq.srq_context); |
| 178 | } else |
| 179 | spin_unlock(&rq->lock); |
| 180 | } else |
| 181 | spin_unlock(&rq->lock); |
| 182 | ret = 1; |
| 183 | |
| 184 | bail: |
| 185 | return ret; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * ipath_ruc_loopback - handle UC and RC lookback requests |
| 190 | * @sqp: the loopback QP |
| 191 | * @wc: the work completion entry |
| 192 | * |
| 193 | * This is called from ipath_do_uc_send() or ipath_do_rc_send() to |
| 194 | * forward a WQE addressed to the same HCA. |
| 195 | * Note that although we are single threaded due to the tasklet, we still |
| 196 | * have to protect against post_send(). We don't have to worry about |
| 197 | * receive interrupts since this is a connected protocol and all packets |
| 198 | * will pass through here. |
| 199 | */ |
| 200 | void ipath_ruc_loopback(struct ipath_qp *sqp, struct ib_wc *wc) |
| 201 | { |
| 202 | struct ipath_ibdev *dev = to_idev(sqp->ibqp.device); |
| 203 | struct ipath_qp *qp; |
| 204 | struct ipath_swqe *wqe; |
| 205 | struct ipath_sge *sge; |
| 206 | unsigned long flags; |
| 207 | u64 sdata; |
| 208 | |
| 209 | qp = ipath_lookup_qpn(&dev->qp_table, sqp->remote_qpn); |
| 210 | if (!qp) { |
| 211 | dev->n_pkt_drops++; |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | again: |
| 216 | spin_lock_irqsave(&sqp->s_lock, flags); |
| 217 | |
| 218 | if (!(ib_ipath_state_ops[sqp->state] & IPATH_PROCESS_SEND_OK)) { |
| 219 | spin_unlock_irqrestore(&sqp->s_lock, flags); |
| 220 | goto done; |
| 221 | } |
| 222 | |
| 223 | /* Get the next send request. */ |
| 224 | if (sqp->s_last == sqp->s_head) { |
| 225 | /* Send work queue is empty. */ |
| 226 | spin_unlock_irqrestore(&sqp->s_lock, flags); |
| 227 | goto done; |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | * We can rely on the entry not changing without the s_lock |
| 232 | * being held until we update s_last. |
| 233 | */ |
| 234 | wqe = get_swqe_ptr(sqp, sqp->s_last); |
| 235 | spin_unlock_irqrestore(&sqp->s_lock, flags); |
| 236 | |
| 237 | wc->wc_flags = 0; |
| 238 | wc->imm_data = 0; |
| 239 | |
| 240 | sqp->s_sge.sge = wqe->sg_list[0]; |
| 241 | sqp->s_sge.sg_list = wqe->sg_list + 1; |
| 242 | sqp->s_sge.num_sge = wqe->wr.num_sge; |
| 243 | sqp->s_len = wqe->length; |
| 244 | switch (wqe->wr.opcode) { |
| 245 | case IB_WR_SEND_WITH_IMM: |
| 246 | wc->wc_flags = IB_WC_WITH_IMM; |
| 247 | wc->imm_data = wqe->wr.imm_data; |
| 248 | /* FALLTHROUGH */ |
| 249 | case IB_WR_SEND: |
| 250 | spin_lock_irqsave(&qp->r_rq.lock, flags); |
| 251 | if (!ipath_get_rwqe(qp, 0)) { |
| 252 | rnr_nak: |
| 253 | spin_unlock_irqrestore(&qp->r_rq.lock, flags); |
| 254 | /* Handle RNR NAK */ |
| 255 | if (qp->ibqp.qp_type == IB_QPT_UC) |
| 256 | goto send_comp; |
| 257 | if (sqp->s_rnr_retry == 0) { |
| 258 | wc->status = IB_WC_RNR_RETRY_EXC_ERR; |
| 259 | goto err; |
| 260 | } |
| 261 | if (sqp->s_rnr_retry_cnt < 7) |
| 262 | sqp->s_rnr_retry--; |
| 263 | dev->n_rnr_naks++; |
| 264 | sqp->s_rnr_timeout = |
| 265 | ib_ipath_rnr_table[sqp->s_min_rnr_timer]; |
| 266 | ipath_insert_rnr_queue(sqp); |
| 267 | goto done; |
| 268 | } |
| 269 | spin_unlock_irqrestore(&qp->r_rq.lock, flags); |
| 270 | break; |
| 271 | |
| 272 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 273 | wc->wc_flags = IB_WC_WITH_IMM; |
| 274 | wc->imm_data = wqe->wr.imm_data; |
| 275 | spin_lock_irqsave(&qp->r_rq.lock, flags); |
| 276 | if (!ipath_get_rwqe(qp, 1)) |
| 277 | goto rnr_nak; |
| 278 | spin_unlock_irqrestore(&qp->r_rq.lock, flags); |
| 279 | /* FALLTHROUGH */ |
| 280 | case IB_WR_RDMA_WRITE: |
| 281 | if (wqe->length == 0) |
| 282 | break; |
| 283 | if (unlikely(!ipath_rkey_ok(dev, &qp->r_sge, wqe->length, |
| 284 | wqe->wr.wr.rdma.remote_addr, |
| 285 | wqe->wr.wr.rdma.rkey, |
| 286 | IB_ACCESS_REMOTE_WRITE))) { |
| 287 | acc_err: |
| 288 | wc->status = IB_WC_REM_ACCESS_ERR; |
| 289 | err: |
| 290 | wc->wr_id = wqe->wr.wr_id; |
| 291 | wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode]; |
| 292 | wc->vendor_err = 0; |
| 293 | wc->byte_len = 0; |
| 294 | wc->qp_num = sqp->ibqp.qp_num; |
| 295 | wc->src_qp = sqp->remote_qpn; |
| 296 | wc->pkey_index = 0; |
| 297 | wc->slid = sqp->remote_ah_attr.dlid; |
| 298 | wc->sl = sqp->remote_ah_attr.sl; |
| 299 | wc->dlid_path_bits = 0; |
| 300 | wc->port_num = 0; |
| 301 | ipath_sqerror_qp(sqp, wc); |
| 302 | goto done; |
| 303 | } |
| 304 | break; |
| 305 | |
| 306 | case IB_WR_RDMA_READ: |
| 307 | if (unlikely(!ipath_rkey_ok(dev, &sqp->s_sge, wqe->length, |
| 308 | wqe->wr.wr.rdma.remote_addr, |
| 309 | wqe->wr.wr.rdma.rkey, |
| 310 | IB_ACCESS_REMOTE_READ))) |
| 311 | goto acc_err; |
| 312 | if (unlikely(!(qp->qp_access_flags & |
| 313 | IB_ACCESS_REMOTE_READ))) |
| 314 | goto acc_err; |
| 315 | qp->r_sge.sge = wqe->sg_list[0]; |
| 316 | qp->r_sge.sg_list = wqe->sg_list + 1; |
| 317 | qp->r_sge.num_sge = wqe->wr.num_sge; |
| 318 | break; |
| 319 | |
| 320 | case IB_WR_ATOMIC_CMP_AND_SWP: |
| 321 | case IB_WR_ATOMIC_FETCH_AND_ADD: |
| 322 | if (unlikely(!ipath_rkey_ok(dev, &qp->r_sge, sizeof(u64), |
| 323 | wqe->wr.wr.rdma.remote_addr, |
| 324 | wqe->wr.wr.rdma.rkey, |
| 325 | IB_ACCESS_REMOTE_ATOMIC))) |
| 326 | goto acc_err; |
| 327 | /* Perform atomic OP and save result. */ |
| 328 | sdata = wqe->wr.wr.atomic.swap; |
| 329 | spin_lock_irqsave(&dev->pending_lock, flags); |
| 330 | qp->r_atomic_data = *(u64 *) qp->r_sge.sge.vaddr; |
| 331 | if (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) |
| 332 | *(u64 *) qp->r_sge.sge.vaddr = |
| 333 | qp->r_atomic_data + sdata; |
| 334 | else if (qp->r_atomic_data == wqe->wr.wr.atomic.compare_add) |
| 335 | *(u64 *) qp->r_sge.sge.vaddr = sdata; |
| 336 | spin_unlock_irqrestore(&dev->pending_lock, flags); |
| 337 | *(u64 *) sqp->s_sge.sge.vaddr = qp->r_atomic_data; |
| 338 | goto send_comp; |
| 339 | |
| 340 | default: |
| 341 | goto done; |
| 342 | } |
| 343 | |
| 344 | sge = &sqp->s_sge.sge; |
| 345 | while (sqp->s_len) { |
| 346 | u32 len = sqp->s_len; |
| 347 | |
| 348 | if (len > sge->length) |
| 349 | len = sge->length; |
| 350 | BUG_ON(len == 0); |
| 351 | ipath_copy_sge(&qp->r_sge, sge->vaddr, len); |
| 352 | sge->vaddr += len; |
| 353 | sge->length -= len; |
| 354 | sge->sge_length -= len; |
| 355 | if (sge->sge_length == 0) { |
| 356 | if (--sqp->s_sge.num_sge) |
| 357 | *sge = *sqp->s_sge.sg_list++; |
| 358 | } else if (sge->length == 0 && sge->mr != NULL) { |
| 359 | if (++sge->n >= IPATH_SEGSZ) { |
| 360 | if (++sge->m >= sge->mr->mapsz) |
| 361 | break; |
| 362 | sge->n = 0; |
| 363 | } |
| 364 | sge->vaddr = |
| 365 | sge->mr->map[sge->m]->segs[sge->n].vaddr; |
| 366 | sge->length = |
| 367 | sge->mr->map[sge->m]->segs[sge->n].length; |
| 368 | } |
| 369 | sqp->s_len -= len; |
| 370 | } |
| 371 | |
| 372 | if (wqe->wr.opcode == IB_WR_RDMA_WRITE || |
| 373 | wqe->wr.opcode == IB_WR_RDMA_READ) |
| 374 | goto send_comp; |
| 375 | |
| 376 | if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM) |
| 377 | wc->opcode = IB_WC_RECV_RDMA_WITH_IMM; |
| 378 | else |
| 379 | wc->opcode = IB_WC_RECV; |
| 380 | wc->wr_id = qp->r_wr_id; |
| 381 | wc->status = IB_WC_SUCCESS; |
| 382 | wc->vendor_err = 0; |
| 383 | wc->byte_len = wqe->length; |
| 384 | wc->qp_num = qp->ibqp.qp_num; |
| 385 | wc->src_qp = qp->remote_qpn; |
| 386 | /* XXX do we know which pkey matched? Only needed for GSI. */ |
| 387 | wc->pkey_index = 0; |
| 388 | wc->slid = qp->remote_ah_attr.dlid; |
| 389 | wc->sl = qp->remote_ah_attr.sl; |
| 390 | wc->dlid_path_bits = 0; |
| 391 | /* Signal completion event if the solicited bit is set. */ |
| 392 | ipath_cq_enter(to_icq(qp->ibqp.recv_cq), wc, |
| 393 | wqe->wr.send_flags & IB_SEND_SOLICITED); |
| 394 | |
| 395 | send_comp: |
| 396 | sqp->s_rnr_retry = sqp->s_rnr_retry_cnt; |
| 397 | |
| 398 | if (!test_bit(IPATH_S_SIGNAL_REQ_WR, &sqp->s_flags) || |
| 399 | (wqe->wr.send_flags & IB_SEND_SIGNALED)) { |
| 400 | wc->wr_id = wqe->wr.wr_id; |
| 401 | wc->status = IB_WC_SUCCESS; |
| 402 | wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode]; |
| 403 | wc->vendor_err = 0; |
| 404 | wc->byte_len = wqe->length; |
| 405 | wc->qp_num = sqp->ibqp.qp_num; |
| 406 | wc->src_qp = 0; |
| 407 | wc->pkey_index = 0; |
| 408 | wc->slid = 0; |
| 409 | wc->sl = 0; |
| 410 | wc->dlid_path_bits = 0; |
| 411 | wc->port_num = 0; |
| 412 | ipath_cq_enter(to_icq(sqp->ibqp.send_cq), wc, 0); |
| 413 | } |
| 414 | |
| 415 | /* Update s_last now that we are finished with the SWQE */ |
| 416 | spin_lock_irqsave(&sqp->s_lock, flags); |
| 417 | if (++sqp->s_last >= sqp->s_size) |
| 418 | sqp->s_last = 0; |
| 419 | spin_unlock_irqrestore(&sqp->s_lock, flags); |
| 420 | goto again; |
| 421 | |
| 422 | done: |
| 423 | if (atomic_dec_and_test(&qp->refcount)) |
| 424 | wake_up(&qp->wait); |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * ipath_no_bufs_available - tell the layer driver we need buffers |
| 429 | * @qp: the QP that caused the problem |
| 430 | * @dev: the device we ran out of buffers on |
| 431 | * |
| 432 | * Called when we run out of PIO buffers. |
| 433 | */ |
| 434 | void ipath_no_bufs_available(struct ipath_qp *qp, struct ipath_ibdev *dev) |
| 435 | { |
| 436 | unsigned long flags; |
| 437 | |
| 438 | spin_lock_irqsave(&dev->pending_lock, flags); |
Bryan O'Sullivan | 94b8d9f | 2006-05-23 11:32:32 -0700 | [diff] [blame] | 439 | if (list_empty(&qp->piowait)) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 440 | list_add_tail(&qp->piowait, &dev->piowait); |
| 441 | spin_unlock_irqrestore(&dev->pending_lock, flags); |
| 442 | /* |
| 443 | * Note that as soon as ipath_layer_want_buffer() is called and |
| 444 | * possibly before it returns, ipath_ib_piobufavail() |
| 445 | * could be called. If we are still in the tasklet function, |
| 446 | * tasklet_hi_schedule() will not call us until the next time |
| 447 | * tasklet_hi_schedule() is called. |
| 448 | * We clear the tasklet flag now since we are committing to return |
| 449 | * from the tasklet function. |
| 450 | */ |
| 451 | clear_bit(IPATH_S_BUSY, &qp->s_flags); |
| 452 | tasklet_unlock(&qp->s_task); |
| 453 | ipath_layer_want_buffer(dev->dd); |
| 454 | dev->n_piowait++; |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * ipath_post_rc_send - post RC and UC sends |
| 459 | * @qp: the QP to post on |
| 460 | * @wr: the work request to send |
| 461 | */ |
| 462 | int ipath_post_rc_send(struct ipath_qp *qp, struct ib_send_wr *wr) |
| 463 | { |
| 464 | struct ipath_swqe *wqe; |
| 465 | unsigned long flags; |
| 466 | u32 next; |
| 467 | int i, j; |
| 468 | int acc; |
| 469 | int ret; |
| 470 | |
| 471 | /* |
| 472 | * Don't allow RDMA reads or atomic operations on UC or |
| 473 | * undefined operations. |
| 474 | * Make sure buffer is large enough to hold the result for atomics. |
| 475 | */ |
| 476 | if (qp->ibqp.qp_type == IB_QPT_UC) { |
| 477 | if ((unsigned) wr->opcode >= IB_WR_RDMA_READ) { |
| 478 | ret = -EINVAL; |
| 479 | goto bail; |
| 480 | } |
| 481 | } else if ((unsigned) wr->opcode > IB_WR_ATOMIC_FETCH_AND_ADD) { |
| 482 | ret = -EINVAL; |
| 483 | goto bail; |
| 484 | } else if (wr->opcode >= IB_WR_ATOMIC_CMP_AND_SWP && |
| 485 | (wr->num_sge == 0 || |
| 486 | wr->sg_list[0].length < sizeof(u64) || |
| 487 | wr->sg_list[0].addr & (sizeof(u64) - 1))) { |
| 488 | ret = -EINVAL; |
| 489 | goto bail; |
| 490 | } |
| 491 | /* IB spec says that num_sge == 0 is OK. */ |
| 492 | if (wr->num_sge > qp->s_max_sge) { |
| 493 | ret = -ENOMEM; |
| 494 | goto bail; |
| 495 | } |
| 496 | spin_lock_irqsave(&qp->s_lock, flags); |
| 497 | next = qp->s_head + 1; |
| 498 | if (next >= qp->s_size) |
| 499 | next = 0; |
| 500 | if (next == qp->s_last) { |
| 501 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 502 | ret = -EINVAL; |
| 503 | goto bail; |
| 504 | } |
| 505 | |
| 506 | wqe = get_swqe_ptr(qp, qp->s_head); |
| 507 | wqe->wr = *wr; |
| 508 | wqe->ssn = qp->s_ssn++; |
| 509 | wqe->sg_list[0].mr = NULL; |
| 510 | wqe->sg_list[0].vaddr = NULL; |
| 511 | wqe->sg_list[0].length = 0; |
| 512 | wqe->sg_list[0].sge_length = 0; |
| 513 | wqe->length = 0; |
| 514 | acc = wr->opcode >= IB_WR_RDMA_READ ? IB_ACCESS_LOCAL_WRITE : 0; |
| 515 | for (i = 0, j = 0; i < wr->num_sge; i++) { |
| 516 | if (to_ipd(qp->ibqp.pd)->user && wr->sg_list[i].lkey == 0) { |
| 517 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 518 | ret = -EINVAL; |
| 519 | goto bail; |
| 520 | } |
| 521 | if (wr->sg_list[i].length == 0) |
| 522 | continue; |
| 523 | if (!ipath_lkey_ok(&to_idev(qp->ibqp.device)->lk_table, |
| 524 | &wqe->sg_list[j], &wr->sg_list[i], |
| 525 | acc)) { |
| 526 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 527 | ret = -EINVAL; |
| 528 | goto bail; |
| 529 | } |
| 530 | wqe->length += wr->sg_list[i].length; |
| 531 | j++; |
| 532 | } |
| 533 | wqe->wr.num_sge = j; |
| 534 | qp->s_head = next; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 535 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 536 | |
Bryan O'Sullivan | 76f0dd1 | 2006-04-24 14:23:05 -0700 | [diff] [blame] | 537 | if (qp->ibqp.qp_type == IB_QPT_UC) |
| 538 | ipath_do_uc_send((unsigned long) qp); |
| 539 | else |
| 540 | ipath_do_rc_send((unsigned long) qp); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 541 | |
| 542 | ret = 0; |
| 543 | |
| 544 | bail: |
| 545 | return ret; |
| 546 | } |