blob: a5da9fc6f45407c765587e48c1e9bd7b19dd0264 [file] [log] [blame]
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001/* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +030032#include <linux/if_ether.h>
33#include <linux/if_vlan.h>
Kalderon, Michal65a91a62017-07-02 10:29:26 +030034#include <linux/ip.h>
35#include <linux/ipv6.h>
36#include <linux/spinlock.h>
37#include <linux/tcp.h>
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030038#include "qed_cxt.h"
39#include "qed_hw.h"
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +030040#include "qed_ll2.h"
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030041#include "qed_rdma.h"
42#include "qed_reg_addr.h"
43#include "qed_sp.h"
44
45#define QED_IWARP_ORD_DEFAULT 32
46#define QED_IWARP_IRD_DEFAULT 32
Kalderon, Michal456a5842017-07-02 10:29:27 +030047#define QED_IWARP_MAX_FW_MSS 4120
48
49#define QED_EP_SIG 0xecabcdef
50
51struct mpa_v2_hdr {
52 __be16 ird;
53 __be16 ord;
54};
55
56#define MPA_V2_PEER2PEER_MODEL 0x8000
57#define MPA_V2_SEND_RTR 0x4000 /* on ird */
58#define MPA_V2_READ_RTR 0x4000 /* on ord */
59#define MPA_V2_WRITE_RTR 0x8000
60#define MPA_V2_IRD_ORD_MASK 0x3FFF
61
62#define MPA_REV2(_mpa_rev) ((_mpa_rev) == MPA_NEGOTIATION_TYPE_ENHANCED)
63
64#define QED_IWARP_INVALID_TCP_CID 0xffffffff
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030065#define QED_IWARP_RCV_WND_SIZE_DEF (256 * 1024)
66#define QED_IWARP_RCV_WND_SIZE_MIN (64 * 1024)
Kalderon, Michal456a5842017-07-02 10:29:27 +030067#define TIMESTAMP_HEADER_SIZE (12)
68
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030069#define QED_IWARP_TS_EN BIT(0)
Kalderon, Michal456a5842017-07-02 10:29:27 +030070#define QED_IWARP_DA_EN BIT(1)
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030071#define QED_IWARP_PARAM_CRC_NEEDED (1)
72#define QED_IWARP_PARAM_P2P (1)
73
74static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn,
75 u8 fw_event_code, u16 echo,
76 union event_ring_data *data,
77 u8 fw_return_code);
78
79/* Override devinfo with iWARP specific values */
80void qed_iwarp_init_devinfo(struct qed_hwfn *p_hwfn)
81{
82 struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
83
84 dev->max_inline = IWARP_REQ_MAX_INLINE_DATA_SIZE;
85 dev->max_qp = min_t(u32,
86 IWARP_MAX_QPS,
Kalderon, Michal456a5842017-07-02 10:29:27 +030087 p_hwfn->p_rdma_info->num_qps) -
88 QED_IWARP_PREALLOC_CNT;
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030089
90 dev->max_cq = dev->max_qp;
91
92 dev->max_qp_resp_rd_atomic_resc = QED_IWARP_IRD_DEFAULT;
93 dev->max_qp_req_rd_atomic_resc = QED_IWARP_ORD_DEFAULT;
94}
95
96void qed_iwarp_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
97{
98 p_hwfn->rdma_prs_search_reg = PRS_REG_SEARCH_TCP;
99 qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1);
100 p_hwfn->b_rdma_enabled_in_prs = true;
101}
102
Kalderon, Michal456a5842017-07-02 10:29:27 +0300103/* We have two cid maps, one for tcp which should be used only from passive
104 * syn processing and replacing a pre-allocated ep in the list. The second
105 * for active tcp and for QPs.
106 */
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300107static void qed_iwarp_cid_cleaned(struct qed_hwfn *p_hwfn, u32 cid)
108{
109 cid -= qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
110
111 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
Kalderon, Michal456a5842017-07-02 10:29:27 +0300112
113 if (cid < QED_IWARP_PREALLOC_CNT)
114 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map,
115 cid);
116 else
117 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid);
118
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300119 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
120}
121
122static int qed_iwarp_alloc_cid(struct qed_hwfn *p_hwfn, u32 *cid)
123{
124 int rc;
125
126 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
127 rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid);
128 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
129 if (rc) {
130 DP_NOTICE(p_hwfn, "Failed in allocating iwarp cid\n");
131 return rc;
132 }
133 *cid += qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
134
135 rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, *cid);
136 if (rc)
137 qed_iwarp_cid_cleaned(p_hwfn, *cid);
138
139 return rc;
140}
141
Kalderon, Michal456a5842017-07-02 10:29:27 +0300142static void qed_iwarp_set_tcp_cid(struct qed_hwfn *p_hwfn, u32 cid)
143{
144 cid -= qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
145
146 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
147 qed_bmap_set_id(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map, cid);
148 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
149}
150
151/* This function allocates a cid for passive tcp (called from syn receive)
152 * the reason it's separate from the regular cid allocation is because it
153 * is assured that these cids already have ilt allocated. They are preallocated
154 * to ensure that we won't need to allocate memory during syn processing
155 */
156static int qed_iwarp_alloc_tcp_cid(struct qed_hwfn *p_hwfn, u32 *cid)
157{
158 int rc;
159
160 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
161
162 rc = qed_rdma_bmap_alloc_id(p_hwfn,
163 &p_hwfn->p_rdma_info->tcp_cid_map, cid);
164
165 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
166
167 if (rc) {
168 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
169 "can't allocate iwarp tcp cid max-count=%d\n",
170 p_hwfn->p_rdma_info->tcp_cid_map.max_count);
171
172 *cid = QED_IWARP_INVALID_TCP_CID;
173 return rc;
174 }
175
176 *cid += qed_cxt_get_proto_cid_start(p_hwfn,
177 p_hwfn->p_rdma_info->proto);
178 return 0;
179}
180
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300181int qed_iwarp_create_qp(struct qed_hwfn *p_hwfn,
182 struct qed_rdma_qp *qp,
183 struct qed_rdma_create_qp_out_params *out_params)
184{
185 struct iwarp_create_qp_ramrod_data *p_ramrod;
186 struct qed_sp_init_data init_data;
187 struct qed_spq_entry *p_ent;
188 u16 physical_queue;
189 u32 cid;
190 int rc;
191
192 qp->shared_queue = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
193 IWARP_SHARED_QUEUE_PAGE_SIZE,
194 &qp->shared_queue_phys_addr,
195 GFP_KERNEL);
196 if (!qp->shared_queue)
197 return -ENOMEM;
198
199 out_params->sq_pbl_virt = (u8 *)qp->shared_queue +
200 IWARP_SHARED_QUEUE_PAGE_SQ_PBL_OFFSET;
201 out_params->sq_pbl_phys = qp->shared_queue_phys_addr +
202 IWARP_SHARED_QUEUE_PAGE_SQ_PBL_OFFSET;
203 out_params->rq_pbl_virt = (u8 *)qp->shared_queue +
204 IWARP_SHARED_QUEUE_PAGE_RQ_PBL_OFFSET;
205 out_params->rq_pbl_phys = qp->shared_queue_phys_addr +
206 IWARP_SHARED_QUEUE_PAGE_RQ_PBL_OFFSET;
207
208 rc = qed_iwarp_alloc_cid(p_hwfn, &cid);
209 if (rc)
210 goto err1;
211
212 qp->icid = (u16)cid;
213
214 memset(&init_data, 0, sizeof(init_data));
215 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
216 init_data.cid = qp->icid;
217 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
218
219 rc = qed_sp_init_request(p_hwfn, &p_ent,
220 IWARP_RAMROD_CMD_ID_CREATE_QP,
221 PROTOCOLID_IWARP, &init_data);
222 if (rc)
223 goto err2;
224
225 p_ramrod = &p_ent->ramrod.iwarp_create_qp;
226
227 SET_FIELD(p_ramrod->flags,
228 IWARP_CREATE_QP_RAMROD_DATA_FMR_AND_RESERVED_EN,
229 qp->fmr_and_reserved_lkey);
230
231 SET_FIELD(p_ramrod->flags,
232 IWARP_CREATE_QP_RAMROD_DATA_SIGNALED_COMP, qp->signal_all);
233
234 SET_FIELD(p_ramrod->flags,
235 IWARP_CREATE_QP_RAMROD_DATA_RDMA_RD_EN,
236 qp->incoming_rdma_read_en);
237
238 SET_FIELD(p_ramrod->flags,
239 IWARP_CREATE_QP_RAMROD_DATA_RDMA_WR_EN,
240 qp->incoming_rdma_write_en);
241
242 SET_FIELD(p_ramrod->flags,
243 IWARP_CREATE_QP_RAMROD_DATA_ATOMIC_EN,
244 qp->incoming_atomic_en);
245
246 SET_FIELD(p_ramrod->flags,
247 IWARP_CREATE_QP_RAMROD_DATA_SRQ_FLG, qp->use_srq);
248
249 p_ramrod->pd = qp->pd;
250 p_ramrod->sq_num_pages = qp->sq_num_pages;
251 p_ramrod->rq_num_pages = qp->rq_num_pages;
252
253 p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi);
254 p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo);
255
256 p_ramrod->cq_cid_for_sq =
257 cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->sq_cq_id);
258 p_ramrod->cq_cid_for_rq =
259 cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->rq_cq_id);
260
261 p_ramrod->dpi = cpu_to_le16(qp->dpi);
262
263 physical_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
264 p_ramrod->physical_q0 = cpu_to_le16(physical_queue);
265 physical_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK);
266 p_ramrod->physical_q1 = cpu_to_le16(physical_queue);
267
268 rc = qed_spq_post(p_hwfn, p_ent, NULL);
269 if (rc)
270 goto err2;
271
272 return rc;
273
274err2:
275 qed_iwarp_cid_cleaned(p_hwfn, cid);
276err1:
277 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
278 IWARP_SHARED_QUEUE_PAGE_SIZE,
279 qp->shared_queue, qp->shared_queue_phys_addr);
280
281 return rc;
282}
283
284static int qed_iwarp_modify_fw(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
285{
286 struct iwarp_modify_qp_ramrod_data *p_ramrod;
287 struct qed_sp_init_data init_data;
288 struct qed_spq_entry *p_ent;
289 int rc;
290
291 /* Get SPQ entry */
292 memset(&init_data, 0, sizeof(init_data));
293 init_data.cid = qp->icid;
294 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
295 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
296
297 rc = qed_sp_init_request(p_hwfn, &p_ent,
298 IWARP_RAMROD_CMD_ID_MODIFY_QP,
299 p_hwfn->p_rdma_info->proto, &init_data);
300 if (rc)
301 return rc;
302
303 p_ramrod = &p_ent->ramrod.iwarp_modify_qp;
304 SET_FIELD(p_ramrod->flags, IWARP_MODIFY_QP_RAMROD_DATA_STATE_TRANS_EN,
305 0x1);
306 if (qp->iwarp_state == QED_IWARP_QP_STATE_CLOSING)
307 p_ramrod->transition_to_state = IWARP_MODIFY_QP_STATE_CLOSING;
308 else
309 p_ramrod->transition_to_state = IWARP_MODIFY_QP_STATE_ERROR;
310
311 rc = qed_spq_post(p_hwfn, p_ent, NULL);
312
313 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x)rc=%d\n", qp->icid, rc);
314
315 return rc;
316}
317
318enum qed_iwarp_qp_state qed_roce2iwarp_state(enum qed_roce_qp_state state)
319{
320 switch (state) {
321 case QED_ROCE_QP_STATE_RESET:
322 case QED_ROCE_QP_STATE_INIT:
323 case QED_ROCE_QP_STATE_RTR:
324 return QED_IWARP_QP_STATE_IDLE;
325 case QED_ROCE_QP_STATE_RTS:
326 return QED_IWARP_QP_STATE_RTS;
327 case QED_ROCE_QP_STATE_SQD:
328 return QED_IWARP_QP_STATE_CLOSING;
329 case QED_ROCE_QP_STATE_ERR:
330 return QED_IWARP_QP_STATE_ERROR;
331 case QED_ROCE_QP_STATE_SQE:
332 return QED_IWARP_QP_STATE_TERMINATE;
333 default:
334 return QED_IWARP_QP_STATE_ERROR;
335 }
336}
337
338static enum qed_roce_qp_state
339qed_iwarp2roce_state(enum qed_iwarp_qp_state state)
340{
341 switch (state) {
342 case QED_IWARP_QP_STATE_IDLE:
343 return QED_ROCE_QP_STATE_INIT;
344 case QED_IWARP_QP_STATE_RTS:
345 return QED_ROCE_QP_STATE_RTS;
346 case QED_IWARP_QP_STATE_TERMINATE:
347 return QED_ROCE_QP_STATE_SQE;
348 case QED_IWARP_QP_STATE_CLOSING:
349 return QED_ROCE_QP_STATE_SQD;
350 case QED_IWARP_QP_STATE_ERROR:
351 return QED_ROCE_QP_STATE_ERR;
352 default:
353 return QED_ROCE_QP_STATE_ERR;
354 }
355}
356
357const char *iwarp_state_names[] = {
358 "IDLE",
359 "RTS",
360 "TERMINATE",
361 "CLOSING",
362 "ERROR",
363};
364
365int
366qed_iwarp_modify_qp(struct qed_hwfn *p_hwfn,
367 struct qed_rdma_qp *qp,
368 enum qed_iwarp_qp_state new_state, bool internal)
369{
370 enum qed_iwarp_qp_state prev_iw_state;
371 bool modify_fw = false;
372 int rc = 0;
373
374 /* modify QP can be called from upper-layer or as a result of async
375 * RST/FIN... therefore need to protect
376 */
377 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
378 prev_iw_state = qp->iwarp_state;
379
380 if (prev_iw_state == new_state) {
381 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
382 return 0;
383 }
384
385 switch (prev_iw_state) {
386 case QED_IWARP_QP_STATE_IDLE:
387 switch (new_state) {
388 case QED_IWARP_QP_STATE_RTS:
389 qp->iwarp_state = QED_IWARP_QP_STATE_RTS;
390 break;
391 case QED_IWARP_QP_STATE_ERROR:
392 qp->iwarp_state = QED_IWARP_QP_STATE_ERROR;
393 if (!internal)
394 modify_fw = true;
395 break;
396 default:
397 break;
398 }
399 break;
400 case QED_IWARP_QP_STATE_RTS:
401 switch (new_state) {
402 case QED_IWARP_QP_STATE_CLOSING:
403 if (!internal)
404 modify_fw = true;
405
406 qp->iwarp_state = QED_IWARP_QP_STATE_CLOSING;
407 break;
408 case QED_IWARP_QP_STATE_ERROR:
409 if (!internal)
410 modify_fw = true;
411 qp->iwarp_state = QED_IWARP_QP_STATE_ERROR;
412 break;
413 default:
414 break;
415 }
416 break;
417 case QED_IWARP_QP_STATE_ERROR:
418 switch (new_state) {
419 case QED_IWARP_QP_STATE_IDLE:
420
421 qp->iwarp_state = new_state;
422 break;
423 case QED_IWARP_QP_STATE_CLOSING:
424 /* could happen due to race... do nothing.... */
425 break;
426 default:
427 rc = -EINVAL;
428 }
429 break;
430 case QED_IWARP_QP_STATE_TERMINATE:
431 case QED_IWARP_QP_STATE_CLOSING:
432 qp->iwarp_state = new_state;
433 break;
434 default:
435 break;
436 }
437
438 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) %s --> %s%s\n",
439 qp->icid,
440 iwarp_state_names[prev_iw_state],
441 iwarp_state_names[qp->iwarp_state],
442 internal ? "internal" : "");
443
444 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
445
446 if (modify_fw)
447 rc = qed_iwarp_modify_fw(p_hwfn, qp);
448
449 return rc;
450}
451
452int qed_iwarp_fw_destroy(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
453{
454 struct qed_sp_init_data init_data;
455 struct qed_spq_entry *p_ent;
456 int rc;
457
458 /* Get SPQ entry */
459 memset(&init_data, 0, sizeof(init_data));
460 init_data.cid = qp->icid;
461 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
462 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
463
464 rc = qed_sp_init_request(p_hwfn, &p_ent,
465 IWARP_RAMROD_CMD_ID_DESTROY_QP,
466 p_hwfn->p_rdma_info->proto, &init_data);
467 if (rc)
468 return rc;
469
470 rc = qed_spq_post(p_hwfn, p_ent, NULL);
471
472 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) rc = %d\n", qp->icid, rc);
473
474 return rc;
475}
476
Kalderon, Michal456a5842017-07-02 10:29:27 +0300477static void qed_iwarp_destroy_ep(struct qed_hwfn *p_hwfn,
478 struct qed_iwarp_ep *ep,
479 bool remove_from_active_list)
480{
481 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
482 sizeof(*ep->ep_buffer_virt),
483 ep->ep_buffer_virt, ep->ep_buffer_phys);
484
485 if (remove_from_active_list) {
486 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
487 list_del(&ep->list_entry);
488 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
489 }
490
491 if (ep->qp)
492 ep->qp->ep = NULL;
493
494 kfree(ep);
495}
496
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300497int qed_iwarp_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
498{
499 int rc = 0;
500
501 if (qp->iwarp_state != QED_IWARP_QP_STATE_ERROR) {
502 rc = qed_iwarp_modify_qp(p_hwfn, qp,
503 QED_IWARP_QP_STATE_ERROR, false);
504 if (rc)
505 return rc;
506 }
507
508 rc = qed_iwarp_fw_destroy(p_hwfn, qp);
509
510 if (qp->shared_queue)
511 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
512 IWARP_SHARED_QUEUE_PAGE_SIZE,
513 qp->shared_queue, qp->shared_queue_phys_addr);
514
515 return rc;
516}
517
Kalderon, Michal456a5842017-07-02 10:29:27 +0300518static int
519qed_iwarp_create_ep(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep **ep_out)
520{
521 struct qed_iwarp_ep *ep;
522 int rc;
523
524 ep = kzalloc(sizeof(*ep), GFP_KERNEL);
525 if (!ep)
526 return -ENOMEM;
527
528 ep->state = QED_IWARP_EP_INIT;
529
530 ep->ep_buffer_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
531 sizeof(*ep->ep_buffer_virt),
532 &ep->ep_buffer_phys,
533 GFP_KERNEL);
534 if (!ep->ep_buffer_virt) {
535 rc = -ENOMEM;
536 goto err;
537 }
538
539 ep->sig = QED_EP_SIG;
540
541 *ep_out = ep;
542
543 return 0;
544
545err:
546 kfree(ep);
547 return rc;
548}
549
550static void
551qed_iwarp_print_tcp_ramrod(struct qed_hwfn *p_hwfn,
552 struct iwarp_tcp_offload_ramrod_data *p_tcp_ramrod)
553{
554 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "local_mac=%x %x %x, remote_mac=%x %x %x\n",
555 p_tcp_ramrod->tcp.local_mac_addr_lo,
556 p_tcp_ramrod->tcp.local_mac_addr_mid,
557 p_tcp_ramrod->tcp.local_mac_addr_hi,
558 p_tcp_ramrod->tcp.remote_mac_addr_lo,
559 p_tcp_ramrod->tcp.remote_mac_addr_mid,
560 p_tcp_ramrod->tcp.remote_mac_addr_hi);
561
562 if (p_tcp_ramrod->tcp.ip_version == TCP_IPV4) {
563 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
564 "local_ip=%pI4h:%x, remote_ip=%pI4h%x, vlan=%x\n",
565 p_tcp_ramrod->tcp.local_ip,
566 p_tcp_ramrod->tcp.local_port,
567 p_tcp_ramrod->tcp.remote_ip,
568 p_tcp_ramrod->tcp.remote_port,
569 p_tcp_ramrod->tcp.vlan_id);
570 } else {
571 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
572 "local_ip=%pI6h:%x, remote_ip=%pI6h:%x, vlan=%x\n",
573 p_tcp_ramrod->tcp.local_ip,
574 p_tcp_ramrod->tcp.local_port,
575 p_tcp_ramrod->tcp.remote_ip,
576 p_tcp_ramrod->tcp.remote_port,
577 p_tcp_ramrod->tcp.vlan_id);
578 }
579
580 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
581 "flow_label=%x, ttl=%x, tos_or_tc=%x, mss=%x, rcv_wnd_scale=%x, connect_mode=%x, flags=%x\n",
582 p_tcp_ramrod->tcp.flow_label,
583 p_tcp_ramrod->tcp.ttl,
584 p_tcp_ramrod->tcp.tos_or_tc,
585 p_tcp_ramrod->tcp.mss,
586 p_tcp_ramrod->tcp.rcv_wnd_scale,
587 p_tcp_ramrod->tcp.connect_mode,
588 p_tcp_ramrod->tcp.flags);
589
590 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "syn_ip_payload_length=%x, lo=%x, hi=%x\n",
591 p_tcp_ramrod->tcp.syn_ip_payload_length,
592 p_tcp_ramrod->tcp.syn_phy_addr_lo,
593 p_tcp_ramrod->tcp.syn_phy_addr_hi);
594}
595
596static int
597qed_iwarp_tcp_offload(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
598{
599 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
600 struct iwarp_tcp_offload_ramrod_data *p_tcp_ramrod;
601 struct tcp_offload_params_opt2 *tcp;
602 struct qed_sp_init_data init_data;
603 struct qed_spq_entry *p_ent;
604 dma_addr_t async_output_phys;
605 dma_addr_t in_pdata_phys;
606 u16 physical_q;
607 u8 tcp_flags;
608 int rc;
609 int i;
610
611 memset(&init_data, 0, sizeof(init_data));
612 init_data.cid = ep->tcp_cid;
613 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +0300614 if (ep->connect_mode == TCP_CONNECT_PASSIVE)
615 init_data.comp_mode = QED_SPQ_MODE_CB;
616 else
617 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
Kalderon, Michal456a5842017-07-02 10:29:27 +0300618
619 rc = qed_sp_init_request(p_hwfn, &p_ent,
620 IWARP_RAMROD_CMD_ID_TCP_OFFLOAD,
621 PROTOCOLID_IWARP, &init_data);
622 if (rc)
623 return rc;
624
625 p_tcp_ramrod = &p_ent->ramrod.iwarp_tcp_offload;
626
627 in_pdata_phys = ep->ep_buffer_phys +
628 offsetof(struct qed_iwarp_ep_memory, in_pdata);
629 DMA_REGPAIR_LE(p_tcp_ramrod->iwarp.incoming_ulp_buffer.addr,
630 in_pdata_phys);
631
632 p_tcp_ramrod->iwarp.incoming_ulp_buffer.len =
633 cpu_to_le16(sizeof(ep->ep_buffer_virt->in_pdata));
634
635 async_output_phys = ep->ep_buffer_phys +
636 offsetof(struct qed_iwarp_ep_memory, async_output);
637 DMA_REGPAIR_LE(p_tcp_ramrod->iwarp.async_eqe_output_buf,
638 async_output_phys);
639
640 p_tcp_ramrod->iwarp.handle_for_async.hi = cpu_to_le32(PTR_HI(ep));
641 p_tcp_ramrod->iwarp.handle_for_async.lo = cpu_to_le32(PTR_LO(ep));
642
643 physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
644 p_tcp_ramrod->iwarp.physical_q0 = cpu_to_le16(physical_q);
645 physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK);
646 p_tcp_ramrod->iwarp.physical_q1 = cpu_to_le16(physical_q);
647 p_tcp_ramrod->iwarp.mpa_mode = iwarp_info->mpa_rev;
648
649 tcp = &p_tcp_ramrod->tcp;
650 qed_set_fw_mac_addr(&tcp->remote_mac_addr_hi,
651 &tcp->remote_mac_addr_mid,
652 &tcp->remote_mac_addr_lo, ep->remote_mac_addr);
653 qed_set_fw_mac_addr(&tcp->local_mac_addr_hi, &tcp->local_mac_addr_mid,
654 &tcp->local_mac_addr_lo, ep->local_mac_addr);
655
656 tcp->vlan_id = cpu_to_le16(ep->cm_info.vlan);
657
658 tcp_flags = p_hwfn->p_rdma_info->iwarp.tcp_flags;
659 tcp->flags = 0;
660 SET_FIELD(tcp->flags, TCP_OFFLOAD_PARAMS_OPT2_TS_EN,
661 !!(tcp_flags & QED_IWARP_TS_EN));
662
663 SET_FIELD(tcp->flags, TCP_OFFLOAD_PARAMS_OPT2_DA_EN,
664 !!(tcp_flags & QED_IWARP_DA_EN));
665
666 tcp->ip_version = ep->cm_info.ip_version;
667
668 for (i = 0; i < 4; i++) {
669 tcp->remote_ip[i] = cpu_to_le32(ep->cm_info.remote_ip[i]);
670 tcp->local_ip[i] = cpu_to_le32(ep->cm_info.local_ip[i]);
671 }
672
673 tcp->remote_port = cpu_to_le16(ep->cm_info.remote_port);
674 tcp->local_port = cpu_to_le16(ep->cm_info.local_port);
675 tcp->mss = cpu_to_le16(ep->mss);
676 tcp->flow_label = 0;
677 tcp->ttl = 0x40;
678 tcp->tos_or_tc = 0;
679
680 tcp->rcv_wnd_scale = (u8)p_hwfn->p_rdma_info->iwarp.rcv_wnd_scale;
681 tcp->connect_mode = ep->connect_mode;
682
683 if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
684 tcp->syn_ip_payload_length =
685 cpu_to_le16(ep->syn_ip_payload_length);
686 tcp->syn_phy_addr_hi = DMA_HI_LE(ep->syn_phy_addr);
687 tcp->syn_phy_addr_lo = DMA_LO_LE(ep->syn_phy_addr);
688 }
689
690 qed_iwarp_print_tcp_ramrod(p_hwfn, p_tcp_ramrod);
691
692 rc = qed_spq_post(p_hwfn, p_ent, NULL);
693
694 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
695 "EP(0x%x) Offload completed rc=%d\n", ep->tcp_cid, rc);
696
697 return rc;
698}
699
700static void
701qed_iwarp_mpa_received(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
702{
703 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
704 struct qed_iwarp_cm_event_params params;
705 struct mpa_v2_hdr *mpa_v2;
706 union async_output *async_data;
707 u16 mpa_ord, mpa_ird;
708 u8 mpa_hdr_size = 0;
709 u8 mpa_rev;
710
711 async_data = &ep->ep_buffer_virt->async_output;
712
713 mpa_rev = async_data->mpa_request.mpa_handshake_mode;
714 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
715 "private_data_len=%x handshake_mode=%x private_data=(%x)\n",
716 async_data->mpa_request.ulp_data_len,
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +0300717 mpa_rev, *((u32 *)(ep->ep_buffer_virt->in_pdata)));
Kalderon, Michal456a5842017-07-02 10:29:27 +0300718
719 if (mpa_rev == MPA_NEGOTIATION_TYPE_ENHANCED) {
720 /* Read ord/ird values from private data buffer */
721 mpa_v2 = (struct mpa_v2_hdr *)ep->ep_buffer_virt->in_pdata;
722 mpa_hdr_size = sizeof(*mpa_v2);
723
724 mpa_ord = ntohs(mpa_v2->ord);
725 mpa_ird = ntohs(mpa_v2->ird);
726
727 /* Temprary store in cm_info incoming ord/ird requested, later
728 * replace with negotiated value during accept
729 */
730 ep->cm_info.ord = (u8)min_t(u16,
731 (mpa_ord & MPA_V2_IRD_ORD_MASK),
732 QED_IWARP_ORD_DEFAULT);
733
734 ep->cm_info.ird = (u8)min_t(u16,
735 (mpa_ird & MPA_V2_IRD_ORD_MASK),
736 QED_IWARP_IRD_DEFAULT);
737
738 /* Peer2Peer negotiation */
739 ep->rtr_type = MPA_RTR_TYPE_NONE;
740 if (mpa_ird & MPA_V2_PEER2PEER_MODEL) {
741 if (mpa_ord & MPA_V2_WRITE_RTR)
742 ep->rtr_type |= MPA_RTR_TYPE_ZERO_WRITE;
743
744 if (mpa_ord & MPA_V2_READ_RTR)
745 ep->rtr_type |= MPA_RTR_TYPE_ZERO_READ;
746
747 if (mpa_ird & MPA_V2_SEND_RTR)
748 ep->rtr_type |= MPA_RTR_TYPE_ZERO_SEND;
749
750 ep->rtr_type &= iwarp_info->rtr_type;
751
752 /* if we're left with no match send our capabilities */
753 if (ep->rtr_type == MPA_RTR_TYPE_NONE)
754 ep->rtr_type = iwarp_info->rtr_type;
755 }
756
757 ep->mpa_rev = MPA_NEGOTIATION_TYPE_ENHANCED;
758 } else {
759 ep->cm_info.ord = QED_IWARP_ORD_DEFAULT;
760 ep->cm_info.ird = QED_IWARP_IRD_DEFAULT;
761 ep->mpa_rev = MPA_NEGOTIATION_TYPE_BASIC;
762 }
763
764 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
765 "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x rtr:0x%x ulp_data_len = %x mpa_hdr_size = %x\n",
766 mpa_rev, ep->cm_info.ord, ep->cm_info.ird, ep->rtr_type,
767 async_data->mpa_request.ulp_data_len, mpa_hdr_size);
768
769 /* Strip mpa v2 hdr from private data before sending to upper layer */
770 ep->cm_info.private_data = ep->ep_buffer_virt->in_pdata + mpa_hdr_size;
771
772 ep->cm_info.private_data_len = async_data->mpa_request.ulp_data_len -
773 mpa_hdr_size;
774
775 params.event = QED_IWARP_EVENT_MPA_REQUEST;
776 params.cm_info = &ep->cm_info;
777 params.ep_context = ep;
778 params.status = 0;
779
780 ep->state = QED_IWARP_EP_MPA_REQ_RCVD;
781 ep->event_cb(ep->cb_context, &params);
782}
783
784static int
785qed_iwarp_mpa_offload(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
786{
787 struct iwarp_mpa_offload_ramrod_data *p_mpa_ramrod;
788 struct qed_sp_init_data init_data;
789 dma_addr_t async_output_phys;
790 struct qed_spq_entry *p_ent;
791 dma_addr_t out_pdata_phys;
792 dma_addr_t in_pdata_phys;
793 struct qed_rdma_qp *qp;
794 bool reject;
795 int rc;
796
797 if (!ep)
798 return -EINVAL;
799
800 qp = ep->qp;
801 reject = !qp;
802
803 memset(&init_data, 0, sizeof(init_data));
804 init_data.cid = reject ? ep->tcp_cid : qp->icid;
805 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
806
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +0300807 if (ep->connect_mode == TCP_CONNECT_ACTIVE)
808 init_data.comp_mode = QED_SPQ_MODE_CB;
809 else
810 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
Kalderon, Michal456a5842017-07-02 10:29:27 +0300811
812 rc = qed_sp_init_request(p_hwfn, &p_ent,
813 IWARP_RAMROD_CMD_ID_MPA_OFFLOAD,
814 PROTOCOLID_IWARP, &init_data);
815 if (rc)
816 return rc;
817
818 p_mpa_ramrod = &p_ent->ramrod.iwarp_mpa_offload;
819 out_pdata_phys = ep->ep_buffer_phys +
820 offsetof(struct qed_iwarp_ep_memory, out_pdata);
821 DMA_REGPAIR_LE(p_mpa_ramrod->common.outgoing_ulp_buffer.addr,
822 out_pdata_phys);
823 p_mpa_ramrod->common.outgoing_ulp_buffer.len =
824 ep->cm_info.private_data_len;
825 p_mpa_ramrod->common.crc_needed = p_hwfn->p_rdma_info->iwarp.crc_needed;
826
827 p_mpa_ramrod->common.out_rq.ord = ep->cm_info.ord;
828 p_mpa_ramrod->common.out_rq.ird = ep->cm_info.ird;
829
830 p_mpa_ramrod->tcp_cid = p_hwfn->hw_info.opaque_fid << 16 | ep->tcp_cid;
831
832 in_pdata_phys = ep->ep_buffer_phys +
833 offsetof(struct qed_iwarp_ep_memory, in_pdata);
834 p_mpa_ramrod->tcp_connect_side = ep->connect_mode;
835 DMA_REGPAIR_LE(p_mpa_ramrod->incoming_ulp_buffer.addr,
836 in_pdata_phys);
837 p_mpa_ramrod->incoming_ulp_buffer.len =
838 cpu_to_le16(sizeof(ep->ep_buffer_virt->in_pdata));
839 async_output_phys = ep->ep_buffer_phys +
840 offsetof(struct qed_iwarp_ep_memory, async_output);
841 DMA_REGPAIR_LE(p_mpa_ramrod->async_eqe_output_buf,
842 async_output_phys);
843 p_mpa_ramrod->handle_for_async.hi = cpu_to_le32(PTR_HI(ep));
844 p_mpa_ramrod->handle_for_async.lo = cpu_to_le32(PTR_LO(ep));
845
846 if (!reject) {
847 DMA_REGPAIR_LE(p_mpa_ramrod->shared_queue_addr,
848 qp->shared_queue_phys_addr);
849 p_mpa_ramrod->stats_counter_id =
850 RESC_START(p_hwfn, QED_RDMA_STATS_QUEUE) + qp->stats_queue;
851 } else {
852 p_mpa_ramrod->common.reject = 1;
853 }
854
855 p_mpa_ramrod->mode = ep->mpa_rev;
856 SET_FIELD(p_mpa_ramrod->rtr_pref,
857 IWARP_MPA_OFFLOAD_RAMROD_DATA_RTR_SUPPORTED, ep->rtr_type);
858
859 ep->state = QED_IWARP_EP_MPA_OFFLOADED;
860 rc = qed_spq_post(p_hwfn, p_ent, NULL);
861 if (!reject)
862 ep->cid = qp->icid; /* Now they're migrated. */
863
864 DP_VERBOSE(p_hwfn,
865 QED_MSG_RDMA,
866 "QP(0x%x) EP(0x%x) MPA Offload rc = %d IRD=0x%x ORD=0x%x rtr_type=%d mpa_rev=%d reject=%d\n",
867 reject ? 0xffff : qp->icid,
868 ep->tcp_cid,
869 rc,
870 ep->cm_info.ird,
871 ep->cm_info.ord, ep->rtr_type, ep->mpa_rev, reject);
872 return rc;
873}
874
875static void
876qed_iwarp_return_ep(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
877{
878 ep->state = QED_IWARP_EP_INIT;
879 if (ep->qp)
880 ep->qp->ep = NULL;
881 ep->qp = NULL;
882 memset(&ep->cm_info, 0, sizeof(ep->cm_info));
883
884 if (ep->tcp_cid == QED_IWARP_INVALID_TCP_CID) {
885 /* We don't care about the return code, it's ok if tcp_cid
886 * remains invalid...in this case we'll defer allocation
887 */
888 qed_iwarp_alloc_tcp_cid(p_hwfn, &ep->tcp_cid);
889 }
890 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
891
892 list_del(&ep->list_entry);
893 list_add_tail(&ep->list_entry,
894 &p_hwfn->p_rdma_info->iwarp.ep_free_list);
895
896 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
897}
898
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +0300899void
900qed_iwarp_parse_private_data(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
901{
902 struct mpa_v2_hdr *mpa_v2_params;
903 union async_output *async_data;
904 u16 mpa_ird, mpa_ord;
905 u8 mpa_data_size = 0;
906
907 if (MPA_REV2(p_hwfn->p_rdma_info->iwarp.mpa_rev)) {
908 mpa_v2_params =
909 (struct mpa_v2_hdr *)(ep->ep_buffer_virt->in_pdata);
910 mpa_data_size = sizeof(*mpa_v2_params);
911 mpa_ird = ntohs(mpa_v2_params->ird);
912 mpa_ord = ntohs(mpa_v2_params->ord);
913
914 ep->cm_info.ird = (u8)(mpa_ord & MPA_V2_IRD_ORD_MASK);
915 ep->cm_info.ord = (u8)(mpa_ird & MPA_V2_IRD_ORD_MASK);
916 }
917 async_data = &ep->ep_buffer_virt->async_output;
918
919 ep->cm_info.private_data = ep->ep_buffer_virt->in_pdata + mpa_data_size;
920 ep->cm_info.private_data_len = async_data->mpa_response.ulp_data_len -
921 mpa_data_size;
922}
923
924void
925qed_iwarp_mpa_reply_arrived(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
926{
927 struct qed_iwarp_cm_event_params params;
928
929 if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
930 DP_NOTICE(p_hwfn,
931 "MPA reply event not expected on passive side!\n");
932 return;
933 }
934
935 params.event = QED_IWARP_EVENT_ACTIVE_MPA_REPLY;
936
937 qed_iwarp_parse_private_data(p_hwfn, ep);
938
939 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
940 "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x\n",
941 ep->mpa_rev, ep->cm_info.ord, ep->cm_info.ird);
942
943 params.cm_info = &ep->cm_info;
944 params.ep_context = ep;
945 params.status = 0;
946
947 ep->mpa_reply_processed = true;
948
949 ep->event_cb(ep->cb_context, &params);
950}
951
Kalderon, Michal456a5842017-07-02 10:29:27 +0300952#define QED_IWARP_CONNECT_MODE_STRING(ep) \
953 ((ep)->connect_mode == TCP_CONNECT_PASSIVE) ? "Passive" : "Active"
954
955/* Called as a result of the event:
956 * IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE
957 */
958static void
959qed_iwarp_mpa_complete(struct qed_hwfn *p_hwfn,
960 struct qed_iwarp_ep *ep, u8 fw_return_code)
961{
962 struct qed_iwarp_cm_event_params params;
963
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +0300964 if (ep->connect_mode == TCP_CONNECT_ACTIVE)
965 params.event = QED_IWARP_EVENT_ACTIVE_COMPLETE;
966 else
967 params.event = QED_IWARP_EVENT_PASSIVE_COMPLETE;
968
969 if (ep->connect_mode == TCP_CONNECT_ACTIVE && !ep->mpa_reply_processed)
970 qed_iwarp_parse_private_data(p_hwfn, ep);
Kalderon, Michal456a5842017-07-02 10:29:27 +0300971
972 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
973 "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x\n",
974 ep->mpa_rev, ep->cm_info.ord, ep->cm_info.ird);
975
976 params.cm_info = &ep->cm_info;
977
978 params.ep_context = ep;
979
980 ep->state = QED_IWARP_EP_CLOSED;
981
982 switch (fw_return_code) {
983 case RDMA_RETURN_OK:
984 ep->qp->max_rd_atomic_req = ep->cm_info.ord;
985 ep->qp->max_rd_atomic_resp = ep->cm_info.ird;
986 qed_iwarp_modify_qp(p_hwfn, ep->qp, QED_IWARP_QP_STATE_RTS, 1);
987 ep->state = QED_IWARP_EP_ESTABLISHED;
988 params.status = 0;
989 break;
990 default:
991 params.status = -ECONNRESET;
992 break;
993 }
994
995 ep->event_cb(ep->cb_context, &params);
996}
997
998static void
999qed_iwarp_mpa_v2_set_private(struct qed_hwfn *p_hwfn,
1000 struct qed_iwarp_ep *ep, u8 *mpa_data_size)
1001{
1002 struct mpa_v2_hdr *mpa_v2_params;
1003 u16 mpa_ird, mpa_ord;
1004
1005 *mpa_data_size = 0;
1006 if (MPA_REV2(ep->mpa_rev)) {
1007 mpa_v2_params =
1008 (struct mpa_v2_hdr *)ep->ep_buffer_virt->out_pdata;
1009 *mpa_data_size = sizeof(*mpa_v2_params);
1010
1011 mpa_ird = (u16)ep->cm_info.ird;
1012 mpa_ord = (u16)ep->cm_info.ord;
1013
1014 if (ep->rtr_type != MPA_RTR_TYPE_NONE) {
1015 mpa_ird |= MPA_V2_PEER2PEER_MODEL;
1016
1017 if (ep->rtr_type & MPA_RTR_TYPE_ZERO_SEND)
1018 mpa_ird |= MPA_V2_SEND_RTR;
1019
1020 if (ep->rtr_type & MPA_RTR_TYPE_ZERO_WRITE)
1021 mpa_ord |= MPA_V2_WRITE_RTR;
1022
1023 if (ep->rtr_type & MPA_RTR_TYPE_ZERO_READ)
1024 mpa_ord |= MPA_V2_READ_RTR;
1025 }
1026
1027 mpa_v2_params->ird = htons(mpa_ird);
1028 mpa_v2_params->ord = htons(mpa_ord);
1029
1030 DP_VERBOSE(p_hwfn,
1031 QED_MSG_RDMA,
1032 "MPA_NEGOTIATE Header: [%x ord:%x ird] %x ord:%x ird:%x peer2peer:%x rtr_send:%x rtr_write:%x rtr_read:%x\n",
1033 mpa_v2_params->ird,
1034 mpa_v2_params->ord,
1035 *((u32 *)mpa_v2_params),
1036 mpa_ord & MPA_V2_IRD_ORD_MASK,
1037 mpa_ird & MPA_V2_IRD_ORD_MASK,
1038 !!(mpa_ird & MPA_V2_PEER2PEER_MODEL),
1039 !!(mpa_ird & MPA_V2_SEND_RTR),
1040 !!(mpa_ord & MPA_V2_WRITE_RTR),
1041 !!(mpa_ord & MPA_V2_READ_RTR));
1042 }
1043}
1044
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03001045int qed_iwarp_connect(void *rdma_cxt,
1046 struct qed_iwarp_connect_in *iparams,
1047 struct qed_iwarp_connect_out *oparams)
1048{
1049 struct qed_hwfn *p_hwfn = rdma_cxt;
1050 struct qed_iwarp_info *iwarp_info;
1051 struct qed_iwarp_ep *ep;
1052 u8 mpa_data_size = 0;
1053 u8 ts_hdr_size = 0;
1054 u32 cid;
1055 int rc;
1056
1057 if ((iparams->cm_info.ord > QED_IWARP_ORD_DEFAULT) ||
1058 (iparams->cm_info.ird > QED_IWARP_IRD_DEFAULT)) {
1059 DP_NOTICE(p_hwfn,
1060 "QP(0x%x) ERROR: Invalid ord(0x%x)/ird(0x%x)\n",
1061 iparams->qp->icid, iparams->cm_info.ord,
1062 iparams->cm_info.ird);
1063
1064 return -EINVAL;
1065 }
1066
1067 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
1068
1069 /* Allocate ep object */
1070 rc = qed_iwarp_alloc_cid(p_hwfn, &cid);
1071 if (rc)
1072 return rc;
1073
1074 rc = qed_iwarp_create_ep(p_hwfn, &ep);
1075 if (rc)
1076 goto err;
1077
1078 ep->tcp_cid = cid;
1079
1080 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1081 list_add_tail(&ep->list_entry, &p_hwfn->p_rdma_info->iwarp.ep_list);
1082 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1083
1084 ep->qp = iparams->qp;
1085 ep->qp->ep = ep;
1086 ether_addr_copy(ep->remote_mac_addr, iparams->remote_mac_addr);
1087 ether_addr_copy(ep->local_mac_addr, iparams->local_mac_addr);
1088 memcpy(&ep->cm_info, &iparams->cm_info, sizeof(ep->cm_info));
1089
1090 ep->cm_info.ord = iparams->cm_info.ord;
1091 ep->cm_info.ird = iparams->cm_info.ird;
1092
1093 ep->rtr_type = iwarp_info->rtr_type;
1094 if (!iwarp_info->peer2peer)
1095 ep->rtr_type = MPA_RTR_TYPE_NONE;
1096
1097 if ((ep->rtr_type & MPA_RTR_TYPE_ZERO_READ) && (ep->cm_info.ord == 0))
1098 ep->cm_info.ord = 1;
1099
1100 ep->mpa_rev = iwarp_info->mpa_rev;
1101
1102 qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size);
1103
1104 ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata;
1105 ep->cm_info.private_data_len = iparams->cm_info.private_data_len +
1106 mpa_data_size;
1107
1108 memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size,
1109 iparams->cm_info.private_data,
1110 iparams->cm_info.private_data_len);
1111
1112 if (p_hwfn->p_rdma_info->iwarp.tcp_flags & QED_IWARP_TS_EN)
1113 ts_hdr_size = TIMESTAMP_HEADER_SIZE;
1114
1115 ep->mss = iparams->mss - ts_hdr_size;
1116 ep->mss = min_t(u16, QED_IWARP_MAX_FW_MSS, ep->mss);
1117
1118 ep->event_cb = iparams->event_cb;
1119 ep->cb_context = iparams->cb_context;
1120 ep->connect_mode = TCP_CONNECT_ACTIVE;
1121
1122 oparams->ep_context = ep;
1123
1124 rc = qed_iwarp_tcp_offload(p_hwfn, ep);
1125
1126 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x) rc = %d\n",
1127 iparams->qp->icid, ep->tcp_cid, rc);
1128
1129 if (rc) {
1130 qed_iwarp_destroy_ep(p_hwfn, ep, true);
1131 goto err;
1132 }
1133
1134 return rc;
1135err:
1136 qed_iwarp_cid_cleaned(p_hwfn, cid);
1137
1138 return rc;
1139}
1140
Kalderon, Michal456a5842017-07-02 10:29:27 +03001141static struct qed_iwarp_ep *qed_iwarp_get_free_ep(struct qed_hwfn *p_hwfn)
1142{
1143 struct qed_iwarp_ep *ep = NULL;
1144 int rc;
1145
1146 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1147
1148 if (list_empty(&p_hwfn->p_rdma_info->iwarp.ep_free_list)) {
1149 DP_ERR(p_hwfn, "Ep list is empty\n");
1150 goto out;
1151 }
1152
1153 ep = list_first_entry(&p_hwfn->p_rdma_info->iwarp.ep_free_list,
1154 struct qed_iwarp_ep, list_entry);
1155
1156 /* in some cases we could have failed allocating a tcp cid when added
1157 * from accept / failure... retry now..this is not the common case.
1158 */
1159 if (ep->tcp_cid == QED_IWARP_INVALID_TCP_CID) {
1160 rc = qed_iwarp_alloc_tcp_cid(p_hwfn, &ep->tcp_cid);
1161
1162 /* if we fail we could look for another entry with a valid
1163 * tcp_cid, but since we don't expect to reach this anyway
1164 * it's not worth the handling
1165 */
1166 if (rc) {
1167 ep->tcp_cid = QED_IWARP_INVALID_TCP_CID;
1168 ep = NULL;
1169 goto out;
1170 }
1171 }
1172
1173 list_del(&ep->list_entry);
1174
1175out:
1176 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1177 return ep;
1178}
1179
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001180#define QED_IWARP_MAX_CID_CLEAN_TIME 100
1181#define QED_IWARP_MAX_NO_PROGRESS_CNT 5
1182
1183/* This function waits for all the bits of a bmap to be cleared, as long as
1184 * there is progress ( i.e. the number of bits left to be cleared decreases )
1185 * the function continues.
1186 */
1187static int
1188qed_iwarp_wait_cid_map_cleared(struct qed_hwfn *p_hwfn, struct qed_bmap *bmap)
1189{
1190 int prev_weight = 0;
1191 int wait_count = 0;
1192 int weight = 0;
1193
1194 weight = bitmap_weight(bmap->bitmap, bmap->max_count);
1195 prev_weight = weight;
1196
1197 while (weight) {
1198 msleep(QED_IWARP_MAX_CID_CLEAN_TIME);
1199
1200 weight = bitmap_weight(bmap->bitmap, bmap->max_count);
1201
1202 if (prev_weight == weight) {
1203 wait_count++;
1204 } else {
1205 prev_weight = weight;
1206 wait_count = 0;
1207 }
1208
1209 if (wait_count > QED_IWARP_MAX_NO_PROGRESS_CNT) {
1210 DP_NOTICE(p_hwfn,
1211 "%s bitmap wait timed out (%d cids pending)\n",
1212 bmap->name, weight);
1213 return -EBUSY;
1214 }
1215 }
1216 return 0;
1217}
1218
1219static int qed_iwarp_wait_for_all_cids(struct qed_hwfn *p_hwfn)
1220{
Kalderon, Michal456a5842017-07-02 10:29:27 +03001221 int rc;
1222 int i;
1223
1224 rc = qed_iwarp_wait_cid_map_cleared(p_hwfn,
1225 &p_hwfn->p_rdma_info->tcp_cid_map);
1226 if (rc)
1227 return rc;
1228
1229 /* Now free the tcp cids from the main cid map */
1230 for (i = 0; i < QED_IWARP_PREALLOC_CNT; i++)
1231 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, i);
1232
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001233 /* Now wait for all cids to be completed */
1234 return qed_iwarp_wait_cid_map_cleared(p_hwfn,
1235 &p_hwfn->p_rdma_info->cid_map);
1236}
1237
Kalderon, Michal456a5842017-07-02 10:29:27 +03001238static void qed_iwarp_free_prealloc_ep(struct qed_hwfn *p_hwfn)
1239{
1240 struct qed_iwarp_ep *ep;
1241
1242 while (!list_empty(&p_hwfn->p_rdma_info->iwarp.ep_free_list)) {
1243 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1244
1245 ep = list_first_entry(&p_hwfn->p_rdma_info->iwarp.ep_free_list,
1246 struct qed_iwarp_ep, list_entry);
1247
1248 if (!ep) {
1249 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1250 break;
1251 }
1252 list_del(&ep->list_entry);
1253
1254 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1255
1256 if (ep->tcp_cid != QED_IWARP_INVALID_TCP_CID)
1257 qed_iwarp_cid_cleaned(p_hwfn, ep->tcp_cid);
1258
1259 qed_iwarp_destroy_ep(p_hwfn, ep, false);
1260 }
1261}
1262
1263static int qed_iwarp_prealloc_ep(struct qed_hwfn *p_hwfn, bool init)
1264{
1265 struct qed_iwarp_ep *ep;
1266 int rc = 0;
1267 int count;
1268 u32 cid;
1269 int i;
1270
1271 count = init ? QED_IWARP_PREALLOC_CNT : 1;
1272 for (i = 0; i < count; i++) {
1273 rc = qed_iwarp_create_ep(p_hwfn, &ep);
1274 if (rc)
1275 return rc;
1276
1277 /* During initialization we allocate from the main pool,
1278 * afterwards we allocate only from the tcp_cid.
1279 */
1280 if (init) {
1281 rc = qed_iwarp_alloc_cid(p_hwfn, &cid);
1282 if (rc)
1283 goto err;
1284 qed_iwarp_set_tcp_cid(p_hwfn, cid);
1285 } else {
1286 /* We don't care about the return code, it's ok if
1287 * tcp_cid remains invalid...in this case we'll
1288 * defer allocation
1289 */
1290 qed_iwarp_alloc_tcp_cid(p_hwfn, &cid);
1291 }
1292
1293 ep->tcp_cid = cid;
1294
1295 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1296 list_add_tail(&ep->list_entry,
1297 &p_hwfn->p_rdma_info->iwarp.ep_free_list);
1298 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1299 }
1300
1301 return rc;
1302
1303err:
1304 qed_iwarp_destroy_ep(p_hwfn, ep, false);
1305
1306 return rc;
1307}
1308
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001309int qed_iwarp_alloc(struct qed_hwfn *p_hwfn)
1310{
Kalderon, Michal456a5842017-07-02 10:29:27 +03001311 int rc;
1312
1313 /* Allocate bitmap for tcp cid. These are used by passive side
1314 * to ensure it can allocate a tcp cid during dpc that was
1315 * pre-acquired and doesn't require dynamic allocation of ilt
1316 */
1317 rc = qed_rdma_bmap_alloc(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map,
1318 QED_IWARP_PREALLOC_CNT, "TCP_CID");
1319 if (rc) {
1320 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1321 "Failed to allocate tcp cid, rc = %d\n", rc);
1322 return rc;
1323 }
1324
1325 INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.ep_free_list);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001326 spin_lock_init(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1327
Kalderon, Michal456a5842017-07-02 10:29:27 +03001328 return qed_iwarp_prealloc_ep(p_hwfn, true);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001329}
1330
1331void qed_iwarp_resc_free(struct qed_hwfn *p_hwfn)
1332{
Kalderon, Michal456a5842017-07-02 10:29:27 +03001333 qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map, 1);
1334}
1335
1336int qed_iwarp_accept(void *rdma_cxt, struct qed_iwarp_accept_in *iparams)
1337{
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03001338 struct qed_hwfn *p_hwfn = rdma_cxt;
Kalderon, Michal456a5842017-07-02 10:29:27 +03001339 struct qed_iwarp_ep *ep;
1340 u8 mpa_data_size = 0;
1341 int rc;
1342
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03001343 ep = iparams->ep_context;
Kalderon, Michal456a5842017-07-02 10:29:27 +03001344 if (!ep) {
1345 DP_ERR(p_hwfn, "Ep Context receive in accept is NULL\n");
1346 return -EINVAL;
1347 }
1348
1349 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x)\n",
1350 iparams->qp->icid, ep->tcp_cid);
1351
1352 if ((iparams->ord > QED_IWARP_ORD_DEFAULT) ||
1353 (iparams->ird > QED_IWARP_IRD_DEFAULT)) {
1354 DP_VERBOSE(p_hwfn,
1355 QED_MSG_RDMA,
1356 "QP(0x%x) EP(0x%x) ERROR: Invalid ord(0x%x)/ird(0x%x)\n",
1357 iparams->qp->icid,
1358 ep->tcp_cid, iparams->ord, iparams->ord);
1359 return -EINVAL;
1360 }
1361
1362 qed_iwarp_prealloc_ep(p_hwfn, false);
1363
1364 ep->cb_context = iparams->cb_context;
1365 ep->qp = iparams->qp;
1366 ep->qp->ep = ep;
1367
1368 if (ep->mpa_rev == MPA_NEGOTIATION_TYPE_ENHANCED) {
1369 /* Negotiate ord/ird: if upperlayer requested ord larger than
1370 * ird advertised by remote, we need to decrease our ord
1371 */
1372 if (iparams->ord > ep->cm_info.ird)
1373 iparams->ord = ep->cm_info.ird;
1374
1375 if ((ep->rtr_type & MPA_RTR_TYPE_ZERO_READ) &&
1376 (iparams->ird == 0))
1377 iparams->ird = 1;
1378 }
1379
1380 /* Update cm_info ord/ird to be negotiated values */
1381 ep->cm_info.ord = iparams->ord;
1382 ep->cm_info.ird = iparams->ird;
1383
1384 qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size);
1385
1386 ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata;
1387 ep->cm_info.private_data_len = iparams->private_data_len +
1388 mpa_data_size;
1389
1390 memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size,
1391 iparams->private_data, iparams->private_data_len);
1392
1393 rc = qed_iwarp_mpa_offload(p_hwfn, ep);
1394 if (rc)
1395 qed_iwarp_modify_qp(p_hwfn,
1396 iparams->qp, QED_IWARP_QP_STATE_ERROR, 1);
1397
1398 return rc;
1399}
1400
1401int qed_iwarp_reject(void *rdma_cxt, struct qed_iwarp_reject_in *iparams)
1402{
1403 struct qed_hwfn *p_hwfn = rdma_cxt;
1404 struct qed_iwarp_ep *ep;
1405 u8 mpa_data_size = 0;
1406
1407 ep = iparams->ep_context;
1408 if (!ep) {
1409 DP_ERR(p_hwfn, "Ep Context receive in reject is NULL\n");
1410 return -EINVAL;
1411 }
1412
1413 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "EP(0x%x)\n", ep->tcp_cid);
1414
1415 ep->cb_context = iparams->cb_context;
1416 ep->qp = NULL;
1417
1418 qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size);
1419
1420 ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata;
1421 ep->cm_info.private_data_len = iparams->private_data_len +
1422 mpa_data_size;
1423
1424 memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size,
1425 iparams->private_data, iparams->private_data_len);
1426
1427 return qed_iwarp_mpa_offload(p_hwfn, ep);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001428}
1429
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001430static void
1431qed_iwarp_print_cm_info(struct qed_hwfn *p_hwfn,
1432 struct qed_iwarp_cm_info *cm_info)
1433{
1434 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "ip_version = %d\n",
1435 cm_info->ip_version);
1436
1437 if (cm_info->ip_version == QED_TCP_IPV4)
1438 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1439 "remote_ip %pI4h:%x, local_ip %pI4h:%x vlan=%x\n",
1440 cm_info->remote_ip, cm_info->remote_port,
1441 cm_info->local_ip, cm_info->local_port,
1442 cm_info->vlan);
1443 else
1444 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1445 "remote_ip %pI6h:%x, local_ip %pI6h:%x vlan=%x\n",
1446 cm_info->remote_ip, cm_info->remote_port,
1447 cm_info->local_ip, cm_info->local_port,
1448 cm_info->vlan);
1449
1450 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1451 "private_data_len = %x ord = %d, ird = %d\n",
1452 cm_info->private_data_len, cm_info->ord, cm_info->ird);
1453}
1454
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03001455static int
1456qed_iwarp_ll2_post_rx(struct qed_hwfn *p_hwfn,
1457 struct qed_iwarp_ll2_buff *buf, u8 handle)
1458{
1459 int rc;
1460
1461 rc = qed_ll2_post_rx_buffer(p_hwfn, handle, buf->data_phys_addr,
1462 (u16)buf->buff_size, buf, 1);
1463 if (rc) {
1464 DP_NOTICE(p_hwfn,
1465 "Failed to repost rx buffer to ll2 rc = %d, handle=%d\n",
1466 rc, handle);
1467 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buf->buff_size,
1468 buf->data, buf->data_phys_addr);
1469 kfree(buf);
1470 }
1471
1472 return rc;
1473}
1474
Kalderon, Michal456a5842017-07-02 10:29:27 +03001475static bool
1476qed_iwarp_ep_exists(struct qed_hwfn *p_hwfn, struct qed_iwarp_cm_info *cm_info)
1477{
1478 struct qed_iwarp_ep *ep = NULL;
1479 bool found = false;
1480
1481 list_for_each_entry(ep,
1482 &p_hwfn->p_rdma_info->iwarp.ep_list,
1483 list_entry) {
1484 if ((ep->cm_info.local_port == cm_info->local_port) &&
1485 (ep->cm_info.remote_port == cm_info->remote_port) &&
1486 (ep->cm_info.vlan == cm_info->vlan) &&
1487 !memcmp(&ep->cm_info.local_ip, cm_info->local_ip,
1488 sizeof(cm_info->local_ip)) &&
1489 !memcmp(&ep->cm_info.remote_ip, cm_info->remote_ip,
1490 sizeof(cm_info->remote_ip))) {
1491 found = true;
1492 break;
1493 }
1494 }
1495
1496 if (found) {
1497 DP_NOTICE(p_hwfn,
1498 "SYN received on active connection - dropping\n");
1499 qed_iwarp_print_cm_info(p_hwfn, cm_info);
1500
1501 return true;
1502 }
1503
1504 return false;
1505}
1506
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001507static struct qed_iwarp_listener *
1508qed_iwarp_get_listener(struct qed_hwfn *p_hwfn,
1509 struct qed_iwarp_cm_info *cm_info)
1510{
1511 struct qed_iwarp_listener *listener = NULL;
1512 static const u32 ip_zero[4] = { 0, 0, 0, 0 };
1513 bool found = false;
1514
1515 qed_iwarp_print_cm_info(p_hwfn, cm_info);
1516
1517 list_for_each_entry(listener,
1518 &p_hwfn->p_rdma_info->iwarp.listen_list,
1519 list_entry) {
1520 if (listener->port == cm_info->local_port) {
1521 if (!memcmp(listener->ip_addr,
1522 ip_zero, sizeof(ip_zero))) {
1523 found = true;
1524 break;
1525 }
1526
1527 if (!memcmp(listener->ip_addr,
1528 cm_info->local_ip,
1529 sizeof(cm_info->local_ip)) &&
1530 (listener->vlan == cm_info->vlan)) {
1531 found = true;
1532 break;
1533 }
1534 }
1535 }
1536
1537 if (found) {
1538 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener found = %p\n",
1539 listener);
1540 return listener;
1541 }
1542
1543 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener not found\n");
1544 return NULL;
1545}
1546
1547static int
1548qed_iwarp_parse_rx_pkt(struct qed_hwfn *p_hwfn,
1549 struct qed_iwarp_cm_info *cm_info,
1550 void *buf,
1551 u8 *remote_mac_addr,
1552 u8 *local_mac_addr,
1553 int *payload_len, int *tcp_start_offset)
1554{
1555 struct vlan_ethhdr *vethh;
1556 bool vlan_valid = false;
1557 struct ipv6hdr *ip6h;
1558 struct ethhdr *ethh;
1559 struct tcphdr *tcph;
1560 struct iphdr *iph;
1561 int eth_hlen;
1562 int ip_hlen;
1563 int eth_type;
1564 int i;
1565
1566 ethh = buf;
1567 eth_type = ntohs(ethh->h_proto);
1568 if (eth_type == ETH_P_8021Q) {
1569 vlan_valid = true;
1570 vethh = (struct vlan_ethhdr *)ethh;
1571 cm_info->vlan = ntohs(vethh->h_vlan_TCI) & VLAN_VID_MASK;
1572 eth_type = ntohs(vethh->h_vlan_encapsulated_proto);
1573 }
1574
1575 eth_hlen = ETH_HLEN + (vlan_valid ? sizeof(u32) : 0);
1576
Kalderon, Michal456a5842017-07-02 10:29:27 +03001577 ether_addr_copy(remote_mac_addr, ethh->h_source);
1578 ether_addr_copy(local_mac_addr, ethh->h_dest);
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001579
1580 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "eth_type =%d source mac: %pM\n",
1581 eth_type, ethh->h_source);
1582
1583 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "eth_hlen=%d destination mac: %pM\n",
1584 eth_hlen, ethh->h_dest);
1585
1586 iph = (struct iphdr *)((u8 *)(ethh) + eth_hlen);
1587
1588 if (eth_type == ETH_P_IP) {
1589 cm_info->local_ip[0] = ntohl(iph->daddr);
1590 cm_info->remote_ip[0] = ntohl(iph->saddr);
1591 cm_info->ip_version = TCP_IPV4;
1592
1593 ip_hlen = (iph->ihl) * sizeof(u32);
1594 *payload_len = ntohs(iph->tot_len) - ip_hlen;
1595 } else if (eth_type == ETH_P_IPV6) {
1596 ip6h = (struct ipv6hdr *)iph;
1597 for (i = 0; i < 4; i++) {
1598 cm_info->local_ip[i] =
1599 ntohl(ip6h->daddr.in6_u.u6_addr32[i]);
1600 cm_info->remote_ip[i] =
1601 ntohl(ip6h->saddr.in6_u.u6_addr32[i]);
1602 }
1603 cm_info->ip_version = TCP_IPV6;
1604
1605 ip_hlen = sizeof(*ip6h);
1606 *payload_len = ntohs(ip6h->payload_len);
1607 } else {
1608 DP_NOTICE(p_hwfn, "Unexpected ethertype on ll2 %x\n", eth_type);
1609 return -EINVAL;
1610 }
1611
1612 tcph = (struct tcphdr *)((u8 *)iph + ip_hlen);
1613
1614 if (!tcph->syn) {
1615 DP_NOTICE(p_hwfn,
1616 "Only SYN type packet expected on this ll2 conn, iph->ihl=%d source=%d dest=%d\n",
1617 iph->ihl, tcph->source, tcph->dest);
1618 return -EINVAL;
1619 }
1620
1621 cm_info->local_port = ntohs(tcph->dest);
1622 cm_info->remote_port = ntohs(tcph->source);
1623
1624 qed_iwarp_print_cm_info(p_hwfn, cm_info);
1625
1626 *tcp_start_offset = eth_hlen + ip_hlen;
1627
1628 return 0;
1629}
1630
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03001631static void
1632qed_iwarp_ll2_comp_syn_pkt(void *cxt, struct qed_ll2_comp_rx_data *data)
1633{
1634 struct qed_iwarp_ll2_buff *buf = data->cookie;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001635 struct qed_iwarp_listener *listener;
1636 struct qed_ll2_tx_pkt_info tx_pkt;
1637 struct qed_iwarp_cm_info cm_info;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03001638 struct qed_hwfn *p_hwfn = cxt;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001639 u8 remote_mac_addr[ETH_ALEN];
1640 u8 local_mac_addr[ETH_ALEN];
Kalderon, Michal456a5842017-07-02 10:29:27 +03001641 struct qed_iwarp_ep *ep;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001642 int tcp_start_offset;
Kalderon, Michal456a5842017-07-02 10:29:27 +03001643 u8 ts_hdr_size = 0;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001644 u8 ll2_syn_handle;
1645 int payload_len;
Kalderon, Michal456a5842017-07-02 10:29:27 +03001646 u32 hdr_size;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001647 int rc;
1648
1649 memset(&cm_info, 0, sizeof(cm_info));
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03001650
1651 if (GET_FIELD(data->parse_flags,
1652 PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED) &&
1653 GET_FIELD(data->parse_flags, PARSING_AND_ERR_FLAGS_L4CHKSMERROR)) {
1654 DP_NOTICE(p_hwfn, "Syn packet received with checksum error\n");
1655 goto err;
1656 }
1657
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001658 rc = qed_iwarp_parse_rx_pkt(p_hwfn, &cm_info, (u8 *)(buf->data) +
1659 data->u.placement_offset, remote_mac_addr,
1660 local_mac_addr, &payload_len,
1661 &tcp_start_offset);
1662 if (rc)
1663 goto err;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03001664
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001665 /* Check if there is a listener for this 4-tuple+vlan */
1666 ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle;
1667 listener = qed_iwarp_get_listener(p_hwfn, &cm_info);
1668 if (!listener) {
1669 DP_VERBOSE(p_hwfn,
1670 QED_MSG_RDMA,
1671 "SYN received on tuple not listened on parse_flags=%d packet len=%d\n",
1672 data->parse_flags, data->length.packet_length);
1673
1674 memset(&tx_pkt, 0, sizeof(tx_pkt));
1675 tx_pkt.num_of_bds = 1;
1676 tx_pkt.vlan = data->vlan;
1677
1678 if (GET_FIELD(data->parse_flags,
1679 PARSING_AND_ERR_FLAGS_TAG8021QEXIST))
1680 SET_FIELD(tx_pkt.bd_flags,
1681 CORE_TX_BD_DATA_VLAN_INSERTION, 1);
1682
1683 tx_pkt.l4_hdr_offset_w = (data->length.packet_length) >> 2;
1684 tx_pkt.tx_dest = QED_LL2_TX_DEST_LB;
1685 tx_pkt.first_frag = buf->data_phys_addr +
1686 data->u.placement_offset;
1687 tx_pkt.first_frag_len = data->length.packet_length;
1688 tx_pkt.cookie = buf;
1689
1690 rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_syn_handle,
1691 &tx_pkt, true);
1692
1693 if (rc) {
1694 DP_NOTICE(p_hwfn,
1695 "Can't post SYN back to chip rc=%d\n", rc);
1696 goto err;
1697 }
1698 return;
1699 }
1700
1701 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Received syn on listening port\n");
Kalderon, Michal456a5842017-07-02 10:29:27 +03001702 /* There may be an open ep on this connection if this is a syn
1703 * retrasnmit... need to make sure there isn't...
1704 */
1705 if (qed_iwarp_ep_exists(p_hwfn, &cm_info))
1706 goto err;
1707
1708 ep = qed_iwarp_get_free_ep(p_hwfn);
1709 if (!ep)
1710 goto err;
1711
1712 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1713 list_add_tail(&ep->list_entry, &p_hwfn->p_rdma_info->iwarp.ep_list);
1714 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1715
1716 ether_addr_copy(ep->remote_mac_addr, remote_mac_addr);
1717 ether_addr_copy(ep->local_mac_addr, local_mac_addr);
1718
1719 memcpy(&ep->cm_info, &cm_info, sizeof(ep->cm_info));
1720
1721 if (p_hwfn->p_rdma_info->iwarp.tcp_flags & QED_IWARP_TS_EN)
1722 ts_hdr_size = TIMESTAMP_HEADER_SIZE;
1723
1724 hdr_size = ((cm_info.ip_version == QED_TCP_IPV4) ? 40 : 60) +
1725 ts_hdr_size;
1726 ep->mss = p_hwfn->p_rdma_info->iwarp.max_mtu - hdr_size;
1727 ep->mss = min_t(u16, QED_IWARP_MAX_FW_MSS, ep->mss);
1728
1729 ep->event_cb = listener->event_cb;
1730 ep->cb_context = listener->cb_context;
1731 ep->connect_mode = TCP_CONNECT_PASSIVE;
1732
1733 ep->syn = buf;
1734 ep->syn_ip_payload_length = (u16)payload_len;
1735 ep->syn_phy_addr = buf->data_phys_addr + data->u.placement_offset +
1736 tcp_start_offset;
1737
1738 rc = qed_iwarp_tcp_offload(p_hwfn, ep);
1739 if (rc) {
1740 qed_iwarp_return_ep(p_hwfn, ep);
1741 goto err;
1742 }
1743
1744 return;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03001745err:
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001746 qed_iwarp_ll2_post_rx(p_hwfn, buf, ll2_syn_handle);
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03001747}
1748
1749static void qed_iwarp_ll2_rel_rx_pkt(void *cxt, u8 connection_handle,
1750 void *cookie, dma_addr_t rx_buf_addr,
1751 bool b_last_packet)
1752{
1753 struct qed_iwarp_ll2_buff *buffer = cookie;
1754 struct qed_hwfn *p_hwfn = cxt;
1755
1756 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size,
1757 buffer->data, buffer->data_phys_addr);
1758 kfree(buffer);
1759}
1760
1761static void qed_iwarp_ll2_comp_tx_pkt(void *cxt, u8 connection_handle,
1762 void *cookie, dma_addr_t first_frag_addr,
1763 bool b_last_fragment, bool b_last_packet)
1764{
1765 struct qed_iwarp_ll2_buff *buffer = cookie;
1766 struct qed_hwfn *p_hwfn = cxt;
1767
1768 /* this was originally an rx packet, post it back */
1769 qed_iwarp_ll2_post_rx(p_hwfn, buffer, connection_handle);
1770}
1771
1772static void qed_iwarp_ll2_rel_tx_pkt(void *cxt, u8 connection_handle,
1773 void *cookie, dma_addr_t first_frag_addr,
1774 bool b_last_fragment, bool b_last_packet)
1775{
1776 struct qed_iwarp_ll2_buff *buffer = cookie;
1777 struct qed_hwfn *p_hwfn = cxt;
1778
1779 if (!buffer)
1780 return;
1781
1782 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size,
1783 buffer->data, buffer->data_phys_addr);
1784
1785 kfree(buffer);
1786}
1787
1788static int qed_iwarp_ll2_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1789{
1790 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
1791 int rc = 0;
1792
1793 if (iwarp_info->ll2_syn_handle != QED_IWARP_HANDLE_INVAL) {
1794 rc = qed_ll2_terminate_connection(p_hwfn,
1795 iwarp_info->ll2_syn_handle);
1796 if (rc)
1797 DP_INFO(p_hwfn, "Failed to terminate syn connection\n");
1798
1799 qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_syn_handle);
1800 iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL;
1801 }
1802
1803 qed_llh_remove_mac_filter(p_hwfn,
1804 p_ptt, p_hwfn->p_rdma_info->iwarp.mac_addr);
1805 return rc;
1806}
1807
1808static int
1809qed_iwarp_ll2_alloc_buffers(struct qed_hwfn *p_hwfn,
1810 int num_rx_bufs, int buff_size, u8 ll2_handle)
1811{
1812 struct qed_iwarp_ll2_buff *buffer;
1813 int rc = 0;
1814 int i;
1815
1816 for (i = 0; i < num_rx_bufs; i++) {
1817 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
1818 if (!buffer) {
1819 rc = -ENOMEM;
1820 break;
1821 }
1822
1823 buffer->data = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
1824 buff_size,
1825 &buffer->data_phys_addr,
1826 GFP_KERNEL);
1827 if (!buffer->data) {
1828 kfree(buffer);
1829 rc = -ENOMEM;
1830 break;
1831 }
1832
1833 buffer->buff_size = buff_size;
1834 rc = qed_iwarp_ll2_post_rx(p_hwfn, buffer, ll2_handle);
1835 if (rc)
1836 /* buffers will be deallocated by qed_ll2 */
1837 break;
1838 }
1839 return rc;
1840}
1841
1842#define QED_IWARP_MAX_BUF_SIZE(mtu) \
1843 ALIGN((mtu) + ETH_HLEN + 2 * VLAN_HLEN + 2 + ETH_CACHE_LINE_SIZE, \
1844 ETH_CACHE_LINE_SIZE)
1845
1846static int
1847qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn,
1848 struct qed_rdma_start_in_params *params,
1849 struct qed_ptt *p_ptt)
1850{
1851 struct qed_iwarp_info *iwarp_info;
1852 struct qed_ll2_acquire_data data;
1853 struct qed_ll2_cbs cbs;
1854 int rc = 0;
1855
1856 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
1857 iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL;
1858
1859 iwarp_info->max_mtu = params->max_mtu;
1860
1861 ether_addr_copy(p_hwfn->p_rdma_info->iwarp.mac_addr, params->mac_addr);
1862
1863 rc = qed_llh_add_mac_filter(p_hwfn, p_ptt, params->mac_addr);
1864 if (rc)
1865 return rc;
1866
1867 /* Start SYN connection */
1868 cbs.rx_comp_cb = qed_iwarp_ll2_comp_syn_pkt;
1869 cbs.rx_release_cb = qed_iwarp_ll2_rel_rx_pkt;
1870 cbs.tx_comp_cb = qed_iwarp_ll2_comp_tx_pkt;
1871 cbs.tx_release_cb = qed_iwarp_ll2_rel_tx_pkt;
1872 cbs.cookie = p_hwfn;
1873
1874 memset(&data, 0, sizeof(data));
1875 data.input.conn_type = QED_LL2_TYPE_IWARP;
1876 data.input.mtu = QED_IWARP_MAX_SYN_PKT_SIZE;
1877 data.input.rx_num_desc = QED_IWARP_LL2_SYN_RX_SIZE;
1878 data.input.tx_num_desc = QED_IWARP_LL2_SYN_TX_SIZE;
1879 data.input.tx_max_bds_per_packet = 1; /* will never be fragmented */
1880 data.input.tx_tc = PKT_LB_TC;
1881 data.input.tx_dest = QED_LL2_TX_DEST_LB;
1882 data.p_connection_handle = &iwarp_info->ll2_syn_handle;
1883 data.cbs = &cbs;
1884
1885 rc = qed_ll2_acquire_connection(p_hwfn, &data);
1886 if (rc) {
1887 DP_NOTICE(p_hwfn, "Failed to acquire LL2 connection\n");
1888 qed_llh_remove_mac_filter(p_hwfn, p_ptt, params->mac_addr);
1889 return rc;
1890 }
1891
1892 rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_syn_handle);
1893 if (rc) {
1894 DP_NOTICE(p_hwfn, "Failed to establish LL2 connection\n");
1895 goto err;
1896 }
1897
1898 rc = qed_iwarp_ll2_alloc_buffers(p_hwfn,
1899 QED_IWARP_LL2_SYN_RX_SIZE,
1900 QED_IWARP_MAX_SYN_PKT_SIZE,
1901 iwarp_info->ll2_syn_handle);
1902 if (rc)
1903 goto err;
1904
1905 return rc;
1906err:
1907 qed_iwarp_ll2_stop(p_hwfn, p_ptt);
1908
1909 return rc;
1910}
1911
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001912int qed_iwarp_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
1913 struct qed_rdma_start_in_params *params)
1914{
1915 struct qed_iwarp_info *iwarp_info;
1916 u32 rcv_wnd_size;
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001917
1918 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
1919
1920 iwarp_info->tcp_flags = QED_IWARP_TS_EN;
1921 rcv_wnd_size = QED_IWARP_RCV_WND_SIZE_DEF;
1922
1923 /* value 0 is used for ilog2(QED_IWARP_RCV_WND_SIZE_MIN) */
1924 iwarp_info->rcv_wnd_scale = ilog2(rcv_wnd_size) -
1925 ilog2(QED_IWARP_RCV_WND_SIZE_MIN);
1926 iwarp_info->crc_needed = QED_IWARP_PARAM_CRC_NEEDED;
1927 iwarp_info->mpa_rev = MPA_NEGOTIATION_TYPE_ENHANCED;
1928
1929 iwarp_info->peer2peer = QED_IWARP_PARAM_P2P;
1930
Kalderon, Michal456a5842017-07-02 10:29:27 +03001931 iwarp_info->rtr_type = MPA_RTR_TYPE_ZERO_SEND |
1932 MPA_RTR_TYPE_ZERO_WRITE |
1933 MPA_RTR_TYPE_ZERO_READ;
1934
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001935 spin_lock_init(&p_hwfn->p_rdma_info->iwarp.qp_lock);
Kalderon, Michal456a5842017-07-02 10:29:27 +03001936 INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.ep_list);
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001937 INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.listen_list);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001938
1939 qed_spq_register_async_cb(p_hwfn, PROTOCOLID_IWARP,
1940 qed_iwarp_async_event);
1941
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03001942 return qed_iwarp_ll2_start(p_hwfn, params, p_ptt);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001943}
1944
1945int qed_iwarp_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1946{
1947 int rc;
1948
Kalderon, Michal456a5842017-07-02 10:29:27 +03001949 qed_iwarp_free_prealloc_ep(p_hwfn);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001950 rc = qed_iwarp_wait_for_all_cids(p_hwfn);
1951 if (rc)
1952 return rc;
1953
1954 qed_spq_unregister_async_cb(p_hwfn, PROTOCOLID_IWARP);
1955
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03001956 return qed_iwarp_ll2_stop(p_hwfn, p_ptt);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001957}
1958
Kalderon, Michal456a5842017-07-02 10:29:27 +03001959void
1960qed_iwarp_connect_complete(struct qed_hwfn *p_hwfn,
1961 struct qed_iwarp_ep *ep, u8 fw_return_code)
1962{
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03001963 u8 ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle;
Kalderon, Michal456a5842017-07-02 10:29:27 +03001964
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03001965 if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
1966 /* Done with the SYN packet, post back to ll2 rx */
1967 qed_iwarp_ll2_post_rx(p_hwfn, ep->syn, ll2_syn_handle);
1968
1969 ep->syn = NULL;
1970
1971 /* If connect failed - upper layer doesn't know about it */
1972 qed_iwarp_mpa_received(p_hwfn, ep);
1973 } else {
1974 qed_iwarp_mpa_offload(p_hwfn, ep);
1975 }
Kalderon, Michal456a5842017-07-02 10:29:27 +03001976}
1977
1978static inline bool
1979qed_iwarp_check_ep_ok(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
1980{
1981 if (!ep || (ep->sig != QED_EP_SIG)) {
1982 DP_ERR(p_hwfn, "ERROR ON ASYNC ep=%p\n", ep);
1983 return false;
1984 }
1985
1986 return true;
1987}
1988
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001989static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn,
1990 u8 fw_event_code, u16 echo,
1991 union event_ring_data *data,
1992 u8 fw_return_code)
1993{
Kalderon, Michal456a5842017-07-02 10:29:27 +03001994 struct regpair *fw_handle = &data->rdma_data.async_handle;
1995 struct qed_iwarp_ep *ep = NULL;
1996 u16 cid;
1997
1998 ep = (struct qed_iwarp_ep *)(uintptr_t)HILO_64(fw_handle->hi,
1999 fw_handle->lo);
2000
2001 switch (fw_event_code) {
2002 case IWARP_EVENT_TYPE_ASYNC_CONNECT_COMPLETE:
2003 /* Async completion after TCP 3-way handshake */
2004 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2005 return -EINVAL;
2006 DP_VERBOSE(p_hwfn,
2007 QED_MSG_RDMA,
2008 "EP(0x%x) IWARP_EVENT_TYPE_ASYNC_CONNECT_COMPLETE fw_ret_code=%d\n",
2009 ep->tcp_cid, fw_return_code);
2010 qed_iwarp_connect_complete(p_hwfn, ep, fw_return_code);
2011 break;
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002012 /* Async event for active side only */
2013 case IWARP_EVENT_TYPE_ASYNC_ENHANCED_MPA_REPLY_ARRIVED:
2014 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2015 return -EINVAL;
2016 DP_VERBOSE(p_hwfn,
2017 QED_MSG_RDMA,
2018 "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_MPA_REPLY_ARRIVED fw_ret_code=%d\n",
2019 ep->cid, fw_return_code);
2020 qed_iwarp_mpa_reply_arrived(p_hwfn, ep);
2021 break;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002022 case IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE:
2023 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2024 return -EINVAL;
2025 DP_VERBOSE(p_hwfn,
2026 QED_MSG_RDMA,
2027 "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE fw_ret_code=%d\n",
2028 ep->cid, fw_return_code);
2029 qed_iwarp_mpa_complete(p_hwfn, ep, fw_return_code);
2030 break;
2031 case IWARP_EVENT_TYPE_ASYNC_CID_CLEANED:
2032 cid = (u16)le32_to_cpu(fw_handle->lo);
2033 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2034 "(0x%x)IWARP_EVENT_TYPE_ASYNC_CID_CLEANED\n", cid);
2035 qed_iwarp_cid_cleaned(p_hwfn, cid);
2036
2037 break;
2038 }
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002039 return 0;
2040}
2041
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002042int
2043qed_iwarp_create_listen(void *rdma_cxt,
2044 struct qed_iwarp_listen_in *iparams,
2045 struct qed_iwarp_listen_out *oparams)
2046{
2047 struct qed_hwfn *p_hwfn = rdma_cxt;
2048 struct qed_iwarp_listener *listener;
2049
2050 listener = kzalloc(sizeof(*listener), GFP_KERNEL);
2051 if (!listener)
2052 return -ENOMEM;
2053
2054 listener->ip_version = iparams->ip_version;
2055 memcpy(listener->ip_addr, iparams->ip_addr, sizeof(listener->ip_addr));
2056 listener->port = iparams->port;
2057 listener->vlan = iparams->vlan;
2058
2059 listener->event_cb = iparams->event_cb;
2060 listener->cb_context = iparams->cb_context;
2061 listener->max_backlog = iparams->max_backlog;
2062 oparams->handle = listener;
2063
2064 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2065 list_add_tail(&listener->list_entry,
2066 &p_hwfn->p_rdma_info->iwarp.listen_list);
2067 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2068
2069 DP_VERBOSE(p_hwfn,
2070 QED_MSG_RDMA,
2071 "callback=%p handle=%p ip=%x:%x:%x:%x port=0x%x vlan=0x%x\n",
2072 listener->event_cb,
2073 listener,
2074 listener->ip_addr[0],
2075 listener->ip_addr[1],
2076 listener->ip_addr[2],
2077 listener->ip_addr[3], listener->port, listener->vlan);
2078
2079 return 0;
2080}
2081
2082int qed_iwarp_destroy_listen(void *rdma_cxt, void *handle)
2083{
2084 struct qed_iwarp_listener *listener = handle;
2085 struct qed_hwfn *p_hwfn = rdma_cxt;
2086
2087 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "handle=%p\n", handle);
2088
2089 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2090 list_del(&listener->list_entry);
2091 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2092
2093 kfree(listener);
2094
2095 return 0;
2096}
2097
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002098int qed_iwarp_send_rtr(void *rdma_cxt, struct qed_iwarp_send_rtr_in *iparams)
2099{
2100 struct qed_hwfn *p_hwfn = rdma_cxt;
2101 struct qed_sp_init_data init_data;
2102 struct qed_spq_entry *p_ent;
2103 struct qed_iwarp_ep *ep;
2104 struct qed_rdma_qp *qp;
2105 int rc;
2106
2107 ep = iparams->ep_context;
2108 if (!ep) {
2109 DP_ERR(p_hwfn, "Ep Context receive in send_rtr is NULL\n");
2110 return -EINVAL;
2111 }
2112
2113 qp = ep->qp;
2114
2115 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x)\n",
2116 qp->icid, ep->tcp_cid);
2117
2118 memset(&init_data, 0, sizeof(init_data));
2119 init_data.cid = qp->icid;
2120 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
2121 init_data.comp_mode = QED_SPQ_MODE_CB;
2122
2123 rc = qed_sp_init_request(p_hwfn, &p_ent,
2124 IWARP_RAMROD_CMD_ID_MPA_OFFLOAD_SEND_RTR,
2125 PROTOCOLID_IWARP, &init_data);
2126
2127 if (rc)
2128 return rc;
2129
2130 rc = qed_spq_post(p_hwfn, p_ent, NULL);
2131
2132 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = 0x%x\n", rc);
2133
2134 return rc;
2135}
2136
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002137void
2138qed_iwarp_query_qp(struct qed_rdma_qp *qp,
2139 struct qed_rdma_query_qp_out_params *out_params)
2140{
2141 out_params->state = qed_iwarp2roce_state(qp->iwarp_state);
2142}