Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 1 | /* QLogic qed NIC Driver |
Mintz, Yuval | e8f1cb5 | 2017-01-01 13:57:00 +0200 | [diff] [blame] | 2 | * Copyright (c) 2015-2017 QLogic Corporation |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and /or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | #include <linux/types.h> |
| 33 | #include <asm/byteorder.h> |
| 34 | #include <linux/bitops.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/dma-mapping.h> |
| 37 | #include <linux/errno.h> |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 38 | #include <linux/if_ether.h> |
| 39 | #include <linux/if_vlan.h> |
| 40 | #include <linux/io.h> |
| 41 | #include <linux/ip.h> |
| 42 | #include <linux/ipv6.h> |
| 43 | #include <linux/kernel.h> |
| 44 | #include <linux/list.h> |
| 45 | #include <linux/module.h> |
| 46 | #include <linux/mutex.h> |
| 47 | #include <linux/pci.h> |
| 48 | #include <linux/slab.h> |
| 49 | #include <linux/spinlock.h> |
| 50 | #include <linux/string.h> |
| 51 | #include <linux/tcp.h> |
| 52 | #include <linux/bitops.h> |
| 53 | #include <linux/qed/qed_roce_if.h> |
| 54 | #include <linux/qed/qed_roce_if.h> |
| 55 | #include "qed.h" |
| 56 | #include "qed_cxt.h" |
| 57 | #include "qed_hsi.h" |
| 58 | #include "qed_hw.h" |
| 59 | #include "qed_init_ops.h" |
| 60 | #include "qed_int.h" |
| 61 | #include "qed_ll2.h" |
| 62 | #include "qed_mcp.h" |
| 63 | #include "qed_reg_addr.h" |
| 64 | #include "qed_sp.h" |
| 65 | #include "qed_roce.h" |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 66 | #include "qed_ll2.h" |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 67 | #include <linux/qed/qed_ll2_if.h> |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 68 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 69 | static void qed_roce_free_real_icid(struct qed_hwfn *p_hwfn, u16 icid); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 70 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 71 | void qed_roce_async_event(struct qed_hwfn *p_hwfn, |
| 72 | u8 fw_event_code, union rdma_eqe_data *rdma_data) |
| 73 | { |
| 74 | if (fw_event_code == ROCE_ASYNC_EVENT_DESTROY_QP_DONE) { |
| 75 | u16 icid = |
| 76 | (u16)le32_to_cpu(rdma_data->rdma_destroy_qp_data.cid); |
| 77 | |
| 78 | /* icid release in this async event can occur only if the icid |
| 79 | * was offloaded to the FW. In case it wasn't offloaded this is |
| 80 | * handled in qed_roce_sp_destroy_qp. |
| 81 | */ |
| 82 | qed_roce_free_real_icid(p_hwfn, icid); |
| 83 | } else { |
| 84 | struct qed_rdma_events *events = &p_hwfn->p_rdma_info->events; |
| 85 | |
| 86 | events->affiliated_event(p_hwfn->p_rdma_info->events.context, |
| 87 | fw_event_code, |
| 88 | &rdma_data->async_handle); |
| 89 | } |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static int qed_rdma_bmap_alloc(struct qed_hwfn *p_hwfn, |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 93 | struct qed_bmap *bmap, u32 max_count, char *name) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 94 | { |
| 95 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "max_count = %08x\n", max_count); |
| 96 | |
| 97 | bmap->max_count = max_count; |
| 98 | |
| 99 | bmap->bitmap = kzalloc(BITS_TO_LONGS(max_count) * sizeof(long), |
| 100 | GFP_KERNEL); |
| 101 | if (!bmap->bitmap) { |
| 102 | DP_NOTICE(p_hwfn, |
| 103 | "qed bmap alloc failed: cannot allocate memory (bitmap)\n"); |
| 104 | return -ENOMEM; |
| 105 | } |
| 106 | |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 107 | snprintf(bmap->name, QED_RDMA_MAX_BMAP_NAME, "%s", name); |
| 108 | |
| 109 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "0\n"); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static int qed_rdma_bmap_alloc_id(struct qed_hwfn *p_hwfn, |
| 114 | struct qed_bmap *bmap, u32 *id_num) |
| 115 | { |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 116 | *id_num = find_first_zero_bit(bmap->bitmap, bmap->max_count); |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 117 | if (*id_num >= bmap->max_count) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 118 | return -EINVAL; |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 119 | |
| 120 | __set_bit(*id_num, bmap->bitmap); |
| 121 | |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 122 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "%s bitmap: allocated id %d\n", |
| 123 | bmap->name, *id_num); |
| 124 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 128 | static void qed_bmap_set_id(struct qed_hwfn *p_hwfn, |
| 129 | struct qed_bmap *bmap, u32 id_num) |
| 130 | { |
| 131 | if (id_num >= bmap->max_count) |
| 132 | return; |
| 133 | |
| 134 | __set_bit(id_num, bmap->bitmap); |
| 135 | } |
| 136 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 137 | static void qed_bmap_release_id(struct qed_hwfn *p_hwfn, |
| 138 | struct qed_bmap *bmap, u32 id_num) |
| 139 | { |
| 140 | bool b_acquired; |
| 141 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 142 | if (id_num >= bmap->max_count) |
| 143 | return; |
| 144 | |
| 145 | b_acquired = test_and_clear_bit(id_num, bmap->bitmap); |
| 146 | if (!b_acquired) { |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 147 | DP_NOTICE(p_hwfn, "%s bitmap: id %d already released\n", |
| 148 | bmap->name, id_num); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 149 | return; |
| 150 | } |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 151 | |
| 152 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "%s bitmap: released id %d\n", |
| 153 | bmap->name, id_num); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 154 | } |
| 155 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 156 | static int qed_bmap_test_id(struct qed_hwfn *p_hwfn, |
| 157 | struct qed_bmap *bmap, u32 id_num) |
| 158 | { |
| 159 | if (id_num >= bmap->max_count) |
| 160 | return -1; |
| 161 | |
| 162 | return test_bit(id_num, bmap->bitmap); |
| 163 | } |
| 164 | |
Mintz, Yuval | 9331dad | 2017-06-20 16:00:02 +0300 | [diff] [blame] | 165 | static bool qed_bmap_is_empty(struct qed_bmap *bmap) |
| 166 | { |
| 167 | return bmap->max_count == find_first_bit(bmap->bitmap, bmap->max_count); |
| 168 | } |
| 169 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 170 | static u32 qed_rdma_get_sb_id(void *p_hwfn, u32 rel_sb_id) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 171 | { |
| 172 | /* First sb id for RoCE is after all the l2 sb */ |
| 173 | return FEAT_NUM((struct qed_hwfn *)p_hwfn, QED_PF_L2_QUE) + rel_sb_id; |
| 174 | } |
| 175 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 176 | static int qed_rdma_alloc(struct qed_hwfn *p_hwfn, |
| 177 | struct qed_ptt *p_ptt, |
| 178 | struct qed_rdma_start_in_params *params) |
| 179 | { |
| 180 | struct qed_rdma_info *p_rdma_info; |
| 181 | u32 num_cons, num_tasks; |
| 182 | int rc = -ENOMEM; |
| 183 | |
| 184 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocating RDMA\n"); |
| 185 | |
| 186 | /* Allocate a struct with current pf rdma info */ |
| 187 | p_rdma_info = kzalloc(sizeof(*p_rdma_info), GFP_KERNEL); |
| 188 | if (!p_rdma_info) { |
| 189 | DP_NOTICE(p_hwfn, |
| 190 | "qed rdma alloc failed: cannot allocate memory (rdma info). rc = %d\n", |
| 191 | rc); |
| 192 | return rc; |
| 193 | } |
| 194 | |
| 195 | p_hwfn->p_rdma_info = p_rdma_info; |
| 196 | p_rdma_info->proto = PROTOCOLID_ROCE; |
| 197 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 198 | num_cons = qed_cxt_get_proto_cid_count(p_hwfn, p_rdma_info->proto, |
| 199 | NULL); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 200 | |
| 201 | p_rdma_info->num_qps = num_cons / 2; |
| 202 | |
| 203 | num_tasks = qed_cxt_get_proto_tid_count(p_hwfn, PROTOCOLID_ROCE); |
| 204 | |
| 205 | /* Each MR uses a single task */ |
| 206 | p_rdma_info->num_mrs = num_tasks; |
| 207 | |
| 208 | /* Queue zone lines are shared between RoCE and L2 in such a way that |
| 209 | * they can be used by each without obstructing the other. |
| 210 | */ |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 211 | p_rdma_info->queue_zone_base = (u16)RESC_START(p_hwfn, QED_L2_QUEUE); |
| 212 | p_rdma_info->max_queue_zones = (u16)RESC_NUM(p_hwfn, QED_L2_QUEUE); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 213 | |
| 214 | /* Allocate a struct with device params and fill it */ |
| 215 | p_rdma_info->dev = kzalloc(sizeof(*p_rdma_info->dev), GFP_KERNEL); |
| 216 | if (!p_rdma_info->dev) { |
| 217 | DP_NOTICE(p_hwfn, |
| 218 | "qed rdma alloc failed: cannot allocate memory (rdma info dev). rc = %d\n", |
| 219 | rc); |
| 220 | goto free_rdma_info; |
| 221 | } |
| 222 | |
| 223 | /* Allocate a struct with port params and fill it */ |
| 224 | p_rdma_info->port = kzalloc(sizeof(*p_rdma_info->port), GFP_KERNEL); |
| 225 | if (!p_rdma_info->port) { |
| 226 | DP_NOTICE(p_hwfn, |
| 227 | "qed rdma alloc failed: cannot allocate memory (rdma info port). rc = %d\n", |
| 228 | rc); |
| 229 | goto free_rdma_dev; |
| 230 | } |
| 231 | |
| 232 | /* Allocate bit map for pd's */ |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 233 | rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->pd_map, RDMA_MAX_PDS, |
| 234 | "PD"); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 235 | if (rc) { |
| 236 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 237 | "Failed to allocate pd_map, rc = %d\n", |
| 238 | rc); |
| 239 | goto free_rdma_port; |
| 240 | } |
| 241 | |
| 242 | /* Allocate DPI bitmap */ |
| 243 | rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->dpi_map, |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 244 | p_hwfn->dpi_count, "DPI"); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 245 | if (rc) { |
| 246 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 247 | "Failed to allocate DPI bitmap, rc = %d\n", rc); |
| 248 | goto free_pd_map; |
| 249 | } |
| 250 | |
| 251 | /* Allocate bitmap for cq's. The maximum number of CQs is bounded to |
| 252 | * twice the number of QPs. |
| 253 | */ |
| 254 | rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->cq_map, |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 255 | p_rdma_info->num_qps * 2, "CQ"); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 256 | if (rc) { |
| 257 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 258 | "Failed to allocate cq bitmap, rc = %d\n", rc); |
| 259 | goto free_dpi_map; |
| 260 | } |
| 261 | |
| 262 | /* Allocate bitmap for toggle bit for cq icids |
| 263 | * We toggle the bit every time we create or resize cq for a given icid. |
| 264 | * The maximum number of CQs is bounded to twice the number of QPs. |
| 265 | */ |
| 266 | rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->toggle_bits, |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 267 | p_rdma_info->num_qps * 2, "Toggle"); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 268 | if (rc) { |
| 269 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 270 | "Failed to allocate toogle bits, rc = %d\n", rc); |
| 271 | goto free_cq_map; |
| 272 | } |
| 273 | |
| 274 | /* Allocate bitmap for itids */ |
| 275 | rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->tid_map, |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 276 | p_rdma_info->num_mrs, "MR"); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 277 | if (rc) { |
| 278 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 279 | "Failed to allocate itids bitmaps, rc = %d\n", rc); |
| 280 | goto free_toggle_map; |
| 281 | } |
| 282 | |
| 283 | /* Allocate bitmap for cids used for qps. */ |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 284 | rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->cid_map, num_cons, |
| 285 | "CID"); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 286 | if (rc) { |
| 287 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 288 | "Failed to allocate cid bitmap, rc = %d\n", rc); |
| 289 | goto free_tid_map; |
| 290 | } |
| 291 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 292 | /* Allocate bitmap for cids used for responders/requesters. */ |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 293 | rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->real_cid_map, num_cons, |
| 294 | "REAL_CID"); |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 295 | if (rc) { |
| 296 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 297 | "Failed to allocate real cid bitmap, rc = %d\n", rc); |
| 298 | goto free_cid_map; |
| 299 | } |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 300 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocation successful\n"); |
| 301 | return 0; |
| 302 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 303 | free_cid_map: |
| 304 | kfree(p_rdma_info->cid_map.bitmap); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 305 | free_tid_map: |
| 306 | kfree(p_rdma_info->tid_map.bitmap); |
| 307 | free_toggle_map: |
| 308 | kfree(p_rdma_info->toggle_bits.bitmap); |
| 309 | free_cq_map: |
| 310 | kfree(p_rdma_info->cq_map.bitmap); |
| 311 | free_dpi_map: |
| 312 | kfree(p_rdma_info->dpi_map.bitmap); |
| 313 | free_pd_map: |
| 314 | kfree(p_rdma_info->pd_map.bitmap); |
| 315 | free_rdma_port: |
| 316 | kfree(p_rdma_info->port); |
| 317 | free_rdma_dev: |
| 318 | kfree(p_rdma_info->dev); |
| 319 | free_rdma_info: |
| 320 | kfree(p_rdma_info); |
| 321 | |
| 322 | return rc; |
| 323 | } |
| 324 | |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 325 | static void qed_rdma_bmap_free(struct qed_hwfn *p_hwfn, |
| 326 | struct qed_bmap *bmap, bool check) |
| 327 | { |
| 328 | int weight = bitmap_weight(bmap->bitmap, bmap->max_count); |
| 329 | int last_line = bmap->max_count / (64 * 8); |
| 330 | int last_item = last_line * 8 + |
| 331 | DIV_ROUND_UP(bmap->max_count % (64 * 8), 64); |
| 332 | u64 *pmap = (u64 *)bmap->bitmap; |
| 333 | int line, item, offset; |
| 334 | u8 str_last_line[200] = { 0 }; |
| 335 | |
| 336 | if (!weight || !check) |
| 337 | goto end; |
| 338 | |
| 339 | DP_NOTICE(p_hwfn, |
| 340 | "%s bitmap not free - size=%d, weight=%d, 512 bits per line\n", |
| 341 | bmap->name, bmap->max_count, weight); |
| 342 | |
| 343 | /* print aligned non-zero lines, if any */ |
| 344 | for (item = 0, line = 0; line < last_line; line++, item += 8) |
| 345 | if (bitmap_weight((unsigned long *)&pmap[item], 64 * 8)) |
| 346 | DP_NOTICE(p_hwfn, |
| 347 | "line 0x%04x: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n", |
| 348 | line, |
| 349 | pmap[item], |
| 350 | pmap[item + 1], |
| 351 | pmap[item + 2], |
| 352 | pmap[item + 3], |
| 353 | pmap[item + 4], |
| 354 | pmap[item + 5], |
| 355 | pmap[item + 6], pmap[item + 7]); |
| 356 | |
| 357 | /* print last unaligned non-zero line, if any */ |
| 358 | if ((bmap->max_count % (64 * 8)) && |
| 359 | (bitmap_weight((unsigned long *)&pmap[item], |
| 360 | bmap->max_count - item * 64))) { |
| 361 | offset = sprintf(str_last_line, "line 0x%04x: ", line); |
| 362 | for (; item < last_item; item++) |
| 363 | offset += sprintf(str_last_line + offset, |
| 364 | "0x%016llx ", pmap[item]); |
| 365 | DP_NOTICE(p_hwfn, "%s\n", str_last_line); |
| 366 | } |
| 367 | |
| 368 | end: |
| 369 | kfree(bmap->bitmap); |
| 370 | bmap->bitmap = NULL; |
| 371 | } |
| 372 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 373 | static void qed_rdma_resc_free(struct qed_hwfn *p_hwfn) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 374 | { |
| 375 | struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info; |
| 376 | |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 377 | qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->cid_map, 1); |
| 378 | qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->pd_map, 1); |
| 379 | qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->dpi_map, 1); |
| 380 | qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->cq_map, 1); |
| 381 | qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->toggle_bits, 0); |
| 382 | qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->tid_map, 1); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 383 | |
| 384 | kfree(p_rdma_info->port); |
| 385 | kfree(p_rdma_info->dev); |
| 386 | |
| 387 | kfree(p_rdma_info); |
| 388 | } |
| 389 | |
| 390 | static void qed_rdma_free(struct qed_hwfn *p_hwfn) |
| 391 | { |
| 392 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Freeing RDMA\n"); |
| 393 | |
| 394 | qed_rdma_resc_free(p_hwfn); |
| 395 | } |
| 396 | |
| 397 | static void qed_rdma_get_guid(struct qed_hwfn *p_hwfn, u8 *guid) |
| 398 | { |
| 399 | guid[0] = p_hwfn->hw_info.hw_mac_addr[0] ^ 2; |
| 400 | guid[1] = p_hwfn->hw_info.hw_mac_addr[1]; |
| 401 | guid[2] = p_hwfn->hw_info.hw_mac_addr[2]; |
| 402 | guid[3] = 0xff; |
| 403 | guid[4] = 0xfe; |
| 404 | guid[5] = p_hwfn->hw_info.hw_mac_addr[3]; |
| 405 | guid[6] = p_hwfn->hw_info.hw_mac_addr[4]; |
| 406 | guid[7] = p_hwfn->hw_info.hw_mac_addr[5]; |
| 407 | } |
| 408 | |
| 409 | static void qed_rdma_init_events(struct qed_hwfn *p_hwfn, |
| 410 | struct qed_rdma_start_in_params *params) |
| 411 | { |
| 412 | struct qed_rdma_events *events; |
| 413 | |
| 414 | events = &p_hwfn->p_rdma_info->events; |
| 415 | |
| 416 | events->unaffiliated_event = params->events->unaffiliated_event; |
| 417 | events->affiliated_event = params->events->affiliated_event; |
| 418 | events->context = params->events->context; |
| 419 | } |
| 420 | |
| 421 | static void qed_rdma_init_devinfo(struct qed_hwfn *p_hwfn, |
| 422 | struct qed_rdma_start_in_params *params) |
| 423 | { |
| 424 | struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev; |
| 425 | struct qed_dev *cdev = p_hwfn->cdev; |
| 426 | u32 pci_status_control; |
| 427 | u32 num_qps; |
| 428 | |
| 429 | /* Vendor specific information */ |
| 430 | dev->vendor_id = cdev->vendor_id; |
| 431 | dev->vendor_part_id = cdev->device_id; |
| 432 | dev->hw_ver = 0; |
| 433 | dev->fw_ver = (FW_MAJOR_VERSION << 24) | (FW_MINOR_VERSION << 16) | |
| 434 | (FW_REVISION_VERSION << 8) | (FW_ENGINEERING_VERSION); |
| 435 | |
| 436 | qed_rdma_get_guid(p_hwfn, (u8 *)&dev->sys_image_guid); |
| 437 | dev->node_guid = dev->sys_image_guid; |
| 438 | |
| 439 | dev->max_sge = min_t(u32, RDMA_MAX_SGE_PER_SQ_WQE, |
| 440 | RDMA_MAX_SGE_PER_RQ_WQE); |
| 441 | |
| 442 | if (cdev->rdma_max_sge) |
| 443 | dev->max_sge = min_t(u32, cdev->rdma_max_sge, dev->max_sge); |
| 444 | |
| 445 | dev->max_inline = ROCE_REQ_MAX_INLINE_DATA_SIZE; |
| 446 | |
| 447 | dev->max_inline = (cdev->rdma_max_inline) ? |
| 448 | min_t(u32, cdev->rdma_max_inline, dev->max_inline) : |
| 449 | dev->max_inline; |
| 450 | |
| 451 | dev->max_wqe = QED_RDMA_MAX_WQE; |
| 452 | dev->max_cnq = (u8)FEAT_NUM(p_hwfn, QED_RDMA_CNQ); |
| 453 | |
| 454 | /* The number of QPs may be higher than QED_ROCE_MAX_QPS, because |
| 455 | * it is up-aligned to 16 and then to ILT page size within qed cxt. |
| 456 | * This is OK in terms of ILT but we don't want to configure the FW |
| 457 | * above its abilities |
| 458 | */ |
| 459 | num_qps = ROCE_MAX_QPS; |
| 460 | num_qps = min_t(u64, num_qps, p_hwfn->p_rdma_info->num_qps); |
| 461 | dev->max_qp = num_qps; |
| 462 | |
| 463 | /* CQs uses the same icids that QPs use hence they are limited by the |
| 464 | * number of icids. There are two icids per QP. |
| 465 | */ |
| 466 | dev->max_cq = num_qps * 2; |
| 467 | |
| 468 | /* The number of mrs is smaller by 1 since the first is reserved */ |
| 469 | dev->max_mr = p_hwfn->p_rdma_info->num_mrs - 1; |
| 470 | dev->max_mr_size = QED_RDMA_MAX_MR_SIZE; |
| 471 | |
| 472 | /* The maximum CQE capacity per CQ supported. |
| 473 | * max number of cqes will be in two layer pbl, |
| 474 | * 8 is the pointer size in bytes |
| 475 | * 32 is the size of cq element in bytes |
| 476 | */ |
| 477 | if (params->cq_mode == QED_RDMA_CQ_MODE_32_BITS) |
| 478 | dev->max_cqe = QED_RDMA_MAX_CQE_32_BIT; |
| 479 | else |
| 480 | dev->max_cqe = QED_RDMA_MAX_CQE_16_BIT; |
| 481 | |
| 482 | dev->max_mw = 0; |
| 483 | dev->max_fmr = QED_RDMA_MAX_FMR; |
| 484 | dev->max_mr_mw_fmr_pbl = (PAGE_SIZE / 8) * (PAGE_SIZE / 8); |
| 485 | dev->max_mr_mw_fmr_size = dev->max_mr_mw_fmr_pbl * PAGE_SIZE; |
| 486 | dev->max_pkey = QED_RDMA_MAX_P_KEY; |
| 487 | |
| 488 | dev->max_qp_resp_rd_atomic_resc = RDMA_RING_PAGE_SIZE / |
| 489 | (RDMA_RESP_RD_ATOMIC_ELM_SIZE * 2); |
| 490 | dev->max_qp_req_rd_atomic_resc = RDMA_RING_PAGE_SIZE / |
| 491 | RDMA_REQ_RD_ATOMIC_ELM_SIZE; |
| 492 | dev->max_dev_resp_rd_atomic_resc = dev->max_qp_resp_rd_atomic_resc * |
| 493 | p_hwfn->p_rdma_info->num_qps; |
| 494 | dev->page_size_caps = QED_RDMA_PAGE_SIZE_CAPS; |
| 495 | dev->dev_ack_delay = QED_RDMA_ACK_DELAY; |
| 496 | dev->max_pd = RDMA_MAX_PDS; |
| 497 | dev->max_ah = p_hwfn->p_rdma_info->num_qps; |
| 498 | dev->max_stats_queues = (u8)RESC_NUM(p_hwfn, QED_RDMA_STATS_QUEUE); |
| 499 | |
| 500 | /* Set capablities */ |
| 501 | dev->dev_caps = 0; |
| 502 | SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_RNR_NAK, 1); |
| 503 | SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_PORT_ACTIVE_EVENT, 1); |
| 504 | SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_PORT_CHANGE_EVENT, 1); |
| 505 | SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_RESIZE_CQ, 1); |
| 506 | SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_BASE_MEMORY_EXT, 1); |
| 507 | SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_BASE_QUEUE_EXT, 1); |
| 508 | SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_ZBVA, 1); |
| 509 | SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_LOCAL_INV_FENCE, 1); |
| 510 | |
| 511 | /* Check atomic operations support in PCI configuration space. */ |
| 512 | pci_read_config_dword(cdev->pdev, |
| 513 | cdev->pdev->pcie_cap + PCI_EXP_DEVCTL2, |
| 514 | &pci_status_control); |
| 515 | |
| 516 | if (pci_status_control & PCI_EXP_DEVCTL2_LTR_EN) |
| 517 | SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_ATOMIC_OP, 1); |
| 518 | } |
| 519 | |
| 520 | static void qed_rdma_init_port(struct qed_hwfn *p_hwfn) |
| 521 | { |
| 522 | struct qed_rdma_port *port = p_hwfn->p_rdma_info->port; |
| 523 | struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev; |
| 524 | |
| 525 | port->port_state = p_hwfn->mcp_info->link_output.link_up ? |
| 526 | QED_RDMA_PORT_UP : QED_RDMA_PORT_DOWN; |
| 527 | |
| 528 | port->max_msg_size = min_t(u64, |
| 529 | (dev->max_mr_mw_fmr_size * |
| 530 | p_hwfn->cdev->rdma_max_sge), |
| 531 | BIT(31)); |
| 532 | |
| 533 | port->pkey_bad_counter = 0; |
| 534 | } |
| 535 | |
| 536 | static int qed_rdma_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 537 | { |
| 538 | u32 ll2_ethertype_en; |
| 539 | |
| 540 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Initializing HW\n"); |
| 541 | p_hwfn->b_rdma_enabled_in_prs = false; |
| 542 | |
| 543 | qed_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF, 0); |
| 544 | |
| 545 | p_hwfn->rdma_prs_search_reg = PRS_REG_SEARCH_ROCE; |
| 546 | |
| 547 | /* We delay writing to this reg until first cid is allocated. See |
| 548 | * qed_cxt_dynamic_ilt_alloc function for more details |
| 549 | */ |
| 550 | ll2_ethertype_en = qed_rd(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN); |
| 551 | qed_wr(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN, |
| 552 | (ll2_ethertype_en | 0x01)); |
| 553 | |
| 554 | if (qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_ROCE) % 2) { |
| 555 | DP_NOTICE(p_hwfn, "The first RoCE's cid should be even\n"); |
| 556 | return -EINVAL; |
| 557 | } |
| 558 | |
| 559 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Initializing HW - Done\n"); |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | static int qed_rdma_start_fw(struct qed_hwfn *p_hwfn, |
| 564 | struct qed_rdma_start_in_params *params, |
| 565 | struct qed_ptt *p_ptt) |
| 566 | { |
| 567 | struct rdma_init_func_ramrod_data *p_ramrod; |
| 568 | struct qed_rdma_cnq_params *p_cnq_pbl_list; |
| 569 | struct rdma_init_func_hdr *p_params_header; |
| 570 | struct rdma_cnq_params *p_cnq_params; |
| 571 | struct qed_sp_init_data init_data; |
| 572 | struct qed_spq_entry *p_ent; |
| 573 | u32 cnq_id, sb_id; |
Mintz, Yuval | 50a2071 | 2017-06-01 15:29:09 +0300 | [diff] [blame] | 574 | u16 igu_sb_id; |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 575 | int rc; |
| 576 | |
| 577 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Starting FW\n"); |
| 578 | |
| 579 | /* Save the number of cnqs for the function close ramrod */ |
| 580 | p_hwfn->p_rdma_info->num_cnqs = params->desired_cnq; |
| 581 | |
| 582 | /* Get SPQ entry */ |
| 583 | memset(&init_data, 0, sizeof(init_data)); |
| 584 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 585 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 586 | |
| 587 | rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_FUNC_INIT, |
| 588 | p_hwfn->p_rdma_info->proto, &init_data); |
| 589 | if (rc) |
| 590 | return rc; |
| 591 | |
| 592 | p_ramrod = &p_ent->ramrod.roce_init_func.rdma; |
| 593 | |
| 594 | p_params_header = &p_ramrod->params_header; |
| 595 | p_params_header->cnq_start_offset = (u8)RESC_START(p_hwfn, |
| 596 | QED_RDMA_CNQ_RAM); |
| 597 | p_params_header->num_cnqs = params->desired_cnq; |
| 598 | |
| 599 | if (params->cq_mode == QED_RDMA_CQ_MODE_16_BITS) |
| 600 | p_params_header->cq_ring_mode = 1; |
| 601 | else |
| 602 | p_params_header->cq_ring_mode = 0; |
| 603 | |
| 604 | for (cnq_id = 0; cnq_id < params->desired_cnq; cnq_id++) { |
| 605 | sb_id = qed_rdma_get_sb_id(p_hwfn, cnq_id); |
Mintz, Yuval | 50a2071 | 2017-06-01 15:29:09 +0300 | [diff] [blame] | 606 | igu_sb_id = qed_get_igu_sb_id(p_hwfn, sb_id); |
| 607 | p_ramrod->cnq_params[cnq_id].sb_num = cpu_to_le16(igu_sb_id); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 608 | p_cnq_params = &p_ramrod->cnq_params[cnq_id]; |
| 609 | p_cnq_pbl_list = ¶ms->cnq_pbl_list[cnq_id]; |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 610 | |
| 611 | p_cnq_params->sb_index = p_hwfn->pf_params.rdma_pf_params.gl_pi; |
| 612 | p_cnq_params->num_pbl_pages = p_cnq_pbl_list->num_pbl_pages; |
| 613 | |
| 614 | DMA_REGPAIR_LE(p_cnq_params->pbl_base_addr, |
| 615 | p_cnq_pbl_list->pbl_ptr); |
| 616 | |
| 617 | /* we assume here that cnq_id and qz_offset are the same */ |
| 618 | p_cnq_params->queue_zone_num = |
| 619 | cpu_to_le16(p_hwfn->p_rdma_info->queue_zone_base + |
| 620 | cnq_id); |
| 621 | } |
| 622 | |
| 623 | return qed_spq_post(p_hwfn, p_ent, NULL); |
| 624 | } |
| 625 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 626 | static int qed_rdma_alloc_tid(void *rdma_cxt, u32 *itid) |
| 627 | { |
| 628 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 629 | int rc; |
| 630 | |
| 631 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID\n"); |
| 632 | |
| 633 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 634 | rc = qed_rdma_bmap_alloc_id(p_hwfn, |
| 635 | &p_hwfn->p_rdma_info->tid_map, itid); |
| 636 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 637 | if (rc) |
| 638 | goto out; |
| 639 | |
| 640 | rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_TASK, *itid); |
| 641 | out: |
| 642 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID - done, rc = %d\n", rc); |
| 643 | return rc; |
| 644 | } |
| 645 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 646 | static int qed_rdma_reserve_lkey(struct qed_hwfn *p_hwfn) |
| 647 | { |
| 648 | struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev; |
| 649 | |
| 650 | /* The first DPI is reserved for the Kernel */ |
| 651 | __set_bit(0, p_hwfn->p_rdma_info->dpi_map.bitmap); |
| 652 | |
| 653 | /* Tid 0 will be used as the key for "reserved MR". |
| 654 | * The driver should allocate memory for it so it can be loaded but no |
| 655 | * ramrod should be passed on it. |
| 656 | */ |
| 657 | qed_rdma_alloc_tid(p_hwfn, &dev->reserved_lkey); |
| 658 | if (dev->reserved_lkey != RDMA_RESERVED_LKEY) { |
| 659 | DP_NOTICE(p_hwfn, |
| 660 | "Reserved lkey should be equal to RDMA_RESERVED_LKEY\n"); |
| 661 | return -EINVAL; |
| 662 | } |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int qed_rdma_setup(struct qed_hwfn *p_hwfn, |
| 668 | struct qed_ptt *p_ptt, |
| 669 | struct qed_rdma_start_in_params *params) |
| 670 | { |
| 671 | int rc; |
| 672 | |
| 673 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA setup\n"); |
| 674 | |
| 675 | spin_lock_init(&p_hwfn->p_rdma_info->lock); |
| 676 | |
| 677 | qed_rdma_init_devinfo(p_hwfn, params); |
| 678 | qed_rdma_init_port(p_hwfn); |
| 679 | qed_rdma_init_events(p_hwfn, params); |
| 680 | |
| 681 | rc = qed_rdma_reserve_lkey(p_hwfn); |
| 682 | if (rc) |
| 683 | return rc; |
| 684 | |
| 685 | rc = qed_rdma_init_hw(p_hwfn, p_ptt); |
| 686 | if (rc) |
| 687 | return rc; |
| 688 | |
| 689 | return qed_rdma_start_fw(p_hwfn, params, p_ptt); |
| 690 | } |
| 691 | |
Michal Kalderon | 898fff1 | 2017-06-20 16:00:05 +0300 | [diff] [blame^] | 692 | void qed_roce_stop(struct qed_hwfn *p_hwfn) |
| 693 | { |
| 694 | struct qed_bmap *rcid_map = &p_hwfn->p_rdma_info->real_cid_map; |
| 695 | int wait_count = 0; |
| 696 | |
| 697 | /* when destroying a_RoCE QP the control is returned to the user after |
| 698 | * the synchronous part. The asynchronous part may take a little longer. |
| 699 | * We delay for a short while if an async destroy QP is still expected. |
| 700 | * Beyond the added delay we clear the bitmap anyway. |
| 701 | */ |
| 702 | while (bitmap_weight(rcid_map->bitmap, rcid_map->max_count)) { |
| 703 | msleep(100); |
| 704 | if (wait_count++ > 20) { |
| 705 | DP_NOTICE(p_hwfn, "cid bitmap wait timed out\n"); |
| 706 | break; |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 711 | static int qed_rdma_stop(void *rdma_cxt) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 712 | { |
| 713 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 714 | struct rdma_close_func_ramrod_data *p_ramrod; |
| 715 | struct qed_sp_init_data init_data; |
| 716 | struct qed_spq_entry *p_ent; |
| 717 | struct qed_ptt *p_ptt; |
| 718 | u32 ll2_ethertype_en; |
| 719 | int rc = -EBUSY; |
| 720 | |
| 721 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA stop\n"); |
| 722 | |
| 723 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 724 | if (!p_ptt) { |
| 725 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Failed to acquire PTT\n"); |
| 726 | return rc; |
| 727 | } |
| 728 | |
| 729 | /* Disable RoCE search */ |
| 730 | qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 0); |
| 731 | p_hwfn->b_rdma_enabled_in_prs = false; |
| 732 | |
| 733 | qed_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF, 0); |
| 734 | |
| 735 | ll2_ethertype_en = qed_rd(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN); |
| 736 | |
| 737 | qed_wr(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN, |
| 738 | (ll2_ethertype_en & 0xFFFE)); |
| 739 | |
Michal Kalderon | 898fff1 | 2017-06-20 16:00:05 +0300 | [diff] [blame^] | 740 | qed_roce_stop(p_hwfn); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 741 | qed_ptt_release(p_hwfn, p_ptt); |
| 742 | |
| 743 | /* Get SPQ entry */ |
| 744 | memset(&init_data, 0, sizeof(init_data)); |
| 745 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 746 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 747 | |
| 748 | /* Stop RoCE */ |
| 749 | rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_FUNC_CLOSE, |
| 750 | p_hwfn->p_rdma_info->proto, &init_data); |
| 751 | if (rc) |
| 752 | goto out; |
| 753 | |
| 754 | p_ramrod = &p_ent->ramrod.rdma_close_func; |
| 755 | |
| 756 | p_ramrod->num_cnqs = p_hwfn->p_rdma_info->num_cnqs; |
| 757 | p_ramrod->cnq_start_offset = (u8)RESC_START(p_hwfn, QED_RDMA_CNQ_RAM); |
| 758 | |
| 759 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 760 | |
| 761 | out: |
| 762 | qed_rdma_free(p_hwfn); |
| 763 | |
| 764 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA stop done, rc = %d\n", rc); |
| 765 | return rc; |
| 766 | } |
| 767 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 768 | static int qed_rdma_add_user(void *rdma_cxt, |
| 769 | struct qed_rdma_add_user_out_params *out_params) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 770 | { |
| 771 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 772 | u32 dpi_start_offset; |
| 773 | u32 returned_id = 0; |
| 774 | int rc; |
| 775 | |
| 776 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Adding User\n"); |
| 777 | |
| 778 | /* Allocate DPI */ |
| 779 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 780 | rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_hwfn->p_rdma_info->dpi_map, |
| 781 | &returned_id); |
| 782 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 783 | |
| 784 | out_params->dpi = (u16)returned_id; |
| 785 | |
| 786 | /* Calculate the corresponding DPI address */ |
| 787 | dpi_start_offset = p_hwfn->dpi_start_offset; |
| 788 | |
| 789 | out_params->dpi_addr = (u64)((u8 __iomem *)p_hwfn->doorbells + |
| 790 | dpi_start_offset + |
| 791 | ((out_params->dpi) * p_hwfn->dpi_size)); |
| 792 | |
| 793 | out_params->dpi_phys_addr = p_hwfn->cdev->db_phys_addr + |
| 794 | dpi_start_offset + |
| 795 | ((out_params->dpi) * p_hwfn->dpi_size); |
| 796 | |
| 797 | out_params->dpi_size = p_hwfn->dpi_size; |
Ram Amrani | 20b1bd9 | 2017-04-30 11:49:10 +0300 | [diff] [blame] | 798 | out_params->wid_count = p_hwfn->wid_count; |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 799 | |
| 800 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Adding user - done, rc = %d\n", rc); |
| 801 | return rc; |
| 802 | } |
| 803 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 804 | static struct qed_rdma_port *qed_rdma_query_port(void *rdma_cxt) |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 805 | { |
| 806 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 807 | struct qed_rdma_port *p_port = p_hwfn->p_rdma_info->port; |
| 808 | |
| 809 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA Query port\n"); |
| 810 | |
| 811 | /* Link may have changed */ |
| 812 | p_port->port_state = p_hwfn->mcp_info->link_output.link_up ? |
| 813 | QED_RDMA_PORT_UP : QED_RDMA_PORT_DOWN; |
| 814 | |
| 815 | p_port->link_speed = p_hwfn->mcp_info->link_output.speed; |
| 816 | |
Ram Amrani | 793ea8a | 2017-04-30 11:49:05 +0300 | [diff] [blame] | 817 | p_port->max_msg_size = RDMA_MAX_DATA_SIZE_IN_WQE; |
| 818 | |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 819 | return p_port; |
| 820 | } |
| 821 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 822 | static struct qed_rdma_device *qed_rdma_query_device(void *rdma_cxt) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 823 | { |
| 824 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 825 | |
| 826 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Query device\n"); |
| 827 | |
| 828 | /* Return struct with device parameters */ |
| 829 | return p_hwfn->p_rdma_info->dev; |
| 830 | } |
| 831 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 832 | static void qed_rdma_free_tid(void *rdma_cxt, u32 itid) |
Ram Amrani | ee8eaea | 2016-10-01 22:00:00 +0300 | [diff] [blame] | 833 | { |
| 834 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 835 | |
| 836 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", itid); |
| 837 | |
| 838 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 839 | qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->tid_map, itid); |
| 840 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 841 | } |
| 842 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 843 | static void qed_rdma_cnq_prod_update(void *rdma_cxt, u8 qz_offset, u16 prod) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 844 | { |
| 845 | struct qed_hwfn *p_hwfn; |
| 846 | u16 qz_num; |
| 847 | u32 addr; |
| 848 | |
| 849 | p_hwfn = (struct qed_hwfn *)rdma_cxt; |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 850 | |
| 851 | if (qz_offset > p_hwfn->p_rdma_info->max_queue_zones) { |
| 852 | DP_NOTICE(p_hwfn, |
| 853 | "queue zone offset %d is too large (max is %d)\n", |
| 854 | qz_offset, p_hwfn->p_rdma_info->max_queue_zones); |
| 855 | return; |
| 856 | } |
| 857 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 858 | qz_num = p_hwfn->p_rdma_info->queue_zone_base + qz_offset; |
| 859 | addr = GTT_BAR0_MAP_REG_USDM_RAM + |
| 860 | USTORM_COMMON_QUEUE_CONS_OFFSET(qz_num); |
| 861 | |
| 862 | REG_WR16(p_hwfn, addr, prod); |
| 863 | |
| 864 | /* keep prod updates ordered */ |
| 865 | wmb(); |
| 866 | } |
| 867 | |
| 868 | static int qed_fill_rdma_dev_info(struct qed_dev *cdev, |
| 869 | struct qed_dev_rdma_info *info) |
| 870 | { |
Ram Amrani | 20b1bd9 | 2017-04-30 11:49:10 +0300 | [diff] [blame] | 871 | struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev); |
| 872 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 873 | memset(info, 0, sizeof(*info)); |
| 874 | |
| 875 | info->rdma_type = QED_RDMA_TYPE_ROCE; |
Ram Amrani | 20b1bd9 | 2017-04-30 11:49:10 +0300 | [diff] [blame] | 876 | info->user_dpm_enabled = (p_hwfn->db_bar_no_edpm == 0); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 877 | |
| 878 | qed_fill_dev_info(cdev, &info->common); |
| 879 | |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | static int qed_rdma_get_sb_start(struct qed_dev *cdev) |
| 884 | { |
| 885 | int feat_num; |
| 886 | |
| 887 | if (cdev->num_hwfns > 1) |
| 888 | feat_num = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_PF_L2_QUE); |
| 889 | else |
| 890 | feat_num = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_PF_L2_QUE) * |
| 891 | cdev->num_hwfns; |
| 892 | |
| 893 | return feat_num; |
| 894 | } |
| 895 | |
| 896 | static int qed_rdma_get_min_cnq_msix(struct qed_dev *cdev) |
| 897 | { |
| 898 | int n_cnq = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_RDMA_CNQ); |
| 899 | int n_msix = cdev->int_params.rdma_msix_cnt; |
| 900 | |
| 901 | return min_t(int, n_cnq, n_msix); |
| 902 | } |
| 903 | |
| 904 | static int qed_rdma_set_int(struct qed_dev *cdev, u16 cnt) |
| 905 | { |
| 906 | int limit = 0; |
| 907 | |
| 908 | /* Mark the fastpath as free/used */ |
| 909 | cdev->int_params.fp_initialized = cnt ? true : false; |
| 910 | |
| 911 | if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX) { |
| 912 | DP_ERR(cdev, |
| 913 | "qed roce supports only MSI-X interrupts (detected %d).\n", |
| 914 | cdev->int_params.out.int_mode); |
| 915 | return -EINVAL; |
| 916 | } else if (cdev->int_params.fp_msix_cnt) { |
| 917 | limit = cdev->int_params.rdma_msix_cnt; |
| 918 | } |
| 919 | |
| 920 | if (!limit) |
| 921 | return -ENOMEM; |
| 922 | |
| 923 | return min_t(int, cnt, limit); |
| 924 | } |
| 925 | |
| 926 | static int qed_rdma_get_int(struct qed_dev *cdev, struct qed_int_info *info) |
| 927 | { |
| 928 | memset(info, 0, sizeof(*info)); |
| 929 | |
| 930 | if (!cdev->int_params.fp_initialized) { |
| 931 | DP_INFO(cdev, |
| 932 | "Protocol driver requested interrupt information, but its support is not yet configured\n"); |
| 933 | return -EINVAL; |
| 934 | } |
| 935 | |
| 936 | if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) { |
| 937 | int msix_base = cdev->int_params.rdma_msix_base; |
| 938 | |
| 939 | info->msix_cnt = cdev->int_params.rdma_msix_cnt; |
| 940 | info->msix = &cdev->int_params.msix_table[msix_base]; |
| 941 | |
| 942 | DP_VERBOSE(cdev, QED_MSG_RDMA, "msix_cnt = %d msix_base=%d\n", |
| 943 | info->msix_cnt, msix_base); |
| 944 | } |
| 945 | |
| 946 | return 0; |
| 947 | } |
| 948 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 949 | static int qed_rdma_alloc_pd(void *rdma_cxt, u16 *pd) |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 950 | { |
| 951 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 952 | u32 returned_id; |
| 953 | int rc; |
| 954 | |
| 955 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Alloc PD\n"); |
| 956 | |
| 957 | /* Allocates an unused protection domain */ |
| 958 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 959 | rc = qed_rdma_bmap_alloc_id(p_hwfn, |
| 960 | &p_hwfn->p_rdma_info->pd_map, &returned_id); |
| 961 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 962 | |
| 963 | *pd = (u16)returned_id; |
| 964 | |
| 965 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Alloc PD - done, rc = %d\n", rc); |
| 966 | return rc; |
| 967 | } |
| 968 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 969 | static void qed_rdma_free_pd(void *rdma_cxt, u16 pd) |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 970 | { |
| 971 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 972 | |
| 973 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "pd = %08x\n", pd); |
| 974 | |
| 975 | /* Returns a previously allocated protection domain for reuse */ |
| 976 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 977 | qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->pd_map, pd); |
| 978 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 979 | } |
| 980 | |
| 981 | static enum qed_rdma_toggle_bit |
| 982 | qed_rdma_toggle_bit_create_resize_cq(struct qed_hwfn *p_hwfn, u16 icid) |
| 983 | { |
| 984 | struct qed_rdma_info *p_info = p_hwfn->p_rdma_info; |
| 985 | enum qed_rdma_toggle_bit toggle_bit; |
| 986 | u32 bmap_id; |
| 987 | |
| 988 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", icid); |
| 989 | |
| 990 | /* the function toggle the bit that is related to a given icid |
| 991 | * and returns the new toggle bit's value |
| 992 | */ |
| 993 | bmap_id = icid - qed_cxt_get_proto_cid_start(p_hwfn, p_info->proto); |
| 994 | |
| 995 | spin_lock_bh(&p_info->lock); |
| 996 | toggle_bit = !test_and_change_bit(bmap_id, |
| 997 | p_info->toggle_bits.bitmap); |
| 998 | spin_unlock_bh(&p_info->lock); |
| 999 | |
| 1000 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QED_RDMA_TOGGLE_BIT_= %d\n", |
| 1001 | toggle_bit); |
| 1002 | |
| 1003 | return toggle_bit; |
| 1004 | } |
| 1005 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 1006 | static int qed_rdma_create_cq(void *rdma_cxt, |
| 1007 | struct qed_rdma_create_cq_in_params *params, |
| 1008 | u16 *icid) |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 1009 | { |
| 1010 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 1011 | struct qed_rdma_info *p_info = p_hwfn->p_rdma_info; |
| 1012 | struct rdma_create_cq_ramrod_data *p_ramrod; |
| 1013 | enum qed_rdma_toggle_bit toggle_bit; |
| 1014 | struct qed_sp_init_data init_data; |
| 1015 | struct qed_spq_entry *p_ent; |
| 1016 | u32 returned_id, start_cid; |
| 1017 | int rc; |
| 1018 | |
| 1019 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "cq_handle = %08x%08x\n", |
| 1020 | params->cq_handle_hi, params->cq_handle_lo); |
| 1021 | |
| 1022 | /* Allocate icid */ |
| 1023 | spin_lock_bh(&p_info->lock); |
Ram Amrani | e015d58 | 2017-04-30 11:49:08 +0300 | [diff] [blame] | 1024 | rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_info->cq_map, &returned_id); |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 1025 | spin_unlock_bh(&p_info->lock); |
| 1026 | |
| 1027 | if (rc) { |
| 1028 | DP_NOTICE(p_hwfn, "Can't create CQ, rc = %d\n", rc); |
| 1029 | return rc; |
| 1030 | } |
| 1031 | |
| 1032 | start_cid = qed_cxt_get_proto_cid_start(p_hwfn, |
| 1033 | p_info->proto); |
| 1034 | *icid = returned_id + start_cid; |
| 1035 | |
| 1036 | /* Check if icid requires a page allocation */ |
| 1037 | rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, *icid); |
| 1038 | if (rc) |
| 1039 | goto err; |
| 1040 | |
| 1041 | /* Get SPQ entry */ |
| 1042 | memset(&init_data, 0, sizeof(init_data)); |
| 1043 | init_data.cid = *icid; |
| 1044 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1045 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1046 | |
| 1047 | /* Send create CQ ramrod */ |
| 1048 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 1049 | RDMA_RAMROD_CREATE_CQ, |
| 1050 | p_info->proto, &init_data); |
| 1051 | if (rc) |
| 1052 | goto err; |
| 1053 | |
| 1054 | p_ramrod = &p_ent->ramrod.rdma_create_cq; |
| 1055 | |
| 1056 | p_ramrod->cq_handle.hi = cpu_to_le32(params->cq_handle_hi); |
| 1057 | p_ramrod->cq_handle.lo = cpu_to_le32(params->cq_handle_lo); |
| 1058 | p_ramrod->dpi = cpu_to_le16(params->dpi); |
| 1059 | p_ramrod->is_two_level_pbl = params->pbl_two_level; |
| 1060 | p_ramrod->max_cqes = cpu_to_le32(params->cq_size); |
| 1061 | DMA_REGPAIR_LE(p_ramrod->pbl_addr, params->pbl_ptr); |
| 1062 | p_ramrod->pbl_num_pages = cpu_to_le16(params->pbl_num_pages); |
| 1063 | p_ramrod->cnq_id = (u8)RESC_START(p_hwfn, QED_RDMA_CNQ_RAM) + |
| 1064 | params->cnq_id; |
| 1065 | p_ramrod->int_timeout = params->int_timeout; |
| 1066 | |
| 1067 | /* toggle the bit for every resize or create cq for a given icid */ |
| 1068 | toggle_bit = qed_rdma_toggle_bit_create_resize_cq(p_hwfn, *icid); |
| 1069 | |
| 1070 | p_ramrod->toggle_bit = toggle_bit; |
| 1071 | |
| 1072 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 1073 | if (rc) { |
| 1074 | /* restore toggle bit */ |
| 1075 | qed_rdma_toggle_bit_create_resize_cq(p_hwfn, *icid); |
| 1076 | goto err; |
| 1077 | } |
| 1078 | |
| 1079 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Created CQ, rc = %d\n", rc); |
| 1080 | return rc; |
| 1081 | |
| 1082 | err: |
| 1083 | /* release allocated icid */ |
Ram Amrani | 670dde5 | 2017-02-20 22:43:30 +0200 | [diff] [blame] | 1084 | spin_lock_bh(&p_info->lock); |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 1085 | qed_bmap_release_id(p_hwfn, &p_info->cq_map, returned_id); |
Ram Amrani | 670dde5 | 2017-02-20 22:43:30 +0200 | [diff] [blame] | 1086 | spin_unlock_bh(&p_info->lock); |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 1087 | DP_NOTICE(p_hwfn, "Create CQ failed, rc = %d\n", rc); |
| 1088 | |
| 1089 | return rc; |
| 1090 | } |
| 1091 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 1092 | static int |
| 1093 | qed_rdma_destroy_cq(void *rdma_cxt, |
| 1094 | struct qed_rdma_destroy_cq_in_params *in_params, |
| 1095 | struct qed_rdma_destroy_cq_out_params *out_params) |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 1096 | { |
| 1097 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 1098 | struct rdma_destroy_cq_output_params *p_ramrod_res; |
| 1099 | struct rdma_destroy_cq_ramrod_data *p_ramrod; |
| 1100 | struct qed_sp_init_data init_data; |
| 1101 | struct qed_spq_entry *p_ent; |
| 1102 | dma_addr_t ramrod_res_phys; |
| 1103 | int rc = -ENOMEM; |
| 1104 | |
| 1105 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", in_params->icid); |
| 1106 | |
| 1107 | p_ramrod_res = |
| 1108 | (struct rdma_destroy_cq_output_params *) |
| 1109 | dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 1110 | sizeof(struct rdma_destroy_cq_output_params), |
| 1111 | &ramrod_res_phys, GFP_KERNEL); |
| 1112 | if (!p_ramrod_res) { |
| 1113 | DP_NOTICE(p_hwfn, |
| 1114 | "qed destroy cq failed: cannot allocate memory (ramrod)\n"); |
| 1115 | return rc; |
| 1116 | } |
| 1117 | |
| 1118 | /* Get SPQ entry */ |
| 1119 | memset(&init_data, 0, sizeof(init_data)); |
| 1120 | init_data.cid = in_params->icid; |
| 1121 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1122 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1123 | |
| 1124 | /* Send destroy CQ ramrod */ |
| 1125 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 1126 | RDMA_RAMROD_DESTROY_CQ, |
| 1127 | p_hwfn->p_rdma_info->proto, &init_data); |
| 1128 | if (rc) |
| 1129 | goto err; |
| 1130 | |
| 1131 | p_ramrod = &p_ent->ramrod.rdma_destroy_cq; |
| 1132 | DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys); |
| 1133 | |
| 1134 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 1135 | if (rc) |
| 1136 | goto err; |
| 1137 | |
| 1138 | out_params->num_cq_notif = le16_to_cpu(p_ramrod_res->cnq_num); |
| 1139 | |
| 1140 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 1141 | sizeof(struct rdma_destroy_cq_output_params), |
| 1142 | p_ramrod_res, ramrod_res_phys); |
| 1143 | |
| 1144 | /* Free icid */ |
| 1145 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 1146 | |
| 1147 | qed_bmap_release_id(p_hwfn, |
| 1148 | &p_hwfn->p_rdma_info->cq_map, |
| 1149 | (in_params->icid - |
| 1150 | qed_cxt_get_proto_cid_start(p_hwfn, |
| 1151 | p_hwfn-> |
| 1152 | p_rdma_info->proto))); |
| 1153 | |
| 1154 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 1155 | |
| 1156 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Destroyed CQ, rc = %d\n", rc); |
| 1157 | return rc; |
| 1158 | |
| 1159 | err: dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 1160 | sizeof(struct rdma_destroy_cq_output_params), |
| 1161 | p_ramrod_res, ramrod_res_phys); |
| 1162 | |
| 1163 | return rc; |
| 1164 | } |
| 1165 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1166 | static void qed_rdma_set_fw_mac(u16 *p_fw_mac, u8 *p_qed_mac) |
| 1167 | { |
| 1168 | p_fw_mac[0] = cpu_to_le16((p_qed_mac[0] << 8) + p_qed_mac[1]); |
| 1169 | p_fw_mac[1] = cpu_to_le16((p_qed_mac[2] << 8) + p_qed_mac[3]); |
| 1170 | p_fw_mac[2] = cpu_to_le16((p_qed_mac[4] << 8) + p_qed_mac[5]); |
| 1171 | } |
| 1172 | |
| 1173 | static void qed_rdma_copy_gids(struct qed_rdma_qp *qp, __le32 *src_gid, |
| 1174 | __le32 *dst_gid) |
| 1175 | { |
| 1176 | u32 i; |
| 1177 | |
| 1178 | if (qp->roce_mode == ROCE_V2_IPV4) { |
| 1179 | /* The IPv4 addresses shall be aligned to the highest word. |
| 1180 | * The lower words must be zero. |
| 1181 | */ |
| 1182 | memset(src_gid, 0, sizeof(union qed_gid)); |
| 1183 | memset(dst_gid, 0, sizeof(union qed_gid)); |
| 1184 | src_gid[3] = cpu_to_le32(qp->sgid.ipv4_addr); |
| 1185 | dst_gid[3] = cpu_to_le32(qp->dgid.ipv4_addr); |
| 1186 | } else { |
| 1187 | /* GIDs and IPv6 addresses coincide in location and size */ |
| 1188 | for (i = 0; i < ARRAY_SIZE(qp->sgid.dwords); i++) { |
| 1189 | src_gid[i] = cpu_to_le32(qp->sgid.dwords[i]); |
| 1190 | dst_gid[i] = cpu_to_le32(qp->dgid.dwords[i]); |
| 1191 | } |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | static enum roce_flavor qed_roce_mode_to_flavor(enum roce_mode roce_mode) |
| 1196 | { |
| 1197 | enum roce_flavor flavor; |
| 1198 | |
| 1199 | switch (roce_mode) { |
| 1200 | case ROCE_V1: |
| 1201 | flavor = PLAIN_ROCE; |
| 1202 | break; |
| 1203 | case ROCE_V2_IPV4: |
| 1204 | flavor = RROCE_IPV4; |
| 1205 | break; |
| 1206 | case ROCE_V2_IPV6: |
| 1207 | flavor = ROCE_V2_IPV6; |
| 1208 | break; |
| 1209 | default: |
| 1210 | flavor = MAX_ROCE_MODE; |
| 1211 | break; |
| 1212 | } |
| 1213 | return flavor; |
| 1214 | } |
| 1215 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1216 | void qed_roce_free_cid_pair(struct qed_hwfn *p_hwfn, u16 cid) |
| 1217 | { |
| 1218 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 1219 | qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid); |
| 1220 | qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid + 1); |
| 1221 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 1222 | } |
| 1223 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 1224 | static int qed_roce_alloc_cid(struct qed_hwfn *p_hwfn, u16 *cid) |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1225 | { |
| 1226 | struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info; |
| 1227 | u32 responder_icid; |
| 1228 | u32 requester_icid; |
| 1229 | int rc; |
| 1230 | |
| 1231 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 1232 | rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_rdma_info->cid_map, |
| 1233 | &responder_icid); |
| 1234 | if (rc) { |
| 1235 | spin_unlock_bh(&p_rdma_info->lock); |
| 1236 | return rc; |
| 1237 | } |
| 1238 | |
| 1239 | rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_rdma_info->cid_map, |
| 1240 | &requester_icid); |
| 1241 | |
| 1242 | spin_unlock_bh(&p_rdma_info->lock); |
| 1243 | if (rc) |
| 1244 | goto err; |
| 1245 | |
| 1246 | /* the two icid's should be adjacent */ |
| 1247 | if ((requester_icid - responder_icid) != 1) { |
| 1248 | DP_NOTICE(p_hwfn, "Failed to allocate two adjacent qp's'\n"); |
| 1249 | rc = -EINVAL; |
| 1250 | goto err; |
| 1251 | } |
| 1252 | |
| 1253 | responder_icid += qed_cxt_get_proto_cid_start(p_hwfn, |
| 1254 | p_rdma_info->proto); |
| 1255 | requester_icid += qed_cxt_get_proto_cid_start(p_hwfn, |
| 1256 | p_rdma_info->proto); |
| 1257 | |
| 1258 | /* If these icids require a new ILT line allocate DMA-able context for |
| 1259 | * an ILT page |
| 1260 | */ |
| 1261 | rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, responder_icid); |
| 1262 | if (rc) |
| 1263 | goto err; |
| 1264 | |
| 1265 | rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, requester_icid); |
| 1266 | if (rc) |
| 1267 | goto err; |
| 1268 | |
| 1269 | *cid = (u16)responder_icid; |
| 1270 | return rc; |
| 1271 | |
| 1272 | err: |
| 1273 | spin_lock_bh(&p_rdma_info->lock); |
| 1274 | qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, responder_icid); |
| 1275 | qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, requester_icid); |
| 1276 | |
| 1277 | spin_unlock_bh(&p_rdma_info->lock); |
| 1278 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 1279 | "Allocate CID - failed, rc = %d\n", rc); |
| 1280 | return rc; |
| 1281 | } |
| 1282 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1283 | static void qed_roce_set_real_cid(struct qed_hwfn *p_hwfn, u32 cid) |
| 1284 | { |
| 1285 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 1286 | qed_bmap_set_id(p_hwfn, &p_hwfn->p_rdma_info->real_cid_map, cid); |
| 1287 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 1288 | } |
| 1289 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1290 | static int qed_roce_sp_create_responder(struct qed_hwfn *p_hwfn, |
| 1291 | struct qed_rdma_qp *qp) |
| 1292 | { |
| 1293 | struct roce_create_qp_resp_ramrod_data *p_ramrod; |
| 1294 | struct qed_sp_init_data init_data; |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1295 | enum roce_flavor roce_flavor; |
| 1296 | struct qed_spq_entry *p_ent; |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1297 | u16 regular_latency_queue; |
| 1298 | enum protocol_type proto; |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1299 | int rc; |
| 1300 | |
| 1301 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid); |
| 1302 | |
| 1303 | /* Allocate DMA-able memory for IRQ */ |
| 1304 | qp->irq_num_pages = 1; |
| 1305 | qp->irq = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 1306 | RDMA_RING_PAGE_SIZE, |
| 1307 | &qp->irq_phys_addr, GFP_KERNEL); |
| 1308 | if (!qp->irq) { |
| 1309 | rc = -ENOMEM; |
| 1310 | DP_NOTICE(p_hwfn, |
| 1311 | "qed create responder failed: cannot allocate memory (irq). rc = %d\n", |
| 1312 | rc); |
| 1313 | return rc; |
| 1314 | } |
| 1315 | |
| 1316 | /* Get SPQ entry */ |
| 1317 | memset(&init_data, 0, sizeof(init_data)); |
| 1318 | init_data.cid = qp->icid; |
| 1319 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1320 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1321 | |
| 1322 | rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_CREATE_QP, |
| 1323 | PROTOCOLID_ROCE, &init_data); |
| 1324 | if (rc) |
| 1325 | goto err; |
| 1326 | |
| 1327 | p_ramrod = &p_ent->ramrod.roce_create_qp_resp; |
| 1328 | |
| 1329 | p_ramrod->flags = 0; |
| 1330 | |
| 1331 | roce_flavor = qed_roce_mode_to_flavor(qp->roce_mode); |
| 1332 | SET_FIELD(p_ramrod->flags, |
| 1333 | ROCE_CREATE_QP_RESP_RAMROD_DATA_ROCE_FLAVOR, roce_flavor); |
| 1334 | |
| 1335 | SET_FIELD(p_ramrod->flags, |
| 1336 | ROCE_CREATE_QP_RESP_RAMROD_DATA_RDMA_RD_EN, |
| 1337 | qp->incoming_rdma_read_en); |
| 1338 | |
| 1339 | SET_FIELD(p_ramrod->flags, |
| 1340 | ROCE_CREATE_QP_RESP_RAMROD_DATA_RDMA_WR_EN, |
| 1341 | qp->incoming_rdma_write_en); |
| 1342 | |
| 1343 | SET_FIELD(p_ramrod->flags, |
| 1344 | ROCE_CREATE_QP_RESP_RAMROD_DATA_ATOMIC_EN, |
| 1345 | qp->incoming_atomic_en); |
| 1346 | |
| 1347 | SET_FIELD(p_ramrod->flags, |
| 1348 | ROCE_CREATE_QP_RESP_RAMROD_DATA_E2E_FLOW_CONTROL_EN, |
| 1349 | qp->e2e_flow_control_en); |
| 1350 | |
| 1351 | SET_FIELD(p_ramrod->flags, |
| 1352 | ROCE_CREATE_QP_RESP_RAMROD_DATA_SRQ_FLG, qp->use_srq); |
| 1353 | |
| 1354 | SET_FIELD(p_ramrod->flags, |
| 1355 | ROCE_CREATE_QP_RESP_RAMROD_DATA_RESERVED_KEY_EN, |
| 1356 | qp->fmr_and_reserved_lkey); |
| 1357 | |
| 1358 | SET_FIELD(p_ramrod->flags, |
| 1359 | ROCE_CREATE_QP_RESP_RAMROD_DATA_MIN_RNR_NAK_TIMER, |
| 1360 | qp->min_rnr_nak_timer); |
| 1361 | |
| 1362 | p_ramrod->max_ird = qp->max_rd_atomic_resp; |
| 1363 | p_ramrod->traffic_class = qp->traffic_class_tos; |
| 1364 | p_ramrod->hop_limit = qp->hop_limit_ttl; |
| 1365 | p_ramrod->irq_num_pages = qp->irq_num_pages; |
| 1366 | p_ramrod->p_key = cpu_to_le16(qp->pkey); |
| 1367 | p_ramrod->flow_label = cpu_to_le32(qp->flow_label); |
| 1368 | p_ramrod->dst_qp_id = cpu_to_le32(qp->dest_qp); |
| 1369 | p_ramrod->mtu = cpu_to_le16(qp->mtu); |
| 1370 | p_ramrod->initial_psn = cpu_to_le32(qp->rq_psn); |
| 1371 | p_ramrod->pd = cpu_to_le16(qp->pd); |
| 1372 | p_ramrod->rq_num_pages = cpu_to_le16(qp->rq_num_pages); |
| 1373 | DMA_REGPAIR_LE(p_ramrod->rq_pbl_addr, qp->rq_pbl_ptr); |
| 1374 | DMA_REGPAIR_LE(p_ramrod->irq_pbl_addr, qp->irq_phys_addr); |
| 1375 | qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid); |
| 1376 | p_ramrod->qp_handle_for_async.hi = cpu_to_le32(qp->qp_handle_async.hi); |
| 1377 | p_ramrod->qp_handle_for_async.lo = cpu_to_le32(qp->qp_handle_async.lo); |
| 1378 | p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi); |
| 1379 | p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo); |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1380 | p_ramrod->cq_cid = cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | |
| 1381 | qp->rq_cq_id); |
| 1382 | |
Ariel Elior | b5a9ee7 | 2017-04-03 12:21:09 +0300 | [diff] [blame] | 1383 | regular_latency_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD); |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1384 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1385 | p_ramrod->regular_latency_phy_queue = |
| 1386 | cpu_to_le16(regular_latency_queue); |
| 1387 | p_ramrod->low_latency_phy_queue = |
| 1388 | cpu_to_le16(regular_latency_queue); |
| 1389 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1390 | p_ramrod->dpi = cpu_to_le16(qp->dpi); |
| 1391 | |
| 1392 | qed_rdma_set_fw_mac(p_ramrod->remote_mac_addr, qp->remote_mac_addr); |
| 1393 | qed_rdma_set_fw_mac(p_ramrod->local_mac_addr, qp->local_mac_addr); |
| 1394 | |
| 1395 | p_ramrod->udp_src_port = qp->udp_src_port; |
| 1396 | p_ramrod->vlan_id = cpu_to_le16(qp->vlan_id); |
| 1397 | p_ramrod->srq_id.srq_idx = cpu_to_le16(qp->srq_id); |
| 1398 | p_ramrod->srq_id.opaque_fid = cpu_to_le16(p_hwfn->hw_info.opaque_fid); |
| 1399 | |
| 1400 | p_ramrod->stats_counter_id = RESC_START(p_hwfn, QED_RDMA_STATS_QUEUE) + |
| 1401 | qp->stats_queue; |
| 1402 | |
| 1403 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 1404 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1405 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 1406 | "rc = %d regular physical queue = 0x%x\n", rc, |
| 1407 | regular_latency_queue); |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1408 | |
| 1409 | if (rc) |
| 1410 | goto err; |
| 1411 | |
| 1412 | qp->resp_offloaded = true; |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1413 | qp->cq_prod = 0; |
| 1414 | |
| 1415 | proto = p_hwfn->p_rdma_info->proto; |
| 1416 | qed_roce_set_real_cid(p_hwfn, qp->icid - |
| 1417 | qed_cxt_get_proto_cid_start(p_hwfn, proto)); |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1418 | |
| 1419 | return rc; |
| 1420 | |
| 1421 | err: |
| 1422 | DP_NOTICE(p_hwfn, "create responder - failed, rc = %d\n", rc); |
| 1423 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 1424 | qp->irq_num_pages * RDMA_RING_PAGE_SIZE, |
| 1425 | qp->irq, qp->irq_phys_addr); |
| 1426 | |
| 1427 | return rc; |
| 1428 | } |
| 1429 | |
| 1430 | static int qed_roce_sp_create_requester(struct qed_hwfn *p_hwfn, |
| 1431 | struct qed_rdma_qp *qp) |
| 1432 | { |
| 1433 | struct roce_create_qp_req_ramrod_data *p_ramrod; |
| 1434 | struct qed_sp_init_data init_data; |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1435 | enum roce_flavor roce_flavor; |
| 1436 | struct qed_spq_entry *p_ent; |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1437 | u16 regular_latency_queue; |
| 1438 | enum protocol_type proto; |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1439 | int rc; |
| 1440 | |
| 1441 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid); |
| 1442 | |
| 1443 | /* Allocate DMA-able memory for ORQ */ |
| 1444 | qp->orq_num_pages = 1; |
| 1445 | qp->orq = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 1446 | RDMA_RING_PAGE_SIZE, |
| 1447 | &qp->orq_phys_addr, GFP_KERNEL); |
| 1448 | if (!qp->orq) { |
| 1449 | rc = -ENOMEM; |
| 1450 | DP_NOTICE(p_hwfn, |
| 1451 | "qed create requester failed: cannot allocate memory (orq). rc = %d\n", |
| 1452 | rc); |
| 1453 | return rc; |
| 1454 | } |
| 1455 | |
| 1456 | /* Get SPQ entry */ |
| 1457 | memset(&init_data, 0, sizeof(init_data)); |
| 1458 | init_data.cid = qp->icid + 1; |
| 1459 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1460 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1461 | |
| 1462 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 1463 | ROCE_RAMROD_CREATE_QP, |
| 1464 | PROTOCOLID_ROCE, &init_data); |
| 1465 | if (rc) |
| 1466 | goto err; |
| 1467 | |
| 1468 | p_ramrod = &p_ent->ramrod.roce_create_qp_req; |
| 1469 | |
| 1470 | p_ramrod->flags = 0; |
| 1471 | |
| 1472 | roce_flavor = qed_roce_mode_to_flavor(qp->roce_mode); |
| 1473 | SET_FIELD(p_ramrod->flags, |
| 1474 | ROCE_CREATE_QP_REQ_RAMROD_DATA_ROCE_FLAVOR, roce_flavor); |
| 1475 | |
| 1476 | SET_FIELD(p_ramrod->flags, |
| 1477 | ROCE_CREATE_QP_REQ_RAMROD_DATA_FMR_AND_RESERVED_EN, |
| 1478 | qp->fmr_and_reserved_lkey); |
| 1479 | |
| 1480 | SET_FIELD(p_ramrod->flags, |
| 1481 | ROCE_CREATE_QP_REQ_RAMROD_DATA_SIGNALED_COMP, qp->signal_all); |
| 1482 | |
| 1483 | SET_FIELD(p_ramrod->flags, |
| 1484 | ROCE_CREATE_QP_REQ_RAMROD_DATA_ERR_RETRY_CNT, qp->retry_cnt); |
| 1485 | |
| 1486 | SET_FIELD(p_ramrod->flags, |
| 1487 | ROCE_CREATE_QP_REQ_RAMROD_DATA_RNR_NAK_CNT, |
| 1488 | qp->rnr_retry_cnt); |
| 1489 | |
| 1490 | p_ramrod->max_ord = qp->max_rd_atomic_req; |
| 1491 | p_ramrod->traffic_class = qp->traffic_class_tos; |
| 1492 | p_ramrod->hop_limit = qp->hop_limit_ttl; |
| 1493 | p_ramrod->orq_num_pages = qp->orq_num_pages; |
| 1494 | p_ramrod->p_key = cpu_to_le16(qp->pkey); |
| 1495 | p_ramrod->flow_label = cpu_to_le32(qp->flow_label); |
| 1496 | p_ramrod->dst_qp_id = cpu_to_le32(qp->dest_qp); |
| 1497 | p_ramrod->ack_timeout_val = cpu_to_le32(qp->ack_timeout); |
| 1498 | p_ramrod->mtu = cpu_to_le16(qp->mtu); |
| 1499 | p_ramrod->initial_psn = cpu_to_le32(qp->sq_psn); |
| 1500 | p_ramrod->pd = cpu_to_le16(qp->pd); |
| 1501 | p_ramrod->sq_num_pages = cpu_to_le16(qp->sq_num_pages); |
| 1502 | DMA_REGPAIR_LE(p_ramrod->sq_pbl_addr, qp->sq_pbl_ptr); |
| 1503 | DMA_REGPAIR_LE(p_ramrod->orq_pbl_addr, qp->orq_phys_addr); |
| 1504 | qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid); |
| 1505 | p_ramrod->qp_handle_for_async.hi = cpu_to_le32(qp->qp_handle_async.hi); |
| 1506 | p_ramrod->qp_handle_for_async.lo = cpu_to_le32(qp->qp_handle_async.lo); |
| 1507 | p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi); |
| 1508 | p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo); |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1509 | p_ramrod->cq_cid = |
| 1510 | cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->sq_cq_id); |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1511 | |
Ariel Elior | b5a9ee7 | 2017-04-03 12:21:09 +0300 | [diff] [blame] | 1512 | regular_latency_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD); |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1513 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1514 | p_ramrod->regular_latency_phy_queue = |
| 1515 | cpu_to_le16(regular_latency_queue); |
| 1516 | p_ramrod->low_latency_phy_queue = |
| 1517 | cpu_to_le16(regular_latency_queue); |
| 1518 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1519 | p_ramrod->dpi = cpu_to_le16(qp->dpi); |
| 1520 | |
| 1521 | qed_rdma_set_fw_mac(p_ramrod->remote_mac_addr, qp->remote_mac_addr); |
| 1522 | qed_rdma_set_fw_mac(p_ramrod->local_mac_addr, qp->local_mac_addr); |
| 1523 | |
| 1524 | p_ramrod->udp_src_port = qp->udp_src_port; |
| 1525 | p_ramrod->vlan_id = cpu_to_le16(qp->vlan_id); |
| 1526 | p_ramrod->stats_counter_id = RESC_START(p_hwfn, QED_RDMA_STATS_QUEUE) + |
| 1527 | qp->stats_queue; |
| 1528 | |
| 1529 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 1530 | |
| 1531 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc); |
| 1532 | |
| 1533 | if (rc) |
| 1534 | goto err; |
| 1535 | |
| 1536 | qp->req_offloaded = true; |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1537 | proto = p_hwfn->p_rdma_info->proto; |
| 1538 | qed_roce_set_real_cid(p_hwfn, |
| 1539 | qp->icid + 1 - |
| 1540 | qed_cxt_get_proto_cid_start(p_hwfn, proto)); |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1541 | |
| 1542 | return rc; |
| 1543 | |
| 1544 | err: |
| 1545 | DP_NOTICE(p_hwfn, "Create requested - failed, rc = %d\n", rc); |
| 1546 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 1547 | qp->orq_num_pages * RDMA_RING_PAGE_SIZE, |
| 1548 | qp->orq, qp->orq_phys_addr); |
| 1549 | return rc; |
| 1550 | } |
| 1551 | |
| 1552 | static int qed_roce_sp_modify_responder(struct qed_hwfn *p_hwfn, |
| 1553 | struct qed_rdma_qp *qp, |
| 1554 | bool move_to_err, u32 modify_flags) |
| 1555 | { |
| 1556 | struct roce_modify_qp_resp_ramrod_data *p_ramrod; |
| 1557 | struct qed_sp_init_data init_data; |
| 1558 | struct qed_spq_entry *p_ent; |
| 1559 | int rc; |
| 1560 | |
| 1561 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid); |
| 1562 | |
| 1563 | if (move_to_err && !qp->resp_offloaded) |
| 1564 | return 0; |
| 1565 | |
| 1566 | /* Get SPQ entry */ |
| 1567 | memset(&init_data, 0, sizeof(init_data)); |
| 1568 | init_data.cid = qp->icid; |
| 1569 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1570 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1571 | |
| 1572 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 1573 | ROCE_EVENT_MODIFY_QP, |
| 1574 | PROTOCOLID_ROCE, &init_data); |
| 1575 | if (rc) { |
| 1576 | DP_NOTICE(p_hwfn, "rc = %d\n", rc); |
| 1577 | return rc; |
| 1578 | } |
| 1579 | |
| 1580 | p_ramrod = &p_ent->ramrod.roce_modify_qp_resp; |
| 1581 | |
| 1582 | p_ramrod->flags = 0; |
| 1583 | |
| 1584 | SET_FIELD(p_ramrod->flags, |
| 1585 | ROCE_MODIFY_QP_RESP_RAMROD_DATA_MOVE_TO_ERR_FLG, move_to_err); |
| 1586 | |
| 1587 | SET_FIELD(p_ramrod->flags, |
| 1588 | ROCE_MODIFY_QP_RESP_RAMROD_DATA_RDMA_RD_EN, |
| 1589 | qp->incoming_rdma_read_en); |
| 1590 | |
| 1591 | SET_FIELD(p_ramrod->flags, |
| 1592 | ROCE_MODIFY_QP_RESP_RAMROD_DATA_RDMA_WR_EN, |
| 1593 | qp->incoming_rdma_write_en); |
| 1594 | |
| 1595 | SET_FIELD(p_ramrod->flags, |
| 1596 | ROCE_MODIFY_QP_RESP_RAMROD_DATA_ATOMIC_EN, |
| 1597 | qp->incoming_atomic_en); |
| 1598 | |
| 1599 | SET_FIELD(p_ramrod->flags, |
| 1600 | ROCE_CREATE_QP_RESP_RAMROD_DATA_E2E_FLOW_CONTROL_EN, |
| 1601 | qp->e2e_flow_control_en); |
| 1602 | |
| 1603 | SET_FIELD(p_ramrod->flags, |
| 1604 | ROCE_MODIFY_QP_RESP_RAMROD_DATA_RDMA_OPS_EN_FLG, |
| 1605 | GET_FIELD(modify_flags, |
| 1606 | QED_RDMA_MODIFY_QP_VALID_RDMA_OPS_EN)); |
| 1607 | |
| 1608 | SET_FIELD(p_ramrod->flags, |
| 1609 | ROCE_MODIFY_QP_RESP_RAMROD_DATA_P_KEY_FLG, |
| 1610 | GET_FIELD(modify_flags, QED_ROCE_MODIFY_QP_VALID_PKEY)); |
| 1611 | |
| 1612 | SET_FIELD(p_ramrod->flags, |
| 1613 | ROCE_MODIFY_QP_RESP_RAMROD_DATA_ADDRESS_VECTOR_FLG, |
| 1614 | GET_FIELD(modify_flags, |
| 1615 | QED_ROCE_MODIFY_QP_VALID_ADDRESS_VECTOR)); |
| 1616 | |
| 1617 | SET_FIELD(p_ramrod->flags, |
| 1618 | ROCE_MODIFY_QP_RESP_RAMROD_DATA_MAX_IRD_FLG, |
| 1619 | GET_FIELD(modify_flags, |
| 1620 | QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_RESP)); |
| 1621 | |
| 1622 | SET_FIELD(p_ramrod->flags, |
| 1623 | ROCE_MODIFY_QP_RESP_RAMROD_DATA_MIN_RNR_NAK_TIMER_FLG, |
| 1624 | GET_FIELD(modify_flags, |
| 1625 | QED_ROCE_MODIFY_QP_VALID_MIN_RNR_NAK_TIMER)); |
| 1626 | |
| 1627 | p_ramrod->fields = 0; |
| 1628 | SET_FIELD(p_ramrod->fields, |
| 1629 | ROCE_MODIFY_QP_RESP_RAMROD_DATA_MIN_RNR_NAK_TIMER, |
| 1630 | qp->min_rnr_nak_timer); |
| 1631 | |
| 1632 | p_ramrod->max_ird = qp->max_rd_atomic_resp; |
| 1633 | p_ramrod->traffic_class = qp->traffic_class_tos; |
| 1634 | p_ramrod->hop_limit = qp->hop_limit_ttl; |
| 1635 | p_ramrod->p_key = cpu_to_le16(qp->pkey); |
| 1636 | p_ramrod->flow_label = cpu_to_le32(qp->flow_label); |
| 1637 | p_ramrod->mtu = cpu_to_le16(qp->mtu); |
| 1638 | qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid); |
| 1639 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 1640 | |
| 1641 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Modify responder, rc = %d\n", rc); |
| 1642 | return rc; |
| 1643 | } |
| 1644 | |
| 1645 | static int qed_roce_sp_modify_requester(struct qed_hwfn *p_hwfn, |
| 1646 | struct qed_rdma_qp *qp, |
| 1647 | bool move_to_sqd, |
| 1648 | bool move_to_err, u32 modify_flags) |
| 1649 | { |
| 1650 | struct roce_modify_qp_req_ramrod_data *p_ramrod; |
| 1651 | struct qed_sp_init_data init_data; |
| 1652 | struct qed_spq_entry *p_ent; |
| 1653 | int rc; |
| 1654 | |
| 1655 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid); |
| 1656 | |
| 1657 | if (move_to_err && !(qp->req_offloaded)) |
| 1658 | return 0; |
| 1659 | |
| 1660 | /* Get SPQ entry */ |
| 1661 | memset(&init_data, 0, sizeof(init_data)); |
| 1662 | init_data.cid = qp->icid + 1; |
| 1663 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1664 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1665 | |
| 1666 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 1667 | ROCE_EVENT_MODIFY_QP, |
| 1668 | PROTOCOLID_ROCE, &init_data); |
| 1669 | if (rc) { |
| 1670 | DP_NOTICE(p_hwfn, "rc = %d\n", rc); |
| 1671 | return rc; |
| 1672 | } |
| 1673 | |
| 1674 | p_ramrod = &p_ent->ramrod.roce_modify_qp_req; |
| 1675 | |
| 1676 | p_ramrod->flags = 0; |
| 1677 | |
| 1678 | SET_FIELD(p_ramrod->flags, |
| 1679 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_MOVE_TO_ERR_FLG, move_to_err); |
| 1680 | |
| 1681 | SET_FIELD(p_ramrod->flags, |
| 1682 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_MOVE_TO_SQD_FLG, move_to_sqd); |
| 1683 | |
| 1684 | SET_FIELD(p_ramrod->flags, |
| 1685 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_EN_SQD_ASYNC_NOTIFY, |
| 1686 | qp->sqd_async); |
| 1687 | |
| 1688 | SET_FIELD(p_ramrod->flags, |
| 1689 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_P_KEY_FLG, |
| 1690 | GET_FIELD(modify_flags, QED_ROCE_MODIFY_QP_VALID_PKEY)); |
| 1691 | |
| 1692 | SET_FIELD(p_ramrod->flags, |
| 1693 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_ADDRESS_VECTOR_FLG, |
| 1694 | GET_FIELD(modify_flags, |
| 1695 | QED_ROCE_MODIFY_QP_VALID_ADDRESS_VECTOR)); |
| 1696 | |
| 1697 | SET_FIELD(p_ramrod->flags, |
| 1698 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_MAX_ORD_FLG, |
| 1699 | GET_FIELD(modify_flags, |
| 1700 | QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_REQ)); |
| 1701 | |
| 1702 | SET_FIELD(p_ramrod->flags, |
| 1703 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_RNR_NAK_CNT_FLG, |
| 1704 | GET_FIELD(modify_flags, |
| 1705 | QED_ROCE_MODIFY_QP_VALID_RNR_RETRY_CNT)); |
| 1706 | |
| 1707 | SET_FIELD(p_ramrod->flags, |
| 1708 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_ERR_RETRY_CNT_FLG, |
| 1709 | GET_FIELD(modify_flags, QED_ROCE_MODIFY_QP_VALID_RETRY_CNT)); |
| 1710 | |
| 1711 | SET_FIELD(p_ramrod->flags, |
| 1712 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_ACK_TIMEOUT_FLG, |
| 1713 | GET_FIELD(modify_flags, |
| 1714 | QED_ROCE_MODIFY_QP_VALID_ACK_TIMEOUT)); |
| 1715 | |
| 1716 | p_ramrod->fields = 0; |
| 1717 | SET_FIELD(p_ramrod->fields, |
| 1718 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_ERR_RETRY_CNT, qp->retry_cnt); |
| 1719 | |
| 1720 | SET_FIELD(p_ramrod->fields, |
| 1721 | ROCE_MODIFY_QP_REQ_RAMROD_DATA_RNR_NAK_CNT, |
| 1722 | qp->rnr_retry_cnt); |
| 1723 | |
| 1724 | p_ramrod->max_ord = qp->max_rd_atomic_req; |
| 1725 | p_ramrod->traffic_class = qp->traffic_class_tos; |
| 1726 | p_ramrod->hop_limit = qp->hop_limit_ttl; |
| 1727 | p_ramrod->p_key = cpu_to_le16(qp->pkey); |
| 1728 | p_ramrod->flow_label = cpu_to_le32(qp->flow_label); |
| 1729 | p_ramrod->ack_timeout_val = cpu_to_le32(qp->ack_timeout); |
| 1730 | p_ramrod->mtu = cpu_to_le16(qp->mtu); |
| 1731 | qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid); |
| 1732 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 1733 | |
| 1734 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Modify requester, rc = %d\n", rc); |
| 1735 | return rc; |
| 1736 | } |
| 1737 | |
| 1738 | static int qed_roce_sp_destroy_qp_responder(struct qed_hwfn *p_hwfn, |
| 1739 | struct qed_rdma_qp *qp, |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1740 | u32 *num_invalidated_mw, |
| 1741 | u32 *cq_prod) |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1742 | { |
| 1743 | struct roce_destroy_qp_resp_output_params *p_ramrod_res; |
| 1744 | struct roce_destroy_qp_resp_ramrod_data *p_ramrod; |
| 1745 | struct qed_sp_init_data init_data; |
| 1746 | struct qed_spq_entry *p_ent; |
| 1747 | dma_addr_t ramrod_res_phys; |
| 1748 | int rc; |
| 1749 | |
| 1750 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid); |
| 1751 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1752 | *num_invalidated_mw = 0; |
| 1753 | *cq_prod = qp->cq_prod; |
| 1754 | |
| 1755 | if (!qp->resp_offloaded) { |
| 1756 | /* If a responder was never offload, we need to free the cids |
| 1757 | * allocated in create_qp as a FW async event will never arrive |
| 1758 | */ |
| 1759 | u32 cid; |
| 1760 | |
| 1761 | cid = qp->icid - |
| 1762 | qed_cxt_get_proto_cid_start(p_hwfn, |
| 1763 | p_hwfn->p_rdma_info->proto); |
| 1764 | qed_roce_free_cid_pair(p_hwfn, (u16)cid); |
| 1765 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1766 | return 0; |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1767 | } |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1768 | |
| 1769 | /* Get SPQ entry */ |
| 1770 | memset(&init_data, 0, sizeof(init_data)); |
| 1771 | init_data.cid = qp->icid; |
| 1772 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1773 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1774 | |
| 1775 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 1776 | ROCE_RAMROD_DESTROY_QP, |
| 1777 | PROTOCOLID_ROCE, &init_data); |
| 1778 | if (rc) |
| 1779 | return rc; |
| 1780 | |
| 1781 | p_ramrod = &p_ent->ramrod.roce_destroy_qp_resp; |
| 1782 | |
| 1783 | p_ramrod_res = (struct roce_destroy_qp_resp_output_params *) |
| 1784 | dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_ramrod_res), |
| 1785 | &ramrod_res_phys, GFP_KERNEL); |
| 1786 | |
| 1787 | if (!p_ramrod_res) { |
| 1788 | rc = -ENOMEM; |
| 1789 | DP_NOTICE(p_hwfn, |
| 1790 | "qed destroy responder failed: cannot allocate memory (ramrod). rc = %d\n", |
| 1791 | rc); |
| 1792 | return rc; |
| 1793 | } |
| 1794 | |
| 1795 | DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys); |
| 1796 | |
| 1797 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 1798 | if (rc) |
| 1799 | goto err; |
| 1800 | |
| 1801 | *num_invalidated_mw = le32_to_cpu(p_ramrod_res->num_invalidated_mw); |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 1802 | *cq_prod = le32_to_cpu(p_ramrod_res->cq_prod); |
| 1803 | qp->cq_prod = *cq_prod; |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1804 | |
| 1805 | /* Free IRQ - only if ramrod succeeded, in case FW is still using it */ |
| 1806 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 1807 | qp->irq_num_pages * RDMA_RING_PAGE_SIZE, |
| 1808 | qp->irq, qp->irq_phys_addr); |
| 1809 | |
| 1810 | qp->resp_offloaded = false; |
| 1811 | |
| 1812 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Destroy responder, rc = %d\n", rc); |
| 1813 | |
| 1814 | err: |
| 1815 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 1816 | sizeof(struct roce_destroy_qp_resp_output_params), |
| 1817 | p_ramrod_res, ramrod_res_phys); |
| 1818 | |
| 1819 | return rc; |
| 1820 | } |
| 1821 | |
| 1822 | static int qed_roce_sp_destroy_qp_requester(struct qed_hwfn *p_hwfn, |
| 1823 | struct qed_rdma_qp *qp, |
| 1824 | u32 *num_bound_mw) |
| 1825 | { |
| 1826 | struct roce_destroy_qp_req_output_params *p_ramrod_res; |
| 1827 | struct roce_destroy_qp_req_ramrod_data *p_ramrod; |
| 1828 | struct qed_sp_init_data init_data; |
| 1829 | struct qed_spq_entry *p_ent; |
| 1830 | dma_addr_t ramrod_res_phys; |
| 1831 | int rc = -ENOMEM; |
| 1832 | |
| 1833 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid); |
| 1834 | |
| 1835 | if (!qp->req_offloaded) |
| 1836 | return 0; |
| 1837 | |
| 1838 | p_ramrod_res = (struct roce_destroy_qp_req_output_params *) |
| 1839 | dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 1840 | sizeof(*p_ramrod_res), |
| 1841 | &ramrod_res_phys, GFP_KERNEL); |
| 1842 | if (!p_ramrod_res) { |
| 1843 | DP_NOTICE(p_hwfn, |
| 1844 | "qed destroy requester failed: cannot allocate memory (ramrod)\n"); |
| 1845 | return rc; |
| 1846 | } |
| 1847 | |
| 1848 | /* Get SPQ entry */ |
| 1849 | memset(&init_data, 0, sizeof(init_data)); |
| 1850 | init_data.cid = qp->icid + 1; |
| 1851 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1852 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1853 | |
| 1854 | rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_DESTROY_QP, |
| 1855 | PROTOCOLID_ROCE, &init_data); |
| 1856 | if (rc) |
| 1857 | goto err; |
| 1858 | |
| 1859 | p_ramrod = &p_ent->ramrod.roce_destroy_qp_req; |
| 1860 | DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys); |
| 1861 | |
| 1862 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 1863 | if (rc) |
| 1864 | goto err; |
| 1865 | |
| 1866 | *num_bound_mw = le32_to_cpu(p_ramrod_res->num_bound_mw); |
| 1867 | |
| 1868 | /* Free ORQ - only if ramrod succeeded, in case FW is still using it */ |
| 1869 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, |
| 1870 | qp->orq_num_pages * RDMA_RING_PAGE_SIZE, |
| 1871 | qp->orq, qp->orq_phys_addr); |
| 1872 | |
| 1873 | qp->req_offloaded = false; |
| 1874 | |
| 1875 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Destroy requester, rc = %d\n", rc); |
| 1876 | |
| 1877 | err: |
| 1878 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_ramrod_res), |
| 1879 | p_ramrod_res, ramrod_res_phys); |
| 1880 | |
| 1881 | return rc; |
| 1882 | } |
| 1883 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 1884 | static int qed_roce_query_qp(struct qed_hwfn *p_hwfn, |
| 1885 | struct qed_rdma_qp *qp, |
| 1886 | struct qed_rdma_query_qp_out_params *out_params) |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1887 | { |
| 1888 | struct roce_query_qp_resp_output_params *p_resp_ramrod_res; |
| 1889 | struct roce_query_qp_req_output_params *p_req_ramrod_res; |
| 1890 | struct roce_query_qp_resp_ramrod_data *p_resp_ramrod; |
| 1891 | struct roce_query_qp_req_ramrod_data *p_req_ramrod; |
| 1892 | struct qed_sp_init_data init_data; |
| 1893 | dma_addr_t resp_ramrod_res_phys; |
| 1894 | dma_addr_t req_ramrod_res_phys; |
| 1895 | struct qed_spq_entry *p_ent; |
| 1896 | bool rq_err_state; |
| 1897 | bool sq_err_state; |
| 1898 | bool sq_draining; |
| 1899 | int rc = -ENOMEM; |
| 1900 | |
| 1901 | if ((!(qp->resp_offloaded)) && (!(qp->req_offloaded))) { |
| 1902 | /* We can't send ramrod to the fw since this qp wasn't offloaded |
| 1903 | * to the fw yet |
| 1904 | */ |
| 1905 | out_params->draining = false; |
| 1906 | out_params->rq_psn = qp->rq_psn; |
| 1907 | out_params->sq_psn = qp->sq_psn; |
| 1908 | out_params->state = qp->cur_state; |
| 1909 | |
| 1910 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "No QPs as no offload\n"); |
| 1911 | return 0; |
| 1912 | } |
| 1913 | |
| 1914 | if (!(qp->resp_offloaded)) { |
| 1915 | DP_NOTICE(p_hwfn, |
| 1916 | "The responder's qp should be offloded before requester's\n"); |
| 1917 | return -EINVAL; |
| 1918 | } |
| 1919 | |
| 1920 | /* Send a query responder ramrod to FW to get RQ-PSN and state */ |
| 1921 | p_resp_ramrod_res = (struct roce_query_qp_resp_output_params *) |
| 1922 | dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 1923 | sizeof(*p_resp_ramrod_res), |
| 1924 | &resp_ramrod_res_phys, GFP_KERNEL); |
| 1925 | if (!p_resp_ramrod_res) { |
| 1926 | DP_NOTICE(p_hwfn, |
| 1927 | "qed query qp failed: cannot allocate memory (ramrod)\n"); |
| 1928 | return rc; |
| 1929 | } |
| 1930 | |
| 1931 | /* Get SPQ entry */ |
| 1932 | memset(&init_data, 0, sizeof(init_data)); |
| 1933 | init_data.cid = qp->icid; |
| 1934 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 1935 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 1936 | rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_QUERY_QP, |
| 1937 | PROTOCOLID_ROCE, &init_data); |
| 1938 | if (rc) |
| 1939 | goto err_resp; |
| 1940 | |
| 1941 | p_resp_ramrod = &p_ent->ramrod.roce_query_qp_resp; |
| 1942 | DMA_REGPAIR_LE(p_resp_ramrod->output_params_addr, resp_ramrod_res_phys); |
| 1943 | |
| 1944 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 1945 | if (rc) |
| 1946 | goto err_resp; |
| 1947 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1948 | out_params->rq_psn = le32_to_cpu(p_resp_ramrod_res->psn); |
| 1949 | rq_err_state = GET_FIELD(le32_to_cpu(p_resp_ramrod_res->err_flag), |
| 1950 | ROCE_QUERY_QP_RESP_OUTPUT_PARAMS_ERROR_FLG); |
| 1951 | |
Ram Amrani | c5212b9 | 2017-02-20 22:43:31 +0200 | [diff] [blame] | 1952 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_resp_ramrod_res), |
| 1953 | p_resp_ramrod_res, resp_ramrod_res_phys); |
| 1954 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1955 | if (!(qp->req_offloaded)) { |
| 1956 | /* Don't send query qp for the requester */ |
| 1957 | out_params->sq_psn = qp->sq_psn; |
| 1958 | out_params->draining = false; |
| 1959 | |
| 1960 | if (rq_err_state) |
| 1961 | qp->cur_state = QED_ROCE_QP_STATE_ERR; |
| 1962 | |
| 1963 | out_params->state = qp->cur_state; |
| 1964 | |
| 1965 | return 0; |
| 1966 | } |
| 1967 | |
| 1968 | /* Send a query requester ramrod to FW to get SQ-PSN and state */ |
| 1969 | p_req_ramrod_res = (struct roce_query_qp_req_output_params *) |
| 1970 | dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, |
| 1971 | sizeof(*p_req_ramrod_res), |
| 1972 | &req_ramrod_res_phys, |
| 1973 | GFP_KERNEL); |
| 1974 | if (!p_req_ramrod_res) { |
| 1975 | rc = -ENOMEM; |
| 1976 | DP_NOTICE(p_hwfn, |
| 1977 | "qed query qp failed: cannot allocate memory (ramrod)\n"); |
| 1978 | return rc; |
| 1979 | } |
| 1980 | |
| 1981 | /* Get SPQ entry */ |
| 1982 | init_data.cid = qp->icid + 1; |
| 1983 | rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_QUERY_QP, |
| 1984 | PROTOCOLID_ROCE, &init_data); |
| 1985 | if (rc) |
| 1986 | goto err_req; |
| 1987 | |
| 1988 | p_req_ramrod = &p_ent->ramrod.roce_query_qp_req; |
| 1989 | DMA_REGPAIR_LE(p_req_ramrod->output_params_addr, req_ramrod_res_phys); |
| 1990 | |
| 1991 | rc = qed_spq_post(p_hwfn, p_ent, NULL); |
| 1992 | if (rc) |
| 1993 | goto err_req; |
| 1994 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 1995 | out_params->sq_psn = le32_to_cpu(p_req_ramrod_res->psn); |
| 1996 | sq_err_state = GET_FIELD(le32_to_cpu(p_req_ramrod_res->flags), |
| 1997 | ROCE_QUERY_QP_REQ_OUTPUT_PARAMS_ERR_FLG); |
| 1998 | sq_draining = |
| 1999 | GET_FIELD(le32_to_cpu(p_req_ramrod_res->flags), |
| 2000 | ROCE_QUERY_QP_REQ_OUTPUT_PARAMS_SQ_DRAINING_FLG); |
| 2001 | |
Ram Amrani | c5212b9 | 2017-02-20 22:43:31 +0200 | [diff] [blame] | 2002 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_req_ramrod_res), |
| 2003 | p_req_ramrod_res, req_ramrod_res_phys); |
| 2004 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2005 | out_params->draining = false; |
| 2006 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 2007 | if (rq_err_state || sq_err_state) |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2008 | qp->cur_state = QED_ROCE_QP_STATE_ERR; |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2009 | else if (sq_draining) |
| 2010 | out_params->draining = true; |
| 2011 | out_params->state = qp->cur_state; |
| 2012 | |
| 2013 | return 0; |
| 2014 | |
| 2015 | err_req: |
| 2016 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_req_ramrod_res), |
| 2017 | p_req_ramrod_res, req_ramrod_res_phys); |
| 2018 | return rc; |
| 2019 | err_resp: |
| 2020 | dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_resp_ramrod_res), |
| 2021 | p_resp_ramrod_res, resp_ramrod_res_phys); |
| 2022 | return rc; |
| 2023 | } |
| 2024 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 2025 | static int qed_roce_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp) |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2026 | { |
| 2027 | u32 num_invalidated_mw = 0; |
| 2028 | u32 num_bound_mw = 0; |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 2029 | u32 cq_prod; |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2030 | int rc; |
| 2031 | |
| 2032 | /* Destroys the specified QP */ |
| 2033 | if ((qp->cur_state != QED_ROCE_QP_STATE_RESET) && |
| 2034 | (qp->cur_state != QED_ROCE_QP_STATE_ERR) && |
| 2035 | (qp->cur_state != QED_ROCE_QP_STATE_INIT)) { |
| 2036 | DP_NOTICE(p_hwfn, |
| 2037 | "QP must be in error, reset or init state before destroying it\n"); |
| 2038 | return -EINVAL; |
| 2039 | } |
| 2040 | |
Ram Amrani | 300c0d7 | 2017-02-20 22:43:32 +0200 | [diff] [blame] | 2041 | if (qp->cur_state != QED_ROCE_QP_STATE_RESET) { |
| 2042 | rc = qed_roce_sp_destroy_qp_responder(p_hwfn, qp, |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 2043 | &num_invalidated_mw, |
| 2044 | &cq_prod); |
Ram Amrani | 300c0d7 | 2017-02-20 22:43:32 +0200 | [diff] [blame] | 2045 | if (rc) |
| 2046 | return rc; |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2047 | |
Ram Amrani | 300c0d7 | 2017-02-20 22:43:32 +0200 | [diff] [blame] | 2048 | /* Send destroy requester ramrod */ |
| 2049 | rc = qed_roce_sp_destroy_qp_requester(p_hwfn, qp, |
| 2050 | &num_bound_mw); |
| 2051 | if (rc) |
| 2052 | return rc; |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2053 | |
Ram Amrani | 300c0d7 | 2017-02-20 22:43:32 +0200 | [diff] [blame] | 2054 | if (num_invalidated_mw != num_bound_mw) { |
| 2055 | DP_NOTICE(p_hwfn, |
| 2056 | "number of invalidate memory windows is different from bounded ones\n"); |
| 2057 | return -EINVAL; |
| 2058 | } |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2059 | } |
| 2060 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2061 | return 0; |
| 2062 | } |
| 2063 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 2064 | static int qed_rdma_query_qp(void *rdma_cxt, |
| 2065 | struct qed_rdma_qp *qp, |
| 2066 | struct qed_rdma_query_qp_out_params *out_params) |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2067 | { |
| 2068 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 2069 | int rc; |
| 2070 | |
| 2071 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid); |
| 2072 | |
| 2073 | /* The following fields are filled in from qp and not FW as they can't |
| 2074 | * be modified by FW |
| 2075 | */ |
| 2076 | out_params->mtu = qp->mtu; |
| 2077 | out_params->dest_qp = qp->dest_qp; |
| 2078 | out_params->incoming_atomic_en = qp->incoming_atomic_en; |
| 2079 | out_params->e2e_flow_control_en = qp->e2e_flow_control_en; |
| 2080 | out_params->incoming_rdma_read_en = qp->incoming_rdma_read_en; |
| 2081 | out_params->incoming_rdma_write_en = qp->incoming_rdma_write_en; |
| 2082 | out_params->dgid = qp->dgid; |
| 2083 | out_params->flow_label = qp->flow_label; |
| 2084 | out_params->hop_limit_ttl = qp->hop_limit_ttl; |
| 2085 | out_params->traffic_class_tos = qp->traffic_class_tos; |
| 2086 | out_params->timeout = qp->ack_timeout; |
| 2087 | out_params->rnr_retry = qp->rnr_retry_cnt; |
| 2088 | out_params->retry_cnt = qp->retry_cnt; |
| 2089 | out_params->min_rnr_nak_timer = qp->min_rnr_nak_timer; |
| 2090 | out_params->pkey_index = 0; |
| 2091 | out_params->max_rd_atomic = qp->max_rd_atomic_req; |
| 2092 | out_params->max_dest_rd_atomic = qp->max_rd_atomic_resp; |
| 2093 | out_params->sqd_async = qp->sqd_async; |
| 2094 | |
| 2095 | rc = qed_roce_query_qp(p_hwfn, qp, out_params); |
| 2096 | |
| 2097 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Query QP, rc = %d\n", rc); |
| 2098 | return rc; |
| 2099 | } |
| 2100 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 2101 | static int qed_rdma_destroy_qp(void *rdma_cxt, struct qed_rdma_qp *qp) |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2102 | { |
| 2103 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 2104 | int rc = 0; |
| 2105 | |
| 2106 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid); |
| 2107 | |
| 2108 | rc = qed_roce_destroy_qp(p_hwfn, qp); |
| 2109 | |
| 2110 | /* free qp params struct */ |
| 2111 | kfree(qp); |
| 2112 | |
| 2113 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP destroyed\n"); |
| 2114 | return rc; |
| 2115 | } |
| 2116 | |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 2117 | static struct qed_rdma_qp * |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2118 | qed_rdma_create_qp(void *rdma_cxt, |
| 2119 | struct qed_rdma_create_qp_in_params *in_params, |
| 2120 | struct qed_rdma_create_qp_out_params *out_params) |
| 2121 | { |
| 2122 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 2123 | struct qed_rdma_qp *qp; |
| 2124 | u8 max_stats_queues; |
| 2125 | int rc; |
| 2126 | |
| 2127 | if (!rdma_cxt || !in_params || !out_params || !p_hwfn->p_rdma_info) { |
| 2128 | DP_ERR(p_hwfn->cdev, |
| 2129 | "qed roce create qp failed due to NULL entry (rdma_cxt=%p, in=%p, out=%p, roce_info=?\n", |
| 2130 | rdma_cxt, in_params, out_params); |
| 2131 | return NULL; |
| 2132 | } |
| 2133 | |
| 2134 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 2135 | "qed rdma create qp called with qp_handle = %08x%08x\n", |
| 2136 | in_params->qp_handle_hi, in_params->qp_handle_lo); |
| 2137 | |
| 2138 | /* Some sanity checks... */ |
| 2139 | max_stats_queues = p_hwfn->p_rdma_info->dev->max_stats_queues; |
| 2140 | if (in_params->stats_queue >= max_stats_queues) { |
| 2141 | DP_ERR(p_hwfn->cdev, |
| 2142 | "qed rdma create qp failed due to invalid statistics queue %d. maximum is %d\n", |
| 2143 | in_params->stats_queue, max_stats_queues); |
| 2144 | return NULL; |
| 2145 | } |
| 2146 | |
| 2147 | qp = kzalloc(sizeof(*qp), GFP_KERNEL); |
| 2148 | if (!qp) { |
| 2149 | DP_NOTICE(p_hwfn, "Failed to allocate qed_rdma_qp\n"); |
| 2150 | return NULL; |
| 2151 | } |
| 2152 | |
| 2153 | rc = qed_roce_alloc_cid(p_hwfn, &qp->icid); |
| 2154 | qp->qpid = ((0xFF << 16) | qp->icid); |
| 2155 | |
| 2156 | DP_INFO(p_hwfn, "ROCE qpid=%x\n", qp->qpid); |
| 2157 | |
| 2158 | if (rc) { |
| 2159 | kfree(qp); |
| 2160 | return NULL; |
| 2161 | } |
| 2162 | |
| 2163 | qp->cur_state = QED_ROCE_QP_STATE_RESET; |
| 2164 | qp->qp_handle.hi = cpu_to_le32(in_params->qp_handle_hi); |
| 2165 | qp->qp_handle.lo = cpu_to_le32(in_params->qp_handle_lo); |
| 2166 | qp->qp_handle_async.hi = cpu_to_le32(in_params->qp_handle_async_hi); |
| 2167 | qp->qp_handle_async.lo = cpu_to_le32(in_params->qp_handle_async_lo); |
| 2168 | qp->use_srq = in_params->use_srq; |
| 2169 | qp->signal_all = in_params->signal_all; |
| 2170 | qp->fmr_and_reserved_lkey = in_params->fmr_and_reserved_lkey; |
| 2171 | qp->pd = in_params->pd; |
| 2172 | qp->dpi = in_params->dpi; |
| 2173 | qp->sq_cq_id = in_params->sq_cq_id; |
| 2174 | qp->sq_num_pages = in_params->sq_num_pages; |
| 2175 | qp->sq_pbl_ptr = in_params->sq_pbl_ptr; |
| 2176 | qp->rq_cq_id = in_params->rq_cq_id; |
| 2177 | qp->rq_num_pages = in_params->rq_num_pages; |
| 2178 | qp->rq_pbl_ptr = in_params->rq_pbl_ptr; |
| 2179 | qp->srq_id = in_params->srq_id; |
| 2180 | qp->req_offloaded = false; |
| 2181 | qp->resp_offloaded = false; |
| 2182 | qp->e2e_flow_control_en = qp->use_srq ? false : true; |
| 2183 | qp->stats_queue = in_params->stats_queue; |
| 2184 | |
| 2185 | out_params->icid = qp->icid; |
| 2186 | out_params->qp_id = qp->qpid; |
| 2187 | |
| 2188 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Create QP, rc = %d\n", rc); |
| 2189 | return qp; |
| 2190 | } |
| 2191 | |
| 2192 | static int qed_roce_modify_qp(struct qed_hwfn *p_hwfn, |
| 2193 | struct qed_rdma_qp *qp, |
| 2194 | enum qed_roce_qp_state prev_state, |
| 2195 | struct qed_rdma_modify_qp_in_params *params) |
| 2196 | { |
| 2197 | u32 num_invalidated_mw = 0, num_bound_mw = 0; |
| 2198 | int rc = 0; |
| 2199 | |
| 2200 | /* Perform additional operations according to the current state and the |
| 2201 | * next state |
| 2202 | */ |
| 2203 | if (((prev_state == QED_ROCE_QP_STATE_INIT) || |
| 2204 | (prev_state == QED_ROCE_QP_STATE_RESET)) && |
| 2205 | (qp->cur_state == QED_ROCE_QP_STATE_RTR)) { |
| 2206 | /* Init->RTR or Reset->RTR */ |
| 2207 | rc = qed_roce_sp_create_responder(p_hwfn, qp); |
| 2208 | return rc; |
| 2209 | } else if ((prev_state == QED_ROCE_QP_STATE_RTR) && |
| 2210 | (qp->cur_state == QED_ROCE_QP_STATE_RTS)) { |
| 2211 | /* RTR-> RTS */ |
| 2212 | rc = qed_roce_sp_create_requester(p_hwfn, qp); |
| 2213 | if (rc) |
| 2214 | return rc; |
| 2215 | |
| 2216 | /* Send modify responder ramrod */ |
| 2217 | rc = qed_roce_sp_modify_responder(p_hwfn, qp, false, |
| 2218 | params->modify_flags); |
| 2219 | return rc; |
| 2220 | } else if ((prev_state == QED_ROCE_QP_STATE_RTS) && |
| 2221 | (qp->cur_state == QED_ROCE_QP_STATE_RTS)) { |
| 2222 | /* RTS->RTS */ |
| 2223 | rc = qed_roce_sp_modify_responder(p_hwfn, qp, false, |
| 2224 | params->modify_flags); |
| 2225 | if (rc) |
| 2226 | return rc; |
| 2227 | |
| 2228 | rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, false, |
| 2229 | params->modify_flags); |
| 2230 | return rc; |
| 2231 | } else if ((prev_state == QED_ROCE_QP_STATE_RTS) && |
| 2232 | (qp->cur_state == QED_ROCE_QP_STATE_SQD)) { |
| 2233 | /* RTS->SQD */ |
| 2234 | rc = qed_roce_sp_modify_requester(p_hwfn, qp, true, false, |
| 2235 | params->modify_flags); |
| 2236 | return rc; |
| 2237 | } else if ((prev_state == QED_ROCE_QP_STATE_SQD) && |
| 2238 | (qp->cur_state == QED_ROCE_QP_STATE_SQD)) { |
| 2239 | /* SQD->SQD */ |
| 2240 | rc = qed_roce_sp_modify_responder(p_hwfn, qp, false, |
| 2241 | params->modify_flags); |
| 2242 | if (rc) |
| 2243 | return rc; |
| 2244 | |
| 2245 | rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, false, |
| 2246 | params->modify_flags); |
| 2247 | return rc; |
| 2248 | } else if ((prev_state == QED_ROCE_QP_STATE_SQD) && |
| 2249 | (qp->cur_state == QED_ROCE_QP_STATE_RTS)) { |
| 2250 | /* SQD->RTS */ |
| 2251 | rc = qed_roce_sp_modify_responder(p_hwfn, qp, false, |
| 2252 | params->modify_flags); |
| 2253 | if (rc) |
| 2254 | return rc; |
| 2255 | |
| 2256 | rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, false, |
| 2257 | params->modify_flags); |
| 2258 | |
| 2259 | return rc; |
Ram Amrani | ba0154e | 2017-04-30 11:49:06 +0300 | [diff] [blame] | 2260 | } else if (qp->cur_state == QED_ROCE_QP_STATE_ERR) { |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2261 | /* ->ERR */ |
| 2262 | rc = qed_roce_sp_modify_responder(p_hwfn, qp, true, |
| 2263 | params->modify_flags); |
| 2264 | if (rc) |
| 2265 | return rc; |
| 2266 | |
| 2267 | rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, true, |
| 2268 | params->modify_flags); |
| 2269 | return rc; |
| 2270 | } else if (qp->cur_state == QED_ROCE_QP_STATE_RESET) { |
| 2271 | /* Any state -> RESET */ |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 2272 | u32 cq_prod; |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2273 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 2274 | /* Send destroy responder ramrod */ |
| 2275 | rc = qed_roce_sp_destroy_qp_responder(p_hwfn, |
| 2276 | qp, |
| 2277 | &num_invalidated_mw, |
| 2278 | &cq_prod); |
| 2279 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2280 | if (rc) |
| 2281 | return rc; |
| 2282 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 2283 | qp->cq_prod = cq_prod; |
| 2284 | |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2285 | rc = qed_roce_sp_destroy_qp_requester(p_hwfn, qp, |
| 2286 | &num_bound_mw); |
| 2287 | |
| 2288 | if (num_invalidated_mw != num_bound_mw) { |
| 2289 | DP_NOTICE(p_hwfn, |
| 2290 | "number of invalidate memory windows is different from bounded ones\n"); |
| 2291 | return -EINVAL; |
| 2292 | } |
| 2293 | } else { |
| 2294 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "0\n"); |
| 2295 | } |
| 2296 | |
| 2297 | return rc; |
| 2298 | } |
| 2299 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 2300 | static int qed_rdma_modify_qp(void *rdma_cxt, |
| 2301 | struct qed_rdma_qp *qp, |
| 2302 | struct qed_rdma_modify_qp_in_params *params) |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2303 | { |
| 2304 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 2305 | enum qed_roce_qp_state prev_state; |
| 2306 | int rc = 0; |
| 2307 | |
| 2308 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x params->new_state=%d\n", |
| 2309 | qp->icid, params->new_state); |
| 2310 | |
| 2311 | if (rc) { |
| 2312 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc); |
| 2313 | return rc; |
| 2314 | } |
| 2315 | |
| 2316 | if (GET_FIELD(params->modify_flags, |
| 2317 | QED_RDMA_MODIFY_QP_VALID_RDMA_OPS_EN)) { |
| 2318 | qp->incoming_rdma_read_en = params->incoming_rdma_read_en; |
| 2319 | qp->incoming_rdma_write_en = params->incoming_rdma_write_en; |
| 2320 | qp->incoming_atomic_en = params->incoming_atomic_en; |
| 2321 | } |
| 2322 | |
| 2323 | /* Update QP structure with the updated values */ |
| 2324 | if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_ROCE_MODE)) |
| 2325 | qp->roce_mode = params->roce_mode; |
| 2326 | if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_PKEY)) |
| 2327 | qp->pkey = params->pkey; |
| 2328 | if (GET_FIELD(params->modify_flags, |
| 2329 | QED_ROCE_MODIFY_QP_VALID_E2E_FLOW_CONTROL_EN)) |
| 2330 | qp->e2e_flow_control_en = params->e2e_flow_control_en; |
| 2331 | if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_DEST_QP)) |
| 2332 | qp->dest_qp = params->dest_qp; |
| 2333 | if (GET_FIELD(params->modify_flags, |
| 2334 | QED_ROCE_MODIFY_QP_VALID_ADDRESS_VECTOR)) { |
| 2335 | /* Indicates that the following parameters have changed: |
| 2336 | * Traffic class, flow label, hop limit, source GID, |
| 2337 | * destination GID, loopback indicator |
| 2338 | */ |
| 2339 | qp->traffic_class_tos = params->traffic_class_tos; |
| 2340 | qp->flow_label = params->flow_label; |
| 2341 | qp->hop_limit_ttl = params->hop_limit_ttl; |
| 2342 | |
| 2343 | qp->sgid = params->sgid; |
| 2344 | qp->dgid = params->dgid; |
| 2345 | qp->udp_src_port = 0; |
| 2346 | qp->vlan_id = params->vlan_id; |
| 2347 | qp->mtu = params->mtu; |
| 2348 | qp->lb_indication = params->lb_indication; |
| 2349 | memcpy((u8 *)&qp->remote_mac_addr[0], |
| 2350 | (u8 *)¶ms->remote_mac_addr[0], ETH_ALEN); |
| 2351 | if (params->use_local_mac) { |
| 2352 | memcpy((u8 *)&qp->local_mac_addr[0], |
| 2353 | (u8 *)¶ms->local_mac_addr[0], ETH_ALEN); |
| 2354 | } else { |
| 2355 | memcpy((u8 *)&qp->local_mac_addr[0], |
| 2356 | (u8 *)&p_hwfn->hw_info.hw_mac_addr, ETH_ALEN); |
| 2357 | } |
| 2358 | } |
| 2359 | if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_RQ_PSN)) |
| 2360 | qp->rq_psn = params->rq_psn; |
| 2361 | if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_SQ_PSN)) |
| 2362 | qp->sq_psn = params->sq_psn; |
| 2363 | if (GET_FIELD(params->modify_flags, |
| 2364 | QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_REQ)) |
| 2365 | qp->max_rd_atomic_req = params->max_rd_atomic_req; |
| 2366 | if (GET_FIELD(params->modify_flags, |
| 2367 | QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_RESP)) |
| 2368 | qp->max_rd_atomic_resp = params->max_rd_atomic_resp; |
| 2369 | if (GET_FIELD(params->modify_flags, |
| 2370 | QED_ROCE_MODIFY_QP_VALID_ACK_TIMEOUT)) |
| 2371 | qp->ack_timeout = params->ack_timeout; |
| 2372 | if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_RETRY_CNT)) |
| 2373 | qp->retry_cnt = params->retry_cnt; |
| 2374 | if (GET_FIELD(params->modify_flags, |
| 2375 | QED_ROCE_MODIFY_QP_VALID_RNR_RETRY_CNT)) |
| 2376 | qp->rnr_retry_cnt = params->rnr_retry_cnt; |
| 2377 | if (GET_FIELD(params->modify_flags, |
| 2378 | QED_ROCE_MODIFY_QP_VALID_MIN_RNR_NAK_TIMER)) |
| 2379 | qp->min_rnr_nak_timer = params->min_rnr_nak_timer; |
| 2380 | |
| 2381 | qp->sqd_async = params->sqd_async; |
| 2382 | |
| 2383 | prev_state = qp->cur_state; |
| 2384 | if (GET_FIELD(params->modify_flags, |
| 2385 | QED_RDMA_MODIFY_QP_VALID_NEW_STATE)) { |
| 2386 | qp->cur_state = params->new_state; |
| 2387 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "qp->cur_state=%d\n", |
| 2388 | qp->cur_state); |
| 2389 | } |
| 2390 | |
| 2391 | rc = qed_roce_modify_qp(p_hwfn, qp, prev_state, params); |
| 2392 | |
| 2393 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Modify QP, rc = %d\n", rc); |
| 2394 | return rc; |
| 2395 | } |
| 2396 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 2397 | static int |
| 2398 | qed_rdma_register_tid(void *rdma_cxt, |
| 2399 | struct qed_rdma_register_tid_in_params *params) |
Ram Amrani | ee8eaea | 2016-10-01 22:00:00 +0300 | [diff] [blame] | 2400 | { |
| 2401 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 2402 | struct rdma_register_tid_ramrod_data *p_ramrod; |
| 2403 | struct qed_sp_init_data init_data; |
| 2404 | struct qed_spq_entry *p_ent; |
| 2405 | enum rdma_tid_type tid_type; |
| 2406 | u8 fw_return_code; |
| 2407 | int rc; |
| 2408 | |
| 2409 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", params->itid); |
| 2410 | |
| 2411 | /* Get SPQ entry */ |
| 2412 | memset(&init_data, 0, sizeof(init_data)); |
| 2413 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 2414 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 2415 | |
| 2416 | rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_REGISTER_MR, |
| 2417 | p_hwfn->p_rdma_info->proto, &init_data); |
| 2418 | if (rc) { |
| 2419 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc); |
| 2420 | return rc; |
| 2421 | } |
| 2422 | |
| 2423 | if (p_hwfn->p_rdma_info->last_tid < params->itid) |
| 2424 | p_hwfn->p_rdma_info->last_tid = params->itid; |
| 2425 | |
| 2426 | p_ramrod = &p_ent->ramrod.rdma_register_tid; |
| 2427 | |
| 2428 | p_ramrod->flags = 0; |
| 2429 | SET_FIELD(p_ramrod->flags, |
| 2430 | RDMA_REGISTER_TID_RAMROD_DATA_TWO_LEVEL_PBL, |
| 2431 | params->pbl_two_level); |
| 2432 | |
| 2433 | SET_FIELD(p_ramrod->flags, |
| 2434 | RDMA_REGISTER_TID_RAMROD_DATA_ZERO_BASED, params->zbva); |
| 2435 | |
| 2436 | SET_FIELD(p_ramrod->flags, |
| 2437 | RDMA_REGISTER_TID_RAMROD_DATA_PHY_MR, params->phy_mr); |
| 2438 | |
| 2439 | /* Don't initialize D/C field, as it may override other bits. */ |
| 2440 | if (!(params->tid_type == QED_RDMA_TID_FMR) && !(params->dma_mr)) |
| 2441 | SET_FIELD(p_ramrod->flags, |
| 2442 | RDMA_REGISTER_TID_RAMROD_DATA_PAGE_SIZE_LOG, |
| 2443 | params->page_size_log - 12); |
| 2444 | |
| 2445 | SET_FIELD(p_ramrod->flags, |
Ram Amrani | ee8eaea | 2016-10-01 22:00:00 +0300 | [diff] [blame] | 2446 | RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_READ, |
| 2447 | params->remote_read); |
| 2448 | |
| 2449 | SET_FIELD(p_ramrod->flags, |
| 2450 | RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_WRITE, |
| 2451 | params->remote_write); |
| 2452 | |
| 2453 | SET_FIELD(p_ramrod->flags, |
| 2454 | RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_ATOMIC, |
| 2455 | params->remote_atomic); |
| 2456 | |
| 2457 | SET_FIELD(p_ramrod->flags, |
| 2458 | RDMA_REGISTER_TID_RAMROD_DATA_LOCAL_WRITE, |
| 2459 | params->local_write); |
| 2460 | |
| 2461 | SET_FIELD(p_ramrod->flags, |
| 2462 | RDMA_REGISTER_TID_RAMROD_DATA_LOCAL_READ, params->local_read); |
| 2463 | |
| 2464 | SET_FIELD(p_ramrod->flags, |
| 2465 | RDMA_REGISTER_TID_RAMROD_DATA_ENABLE_MW_BIND, |
| 2466 | params->mw_bind); |
| 2467 | |
| 2468 | SET_FIELD(p_ramrod->flags1, |
| 2469 | RDMA_REGISTER_TID_RAMROD_DATA_PBL_PAGE_SIZE_LOG, |
| 2470 | params->pbl_page_size_log - 12); |
| 2471 | |
| 2472 | SET_FIELD(p_ramrod->flags2, |
| 2473 | RDMA_REGISTER_TID_RAMROD_DATA_DMA_MR, params->dma_mr); |
| 2474 | |
| 2475 | switch (params->tid_type) { |
| 2476 | case QED_RDMA_TID_REGISTERED_MR: |
| 2477 | tid_type = RDMA_TID_REGISTERED_MR; |
| 2478 | break; |
| 2479 | case QED_RDMA_TID_FMR: |
| 2480 | tid_type = RDMA_TID_FMR; |
| 2481 | break; |
| 2482 | case QED_RDMA_TID_MW_TYPE1: |
| 2483 | tid_type = RDMA_TID_MW_TYPE1; |
| 2484 | break; |
| 2485 | case QED_RDMA_TID_MW_TYPE2A: |
| 2486 | tid_type = RDMA_TID_MW_TYPE2A; |
| 2487 | break; |
| 2488 | default: |
| 2489 | rc = -EINVAL; |
| 2490 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc); |
| 2491 | return rc; |
| 2492 | } |
| 2493 | SET_FIELD(p_ramrod->flags1, |
| 2494 | RDMA_REGISTER_TID_RAMROD_DATA_TID_TYPE, tid_type); |
| 2495 | |
| 2496 | p_ramrod->itid = cpu_to_le32(params->itid); |
| 2497 | p_ramrod->key = params->key; |
| 2498 | p_ramrod->pd = cpu_to_le16(params->pd); |
| 2499 | p_ramrod->length_hi = (u8)(params->length >> 32); |
| 2500 | p_ramrod->length_lo = DMA_LO_LE(params->length); |
| 2501 | if (params->zbva) { |
| 2502 | /* Lower 32 bits of the registered MR address. |
| 2503 | * In case of zero based MR, will hold FBO |
| 2504 | */ |
| 2505 | p_ramrod->va.hi = 0; |
| 2506 | p_ramrod->va.lo = cpu_to_le32(params->fbo); |
| 2507 | } else { |
| 2508 | DMA_REGPAIR_LE(p_ramrod->va, params->vaddr); |
| 2509 | } |
| 2510 | DMA_REGPAIR_LE(p_ramrod->pbl_base, params->pbl_ptr); |
| 2511 | |
| 2512 | /* DIF */ |
| 2513 | if (params->dif_enabled) { |
| 2514 | SET_FIELD(p_ramrod->flags2, |
| 2515 | RDMA_REGISTER_TID_RAMROD_DATA_DIF_ON_HOST_FLG, 1); |
| 2516 | DMA_REGPAIR_LE(p_ramrod->dif_error_addr, |
| 2517 | params->dif_error_addr); |
| 2518 | DMA_REGPAIR_LE(p_ramrod->dif_runt_addr, params->dif_runt_addr); |
| 2519 | } |
| 2520 | |
| 2521 | rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code); |
Ram Amrani | 1053619 | 2017-04-30 11:49:07 +0300 | [diff] [blame] | 2522 | if (rc) |
| 2523 | return rc; |
Ram Amrani | ee8eaea | 2016-10-01 22:00:00 +0300 | [diff] [blame] | 2524 | |
| 2525 | if (fw_return_code != RDMA_RETURN_OK) { |
| 2526 | DP_NOTICE(p_hwfn, "fw_return_code = %d\n", fw_return_code); |
| 2527 | return -EINVAL; |
| 2528 | } |
| 2529 | |
| 2530 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Register TID, rc = %d\n", rc); |
| 2531 | return rc; |
| 2532 | } |
| 2533 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 2534 | static int qed_rdma_deregister_tid(void *rdma_cxt, u32 itid) |
Ram Amrani | ee8eaea | 2016-10-01 22:00:00 +0300 | [diff] [blame] | 2535 | { |
| 2536 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 2537 | struct rdma_deregister_tid_ramrod_data *p_ramrod; |
| 2538 | struct qed_sp_init_data init_data; |
| 2539 | struct qed_spq_entry *p_ent; |
| 2540 | struct qed_ptt *p_ptt; |
| 2541 | u8 fw_return_code; |
| 2542 | int rc; |
| 2543 | |
| 2544 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", itid); |
| 2545 | |
| 2546 | /* Get SPQ entry */ |
| 2547 | memset(&init_data, 0, sizeof(init_data)); |
| 2548 | init_data.opaque_fid = p_hwfn->hw_info.opaque_fid; |
| 2549 | init_data.comp_mode = QED_SPQ_MODE_EBLOCK; |
| 2550 | |
| 2551 | rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_DEREGISTER_MR, |
| 2552 | p_hwfn->p_rdma_info->proto, &init_data); |
| 2553 | if (rc) { |
| 2554 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc); |
| 2555 | return rc; |
| 2556 | } |
| 2557 | |
| 2558 | p_ramrod = &p_ent->ramrod.rdma_deregister_tid; |
| 2559 | p_ramrod->itid = cpu_to_le32(itid); |
| 2560 | |
| 2561 | rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code); |
| 2562 | if (rc) { |
| 2563 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc); |
| 2564 | return rc; |
| 2565 | } |
| 2566 | |
| 2567 | if (fw_return_code == RDMA_RETURN_DEREGISTER_MR_BAD_STATE_ERR) { |
| 2568 | DP_NOTICE(p_hwfn, "fw_return_code = %d\n", fw_return_code); |
| 2569 | return -EINVAL; |
| 2570 | } else if (fw_return_code == RDMA_RETURN_NIG_DRAIN_REQ) { |
| 2571 | /* Bit indicating that the TID is in use and a nig drain is |
| 2572 | * required before sending the ramrod again |
| 2573 | */ |
| 2574 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 2575 | if (!p_ptt) { |
| 2576 | rc = -EBUSY; |
| 2577 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 2578 | "Failed to acquire PTT\n"); |
| 2579 | return rc; |
| 2580 | } |
| 2581 | |
| 2582 | rc = qed_mcp_drain(p_hwfn, p_ptt); |
| 2583 | if (rc) { |
| 2584 | qed_ptt_release(p_hwfn, p_ptt); |
| 2585 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 2586 | "Drain failed\n"); |
| 2587 | return rc; |
| 2588 | } |
| 2589 | |
| 2590 | qed_ptt_release(p_hwfn, p_ptt); |
| 2591 | |
| 2592 | /* Resend the ramrod */ |
| 2593 | rc = qed_sp_init_request(p_hwfn, &p_ent, |
| 2594 | RDMA_RAMROD_DEREGISTER_MR, |
| 2595 | p_hwfn->p_rdma_info->proto, |
| 2596 | &init_data); |
| 2597 | if (rc) { |
| 2598 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 2599 | "Failed to init sp-element\n"); |
| 2600 | return rc; |
| 2601 | } |
| 2602 | |
| 2603 | rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code); |
| 2604 | if (rc) { |
| 2605 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 2606 | "Ramrod failed\n"); |
| 2607 | return rc; |
| 2608 | } |
| 2609 | |
| 2610 | if (fw_return_code != RDMA_RETURN_OK) { |
| 2611 | DP_NOTICE(p_hwfn, "fw_return_code = %d\n", |
| 2612 | fw_return_code); |
| 2613 | return rc; |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "De-registered TID, rc = %d\n", rc); |
| 2618 | return rc; |
| 2619 | } |
| 2620 | |
Mintz, Yuval | be086e7 | 2017-03-11 18:39:18 +0200 | [diff] [blame] | 2621 | static void qed_roce_free_real_icid(struct qed_hwfn *p_hwfn, u16 icid) |
| 2622 | { |
| 2623 | struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info; |
| 2624 | u32 start_cid, cid, xcid; |
| 2625 | |
| 2626 | /* an even icid belongs to a responder while an odd icid belongs to a |
| 2627 | * requester. The 'cid' received as an input can be either. We calculate |
| 2628 | * the "partner" icid and call it xcid. Only if both are free then the |
| 2629 | * "cid" map can be cleared. |
| 2630 | */ |
| 2631 | start_cid = qed_cxt_get_proto_cid_start(p_hwfn, p_rdma_info->proto); |
| 2632 | cid = icid - start_cid; |
| 2633 | xcid = cid ^ 1; |
| 2634 | |
| 2635 | spin_lock_bh(&p_rdma_info->lock); |
| 2636 | |
| 2637 | qed_bmap_release_id(p_hwfn, &p_rdma_info->real_cid_map, cid); |
| 2638 | if (qed_bmap_test_id(p_hwfn, &p_rdma_info->real_cid_map, xcid) == 0) { |
| 2639 | qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, cid); |
| 2640 | qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, xcid); |
| 2641 | } |
| 2642 | |
| 2643 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 2644 | } |
| 2645 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 2646 | static void *qed_rdma_get_rdma_ctx(struct qed_dev *cdev) |
| 2647 | { |
| 2648 | return QED_LEADING_HWFN(cdev); |
| 2649 | } |
| 2650 | |
Mintz, Yuval | 9331dad | 2017-06-20 16:00:02 +0300 | [diff] [blame] | 2651 | static bool qed_rdma_allocated_qps(struct qed_hwfn *p_hwfn) |
| 2652 | { |
| 2653 | bool result; |
| 2654 | |
| 2655 | /* if rdma info has not been allocated, naturally there are no qps */ |
| 2656 | if (!p_hwfn->p_rdma_info) |
| 2657 | return false; |
| 2658 | |
| 2659 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 2660 | if (!p_hwfn->p_rdma_info->cid_map.bitmap) |
| 2661 | result = false; |
| 2662 | else |
| 2663 | result = !qed_bmap_is_empty(&p_hwfn->p_rdma_info->cid_map); |
| 2664 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 2665 | return result; |
| 2666 | } |
| 2667 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 2668 | static void qed_rdma_dpm_conf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 2669 | { |
| 2670 | u32 val; |
| 2671 | |
| 2672 | val = (p_hwfn->dcbx_no_edpm || p_hwfn->db_bar_no_edpm) ? 0 : 1; |
| 2673 | |
| 2674 | qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPM_ENABLE, val); |
| 2675 | DP_VERBOSE(p_hwfn, (QED_MSG_DCB | QED_MSG_RDMA), |
| 2676 | "Changing DPM_EN state to %d (DCBX=%d, DB_BAR=%d)\n", |
| 2677 | val, p_hwfn->dcbx_no_edpm, p_hwfn->db_bar_no_edpm); |
| 2678 | } |
| 2679 | |
Mintz, Yuval | 9331dad | 2017-06-20 16:00:02 +0300 | [diff] [blame] | 2680 | void qed_roce_dpm_dcbx(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 2681 | { |
| 2682 | u8 val; |
| 2683 | |
| 2684 | /* if any QPs are already active, we want to disable DPM, since their |
| 2685 | * context information contains information from before the latest DCBx |
| 2686 | * update. Otherwise enable it. |
| 2687 | */ |
| 2688 | val = qed_rdma_allocated_qps(p_hwfn) ? true : false; |
| 2689 | p_hwfn->dcbx_no_edpm = (u8)val; |
| 2690 | |
| 2691 | qed_rdma_dpm_conf(p_hwfn, p_ptt); |
| 2692 | } |
| 2693 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 2694 | void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 2695 | { |
| 2696 | p_hwfn->db_bar_no_edpm = true; |
| 2697 | |
| 2698 | qed_rdma_dpm_conf(p_hwfn, p_ptt); |
| 2699 | } |
| 2700 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 2701 | static int qed_rdma_start(void *rdma_cxt, |
| 2702 | struct qed_rdma_start_in_params *params) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 2703 | { |
| 2704 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 2705 | struct qed_ptt *p_ptt; |
| 2706 | int rc = -EBUSY; |
| 2707 | |
| 2708 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, |
| 2709 | "desired_cnq = %08x\n", params->desired_cnq); |
| 2710 | |
| 2711 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 2712 | if (!p_ptt) |
| 2713 | goto err; |
| 2714 | |
| 2715 | rc = qed_rdma_alloc(p_hwfn, p_ptt, params); |
| 2716 | if (rc) |
| 2717 | goto err1; |
| 2718 | |
| 2719 | rc = qed_rdma_setup(p_hwfn, p_ptt, params); |
| 2720 | if (rc) |
| 2721 | goto err2; |
| 2722 | |
| 2723 | qed_ptt_release(p_hwfn, p_ptt); |
| 2724 | |
| 2725 | return rc; |
| 2726 | |
| 2727 | err2: |
| 2728 | qed_rdma_free(p_hwfn); |
| 2729 | err1: |
| 2730 | qed_ptt_release(p_hwfn, p_ptt); |
| 2731 | err: |
| 2732 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA start - error, rc = %d\n", rc); |
| 2733 | return rc; |
| 2734 | } |
| 2735 | |
| 2736 | static int qed_rdma_init(struct qed_dev *cdev, |
| 2737 | struct qed_rdma_start_in_params *params) |
| 2738 | { |
| 2739 | return qed_rdma_start(QED_LEADING_HWFN(cdev), params); |
| 2740 | } |
| 2741 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 2742 | static void qed_rdma_remove_user(void *rdma_cxt, u16 dpi) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 2743 | { |
| 2744 | struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; |
| 2745 | |
| 2746 | DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "dpi = %08x\n", dpi); |
| 2747 | |
| 2748 | spin_lock_bh(&p_hwfn->p_rdma_info->lock); |
| 2749 | qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->dpi_map, dpi); |
| 2750 | spin_unlock_bh(&p_hwfn->p_rdma_info->lock); |
| 2751 | } |
| 2752 | |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 2753 | static int qed_roce_ll2_set_mac_filter(struct qed_dev *cdev, |
| 2754 | u8 *old_mac_address, |
| 2755 | u8 *new_mac_address) |
| 2756 | { |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2757 | struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev); |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 2758 | struct qed_ptt *p_ptt; |
| 2759 | int rc = 0; |
| 2760 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2761 | p_ptt = qed_ptt_acquire(p_hwfn); |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 2762 | if (!p_ptt) { |
| 2763 | DP_ERR(cdev, |
| 2764 | "qed roce ll2 mac filter set: failed to acquire PTT\n"); |
| 2765 | return -EINVAL; |
| 2766 | } |
| 2767 | |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 2768 | if (old_mac_address) |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2769 | qed_llh_remove_mac_filter(p_hwfn, p_ptt, old_mac_address); |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 2770 | if (new_mac_address) |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2771 | rc = qed_llh_add_mac_filter(p_hwfn, p_ptt, new_mac_address); |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 2772 | |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2773 | qed_ptt_release(p_hwfn, p_ptt); |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 2774 | |
| 2775 | if (rc) |
| 2776 | DP_ERR(cdev, |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2777 | "qed roce ll2 mac filter set: failed to add MAC filter\n"); |
Ram Amrani | abd4967 | 2016-10-01 22:00:01 +0300 | [diff] [blame] | 2778 | |
| 2779 | return rc; |
| 2780 | } |
| 2781 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 2782 | static const struct qed_rdma_ops qed_rdma_ops_pass = { |
| 2783 | .common = &qed_common_ops_pass, |
| 2784 | .fill_dev_info = &qed_fill_rdma_dev_info, |
| 2785 | .rdma_get_rdma_ctx = &qed_rdma_get_rdma_ctx, |
| 2786 | .rdma_init = &qed_rdma_init, |
| 2787 | .rdma_add_user = &qed_rdma_add_user, |
| 2788 | .rdma_remove_user = &qed_rdma_remove_user, |
| 2789 | .rdma_stop = &qed_rdma_stop, |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 2790 | .rdma_query_port = &qed_rdma_query_port, |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 2791 | .rdma_query_device = &qed_rdma_query_device, |
| 2792 | .rdma_get_start_sb = &qed_rdma_get_sb_start, |
| 2793 | .rdma_get_rdma_int = &qed_rdma_get_int, |
| 2794 | .rdma_set_rdma_int = &qed_rdma_set_int, |
| 2795 | .rdma_get_min_cnq_msix = &qed_rdma_get_min_cnq_msix, |
| 2796 | .rdma_cnq_prod_update = &qed_rdma_cnq_prod_update, |
Ram Amrani | c295f86 | 2016-10-01 21:59:58 +0300 | [diff] [blame] | 2797 | .rdma_alloc_pd = &qed_rdma_alloc_pd, |
| 2798 | .rdma_dealloc_pd = &qed_rdma_free_pd, |
| 2799 | .rdma_create_cq = &qed_rdma_create_cq, |
| 2800 | .rdma_destroy_cq = &qed_rdma_destroy_cq, |
Ram Amrani | f109394 | 2016-10-01 21:59:59 +0300 | [diff] [blame] | 2801 | .rdma_create_qp = &qed_rdma_create_qp, |
| 2802 | .rdma_modify_qp = &qed_rdma_modify_qp, |
| 2803 | .rdma_query_qp = &qed_rdma_query_qp, |
| 2804 | .rdma_destroy_qp = &qed_rdma_destroy_qp, |
Ram Amrani | ee8eaea | 2016-10-01 22:00:00 +0300 | [diff] [blame] | 2805 | .rdma_alloc_tid = &qed_rdma_alloc_tid, |
| 2806 | .rdma_free_tid = &qed_rdma_free_tid, |
| 2807 | .rdma_register_tid = &qed_rdma_register_tid, |
| 2808 | .rdma_deregister_tid = &qed_rdma_deregister_tid, |
Michal Kalderon | 0518c12 | 2017-06-09 17:13:22 +0300 | [diff] [blame] | 2809 | .ll2_acquire_connection = &qed_ll2_acquire_connection, |
| 2810 | .ll2_establish_connection = &qed_ll2_establish_connection, |
| 2811 | .ll2_terminate_connection = &qed_ll2_terminate_connection, |
| 2812 | .ll2_release_connection = &qed_ll2_release_connection, |
| 2813 | .ll2_post_rx_buffer = &qed_ll2_post_rx_buffer, |
| 2814 | .ll2_prepare_tx_packet = &qed_ll2_prepare_tx_packet, |
| 2815 | .ll2_set_fragment_of_tx_packet = &qed_ll2_set_fragment_of_tx_packet, |
| 2816 | .ll2_set_mac_filter = &qed_roce_ll2_set_mac_filter, |
| 2817 | .ll2_get_stats = &qed_ll2_get_stats, |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 2818 | }; |
| 2819 | |
Arnd Bergmann | d4e9913 | 2016-10-10 13:59:16 +0200 | [diff] [blame] | 2820 | const struct qed_rdma_ops *qed_get_rdma_ops(void) |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 2821 | { |
| 2822 | return &qed_rdma_ops_pass; |
| 2823 | } |
| 2824 | EXPORT_SYMBOL(qed_get_rdma_ops); |