Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 1 | /* |
Bryan O'Sullivan | 759d576 | 2006-07-01 04:35:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2006 QLogic, Inc. All rights reserved. |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -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" |
| 38 | |
| 39 | /** |
| 40 | * ipath_cq_enter - add a new entry to the completion queue |
| 41 | * @cq: completion queue |
| 42 | * @entry: work completion entry to add |
| 43 | * @sig: true if @entry is a solicitated entry |
| 44 | * |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 45 | * This may be called with qp->s_lock held. |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 46 | */ |
| 47 | void ipath_cq_enter(struct ipath_cq *cq, struct ib_wc *entry, int solicited) |
| 48 | { |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 49 | struct ipath_cq_wc *wc; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 50 | unsigned long flags; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 51 | u32 head; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 52 | u32 next; |
| 53 | |
| 54 | spin_lock_irqsave(&cq->lock, flags); |
| 55 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 56 | /* |
| 57 | * Note that the head pointer might be writable by user processes. |
| 58 | * Take care to verify it is a sane value. |
| 59 | */ |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 60 | wc = cq->queue; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 61 | head = wc->head; |
| 62 | if (head >= (unsigned) cq->ibcq.cqe) { |
| 63 | head = cq->ibcq.cqe; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 64 | next = 0; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 65 | } else |
| 66 | next = head + 1; |
| 67 | if (unlikely(next == wc->tail)) { |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 68 | spin_unlock_irqrestore(&cq->lock, flags); |
| 69 | if (cq->ibcq.event_handler) { |
| 70 | struct ib_event ev; |
| 71 | |
| 72 | ev.device = cq->ibcq.device; |
| 73 | ev.element.cq = &cq->ibcq; |
| 74 | ev.event = IB_EVENT_CQ_ERR; |
| 75 | cq->ibcq.event_handler(&ev, cq->ibcq.cq_context); |
| 76 | } |
| 77 | return; |
| 78 | } |
Robert Walsh | 40b9043 | 2007-03-15 14:45:17 -0700 | [diff] [blame] | 79 | wc->queue[head].wr_id = entry->wr_id; |
| 80 | wc->queue[head].status = entry->status; |
| 81 | wc->queue[head].opcode = entry->opcode; |
| 82 | wc->queue[head].vendor_err = entry->vendor_err; |
| 83 | wc->queue[head].byte_len = entry->byte_len; |
| 84 | wc->queue[head].imm_data = (__u32 __force)entry->imm_data; |
| 85 | wc->queue[head].qp_num = entry->qp->qp_num; |
| 86 | wc->queue[head].src_qp = entry->src_qp; |
| 87 | wc->queue[head].wc_flags = entry->wc_flags; |
| 88 | wc->queue[head].pkey_index = entry->pkey_index; |
| 89 | wc->queue[head].slid = entry->slid; |
| 90 | wc->queue[head].sl = entry->sl; |
| 91 | wc->queue[head].dlid_path_bits = entry->dlid_path_bits; |
| 92 | wc->queue[head].port_num = entry->port_num; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 93 | wc->head = next; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 94 | |
| 95 | if (cq->notify == IB_CQ_NEXT_COMP || |
| 96 | (cq->notify == IB_CQ_SOLICITED && solicited)) { |
| 97 | cq->notify = IB_CQ_NONE; |
| 98 | cq->triggered++; |
| 99 | /* |
| 100 | * This will cause send_complete() to be called in |
| 101 | * another thread. |
| 102 | */ |
| 103 | tasklet_hi_schedule(&cq->comptask); |
| 104 | } |
| 105 | |
| 106 | spin_unlock_irqrestore(&cq->lock, flags); |
| 107 | |
| 108 | if (entry->status != IB_WC_SUCCESS) |
| 109 | to_idev(cq->ibcq.device)->n_wqe_errs++; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * ipath_poll_cq - poll for work completion entries |
| 114 | * @ibcq: the completion queue to poll |
| 115 | * @num_entries: the maximum number of entries to return |
| 116 | * @entry: pointer to array where work completions are placed |
| 117 | * |
| 118 | * Returns the number of completion entries polled. |
| 119 | * |
| 120 | * This may be called from interrupt context. Also called by ib_poll_cq() |
| 121 | * in the generic verbs code. |
| 122 | */ |
| 123 | int ipath_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry) |
| 124 | { |
| 125 | struct ipath_cq *cq = to_icq(ibcq); |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 126 | struct ipath_cq_wc *wc; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 127 | unsigned long flags; |
| 128 | int npolled; |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 129 | u32 tail; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 130 | |
| 131 | spin_lock_irqsave(&cq->lock, flags); |
| 132 | |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 133 | wc = cq->queue; |
| 134 | tail = wc->tail; |
| 135 | if (tail > (u32) cq->ibcq.cqe) |
| 136 | tail = (u32) cq->ibcq.cqe; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 137 | for (npolled = 0; npolled < num_entries; ++npolled, ++entry) { |
Robert Walsh | 40b9043 | 2007-03-15 14:45:17 -0700 | [diff] [blame] | 138 | struct ipath_qp *qp; |
| 139 | |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 140 | if (tail == wc->head) |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 141 | break; |
Robert Walsh | 40b9043 | 2007-03-15 14:45:17 -0700 | [diff] [blame] | 142 | |
| 143 | qp = ipath_lookup_qpn(&to_idev(cq->ibcq.device)->qp_table, |
| 144 | wc->queue[tail].qp_num); |
| 145 | entry->qp = &qp->ibqp; |
| 146 | if (atomic_dec_and_test(&qp->refcount)) |
| 147 | wake_up(&qp->wait); |
| 148 | |
| 149 | entry->wr_id = wc->queue[tail].wr_id; |
| 150 | entry->status = wc->queue[tail].status; |
| 151 | entry->opcode = wc->queue[tail].opcode; |
| 152 | entry->vendor_err = wc->queue[tail].vendor_err; |
| 153 | entry->byte_len = wc->queue[tail].byte_len; |
| 154 | entry->imm_data = wc->queue[tail].imm_data; |
| 155 | entry->src_qp = wc->queue[tail].src_qp; |
| 156 | entry->wc_flags = wc->queue[tail].wc_flags; |
| 157 | entry->pkey_index = wc->queue[tail].pkey_index; |
| 158 | entry->slid = wc->queue[tail].slid; |
| 159 | entry->sl = wc->queue[tail].sl; |
| 160 | entry->dlid_path_bits = wc->queue[tail].dlid_path_bits; |
| 161 | entry->port_num = wc->queue[tail].port_num; |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 162 | if (tail >= cq->ibcq.cqe) |
| 163 | tail = 0; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 164 | else |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 165 | tail++; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 166 | } |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 167 | wc->tail = tail; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 168 | |
| 169 | spin_unlock_irqrestore(&cq->lock, flags); |
| 170 | |
| 171 | return npolled; |
| 172 | } |
| 173 | |
| 174 | static void send_complete(unsigned long data) |
| 175 | { |
| 176 | struct ipath_cq *cq = (struct ipath_cq *)data; |
| 177 | |
| 178 | /* |
| 179 | * The completion handler will most likely rearm the notification |
| 180 | * and poll for all pending entries. If a new completion entry |
| 181 | * is added while we are in this routine, tasklet_hi_schedule() |
| 182 | * won't call us again until we return so we check triggered to |
| 183 | * see if we need to call the handler again. |
| 184 | */ |
| 185 | for (;;) { |
| 186 | u8 triggered = cq->triggered; |
| 187 | |
| 188 | cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context); |
| 189 | |
| 190 | if (cq->triggered == triggered) |
| 191 | return; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * ipath_create_cq - create a completion queue |
| 197 | * @ibdev: the device this completion queue is attached to |
| 198 | * @entries: the minimum size of the completion queue |
| 199 | * @context: unused by the InfiniPath driver |
| 200 | * @udata: unused by the InfiniPath driver |
| 201 | * |
| 202 | * Returns a pointer to the completion queue or negative errno values |
| 203 | * for failure. |
| 204 | * |
| 205 | * Called by ib_create_cq() in the generic verbs code. |
| 206 | */ |
| 207 | struct ib_cq *ipath_create_cq(struct ib_device *ibdev, int entries, |
| 208 | struct ib_ucontext *context, |
| 209 | struct ib_udata *udata) |
| 210 | { |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 211 | struct ipath_ibdev *dev = to_idev(ibdev); |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 212 | struct ipath_cq *cq; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 213 | struct ipath_cq_wc *wc; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 214 | struct ib_cq *ret; |
| 215 | |
Bryan O'Sullivan | eae33d4 | 2006-08-25 11:24:37 -0700 | [diff] [blame] | 216 | if (entries < 1 || entries > ib_ipath_max_cqes) { |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 217 | ret = ERR_PTR(-EINVAL); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 218 | goto done; |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 221 | /* Allocate the completion queue structure. */ |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 222 | cq = kmalloc(sizeof(*cq), GFP_KERNEL); |
| 223 | if (!cq) { |
| 224 | ret = ERR_PTR(-ENOMEM); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 225 | goto done; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 229 | * Allocate the completion queue entries and head/tail pointers. |
| 230 | * This is allocated separately so that it can be resized and |
| 231 | * also mapped into user space. |
| 232 | * We need to use vmalloc() in order to support mmap and large |
| 233 | * numbers of entries. |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 234 | */ |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 235 | wc = vmalloc_user(sizeof(*wc) + sizeof(struct ib_wc) * entries); |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 236 | if (!wc) { |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 237 | ret = ERR_PTR(-ENOMEM); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 238 | goto bail_cq; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 239 | } |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 240 | |
| 241 | /* |
| 242 | * Return the address of the WC as the offset to mmap. |
| 243 | * See ipath_mmap() for details. |
| 244 | */ |
| 245 | if (udata && udata->outlen >= sizeof(__u64)) { |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 246 | int err; |
Robert Walsh | 6b66b2d | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 247 | u32 s = sizeof *wc + sizeof(struct ib_wc) * entries; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 248 | |
Robert Walsh | 6b66b2d | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 249 | cq->ip = ipath_create_mmap_info(dev, s, context, wc); |
| 250 | if (!cq->ip) { |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 251 | ret = ERR_PTR(-ENOMEM); |
| 252 | goto bail_wc; |
| 253 | } |
Robert Walsh | 6b66b2d | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 254 | |
| 255 | err = ib_copy_to_udata(udata, &cq->ip->offset, |
| 256 | sizeof(cq->ip->offset)); |
| 257 | if (err) { |
| 258 | ret = ERR_PTR(err); |
| 259 | goto bail_ip; |
| 260 | } |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 261 | } else |
| 262 | cq->ip = NULL; |
| 263 | |
Bryan O'Sullivan | aa4eaed | 2006-09-28 09:00:03 -0700 | [diff] [blame] | 264 | spin_lock(&dev->n_cqs_lock); |
| 265 | if (dev->n_cqs_allocated == ib_ipath_max_cqs) { |
| 266 | spin_unlock(&dev->n_cqs_lock); |
| 267 | ret = ERR_PTR(-ENOMEM); |
Robert Walsh | 6b66b2d | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 268 | goto bail_ip; |
Bryan O'Sullivan | aa4eaed | 2006-09-28 09:00:03 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | dev->n_cqs_allocated++; |
| 272 | spin_unlock(&dev->n_cqs_lock); |
| 273 | |
Robert Walsh | 6b66b2d | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 274 | if (cq->ip) { |
| 275 | spin_lock_irq(&dev->pending_lock); |
| 276 | list_add(&cq->ip->pending_mmaps, &dev->pending_mmaps); |
| 277 | spin_unlock_irq(&dev->pending_lock); |
| 278 | } |
| 279 | |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 280 | /* |
| 281 | * ib_create_cq() will initialize cq->ibcq except for cq->ibcq.cqe. |
| 282 | * The number of entries should be >= the number requested or return |
| 283 | * an error. |
| 284 | */ |
| 285 | cq->ibcq.cqe = entries; |
| 286 | cq->notify = IB_CQ_NONE; |
| 287 | cq->triggered = 0; |
| 288 | spin_lock_init(&cq->lock); |
| 289 | tasklet_init(&cq->comptask, send_complete, (unsigned long)cq); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 290 | wc->head = 0; |
| 291 | wc->tail = 0; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 292 | cq->queue = wc; |
| 293 | |
| 294 | ret = &cq->ibcq; |
| 295 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 296 | goto done; |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 297 | |
Robert Walsh | 6b66b2d | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 298 | bail_ip: |
| 299 | kfree(cq->ip); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 300 | bail_wc: |
| 301 | vfree(wc); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 302 | bail_cq: |
| 303 | kfree(cq); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 304 | done: |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * ipath_destroy_cq - destroy a completion queue |
| 310 | * @ibcq: the completion queue to destroy. |
| 311 | * |
| 312 | * Returns 0 for success. |
| 313 | * |
| 314 | * Called by ib_destroy_cq() in the generic verbs code. |
| 315 | */ |
| 316 | int ipath_destroy_cq(struct ib_cq *ibcq) |
| 317 | { |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 318 | struct ipath_ibdev *dev = to_idev(ibcq->device); |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 319 | struct ipath_cq *cq = to_icq(ibcq); |
| 320 | |
| 321 | tasklet_kill(&cq->comptask); |
Bryan O'Sullivan | aa4eaed | 2006-09-28 09:00:03 -0700 | [diff] [blame] | 322 | spin_lock(&dev->n_cqs_lock); |
Bryan O'Sullivan | fe62546 | 2006-07-01 04:35:58 -0700 | [diff] [blame] | 323 | dev->n_cqs_allocated--; |
Bryan O'Sullivan | aa4eaed | 2006-09-28 09:00:03 -0700 | [diff] [blame] | 324 | spin_unlock(&dev->n_cqs_lock); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 325 | if (cq->ip) |
| 326 | kref_put(&cq->ip->ref, ipath_release_mmap_info); |
| 327 | else |
| 328 | vfree(cq->queue); |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 329 | kfree(cq); |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * ipath_req_notify_cq - change the notification type for a completion queue |
| 336 | * @ibcq: the completion queue |
| 337 | * @notify: the type of notification to request |
| 338 | * |
| 339 | * Returns 0 for success. |
| 340 | * |
| 341 | * This may be called from interrupt context. Also called by |
| 342 | * ib_req_notify_cq() in the generic verbs code. |
| 343 | */ |
| 344 | int ipath_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify notify) |
| 345 | { |
| 346 | struct ipath_cq *cq = to_icq(ibcq); |
| 347 | unsigned long flags; |
| 348 | |
| 349 | spin_lock_irqsave(&cq->lock, flags); |
| 350 | /* |
| 351 | * Don't change IB_CQ_NEXT_COMP to IB_CQ_SOLICITED but allow |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 352 | * any other transitions (see C11-31 and C11-32 in ch. 11.4.2.2). |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 353 | */ |
| 354 | if (cq->notify != IB_CQ_NEXT_COMP) |
| 355 | cq->notify = notify; |
| 356 | spin_unlock_irqrestore(&cq->lock, flags); |
| 357 | return 0; |
| 358 | } |
| 359 | |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 360 | /** |
| 361 | * ipath_resize_cq - change the size of the CQ |
| 362 | * @ibcq: the completion queue |
| 363 | * |
| 364 | * Returns 0 for success. |
| 365 | */ |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 366 | int ipath_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata) |
| 367 | { |
| 368 | struct ipath_cq *cq = to_icq(ibcq); |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 369 | struct ipath_cq_wc *old_wc; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 370 | struct ipath_cq_wc *wc; |
| 371 | u32 head, tail, n; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 372 | int ret; |
| 373 | |
Bryan O'Sullivan | eae33d4 | 2006-08-25 11:24:37 -0700 | [diff] [blame] | 374 | if (cqe < 1 || cqe > ib_ipath_max_cqes) { |
| 375 | ret = -EINVAL; |
| 376 | goto bail; |
| 377 | } |
| 378 | |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 379 | /* |
| 380 | * Need to use vmalloc() if we want to support large #s of entries. |
| 381 | */ |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 382 | wc = vmalloc_user(sizeof(*wc) + sizeof(struct ib_wc) * cqe); |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 383 | if (!wc) { |
| 384 | ret = -ENOMEM; |
| 385 | goto bail; |
| 386 | } |
| 387 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 388 | /* |
| 389 | * Return the address of the WC as the offset to mmap. |
| 390 | * See ipath_mmap() for details. |
| 391 | */ |
| 392 | if (udata && udata->outlen >= sizeof(__u64)) { |
| 393 | __u64 offset = (__u64) wc; |
| 394 | |
| 395 | ret = ib_copy_to_udata(udata, &offset, sizeof(offset)); |
| 396 | if (ret) |
| 397 | goto bail; |
| 398 | } |
| 399 | |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 400 | spin_lock_irq(&cq->lock); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 401 | /* |
| 402 | * Make sure head and tail are sane since they |
| 403 | * might be user writable. |
| 404 | */ |
Bryan O'Sullivan | 7a26c47 | 2006-09-28 09:00:23 -0700 | [diff] [blame] | 405 | old_wc = cq->queue; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 406 | head = old_wc->head; |
| 407 | if (head > (u32) cq->ibcq.cqe) |
| 408 | head = (u32) cq->ibcq.cqe; |
| 409 | tail = old_wc->tail; |
| 410 | if (tail > (u32) cq->ibcq.cqe) |
| 411 | tail = (u32) cq->ibcq.cqe; |
| 412 | if (head < tail) |
| 413 | n = cq->ibcq.cqe + 1 + head - tail; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 414 | else |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 415 | n = head - tail; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 416 | if (unlikely((u32)cqe < n)) { |
| 417 | spin_unlock_irq(&cq->lock); |
| 418 | vfree(wc); |
| 419 | ret = -EOVERFLOW; |
| 420 | goto bail; |
| 421 | } |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 422 | for (n = 0; tail != head; n++) { |
| 423 | wc->queue[n] = old_wc->queue[tail]; |
| 424 | if (tail == (u32) cq->ibcq.cqe) |
| 425 | tail = 0; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 426 | else |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 427 | tail++; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 428 | } |
| 429 | cq->ibcq.cqe = cqe; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 430 | wc->head = n; |
| 431 | wc->tail = 0; |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 432 | cq->queue = wc; |
| 433 | spin_unlock_irq(&cq->lock); |
| 434 | |
| 435 | vfree(old_wc); |
| 436 | |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 437 | if (cq->ip) { |
| 438 | struct ipath_ibdev *dev = to_idev(ibcq->device); |
| 439 | struct ipath_mmap_info *ip = cq->ip; |
Robert Walsh | 6b66b2d | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 440 | u32 s = sizeof *wc + sizeof(struct ib_wc) * cqe; |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 441 | |
Robert Walsh | 6b66b2d | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 442 | ipath_update_mmap_info(dev, ip, s, wc); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 443 | spin_lock_irq(&dev->pending_lock); |
Robert Walsh | 6b66b2d | 2007-04-27 21:07:23 -0700 | [diff] [blame] | 444 | if (list_empty(&ip->pending_mmaps)) |
| 445 | list_add(&ip->pending_mmaps, &dev->pending_mmaps); |
Ralph Campbell | 373d991 | 2006-09-22 15:22:26 -0700 | [diff] [blame] | 446 | spin_unlock_irq(&dev->pending_lock); |
| 447 | } |
| 448 | |
Bryan O'Sullivan | cef1cce | 2006-03-29 15:23:36 -0800 | [diff] [blame] | 449 | ret = 0; |
| 450 | |
| 451 | bail: |
| 452 | return ret; |
| 453 | } |