Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1 | /* |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 2 | * Copyright (c) 2006, 2007, 2008 QLogic Corporation. 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 | |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 34 | #include <linux/sched.h> |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 35 | #include <linux/spinlock.h> |
| 36 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 37 | #include "ipath_verbs.h" |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 38 | #include "ipath_kernel.h" |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * Convert the AETH RNR timeout code into the number of milliseconds. |
| 42 | */ |
| 43 | const u32 ib_ipath_rnr_table[32] = { |
| 44 | 656, /* 0 */ |
| 45 | 1, /* 1 */ |
| 46 | 1, /* 2 */ |
| 47 | 1, /* 3 */ |
| 48 | 1, /* 4 */ |
| 49 | 1, /* 5 */ |
| 50 | 1, /* 6 */ |
| 51 | 1, /* 7 */ |
| 52 | 1, /* 8 */ |
| 53 | 1, /* 9 */ |
| 54 | 1, /* A */ |
| 55 | 1, /* B */ |
| 56 | 1, /* C */ |
| 57 | 1, /* D */ |
| 58 | 2, /* E */ |
| 59 | 2, /* F */ |
| 60 | 3, /* 10 */ |
| 61 | 4, /* 11 */ |
| 62 | 6, /* 12 */ |
| 63 | 8, /* 13 */ |
| 64 | 11, /* 14 */ |
| 65 | 16, /* 15 */ |
| 66 | 21, /* 16 */ |
| 67 | 31, /* 17 */ |
| 68 | 41, /* 18 */ |
| 69 | 62, /* 19 */ |
| 70 | 82, /* 1A */ |
| 71 | 123, /* 1B */ |
| 72 | 164, /* 1C */ |
| 73 | 246, /* 1D */ |
| 74 | 328, /* 1E */ |
| 75 | 492 /* 1F */ |
| 76 | }; |
| 77 | |
| 78 | /** |
| 79 | * ipath_insert_rnr_queue - put QP on the RNR timeout list for the device |
| 80 | * @qp: the QP |
| 81 | * |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 82 | * Called with the QP s_lock held and interrupts disabled. |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 83 | * XXX Use a simple list for now. We might need a priority |
| 84 | * queue if we have lots of QPs waiting for RNR timeouts |
| 85 | * but that should be rare. |
| 86 | */ |
| 87 | void ipath_insert_rnr_queue(struct ipath_qp *qp) |
| 88 | { |
| 89 | struct ipath_ibdev *dev = to_idev(qp->ibqp.device); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 90 | |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 91 | /* We already did a spin_lock_irqsave(), so just use spin_lock */ |
| 92 | spin_lock(&dev->pending_lock); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 93 | if (list_empty(&dev->rnrwait)) |
| 94 | list_add(&qp->timerwait, &dev->rnrwait); |
| 95 | else { |
| 96 | struct list_head *l = &dev->rnrwait; |
| 97 | struct ipath_qp *nqp = list_entry(l->next, struct ipath_qp, |
| 98 | timerwait); |
| 99 | |
| 100 | while (qp->s_rnr_timeout >= nqp->s_rnr_timeout) { |
| 101 | qp->s_rnr_timeout -= nqp->s_rnr_timeout; |
| 102 | l = l->next; |
Ralph Campbell | cc65edc | 2007-12-14 19:22:34 -0800 | [diff] [blame] | 103 | if (l->next == &dev->rnrwait) { |
| 104 | nqp = NULL; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 105 | break; |
Ralph Campbell | cc65edc | 2007-12-14 19:22:34 -0800 | [diff] [blame] | 106 | } |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 107 | nqp = list_entry(l->next, struct ipath_qp, |
| 108 | timerwait); |
| 109 | } |
Ralph Campbell | cc65edc | 2007-12-14 19:22:34 -0800 | [diff] [blame] | 110 | if (nqp) |
| 111 | nqp->s_rnr_timeout -= qp->s_rnr_timeout; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 112 | list_add(&qp->timerwait, l); |
| 113 | } |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 114 | spin_unlock(&dev->pending_lock); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 117 | /** |
| 118 | * ipath_init_sge - Validate a RWQE and fill in the SGE state |
| 119 | * @qp: the QP |
| 120 | * |
| 121 | * Return 1 if OK. |
| 122 | */ |
| 123 | int ipath_init_sge(struct ipath_qp *qp, struct ipath_rwqe *wqe, |
| 124 | u32 *lengthp, struct ipath_sge_state *ss) |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 125 | { |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 126 | int i, j, ret; |
| 127 | struct ib_wc wc; |
| 128 | |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 129 | *lengthp = 0; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 130 | for (i = j = 0; i < wqe->num_sge; i++) { |
| 131 | if (wqe->sg_list[i].length == 0) |
| 132 | continue; |
| 133 | /* Check LKEY */ |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 134 | if (!ipath_lkey_ok(qp, j ? &ss->sg_list[j - 1] : &ss->sge, |
| 135 | &wqe->sg_list[i], IB_ACCESS_LOCAL_WRITE)) |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 136 | goto bad_lkey; |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 137 | *lengthp += wqe->sg_list[i].length; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 138 | j++; |
| 139 | } |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 140 | ss->num_sge = j; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 141 | ret = 1; |
| 142 | goto bail; |
| 143 | |
| 144 | bad_lkey: |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 145 | memset(&wc, 0, sizeof(wc)); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 146 | wc.wr_id = wqe->wr_id; |
| 147 | wc.status = IB_WC_LOC_PROT_ERR; |
| 148 | wc.opcode = IB_WC_RECV; |
Michael S. Tsirkin | 062dbb6 | 2006-12-31 21:09:42 +0200 | [diff] [blame] | 149 | wc.qp = &qp->ibqp; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 150 | /* Signal solicited completion event. */ |
| 151 | ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1); |
| 152 | ret = 0; |
| 153 | bail: |
| 154 | return ret; |
| 155 | } |
| 156 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 157 | /** |
| 158 | * ipath_get_rwqe - copy the next RWQE into the QP's RWQE |
| 159 | * @qp: the QP |
Ralph Campbell | a8b56f2 | 2008-10-27 15:31:25 -0700 | [diff] [blame] | 160 | * @wr_id_only: update qp->r_wr_id only, not qp->r_sge |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 161 | * |
| 162 | * Return 0 if no RWQE is available, otherwise return 1. |
| 163 | * |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 164 | * Can be called from interrupt level. |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 165 | */ |
| 166 | int ipath_get_rwqe(struct ipath_qp *qp, int wr_id_only) |
| 167 | { |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 168 | unsigned long flags; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 169 | struct ipath_rq *rq; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 170 | struct ipath_rwq *wq; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 171 | struct ipath_srq *srq; |
| 172 | struct ipath_rwqe *wqe; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 173 | void (*handler)(struct ib_event *, void *); |
| 174 | u32 tail; |
| 175 | int ret; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 176 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 177 | if (qp->ibqp.srq) { |
| 178 | srq = to_isrq(qp->ibqp.srq); |
| 179 | handler = srq->ibsrq.event_handler; |
| 180 | rq = &srq->rq; |
| 181 | } else { |
| 182 | srq = NULL; |
| 183 | handler = NULL; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 184 | rq = &qp->r_rq; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 187 | spin_lock_irqsave(&rq->lock, flags); |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 188 | if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) { |
| 189 | ret = 0; |
| 190 | goto unlock; |
| 191 | } |
| 192 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 193 | wq = rq->wq; |
| 194 | tail = wq->tail; |
| 195 | /* Validate tail before using it since it is user writable. */ |
| 196 | if (tail >= rq->size) |
| 197 | tail = 0; |
| 198 | do { |
| 199 | if (unlikely(tail == wq->head)) { |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 200 | ret = 0; |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 201 | goto unlock; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 202 | } |
Ralph Campbell | 4fc570b | 2007-07-06 12:48:23 -0700 | [diff] [blame] | 203 | /* Make sure entry is read after head index is read. */ |
| 204 | smp_rmb(); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 205 | wqe = get_rwqe_ptr(rq, tail); |
| 206 | if (++tail >= rq->size) |
| 207 | tail = 0; |
Ralph Campbell | a8b56f2 | 2008-10-27 15:31:25 -0700 | [diff] [blame] | 208 | if (wr_id_only) |
| 209 | break; |
| 210 | qp->r_sge.sg_list = qp->r_sg_list; |
| 211 | } while (!ipath_init_sge(qp, wqe, &qp->r_len, &qp->r_sge)); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 212 | qp->r_wr_id = wqe->wr_id; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 213 | wq->tail = tail; |
| 214 | |
| 215 | ret = 1; |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 216 | set_bit(IPATH_R_WRID_VALID, &qp->r_aflags); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 217 | if (handler) { |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 218 | u32 n; |
| 219 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 220 | /* |
| 221 | * validate head pointer value and compute |
| 222 | * the number of remaining WQEs. |
| 223 | */ |
| 224 | n = wq->head; |
| 225 | if (n >= rq->size) |
| 226 | n = 0; |
| 227 | if (n < tail) |
| 228 | n += rq->size - tail; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 229 | else |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 230 | n -= tail; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 231 | if (n < srq->limit) { |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 232 | struct ib_event ev; |
| 233 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 234 | srq->limit = 0; |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 235 | spin_unlock_irqrestore(&rq->lock, flags); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 236 | ev.device = qp->ibqp.device; |
| 237 | ev.element.srq = qp->ibqp.srq; |
| 238 | ev.event = IB_EVENT_SRQ_LIMIT_REACHED; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 239 | handler(&ev, srq->ibsrq.srq_context); |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 240 | goto bail; |
| 241 | } |
| 242 | } |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 243 | unlock: |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 244 | spin_unlock_irqrestore(&rq->lock, flags); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 245 | bail: |
| 246 | return ret; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * ipath_ruc_loopback - handle UC and RC lookback requests |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 251 | * @sqp: the sending QP |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 252 | * |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 253 | * This is called from ipath_do_send() to |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 254 | * forward a WQE addressed to the same HCA. |
| 255 | * Note that although we are single threaded due to the tasklet, we still |
| 256 | * have to protect against post_send(). We don't have to worry about |
| 257 | * receive interrupts since this is a connected protocol and all packets |
| 258 | * will pass through here. |
| 259 | */ |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 260 | static void ipath_ruc_loopback(struct ipath_qp *sqp) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 261 | { |
| 262 | struct ipath_ibdev *dev = to_idev(sqp->ibqp.device); |
| 263 | struct ipath_qp *qp; |
| 264 | struct ipath_swqe *wqe; |
| 265 | struct ipath_sge *sge; |
| 266 | unsigned long flags; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 267 | struct ib_wc wc; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 268 | u64 sdata; |
Ralph Campbell | 3859e39 | 2007-03-15 14:44:51 -0700 | [diff] [blame] | 269 | atomic64_t *maddr; |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 270 | enum ib_wc_status send_status; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 271 | |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 272 | /* |
| 273 | * Note that we check the responder QP state after |
| 274 | * checking the requester's state. |
| 275 | */ |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 276 | qp = ipath_lookup_qpn(&dev->qp_table, sqp->remote_qpn); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 277 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 278 | spin_lock_irqsave(&sqp->s_lock, flags); |
| 279 | |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 280 | /* Return if we are already busy processing a work request. */ |
| 281 | if ((sqp->s_flags & (IPATH_S_BUSY | IPATH_S_ANY_WAIT)) || |
| 282 | !(ib_ipath_state_ops[sqp->state] & IPATH_PROCESS_OR_FLUSH_SEND)) |
| 283 | goto unlock; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 284 | |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 285 | sqp->s_flags |= IPATH_S_BUSY; |
| 286 | |
| 287 | again: |
| 288 | if (sqp->s_last == sqp->s_head) |
| 289 | goto clr_busy; |
| 290 | wqe = get_swqe_ptr(sqp, sqp->s_last); |
| 291 | |
| 292 | /* Return if it is not OK to start a new work reqeust. */ |
| 293 | if (!(ib_ipath_state_ops[sqp->state] & IPATH_PROCESS_NEXT_SEND_OK)) { |
| 294 | if (!(ib_ipath_state_ops[sqp->state] & IPATH_FLUSH_SEND)) |
| 295 | goto clr_busy; |
| 296 | /* We are in the error state, flush the work request. */ |
| 297 | send_status = IB_WC_WR_FLUSH_ERR; |
| 298 | goto flush_send; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | /* |
| 302 | * We can rely on the entry not changing without the s_lock |
| 303 | * being held until we update s_last. |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 304 | * We increment s_cur to indicate s_last is in progress. |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 305 | */ |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 306 | if (sqp->s_last == sqp->s_cur) { |
| 307 | if (++sqp->s_cur >= sqp->s_size) |
| 308 | sqp->s_cur = 0; |
| 309 | } |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 310 | spin_unlock_irqrestore(&sqp->s_lock, flags); |
| 311 | |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 312 | if (!qp || !(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) { |
| 313 | dev->n_pkt_drops++; |
| 314 | /* |
| 315 | * For RC, the requester would timeout and retry so |
| 316 | * shortcut the timeouts and just signal too many retries. |
| 317 | */ |
| 318 | if (sqp->ibqp.qp_type == IB_QPT_RC) |
| 319 | send_status = IB_WC_RETRY_EXC_ERR; |
| 320 | else |
| 321 | send_status = IB_WC_SUCCESS; |
| 322 | goto serr; |
| 323 | } |
| 324 | |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 325 | memset(&wc, 0, sizeof wc); |
| 326 | send_status = IB_WC_SUCCESS; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 327 | |
| 328 | sqp->s_sge.sge = wqe->sg_list[0]; |
| 329 | sqp->s_sge.sg_list = wqe->sg_list + 1; |
| 330 | sqp->s_sge.num_sge = wqe->wr.num_sge; |
| 331 | sqp->s_len = wqe->length; |
| 332 | switch (wqe->wr.opcode) { |
| 333 | case IB_WR_SEND_WITH_IMM: |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 334 | wc.wc_flags = IB_WC_WITH_IMM; |
Steve Wise | 00f7ec3 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 335 | wc.ex.imm_data = wqe->wr.ex.imm_data; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 336 | /* FALLTHROUGH */ |
| 337 | case IB_WR_SEND: |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 338 | if (!ipath_get_rwqe(qp, 0)) |
| 339 | goto rnr_nak; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 340 | break; |
| 341 | |
| 342 | case IB_WR_RDMA_WRITE_WITH_IMM: |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 343 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) |
| 344 | goto inv_err; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 345 | wc.wc_flags = IB_WC_WITH_IMM; |
Steve Wise | 00f7ec3 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 346 | wc.ex.imm_data = wqe->wr.ex.imm_data; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 347 | if (!ipath_get_rwqe(qp, 1)) |
| 348 | goto rnr_nak; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 349 | /* FALLTHROUGH */ |
| 350 | case IB_WR_RDMA_WRITE: |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 351 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) |
| 352 | goto inv_err; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 353 | if (wqe->length == 0) |
| 354 | break; |
Bryan O'Sullivan | 6a553af | 2006-09-28 09:00:07 -0700 | [diff] [blame] | 355 | if (unlikely(!ipath_rkey_ok(qp, &qp->r_sge, wqe->length, |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 356 | wqe->wr.wr.rdma.remote_addr, |
| 357 | wqe->wr.wr.rdma.rkey, |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 358 | IB_ACCESS_REMOTE_WRITE))) |
| 359 | goto acc_err; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 360 | break; |
| 361 | |
| 362 | case IB_WR_RDMA_READ: |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 363 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ))) |
| 364 | goto inv_err; |
Bryan O'Sullivan | 6a553af | 2006-09-28 09:00:07 -0700 | [diff] [blame] | 365 | if (unlikely(!ipath_rkey_ok(qp, &sqp->s_sge, wqe->length, |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 366 | wqe->wr.wr.rdma.remote_addr, |
| 367 | wqe->wr.wr.rdma.rkey, |
| 368 | IB_ACCESS_REMOTE_READ))) |
| 369 | goto acc_err; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 370 | qp->r_sge.sge = wqe->sg_list[0]; |
| 371 | qp->r_sge.sg_list = wqe->sg_list + 1; |
| 372 | qp->r_sge.num_sge = wqe->wr.num_sge; |
| 373 | break; |
| 374 | |
| 375 | case IB_WR_ATOMIC_CMP_AND_SWP: |
| 376 | case IB_WR_ATOMIC_FETCH_AND_ADD: |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 377 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC))) |
| 378 | goto inv_err; |
Bryan O'Sullivan | 6a553af | 2006-09-28 09:00:07 -0700 | [diff] [blame] | 379 | if (unlikely(!ipath_rkey_ok(qp, &qp->r_sge, sizeof(u64), |
Ralph Campbell | 3859e39 | 2007-03-15 14:44:51 -0700 | [diff] [blame] | 380 | wqe->wr.wr.atomic.remote_addr, |
| 381 | wqe->wr.wr.atomic.rkey, |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 382 | IB_ACCESS_REMOTE_ATOMIC))) |
| 383 | goto acc_err; |
| 384 | /* Perform atomic OP and save result. */ |
Ralph Campbell | 3859e39 | 2007-03-15 14:44:51 -0700 | [diff] [blame] | 385 | maddr = (atomic64_t *) qp->r_sge.sge.vaddr; |
| 386 | sdata = wqe->wr.wr.atomic.compare_add; |
| 387 | *(u64 *) sqp->s_sge.sge.vaddr = |
| 388 | (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ? |
| 389 | (u64) atomic64_add_return(sdata, maddr) - sdata : |
| 390 | (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr, |
| 391 | sdata, wqe->wr.wr.atomic.swap); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 392 | goto send_comp; |
| 393 | |
| 394 | default: |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 395 | send_status = IB_WC_LOC_QP_OP_ERR; |
| 396 | goto serr; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | sge = &sqp->s_sge.sge; |
| 400 | while (sqp->s_len) { |
| 401 | u32 len = sqp->s_len; |
| 402 | |
| 403 | if (len > sge->length) |
| 404 | len = sge->length; |
Ralph Campbell | 30d149a | 2007-06-18 14:24:44 -0700 | [diff] [blame] | 405 | if (len > sge->sge_length) |
| 406 | len = sge->sge_length; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 407 | BUG_ON(len == 0); |
| 408 | ipath_copy_sge(&qp->r_sge, sge->vaddr, len); |
| 409 | sge->vaddr += len; |
| 410 | sge->length -= len; |
| 411 | sge->sge_length -= len; |
| 412 | if (sge->sge_length == 0) { |
| 413 | if (--sqp->s_sge.num_sge) |
| 414 | *sge = *sqp->s_sge.sg_list++; |
| 415 | } else if (sge->length == 0 && sge->mr != NULL) { |
| 416 | if (++sge->n >= IPATH_SEGSZ) { |
| 417 | if (++sge->m >= sge->mr->mapsz) |
| 418 | break; |
| 419 | sge->n = 0; |
| 420 | } |
| 421 | sge->vaddr = |
| 422 | sge->mr->map[sge->m]->segs[sge->n].vaddr; |
| 423 | sge->length = |
| 424 | sge->mr->map[sge->m]->segs[sge->n].length; |
| 425 | } |
| 426 | sqp->s_len -= len; |
| 427 | } |
| 428 | |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 429 | if (!test_and_clear_bit(IPATH_R_WRID_VALID, &qp->r_aflags)) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 430 | goto send_comp; |
| 431 | |
| 432 | if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM) |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 433 | wc.opcode = IB_WC_RECV_RDMA_WITH_IMM; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 434 | else |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 435 | wc.opcode = IB_WC_RECV; |
| 436 | wc.wr_id = qp->r_wr_id; |
| 437 | wc.status = IB_WC_SUCCESS; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 438 | wc.byte_len = wqe->length; |
Michael S. Tsirkin | 062dbb6 | 2006-12-31 21:09:42 +0200 | [diff] [blame] | 439 | wc.qp = &qp->ibqp; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 440 | wc.src_qp = qp->remote_qpn; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 441 | wc.slid = qp->remote_ah_attr.dlid; |
| 442 | wc.sl = qp->remote_ah_attr.sl; |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 443 | wc.port_num = 1; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 444 | /* Signal completion event if the solicited bit is set. */ |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 445 | ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 446 | wqe->wr.send_flags & IB_SEND_SOLICITED); |
| 447 | |
| 448 | send_comp: |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 449 | spin_lock_irqsave(&sqp->s_lock, flags); |
| 450 | flush_send: |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 451 | sqp->s_rnr_retry = sqp->s_rnr_retry_cnt; |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 452 | ipath_send_complete(sqp, wqe, send_status); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 453 | goto again; |
| 454 | |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 455 | rnr_nak: |
| 456 | /* Handle RNR NAK */ |
| 457 | if (qp->ibqp.qp_type == IB_QPT_UC) |
| 458 | goto send_comp; |
| 459 | /* |
| 460 | * Note: we don't need the s_lock held since the BUSY flag |
| 461 | * makes this single threaded. |
| 462 | */ |
| 463 | if (sqp->s_rnr_retry == 0) { |
| 464 | send_status = IB_WC_RNR_RETRY_EXC_ERR; |
| 465 | goto serr; |
| 466 | } |
| 467 | if (sqp->s_rnr_retry_cnt < 7) |
| 468 | sqp->s_rnr_retry--; |
| 469 | spin_lock_irqsave(&sqp->s_lock, flags); |
| 470 | if (!(ib_ipath_state_ops[sqp->state] & IPATH_PROCESS_RECV_OK)) |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 471 | goto clr_busy; |
| 472 | sqp->s_flags |= IPATH_S_WAITING; |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 473 | dev->n_rnr_naks++; |
| 474 | sqp->s_rnr_timeout = ib_ipath_rnr_table[qp->r_min_rnr_timer]; |
| 475 | ipath_insert_rnr_queue(sqp); |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 476 | goto clr_busy; |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 477 | |
| 478 | inv_err: |
| 479 | send_status = IB_WC_REM_INV_REQ_ERR; |
| 480 | wc.status = IB_WC_LOC_QP_OP_ERR; |
| 481 | goto err; |
| 482 | |
| 483 | acc_err: |
| 484 | send_status = IB_WC_REM_ACCESS_ERR; |
| 485 | wc.status = IB_WC_LOC_PROT_ERR; |
| 486 | err: |
| 487 | /* responder goes to error state */ |
| 488 | ipath_rc_error(qp, wc.status); |
| 489 | |
| 490 | serr: |
| 491 | spin_lock_irqsave(&sqp->s_lock, flags); |
| 492 | ipath_send_complete(sqp, wqe, send_status); |
| 493 | if (sqp->ibqp.qp_type == IB_QPT_RC) { |
| 494 | int lastwqe = ipath_error_qp(sqp, IB_WC_WR_FLUSH_ERR); |
| 495 | |
| 496 | sqp->s_flags &= ~IPATH_S_BUSY; |
| 497 | spin_unlock_irqrestore(&sqp->s_lock, flags); |
| 498 | if (lastwqe) { |
| 499 | struct ib_event ev; |
| 500 | |
| 501 | ev.device = sqp->ibqp.device; |
| 502 | ev.element.qp = &sqp->ibqp; |
| 503 | ev.event = IB_EVENT_QP_LAST_WQE_REACHED; |
| 504 | sqp->ibqp.event_handler(&ev, sqp->ibqp.qp_context); |
| 505 | } |
| 506 | goto done; |
| 507 | } |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 508 | clr_busy: |
| 509 | sqp->s_flags &= ~IPATH_S_BUSY; |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 510 | unlock: |
| 511 | spin_unlock_irqrestore(&sqp->s_lock, flags); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 512 | done: |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 513 | if (qp && atomic_dec_and_test(&qp->refcount)) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 514 | wake_up(&qp->wait); |
| 515 | } |
| 516 | |
Dave Olson | e2ab41c | 2008-05-07 11:00:15 -0700 | [diff] [blame] | 517 | static void want_buffer(struct ipath_devdata *dd, struct ipath_qp *qp) |
Bryan O'Sullivan | 34b2aaf | 2006-08-25 11:24:32 -0700 | [diff] [blame] | 518 | { |
Dave Olson | e2ab41c | 2008-05-07 11:00:15 -0700 | [diff] [blame] | 519 | if (!(dd->ipath_flags & IPATH_HAS_SEND_DMA) || |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 520 | qp->ibqp.qp_type == IB_QPT_SMI) { |
Dave Olson | 124b4dc | 2008-04-16 21:09:32 -0700 | [diff] [blame] | 521 | unsigned long flags; |
John Gregor | e342c11 | 2007-09-05 01:57:14 -0700 | [diff] [blame] | 522 | |
Dave Olson | 124b4dc | 2008-04-16 21:09:32 -0700 | [diff] [blame] | 523 | spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags); |
| 524 | dd->ipath_sendctrl |= INFINIPATH_S_PIOINTBUFAVAIL; |
| 525 | ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl, |
| 526 | dd->ipath_sendctrl); |
| 527 | ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch); |
| 528 | spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags); |
| 529 | } |
Bryan O'Sullivan | 34b2aaf | 2006-08-25 11:24:32 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 532 | /** |
| 533 | * ipath_no_bufs_available - tell the layer driver we need buffers |
| 534 | * @qp: the QP that caused the problem |
| 535 | * @dev: the device we ran out of buffers on |
| 536 | * |
| 537 | * Called when we run out of PIO buffers. |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 538 | * If we are now in the error state, return zero to flush the |
| 539 | * send work request. |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 540 | */ |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 541 | static int ipath_no_bufs_available(struct ipath_qp *qp, |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 542 | struct ipath_ibdev *dev) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 543 | { |
| 544 | unsigned long flags; |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 545 | int ret = 1; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 546 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 547 | /* |
Bryan O'Sullivan | 34b2aaf | 2006-08-25 11:24:32 -0700 | [diff] [blame] | 548 | * Note that as soon as want_buffer() is called and |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 549 | * possibly before it returns, ipath_ib_piobufavail() |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 550 | * could be called. Therefore, put QP on the piowait list before |
| 551 | * enabling the PIO avail interrupt. |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 552 | */ |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 553 | spin_lock_irqsave(&qp->s_lock, flags); |
| 554 | if (ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK) { |
| 555 | dev->n_piowait++; |
| 556 | qp->s_flags |= IPATH_S_WAITING; |
| 557 | qp->s_flags &= ~IPATH_S_BUSY; |
| 558 | spin_lock(&dev->pending_lock); |
| 559 | if (list_empty(&qp->piowait)) |
| 560 | list_add_tail(&qp->piowait, &dev->piowait); |
| 561 | spin_unlock(&dev->pending_lock); |
| 562 | } else |
| 563 | ret = 0; |
| 564 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 565 | if (ret) |
| 566 | want_buffer(dev->dd, qp); |
| 567 | return ret; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /** |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 571 | * ipath_make_grh - construct a GRH header |
| 572 | * @dev: a pointer to the ipath device |
| 573 | * @hdr: a pointer to the GRH header being constructed |
| 574 | * @grh: the global route address to send to |
| 575 | * @hwords: the number of 32 bit words of header being sent |
| 576 | * @nwords: the number of 32 bit words of data being sent |
| 577 | * |
| 578 | * Return the size of the header in 32 bit words. |
| 579 | */ |
| 580 | u32 ipath_make_grh(struct ipath_ibdev *dev, struct ib_grh *hdr, |
| 581 | struct ib_global_route *grh, u32 hwords, u32 nwords) |
| 582 | { |
| 583 | hdr->version_tclass_flow = |
| 584 | cpu_to_be32((6 << 28) | |
| 585 | (grh->traffic_class << 20) | |
| 586 | grh->flow_label); |
| 587 | hdr->paylen = cpu_to_be16((hwords - 2 + nwords + SIZE_OF_CRC) << 2); |
| 588 | /* next_hdr is defined by C8-7 in ch. 8.4.1 */ |
| 589 | hdr->next_hdr = 0x1B; |
| 590 | hdr->hop_limit = grh->hop_limit; |
| 591 | /* The SGID is 32-bit aligned. */ |
| 592 | hdr->sgid.global.subnet_prefix = dev->gid_prefix; |
Bryan O'Sullivan | 34b2aaf | 2006-08-25 11:24:32 -0700 | [diff] [blame] | 593 | hdr->sgid.global.interface_id = dev->dd->ipath_guid; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 594 | hdr->dgid = grh->dgid; |
| 595 | |
| 596 | /* GRH header size in 32-bit words. */ |
| 597 | return sizeof(struct ib_grh) / sizeof(u32); |
| 598 | } |
| 599 | |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 600 | void ipath_make_ruc_header(struct ipath_ibdev *dev, struct ipath_qp *qp, |
| 601 | struct ipath_other_headers *ohdr, |
| 602 | u32 bth0, u32 bth2) |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 603 | { |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 604 | u16 lrh0; |
| 605 | u32 nwords; |
| 606 | u32 extra_bytes; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 607 | |
| 608 | /* Construct the header. */ |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 609 | extra_bytes = -qp->s_cur_size & 3; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 610 | nwords = (qp->s_cur_size + extra_bytes) >> 2; |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 611 | lrh0 = IPATH_LRH_BTH; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 612 | if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) { |
| 613 | qp->s_hdrwords += ipath_make_grh(dev, &qp->s_hdr.u.l.grh, |
| 614 | &qp->remote_ah_attr.grh, |
| 615 | qp->s_hdrwords, nwords); |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 616 | lrh0 = IPATH_LRH_GRH; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 617 | } |
| 618 | lrh0 |= qp->remote_ah_attr.sl << 4; |
| 619 | qp->s_hdr.lrh[0] = cpu_to_be16(lrh0); |
| 620 | qp->s_hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid); |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 621 | qp->s_hdr.lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC); |
Ralph Campbell | 9403589 | 2008-09-20 20:05:51 -0700 | [diff] [blame] | 622 | qp->s_hdr.lrh[3] = cpu_to_be16(dev->dd->ipath_lid | |
| 623 | qp->remote_ah_attr.src_path_bits); |
Bryan O'Sullivan | 34b2aaf | 2006-08-25 11:24:32 -0700 | [diff] [blame] | 624 | bth0 |= ipath_get_pkey(dev->dd, qp->s_pkey_index); |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 625 | bth0 |= extra_bytes << 20; |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 626 | ohdr->bth[0] = cpu_to_be32(bth0 | (1 << 22)); |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 627 | ohdr->bth[1] = cpu_to_be32(qp->remote_qpn); |
| 628 | ohdr->bth[2] = cpu_to_be32(bth2); |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 629 | } |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 630 | |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 631 | /** |
| 632 | * ipath_do_send - perform a send on a QP |
| 633 | * @data: contains a pointer to the QP |
| 634 | * |
| 635 | * Process entries in the send work queue until credit or queue is |
| 636 | * exhausted. Only allow one CPU to send a packet per QP (tasklet). |
| 637 | * Otherwise, two threads could send packets out of order. |
| 638 | */ |
| 639 | void ipath_do_send(unsigned long data) |
| 640 | { |
| 641 | struct ipath_qp *qp = (struct ipath_qp *)data; |
| 642 | struct ipath_ibdev *dev = to_idev(qp->ibqp.device); |
| 643 | int (*make_req)(struct ipath_qp *qp); |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 644 | unsigned long flags; |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 645 | |
| 646 | if ((qp->ibqp.qp_type == IB_QPT_RC || |
| 647 | qp->ibqp.qp_type == IB_QPT_UC) && |
| 648 | qp->remote_ah_attr.dlid == dev->dd->ipath_lid) { |
| 649 | ipath_ruc_loopback(qp); |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 650 | goto bail; |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | if (qp->ibqp.qp_type == IB_QPT_RC) |
| 654 | make_req = ipath_make_rc_req; |
| 655 | else if (qp->ibqp.qp_type == IB_QPT_UC) |
| 656 | make_req = ipath_make_uc_req; |
| 657 | else |
| 658 | make_req = ipath_make_ud_req; |
| 659 | |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 660 | spin_lock_irqsave(&qp->s_lock, flags); |
| 661 | |
| 662 | /* Return if we are already busy processing a work request. */ |
| 663 | if ((qp->s_flags & (IPATH_S_BUSY | IPATH_S_ANY_WAIT)) || |
| 664 | !(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_OR_FLUSH_SEND)) { |
| 665 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 666 | goto bail; |
| 667 | } |
| 668 | |
| 669 | qp->s_flags |= IPATH_S_BUSY; |
| 670 | |
| 671 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 672 | |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 673 | again: |
| 674 | /* Check for a constructed packet to be sent. */ |
| 675 | if (qp->s_hdrwords != 0) { |
| 676 | /* |
| 677 | * If no PIO bufs are available, return. An interrupt will |
| 678 | * call ipath_ib_piobufavail() when one is available. |
| 679 | */ |
| 680 | if (ipath_verbs_send(qp, &qp->s_hdr, qp->s_hdrwords, |
| 681 | qp->s_cur_sge, qp->s_cur_size)) { |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 682 | if (ipath_no_bufs_available(qp, dev)) |
| 683 | goto bail; |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 684 | } |
| 685 | dev->n_unicast_xmit++; |
| 686 | /* Record that we sent the packet and s_hdr is empty. */ |
| 687 | qp->s_hdrwords = 0; |
| 688 | } |
| 689 | |
| 690 | if (make_req(qp)) |
| 691 | goto again; |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 692 | |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 693 | bail:; |
| 694 | } |
| 695 | |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 696 | /* |
| 697 | * This should be called with s_lock held. |
| 698 | */ |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 699 | void ipath_send_complete(struct ipath_qp *qp, struct ipath_swqe *wqe, |
| 700 | enum ib_wc_status status) |
| 701 | { |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 702 | u32 old_last, last; |
| 703 | |
| 704 | if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_OR_FLUSH_SEND)) |
| 705 | return; |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 706 | |
| 707 | /* See ch. 11.2.4.1 and 10.7.3.1 */ |
| 708 | if (!(qp->s_flags & IPATH_S_SIGNAL_REQ_WR) || |
| 709 | (wqe->wr.send_flags & IB_SEND_SIGNALED) || |
| 710 | status != IB_WC_SUCCESS) { |
| 711 | struct ib_wc wc; |
| 712 | |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 713 | memset(&wc, 0, sizeof wc); |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 714 | wc.wr_id = wqe->wr.wr_id; |
| 715 | wc.status = status; |
| 716 | wc.opcode = ib_ipath_wc_opcode[wqe->wr.opcode]; |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 717 | wc.qp = &qp->ibqp; |
Ralph Campbell | 53dc1ca | 2008-05-13 11:40:25 -0700 | [diff] [blame] | 718 | if (status == IB_WC_SUCCESS) |
| 719 | wc.byte_len = wqe->length; |
| 720 | ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, |
| 721 | status != IB_WC_SUCCESS); |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 722 | } |
Ralph Campbell | fffbfea | 2007-10-19 15:04:10 -0700 | [diff] [blame] | 723 | |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 724 | old_last = last = qp->s_last; |
Ralph Campbell | fffbfea | 2007-10-19 15:04:10 -0700 | [diff] [blame] | 725 | if (++last >= qp->s_size) |
| 726 | last = 0; |
| 727 | qp->s_last = last; |
Ralph Campbell | e509be8 | 2008-05-13 11:41:29 -0700 | [diff] [blame] | 728 | if (qp->s_cur == old_last) |
| 729 | qp->s_cur = last; |
| 730 | if (qp->s_tail == old_last) |
| 731 | qp->s_tail = last; |
| 732 | if (qp->state == IB_QPS_SQD && last == qp->s_cur) |
| 733 | qp->s_draining = 0; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 734 | } |