blob: 53f285e40e3d4affb32a63cc7239da564352386c [file] [log] [blame]
Ram Amrani51ff1722016-10-01 21:59:57 +03001/* QLogic qed NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
Ram Amrani51ff1722016-10-01 21:59:57 +03003 *
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>
38#include <linux/etherdevice.h>
39#include <linux/if_ether.h>
40#include <linux/if_vlan.h>
41#include <linux/io.h>
42#include <linux/ip.h>
43#include <linux/ipv6.h>
44#include <linux/kernel.h>
45#include <linux/list.h>
46#include <linux/module.h>
47#include <linux/mutex.h>
48#include <linux/pci.h>
49#include <linux/slab.h>
50#include <linux/spinlock.h>
51#include <linux/string.h>
52#include <linux/tcp.h>
53#include <linux/bitops.h>
54#include <linux/qed/qed_roce_if.h>
55#include <linux/qed/qed_roce_if.h>
56#include "qed.h"
57#include "qed_cxt.h"
58#include "qed_hsi.h"
59#include "qed_hw.h"
60#include "qed_init_ops.h"
61#include "qed_int.h"
62#include "qed_ll2.h"
63#include "qed_mcp.h"
64#include "qed_reg_addr.h"
65#include "qed_sp.h"
66#include "qed_roce.h"
Ram Amraniabd49672016-10-01 22:00:01 +030067#include "qed_ll2.h"
Ram Amrani51ff1722016-10-01 21:59:57 +030068
Mintz, Yuvalbe086e72017-03-11 18:39:18 +020069static void qed_roce_free_real_icid(struct qed_hwfn *p_hwfn, u16 icid);
Ram Amrani51ff1722016-10-01 21:59:57 +030070
Mintz, Yuvalbe086e72017-03-11 18:39:18 +020071void 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 Amrani51ff1722016-10-01 21:59:57 +030090}
91
92static int qed_rdma_bmap_alloc(struct qed_hwfn *p_hwfn,
Ram Amranie015d582017-04-30 11:49:08 +030093 struct qed_bmap *bmap, u32 max_count, char *name)
Ram Amrani51ff1722016-10-01 21:59:57 +030094{
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 Amranie015d582017-04-30 11:49:08 +0300107 snprintf(bmap->name, QED_RDMA_MAX_BMAP_NAME, "%s", name);
108
109 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "0\n");
Ram Amrani51ff1722016-10-01 21:59:57 +0300110 return 0;
111}
112
113static int qed_rdma_bmap_alloc_id(struct qed_hwfn *p_hwfn,
114 struct qed_bmap *bmap, u32 *id_num)
115{
Ram Amrani51ff1722016-10-01 21:59:57 +0300116 *id_num = find_first_zero_bit(bmap->bitmap, bmap->max_count);
Ram Amranie015d582017-04-30 11:49:08 +0300117 if (*id_num >= bmap->max_count)
Ram Amrani51ff1722016-10-01 21:59:57 +0300118 return -EINVAL;
Ram Amrani51ff1722016-10-01 21:59:57 +0300119
120 __set_bit(*id_num, bmap->bitmap);
121
Ram Amranie015d582017-04-30 11:49:08 +0300122 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "%s bitmap: allocated id %d\n",
123 bmap->name, *id_num);
124
Ram Amrani51ff1722016-10-01 21:59:57 +0300125 return 0;
126}
127
Mintz, Yuvalbe086e72017-03-11 18:39:18 +0200128static 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 Amrani51ff1722016-10-01 21:59:57 +0300137static 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 Amrani51ff1722016-10-01 21:59:57 +0300142 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 Amranie015d582017-04-30 11:49:08 +0300147 DP_NOTICE(p_hwfn, "%s bitmap: id %d already released\n",
148 bmap->name, id_num);
Ram Amrani51ff1722016-10-01 21:59:57 +0300149 return;
150 }
Ram Amranie015d582017-04-30 11:49:08 +0300151
152 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "%s bitmap: released id %d\n",
153 bmap->name, id_num);
Ram Amrani51ff1722016-10-01 21:59:57 +0300154}
155
Mintz, Yuvalbe086e72017-03-11 18:39:18 +0200156static 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
Yuval Mintz0189efb2016-10-13 22:57:02 +0300165static u32 qed_rdma_get_sb_id(void *p_hwfn, u32 rel_sb_id)
Ram Amrani51ff1722016-10-01 21:59:57 +0300166{
167 /* First sb id for RoCE is after all the l2 sb */
168 return FEAT_NUM((struct qed_hwfn *)p_hwfn, QED_PF_L2_QUE) + rel_sb_id;
169}
170
Ram Amrani51ff1722016-10-01 21:59:57 +0300171static int qed_rdma_alloc(struct qed_hwfn *p_hwfn,
172 struct qed_ptt *p_ptt,
173 struct qed_rdma_start_in_params *params)
174{
175 struct qed_rdma_info *p_rdma_info;
176 u32 num_cons, num_tasks;
177 int rc = -ENOMEM;
178
179 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocating RDMA\n");
180
181 /* Allocate a struct with current pf rdma info */
182 p_rdma_info = kzalloc(sizeof(*p_rdma_info), GFP_KERNEL);
183 if (!p_rdma_info) {
184 DP_NOTICE(p_hwfn,
185 "qed rdma alloc failed: cannot allocate memory (rdma info). rc = %d\n",
186 rc);
187 return rc;
188 }
189
190 p_hwfn->p_rdma_info = p_rdma_info;
191 p_rdma_info->proto = PROTOCOLID_ROCE;
192
Yuval Mintz8c93bea2016-10-13 22:57:03 +0300193 num_cons = qed_cxt_get_proto_cid_count(p_hwfn, p_rdma_info->proto,
194 NULL);
Ram Amrani51ff1722016-10-01 21:59:57 +0300195
196 p_rdma_info->num_qps = num_cons / 2;
197
198 num_tasks = qed_cxt_get_proto_tid_count(p_hwfn, PROTOCOLID_ROCE);
199
200 /* Each MR uses a single task */
201 p_rdma_info->num_mrs = num_tasks;
202
203 /* Queue zone lines are shared between RoCE and L2 in such a way that
204 * they can be used by each without obstructing the other.
205 */
Mintz, Yuvalbe086e72017-03-11 18:39:18 +0200206 p_rdma_info->queue_zone_base = (u16)RESC_START(p_hwfn, QED_L2_QUEUE);
207 p_rdma_info->max_queue_zones = (u16)RESC_NUM(p_hwfn, QED_L2_QUEUE);
Ram Amrani51ff1722016-10-01 21:59:57 +0300208
209 /* Allocate a struct with device params and fill it */
210 p_rdma_info->dev = kzalloc(sizeof(*p_rdma_info->dev), GFP_KERNEL);
211 if (!p_rdma_info->dev) {
212 DP_NOTICE(p_hwfn,
213 "qed rdma alloc failed: cannot allocate memory (rdma info dev). rc = %d\n",
214 rc);
215 goto free_rdma_info;
216 }
217
218 /* Allocate a struct with port params and fill it */
219 p_rdma_info->port = kzalloc(sizeof(*p_rdma_info->port), GFP_KERNEL);
220 if (!p_rdma_info->port) {
221 DP_NOTICE(p_hwfn,
222 "qed rdma alloc failed: cannot allocate memory (rdma info port). rc = %d\n",
223 rc);
224 goto free_rdma_dev;
225 }
226
227 /* Allocate bit map for pd's */
Ram Amranie015d582017-04-30 11:49:08 +0300228 rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->pd_map, RDMA_MAX_PDS,
229 "PD");
Ram Amrani51ff1722016-10-01 21:59:57 +0300230 if (rc) {
231 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
232 "Failed to allocate pd_map, rc = %d\n",
233 rc);
234 goto free_rdma_port;
235 }
236
237 /* Allocate DPI bitmap */
238 rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->dpi_map,
Ram Amranie015d582017-04-30 11:49:08 +0300239 p_hwfn->dpi_count, "DPI");
Ram Amrani51ff1722016-10-01 21:59:57 +0300240 if (rc) {
241 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
242 "Failed to allocate DPI bitmap, rc = %d\n", rc);
243 goto free_pd_map;
244 }
245
246 /* Allocate bitmap for cq's. The maximum number of CQs is bounded to
247 * twice the number of QPs.
248 */
249 rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->cq_map,
Ram Amranie015d582017-04-30 11:49:08 +0300250 p_rdma_info->num_qps * 2, "CQ");
Ram Amrani51ff1722016-10-01 21:59:57 +0300251 if (rc) {
252 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
253 "Failed to allocate cq bitmap, rc = %d\n", rc);
254 goto free_dpi_map;
255 }
256
257 /* Allocate bitmap for toggle bit for cq icids
258 * We toggle the bit every time we create or resize cq for a given icid.
259 * The maximum number of CQs is bounded to twice the number of QPs.
260 */
261 rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->toggle_bits,
Ram Amranie015d582017-04-30 11:49:08 +0300262 p_rdma_info->num_qps * 2, "Toggle");
Ram Amrani51ff1722016-10-01 21:59:57 +0300263 if (rc) {
264 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
265 "Failed to allocate toogle bits, rc = %d\n", rc);
266 goto free_cq_map;
267 }
268
269 /* Allocate bitmap for itids */
270 rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->tid_map,
Ram Amranie015d582017-04-30 11:49:08 +0300271 p_rdma_info->num_mrs, "MR");
Ram Amrani51ff1722016-10-01 21:59:57 +0300272 if (rc) {
273 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
274 "Failed to allocate itids bitmaps, rc = %d\n", rc);
275 goto free_toggle_map;
276 }
277
278 /* Allocate bitmap for cids used for qps. */
Ram Amranie015d582017-04-30 11:49:08 +0300279 rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->cid_map, num_cons,
280 "CID");
Ram Amrani51ff1722016-10-01 21:59:57 +0300281 if (rc) {
282 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
283 "Failed to allocate cid bitmap, rc = %d\n", rc);
284 goto free_tid_map;
285 }
286
Mintz, Yuvalbe086e72017-03-11 18:39:18 +0200287 /* Allocate bitmap for cids used for responders/requesters. */
Ram Amranie015d582017-04-30 11:49:08 +0300288 rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->real_cid_map, num_cons,
289 "REAL_CID");
Mintz, Yuvalbe086e72017-03-11 18:39:18 +0200290 if (rc) {
291 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
292 "Failed to allocate real cid bitmap, rc = %d\n", rc);
293 goto free_cid_map;
294 }
Ram Amrani51ff1722016-10-01 21:59:57 +0300295 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocation successful\n");
296 return 0;
297
Mintz, Yuvalbe086e72017-03-11 18:39:18 +0200298free_cid_map:
299 kfree(p_rdma_info->cid_map.bitmap);
Ram Amrani51ff1722016-10-01 21:59:57 +0300300free_tid_map:
301 kfree(p_rdma_info->tid_map.bitmap);
302free_toggle_map:
303 kfree(p_rdma_info->toggle_bits.bitmap);
304free_cq_map:
305 kfree(p_rdma_info->cq_map.bitmap);
306free_dpi_map:
307 kfree(p_rdma_info->dpi_map.bitmap);
308free_pd_map:
309 kfree(p_rdma_info->pd_map.bitmap);
310free_rdma_port:
311 kfree(p_rdma_info->port);
312free_rdma_dev:
313 kfree(p_rdma_info->dev);
314free_rdma_info:
315 kfree(p_rdma_info);
316
317 return rc;
318}
319
Ram Amranie015d582017-04-30 11:49:08 +0300320static void qed_rdma_bmap_free(struct qed_hwfn *p_hwfn,
321 struct qed_bmap *bmap, bool check)
322{
323 int weight = bitmap_weight(bmap->bitmap, bmap->max_count);
324 int last_line = bmap->max_count / (64 * 8);
325 int last_item = last_line * 8 +
326 DIV_ROUND_UP(bmap->max_count % (64 * 8), 64);
327 u64 *pmap = (u64 *)bmap->bitmap;
328 int line, item, offset;
329 u8 str_last_line[200] = { 0 };
330
331 if (!weight || !check)
332 goto end;
333
334 DP_NOTICE(p_hwfn,
335 "%s bitmap not free - size=%d, weight=%d, 512 bits per line\n",
336 bmap->name, bmap->max_count, weight);
337
338 /* print aligned non-zero lines, if any */
339 for (item = 0, line = 0; line < last_line; line++, item += 8)
340 if (bitmap_weight((unsigned long *)&pmap[item], 64 * 8))
341 DP_NOTICE(p_hwfn,
342 "line 0x%04x: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
343 line,
344 pmap[item],
345 pmap[item + 1],
346 pmap[item + 2],
347 pmap[item + 3],
348 pmap[item + 4],
349 pmap[item + 5],
350 pmap[item + 6], pmap[item + 7]);
351
352 /* print last unaligned non-zero line, if any */
353 if ((bmap->max_count % (64 * 8)) &&
354 (bitmap_weight((unsigned long *)&pmap[item],
355 bmap->max_count - item * 64))) {
356 offset = sprintf(str_last_line, "line 0x%04x: ", line);
357 for (; item < last_item; item++)
358 offset += sprintf(str_last_line + offset,
359 "0x%016llx ", pmap[item]);
360 DP_NOTICE(p_hwfn, "%s\n", str_last_line);
361 }
362
363end:
364 kfree(bmap->bitmap);
365 bmap->bitmap = NULL;
366}
367
Yuval Mintz0189efb2016-10-13 22:57:02 +0300368static void qed_rdma_resc_free(struct qed_hwfn *p_hwfn)
Ram Amrani51ff1722016-10-01 21:59:57 +0300369{
Mintz, Yuvalbe086e72017-03-11 18:39:18 +0200370 struct qed_bmap *rcid_map = &p_hwfn->p_rdma_info->real_cid_map;
Ram Amrani51ff1722016-10-01 21:59:57 +0300371 struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info;
Mintz, Yuvalbe086e72017-03-11 18:39:18 +0200372 int wait_count = 0;
373
374 /* when destroying a_RoCE QP the control is returned to the user after
375 * the synchronous part. The asynchronous part may take a little longer.
376 * We delay for a short while if an async destroy QP is still expected.
377 * Beyond the added delay we clear the bitmap anyway.
378 */
379 while (bitmap_weight(rcid_map->bitmap, rcid_map->max_count)) {
380 msleep(100);
381 if (wait_count++ > 20) {
382 DP_NOTICE(p_hwfn, "cid bitmap wait timed out\n");
383 break;
384 }
385 }
Ram Amrani51ff1722016-10-01 21:59:57 +0300386
Ram Amranie015d582017-04-30 11:49:08 +0300387 qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->cid_map, 1);
388 qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->pd_map, 1);
389 qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->dpi_map, 1);
390 qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->cq_map, 1);
391 qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->toggle_bits, 0);
392 qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->tid_map, 1);
Ram Amrani51ff1722016-10-01 21:59:57 +0300393
394 kfree(p_rdma_info->port);
395 kfree(p_rdma_info->dev);
396
397 kfree(p_rdma_info);
398}
399
400static void qed_rdma_free(struct qed_hwfn *p_hwfn)
401{
402 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Freeing RDMA\n");
403
404 qed_rdma_resc_free(p_hwfn);
405}
406
407static void qed_rdma_get_guid(struct qed_hwfn *p_hwfn, u8 *guid)
408{
409 guid[0] = p_hwfn->hw_info.hw_mac_addr[0] ^ 2;
410 guid[1] = p_hwfn->hw_info.hw_mac_addr[1];
411 guid[2] = p_hwfn->hw_info.hw_mac_addr[2];
412 guid[3] = 0xff;
413 guid[4] = 0xfe;
414 guid[5] = p_hwfn->hw_info.hw_mac_addr[3];
415 guid[6] = p_hwfn->hw_info.hw_mac_addr[4];
416 guid[7] = p_hwfn->hw_info.hw_mac_addr[5];
417}
418
419static void qed_rdma_init_events(struct qed_hwfn *p_hwfn,
420 struct qed_rdma_start_in_params *params)
421{
422 struct qed_rdma_events *events;
423
424 events = &p_hwfn->p_rdma_info->events;
425
426 events->unaffiliated_event = params->events->unaffiliated_event;
427 events->affiliated_event = params->events->affiliated_event;
428 events->context = params->events->context;
429}
430
431static void qed_rdma_init_devinfo(struct qed_hwfn *p_hwfn,
432 struct qed_rdma_start_in_params *params)
433{
434 struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
435 struct qed_dev *cdev = p_hwfn->cdev;
436 u32 pci_status_control;
437 u32 num_qps;
438
439 /* Vendor specific information */
440 dev->vendor_id = cdev->vendor_id;
441 dev->vendor_part_id = cdev->device_id;
442 dev->hw_ver = 0;
443 dev->fw_ver = (FW_MAJOR_VERSION << 24) | (FW_MINOR_VERSION << 16) |
444 (FW_REVISION_VERSION << 8) | (FW_ENGINEERING_VERSION);
445
446 qed_rdma_get_guid(p_hwfn, (u8 *)&dev->sys_image_guid);
447 dev->node_guid = dev->sys_image_guid;
448
449 dev->max_sge = min_t(u32, RDMA_MAX_SGE_PER_SQ_WQE,
450 RDMA_MAX_SGE_PER_RQ_WQE);
451
452 if (cdev->rdma_max_sge)
453 dev->max_sge = min_t(u32, cdev->rdma_max_sge, dev->max_sge);
454
455 dev->max_inline = ROCE_REQ_MAX_INLINE_DATA_SIZE;
456
457 dev->max_inline = (cdev->rdma_max_inline) ?
458 min_t(u32, cdev->rdma_max_inline, dev->max_inline) :
459 dev->max_inline;
460
461 dev->max_wqe = QED_RDMA_MAX_WQE;
462 dev->max_cnq = (u8)FEAT_NUM(p_hwfn, QED_RDMA_CNQ);
463
464 /* The number of QPs may be higher than QED_ROCE_MAX_QPS, because
465 * it is up-aligned to 16 and then to ILT page size within qed cxt.
466 * This is OK in terms of ILT but we don't want to configure the FW
467 * above its abilities
468 */
469 num_qps = ROCE_MAX_QPS;
470 num_qps = min_t(u64, num_qps, p_hwfn->p_rdma_info->num_qps);
471 dev->max_qp = num_qps;
472
473 /* CQs uses the same icids that QPs use hence they are limited by the
474 * number of icids. There are two icids per QP.
475 */
476 dev->max_cq = num_qps * 2;
477
478 /* The number of mrs is smaller by 1 since the first is reserved */
479 dev->max_mr = p_hwfn->p_rdma_info->num_mrs - 1;
480 dev->max_mr_size = QED_RDMA_MAX_MR_SIZE;
481
482 /* The maximum CQE capacity per CQ supported.
483 * max number of cqes will be in two layer pbl,
484 * 8 is the pointer size in bytes
485 * 32 is the size of cq element in bytes
486 */
487 if (params->cq_mode == QED_RDMA_CQ_MODE_32_BITS)
488 dev->max_cqe = QED_RDMA_MAX_CQE_32_BIT;
489 else
490 dev->max_cqe = QED_RDMA_MAX_CQE_16_BIT;
491
492 dev->max_mw = 0;
493 dev->max_fmr = QED_RDMA_MAX_FMR;
494 dev->max_mr_mw_fmr_pbl = (PAGE_SIZE / 8) * (PAGE_SIZE / 8);
495 dev->max_mr_mw_fmr_size = dev->max_mr_mw_fmr_pbl * PAGE_SIZE;
496 dev->max_pkey = QED_RDMA_MAX_P_KEY;
497
498 dev->max_qp_resp_rd_atomic_resc = RDMA_RING_PAGE_SIZE /
499 (RDMA_RESP_RD_ATOMIC_ELM_SIZE * 2);
500 dev->max_qp_req_rd_atomic_resc = RDMA_RING_PAGE_SIZE /
501 RDMA_REQ_RD_ATOMIC_ELM_SIZE;
502 dev->max_dev_resp_rd_atomic_resc = dev->max_qp_resp_rd_atomic_resc *
503 p_hwfn->p_rdma_info->num_qps;
504 dev->page_size_caps = QED_RDMA_PAGE_SIZE_CAPS;
505 dev->dev_ack_delay = QED_RDMA_ACK_DELAY;
506 dev->max_pd = RDMA_MAX_PDS;
507 dev->max_ah = p_hwfn->p_rdma_info->num_qps;
508 dev->max_stats_queues = (u8)RESC_NUM(p_hwfn, QED_RDMA_STATS_QUEUE);
509
510 /* Set capablities */
511 dev->dev_caps = 0;
512 SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_RNR_NAK, 1);
513 SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_PORT_ACTIVE_EVENT, 1);
514 SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_PORT_CHANGE_EVENT, 1);
515 SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_RESIZE_CQ, 1);
516 SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_BASE_MEMORY_EXT, 1);
517 SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_BASE_QUEUE_EXT, 1);
518 SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_ZBVA, 1);
519 SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_LOCAL_INV_FENCE, 1);
520
521 /* Check atomic operations support in PCI configuration space. */
522 pci_read_config_dword(cdev->pdev,
523 cdev->pdev->pcie_cap + PCI_EXP_DEVCTL2,
524 &pci_status_control);
525
526 if (pci_status_control & PCI_EXP_DEVCTL2_LTR_EN)
527 SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_ATOMIC_OP, 1);
528}
529
530static void qed_rdma_init_port(struct qed_hwfn *p_hwfn)
531{
532 struct qed_rdma_port *port = p_hwfn->p_rdma_info->port;
533 struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
534
535 port->port_state = p_hwfn->mcp_info->link_output.link_up ?
536 QED_RDMA_PORT_UP : QED_RDMA_PORT_DOWN;
537
538 port->max_msg_size = min_t(u64,
539 (dev->max_mr_mw_fmr_size *
540 p_hwfn->cdev->rdma_max_sge),
541 BIT(31));
542
543 port->pkey_bad_counter = 0;
544}
545
546static int qed_rdma_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
547{
548 u32 ll2_ethertype_en;
549
550 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Initializing HW\n");
551 p_hwfn->b_rdma_enabled_in_prs = false;
552
553 qed_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF, 0);
554
555 p_hwfn->rdma_prs_search_reg = PRS_REG_SEARCH_ROCE;
556
557 /* We delay writing to this reg until first cid is allocated. See
558 * qed_cxt_dynamic_ilt_alloc function for more details
559 */
560 ll2_ethertype_en = qed_rd(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN);
561 qed_wr(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN,
562 (ll2_ethertype_en | 0x01));
563
564 if (qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_ROCE) % 2) {
565 DP_NOTICE(p_hwfn, "The first RoCE's cid should be even\n");
566 return -EINVAL;
567 }
568
569 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Initializing HW - Done\n");
570 return 0;
571}
572
573static int qed_rdma_start_fw(struct qed_hwfn *p_hwfn,
574 struct qed_rdma_start_in_params *params,
575 struct qed_ptt *p_ptt)
576{
577 struct rdma_init_func_ramrod_data *p_ramrod;
578 struct qed_rdma_cnq_params *p_cnq_pbl_list;
579 struct rdma_init_func_hdr *p_params_header;
580 struct rdma_cnq_params *p_cnq_params;
581 struct qed_sp_init_data init_data;
582 struct qed_spq_entry *p_ent;
583 u32 cnq_id, sb_id;
584 int rc;
585
586 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Starting FW\n");
587
588 /* Save the number of cnqs for the function close ramrod */
589 p_hwfn->p_rdma_info->num_cnqs = params->desired_cnq;
590
591 /* Get SPQ entry */
592 memset(&init_data, 0, sizeof(init_data));
593 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
594 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
595
596 rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_FUNC_INIT,
597 p_hwfn->p_rdma_info->proto, &init_data);
598 if (rc)
599 return rc;
600
601 p_ramrod = &p_ent->ramrod.roce_init_func.rdma;
602
603 p_params_header = &p_ramrod->params_header;
604 p_params_header->cnq_start_offset = (u8)RESC_START(p_hwfn,
605 QED_RDMA_CNQ_RAM);
606 p_params_header->num_cnqs = params->desired_cnq;
607
608 if (params->cq_mode == QED_RDMA_CQ_MODE_16_BITS)
609 p_params_header->cq_ring_mode = 1;
610 else
611 p_params_header->cq_ring_mode = 0;
612
613 for (cnq_id = 0; cnq_id < params->desired_cnq; cnq_id++) {
614 sb_id = qed_rdma_get_sb_id(p_hwfn, cnq_id);
615 p_cnq_params = &p_ramrod->cnq_params[cnq_id];
616 p_cnq_pbl_list = &params->cnq_pbl_list[cnq_id];
617 p_cnq_params->sb_num =
618 cpu_to_le16(p_hwfn->sbs_info[sb_id]->igu_sb_id);
619
620 p_cnq_params->sb_index = p_hwfn->pf_params.rdma_pf_params.gl_pi;
621 p_cnq_params->num_pbl_pages = p_cnq_pbl_list->num_pbl_pages;
622
623 DMA_REGPAIR_LE(p_cnq_params->pbl_base_addr,
624 p_cnq_pbl_list->pbl_ptr);
625
626 /* we assume here that cnq_id and qz_offset are the same */
627 p_cnq_params->queue_zone_num =
628 cpu_to_le16(p_hwfn->p_rdma_info->queue_zone_base +
629 cnq_id);
630 }
631
632 return qed_spq_post(p_hwfn, p_ent, NULL);
633}
634
Yuval Mintz0189efb2016-10-13 22:57:02 +0300635static int qed_rdma_alloc_tid(void *rdma_cxt, u32 *itid)
636{
637 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
638 int rc;
639
640 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID\n");
641
642 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
643 rc = qed_rdma_bmap_alloc_id(p_hwfn,
644 &p_hwfn->p_rdma_info->tid_map, itid);
645 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
646 if (rc)
647 goto out;
648
649 rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_TASK, *itid);
650out:
651 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID - done, rc = %d\n", rc);
652 return rc;
653}
654
Ram Amrani51ff1722016-10-01 21:59:57 +0300655static int qed_rdma_reserve_lkey(struct qed_hwfn *p_hwfn)
656{
657 struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
658
659 /* The first DPI is reserved for the Kernel */
660 __set_bit(0, p_hwfn->p_rdma_info->dpi_map.bitmap);
661
662 /* Tid 0 will be used as the key for "reserved MR".
663 * The driver should allocate memory for it so it can be loaded but no
664 * ramrod should be passed on it.
665 */
666 qed_rdma_alloc_tid(p_hwfn, &dev->reserved_lkey);
667 if (dev->reserved_lkey != RDMA_RESERVED_LKEY) {
668 DP_NOTICE(p_hwfn,
669 "Reserved lkey should be equal to RDMA_RESERVED_LKEY\n");
670 return -EINVAL;
671 }
672
673 return 0;
674}
675
676static int qed_rdma_setup(struct qed_hwfn *p_hwfn,
677 struct qed_ptt *p_ptt,
678 struct qed_rdma_start_in_params *params)
679{
680 int rc;
681
682 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA setup\n");
683
684 spin_lock_init(&p_hwfn->p_rdma_info->lock);
685
686 qed_rdma_init_devinfo(p_hwfn, params);
687 qed_rdma_init_port(p_hwfn);
688 qed_rdma_init_events(p_hwfn, params);
689
690 rc = qed_rdma_reserve_lkey(p_hwfn);
691 if (rc)
692 return rc;
693
694 rc = qed_rdma_init_hw(p_hwfn, p_ptt);
695 if (rc)
696 return rc;
697
698 return qed_rdma_start_fw(p_hwfn, params, p_ptt);
699}
700
Yuval Mintz0189efb2016-10-13 22:57:02 +0300701static int qed_rdma_stop(void *rdma_cxt)
Ram Amrani51ff1722016-10-01 21:59:57 +0300702{
703 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
704 struct rdma_close_func_ramrod_data *p_ramrod;
705 struct qed_sp_init_data init_data;
706 struct qed_spq_entry *p_ent;
707 struct qed_ptt *p_ptt;
708 u32 ll2_ethertype_en;
709 int rc = -EBUSY;
710
711 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA stop\n");
712
713 p_ptt = qed_ptt_acquire(p_hwfn);
714 if (!p_ptt) {
715 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Failed to acquire PTT\n");
716 return rc;
717 }
718
719 /* Disable RoCE search */
720 qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 0);
721 p_hwfn->b_rdma_enabled_in_prs = false;
722
723 qed_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF, 0);
724
725 ll2_ethertype_en = qed_rd(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN);
726
727 qed_wr(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN,
728 (ll2_ethertype_en & 0xFFFE));
729
730 qed_ptt_release(p_hwfn, p_ptt);
731
732 /* Get SPQ entry */
733 memset(&init_data, 0, sizeof(init_data));
734 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
735 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
736
737 /* Stop RoCE */
738 rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_FUNC_CLOSE,
739 p_hwfn->p_rdma_info->proto, &init_data);
740 if (rc)
741 goto out;
742
743 p_ramrod = &p_ent->ramrod.rdma_close_func;
744
745 p_ramrod->num_cnqs = p_hwfn->p_rdma_info->num_cnqs;
746 p_ramrod->cnq_start_offset = (u8)RESC_START(p_hwfn, QED_RDMA_CNQ_RAM);
747
748 rc = qed_spq_post(p_hwfn, p_ent, NULL);
749
750out:
751 qed_rdma_free(p_hwfn);
752
753 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA stop done, rc = %d\n", rc);
754 return rc;
755}
756
Yuval Mintz0189efb2016-10-13 22:57:02 +0300757static int qed_rdma_add_user(void *rdma_cxt,
758 struct qed_rdma_add_user_out_params *out_params)
Ram Amrani51ff1722016-10-01 21:59:57 +0300759{
760 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
761 u32 dpi_start_offset;
762 u32 returned_id = 0;
763 int rc;
764
765 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Adding User\n");
766
767 /* Allocate DPI */
768 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
769 rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_hwfn->p_rdma_info->dpi_map,
770 &returned_id);
771 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
772
773 out_params->dpi = (u16)returned_id;
774
775 /* Calculate the corresponding DPI address */
776 dpi_start_offset = p_hwfn->dpi_start_offset;
777
778 out_params->dpi_addr = (u64)((u8 __iomem *)p_hwfn->doorbells +
779 dpi_start_offset +
780 ((out_params->dpi) * p_hwfn->dpi_size));
781
782 out_params->dpi_phys_addr = p_hwfn->cdev->db_phys_addr +
783 dpi_start_offset +
784 ((out_params->dpi) * p_hwfn->dpi_size);
785
786 out_params->dpi_size = p_hwfn->dpi_size;
787
788 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Adding user - done, rc = %d\n", rc);
789 return rc;
790}
791
Yuval Mintz0189efb2016-10-13 22:57:02 +0300792static struct qed_rdma_port *qed_rdma_query_port(void *rdma_cxt)
Ram Amranic295f862016-10-01 21:59:58 +0300793{
794 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
795 struct qed_rdma_port *p_port = p_hwfn->p_rdma_info->port;
796
797 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA Query port\n");
798
799 /* Link may have changed */
800 p_port->port_state = p_hwfn->mcp_info->link_output.link_up ?
801 QED_RDMA_PORT_UP : QED_RDMA_PORT_DOWN;
802
803 p_port->link_speed = p_hwfn->mcp_info->link_output.speed;
804
Ram Amrani793ea8a2017-04-30 11:49:05 +0300805 p_port->max_msg_size = RDMA_MAX_DATA_SIZE_IN_WQE;
806
Ram Amranic295f862016-10-01 21:59:58 +0300807 return p_port;
808}
809
Yuval Mintz0189efb2016-10-13 22:57:02 +0300810static struct qed_rdma_device *qed_rdma_query_device(void *rdma_cxt)
Ram Amrani51ff1722016-10-01 21:59:57 +0300811{
812 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
813
814 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Query device\n");
815
816 /* Return struct with device parameters */
817 return p_hwfn->p_rdma_info->dev;
818}
819
Yuval Mintz0189efb2016-10-13 22:57:02 +0300820static void qed_rdma_free_tid(void *rdma_cxt, u32 itid)
Ram Amraniee8eaea2016-10-01 22:00:00 +0300821{
822 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
823
824 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", itid);
825
826 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
827 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->tid_map, itid);
828 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
829}
830
Yuval Mintz0189efb2016-10-13 22:57:02 +0300831static void qed_rdma_cnq_prod_update(void *rdma_cxt, u8 qz_offset, u16 prod)
Ram Amrani51ff1722016-10-01 21:59:57 +0300832{
833 struct qed_hwfn *p_hwfn;
834 u16 qz_num;
835 u32 addr;
836
837 p_hwfn = (struct qed_hwfn *)rdma_cxt;
Mintz, Yuvalbe086e72017-03-11 18:39:18 +0200838
839 if (qz_offset > p_hwfn->p_rdma_info->max_queue_zones) {
840 DP_NOTICE(p_hwfn,
841 "queue zone offset %d is too large (max is %d)\n",
842 qz_offset, p_hwfn->p_rdma_info->max_queue_zones);
843 return;
844 }
845
Ram Amrani51ff1722016-10-01 21:59:57 +0300846 qz_num = p_hwfn->p_rdma_info->queue_zone_base + qz_offset;
847 addr = GTT_BAR0_MAP_REG_USDM_RAM +
848 USTORM_COMMON_QUEUE_CONS_OFFSET(qz_num);
849
850 REG_WR16(p_hwfn, addr, prod);
851
852 /* keep prod updates ordered */
853 wmb();
854}
855
856static int qed_fill_rdma_dev_info(struct qed_dev *cdev,
857 struct qed_dev_rdma_info *info)
858{
859 memset(info, 0, sizeof(*info));
860
861 info->rdma_type = QED_RDMA_TYPE_ROCE;
862
863 qed_fill_dev_info(cdev, &info->common);
864
865 return 0;
866}
867
868static int qed_rdma_get_sb_start(struct qed_dev *cdev)
869{
870 int feat_num;
871
872 if (cdev->num_hwfns > 1)
873 feat_num = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_PF_L2_QUE);
874 else
875 feat_num = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_PF_L2_QUE) *
876 cdev->num_hwfns;
877
878 return feat_num;
879}
880
881static int qed_rdma_get_min_cnq_msix(struct qed_dev *cdev)
882{
883 int n_cnq = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_RDMA_CNQ);
884 int n_msix = cdev->int_params.rdma_msix_cnt;
885
886 return min_t(int, n_cnq, n_msix);
887}
888
889static int qed_rdma_set_int(struct qed_dev *cdev, u16 cnt)
890{
891 int limit = 0;
892
893 /* Mark the fastpath as free/used */
894 cdev->int_params.fp_initialized = cnt ? true : false;
895
896 if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX) {
897 DP_ERR(cdev,
898 "qed roce supports only MSI-X interrupts (detected %d).\n",
899 cdev->int_params.out.int_mode);
900 return -EINVAL;
901 } else if (cdev->int_params.fp_msix_cnt) {
902 limit = cdev->int_params.rdma_msix_cnt;
903 }
904
905 if (!limit)
906 return -ENOMEM;
907
908 return min_t(int, cnt, limit);
909}
910
911static int qed_rdma_get_int(struct qed_dev *cdev, struct qed_int_info *info)
912{
913 memset(info, 0, sizeof(*info));
914
915 if (!cdev->int_params.fp_initialized) {
916 DP_INFO(cdev,
917 "Protocol driver requested interrupt information, but its support is not yet configured\n");
918 return -EINVAL;
919 }
920
921 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
922 int msix_base = cdev->int_params.rdma_msix_base;
923
924 info->msix_cnt = cdev->int_params.rdma_msix_cnt;
925 info->msix = &cdev->int_params.msix_table[msix_base];
926
927 DP_VERBOSE(cdev, QED_MSG_RDMA, "msix_cnt = %d msix_base=%d\n",
928 info->msix_cnt, msix_base);
929 }
930
931 return 0;
932}
933
Yuval Mintz0189efb2016-10-13 22:57:02 +0300934static int qed_rdma_alloc_pd(void *rdma_cxt, u16 *pd)
Ram Amranic295f862016-10-01 21:59:58 +0300935{
936 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
937 u32 returned_id;
938 int rc;
939
940 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Alloc PD\n");
941
942 /* Allocates an unused protection domain */
943 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
944 rc = qed_rdma_bmap_alloc_id(p_hwfn,
945 &p_hwfn->p_rdma_info->pd_map, &returned_id);
946 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
947
948 *pd = (u16)returned_id;
949
950 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Alloc PD - done, rc = %d\n", rc);
951 return rc;
952}
953
Yuval Mintz8c93bea2016-10-13 22:57:03 +0300954static void qed_rdma_free_pd(void *rdma_cxt, u16 pd)
Ram Amranic295f862016-10-01 21:59:58 +0300955{
956 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
957
958 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "pd = %08x\n", pd);
959
960 /* Returns a previously allocated protection domain for reuse */
961 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
962 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->pd_map, pd);
963 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
964}
965
966static enum qed_rdma_toggle_bit
967qed_rdma_toggle_bit_create_resize_cq(struct qed_hwfn *p_hwfn, u16 icid)
968{
969 struct qed_rdma_info *p_info = p_hwfn->p_rdma_info;
970 enum qed_rdma_toggle_bit toggle_bit;
971 u32 bmap_id;
972
973 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", icid);
974
975 /* the function toggle the bit that is related to a given icid
976 * and returns the new toggle bit's value
977 */
978 bmap_id = icid - qed_cxt_get_proto_cid_start(p_hwfn, p_info->proto);
979
980 spin_lock_bh(&p_info->lock);
981 toggle_bit = !test_and_change_bit(bmap_id,
982 p_info->toggle_bits.bitmap);
983 spin_unlock_bh(&p_info->lock);
984
985 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QED_RDMA_TOGGLE_BIT_= %d\n",
986 toggle_bit);
987
988 return toggle_bit;
989}
990
Yuval Mintz8c93bea2016-10-13 22:57:03 +0300991static int qed_rdma_create_cq(void *rdma_cxt,
992 struct qed_rdma_create_cq_in_params *params,
993 u16 *icid)
Ram Amranic295f862016-10-01 21:59:58 +0300994{
995 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
996 struct qed_rdma_info *p_info = p_hwfn->p_rdma_info;
997 struct rdma_create_cq_ramrod_data *p_ramrod;
998 enum qed_rdma_toggle_bit toggle_bit;
999 struct qed_sp_init_data init_data;
1000 struct qed_spq_entry *p_ent;
1001 u32 returned_id, start_cid;
1002 int rc;
1003
1004 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "cq_handle = %08x%08x\n",
1005 params->cq_handle_hi, params->cq_handle_lo);
1006
1007 /* Allocate icid */
1008 spin_lock_bh(&p_info->lock);
Ram Amranie015d582017-04-30 11:49:08 +03001009 rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_info->cq_map, &returned_id);
Ram Amranic295f862016-10-01 21:59:58 +03001010 spin_unlock_bh(&p_info->lock);
1011
1012 if (rc) {
1013 DP_NOTICE(p_hwfn, "Can't create CQ, rc = %d\n", rc);
1014 return rc;
1015 }
1016
1017 start_cid = qed_cxt_get_proto_cid_start(p_hwfn,
1018 p_info->proto);
1019 *icid = returned_id + start_cid;
1020
1021 /* Check if icid requires a page allocation */
1022 rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, *icid);
1023 if (rc)
1024 goto err;
1025
1026 /* Get SPQ entry */
1027 memset(&init_data, 0, sizeof(init_data));
1028 init_data.cid = *icid;
1029 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1030 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1031
1032 /* Send create CQ ramrod */
1033 rc = qed_sp_init_request(p_hwfn, &p_ent,
1034 RDMA_RAMROD_CREATE_CQ,
1035 p_info->proto, &init_data);
1036 if (rc)
1037 goto err;
1038
1039 p_ramrod = &p_ent->ramrod.rdma_create_cq;
1040
1041 p_ramrod->cq_handle.hi = cpu_to_le32(params->cq_handle_hi);
1042 p_ramrod->cq_handle.lo = cpu_to_le32(params->cq_handle_lo);
1043 p_ramrod->dpi = cpu_to_le16(params->dpi);
1044 p_ramrod->is_two_level_pbl = params->pbl_two_level;
1045 p_ramrod->max_cqes = cpu_to_le32(params->cq_size);
1046 DMA_REGPAIR_LE(p_ramrod->pbl_addr, params->pbl_ptr);
1047 p_ramrod->pbl_num_pages = cpu_to_le16(params->pbl_num_pages);
1048 p_ramrod->cnq_id = (u8)RESC_START(p_hwfn, QED_RDMA_CNQ_RAM) +
1049 params->cnq_id;
1050 p_ramrod->int_timeout = params->int_timeout;
1051
1052 /* toggle the bit for every resize or create cq for a given icid */
1053 toggle_bit = qed_rdma_toggle_bit_create_resize_cq(p_hwfn, *icid);
1054
1055 p_ramrod->toggle_bit = toggle_bit;
1056
1057 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1058 if (rc) {
1059 /* restore toggle bit */
1060 qed_rdma_toggle_bit_create_resize_cq(p_hwfn, *icid);
1061 goto err;
1062 }
1063
1064 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Created CQ, rc = %d\n", rc);
1065 return rc;
1066
1067err:
1068 /* release allocated icid */
Ram Amrani670dde52017-02-20 22:43:30 +02001069 spin_lock_bh(&p_info->lock);
Ram Amranic295f862016-10-01 21:59:58 +03001070 qed_bmap_release_id(p_hwfn, &p_info->cq_map, returned_id);
Ram Amrani670dde52017-02-20 22:43:30 +02001071 spin_unlock_bh(&p_info->lock);
Ram Amranic295f862016-10-01 21:59:58 +03001072 DP_NOTICE(p_hwfn, "Create CQ failed, rc = %d\n", rc);
1073
1074 return rc;
1075}
1076
Yuval Mintz8c93bea2016-10-13 22:57:03 +03001077static int
1078qed_rdma_destroy_cq(void *rdma_cxt,
1079 struct qed_rdma_destroy_cq_in_params *in_params,
1080 struct qed_rdma_destroy_cq_out_params *out_params)
Ram Amranic295f862016-10-01 21:59:58 +03001081{
1082 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
1083 struct rdma_destroy_cq_output_params *p_ramrod_res;
1084 struct rdma_destroy_cq_ramrod_data *p_ramrod;
1085 struct qed_sp_init_data init_data;
1086 struct qed_spq_entry *p_ent;
1087 dma_addr_t ramrod_res_phys;
1088 int rc = -ENOMEM;
1089
1090 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", in_params->icid);
1091
1092 p_ramrod_res =
1093 (struct rdma_destroy_cq_output_params *)
1094 dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
1095 sizeof(struct rdma_destroy_cq_output_params),
1096 &ramrod_res_phys, GFP_KERNEL);
1097 if (!p_ramrod_res) {
1098 DP_NOTICE(p_hwfn,
1099 "qed destroy cq failed: cannot allocate memory (ramrod)\n");
1100 return rc;
1101 }
1102
1103 /* Get SPQ entry */
1104 memset(&init_data, 0, sizeof(init_data));
1105 init_data.cid = in_params->icid;
1106 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1107 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1108
1109 /* Send destroy CQ ramrod */
1110 rc = qed_sp_init_request(p_hwfn, &p_ent,
1111 RDMA_RAMROD_DESTROY_CQ,
1112 p_hwfn->p_rdma_info->proto, &init_data);
1113 if (rc)
1114 goto err;
1115
1116 p_ramrod = &p_ent->ramrod.rdma_destroy_cq;
1117 DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys);
1118
1119 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1120 if (rc)
1121 goto err;
1122
1123 out_params->num_cq_notif = le16_to_cpu(p_ramrod_res->cnq_num);
1124
1125 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1126 sizeof(struct rdma_destroy_cq_output_params),
1127 p_ramrod_res, ramrod_res_phys);
1128
1129 /* Free icid */
1130 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
1131
1132 qed_bmap_release_id(p_hwfn,
1133 &p_hwfn->p_rdma_info->cq_map,
1134 (in_params->icid -
1135 qed_cxt_get_proto_cid_start(p_hwfn,
1136 p_hwfn->
1137 p_rdma_info->proto)));
1138
1139 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
1140
1141 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Destroyed CQ, rc = %d\n", rc);
1142 return rc;
1143
1144err: dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1145 sizeof(struct rdma_destroy_cq_output_params),
1146 p_ramrod_res, ramrod_res_phys);
1147
1148 return rc;
1149}
1150
Ram Amranif1093942016-10-01 21:59:59 +03001151static void qed_rdma_set_fw_mac(u16 *p_fw_mac, u8 *p_qed_mac)
1152{
1153 p_fw_mac[0] = cpu_to_le16((p_qed_mac[0] << 8) + p_qed_mac[1]);
1154 p_fw_mac[1] = cpu_to_le16((p_qed_mac[2] << 8) + p_qed_mac[3]);
1155 p_fw_mac[2] = cpu_to_le16((p_qed_mac[4] << 8) + p_qed_mac[5]);
1156}
1157
1158static void qed_rdma_copy_gids(struct qed_rdma_qp *qp, __le32 *src_gid,
1159 __le32 *dst_gid)
1160{
1161 u32 i;
1162
1163 if (qp->roce_mode == ROCE_V2_IPV4) {
1164 /* The IPv4 addresses shall be aligned to the highest word.
1165 * The lower words must be zero.
1166 */
1167 memset(src_gid, 0, sizeof(union qed_gid));
1168 memset(dst_gid, 0, sizeof(union qed_gid));
1169 src_gid[3] = cpu_to_le32(qp->sgid.ipv4_addr);
1170 dst_gid[3] = cpu_to_le32(qp->dgid.ipv4_addr);
1171 } else {
1172 /* GIDs and IPv6 addresses coincide in location and size */
1173 for (i = 0; i < ARRAY_SIZE(qp->sgid.dwords); i++) {
1174 src_gid[i] = cpu_to_le32(qp->sgid.dwords[i]);
1175 dst_gid[i] = cpu_to_le32(qp->dgid.dwords[i]);
1176 }
1177 }
1178}
1179
1180static enum roce_flavor qed_roce_mode_to_flavor(enum roce_mode roce_mode)
1181{
1182 enum roce_flavor flavor;
1183
1184 switch (roce_mode) {
1185 case ROCE_V1:
1186 flavor = PLAIN_ROCE;
1187 break;
1188 case ROCE_V2_IPV4:
1189 flavor = RROCE_IPV4;
1190 break;
1191 case ROCE_V2_IPV6:
1192 flavor = ROCE_V2_IPV6;
1193 break;
1194 default:
1195 flavor = MAX_ROCE_MODE;
1196 break;
1197 }
1198 return flavor;
1199}
1200
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001201void qed_roce_free_cid_pair(struct qed_hwfn *p_hwfn, u16 cid)
1202{
1203 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
1204 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid);
1205 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid + 1);
1206 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
1207}
1208
Yuval Mintz8c93bea2016-10-13 22:57:03 +03001209static int qed_roce_alloc_cid(struct qed_hwfn *p_hwfn, u16 *cid)
Ram Amranif1093942016-10-01 21:59:59 +03001210{
1211 struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info;
1212 u32 responder_icid;
1213 u32 requester_icid;
1214 int rc;
1215
1216 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
1217 rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_rdma_info->cid_map,
1218 &responder_icid);
1219 if (rc) {
1220 spin_unlock_bh(&p_rdma_info->lock);
1221 return rc;
1222 }
1223
1224 rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_rdma_info->cid_map,
1225 &requester_icid);
1226
1227 spin_unlock_bh(&p_rdma_info->lock);
1228 if (rc)
1229 goto err;
1230
1231 /* the two icid's should be adjacent */
1232 if ((requester_icid - responder_icid) != 1) {
1233 DP_NOTICE(p_hwfn, "Failed to allocate two adjacent qp's'\n");
1234 rc = -EINVAL;
1235 goto err;
1236 }
1237
1238 responder_icid += qed_cxt_get_proto_cid_start(p_hwfn,
1239 p_rdma_info->proto);
1240 requester_icid += qed_cxt_get_proto_cid_start(p_hwfn,
1241 p_rdma_info->proto);
1242
1243 /* If these icids require a new ILT line allocate DMA-able context for
1244 * an ILT page
1245 */
1246 rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, responder_icid);
1247 if (rc)
1248 goto err;
1249
1250 rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, requester_icid);
1251 if (rc)
1252 goto err;
1253
1254 *cid = (u16)responder_icid;
1255 return rc;
1256
1257err:
1258 spin_lock_bh(&p_rdma_info->lock);
1259 qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, responder_icid);
1260 qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, requester_icid);
1261
1262 spin_unlock_bh(&p_rdma_info->lock);
1263 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1264 "Allocate CID - failed, rc = %d\n", rc);
1265 return rc;
1266}
1267
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001268static void qed_roce_set_real_cid(struct qed_hwfn *p_hwfn, u32 cid)
1269{
1270 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
1271 qed_bmap_set_id(p_hwfn, &p_hwfn->p_rdma_info->real_cid_map, cid);
1272 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
1273}
1274
Ram Amranif1093942016-10-01 21:59:59 +03001275static int qed_roce_sp_create_responder(struct qed_hwfn *p_hwfn,
1276 struct qed_rdma_qp *qp)
1277{
1278 struct roce_create_qp_resp_ramrod_data *p_ramrod;
1279 struct qed_sp_init_data init_data;
Ram Amranif1093942016-10-01 21:59:59 +03001280 enum roce_flavor roce_flavor;
1281 struct qed_spq_entry *p_ent;
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001282 u16 regular_latency_queue;
1283 enum protocol_type proto;
Ram Amranif1093942016-10-01 21:59:59 +03001284 int rc;
1285
1286 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
1287
1288 /* Allocate DMA-able memory for IRQ */
1289 qp->irq_num_pages = 1;
1290 qp->irq = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
1291 RDMA_RING_PAGE_SIZE,
1292 &qp->irq_phys_addr, GFP_KERNEL);
1293 if (!qp->irq) {
1294 rc = -ENOMEM;
1295 DP_NOTICE(p_hwfn,
1296 "qed create responder failed: cannot allocate memory (irq). rc = %d\n",
1297 rc);
1298 return rc;
1299 }
1300
1301 /* Get SPQ entry */
1302 memset(&init_data, 0, sizeof(init_data));
1303 init_data.cid = qp->icid;
1304 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1305 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1306
1307 rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_CREATE_QP,
1308 PROTOCOLID_ROCE, &init_data);
1309 if (rc)
1310 goto err;
1311
1312 p_ramrod = &p_ent->ramrod.roce_create_qp_resp;
1313
1314 p_ramrod->flags = 0;
1315
1316 roce_flavor = qed_roce_mode_to_flavor(qp->roce_mode);
1317 SET_FIELD(p_ramrod->flags,
1318 ROCE_CREATE_QP_RESP_RAMROD_DATA_ROCE_FLAVOR, roce_flavor);
1319
1320 SET_FIELD(p_ramrod->flags,
1321 ROCE_CREATE_QP_RESP_RAMROD_DATA_RDMA_RD_EN,
1322 qp->incoming_rdma_read_en);
1323
1324 SET_FIELD(p_ramrod->flags,
1325 ROCE_CREATE_QP_RESP_RAMROD_DATA_RDMA_WR_EN,
1326 qp->incoming_rdma_write_en);
1327
1328 SET_FIELD(p_ramrod->flags,
1329 ROCE_CREATE_QP_RESP_RAMROD_DATA_ATOMIC_EN,
1330 qp->incoming_atomic_en);
1331
1332 SET_FIELD(p_ramrod->flags,
1333 ROCE_CREATE_QP_RESP_RAMROD_DATA_E2E_FLOW_CONTROL_EN,
1334 qp->e2e_flow_control_en);
1335
1336 SET_FIELD(p_ramrod->flags,
1337 ROCE_CREATE_QP_RESP_RAMROD_DATA_SRQ_FLG, qp->use_srq);
1338
1339 SET_FIELD(p_ramrod->flags,
1340 ROCE_CREATE_QP_RESP_RAMROD_DATA_RESERVED_KEY_EN,
1341 qp->fmr_and_reserved_lkey);
1342
1343 SET_FIELD(p_ramrod->flags,
1344 ROCE_CREATE_QP_RESP_RAMROD_DATA_MIN_RNR_NAK_TIMER,
1345 qp->min_rnr_nak_timer);
1346
1347 p_ramrod->max_ird = qp->max_rd_atomic_resp;
1348 p_ramrod->traffic_class = qp->traffic_class_tos;
1349 p_ramrod->hop_limit = qp->hop_limit_ttl;
1350 p_ramrod->irq_num_pages = qp->irq_num_pages;
1351 p_ramrod->p_key = cpu_to_le16(qp->pkey);
1352 p_ramrod->flow_label = cpu_to_le32(qp->flow_label);
1353 p_ramrod->dst_qp_id = cpu_to_le32(qp->dest_qp);
1354 p_ramrod->mtu = cpu_to_le16(qp->mtu);
1355 p_ramrod->initial_psn = cpu_to_le32(qp->rq_psn);
1356 p_ramrod->pd = cpu_to_le16(qp->pd);
1357 p_ramrod->rq_num_pages = cpu_to_le16(qp->rq_num_pages);
1358 DMA_REGPAIR_LE(p_ramrod->rq_pbl_addr, qp->rq_pbl_ptr);
1359 DMA_REGPAIR_LE(p_ramrod->irq_pbl_addr, qp->irq_phys_addr);
1360 qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid);
1361 p_ramrod->qp_handle_for_async.hi = cpu_to_le32(qp->qp_handle_async.hi);
1362 p_ramrod->qp_handle_for_async.lo = cpu_to_le32(qp->qp_handle_async.lo);
1363 p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi);
1364 p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo);
Ram Amranif1093942016-10-01 21:59:59 +03001365 p_ramrod->cq_cid = cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) |
1366 qp->rq_cq_id);
1367
Ariel Eliorb5a9ee72017-04-03 12:21:09 +03001368 regular_latency_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
Ram Amranif1093942016-10-01 21:59:59 +03001369
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001370 p_ramrod->regular_latency_phy_queue =
1371 cpu_to_le16(regular_latency_queue);
1372 p_ramrod->low_latency_phy_queue =
1373 cpu_to_le16(regular_latency_queue);
1374
Ram Amranif1093942016-10-01 21:59:59 +03001375 p_ramrod->dpi = cpu_to_le16(qp->dpi);
1376
1377 qed_rdma_set_fw_mac(p_ramrod->remote_mac_addr, qp->remote_mac_addr);
1378 qed_rdma_set_fw_mac(p_ramrod->local_mac_addr, qp->local_mac_addr);
1379
1380 p_ramrod->udp_src_port = qp->udp_src_port;
1381 p_ramrod->vlan_id = cpu_to_le16(qp->vlan_id);
1382 p_ramrod->srq_id.srq_idx = cpu_to_le16(qp->srq_id);
1383 p_ramrod->srq_id.opaque_fid = cpu_to_le16(p_hwfn->hw_info.opaque_fid);
1384
1385 p_ramrod->stats_counter_id = RESC_START(p_hwfn, QED_RDMA_STATS_QUEUE) +
1386 qp->stats_queue;
1387
1388 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1389
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001390 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1391 "rc = %d regular physical queue = 0x%x\n", rc,
1392 regular_latency_queue);
Ram Amranif1093942016-10-01 21:59:59 +03001393
1394 if (rc)
1395 goto err;
1396
1397 qp->resp_offloaded = true;
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001398 qp->cq_prod = 0;
1399
1400 proto = p_hwfn->p_rdma_info->proto;
1401 qed_roce_set_real_cid(p_hwfn, qp->icid -
1402 qed_cxt_get_proto_cid_start(p_hwfn, proto));
Ram Amranif1093942016-10-01 21:59:59 +03001403
1404 return rc;
1405
1406err:
1407 DP_NOTICE(p_hwfn, "create responder - failed, rc = %d\n", rc);
1408 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1409 qp->irq_num_pages * RDMA_RING_PAGE_SIZE,
1410 qp->irq, qp->irq_phys_addr);
1411
1412 return rc;
1413}
1414
1415static int qed_roce_sp_create_requester(struct qed_hwfn *p_hwfn,
1416 struct qed_rdma_qp *qp)
1417{
1418 struct roce_create_qp_req_ramrod_data *p_ramrod;
1419 struct qed_sp_init_data init_data;
Ram Amranif1093942016-10-01 21:59:59 +03001420 enum roce_flavor roce_flavor;
1421 struct qed_spq_entry *p_ent;
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001422 u16 regular_latency_queue;
1423 enum protocol_type proto;
Ram Amranif1093942016-10-01 21:59:59 +03001424 int rc;
1425
1426 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
1427
1428 /* Allocate DMA-able memory for ORQ */
1429 qp->orq_num_pages = 1;
1430 qp->orq = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
1431 RDMA_RING_PAGE_SIZE,
1432 &qp->orq_phys_addr, GFP_KERNEL);
1433 if (!qp->orq) {
1434 rc = -ENOMEM;
1435 DP_NOTICE(p_hwfn,
1436 "qed create requester failed: cannot allocate memory (orq). rc = %d\n",
1437 rc);
1438 return rc;
1439 }
1440
1441 /* Get SPQ entry */
1442 memset(&init_data, 0, sizeof(init_data));
1443 init_data.cid = qp->icid + 1;
1444 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1445 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1446
1447 rc = qed_sp_init_request(p_hwfn, &p_ent,
1448 ROCE_RAMROD_CREATE_QP,
1449 PROTOCOLID_ROCE, &init_data);
1450 if (rc)
1451 goto err;
1452
1453 p_ramrod = &p_ent->ramrod.roce_create_qp_req;
1454
1455 p_ramrod->flags = 0;
1456
1457 roce_flavor = qed_roce_mode_to_flavor(qp->roce_mode);
1458 SET_FIELD(p_ramrod->flags,
1459 ROCE_CREATE_QP_REQ_RAMROD_DATA_ROCE_FLAVOR, roce_flavor);
1460
1461 SET_FIELD(p_ramrod->flags,
1462 ROCE_CREATE_QP_REQ_RAMROD_DATA_FMR_AND_RESERVED_EN,
1463 qp->fmr_and_reserved_lkey);
1464
1465 SET_FIELD(p_ramrod->flags,
1466 ROCE_CREATE_QP_REQ_RAMROD_DATA_SIGNALED_COMP, qp->signal_all);
1467
1468 SET_FIELD(p_ramrod->flags,
1469 ROCE_CREATE_QP_REQ_RAMROD_DATA_ERR_RETRY_CNT, qp->retry_cnt);
1470
1471 SET_FIELD(p_ramrod->flags,
1472 ROCE_CREATE_QP_REQ_RAMROD_DATA_RNR_NAK_CNT,
1473 qp->rnr_retry_cnt);
1474
1475 p_ramrod->max_ord = qp->max_rd_atomic_req;
1476 p_ramrod->traffic_class = qp->traffic_class_tos;
1477 p_ramrod->hop_limit = qp->hop_limit_ttl;
1478 p_ramrod->orq_num_pages = qp->orq_num_pages;
1479 p_ramrod->p_key = cpu_to_le16(qp->pkey);
1480 p_ramrod->flow_label = cpu_to_le32(qp->flow_label);
1481 p_ramrod->dst_qp_id = cpu_to_le32(qp->dest_qp);
1482 p_ramrod->ack_timeout_val = cpu_to_le32(qp->ack_timeout);
1483 p_ramrod->mtu = cpu_to_le16(qp->mtu);
1484 p_ramrod->initial_psn = cpu_to_le32(qp->sq_psn);
1485 p_ramrod->pd = cpu_to_le16(qp->pd);
1486 p_ramrod->sq_num_pages = cpu_to_le16(qp->sq_num_pages);
1487 DMA_REGPAIR_LE(p_ramrod->sq_pbl_addr, qp->sq_pbl_ptr);
1488 DMA_REGPAIR_LE(p_ramrod->orq_pbl_addr, qp->orq_phys_addr);
1489 qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid);
1490 p_ramrod->qp_handle_for_async.hi = cpu_to_le32(qp->qp_handle_async.hi);
1491 p_ramrod->qp_handle_for_async.lo = cpu_to_le32(qp->qp_handle_async.lo);
1492 p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi);
1493 p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo);
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001494 p_ramrod->cq_cid =
1495 cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->sq_cq_id);
Ram Amranif1093942016-10-01 21:59:59 +03001496
Ariel Eliorb5a9ee72017-04-03 12:21:09 +03001497 regular_latency_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
Ram Amranif1093942016-10-01 21:59:59 +03001498
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001499 p_ramrod->regular_latency_phy_queue =
1500 cpu_to_le16(regular_latency_queue);
1501 p_ramrod->low_latency_phy_queue =
1502 cpu_to_le16(regular_latency_queue);
1503
Ram Amranif1093942016-10-01 21:59:59 +03001504 p_ramrod->dpi = cpu_to_le16(qp->dpi);
1505
1506 qed_rdma_set_fw_mac(p_ramrod->remote_mac_addr, qp->remote_mac_addr);
1507 qed_rdma_set_fw_mac(p_ramrod->local_mac_addr, qp->local_mac_addr);
1508
1509 p_ramrod->udp_src_port = qp->udp_src_port;
1510 p_ramrod->vlan_id = cpu_to_le16(qp->vlan_id);
1511 p_ramrod->stats_counter_id = RESC_START(p_hwfn, QED_RDMA_STATS_QUEUE) +
1512 qp->stats_queue;
1513
1514 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1515
1516 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
1517
1518 if (rc)
1519 goto err;
1520
1521 qp->req_offloaded = true;
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001522 proto = p_hwfn->p_rdma_info->proto;
1523 qed_roce_set_real_cid(p_hwfn,
1524 qp->icid + 1 -
1525 qed_cxt_get_proto_cid_start(p_hwfn, proto));
Ram Amranif1093942016-10-01 21:59:59 +03001526
1527 return rc;
1528
1529err:
1530 DP_NOTICE(p_hwfn, "Create requested - failed, rc = %d\n", rc);
1531 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1532 qp->orq_num_pages * RDMA_RING_PAGE_SIZE,
1533 qp->orq, qp->orq_phys_addr);
1534 return rc;
1535}
1536
1537static int qed_roce_sp_modify_responder(struct qed_hwfn *p_hwfn,
1538 struct qed_rdma_qp *qp,
1539 bool move_to_err, u32 modify_flags)
1540{
1541 struct roce_modify_qp_resp_ramrod_data *p_ramrod;
1542 struct qed_sp_init_data init_data;
1543 struct qed_spq_entry *p_ent;
1544 int rc;
1545
1546 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
1547
1548 if (move_to_err && !qp->resp_offloaded)
1549 return 0;
1550
1551 /* Get SPQ entry */
1552 memset(&init_data, 0, sizeof(init_data));
1553 init_data.cid = qp->icid;
1554 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1555 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1556
1557 rc = qed_sp_init_request(p_hwfn, &p_ent,
1558 ROCE_EVENT_MODIFY_QP,
1559 PROTOCOLID_ROCE, &init_data);
1560 if (rc) {
1561 DP_NOTICE(p_hwfn, "rc = %d\n", rc);
1562 return rc;
1563 }
1564
1565 p_ramrod = &p_ent->ramrod.roce_modify_qp_resp;
1566
1567 p_ramrod->flags = 0;
1568
1569 SET_FIELD(p_ramrod->flags,
1570 ROCE_MODIFY_QP_RESP_RAMROD_DATA_MOVE_TO_ERR_FLG, move_to_err);
1571
1572 SET_FIELD(p_ramrod->flags,
1573 ROCE_MODIFY_QP_RESP_RAMROD_DATA_RDMA_RD_EN,
1574 qp->incoming_rdma_read_en);
1575
1576 SET_FIELD(p_ramrod->flags,
1577 ROCE_MODIFY_QP_RESP_RAMROD_DATA_RDMA_WR_EN,
1578 qp->incoming_rdma_write_en);
1579
1580 SET_FIELD(p_ramrod->flags,
1581 ROCE_MODIFY_QP_RESP_RAMROD_DATA_ATOMIC_EN,
1582 qp->incoming_atomic_en);
1583
1584 SET_FIELD(p_ramrod->flags,
1585 ROCE_CREATE_QP_RESP_RAMROD_DATA_E2E_FLOW_CONTROL_EN,
1586 qp->e2e_flow_control_en);
1587
1588 SET_FIELD(p_ramrod->flags,
1589 ROCE_MODIFY_QP_RESP_RAMROD_DATA_RDMA_OPS_EN_FLG,
1590 GET_FIELD(modify_flags,
1591 QED_RDMA_MODIFY_QP_VALID_RDMA_OPS_EN));
1592
1593 SET_FIELD(p_ramrod->flags,
1594 ROCE_MODIFY_QP_RESP_RAMROD_DATA_P_KEY_FLG,
1595 GET_FIELD(modify_flags, QED_ROCE_MODIFY_QP_VALID_PKEY));
1596
1597 SET_FIELD(p_ramrod->flags,
1598 ROCE_MODIFY_QP_RESP_RAMROD_DATA_ADDRESS_VECTOR_FLG,
1599 GET_FIELD(modify_flags,
1600 QED_ROCE_MODIFY_QP_VALID_ADDRESS_VECTOR));
1601
1602 SET_FIELD(p_ramrod->flags,
1603 ROCE_MODIFY_QP_RESP_RAMROD_DATA_MAX_IRD_FLG,
1604 GET_FIELD(modify_flags,
1605 QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_RESP));
1606
1607 SET_FIELD(p_ramrod->flags,
1608 ROCE_MODIFY_QP_RESP_RAMROD_DATA_MIN_RNR_NAK_TIMER_FLG,
1609 GET_FIELD(modify_flags,
1610 QED_ROCE_MODIFY_QP_VALID_MIN_RNR_NAK_TIMER));
1611
1612 p_ramrod->fields = 0;
1613 SET_FIELD(p_ramrod->fields,
1614 ROCE_MODIFY_QP_RESP_RAMROD_DATA_MIN_RNR_NAK_TIMER,
1615 qp->min_rnr_nak_timer);
1616
1617 p_ramrod->max_ird = qp->max_rd_atomic_resp;
1618 p_ramrod->traffic_class = qp->traffic_class_tos;
1619 p_ramrod->hop_limit = qp->hop_limit_ttl;
1620 p_ramrod->p_key = cpu_to_le16(qp->pkey);
1621 p_ramrod->flow_label = cpu_to_le32(qp->flow_label);
1622 p_ramrod->mtu = cpu_to_le16(qp->mtu);
1623 qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid);
1624 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1625
1626 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Modify responder, rc = %d\n", rc);
1627 return rc;
1628}
1629
1630static int qed_roce_sp_modify_requester(struct qed_hwfn *p_hwfn,
1631 struct qed_rdma_qp *qp,
1632 bool move_to_sqd,
1633 bool move_to_err, u32 modify_flags)
1634{
1635 struct roce_modify_qp_req_ramrod_data *p_ramrod;
1636 struct qed_sp_init_data init_data;
1637 struct qed_spq_entry *p_ent;
1638 int rc;
1639
1640 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
1641
1642 if (move_to_err && !(qp->req_offloaded))
1643 return 0;
1644
1645 /* Get SPQ entry */
1646 memset(&init_data, 0, sizeof(init_data));
1647 init_data.cid = qp->icid + 1;
1648 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1649 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1650
1651 rc = qed_sp_init_request(p_hwfn, &p_ent,
1652 ROCE_EVENT_MODIFY_QP,
1653 PROTOCOLID_ROCE, &init_data);
1654 if (rc) {
1655 DP_NOTICE(p_hwfn, "rc = %d\n", rc);
1656 return rc;
1657 }
1658
1659 p_ramrod = &p_ent->ramrod.roce_modify_qp_req;
1660
1661 p_ramrod->flags = 0;
1662
1663 SET_FIELD(p_ramrod->flags,
1664 ROCE_MODIFY_QP_REQ_RAMROD_DATA_MOVE_TO_ERR_FLG, move_to_err);
1665
1666 SET_FIELD(p_ramrod->flags,
1667 ROCE_MODIFY_QP_REQ_RAMROD_DATA_MOVE_TO_SQD_FLG, move_to_sqd);
1668
1669 SET_FIELD(p_ramrod->flags,
1670 ROCE_MODIFY_QP_REQ_RAMROD_DATA_EN_SQD_ASYNC_NOTIFY,
1671 qp->sqd_async);
1672
1673 SET_FIELD(p_ramrod->flags,
1674 ROCE_MODIFY_QP_REQ_RAMROD_DATA_P_KEY_FLG,
1675 GET_FIELD(modify_flags, QED_ROCE_MODIFY_QP_VALID_PKEY));
1676
1677 SET_FIELD(p_ramrod->flags,
1678 ROCE_MODIFY_QP_REQ_RAMROD_DATA_ADDRESS_VECTOR_FLG,
1679 GET_FIELD(modify_flags,
1680 QED_ROCE_MODIFY_QP_VALID_ADDRESS_VECTOR));
1681
1682 SET_FIELD(p_ramrod->flags,
1683 ROCE_MODIFY_QP_REQ_RAMROD_DATA_MAX_ORD_FLG,
1684 GET_FIELD(modify_flags,
1685 QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_REQ));
1686
1687 SET_FIELD(p_ramrod->flags,
1688 ROCE_MODIFY_QP_REQ_RAMROD_DATA_RNR_NAK_CNT_FLG,
1689 GET_FIELD(modify_flags,
1690 QED_ROCE_MODIFY_QP_VALID_RNR_RETRY_CNT));
1691
1692 SET_FIELD(p_ramrod->flags,
1693 ROCE_MODIFY_QP_REQ_RAMROD_DATA_ERR_RETRY_CNT_FLG,
1694 GET_FIELD(modify_flags, QED_ROCE_MODIFY_QP_VALID_RETRY_CNT));
1695
1696 SET_FIELD(p_ramrod->flags,
1697 ROCE_MODIFY_QP_REQ_RAMROD_DATA_ACK_TIMEOUT_FLG,
1698 GET_FIELD(modify_flags,
1699 QED_ROCE_MODIFY_QP_VALID_ACK_TIMEOUT));
1700
1701 p_ramrod->fields = 0;
1702 SET_FIELD(p_ramrod->fields,
1703 ROCE_MODIFY_QP_REQ_RAMROD_DATA_ERR_RETRY_CNT, qp->retry_cnt);
1704
1705 SET_FIELD(p_ramrod->fields,
1706 ROCE_MODIFY_QP_REQ_RAMROD_DATA_RNR_NAK_CNT,
1707 qp->rnr_retry_cnt);
1708
1709 p_ramrod->max_ord = qp->max_rd_atomic_req;
1710 p_ramrod->traffic_class = qp->traffic_class_tos;
1711 p_ramrod->hop_limit = qp->hop_limit_ttl;
1712 p_ramrod->p_key = cpu_to_le16(qp->pkey);
1713 p_ramrod->flow_label = cpu_to_le32(qp->flow_label);
1714 p_ramrod->ack_timeout_val = cpu_to_le32(qp->ack_timeout);
1715 p_ramrod->mtu = cpu_to_le16(qp->mtu);
1716 qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid);
1717 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1718
1719 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Modify requester, rc = %d\n", rc);
1720 return rc;
1721}
1722
1723static int qed_roce_sp_destroy_qp_responder(struct qed_hwfn *p_hwfn,
1724 struct qed_rdma_qp *qp,
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001725 u32 *num_invalidated_mw,
1726 u32 *cq_prod)
Ram Amranif1093942016-10-01 21:59:59 +03001727{
1728 struct roce_destroy_qp_resp_output_params *p_ramrod_res;
1729 struct roce_destroy_qp_resp_ramrod_data *p_ramrod;
1730 struct qed_sp_init_data init_data;
1731 struct qed_spq_entry *p_ent;
1732 dma_addr_t ramrod_res_phys;
1733 int rc;
1734
1735 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
1736
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001737 *num_invalidated_mw = 0;
1738 *cq_prod = qp->cq_prod;
1739
1740 if (!qp->resp_offloaded) {
1741 /* If a responder was never offload, we need to free the cids
1742 * allocated in create_qp as a FW async event will never arrive
1743 */
1744 u32 cid;
1745
1746 cid = qp->icid -
1747 qed_cxt_get_proto_cid_start(p_hwfn,
1748 p_hwfn->p_rdma_info->proto);
1749 qed_roce_free_cid_pair(p_hwfn, (u16)cid);
1750
Ram Amranif1093942016-10-01 21:59:59 +03001751 return 0;
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001752 }
Ram Amranif1093942016-10-01 21:59:59 +03001753
1754 /* Get SPQ entry */
1755 memset(&init_data, 0, sizeof(init_data));
1756 init_data.cid = qp->icid;
1757 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1758 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1759
1760 rc = qed_sp_init_request(p_hwfn, &p_ent,
1761 ROCE_RAMROD_DESTROY_QP,
1762 PROTOCOLID_ROCE, &init_data);
1763 if (rc)
1764 return rc;
1765
1766 p_ramrod = &p_ent->ramrod.roce_destroy_qp_resp;
1767
1768 p_ramrod_res = (struct roce_destroy_qp_resp_output_params *)
1769 dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_ramrod_res),
1770 &ramrod_res_phys, GFP_KERNEL);
1771
1772 if (!p_ramrod_res) {
1773 rc = -ENOMEM;
1774 DP_NOTICE(p_hwfn,
1775 "qed destroy responder failed: cannot allocate memory (ramrod). rc = %d\n",
1776 rc);
1777 return rc;
1778 }
1779
1780 DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys);
1781
1782 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1783 if (rc)
1784 goto err;
1785
1786 *num_invalidated_mw = le32_to_cpu(p_ramrod_res->num_invalidated_mw);
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001787 *cq_prod = le32_to_cpu(p_ramrod_res->cq_prod);
1788 qp->cq_prod = *cq_prod;
Ram Amranif1093942016-10-01 21:59:59 +03001789
1790 /* Free IRQ - only if ramrod succeeded, in case FW is still using it */
1791 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1792 qp->irq_num_pages * RDMA_RING_PAGE_SIZE,
1793 qp->irq, qp->irq_phys_addr);
1794
1795 qp->resp_offloaded = false;
1796
1797 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Destroy responder, rc = %d\n", rc);
1798
1799err:
1800 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1801 sizeof(struct roce_destroy_qp_resp_output_params),
1802 p_ramrod_res, ramrod_res_phys);
1803
1804 return rc;
1805}
1806
1807static int qed_roce_sp_destroy_qp_requester(struct qed_hwfn *p_hwfn,
1808 struct qed_rdma_qp *qp,
1809 u32 *num_bound_mw)
1810{
1811 struct roce_destroy_qp_req_output_params *p_ramrod_res;
1812 struct roce_destroy_qp_req_ramrod_data *p_ramrod;
1813 struct qed_sp_init_data init_data;
1814 struct qed_spq_entry *p_ent;
1815 dma_addr_t ramrod_res_phys;
1816 int rc = -ENOMEM;
1817
1818 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
1819
1820 if (!qp->req_offloaded)
1821 return 0;
1822
1823 p_ramrod_res = (struct roce_destroy_qp_req_output_params *)
1824 dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
1825 sizeof(*p_ramrod_res),
1826 &ramrod_res_phys, GFP_KERNEL);
1827 if (!p_ramrod_res) {
1828 DP_NOTICE(p_hwfn,
1829 "qed destroy requester failed: cannot allocate memory (ramrod)\n");
1830 return rc;
1831 }
1832
1833 /* Get SPQ entry */
1834 memset(&init_data, 0, sizeof(init_data));
1835 init_data.cid = qp->icid + 1;
1836 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1837 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1838
1839 rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_DESTROY_QP,
1840 PROTOCOLID_ROCE, &init_data);
1841 if (rc)
1842 goto err;
1843
1844 p_ramrod = &p_ent->ramrod.roce_destroy_qp_req;
1845 DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys);
1846
1847 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1848 if (rc)
1849 goto err;
1850
1851 *num_bound_mw = le32_to_cpu(p_ramrod_res->num_bound_mw);
1852
1853 /* Free ORQ - only if ramrod succeeded, in case FW is still using it */
1854 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1855 qp->orq_num_pages * RDMA_RING_PAGE_SIZE,
1856 qp->orq, qp->orq_phys_addr);
1857
1858 qp->req_offloaded = false;
1859
1860 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Destroy requester, rc = %d\n", rc);
1861
1862err:
1863 dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_ramrod_res),
1864 p_ramrod_res, ramrod_res_phys);
1865
1866 return rc;
1867}
1868
Yuval Mintz8c93bea2016-10-13 22:57:03 +03001869static int qed_roce_query_qp(struct qed_hwfn *p_hwfn,
1870 struct qed_rdma_qp *qp,
1871 struct qed_rdma_query_qp_out_params *out_params)
Ram Amranif1093942016-10-01 21:59:59 +03001872{
1873 struct roce_query_qp_resp_output_params *p_resp_ramrod_res;
1874 struct roce_query_qp_req_output_params *p_req_ramrod_res;
1875 struct roce_query_qp_resp_ramrod_data *p_resp_ramrod;
1876 struct roce_query_qp_req_ramrod_data *p_req_ramrod;
1877 struct qed_sp_init_data init_data;
1878 dma_addr_t resp_ramrod_res_phys;
1879 dma_addr_t req_ramrod_res_phys;
1880 struct qed_spq_entry *p_ent;
1881 bool rq_err_state;
1882 bool sq_err_state;
1883 bool sq_draining;
1884 int rc = -ENOMEM;
1885
1886 if ((!(qp->resp_offloaded)) && (!(qp->req_offloaded))) {
1887 /* We can't send ramrod to the fw since this qp wasn't offloaded
1888 * to the fw yet
1889 */
1890 out_params->draining = false;
1891 out_params->rq_psn = qp->rq_psn;
1892 out_params->sq_psn = qp->sq_psn;
1893 out_params->state = qp->cur_state;
1894
1895 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "No QPs as no offload\n");
1896 return 0;
1897 }
1898
1899 if (!(qp->resp_offloaded)) {
1900 DP_NOTICE(p_hwfn,
1901 "The responder's qp should be offloded before requester's\n");
1902 return -EINVAL;
1903 }
1904
1905 /* Send a query responder ramrod to FW to get RQ-PSN and state */
1906 p_resp_ramrod_res = (struct roce_query_qp_resp_output_params *)
1907 dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
1908 sizeof(*p_resp_ramrod_res),
1909 &resp_ramrod_res_phys, GFP_KERNEL);
1910 if (!p_resp_ramrod_res) {
1911 DP_NOTICE(p_hwfn,
1912 "qed query qp failed: cannot allocate memory (ramrod)\n");
1913 return rc;
1914 }
1915
1916 /* Get SPQ entry */
1917 memset(&init_data, 0, sizeof(init_data));
1918 init_data.cid = qp->icid;
1919 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
1920 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
1921 rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_QUERY_QP,
1922 PROTOCOLID_ROCE, &init_data);
1923 if (rc)
1924 goto err_resp;
1925
1926 p_resp_ramrod = &p_ent->ramrod.roce_query_qp_resp;
1927 DMA_REGPAIR_LE(p_resp_ramrod->output_params_addr, resp_ramrod_res_phys);
1928
1929 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1930 if (rc)
1931 goto err_resp;
1932
Ram Amranif1093942016-10-01 21:59:59 +03001933 out_params->rq_psn = le32_to_cpu(p_resp_ramrod_res->psn);
1934 rq_err_state = GET_FIELD(le32_to_cpu(p_resp_ramrod_res->err_flag),
1935 ROCE_QUERY_QP_RESP_OUTPUT_PARAMS_ERROR_FLG);
1936
Ram Amranic5212b92017-02-20 22:43:31 +02001937 dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_resp_ramrod_res),
1938 p_resp_ramrod_res, resp_ramrod_res_phys);
1939
Ram Amranif1093942016-10-01 21:59:59 +03001940 if (!(qp->req_offloaded)) {
1941 /* Don't send query qp for the requester */
1942 out_params->sq_psn = qp->sq_psn;
1943 out_params->draining = false;
1944
1945 if (rq_err_state)
1946 qp->cur_state = QED_ROCE_QP_STATE_ERR;
1947
1948 out_params->state = qp->cur_state;
1949
1950 return 0;
1951 }
1952
1953 /* Send a query requester ramrod to FW to get SQ-PSN and state */
1954 p_req_ramrod_res = (struct roce_query_qp_req_output_params *)
1955 dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
1956 sizeof(*p_req_ramrod_res),
1957 &req_ramrod_res_phys,
1958 GFP_KERNEL);
1959 if (!p_req_ramrod_res) {
1960 rc = -ENOMEM;
1961 DP_NOTICE(p_hwfn,
1962 "qed query qp failed: cannot allocate memory (ramrod)\n");
1963 return rc;
1964 }
1965
1966 /* Get SPQ entry */
1967 init_data.cid = qp->icid + 1;
1968 rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_QUERY_QP,
1969 PROTOCOLID_ROCE, &init_data);
1970 if (rc)
1971 goto err_req;
1972
1973 p_req_ramrod = &p_ent->ramrod.roce_query_qp_req;
1974 DMA_REGPAIR_LE(p_req_ramrod->output_params_addr, req_ramrod_res_phys);
1975
1976 rc = qed_spq_post(p_hwfn, p_ent, NULL);
1977 if (rc)
1978 goto err_req;
1979
Ram Amranif1093942016-10-01 21:59:59 +03001980 out_params->sq_psn = le32_to_cpu(p_req_ramrod_res->psn);
1981 sq_err_state = GET_FIELD(le32_to_cpu(p_req_ramrod_res->flags),
1982 ROCE_QUERY_QP_REQ_OUTPUT_PARAMS_ERR_FLG);
1983 sq_draining =
1984 GET_FIELD(le32_to_cpu(p_req_ramrod_res->flags),
1985 ROCE_QUERY_QP_REQ_OUTPUT_PARAMS_SQ_DRAINING_FLG);
1986
Ram Amranic5212b92017-02-20 22:43:31 +02001987 dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_req_ramrod_res),
1988 p_req_ramrod_res, req_ramrod_res_phys);
1989
Ram Amranif1093942016-10-01 21:59:59 +03001990 out_params->draining = false;
1991
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02001992 if (rq_err_state || sq_err_state)
Ram Amranif1093942016-10-01 21:59:59 +03001993 qp->cur_state = QED_ROCE_QP_STATE_ERR;
Ram Amranif1093942016-10-01 21:59:59 +03001994 else if (sq_draining)
1995 out_params->draining = true;
1996 out_params->state = qp->cur_state;
1997
1998 return 0;
1999
2000err_req:
2001 dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_req_ramrod_res),
2002 p_req_ramrod_res, req_ramrod_res_phys);
2003 return rc;
2004err_resp:
2005 dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_resp_ramrod_res),
2006 p_resp_ramrod_res, resp_ramrod_res_phys);
2007 return rc;
2008}
2009
Yuval Mintz8c93bea2016-10-13 22:57:03 +03002010static int qed_roce_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
Ram Amranif1093942016-10-01 21:59:59 +03002011{
2012 u32 num_invalidated_mw = 0;
2013 u32 num_bound_mw = 0;
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02002014 u32 cq_prod;
Ram Amranif1093942016-10-01 21:59:59 +03002015 int rc;
2016
2017 /* Destroys the specified QP */
2018 if ((qp->cur_state != QED_ROCE_QP_STATE_RESET) &&
2019 (qp->cur_state != QED_ROCE_QP_STATE_ERR) &&
2020 (qp->cur_state != QED_ROCE_QP_STATE_INIT)) {
2021 DP_NOTICE(p_hwfn,
2022 "QP must be in error, reset or init state before destroying it\n");
2023 return -EINVAL;
2024 }
2025
Ram Amrani300c0d72017-02-20 22:43:32 +02002026 if (qp->cur_state != QED_ROCE_QP_STATE_RESET) {
2027 rc = qed_roce_sp_destroy_qp_responder(p_hwfn, qp,
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02002028 &num_invalidated_mw,
2029 &cq_prod);
Ram Amrani300c0d72017-02-20 22:43:32 +02002030 if (rc)
2031 return rc;
Ram Amranif1093942016-10-01 21:59:59 +03002032
Ram Amrani300c0d72017-02-20 22:43:32 +02002033 /* Send destroy requester ramrod */
2034 rc = qed_roce_sp_destroy_qp_requester(p_hwfn, qp,
2035 &num_bound_mw);
2036 if (rc)
2037 return rc;
Ram Amranif1093942016-10-01 21:59:59 +03002038
Ram Amrani300c0d72017-02-20 22:43:32 +02002039 if (num_invalidated_mw != num_bound_mw) {
2040 DP_NOTICE(p_hwfn,
2041 "number of invalidate memory windows is different from bounded ones\n");
2042 return -EINVAL;
2043 }
Ram Amranif1093942016-10-01 21:59:59 +03002044 }
2045
Ram Amranif1093942016-10-01 21:59:59 +03002046 return 0;
2047}
2048
Yuval Mintz0189efb2016-10-13 22:57:02 +03002049static int qed_rdma_query_qp(void *rdma_cxt,
2050 struct qed_rdma_qp *qp,
2051 struct qed_rdma_query_qp_out_params *out_params)
Ram Amranif1093942016-10-01 21:59:59 +03002052{
2053 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2054 int rc;
2055
2056 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
2057
2058 /* The following fields are filled in from qp and not FW as they can't
2059 * be modified by FW
2060 */
2061 out_params->mtu = qp->mtu;
2062 out_params->dest_qp = qp->dest_qp;
2063 out_params->incoming_atomic_en = qp->incoming_atomic_en;
2064 out_params->e2e_flow_control_en = qp->e2e_flow_control_en;
2065 out_params->incoming_rdma_read_en = qp->incoming_rdma_read_en;
2066 out_params->incoming_rdma_write_en = qp->incoming_rdma_write_en;
2067 out_params->dgid = qp->dgid;
2068 out_params->flow_label = qp->flow_label;
2069 out_params->hop_limit_ttl = qp->hop_limit_ttl;
2070 out_params->traffic_class_tos = qp->traffic_class_tos;
2071 out_params->timeout = qp->ack_timeout;
2072 out_params->rnr_retry = qp->rnr_retry_cnt;
2073 out_params->retry_cnt = qp->retry_cnt;
2074 out_params->min_rnr_nak_timer = qp->min_rnr_nak_timer;
2075 out_params->pkey_index = 0;
2076 out_params->max_rd_atomic = qp->max_rd_atomic_req;
2077 out_params->max_dest_rd_atomic = qp->max_rd_atomic_resp;
2078 out_params->sqd_async = qp->sqd_async;
2079
2080 rc = qed_roce_query_qp(p_hwfn, qp, out_params);
2081
2082 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Query QP, rc = %d\n", rc);
2083 return rc;
2084}
2085
Yuval Mintz0189efb2016-10-13 22:57:02 +03002086static int qed_rdma_destroy_qp(void *rdma_cxt, struct qed_rdma_qp *qp)
Ram Amranif1093942016-10-01 21:59:59 +03002087{
2088 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2089 int rc = 0;
2090
2091 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
2092
2093 rc = qed_roce_destroy_qp(p_hwfn, qp);
2094
2095 /* free qp params struct */
2096 kfree(qp);
2097
2098 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP destroyed\n");
2099 return rc;
2100}
2101
Yuval Mintz8c93bea2016-10-13 22:57:03 +03002102static struct qed_rdma_qp *
Ram Amranif1093942016-10-01 21:59:59 +03002103qed_rdma_create_qp(void *rdma_cxt,
2104 struct qed_rdma_create_qp_in_params *in_params,
2105 struct qed_rdma_create_qp_out_params *out_params)
2106{
2107 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2108 struct qed_rdma_qp *qp;
2109 u8 max_stats_queues;
2110 int rc;
2111
2112 if (!rdma_cxt || !in_params || !out_params || !p_hwfn->p_rdma_info) {
2113 DP_ERR(p_hwfn->cdev,
2114 "qed roce create qp failed due to NULL entry (rdma_cxt=%p, in=%p, out=%p, roce_info=?\n",
2115 rdma_cxt, in_params, out_params);
2116 return NULL;
2117 }
2118
2119 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2120 "qed rdma create qp called with qp_handle = %08x%08x\n",
2121 in_params->qp_handle_hi, in_params->qp_handle_lo);
2122
2123 /* Some sanity checks... */
2124 max_stats_queues = p_hwfn->p_rdma_info->dev->max_stats_queues;
2125 if (in_params->stats_queue >= max_stats_queues) {
2126 DP_ERR(p_hwfn->cdev,
2127 "qed rdma create qp failed due to invalid statistics queue %d. maximum is %d\n",
2128 in_params->stats_queue, max_stats_queues);
2129 return NULL;
2130 }
2131
2132 qp = kzalloc(sizeof(*qp), GFP_KERNEL);
2133 if (!qp) {
2134 DP_NOTICE(p_hwfn, "Failed to allocate qed_rdma_qp\n");
2135 return NULL;
2136 }
2137
2138 rc = qed_roce_alloc_cid(p_hwfn, &qp->icid);
2139 qp->qpid = ((0xFF << 16) | qp->icid);
2140
2141 DP_INFO(p_hwfn, "ROCE qpid=%x\n", qp->qpid);
2142
2143 if (rc) {
2144 kfree(qp);
2145 return NULL;
2146 }
2147
2148 qp->cur_state = QED_ROCE_QP_STATE_RESET;
2149 qp->qp_handle.hi = cpu_to_le32(in_params->qp_handle_hi);
2150 qp->qp_handle.lo = cpu_to_le32(in_params->qp_handle_lo);
2151 qp->qp_handle_async.hi = cpu_to_le32(in_params->qp_handle_async_hi);
2152 qp->qp_handle_async.lo = cpu_to_le32(in_params->qp_handle_async_lo);
2153 qp->use_srq = in_params->use_srq;
2154 qp->signal_all = in_params->signal_all;
2155 qp->fmr_and_reserved_lkey = in_params->fmr_and_reserved_lkey;
2156 qp->pd = in_params->pd;
2157 qp->dpi = in_params->dpi;
2158 qp->sq_cq_id = in_params->sq_cq_id;
2159 qp->sq_num_pages = in_params->sq_num_pages;
2160 qp->sq_pbl_ptr = in_params->sq_pbl_ptr;
2161 qp->rq_cq_id = in_params->rq_cq_id;
2162 qp->rq_num_pages = in_params->rq_num_pages;
2163 qp->rq_pbl_ptr = in_params->rq_pbl_ptr;
2164 qp->srq_id = in_params->srq_id;
2165 qp->req_offloaded = false;
2166 qp->resp_offloaded = false;
2167 qp->e2e_flow_control_en = qp->use_srq ? false : true;
2168 qp->stats_queue = in_params->stats_queue;
2169
2170 out_params->icid = qp->icid;
2171 out_params->qp_id = qp->qpid;
2172
2173 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Create QP, rc = %d\n", rc);
2174 return qp;
2175}
2176
2177static int qed_roce_modify_qp(struct qed_hwfn *p_hwfn,
2178 struct qed_rdma_qp *qp,
2179 enum qed_roce_qp_state prev_state,
2180 struct qed_rdma_modify_qp_in_params *params)
2181{
2182 u32 num_invalidated_mw = 0, num_bound_mw = 0;
2183 int rc = 0;
2184
2185 /* Perform additional operations according to the current state and the
2186 * next state
2187 */
2188 if (((prev_state == QED_ROCE_QP_STATE_INIT) ||
2189 (prev_state == QED_ROCE_QP_STATE_RESET)) &&
2190 (qp->cur_state == QED_ROCE_QP_STATE_RTR)) {
2191 /* Init->RTR or Reset->RTR */
2192 rc = qed_roce_sp_create_responder(p_hwfn, qp);
2193 return rc;
2194 } else if ((prev_state == QED_ROCE_QP_STATE_RTR) &&
2195 (qp->cur_state == QED_ROCE_QP_STATE_RTS)) {
2196 /* RTR-> RTS */
2197 rc = qed_roce_sp_create_requester(p_hwfn, qp);
2198 if (rc)
2199 return rc;
2200
2201 /* Send modify responder ramrod */
2202 rc = qed_roce_sp_modify_responder(p_hwfn, qp, false,
2203 params->modify_flags);
2204 return rc;
2205 } else if ((prev_state == QED_ROCE_QP_STATE_RTS) &&
2206 (qp->cur_state == QED_ROCE_QP_STATE_RTS)) {
2207 /* RTS->RTS */
2208 rc = qed_roce_sp_modify_responder(p_hwfn, qp, false,
2209 params->modify_flags);
2210 if (rc)
2211 return rc;
2212
2213 rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, false,
2214 params->modify_flags);
2215 return rc;
2216 } else if ((prev_state == QED_ROCE_QP_STATE_RTS) &&
2217 (qp->cur_state == QED_ROCE_QP_STATE_SQD)) {
2218 /* RTS->SQD */
2219 rc = qed_roce_sp_modify_requester(p_hwfn, qp, true, false,
2220 params->modify_flags);
2221 return rc;
2222 } else if ((prev_state == QED_ROCE_QP_STATE_SQD) &&
2223 (qp->cur_state == QED_ROCE_QP_STATE_SQD)) {
2224 /* SQD->SQD */
2225 rc = qed_roce_sp_modify_responder(p_hwfn, qp, false,
2226 params->modify_flags);
2227 if (rc)
2228 return rc;
2229
2230 rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, false,
2231 params->modify_flags);
2232 return rc;
2233 } else if ((prev_state == QED_ROCE_QP_STATE_SQD) &&
2234 (qp->cur_state == QED_ROCE_QP_STATE_RTS)) {
2235 /* SQD->RTS */
2236 rc = qed_roce_sp_modify_responder(p_hwfn, qp, false,
2237 params->modify_flags);
2238 if (rc)
2239 return rc;
2240
2241 rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, false,
2242 params->modify_flags);
2243
2244 return rc;
Ram Amraniba0154e2017-04-30 11:49:06 +03002245 } else if (qp->cur_state == QED_ROCE_QP_STATE_ERR) {
Ram Amranif1093942016-10-01 21:59:59 +03002246 /* ->ERR */
2247 rc = qed_roce_sp_modify_responder(p_hwfn, qp, true,
2248 params->modify_flags);
2249 if (rc)
2250 return rc;
2251
2252 rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, true,
2253 params->modify_flags);
2254 return rc;
2255 } else if (qp->cur_state == QED_ROCE_QP_STATE_RESET) {
2256 /* Any state -> RESET */
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02002257 u32 cq_prod;
Ram Amranif1093942016-10-01 21:59:59 +03002258
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02002259 /* Send destroy responder ramrod */
2260 rc = qed_roce_sp_destroy_qp_responder(p_hwfn,
2261 qp,
2262 &num_invalidated_mw,
2263 &cq_prod);
2264
Ram Amranif1093942016-10-01 21:59:59 +03002265 if (rc)
2266 return rc;
2267
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02002268 qp->cq_prod = cq_prod;
2269
Ram Amranif1093942016-10-01 21:59:59 +03002270 rc = qed_roce_sp_destroy_qp_requester(p_hwfn, qp,
2271 &num_bound_mw);
2272
2273 if (num_invalidated_mw != num_bound_mw) {
2274 DP_NOTICE(p_hwfn,
2275 "number of invalidate memory windows is different from bounded ones\n");
2276 return -EINVAL;
2277 }
2278 } else {
2279 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "0\n");
2280 }
2281
2282 return rc;
2283}
2284
Yuval Mintz0189efb2016-10-13 22:57:02 +03002285static int qed_rdma_modify_qp(void *rdma_cxt,
2286 struct qed_rdma_qp *qp,
2287 struct qed_rdma_modify_qp_in_params *params)
Ram Amranif1093942016-10-01 21:59:59 +03002288{
2289 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2290 enum qed_roce_qp_state prev_state;
2291 int rc = 0;
2292
2293 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x params->new_state=%d\n",
2294 qp->icid, params->new_state);
2295
2296 if (rc) {
2297 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
2298 return rc;
2299 }
2300
2301 if (GET_FIELD(params->modify_flags,
2302 QED_RDMA_MODIFY_QP_VALID_RDMA_OPS_EN)) {
2303 qp->incoming_rdma_read_en = params->incoming_rdma_read_en;
2304 qp->incoming_rdma_write_en = params->incoming_rdma_write_en;
2305 qp->incoming_atomic_en = params->incoming_atomic_en;
2306 }
2307
2308 /* Update QP structure with the updated values */
2309 if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_ROCE_MODE))
2310 qp->roce_mode = params->roce_mode;
2311 if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_PKEY))
2312 qp->pkey = params->pkey;
2313 if (GET_FIELD(params->modify_flags,
2314 QED_ROCE_MODIFY_QP_VALID_E2E_FLOW_CONTROL_EN))
2315 qp->e2e_flow_control_en = params->e2e_flow_control_en;
2316 if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_DEST_QP))
2317 qp->dest_qp = params->dest_qp;
2318 if (GET_FIELD(params->modify_flags,
2319 QED_ROCE_MODIFY_QP_VALID_ADDRESS_VECTOR)) {
2320 /* Indicates that the following parameters have changed:
2321 * Traffic class, flow label, hop limit, source GID,
2322 * destination GID, loopback indicator
2323 */
2324 qp->traffic_class_tos = params->traffic_class_tos;
2325 qp->flow_label = params->flow_label;
2326 qp->hop_limit_ttl = params->hop_limit_ttl;
2327
2328 qp->sgid = params->sgid;
2329 qp->dgid = params->dgid;
2330 qp->udp_src_port = 0;
2331 qp->vlan_id = params->vlan_id;
2332 qp->mtu = params->mtu;
2333 qp->lb_indication = params->lb_indication;
2334 memcpy((u8 *)&qp->remote_mac_addr[0],
2335 (u8 *)&params->remote_mac_addr[0], ETH_ALEN);
2336 if (params->use_local_mac) {
2337 memcpy((u8 *)&qp->local_mac_addr[0],
2338 (u8 *)&params->local_mac_addr[0], ETH_ALEN);
2339 } else {
2340 memcpy((u8 *)&qp->local_mac_addr[0],
2341 (u8 *)&p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
2342 }
2343 }
2344 if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_RQ_PSN))
2345 qp->rq_psn = params->rq_psn;
2346 if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_SQ_PSN))
2347 qp->sq_psn = params->sq_psn;
2348 if (GET_FIELD(params->modify_flags,
2349 QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_REQ))
2350 qp->max_rd_atomic_req = params->max_rd_atomic_req;
2351 if (GET_FIELD(params->modify_flags,
2352 QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_RESP))
2353 qp->max_rd_atomic_resp = params->max_rd_atomic_resp;
2354 if (GET_FIELD(params->modify_flags,
2355 QED_ROCE_MODIFY_QP_VALID_ACK_TIMEOUT))
2356 qp->ack_timeout = params->ack_timeout;
2357 if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_RETRY_CNT))
2358 qp->retry_cnt = params->retry_cnt;
2359 if (GET_FIELD(params->modify_flags,
2360 QED_ROCE_MODIFY_QP_VALID_RNR_RETRY_CNT))
2361 qp->rnr_retry_cnt = params->rnr_retry_cnt;
2362 if (GET_FIELD(params->modify_flags,
2363 QED_ROCE_MODIFY_QP_VALID_MIN_RNR_NAK_TIMER))
2364 qp->min_rnr_nak_timer = params->min_rnr_nak_timer;
2365
2366 qp->sqd_async = params->sqd_async;
2367
2368 prev_state = qp->cur_state;
2369 if (GET_FIELD(params->modify_flags,
2370 QED_RDMA_MODIFY_QP_VALID_NEW_STATE)) {
2371 qp->cur_state = params->new_state;
2372 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "qp->cur_state=%d\n",
2373 qp->cur_state);
2374 }
2375
2376 rc = qed_roce_modify_qp(p_hwfn, qp, prev_state, params);
2377
2378 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Modify QP, rc = %d\n", rc);
2379 return rc;
2380}
2381
Yuval Mintz0189efb2016-10-13 22:57:02 +03002382static int
2383qed_rdma_register_tid(void *rdma_cxt,
2384 struct qed_rdma_register_tid_in_params *params)
Ram Amraniee8eaea2016-10-01 22:00:00 +03002385{
2386 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2387 struct rdma_register_tid_ramrod_data *p_ramrod;
2388 struct qed_sp_init_data init_data;
2389 struct qed_spq_entry *p_ent;
2390 enum rdma_tid_type tid_type;
2391 u8 fw_return_code;
2392 int rc;
2393
2394 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", params->itid);
2395
2396 /* Get SPQ entry */
2397 memset(&init_data, 0, sizeof(init_data));
2398 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
2399 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
2400
2401 rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_REGISTER_MR,
2402 p_hwfn->p_rdma_info->proto, &init_data);
2403 if (rc) {
2404 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
2405 return rc;
2406 }
2407
2408 if (p_hwfn->p_rdma_info->last_tid < params->itid)
2409 p_hwfn->p_rdma_info->last_tid = params->itid;
2410
2411 p_ramrod = &p_ent->ramrod.rdma_register_tid;
2412
2413 p_ramrod->flags = 0;
2414 SET_FIELD(p_ramrod->flags,
2415 RDMA_REGISTER_TID_RAMROD_DATA_TWO_LEVEL_PBL,
2416 params->pbl_two_level);
2417
2418 SET_FIELD(p_ramrod->flags,
2419 RDMA_REGISTER_TID_RAMROD_DATA_ZERO_BASED, params->zbva);
2420
2421 SET_FIELD(p_ramrod->flags,
2422 RDMA_REGISTER_TID_RAMROD_DATA_PHY_MR, params->phy_mr);
2423
2424 /* Don't initialize D/C field, as it may override other bits. */
2425 if (!(params->tid_type == QED_RDMA_TID_FMR) && !(params->dma_mr))
2426 SET_FIELD(p_ramrod->flags,
2427 RDMA_REGISTER_TID_RAMROD_DATA_PAGE_SIZE_LOG,
2428 params->page_size_log - 12);
2429
2430 SET_FIELD(p_ramrod->flags,
2431 RDMA_REGISTER_TID_RAMROD_DATA_MAX_ID,
2432 p_hwfn->p_rdma_info->last_tid);
2433
2434 SET_FIELD(p_ramrod->flags,
2435 RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_READ,
2436 params->remote_read);
2437
2438 SET_FIELD(p_ramrod->flags,
2439 RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_WRITE,
2440 params->remote_write);
2441
2442 SET_FIELD(p_ramrod->flags,
2443 RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_ATOMIC,
2444 params->remote_atomic);
2445
2446 SET_FIELD(p_ramrod->flags,
2447 RDMA_REGISTER_TID_RAMROD_DATA_LOCAL_WRITE,
2448 params->local_write);
2449
2450 SET_FIELD(p_ramrod->flags,
2451 RDMA_REGISTER_TID_RAMROD_DATA_LOCAL_READ, params->local_read);
2452
2453 SET_FIELD(p_ramrod->flags,
2454 RDMA_REGISTER_TID_RAMROD_DATA_ENABLE_MW_BIND,
2455 params->mw_bind);
2456
2457 SET_FIELD(p_ramrod->flags1,
2458 RDMA_REGISTER_TID_RAMROD_DATA_PBL_PAGE_SIZE_LOG,
2459 params->pbl_page_size_log - 12);
2460
2461 SET_FIELD(p_ramrod->flags2,
2462 RDMA_REGISTER_TID_RAMROD_DATA_DMA_MR, params->dma_mr);
2463
2464 switch (params->tid_type) {
2465 case QED_RDMA_TID_REGISTERED_MR:
2466 tid_type = RDMA_TID_REGISTERED_MR;
2467 break;
2468 case QED_RDMA_TID_FMR:
2469 tid_type = RDMA_TID_FMR;
2470 break;
2471 case QED_RDMA_TID_MW_TYPE1:
2472 tid_type = RDMA_TID_MW_TYPE1;
2473 break;
2474 case QED_RDMA_TID_MW_TYPE2A:
2475 tid_type = RDMA_TID_MW_TYPE2A;
2476 break;
2477 default:
2478 rc = -EINVAL;
2479 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
2480 return rc;
2481 }
2482 SET_FIELD(p_ramrod->flags1,
2483 RDMA_REGISTER_TID_RAMROD_DATA_TID_TYPE, tid_type);
2484
2485 p_ramrod->itid = cpu_to_le32(params->itid);
2486 p_ramrod->key = params->key;
2487 p_ramrod->pd = cpu_to_le16(params->pd);
2488 p_ramrod->length_hi = (u8)(params->length >> 32);
2489 p_ramrod->length_lo = DMA_LO_LE(params->length);
2490 if (params->zbva) {
2491 /* Lower 32 bits of the registered MR address.
2492 * In case of zero based MR, will hold FBO
2493 */
2494 p_ramrod->va.hi = 0;
2495 p_ramrod->va.lo = cpu_to_le32(params->fbo);
2496 } else {
2497 DMA_REGPAIR_LE(p_ramrod->va, params->vaddr);
2498 }
2499 DMA_REGPAIR_LE(p_ramrod->pbl_base, params->pbl_ptr);
2500
2501 /* DIF */
2502 if (params->dif_enabled) {
2503 SET_FIELD(p_ramrod->flags2,
2504 RDMA_REGISTER_TID_RAMROD_DATA_DIF_ON_HOST_FLG, 1);
2505 DMA_REGPAIR_LE(p_ramrod->dif_error_addr,
2506 params->dif_error_addr);
2507 DMA_REGPAIR_LE(p_ramrod->dif_runt_addr, params->dif_runt_addr);
2508 }
2509
2510 rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code);
Ram Amrani10536192017-04-30 11:49:07 +03002511 if (rc)
2512 return rc;
Ram Amraniee8eaea2016-10-01 22:00:00 +03002513
2514 if (fw_return_code != RDMA_RETURN_OK) {
2515 DP_NOTICE(p_hwfn, "fw_return_code = %d\n", fw_return_code);
2516 return -EINVAL;
2517 }
2518
2519 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Register TID, rc = %d\n", rc);
2520 return rc;
2521}
2522
Yuval Mintz0189efb2016-10-13 22:57:02 +03002523static int qed_rdma_deregister_tid(void *rdma_cxt, u32 itid)
Ram Amraniee8eaea2016-10-01 22:00:00 +03002524{
2525 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2526 struct rdma_deregister_tid_ramrod_data *p_ramrod;
2527 struct qed_sp_init_data init_data;
2528 struct qed_spq_entry *p_ent;
2529 struct qed_ptt *p_ptt;
2530 u8 fw_return_code;
2531 int rc;
2532
2533 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", itid);
2534
2535 /* Get SPQ entry */
2536 memset(&init_data, 0, sizeof(init_data));
2537 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
2538 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
2539
2540 rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_DEREGISTER_MR,
2541 p_hwfn->p_rdma_info->proto, &init_data);
2542 if (rc) {
2543 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
2544 return rc;
2545 }
2546
2547 p_ramrod = &p_ent->ramrod.rdma_deregister_tid;
2548 p_ramrod->itid = cpu_to_le32(itid);
2549
2550 rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code);
2551 if (rc) {
2552 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
2553 return rc;
2554 }
2555
2556 if (fw_return_code == RDMA_RETURN_DEREGISTER_MR_BAD_STATE_ERR) {
2557 DP_NOTICE(p_hwfn, "fw_return_code = %d\n", fw_return_code);
2558 return -EINVAL;
2559 } else if (fw_return_code == RDMA_RETURN_NIG_DRAIN_REQ) {
2560 /* Bit indicating that the TID is in use and a nig drain is
2561 * required before sending the ramrod again
2562 */
2563 p_ptt = qed_ptt_acquire(p_hwfn);
2564 if (!p_ptt) {
2565 rc = -EBUSY;
2566 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2567 "Failed to acquire PTT\n");
2568 return rc;
2569 }
2570
2571 rc = qed_mcp_drain(p_hwfn, p_ptt);
2572 if (rc) {
2573 qed_ptt_release(p_hwfn, p_ptt);
2574 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2575 "Drain failed\n");
2576 return rc;
2577 }
2578
2579 qed_ptt_release(p_hwfn, p_ptt);
2580
2581 /* Resend the ramrod */
2582 rc = qed_sp_init_request(p_hwfn, &p_ent,
2583 RDMA_RAMROD_DEREGISTER_MR,
2584 p_hwfn->p_rdma_info->proto,
2585 &init_data);
2586 if (rc) {
2587 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2588 "Failed to init sp-element\n");
2589 return rc;
2590 }
2591
2592 rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code);
2593 if (rc) {
2594 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2595 "Ramrod failed\n");
2596 return rc;
2597 }
2598
2599 if (fw_return_code != RDMA_RETURN_OK) {
2600 DP_NOTICE(p_hwfn, "fw_return_code = %d\n",
2601 fw_return_code);
2602 return rc;
2603 }
2604 }
2605
2606 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "De-registered TID, rc = %d\n", rc);
2607 return rc;
2608}
2609
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02002610static void qed_roce_free_real_icid(struct qed_hwfn *p_hwfn, u16 icid)
2611{
2612 struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info;
2613 u32 start_cid, cid, xcid;
2614
2615 /* an even icid belongs to a responder while an odd icid belongs to a
2616 * requester. The 'cid' received as an input can be either. We calculate
2617 * the "partner" icid and call it xcid. Only if both are free then the
2618 * "cid" map can be cleared.
2619 */
2620 start_cid = qed_cxt_get_proto_cid_start(p_hwfn, p_rdma_info->proto);
2621 cid = icid - start_cid;
2622 xcid = cid ^ 1;
2623
2624 spin_lock_bh(&p_rdma_info->lock);
2625
2626 qed_bmap_release_id(p_hwfn, &p_rdma_info->real_cid_map, cid);
2627 if (qed_bmap_test_id(p_hwfn, &p_rdma_info->real_cid_map, xcid) == 0) {
2628 qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, cid);
2629 qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, xcid);
2630 }
2631
2632 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
2633}
2634
Ram Amrani51ff1722016-10-01 21:59:57 +03002635static void *qed_rdma_get_rdma_ctx(struct qed_dev *cdev)
2636{
2637 return QED_LEADING_HWFN(cdev);
2638}
2639
2640static void qed_rdma_dpm_conf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2641{
2642 u32 val;
2643
2644 val = (p_hwfn->dcbx_no_edpm || p_hwfn->db_bar_no_edpm) ? 0 : 1;
2645
2646 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPM_ENABLE, val);
2647 DP_VERBOSE(p_hwfn, (QED_MSG_DCB | QED_MSG_RDMA),
2648 "Changing DPM_EN state to %d (DCBX=%d, DB_BAR=%d)\n",
2649 val, p_hwfn->dcbx_no_edpm, p_hwfn->db_bar_no_edpm);
2650}
2651
2652void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2653{
2654 p_hwfn->db_bar_no_edpm = true;
2655
2656 qed_rdma_dpm_conf(p_hwfn, p_ptt);
2657}
2658
Yuval Mintz0189efb2016-10-13 22:57:02 +03002659static int qed_rdma_start(void *rdma_cxt,
2660 struct qed_rdma_start_in_params *params)
Ram Amrani51ff1722016-10-01 21:59:57 +03002661{
2662 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2663 struct qed_ptt *p_ptt;
2664 int rc = -EBUSY;
2665
2666 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2667 "desired_cnq = %08x\n", params->desired_cnq);
2668
2669 p_ptt = qed_ptt_acquire(p_hwfn);
2670 if (!p_ptt)
2671 goto err;
2672
2673 rc = qed_rdma_alloc(p_hwfn, p_ptt, params);
2674 if (rc)
2675 goto err1;
2676
2677 rc = qed_rdma_setup(p_hwfn, p_ptt, params);
2678 if (rc)
2679 goto err2;
2680
2681 qed_ptt_release(p_hwfn, p_ptt);
2682
2683 return rc;
2684
2685err2:
2686 qed_rdma_free(p_hwfn);
2687err1:
2688 qed_ptt_release(p_hwfn, p_ptt);
2689err:
2690 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA start - error, rc = %d\n", rc);
2691 return rc;
2692}
2693
2694static int qed_rdma_init(struct qed_dev *cdev,
2695 struct qed_rdma_start_in_params *params)
2696{
2697 return qed_rdma_start(QED_LEADING_HWFN(cdev), params);
2698}
2699
Yuval Mintz0189efb2016-10-13 22:57:02 +03002700static void qed_rdma_remove_user(void *rdma_cxt, u16 dpi)
Ram Amrani51ff1722016-10-01 21:59:57 +03002701{
2702 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2703
2704 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "dpi = %08x\n", dpi);
2705
2706 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
2707 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->dpi_map, dpi);
2708 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
2709}
2710
Ram Amraniabd49672016-10-01 22:00:01 +03002711void qed_ll2b_complete_tx_gsi_packet(struct qed_hwfn *p_hwfn,
2712 u8 connection_handle,
2713 void *cookie,
2714 dma_addr_t first_frag_addr,
2715 bool b_last_fragment, bool b_last_packet)
2716{
2717 struct qed_roce_ll2_packet *packet = cookie;
2718 struct qed_roce_ll2_info *roce_ll2 = p_hwfn->ll2;
2719
2720 roce_ll2->cbs.tx_cb(roce_ll2->cb_cookie, packet);
2721}
2722
2723void qed_ll2b_release_tx_gsi_packet(struct qed_hwfn *p_hwfn,
2724 u8 connection_handle,
2725 void *cookie,
2726 dma_addr_t first_frag_addr,
2727 bool b_last_fragment, bool b_last_packet)
2728{
2729 qed_ll2b_complete_tx_gsi_packet(p_hwfn, connection_handle,
2730 cookie, first_frag_addr,
2731 b_last_fragment, b_last_packet);
2732}
2733
2734void qed_ll2b_complete_rx_gsi_packet(struct qed_hwfn *p_hwfn,
2735 u8 connection_handle,
2736 void *cookie,
2737 dma_addr_t rx_buf_addr,
2738 u16 data_length,
2739 u8 data_length_error,
2740 u16 parse_flags,
2741 u16 vlan,
2742 u32 src_mac_addr_hi,
2743 u16 src_mac_addr_lo, bool b_last_packet)
2744{
2745 struct qed_roce_ll2_info *roce_ll2 = p_hwfn->ll2;
2746 struct qed_roce_ll2_rx_params params;
2747 struct qed_dev *cdev = p_hwfn->cdev;
2748 struct qed_roce_ll2_packet pkt;
2749
2750 DP_VERBOSE(cdev,
2751 QED_MSG_LL2,
2752 "roce ll2 rx complete: bus_addr=%p, len=%d, data_len_err=%d\n",
2753 (void *)(uintptr_t)rx_buf_addr,
2754 data_length, data_length_error);
2755
2756 memset(&pkt, 0, sizeof(pkt));
2757 pkt.n_seg = 1;
2758 pkt.payload[0].baddr = rx_buf_addr;
2759 pkt.payload[0].len = data_length;
2760
2761 memset(&params, 0, sizeof(params));
2762 params.vlan_id = vlan;
2763 *((u32 *)&params.smac[0]) = ntohl(src_mac_addr_hi);
2764 *((u16 *)&params.smac[4]) = ntohs(src_mac_addr_lo);
2765
2766 if (data_length_error) {
2767 DP_ERR(cdev,
2768 "roce ll2 rx complete: data length error %d, length=%d\n",
2769 data_length_error, data_length);
2770 params.rc = -EINVAL;
2771 }
2772
2773 roce_ll2->cbs.rx_cb(roce_ll2->cb_cookie, &pkt, &params);
2774}
2775
2776static int qed_roce_ll2_set_mac_filter(struct qed_dev *cdev,
2777 u8 *old_mac_address,
2778 u8 *new_mac_address)
2779{
2780 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2781 struct qed_ptt *p_ptt;
2782 int rc = 0;
2783
2784 if (!hwfn->ll2 || hwfn->ll2->handle == QED_LL2_UNUSED_HANDLE) {
2785 DP_ERR(cdev,
2786 "qed roce mac filter failed - roce_info/ll2 NULL\n");
2787 return -EINVAL;
2788 }
2789
2790 p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
2791 if (!p_ptt) {
2792 DP_ERR(cdev,
2793 "qed roce ll2 mac filter set: failed to acquire PTT\n");
2794 return -EINVAL;
2795 }
2796
2797 mutex_lock(&hwfn->ll2->lock);
2798 if (old_mac_address)
2799 qed_llh_remove_mac_filter(QED_LEADING_HWFN(cdev), p_ptt,
2800 old_mac_address);
2801 if (new_mac_address)
2802 rc = qed_llh_add_mac_filter(QED_LEADING_HWFN(cdev), p_ptt,
2803 new_mac_address);
2804 mutex_unlock(&hwfn->ll2->lock);
2805
2806 qed_ptt_release(QED_LEADING_HWFN(cdev), p_ptt);
2807
2808 if (rc)
2809 DP_ERR(cdev,
2810 "qed roce ll2 mac filter set: failed to add mac filter\n");
2811
2812 return rc;
2813}
2814
2815static int qed_roce_ll2_start(struct qed_dev *cdev,
2816 struct qed_roce_ll2_params *params)
2817{
2818 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2819 struct qed_roce_ll2_info *roce_ll2;
Arnd Bergmann0629a332017-01-18 15:52:52 +01002820 struct qed_ll2_conn ll2_params;
Ram Amraniabd49672016-10-01 22:00:01 +03002821 int rc;
2822
2823 if (!params) {
2824 DP_ERR(cdev, "qed roce ll2 start: failed due to NULL params\n");
2825 return -EINVAL;
2826 }
2827 if (!params->cbs.tx_cb || !params->cbs.rx_cb) {
2828 DP_ERR(cdev,
2829 "qed roce ll2 start: failed due to NULL tx/rx. tx_cb=%p, rx_cb=%p\n",
2830 params->cbs.tx_cb, params->cbs.rx_cb);
2831 return -EINVAL;
2832 }
2833 if (!is_valid_ether_addr(params->mac_address)) {
2834 DP_ERR(cdev,
2835 "qed roce ll2 start: failed due to invalid Ethernet address %pM\n",
2836 params->mac_address);
2837 return -EINVAL;
2838 }
2839
2840 /* Initialize */
2841 roce_ll2 = kzalloc(sizeof(*roce_ll2), GFP_ATOMIC);
2842 if (!roce_ll2) {
2843 DP_ERR(cdev, "qed roce ll2 start: failed memory allocation\n");
2844 return -ENOMEM;
2845 }
Ram Amraniabd49672016-10-01 22:00:01 +03002846 roce_ll2->handle = QED_LL2_UNUSED_HANDLE;
2847 roce_ll2->cbs = params->cbs;
2848 roce_ll2->cb_cookie = params->cb_cookie;
2849 mutex_init(&roce_ll2->lock);
2850
2851 memset(&ll2_params, 0, sizeof(ll2_params));
2852 ll2_params.conn_type = QED_LL2_TYPE_ROCE;
2853 ll2_params.mtu = params->mtu;
2854 ll2_params.rx_drop_ttl0_flg = true;
2855 ll2_params.rx_vlan_removal_en = false;
2856 ll2_params.tx_dest = CORE_TX_DEST_NW;
2857 ll2_params.ai_err_packet_too_big = LL2_DROP_PACKET;
2858 ll2_params.ai_err_no_buf = LL2_DROP_PACKET;
2859 ll2_params.gsi_enable = true;
2860
2861 rc = qed_ll2_acquire_connection(QED_LEADING_HWFN(cdev), &ll2_params,
2862 params->max_rx_buffers,
2863 params->max_tx_buffers,
2864 &roce_ll2->handle);
2865 if (rc) {
2866 DP_ERR(cdev,
2867 "qed roce ll2 start: failed to acquire LL2 connection (rc=%d)\n",
2868 rc);
2869 goto err;
2870 }
2871
2872 rc = qed_ll2_establish_connection(QED_LEADING_HWFN(cdev),
2873 roce_ll2->handle);
2874 if (rc) {
2875 DP_ERR(cdev,
2876 "qed roce ll2 start: failed to establish LL2 connection (rc=%d)\n",
2877 rc);
2878 goto err1;
2879 }
2880
2881 hwfn->ll2 = roce_ll2;
2882
2883 rc = qed_roce_ll2_set_mac_filter(cdev, NULL, params->mac_address);
2884 if (rc) {
2885 hwfn->ll2 = NULL;
2886 goto err2;
2887 }
2888 ether_addr_copy(roce_ll2->mac_address, params->mac_address);
2889
2890 return 0;
2891
2892err2:
2893 qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev), roce_ll2->handle);
2894err1:
2895 qed_ll2_release_connection(QED_LEADING_HWFN(cdev), roce_ll2->handle);
2896err:
2897 kfree(roce_ll2);
2898 return rc;
2899}
2900
2901static int qed_roce_ll2_stop(struct qed_dev *cdev)
2902{
2903 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2904 struct qed_roce_ll2_info *roce_ll2 = hwfn->ll2;
2905 int rc;
2906
Ram Amraniabd49672016-10-01 22:00:01 +03002907 if (roce_ll2->handle == QED_LL2_UNUSED_HANDLE) {
2908 DP_ERR(cdev, "qed roce ll2 stop: cannot stop an unused LL2\n");
2909 return -EINVAL;
2910 }
2911
2912 /* remove LL2 MAC address filter */
2913 rc = qed_roce_ll2_set_mac_filter(cdev, roce_ll2->mac_address, NULL);
2914 eth_zero_addr(roce_ll2->mac_address);
2915
2916 rc = qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev),
2917 roce_ll2->handle);
2918 if (rc)
2919 DP_ERR(cdev,
2920 "qed roce ll2 stop: failed to terminate LL2 connection (rc=%d)\n",
2921 rc);
2922
2923 qed_ll2_release_connection(QED_LEADING_HWFN(cdev), roce_ll2->handle);
2924
2925 roce_ll2->handle = QED_LL2_UNUSED_HANDLE;
2926
2927 kfree(roce_ll2);
2928
2929 return rc;
2930}
2931
2932static int qed_roce_ll2_tx(struct qed_dev *cdev,
2933 struct qed_roce_ll2_packet *pkt,
2934 struct qed_roce_ll2_tx_params *params)
2935{
2936 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2937 struct qed_roce_ll2_info *roce_ll2 = hwfn->ll2;
2938 enum qed_ll2_roce_flavor_type qed_roce_flavor;
2939 u8 flags = 0;
2940 int rc;
2941 int i;
2942
Yuval Mintzce6b04e2016-10-13 22:57:01 +03002943 if (!pkt || !params) {
Ram Amraniabd49672016-10-01 22:00:01 +03002944 DP_ERR(cdev,
2945 "roce ll2 tx: failed tx because one of the following is NULL - drv=%p, pkt=%p, params=%p\n",
2946 cdev, pkt, params);
2947 return -EINVAL;
2948 }
2949
2950 qed_roce_flavor = (pkt->roce_mode == ROCE_V1) ? QED_LL2_ROCE
2951 : QED_LL2_RROCE;
2952
2953 if (pkt->roce_mode == ROCE_V2_IPV4)
Mintz, Yuvalbe086e72017-03-11 18:39:18 +02002954 flags |= BIT(CORE_TX_BD_DATA_IP_CSUM_SHIFT);
Ram Amraniabd49672016-10-01 22:00:01 +03002955
2956 /* Tx header */
2957 rc = qed_ll2_prepare_tx_packet(QED_LEADING_HWFN(cdev), roce_ll2->handle,
2958 1 + pkt->n_seg, 0, flags, 0,
Yuval Mintz1d6cff42016-12-01 00:21:07 -08002959 QED_LL2_TX_DEST_NW,
Ram Amraniabd49672016-10-01 22:00:01 +03002960 qed_roce_flavor, pkt->header.baddr,
2961 pkt->header.len, pkt, 1);
2962 if (rc) {
2963 DP_ERR(cdev, "roce ll2 tx: header failed (rc=%d)\n", rc);
2964 return QED_ROCE_TX_HEAD_FAILURE;
2965 }
2966
2967 /* Tx payload */
2968 for (i = 0; i < pkt->n_seg; i++) {
2969 rc = qed_ll2_set_fragment_of_tx_packet(QED_LEADING_HWFN(cdev),
2970 roce_ll2->handle,
2971 pkt->payload[i].baddr,
2972 pkt->payload[i].len);
2973 if (rc) {
2974 /* If failed not much to do here, partial packet has
2975 * been posted * we can't free memory, will need to wait
2976 * for completion
2977 */
2978 DP_ERR(cdev,
2979 "roce ll2 tx: payload failed (rc=%d)\n", rc);
2980 return QED_ROCE_TX_FRAG_FAILURE;
2981 }
2982 }
2983
2984 return 0;
2985}
2986
2987static int qed_roce_ll2_post_rx_buffer(struct qed_dev *cdev,
2988 struct qed_roce_ll2_buffer *buf,
2989 u64 cookie, u8 notify_fw)
2990{
2991 return qed_ll2_post_rx_buffer(QED_LEADING_HWFN(cdev),
2992 QED_LEADING_HWFN(cdev)->ll2->handle,
2993 buf->baddr, buf->len,
2994 (void *)(uintptr_t)cookie, notify_fw);
2995}
2996
2997static int qed_roce_ll2_stats(struct qed_dev *cdev, struct qed_ll2_stats *stats)
2998{
2999 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
3000 struct qed_roce_ll2_info *roce_ll2 = hwfn->ll2;
3001
3002 return qed_ll2_get_stats(QED_LEADING_HWFN(cdev),
3003 roce_ll2->handle, stats);
3004}
3005
Ram Amrani51ff1722016-10-01 21:59:57 +03003006static const struct qed_rdma_ops qed_rdma_ops_pass = {
3007 .common = &qed_common_ops_pass,
3008 .fill_dev_info = &qed_fill_rdma_dev_info,
3009 .rdma_get_rdma_ctx = &qed_rdma_get_rdma_ctx,
3010 .rdma_init = &qed_rdma_init,
3011 .rdma_add_user = &qed_rdma_add_user,
3012 .rdma_remove_user = &qed_rdma_remove_user,
3013 .rdma_stop = &qed_rdma_stop,
Ram Amranic295f862016-10-01 21:59:58 +03003014 .rdma_query_port = &qed_rdma_query_port,
Ram Amrani51ff1722016-10-01 21:59:57 +03003015 .rdma_query_device = &qed_rdma_query_device,
3016 .rdma_get_start_sb = &qed_rdma_get_sb_start,
3017 .rdma_get_rdma_int = &qed_rdma_get_int,
3018 .rdma_set_rdma_int = &qed_rdma_set_int,
3019 .rdma_get_min_cnq_msix = &qed_rdma_get_min_cnq_msix,
3020 .rdma_cnq_prod_update = &qed_rdma_cnq_prod_update,
Ram Amranic295f862016-10-01 21:59:58 +03003021 .rdma_alloc_pd = &qed_rdma_alloc_pd,
3022 .rdma_dealloc_pd = &qed_rdma_free_pd,
3023 .rdma_create_cq = &qed_rdma_create_cq,
3024 .rdma_destroy_cq = &qed_rdma_destroy_cq,
Ram Amranif1093942016-10-01 21:59:59 +03003025 .rdma_create_qp = &qed_rdma_create_qp,
3026 .rdma_modify_qp = &qed_rdma_modify_qp,
3027 .rdma_query_qp = &qed_rdma_query_qp,
3028 .rdma_destroy_qp = &qed_rdma_destroy_qp,
Ram Amraniee8eaea2016-10-01 22:00:00 +03003029 .rdma_alloc_tid = &qed_rdma_alloc_tid,
3030 .rdma_free_tid = &qed_rdma_free_tid,
3031 .rdma_register_tid = &qed_rdma_register_tid,
3032 .rdma_deregister_tid = &qed_rdma_deregister_tid,
Ram Amraniabd49672016-10-01 22:00:01 +03003033 .roce_ll2_start = &qed_roce_ll2_start,
3034 .roce_ll2_stop = &qed_roce_ll2_stop,
3035 .roce_ll2_tx = &qed_roce_ll2_tx,
3036 .roce_ll2_post_rx_buffer = &qed_roce_ll2_post_rx_buffer,
3037 .roce_ll2_set_mac_filter = &qed_roce_ll2_set_mac_filter,
3038 .roce_ll2_stats = &qed_roce_ll2_stats,
Ram Amrani51ff1722016-10-01 21:59:57 +03003039};
3040
Arnd Bergmannd4e99132016-10-10 13:59:16 +02003041const struct qed_rdma_ops *qed_get_rdma_ops(void)
Ram Amrani51ff1722016-10-01 21:59:57 +03003042{
3043 return &qed_rdma_ops_pass;
3044}
3045EXPORT_SYMBOL(qed_get_rdma_ops);