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 | */ |
| 32 | |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 33 | #include <linux/module.h> |
| 34 | #include <linux/moduleparam.h> |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 35 | #include <rdma/ib_umem.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 36 | #include <linux/atomic.h> |
Matan Barak | b2a239d | 2016-02-29 18:05:29 +0200 | [diff] [blame] | 37 | #include <rdma/ib_user_verbs.h> |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 38 | |
| 39 | #include "iw_cxgb4.h" |
| 40 | |
Ganesh Goudar | e821303 | 2017-02-23 12:31:43 +0530 | [diff] [blame] | 41 | int use_dsgl = 1; |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 42 | module_param(use_dsgl, int, 0644); |
Ganesh Goudar | e821303 | 2017-02-23 12:31:43 +0530 | [diff] [blame] | 43 | MODULE_PARM_DESC(use_dsgl, "Use DSGL for PBL/FastReg (default=1) (DEPRECATED)"); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 44 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 45 | #define T4_ULPTX_MIN_IO 32 |
| 46 | #define C4IW_MAX_INLINE_SIZE 96 |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 47 | #define T4_ULPTX_MAX_DMA 1024 |
| 48 | #define C4IW_INLINE_THRESHOLD 128 |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 49 | |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 50 | static int inline_threshold = C4IW_INLINE_THRESHOLD; |
| 51 | module_param(inline_threshold, int, 0644); |
| 52 | MODULE_PARM_DESC(inline_threshold, "inline vs dsgl threshold (default=128)"); |
| 53 | |
Hariprasad Shenai | 2550a88 | 2014-11-21 09:36:36 -0600 | [diff] [blame] | 54 | static int mr_exceeds_hw_limits(struct c4iw_dev *dev, u64 length) |
| 55 | { |
| 56 | return (is_t4(dev->rdev.lldi.adapter_type) || |
| 57 | is_t5(dev->rdev.lldi.adapter_type)) && |
| 58 | length >= 8*1024*1024*1024ULL; |
| 59 | } |
| 60 | |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 61 | static int _c4iw_write_mem_dma_aligned(struct c4iw_rdev *rdev, u32 addr, |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 62 | u32 len, dma_addr_t data, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 63 | struct sk_buff *skb, |
| 64 | struct c4iw_wr_wait *wr_waitp) |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 65 | { |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 66 | struct ulp_mem_io *req; |
| 67 | struct ulptx_sgl *sgl; |
| 68 | u8 wr_len; |
| 69 | int ret = 0; |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 70 | |
| 71 | addr &= 0x7FFFFFF; |
| 72 | |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 73 | if (wr_waitp) |
| 74 | c4iw_init_wr_wait(wr_waitp); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 75 | wr_len = roundup(sizeof(*req) + sizeof(*sgl), 16); |
| 76 | |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 77 | if (!skb) { |
| 78 | skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL); |
| 79 | if (!skb) |
| 80 | return -ENOMEM; |
| 81 | } |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 82 | set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0); |
| 83 | |
yuan linyu | de77b96 | 2017-06-18 22:48:17 +0800 | [diff] [blame] | 84 | req = __skb_put_zero(skb, wr_len); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 85 | INIT_ULPTX_WR(req, wr_len, 0, 0); |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 86 | req->wr.wr_hi = cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR) | |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 87 | (wr_waitp ? FW_WR_COMPL_F : 0)); |
| 88 | req->wr.wr_lo = wr_waitp ? (__force __be64)(unsigned long)wr_waitp : 0L; |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 89 | req->wr.wr_mid = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(wr_len, 16))); |
Hariprasad S | 92f850e | 2016-05-06 22:17:56 +0530 | [diff] [blame] | 90 | req->cmd = cpu_to_be32(ULPTX_CMD_V(ULP_TX_MEM_WRITE) | |
| 91 | T5_ULP_MEMIO_ORDER_V(1) | |
| 92 | T5_ULP_MEMIO_FID_V(rdev->lldi.rxq_ids[0])); |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 93 | req->dlen = cpu_to_be32(ULP_MEMIO_DATA_LEN_V(len>>5)); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 94 | req->len16 = cpu_to_be32(DIV_ROUND_UP(wr_len-sizeof(req->wr), 16)); |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 95 | req->lock_addr = cpu_to_be32(ULP_MEMIO_ADDR_V(addr)); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 96 | |
| 97 | sgl = (struct ulptx_sgl *)(req + 1); |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 98 | sgl->cmd_nsge = cpu_to_be32(ULPTX_CMD_V(ULP_TX_SC_DSGL) | |
Hariprasad Shenai | bdc590b | 2015-01-08 21:38:16 -0800 | [diff] [blame] | 99 | ULPTX_NSGE_V(1)); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 100 | sgl->len0 = cpu_to_be32(len); |
Vipul Pandya | 0e5eca7 | 2013-03-14 05:09:02 +0000 | [diff] [blame] | 101 | sgl->addr0 = cpu_to_be64(data); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 102 | |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 103 | if (wr_waitp) |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 104 | ret = c4iw_ref_send_wait(rdev, skb, wr_waitp, 0, 0, __func__); |
| 105 | else |
| 106 | ret = c4iw_ofld_send(rdev, skb); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | static int _c4iw_write_mem_inline(struct c4iw_rdev *rdev, u32 addr, u32 len, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 111 | void *data, struct sk_buff *skb, |
| 112 | struct c4iw_wr_wait *wr_waitp) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 113 | { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 114 | struct ulp_mem_io *req; |
| 115 | struct ulptx_idata *sc; |
| 116 | u8 wr_len, *to_dp, *from_dp; |
| 117 | int copy_len, num_wqe, i, ret = 0; |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 118 | __be32 cmd = cpu_to_be32(ULPTX_CMD_V(ULP_TX_MEM_WRITE)); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 119 | |
| 120 | if (is_t4(rdev->lldi.adapter_type)) |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 121 | cmd |= cpu_to_be32(ULP_MEMIO_ORDER_F); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 122 | else |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 123 | cmd |= cpu_to_be32(T5_ULP_MEMIO_IMM_F); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 124 | |
| 125 | addr &= 0x7FFFFFF; |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 126 | pr_debug("addr 0x%x len %u\n", addr, len); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 127 | num_wqe = DIV_ROUND_UP(len, C4IW_MAX_INLINE_SIZE); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 128 | c4iw_init_wr_wait(wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 129 | for (i = 0; i < num_wqe; i++) { |
| 130 | |
| 131 | copy_len = len > C4IW_MAX_INLINE_SIZE ? C4IW_MAX_INLINE_SIZE : |
| 132 | len; |
| 133 | wr_len = roundup(sizeof *req + sizeof *sc + |
| 134 | roundup(copy_len, T4_ULPTX_MIN_IO), 16); |
| 135 | |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 136 | if (!skb) { |
| 137 | skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL); |
| 138 | if (!skb) |
| 139 | return -ENOMEM; |
| 140 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 141 | set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0); |
| 142 | |
yuan linyu | de77b96 | 2017-06-18 22:48:17 +0800 | [diff] [blame] | 143 | req = __skb_put_zero(skb, wr_len); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 144 | INIT_ULPTX_WR(req, wr_len, 0, 0); |
| 145 | |
| 146 | if (i == (num_wqe-1)) { |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 147 | req->wr.wr_hi = cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR) | |
| 148 | FW_WR_COMPL_F); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 149 | req->wr.wr_lo = (__force __be64)(unsigned long)wr_waitp; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 150 | } else |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 151 | req->wr.wr_hi = cpu_to_be32(FW_WR_OP_V(FW_ULPTX_WR)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 152 | req->wr.wr_mid = cpu_to_be32( |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 153 | FW_WR_LEN16_V(DIV_ROUND_UP(wr_len, 16))); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 154 | |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 155 | req->cmd = cmd; |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 156 | req->dlen = cpu_to_be32(ULP_MEMIO_DATA_LEN_V( |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 157 | DIV_ROUND_UP(copy_len, T4_ULPTX_MIN_IO))); |
| 158 | req->len16 = cpu_to_be32(DIV_ROUND_UP(wr_len-sizeof(req->wr), |
| 159 | 16)); |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 160 | req->lock_addr = cpu_to_be32(ULP_MEMIO_ADDR_V(addr + i * 3)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 161 | |
| 162 | sc = (struct ulptx_idata *)(req + 1); |
Anish Bhatt | d7990b0 | 2014-11-12 17:15:57 -0800 | [diff] [blame] | 163 | sc->cmd_more = cpu_to_be32(ULPTX_CMD_V(ULP_TX_SC_IMM)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 164 | sc->len = cpu_to_be32(roundup(copy_len, T4_ULPTX_MIN_IO)); |
| 165 | |
| 166 | to_dp = (u8 *)(sc + 1); |
| 167 | from_dp = (u8 *)data + i * C4IW_MAX_INLINE_SIZE; |
| 168 | if (data) |
| 169 | memcpy(to_dp, from_dp, copy_len); |
| 170 | else |
| 171 | memset(to_dp, 0, copy_len); |
| 172 | if (copy_len % T4_ULPTX_MIN_IO) |
| 173 | memset(to_dp + copy_len, 0, T4_ULPTX_MIN_IO - |
| 174 | (copy_len % T4_ULPTX_MIN_IO)); |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 175 | if (i == (num_wqe-1)) |
| 176 | ret = c4iw_ref_send_wait(rdev, skb, wr_waitp, 0, 0, |
| 177 | __func__); |
| 178 | else |
| 179 | ret = c4iw_ofld_send(rdev, skb); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 180 | if (ret) |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 181 | break; |
| 182 | skb = NULL; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 183 | len -= C4IW_MAX_INLINE_SIZE; |
| 184 | } |
| 185 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 186 | return ret; |
| 187 | } |
| 188 | |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 189 | static int _c4iw_write_mem_dma(struct c4iw_rdev *rdev, u32 addr, u32 len, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 190 | void *data, struct sk_buff *skb, |
| 191 | struct c4iw_wr_wait *wr_waitp) |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 192 | { |
| 193 | u32 remain = len; |
| 194 | u32 dmalen; |
| 195 | int ret = 0; |
Vipul Pandya | 0e5eca7 | 2013-03-14 05:09:02 +0000 | [diff] [blame] | 196 | dma_addr_t daddr; |
| 197 | dma_addr_t save; |
| 198 | |
| 199 | daddr = dma_map_single(&rdev->lldi.pdev->dev, data, len, DMA_TO_DEVICE); |
| 200 | if (dma_mapping_error(&rdev->lldi.pdev->dev, daddr)) |
| 201 | return -1; |
| 202 | save = daddr; |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 203 | |
| 204 | while (remain > inline_threshold) { |
| 205 | if (remain < T4_ULPTX_MAX_DMA) { |
| 206 | if (remain & ~T4_ULPTX_MIN_IO) |
| 207 | dmalen = remain & ~(T4_ULPTX_MIN_IO-1); |
| 208 | else |
| 209 | dmalen = remain; |
| 210 | } else |
| 211 | dmalen = T4_ULPTX_MAX_DMA; |
| 212 | remain -= dmalen; |
Vipul Pandya | 0e5eca7 | 2013-03-14 05:09:02 +0000 | [diff] [blame] | 213 | ret = _c4iw_write_mem_dma_aligned(rdev, addr, dmalen, daddr, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 214 | skb, remain ? NULL : wr_waitp); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 215 | if (ret) |
| 216 | goto out; |
| 217 | addr += dmalen >> 5; |
| 218 | data += dmalen; |
Vipul Pandya | 0e5eca7 | 2013-03-14 05:09:02 +0000 | [diff] [blame] | 219 | daddr += dmalen; |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 220 | } |
| 221 | if (remain) |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 222 | ret = _c4iw_write_mem_inline(rdev, addr, remain, data, skb, |
| 223 | wr_waitp); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 224 | out: |
Vipul Pandya | 0e5eca7 | 2013-03-14 05:09:02 +0000 | [diff] [blame] | 225 | dma_unmap_single(&rdev->lldi.pdev->dev, save, len, DMA_TO_DEVICE); |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 226 | return ret; |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | * write len bytes of data into addr (32B aligned address) |
| 231 | * If data is NULL, clear len byte of memory to zero. |
| 232 | */ |
| 233 | static int write_adapter_mem(struct c4iw_rdev *rdev, u32 addr, u32 len, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 234 | void *data, struct sk_buff *skb, |
| 235 | struct c4iw_wr_wait *wr_waitp) |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 236 | { |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 237 | int ret; |
| 238 | |
| 239 | if (!rdev->lldi.ulptx_memwrite_dsgl || !use_dsgl) { |
| 240 | ret = _c4iw_write_mem_inline(rdev, addr, len, data, skb, |
| 241 | wr_waitp); |
| 242 | goto out; |
| 243 | } |
| 244 | |
| 245 | if (len <= inline_threshold) { |
| 246 | ret = _c4iw_write_mem_inline(rdev, addr, len, data, skb, |
| 247 | wr_waitp); |
| 248 | goto out; |
| 249 | } |
| 250 | |
| 251 | ret = _c4iw_write_mem_dma(rdev, addr, len, data, skb, wr_waitp); |
| 252 | if (ret) { |
| 253 | pr_warn_ratelimited("%s: dma map failure (non fatal)\n", |
| 254 | pci_name(rdev->lldi.pdev)); |
| 255 | ret = _c4iw_write_mem_inline(rdev, addr, len, data, skb, |
| 256 | wr_waitp); |
| 257 | } |
| 258 | out: |
| 259 | return ret; |
| 260 | |
Vipul Pandya | 42b6a94 | 2013-03-14 05:09:01 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 263 | /* |
| 264 | * Build and write a TPT entry. |
| 265 | * IN: stag key, pdid, perm, bind_enabled, zbva, to, len, page_size, |
| 266 | * pbl_size and pbl_addr |
| 267 | * OUT: stag index |
| 268 | */ |
| 269 | static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry, |
| 270 | u32 *stag, u8 stag_state, u32 pdid, |
| 271 | enum fw_ri_stag_type type, enum fw_ri_mem_perms perm, |
| 272 | int bind_enabled, u32 zbva, u64 to, |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 273 | u64 len, u8 page_size, u32 pbl_size, u32 pbl_addr, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 274 | struct sk_buff *skb, struct c4iw_wr_wait *wr_waitp) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 275 | { |
| 276 | int err; |
| 277 | struct fw_ri_tpte tpt; |
| 278 | u32 stag_idx; |
| 279 | static atomic_t key; |
| 280 | |
| 281 | if (c4iw_fatal_error(rdev)) |
| 282 | return -EIO; |
| 283 | |
| 284 | stag_state = stag_state > 0; |
| 285 | stag_idx = (*stag) >> 8; |
| 286 | |
| 287 | if ((!reset_tpt_entry) && (*stag == T4_STAG_UNSET)) { |
Vipul Pandya | ec3eead | 2012-05-18 15:29:32 +0530 | [diff] [blame] | 288 | stag_idx = c4iw_get_resource(&rdev->resource.tpt_table); |
Steve Wise | 98a3e87 | 2014-04-09 09:38:28 -0500 | [diff] [blame] | 289 | if (!stag_idx) { |
| 290 | mutex_lock(&rdev->stats.lock); |
| 291 | rdev->stats.stag.fail++; |
| 292 | mutex_unlock(&rdev->stats.lock); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 293 | return -ENOMEM; |
Steve Wise | 98a3e87 | 2014-04-09 09:38:28 -0500 | [diff] [blame] | 294 | } |
Vipul Pandya | 8d81ef3 | 2012-05-18 15:29:27 +0530 | [diff] [blame] | 295 | mutex_lock(&rdev->stats.lock); |
| 296 | rdev->stats.stag.cur += 32; |
| 297 | if (rdev->stats.stag.cur > rdev->stats.stag.max) |
| 298 | rdev->stats.stag.max = rdev->stats.stag.cur; |
| 299 | mutex_unlock(&rdev->stats.lock); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 300 | *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff); |
| 301 | } |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 302 | pr_debug("stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n", |
| 303 | stag_state, type, pdid, stag_idx); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 304 | |
| 305 | /* write TPT entry */ |
| 306 | if (reset_tpt_entry) |
| 307 | memset(&tpt, 0, sizeof(tpt)); |
| 308 | else { |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 309 | tpt.valid_to_pdid = cpu_to_be32(FW_RI_TPTE_VALID_F | |
| 310 | FW_RI_TPTE_STAGKEY_V((*stag & FW_RI_TPTE_STAGKEY_M)) | |
| 311 | FW_RI_TPTE_STAGSTATE_V(stag_state) | |
| 312 | FW_RI_TPTE_STAGTYPE_V(type) | FW_RI_TPTE_PDID_V(pdid)); |
| 313 | tpt.locread_to_qpid = cpu_to_be32(FW_RI_TPTE_PERM_V(perm) | |
| 314 | (bind_enabled ? FW_RI_TPTE_MWBINDEN_F : 0) | |
| 315 | FW_RI_TPTE_ADDRTYPE_V((zbva ? FW_RI_ZERO_BASED_TO : |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 316 | FW_RI_VA_BASED_TO))| |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 317 | FW_RI_TPTE_PS_V(page_size)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 318 | tpt.nosnoop_pbladdr = !pbl_size ? 0 : cpu_to_be32( |
Hariprasad Shenai | cf7fe64 | 2015-01-16 09:24:48 +0530 | [diff] [blame] | 319 | FW_RI_TPTE_PBLADDR_V(PBL_OFF(rdev, pbl_addr)>>3)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 320 | tpt.len_lo = cpu_to_be32((u32)(len & 0xffffffffUL)); |
| 321 | tpt.va_hi = cpu_to_be32((u32)(to >> 32)); |
| 322 | tpt.va_lo_fbo = cpu_to_be32((u32)(to & 0xffffffffUL)); |
| 323 | tpt.dca_mwbcnt_pstag = cpu_to_be32(0); |
| 324 | tpt.len_hi = cpu_to_be32((u32)(len >> 32)); |
| 325 | } |
| 326 | err = write_adapter_mem(rdev, stag_idx + |
| 327 | (rdev->lldi.vr->stag.start >> 5), |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 328 | sizeof(tpt), &tpt, skb, wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 329 | |
Vipul Pandya | 8d81ef3 | 2012-05-18 15:29:27 +0530 | [diff] [blame] | 330 | if (reset_tpt_entry) { |
Vipul Pandya | ec3eead | 2012-05-18 15:29:32 +0530 | [diff] [blame] | 331 | c4iw_put_resource(&rdev->resource.tpt_table, stag_idx); |
Vipul Pandya | 8d81ef3 | 2012-05-18 15:29:27 +0530 | [diff] [blame] | 332 | mutex_lock(&rdev->stats.lock); |
| 333 | rdev->stats.stag.cur -= 32; |
| 334 | mutex_unlock(&rdev->stats.lock); |
| 335 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 336 | return err; |
| 337 | } |
| 338 | |
| 339 | static int write_pbl(struct c4iw_rdev *rdev, __be64 *pbl, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 340 | u32 pbl_addr, u32 pbl_size, struct c4iw_wr_wait *wr_waitp) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 341 | { |
| 342 | int err; |
| 343 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 344 | pr_debug("*pdb_addr 0x%x, pbl_base 0x%x, pbl_size %d\n", |
| 345 | pbl_addr, rdev->lldi.vr->pbl.start, |
Joe Perches | a9a4288 | 2017-02-09 14:23:51 -0800 | [diff] [blame] | 346 | pbl_size); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 347 | |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 348 | err = write_adapter_mem(rdev, pbl_addr >> 5, pbl_size << 3, pbl, NULL, |
| 349 | wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 350 | return err; |
| 351 | } |
| 352 | |
| 353 | static int dereg_mem(struct c4iw_rdev *rdev, u32 stag, u32 pbl_size, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 354 | u32 pbl_addr, struct sk_buff *skb, |
| 355 | struct c4iw_wr_wait *wr_waitp) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 356 | { |
| 357 | return write_tpt_entry(rdev, 1, &stag, 0, 0, 0, 0, 0, 0, 0UL, 0, 0, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 358 | pbl_size, pbl_addr, skb, wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 361 | static int allocate_window(struct c4iw_rdev *rdev, u32 *stag, u32 pdid, |
| 362 | struct c4iw_wr_wait *wr_waitp) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 363 | { |
| 364 | *stag = T4_STAG_UNSET; |
| 365 | return write_tpt_entry(rdev, 0, stag, 0, pdid, FW_RI_STAG_MW, 0, 0, 0, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 366 | 0UL, 0, 0, 0, 0, NULL, wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 369 | static int deallocate_window(struct c4iw_rdev *rdev, u32 stag, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 370 | struct sk_buff *skb, |
| 371 | struct c4iw_wr_wait *wr_waitp) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 372 | { |
| 373 | return write_tpt_entry(rdev, 1, &stag, 0, 0, 0, 0, 0, 0, 0UL, 0, 0, 0, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 374 | 0, skb, wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static int allocate_stag(struct c4iw_rdev *rdev, u32 *stag, u32 pdid, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 378 | u32 pbl_size, u32 pbl_addr, |
| 379 | struct c4iw_wr_wait *wr_waitp) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 380 | { |
| 381 | *stag = T4_STAG_UNSET; |
| 382 | return write_tpt_entry(rdev, 0, stag, 0, pdid, FW_RI_STAG_NSMR, 0, 0, 0, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 383 | 0UL, 0, 0, pbl_size, pbl_addr, NULL, wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static int finish_mem_reg(struct c4iw_mr *mhp, u32 stag) |
| 387 | { |
| 388 | u32 mmid; |
| 389 | |
| 390 | mhp->attr.state = 1; |
| 391 | mhp->attr.stag = stag; |
| 392 | mmid = stag >> 8; |
| 393 | mhp->ibmr.rkey = mhp->ibmr.lkey = stag; |
Steve Wise | 750fb16 | 2018-03-01 13:57:58 -0800 | [diff] [blame] | 394 | mhp->ibmr.length = mhp->attr.len; |
| 395 | mhp->ibmr.iova = mhp->attr.va_fbo; |
| 396 | mhp->ibmr.page_size = 1U << (mhp->attr.page_size + 12); |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 397 | pr_debug("mmid 0x%x mhp %p\n", mmid, mhp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 398 | return insert_handle(mhp->rhp, &mhp->rhp->mmidr, mhp, mmid); |
| 399 | } |
| 400 | |
| 401 | static int register_mem(struct c4iw_dev *rhp, struct c4iw_pd *php, |
| 402 | struct c4iw_mr *mhp, int shift) |
| 403 | { |
| 404 | u32 stag = T4_STAG_UNSET; |
| 405 | int ret; |
| 406 | |
| 407 | ret = write_tpt_entry(&rhp->rdev, 0, &stag, 1, mhp->attr.pdid, |
Pramod Kumar | 123bc2a | 2014-11-21 09:36:35 -0600 | [diff] [blame] | 408 | FW_RI_STAG_NSMR, mhp->attr.len ? |
| 409 | mhp->attr.perms : 0, |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 410 | mhp->attr.mw_bind_enable, mhp->attr.zbva, |
Pramod Kumar | 123bc2a | 2014-11-21 09:36:35 -0600 | [diff] [blame] | 411 | mhp->attr.va_fbo, mhp->attr.len ? |
| 412 | mhp->attr.len : -1, shift - 12, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 413 | mhp->attr.pbl_size, mhp->attr.pbl_addr, NULL, |
| 414 | mhp->wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 415 | if (ret) |
| 416 | return ret; |
| 417 | |
| 418 | ret = finish_mem_reg(mhp, stag); |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 419 | if (ret) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 420 | dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 421 | mhp->attr.pbl_addr, mhp->dereg_skb, mhp->wr_waitp); |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 422 | mhp->dereg_skb = NULL; |
| 423 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 424 | return ret; |
| 425 | } |
| 426 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 427 | static int alloc_pbl(struct c4iw_mr *mhp, int npages) |
| 428 | { |
| 429 | mhp->attr.pbl_addr = c4iw_pblpool_alloc(&mhp->rhp->rdev, |
| 430 | npages << 3); |
| 431 | |
| 432 | if (!mhp->attr.pbl_addr) |
| 433 | return -ENOMEM; |
| 434 | |
| 435 | mhp->attr.pbl_size = npages; |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 440 | struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc) |
| 441 | { |
| 442 | struct c4iw_dev *rhp; |
| 443 | struct c4iw_pd *php; |
| 444 | struct c4iw_mr *mhp; |
| 445 | int ret; |
| 446 | u32 stag = T4_STAG_UNSET; |
| 447 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 448 | pr_debug("ib_pd %p\n", pd); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 449 | php = to_c4iw_pd(pd); |
| 450 | rhp = php->rhp; |
| 451 | |
| 452 | mhp = kzalloc(sizeof(*mhp), GFP_KERNEL); |
| 453 | if (!mhp) |
| 454 | return ERR_PTR(-ENOMEM); |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 455 | mhp->wr_waitp = c4iw_alloc_wr_wait(GFP_KERNEL); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 456 | if (!mhp->wr_waitp) { |
| 457 | ret = -ENOMEM; |
| 458 | goto err_free_mhp; |
| 459 | } |
| 460 | c4iw_init_wr_wait(mhp->wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 461 | |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 462 | mhp->dereg_skb = alloc_skb(SGE_MAX_WR_LEN, GFP_KERNEL); |
| 463 | if (!mhp->dereg_skb) { |
| 464 | ret = -ENOMEM; |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 465 | goto err_free_wr_wait; |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 466 | } |
| 467 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 468 | mhp->rhp = rhp; |
| 469 | mhp->attr.pdid = php->pdid; |
| 470 | mhp->attr.perms = c4iw_ib_to_tpt_access(acc); |
| 471 | mhp->attr.mw_bind_enable = (acc&IB_ACCESS_MW_BIND) == IB_ACCESS_MW_BIND; |
| 472 | mhp->attr.zbva = 0; |
| 473 | mhp->attr.va_fbo = 0; |
| 474 | mhp->attr.page_size = 0; |
Hariprasad S | 6198dd8 | 2015-04-22 01:44:59 +0530 | [diff] [blame] | 475 | mhp->attr.len = ~0ULL; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 476 | mhp->attr.pbl_size = 0; |
| 477 | |
| 478 | ret = write_tpt_entry(&rhp->rdev, 0, &stag, 1, php->pdid, |
| 479 | FW_RI_STAG_NSMR, mhp->attr.perms, |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 480 | mhp->attr.mw_bind_enable, 0, 0, ~0ULL, 0, 0, 0, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 481 | NULL, mhp->wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 482 | if (ret) |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 483 | goto err_free_skb; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 484 | |
| 485 | ret = finish_mem_reg(mhp, stag); |
| 486 | if (ret) |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 487 | goto err_dereg_mem; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 488 | return &mhp->ibmr; |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 489 | err_dereg_mem: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 490 | dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 491 | mhp->attr.pbl_addr, mhp->dereg_skb, mhp->wr_waitp); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 492 | err_free_skb: |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 493 | kfree_skb(mhp->dereg_skb); |
Christophe Jaillet | 3d69191 | 2018-05-08 07:44:27 +0200 | [diff] [blame^] | 494 | err_free_wr_wait: |
| 495 | c4iw_put_wr_wait(mhp->wr_waitp); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 496 | err_free_mhp: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 497 | kfree(mhp); |
| 498 | return ERR_PTR(ret); |
| 499 | } |
| 500 | |
| 501 | struct ib_mr *c4iw_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, |
| 502 | u64 virt, int acc, struct ib_udata *udata) |
| 503 | { |
| 504 | __be64 *pages; |
| 505 | int shift, n, len; |
Yishai Hadas | eeb8461 | 2014-01-28 13:40:15 +0200 | [diff] [blame] | 506 | int i, k, entry; |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 507 | int err = -ENOMEM; |
Yishai Hadas | eeb8461 | 2014-01-28 13:40:15 +0200 | [diff] [blame] | 508 | struct scatterlist *sg; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 509 | struct c4iw_dev *rhp; |
| 510 | struct c4iw_pd *php; |
| 511 | struct c4iw_mr *mhp; |
| 512 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 513 | pr_debug("ib_pd %p\n", pd); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 514 | |
| 515 | if (length == ~0ULL) |
| 516 | return ERR_PTR(-EINVAL); |
| 517 | |
| 518 | if ((length + start) < start) |
| 519 | return ERR_PTR(-EINVAL); |
| 520 | |
| 521 | php = to_c4iw_pd(pd); |
| 522 | rhp = php->rhp; |
Hariprasad Shenai | 2550a88 | 2014-11-21 09:36:36 -0600 | [diff] [blame] | 523 | |
| 524 | if (mr_exceeds_hw_limits(rhp, length)) |
| 525 | return ERR_PTR(-EINVAL); |
| 526 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 527 | mhp = kzalloc(sizeof(*mhp), GFP_KERNEL); |
| 528 | if (!mhp) |
| 529 | return ERR_PTR(-ENOMEM); |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 530 | mhp->wr_waitp = c4iw_alloc_wr_wait(GFP_KERNEL); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 531 | if (!mhp->wr_waitp) |
| 532 | goto err_free_mhp; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 533 | |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 534 | mhp->dereg_skb = alloc_skb(SGE_MAX_WR_LEN, GFP_KERNEL); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 535 | if (!mhp->dereg_skb) |
| 536 | goto err_free_wr_wait; |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 537 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 538 | mhp->rhp = rhp; |
| 539 | |
| 540 | mhp->umem = ib_umem_get(pd->uobject->context, start, length, acc, 0); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 541 | if (IS_ERR(mhp->umem)) |
| 542 | goto err_free_skb; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 543 | |
Artemy Kovalyov | 3e7e119 | 2017-04-05 09:23:50 +0300 | [diff] [blame] | 544 | shift = mhp->umem->page_shift; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 545 | |
Yishai Hadas | eeb8461 | 2014-01-28 13:40:15 +0200 | [diff] [blame] | 546 | n = mhp->umem->nmap; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 547 | err = alloc_pbl(mhp, n); |
| 548 | if (err) |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 549 | goto err_umem_release; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 550 | |
| 551 | pages = (__be64 *) __get_free_page(GFP_KERNEL); |
| 552 | if (!pages) { |
| 553 | err = -ENOMEM; |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 554 | goto err_pbl_free; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | i = n = 0; |
| 558 | |
Yishai Hadas | eeb8461 | 2014-01-28 13:40:15 +0200 | [diff] [blame] | 559 | for_each_sg(mhp->umem->sg_head.sgl, sg, mhp->umem->nmap, entry) { |
| 560 | len = sg_dma_len(sg) >> shift; |
| 561 | for (k = 0; k < len; ++k) { |
| 562 | pages[i++] = cpu_to_be64(sg_dma_address(sg) + |
Artemy Kovalyov | 3e7e119 | 2017-04-05 09:23:50 +0300 | [diff] [blame] | 563 | (k << shift)); |
Yishai Hadas | eeb8461 | 2014-01-28 13:40:15 +0200 | [diff] [blame] | 564 | if (i == PAGE_SIZE / sizeof *pages) { |
| 565 | err = write_pbl(&mhp->rhp->rdev, |
| 566 | pages, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 567 | mhp->attr.pbl_addr + (n << 3), i, |
| 568 | mhp->wr_waitp); |
Yishai Hadas | eeb8461 | 2014-01-28 13:40:15 +0200 | [diff] [blame] | 569 | if (err) |
| 570 | goto pbl_done; |
| 571 | n += i; |
| 572 | i = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 573 | } |
| 574 | } |
Yishai Hadas | eeb8461 | 2014-01-28 13:40:15 +0200 | [diff] [blame] | 575 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 576 | |
| 577 | if (i) |
| 578 | err = write_pbl(&mhp->rhp->rdev, pages, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 579 | mhp->attr.pbl_addr + (n << 3), i, |
| 580 | mhp->wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 581 | |
| 582 | pbl_done: |
| 583 | free_page((unsigned long) pages); |
| 584 | if (err) |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 585 | goto err_pbl_free; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 586 | |
| 587 | mhp->attr.pdid = php->pdid; |
| 588 | mhp->attr.zbva = 0; |
| 589 | mhp->attr.perms = c4iw_ib_to_tpt_access(acc); |
| 590 | mhp->attr.va_fbo = virt; |
| 591 | mhp->attr.page_size = shift - 12; |
Steve Wise | 301c2c3f | 2011-06-14 20:59:21 +0000 | [diff] [blame] | 592 | mhp->attr.len = length; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 593 | |
| 594 | err = register_mem(rhp, php, mhp, shift); |
| 595 | if (err) |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 596 | goto err_pbl_free; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 597 | |
| 598 | return &mhp->ibmr; |
| 599 | |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 600 | err_pbl_free: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 601 | c4iw_pblpool_free(&mhp->rhp->rdev, mhp->attr.pbl_addr, |
| 602 | mhp->attr.pbl_size << 3); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 603 | err_umem_release: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 604 | ib_umem_release(mhp->umem); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 605 | err_free_skb: |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 606 | kfree_skb(mhp->dereg_skb); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 607 | err_free_wr_wait: |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 608 | c4iw_put_wr_wait(mhp->wr_waitp); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 609 | err_free_mhp: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 610 | kfree(mhp); |
| 611 | return ERR_PTR(err); |
| 612 | } |
| 613 | |
Matan Barak | b2a239d | 2016-02-29 18:05:29 +0200 | [diff] [blame] | 614 | struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd, enum ib_mw_type type, |
| 615 | struct ib_udata *udata) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 616 | { |
| 617 | struct c4iw_dev *rhp; |
| 618 | struct c4iw_pd *php; |
| 619 | struct c4iw_mw *mhp; |
| 620 | u32 mmid; |
| 621 | u32 stag = 0; |
| 622 | int ret; |
| 623 | |
Shani Michaeli | 7083e42 | 2013-02-06 16:19:12 +0000 | [diff] [blame] | 624 | if (type != IB_MW_TYPE_1) |
| 625 | return ERR_PTR(-EINVAL); |
| 626 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 627 | php = to_c4iw_pd(pd); |
| 628 | rhp = php->rhp; |
| 629 | mhp = kzalloc(sizeof(*mhp), GFP_KERNEL); |
| 630 | if (!mhp) |
| 631 | return ERR_PTR(-ENOMEM); |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 632 | |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 633 | mhp->wr_waitp = c4iw_alloc_wr_wait(GFP_KERNEL); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 634 | if (!mhp->wr_waitp) { |
Hariprasad S | 56b2eca | 2016-06-30 11:44:33 +0530 | [diff] [blame] | 635 | ret = -ENOMEM; |
| 636 | goto free_mhp; |
Hariprasad S | 0f8ab0b | 2016-06-10 01:05:16 +0530 | [diff] [blame] | 637 | } |
| 638 | |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 639 | mhp->dereg_skb = alloc_skb(SGE_MAX_WR_LEN, GFP_KERNEL); |
| 640 | if (!mhp->dereg_skb) { |
| 641 | ret = -ENOMEM; |
| 642 | goto free_wr_wait; |
| 643 | } |
| 644 | |
| 645 | ret = allocate_window(&rhp->rdev, &stag, php->pdid, mhp->wr_waitp); |
Hariprasad S | 56b2eca | 2016-06-30 11:44:33 +0530 | [diff] [blame] | 646 | if (ret) |
| 647 | goto free_skb; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 648 | mhp->rhp = rhp; |
| 649 | mhp->attr.pdid = php->pdid; |
| 650 | mhp->attr.type = FW_RI_STAG_MW; |
| 651 | mhp->attr.stag = stag; |
| 652 | mmid = (stag) >> 8; |
| 653 | mhp->ibmw.rkey = stag; |
| 654 | if (insert_handle(rhp, &rhp->mmidr, mhp, mmid)) { |
Hariprasad S | 56b2eca | 2016-06-30 11:44:33 +0530 | [diff] [blame] | 655 | ret = -ENOMEM; |
| 656 | goto dealloc_win; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 657 | } |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 658 | pr_debug("mmid 0x%x mhp %p stag 0x%x\n", mmid, mhp, stag); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 659 | return &(mhp->ibmw); |
Hariprasad S | 56b2eca | 2016-06-30 11:44:33 +0530 | [diff] [blame] | 660 | |
| 661 | dealloc_win: |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 662 | deallocate_window(&rhp->rdev, mhp->attr.stag, mhp->dereg_skb, |
| 663 | mhp->wr_waitp); |
Hariprasad S | 56b2eca | 2016-06-30 11:44:33 +0530 | [diff] [blame] | 664 | free_skb: |
| 665 | kfree_skb(mhp->dereg_skb); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 666 | free_wr_wait: |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 667 | c4iw_put_wr_wait(mhp->wr_waitp); |
Hariprasad S | 56b2eca | 2016-06-30 11:44:33 +0530 | [diff] [blame] | 668 | free_mhp: |
| 669 | kfree(mhp); |
| 670 | return ERR_PTR(ret); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | int c4iw_dealloc_mw(struct ib_mw *mw) |
| 674 | { |
| 675 | struct c4iw_dev *rhp; |
| 676 | struct c4iw_mw *mhp; |
| 677 | u32 mmid; |
| 678 | |
| 679 | mhp = to_c4iw_mw(mw); |
| 680 | rhp = mhp->rhp; |
| 681 | mmid = (mw->rkey) >> 8; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 682 | remove_handle(rhp, &rhp->mmidr, mmid); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 683 | deallocate_window(&rhp->rdev, mhp->attr.stag, mhp->dereg_skb, |
| 684 | mhp->wr_waitp); |
Hariprasad S | 56b2eca | 2016-06-30 11:44:33 +0530 | [diff] [blame] | 685 | kfree_skb(mhp->dereg_skb); |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 686 | c4iw_put_wr_wait(mhp->wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 687 | kfree(mhp); |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 688 | pr_debug("ib_mw %p mmid 0x%x ptr %p\n", mw, mmid, mhp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 689 | return 0; |
| 690 | } |
| 691 | |
Sagi Grimberg | a216403 | 2015-07-30 10:32:44 +0300 | [diff] [blame] | 692 | struct ib_mr *c4iw_alloc_mr(struct ib_pd *pd, |
| 693 | enum ib_mr_type mr_type, |
| 694 | u32 max_num_sg) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 695 | { |
| 696 | struct c4iw_dev *rhp; |
| 697 | struct c4iw_pd *php; |
| 698 | struct c4iw_mr *mhp; |
| 699 | u32 mmid; |
| 700 | u32 stag = 0; |
| 701 | int ret = 0; |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 702 | int length = roundup(max_num_sg * sizeof(u64), 32); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 703 | |
| 704 | php = to_c4iw_pd(pd); |
| 705 | rhp = php->rhp; |
Hariprasad S | ee30f7d | 2016-02-12 16:10:35 +0530 | [diff] [blame] | 706 | |
| 707 | if (mr_type != IB_MR_TYPE_MEM_REG || |
Steve Wise | d4ba61d | 2017-07-25 06:51:15 -0700 | [diff] [blame] | 708 | max_num_sg > t4_max_fr_depth(rhp->rdev.lldi.ulptx_memwrite_dsgl && |
Hariprasad S | ee30f7d | 2016-02-12 16:10:35 +0530 | [diff] [blame] | 709 | use_dsgl)) |
| 710 | return ERR_PTR(-EINVAL); |
| 711 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 712 | mhp = kzalloc(sizeof(*mhp), GFP_KERNEL); |
Steve Wise | 841dba9 | 2010-05-20 16:57:54 -0500 | [diff] [blame] | 713 | if (!mhp) { |
| 714 | ret = -ENOMEM; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 715 | goto err; |
Steve Wise | 841dba9 | 2010-05-20 16:57:54 -0500 | [diff] [blame] | 716 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 717 | |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 718 | mhp->wr_waitp = c4iw_alloc_wr_wait(GFP_KERNEL); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 719 | if (!mhp->wr_waitp) { |
| 720 | ret = -ENOMEM; |
| 721 | goto err_free_mhp; |
| 722 | } |
| 723 | c4iw_init_wr_wait(mhp->wr_waitp); |
| 724 | |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 725 | mhp->mpl = dma_alloc_coherent(&rhp->rdev.lldi.pdev->dev, |
| 726 | length, &mhp->mpl_addr, GFP_KERNEL); |
| 727 | if (!mhp->mpl) { |
| 728 | ret = -ENOMEM; |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 729 | goto err_free_wr_wait; |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 730 | } |
| 731 | mhp->max_mpl_len = length; |
| 732 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 733 | mhp->rhp = rhp; |
Sagi Grimberg | a216403 | 2015-07-30 10:32:44 +0300 | [diff] [blame] | 734 | ret = alloc_pbl(mhp, max_num_sg); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 735 | if (ret) |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 736 | goto err_free_dma; |
Sagi Grimberg | a216403 | 2015-07-30 10:32:44 +0300 | [diff] [blame] | 737 | mhp->attr.pbl_size = max_num_sg; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 738 | ret = allocate_stag(&rhp->rdev, &stag, php->pdid, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 739 | mhp->attr.pbl_size, mhp->attr.pbl_addr, |
| 740 | mhp->wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 741 | if (ret) |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 742 | goto err_free_pbl; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 743 | mhp->attr.pdid = php->pdid; |
| 744 | mhp->attr.type = FW_RI_STAG_NSMR; |
| 745 | mhp->attr.stag = stag; |
Steve Wise | 49b53a9 | 2016-09-16 07:54:52 -0700 | [diff] [blame] | 746 | mhp->attr.state = 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 747 | mmid = (stag) >> 8; |
| 748 | mhp->ibmr.rkey = mhp->ibmr.lkey = stag; |
Steve Wise | 841dba9 | 2010-05-20 16:57:54 -0500 | [diff] [blame] | 749 | if (insert_handle(rhp, &rhp->mmidr, mhp, mmid)) { |
| 750 | ret = -ENOMEM; |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 751 | goto err_dereg; |
Steve Wise | 841dba9 | 2010-05-20 16:57:54 -0500 | [diff] [blame] | 752 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 753 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 754 | pr_debug("mmid 0x%x mhp %p stag 0x%x\n", mmid, mhp, stag); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 755 | return &(mhp->ibmr); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 756 | err_dereg: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 757 | dereg_mem(&rhp->rdev, stag, mhp->attr.pbl_size, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 758 | mhp->attr.pbl_addr, mhp->dereg_skb, mhp->wr_waitp); |
| 759 | err_free_pbl: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 760 | c4iw_pblpool_free(&mhp->rhp->rdev, mhp->attr.pbl_addr, |
| 761 | mhp->attr.pbl_size << 3); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 762 | err_free_dma: |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 763 | dma_free_coherent(&mhp->rhp->rdev.lldi.pdev->dev, |
| 764 | mhp->max_mpl_len, mhp->mpl, mhp->mpl_addr); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 765 | err_free_wr_wait: |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 766 | c4iw_put_wr_wait(mhp->wr_waitp); |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 767 | err_free_mhp: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 768 | kfree(mhp); |
| 769 | err: |
| 770 | return ERR_PTR(ret); |
| 771 | } |
| 772 | |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 773 | static int c4iw_set_page(struct ib_mr *ibmr, u64 addr) |
| 774 | { |
| 775 | struct c4iw_mr *mhp = to_c4iw_mr(ibmr); |
| 776 | |
| 777 | if (unlikely(mhp->mpl_len == mhp->max_mpl_len)) |
| 778 | return -ENOMEM; |
| 779 | |
| 780 | mhp->mpl[mhp->mpl_len++] = addr; |
| 781 | |
| 782 | return 0; |
| 783 | } |
| 784 | |
Christoph Hellwig | ff2ba99 | 2016-05-03 18:01:04 +0200 | [diff] [blame] | 785 | int c4iw_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents, |
Bart Van Assche | 9aa8b32 | 2016-05-12 10:49:15 -0700 | [diff] [blame] | 786 | unsigned int *sg_offset) |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 787 | { |
| 788 | struct c4iw_mr *mhp = to_c4iw_mr(ibmr); |
| 789 | |
| 790 | mhp->mpl_len = 0; |
| 791 | |
Christoph Hellwig | ff2ba99 | 2016-05-03 18:01:04 +0200 | [diff] [blame] | 792 | return ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, c4iw_set_page); |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 793 | } |
| 794 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 795 | int c4iw_dereg_mr(struct ib_mr *ib_mr) |
| 796 | { |
| 797 | struct c4iw_dev *rhp; |
| 798 | struct c4iw_mr *mhp; |
| 799 | u32 mmid; |
| 800 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 801 | pr_debug("ib_mr %p\n", ib_mr); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 802 | |
| 803 | mhp = to_c4iw_mr(ib_mr); |
| 804 | rhp = mhp->rhp; |
| 805 | mmid = mhp->attr.stag >> 8; |
Vipul Pandya | ec3eead | 2012-05-18 15:29:32 +0530 | [diff] [blame] | 806 | remove_handle(rhp, &rhp->mmidr, mmid); |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 807 | if (mhp->mpl) |
| 808 | dma_free_coherent(&mhp->rhp->rdev.lldi.pdev->dev, |
| 809 | mhp->max_mpl_len, mhp->mpl, mhp->mpl_addr); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 810 | dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size, |
Steve Wise | a3f12da | 2017-09-26 13:07:26 -0700 | [diff] [blame] | 811 | mhp->attr.pbl_addr, mhp->dereg_skb, mhp->wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 812 | if (mhp->attr.pbl_size) |
| 813 | c4iw_pblpool_free(&mhp->rhp->rdev, mhp->attr.pbl_addr, |
| 814 | mhp->attr.pbl_size << 3); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 815 | if (mhp->kva) |
| 816 | kfree((void *) (unsigned long) mhp->kva); |
| 817 | if (mhp->umem) |
| 818 | ib_umem_release(mhp->umem); |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 819 | pr_debug("mmid 0x%x ptr %p\n", mmid, mhp); |
Steve Wise | 2015f26 | 2017-09-26 13:13:17 -0700 | [diff] [blame] | 820 | c4iw_put_wr_wait(mhp->wr_waitp); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 821 | kfree(mhp); |
| 822 | return 0; |
| 823 | } |
Steve Wise | 5c6b2aa | 2016-11-03 12:09:38 -0700 | [diff] [blame] | 824 | |
| 825 | void c4iw_invalidate_mr(struct c4iw_dev *rhp, u32 rkey) |
| 826 | { |
| 827 | struct c4iw_mr *mhp; |
| 828 | unsigned long flags; |
| 829 | |
| 830 | spin_lock_irqsave(&rhp->lock, flags); |
| 831 | mhp = get_mhp(rhp, rkey >> 8); |
| 832 | if (mhp) |
| 833 | mhp->attr.state = 0; |
| 834 | spin_unlock_irqrestore(&rhp->lock, flags); |
| 835 | } |