Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006 Chelsio, Inc. All rights reserved. |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | #include <asm/delay.h> |
| 33 | |
| 34 | #include <linux/mutex.h> |
| 35 | #include <linux/netdevice.h> |
| 36 | #include <linux/sched.h> |
| 37 | #include <linux/spinlock.h> |
| 38 | #include <linux/pci.h> |
David Miller | c3bb109 | 2007-03-05 15:21:29 -0800 | [diff] [blame] | 39 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 40 | #include <linux/slab.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 41 | #include <net/net_namespace.h> |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 42 | |
| 43 | #include "cxio_resource.h" |
| 44 | #include "cxio_hal.h" |
| 45 | #include "cxgb3_offload.h" |
| 46 | #include "sge_defs.h" |
| 47 | |
| 48 | static LIST_HEAD(rdev_list); |
| 49 | static cxio_hal_ev_callback_func_t cxio_ev_cb = NULL; |
| 50 | |
Adrian Bunk | 2b54035 | 2007-02-21 11:52:49 +0100 | [diff] [blame] | 51 | static struct cxio_rdev *cxio_hal_find_rdev_by_name(char *dev_name) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 52 | { |
| 53 | struct cxio_rdev *rdev; |
| 54 | |
| 55 | list_for_each_entry(rdev, &rdev_list, entry) |
| 56 | if (!strcmp(rdev->dev_name, dev_name)) |
| 57 | return rdev; |
| 58 | return NULL; |
| 59 | } |
| 60 | |
Adrian Bunk | 2b54035 | 2007-02-21 11:52:49 +0100 | [diff] [blame] | 61 | static struct cxio_rdev *cxio_hal_find_rdev_by_t3cdev(struct t3cdev *tdev) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 62 | { |
| 63 | struct cxio_rdev *rdev; |
| 64 | |
| 65 | list_for_each_entry(rdev, &rdev_list, entry) |
| 66 | if (rdev->t3cdev_p == tdev) |
| 67 | return rdev; |
| 68 | return NULL; |
| 69 | } |
| 70 | |
| 71 | int cxio_hal_cq_op(struct cxio_rdev *rdev_p, struct t3_cq *cq, |
| 72 | enum t3_cq_opcode op, u32 credit) |
| 73 | { |
| 74 | int ret; |
| 75 | struct t3_cqe *cqe; |
| 76 | u32 rptr; |
| 77 | |
| 78 | struct rdma_cq_op setup; |
| 79 | setup.id = cq->cqid; |
| 80 | setup.credits = (op == CQ_CREDIT_UPDATE) ? credit : 0; |
| 81 | setup.op = op; |
| 82 | ret = rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_OP, &setup); |
| 83 | |
| 84 | if ((ret < 0) || (op == CQ_CREDIT_UPDATE)) |
| 85 | return ret; |
| 86 | |
| 87 | /* |
| 88 | * If the rearm returned an index other than our current index, |
| 89 | * then there might be CQE's in flight (being DMA'd). We must wait |
| 90 | * here for them to complete or the consumer can miss a notification. |
| 91 | */ |
| 92 | if (Q_PTR2IDX((cq->rptr), cq->size_log2) != ret) { |
| 93 | int i=0; |
| 94 | |
| 95 | rptr = cq->rptr; |
| 96 | |
| 97 | /* |
| 98 | * Keep the generation correct by bumping rptr until it |
| 99 | * matches the index returned by the rearm - 1. |
| 100 | */ |
| 101 | while (Q_PTR2IDX((rptr+1), cq->size_log2) != ret) |
| 102 | rptr++; |
| 103 | |
| 104 | /* |
| 105 | * Now rptr is the index for the (last) cqe that was |
| 106 | * in-flight at the time the HW rearmed the CQ. We |
| 107 | * spin until that CQE is valid. |
| 108 | */ |
| 109 | cqe = cq->queue + Q_PTR2IDX(rptr, cq->size_log2); |
| 110 | while (!CQ_VLD_ENTRY(rptr, cq->size_log2, cqe)) { |
| 111 | udelay(1); |
| 112 | if (i++ > 1000000) { |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 113 | printk(KERN_ERR "%s: stalled rnic\n", |
| 114 | rdev_p->dev_name); |
| 115 | return -EIO; |
| 116 | } |
| 117 | } |
Roland Dreier | ed23a72 | 2007-05-06 21:02:48 -0700 | [diff] [blame] | 118 | |
| 119 | return 1; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 120 | } |
Roland Dreier | ed23a72 | 2007-05-06 21:02:48 -0700 | [diff] [blame] | 121 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | |
Adrian Bunk | 2b54035 | 2007-02-21 11:52:49 +0100 | [diff] [blame] | 125 | static int cxio_hal_clear_cq_ctx(struct cxio_rdev *rdev_p, u32 cqid) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 126 | { |
| 127 | struct rdma_cq_setup setup; |
| 128 | setup.id = cqid; |
| 129 | setup.base_addr = 0; /* NULL address */ |
| 130 | setup.size = 0; /* disaable the CQ */ |
| 131 | setup.credits = 0; |
| 132 | setup.credit_thres = 0; |
| 133 | setup.ovfl_mode = 0; |
| 134 | return (rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_SETUP, &setup)); |
| 135 | } |
| 136 | |
Adrian Bunk | 2b54035 | 2007-02-21 11:52:49 +0100 | [diff] [blame] | 137 | static int cxio_hal_clear_qp_ctx(struct cxio_rdev *rdev_p, u32 qpid) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 138 | { |
| 139 | u64 sge_cmd; |
| 140 | struct t3_modify_qp_wr *wqe; |
| 141 | struct sk_buff *skb = alloc_skb(sizeof(*wqe), GFP_KERNEL); |
| 142 | if (!skb) { |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 143 | PDBG("%s alloc_skb failed\n", __func__); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 144 | return -ENOMEM; |
| 145 | } |
| 146 | wqe = (struct t3_modify_qp_wr *) skb_put(skb, sizeof(*wqe)); |
| 147 | memset(wqe, 0, sizeof(*wqe)); |
Steve Wise | e7e5582 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 148 | build_fw_riwrh((struct fw_riwrh *) wqe, T3_WR_QP_MOD, |
| 149 | T3_COMPLETION_FLAG | T3_NOTIFY_FLAG, 0, qpid, 7, |
| 150 | T3_SOPEOP); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 151 | wqe->flags = cpu_to_be32(MODQP_WRITE_EC); |
| 152 | sge_cmd = qpid << 8 | 3; |
| 153 | wqe->sge_cmd = cpu_to_be64(sge_cmd); |
| 154 | skb->priority = CPL_PRIORITY_CONTROL; |
Steve Wise | 04b5d02 | 2009-03-30 08:37:56 -0700 | [diff] [blame] | 155 | return iwch_cxgb3_ofld_send(rdev_p->t3cdev_p, skb); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Steve Wise | 5279d3a | 2010-01-27 20:22:34 +0000 | [diff] [blame] | 158 | int cxio_create_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq, int kernel) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 159 | { |
| 160 | struct rdma_cq_setup setup; |
| 161 | int size = (1UL << (cq->size_log2)) * sizeof(struct t3_cqe); |
| 162 | |
Steve Wise | b955150 | 2010-10-21 12:37:06 +0000 | [diff] [blame^] | 163 | size += 1; /* one extra page for storing cq-in-err state */ |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 164 | cq->cqid = cxio_hal_get_cqid(rdev_p->rscp); |
| 165 | if (!cq->cqid) |
| 166 | return -ENOMEM; |
Steve Wise | 5279d3a | 2010-01-27 20:22:34 +0000 | [diff] [blame] | 167 | if (kernel) { |
| 168 | cq->sw_queue = kzalloc(size, GFP_KERNEL); |
| 169 | if (!cq->sw_queue) |
| 170 | return -ENOMEM; |
| 171 | } |
| 172 | cq->queue = dma_alloc_coherent(&(rdev_p->rnic_info.pdev->dev), size, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 173 | &(cq->dma_addr), GFP_KERNEL); |
| 174 | if (!cq->queue) { |
| 175 | kfree(cq->sw_queue); |
| 176 | return -ENOMEM; |
| 177 | } |
FUJITA Tomonori | 7960d6b | 2010-04-02 04:29:38 +0000 | [diff] [blame] | 178 | dma_unmap_addr_set(cq, mapping, cq->dma_addr); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 179 | memset(cq->queue, 0, size); |
| 180 | setup.id = cq->cqid; |
| 181 | setup.base_addr = (u64) (cq->dma_addr); |
| 182 | setup.size = 1UL << cq->size_log2; |
| 183 | setup.credits = 65535; |
| 184 | setup.credit_thres = 1; |
Steve Wise | 8176d29 | 2008-01-24 16:30:16 -0600 | [diff] [blame] | 185 | if (rdev_p->t3cdev_p->type != T3A) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 186 | setup.ovfl_mode = 0; |
| 187 | else |
| 188 | setup.ovfl_mode = 1; |
| 189 | return (rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_SETUP, &setup)); |
| 190 | } |
| 191 | |
| 192 | int cxio_resize_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq) |
| 193 | { |
| 194 | struct rdma_cq_setup setup; |
| 195 | setup.id = cq->cqid; |
| 196 | setup.base_addr = (u64) (cq->dma_addr); |
| 197 | setup.size = 1UL << cq->size_log2; |
| 198 | setup.credits = setup.size; |
| 199 | setup.credit_thres = setup.size; /* TBD: overflow recovery */ |
| 200 | setup.ovfl_mode = 1; |
| 201 | return (rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_SETUP, &setup)); |
| 202 | } |
| 203 | |
| 204 | static u32 get_qpid(struct cxio_rdev *rdev_p, struct cxio_ucontext *uctx) |
| 205 | { |
| 206 | struct cxio_qpid_list *entry; |
| 207 | u32 qpid; |
| 208 | int i; |
| 209 | |
| 210 | mutex_lock(&uctx->lock); |
| 211 | if (!list_empty(&uctx->qpids)) { |
| 212 | entry = list_entry(uctx->qpids.next, struct cxio_qpid_list, |
| 213 | entry); |
| 214 | list_del(&entry->entry); |
| 215 | qpid = entry->qpid; |
| 216 | kfree(entry); |
| 217 | } else { |
| 218 | qpid = cxio_hal_get_qpid(rdev_p->rscp); |
| 219 | if (!qpid) |
| 220 | goto out; |
| 221 | for (i = qpid+1; i & rdev_p->qpmask; i++) { |
| 222 | entry = kmalloc(sizeof *entry, GFP_KERNEL); |
| 223 | if (!entry) |
| 224 | break; |
| 225 | entry->qpid = i; |
| 226 | list_add_tail(&entry->entry, &uctx->qpids); |
| 227 | } |
| 228 | } |
| 229 | out: |
| 230 | mutex_unlock(&uctx->lock); |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 231 | PDBG("%s qpid 0x%x\n", __func__, qpid); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 232 | return qpid; |
| 233 | } |
| 234 | |
| 235 | static void put_qpid(struct cxio_rdev *rdev_p, u32 qpid, |
| 236 | struct cxio_ucontext *uctx) |
| 237 | { |
| 238 | struct cxio_qpid_list *entry; |
| 239 | |
| 240 | entry = kmalloc(sizeof *entry, GFP_KERNEL); |
| 241 | if (!entry) |
| 242 | return; |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 243 | PDBG("%s qpid 0x%x\n", __func__, qpid); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 244 | entry->qpid = qpid; |
| 245 | mutex_lock(&uctx->lock); |
| 246 | list_add_tail(&entry->entry, &uctx->qpids); |
| 247 | mutex_unlock(&uctx->lock); |
| 248 | } |
| 249 | |
| 250 | void cxio_release_ucontext(struct cxio_rdev *rdev_p, struct cxio_ucontext *uctx) |
| 251 | { |
| 252 | struct list_head *pos, *nxt; |
| 253 | struct cxio_qpid_list *entry; |
| 254 | |
| 255 | mutex_lock(&uctx->lock); |
| 256 | list_for_each_safe(pos, nxt, &uctx->qpids) { |
| 257 | entry = list_entry(pos, struct cxio_qpid_list, entry); |
| 258 | list_del_init(&entry->entry); |
| 259 | if (!(entry->qpid & rdev_p->qpmask)) |
| 260 | cxio_hal_put_qpid(rdev_p->rscp, entry->qpid); |
| 261 | kfree(entry); |
| 262 | } |
| 263 | mutex_unlock(&uctx->lock); |
| 264 | } |
| 265 | |
| 266 | void cxio_init_ucontext(struct cxio_rdev *rdev_p, struct cxio_ucontext *uctx) |
| 267 | { |
| 268 | INIT_LIST_HEAD(&uctx->qpids); |
| 269 | mutex_init(&uctx->lock); |
| 270 | } |
| 271 | |
| 272 | int cxio_create_qp(struct cxio_rdev *rdev_p, u32 kernel_domain, |
| 273 | struct t3_wq *wq, struct cxio_ucontext *uctx) |
| 274 | { |
| 275 | int depth = 1UL << wq->size_log2; |
| 276 | int rqsize = 1UL << wq->rq_size_log2; |
| 277 | |
| 278 | wq->qpid = get_qpid(rdev_p, uctx); |
| 279 | if (!wq->qpid) |
| 280 | return -ENOMEM; |
| 281 | |
Steve Wise | 4ab928f | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 282 | wq->rq = kzalloc(depth * sizeof(struct t3_swrq), GFP_KERNEL); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 283 | if (!wq->rq) |
| 284 | goto err1; |
| 285 | |
| 286 | wq->rq_addr = cxio_hal_rqtpool_alloc(rdev_p, rqsize); |
| 287 | if (!wq->rq_addr) |
| 288 | goto err2; |
| 289 | |
| 290 | wq->sq = kzalloc(depth * sizeof(struct t3_swsq), GFP_KERNEL); |
| 291 | if (!wq->sq) |
| 292 | goto err3; |
| 293 | |
| 294 | wq->queue = dma_alloc_coherent(&(rdev_p->rnic_info.pdev->dev), |
| 295 | depth * sizeof(union t3_wr), |
| 296 | &(wq->dma_addr), GFP_KERNEL); |
| 297 | if (!wq->queue) |
| 298 | goto err4; |
| 299 | |
| 300 | memset(wq->queue, 0, depth * sizeof(union t3_wr)); |
FUJITA Tomonori | 7960d6b | 2010-04-02 04:29:38 +0000 | [diff] [blame] | 301 | dma_unmap_addr_set(wq, mapping, wq->dma_addr); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 302 | wq->doorbell = (void __iomem *)rdev_p->rnic_info.kdb_addr; |
| 303 | if (!kernel_domain) |
| 304 | wq->udb = (u64)rdev_p->rnic_info.udbell_physbase + |
| 305 | (wq->qpid << rdev_p->qpshift); |
Steve Wise | 4ab928f | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 306 | wq->rdev = rdev_p; |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 307 | PDBG("%s qpid 0x%x doorbell 0x%p udb 0x%llx\n", __func__, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 308 | wq->qpid, wq->doorbell, (unsigned long long) wq->udb); |
| 309 | return 0; |
| 310 | err4: |
| 311 | kfree(wq->sq); |
| 312 | err3: |
| 313 | cxio_hal_rqtpool_free(rdev_p, wq->rq_addr, rqsize); |
| 314 | err2: |
| 315 | kfree(wq->rq); |
| 316 | err1: |
| 317 | put_qpid(rdev_p, wq->qpid, uctx); |
| 318 | return -ENOMEM; |
| 319 | } |
| 320 | |
| 321 | int cxio_destroy_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq) |
| 322 | { |
| 323 | int err; |
| 324 | err = cxio_hal_clear_cq_ctx(rdev_p, cq->cqid); |
| 325 | kfree(cq->sw_queue); |
| 326 | dma_free_coherent(&(rdev_p->rnic_info.pdev->dev), |
| 327 | (1UL << (cq->size_log2)) |
| 328 | * sizeof(struct t3_cqe), cq->queue, |
FUJITA Tomonori | 7960d6b | 2010-04-02 04:29:38 +0000 | [diff] [blame] | 329 | dma_unmap_addr(cq, mapping)); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 330 | cxio_hal_put_cqid(rdev_p->rscp, cq->cqid); |
| 331 | return err; |
| 332 | } |
| 333 | |
| 334 | int cxio_destroy_qp(struct cxio_rdev *rdev_p, struct t3_wq *wq, |
| 335 | struct cxio_ucontext *uctx) |
| 336 | { |
| 337 | dma_free_coherent(&(rdev_p->rnic_info.pdev->dev), |
| 338 | (1UL << (wq->size_log2)) |
| 339 | * sizeof(union t3_wr), wq->queue, |
FUJITA Tomonori | 7960d6b | 2010-04-02 04:29:38 +0000 | [diff] [blame] | 340 | dma_unmap_addr(wq, mapping)); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 341 | kfree(wq->sq); |
| 342 | cxio_hal_rqtpool_free(rdev_p, wq->rq_addr, (1UL << wq->rq_size_log2)); |
| 343 | kfree(wq->rq); |
| 344 | put_qpid(rdev_p, wq->qpid, uctx); |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | static void insert_recv_cqe(struct t3_wq *wq, struct t3_cq *cq) |
| 349 | { |
| 350 | struct t3_cqe cqe; |
| 351 | |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 352 | PDBG("%s wq %p cq %p sw_rptr 0x%x sw_wptr 0x%x\n", __func__, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 353 | wq, cq, cq->sw_rptr, cq->sw_wptr); |
| 354 | memset(&cqe, 0, sizeof(cqe)); |
| 355 | cqe.header = cpu_to_be32(V_CQE_STATUS(TPT_ERR_SWFLUSH) | |
| 356 | V_CQE_OPCODE(T3_SEND) | |
| 357 | V_CQE_TYPE(0) | |
| 358 | V_CQE_SWCQE(1) | |
| 359 | V_CQE_QPID(wq->qpid) | |
| 360 | V_CQE_GENBIT(Q_GENBIT(cq->sw_wptr, |
| 361 | cq->size_log2))); |
| 362 | *(cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2)) = cqe; |
| 363 | cq->sw_wptr++; |
| 364 | } |
| 365 | |
Steve Wise | c828694 | 2008-05-02 11:17:41 -0500 | [diff] [blame] | 366 | int cxio_flush_rq(struct t3_wq *wq, struct t3_cq *cq, int count) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 367 | { |
| 368 | u32 ptr; |
Steve Wise | c828694 | 2008-05-02 11:17:41 -0500 | [diff] [blame] | 369 | int flushed = 0; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 370 | |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 371 | PDBG("%s wq %p cq %p\n", __func__, wq, cq); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 372 | |
| 373 | /* flush RQ */ |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 374 | PDBG("%s rq_rptr %u rq_wptr %u skip count %u\n", __func__, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 375 | wq->rq_rptr, wq->rq_wptr, count); |
| 376 | ptr = wq->rq_rptr + count; |
Steve Wise | c828694 | 2008-05-02 11:17:41 -0500 | [diff] [blame] | 377 | while (ptr++ != wq->rq_wptr) { |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 378 | insert_recv_cqe(wq, cq); |
Steve Wise | c828694 | 2008-05-02 11:17:41 -0500 | [diff] [blame] | 379 | flushed++; |
| 380 | } |
| 381 | return flushed; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | static void insert_sq_cqe(struct t3_wq *wq, struct t3_cq *cq, |
| 385 | struct t3_swsq *sqp) |
| 386 | { |
| 387 | struct t3_cqe cqe; |
| 388 | |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 389 | PDBG("%s wq %p cq %p sw_rptr 0x%x sw_wptr 0x%x\n", __func__, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 390 | wq, cq, cq->sw_rptr, cq->sw_wptr); |
| 391 | memset(&cqe, 0, sizeof(cqe)); |
| 392 | cqe.header = cpu_to_be32(V_CQE_STATUS(TPT_ERR_SWFLUSH) | |
| 393 | V_CQE_OPCODE(sqp->opcode) | |
| 394 | V_CQE_TYPE(1) | |
| 395 | V_CQE_SWCQE(1) | |
| 396 | V_CQE_QPID(wq->qpid) | |
| 397 | V_CQE_GENBIT(Q_GENBIT(cq->sw_wptr, |
| 398 | cq->size_log2))); |
| 399 | cqe.u.scqe.wrid_hi = sqp->sq_wptr; |
| 400 | |
| 401 | *(cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2)) = cqe; |
| 402 | cq->sw_wptr++; |
| 403 | } |
| 404 | |
Steve Wise | c828694 | 2008-05-02 11:17:41 -0500 | [diff] [blame] | 405 | int cxio_flush_sq(struct t3_wq *wq, struct t3_cq *cq, int count) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 406 | { |
| 407 | __u32 ptr; |
Steve Wise | c828694 | 2008-05-02 11:17:41 -0500 | [diff] [blame] | 408 | int flushed = 0; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 409 | struct t3_swsq *sqp = wq->sq + Q_PTR2IDX(wq->sq_rptr, wq->sq_size_log2); |
| 410 | |
| 411 | ptr = wq->sq_rptr + count; |
Steve Wise | a58e58f | 2008-05-13 11:52:55 -0700 | [diff] [blame] | 412 | sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 413 | while (ptr != wq->sq_wptr) { |
Steve Wise | ec6995d | 2009-04-29 15:15:59 -0700 | [diff] [blame] | 414 | sqp->signaled = 0; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 415 | insert_sq_cqe(wq, cq, sqp); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 416 | ptr++; |
Steve Wise | a58e58f | 2008-05-13 11:52:55 -0700 | [diff] [blame] | 417 | sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2); |
Steve Wise | c828694 | 2008-05-02 11:17:41 -0500 | [diff] [blame] | 418 | flushed++; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 419 | } |
Steve Wise | c828694 | 2008-05-02 11:17:41 -0500 | [diff] [blame] | 420 | return flushed; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* |
| 424 | * Move all CQEs from the HWCQ into the SWCQ. |
| 425 | */ |
| 426 | void cxio_flush_hw_cq(struct t3_cq *cq) |
| 427 | { |
| 428 | struct t3_cqe *cqe, *swcqe; |
| 429 | |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 430 | PDBG("%s cq %p cqid 0x%x\n", __func__, cq, cq->cqid); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 431 | cqe = cxio_next_hw_cqe(cq); |
| 432 | while (cqe) { |
| 433 | PDBG("%s flushing hwcq rptr 0x%x to swcq wptr 0x%x\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 434 | __func__, cq->rptr, cq->sw_wptr); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 435 | swcqe = cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2); |
| 436 | *swcqe = *cqe; |
| 437 | swcqe->header |= cpu_to_be32(V_CQE_SWCQE(1)); |
| 438 | cq->sw_wptr++; |
| 439 | cq->rptr++; |
| 440 | cqe = cxio_next_hw_cqe(cq); |
| 441 | } |
| 442 | } |
| 443 | |
Adrian Bunk | 2b54035 | 2007-02-21 11:52:49 +0100 | [diff] [blame] | 444 | static int cqe_completes_wr(struct t3_cqe *cqe, struct t3_wq *wq) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 445 | { |
| 446 | if (CQE_OPCODE(*cqe) == T3_TERMINATE) |
| 447 | return 0; |
| 448 | |
| 449 | if ((CQE_OPCODE(*cqe) == T3_RDMA_WRITE) && RQ_TYPE(*cqe)) |
| 450 | return 0; |
| 451 | |
| 452 | if ((CQE_OPCODE(*cqe) == T3_READ_RESP) && SQ_TYPE(*cqe)) |
| 453 | return 0; |
| 454 | |
Steve Wise | 42fb61f | 2009-02-10 16:38:57 -0800 | [diff] [blame] | 455 | if (CQE_SEND_OPCODE(*cqe) && RQ_TYPE(*cqe) && |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 456 | Q_EMPTY(wq->rq_rptr, wq->rq_wptr)) |
| 457 | return 0; |
| 458 | |
| 459 | return 1; |
| 460 | } |
| 461 | |
| 462 | void cxio_count_scqes(struct t3_cq *cq, struct t3_wq *wq, int *count) |
| 463 | { |
| 464 | struct t3_cqe *cqe; |
| 465 | u32 ptr; |
| 466 | |
| 467 | *count = 0; |
| 468 | ptr = cq->sw_rptr; |
| 469 | while (!Q_EMPTY(ptr, cq->sw_wptr)) { |
| 470 | cqe = cq->sw_queue + (Q_PTR2IDX(ptr, cq->size_log2)); |
Steve Wise | f8b0dfd | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 471 | if ((SQ_TYPE(*cqe) || |
| 472 | ((CQE_OPCODE(*cqe) == T3_READ_RESP) && wq->oldest_read)) && |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 473 | (CQE_QPID(*cqe) == wq->qpid)) |
| 474 | (*count)++; |
| 475 | ptr++; |
| 476 | } |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 477 | PDBG("%s cq %p count %d\n", __func__, cq, *count); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | void cxio_count_rcqes(struct t3_cq *cq, struct t3_wq *wq, int *count) |
| 481 | { |
| 482 | struct t3_cqe *cqe; |
| 483 | u32 ptr; |
| 484 | |
| 485 | *count = 0; |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 486 | PDBG("%s count zero %d\n", __func__, *count); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 487 | ptr = cq->sw_rptr; |
| 488 | while (!Q_EMPTY(ptr, cq->sw_wptr)) { |
| 489 | cqe = cq->sw_queue + (Q_PTR2IDX(ptr, cq->size_log2)); |
| 490 | if (RQ_TYPE(*cqe) && (CQE_OPCODE(*cqe) != T3_READ_RESP) && |
| 491 | (CQE_QPID(*cqe) == wq->qpid) && cqe_completes_wr(cqe, wq)) |
| 492 | (*count)++; |
| 493 | ptr++; |
| 494 | } |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 495 | PDBG("%s cq %p count %d\n", __func__, cq, *count); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static int cxio_hal_init_ctrl_cq(struct cxio_rdev *rdev_p) |
| 499 | { |
| 500 | struct rdma_cq_setup setup; |
| 501 | setup.id = 0; |
| 502 | setup.base_addr = 0; /* NULL address */ |
| 503 | setup.size = 1; /* enable the CQ */ |
| 504 | setup.credits = 0; |
| 505 | |
| 506 | /* force SGE to redirect to RspQ and interrupt */ |
| 507 | setup.credit_thres = 0; |
| 508 | setup.ovfl_mode = 1; |
| 509 | return (rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_SETUP, &setup)); |
| 510 | } |
| 511 | |
| 512 | static int cxio_hal_init_ctrl_qp(struct cxio_rdev *rdev_p) |
| 513 | { |
| 514 | int err; |
| 515 | u64 sge_cmd, ctx0, ctx1; |
| 516 | u64 base_addr; |
| 517 | struct t3_modify_qp_wr *wqe; |
Steve Wise | ed6ee51 | 2007-03-26 17:48:52 -0500 | [diff] [blame] | 518 | struct sk_buff *skb; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 519 | |
Steve Wise | ed6ee51 | 2007-03-26 17:48:52 -0500 | [diff] [blame] | 520 | skb = alloc_skb(sizeof(*wqe), GFP_KERNEL); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 521 | if (!skb) { |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 522 | PDBG("%s alloc_skb failed\n", __func__); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 523 | return -ENOMEM; |
| 524 | } |
| 525 | err = cxio_hal_init_ctrl_cq(rdev_p); |
| 526 | if (err) { |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 527 | PDBG("%s err %d initializing ctrl_cq\n", __func__, err); |
Steve Wise | ed6ee51 | 2007-03-26 17:48:52 -0500 | [diff] [blame] | 528 | goto err; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 529 | } |
| 530 | rdev_p->ctrl_qp.workq = dma_alloc_coherent( |
| 531 | &(rdev_p->rnic_info.pdev->dev), |
| 532 | (1 << T3_CTRL_QP_SIZE_LOG2) * |
| 533 | sizeof(union t3_wr), |
| 534 | &(rdev_p->ctrl_qp.dma_addr), |
| 535 | GFP_KERNEL); |
| 536 | if (!rdev_p->ctrl_qp.workq) { |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 537 | PDBG("%s dma_alloc_coherent failed\n", __func__); |
Steve Wise | ed6ee51 | 2007-03-26 17:48:52 -0500 | [diff] [blame] | 538 | err = -ENOMEM; |
| 539 | goto err; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 540 | } |
FUJITA Tomonori | 7960d6b | 2010-04-02 04:29:38 +0000 | [diff] [blame] | 541 | dma_unmap_addr_set(&rdev_p->ctrl_qp, mapping, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 542 | rdev_p->ctrl_qp.dma_addr); |
| 543 | rdev_p->ctrl_qp.doorbell = (void __iomem *)rdev_p->rnic_info.kdb_addr; |
| 544 | memset(rdev_p->ctrl_qp.workq, 0, |
| 545 | (1 << T3_CTRL_QP_SIZE_LOG2) * sizeof(union t3_wr)); |
| 546 | |
| 547 | mutex_init(&rdev_p->ctrl_qp.lock); |
| 548 | init_waitqueue_head(&rdev_p->ctrl_qp.waitq); |
| 549 | |
| 550 | /* update HW Ctrl QP context */ |
| 551 | base_addr = rdev_p->ctrl_qp.dma_addr; |
| 552 | base_addr >>= 12; |
| 553 | ctx0 = (V_EC_SIZE((1 << T3_CTRL_QP_SIZE_LOG2)) | |
| 554 | V_EC_BASE_LO((u32) base_addr & 0xffff)); |
| 555 | ctx0 <<= 32; |
| 556 | ctx0 |= V_EC_CREDITS(FW_WR_NUM); |
| 557 | base_addr >>= 16; |
| 558 | ctx1 = (u32) base_addr; |
| 559 | base_addr >>= 32; |
| 560 | ctx1 |= ((u64) (V_EC_BASE_HI((u32) base_addr & 0xf) | V_EC_RESPQ(0) | |
| 561 | V_EC_TYPE(0) | V_EC_GEN(1) | |
| 562 | V_EC_UP_TOKEN(T3_CTL_QP_TID) | F_EC_VALID)) << 32; |
| 563 | wqe = (struct t3_modify_qp_wr *) skb_put(skb, sizeof(*wqe)); |
| 564 | memset(wqe, 0, sizeof(*wqe)); |
Steve Wise | 6eda48d | 2007-06-19 09:27:48 -0500 | [diff] [blame] | 565 | build_fw_riwrh((struct fw_riwrh *) wqe, T3_WR_QP_MOD, 0, 0, |
Steve Wise | e7e5582 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 566 | T3_CTL_QP_TID, 7, T3_SOPEOP); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 567 | wqe->flags = cpu_to_be32(MODQP_WRITE_EC); |
| 568 | sge_cmd = (3ULL << 56) | FW_RI_SGEEC_START << 8 | 3; |
| 569 | wqe->sge_cmd = cpu_to_be64(sge_cmd); |
| 570 | wqe->ctx1 = cpu_to_be64(ctx1); |
| 571 | wqe->ctx0 = cpu_to_be64(ctx0); |
| 572 | PDBG("CtrlQP dma_addr 0x%llx workq %p size %d\n", |
| 573 | (unsigned long long) rdev_p->ctrl_qp.dma_addr, |
| 574 | rdev_p->ctrl_qp.workq, 1 << T3_CTRL_QP_SIZE_LOG2); |
| 575 | skb->priority = CPL_PRIORITY_CONTROL; |
Steve Wise | 04b5d02 | 2009-03-30 08:37:56 -0700 | [diff] [blame] | 576 | return iwch_cxgb3_ofld_send(rdev_p->t3cdev_p, skb); |
Steve Wise | ed6ee51 | 2007-03-26 17:48:52 -0500 | [diff] [blame] | 577 | err: |
| 578 | kfree_skb(skb); |
| 579 | return err; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | static int cxio_hal_destroy_ctrl_qp(struct cxio_rdev *rdev_p) |
| 583 | { |
| 584 | dma_free_coherent(&(rdev_p->rnic_info.pdev->dev), |
| 585 | (1UL << T3_CTRL_QP_SIZE_LOG2) |
| 586 | * sizeof(union t3_wr), rdev_p->ctrl_qp.workq, |
FUJITA Tomonori | 7960d6b | 2010-04-02 04:29:38 +0000 | [diff] [blame] | 587 | dma_unmap_addr(&rdev_p->ctrl_qp, mapping)); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 588 | return cxio_hal_clear_qp_ctx(rdev_p, T3_CTRL_QP_ID); |
| 589 | } |
| 590 | |
| 591 | /* write len bytes of data into addr (32B aligned address) |
| 592 | * If data is NULL, clear len byte of memory to zero. |
Uwe Kleine-König | 21ae295 | 2009-10-07 15:21:09 +0200 | [diff] [blame] | 593 | * caller acquires the ctrl_qp lock before the call |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 594 | */ |
| 595 | static int cxio_hal_ctrl_qp_write_mem(struct cxio_rdev *rdev_p, u32 addr, |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 596 | u32 len, void *data) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 597 | { |
| 598 | u32 i, nr_wqe, copy_len; |
| 599 | u8 *copy_data; |
Joe Perches | 94545e8 | 2007-12-17 11:30:36 -0800 | [diff] [blame] | 600 | u8 wr_len, utx_len; /* length in 8 byte flit */ |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 601 | enum t3_wr_flags flag; |
| 602 | __be64 *wqe; |
| 603 | u64 utx_cmd; |
| 604 | addr &= 0x7FFFFFF; |
| 605 | nr_wqe = len % 96 ? len / 96 + 1 : len / 96; /* 96B max per WQE */ |
| 606 | PDBG("%s wptr 0x%x rptr 0x%x len %d, nr_wqe %d data %p addr 0x%0x\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 607 | __func__, rdev_p->ctrl_qp.wptr, rdev_p->ctrl_qp.rptr, len, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 608 | nr_wqe, data, addr); |
| 609 | utx_len = 3; /* in 32B unit */ |
| 610 | for (i = 0; i < nr_wqe; i++) { |
| 611 | if (Q_FULL(rdev_p->ctrl_qp.rptr, rdev_p->ctrl_qp.wptr, |
| 612 | T3_CTRL_QP_SIZE_LOG2)) { |
| 613 | PDBG("%s ctrl_qp full wtpr 0x%0x rptr 0x%0x, " |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 614 | "wait for more space i %d\n", __func__, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 615 | rdev_p->ctrl_qp.wptr, rdev_p->ctrl_qp.rptr, i); |
| 616 | if (wait_event_interruptible(rdev_p->ctrl_qp.waitq, |
| 617 | !Q_FULL(rdev_p->ctrl_qp.rptr, |
| 618 | rdev_p->ctrl_qp.wptr, |
| 619 | T3_CTRL_QP_SIZE_LOG2))) { |
| 620 | PDBG("%s ctrl_qp workq interrupted\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 621 | __func__); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 622 | return -ERESTARTSYS; |
| 623 | } |
| 624 | PDBG("%s ctrl_qp wakeup, continue posting work request " |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 625 | "i %d\n", __func__, i); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 626 | } |
| 627 | wqe = (__be64 *)(rdev_p->ctrl_qp.workq + (rdev_p->ctrl_qp.wptr % |
| 628 | (1 << T3_CTRL_QP_SIZE_LOG2))); |
| 629 | flag = 0; |
| 630 | if (i == (nr_wqe - 1)) { |
| 631 | /* last WQE */ |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 632 | flag = T3_COMPLETION_FLAG; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 633 | if (len % 32) |
| 634 | utx_len = len / 32 + 1; |
| 635 | else |
| 636 | utx_len = len / 32; |
| 637 | } |
| 638 | |
| 639 | /* |
| 640 | * Force a CQE to return the credit to the workq in case |
| 641 | * we posted more than half the max QP size of WRs |
| 642 | */ |
| 643 | if ((i != 0) && |
| 644 | (i % (((1 << T3_CTRL_QP_SIZE_LOG2)) >> 1) == 0)) { |
| 645 | flag = T3_COMPLETION_FLAG; |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 646 | PDBG("%s force completion at i %d\n", __func__, i); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /* build the utx mem command */ |
| 650 | wqe += (sizeof(struct t3_bypass_wr) >> 3); |
| 651 | utx_cmd = (T3_UTX_MEM_WRITE << 28) | (addr + i * 3); |
| 652 | utx_cmd <<= 32; |
| 653 | utx_cmd |= (utx_len << 28) | ((utx_len << 2) + 1); |
| 654 | *wqe = cpu_to_be64(utx_cmd); |
| 655 | wqe++; |
| 656 | copy_data = (u8 *) data + i * 96; |
| 657 | copy_len = len > 96 ? 96 : len; |
| 658 | |
| 659 | /* clear memory content if data is NULL */ |
| 660 | if (data) |
| 661 | memcpy(wqe, copy_data, copy_len); |
| 662 | else |
| 663 | memset(wqe, 0, copy_len); |
| 664 | if (copy_len % 32) |
| 665 | memset(((u8 *) wqe) + copy_len, 0, |
| 666 | 32 - (copy_len % 32)); |
| 667 | wr_len = ((sizeof(struct t3_bypass_wr)) >> 3) + 1 + |
| 668 | (utx_len << 2); |
| 669 | wqe = (__be64 *)(rdev_p->ctrl_qp.workq + (rdev_p->ctrl_qp.wptr % |
| 670 | (1 << T3_CTRL_QP_SIZE_LOG2))); |
| 671 | |
| 672 | /* wptr in the WRID[31:0] */ |
| 673 | ((union t3_wrid *)(wqe+1))->id0.low = rdev_p->ctrl_qp.wptr; |
| 674 | |
| 675 | /* |
| 676 | * This must be the last write with a memory barrier |
| 677 | * for the genbit |
| 678 | */ |
| 679 | build_fw_riwrh((struct fw_riwrh *) wqe, T3_WR_BP, flag, |
| 680 | Q_GENBIT(rdev_p->ctrl_qp.wptr, |
| 681 | T3_CTRL_QP_SIZE_LOG2), T3_CTRL_QP_ID, |
Steve Wise | e7e5582 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 682 | wr_len, T3_SOPEOP); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 683 | if (flag == T3_COMPLETION_FLAG) |
| 684 | ring_doorbell(rdev_p->ctrl_qp.doorbell, T3_CTRL_QP_ID); |
| 685 | len -= 96; |
| 686 | rdev_p->ctrl_qp.wptr++; |
| 687 | } |
| 688 | return 0; |
| 689 | } |
| 690 | |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 691 | /* IN: stag key, pdid, perm, zbva, to, len, page_size, pbl_size and pbl_addr |
| 692 | * OUT: stag index |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 693 | * TBD: shared memory region support |
| 694 | */ |
| 695 | static int __cxio_tpt_op(struct cxio_rdev *rdev_p, u32 reset_tpt_entry, |
| 696 | u32 *stag, u8 stag_state, u32 pdid, |
| 697 | enum tpt_mem_type type, enum tpt_mem_perm perm, |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 698 | u32 zbva, u64 to, u32 len, u8 page_size, |
| 699 | u32 pbl_size, u32 pbl_addr) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 700 | { |
| 701 | int err; |
| 702 | struct tpt_entry tpt; |
| 703 | u32 stag_idx; |
| 704 | u32 wptr; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 705 | |
Steve Wise | 04b5d02 | 2009-03-30 08:37:56 -0700 | [diff] [blame] | 706 | if (cxio_fatal_error(rdev_p)) |
Divy Le Ray | a73efd0 | 2009-01-26 22:22:19 -0800 | [diff] [blame] | 707 | return -EIO; |
| 708 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 709 | stag_state = stag_state > 0; |
| 710 | stag_idx = (*stag) >> 8; |
| 711 | |
| 712 | if ((!reset_tpt_entry) && !(*stag != T3_STAG_UNSET)) { |
| 713 | stag_idx = cxio_hal_get_stag(rdev_p->rscp); |
| 714 | if (!stag_idx) |
| 715 | return -ENOMEM; |
| 716 | *stag = (stag_idx << 8) | ((*stag) & 0xFF); |
| 717 | } |
| 718 | PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 719 | __func__, stag_state, type, pdid, stag_idx); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 720 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 721 | mutex_lock(&rdev_p->ctrl_qp.lock); |
| 722 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 723 | /* write TPT entry */ |
| 724 | if (reset_tpt_entry) |
| 725 | memset(&tpt, 0, sizeof(tpt)); |
| 726 | else { |
| 727 | tpt.valid_stag_pdid = cpu_to_be32(F_TPT_VALID | |
| 728 | V_TPT_STAG_KEY((*stag) & M_TPT_STAG_KEY) | |
| 729 | V_TPT_STAG_STATE(stag_state) | |
| 730 | V_TPT_STAG_TYPE(type) | V_TPT_PDID(pdid)); |
| 731 | BUG_ON(page_size >= 28); |
| 732 | tpt.flags_pagesize_qpid = cpu_to_be32(V_TPT_PERM(perm) | |
Steve Wise | 1c355a6 | 2008-08-04 11:05:43 -0700 | [diff] [blame] | 733 | ((perm & TPT_MW_BIND) ? F_TPT_MW_BIND_ENABLE : 0) | |
| 734 | V_TPT_ADDR_TYPE((zbva ? TPT_ZBTO : TPT_VATO)) | |
| 735 | V_TPT_PAGE_SIZE(page_size)); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 736 | tpt.rsvd_pbl_addr = reset_tpt_entry ? 0 : |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 737 | cpu_to_be32(V_TPT_PBL_ADDR(PBL_OFF(rdev_p, pbl_addr)>>3)); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 738 | tpt.len = cpu_to_be32(len); |
| 739 | tpt.va_hi = cpu_to_be32((u32) (to >> 32)); |
| 740 | tpt.va_low_or_fbo = cpu_to_be32((u32) (to & 0xFFFFFFFFULL)); |
| 741 | tpt.rsvd_bind_cnt_or_pstag = 0; |
| 742 | tpt.rsvd_pbl_size = reset_tpt_entry ? 0 : |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 743 | cpu_to_be32(V_TPT_PBL_SIZE(pbl_size >> 2)); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 744 | } |
| 745 | err = cxio_hal_ctrl_qp_write_mem(rdev_p, |
| 746 | stag_idx + |
| 747 | (rdev_p->rnic_info.tpt_base >> 5), |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 748 | sizeof(tpt), &tpt); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 749 | |
| 750 | /* release the stag index to free pool */ |
| 751 | if (reset_tpt_entry) |
| 752 | cxio_hal_put_stag(rdev_p->rscp, stag_idx); |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 753 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 754 | wptr = rdev_p->ctrl_qp.wptr; |
| 755 | mutex_unlock(&rdev_p->ctrl_qp.lock); |
| 756 | if (!err) |
| 757 | if (wait_event_interruptible(rdev_p->ctrl_qp.waitq, |
| 758 | SEQ32_GE(rdev_p->ctrl_qp.rptr, |
| 759 | wptr))) |
| 760 | return -ERESTARTSYS; |
| 761 | return err; |
| 762 | } |
| 763 | |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 764 | int cxio_write_pbl(struct cxio_rdev *rdev_p, __be64 *pbl, |
| 765 | u32 pbl_addr, u32 pbl_size) |
| 766 | { |
| 767 | u32 wptr; |
| 768 | int err; |
| 769 | |
| 770 | PDBG("%s *pdb_addr 0x%x, pbl_base 0x%x, pbl_size %d\n", |
| 771 | __func__, pbl_addr, rdev_p->rnic_info.pbl_base, |
| 772 | pbl_size); |
| 773 | |
| 774 | mutex_lock(&rdev_p->ctrl_qp.lock); |
| 775 | err = cxio_hal_ctrl_qp_write_mem(rdev_p, pbl_addr >> 5, pbl_size << 3, |
| 776 | pbl); |
| 777 | wptr = rdev_p->ctrl_qp.wptr; |
| 778 | mutex_unlock(&rdev_p->ctrl_qp.lock); |
| 779 | if (err) |
| 780 | return err; |
| 781 | |
| 782 | if (wait_event_interruptible(rdev_p->ctrl_qp.waitq, |
| 783 | SEQ32_GE(rdev_p->ctrl_qp.rptr, |
| 784 | wptr))) |
| 785 | return -ERESTARTSYS; |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 790 | int cxio_register_phys_mem(struct cxio_rdev *rdev_p, u32 *stag, u32 pdid, |
| 791 | enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len, |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 792 | u8 page_size, u32 pbl_size, u32 pbl_addr) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 793 | { |
| 794 | *stag = T3_STAG_UNSET; |
| 795 | return __cxio_tpt_op(rdev_p, 0, stag, 1, pdid, TPT_NON_SHARED_MR, perm, |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 796 | zbva, to, len, page_size, pbl_size, pbl_addr); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | int cxio_reregister_phys_mem(struct cxio_rdev *rdev_p, u32 *stag, u32 pdid, |
| 800 | enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len, |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 801 | u8 page_size, u32 pbl_size, u32 pbl_addr) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 802 | { |
| 803 | return __cxio_tpt_op(rdev_p, 0, stag, 1, pdid, TPT_NON_SHARED_MR, perm, |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 804 | zbva, to, len, page_size, pbl_size, pbl_addr); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | int cxio_dereg_mem(struct cxio_rdev *rdev_p, u32 stag, u32 pbl_size, |
| 808 | u32 pbl_addr) |
| 809 | { |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 810 | return __cxio_tpt_op(rdev_p, 1, &stag, 0, 0, 0, 0, 0, 0ULL, 0, 0, |
| 811 | pbl_size, pbl_addr); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | int cxio_allocate_window(struct cxio_rdev *rdev_p, u32 * stag, u32 pdid) |
| 815 | { |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 816 | *stag = T3_STAG_UNSET; |
| 817 | return __cxio_tpt_op(rdev_p, 0, stag, 0, pdid, TPT_MW, 0, 0, 0ULL, 0, 0, |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 818 | 0, 0); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | int cxio_deallocate_window(struct cxio_rdev *rdev_p, u32 stag) |
| 822 | { |
Roland Dreier | 273748c | 2008-05-06 15:56:22 -0700 | [diff] [blame] | 823 | return __cxio_tpt_op(rdev_p, 1, &stag, 0, 0, 0, 0, 0, 0ULL, 0, 0, |
| 824 | 0, 0); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 825 | } |
| 826 | |
Steve Wise | e7e5582 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 827 | int cxio_allocate_stag(struct cxio_rdev *rdev_p, u32 *stag, u32 pdid, u32 pbl_size, u32 pbl_addr) |
| 828 | { |
| 829 | *stag = T3_STAG_UNSET; |
| 830 | return __cxio_tpt_op(rdev_p, 0, stag, 0, pdid, TPT_NON_SHARED_MR, |
| 831 | 0, 0, 0ULL, 0, 0, pbl_size, pbl_addr); |
| 832 | } |
| 833 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 834 | int cxio_rdma_init(struct cxio_rdev *rdev_p, struct t3_rdma_init_attr *attr) |
| 835 | { |
| 836 | struct t3_rdma_init_wr *wqe; |
| 837 | struct sk_buff *skb = alloc_skb(sizeof(*wqe), GFP_ATOMIC); |
| 838 | if (!skb) |
| 839 | return -ENOMEM; |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 840 | PDBG("%s rdev_p %p\n", __func__, rdev_p); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 841 | wqe = (struct t3_rdma_init_wr *) __skb_put(skb, sizeof(*wqe)); |
| 842 | wqe->wrh.op_seop_flags = cpu_to_be32(V_FW_RIWR_OP(T3_WR_INIT)); |
| 843 | wqe->wrh.gen_tid_len = cpu_to_be32(V_FW_RIWR_TID(attr->tid) | |
| 844 | V_FW_RIWR_LEN(sizeof(*wqe) >> 3)); |
| 845 | wqe->wrid.id1 = 0; |
| 846 | wqe->qpid = cpu_to_be32(attr->qpid); |
| 847 | wqe->pdid = cpu_to_be32(attr->pdid); |
| 848 | wqe->scqid = cpu_to_be32(attr->scqid); |
| 849 | wqe->rcqid = cpu_to_be32(attr->rcqid); |
| 850 | wqe->rq_addr = cpu_to_be32(attr->rq_addr - rdev_p->rnic_info.rqt_base); |
| 851 | wqe->rq_size = cpu_to_be32(attr->rq_size); |
| 852 | wqe->mpaattrs = attr->mpaattrs; |
| 853 | wqe->qpcaps = attr->qpcaps; |
| 854 | wqe->ulpdu_size = cpu_to_be16(attr->tcp_emss); |
Steve Wise | f8b0dfd | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 855 | wqe->rqe_count = cpu_to_be16(attr->rqe_count); |
Steve Wise | b496fe8 | 2009-09-05 20:22:37 -0700 | [diff] [blame] | 856 | wqe->flags_rtr_type = cpu_to_be16(attr->flags | |
| 857 | V_RTR_TYPE(attr->rtr_type) | |
| 858 | V_CHAN(attr->chan)); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 859 | wqe->ord = cpu_to_be32(attr->ord); |
| 860 | wqe->ird = cpu_to_be32(attr->ird); |
| 861 | wqe->qp_dma_addr = cpu_to_be64(attr->qp_dma_addr); |
| 862 | wqe->qp_dma_size = cpu_to_be32(attr->qp_dma_size); |
Steve Wise | de3d353 | 2007-05-14 13:27:27 -0500 | [diff] [blame] | 863 | wqe->irs = cpu_to_be32(attr->irs); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 864 | skb->priority = 0; /* 0=>ToeQ; 1=>CtrlQ */ |
Steve Wise | 04b5d02 | 2009-03-30 08:37:56 -0700 | [diff] [blame] | 865 | return iwch_cxgb3_ofld_send(rdev_p->t3cdev_p, skb); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | void cxio_register_ev_cb(cxio_hal_ev_callback_func_t ev_cb) |
| 869 | { |
| 870 | cxio_ev_cb = ev_cb; |
| 871 | } |
| 872 | |
| 873 | void cxio_unregister_ev_cb(cxio_hal_ev_callback_func_t ev_cb) |
| 874 | { |
| 875 | cxio_ev_cb = NULL; |
| 876 | } |
| 877 | |
| 878 | static int cxio_hal_ev_handler(struct t3cdev *t3cdev_p, struct sk_buff *skb) |
| 879 | { |
| 880 | static int cnt; |
| 881 | struct cxio_rdev *rdev_p = NULL; |
| 882 | struct respQ_msg_t *rsp_msg = (struct respQ_msg_t *) skb->data; |
| 883 | PDBG("%d: %s cq_id 0x%x cq_ptr 0x%x genbit %0x overflow %0x an %0x" |
| 884 | " se %0x notify %0x cqbranch %0x creditth %0x\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 885 | cnt, __func__, RSPQ_CQID(rsp_msg), RSPQ_CQPTR(rsp_msg), |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 886 | RSPQ_GENBIT(rsp_msg), RSPQ_OVERFLOW(rsp_msg), RSPQ_AN(rsp_msg), |
| 887 | RSPQ_SE(rsp_msg), RSPQ_NOTIFY(rsp_msg), RSPQ_CQBRANCH(rsp_msg), |
| 888 | RSPQ_CREDIT_THRESH(rsp_msg)); |
| 889 | PDBG("CQE: QPID 0x%0x genbit %0x type 0x%0x status 0x%0x opcode %d " |
| 890 | "len 0x%0x wrid_hi_stag 0x%x wrid_low_msn 0x%x\n", |
| 891 | CQE_QPID(rsp_msg->cqe), CQE_GENBIT(rsp_msg->cqe), |
| 892 | CQE_TYPE(rsp_msg->cqe), CQE_STATUS(rsp_msg->cqe), |
| 893 | CQE_OPCODE(rsp_msg->cqe), CQE_LEN(rsp_msg->cqe), |
| 894 | CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe)); |
| 895 | rdev_p = (struct cxio_rdev *)t3cdev_p->ulp; |
| 896 | if (!rdev_p) { |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 897 | PDBG("%s called by t3cdev %p with null ulp\n", __func__, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 898 | t3cdev_p); |
| 899 | return 0; |
| 900 | } |
| 901 | if (CQE_QPID(rsp_msg->cqe) == T3_CTRL_QP_ID) { |
| 902 | rdev_p->ctrl_qp.rptr = CQE_WRID_LOW(rsp_msg->cqe) + 1; |
| 903 | wake_up_interruptible(&rdev_p->ctrl_qp.waitq); |
| 904 | dev_kfree_skb_irq(skb); |
| 905 | } else if (CQE_QPID(rsp_msg->cqe) == 0xfff8) |
| 906 | dev_kfree_skb_irq(skb); |
| 907 | else if (cxio_ev_cb) |
| 908 | (*cxio_ev_cb) (rdev_p, skb); |
| 909 | else |
| 910 | dev_kfree_skb_irq(skb); |
| 911 | cnt++; |
| 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | /* Caller takes care of locking if needed */ |
| 916 | int cxio_rdev_open(struct cxio_rdev *rdev_p) |
| 917 | { |
| 918 | struct net_device *netdev_p = NULL; |
| 919 | int err = 0; |
| 920 | if (strlen(rdev_p->dev_name)) { |
| 921 | if (cxio_hal_find_rdev_by_name(rdev_p->dev_name)) { |
| 922 | return -EBUSY; |
| 923 | } |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 924 | netdev_p = dev_get_by_name(&init_net, rdev_p->dev_name); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 925 | if (!netdev_p) { |
| 926 | return -EINVAL; |
| 927 | } |
| 928 | dev_put(netdev_p); |
| 929 | } else if (rdev_p->t3cdev_p) { |
| 930 | if (cxio_hal_find_rdev_by_t3cdev(rdev_p->t3cdev_p)) { |
| 931 | return -EBUSY; |
| 932 | } |
| 933 | netdev_p = rdev_p->t3cdev_p->lldev; |
| 934 | strncpy(rdev_p->dev_name, rdev_p->t3cdev_p->name, |
| 935 | T3_MAX_DEV_NAME_LEN); |
| 936 | } else { |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 937 | PDBG("%s t3cdev_p or dev_name must be set\n", __func__); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 938 | return -EINVAL; |
| 939 | } |
| 940 | |
| 941 | list_add_tail(&rdev_p->entry, &rdev_list); |
| 942 | |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 943 | PDBG("%s opening rnic dev %s\n", __func__, rdev_p->dev_name); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 944 | memset(&rdev_p->ctrl_qp, 0, sizeof(rdev_p->ctrl_qp)); |
| 945 | if (!rdev_p->t3cdev_p) |
Divy Le Ray | 5fbf816 | 2007-08-29 19:15:47 -0700 | [diff] [blame] | 946 | rdev_p->t3cdev_p = dev2t3cdev(netdev_p); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 947 | rdev_p->t3cdev_p->ulp = (void *) rdev_p; |
Steve Wise | d1fbe04 | 2009-03-24 20:44:18 -0700 | [diff] [blame] | 948 | |
| 949 | err = rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, GET_EMBEDDED_INFO, |
| 950 | &(rdev_p->fw_info)); |
| 951 | if (err) { |
| 952 | printk(KERN_ERR "%s t3cdev_p(%p)->ctl returned error %d.\n", |
| 953 | __func__, rdev_p->t3cdev_p, err); |
| 954 | goto err1; |
| 955 | } |
| 956 | if (G_FW_VERSION_MAJOR(rdev_p->fw_info.fw_vers) != CXIO_FW_MAJ) { |
| 957 | printk(KERN_ERR MOD "fatal firmware version mismatch: " |
| 958 | "need version %u but adapter has version %u\n", |
| 959 | CXIO_FW_MAJ, |
| 960 | G_FW_VERSION_MAJOR(rdev_p->fw_info.fw_vers)); |
| 961 | err = -EINVAL; |
| 962 | goto err1; |
| 963 | } |
| 964 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 965 | err = rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_GET_PARAMS, |
| 966 | &(rdev_p->rnic_info)); |
| 967 | if (err) { |
| 968 | printk(KERN_ERR "%s t3cdev_p(%p)->ctl returned error %d.\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 969 | __func__, rdev_p->t3cdev_p, err); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 970 | goto err1; |
| 971 | } |
| 972 | err = rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, GET_PORTS, |
| 973 | &(rdev_p->port_info)); |
| 974 | if (err) { |
| 975 | printk(KERN_ERR "%s t3cdev_p(%p)->ctl returned error %d.\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 976 | __func__, rdev_p->t3cdev_p, err); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 977 | goto err1; |
| 978 | } |
| 979 | |
| 980 | /* |
| 981 | * qpshift is the number of bits to shift the qpid left in order |
| 982 | * to get the correct address of the doorbell for that qp. |
| 983 | */ |
| 984 | cxio_init_ucontext(rdev_p, &rdev_p->uctx); |
| 985 | rdev_p->qpshift = PAGE_SHIFT - |
| 986 | ilog2(65536 >> |
| 987 | ilog2(rdev_p->rnic_info.udbell_len >> |
| 988 | PAGE_SHIFT)); |
| 989 | rdev_p->qpnr = rdev_p->rnic_info.udbell_len >> PAGE_SHIFT; |
| 990 | rdev_p->qpmask = (65536 >> ilog2(rdev_p->qpnr)) - 1; |
| 991 | PDBG("%s rnic %s info: tpt_base 0x%0x tpt_top 0x%0x num stags %d " |
| 992 | "pbl_base 0x%0x pbl_top 0x%0x rqt_base 0x%0x, rqt_top 0x%0x\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 993 | __func__, rdev_p->dev_name, rdev_p->rnic_info.tpt_base, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 994 | rdev_p->rnic_info.tpt_top, cxio_num_stags(rdev_p), |
| 995 | rdev_p->rnic_info.pbl_base, |
| 996 | rdev_p->rnic_info.pbl_top, rdev_p->rnic_info.rqt_base, |
| 997 | rdev_p->rnic_info.rqt_top); |
| 998 | PDBG("udbell_len 0x%0x udbell_physbase 0x%lx kdb_addr %p qpshift %lu " |
| 999 | "qpnr %d qpmask 0x%x\n", |
| 1000 | rdev_p->rnic_info.udbell_len, |
| 1001 | rdev_p->rnic_info.udbell_physbase, rdev_p->rnic_info.kdb_addr, |
| 1002 | rdev_p->qpshift, rdev_p->qpnr, rdev_p->qpmask); |
| 1003 | |
| 1004 | err = cxio_hal_init_ctrl_qp(rdev_p); |
| 1005 | if (err) { |
| 1006 | printk(KERN_ERR "%s error %d initializing ctrl_qp.\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1007 | __func__, err); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1008 | goto err1; |
| 1009 | } |
| 1010 | err = cxio_hal_init_resource(rdev_p, cxio_num_stags(rdev_p), 0, |
| 1011 | 0, T3_MAX_NUM_QP, T3_MAX_NUM_CQ, |
| 1012 | T3_MAX_NUM_PD); |
| 1013 | if (err) { |
| 1014 | printk(KERN_ERR "%s error %d initializing hal resources.\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1015 | __func__, err); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1016 | goto err2; |
| 1017 | } |
| 1018 | err = cxio_hal_pblpool_create(rdev_p); |
| 1019 | if (err) { |
| 1020 | printk(KERN_ERR "%s error %d initializing pbl mem pool.\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1021 | __func__, err); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1022 | goto err3; |
| 1023 | } |
| 1024 | err = cxio_hal_rqtpool_create(rdev_p); |
| 1025 | if (err) { |
| 1026 | printk(KERN_ERR "%s error %d initializing rqt mem pool.\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1027 | __func__, err); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1028 | goto err4; |
| 1029 | } |
| 1030 | return 0; |
| 1031 | err4: |
| 1032 | cxio_hal_pblpool_destroy(rdev_p); |
| 1033 | err3: |
| 1034 | cxio_hal_destroy_resource(rdev_p->rscp); |
| 1035 | err2: |
| 1036 | cxio_hal_destroy_ctrl_qp(rdev_p); |
| 1037 | err1: |
Steve Wise | ffc40c6 | 2009-09-09 11:25:56 -0700 | [diff] [blame] | 1038 | rdev_p->t3cdev_p->ulp = NULL; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1039 | list_del(&rdev_p->entry); |
| 1040 | return err; |
| 1041 | } |
| 1042 | |
| 1043 | void cxio_rdev_close(struct cxio_rdev *rdev_p) |
| 1044 | { |
| 1045 | if (rdev_p) { |
| 1046 | cxio_hal_pblpool_destroy(rdev_p); |
| 1047 | cxio_hal_rqtpool_destroy(rdev_p); |
| 1048 | list_del(&rdev_p->entry); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1049 | cxio_hal_destroy_ctrl_qp(rdev_p); |
| 1050 | cxio_hal_destroy_resource(rdev_p->rscp); |
Steve Wise | 04b5d02 | 2009-03-30 08:37:56 -0700 | [diff] [blame] | 1051 | rdev_p->t3cdev_p->ulp = NULL; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | int __init cxio_hal_init(void) |
| 1056 | { |
| 1057 | if (cxio_hal_init_rhdl_resource(T3_MAX_NUM_RI)) |
| 1058 | return -ENOMEM; |
| 1059 | t3_register_cpl_handler(CPL_ASYNC_NOTIF, cxio_hal_ev_handler); |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | void __exit cxio_hal_exit(void) |
| 1064 | { |
| 1065 | struct cxio_rdev *rdev, *tmp; |
| 1066 | |
| 1067 | t3_register_cpl_handler(CPL_ASYNC_NOTIF, NULL); |
| 1068 | list_for_each_entry_safe(rdev, tmp, &rdev_list, entry) |
| 1069 | cxio_rdev_close(rdev); |
| 1070 | cxio_hal_destroy_rhdl_resource(); |
| 1071 | } |
| 1072 | |
Adrian Bunk | 2b54035 | 2007-02-21 11:52:49 +0100 | [diff] [blame] | 1073 | static void flush_completed_wrs(struct t3_wq *wq, struct t3_cq *cq) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1074 | { |
| 1075 | struct t3_swsq *sqp; |
| 1076 | __u32 ptr = wq->sq_rptr; |
| 1077 | int count = Q_COUNT(wq->sq_rptr, wq->sq_wptr); |
| 1078 | |
| 1079 | sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2); |
| 1080 | while (count--) |
| 1081 | if (!sqp->signaled) { |
| 1082 | ptr++; |
| 1083 | sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2); |
| 1084 | } else if (sqp->complete) { |
| 1085 | |
| 1086 | /* |
| 1087 | * Insert this completed cqe into the swcq. |
| 1088 | */ |
| 1089 | PDBG("%s moving cqe into swcq sq idx %ld cq idx %ld\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1090 | __func__, Q_PTR2IDX(ptr, wq->sq_size_log2), |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1091 | Q_PTR2IDX(cq->sw_wptr, cq->size_log2)); |
| 1092 | sqp->cqe.header |= htonl(V_CQE_SWCQE(1)); |
| 1093 | *(cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2)) |
| 1094 | = sqp->cqe; |
| 1095 | cq->sw_wptr++; |
| 1096 | sqp->signaled = 0; |
| 1097 | break; |
| 1098 | } else |
| 1099 | break; |
| 1100 | } |
| 1101 | |
Adrian Bunk | 2b54035 | 2007-02-21 11:52:49 +0100 | [diff] [blame] | 1102 | static void create_read_req_cqe(struct t3_wq *wq, struct t3_cqe *hw_cqe, |
| 1103 | struct t3_cqe *read_cqe) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1104 | { |
| 1105 | read_cqe->u.scqe.wrid_hi = wq->oldest_read->sq_wptr; |
| 1106 | read_cqe->len = wq->oldest_read->read_len; |
| 1107 | read_cqe->header = htonl(V_CQE_QPID(CQE_QPID(*hw_cqe)) | |
| 1108 | V_CQE_SWCQE(SW_CQE(*hw_cqe)) | |
| 1109 | V_CQE_OPCODE(T3_READ_REQ) | |
| 1110 | V_CQE_TYPE(1)); |
| 1111 | } |
| 1112 | |
| 1113 | /* |
| 1114 | * Return a ptr to the next read wr in the SWSQ or NULL. |
| 1115 | */ |
Adrian Bunk | 2b54035 | 2007-02-21 11:52:49 +0100 | [diff] [blame] | 1116 | static void advance_oldest_read(struct t3_wq *wq) |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1117 | { |
| 1118 | |
| 1119 | u32 rptr = wq->oldest_read - wq->sq + 1; |
| 1120 | u32 wptr = Q_PTR2IDX(wq->sq_wptr, wq->sq_size_log2); |
| 1121 | |
| 1122 | while (Q_PTR2IDX(rptr, wq->sq_size_log2) != wptr) { |
| 1123 | wq->oldest_read = wq->sq + Q_PTR2IDX(rptr, wq->sq_size_log2); |
| 1124 | |
| 1125 | if (wq->oldest_read->opcode == T3_READ_REQ) |
| 1126 | return; |
| 1127 | rptr++; |
| 1128 | } |
| 1129 | wq->oldest_read = NULL; |
| 1130 | } |
| 1131 | |
| 1132 | /* |
| 1133 | * cxio_poll_cq |
| 1134 | * |
| 1135 | * Caller must: |
| 1136 | * check the validity of the first CQE, |
| 1137 | * supply the wq assicated with the qpid. |
| 1138 | * |
| 1139 | * credit: cq credit to return to sge. |
| 1140 | * cqe_flushed: 1 iff the CQE is flushed. |
| 1141 | * cqe: copy of the polled CQE. |
| 1142 | * |
| 1143 | * return value: |
| 1144 | * 0 CQE returned, |
| 1145 | * -1 CQE skipped, try again. |
| 1146 | */ |
| 1147 | int cxio_poll_cq(struct t3_wq *wq, struct t3_cq *cq, struct t3_cqe *cqe, |
| 1148 | u8 *cqe_flushed, u64 *cookie, u32 *credit) |
| 1149 | { |
| 1150 | int ret = 0; |
| 1151 | struct t3_cqe *hw_cqe, read_cqe; |
| 1152 | |
| 1153 | *cqe_flushed = 0; |
| 1154 | *credit = 0; |
| 1155 | hw_cqe = cxio_next_cqe(cq); |
| 1156 | |
| 1157 | PDBG("%s CQE OOO %d qpid 0x%0x genbit %d type %d status 0x%0x" |
| 1158 | " opcode 0x%0x len 0x%0x wrid_hi_stag 0x%x wrid_low_msn 0x%x\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1159 | __func__, CQE_OOO(*hw_cqe), CQE_QPID(*hw_cqe), |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1160 | CQE_GENBIT(*hw_cqe), CQE_TYPE(*hw_cqe), CQE_STATUS(*hw_cqe), |
| 1161 | CQE_OPCODE(*hw_cqe), CQE_LEN(*hw_cqe), CQE_WRID_HI(*hw_cqe), |
| 1162 | CQE_WRID_LOW(*hw_cqe)); |
| 1163 | |
| 1164 | /* |
| 1165 | * skip cqe's not affiliated with a QP. |
| 1166 | */ |
| 1167 | if (wq == NULL) { |
| 1168 | ret = -1; |
| 1169 | goto skip_cqe; |
| 1170 | } |
| 1171 | |
| 1172 | /* |
| 1173 | * Gotta tweak READ completions: |
| 1174 | * 1) the cqe doesn't contain the sq_wptr from the wr. |
| 1175 | * 2) opcode not reflected from the wr. |
| 1176 | * 3) read_len not reflected from the wr. |
| 1177 | * 4) cq_type is RQ_TYPE not SQ_TYPE. |
| 1178 | */ |
| 1179 | if (RQ_TYPE(*hw_cqe) && (CQE_OPCODE(*hw_cqe) == T3_READ_RESP)) { |
| 1180 | |
| 1181 | /* |
Steve Wise | f8b0dfd | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 1182 | * If this is an unsolicited read response, then the read |
| 1183 | * was generated by the kernel driver as part of peer-2-peer |
| 1184 | * connection setup. So ignore the completion. |
| 1185 | */ |
| 1186 | if (!wq->oldest_read) { |
| 1187 | if (CQE_STATUS(*hw_cqe)) |
| 1188 | wq->error = 1; |
| 1189 | ret = -1; |
| 1190 | goto skip_cqe; |
| 1191 | } |
| 1192 | |
| 1193 | /* |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1194 | * Don't write to the HWCQ, so create a new read req CQE |
| 1195 | * in local memory. |
| 1196 | */ |
| 1197 | create_read_req_cqe(wq, hw_cqe, &read_cqe); |
| 1198 | hw_cqe = &read_cqe; |
| 1199 | advance_oldest_read(wq); |
| 1200 | } |
| 1201 | |
| 1202 | /* |
| 1203 | * T3A: Discard TERMINATE CQEs. |
| 1204 | */ |
| 1205 | if (CQE_OPCODE(*hw_cqe) == T3_TERMINATE) { |
| 1206 | ret = -1; |
| 1207 | wq->error = 1; |
| 1208 | goto skip_cqe; |
| 1209 | } |
| 1210 | |
| 1211 | if (CQE_STATUS(*hw_cqe) || wq->error) { |
| 1212 | *cqe_flushed = wq->error; |
| 1213 | wq->error = 1; |
| 1214 | |
| 1215 | /* |
| 1216 | * T3A inserts errors into the CQE. We cannot return |
| 1217 | * these as work completions. |
| 1218 | */ |
| 1219 | /* incoming write failures */ |
| 1220 | if ((CQE_OPCODE(*hw_cqe) == T3_RDMA_WRITE) |
| 1221 | && RQ_TYPE(*hw_cqe)) { |
| 1222 | ret = -1; |
| 1223 | goto skip_cqe; |
| 1224 | } |
| 1225 | /* incoming read request failures */ |
| 1226 | if ((CQE_OPCODE(*hw_cqe) == T3_READ_RESP) && SQ_TYPE(*hw_cqe)) { |
| 1227 | ret = -1; |
| 1228 | goto skip_cqe; |
| 1229 | } |
| 1230 | |
| 1231 | /* incoming SEND with no receive posted failures */ |
Steve Wise | 42fb61f | 2009-02-10 16:38:57 -0800 | [diff] [blame] | 1232 | if (CQE_SEND_OPCODE(*hw_cqe) && RQ_TYPE(*hw_cqe) && |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1233 | Q_EMPTY(wq->rq_rptr, wq->rq_wptr)) { |
| 1234 | ret = -1; |
| 1235 | goto skip_cqe; |
| 1236 | } |
Steve Wise | 42fb61f | 2009-02-10 16:38:57 -0800 | [diff] [blame] | 1237 | BUG_ON((*cqe_flushed == 0) && !SW_CQE(*hw_cqe)); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1238 | goto proc_cqe; |
| 1239 | } |
| 1240 | |
| 1241 | /* |
| 1242 | * RECV completion. |
| 1243 | */ |
| 1244 | if (RQ_TYPE(*hw_cqe)) { |
| 1245 | |
| 1246 | /* |
| 1247 | * HW only validates 4 bits of MSN. So we must validate that |
| 1248 | * the MSN in the SEND is the next expected MSN. If its not, |
| 1249 | * then we complete this with TPT_ERR_MSN and mark the wq in |
| 1250 | * error. |
| 1251 | */ |
Steve Wise | 42fb61f | 2009-02-10 16:38:57 -0800 | [diff] [blame] | 1252 | |
| 1253 | if (Q_EMPTY(wq->rq_rptr, wq->rq_wptr)) { |
| 1254 | wq->error = 1; |
| 1255 | ret = -1; |
| 1256 | goto skip_cqe; |
| 1257 | } |
| 1258 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1259 | if (unlikely((CQE_WRID_MSN(*hw_cqe) != (wq->rq_rptr + 1)))) { |
| 1260 | wq->error = 1; |
| 1261 | hw_cqe->header |= htonl(V_CQE_STATUS(TPT_ERR_MSN)); |
| 1262 | goto proc_cqe; |
| 1263 | } |
| 1264 | goto proc_cqe; |
| 1265 | } |
| 1266 | |
| 1267 | /* |
| 1268 | * If we get here its a send completion. |
| 1269 | * |
| 1270 | * Handle out of order completion. These get stuffed |
| 1271 | * in the SW SQ. Then the SW SQ is walked to move any |
| 1272 | * now in-order completions into the SW CQ. This handles |
| 1273 | * 2 cases: |
| 1274 | * 1) reaping unsignaled WRs when the first subsequent |
| 1275 | * signaled WR is completed. |
| 1276 | * 2) out of order read completions. |
| 1277 | */ |
| 1278 | if (!SW_CQE(*hw_cqe) && (CQE_WRID_SQ_WPTR(*hw_cqe) != wq->sq_rptr)) { |
| 1279 | struct t3_swsq *sqp; |
| 1280 | |
| 1281 | PDBG("%s out of order completion going in swsq at idx %ld\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1282 | __func__, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1283 | Q_PTR2IDX(CQE_WRID_SQ_WPTR(*hw_cqe), wq->sq_size_log2)); |
| 1284 | sqp = wq->sq + |
| 1285 | Q_PTR2IDX(CQE_WRID_SQ_WPTR(*hw_cqe), wq->sq_size_log2); |
| 1286 | sqp->cqe = *hw_cqe; |
| 1287 | sqp->complete = 1; |
| 1288 | ret = -1; |
| 1289 | goto flush_wq; |
| 1290 | } |
| 1291 | |
| 1292 | proc_cqe: |
| 1293 | *cqe = *hw_cqe; |
| 1294 | |
| 1295 | /* |
| 1296 | * Reap the associated WR(s) that are freed up with this |
| 1297 | * completion. |
| 1298 | */ |
| 1299 | if (SQ_TYPE(*hw_cqe)) { |
| 1300 | wq->sq_rptr = CQE_WRID_SQ_WPTR(*hw_cqe); |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1301 | PDBG("%s completing sq idx %ld\n", __func__, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1302 | Q_PTR2IDX(wq->sq_rptr, wq->sq_size_log2)); |
Steve Wise | 4ab928f | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1303 | *cookie = wq->sq[Q_PTR2IDX(wq->sq_rptr, wq->sq_size_log2)].wr_id; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1304 | wq->sq_rptr++; |
| 1305 | } else { |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1306 | PDBG("%s completing rq idx %ld\n", __func__, |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1307 | Q_PTR2IDX(wq->rq_rptr, wq->rq_size_log2)); |
Steve Wise | 4ab928f | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1308 | *cookie = wq->rq[Q_PTR2IDX(wq->rq_rptr, wq->rq_size_log2)].wr_id; |
| 1309 | if (wq->rq[Q_PTR2IDX(wq->rq_rptr, wq->rq_size_log2)].pbl_addr) |
| 1310 | cxio_hal_pblpool_free(wq->rdev, |
| 1311 | wq->rq[Q_PTR2IDX(wq->rq_rptr, |
| 1312 | wq->rq_size_log2)].pbl_addr, T3_STAG0_PBL_SIZE); |
Steve Wise | 42fb61f | 2009-02-10 16:38:57 -0800 | [diff] [blame] | 1313 | BUG_ON(Q_EMPTY(wq->rq_rptr, wq->rq_wptr)); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1314 | wq->rq_rptr++; |
| 1315 | } |
| 1316 | |
| 1317 | flush_wq: |
| 1318 | /* |
| 1319 | * Flush any completed cqes that are now in-order. |
| 1320 | */ |
| 1321 | flush_completed_wrs(wq, cq); |
| 1322 | |
| 1323 | skip_cqe: |
| 1324 | if (SW_CQE(*hw_cqe)) { |
| 1325 | PDBG("%s cq %p cqid 0x%x skip sw cqe sw_rptr 0x%x\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1326 | __func__, cq, cq->cqid, cq->sw_rptr); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1327 | ++cq->sw_rptr; |
| 1328 | } else { |
| 1329 | PDBG("%s cq %p cqid 0x%x skip hw cqe rptr 0x%x\n", |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1330 | __func__, cq, cq->cqid, cq->rptr); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1331 | ++cq->rptr; |
| 1332 | |
| 1333 | /* |
| 1334 | * T3A: compute credits. |
| 1335 | */ |
| 1336 | if (((cq->rptr - cq->wptr) > (1 << (cq->size_log2 - 1))) |
| 1337 | || ((cq->rptr - cq->wptr) >= 128)) { |
| 1338 | *credit = cq->rptr - cq->wptr; |
| 1339 | cq->wptr = cq->rptr; |
| 1340 | } |
| 1341 | } |
| 1342 | return ret; |
| 1343 | } |