Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved. |
| 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 | */ |
Paul Gortmaker | e4dd23d | 2011-05-27 15:35:46 -0400 | [diff] [blame] | 32 | |
| 33 | #include <linux/module.h> |
| 34 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 35 | #include "iw_cxgb4.h" |
| 36 | |
Vipul Pandya | 2c97478 | 2012-05-18 15:29:28 +0530 | [diff] [blame] | 37 | static int db_delay_usecs = 1; |
| 38 | module_param(db_delay_usecs, int, 0644); |
| 39 | MODULE_PARM_DESC(db_delay_usecs, "Usecs to delay awaiting db fifo to drain"); |
| 40 | |
Steve Wise | a9c7719 | 2011-03-11 22:30:11 +0000 | [diff] [blame] | 41 | static int ocqp_support = 1; |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 42 | module_param(ocqp_support, int, 0644); |
Steve Wise | a9c7719 | 2011-03-11 22:30:11 +0000 | [diff] [blame] | 43 | MODULE_PARM_DESC(ocqp_support, "Support on-chip SQs (default=1)"); |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 44 | |
Vipul Pandya | 3cbdb92 | 2013-03-14 05:08:59 +0000 | [diff] [blame] | 45 | int db_fc_threshold = 1000; |
Vipul Pandya | 422eea0 | 2012-05-18 15:29:30 +0530 | [diff] [blame] | 46 | module_param(db_fc_threshold, int, 0644); |
Vipul Pandya | 3cbdb92 | 2013-03-14 05:08:59 +0000 | [diff] [blame] | 47 | MODULE_PARM_DESC(db_fc_threshold, |
| 48 | "QP count/threshold that triggers" |
| 49 | " automatic db flow control mode (default = 1000)"); |
| 50 | |
| 51 | int db_coalescing_threshold; |
| 52 | module_param(db_coalescing_threshold, int, 0644); |
| 53 | MODULE_PARM_DESC(db_coalescing_threshold, |
| 54 | "QP count/threshold that triggers" |
| 55 | " disabling db coalescing (default = 0)"); |
Vipul Pandya | 422eea0 | 2012-05-18 15:29:30 +0530 | [diff] [blame] | 56 | |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 57 | static int max_fr_immd = T4_MAX_FR_IMMD; |
| 58 | module_param(max_fr_immd, int, 0644); |
| 59 | MODULE_PARM_DESC(max_fr_immd, "fastreg threshold for using DSGL instead of immedate"); |
| 60 | |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 61 | static int alloc_ird(struct c4iw_dev *dev, u32 ird) |
| 62 | { |
| 63 | int ret = 0; |
| 64 | |
| 65 | spin_lock_irq(&dev->lock); |
| 66 | if (ird <= dev->avail_ird) |
| 67 | dev->avail_ird -= ird; |
| 68 | else |
| 69 | ret = -ENOMEM; |
| 70 | spin_unlock_irq(&dev->lock); |
| 71 | |
| 72 | if (ret) |
| 73 | dev_warn(&dev->rdev.lldi.pdev->dev, |
| 74 | "device IRD resources exhausted\n"); |
| 75 | |
| 76 | return ret; |
| 77 | } |
| 78 | |
| 79 | static void free_ird(struct c4iw_dev *dev, int ird) |
| 80 | { |
| 81 | spin_lock_irq(&dev->lock); |
| 82 | dev->avail_ird += ird; |
| 83 | spin_unlock_irq(&dev->lock); |
| 84 | } |
| 85 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 86 | static void set_state(struct c4iw_qp *qhp, enum c4iw_qp_state state) |
| 87 | { |
| 88 | unsigned long flag; |
| 89 | spin_lock_irqsave(&qhp->lock, flag); |
| 90 | qhp->attr.state = state; |
| 91 | spin_unlock_irqrestore(&qhp->lock, flag); |
| 92 | } |
| 93 | |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 94 | static void dealloc_oc_sq(struct c4iw_rdev *rdev, struct t4_sq *sq) |
| 95 | { |
| 96 | c4iw_ocqp_pool_free(rdev, sq->dma_addr, sq->memsize); |
| 97 | } |
| 98 | |
| 99 | static void dealloc_host_sq(struct c4iw_rdev *rdev, struct t4_sq *sq) |
| 100 | { |
| 101 | dma_free_coherent(&(rdev->lldi.pdev->dev), sq->memsize, sq->queue, |
| 102 | pci_unmap_addr(sq, mapping)); |
| 103 | } |
| 104 | |
| 105 | static void dealloc_sq(struct c4iw_rdev *rdev, struct t4_sq *sq) |
| 106 | { |
| 107 | if (t4_sq_onchip(sq)) |
| 108 | dealloc_oc_sq(rdev, sq); |
| 109 | else |
| 110 | dealloc_host_sq(rdev, sq); |
| 111 | } |
| 112 | |
| 113 | static int alloc_oc_sq(struct c4iw_rdev *rdev, struct t4_sq *sq) |
| 114 | { |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 115 | if (!ocqp_support || !ocqp_supported(&rdev->lldi)) |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 116 | return -ENOSYS; |
| 117 | sq->dma_addr = c4iw_ocqp_pool_alloc(rdev, sq->memsize); |
| 118 | if (!sq->dma_addr) |
| 119 | return -ENOMEM; |
| 120 | sq->phys_addr = rdev->oc_mw_pa + sq->dma_addr - |
| 121 | rdev->lldi.vr->ocq.start; |
| 122 | sq->queue = (__force union t4_wr *)(rdev->oc_mw_kva + sq->dma_addr - |
| 123 | rdev->lldi.vr->ocq.start); |
| 124 | sq->flags |= T4_SQ_ONCHIP; |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static int alloc_host_sq(struct c4iw_rdev *rdev, struct t4_sq *sq) |
| 129 | { |
| 130 | sq->queue = dma_alloc_coherent(&(rdev->lldi.pdev->dev), sq->memsize, |
| 131 | &(sq->dma_addr), GFP_KERNEL); |
| 132 | if (!sq->queue) |
| 133 | return -ENOMEM; |
| 134 | sq->phys_addr = virt_to_phys(sq->queue); |
| 135 | pci_unmap_addr_set(sq, mapping, sq->dma_addr); |
| 136 | return 0; |
| 137 | } |
| 138 | |
Thadeu Lima de Souza Cascardo | 5b0c275 | 2013-04-01 20:13:39 +0000 | [diff] [blame] | 139 | static int alloc_sq(struct c4iw_rdev *rdev, struct t4_sq *sq, int user) |
| 140 | { |
| 141 | int ret = -ENOSYS; |
| 142 | if (user) |
| 143 | ret = alloc_oc_sq(rdev, sq); |
| 144 | if (ret) |
| 145 | ret = alloc_host_sq(rdev, sq); |
| 146 | return ret; |
| 147 | } |
| 148 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 149 | static int destroy_qp(struct c4iw_rdev *rdev, struct t4_wq *wq, |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 150 | struct c4iw_dev_ucontext *uctx, int has_rq) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 151 | { |
| 152 | /* |
| 153 | * uP clears EQ contexts when the connection exits rdma mode, |
| 154 | * so no need to post a RESET WR for these EQs. |
| 155 | */ |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 156 | dealloc_sq(rdev, &wq->sq); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 157 | kfree(wq->sq.sw_sq); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 158 | c4iw_put_qpid(rdev, wq->sq.qid, uctx); |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 159 | |
| 160 | if (has_rq) { |
| 161 | dma_free_coherent(&rdev->lldi.pdev->dev, |
| 162 | wq->rq.memsize, wq->rq.queue, |
| 163 | dma_unmap_addr(&wq->rq, mapping)); |
| 164 | c4iw_rqtpool_free(rdev, wq->rq.rqt_hwaddr, wq->rq.rqt_size); |
| 165 | kfree(wq->rq.sw_rq); |
| 166 | c4iw_put_qpid(rdev, wq->rq.qid, uctx); |
| 167 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
Hariprasad S | 74217d4 | 2015-06-09 18:23:12 +0530 | [diff] [blame] | 171 | /* |
| 172 | * Determine the BAR2 virtual address and qid. If pbar2_pa is not NULL, |
| 173 | * then this is a user mapping so compute the page-aligned physical address |
| 174 | * for mapping. |
| 175 | */ |
| 176 | void __iomem *c4iw_bar2_addrs(struct c4iw_rdev *rdev, unsigned int qid, |
| 177 | enum cxgb4_bar2_qtype qtype, |
| 178 | unsigned int *pbar2_qid, u64 *pbar2_pa) |
| 179 | { |
| 180 | u64 bar2_qoffset; |
| 181 | int ret; |
| 182 | |
| 183 | ret = cxgb4_bar2_sge_qregs(rdev->lldi.ports[0], qid, qtype, |
| 184 | pbar2_pa ? 1 : 0, |
| 185 | &bar2_qoffset, pbar2_qid); |
| 186 | if (ret) |
| 187 | return NULL; |
| 188 | |
| 189 | if (pbar2_pa) |
| 190 | *pbar2_pa = (rdev->bar2_pa + bar2_qoffset) & PAGE_MASK; |
Hariprasad S | 32cc92c | 2016-04-05 10:23:48 +0530 | [diff] [blame] | 191 | |
| 192 | if (is_t4(rdev->lldi.adapter_type)) |
| 193 | return NULL; |
| 194 | |
Hariprasad S | 74217d4 | 2015-06-09 18:23:12 +0530 | [diff] [blame] | 195 | return rdev->bar2_kva + bar2_qoffset; |
| 196 | } |
| 197 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 198 | static int create_qp(struct c4iw_rdev *rdev, struct t4_wq *wq, |
| 199 | struct t4_cq *rcq, struct t4_cq *scq, |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 200 | struct c4iw_dev_ucontext *uctx, |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 201 | struct c4iw_wr_wait *wr_waitp, |
| 202 | int need_rq) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 203 | { |
| 204 | int user = (uctx != &rdev->uctx); |
| 205 | struct fw_ri_res_wr *res_wr; |
| 206 | struct fw_ri_res *res; |
| 207 | int wr_len; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 208 | struct sk_buff *skb; |
Vipul Pandya | 9919d5b | 2013-03-14 05:09:04 +0000 | [diff] [blame] | 209 | int ret = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 210 | int eqsize; |
| 211 | |
| 212 | wq->sq.qid = c4iw_get_qpid(rdev, uctx); |
| 213 | if (!wq->sq.qid) |
| 214 | return -ENOMEM; |
| 215 | |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 216 | if (need_rq) { |
| 217 | wq->rq.qid = c4iw_get_qpid(rdev, uctx); |
| 218 | if (!wq->rq.qid) { |
| 219 | ret = -ENOMEM; |
| 220 | goto free_sq_qid; |
| 221 | } |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 222 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 223 | |
| 224 | if (!user) { |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 225 | wq->sq.sw_sq = kcalloc(wq->sq.size, sizeof(*wq->sq.sw_sq), |
| 226 | GFP_KERNEL); |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 227 | if (!wq->sq.sw_sq) { |
| 228 | ret = -ENOMEM; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 229 | goto free_rq_qid;//FIXME |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 230 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 231 | |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 232 | if (need_rq) { |
| 233 | wq->rq.sw_rq = kcalloc(wq->rq.size, |
| 234 | sizeof(*wq->rq.sw_rq), |
| 235 | GFP_KERNEL); |
| 236 | if (!wq->rq.sw_rq) { |
| 237 | ret = -ENOMEM; |
| 238 | goto free_sw_sq; |
| 239 | } |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 240 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 243 | if (need_rq) { |
| 244 | /* |
| 245 | * RQT must be a power of 2 and at least 16 deep. |
| 246 | */ |
| 247 | wq->rq.rqt_size = |
| 248 | roundup_pow_of_two(max_t(u16, wq->rq.size, 16)); |
| 249 | wq->rq.rqt_hwaddr = c4iw_rqtpool_alloc(rdev, wq->rq.rqt_size); |
| 250 | if (!wq->rq.rqt_hwaddr) { |
| 251 | ret = -ENOMEM; |
| 252 | goto free_sw_rq; |
| 253 | } |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 254 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 255 | |
Thadeu Lima de Souza Cascardo | 5b0c275 | 2013-04-01 20:13:39 +0000 | [diff] [blame] | 256 | ret = alloc_sq(rdev, &wq->sq, user); |
| 257 | if (ret) |
| 258 | goto free_hwaddr; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 259 | memset(wq->sq.queue, 0, wq->sq.memsize); |
FUJITA Tomonori | f38926a | 2010-06-03 05:37:50 +0000 | [diff] [blame] | 260 | dma_unmap_addr_set(&wq->sq, mapping, wq->sq.dma_addr); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 261 | |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 262 | if (need_rq) { |
| 263 | wq->rq.queue = dma_alloc_coherent(&rdev->lldi.pdev->dev, |
| 264 | wq->rq.memsize, |
| 265 | &wq->rq.dma_addr, |
| 266 | GFP_KERNEL); |
| 267 | if (!wq->rq.queue) { |
| 268 | ret = -ENOMEM; |
| 269 | goto free_sq; |
| 270 | } |
| 271 | pr_debug("sq base va 0x%p pa 0x%llx rq base va 0x%p pa 0x%llx\n", |
| 272 | wq->sq.queue, |
| 273 | (unsigned long long)virt_to_phys(wq->sq.queue), |
| 274 | wq->rq.queue, |
| 275 | (unsigned long long)virt_to_phys(wq->rq.queue)); |
| 276 | memset(wq->rq.queue, 0, wq->rq.memsize); |
| 277 | dma_unmap_addr_set(&wq->rq, mapping, wq->rq.dma_addr); |
Wei Yongjun | 55e57a7 | 2013-03-15 09:42:12 +0000 | [diff] [blame] | 278 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 279 | |
| 280 | wq->db = rdev->lldi.db_reg; |
Steve Wise | fa658a9 | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 281 | |
Hariprasad S | 74217d4 | 2015-06-09 18:23:12 +0530 | [diff] [blame] | 282 | wq->sq.bar2_va = c4iw_bar2_addrs(rdev, wq->sq.qid, T4_BAR2_QTYPE_EGRESS, |
| 283 | &wq->sq.bar2_qid, |
| 284 | user ? &wq->sq.bar2_pa : NULL); |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 285 | if (need_rq) |
| 286 | wq->rq.bar2_va = c4iw_bar2_addrs(rdev, wq->rq.qid, |
| 287 | T4_BAR2_QTYPE_EGRESS, |
| 288 | &wq->rq.bar2_qid, |
| 289 | user ? &wq->rq.bar2_pa : NULL); |
Hariprasad S | 74217d4 | 2015-06-09 18:23:12 +0530 | [diff] [blame] | 290 | |
| 291 | /* |
| 292 | * User mode must have bar2 access. |
| 293 | */ |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 294 | if (user && (!wq->sq.bar2_pa || (need_rq && !wq->rq.bar2_pa))) { |
Joe Perches | 700456b | 2017-02-09 14:23:50 -0800 | [diff] [blame] | 295 | pr_warn("%s: sqid %u or rqid %u not in BAR2 range\n", |
Hariprasad S | 74217d4 | 2015-06-09 18:23:12 +0530 | [diff] [blame] | 296 | pci_name(rdev->lldi.pdev), wq->sq.qid, wq->rq.qid); |
| 297 | goto free_dma; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 298 | } |
Hariprasad S | 74217d4 | 2015-06-09 18:23:12 +0530 | [diff] [blame] | 299 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 300 | wq->rdev = rdev; |
| 301 | wq->rq.msn = 1; |
| 302 | |
| 303 | /* build fw_ri_res_wr */ |
| 304 | wr_len = sizeof *res_wr + 2 * sizeof *res; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 305 | if (need_rq) |
| 306 | wr_len += sizeof(*res); |
David Rientjes | d3c814e | 2010-07-21 02:44:56 +0000 | [diff] [blame] | 307 | skb = alloc_skb(wr_len, GFP_KERNEL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 308 | if (!skb) { |
| 309 | ret = -ENOMEM; |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 310 | goto free_dma; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 311 | } |
| 312 | set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0); |
| 313 | |
yuan linyu | de77b96 | 2017-06-18 22:48:17 +0800 | [diff] [blame] | 314 | res_wr = __skb_put_zero(skb, wr_len); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 315 | res_wr->op_nres = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 316 | FW_WR_OP_V(FW_RI_RES_WR) | |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 317 | FW_RI_RES_WR_NRES_V(need_rq ? 2 : 1) | |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 318 | FW_WR_COMPL_F); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 319 | res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16)); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 320 | res_wr->cookie = (uintptr_t)wr_waitp; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 321 | res = res_wr->res; |
| 322 | res->u.sqrq.restype = FW_RI_RES_TYPE_SQ; |
| 323 | res->u.sqrq.op = FW_RI_RES_OP_WRITE; |
| 324 | |
| 325 | /* |
| 326 | * eqsize is the number of 64B entries plus the status page size. |
| 327 | */ |
Hariprasad Shenai | 04e10e2 | 2014-07-14 21:34:51 +0530 | [diff] [blame] | 328 | eqsize = wq->sq.size * T4_SQ_NUM_SLOTS + |
| 329 | rdev->hw_queue.t4_eq_status_entries; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 330 | |
| 331 | res->u.sqrq.fetchszm_to_iqid = cpu_to_be32( |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 332 | FW_RI_RES_WR_HOSTFCMODE_V(0) | /* no host cidx updates */ |
| 333 | FW_RI_RES_WR_CPRIO_V(0) | /* don't keep in chip cache */ |
| 334 | FW_RI_RES_WR_PCIECHN_V(0) | /* set by uP at ri_init time */ |
| 335 | (t4_sq_onchip(&wq->sq) ? FW_RI_RES_WR_ONCHIP_F : 0) | |
| 336 | FW_RI_RES_WR_IQID_V(scq->cqid)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 337 | res->u.sqrq.dcaen_to_eqsize = cpu_to_be32( |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 338 | FW_RI_RES_WR_DCAEN_V(0) | |
| 339 | FW_RI_RES_WR_DCACPU_V(0) | |
| 340 | FW_RI_RES_WR_FBMIN_V(2) | |
Steve Wise | b414fa0 | 2016-12-15 08:09:35 -0800 | [diff] [blame] | 341 | (t4_sq_onchip(&wq->sq) ? FW_RI_RES_WR_FBMAX_V(2) : |
| 342 | FW_RI_RES_WR_FBMAX_V(3)) | |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 343 | FW_RI_RES_WR_CIDXFTHRESHO_V(0) | |
| 344 | FW_RI_RES_WR_CIDXFTHRESH_V(0) | |
| 345 | FW_RI_RES_WR_EQSIZE_V(eqsize)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 346 | res->u.sqrq.eqid = cpu_to_be32(wq->sq.qid); |
| 347 | res->u.sqrq.eqaddr = cpu_to_be64(wq->sq.dma_addr); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 348 | |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 349 | if (need_rq) { |
| 350 | res++; |
| 351 | res->u.sqrq.restype = FW_RI_RES_TYPE_RQ; |
| 352 | res->u.sqrq.op = FW_RI_RES_OP_WRITE; |
| 353 | |
| 354 | /* |
| 355 | * eqsize is the number of 64B entries plus the status page size |
| 356 | */ |
| 357 | eqsize = wq->rq.size * T4_RQ_NUM_SLOTS + |
| 358 | rdev->hw_queue.t4_eq_status_entries; |
| 359 | res->u.sqrq.fetchszm_to_iqid = |
| 360 | /* no host cidx updates */ |
| 361 | cpu_to_be32(FW_RI_RES_WR_HOSTFCMODE_V(0) | |
| 362 | /* don't keep in chip cache */ |
| 363 | FW_RI_RES_WR_CPRIO_V(0) | |
| 364 | /* set by uP at ri_init time */ |
| 365 | FW_RI_RES_WR_PCIECHN_V(0) | |
| 366 | FW_RI_RES_WR_IQID_V(rcq->cqid)); |
| 367 | res->u.sqrq.dcaen_to_eqsize = |
| 368 | cpu_to_be32(FW_RI_RES_WR_DCAEN_V(0) | |
| 369 | FW_RI_RES_WR_DCACPU_V(0) | |
| 370 | FW_RI_RES_WR_FBMIN_V(2) | |
| 371 | FW_RI_RES_WR_FBMAX_V(3) | |
| 372 | FW_RI_RES_WR_CIDXFTHRESHO_V(0) | |
| 373 | FW_RI_RES_WR_CIDXFTHRESH_V(0) | |
| 374 | FW_RI_RES_WR_EQSIZE_V(eqsize)); |
| 375 | res->u.sqrq.eqid = cpu_to_be32(wq->rq.qid); |
| 376 | res->u.sqrq.eqaddr = cpu_to_be64(wq->rq.dma_addr); |
| 377 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 378 | |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 379 | c4iw_init_wr_wait(wr_waitp); |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 380 | ret = c4iw_ref_send_wait(rdev, skb, wr_waitp, 0, wq->sq.qid, __func__); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 381 | if (ret) |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 382 | goto free_dma; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 383 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 384 | pr_debug("sqid 0x%x rqid 0x%x kdb 0x%p sq_bar2_addr %p rq_bar2_addr %p\n", |
| 385 | wq->sq.qid, wq->rq.qid, wq->db, |
Joe Perches | a9a4288 | 2017-02-09 14:23:51 -0800 | [diff] [blame] | 386 | wq->sq.bar2_va, wq->rq.bar2_va); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 387 | |
| 388 | return 0; |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 389 | free_dma: |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 390 | if (need_rq) |
| 391 | dma_free_coherent(&rdev->lldi.pdev->dev, |
| 392 | wq->rq.memsize, wq->rq.queue, |
| 393 | dma_unmap_addr(&wq->rq, mapping)); |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 394 | free_sq: |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 395 | dealloc_sq(rdev, &wq->sq); |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 396 | free_hwaddr: |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 397 | if (need_rq) |
| 398 | c4iw_rqtpool_free(rdev, wq->rq.rqt_hwaddr, wq->rq.rqt_size); |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 399 | free_sw_rq: |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 400 | if (need_rq) |
| 401 | kfree(wq->rq.sw_rq); |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 402 | free_sw_sq: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 403 | kfree(wq->sq.sw_sq); |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 404 | free_rq_qid: |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 405 | if (need_rq) |
| 406 | c4iw_put_qpid(rdev, wq->rq.qid, uctx); |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 407 | free_sq_qid: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 408 | c4iw_put_qpid(rdev, wq->sq.qid, uctx); |
Emil Goode | c079c28 | 2012-08-19 17:59:40 +0000 | [diff] [blame] | 409 | return ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 412 | static int build_immd(struct t4_sq *sq, struct fw_ri_immd *immdp, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 413 | const struct ib_send_wr *wr, int max, u32 *plenp) |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 414 | { |
| 415 | u8 *dstp, *srcp; |
| 416 | u32 plen = 0; |
| 417 | int i; |
| 418 | int rem, len; |
| 419 | |
| 420 | dstp = (u8 *)immdp->data; |
| 421 | for (i = 0; i < wr->num_sge; i++) { |
| 422 | if ((plen + wr->sg_list[i].length) > max) |
| 423 | return -EMSGSIZE; |
| 424 | srcp = (u8 *)(unsigned long)wr->sg_list[i].addr; |
| 425 | plen += wr->sg_list[i].length; |
| 426 | rem = wr->sg_list[i].length; |
| 427 | while (rem) { |
| 428 | if (dstp == (u8 *)&sq->queue[sq->size]) |
| 429 | dstp = (u8 *)sq->queue; |
| 430 | if (rem <= (u8 *)&sq->queue[sq->size] - dstp) |
| 431 | len = rem; |
| 432 | else |
| 433 | len = (u8 *)&sq->queue[sq->size] - dstp; |
| 434 | memcpy(dstp, srcp, len); |
| 435 | dstp += len; |
| 436 | srcp += len; |
| 437 | rem -= len; |
| 438 | } |
| 439 | } |
Steve Wise | 13fecb8 | 2010-09-10 11:14:53 -0500 | [diff] [blame] | 440 | len = roundup(plen + sizeof *immdp, 16) - (plen + sizeof *immdp); |
| 441 | if (len) |
| 442 | memset(dstp, 0, len); |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 443 | immdp->op = FW_RI_DATA_IMMD; |
| 444 | immdp->r1 = 0; |
| 445 | immdp->r2 = 0; |
| 446 | immdp->immdlen = cpu_to_be32(plen); |
| 447 | *plenp = plen; |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static int build_isgl(__be64 *queue_start, __be64 *queue_end, |
| 452 | struct fw_ri_isgl *isglp, struct ib_sge *sg_list, |
| 453 | int num_sge, u32 *plenp) |
| 454 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 455 | { |
| 456 | int i; |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 457 | u32 plen = 0; |
Potnuri Bharat Teja | 94245f4 | 2018-08-02 11:33:04 +0530 | [diff] [blame] | 458 | __be64 *flitp; |
| 459 | |
| 460 | if ((__be64 *)isglp == queue_end) |
| 461 | isglp = (struct fw_ri_isgl *)queue_start; |
| 462 | |
| 463 | flitp = (__be64 *)isglp->sge; |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 464 | |
| 465 | for (i = 0; i < num_sge; i++) { |
| 466 | if ((plen + sg_list[i].length) < plen) |
| 467 | return -EMSGSIZE; |
| 468 | plen += sg_list[i].length; |
| 469 | *flitp = cpu_to_be64(((u64)sg_list[i].lkey << 32) | |
| 470 | sg_list[i].length); |
| 471 | if (++flitp == queue_end) |
| 472 | flitp = queue_start; |
| 473 | *flitp = cpu_to_be64(sg_list[i].addr); |
| 474 | if (++flitp == queue_end) |
| 475 | flitp = queue_start; |
| 476 | } |
Steve Wise | 13fecb8 | 2010-09-10 11:14:53 -0500 | [diff] [blame] | 477 | *flitp = (__force __be64)0; |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 478 | isglp->op = FW_RI_DATA_ISGL; |
| 479 | isglp->r1 = 0; |
| 480 | isglp->nsge = cpu_to_be16(num_sge); |
| 481 | isglp->r2 = 0; |
| 482 | if (plenp) |
| 483 | *plenp = plen; |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static int build_rdma_send(struct t4_sq *sq, union t4_wr *wqe, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 488 | const struct ib_send_wr *wr, u8 *len16) |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 489 | { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 490 | u32 plen; |
| 491 | int size; |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 492 | int ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 493 | |
| 494 | if (wr->num_sge > T4_MAX_SEND_SGE) |
| 495 | return -EINVAL; |
| 496 | switch (wr->opcode) { |
| 497 | case IB_WR_SEND: |
| 498 | if (wr->send_flags & IB_SEND_SOLICITED) |
| 499 | wqe->send.sendop_pkd = cpu_to_be32( |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 500 | FW_RI_SEND_WR_SENDOP_V(FW_RI_SEND_WITH_SE)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 501 | else |
| 502 | wqe->send.sendop_pkd = cpu_to_be32( |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 503 | FW_RI_SEND_WR_SENDOP_V(FW_RI_SEND)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 504 | wqe->send.stag_inv = 0; |
| 505 | break; |
| 506 | case IB_WR_SEND_WITH_INV: |
| 507 | if (wr->send_flags & IB_SEND_SOLICITED) |
| 508 | wqe->send.sendop_pkd = cpu_to_be32( |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 509 | FW_RI_SEND_WR_SENDOP_V(FW_RI_SEND_WITH_SE_INV)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 510 | else |
| 511 | wqe->send.sendop_pkd = cpu_to_be32( |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 512 | FW_RI_SEND_WR_SENDOP_V(FW_RI_SEND_WITH_INV)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 513 | wqe->send.stag_inv = cpu_to_be32(wr->ex.invalidate_rkey); |
| 514 | break; |
| 515 | |
| 516 | default: |
| 517 | return -EINVAL; |
| 518 | } |
Steve Wise | c3f98fa | 2014-04-09 09:38:27 -0500 | [diff] [blame] | 519 | wqe->send.r3 = 0; |
| 520 | wqe->send.r4 = 0; |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 521 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 522 | plen = 0; |
| 523 | if (wr->num_sge) { |
| 524 | if (wr->send_flags & IB_SEND_INLINE) { |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 525 | ret = build_immd(sq, wqe->send.u.immd_src, wr, |
| 526 | T4_MAX_SEND_INLINE, &plen); |
| 527 | if (ret) |
| 528 | return ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 529 | size = sizeof wqe->send + sizeof(struct fw_ri_immd) + |
| 530 | plen; |
| 531 | } else { |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 532 | ret = build_isgl((__be64 *)sq->queue, |
| 533 | (__be64 *)&sq->queue[sq->size], |
| 534 | wqe->send.u.isgl_src, |
| 535 | wr->sg_list, wr->num_sge, &plen); |
| 536 | if (ret) |
| 537 | return ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 538 | size = sizeof wqe->send + sizeof(struct fw_ri_isgl) + |
| 539 | wr->num_sge * sizeof(struct fw_ri_sge); |
| 540 | } |
| 541 | } else { |
| 542 | wqe->send.u.immd_src[0].op = FW_RI_DATA_IMMD; |
| 543 | wqe->send.u.immd_src[0].r1 = 0; |
| 544 | wqe->send.u.immd_src[0].r2 = 0; |
| 545 | wqe->send.u.immd_src[0].immdlen = 0; |
| 546 | size = sizeof wqe->send + sizeof(struct fw_ri_immd); |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 547 | plen = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 548 | } |
| 549 | *len16 = DIV_ROUND_UP(size, 16); |
| 550 | wqe->send.plen = cpu_to_be32(plen); |
| 551 | return 0; |
| 552 | } |
| 553 | |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 554 | static int build_rdma_write(struct t4_sq *sq, union t4_wr *wqe, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 555 | const struct ib_send_wr *wr, u8 *len16) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 556 | { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 557 | u32 plen; |
| 558 | int size; |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 559 | int ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 560 | |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 561 | if (wr->num_sge > T4_MAX_SEND_SGE) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 562 | return -EINVAL; |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 563 | |
| 564 | /* |
| 565 | * iWARP protocol supports 64 bit immediate data but rdma api |
| 566 | * limits it to 32bit. |
| 567 | */ |
| 568 | if (wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM) |
| 569 | wqe->write.iw_imm_data.ib_imm_data.imm_data32 = wr->ex.imm_data; |
| 570 | else |
| 571 | wqe->write.iw_imm_data.ib_imm_data.imm_data32 = 0; |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 572 | wqe->write.stag_sink = cpu_to_be32(rdma_wr(wr)->rkey); |
| 573 | wqe->write.to_sink = cpu_to_be64(rdma_wr(wr)->remote_addr); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 574 | if (wr->num_sge) { |
| 575 | if (wr->send_flags & IB_SEND_INLINE) { |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 576 | ret = build_immd(sq, wqe->write.u.immd_src, wr, |
| 577 | T4_MAX_WRITE_INLINE, &plen); |
| 578 | if (ret) |
| 579 | return ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 580 | size = sizeof wqe->write + sizeof(struct fw_ri_immd) + |
| 581 | plen; |
| 582 | } else { |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 583 | ret = build_isgl((__be64 *)sq->queue, |
| 584 | (__be64 *)&sq->queue[sq->size], |
| 585 | wqe->write.u.isgl_src, |
| 586 | wr->sg_list, wr->num_sge, &plen); |
| 587 | if (ret) |
| 588 | return ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 589 | size = sizeof wqe->write + sizeof(struct fw_ri_isgl) + |
| 590 | wr->num_sge * sizeof(struct fw_ri_sge); |
| 591 | } |
| 592 | } else { |
| 593 | wqe->write.u.immd_src[0].op = FW_RI_DATA_IMMD; |
| 594 | wqe->write.u.immd_src[0].r1 = 0; |
| 595 | wqe->write.u.immd_src[0].r2 = 0; |
| 596 | wqe->write.u.immd_src[0].immdlen = 0; |
| 597 | size = sizeof wqe->write + sizeof(struct fw_ri_immd); |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 598 | plen = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 599 | } |
| 600 | *len16 = DIV_ROUND_UP(size, 16); |
| 601 | wqe->write.plen = cpu_to_be32(plen); |
| 602 | return 0; |
| 603 | } |
| 604 | |
Potnuri Bharat Teja | 94245f4 | 2018-08-02 11:33:04 +0530 | [diff] [blame] | 605 | static void build_immd_cmpl(struct t4_sq *sq, struct fw_ri_immd_cmpl *immdp, |
| 606 | struct ib_send_wr *wr) |
| 607 | { |
| 608 | memcpy((u8 *)immdp->data, (u8 *)(uintptr_t)wr->sg_list->addr, 16); |
| 609 | memset(immdp->r1, 0, 6); |
| 610 | immdp->op = FW_RI_DATA_IMMD; |
| 611 | immdp->immdlen = 16; |
| 612 | } |
| 613 | |
| 614 | static void build_rdma_write_cmpl(struct t4_sq *sq, |
| 615 | struct fw_ri_rdma_write_cmpl_wr *wcwr, |
| 616 | const struct ib_send_wr *wr, u8 *len16) |
| 617 | { |
| 618 | u32 plen; |
| 619 | int size; |
| 620 | |
| 621 | /* |
| 622 | * This code assumes the struct fields preceding the write isgl |
| 623 | * fit in one 64B WR slot. This is because the WQE is built |
| 624 | * directly in the dma queue, and wrapping is only handled |
| 625 | * by the code buildling sgls. IE the "fixed part" of the wr |
| 626 | * structs must all fit in 64B. The WQE build code should probably be |
| 627 | * redesigned to avoid this restriction, but for now just add |
| 628 | * the BUILD_BUG_ON() to catch if this WQE struct gets too big. |
| 629 | */ |
| 630 | BUILD_BUG_ON(offsetof(struct fw_ri_rdma_write_cmpl_wr, u) > 64); |
| 631 | |
| 632 | wcwr->stag_sink = cpu_to_be32(rdma_wr(wr)->rkey); |
| 633 | wcwr->to_sink = cpu_to_be64(rdma_wr(wr)->remote_addr); |
| 634 | wcwr->stag_inv = cpu_to_be32(wr->next->ex.invalidate_rkey); |
| 635 | wcwr->r2 = 0; |
| 636 | wcwr->r3 = 0; |
| 637 | |
| 638 | /* SEND_INV SGL */ |
| 639 | if (wr->next->send_flags & IB_SEND_INLINE) |
| 640 | build_immd_cmpl(sq, &wcwr->u_cmpl.immd_src, wr->next); |
| 641 | else |
| 642 | build_isgl((__be64 *)sq->queue, (__be64 *)&sq->queue[sq->size], |
| 643 | &wcwr->u_cmpl.isgl_src, wr->next->sg_list, 1, NULL); |
| 644 | |
| 645 | /* WRITE SGL */ |
| 646 | build_isgl((__be64 *)sq->queue, (__be64 *)&sq->queue[sq->size], |
| 647 | wcwr->u.isgl_src, wr->sg_list, wr->num_sge, &plen); |
| 648 | |
| 649 | size = sizeof(*wcwr) + sizeof(struct fw_ri_isgl) + |
| 650 | wr->num_sge * sizeof(struct fw_ri_sge); |
| 651 | wcwr->plen = cpu_to_be32(plen); |
| 652 | *len16 = DIV_ROUND_UP(size, 16); |
| 653 | } |
| 654 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 655 | static int build_rdma_read(union t4_wr *wqe, const struct ib_send_wr *wr, |
| 656 | u8 *len16) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 657 | { |
| 658 | if (wr->num_sge > 1) |
| 659 | return -EINVAL; |
Ganesh Goudar | 720336c | 2017-06-21 19:55:43 +0530 | [diff] [blame] | 660 | if (wr->num_sge && wr->sg_list[0].length) { |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 661 | wqe->read.stag_src = cpu_to_be32(rdma_wr(wr)->rkey); |
| 662 | wqe->read.to_src_hi = cpu_to_be32((u32)(rdma_wr(wr)->remote_addr |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 663 | >> 32)); |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 664 | wqe->read.to_src_lo = cpu_to_be32((u32)rdma_wr(wr)->remote_addr); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 665 | wqe->read.stag_sink = cpu_to_be32(wr->sg_list[0].lkey); |
| 666 | wqe->read.plen = cpu_to_be32(wr->sg_list[0].length); |
| 667 | wqe->read.to_sink_hi = cpu_to_be32((u32)(wr->sg_list[0].addr |
| 668 | >> 32)); |
| 669 | wqe->read.to_sink_lo = cpu_to_be32((u32)(wr->sg_list[0].addr)); |
| 670 | } else { |
| 671 | wqe->read.stag_src = cpu_to_be32(2); |
| 672 | wqe->read.to_src_hi = 0; |
| 673 | wqe->read.to_src_lo = 0; |
| 674 | wqe->read.stag_sink = cpu_to_be32(2); |
| 675 | wqe->read.plen = 0; |
| 676 | wqe->read.to_sink_hi = 0; |
| 677 | wqe->read.to_sink_lo = 0; |
| 678 | } |
| 679 | wqe->read.r2 = 0; |
| 680 | wqe->read.r5 = 0; |
| 681 | *len16 = DIV_ROUND_UP(sizeof wqe->read, 16); |
| 682 | return 0; |
| 683 | } |
| 684 | |
Potnuri Bharat Teja | 94245f4 | 2018-08-02 11:33:04 +0530 | [diff] [blame] | 685 | static void post_write_cmpl(struct c4iw_qp *qhp, const struct ib_send_wr *wr) |
| 686 | { |
| 687 | bool send_signaled = (wr->next->send_flags & IB_SEND_SIGNALED) || |
| 688 | qhp->sq_sig_all; |
| 689 | bool write_signaled = (wr->send_flags & IB_SEND_SIGNALED) || |
| 690 | qhp->sq_sig_all; |
| 691 | struct t4_swsqe *swsqe; |
| 692 | union t4_wr *wqe; |
| 693 | u16 write_wrid; |
| 694 | u8 len16; |
| 695 | u16 idx; |
| 696 | |
| 697 | /* |
| 698 | * The sw_sq entries still look like a WRITE and a SEND and consume |
| 699 | * 2 slots. The FW WR, however, will be a single uber-WR. |
| 700 | */ |
| 701 | wqe = (union t4_wr *)((u8 *)qhp->wq.sq.queue + |
| 702 | qhp->wq.sq.wq_pidx * T4_EQ_ENTRY_SIZE); |
| 703 | build_rdma_write_cmpl(&qhp->wq.sq, &wqe->write_cmpl, wr, &len16); |
| 704 | |
| 705 | /* WRITE swsqe */ |
| 706 | swsqe = &qhp->wq.sq.sw_sq[qhp->wq.sq.pidx]; |
| 707 | swsqe->opcode = FW_RI_RDMA_WRITE; |
| 708 | swsqe->idx = qhp->wq.sq.pidx; |
| 709 | swsqe->complete = 0; |
| 710 | swsqe->signaled = write_signaled; |
| 711 | swsqe->flushed = 0; |
| 712 | swsqe->wr_id = wr->wr_id; |
| 713 | if (c4iw_wr_log) { |
| 714 | swsqe->sge_ts = |
| 715 | cxgb4_read_sge_timestamp(qhp->rhp->rdev.lldi.ports[0]); |
| 716 | swsqe->host_time = ktime_get(); |
| 717 | } |
| 718 | |
| 719 | write_wrid = qhp->wq.sq.pidx; |
| 720 | |
| 721 | /* just bump the sw_sq */ |
| 722 | qhp->wq.sq.in_use++; |
| 723 | if (++qhp->wq.sq.pidx == qhp->wq.sq.size) |
| 724 | qhp->wq.sq.pidx = 0; |
| 725 | |
| 726 | /* SEND_WITH_INV swsqe */ |
| 727 | swsqe = &qhp->wq.sq.sw_sq[qhp->wq.sq.pidx]; |
| 728 | swsqe->opcode = FW_RI_SEND_WITH_INV; |
| 729 | swsqe->idx = qhp->wq.sq.pidx; |
| 730 | swsqe->complete = 0; |
| 731 | swsqe->signaled = send_signaled; |
| 732 | swsqe->flushed = 0; |
| 733 | swsqe->wr_id = wr->next->wr_id; |
| 734 | if (c4iw_wr_log) { |
| 735 | swsqe->sge_ts = |
| 736 | cxgb4_read_sge_timestamp(qhp->rhp->rdev.lldi.ports[0]); |
| 737 | swsqe->host_time = ktime_get(); |
| 738 | } |
| 739 | |
| 740 | wqe->write_cmpl.flags_send = send_signaled ? FW_RI_COMPLETION_FLAG : 0; |
| 741 | wqe->write_cmpl.wrid_send = qhp->wq.sq.pidx; |
| 742 | |
| 743 | init_wr_hdr(wqe, write_wrid, FW_RI_RDMA_WRITE_CMPL_WR, |
| 744 | write_signaled ? FW_RI_COMPLETION_FLAG : 0, len16); |
| 745 | t4_sq_produce(&qhp->wq, len16); |
| 746 | idx = DIV_ROUND_UP(len16 * 16, T4_EQ_ENTRY_SIZE); |
| 747 | |
| 748 | t4_ring_sq_db(&qhp->wq, idx, wqe); |
| 749 | } |
| 750 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 751 | static int build_rdma_recv(struct c4iw_qp *qhp, union t4_recv_wr *wqe, |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 752 | const struct ib_recv_wr *wr, u8 *len16) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 753 | { |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 754 | int ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 755 | |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 756 | ret = build_isgl((__be64 *)qhp->wq.rq.queue, |
| 757 | (__be64 *)&qhp->wq.rq.queue[qhp->wq.rq.size], |
| 758 | &wqe->recv.isgl, wr->sg_list, wr->num_sge, NULL); |
| 759 | if (ret) |
| 760 | return ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 761 | *len16 = DIV_ROUND_UP(sizeof wqe->recv + |
| 762 | wr->num_sge * sizeof(struct fw_ri_sge), 16); |
| 763 | return 0; |
| 764 | } |
| 765 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 766 | static int build_srq_recv(union t4_recv_wr *wqe, const struct ib_recv_wr *wr, |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 767 | u8 *len16) |
| 768 | { |
| 769 | int ret; |
| 770 | |
| 771 | ret = build_isgl((__be64 *)wqe, (__be64 *)(wqe + 1), |
| 772 | &wqe->recv.isgl, wr->sg_list, wr->num_sge, NULL); |
| 773 | if (ret) |
| 774 | return ret; |
| 775 | *len16 = DIV_ROUND_UP(sizeof(wqe->recv) + |
| 776 | wr->num_sge * sizeof(struct fw_ri_sge), 16); |
| 777 | return 0; |
| 778 | } |
| 779 | |
Steve Wise | 49b53a9 | 2016-09-16 07:54:52 -0700 | [diff] [blame] | 780 | static void build_tpte_memreg(struct fw_ri_fr_nsmr_tpte_wr *fr, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 781 | const struct ib_reg_wr *wr, struct c4iw_mr *mhp, |
Steve Wise | 49b53a9 | 2016-09-16 07:54:52 -0700 | [diff] [blame] | 782 | u8 *len16) |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 783 | { |
Steve Wise | 49b53a9 | 2016-09-16 07:54:52 -0700 | [diff] [blame] | 784 | __be64 *p = (__be64 *)fr->pbl; |
| 785 | |
| 786 | fr->r2 = cpu_to_be32(0); |
| 787 | fr->stag = cpu_to_be32(mhp->ibmr.rkey); |
| 788 | |
| 789 | fr->tpte.valid_to_pdid = cpu_to_be32(FW_RI_TPTE_VALID_F | |
| 790 | FW_RI_TPTE_STAGKEY_V((mhp->ibmr.rkey & FW_RI_TPTE_STAGKEY_M)) | |
| 791 | FW_RI_TPTE_STAGSTATE_V(1) | |
| 792 | FW_RI_TPTE_STAGTYPE_V(FW_RI_STAG_NSMR) | |
| 793 | FW_RI_TPTE_PDID_V(mhp->attr.pdid)); |
| 794 | fr->tpte.locread_to_qpid = cpu_to_be32( |
| 795 | FW_RI_TPTE_PERM_V(c4iw_ib_to_tpt_access(wr->access)) | |
| 796 | FW_RI_TPTE_ADDRTYPE_V(FW_RI_VA_BASED_TO) | |
| 797 | FW_RI_TPTE_PS_V(ilog2(wr->mr->page_size) - 12)); |
| 798 | fr->tpte.nosnoop_pbladdr = cpu_to_be32(FW_RI_TPTE_PBLADDR_V( |
| 799 | PBL_OFF(&mhp->rhp->rdev, mhp->attr.pbl_addr)>>3)); |
| 800 | fr->tpte.dca_mwbcnt_pstag = cpu_to_be32(0); |
| 801 | fr->tpte.len_hi = cpu_to_be32(0); |
| 802 | fr->tpte.len_lo = cpu_to_be32(mhp->ibmr.length); |
| 803 | fr->tpte.va_hi = cpu_to_be32(mhp->ibmr.iova >> 32); |
| 804 | fr->tpte.va_lo_fbo = cpu_to_be32(mhp->ibmr.iova & 0xffffffff); |
| 805 | |
| 806 | p[0] = cpu_to_be64((u64)mhp->mpl[0]); |
| 807 | p[1] = cpu_to_be64((u64)mhp->mpl[1]); |
| 808 | |
| 809 | *len16 = DIV_ROUND_UP(sizeof(*fr), 16); |
| 810 | } |
| 811 | |
| 812 | static int build_memreg(struct t4_sq *sq, union t4_wr *wqe, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 813 | const struct ib_reg_wr *wr, struct c4iw_mr *mhp, |
| 814 | u8 *len16, bool dsgl_supported) |
Steve Wise | 49b53a9 | 2016-09-16 07:54:52 -0700 | [diff] [blame] | 815 | { |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 816 | struct fw_ri_immd *imdp; |
| 817 | __be64 *p; |
| 818 | int i; |
| 819 | int pbllen = roundup(mhp->mpl_len * sizeof(u64), 32); |
| 820 | int rem; |
| 821 | |
Hariprasad S | ee30f7d | 2016-02-12 16:10:35 +0530 | [diff] [blame] | 822 | if (mhp->mpl_len > t4_max_fr_depth(dsgl_supported && use_dsgl)) |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 823 | return -EINVAL; |
| 824 | |
| 825 | wqe->fr.qpbinde_to_dcacpu = 0; |
| 826 | wqe->fr.pgsz_shift = ilog2(wr->mr->page_size) - 12; |
| 827 | wqe->fr.addr_type = FW_RI_VA_BASED_TO; |
| 828 | wqe->fr.mem_perms = c4iw_ib_to_tpt_access(wr->access); |
| 829 | wqe->fr.len_hi = 0; |
| 830 | wqe->fr.len_lo = cpu_to_be32(mhp->ibmr.length); |
| 831 | wqe->fr.stag = cpu_to_be32(wr->key); |
| 832 | wqe->fr.va_hi = cpu_to_be32(mhp->ibmr.iova >> 32); |
| 833 | wqe->fr.va_lo_fbo = cpu_to_be32(mhp->ibmr.iova & |
| 834 | 0xffffffff); |
| 835 | |
Hariprasad S | ee30f7d | 2016-02-12 16:10:35 +0530 | [diff] [blame] | 836 | if (dsgl_supported && use_dsgl && (pbllen > max_fr_immd)) { |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 837 | struct fw_ri_dsgl *sglp; |
| 838 | |
| 839 | for (i = 0; i < mhp->mpl_len; i++) |
| 840 | mhp->mpl[i] = (__force u64)cpu_to_be64((u64)mhp->mpl[i]); |
| 841 | |
| 842 | sglp = (struct fw_ri_dsgl *)(&wqe->fr + 1); |
| 843 | sglp->op = FW_RI_DATA_DSGL; |
| 844 | sglp->r1 = 0; |
| 845 | sglp->nsge = cpu_to_be16(1); |
| 846 | sglp->addr0 = cpu_to_be64(mhp->mpl_addr); |
| 847 | sglp->len0 = cpu_to_be32(pbllen); |
| 848 | |
| 849 | *len16 = DIV_ROUND_UP(sizeof(wqe->fr) + sizeof(*sglp), 16); |
| 850 | } else { |
| 851 | imdp = (struct fw_ri_immd *)(&wqe->fr + 1); |
| 852 | imdp->op = FW_RI_DATA_IMMD; |
| 853 | imdp->r1 = 0; |
| 854 | imdp->r2 = 0; |
| 855 | imdp->immdlen = cpu_to_be32(pbllen); |
| 856 | p = (__be64 *)(imdp + 1); |
| 857 | rem = pbllen; |
| 858 | for (i = 0; i < mhp->mpl_len; i++) { |
| 859 | *p = cpu_to_be64((u64)mhp->mpl[i]); |
| 860 | rem -= sizeof(*p); |
| 861 | if (++p == (__be64 *)&sq->queue[sq->size]) |
| 862 | p = (__be64 *)sq->queue; |
| 863 | } |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 864 | while (rem) { |
| 865 | *p = 0; |
| 866 | rem -= sizeof(*p); |
| 867 | if (++p == (__be64 *)&sq->queue[sq->size]) |
| 868 | p = (__be64 *)sq->queue; |
| 869 | } |
| 870 | *len16 = DIV_ROUND_UP(sizeof(wqe->fr) + sizeof(*imdp) |
| 871 | + pbllen, 16); |
| 872 | } |
| 873 | return 0; |
| 874 | } |
| 875 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 876 | static int build_inv_stag(union t4_wr *wqe, const struct ib_send_wr *wr, |
| 877 | u8 *len16) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 878 | { |
| 879 | wqe->inv.stag_inv = cpu_to_be32(wr->ex.invalidate_rkey); |
| 880 | wqe->inv.r2 = 0; |
| 881 | *len16 = DIV_ROUND_UP(sizeof wqe->inv, 16); |
| 882 | return 0; |
| 883 | } |
| 884 | |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 885 | static void free_qp_work(struct work_struct *work) |
| 886 | { |
| 887 | struct c4iw_ucontext *ucontext; |
| 888 | struct c4iw_qp *qhp; |
| 889 | struct c4iw_dev *rhp; |
| 890 | |
| 891 | qhp = container_of(work, struct c4iw_qp, free_work); |
| 892 | ucontext = qhp->ucontext; |
| 893 | rhp = qhp->rhp; |
| 894 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 895 | pr_debug("qhp %p ucontext %p\n", qhp, ucontext); |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 896 | destroy_qp(&rhp->rdev, &qhp->wq, |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 897 | ucontext ? &ucontext->uctx : &rhp->rdev.uctx, !qhp->srq); |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 898 | |
| 899 | if (ucontext) |
| 900 | c4iw_put_ucontext(ucontext); |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 901 | c4iw_put_wr_wait(qhp->wr_waitp); |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 902 | kfree(qhp); |
| 903 | } |
| 904 | |
| 905 | static void queue_qp_free(struct kref *kref) |
Steve Wise | ad61a4c | 2016-07-29 11:00:54 -0700 | [diff] [blame] | 906 | { |
| 907 | struct c4iw_qp *qhp; |
| 908 | |
| 909 | qhp = container_of(kref, struct c4iw_qp, kref); |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 910 | pr_debug("qhp %p\n", qhp); |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 911 | queue_work(qhp->rhp->rdev.free_workq, &qhp->free_work); |
Steve Wise | ad61a4c | 2016-07-29 11:00:54 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 914 | void c4iw_qp_add_ref(struct ib_qp *qp) |
| 915 | { |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 916 | pr_debug("ib_qp %p\n", qp); |
Steve Wise | ad61a4c | 2016-07-29 11:00:54 -0700 | [diff] [blame] | 917 | kref_get(&to_c4iw_qp(qp)->kref); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | void c4iw_qp_rem_ref(struct ib_qp *qp) |
| 921 | { |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 922 | pr_debug("ib_qp %p\n", qp); |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 923 | kref_put(&to_c4iw_qp(qp)->kref, queue_qp_free); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 926 | static void add_to_fc_list(struct list_head *head, struct list_head *entry) |
| 927 | { |
| 928 | if (list_empty(entry)) |
| 929 | list_add_tail(entry, head); |
| 930 | } |
| 931 | |
| 932 | static int ring_kernel_sq_db(struct c4iw_qp *qhp, u16 inc) |
| 933 | { |
| 934 | unsigned long flags; |
| 935 | |
| 936 | spin_lock_irqsave(&qhp->rhp->lock, flags); |
| 937 | spin_lock(&qhp->lock); |
Steve Wise | fa658a9 | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 938 | if (qhp->rhp->db_state == NORMAL) |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 939 | t4_ring_sq_db(&qhp->wq, inc, NULL); |
Steve Wise | fa658a9 | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 940 | else { |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 941 | add_to_fc_list(&qhp->rhp->db_fc_list, &qhp->db_fc_entry); |
| 942 | qhp->wq.sq.wq_pidx_inc += inc; |
| 943 | } |
| 944 | spin_unlock(&qhp->lock); |
| 945 | spin_unlock_irqrestore(&qhp->rhp->lock, flags); |
| 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | static int ring_kernel_rq_db(struct c4iw_qp *qhp, u16 inc) |
| 950 | { |
| 951 | unsigned long flags; |
| 952 | |
| 953 | spin_lock_irqsave(&qhp->rhp->lock, flags); |
| 954 | spin_lock(&qhp->lock); |
Steve Wise | fa658a9 | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 955 | if (qhp->rhp->db_state == NORMAL) |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 956 | t4_ring_rq_db(&qhp->wq, inc, NULL); |
Steve Wise | fa658a9 | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 957 | else { |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 958 | add_to_fc_list(&qhp->rhp->db_fc_list, &qhp->db_fc_entry); |
| 959 | qhp->wq.rq.wq_pidx_inc += inc; |
| 960 | } |
| 961 | spin_unlock(&qhp->lock); |
| 962 | spin_unlock_irqrestore(&qhp->rhp->lock, flags); |
| 963 | return 0; |
| 964 | } |
| 965 | |
Steve Wise | 96a236e | 2017-12-19 10:29:25 -0800 | [diff] [blame] | 966 | static int ib_to_fw_opcode(int ib_opcode) |
| 967 | { |
| 968 | int opcode; |
| 969 | |
| 970 | switch (ib_opcode) { |
| 971 | case IB_WR_SEND_WITH_INV: |
| 972 | opcode = FW_RI_SEND_WITH_INV; |
| 973 | break; |
| 974 | case IB_WR_SEND: |
| 975 | opcode = FW_RI_SEND; |
| 976 | break; |
| 977 | case IB_WR_RDMA_WRITE: |
| 978 | opcode = FW_RI_RDMA_WRITE; |
| 979 | break; |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 980 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 981 | opcode = FW_RI_WRITE_IMMEDIATE; |
| 982 | break; |
Steve Wise | 96a236e | 2017-12-19 10:29:25 -0800 | [diff] [blame] | 983 | case IB_WR_RDMA_READ: |
| 984 | case IB_WR_RDMA_READ_WITH_INV: |
| 985 | opcode = FW_RI_READ_REQ; |
| 986 | break; |
| 987 | case IB_WR_REG_MR: |
| 988 | opcode = FW_RI_FAST_REGISTER; |
| 989 | break; |
| 990 | case IB_WR_LOCAL_INV: |
| 991 | opcode = FW_RI_LOCAL_INV; |
| 992 | break; |
| 993 | default: |
| 994 | opcode = -EINVAL; |
| 995 | } |
| 996 | return opcode; |
| 997 | } |
| 998 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 999 | static int complete_sq_drain_wr(struct c4iw_qp *qhp, |
| 1000 | const struct ib_send_wr *wr) |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1001 | { |
| 1002 | struct t4_cqe cqe = {}; |
| 1003 | struct c4iw_cq *schp; |
| 1004 | unsigned long flag; |
| 1005 | struct t4_cq *cq; |
Steve Wise | 96a236e | 2017-12-19 10:29:25 -0800 | [diff] [blame] | 1006 | int opcode; |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1007 | |
| 1008 | schp = to_c4iw_cq(qhp->ibqp.send_cq); |
| 1009 | cq = &schp->cq; |
| 1010 | |
Steve Wise | 96a236e | 2017-12-19 10:29:25 -0800 | [diff] [blame] | 1011 | opcode = ib_to_fw_opcode(wr->opcode); |
| 1012 | if (opcode < 0) |
| 1013 | return opcode; |
| 1014 | |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1015 | cqe.u.drain_cookie = wr->wr_id; |
| 1016 | cqe.header = cpu_to_be32(CQE_STATUS_V(T4_ERR_SWFLUSH) | |
Steve Wise | 96a236e | 2017-12-19 10:29:25 -0800 | [diff] [blame] | 1017 | CQE_OPCODE_V(opcode) | |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1018 | CQE_TYPE_V(1) | |
| 1019 | CQE_SWCQE_V(1) | |
Steve Wise | 96a236e | 2017-12-19 10:29:25 -0800 | [diff] [blame] | 1020 | CQE_DRAIN_V(1) | |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1021 | CQE_QPID_V(qhp->wq.sq.qid)); |
| 1022 | |
| 1023 | spin_lock_irqsave(&schp->lock, flag); |
| 1024 | cqe.bits_type_ts = cpu_to_be64(CQE_GENBIT_V((u64)cq->gen)); |
| 1025 | cq->sw_queue[cq->sw_pidx] = cqe; |
| 1026 | t4_swcq_produce(cq); |
| 1027 | spin_unlock_irqrestore(&schp->lock, flag); |
| 1028 | |
Steve Wise | cbb40fa | 2017-11-09 07:14:43 -0800 | [diff] [blame] | 1029 | if (t4_clear_cq_armed(&schp->cq)) { |
| 1030 | spin_lock_irqsave(&schp->comp_handler_lock, flag); |
| 1031 | (*schp->ibcq.comp_handler)(&schp->ibcq, |
| 1032 | schp->ibcq.cq_context); |
| 1033 | spin_unlock_irqrestore(&schp->comp_handler_lock, flag); |
| 1034 | } |
Steve Wise | 96a236e | 2017-12-19 10:29:25 -0800 | [diff] [blame] | 1035 | return 0; |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1036 | } |
| 1037 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 1038 | static int complete_sq_drain_wrs(struct c4iw_qp *qhp, |
| 1039 | const struct ib_send_wr *wr, |
| 1040 | const struct ib_send_wr **bad_wr) |
Steve Wise | d145873 | 2017-12-19 14:02:10 -0800 | [diff] [blame] | 1041 | { |
| 1042 | int ret = 0; |
| 1043 | |
| 1044 | while (wr) { |
| 1045 | ret = complete_sq_drain_wr(qhp, wr); |
| 1046 | if (ret) { |
| 1047 | *bad_wr = wr; |
| 1048 | break; |
| 1049 | } |
| 1050 | wr = wr->next; |
| 1051 | } |
| 1052 | return ret; |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1053 | } |
| 1054 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 1055 | static void complete_rq_drain_wr(struct c4iw_qp *qhp, |
| 1056 | const struct ib_recv_wr *wr) |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1057 | { |
| 1058 | struct t4_cqe cqe = {}; |
| 1059 | struct c4iw_cq *rchp; |
| 1060 | unsigned long flag; |
| 1061 | struct t4_cq *cq; |
| 1062 | |
| 1063 | rchp = to_c4iw_cq(qhp->ibqp.recv_cq); |
| 1064 | cq = &rchp->cq; |
| 1065 | |
| 1066 | cqe.u.drain_cookie = wr->wr_id; |
| 1067 | cqe.header = cpu_to_be32(CQE_STATUS_V(T4_ERR_SWFLUSH) | |
Steve Wise | 96a236e | 2017-12-19 10:29:25 -0800 | [diff] [blame] | 1068 | CQE_OPCODE_V(FW_RI_SEND) | |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1069 | CQE_TYPE_V(0) | |
| 1070 | CQE_SWCQE_V(1) | |
Steve Wise | 96a236e | 2017-12-19 10:29:25 -0800 | [diff] [blame] | 1071 | CQE_DRAIN_V(1) | |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1072 | CQE_QPID_V(qhp->wq.sq.qid)); |
| 1073 | |
| 1074 | spin_lock_irqsave(&rchp->lock, flag); |
| 1075 | cqe.bits_type_ts = cpu_to_be64(CQE_GENBIT_V((u64)cq->gen)); |
| 1076 | cq->sw_queue[cq->sw_pidx] = cqe; |
| 1077 | t4_swcq_produce(cq); |
| 1078 | spin_unlock_irqrestore(&rchp->lock, flag); |
| 1079 | |
Steve Wise | cbb40fa | 2017-11-09 07:14:43 -0800 | [diff] [blame] | 1080 | if (t4_clear_cq_armed(&rchp->cq)) { |
| 1081 | spin_lock_irqsave(&rchp->comp_handler_lock, flag); |
| 1082 | (*rchp->ibcq.comp_handler)(&rchp->ibcq, |
| 1083 | rchp->ibcq.cq_context); |
| 1084 | spin_unlock_irqrestore(&rchp->comp_handler_lock, flag); |
| 1085 | } |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1086 | } |
| 1087 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 1088 | static void complete_rq_drain_wrs(struct c4iw_qp *qhp, |
| 1089 | const struct ib_recv_wr *wr) |
Steve Wise | d145873 | 2017-12-19 14:02:10 -0800 | [diff] [blame] | 1090 | { |
| 1091 | while (wr) { |
| 1092 | complete_rq_drain_wr(qhp, wr); |
| 1093 | wr = wr->next; |
| 1094 | } |
| 1095 | } |
| 1096 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 1097 | int c4iw_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, |
| 1098 | const struct ib_send_wr **bad_wr) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1099 | { |
| 1100 | int err = 0; |
| 1101 | u8 len16 = 0; |
| 1102 | enum fw_wr_opcodes fw_opcode = 0; |
| 1103 | enum fw_ri_wr_flags fw_flags; |
| 1104 | struct c4iw_qp *qhp; |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 1105 | struct c4iw_dev *rhp; |
Steve Wise | fa658a9 | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 1106 | union t4_wr *wqe = NULL; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1107 | u32 num_wrs; |
| 1108 | struct t4_swsqe *swsqe; |
| 1109 | unsigned long flag; |
| 1110 | u16 idx = 0; |
| 1111 | |
| 1112 | qhp = to_c4iw_qp(ibqp); |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 1113 | rhp = qhp->rhp; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1114 | spin_lock_irqsave(&qhp->lock, flag); |
Steve Wise | c058ecf | 2017-11-27 13:16:32 -0800 | [diff] [blame] | 1115 | |
| 1116 | /* |
| 1117 | * If the qp has been flushed, then just insert a special |
| 1118 | * drain cqe. |
| 1119 | */ |
| 1120 | if (qhp->wq.flushed) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1121 | spin_unlock_irqrestore(&qhp->lock, flag); |
Steve Wise | d145873 | 2017-12-19 14:02:10 -0800 | [diff] [blame] | 1122 | err = complete_sq_drain_wrs(qhp, wr, bad_wr); |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1123 | return err; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1124 | } |
| 1125 | num_wrs = t4_sq_avail(&qhp->wq); |
| 1126 | if (num_wrs == 0) { |
| 1127 | spin_unlock_irqrestore(&qhp->lock, flag); |
Steve Wise | 4ff522e | 2016-10-18 14:04:39 -0700 | [diff] [blame] | 1128 | *bad_wr = wr; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1129 | return -ENOMEM; |
| 1130 | } |
Potnuri Bharat Teja | 94245f4 | 2018-08-02 11:33:04 +0530 | [diff] [blame] | 1131 | |
| 1132 | /* |
| 1133 | * Fastpath for NVMe-oF target WRITE + SEND_WITH_INV wr chain which is |
| 1134 | * the response for small NVMEe-oF READ requests. If the chain is |
| 1135 | * exactly a WRITE->SEND_WITH_INV and the sgl depths and lengths |
| 1136 | * meet the requirements of the fw_ri_write_cmpl_wr work request, |
| 1137 | * then build and post the write_cmpl WR. If any of the tests |
| 1138 | * below are not true, then we continue on with the tradtional WRITE |
| 1139 | * and SEND WRs. |
| 1140 | */ |
| 1141 | if (qhp->rhp->rdev.lldi.write_cmpl_support && |
| 1142 | CHELSIO_CHIP_VERSION(qhp->rhp->rdev.lldi.adapter_type) >= |
| 1143 | CHELSIO_T5 && |
| 1144 | wr && wr->next && !wr->next->next && |
| 1145 | wr->opcode == IB_WR_RDMA_WRITE && |
| 1146 | wr->sg_list[0].length && wr->num_sge <= T4_WRITE_CMPL_MAX_SGL && |
| 1147 | wr->next->opcode == IB_WR_SEND_WITH_INV && |
| 1148 | wr->next->sg_list[0].length == T4_WRITE_CMPL_MAX_CQE && |
| 1149 | wr->next->num_sge == 1 && num_wrs >= 2) { |
| 1150 | post_write_cmpl(qhp, wr); |
| 1151 | spin_unlock_irqrestore(&qhp->lock, flag); |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1155 | while (wr) { |
| 1156 | if (num_wrs == 0) { |
| 1157 | err = -ENOMEM; |
| 1158 | *bad_wr = wr; |
| 1159 | break; |
| 1160 | } |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 1161 | wqe = (union t4_wr *)((u8 *)qhp->wq.sq.queue + |
| 1162 | qhp->wq.sq.wq_pidx * T4_EQ_ENTRY_SIZE); |
| 1163 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1164 | fw_flags = 0; |
| 1165 | if (wr->send_flags & IB_SEND_SOLICITED) |
| 1166 | fw_flags |= FW_RI_SOLICITED_EVENT_FLAG; |
Steve Wise | ba32de9 | 2014-03-19 17:44:43 +0530 | [diff] [blame] | 1167 | if (wr->send_flags & IB_SEND_SIGNALED || qhp->sq_sig_all) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1168 | fw_flags |= FW_RI_COMPLETION_FLAG; |
| 1169 | swsqe = &qhp->wq.sq.sw_sq[qhp->wq.sq.pidx]; |
| 1170 | switch (wr->opcode) { |
| 1171 | case IB_WR_SEND_WITH_INV: |
| 1172 | case IB_WR_SEND: |
| 1173 | if (wr->send_flags & IB_SEND_FENCE) |
| 1174 | fw_flags |= FW_RI_READ_FENCE_FLAG; |
| 1175 | fw_opcode = FW_RI_SEND_WR; |
| 1176 | if (wr->opcode == IB_WR_SEND) |
| 1177 | swsqe->opcode = FW_RI_SEND; |
| 1178 | else |
| 1179 | swsqe->opcode = FW_RI_SEND_WITH_INV; |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 1180 | err = build_rdma_send(&qhp->wq.sq, wqe, wr, &len16); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1181 | break; |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 1182 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 1183 | if (unlikely(!rhp->rdev.lldi.write_w_imm_support)) { |
| 1184 | err = -EINVAL; |
| 1185 | break; |
| 1186 | } |
| 1187 | fw_flags |= FW_RI_RDMA_WRITE_WITH_IMMEDIATE; |
| 1188 | /*FALLTHROUGH*/ |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1189 | case IB_WR_RDMA_WRITE: |
| 1190 | fw_opcode = FW_RI_RDMA_WRITE_WR; |
| 1191 | swsqe->opcode = FW_RI_RDMA_WRITE; |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 1192 | err = build_rdma_write(&qhp->wq.sq, wqe, wr, &len16); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1193 | break; |
| 1194 | case IB_WR_RDMA_READ: |
Steve Wise | 2f1fb50 | 2010-05-20 16:58:16 -0500 | [diff] [blame] | 1195 | case IB_WR_RDMA_READ_WITH_INV: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1196 | fw_opcode = FW_RI_RDMA_READ_WR; |
| 1197 | swsqe->opcode = FW_RI_READ_REQ; |
Steve Wise | 5c6b2aa | 2016-11-03 12:09:38 -0700 | [diff] [blame] | 1198 | if (wr->opcode == IB_WR_RDMA_READ_WITH_INV) { |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 1199 | c4iw_invalidate_mr(rhp, wr->sg_list[0].lkey); |
Steve Wise | 410ade4 | 2010-09-17 15:40:09 -0500 | [diff] [blame] | 1200 | fw_flags = FW_RI_RDMA_READ_INVALIDATE; |
Steve Wise | 5c6b2aa | 2016-11-03 12:09:38 -0700 | [diff] [blame] | 1201 | } else { |
Steve Wise | 2f1fb50 | 2010-05-20 16:58:16 -0500 | [diff] [blame] | 1202 | fw_flags = 0; |
Steve Wise | 5c6b2aa | 2016-11-03 12:09:38 -0700 | [diff] [blame] | 1203 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1204 | err = build_rdma_read(wqe, wr, &len16); |
| 1205 | if (err) |
| 1206 | break; |
| 1207 | swsqe->read_len = wr->sg_list[0].length; |
| 1208 | if (!qhp->wq.sq.oldest_read) |
| 1209 | qhp->wq.sq.oldest_read = swsqe; |
| 1210 | break; |
Steve Wise | 49b53a9 | 2016-09-16 07:54:52 -0700 | [diff] [blame] | 1211 | case IB_WR_REG_MR: { |
| 1212 | struct c4iw_mr *mhp = to_c4iw_mr(reg_wr(wr)->mr); |
| 1213 | |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 1214 | swsqe->opcode = FW_RI_FAST_REGISTER; |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 1215 | if (rhp->rdev.lldi.fr_nsmr_tpte_wr_support && |
Steve Wise | 49b53a9 | 2016-09-16 07:54:52 -0700 | [diff] [blame] | 1216 | !mhp->attr.state && mhp->mpl_len <= 2) { |
| 1217 | fw_opcode = FW_RI_FR_NSMR_TPTE_WR; |
| 1218 | build_tpte_memreg(&wqe->fr_tpte, reg_wr(wr), |
| 1219 | mhp, &len16); |
| 1220 | } else { |
| 1221 | fw_opcode = FW_RI_FR_NSMR_WR; |
| 1222 | err = build_memreg(&qhp->wq.sq, wqe, reg_wr(wr), |
| 1223 | mhp, &len16, |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 1224 | rhp->rdev.lldi.ulptx_memwrite_dsgl); |
Steve Wise | 49b53a9 | 2016-09-16 07:54:52 -0700 | [diff] [blame] | 1225 | if (err) |
| 1226 | break; |
| 1227 | } |
| 1228 | mhp->attr.state = 1; |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 1229 | break; |
Steve Wise | 49b53a9 | 2016-09-16 07:54:52 -0700 | [diff] [blame] | 1230 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1231 | case IB_WR_LOCAL_INV: |
Steve Wise | 4ab1eb9 | 2010-05-20 16:58:10 -0500 | [diff] [blame] | 1232 | if (wr->send_flags & IB_SEND_FENCE) |
| 1233 | fw_flags |= FW_RI_LOCAL_FENCE_FLAG; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1234 | fw_opcode = FW_RI_INV_LSTAG_WR; |
| 1235 | swsqe->opcode = FW_RI_LOCAL_INV; |
Steve Wise | 5c6b2aa | 2016-11-03 12:09:38 -0700 | [diff] [blame] | 1236 | err = build_inv_stag(wqe, wr, &len16); |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 1237 | c4iw_invalidate_mr(rhp, wr->ex.invalidate_rkey); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1238 | break; |
| 1239 | default: |
Bharat Potnuri | 4d45b75 | 2017-09-27 13:05:50 +0530 | [diff] [blame] | 1240 | pr_warn("%s post of type=%d TBD!\n", __func__, |
| 1241 | wr->opcode); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1242 | err = -EINVAL; |
| 1243 | } |
| 1244 | if (err) { |
| 1245 | *bad_wr = wr; |
| 1246 | break; |
| 1247 | } |
| 1248 | swsqe->idx = qhp->wq.sq.pidx; |
| 1249 | swsqe->complete = 0; |
Steve Wise | ba32de9 | 2014-03-19 17:44:43 +0530 | [diff] [blame] | 1250 | swsqe->signaled = (wr->send_flags & IB_SEND_SIGNALED) || |
| 1251 | qhp->sq_sig_all; |
Steve Wise | 1cf24dc | 2013-08-06 21:04:35 +0530 | [diff] [blame] | 1252 | swsqe->flushed = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1253 | swsqe->wr_id = wr->wr_id; |
Hariprasad Shenai | 7730b4c | 2014-07-14 21:34:54 +0530 | [diff] [blame] | 1254 | if (c4iw_wr_log) { |
| 1255 | swsqe->sge_ts = cxgb4_read_sge_timestamp( |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 1256 | rhp->rdev.lldi.ports[0]); |
Arnd Bergmann | f8109d9 | 2017-11-27 12:44:53 +0100 | [diff] [blame] | 1257 | swsqe->host_time = ktime_get(); |
Hariprasad Shenai | 7730b4c | 2014-07-14 21:34:54 +0530 | [diff] [blame] | 1258 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1259 | |
| 1260 | init_wr_hdr(wqe, qhp->wq.sq.pidx, fw_opcode, fw_flags, len16); |
| 1261 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 1262 | pr_debug("cookie 0x%llx pidx 0x%x opcode 0x%x read_len %u\n", |
Joe Perches | a9a4288 | 2017-02-09 14:23:51 -0800 | [diff] [blame] | 1263 | (unsigned long long)wr->wr_id, qhp->wq.sq.pidx, |
| 1264 | swsqe->opcode, swsqe->read_len); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1265 | wr = wr->next; |
| 1266 | num_wrs--; |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 1267 | t4_sq_produce(&qhp->wq, len16); |
| 1268 | idx += DIV_ROUND_UP(len16*16, T4_EQ_ENTRY_SIZE); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1269 | } |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 1270 | if (!rhp->rdev.status_page->db_off) { |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 1271 | t4_ring_sq_db(&qhp->wq, idx, wqe); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 1272 | spin_unlock_irqrestore(&qhp->lock, flag); |
| 1273 | } else { |
| 1274 | spin_unlock_irqrestore(&qhp->lock, flag); |
| 1275 | ring_kernel_sq_db(qhp, idx); |
| 1276 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1277 | return err; |
| 1278 | } |
| 1279 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 1280 | int c4iw_post_receive(struct ib_qp *ibqp, const struct ib_recv_wr *wr, |
| 1281 | const struct ib_recv_wr **bad_wr) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1282 | { |
| 1283 | int err = 0; |
| 1284 | struct c4iw_qp *qhp; |
Steve Wise | fa658a9 | 2014-04-09 09:38:25 -0500 | [diff] [blame] | 1285 | union t4_recv_wr *wqe = NULL; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1286 | u32 num_wrs; |
| 1287 | u8 len16 = 0; |
| 1288 | unsigned long flag; |
| 1289 | u16 idx = 0; |
| 1290 | |
| 1291 | qhp = to_c4iw_qp(ibqp); |
| 1292 | spin_lock_irqsave(&qhp->lock, flag); |
Steve Wise | c058ecf | 2017-11-27 13:16:32 -0800 | [diff] [blame] | 1293 | |
| 1294 | /* |
| 1295 | * If the qp has been flushed, then just insert a special |
| 1296 | * drain cqe. |
| 1297 | */ |
| 1298 | if (qhp->wq.flushed) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1299 | spin_unlock_irqrestore(&qhp->lock, flag); |
Steve Wise | d145873 | 2017-12-19 14:02:10 -0800 | [diff] [blame] | 1300 | complete_rq_drain_wrs(qhp, wr); |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 1301 | return err; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1302 | } |
| 1303 | num_wrs = t4_rq_avail(&qhp->wq); |
| 1304 | if (num_wrs == 0) { |
| 1305 | spin_unlock_irqrestore(&qhp->lock, flag); |
Steve Wise | 4ff522e | 2016-10-18 14:04:39 -0700 | [diff] [blame] | 1306 | *bad_wr = wr; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1307 | return -ENOMEM; |
| 1308 | } |
| 1309 | while (wr) { |
| 1310 | if (wr->num_sge > T4_MAX_RECV_SGE) { |
| 1311 | err = -EINVAL; |
| 1312 | *bad_wr = wr; |
| 1313 | break; |
| 1314 | } |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 1315 | wqe = (union t4_recv_wr *)((u8 *)qhp->wq.rq.queue + |
| 1316 | qhp->wq.rq.wq_pidx * |
| 1317 | T4_EQ_ENTRY_SIZE); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1318 | if (num_wrs) |
| 1319 | err = build_rdma_recv(qhp, wqe, wr, &len16); |
| 1320 | else |
| 1321 | err = -ENOMEM; |
| 1322 | if (err) { |
| 1323 | *bad_wr = wr; |
| 1324 | break; |
| 1325 | } |
| 1326 | |
| 1327 | qhp->wq.rq.sw_rq[qhp->wq.rq.pidx].wr_id = wr->wr_id; |
Hariprasad Shenai | 7730b4c | 2014-07-14 21:34:54 +0530 | [diff] [blame] | 1328 | if (c4iw_wr_log) { |
| 1329 | qhp->wq.rq.sw_rq[qhp->wq.rq.pidx].sge_ts = |
| 1330 | cxgb4_read_sge_timestamp( |
| 1331 | qhp->rhp->rdev.lldi.ports[0]); |
Arnd Bergmann | f8109d9 | 2017-11-27 12:44:53 +0100 | [diff] [blame] | 1332 | qhp->wq.rq.sw_rq[qhp->wq.rq.pidx].host_time = |
| 1333 | ktime_get(); |
Hariprasad Shenai | 7730b4c | 2014-07-14 21:34:54 +0530 | [diff] [blame] | 1334 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1335 | |
| 1336 | wqe->recv.opcode = FW_RI_RECV_WR; |
| 1337 | wqe->recv.r1 = 0; |
| 1338 | wqe->recv.wrid = qhp->wq.rq.pidx; |
| 1339 | wqe->recv.r2[0] = 0; |
| 1340 | wqe->recv.r2[1] = 0; |
| 1341 | wqe->recv.r2[2] = 0; |
| 1342 | wqe->recv.len16 = len16; |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 1343 | pr_debug("cookie 0x%llx pidx %u\n", |
Joe Perches | a9a4288 | 2017-02-09 14:23:51 -0800 | [diff] [blame] | 1344 | (unsigned long long)wr->wr_id, qhp->wq.rq.pidx); |
Steve Wise | d37ac31 | 2010-06-10 19:03:00 +0000 | [diff] [blame] | 1345 | t4_rq_produce(&qhp->wq, len16); |
| 1346 | idx += DIV_ROUND_UP(len16*16, T4_EQ_ENTRY_SIZE); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1347 | wr = wr->next; |
| 1348 | num_wrs--; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1349 | } |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 1350 | if (!qhp->rhp->rdev.status_page->db_off) { |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 1351 | t4_ring_rq_db(&qhp->wq, idx, wqe); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 1352 | spin_unlock_irqrestore(&qhp->lock, flag); |
| 1353 | } else { |
| 1354 | spin_unlock_irqrestore(&qhp->lock, flag); |
| 1355 | ring_kernel_rq_db(qhp, idx); |
| 1356 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1357 | return err; |
| 1358 | } |
| 1359 | |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 1360 | static void defer_srq_wr(struct t4_srq *srq, union t4_recv_wr *wqe, |
| 1361 | u64 wr_id, u8 len16) |
| 1362 | { |
| 1363 | struct t4_srq_pending_wr *pwr = &srq->pending_wrs[srq->pending_pidx]; |
| 1364 | |
| 1365 | pr_debug("%s cidx %u pidx %u wq_pidx %u in_use %u ooo_count %u wr_id 0x%llx pending_cidx %u pending_pidx %u pending_in_use %u\n", |
| 1366 | __func__, srq->cidx, srq->pidx, srq->wq_pidx, |
| 1367 | srq->in_use, srq->ooo_count, |
| 1368 | (unsigned long long)wr_id, srq->pending_cidx, |
| 1369 | srq->pending_pidx, srq->pending_in_use); |
| 1370 | pwr->wr_id = wr_id; |
| 1371 | pwr->len16 = len16; |
| 1372 | memcpy(&pwr->wqe, wqe, len16 * 16); |
| 1373 | t4_srq_produce_pending_wr(srq); |
| 1374 | } |
| 1375 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 1376 | int c4iw_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr, |
| 1377 | const struct ib_recv_wr **bad_wr) |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 1378 | { |
| 1379 | union t4_recv_wr *wqe, lwqe; |
| 1380 | struct c4iw_srq *srq; |
| 1381 | unsigned long flag; |
| 1382 | u8 len16 = 0; |
| 1383 | u16 idx = 0; |
| 1384 | int err = 0; |
| 1385 | u32 num_wrs; |
| 1386 | |
| 1387 | srq = to_c4iw_srq(ibsrq); |
| 1388 | spin_lock_irqsave(&srq->lock, flag); |
| 1389 | num_wrs = t4_srq_avail(&srq->wq); |
| 1390 | if (num_wrs == 0) { |
| 1391 | spin_unlock_irqrestore(&srq->lock, flag); |
| 1392 | return -ENOMEM; |
| 1393 | } |
| 1394 | while (wr) { |
| 1395 | if (wr->num_sge > T4_MAX_RECV_SGE) { |
| 1396 | err = -EINVAL; |
| 1397 | *bad_wr = wr; |
| 1398 | break; |
| 1399 | } |
| 1400 | wqe = &lwqe; |
| 1401 | if (num_wrs) |
| 1402 | err = build_srq_recv(wqe, wr, &len16); |
| 1403 | else |
| 1404 | err = -ENOMEM; |
| 1405 | if (err) { |
| 1406 | *bad_wr = wr; |
| 1407 | break; |
| 1408 | } |
| 1409 | |
| 1410 | wqe->recv.opcode = FW_RI_RECV_WR; |
| 1411 | wqe->recv.r1 = 0; |
| 1412 | wqe->recv.wrid = srq->wq.pidx; |
| 1413 | wqe->recv.r2[0] = 0; |
| 1414 | wqe->recv.r2[1] = 0; |
| 1415 | wqe->recv.r2[2] = 0; |
| 1416 | wqe->recv.len16 = len16; |
| 1417 | |
| 1418 | if (srq->wq.ooo_count || |
| 1419 | srq->wq.pending_in_use || |
| 1420 | srq->wq.sw_rq[srq->wq.pidx].valid) { |
| 1421 | defer_srq_wr(&srq->wq, wqe, wr->wr_id, len16); |
| 1422 | } else { |
| 1423 | srq->wq.sw_rq[srq->wq.pidx].wr_id = wr->wr_id; |
| 1424 | srq->wq.sw_rq[srq->wq.pidx].valid = 1; |
| 1425 | c4iw_copy_wr_to_srq(&srq->wq, wqe, len16); |
| 1426 | pr_debug("%s cidx %u pidx %u wq_pidx %u in_use %u wr_id 0x%llx\n", |
| 1427 | __func__, srq->wq.cidx, |
| 1428 | srq->wq.pidx, srq->wq.wq_pidx, |
| 1429 | srq->wq.in_use, |
| 1430 | (unsigned long long)wr->wr_id); |
| 1431 | t4_srq_produce(&srq->wq, len16); |
| 1432 | idx += DIV_ROUND_UP(len16 * 16, T4_EQ_ENTRY_SIZE); |
| 1433 | } |
| 1434 | wr = wr->next; |
| 1435 | num_wrs--; |
| 1436 | } |
| 1437 | if (idx) |
| 1438 | t4_ring_srq_db(&srq->wq, idx, len16, wqe); |
| 1439 | spin_unlock_irqrestore(&srq->lock, flag); |
| 1440 | return err; |
| 1441 | } |
| 1442 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1443 | static inline void build_term_codes(struct t4_cqe *err_cqe, u8 *layer_type, |
| 1444 | u8 *ecode) |
| 1445 | { |
| 1446 | int status; |
| 1447 | int tagged; |
| 1448 | int opcode; |
| 1449 | int rqtype; |
| 1450 | int send_inv; |
| 1451 | |
| 1452 | if (!err_cqe) { |
| 1453 | *layer_type = LAYER_RDMAP|DDP_LOCAL_CATA; |
| 1454 | *ecode = 0; |
| 1455 | return; |
| 1456 | } |
| 1457 | |
| 1458 | status = CQE_STATUS(err_cqe); |
| 1459 | opcode = CQE_OPCODE(err_cqe); |
| 1460 | rqtype = RQ_TYPE(err_cqe); |
| 1461 | send_inv = (opcode == FW_RI_SEND_WITH_INV) || |
| 1462 | (opcode == FW_RI_SEND_WITH_SE_INV); |
| 1463 | tagged = (opcode == FW_RI_RDMA_WRITE) || |
| 1464 | (rqtype && (opcode == FW_RI_READ_RESP)); |
| 1465 | |
| 1466 | switch (status) { |
| 1467 | case T4_ERR_STAG: |
| 1468 | if (send_inv) { |
| 1469 | *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP; |
| 1470 | *ecode = RDMAP_CANT_INV_STAG; |
| 1471 | } else { |
| 1472 | *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; |
| 1473 | *ecode = RDMAP_INV_STAG; |
| 1474 | } |
| 1475 | break; |
| 1476 | case T4_ERR_PDID: |
| 1477 | *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; |
| 1478 | if ((opcode == FW_RI_SEND_WITH_INV) || |
| 1479 | (opcode == FW_RI_SEND_WITH_SE_INV)) |
| 1480 | *ecode = RDMAP_CANT_INV_STAG; |
| 1481 | else |
| 1482 | *ecode = RDMAP_STAG_NOT_ASSOC; |
| 1483 | break; |
| 1484 | case T4_ERR_QPID: |
| 1485 | *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; |
| 1486 | *ecode = RDMAP_STAG_NOT_ASSOC; |
| 1487 | break; |
| 1488 | case T4_ERR_ACCESS: |
| 1489 | *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; |
| 1490 | *ecode = RDMAP_ACC_VIOL; |
| 1491 | break; |
| 1492 | case T4_ERR_WRAP: |
| 1493 | *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; |
| 1494 | *ecode = RDMAP_TO_WRAP; |
| 1495 | break; |
| 1496 | case T4_ERR_BOUND: |
| 1497 | if (tagged) { |
| 1498 | *layer_type = LAYER_DDP|DDP_TAGGED_ERR; |
| 1499 | *ecode = DDPT_BASE_BOUNDS; |
| 1500 | } else { |
| 1501 | *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; |
| 1502 | *ecode = RDMAP_BASE_BOUNDS; |
| 1503 | } |
| 1504 | break; |
| 1505 | case T4_ERR_INVALIDATE_SHARED_MR: |
| 1506 | case T4_ERR_INVALIDATE_MR_WITH_MW_BOUND: |
| 1507 | *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP; |
| 1508 | *ecode = RDMAP_CANT_INV_STAG; |
| 1509 | break; |
| 1510 | case T4_ERR_ECC: |
| 1511 | case T4_ERR_ECC_PSTAG: |
| 1512 | case T4_ERR_INTERNAL_ERR: |
| 1513 | *layer_type = LAYER_RDMAP|RDMAP_LOCAL_CATA; |
| 1514 | *ecode = 0; |
| 1515 | break; |
| 1516 | case T4_ERR_OUT_OF_RQE: |
| 1517 | *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; |
| 1518 | *ecode = DDPU_INV_MSN_NOBUF; |
| 1519 | break; |
| 1520 | case T4_ERR_PBL_ADDR_BOUND: |
| 1521 | *layer_type = LAYER_DDP|DDP_TAGGED_ERR; |
| 1522 | *ecode = DDPT_BASE_BOUNDS; |
| 1523 | break; |
| 1524 | case T4_ERR_CRC: |
| 1525 | *layer_type = LAYER_MPA|DDP_LLP; |
| 1526 | *ecode = MPA_CRC_ERR; |
| 1527 | break; |
| 1528 | case T4_ERR_MARKER: |
| 1529 | *layer_type = LAYER_MPA|DDP_LLP; |
| 1530 | *ecode = MPA_MARKER_ERR; |
| 1531 | break; |
| 1532 | case T4_ERR_PDU_LEN_ERR: |
| 1533 | *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; |
| 1534 | *ecode = DDPU_MSG_TOOBIG; |
| 1535 | break; |
| 1536 | case T4_ERR_DDP_VERSION: |
| 1537 | if (tagged) { |
| 1538 | *layer_type = LAYER_DDP|DDP_TAGGED_ERR; |
| 1539 | *ecode = DDPT_INV_VERS; |
| 1540 | } else { |
| 1541 | *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; |
| 1542 | *ecode = DDPU_INV_VERS; |
| 1543 | } |
| 1544 | break; |
| 1545 | case T4_ERR_RDMA_VERSION: |
| 1546 | *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP; |
| 1547 | *ecode = RDMAP_INV_VERS; |
| 1548 | break; |
| 1549 | case T4_ERR_OPCODE: |
| 1550 | *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP; |
| 1551 | *ecode = RDMAP_INV_OPCODE; |
| 1552 | break; |
| 1553 | case T4_ERR_DDP_QUEUE_NUM: |
| 1554 | *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; |
| 1555 | *ecode = DDPU_INV_QN; |
| 1556 | break; |
| 1557 | case T4_ERR_MSN: |
| 1558 | case T4_ERR_MSN_GAP: |
| 1559 | case T4_ERR_MSN_RANGE: |
| 1560 | case T4_ERR_IRD_OVERFLOW: |
| 1561 | *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; |
| 1562 | *ecode = DDPU_INV_MSN_RANGE; |
| 1563 | break; |
| 1564 | case T4_ERR_TBIT: |
| 1565 | *layer_type = LAYER_DDP|DDP_LOCAL_CATA; |
| 1566 | *ecode = 0; |
| 1567 | break; |
| 1568 | case T4_ERR_MO: |
| 1569 | *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; |
| 1570 | *ecode = DDPU_INV_MO; |
| 1571 | break; |
| 1572 | default: |
| 1573 | *layer_type = LAYER_RDMAP|DDP_LOCAL_CATA; |
| 1574 | *ecode = 0; |
| 1575 | break; |
| 1576 | } |
| 1577 | } |
| 1578 | |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 1579 | static void post_terminate(struct c4iw_qp *qhp, struct t4_cqe *err_cqe, |
| 1580 | gfp_t gfp) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1581 | { |
| 1582 | struct fw_ri_wr *wqe; |
| 1583 | struct sk_buff *skb; |
| 1584 | struct terminate_message *term; |
| 1585 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 1586 | pr_debug("qhp %p qid 0x%x tid %u\n", qhp, qhp->wq.sq.qid, |
Joe Perches | a9a4288 | 2017-02-09 14:23:51 -0800 | [diff] [blame] | 1587 | qhp->ep->hwtid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1588 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 1589 | skb = skb_dequeue(&qhp->ep->com.ep_skb_list); |
| 1590 | if (WARN_ON(!skb)) |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 1591 | return; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 1592 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1593 | set_wr_txq(skb, CPL_PRIORITY_DATA, qhp->ep->txq_idx); |
| 1594 | |
YueHaibing | ecb238f | 2018-04-28 15:31:06 +0800 | [diff] [blame] | 1595 | wqe = __skb_put_zero(skb, sizeof(*wqe)); |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1596 | wqe->op_compl = cpu_to_be32(FW_WR_OP_V(FW_RI_INIT_WR)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1597 | wqe->flowid_len16 = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1598 | FW_WR_FLOWID_V(qhp->ep->hwtid) | |
| 1599 | FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*wqe), 16))); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1600 | |
| 1601 | wqe->u.terminate.type = FW_RI_TYPE_TERMINATE; |
| 1602 | wqe->u.terminate.immdlen = cpu_to_be32(sizeof *term); |
| 1603 | term = (struct terminate_message *)wqe->u.terminate.termmsg; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1604 | if (qhp->attr.layer_etype == (LAYER_MPA|DDP_LLP)) { |
| 1605 | term->layer_etype = qhp->attr.layer_etype; |
| 1606 | term->ecode = qhp->attr.ecode; |
| 1607 | } else |
| 1608 | build_term_codes(err_cqe, &term->layer_etype, &term->ecode); |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 1609 | c4iw_ofld_send(&qhp->rhp->rdev, skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | /* |
| 1613 | * Assumes qhp lock is held. |
| 1614 | */ |
| 1615 | static void __flush_qp(struct c4iw_qp *qhp, struct c4iw_cq *rchp, |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1616 | struct c4iw_cq *schp) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1617 | { |
| 1618 | int count; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 1619 | int rq_flushed = 0, sq_flushed; |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1620 | unsigned long flag; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1621 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 1622 | pr_debug("qhp %p rchp %p schp %p\n", qhp, rchp, schp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1623 | |
Steve Wise | bc52e9c | 2017-11-09 07:21:26 -0800 | [diff] [blame] | 1624 | /* locking hierarchy: cqs lock first, then qp lock. */ |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1625 | spin_lock_irqsave(&rchp->lock, flag); |
Steve Wise | bc52e9c | 2017-11-09 07:21:26 -0800 | [diff] [blame] | 1626 | if (schp != rchp) |
| 1627 | spin_lock(&schp->lock); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1628 | spin_lock(&qhp->lock); |
Steve Wise | 1cf24dc | 2013-08-06 21:04:35 +0530 | [diff] [blame] | 1629 | |
| 1630 | if (qhp->wq.flushed) { |
| 1631 | spin_unlock(&qhp->lock); |
Steve Wise | bc52e9c | 2017-11-09 07:21:26 -0800 | [diff] [blame] | 1632 | if (schp != rchp) |
| 1633 | spin_unlock(&schp->lock); |
Steve Wise | 1cf24dc | 2013-08-06 21:04:35 +0530 | [diff] [blame] | 1634 | spin_unlock_irqrestore(&rchp->lock, flag); |
| 1635 | return; |
| 1636 | } |
| 1637 | qhp->wq.flushed = 1; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 1638 | t4_set_wq_in_error(&qhp->wq, 0); |
Steve Wise | 1cf24dc | 2013-08-06 21:04:35 +0530 | [diff] [blame] | 1639 | |
Bharat Potnuri | 2df19e1 | 2018-04-27 16:41:16 +0530 | [diff] [blame] | 1640 | c4iw_flush_hw_cq(rchp, qhp); |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 1641 | if (!qhp->srq) { |
| 1642 | c4iw_count_rcqes(&rchp->cq, &qhp->wq, &count); |
| 1643 | rq_flushed = c4iw_flush_rq(&qhp->wq, &rchp->cq, count); |
| 1644 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1645 | |
Steve Wise | 1cf24dc | 2013-08-06 21:04:35 +0530 | [diff] [blame] | 1646 | if (schp != rchp) |
Bharat Potnuri | 2df19e1 | 2018-04-27 16:41:16 +0530 | [diff] [blame] | 1647 | c4iw_flush_hw_cq(schp, qhp); |
Steve Wise | 678ea9b | 2014-07-31 14:35:43 -0500 | [diff] [blame] | 1648 | sq_flushed = c4iw_flush_sq(qhp); |
Steve Wise | bc52e9c | 2017-11-09 07:21:26 -0800 | [diff] [blame] | 1649 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1650 | spin_unlock(&qhp->lock); |
Steve Wise | bc52e9c | 2017-11-09 07:21:26 -0800 | [diff] [blame] | 1651 | if (schp != rchp) |
| 1652 | spin_unlock(&schp->lock); |
| 1653 | spin_unlock_irqrestore(&rchp->lock, flag); |
Steve Wise | 678ea9b | 2014-07-31 14:35:43 -0500 | [diff] [blame] | 1654 | |
| 1655 | if (schp == rchp) { |
Steve Wise | 335ebf6 | 2017-11-30 09:41:56 -0800 | [diff] [blame] | 1656 | if ((rq_flushed || sq_flushed) && |
| 1657 | t4_clear_cq_armed(&rchp->cq)) { |
Steve Wise | 678ea9b | 2014-07-31 14:35:43 -0500 | [diff] [blame] | 1658 | spin_lock_irqsave(&rchp->comp_handler_lock, flag); |
| 1659 | (*rchp->ibcq.comp_handler)(&rchp->ibcq, |
| 1660 | rchp->ibcq.cq_context); |
| 1661 | spin_unlock_irqrestore(&rchp->comp_handler_lock, flag); |
| 1662 | } |
| 1663 | } else { |
Steve Wise | 335ebf6 | 2017-11-30 09:41:56 -0800 | [diff] [blame] | 1664 | if (rq_flushed && t4_clear_cq_armed(&rchp->cq)) { |
Steve Wise | 678ea9b | 2014-07-31 14:35:43 -0500 | [diff] [blame] | 1665 | spin_lock_irqsave(&rchp->comp_handler_lock, flag); |
| 1666 | (*rchp->ibcq.comp_handler)(&rchp->ibcq, |
| 1667 | rchp->ibcq.cq_context); |
| 1668 | spin_unlock_irqrestore(&rchp->comp_handler_lock, flag); |
| 1669 | } |
Steve Wise | 335ebf6 | 2017-11-30 09:41:56 -0800 | [diff] [blame] | 1670 | if (sq_flushed && t4_clear_cq_armed(&schp->cq)) { |
Steve Wise | 678ea9b | 2014-07-31 14:35:43 -0500 | [diff] [blame] | 1671 | spin_lock_irqsave(&schp->comp_handler_lock, flag); |
| 1672 | (*schp->ibcq.comp_handler)(&schp->ibcq, |
| 1673 | schp->ibcq.cq_context); |
| 1674 | spin_unlock_irqrestore(&schp->comp_handler_lock, flag); |
| 1675 | } |
Kumar Sanghvi | 581bbe2 | 2011-10-24 21:20:21 +0530 | [diff] [blame] | 1676 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1679 | static void flush_qp(struct c4iw_qp *qhp) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1680 | { |
| 1681 | struct c4iw_cq *rchp, *schp; |
Kumar Sanghvi | 581bbe2 | 2011-10-24 21:20:21 +0530 | [diff] [blame] | 1682 | unsigned long flag; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1683 | |
Steve Wise | 1cf24dc | 2013-08-06 21:04:35 +0530 | [diff] [blame] | 1684 | rchp = to_c4iw_cq(qhp->ibqp.recv_cq); |
| 1685 | schp = to_c4iw_cq(qhp->ibqp.send_cq); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1686 | |
| 1687 | if (qhp->ibqp.uobject) { |
Steve Wise | 308aa2b | 2018-08-31 07:15:56 -0700 | [diff] [blame] | 1688 | |
| 1689 | /* for user qps, qhp->wq.flushed is protected by qhp->mutex */ |
| 1690 | if (qhp->wq.flushed) |
| 1691 | return; |
| 1692 | |
| 1693 | qhp->wq.flushed = 1; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 1694 | t4_set_wq_in_error(&qhp->wq, 0); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1695 | t4_set_cq_in_error(&rchp->cq); |
Kumar Sanghvi | 581bbe2 | 2011-10-24 21:20:21 +0530 | [diff] [blame] | 1696 | spin_lock_irqsave(&rchp->comp_handler_lock, flag); |
Kumar Sanghvi | 01e7da6 | 2011-10-13 13:51:30 +0530 | [diff] [blame] | 1697 | (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context); |
Kumar Sanghvi | 581bbe2 | 2011-10-24 21:20:21 +0530 | [diff] [blame] | 1698 | spin_unlock_irqrestore(&rchp->comp_handler_lock, flag); |
Kumar Sanghvi | 01e7da6 | 2011-10-13 13:51:30 +0530 | [diff] [blame] | 1699 | if (schp != rchp) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1700 | t4_set_cq_in_error(&schp->cq); |
Kumar Sanghvi | 581bbe2 | 2011-10-24 21:20:21 +0530 | [diff] [blame] | 1701 | spin_lock_irqsave(&schp->comp_handler_lock, flag); |
Kumar Sanghvi | 01e7da6 | 2011-10-13 13:51:30 +0530 | [diff] [blame] | 1702 | (*schp->ibcq.comp_handler)(&schp->ibcq, |
| 1703 | schp->ibcq.cq_context); |
Kumar Sanghvi | 581bbe2 | 2011-10-24 21:20:21 +0530 | [diff] [blame] | 1704 | spin_unlock_irqrestore(&schp->comp_handler_lock, flag); |
Kumar Sanghvi | 01e7da6 | 2011-10-13 13:51:30 +0530 | [diff] [blame] | 1705 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1706 | return; |
| 1707 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1708 | __flush_qp(qhp, rchp, schp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
Steve Wise | 73d6fca | 2010-07-23 19:12:27 +0000 | [diff] [blame] | 1711 | static int rdma_fini(struct c4iw_dev *rhp, struct c4iw_qp *qhp, |
| 1712 | struct c4iw_ep *ep) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1713 | { |
| 1714 | struct fw_ri_wr *wqe; |
| 1715 | int ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1716 | struct sk_buff *skb; |
| 1717 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 1718 | pr_debug("qhp %p qid 0x%x tid %u\n", qhp, qhp->wq.sq.qid, ep->hwtid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1719 | |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 1720 | skb = skb_dequeue(&ep->com.ep_skb_list); |
| 1721 | if (WARN_ON(!skb)) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1722 | return -ENOMEM; |
Hariprasad S | 4a74083 | 2016-06-10 01:05:15 +0530 | [diff] [blame] | 1723 | |
Steve Wise | 73d6fca | 2010-07-23 19:12:27 +0000 | [diff] [blame] | 1724 | set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1725 | |
YueHaibing | ecb238f | 2018-04-28 15:31:06 +0800 | [diff] [blame] | 1726 | wqe = __skb_put_zero(skb, sizeof(*wqe)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1727 | wqe->op_compl = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1728 | FW_WR_OP_V(FW_RI_INIT_WR) | |
| 1729 | FW_WR_COMPL_F); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1730 | wqe->flowid_len16 = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1731 | FW_WR_FLOWID_V(ep->hwtid) | |
| 1732 | FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*wqe), 16))); |
Steve Wise | ef885dc | 2017-09-26 13:12:16 -0700 | [diff] [blame] | 1733 | wqe->cookie = (uintptr_t)ep->com.wr_waitp; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1734 | |
| 1735 | wqe->u.fini.type = FW_RI_TYPE_FINI; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1736 | |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 1737 | ret = c4iw_ref_send_wait(&rhp->rdev, skb, ep->com.wr_waitp, |
| 1738 | qhp->ep->hwtid, qhp->wq.sq.qid, __func__); |
| 1739 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 1740 | pr_debug("ret %d\n", ret); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1741 | return ret; |
| 1742 | } |
| 1743 | |
| 1744 | static void build_rtr_msg(u8 p2p_type, struct fw_ri_init *init) |
| 1745 | { |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 1746 | pr_debug("p2p_type = %d\n", p2p_type); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1747 | memset(&init->u, 0, sizeof init->u); |
| 1748 | switch (p2p_type) { |
| 1749 | case FW_RI_INIT_P2PTYPE_RDMA_WRITE: |
| 1750 | init->u.write.opcode = FW_RI_RDMA_WRITE_WR; |
| 1751 | init->u.write.stag_sink = cpu_to_be32(1); |
| 1752 | init->u.write.to_sink = cpu_to_be64(1); |
| 1753 | init->u.write.u.immd_src[0].op = FW_RI_DATA_IMMD; |
| 1754 | init->u.write.len16 = DIV_ROUND_UP(sizeof init->u.write + |
| 1755 | sizeof(struct fw_ri_immd), |
| 1756 | 16); |
| 1757 | break; |
| 1758 | case FW_RI_INIT_P2PTYPE_READ_REQ: |
| 1759 | init->u.write.opcode = FW_RI_RDMA_READ_WR; |
| 1760 | init->u.read.stag_src = cpu_to_be32(1); |
| 1761 | init->u.read.to_src_lo = cpu_to_be32(1); |
| 1762 | init->u.read.stag_sink = cpu_to_be32(1); |
| 1763 | init->u.read.to_sink_lo = cpu_to_be32(1); |
| 1764 | init->u.read.len16 = DIV_ROUND_UP(sizeof init->u.read, 16); |
| 1765 | break; |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | static int rdma_init(struct c4iw_dev *rhp, struct c4iw_qp *qhp) |
| 1770 | { |
| 1771 | struct fw_ri_wr *wqe; |
| 1772 | int ret; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1773 | struct sk_buff *skb; |
| 1774 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 1775 | pr_debug("qhp %p qid 0x%x tid %u ird %u ord %u\n", qhp, |
Joe Perches | a9a4288 | 2017-02-09 14:23:51 -0800 | [diff] [blame] | 1776 | qhp->wq.sq.qid, qhp->ep->hwtid, qhp->ep->ird, qhp->ep->ord); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1777 | |
David Rientjes | d3c814e | 2010-07-21 02:44:56 +0000 | [diff] [blame] | 1778 | skb = alloc_skb(sizeof *wqe, GFP_KERNEL); |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 1779 | if (!skb) { |
| 1780 | ret = -ENOMEM; |
| 1781 | goto out; |
| 1782 | } |
| 1783 | ret = alloc_ird(rhp, qhp->attr.max_ird); |
| 1784 | if (ret) { |
| 1785 | qhp->attr.max_ird = 0; |
| 1786 | kfree_skb(skb); |
| 1787 | goto out; |
| 1788 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1789 | set_wr_txq(skb, CPL_PRIORITY_DATA, qhp->ep->txq_idx); |
| 1790 | |
YueHaibing | ecb238f | 2018-04-28 15:31:06 +0800 | [diff] [blame] | 1791 | wqe = __skb_put_zero(skb, sizeof(*wqe)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1792 | wqe->op_compl = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1793 | FW_WR_OP_V(FW_RI_INIT_WR) | |
| 1794 | FW_WR_COMPL_F); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1795 | wqe->flowid_len16 = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1796 | FW_WR_FLOWID_V(qhp->ep->hwtid) | |
| 1797 | FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*wqe), 16))); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1798 | |
Steve Wise | ef885dc | 2017-09-26 13:12:16 -0700 | [diff] [blame] | 1799 | wqe->cookie = (uintptr_t)qhp->ep->com.wr_waitp; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1800 | |
| 1801 | wqe->u.init.type = FW_RI_TYPE_INIT; |
| 1802 | wqe->u.init.mpareqbit_p2ptype = |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 1803 | FW_RI_WR_MPAREQBIT_V(qhp->attr.mpa_attr.initiator) | |
| 1804 | FW_RI_WR_P2PTYPE_V(qhp->attr.mpa_attr.p2p_type); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1805 | wqe->u.init.mpa_attrs = FW_RI_MPA_IETF_ENABLE; |
| 1806 | if (qhp->attr.mpa_attr.recv_marker_enabled) |
| 1807 | wqe->u.init.mpa_attrs |= FW_RI_MPA_RX_MARKER_ENABLE; |
| 1808 | if (qhp->attr.mpa_attr.xmit_marker_enabled) |
| 1809 | wqe->u.init.mpa_attrs |= FW_RI_MPA_TX_MARKER_ENABLE; |
| 1810 | if (qhp->attr.mpa_attr.crc_enabled) |
| 1811 | wqe->u.init.mpa_attrs |= FW_RI_MPA_CRC_ENABLE; |
| 1812 | |
| 1813 | wqe->u.init.qp_caps = FW_RI_QP_RDMA_READ_ENABLE | |
| 1814 | FW_RI_QP_RDMA_WRITE_ENABLE | |
| 1815 | FW_RI_QP_BIND_ENABLE; |
| 1816 | if (!qhp->ibqp.uobject) |
| 1817 | wqe->u.init.qp_caps |= FW_RI_QP_FAST_REGISTER_ENABLE | |
| 1818 | FW_RI_QP_STAG0_ENABLE; |
| 1819 | wqe->u.init.nrqe = cpu_to_be16(t4_rqes_posted(&qhp->wq)); |
| 1820 | wqe->u.init.pdid = cpu_to_be32(qhp->attr.pd); |
| 1821 | wqe->u.init.qpid = cpu_to_be32(qhp->wq.sq.qid); |
| 1822 | wqe->u.init.sq_eqid = cpu_to_be32(qhp->wq.sq.qid); |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 1823 | if (qhp->srq) { |
| 1824 | wqe->u.init.rq_eqid = cpu_to_be32(FW_RI_INIT_RQEQID_SRQ | |
| 1825 | qhp->srq->idx); |
| 1826 | } else { |
| 1827 | wqe->u.init.rq_eqid = cpu_to_be32(qhp->wq.rq.qid); |
| 1828 | wqe->u.init.hwrqsize = cpu_to_be32(qhp->wq.rq.rqt_size); |
| 1829 | wqe->u.init.hwrqaddr = cpu_to_be32(qhp->wq.rq.rqt_hwaddr - |
| 1830 | rhp->rdev.lldi.vr->rq.start); |
| 1831 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1832 | wqe->u.init.scqid = cpu_to_be32(qhp->attr.scq); |
| 1833 | wqe->u.init.rcqid = cpu_to_be32(qhp->attr.rcq); |
| 1834 | wqe->u.init.ord_max = cpu_to_be32(qhp->attr.max_ord); |
| 1835 | wqe->u.init.ird_max = cpu_to_be32(qhp->attr.max_ird); |
| 1836 | wqe->u.init.iss = cpu_to_be32(qhp->ep->snd_seq); |
| 1837 | wqe->u.init.irs = cpu_to_be32(qhp->ep->rcv_seq); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1838 | if (qhp->attr.mpa_attr.initiator) |
| 1839 | build_rtr_msg(qhp->attr.mpa_attr.p2p_type, &wqe->u.init); |
| 1840 | |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 1841 | ret = c4iw_ref_send_wait(&rhp->rdev, skb, qhp->ep->com.wr_waitp, |
| 1842 | qhp->ep->hwtid, qhp->wq.sq.qid, __func__); |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 1843 | if (!ret) |
| 1844 | goto out; |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 1845 | |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 1846 | free_ird(rhp, qhp->attr.max_ird); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1847 | out: |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 1848 | pr_debug("ret %d\n", ret); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1849 | return ret; |
| 1850 | } |
| 1851 | |
| 1852 | int c4iw_modify_qp(struct c4iw_dev *rhp, struct c4iw_qp *qhp, |
| 1853 | enum c4iw_qp_attr_mask mask, |
| 1854 | struct c4iw_qp_attributes *attrs, |
| 1855 | int internal) |
| 1856 | { |
| 1857 | int ret = 0; |
| 1858 | struct c4iw_qp_attributes newattr = qhp->attr; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1859 | int disconnect = 0; |
| 1860 | int terminate = 0; |
| 1861 | int abort = 0; |
| 1862 | int free = 0; |
| 1863 | struct c4iw_ep *ep = NULL; |
| 1864 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 1865 | pr_debug("qhp %p sqid 0x%x rqid 0x%x ep %p state %d -> %d\n", |
Joe Perches | a9a4288 | 2017-02-09 14:23:51 -0800 | [diff] [blame] | 1866 | qhp, qhp->wq.sq.qid, qhp->wq.rq.qid, qhp->ep, qhp->attr.state, |
| 1867 | (mask & C4IW_QP_ATTR_NEXT_STATE) ? attrs->next_state : -1); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1868 | |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1869 | mutex_lock(&qhp->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1870 | |
| 1871 | /* Process attr changes if in IDLE */ |
| 1872 | if (mask & C4IW_QP_ATTR_VALID_MODIFY) { |
| 1873 | if (qhp->attr.state != C4IW_QP_STATE_IDLE) { |
| 1874 | ret = -EIO; |
| 1875 | goto out; |
| 1876 | } |
| 1877 | if (mask & C4IW_QP_ATTR_ENABLE_RDMA_READ) |
| 1878 | newattr.enable_rdma_read = attrs->enable_rdma_read; |
| 1879 | if (mask & C4IW_QP_ATTR_ENABLE_RDMA_WRITE) |
| 1880 | newattr.enable_rdma_write = attrs->enable_rdma_write; |
| 1881 | if (mask & C4IW_QP_ATTR_ENABLE_RDMA_BIND) |
| 1882 | newattr.enable_bind = attrs->enable_bind; |
| 1883 | if (mask & C4IW_QP_ATTR_MAX_ORD) { |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 1884 | if (attrs->max_ord > c4iw_max_read_depth) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1885 | ret = -EINVAL; |
| 1886 | goto out; |
| 1887 | } |
| 1888 | newattr.max_ord = attrs->max_ord; |
| 1889 | } |
| 1890 | if (mask & C4IW_QP_ATTR_MAX_IRD) { |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 1891 | if (attrs->max_ird > cur_max_read_depth(rhp)) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1892 | ret = -EINVAL; |
| 1893 | goto out; |
| 1894 | } |
| 1895 | newattr.max_ird = attrs->max_ird; |
| 1896 | } |
| 1897 | qhp->attr = newattr; |
| 1898 | } |
| 1899 | |
Vipul Pandya | 2c97478 | 2012-05-18 15:29:28 +0530 | [diff] [blame] | 1900 | if (mask & C4IW_QP_ATTR_SQ_DB) { |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 1901 | ret = ring_kernel_sq_db(qhp, attrs->sq_db_inc); |
Vipul Pandya | 2c97478 | 2012-05-18 15:29:28 +0530 | [diff] [blame] | 1902 | goto out; |
| 1903 | } |
| 1904 | if (mask & C4IW_QP_ATTR_RQ_DB) { |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 1905 | ret = ring_kernel_rq_db(qhp, attrs->rq_db_inc); |
Vipul Pandya | 2c97478 | 2012-05-18 15:29:28 +0530 | [diff] [blame] | 1906 | goto out; |
| 1907 | } |
| 1908 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1909 | if (!(mask & C4IW_QP_ATTR_NEXT_STATE)) |
| 1910 | goto out; |
| 1911 | if (qhp->attr.state == attrs->next_state) |
| 1912 | goto out; |
| 1913 | |
| 1914 | switch (qhp->attr.state) { |
| 1915 | case C4IW_QP_STATE_IDLE: |
| 1916 | switch (attrs->next_state) { |
| 1917 | case C4IW_QP_STATE_RTS: |
| 1918 | if (!(mask & C4IW_QP_ATTR_LLP_STREAM_HANDLE)) { |
| 1919 | ret = -EINVAL; |
| 1920 | goto out; |
| 1921 | } |
| 1922 | if (!(mask & C4IW_QP_ATTR_MPA_ATTR)) { |
| 1923 | ret = -EINVAL; |
| 1924 | goto out; |
| 1925 | } |
| 1926 | qhp->attr.mpa_attr = attrs->mpa_attr; |
| 1927 | qhp->attr.llp_stream_handle = attrs->llp_stream_handle; |
| 1928 | qhp->ep = qhp->attr.llp_stream_handle; |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1929 | set_state(qhp, C4IW_QP_STATE_RTS); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1930 | |
| 1931 | /* |
| 1932 | * Ref the endpoint here and deref when we |
| 1933 | * disassociate the endpoint from the QP. This |
| 1934 | * happens in CLOSING->IDLE transition or *->ERROR |
| 1935 | * transition. |
| 1936 | */ |
| 1937 | c4iw_get_ep(&qhp->ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1938 | ret = rdma_init(rhp, qhp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1939 | if (ret) |
| 1940 | goto err; |
| 1941 | break; |
| 1942 | case C4IW_QP_STATE_ERROR: |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1943 | set_state(qhp, C4IW_QP_STATE_ERROR); |
| 1944 | flush_qp(qhp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1945 | break; |
| 1946 | default: |
| 1947 | ret = -EINVAL; |
| 1948 | goto out; |
| 1949 | } |
| 1950 | break; |
| 1951 | case C4IW_QP_STATE_RTS: |
| 1952 | switch (attrs->next_state) { |
| 1953 | case C4IW_QP_STATE_CLOSING: |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 1954 | t4_set_wq_in_error(&qhp->wq, 0); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1955 | set_state(qhp, C4IW_QP_STATE_CLOSING); |
Steve Wise | 73d6fca | 2010-07-23 19:12:27 +0000 | [diff] [blame] | 1956 | ep = qhp->ep; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1957 | if (!internal) { |
| 1958 | abort = 0; |
| 1959 | disconnect = 1; |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1960 | c4iw_get_ep(&qhp->ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1961 | } |
Steve Wise | 73d6fca | 2010-07-23 19:12:27 +0000 | [diff] [blame] | 1962 | ret = rdma_fini(rhp, qhp, ep); |
Steve Wise | 8da7e7a | 2011-06-14 20:59:27 +0000 | [diff] [blame] | 1963 | if (ret) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1964 | goto err; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1965 | break; |
| 1966 | case C4IW_QP_STATE_TERMINATE: |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 1967 | t4_set_wq_in_error(&qhp->wq, 0); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1968 | set_state(qhp, C4IW_QP_STATE_TERMINATE); |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 1969 | qhp->attr.layer_etype = attrs->layer_etype; |
| 1970 | qhp->attr.ecode = attrs->ecode; |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 1971 | ep = qhp->ep; |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1972 | if (!internal) { |
| 1973 | c4iw_get_ep(&qhp->ep->com); |
Steve Wise | 0e42c1f | 2010-09-10 11:15:09 -0500 | [diff] [blame] | 1974 | terminate = 1; |
Steve Wise | cc18b93 | 2014-04-24 14:31:53 -0500 | [diff] [blame] | 1975 | disconnect = 1; |
| 1976 | } else { |
| 1977 | terminate = qhp->attr.send_term; |
Steve Wise | 0999257 | 2013-08-06 21:04:40 +0530 | [diff] [blame] | 1978 | ret = rdma_fini(rhp, qhp, ep); |
| 1979 | if (ret) |
| 1980 | goto err; |
| 1981 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1982 | break; |
| 1983 | case C4IW_QP_STATE_ERROR: |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 1984 | t4_set_wq_in_error(&qhp->wq, 0); |
Steve Wise | b4e2901 | 2014-04-09 09:38:26 -0500 | [diff] [blame] | 1985 | set_state(qhp, C4IW_QP_STATE_ERROR); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1986 | if (!internal) { |
| 1987 | abort = 1; |
| 1988 | disconnect = 1; |
| 1989 | ep = qhp->ep; |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 1990 | c4iw_get_ep(&qhp->ep->com); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1991 | } |
| 1992 | goto err; |
| 1993 | break; |
| 1994 | default: |
| 1995 | ret = -EINVAL; |
| 1996 | goto out; |
| 1997 | } |
| 1998 | break; |
| 1999 | case C4IW_QP_STATE_CLOSING: |
Steve Wise | 4fe7c29 | 2016-12-22 07:04:59 -0800 | [diff] [blame] | 2000 | |
| 2001 | /* |
| 2002 | * Allow kernel users to move to ERROR for qp draining. |
| 2003 | */ |
| 2004 | if (!internal && (qhp->ibqp.uobject || attrs->next_state != |
| 2005 | C4IW_QP_STATE_ERROR)) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2006 | ret = -EINVAL; |
| 2007 | goto out; |
| 2008 | } |
| 2009 | switch (attrs->next_state) { |
| 2010 | case C4IW_QP_STATE_IDLE: |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2011 | flush_qp(qhp); |
| 2012 | set_state(qhp, C4IW_QP_STATE_IDLE); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2013 | qhp->attr.llp_stream_handle = NULL; |
| 2014 | c4iw_put_ep(&qhp->ep->com); |
| 2015 | qhp->ep = NULL; |
| 2016 | wake_up(&qhp->wait); |
| 2017 | break; |
| 2018 | case C4IW_QP_STATE_ERROR: |
| 2019 | goto err; |
| 2020 | default: |
| 2021 | ret = -EINVAL; |
| 2022 | goto err; |
| 2023 | } |
| 2024 | break; |
| 2025 | case C4IW_QP_STATE_ERROR: |
| 2026 | if (attrs->next_state != C4IW_QP_STATE_IDLE) { |
| 2027 | ret = -EINVAL; |
| 2028 | goto out; |
| 2029 | } |
| 2030 | if (!t4_sq_empty(&qhp->wq) || !t4_rq_empty(&qhp->wq)) { |
| 2031 | ret = -EINVAL; |
| 2032 | goto out; |
| 2033 | } |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2034 | set_state(qhp, C4IW_QP_STATE_IDLE); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2035 | break; |
| 2036 | case C4IW_QP_STATE_TERMINATE: |
| 2037 | if (!internal) { |
| 2038 | ret = -EINVAL; |
| 2039 | goto out; |
| 2040 | } |
| 2041 | goto err; |
| 2042 | break; |
| 2043 | default: |
Joe Perches | 700456b | 2017-02-09 14:23:50 -0800 | [diff] [blame] | 2044 | pr_err("%s in a bad state %d\n", __func__, qhp->attr.state); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2045 | ret = -EINVAL; |
| 2046 | goto err; |
| 2047 | break; |
| 2048 | } |
| 2049 | goto out; |
| 2050 | err: |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 2051 | pr_debug("disassociating ep %p qpid 0x%x\n", qhp->ep, |
Joe Perches | a9a4288 | 2017-02-09 14:23:51 -0800 | [diff] [blame] | 2052 | qhp->wq.sq.qid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2053 | |
| 2054 | /* disassociate the LLP connection */ |
| 2055 | qhp->attr.llp_stream_handle = NULL; |
Steve Wise | af93fb5 | 2010-09-10 11:14:48 -0500 | [diff] [blame] | 2056 | if (!ep) |
| 2057 | ep = qhp->ep; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2058 | qhp->ep = NULL; |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2059 | set_state(qhp, C4IW_QP_STATE_ERROR); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2060 | free = 1; |
Vipul Pandya | 91e9c071 | 2013-01-07 13:11:51 +0000 | [diff] [blame] | 2061 | abort = 1; |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2062 | flush_qp(qhp); |
Steve Wise | 5b341808 | 2014-11-21 09:36:36 -0600 | [diff] [blame] | 2063 | wake_up(&qhp->wait); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2064 | out: |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2065 | mutex_unlock(&qhp->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2066 | |
| 2067 | if (terminate) |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2068 | post_terminate(qhp, NULL, internal ? GFP_ATOMIC : GFP_KERNEL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2069 | |
| 2070 | /* |
| 2071 | * If disconnect is 1, then we need to initiate a disconnect |
| 2072 | * on the EP. This can be a normal close (RTS->CLOSING) or |
| 2073 | * an abnormal close (RTS/CLOSING->ERROR). |
| 2074 | */ |
| 2075 | if (disconnect) { |
Roland Dreier | be4c9ba | 2010-05-05 14:45:40 -0700 | [diff] [blame] | 2076 | c4iw_ep_disconnect(ep, abort, internal ? GFP_ATOMIC : |
| 2077 | GFP_KERNEL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2078 | c4iw_put_ep(&ep->com); |
| 2079 | } |
| 2080 | |
| 2081 | /* |
| 2082 | * If free is 1, then we've disassociated the EP from the QP |
| 2083 | * and we need to dereference the EP. |
| 2084 | */ |
| 2085 | if (free) |
| 2086 | c4iw_put_ep(&ep->com); |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 2087 | pr_debug("exit state %d\n", qhp->attr.state); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2088 | return ret; |
| 2089 | } |
| 2090 | |
| 2091 | int c4iw_destroy_qp(struct ib_qp *ib_qp) |
| 2092 | { |
| 2093 | struct c4iw_dev *rhp; |
| 2094 | struct c4iw_qp *qhp; |
| 2095 | struct c4iw_qp_attributes attrs; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2096 | |
| 2097 | qhp = to_c4iw_qp(ib_qp); |
| 2098 | rhp = qhp->rhp; |
| 2099 | |
| 2100 | attrs.next_state = C4IW_QP_STATE_ERROR; |
Kumar Sanghvi | d2fe99e | 2011-09-25 20:17:44 +0530 | [diff] [blame] | 2101 | if (qhp->attr.state == C4IW_QP_STATE_TERMINATE) |
| 2102 | c4iw_modify_qp(rhp, qhp, C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
| 2103 | else |
| 2104 | c4iw_modify_qp(rhp, qhp, C4IW_QP_ATTR_NEXT_STATE, &attrs, 0); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2105 | wait_event(qhp->wait, !qhp->ep); |
| 2106 | |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 2107 | remove_handle(rhp, &rhp->qpidr, qhp->wq.sq.qid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2108 | |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 2109 | spin_lock_irq(&rhp->lock); |
| 2110 | if (!list_empty(&qhp->db_fc_entry)) |
| 2111 | list_del_init(&qhp->db_fc_entry); |
| 2112 | spin_unlock_irq(&rhp->lock); |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 2113 | free_ird(rhp, qhp->attr.max_ird); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 2114 | |
Steve Wise | ad61a4c | 2016-07-29 11:00:54 -0700 | [diff] [blame] | 2115 | c4iw_qp_rem_ref(ib_qp); |
| 2116 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 2117 | pr_debug("ib_qp %p qpid 0x%0x\n", ib_qp, qhp->wq.sq.qid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2118 | return 0; |
| 2119 | } |
| 2120 | |
| 2121 | struct ib_qp *c4iw_create_qp(struct ib_pd *pd, struct ib_qp_init_attr *attrs, |
| 2122 | struct ib_udata *udata) |
| 2123 | { |
| 2124 | struct c4iw_dev *rhp; |
| 2125 | struct c4iw_qp *qhp; |
| 2126 | struct c4iw_pd *php; |
| 2127 | struct c4iw_cq *schp; |
| 2128 | struct c4iw_cq *rchp; |
| 2129 | struct c4iw_create_qp_resp uresp; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2130 | unsigned int sqsize, rqsize = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2131 | struct c4iw_ucontext *ucontext; |
| 2132 | int ret; |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2133 | struct c4iw_mm_entry *sq_key_mm, *rq_key_mm = NULL, *sq_db_key_mm; |
| 2134 | struct c4iw_mm_entry *rq_db_key_mm = NULL, *ma_sync_key_mm = NULL; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2135 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 2136 | pr_debug("ib_pd %p\n", pd); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2137 | |
| 2138 | if (attrs->qp_type != IB_QPT_RC) |
| 2139 | return ERR_PTR(-EINVAL); |
| 2140 | |
| 2141 | php = to_c4iw_pd(pd); |
| 2142 | rhp = php->rhp; |
| 2143 | schp = get_chp(rhp, ((struct c4iw_cq *)attrs->send_cq)->cq.cqid); |
| 2144 | rchp = get_chp(rhp, ((struct c4iw_cq *)attrs->recv_cq)->cq.cqid); |
| 2145 | if (!schp || !rchp) |
| 2146 | return ERR_PTR(-EINVAL); |
| 2147 | |
| 2148 | if (attrs->cap.max_inline_data > T4_MAX_SEND_INLINE) |
| 2149 | return ERR_PTR(-EINVAL); |
| 2150 | |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2151 | if (!attrs->srq) { |
| 2152 | if (attrs->cap.max_recv_wr > rhp->rdev.hw_queue.t4_max_rq_size) |
| 2153 | return ERR_PTR(-E2BIG); |
| 2154 | rqsize = attrs->cap.max_recv_wr + 1; |
| 2155 | if (rqsize < 8) |
| 2156 | rqsize = 8; |
| 2157 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2158 | |
Hariprasad Shenai | 66eb19a | 2014-07-21 20:55:15 +0530 | [diff] [blame] | 2159 | if (attrs->cap.max_send_wr > rhp->rdev.hw_queue.t4_max_sq_size) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2160 | return ERR_PTR(-E2BIG); |
Hariprasad Shenai | 66eb19a | 2014-07-21 20:55:15 +0530 | [diff] [blame] | 2161 | sqsize = attrs->cap.max_send_wr + 1; |
| 2162 | if (sqsize < 8) |
| 2163 | sqsize = 8; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2164 | |
| 2165 | ucontext = pd->uobject ? to_c4iw_ucontext(pd->uobject->context) : NULL; |
| 2166 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2167 | qhp = kzalloc(sizeof(*qhp), GFP_KERNEL); |
| 2168 | if (!qhp) |
| 2169 | return ERR_PTR(-ENOMEM); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2170 | |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 2171 | qhp->wr_waitp = c4iw_alloc_wr_wait(GFP_KERNEL); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2172 | if (!qhp->wr_waitp) { |
| 2173 | ret = -ENOMEM; |
| 2174 | goto err_free_qhp; |
| 2175 | } |
| 2176 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2177 | qhp->wq.sq.size = sqsize; |
Hariprasad Shenai | 66eb19a | 2014-07-21 20:55:15 +0530 | [diff] [blame] | 2178 | qhp->wq.sq.memsize = |
| 2179 | (sqsize + rhp->rdev.hw_queue.t4_eq_status_entries) * |
| 2180 | sizeof(*qhp->wq.sq.queue) + 16 * sizeof(__be64); |
Steve Wise | 1cf24dc | 2013-08-06 21:04:35 +0530 | [diff] [blame] | 2181 | qhp->wq.sq.flush_cidx = -1; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2182 | if (!attrs->srq) { |
| 2183 | qhp->wq.rq.size = rqsize; |
| 2184 | qhp->wq.rq.memsize = |
| 2185 | (rqsize + rhp->rdev.hw_queue.t4_eq_status_entries) * |
| 2186 | sizeof(*qhp->wq.rq.queue); |
| 2187 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2188 | |
| 2189 | if (ucontext) { |
| 2190 | qhp->wq.sq.memsize = roundup(qhp->wq.sq.memsize, PAGE_SIZE); |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2191 | if (!attrs->srq) |
| 2192 | qhp->wq.rq.memsize = |
| 2193 | roundup(qhp->wq.rq.memsize, PAGE_SIZE); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2196 | ret = create_qp(&rhp->rdev, &qhp->wq, &schp->cq, &rchp->cq, |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2197 | ucontext ? &ucontext->uctx : &rhp->rdev.uctx, |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2198 | qhp->wr_waitp, !attrs->srq); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2199 | if (ret) |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2200 | goto err_free_wr_wait; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2201 | |
| 2202 | attrs->cap.max_recv_wr = rqsize - 1; |
| 2203 | attrs->cap.max_send_wr = sqsize - 1; |
| 2204 | attrs->cap.max_inline_data = T4_MAX_SEND_INLINE; |
| 2205 | |
| 2206 | qhp->rhp = rhp; |
| 2207 | qhp->attr.pd = php->pdid; |
| 2208 | qhp->attr.scq = ((struct c4iw_cq *) attrs->send_cq)->cq.cqid; |
| 2209 | qhp->attr.rcq = ((struct c4iw_cq *) attrs->recv_cq)->cq.cqid; |
| 2210 | qhp->attr.sq_num_entries = attrs->cap.max_send_wr; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2211 | qhp->attr.sq_max_sges = attrs->cap.max_send_sge; |
| 2212 | qhp->attr.sq_max_sges_rdma_write = attrs->cap.max_send_sge; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2213 | if (!attrs->srq) { |
| 2214 | qhp->attr.rq_num_entries = attrs->cap.max_recv_wr; |
| 2215 | qhp->attr.rq_max_sges = attrs->cap.max_recv_sge; |
| 2216 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2217 | qhp->attr.state = C4IW_QP_STATE_IDLE; |
| 2218 | qhp->attr.next_state = C4IW_QP_STATE_IDLE; |
| 2219 | qhp->attr.enable_rdma_read = 1; |
| 2220 | qhp->attr.enable_rdma_write = 1; |
| 2221 | qhp->attr.enable_bind = 1; |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 2222 | qhp->attr.max_ord = 0; |
| 2223 | qhp->attr.max_ird = 0; |
Steve Wise | ba32de9 | 2014-03-19 17:44:43 +0530 | [diff] [blame] | 2224 | qhp->sq_sig_all = attrs->sq_sig_type == IB_SIGNAL_ALL_WR; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2225 | spin_lock_init(&qhp->lock); |
Steve Wise | 2f5b48c | 2010-09-10 11:15:36 -0500 | [diff] [blame] | 2226 | mutex_init(&qhp->mutex); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2227 | init_waitqueue_head(&qhp->wait); |
Steve Wise | ad61a4c | 2016-07-29 11:00:54 -0700 | [diff] [blame] | 2228 | kref_init(&qhp->kref); |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 2229 | INIT_WORK(&qhp->free_work, free_qp_work); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2230 | |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 2231 | ret = insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.sq.qid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2232 | if (ret) |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2233 | goto err_destroy_qp; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2234 | |
Leon Romanovsky | 9950acf | 2017-10-29 21:34:35 +0200 | [diff] [blame] | 2235 | if (udata && ucontext) { |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2236 | sq_key_mm = kmalloc(sizeof(*sq_key_mm), GFP_KERNEL); |
| 2237 | if (!sq_key_mm) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2238 | ret = -ENOMEM; |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2239 | goto err_remove_handle; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2240 | } |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2241 | if (!attrs->srq) { |
| 2242 | rq_key_mm = kmalloc(sizeof(*rq_key_mm), GFP_KERNEL); |
| 2243 | if (!rq_key_mm) { |
| 2244 | ret = -ENOMEM; |
| 2245 | goto err_free_sq_key; |
| 2246 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2247 | } |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2248 | sq_db_key_mm = kmalloc(sizeof(*sq_db_key_mm), GFP_KERNEL); |
| 2249 | if (!sq_db_key_mm) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2250 | ret = -ENOMEM; |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2251 | goto err_free_rq_key; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2252 | } |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2253 | if (!attrs->srq) { |
| 2254 | rq_db_key_mm = |
| 2255 | kmalloc(sizeof(*rq_db_key_mm), GFP_KERNEL); |
| 2256 | if (!rq_db_key_mm) { |
| 2257 | ret = -ENOMEM; |
| 2258 | goto err_free_sq_db_key; |
| 2259 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2260 | } |
Dan Carpenter | 8001b71 | 2018-08-02 10:56:13 +0300 | [diff] [blame] | 2261 | memset(&uresp, 0, sizeof(uresp)); |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 2262 | if (t4_sq_onchip(&qhp->wq.sq)) { |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2263 | ma_sync_key_mm = kmalloc(sizeof(*ma_sync_key_mm), |
| 2264 | GFP_KERNEL); |
| 2265 | if (!ma_sync_key_mm) { |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 2266 | ret = -ENOMEM; |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2267 | goto err_free_rq_db_key; |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 2268 | } |
| 2269 | uresp.flags = C4IW_QPF_ONCHIP; |
Dan Carpenter | 8001b71 | 2018-08-02 10:56:13 +0300 | [diff] [blame] | 2270 | } |
Potnuri Bharat Teja | b9855f4 | 2018-08-02 11:33:03 +0530 | [diff] [blame] | 2271 | if (rhp->rdev.lldi.write_w_imm_support) |
| 2272 | uresp.flags |= C4IW_QPF_WRITE_W_IMM; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2273 | uresp.qid_mask = rhp->rdev.qpmask; |
| 2274 | uresp.sqid = qhp->wq.sq.qid; |
| 2275 | uresp.sq_size = qhp->wq.sq.size; |
| 2276 | uresp.sq_memsize = qhp->wq.sq.memsize; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2277 | if (!attrs->srq) { |
| 2278 | uresp.rqid = qhp->wq.rq.qid; |
| 2279 | uresp.rq_size = qhp->wq.rq.size; |
| 2280 | uresp.rq_memsize = qhp->wq.rq.memsize; |
| 2281 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2282 | spin_lock(&ucontext->mmap_lock); |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2283 | if (ma_sync_key_mm) { |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 2284 | uresp.ma_sync_key = ucontext->key; |
| 2285 | ucontext->key += PAGE_SIZE; |
| 2286 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2287 | uresp.sq_key = ucontext->key; |
| 2288 | ucontext->key += PAGE_SIZE; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2289 | if (!attrs->srq) { |
| 2290 | uresp.rq_key = ucontext->key; |
| 2291 | ucontext->key += PAGE_SIZE; |
| 2292 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2293 | uresp.sq_db_gts_key = ucontext->key; |
| 2294 | ucontext->key += PAGE_SIZE; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2295 | if (!attrs->srq) { |
| 2296 | uresp.rq_db_gts_key = ucontext->key; |
| 2297 | ucontext->key += PAGE_SIZE; |
| 2298 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2299 | spin_unlock(&ucontext->mmap_lock); |
| 2300 | ret = ib_copy_to_udata(udata, &uresp, sizeof uresp); |
| 2301 | if (ret) |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2302 | goto err_free_ma_sync_key; |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2303 | sq_key_mm->key = uresp.sq_key; |
| 2304 | sq_key_mm->addr = qhp->wq.sq.phys_addr; |
| 2305 | sq_key_mm->len = PAGE_ALIGN(qhp->wq.sq.memsize); |
| 2306 | insert_mmap(ucontext, sq_key_mm); |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2307 | if (!attrs->srq) { |
| 2308 | rq_key_mm->key = uresp.rq_key; |
| 2309 | rq_key_mm->addr = virt_to_phys(qhp->wq.rq.queue); |
| 2310 | rq_key_mm->len = PAGE_ALIGN(qhp->wq.rq.memsize); |
| 2311 | insert_mmap(ucontext, rq_key_mm); |
| 2312 | } |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2313 | sq_db_key_mm->key = uresp.sq_db_gts_key; |
| 2314 | sq_db_key_mm->addr = (u64)(unsigned long)qhp->wq.sq.bar2_pa; |
| 2315 | sq_db_key_mm->len = PAGE_SIZE; |
| 2316 | insert_mmap(ucontext, sq_db_key_mm); |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2317 | if (!attrs->srq) { |
| 2318 | rq_db_key_mm->key = uresp.rq_db_gts_key; |
| 2319 | rq_db_key_mm->addr = |
| 2320 | (u64)(unsigned long)qhp->wq.rq.bar2_pa; |
| 2321 | rq_db_key_mm->len = PAGE_SIZE; |
| 2322 | insert_mmap(ucontext, rq_db_key_mm); |
| 2323 | } |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2324 | if (ma_sync_key_mm) { |
| 2325 | ma_sync_key_mm->key = uresp.ma_sync_key; |
| 2326 | ma_sync_key_mm->addr = |
| 2327 | (pci_resource_start(rhp->rdev.lldi.pdev, 0) + |
| 2328 | PCIE_MA_SYNC_A) & PAGE_MASK; |
| 2329 | ma_sync_key_mm->len = PAGE_SIZE; |
| 2330 | insert_mmap(ucontext, ma_sync_key_mm); |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 2331 | } |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 2332 | |
| 2333 | c4iw_get_ucontext(ucontext); |
| 2334 | qhp->ucontext = ucontext; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2335 | } |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2336 | if (!attrs->srq) { |
| 2337 | qhp->wq.qp_errp = |
| 2338 | &qhp->wq.rq.queue[qhp->wq.rq.size].status.qp_err; |
| 2339 | } else { |
| 2340 | qhp->wq.qp_errp = |
| 2341 | &qhp->wq.sq.queue[qhp->wq.sq.size].status.qp_err; |
| 2342 | qhp->wq.srqidxp = |
| 2343 | &qhp->wq.sq.queue[qhp->wq.sq.size].status.srqidx; |
| 2344 | } |
| 2345 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2346 | qhp->ibqp.qp_num = qhp->wq.sq.qid; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2347 | if (attrs->srq) |
| 2348 | qhp->srq = to_c4iw_srq(attrs->srq); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 2349 | INIT_LIST_HEAD(&qhp->db_fc_entry); |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 2350 | pr_debug("sq id %u size %u memsize %zu num_entries %u rq id %u size %u memsize %zu num_entries %u\n", |
Joe Perches | a9a4288 | 2017-02-09 14:23:51 -0800 | [diff] [blame] | 2351 | qhp->wq.sq.qid, qhp->wq.sq.size, qhp->wq.sq.memsize, |
| 2352 | attrs->cap.max_send_wr, qhp->wq.rq.qid, qhp->wq.rq.size, |
| 2353 | qhp->wq.rq.memsize, attrs->cap.max_recv_wr); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2354 | return &qhp->ibqp; |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2355 | err_free_ma_sync_key: |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2356 | kfree(ma_sync_key_mm); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2357 | err_free_rq_db_key: |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2358 | if (!attrs->srq) |
| 2359 | kfree(rq_db_key_mm); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2360 | err_free_sq_db_key: |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2361 | kfree(sq_db_key_mm); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2362 | err_free_rq_key: |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2363 | if (!attrs->srq) |
| 2364 | kfree(rq_key_mm); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2365 | err_free_sq_key: |
Hariprasad S | a6054df | 2016-02-05 11:43:28 +0530 | [diff] [blame] | 2366 | kfree(sq_key_mm); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2367 | err_remove_handle: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2368 | remove_handle(rhp, &rhp->qpidr, qhp->wq.sq.qid); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2369 | err_destroy_qp: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2370 | destroy_qp(&rhp->rdev, &qhp->wq, |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2371 | ucontext ? &ucontext->uctx : &rhp->rdev.uctx, !attrs->srq); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2372 | err_free_wr_wait: |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 2373 | c4iw_put_wr_wait(qhp->wr_waitp); |
Steve Wise | 7088a9b | 2017-09-26 13:11:36 -0700 | [diff] [blame] | 2374 | err_free_qhp: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2375 | kfree(qhp); |
| 2376 | return ERR_PTR(ret); |
| 2377 | } |
| 2378 | |
| 2379 | int c4iw_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 2380 | int attr_mask, struct ib_udata *udata) |
| 2381 | { |
| 2382 | struct c4iw_dev *rhp; |
| 2383 | struct c4iw_qp *qhp; |
| 2384 | enum c4iw_qp_attr_mask mask = 0; |
| 2385 | struct c4iw_qp_attributes attrs; |
| 2386 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 2387 | pr_debug("ib_qp %p\n", ibqp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2388 | |
| 2389 | /* iwarp does not support the RTR state */ |
| 2390 | if ((attr_mask & IB_QP_STATE) && (attr->qp_state == IB_QPS_RTR)) |
| 2391 | attr_mask &= ~IB_QP_STATE; |
| 2392 | |
| 2393 | /* Make sure we still have something left to do */ |
| 2394 | if (!attr_mask) |
| 2395 | return 0; |
| 2396 | |
| 2397 | memset(&attrs, 0, sizeof attrs); |
| 2398 | qhp = to_c4iw_qp(ibqp); |
| 2399 | rhp = qhp->rhp; |
| 2400 | |
| 2401 | attrs.next_state = c4iw_convert_state(attr->qp_state); |
| 2402 | attrs.enable_rdma_read = (attr->qp_access_flags & |
| 2403 | IB_ACCESS_REMOTE_READ) ? 1 : 0; |
| 2404 | attrs.enable_rdma_write = (attr->qp_access_flags & |
| 2405 | IB_ACCESS_REMOTE_WRITE) ? 1 : 0; |
| 2406 | attrs.enable_bind = (attr->qp_access_flags & IB_ACCESS_MW_BIND) ? 1 : 0; |
| 2407 | |
| 2408 | |
| 2409 | mask |= (attr_mask & IB_QP_STATE) ? C4IW_QP_ATTR_NEXT_STATE : 0; |
| 2410 | mask |= (attr_mask & IB_QP_ACCESS_FLAGS) ? |
| 2411 | (C4IW_QP_ATTR_ENABLE_RDMA_READ | |
| 2412 | C4IW_QP_ATTR_ENABLE_RDMA_WRITE | |
| 2413 | C4IW_QP_ATTR_ENABLE_RDMA_BIND) : 0; |
| 2414 | |
Vipul Pandya | 2c97478 | 2012-05-18 15:29:28 +0530 | [diff] [blame] | 2415 | /* |
| 2416 | * Use SQ_PSN and RQ_PSN to pass in IDX_INC values for |
| 2417 | * ringing the queue db when we're in DB_FULL mode. |
Steve Wise | c2f9da9 | 2014-04-24 14:32:04 -0500 | [diff] [blame] | 2418 | * Only allow this on T4 devices. |
Vipul Pandya | 2c97478 | 2012-05-18 15:29:28 +0530 | [diff] [blame] | 2419 | */ |
| 2420 | attrs.sq_db_inc = attr->sq_psn; |
| 2421 | attrs.rq_db_inc = attr->rq_psn; |
| 2422 | mask |= (attr_mask & IB_QP_SQ_PSN) ? C4IW_QP_ATTR_SQ_DB : 0; |
| 2423 | mask |= (attr_mask & IB_QP_RQ_PSN) ? C4IW_QP_ATTR_RQ_DB : 0; |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 2424 | if (!is_t4(to_c4iw_qp(ibqp)->rhp->rdev.lldi.adapter_type) && |
Steve Wise | c2f9da9 | 2014-04-24 14:32:04 -0500 | [diff] [blame] | 2425 | (mask & (C4IW_QP_ATTR_SQ_DB|C4IW_QP_ATTR_RQ_DB))) |
| 2426 | return -EINVAL; |
Vipul Pandya | 2c97478 | 2012-05-18 15:29:28 +0530 | [diff] [blame] | 2427 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2428 | return c4iw_modify_qp(rhp, qhp, mask, &attrs, 0); |
| 2429 | } |
| 2430 | |
| 2431 | struct ib_qp *c4iw_get_qp(struct ib_device *dev, int qpn) |
| 2432 | { |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 2433 | pr_debug("ib_dev %p qpn 0x%x\n", dev, qpn); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 2434 | return (struct ib_qp *)get_qhp(to_c4iw_dev(dev), qpn); |
| 2435 | } |
Vipul Pandya | 67bbc05 | 2012-05-18 15:29:33 +0530 | [diff] [blame] | 2436 | |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2437 | void c4iw_dispatch_srq_limit_reached_event(struct c4iw_srq *srq) |
| 2438 | { |
Bart Van Assche | dd708e7 | 2018-07-31 08:51:30 -0700 | [diff] [blame] | 2439 | struct ib_event event = {}; |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2440 | |
| 2441 | event.device = &srq->rhp->ibdev; |
| 2442 | event.element.srq = &srq->ibsrq; |
| 2443 | event.event = IB_EVENT_SRQ_LIMIT_REACHED; |
| 2444 | ib_dispatch_event(&event); |
| 2445 | } |
| 2446 | |
| 2447 | int c4iw_modify_srq(struct ib_srq *ib_srq, struct ib_srq_attr *attr, |
| 2448 | enum ib_srq_attr_mask srq_attr_mask, |
| 2449 | struct ib_udata *udata) |
| 2450 | { |
| 2451 | struct c4iw_srq *srq = to_c4iw_srq(ib_srq); |
| 2452 | int ret = 0; |
| 2453 | |
| 2454 | /* |
| 2455 | * XXX 0 mask == a SW interrupt for srq_limit reached... |
| 2456 | */ |
| 2457 | if (udata && !srq_attr_mask) { |
| 2458 | c4iw_dispatch_srq_limit_reached_event(srq); |
| 2459 | goto out; |
| 2460 | } |
| 2461 | |
| 2462 | /* no support for this yet */ |
| 2463 | if (srq_attr_mask & IB_SRQ_MAX_WR) { |
| 2464 | ret = -EINVAL; |
| 2465 | goto out; |
| 2466 | } |
| 2467 | |
| 2468 | if (!udata && (srq_attr_mask & IB_SRQ_LIMIT)) { |
| 2469 | srq->armed = true; |
| 2470 | srq->srq_limit = attr->srq_limit; |
| 2471 | } |
| 2472 | out: |
| 2473 | return ret; |
| 2474 | } |
| 2475 | |
Vipul Pandya | 67bbc05 | 2012-05-18 15:29:33 +0530 | [diff] [blame] | 2476 | int c4iw_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 2477 | int attr_mask, struct ib_qp_init_attr *init_attr) |
| 2478 | { |
| 2479 | struct c4iw_qp *qhp = to_c4iw_qp(ibqp); |
| 2480 | |
| 2481 | memset(attr, 0, sizeof *attr); |
| 2482 | memset(init_attr, 0, sizeof *init_attr); |
| 2483 | attr->qp_state = to_ib_qp_state(qhp->attr.state); |
Hariprasad Shenai | 3e5c02c | 2014-07-21 20:55:14 +0530 | [diff] [blame] | 2484 | init_attr->cap.max_send_wr = qhp->attr.sq_num_entries; |
| 2485 | init_attr->cap.max_recv_wr = qhp->attr.rq_num_entries; |
| 2486 | init_attr->cap.max_send_sge = qhp->attr.sq_max_sges; |
| 2487 | init_attr->cap.max_recv_sge = qhp->attr.sq_max_sges; |
| 2488 | init_attr->cap.max_inline_data = T4_MAX_SEND_INLINE; |
| 2489 | init_attr->sq_sig_type = qhp->sq_sig_all ? IB_SIGNAL_ALL_WR : 0; |
Vipul Pandya | 67bbc05 | 2012-05-18 15:29:33 +0530 | [diff] [blame] | 2490 | return 0; |
| 2491 | } |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2492 | |
| 2493 | static void free_srq_queue(struct c4iw_srq *srq, struct c4iw_dev_ucontext *uctx, |
| 2494 | struct c4iw_wr_wait *wr_waitp) |
| 2495 | { |
| 2496 | struct c4iw_rdev *rdev = &srq->rhp->rdev; |
| 2497 | struct sk_buff *skb = srq->destroy_skb; |
| 2498 | struct t4_srq *wq = &srq->wq; |
| 2499 | struct fw_ri_res_wr *res_wr; |
| 2500 | struct fw_ri_res *res; |
| 2501 | int wr_len; |
| 2502 | |
| 2503 | wr_len = sizeof(*res_wr) + sizeof(*res); |
| 2504 | set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0); |
| 2505 | |
| 2506 | res_wr = (struct fw_ri_res_wr *)__skb_put(skb, wr_len); |
| 2507 | memset(res_wr, 0, wr_len); |
| 2508 | res_wr->op_nres = cpu_to_be32(FW_WR_OP_V(FW_RI_RES_WR) | |
| 2509 | FW_RI_RES_WR_NRES_V(1) | |
| 2510 | FW_WR_COMPL_F); |
| 2511 | res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16)); |
| 2512 | res_wr->cookie = (uintptr_t)wr_waitp; |
| 2513 | res = res_wr->res; |
| 2514 | res->u.srq.restype = FW_RI_RES_TYPE_SRQ; |
| 2515 | res->u.srq.op = FW_RI_RES_OP_RESET; |
| 2516 | res->u.srq.srqid = cpu_to_be32(srq->idx); |
| 2517 | res->u.srq.eqid = cpu_to_be32(wq->qid); |
| 2518 | |
| 2519 | c4iw_init_wr_wait(wr_waitp); |
| 2520 | c4iw_ref_send_wait(rdev, skb, wr_waitp, 0, 0, __func__); |
| 2521 | |
| 2522 | dma_free_coherent(&rdev->lldi.pdev->dev, |
| 2523 | wq->memsize, wq->queue, |
| 2524 | pci_unmap_addr(wq, mapping)); |
| 2525 | c4iw_rqtpool_free(rdev, wq->rqt_hwaddr, wq->rqt_size); |
| 2526 | kfree(wq->sw_rq); |
| 2527 | c4iw_put_qpid(rdev, wq->qid, uctx); |
| 2528 | } |
| 2529 | |
| 2530 | static int alloc_srq_queue(struct c4iw_srq *srq, struct c4iw_dev_ucontext *uctx, |
| 2531 | struct c4iw_wr_wait *wr_waitp) |
| 2532 | { |
| 2533 | struct c4iw_rdev *rdev = &srq->rhp->rdev; |
| 2534 | int user = (uctx != &rdev->uctx); |
| 2535 | struct t4_srq *wq = &srq->wq; |
| 2536 | struct fw_ri_res_wr *res_wr; |
| 2537 | struct fw_ri_res *res; |
| 2538 | struct sk_buff *skb; |
| 2539 | int wr_len; |
| 2540 | int eqsize; |
| 2541 | int ret = -ENOMEM; |
| 2542 | |
| 2543 | wq->qid = c4iw_get_qpid(rdev, uctx); |
| 2544 | if (!wq->qid) |
| 2545 | goto err; |
| 2546 | |
| 2547 | if (!user) { |
| 2548 | wq->sw_rq = kcalloc(wq->size, sizeof(*wq->sw_rq), |
| 2549 | GFP_KERNEL); |
| 2550 | if (!wq->sw_rq) |
| 2551 | goto err_put_qpid; |
| 2552 | wq->pending_wrs = kcalloc(srq->wq.size, |
| 2553 | sizeof(*srq->wq.pending_wrs), |
| 2554 | GFP_KERNEL); |
| 2555 | if (!wq->pending_wrs) |
| 2556 | goto err_free_sw_rq; |
| 2557 | } |
| 2558 | |
| 2559 | wq->rqt_size = wq->size; |
| 2560 | wq->rqt_hwaddr = c4iw_rqtpool_alloc(rdev, wq->rqt_size); |
| 2561 | if (!wq->rqt_hwaddr) |
| 2562 | goto err_free_pending_wrs; |
| 2563 | wq->rqt_abs_idx = (wq->rqt_hwaddr - rdev->lldi.vr->rq.start) >> |
| 2564 | T4_RQT_ENTRY_SHIFT; |
| 2565 | |
| 2566 | wq->queue = dma_alloc_coherent(&rdev->lldi.pdev->dev, |
| 2567 | wq->memsize, &wq->dma_addr, |
| 2568 | GFP_KERNEL); |
| 2569 | if (!wq->queue) |
| 2570 | goto err_free_rqtpool; |
| 2571 | |
| 2572 | memset(wq->queue, 0, wq->memsize); |
| 2573 | pci_unmap_addr_set(wq, mapping, wq->dma_addr); |
| 2574 | |
| 2575 | wq->bar2_va = c4iw_bar2_addrs(rdev, wq->qid, T4_BAR2_QTYPE_EGRESS, |
| 2576 | &wq->bar2_qid, |
| 2577 | user ? &wq->bar2_pa : NULL); |
| 2578 | |
| 2579 | /* |
| 2580 | * User mode must have bar2 access. |
| 2581 | */ |
| 2582 | |
| 2583 | if (user && !wq->bar2_va) { |
| 2584 | pr_warn(MOD "%s: srqid %u not in BAR2 range.\n", |
| 2585 | pci_name(rdev->lldi.pdev), wq->qid); |
| 2586 | ret = -EINVAL; |
| 2587 | goto err_free_queue; |
| 2588 | } |
| 2589 | |
| 2590 | /* build fw_ri_res_wr */ |
| 2591 | wr_len = sizeof(*res_wr) + sizeof(*res); |
| 2592 | |
| 2593 | skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL); |
| 2594 | if (!skb) |
| 2595 | goto err_free_queue; |
| 2596 | set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0); |
| 2597 | |
| 2598 | res_wr = (struct fw_ri_res_wr *)__skb_put(skb, wr_len); |
| 2599 | memset(res_wr, 0, wr_len); |
| 2600 | res_wr->op_nres = cpu_to_be32(FW_WR_OP_V(FW_RI_RES_WR) | |
| 2601 | FW_RI_RES_WR_NRES_V(1) | |
| 2602 | FW_WR_COMPL_F); |
| 2603 | res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16)); |
| 2604 | res_wr->cookie = (uintptr_t)wr_waitp; |
| 2605 | res = res_wr->res; |
| 2606 | res->u.srq.restype = FW_RI_RES_TYPE_SRQ; |
| 2607 | res->u.srq.op = FW_RI_RES_OP_WRITE; |
| 2608 | |
| 2609 | /* |
| 2610 | * eqsize is the number of 64B entries plus the status page size. |
| 2611 | */ |
| 2612 | eqsize = wq->size * T4_RQ_NUM_SLOTS + |
| 2613 | rdev->hw_queue.t4_eq_status_entries; |
| 2614 | res->u.srq.eqid = cpu_to_be32(wq->qid); |
| 2615 | res->u.srq.fetchszm_to_iqid = |
| 2616 | /* no host cidx updates */ |
| 2617 | cpu_to_be32(FW_RI_RES_WR_HOSTFCMODE_V(0) | |
| 2618 | FW_RI_RES_WR_CPRIO_V(0) | /* don't keep in chip cache */ |
| 2619 | FW_RI_RES_WR_PCIECHN_V(0) | /* set by uP at ri_init time */ |
| 2620 | FW_RI_RES_WR_FETCHRO_V(0)); /* relaxed_ordering */ |
| 2621 | res->u.srq.dcaen_to_eqsize = |
| 2622 | cpu_to_be32(FW_RI_RES_WR_DCAEN_V(0) | |
| 2623 | FW_RI_RES_WR_DCACPU_V(0) | |
| 2624 | FW_RI_RES_WR_FBMIN_V(2) | |
| 2625 | FW_RI_RES_WR_FBMAX_V(3) | |
| 2626 | FW_RI_RES_WR_CIDXFTHRESHO_V(0) | |
| 2627 | FW_RI_RES_WR_CIDXFTHRESH_V(0) | |
| 2628 | FW_RI_RES_WR_EQSIZE_V(eqsize)); |
| 2629 | res->u.srq.eqaddr = cpu_to_be64(wq->dma_addr); |
| 2630 | res->u.srq.srqid = cpu_to_be32(srq->idx); |
| 2631 | res->u.srq.pdid = cpu_to_be32(srq->pdid); |
| 2632 | res->u.srq.hwsrqsize = cpu_to_be32(wq->rqt_size); |
| 2633 | res->u.srq.hwsrqaddr = cpu_to_be32(wq->rqt_hwaddr - |
| 2634 | rdev->lldi.vr->rq.start); |
| 2635 | |
| 2636 | c4iw_init_wr_wait(wr_waitp); |
| 2637 | |
| 2638 | ret = c4iw_ref_send_wait(rdev, skb, wr_waitp, 0, wq->qid, __func__); |
| 2639 | if (ret) |
| 2640 | goto err_free_queue; |
| 2641 | |
| 2642 | pr_debug("%s srq %u eqid %u pdid %u queue va %p pa 0x%llx\n" |
| 2643 | " bar2_addr %p rqt addr 0x%x size %d\n", |
| 2644 | __func__, srq->idx, wq->qid, srq->pdid, wq->queue, |
| 2645 | (u64)virt_to_phys(wq->queue), wq->bar2_va, |
| 2646 | wq->rqt_hwaddr, wq->rqt_size); |
| 2647 | |
| 2648 | return 0; |
| 2649 | err_free_queue: |
| 2650 | dma_free_coherent(&rdev->lldi.pdev->dev, |
| 2651 | wq->memsize, wq->queue, |
| 2652 | pci_unmap_addr(wq, mapping)); |
| 2653 | err_free_rqtpool: |
| 2654 | c4iw_rqtpool_free(rdev, wq->rqt_hwaddr, wq->rqt_size); |
| 2655 | err_free_pending_wrs: |
| 2656 | if (!user) |
| 2657 | kfree(wq->pending_wrs); |
| 2658 | err_free_sw_rq: |
| 2659 | if (!user) |
| 2660 | kfree(wq->sw_rq); |
| 2661 | err_put_qpid: |
| 2662 | c4iw_put_qpid(rdev, wq->qid, uctx); |
| 2663 | err: |
| 2664 | return ret; |
| 2665 | } |
| 2666 | |
| 2667 | void c4iw_copy_wr_to_srq(struct t4_srq *srq, union t4_recv_wr *wqe, u8 len16) |
| 2668 | { |
| 2669 | u64 *src, *dst; |
| 2670 | |
| 2671 | src = (u64 *)wqe; |
| 2672 | dst = (u64 *)((u8 *)srq->queue + srq->wq_pidx * T4_EQ_ENTRY_SIZE); |
| 2673 | while (len16) { |
| 2674 | *dst++ = *src++; |
| 2675 | if (dst >= (u64 *)&srq->queue[srq->size]) |
| 2676 | dst = (u64 *)srq->queue; |
| 2677 | *dst++ = *src++; |
| 2678 | if (dst >= (u64 *)&srq->queue[srq->size]) |
| 2679 | dst = (u64 *)srq->queue; |
| 2680 | len16--; |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | struct ib_srq *c4iw_create_srq(struct ib_pd *pd, struct ib_srq_init_attr *attrs, |
| 2685 | struct ib_udata *udata) |
| 2686 | { |
| 2687 | struct c4iw_dev *rhp; |
| 2688 | struct c4iw_srq *srq; |
| 2689 | struct c4iw_pd *php; |
| 2690 | struct c4iw_create_srq_resp uresp; |
| 2691 | struct c4iw_ucontext *ucontext; |
| 2692 | struct c4iw_mm_entry *srq_key_mm, *srq_db_key_mm; |
| 2693 | int rqsize; |
| 2694 | int ret; |
| 2695 | int wr_len; |
| 2696 | |
| 2697 | pr_debug("%s ib_pd %p\n", __func__, pd); |
| 2698 | |
| 2699 | php = to_c4iw_pd(pd); |
| 2700 | rhp = php->rhp; |
| 2701 | |
| 2702 | if (!rhp->rdev.lldi.vr->srq.size) |
| 2703 | return ERR_PTR(-EINVAL); |
| 2704 | if (attrs->attr.max_wr > rhp->rdev.hw_queue.t4_max_rq_size) |
| 2705 | return ERR_PTR(-E2BIG); |
| 2706 | if (attrs->attr.max_sge > T4_MAX_RECV_SGE) |
| 2707 | return ERR_PTR(-E2BIG); |
| 2708 | |
| 2709 | /* |
| 2710 | * SRQ RQT and RQ must be a power of 2 and at least 16 deep. |
| 2711 | */ |
| 2712 | rqsize = attrs->attr.max_wr + 1; |
| 2713 | rqsize = roundup_pow_of_two(max_t(u16, rqsize, 16)); |
| 2714 | |
| 2715 | ucontext = pd->uobject ? to_c4iw_ucontext(pd->uobject->context) : NULL; |
| 2716 | |
| 2717 | srq = kzalloc(sizeof(*srq), GFP_KERNEL); |
| 2718 | if (!srq) |
| 2719 | return ERR_PTR(-ENOMEM); |
| 2720 | |
| 2721 | srq->wr_waitp = c4iw_alloc_wr_wait(GFP_KERNEL); |
| 2722 | if (!srq->wr_waitp) { |
| 2723 | ret = -ENOMEM; |
| 2724 | goto err_free_srq; |
| 2725 | } |
| 2726 | |
| 2727 | srq->idx = c4iw_alloc_srq_idx(&rhp->rdev); |
| 2728 | if (srq->idx < 0) { |
| 2729 | ret = -ENOMEM; |
| 2730 | goto err_free_wr_wait; |
| 2731 | } |
| 2732 | |
| 2733 | wr_len = sizeof(struct fw_ri_res_wr) + sizeof(struct fw_ri_res); |
| 2734 | srq->destroy_skb = alloc_skb(wr_len, GFP_KERNEL); |
| 2735 | if (!srq->destroy_skb) { |
| 2736 | ret = -ENOMEM; |
| 2737 | goto err_free_srq_idx; |
| 2738 | } |
| 2739 | |
| 2740 | srq->rhp = rhp; |
| 2741 | srq->pdid = php->pdid; |
| 2742 | |
| 2743 | srq->wq.size = rqsize; |
| 2744 | srq->wq.memsize = |
| 2745 | (rqsize + rhp->rdev.hw_queue.t4_eq_status_entries) * |
| 2746 | sizeof(*srq->wq.queue); |
| 2747 | if (ucontext) |
| 2748 | srq->wq.memsize = roundup(srq->wq.memsize, PAGE_SIZE); |
| 2749 | |
| 2750 | ret = alloc_srq_queue(srq, ucontext ? &ucontext->uctx : |
| 2751 | &rhp->rdev.uctx, srq->wr_waitp); |
| 2752 | if (ret) |
| 2753 | goto err_free_skb; |
| 2754 | attrs->attr.max_wr = rqsize - 1; |
| 2755 | |
| 2756 | if (CHELSIO_CHIP_VERSION(rhp->rdev.lldi.adapter_type) > CHELSIO_T6) |
| 2757 | srq->flags = T4_SRQ_LIMIT_SUPPORT; |
| 2758 | |
| 2759 | ret = insert_handle(rhp, &rhp->qpidr, srq, srq->wq.qid); |
| 2760 | if (ret) |
| 2761 | goto err_free_queue; |
| 2762 | |
| 2763 | if (udata) { |
| 2764 | srq_key_mm = kmalloc(sizeof(*srq_key_mm), GFP_KERNEL); |
| 2765 | if (!srq_key_mm) { |
| 2766 | ret = -ENOMEM; |
| 2767 | goto err_remove_handle; |
| 2768 | } |
| 2769 | srq_db_key_mm = kmalloc(sizeof(*srq_db_key_mm), GFP_KERNEL); |
| 2770 | if (!srq_db_key_mm) { |
| 2771 | ret = -ENOMEM; |
| 2772 | goto err_free_srq_key_mm; |
| 2773 | } |
Dan Carpenter | 8001b71 | 2018-08-02 10:56:13 +0300 | [diff] [blame] | 2774 | memset(&uresp, 0, sizeof(uresp)); |
Raju Rangoju | 6a0b617 | 2018-07-25 21:22:14 +0530 | [diff] [blame] | 2775 | uresp.flags = srq->flags; |
| 2776 | uresp.qid_mask = rhp->rdev.qpmask; |
| 2777 | uresp.srqid = srq->wq.qid; |
| 2778 | uresp.srq_size = srq->wq.size; |
| 2779 | uresp.srq_memsize = srq->wq.memsize; |
| 2780 | uresp.rqt_abs_idx = srq->wq.rqt_abs_idx; |
| 2781 | spin_lock(&ucontext->mmap_lock); |
| 2782 | uresp.srq_key = ucontext->key; |
| 2783 | ucontext->key += PAGE_SIZE; |
| 2784 | uresp.srq_db_gts_key = ucontext->key; |
| 2785 | ucontext->key += PAGE_SIZE; |
| 2786 | spin_unlock(&ucontext->mmap_lock); |
| 2787 | ret = ib_copy_to_udata(udata, &uresp, sizeof(uresp)); |
| 2788 | if (ret) |
| 2789 | goto err_free_srq_db_key_mm; |
| 2790 | srq_key_mm->key = uresp.srq_key; |
| 2791 | srq_key_mm->addr = virt_to_phys(srq->wq.queue); |
| 2792 | srq_key_mm->len = PAGE_ALIGN(srq->wq.memsize); |
| 2793 | insert_mmap(ucontext, srq_key_mm); |
| 2794 | srq_db_key_mm->key = uresp.srq_db_gts_key; |
| 2795 | srq_db_key_mm->addr = (u64)(unsigned long)srq->wq.bar2_pa; |
| 2796 | srq_db_key_mm->len = PAGE_SIZE; |
| 2797 | insert_mmap(ucontext, srq_db_key_mm); |
| 2798 | } |
| 2799 | |
| 2800 | pr_debug("%s srq qid %u idx %u size %u memsize %lu num_entries %u\n", |
| 2801 | __func__, srq->wq.qid, srq->idx, srq->wq.size, |
| 2802 | (unsigned long)srq->wq.memsize, attrs->attr.max_wr); |
| 2803 | |
| 2804 | spin_lock_init(&srq->lock); |
| 2805 | return &srq->ibsrq; |
| 2806 | err_free_srq_db_key_mm: |
| 2807 | kfree(srq_db_key_mm); |
| 2808 | err_free_srq_key_mm: |
| 2809 | kfree(srq_key_mm); |
| 2810 | err_remove_handle: |
| 2811 | remove_handle(rhp, &rhp->qpidr, srq->wq.qid); |
| 2812 | err_free_queue: |
| 2813 | free_srq_queue(srq, ucontext ? &ucontext->uctx : &rhp->rdev.uctx, |
| 2814 | srq->wr_waitp); |
| 2815 | err_free_skb: |
| 2816 | if (srq->destroy_skb) |
| 2817 | kfree_skb(srq->destroy_skb); |
| 2818 | err_free_srq_idx: |
| 2819 | c4iw_free_srq_idx(&rhp->rdev, srq->idx); |
| 2820 | err_free_wr_wait: |
| 2821 | c4iw_put_wr_wait(srq->wr_waitp); |
| 2822 | err_free_srq: |
| 2823 | kfree(srq); |
| 2824 | return ERR_PTR(ret); |
| 2825 | } |
| 2826 | |
| 2827 | int c4iw_destroy_srq(struct ib_srq *ibsrq) |
| 2828 | { |
| 2829 | struct c4iw_dev *rhp; |
| 2830 | struct c4iw_srq *srq; |
| 2831 | struct c4iw_ucontext *ucontext; |
| 2832 | |
| 2833 | srq = to_c4iw_srq(ibsrq); |
| 2834 | rhp = srq->rhp; |
| 2835 | |
| 2836 | pr_debug("%s id %d\n", __func__, srq->wq.qid); |
| 2837 | |
| 2838 | remove_handle(rhp, &rhp->qpidr, srq->wq.qid); |
| 2839 | ucontext = ibsrq->uobject ? |
| 2840 | to_c4iw_ucontext(ibsrq->uobject->context) : NULL; |
| 2841 | free_srq_queue(srq, ucontext ? &ucontext->uctx : &rhp->rdev.uctx, |
| 2842 | srq->wr_waitp); |
| 2843 | c4iw_free_srq_idx(&rhp->rdev, srq->idx); |
| 2844 | c4iw_put_wr_wait(srq->wr_waitp); |
| 2845 | kfree(srq); |
| 2846 | return 0; |
| 2847 | } |