Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1 | /* |
John Gregor | 87427da | 2007-06-11 10:21:14 -0700 | [diff] [blame] | 2 | * Copyright (c) 2006, 2007 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 | |
| 34 | #include <linux/err.h> |
| 35 | #include <linux/vmalloc.h> |
| 36 | |
| 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 | #define BITS_PER_PAGE (PAGE_SIZE*BITS_PER_BYTE) |
| 41 | #define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1) |
| 42 | #define mk_qpn(qpt, map, off) (((map) - (qpt)->map) * BITS_PER_PAGE + \ |
| 43 | (off)) |
| 44 | #define find_next_offset(map, off) find_next_zero_bit((map)->page, \ |
| 45 | BITS_PER_PAGE, off) |
| 46 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 47 | /* |
| 48 | * Convert the AETH credit code into the number of credits. |
| 49 | */ |
| 50 | static u32 credit_table[31] = { |
| 51 | 0, /* 0 */ |
| 52 | 1, /* 1 */ |
| 53 | 2, /* 2 */ |
| 54 | 3, /* 3 */ |
| 55 | 4, /* 4 */ |
| 56 | 6, /* 5 */ |
| 57 | 8, /* 6 */ |
| 58 | 12, /* 7 */ |
| 59 | 16, /* 8 */ |
| 60 | 24, /* 9 */ |
| 61 | 32, /* A */ |
| 62 | 48, /* B */ |
| 63 | 64, /* C */ |
| 64 | 96, /* D */ |
| 65 | 128, /* E */ |
| 66 | 192, /* F */ |
| 67 | 256, /* 10 */ |
| 68 | 384, /* 11 */ |
| 69 | 512, /* 12 */ |
| 70 | 768, /* 13 */ |
| 71 | 1024, /* 14 */ |
| 72 | 1536, /* 15 */ |
| 73 | 2048, /* 16 */ |
| 74 | 3072, /* 17 */ |
| 75 | 4096, /* 18 */ |
| 76 | 6144, /* 19 */ |
| 77 | 8192, /* 1A */ |
| 78 | 12288, /* 1B */ |
| 79 | 16384, /* 1C */ |
| 80 | 24576, /* 1D */ |
| 81 | 32768 /* 1E */ |
| 82 | }; |
| 83 | |
Bryan O'Sullivan | 662af58 | 2007-03-15 14:45:12 -0700 | [diff] [blame] | 84 | |
| 85 | static void get_map_page(struct ipath_qp_table *qpt, struct qpn_map *map) |
| 86 | { |
| 87 | unsigned long page = get_zeroed_page(GFP_KERNEL); |
| 88 | unsigned long flags; |
| 89 | |
| 90 | /* |
| 91 | * Free the page if someone raced with us installing it. |
| 92 | */ |
| 93 | |
| 94 | spin_lock_irqsave(&qpt->lock, flags); |
| 95 | if (map->page) |
| 96 | free_page(page); |
| 97 | else |
| 98 | map->page = (void *)page; |
| 99 | spin_unlock_irqrestore(&qpt->lock, flags); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | static int alloc_qpn(struct ipath_qp_table *qpt, enum ib_qp_type type) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 104 | { |
| 105 | u32 i, offset, max_scan, qpn; |
| 106 | struct qpn_map *map; |
Bryan O'Sullivan | 662af58 | 2007-03-15 14:45:12 -0700 | [diff] [blame] | 107 | u32 ret = -1; |
| 108 | |
| 109 | if (type == IB_QPT_SMI) |
| 110 | ret = 0; |
| 111 | else if (type == IB_QPT_GSI) |
| 112 | ret = 1; |
| 113 | |
| 114 | if (ret != -1) { |
| 115 | map = &qpt->map[0]; |
| 116 | if (unlikely(!map->page)) { |
| 117 | get_map_page(qpt, map); |
| 118 | if (unlikely(!map->page)) { |
| 119 | ret = -ENOMEM; |
| 120 | goto bail; |
| 121 | } |
| 122 | } |
| 123 | if (!test_and_set_bit(ret, map->page)) |
| 124 | atomic_dec(&map->n_free); |
| 125 | else |
| 126 | ret = -EBUSY; |
| 127 | goto bail; |
| 128 | } |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 129 | |
| 130 | qpn = qpt->last + 1; |
| 131 | if (qpn >= QPN_MAX) |
| 132 | qpn = 2; |
| 133 | offset = qpn & BITS_PER_PAGE_MASK; |
| 134 | map = &qpt->map[qpn / BITS_PER_PAGE]; |
| 135 | max_scan = qpt->nmaps - !offset; |
| 136 | for (i = 0;;) { |
| 137 | if (unlikely(!map->page)) { |
Bryan O'Sullivan | 662af58 | 2007-03-15 14:45:12 -0700 | [diff] [blame] | 138 | get_map_page(qpt, map); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 139 | if (unlikely(!map->page)) |
| 140 | break; |
| 141 | } |
| 142 | if (likely(atomic_read(&map->n_free))) { |
| 143 | do { |
| 144 | if (!test_and_set_bit(offset, map->page)) { |
| 145 | atomic_dec(&map->n_free); |
| 146 | qpt->last = qpn; |
| 147 | ret = qpn; |
| 148 | goto bail; |
| 149 | } |
| 150 | offset = find_next_offset(map, offset); |
| 151 | qpn = mk_qpn(qpt, map, offset); |
| 152 | /* |
| 153 | * This test differs from alloc_pidmap(). |
| 154 | * If find_next_offset() does find a zero |
| 155 | * bit, we don't need to check for QPN |
| 156 | * wrapping around past our starting QPN. |
| 157 | * We just need to be sure we don't loop |
| 158 | * forever. |
| 159 | */ |
| 160 | } while (offset < BITS_PER_PAGE && qpn < QPN_MAX); |
| 161 | } |
| 162 | /* |
| 163 | * In order to keep the number of pages allocated to a |
| 164 | * minimum, we scan the all existing pages before increasing |
| 165 | * the size of the bitmap table. |
| 166 | */ |
| 167 | if (++i > max_scan) { |
| 168 | if (qpt->nmaps == QPNMAP_ENTRIES) |
| 169 | break; |
| 170 | map = &qpt->map[qpt->nmaps++]; |
| 171 | offset = 0; |
| 172 | } else if (map < &qpt->map[qpt->nmaps]) { |
| 173 | ++map; |
| 174 | offset = 0; |
| 175 | } else { |
| 176 | map = &qpt->map[0]; |
| 177 | offset = 2; |
| 178 | } |
| 179 | qpn = mk_qpn(qpt, map, offset); |
| 180 | } |
| 181 | |
Bryan O'Sullivan | 662af58 | 2007-03-15 14:45:12 -0700 | [diff] [blame] | 182 | ret = -ENOMEM; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 183 | |
| 184 | bail: |
| 185 | return ret; |
| 186 | } |
| 187 | |
| 188 | static void free_qpn(struct ipath_qp_table *qpt, u32 qpn) |
| 189 | { |
| 190 | struct qpn_map *map; |
| 191 | |
| 192 | map = qpt->map + qpn / BITS_PER_PAGE; |
| 193 | if (map->page) |
| 194 | clear_bit(qpn & BITS_PER_PAGE_MASK, map->page); |
| 195 | atomic_inc(&map->n_free); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * ipath_alloc_qpn - allocate a QP number |
| 200 | * @qpt: the QP table |
| 201 | * @qp: the QP |
| 202 | * @type: the QP type (IB_QPT_SMI and IB_QPT_GSI are special) |
| 203 | * |
| 204 | * Allocate the next available QPN and put the QP into the hash table. |
| 205 | * The hash table holds a reference to the QP. |
| 206 | */ |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 207 | static int ipath_alloc_qpn(struct ipath_qp_table *qpt, struct ipath_qp *qp, |
| 208 | enum ib_qp_type type) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 209 | { |
| 210 | unsigned long flags; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 211 | int ret; |
| 212 | |
Bryan O'Sullivan | 662af58 | 2007-03-15 14:45:12 -0700 | [diff] [blame] | 213 | ret = alloc_qpn(qpt, type); |
| 214 | if (ret < 0) |
| 215 | goto bail; |
| 216 | qp->ibqp.qp_num = ret; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 217 | |
| 218 | /* Add the QP to the hash table. */ |
| 219 | spin_lock_irqsave(&qpt->lock, flags); |
| 220 | |
Bryan O'Sullivan | 662af58 | 2007-03-15 14:45:12 -0700 | [diff] [blame] | 221 | ret %= qpt->max; |
| 222 | qp->next = qpt->table[ret]; |
| 223 | qpt->table[ret] = qp; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 224 | atomic_inc(&qp->refcount); |
| 225 | |
| 226 | spin_unlock_irqrestore(&qpt->lock, flags); |
| 227 | ret = 0; |
| 228 | |
| 229 | bail: |
| 230 | return ret; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * ipath_free_qp - remove a QP from the QP table |
| 235 | * @qpt: the QP table |
| 236 | * @qp: the QP to remove |
| 237 | * |
| 238 | * Remove the QP from the table so it can't be found asynchronously by |
| 239 | * the receive interrupt routine. |
| 240 | */ |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 241 | static void ipath_free_qp(struct ipath_qp_table *qpt, struct ipath_qp *qp) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 242 | { |
| 243 | struct ipath_qp *q, **qpp; |
| 244 | unsigned long flags; |
| 245 | int fnd = 0; |
| 246 | |
| 247 | spin_lock_irqsave(&qpt->lock, flags); |
| 248 | |
| 249 | /* Remove QP from the hash table. */ |
| 250 | qpp = &qpt->table[qp->ibqp.qp_num % qpt->max]; |
| 251 | for (; (q = *qpp) != NULL; qpp = &q->next) { |
| 252 | if (q == qp) { |
| 253 | *qpp = qp->next; |
| 254 | qp->next = NULL; |
| 255 | atomic_dec(&qp->refcount); |
| 256 | fnd = 1; |
| 257 | break; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | spin_unlock_irqrestore(&qpt->lock, flags); |
| 262 | |
| 263 | if (!fnd) |
| 264 | return; |
| 265 | |
Bryan O'Sullivan | 662af58 | 2007-03-15 14:45:12 -0700 | [diff] [blame] | 266 | free_qpn(qpt, qp->ibqp.qp_num); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 267 | |
| 268 | wait_event(qp->wait, !atomic_read(&qp->refcount)); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * ipath_free_all_qps - remove all QPs from the table |
| 273 | * @qpt: the QP table to empty |
| 274 | */ |
| 275 | void ipath_free_all_qps(struct ipath_qp_table *qpt) |
| 276 | { |
| 277 | unsigned long flags; |
| 278 | struct ipath_qp *qp, *nqp; |
| 279 | u32 n; |
| 280 | |
| 281 | for (n = 0; n < qpt->max; n++) { |
| 282 | spin_lock_irqsave(&qpt->lock, flags); |
| 283 | qp = qpt->table[n]; |
| 284 | qpt->table[n] = NULL; |
| 285 | spin_unlock_irqrestore(&qpt->lock, flags); |
| 286 | |
| 287 | while (qp) { |
| 288 | nqp = qp->next; |
Bryan O'Sullivan | 662af58 | 2007-03-15 14:45:12 -0700 | [diff] [blame] | 289 | free_qpn(qpt, qp->ibqp.qp_num); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 290 | if (!atomic_dec_and_test(&qp->refcount) || |
| 291 | !ipath_destroy_qp(&qp->ibqp)) |
Bryan O'Sullivan | 39c0d0b | 2007-03-15 14:44:52 -0700 | [diff] [blame] | 292 | ipath_dbg("QP memory leak!\n"); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 293 | qp = nqp; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | for (n = 0; n < ARRAY_SIZE(qpt->map); n++) { |
| 298 | if (qpt->map[n].page) |
| 299 | free_page((unsigned long)qpt->map[n].page); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * ipath_lookup_qpn - return the QP with the given QPN |
| 305 | * @qpt: the QP table |
| 306 | * @qpn: the QP number to look up |
| 307 | * |
| 308 | * The caller is responsible for decrementing the QP reference count |
| 309 | * when done. |
| 310 | */ |
| 311 | struct ipath_qp *ipath_lookup_qpn(struct ipath_qp_table *qpt, u32 qpn) |
| 312 | { |
| 313 | unsigned long flags; |
| 314 | struct ipath_qp *qp; |
| 315 | |
| 316 | spin_lock_irqsave(&qpt->lock, flags); |
| 317 | |
| 318 | for (qp = qpt->table[qpn % qpt->max]; qp; qp = qp->next) { |
| 319 | if (qp->ibqp.qp_num == qpn) { |
| 320 | atomic_inc(&qp->refcount); |
| 321 | break; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | spin_unlock_irqrestore(&qpt->lock, flags); |
| 326 | return qp; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * ipath_reset_qp - initialize the QP state to the reset state |
| 331 | * @qp: the QP to reset |
Patrick Marchand Latifi | 4cd5060 | 2008-01-18 20:10:48 -0800 | [diff] [blame] | 332 | * @type: the QP type |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 333 | */ |
Patrick Marchand Latifi | 4cd5060 | 2008-01-18 20:10:48 -0800 | [diff] [blame] | 334 | static void ipath_reset_qp(struct ipath_qp *qp, enum ib_qp_type type) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 335 | { |
| 336 | qp->remote_qpn = 0; |
| 337 | qp->qkey = 0; |
| 338 | qp->qp_access_flags = 0; |
Ralph Campbell | 3859e39 | 2007-03-15 14:44:51 -0700 | [diff] [blame] | 339 | qp->s_busy = 0; |
Robert Walsh | 991bda2 | 2007-06-04 09:55:48 -0700 | [diff] [blame] | 340 | qp->s_flags &= IPATH_S_SIGNAL_REQ_WR; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 341 | qp->s_hdrwords = 0; |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 342 | qp->s_wqe = NULL; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 343 | qp->s_psn = 0; |
| 344 | qp->r_psn = 0; |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 345 | qp->r_msn = 0; |
Patrick Marchand Latifi | 4cd5060 | 2008-01-18 20:10:48 -0800 | [diff] [blame] | 346 | if (type == IB_QPT_RC) { |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 347 | qp->s_state = IB_OPCODE_RC_SEND_LAST; |
| 348 | qp->r_state = IB_OPCODE_RC_SEND_LAST; |
| 349 | } else { |
| 350 | qp->s_state = IB_OPCODE_UC_SEND_LAST; |
| 351 | qp->r_state = IB_OPCODE_UC_SEND_LAST; |
| 352 | } |
| 353 | qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE; |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 354 | qp->r_nak_state = 0; |
Bryan O'Sullivan | 8d0208c | 2006-09-28 09:00:14 -0700 | [diff] [blame] | 355 | qp->r_wrid_valid = 0; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 356 | qp->s_rnr_timeout = 0; |
| 357 | qp->s_head = 0; |
| 358 | qp->s_tail = 0; |
| 359 | qp->s_cur = 0; |
| 360 | qp->s_last = 0; |
| 361 | qp->s_ssn = 1; |
| 362 | qp->s_lsn = 0; |
Bryan O'Sullivan | 6022943 | 2006-09-28 08:59:57 -0700 | [diff] [blame] | 363 | qp->s_wait_credit = 0; |
Ralph Campbell | 3859e39 | 2007-03-15 14:44:51 -0700 | [diff] [blame] | 364 | memset(qp->s_ack_queue, 0, sizeof(qp->s_ack_queue)); |
| 365 | qp->r_head_ack_queue = 0; |
| 366 | qp->s_tail_ack_queue = 0; |
| 367 | qp->s_num_rd_atomic = 0; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 368 | if (qp->r_rq.wq) { |
| 369 | qp->r_rq.wq->head = 0; |
| 370 | qp->r_rq.wq->tail = 0; |
| 371 | } |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 372 | qp->r_reuse_sge = 0; |
| 373 | } |
| 374 | |
| 375 | /** |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 376 | * ipath_error_qp - put a QP into an error state |
| 377 | * @qp: the QP to put into an error state |
Bryan O'Sullivan | 8d0208c | 2006-09-28 09:00:14 -0700 | [diff] [blame] | 378 | * @err: the receive completion error to signal if a RWQE is active |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 379 | * |
| 380 | * Flushes both send and receive work queues. |
Ralph Campbell | d42b01b | 2007-08-25 16:45:03 -0700 | [diff] [blame] | 381 | * Returns true if last WQE event should be generated. |
Ralph Campbell | 0434d27 | 2007-03-15 14:44:53 -0700 | [diff] [blame] | 382 | * The QP s_lock should be held and interrupts disabled. |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 383 | */ |
| 384 | |
Ralph Campbell | d42b01b | 2007-08-25 16:45:03 -0700 | [diff] [blame] | 385 | int ipath_error_qp(struct ipath_qp *qp, enum ib_wc_status err) |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 386 | { |
| 387 | struct ipath_ibdev *dev = to_idev(qp->ibqp.device); |
| 388 | struct ib_wc wc; |
Ralph Campbell | d42b01b | 2007-08-25 16:45:03 -0700 | [diff] [blame] | 389 | int ret = 0; |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 390 | |
Ralph Campbell | a2f76cd | 2007-11-02 17:40:36 -0700 | [diff] [blame] | 391 | ipath_dbg("QP%d/%d in error state (%d)\n", |
| 392 | qp->ibqp.qp_num, qp->remote_qpn, err); |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 393 | |
| 394 | spin_lock(&dev->pending_lock); |
| 395 | /* XXX What if its already removed by the timeout code? */ |
Bryan O'Sullivan | 94b8d9f | 2006-05-23 11:32:32 -0700 | [diff] [blame] | 396 | if (!list_empty(&qp->timerwait)) |
| 397 | list_del_init(&qp->timerwait); |
| 398 | if (!list_empty(&qp->piowait)) |
| 399 | list_del_init(&qp->piowait); |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 400 | spin_unlock(&dev->pending_lock); |
| 401 | |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 402 | wc.vendor_err = 0; |
| 403 | wc.byte_len = 0; |
| 404 | wc.imm_data = 0; |
Michael S. Tsirkin | 062dbb6 | 2006-12-31 21:09:42 +0200 | [diff] [blame] | 405 | wc.qp = &qp->ibqp; |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 406 | wc.src_qp = 0; |
| 407 | wc.wc_flags = 0; |
| 408 | wc.pkey_index = 0; |
| 409 | wc.slid = 0; |
| 410 | wc.sl = 0; |
| 411 | wc.dlid_path_bits = 0; |
| 412 | wc.port_num = 0; |
Bryan O'Sullivan | 8d0208c | 2006-09-28 09:00:14 -0700 | [diff] [blame] | 413 | if (qp->r_wrid_valid) { |
| 414 | qp->r_wrid_valid = 0; |
Ralph Campbell | 0434d27 | 2007-03-15 14:44:53 -0700 | [diff] [blame] | 415 | wc.wr_id = qp->r_wr_id; |
| 416 | wc.opcode = IB_WC_RECV; |
Bryan O'Sullivan | 8d0208c | 2006-09-28 09:00:14 -0700 | [diff] [blame] | 417 | wc.status = err; |
Patrick Marchand Latifi | 2a049e5 | 2008-01-31 00:24:37 -0800 | [diff] [blame] | 418 | ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1); |
Bryan O'Sullivan | 8d0208c | 2006-09-28 09:00:14 -0700 | [diff] [blame] | 419 | } |
| 420 | wc.status = IB_WC_WR_FLUSH_ERR; |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 421 | |
| 422 | while (qp->s_last != qp->s_head) { |
| 423 | struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last); |
| 424 | |
| 425 | wc.wr_id = wqe->wr.wr_id; |
| 426 | wc.opcode = ib_ipath_wc_opcode[wqe->wr.opcode]; |
| 427 | if (++qp->s_last >= qp->s_size) |
| 428 | qp->s_last = 0; |
| 429 | ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 1); |
| 430 | } |
| 431 | qp->s_cur = qp->s_tail = qp->s_head; |
| 432 | qp->s_hdrwords = 0; |
| 433 | qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE; |
| 434 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 435 | if (qp->r_rq.wq) { |
| 436 | struct ipath_rwq *wq; |
| 437 | u32 head; |
| 438 | u32 tail; |
| 439 | |
| 440 | spin_lock(&qp->r_rq.lock); |
| 441 | |
| 442 | /* sanity check pointers before trusting them */ |
| 443 | wq = qp->r_rq.wq; |
| 444 | head = wq->head; |
| 445 | if (head >= qp->r_rq.size) |
| 446 | head = 0; |
| 447 | tail = wq->tail; |
| 448 | if (tail >= qp->r_rq.size) |
| 449 | tail = 0; |
| 450 | wc.opcode = IB_WC_RECV; |
| 451 | while (tail != head) { |
| 452 | wc.wr_id = get_rwqe_ptr(&qp->r_rq, tail)->wr_id; |
| 453 | if (++tail >= qp->r_rq.size) |
| 454 | tail = 0; |
| 455 | ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1); |
| 456 | } |
| 457 | wq->tail = tail; |
| 458 | |
| 459 | spin_unlock(&qp->r_rq.lock); |
Ralph Campbell | d42b01b | 2007-08-25 16:45:03 -0700 | [diff] [blame] | 460 | } else if (qp->ibqp.event_handler) |
| 461 | ret = 1; |
| 462 | |
| 463 | return ret; |
Roland Dreier | ac2ae4c | 2006-04-19 11:40:12 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /** |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 467 | * ipath_modify_qp - modify the attributes of a queue pair |
| 468 | * @ibqp: the queue pair who's attributes we're modifying |
| 469 | * @attr: the new attributes |
| 470 | * @attr_mask: the mask of attributes to modify |
Ralph Campbell | 9bc57e2 | 2006-08-11 14:58:09 -0700 | [diff] [blame] | 471 | * @udata: user data for ipathverbs.so |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 472 | * |
| 473 | * Returns 0 on success, otherwise returns an errno. |
| 474 | */ |
| 475 | int ipath_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
Ralph Campbell | 9bc57e2 | 2006-08-11 14:58:09 -0700 | [diff] [blame] | 476 | int attr_mask, struct ib_udata *udata) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 477 | { |
Bryan O'Sullivan | b228b43 | 2006-05-23 11:32:30 -0700 | [diff] [blame] | 478 | struct ipath_ibdev *dev = to_idev(ibqp->device); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 479 | struct ipath_qp *qp = to_iqp(ibqp); |
| 480 | enum ib_qp_state cur_state, new_state; |
| 481 | unsigned long flags; |
Ralph Campbell | d42b01b | 2007-08-25 16:45:03 -0700 | [diff] [blame] | 482 | int lastwqe = 0; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 483 | int ret; |
| 484 | |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 485 | spin_lock_irqsave(&qp->s_lock, flags); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 486 | |
| 487 | cur_state = attr_mask & IB_QP_CUR_STATE ? |
| 488 | attr->cur_qp_state : qp->state; |
| 489 | new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state; |
| 490 | |
| 491 | if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type, |
| 492 | attr_mask)) |
| 493 | goto inval; |
| 494 | |
Bryan O'Sullivan | fc8cf8c | 2006-08-25 11:24:41 -0700 | [diff] [blame] | 495 | if (attr_mask & IB_QP_AV) { |
Bryan O'Sullivan | b228b43 | 2006-05-23 11:32:30 -0700 | [diff] [blame] | 496 | if (attr->ah_attr.dlid == 0 || |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 497 | attr->ah_attr.dlid >= IPATH_MULTICAST_LID_BASE) |
Bryan O'Sullivan | b228b43 | 2006-05-23 11:32:30 -0700 | [diff] [blame] | 498 | goto inval; |
| 499 | |
Bryan O'Sullivan | fc8cf8c | 2006-08-25 11:24:41 -0700 | [diff] [blame] | 500 | if ((attr->ah_attr.ah_flags & IB_AH_GRH) && |
| 501 | (attr->ah_attr.grh.sgid_index > 1)) |
| 502 | goto inval; |
| 503 | } |
| 504 | |
Bryan O'Sullivan | b228b43 | 2006-05-23 11:32:30 -0700 | [diff] [blame] | 505 | if (attr_mask & IB_QP_PKEY_INDEX) |
Bryan O'Sullivan | 34b2aaf | 2006-08-25 11:24:32 -0700 | [diff] [blame] | 506 | if (attr->pkey_index >= ipath_get_npkeys(dev->dd)) |
Bryan O'Sullivan | b228b43 | 2006-05-23 11:32:30 -0700 | [diff] [blame] | 507 | goto inval; |
| 508 | |
| 509 | if (attr_mask & IB_QP_MIN_RNR_TIMER) |
| 510 | if (attr->min_rnr_timer > 31) |
| 511 | goto inval; |
| 512 | |
Bryan O'Sullivan | fc8cf8c | 2006-08-25 11:24:41 -0700 | [diff] [blame] | 513 | if (attr_mask & IB_QP_PORT) |
| 514 | if (attr->port_num == 0 || |
| 515 | attr->port_num > ibqp->device->phys_port_cnt) |
| 516 | goto inval; |
| 517 | |
Robert Walsh | e7340f0 | 2007-06-18 14:24:35 -0700 | [diff] [blame] | 518 | /* |
| 519 | * Note: the chips support a maximum MTU of 4096, but the driver |
| 520 | * hasn't implemented this feature yet, so don't allow Path MTU |
| 521 | * values greater than 2048. |
| 522 | */ |
Bryan O'Sullivan | fc8cf8c | 2006-08-25 11:24:41 -0700 | [diff] [blame] | 523 | if (attr_mask & IB_QP_PATH_MTU) |
Robert Walsh | e7340f0 | 2007-06-18 14:24:35 -0700 | [diff] [blame] | 524 | if (attr->path_mtu > IB_MTU_2048) |
Bryan O'Sullivan | fc8cf8c | 2006-08-25 11:24:41 -0700 | [diff] [blame] | 525 | goto inval; |
| 526 | |
Bryan O'Sullivan | fc8cf8c | 2006-08-25 11:24:41 -0700 | [diff] [blame] | 527 | if (attr_mask & IB_QP_PATH_MIG_STATE) |
Bryan O'Sullivan | ca4ce38 | 2006-08-25 11:24:42 -0700 | [diff] [blame] | 528 | if (attr->path_mig_state != IB_MIG_MIGRATED && |
| 529 | attr->path_mig_state != IB_MIG_REARM) |
Bryan O'Sullivan | fc8cf8c | 2006-08-25 11:24:41 -0700 | [diff] [blame] | 530 | goto inval; |
| 531 | |
Ralph Campbell | 3859e39 | 2007-03-15 14:44:51 -0700 | [diff] [blame] | 532 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) |
| 533 | if (attr->max_dest_rd_atomic > IPATH_MAX_RDMA_ATOMIC) |
| 534 | goto inval; |
| 535 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 536 | switch (new_state) { |
| 537 | case IB_QPS_RESET: |
Patrick Marchand Latifi | 4cd5060 | 2008-01-18 20:10:48 -0800 | [diff] [blame] | 538 | ipath_reset_qp(qp, ibqp->qp_type); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 539 | break; |
| 540 | |
| 541 | case IB_QPS_ERR: |
Ralph Campbell | d42b01b | 2007-08-25 16:45:03 -0700 | [diff] [blame] | 542 | lastwqe = ipath_error_qp(qp, IB_WC_WR_FLUSH_ERR); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 543 | break; |
| 544 | |
| 545 | default: |
| 546 | break; |
| 547 | |
| 548 | } |
| 549 | |
Bryan O'Sullivan | b228b43 | 2006-05-23 11:32:30 -0700 | [diff] [blame] | 550 | if (attr_mask & IB_QP_PKEY_INDEX) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 551 | qp->s_pkey_index = attr->pkey_index; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 552 | |
| 553 | if (attr_mask & IB_QP_DEST_QPN) |
| 554 | qp->remote_qpn = attr->dest_qp_num; |
| 555 | |
| 556 | if (attr_mask & IB_QP_SQ_PSN) { |
Bryan O'Sullivan | 6022943 | 2006-09-28 08:59:57 -0700 | [diff] [blame] | 557 | qp->s_psn = qp->s_next_psn = attr->sq_psn; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 558 | qp->s_last_psn = qp->s_next_psn - 1; |
| 559 | } |
| 560 | |
| 561 | if (attr_mask & IB_QP_RQ_PSN) |
| 562 | qp->r_psn = attr->rq_psn; |
| 563 | |
| 564 | if (attr_mask & IB_QP_ACCESS_FLAGS) |
| 565 | qp->qp_access_flags = attr->qp_access_flags; |
| 566 | |
Bryan O'Sullivan | b228b43 | 2006-05-23 11:32:30 -0700 | [diff] [blame] | 567 | if (attr_mask & IB_QP_AV) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 568 | qp->remote_ah_attr = attr->ah_attr; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 569 | |
| 570 | if (attr_mask & IB_QP_PATH_MTU) |
| 571 | qp->path_mtu = attr->path_mtu; |
| 572 | |
| 573 | if (attr_mask & IB_QP_RETRY_CNT) |
| 574 | qp->s_retry = qp->s_retry_cnt = attr->retry_cnt; |
| 575 | |
| 576 | if (attr_mask & IB_QP_RNR_RETRY) { |
| 577 | qp->s_rnr_retry = attr->rnr_retry; |
| 578 | if (qp->s_rnr_retry > 7) |
| 579 | qp->s_rnr_retry = 7; |
| 580 | qp->s_rnr_retry_cnt = qp->s_rnr_retry; |
| 581 | } |
| 582 | |
Bryan O'Sullivan | b228b43 | 2006-05-23 11:32:30 -0700 | [diff] [blame] | 583 | if (attr_mask & IB_QP_MIN_RNR_TIMER) |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 584 | qp->r_min_rnr_timer = attr->min_rnr_timer; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 585 | |
Bryan O'Sullivan | fc8cf8c | 2006-08-25 11:24:41 -0700 | [diff] [blame] | 586 | if (attr_mask & IB_QP_TIMEOUT) |
| 587 | qp->timeout = attr->timeout; |
| 588 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 589 | if (attr_mask & IB_QP_QKEY) |
| 590 | qp->qkey = attr->qkey; |
| 591 | |
Ralph Campbell | 3859e39 | 2007-03-15 14:44:51 -0700 | [diff] [blame] | 592 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) |
| 593 | qp->r_max_rd_atomic = attr->max_dest_rd_atomic; |
| 594 | |
| 595 | if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) |
| 596 | qp->s_max_rd_atomic = attr->max_rd_atomic; |
| 597 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 598 | qp->state = new_state; |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 599 | spin_unlock_irqrestore(&qp->s_lock, flags); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 600 | |
Ralph Campbell | d42b01b | 2007-08-25 16:45:03 -0700 | [diff] [blame] | 601 | if (lastwqe) { |
| 602 | struct ib_event ev; |
| 603 | |
| 604 | ev.device = qp->ibqp.device; |
| 605 | ev.element.qp = &qp->ibqp; |
| 606 | ev.event = IB_EVENT_QP_LAST_WQE_REACHED; |
| 607 | qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); |
| 608 | } |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 609 | ret = 0; |
| 610 | goto bail; |
| 611 | |
| 612 | inval: |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 613 | spin_unlock_irqrestore(&qp->s_lock, flags); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 614 | ret = -EINVAL; |
| 615 | |
| 616 | bail: |
| 617 | return ret; |
| 618 | } |
| 619 | |
| 620 | int ipath_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 621 | int attr_mask, struct ib_qp_init_attr *init_attr) |
| 622 | { |
| 623 | struct ipath_qp *qp = to_iqp(ibqp); |
| 624 | |
| 625 | attr->qp_state = qp->state; |
| 626 | attr->cur_qp_state = attr->qp_state; |
| 627 | attr->path_mtu = qp->path_mtu; |
| 628 | attr->path_mig_state = 0; |
| 629 | attr->qkey = qp->qkey; |
| 630 | attr->rq_psn = qp->r_psn; |
| 631 | attr->sq_psn = qp->s_next_psn; |
| 632 | attr->dest_qp_num = qp->remote_qpn; |
| 633 | attr->qp_access_flags = qp->qp_access_flags; |
| 634 | attr->cap.max_send_wr = qp->s_size - 1; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 635 | attr->cap.max_recv_wr = qp->ibqp.srq ? 0 : qp->r_rq.size - 1; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 636 | attr->cap.max_send_sge = qp->s_max_sge; |
| 637 | attr->cap.max_recv_sge = qp->r_rq.max_sge; |
| 638 | attr->cap.max_inline_data = 0; |
| 639 | attr->ah_attr = qp->remote_ah_attr; |
| 640 | memset(&attr->alt_ah_attr, 0, sizeof(attr->alt_ah_attr)); |
| 641 | attr->pkey_index = qp->s_pkey_index; |
| 642 | attr->alt_pkey_index = 0; |
| 643 | attr->en_sqd_async_notify = 0; |
| 644 | attr->sq_draining = 0; |
Ralph Campbell | 3859e39 | 2007-03-15 14:44:51 -0700 | [diff] [blame] | 645 | attr->max_rd_atomic = qp->s_max_rd_atomic; |
| 646 | attr->max_dest_rd_atomic = qp->r_max_rd_atomic; |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 647 | attr->min_rnr_timer = qp->r_min_rnr_timer; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 648 | attr->port_num = 1; |
Bryan O'Sullivan | fc8cf8c | 2006-08-25 11:24:41 -0700 | [diff] [blame] | 649 | attr->timeout = qp->timeout; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 650 | attr->retry_cnt = qp->s_retry_cnt; |
Patrick Marchand Latifi | 87d5aed | 2008-01-07 23:43:04 -0800 | [diff] [blame] | 651 | attr->rnr_retry = qp->s_rnr_retry_cnt; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 652 | attr->alt_port_num = 0; |
| 653 | attr->alt_timeout = 0; |
| 654 | |
| 655 | init_attr->event_handler = qp->ibqp.event_handler; |
| 656 | init_attr->qp_context = qp->ibqp.qp_context; |
| 657 | init_attr->send_cq = qp->ibqp.send_cq; |
| 658 | init_attr->recv_cq = qp->ibqp.recv_cq; |
| 659 | init_attr->srq = qp->ibqp.srq; |
| 660 | init_attr->cap = attr->cap; |
Ralph Campbell | 3859e39 | 2007-03-15 14:44:51 -0700 | [diff] [blame] | 661 | if (qp->s_flags & IPATH_S_SIGNAL_REQ_WR) |
Bryan O'Sullivan | a78aa6f | 2006-08-25 11:24:44 -0700 | [diff] [blame] | 662 | init_attr->sq_sig_type = IB_SIGNAL_REQ_WR; |
| 663 | else |
| 664 | init_attr->sq_sig_type = IB_SIGNAL_ALL_WR; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 665 | init_attr->qp_type = qp->ibqp.qp_type; |
| 666 | init_attr->port_num = 1; |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * ipath_compute_aeth - compute the AETH (syndrome + MSN) |
| 672 | * @qp: the queue pair to compute the AETH for |
| 673 | * |
| 674 | * Returns the AETH. |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 675 | */ |
| 676 | __be32 ipath_compute_aeth(struct ipath_qp *qp) |
| 677 | { |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 678 | u32 aeth = qp->r_msn & IPATH_MSN_MASK; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 679 | |
Bryan O'Sullivan | 12eef41 | 2006-07-01 04:36:10 -0700 | [diff] [blame] | 680 | if (qp->ibqp.srq) { |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 681 | /* |
| 682 | * Shared receive queues don't generate credits. |
| 683 | * Set the credit field to the invalid value. |
| 684 | */ |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 685 | aeth |= IPATH_AETH_CREDIT_INVAL << IPATH_AETH_CREDIT_SHIFT; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 686 | } else { |
| 687 | u32 min, max, x; |
| 688 | u32 credits; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 689 | struct ipath_rwq *wq = qp->r_rq.wq; |
| 690 | u32 head; |
| 691 | u32 tail; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 692 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 693 | /* sanity check pointers before trusting them */ |
| 694 | head = wq->head; |
| 695 | if (head >= qp->r_rq.size) |
| 696 | head = 0; |
| 697 | tail = wq->tail; |
| 698 | if (tail >= qp->r_rq.size) |
| 699 | tail = 0; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 700 | /* |
| 701 | * Compute the number of credits available (RWQEs). |
| 702 | * XXX Not holding the r_rq.lock here so there is a small |
| 703 | * chance that the pair of reads are not atomic. |
| 704 | */ |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 705 | credits = head - tail; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 706 | if ((int)credits < 0) |
| 707 | credits += qp->r_rq.size; |
| 708 | /* |
| 709 | * Binary search the credit table to find the code to |
| 710 | * use. |
| 711 | */ |
| 712 | min = 0; |
| 713 | max = 31; |
| 714 | for (;;) { |
| 715 | x = (min + max) / 2; |
| 716 | if (credit_table[x] == credits) |
| 717 | break; |
| 718 | if (credit_table[x] > credits) |
| 719 | max = x; |
| 720 | else if (min == x) |
| 721 | break; |
| 722 | else |
| 723 | min = x; |
| 724 | } |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 725 | aeth |= x << IPATH_AETH_CREDIT_SHIFT; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 726 | } |
| 727 | return cpu_to_be32(aeth); |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * ipath_create_qp - create a queue pair for a device |
| 732 | * @ibpd: the protection domain who's device we create the queue pair for |
| 733 | * @init_attr: the attributes of the queue pair |
| 734 | * @udata: unused by InfiniPath |
| 735 | * |
| 736 | * Returns the queue pair on success, otherwise returns an errno. |
| 737 | * |
| 738 | * Called by the ib_create_qp() core verbs function. |
| 739 | */ |
| 740 | struct ib_qp *ipath_create_qp(struct ib_pd *ibpd, |
| 741 | struct ib_qp_init_attr *init_attr, |
| 742 | struct ib_udata *udata) |
| 743 | { |
| 744 | struct ipath_qp *qp; |
| 745 | int err; |
| 746 | struct ipath_swqe *swq = NULL; |
| 747 | struct ipath_ibdev *dev; |
| 748 | size_t sz; |
| 749 | struct ib_qp *ret; |
| 750 | |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 751 | if (init_attr->cap.max_send_sge > ib_ipath_max_sges || |
| 752 | init_attr->cap.max_recv_sge > ib_ipath_max_sges || |
| 753 | init_attr->cap.max_send_wr > ib_ipath_max_qp_wrs || |
| 754 | init_attr->cap.max_recv_wr > ib_ipath_max_qp_wrs) { |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 755 | ret = ERR_PTR(-ENOMEM); |
| 756 | goto bail; |
| 757 | } |
| 758 | |
Bryan O'Sullivan | 4a45b7d | 2006-07-01 04:35:55 -0700 | [diff] [blame] | 759 | if (init_attr->cap.max_send_sge + |
| 760 | init_attr->cap.max_recv_sge + |
| 761 | init_attr->cap.max_send_wr + |
| 762 | init_attr->cap.max_recv_wr == 0) { |
| 763 | ret = ERR_PTR(-EINVAL); |
| 764 | goto bail; |
| 765 | } |
| 766 | |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 767 | switch (init_attr->qp_type) { |
| 768 | case IB_QPT_UC: |
| 769 | case IB_QPT_RC: |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 770 | case IB_QPT_UD: |
| 771 | case IB_QPT_SMI: |
| 772 | case IB_QPT_GSI: |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 773 | sz = sizeof(struct ipath_sge) * |
| 774 | init_attr->cap.max_send_sge + |
| 775 | sizeof(struct ipath_swqe); |
| 776 | swq = vmalloc((init_attr->cap.max_send_wr + 1) * sz); |
| 777 | if (swq == NULL) { |
| 778 | ret = ERR_PTR(-ENOMEM); |
| 779 | goto bail; |
| 780 | } |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 781 | sz = sizeof(*qp); |
| 782 | if (init_attr->srq) { |
| 783 | struct ipath_srq *srq = to_isrq(init_attr->srq); |
| 784 | |
| 785 | sz += sizeof(*qp->r_sg_list) * |
| 786 | srq->rq.max_sge; |
| 787 | } else |
| 788 | sz += sizeof(*qp->r_sg_list) * |
| 789 | init_attr->cap.max_recv_sge; |
| 790 | qp = kmalloc(sz, GFP_KERNEL); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 791 | if (!qp) { |
| 792 | ret = ERR_PTR(-ENOMEM); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 793 | goto bail_swq; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 794 | } |
Bryan O'Sullivan | 357b552 | 2006-07-01 04:36:16 -0700 | [diff] [blame] | 795 | if (init_attr->srq) { |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 796 | sz = 0; |
Bryan O'Sullivan | 357b552 | 2006-07-01 04:36:16 -0700 | [diff] [blame] | 797 | qp->r_rq.size = 0; |
| 798 | qp->r_rq.max_sge = 0; |
| 799 | qp->r_rq.wq = NULL; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 800 | init_attr->cap.max_recv_wr = 0; |
| 801 | init_attr->cap.max_recv_sge = 0; |
Bryan O'Sullivan | 357b552 | 2006-07-01 04:36:16 -0700 | [diff] [blame] | 802 | } else { |
| 803 | qp->r_rq.size = init_attr->cap.max_recv_wr + 1; |
| 804 | qp->r_rq.max_sge = init_attr->cap.max_recv_sge; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 805 | sz = (sizeof(struct ib_sge) * qp->r_rq.max_sge) + |
Bryan O'Sullivan | 357b552 | 2006-07-01 04:36:16 -0700 | [diff] [blame] | 806 | sizeof(struct ipath_rwqe); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 807 | qp->r_rq.wq = vmalloc_user(sizeof(struct ipath_rwq) + |
| 808 | qp->r_rq.size * sz); |
Bryan O'Sullivan | 357b552 | 2006-07-01 04:36:16 -0700 | [diff] [blame] | 809 | if (!qp->r_rq.wq) { |
Bryan O'Sullivan | 357b552 | 2006-07-01 04:36:16 -0700 | [diff] [blame] | 810 | ret = ERR_PTR(-ENOMEM); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 811 | goto bail_qp; |
Bryan O'Sullivan | 357b552 | 2006-07-01 04:36:16 -0700 | [diff] [blame] | 812 | } |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /* |
| 816 | * ib_create_qp() will initialize qp->ibqp |
| 817 | * except for qp->ibqp.qp_num. |
| 818 | */ |
| 819 | spin_lock_init(&qp->s_lock); |
| 820 | spin_lock_init(&qp->r_rq.lock); |
| 821 | atomic_set(&qp->refcount, 0); |
| 822 | init_waitqueue_head(&qp->wait); |
Ralph Campbell | 4ee9718 | 2007-07-25 11:08:28 -0700 | [diff] [blame] | 823 | tasklet_init(&qp->s_task, ipath_do_send, (unsigned long)qp); |
Bryan O'Sullivan | 94b8d9f | 2006-05-23 11:32:32 -0700 | [diff] [blame] | 824 | INIT_LIST_HEAD(&qp->piowait); |
| 825 | INIT_LIST_HEAD(&qp->timerwait); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 826 | qp->state = IB_QPS_RESET; |
| 827 | qp->s_wq = swq; |
| 828 | qp->s_size = init_attr->cap.max_send_wr + 1; |
| 829 | qp->s_max_sge = init_attr->cap.max_send_sge; |
Bryan O'Sullivan | a78aa6f | 2006-08-25 11:24:44 -0700 | [diff] [blame] | 830 | if (init_attr->sq_sig_type == IB_SIGNAL_REQ_WR) |
Ralph Campbell | 3859e39 | 2007-03-15 14:44:51 -0700 | [diff] [blame] | 831 | qp->s_flags = IPATH_S_SIGNAL_REQ_WR; |
Bryan O'Sullivan | a78aa6f | 2006-08-25 11:24:44 -0700 | [diff] [blame] | 832 | else |
| 833 | qp->s_flags = 0; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 834 | dev = to_idev(ibpd->device); |
| 835 | err = ipath_alloc_qpn(&dev->qp_table, qp, |
| 836 | init_attr->qp_type); |
| 837 | if (err) { |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 838 | ret = ERR_PTR(err); |
Ralph Campbell | 8a278e6d5 | 2007-11-14 12:09:05 -0800 | [diff] [blame] | 839 | vfree(qp->r_rq.wq); |
| 840 | goto bail_qp; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 841 | } |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 842 | qp->ip = NULL; |
Patrick Marchand Latifi | 4cd5060 | 2008-01-18 20:10:48 -0800 | [diff] [blame] | 843 | ipath_reset_qp(qp, init_attr->qp_type); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 844 | break; |
| 845 | |
| 846 | default: |
| 847 | /* Don't support raw QPs */ |
| 848 | ret = ERR_PTR(-ENOSYS); |
| 849 | goto bail; |
| 850 | } |
| 851 | |
| 852 | init_attr->cap.max_inline_data = 0; |
| 853 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 854 | /* |
| 855 | * Return the address of the RWQ as the offset to mmap. |
| 856 | * See ipath_mmap() for details. |
| 857 | */ |
| 858 | if (udata && udata->outlen >= sizeof(__u64)) { |
Robert Walsh | 6b66b2da | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 859 | if (!qp->r_rq.wq) { |
| 860 | __u64 offset = 0; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 861 | |
Robert Walsh | 6b66b2da | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 862 | err = ib_copy_to_udata(udata, &offset, |
| 863 | sizeof(offset)); |
| 864 | if (err) { |
| 865 | ret = ERR_PTR(err); |
Ralph Campbell | 8a278e6d5 | 2007-11-14 12:09:05 -0800 | [diff] [blame] | 866 | goto bail_ip; |
Robert Walsh | 6b66b2da | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 867 | } |
| 868 | } else { |
| 869 | u32 s = sizeof(struct ipath_rwq) + |
| 870 | qp->r_rq.size * sz; |
| 871 | |
| 872 | qp->ip = |
| 873 | ipath_create_mmap_info(dev, s, |
| 874 | ibpd->uobject->context, |
| 875 | qp->r_rq.wq); |
| 876 | if (!qp->ip) { |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 877 | ret = ERR_PTR(-ENOMEM); |
Ralph Campbell | 8a278e6d5 | 2007-11-14 12:09:05 -0800 | [diff] [blame] | 878 | goto bail_ip; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 879 | } |
Robert Walsh | 6b66b2da | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 880 | |
| 881 | err = ib_copy_to_udata(udata, &(qp->ip->offset), |
| 882 | sizeof(qp->ip->offset)); |
| 883 | if (err) { |
| 884 | ret = ERR_PTR(err); |
| 885 | goto bail_ip; |
| 886 | } |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | |
Bryan O'Sullivan | 0b81e4f | 2006-08-25 11:24:43 -0700 | [diff] [blame] | 890 | spin_lock(&dev->n_qps_lock); |
| 891 | if (dev->n_qps_allocated == ib_ipath_max_qps) { |
| 892 | spin_unlock(&dev->n_qps_lock); |
| 893 | ret = ERR_PTR(-ENOMEM); |
| 894 | goto bail_ip; |
| 895 | } |
| 896 | |
| 897 | dev->n_qps_allocated++; |
| 898 | spin_unlock(&dev->n_qps_lock); |
| 899 | |
Robert Walsh | 6b66b2da | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 900 | if (qp->ip) { |
| 901 | spin_lock_irq(&dev->pending_lock); |
| 902 | list_add(&qp->ip->pending_mmaps, &dev->pending_mmaps); |
| 903 | spin_unlock_irq(&dev->pending_lock); |
| 904 | } |
| 905 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 906 | ret = &qp->ibqp; |
| 907 | goto bail; |
| 908 | |
Bryan O'Sullivan | 0b81e4f | 2006-08-25 11:24:43 -0700 | [diff] [blame] | 909 | bail_ip: |
Ralph Campbell | 8a278e6d5 | 2007-11-14 12:09:05 -0800 | [diff] [blame] | 910 | if (qp->ip) |
| 911 | kref_put(&qp->ip->ref, ipath_release_mmap_info); |
| 912 | else |
| 913 | vfree(qp->r_rq.wq); |
| 914 | ipath_free_qp(&dev->qp_table, qp); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 915 | bail_qp: |
| 916 | kfree(qp); |
| 917 | bail_swq: |
| 918 | vfree(swq); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 919 | bail: |
| 920 | return ret; |
| 921 | } |
| 922 | |
| 923 | /** |
| 924 | * ipath_destroy_qp - destroy a queue pair |
| 925 | * @ibqp: the queue pair to destroy |
| 926 | * |
| 927 | * Returns 0 on success. |
| 928 | * |
| 929 | * Note that this can be called while the QP is actively sending or |
| 930 | * receiving! |
| 931 | */ |
| 932 | int ipath_destroy_qp(struct ib_qp *ibqp) |
| 933 | { |
| 934 | struct ipath_qp *qp = to_iqp(ibqp); |
| 935 | struct ipath_ibdev *dev = to_idev(ibqp->device); |
| 936 | unsigned long flags; |
| 937 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 938 | spin_lock_irqsave(&qp->s_lock, flags); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 939 | qp->state = IB_QPS_ERR; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 940 | spin_unlock_irqrestore(&qp->s_lock, flags); |
Bryan O'Sullivan | 0b81e4f | 2006-08-25 11:24:43 -0700 | [diff] [blame] | 941 | spin_lock(&dev->n_qps_lock); |
| 942 | dev->n_qps_allocated--; |
| 943 | spin_unlock(&dev->n_qps_lock); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 944 | |
| 945 | /* Stop the sending tasklet. */ |
| 946 | tasklet_kill(&qp->s_task); |
| 947 | |
| 948 | /* Make sure the QP isn't on the timeout list. */ |
| 949 | spin_lock_irqsave(&dev->pending_lock, flags); |
Bryan O'Sullivan | 94b8d9f | 2006-05-23 11:32:32 -0700 | [diff] [blame] | 950 | if (!list_empty(&qp->timerwait)) |
| 951 | list_del_init(&qp->timerwait); |
| 952 | if (!list_empty(&qp->piowait)) |
| 953 | list_del_init(&qp->piowait); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 954 | spin_unlock_irqrestore(&dev->pending_lock, flags); |
| 955 | |
| 956 | /* |
| 957 | * Make sure that the QP is not in the QPN table so receive |
| 958 | * interrupts will discard packets for this QP. XXX Also remove QP |
| 959 | * from multicast table. |
| 960 | */ |
| 961 | if (atomic_read(&qp->refcount) != 0) |
| 962 | ipath_free_qp(&dev->qp_table, qp); |
| 963 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 964 | if (qp->ip) |
| 965 | kref_put(&qp->ip->ref, ipath_release_mmap_info); |
| 966 | else |
| 967 | vfree(qp->r_rq.wq); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 968 | vfree(qp->s_wq); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 969 | kfree(qp); |
| 970 | return 0; |
| 971 | } |
| 972 | |
| 973 | /** |
| 974 | * ipath_init_qp_table - initialize the QP table for a device |
| 975 | * @idev: the device who's QP table we're initializing |
| 976 | * @size: the size of the QP table |
| 977 | * |
| 978 | * Returns 0 on success, otherwise returns an errno. |
| 979 | */ |
| 980 | int ipath_init_qp_table(struct ipath_ibdev *idev, int size) |
| 981 | { |
| 982 | int i; |
| 983 | int ret; |
| 984 | |
| 985 | idev->qp_table.last = 1; /* QPN 0 and 1 are special. */ |
| 986 | idev->qp_table.max = size; |
| 987 | idev->qp_table.nmaps = 1; |
| 988 | idev->qp_table.table = kzalloc(size * sizeof(*idev->qp_table.table), |
| 989 | GFP_KERNEL); |
| 990 | if (idev->qp_table.table == NULL) { |
| 991 | ret = -ENOMEM; |
| 992 | goto bail; |
| 993 | } |
| 994 | |
| 995 | for (i = 0; i < ARRAY_SIZE(idev->qp_table.map); i++) { |
| 996 | atomic_set(&idev->qp_table.map[i].n_free, BITS_PER_PAGE); |
| 997 | idev->qp_table.map[i].page = NULL; |
| 998 | } |
| 999 | |
| 1000 | ret = 0; |
| 1001 | |
| 1002 | bail: |
| 1003 | return ret; |
| 1004 | } |
| 1005 | |
| 1006 | /** |
| 1007 | * ipath_sqerror_qp - put a QP's send queue into an error state |
| 1008 | * @qp: QP who's send queue will be put into an error state |
| 1009 | * @wc: the WC responsible for putting the QP in this state |
| 1010 | * |
| 1011 | * Flushes the send work queue. |
Ralph Campbell | 0434d27 | 2007-03-15 14:44:53 -0700 | [diff] [blame] | 1012 | * The QP s_lock should be held and interrupts disabled. |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1013 | */ |
| 1014 | |
| 1015 | void ipath_sqerror_qp(struct ipath_qp *qp, struct ib_wc *wc) |
| 1016 | { |
| 1017 | struct ipath_ibdev *dev = to_idev(qp->ibqp.device); |
| 1018 | struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last); |
| 1019 | |
Bryan O'Sullivan | 39c0d0b | 2007-03-15 14:44:52 -0700 | [diff] [blame] | 1020 | ipath_dbg("Send queue error on QP%d/%d: err: %d\n", |
Bryan O'Sullivan | b55f4f0 | 2006-08-25 11:24:33 -0700 | [diff] [blame] | 1021 | qp->ibqp.qp_num, qp->remote_qpn, wc->status); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1022 | |
| 1023 | spin_lock(&dev->pending_lock); |
| 1024 | /* XXX What if its already removed by the timeout code? */ |
Bryan O'Sullivan | 94b8d9f | 2006-05-23 11:32:32 -0700 | [diff] [blame] | 1025 | if (!list_empty(&qp->timerwait)) |
| 1026 | list_del_init(&qp->timerwait); |
| 1027 | if (!list_empty(&qp->piowait)) |
| 1028 | list_del_init(&qp->piowait); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1029 | spin_unlock(&dev->pending_lock); |
| 1030 | |
| 1031 | ipath_cq_enter(to_icq(qp->ibqp.send_cq), wc, 1); |
| 1032 | if (++qp->s_last >= qp->s_size) |
| 1033 | qp->s_last = 0; |
| 1034 | |
| 1035 | wc->status = IB_WC_WR_FLUSH_ERR; |
| 1036 | |
| 1037 | while (qp->s_last != qp->s_head) { |
Ralph Campbell | 0434d27 | 2007-03-15 14:44:53 -0700 | [diff] [blame] | 1038 | wqe = get_swqe_ptr(qp, qp->s_last); |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1039 | wc->wr_id = wqe->wr.wr_id; |
| 1040 | wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode]; |
| 1041 | ipath_cq_enter(to_icq(qp->ibqp.send_cq), wc, 1); |
| 1042 | if (++qp->s_last >= qp->s_size) |
| 1043 | qp->s_last = 0; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1044 | } |
| 1045 | qp->s_cur = qp->s_tail = qp->s_head; |
| 1046 | qp->state = IB_QPS_SQE; |
| 1047 | } |
| 1048 | |
| 1049 | /** |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1050 | * ipath_get_credit - flush the send work queue of a QP |
| 1051 | * @qp: the qp who's send work queue to flush |
| 1052 | * @aeth: the Acknowledge Extended Transport Header |
| 1053 | * |
| 1054 | * The QP s_lock should be held. |
| 1055 | */ |
| 1056 | void ipath_get_credit(struct ipath_qp *qp, u32 aeth) |
| 1057 | { |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 1058 | u32 credit = (aeth >> IPATH_AETH_CREDIT_SHIFT) & IPATH_AETH_CREDIT_MASK; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1059 | |
| 1060 | /* |
| 1061 | * If the credit is invalid, we can send |
| 1062 | * as many packets as we like. Otherwise, we have to |
| 1063 | * honor the credit field. |
| 1064 | */ |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 1065 | if (credit == IPATH_AETH_CREDIT_INVAL) |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1066 | qp->s_lsn = (u32) -1; |
Bryan O'Sullivan | ddd4bb2 | 2006-07-01 04:35:50 -0700 | [diff] [blame] | 1067 | else if (qp->s_lsn != (u32) -1) { |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1068 | /* Compute new LSN (i.e., MSN + credit) */ |
Bryan O'Sullivan | 27b678d | 2006-07-01 04:36:17 -0700 | [diff] [blame] | 1069 | credit = (aeth + credit_table[credit]) & IPATH_MSN_MASK; |
Bryan O'Sullivan | e28c00a | 2006-03-29 15:23:37 -0800 | [diff] [blame] | 1070 | if (ipath_cmp24(credit, qp->s_lsn) > 0) |
| 1071 | qp->s_lsn = credit; |
| 1072 | } |
| 1073 | |
| 1074 | /* Restart sending if it was blocked due to lack of credits. */ |
| 1075 | if (qp->s_cur != qp->s_head && |
| 1076 | (qp->s_lsn == (u32) -1 || |
| 1077 | ipath_cmp24(get_swqe_ptr(qp, qp->s_cur)->ssn, |
| 1078 | qp->s_lsn + 1) <= 0)) |
| 1079 | tasklet_hi_schedule(&qp->s_task); |
| 1080 | } |