blob: 299494225f44a43c6381435089fdd6103429990b [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"
Michal Kalderond1abfd02017-09-24 12:09:43 +030044#include "qed_ooo.h"
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030045
46#define QED_IWARP_ORD_DEFAULT 32
47#define QED_IWARP_IRD_DEFAULT 32
Kalderon, Michal456a5842017-07-02 10:29:27 +030048#define QED_IWARP_MAX_FW_MSS 4120
49
50#define QED_EP_SIG 0xecabcdef
51
52struct mpa_v2_hdr {
53 __be16 ird;
54 __be16 ord;
55};
56
57#define MPA_V2_PEER2PEER_MODEL 0x8000
58#define MPA_V2_SEND_RTR 0x4000 /* on ird */
59#define MPA_V2_READ_RTR 0x4000 /* on ord */
60#define MPA_V2_WRITE_RTR 0x8000
61#define MPA_V2_IRD_ORD_MASK 0x3FFF
62
63#define MPA_REV2(_mpa_rev) ((_mpa_rev) == MPA_NEGOTIATION_TYPE_ENHANCED)
64
65#define QED_IWARP_INVALID_TCP_CID 0xffffffff
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030066#define QED_IWARP_RCV_WND_SIZE_DEF (256 * 1024)
67#define QED_IWARP_RCV_WND_SIZE_MIN (64 * 1024)
Kalderon, Michal456a5842017-07-02 10:29:27 +030068#define TIMESTAMP_HEADER_SIZE (12)
69
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030070#define QED_IWARP_TS_EN BIT(0)
Kalderon, Michal456a5842017-07-02 10:29:27 +030071#define QED_IWARP_DA_EN BIT(1)
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030072#define QED_IWARP_PARAM_CRC_NEEDED (1)
73#define QED_IWARP_PARAM_P2P (1)
74
75static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn,
76 u8 fw_event_code, u16 echo,
77 union event_ring_data *data,
78 u8 fw_return_code);
79
80/* Override devinfo with iWARP specific values */
81void qed_iwarp_init_devinfo(struct qed_hwfn *p_hwfn)
82{
83 struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
84
85 dev->max_inline = IWARP_REQ_MAX_INLINE_DATA_SIZE;
86 dev->max_qp = min_t(u32,
87 IWARP_MAX_QPS,
Kalderon, Michal456a5842017-07-02 10:29:27 +030088 p_hwfn->p_rdma_info->num_qps) -
89 QED_IWARP_PREALLOC_CNT;
Kalderon, Michal67b40dc2017-07-02 10:29:22 +030090
91 dev->max_cq = dev->max_qp;
92
93 dev->max_qp_resp_rd_atomic_resc = QED_IWARP_IRD_DEFAULT;
94 dev->max_qp_req_rd_atomic_resc = QED_IWARP_ORD_DEFAULT;
95}
96
97void qed_iwarp_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
98{
99 p_hwfn->rdma_prs_search_reg = PRS_REG_SEARCH_TCP;
100 qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1);
101 p_hwfn->b_rdma_enabled_in_prs = true;
102}
103
Kalderon, Michal456a5842017-07-02 10:29:27 +0300104/* We have two cid maps, one for tcp which should be used only from passive
105 * syn processing and replacing a pre-allocated ep in the list. The second
106 * for active tcp and for QPs.
107 */
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300108static void qed_iwarp_cid_cleaned(struct qed_hwfn *p_hwfn, u32 cid)
109{
110 cid -= qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
111
112 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
Kalderon, Michal456a5842017-07-02 10:29:27 +0300113
114 if (cid < QED_IWARP_PREALLOC_CNT)
115 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map,
116 cid);
117 else
118 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid);
119
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300120 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
121}
122
Michal Kalderond1abfd02017-09-24 12:09:43 +0300123void qed_iwarp_init_fw_ramrod(struct qed_hwfn *p_hwfn,
124 struct iwarp_init_func_params *p_ramrod)
125{
126 p_ramrod->ll2_ooo_q_index = RESC_START(p_hwfn, QED_LL2_QUEUE) +
127 p_hwfn->p_rdma_info->iwarp.ll2_ooo_handle;
128}
129
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300130static int qed_iwarp_alloc_cid(struct qed_hwfn *p_hwfn, u32 *cid)
131{
132 int rc;
133
134 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
135 rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid);
136 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
137 if (rc) {
138 DP_NOTICE(p_hwfn, "Failed in allocating iwarp cid\n");
139 return rc;
140 }
141 *cid += qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
142
143 rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, *cid);
144 if (rc)
145 qed_iwarp_cid_cleaned(p_hwfn, *cid);
146
147 return rc;
148}
149
Kalderon, Michal456a5842017-07-02 10:29:27 +0300150static void qed_iwarp_set_tcp_cid(struct qed_hwfn *p_hwfn, u32 cid)
151{
152 cid -= qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
153
154 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
155 qed_bmap_set_id(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map, cid);
156 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
157}
158
159/* This function allocates a cid for passive tcp (called from syn receive)
160 * the reason it's separate from the regular cid allocation is because it
161 * is assured that these cids already have ilt allocated. They are preallocated
162 * to ensure that we won't need to allocate memory during syn processing
163 */
164static int qed_iwarp_alloc_tcp_cid(struct qed_hwfn *p_hwfn, u32 *cid)
165{
166 int rc;
167
168 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
169
170 rc = qed_rdma_bmap_alloc_id(p_hwfn,
171 &p_hwfn->p_rdma_info->tcp_cid_map, cid);
172
173 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
174
175 if (rc) {
176 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
177 "can't allocate iwarp tcp cid max-count=%d\n",
178 p_hwfn->p_rdma_info->tcp_cid_map.max_count);
179
180 *cid = QED_IWARP_INVALID_TCP_CID;
181 return rc;
182 }
183
184 *cid += qed_cxt_get_proto_cid_start(p_hwfn,
185 p_hwfn->p_rdma_info->proto);
186 return 0;
187}
188
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300189int qed_iwarp_create_qp(struct qed_hwfn *p_hwfn,
190 struct qed_rdma_qp *qp,
191 struct qed_rdma_create_qp_out_params *out_params)
192{
193 struct iwarp_create_qp_ramrod_data *p_ramrod;
194 struct qed_sp_init_data init_data;
195 struct qed_spq_entry *p_ent;
196 u16 physical_queue;
197 u32 cid;
198 int rc;
199
200 qp->shared_queue = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
201 IWARP_SHARED_QUEUE_PAGE_SIZE,
202 &qp->shared_queue_phys_addr,
203 GFP_KERNEL);
204 if (!qp->shared_queue)
205 return -ENOMEM;
206
207 out_params->sq_pbl_virt = (u8 *)qp->shared_queue +
208 IWARP_SHARED_QUEUE_PAGE_SQ_PBL_OFFSET;
209 out_params->sq_pbl_phys = qp->shared_queue_phys_addr +
210 IWARP_SHARED_QUEUE_PAGE_SQ_PBL_OFFSET;
211 out_params->rq_pbl_virt = (u8 *)qp->shared_queue +
212 IWARP_SHARED_QUEUE_PAGE_RQ_PBL_OFFSET;
213 out_params->rq_pbl_phys = qp->shared_queue_phys_addr +
214 IWARP_SHARED_QUEUE_PAGE_RQ_PBL_OFFSET;
215
216 rc = qed_iwarp_alloc_cid(p_hwfn, &cid);
217 if (rc)
218 goto err1;
219
220 qp->icid = (u16)cid;
221
222 memset(&init_data, 0, sizeof(init_data));
223 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
224 init_data.cid = qp->icid;
225 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
226
227 rc = qed_sp_init_request(p_hwfn, &p_ent,
228 IWARP_RAMROD_CMD_ID_CREATE_QP,
229 PROTOCOLID_IWARP, &init_data);
230 if (rc)
231 goto err2;
232
233 p_ramrod = &p_ent->ramrod.iwarp_create_qp;
234
235 SET_FIELD(p_ramrod->flags,
236 IWARP_CREATE_QP_RAMROD_DATA_FMR_AND_RESERVED_EN,
237 qp->fmr_and_reserved_lkey);
238
239 SET_FIELD(p_ramrod->flags,
240 IWARP_CREATE_QP_RAMROD_DATA_SIGNALED_COMP, qp->signal_all);
241
242 SET_FIELD(p_ramrod->flags,
243 IWARP_CREATE_QP_RAMROD_DATA_RDMA_RD_EN,
244 qp->incoming_rdma_read_en);
245
246 SET_FIELD(p_ramrod->flags,
247 IWARP_CREATE_QP_RAMROD_DATA_RDMA_WR_EN,
248 qp->incoming_rdma_write_en);
249
250 SET_FIELD(p_ramrod->flags,
251 IWARP_CREATE_QP_RAMROD_DATA_ATOMIC_EN,
252 qp->incoming_atomic_en);
253
254 SET_FIELD(p_ramrod->flags,
255 IWARP_CREATE_QP_RAMROD_DATA_SRQ_FLG, qp->use_srq);
256
257 p_ramrod->pd = qp->pd;
258 p_ramrod->sq_num_pages = qp->sq_num_pages;
259 p_ramrod->rq_num_pages = qp->rq_num_pages;
260
261 p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi);
262 p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo);
263
264 p_ramrod->cq_cid_for_sq =
265 cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->sq_cq_id);
266 p_ramrod->cq_cid_for_rq =
267 cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->rq_cq_id);
268
269 p_ramrod->dpi = cpu_to_le16(qp->dpi);
270
271 physical_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
272 p_ramrod->physical_q0 = cpu_to_le16(physical_queue);
273 physical_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK);
274 p_ramrod->physical_q1 = cpu_to_le16(physical_queue);
275
276 rc = qed_spq_post(p_hwfn, p_ent, NULL);
277 if (rc)
278 goto err2;
279
280 return rc;
281
282err2:
283 qed_iwarp_cid_cleaned(p_hwfn, cid);
284err1:
285 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
286 IWARP_SHARED_QUEUE_PAGE_SIZE,
287 qp->shared_queue, qp->shared_queue_phys_addr);
288
289 return rc;
290}
291
292static int qed_iwarp_modify_fw(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
293{
294 struct iwarp_modify_qp_ramrod_data *p_ramrod;
295 struct qed_sp_init_data init_data;
296 struct qed_spq_entry *p_ent;
297 int rc;
298
299 /* Get SPQ entry */
300 memset(&init_data, 0, sizeof(init_data));
301 init_data.cid = qp->icid;
302 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
303 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
304
305 rc = qed_sp_init_request(p_hwfn, &p_ent,
306 IWARP_RAMROD_CMD_ID_MODIFY_QP,
307 p_hwfn->p_rdma_info->proto, &init_data);
308 if (rc)
309 return rc;
310
311 p_ramrod = &p_ent->ramrod.iwarp_modify_qp;
312 SET_FIELD(p_ramrod->flags, IWARP_MODIFY_QP_RAMROD_DATA_STATE_TRANS_EN,
313 0x1);
314 if (qp->iwarp_state == QED_IWARP_QP_STATE_CLOSING)
315 p_ramrod->transition_to_state = IWARP_MODIFY_QP_STATE_CLOSING;
316 else
317 p_ramrod->transition_to_state = IWARP_MODIFY_QP_STATE_ERROR;
318
319 rc = qed_spq_post(p_hwfn, p_ent, NULL);
320
321 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x)rc=%d\n", qp->icid, rc);
322
323 return rc;
324}
325
326enum qed_iwarp_qp_state qed_roce2iwarp_state(enum qed_roce_qp_state state)
327{
328 switch (state) {
329 case QED_ROCE_QP_STATE_RESET:
330 case QED_ROCE_QP_STATE_INIT:
331 case QED_ROCE_QP_STATE_RTR:
332 return QED_IWARP_QP_STATE_IDLE;
333 case QED_ROCE_QP_STATE_RTS:
334 return QED_IWARP_QP_STATE_RTS;
335 case QED_ROCE_QP_STATE_SQD:
336 return QED_IWARP_QP_STATE_CLOSING;
337 case QED_ROCE_QP_STATE_ERR:
338 return QED_IWARP_QP_STATE_ERROR;
339 case QED_ROCE_QP_STATE_SQE:
340 return QED_IWARP_QP_STATE_TERMINATE;
341 default:
342 return QED_IWARP_QP_STATE_ERROR;
343 }
344}
345
346static enum qed_roce_qp_state
347qed_iwarp2roce_state(enum qed_iwarp_qp_state state)
348{
349 switch (state) {
350 case QED_IWARP_QP_STATE_IDLE:
351 return QED_ROCE_QP_STATE_INIT;
352 case QED_IWARP_QP_STATE_RTS:
353 return QED_ROCE_QP_STATE_RTS;
354 case QED_IWARP_QP_STATE_TERMINATE:
355 return QED_ROCE_QP_STATE_SQE;
356 case QED_IWARP_QP_STATE_CLOSING:
357 return QED_ROCE_QP_STATE_SQD;
358 case QED_IWARP_QP_STATE_ERROR:
359 return QED_ROCE_QP_STATE_ERR;
360 default:
361 return QED_ROCE_QP_STATE_ERR;
362 }
363}
364
365const char *iwarp_state_names[] = {
366 "IDLE",
367 "RTS",
368 "TERMINATE",
369 "CLOSING",
370 "ERROR",
371};
372
373int
374qed_iwarp_modify_qp(struct qed_hwfn *p_hwfn,
375 struct qed_rdma_qp *qp,
376 enum qed_iwarp_qp_state new_state, bool internal)
377{
378 enum qed_iwarp_qp_state prev_iw_state;
379 bool modify_fw = false;
380 int rc = 0;
381
382 /* modify QP can be called from upper-layer or as a result of async
383 * RST/FIN... therefore need to protect
384 */
385 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
386 prev_iw_state = qp->iwarp_state;
387
388 if (prev_iw_state == new_state) {
389 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
390 return 0;
391 }
392
393 switch (prev_iw_state) {
394 case QED_IWARP_QP_STATE_IDLE:
395 switch (new_state) {
396 case QED_IWARP_QP_STATE_RTS:
397 qp->iwarp_state = QED_IWARP_QP_STATE_RTS;
398 break;
399 case QED_IWARP_QP_STATE_ERROR:
400 qp->iwarp_state = QED_IWARP_QP_STATE_ERROR;
401 if (!internal)
402 modify_fw = true;
403 break;
404 default:
405 break;
406 }
407 break;
408 case QED_IWARP_QP_STATE_RTS:
409 switch (new_state) {
410 case QED_IWARP_QP_STATE_CLOSING:
411 if (!internal)
412 modify_fw = true;
413
414 qp->iwarp_state = QED_IWARP_QP_STATE_CLOSING;
415 break;
416 case QED_IWARP_QP_STATE_ERROR:
417 if (!internal)
418 modify_fw = true;
419 qp->iwarp_state = QED_IWARP_QP_STATE_ERROR;
420 break;
421 default:
422 break;
423 }
424 break;
425 case QED_IWARP_QP_STATE_ERROR:
426 switch (new_state) {
427 case QED_IWARP_QP_STATE_IDLE:
428
429 qp->iwarp_state = new_state;
430 break;
431 case QED_IWARP_QP_STATE_CLOSING:
432 /* could happen due to race... do nothing.... */
433 break;
434 default:
435 rc = -EINVAL;
436 }
437 break;
438 case QED_IWARP_QP_STATE_TERMINATE:
439 case QED_IWARP_QP_STATE_CLOSING:
440 qp->iwarp_state = new_state;
441 break;
442 default:
443 break;
444 }
445
446 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) %s --> %s%s\n",
447 qp->icid,
448 iwarp_state_names[prev_iw_state],
449 iwarp_state_names[qp->iwarp_state],
450 internal ? "internal" : "");
451
452 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
453
454 if (modify_fw)
455 rc = qed_iwarp_modify_fw(p_hwfn, qp);
456
457 return rc;
458}
459
460int qed_iwarp_fw_destroy(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
461{
462 struct qed_sp_init_data init_data;
463 struct qed_spq_entry *p_ent;
464 int rc;
465
466 /* Get SPQ entry */
467 memset(&init_data, 0, sizeof(init_data));
468 init_data.cid = qp->icid;
469 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
470 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
471
472 rc = qed_sp_init_request(p_hwfn, &p_ent,
473 IWARP_RAMROD_CMD_ID_DESTROY_QP,
474 p_hwfn->p_rdma_info->proto, &init_data);
475 if (rc)
476 return rc;
477
478 rc = qed_spq_post(p_hwfn, p_ent, NULL);
479
480 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) rc = %d\n", qp->icid, rc);
481
482 return rc;
483}
484
Kalderon, Michal456a5842017-07-02 10:29:27 +0300485static void qed_iwarp_destroy_ep(struct qed_hwfn *p_hwfn,
486 struct qed_iwarp_ep *ep,
487 bool remove_from_active_list)
488{
489 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
490 sizeof(*ep->ep_buffer_virt),
491 ep->ep_buffer_virt, ep->ep_buffer_phys);
492
493 if (remove_from_active_list) {
494 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
495 list_del(&ep->list_entry);
496 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
497 }
498
499 if (ep->qp)
500 ep->qp->ep = NULL;
501
502 kfree(ep);
503}
504
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300505int qed_iwarp_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
506{
Kalderon, Michalfc4c6062017-07-02 10:29:29 +0300507 struct qed_iwarp_ep *ep = qp->ep;
508 int wait_count = 0;
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300509 int rc = 0;
510
511 if (qp->iwarp_state != QED_IWARP_QP_STATE_ERROR) {
512 rc = qed_iwarp_modify_qp(p_hwfn, qp,
513 QED_IWARP_QP_STATE_ERROR, false);
514 if (rc)
515 return rc;
516 }
517
Kalderon, Michalfc4c6062017-07-02 10:29:29 +0300518 /* Make sure ep is closed before returning and freeing memory. */
519 if (ep) {
520 while (ep->state != QED_IWARP_EP_CLOSED && wait_count++ < 200)
521 msleep(100);
522
523 if (ep->state != QED_IWARP_EP_CLOSED)
524 DP_NOTICE(p_hwfn, "ep state close timeout state=%x\n",
525 ep->state);
526
527 qed_iwarp_destroy_ep(p_hwfn, ep, false);
528 }
529
Kalderon, Michal67b40dc2017-07-02 10:29:22 +0300530 rc = qed_iwarp_fw_destroy(p_hwfn, qp);
531
532 if (qp->shared_queue)
533 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
534 IWARP_SHARED_QUEUE_PAGE_SIZE,
535 qp->shared_queue, qp->shared_queue_phys_addr);
536
537 return rc;
538}
539
Kalderon, Michal456a5842017-07-02 10:29:27 +0300540static int
541qed_iwarp_create_ep(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep **ep_out)
542{
543 struct qed_iwarp_ep *ep;
544 int rc;
545
546 ep = kzalloc(sizeof(*ep), GFP_KERNEL);
547 if (!ep)
548 return -ENOMEM;
549
550 ep->state = QED_IWARP_EP_INIT;
551
552 ep->ep_buffer_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
553 sizeof(*ep->ep_buffer_virt),
554 &ep->ep_buffer_phys,
555 GFP_KERNEL);
556 if (!ep->ep_buffer_virt) {
557 rc = -ENOMEM;
558 goto err;
559 }
560
561 ep->sig = QED_EP_SIG;
562
563 *ep_out = ep;
564
565 return 0;
566
567err:
568 kfree(ep);
569 return rc;
570}
571
572static void
573qed_iwarp_print_tcp_ramrod(struct qed_hwfn *p_hwfn,
574 struct iwarp_tcp_offload_ramrod_data *p_tcp_ramrod)
575{
576 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "local_mac=%x %x %x, remote_mac=%x %x %x\n",
577 p_tcp_ramrod->tcp.local_mac_addr_lo,
578 p_tcp_ramrod->tcp.local_mac_addr_mid,
579 p_tcp_ramrod->tcp.local_mac_addr_hi,
580 p_tcp_ramrod->tcp.remote_mac_addr_lo,
581 p_tcp_ramrod->tcp.remote_mac_addr_mid,
582 p_tcp_ramrod->tcp.remote_mac_addr_hi);
583
584 if (p_tcp_ramrod->tcp.ip_version == TCP_IPV4) {
585 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
Kalderon, Michal91d1ae42017-07-09 13:00:16 +0300586 "local_ip=%pI4h:%x, remote_ip=%pI4h:%x, vlan=%x\n",
Kalderon, Michal456a5842017-07-02 10:29:27 +0300587 p_tcp_ramrod->tcp.local_ip,
588 p_tcp_ramrod->tcp.local_port,
589 p_tcp_ramrod->tcp.remote_ip,
590 p_tcp_ramrod->tcp.remote_port,
591 p_tcp_ramrod->tcp.vlan_id);
592 } else {
593 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
Kalderon, Michal91d1ae42017-07-09 13:00:16 +0300594 "local_ip=%pI6:%x, remote_ip=%pI6:%x, vlan=%x\n",
Kalderon, Michal456a5842017-07-02 10:29:27 +0300595 p_tcp_ramrod->tcp.local_ip,
596 p_tcp_ramrod->tcp.local_port,
597 p_tcp_ramrod->tcp.remote_ip,
598 p_tcp_ramrod->tcp.remote_port,
599 p_tcp_ramrod->tcp.vlan_id);
600 }
601
602 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
603 "flow_label=%x, ttl=%x, tos_or_tc=%x, mss=%x, rcv_wnd_scale=%x, connect_mode=%x, flags=%x\n",
604 p_tcp_ramrod->tcp.flow_label,
605 p_tcp_ramrod->tcp.ttl,
606 p_tcp_ramrod->tcp.tos_or_tc,
607 p_tcp_ramrod->tcp.mss,
608 p_tcp_ramrod->tcp.rcv_wnd_scale,
609 p_tcp_ramrod->tcp.connect_mode,
610 p_tcp_ramrod->tcp.flags);
611
612 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "syn_ip_payload_length=%x, lo=%x, hi=%x\n",
613 p_tcp_ramrod->tcp.syn_ip_payload_length,
614 p_tcp_ramrod->tcp.syn_phy_addr_lo,
615 p_tcp_ramrod->tcp.syn_phy_addr_hi);
616}
617
618static int
619qed_iwarp_tcp_offload(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
620{
621 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
622 struct iwarp_tcp_offload_ramrod_data *p_tcp_ramrod;
623 struct tcp_offload_params_opt2 *tcp;
624 struct qed_sp_init_data init_data;
625 struct qed_spq_entry *p_ent;
626 dma_addr_t async_output_phys;
627 dma_addr_t in_pdata_phys;
628 u16 physical_q;
629 u8 tcp_flags;
630 int rc;
631 int i;
632
633 memset(&init_data, 0, sizeof(init_data));
634 init_data.cid = ep->tcp_cid;
635 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +0300636 if (ep->connect_mode == TCP_CONNECT_PASSIVE)
637 init_data.comp_mode = QED_SPQ_MODE_CB;
638 else
639 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
Kalderon, Michal456a5842017-07-02 10:29:27 +0300640
641 rc = qed_sp_init_request(p_hwfn, &p_ent,
642 IWARP_RAMROD_CMD_ID_TCP_OFFLOAD,
643 PROTOCOLID_IWARP, &init_data);
644 if (rc)
645 return rc;
646
647 p_tcp_ramrod = &p_ent->ramrod.iwarp_tcp_offload;
648
649 in_pdata_phys = ep->ep_buffer_phys +
650 offsetof(struct qed_iwarp_ep_memory, in_pdata);
651 DMA_REGPAIR_LE(p_tcp_ramrod->iwarp.incoming_ulp_buffer.addr,
652 in_pdata_phys);
653
654 p_tcp_ramrod->iwarp.incoming_ulp_buffer.len =
655 cpu_to_le16(sizeof(ep->ep_buffer_virt->in_pdata));
656
657 async_output_phys = ep->ep_buffer_phys +
658 offsetof(struct qed_iwarp_ep_memory, async_output);
659 DMA_REGPAIR_LE(p_tcp_ramrod->iwarp.async_eqe_output_buf,
660 async_output_phys);
661
662 p_tcp_ramrod->iwarp.handle_for_async.hi = cpu_to_le32(PTR_HI(ep));
663 p_tcp_ramrod->iwarp.handle_for_async.lo = cpu_to_le32(PTR_LO(ep));
664
665 physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
666 p_tcp_ramrod->iwarp.physical_q0 = cpu_to_le16(physical_q);
667 physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK);
668 p_tcp_ramrod->iwarp.physical_q1 = cpu_to_le16(physical_q);
669 p_tcp_ramrod->iwarp.mpa_mode = iwarp_info->mpa_rev;
670
671 tcp = &p_tcp_ramrod->tcp;
672 qed_set_fw_mac_addr(&tcp->remote_mac_addr_hi,
673 &tcp->remote_mac_addr_mid,
674 &tcp->remote_mac_addr_lo, ep->remote_mac_addr);
675 qed_set_fw_mac_addr(&tcp->local_mac_addr_hi, &tcp->local_mac_addr_mid,
676 &tcp->local_mac_addr_lo, ep->local_mac_addr);
677
678 tcp->vlan_id = cpu_to_le16(ep->cm_info.vlan);
679
680 tcp_flags = p_hwfn->p_rdma_info->iwarp.tcp_flags;
681 tcp->flags = 0;
682 SET_FIELD(tcp->flags, TCP_OFFLOAD_PARAMS_OPT2_TS_EN,
683 !!(tcp_flags & QED_IWARP_TS_EN));
684
685 SET_FIELD(tcp->flags, TCP_OFFLOAD_PARAMS_OPT2_DA_EN,
686 !!(tcp_flags & QED_IWARP_DA_EN));
687
688 tcp->ip_version = ep->cm_info.ip_version;
689
690 for (i = 0; i < 4; i++) {
691 tcp->remote_ip[i] = cpu_to_le32(ep->cm_info.remote_ip[i]);
692 tcp->local_ip[i] = cpu_to_le32(ep->cm_info.local_ip[i]);
693 }
694
695 tcp->remote_port = cpu_to_le16(ep->cm_info.remote_port);
696 tcp->local_port = cpu_to_le16(ep->cm_info.local_port);
697 tcp->mss = cpu_to_le16(ep->mss);
698 tcp->flow_label = 0;
699 tcp->ttl = 0x40;
700 tcp->tos_or_tc = 0;
701
702 tcp->rcv_wnd_scale = (u8)p_hwfn->p_rdma_info->iwarp.rcv_wnd_scale;
703 tcp->connect_mode = ep->connect_mode;
704
705 if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
706 tcp->syn_ip_payload_length =
707 cpu_to_le16(ep->syn_ip_payload_length);
708 tcp->syn_phy_addr_hi = DMA_HI_LE(ep->syn_phy_addr);
709 tcp->syn_phy_addr_lo = DMA_LO_LE(ep->syn_phy_addr);
710 }
711
712 qed_iwarp_print_tcp_ramrod(p_hwfn, p_tcp_ramrod);
713
714 rc = qed_spq_post(p_hwfn, p_ent, NULL);
715
716 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
717 "EP(0x%x) Offload completed rc=%d\n", ep->tcp_cid, rc);
718
719 return rc;
720}
721
722static void
723qed_iwarp_mpa_received(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
724{
725 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
726 struct qed_iwarp_cm_event_params params;
727 struct mpa_v2_hdr *mpa_v2;
728 union async_output *async_data;
729 u16 mpa_ord, mpa_ird;
730 u8 mpa_hdr_size = 0;
731 u8 mpa_rev;
732
733 async_data = &ep->ep_buffer_virt->async_output;
734
735 mpa_rev = async_data->mpa_request.mpa_handshake_mode;
736 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
737 "private_data_len=%x handshake_mode=%x private_data=(%x)\n",
738 async_data->mpa_request.ulp_data_len,
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +0300739 mpa_rev, *((u32 *)(ep->ep_buffer_virt->in_pdata)));
Kalderon, Michal456a5842017-07-02 10:29:27 +0300740
741 if (mpa_rev == MPA_NEGOTIATION_TYPE_ENHANCED) {
742 /* Read ord/ird values from private data buffer */
743 mpa_v2 = (struct mpa_v2_hdr *)ep->ep_buffer_virt->in_pdata;
744 mpa_hdr_size = sizeof(*mpa_v2);
745
746 mpa_ord = ntohs(mpa_v2->ord);
747 mpa_ird = ntohs(mpa_v2->ird);
748
749 /* Temprary store in cm_info incoming ord/ird requested, later
750 * replace with negotiated value during accept
751 */
752 ep->cm_info.ord = (u8)min_t(u16,
753 (mpa_ord & MPA_V2_IRD_ORD_MASK),
754 QED_IWARP_ORD_DEFAULT);
755
756 ep->cm_info.ird = (u8)min_t(u16,
757 (mpa_ird & MPA_V2_IRD_ORD_MASK),
758 QED_IWARP_IRD_DEFAULT);
759
760 /* Peer2Peer negotiation */
761 ep->rtr_type = MPA_RTR_TYPE_NONE;
762 if (mpa_ird & MPA_V2_PEER2PEER_MODEL) {
763 if (mpa_ord & MPA_V2_WRITE_RTR)
764 ep->rtr_type |= MPA_RTR_TYPE_ZERO_WRITE;
765
766 if (mpa_ord & MPA_V2_READ_RTR)
767 ep->rtr_type |= MPA_RTR_TYPE_ZERO_READ;
768
769 if (mpa_ird & MPA_V2_SEND_RTR)
770 ep->rtr_type |= MPA_RTR_TYPE_ZERO_SEND;
771
772 ep->rtr_type &= iwarp_info->rtr_type;
773
774 /* if we're left with no match send our capabilities */
775 if (ep->rtr_type == MPA_RTR_TYPE_NONE)
776 ep->rtr_type = iwarp_info->rtr_type;
777 }
778
779 ep->mpa_rev = MPA_NEGOTIATION_TYPE_ENHANCED;
780 } else {
781 ep->cm_info.ord = QED_IWARP_ORD_DEFAULT;
782 ep->cm_info.ird = QED_IWARP_IRD_DEFAULT;
783 ep->mpa_rev = MPA_NEGOTIATION_TYPE_BASIC;
784 }
785
786 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
787 "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x rtr:0x%x ulp_data_len = %x mpa_hdr_size = %x\n",
788 mpa_rev, ep->cm_info.ord, ep->cm_info.ird, ep->rtr_type,
789 async_data->mpa_request.ulp_data_len, mpa_hdr_size);
790
791 /* Strip mpa v2 hdr from private data before sending to upper layer */
792 ep->cm_info.private_data = ep->ep_buffer_virt->in_pdata + mpa_hdr_size;
793
794 ep->cm_info.private_data_len = async_data->mpa_request.ulp_data_len -
795 mpa_hdr_size;
796
797 params.event = QED_IWARP_EVENT_MPA_REQUEST;
798 params.cm_info = &ep->cm_info;
799 params.ep_context = ep;
800 params.status = 0;
801
802 ep->state = QED_IWARP_EP_MPA_REQ_RCVD;
803 ep->event_cb(ep->cb_context, &params);
804}
805
806static int
807qed_iwarp_mpa_offload(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
808{
809 struct iwarp_mpa_offload_ramrod_data *p_mpa_ramrod;
810 struct qed_sp_init_data init_data;
811 dma_addr_t async_output_phys;
812 struct qed_spq_entry *p_ent;
813 dma_addr_t out_pdata_phys;
814 dma_addr_t in_pdata_phys;
815 struct qed_rdma_qp *qp;
816 bool reject;
817 int rc;
818
819 if (!ep)
820 return -EINVAL;
821
822 qp = ep->qp;
823 reject = !qp;
824
825 memset(&init_data, 0, sizeof(init_data));
826 init_data.cid = reject ? ep->tcp_cid : qp->icid;
827 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
828
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +0300829 if (ep->connect_mode == TCP_CONNECT_ACTIVE)
830 init_data.comp_mode = QED_SPQ_MODE_CB;
831 else
832 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
Kalderon, Michal456a5842017-07-02 10:29:27 +0300833
834 rc = qed_sp_init_request(p_hwfn, &p_ent,
835 IWARP_RAMROD_CMD_ID_MPA_OFFLOAD,
836 PROTOCOLID_IWARP, &init_data);
837 if (rc)
838 return rc;
839
840 p_mpa_ramrod = &p_ent->ramrod.iwarp_mpa_offload;
841 out_pdata_phys = ep->ep_buffer_phys +
842 offsetof(struct qed_iwarp_ep_memory, out_pdata);
843 DMA_REGPAIR_LE(p_mpa_ramrod->common.outgoing_ulp_buffer.addr,
844 out_pdata_phys);
845 p_mpa_ramrod->common.outgoing_ulp_buffer.len =
846 ep->cm_info.private_data_len;
847 p_mpa_ramrod->common.crc_needed = p_hwfn->p_rdma_info->iwarp.crc_needed;
848
849 p_mpa_ramrod->common.out_rq.ord = ep->cm_info.ord;
850 p_mpa_ramrod->common.out_rq.ird = ep->cm_info.ird;
851
852 p_mpa_ramrod->tcp_cid = p_hwfn->hw_info.opaque_fid << 16 | ep->tcp_cid;
853
854 in_pdata_phys = ep->ep_buffer_phys +
855 offsetof(struct qed_iwarp_ep_memory, in_pdata);
856 p_mpa_ramrod->tcp_connect_side = ep->connect_mode;
857 DMA_REGPAIR_LE(p_mpa_ramrod->incoming_ulp_buffer.addr,
858 in_pdata_phys);
859 p_mpa_ramrod->incoming_ulp_buffer.len =
860 cpu_to_le16(sizeof(ep->ep_buffer_virt->in_pdata));
861 async_output_phys = ep->ep_buffer_phys +
862 offsetof(struct qed_iwarp_ep_memory, async_output);
863 DMA_REGPAIR_LE(p_mpa_ramrod->async_eqe_output_buf,
864 async_output_phys);
865 p_mpa_ramrod->handle_for_async.hi = cpu_to_le32(PTR_HI(ep));
866 p_mpa_ramrod->handle_for_async.lo = cpu_to_le32(PTR_LO(ep));
867
868 if (!reject) {
869 DMA_REGPAIR_LE(p_mpa_ramrod->shared_queue_addr,
870 qp->shared_queue_phys_addr);
871 p_mpa_ramrod->stats_counter_id =
872 RESC_START(p_hwfn, QED_RDMA_STATS_QUEUE) + qp->stats_queue;
873 } else {
874 p_mpa_ramrod->common.reject = 1;
875 }
876
877 p_mpa_ramrod->mode = ep->mpa_rev;
878 SET_FIELD(p_mpa_ramrod->rtr_pref,
879 IWARP_MPA_OFFLOAD_RAMROD_DATA_RTR_SUPPORTED, ep->rtr_type);
880
881 ep->state = QED_IWARP_EP_MPA_OFFLOADED;
882 rc = qed_spq_post(p_hwfn, p_ent, NULL);
883 if (!reject)
884 ep->cid = qp->icid; /* Now they're migrated. */
885
886 DP_VERBOSE(p_hwfn,
887 QED_MSG_RDMA,
888 "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",
889 reject ? 0xffff : qp->icid,
890 ep->tcp_cid,
891 rc,
892 ep->cm_info.ird,
893 ep->cm_info.ord, ep->rtr_type, ep->mpa_rev, reject);
894 return rc;
895}
896
897static void
898qed_iwarp_return_ep(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
899{
900 ep->state = QED_IWARP_EP_INIT;
901 if (ep->qp)
902 ep->qp->ep = NULL;
903 ep->qp = NULL;
904 memset(&ep->cm_info, 0, sizeof(ep->cm_info));
905
906 if (ep->tcp_cid == QED_IWARP_INVALID_TCP_CID) {
907 /* We don't care about the return code, it's ok if tcp_cid
908 * remains invalid...in this case we'll defer allocation
909 */
910 qed_iwarp_alloc_tcp_cid(p_hwfn, &ep->tcp_cid);
911 }
912 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
913
914 list_del(&ep->list_entry);
915 list_add_tail(&ep->list_entry,
916 &p_hwfn->p_rdma_info->iwarp.ep_free_list);
917
918 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
919}
920
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +0300921void
922qed_iwarp_parse_private_data(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
923{
924 struct mpa_v2_hdr *mpa_v2_params;
925 union async_output *async_data;
926 u16 mpa_ird, mpa_ord;
927 u8 mpa_data_size = 0;
928
929 if (MPA_REV2(p_hwfn->p_rdma_info->iwarp.mpa_rev)) {
930 mpa_v2_params =
931 (struct mpa_v2_hdr *)(ep->ep_buffer_virt->in_pdata);
932 mpa_data_size = sizeof(*mpa_v2_params);
933 mpa_ird = ntohs(mpa_v2_params->ird);
934 mpa_ord = ntohs(mpa_v2_params->ord);
935
936 ep->cm_info.ird = (u8)(mpa_ord & MPA_V2_IRD_ORD_MASK);
937 ep->cm_info.ord = (u8)(mpa_ird & MPA_V2_IRD_ORD_MASK);
938 }
939 async_data = &ep->ep_buffer_virt->async_output;
940
941 ep->cm_info.private_data = ep->ep_buffer_virt->in_pdata + mpa_data_size;
942 ep->cm_info.private_data_len = async_data->mpa_response.ulp_data_len -
943 mpa_data_size;
944}
945
946void
947qed_iwarp_mpa_reply_arrived(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
948{
949 struct qed_iwarp_cm_event_params params;
950
951 if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
952 DP_NOTICE(p_hwfn,
953 "MPA reply event not expected on passive side!\n");
954 return;
955 }
956
957 params.event = QED_IWARP_EVENT_ACTIVE_MPA_REPLY;
958
959 qed_iwarp_parse_private_data(p_hwfn, ep);
960
961 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
962 "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x\n",
963 ep->mpa_rev, ep->cm_info.ord, ep->cm_info.ird);
964
965 params.cm_info = &ep->cm_info;
966 params.ep_context = ep;
967 params.status = 0;
968
969 ep->mpa_reply_processed = true;
970
971 ep->event_cb(ep->cb_context, &params);
972}
973
Kalderon, Michal456a5842017-07-02 10:29:27 +0300974#define QED_IWARP_CONNECT_MODE_STRING(ep) \
975 ((ep)->connect_mode == TCP_CONNECT_PASSIVE) ? "Passive" : "Active"
976
977/* Called as a result of the event:
978 * IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE
979 */
980static void
981qed_iwarp_mpa_complete(struct qed_hwfn *p_hwfn,
982 struct qed_iwarp_ep *ep, u8 fw_return_code)
983{
984 struct qed_iwarp_cm_event_params params;
985
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +0300986 if (ep->connect_mode == TCP_CONNECT_ACTIVE)
987 params.event = QED_IWARP_EVENT_ACTIVE_COMPLETE;
988 else
989 params.event = QED_IWARP_EVENT_PASSIVE_COMPLETE;
990
991 if (ep->connect_mode == TCP_CONNECT_ACTIVE && !ep->mpa_reply_processed)
992 qed_iwarp_parse_private_data(p_hwfn, ep);
Kalderon, Michal456a5842017-07-02 10:29:27 +0300993
994 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
995 "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x\n",
996 ep->mpa_rev, ep->cm_info.ord, ep->cm_info.ird);
997
998 params.cm_info = &ep->cm_info;
999
1000 params.ep_context = ep;
1001
1002 ep->state = QED_IWARP_EP_CLOSED;
1003
1004 switch (fw_return_code) {
1005 case RDMA_RETURN_OK:
1006 ep->qp->max_rd_atomic_req = ep->cm_info.ord;
1007 ep->qp->max_rd_atomic_resp = ep->cm_info.ird;
1008 qed_iwarp_modify_qp(p_hwfn, ep->qp, QED_IWARP_QP_STATE_RTS, 1);
1009 ep->state = QED_IWARP_EP_ESTABLISHED;
1010 params.status = 0;
1011 break;
Kalderon, Michal9816b612017-07-02 10:29:30 +03001012 case IWARP_CONN_ERROR_MPA_TIMEOUT:
1013 DP_NOTICE(p_hwfn, "%s(0x%x) MPA timeout\n",
1014 QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
1015 params.status = -EBUSY;
1016 break;
1017 case IWARP_CONN_ERROR_MPA_ERROR_REJECT:
1018 DP_NOTICE(p_hwfn, "%s(0x%x) MPA Reject\n",
1019 QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
1020 params.status = -ECONNREFUSED;
1021 break;
1022 case IWARP_CONN_ERROR_MPA_RST:
1023 DP_NOTICE(p_hwfn, "%s(0x%x) MPA reset(tcp cid: 0x%x)\n",
1024 QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid,
1025 ep->tcp_cid);
1026 params.status = -ECONNRESET;
1027 break;
1028 case IWARP_CONN_ERROR_MPA_FIN:
1029 DP_NOTICE(p_hwfn, "%s(0x%x) MPA received FIN\n",
1030 QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
1031 params.status = -ECONNREFUSED;
1032 break;
1033 case IWARP_CONN_ERROR_MPA_INSUF_IRD:
1034 DP_NOTICE(p_hwfn, "%s(0x%x) MPA insufficient ird\n",
1035 QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
1036 params.status = -ECONNREFUSED;
1037 break;
1038 case IWARP_CONN_ERROR_MPA_RTR_MISMATCH:
1039 DP_NOTICE(p_hwfn, "%s(0x%x) MPA RTR MISMATCH\n",
1040 QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
1041 params.status = -ECONNREFUSED;
1042 break;
1043 case IWARP_CONN_ERROR_MPA_INVALID_PACKET:
1044 DP_NOTICE(p_hwfn, "%s(0x%x) MPA Invalid Packet\n",
1045 QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
1046 params.status = -ECONNREFUSED;
1047 break;
1048 case IWARP_CONN_ERROR_MPA_LOCAL_ERROR:
1049 DP_NOTICE(p_hwfn, "%s(0x%x) MPA Local Error\n",
1050 QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
1051 params.status = -ECONNREFUSED;
1052 break;
1053 case IWARP_CONN_ERROR_MPA_TERMINATE:
1054 DP_NOTICE(p_hwfn, "%s(0x%x) MPA TERMINATE\n",
1055 QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
1056 params.status = -ECONNREFUSED;
1057 break;
Kalderon, Michal456a5842017-07-02 10:29:27 +03001058 default:
1059 params.status = -ECONNRESET;
1060 break;
1061 }
1062
1063 ep->event_cb(ep->cb_context, &params);
Kalderon, Michal9816b612017-07-02 10:29:30 +03001064
1065 /* on passive side, if there is no associated QP (REJECT) we need to
1066 * return the ep to the pool, (in the regular case we add an element
1067 * in accept instead of this one.
1068 * In both cases we need to remove it from the ep_list.
1069 */
1070 if (fw_return_code != RDMA_RETURN_OK) {
1071 ep->tcp_cid = QED_IWARP_INVALID_TCP_CID;
1072 if ((ep->connect_mode == TCP_CONNECT_PASSIVE) &&
1073 (!ep->qp)) { /* Rejected */
1074 qed_iwarp_return_ep(p_hwfn, ep);
1075 } else {
1076 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1077 list_del(&ep->list_entry);
1078 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1079 }
1080 }
Kalderon, Michal456a5842017-07-02 10:29:27 +03001081}
1082
1083static void
1084qed_iwarp_mpa_v2_set_private(struct qed_hwfn *p_hwfn,
1085 struct qed_iwarp_ep *ep, u8 *mpa_data_size)
1086{
1087 struct mpa_v2_hdr *mpa_v2_params;
1088 u16 mpa_ird, mpa_ord;
1089
1090 *mpa_data_size = 0;
1091 if (MPA_REV2(ep->mpa_rev)) {
1092 mpa_v2_params =
1093 (struct mpa_v2_hdr *)ep->ep_buffer_virt->out_pdata;
1094 *mpa_data_size = sizeof(*mpa_v2_params);
1095
1096 mpa_ird = (u16)ep->cm_info.ird;
1097 mpa_ord = (u16)ep->cm_info.ord;
1098
1099 if (ep->rtr_type != MPA_RTR_TYPE_NONE) {
1100 mpa_ird |= MPA_V2_PEER2PEER_MODEL;
1101
1102 if (ep->rtr_type & MPA_RTR_TYPE_ZERO_SEND)
1103 mpa_ird |= MPA_V2_SEND_RTR;
1104
1105 if (ep->rtr_type & MPA_RTR_TYPE_ZERO_WRITE)
1106 mpa_ord |= MPA_V2_WRITE_RTR;
1107
1108 if (ep->rtr_type & MPA_RTR_TYPE_ZERO_READ)
1109 mpa_ord |= MPA_V2_READ_RTR;
1110 }
1111
1112 mpa_v2_params->ird = htons(mpa_ird);
1113 mpa_v2_params->ord = htons(mpa_ord);
1114
1115 DP_VERBOSE(p_hwfn,
1116 QED_MSG_RDMA,
1117 "MPA_NEGOTIATE Header: [%x ord:%x ird] %x ord:%x ird:%x peer2peer:%x rtr_send:%x rtr_write:%x rtr_read:%x\n",
1118 mpa_v2_params->ird,
1119 mpa_v2_params->ord,
1120 *((u32 *)mpa_v2_params),
1121 mpa_ord & MPA_V2_IRD_ORD_MASK,
1122 mpa_ird & MPA_V2_IRD_ORD_MASK,
1123 !!(mpa_ird & MPA_V2_PEER2PEER_MODEL),
1124 !!(mpa_ird & MPA_V2_SEND_RTR),
1125 !!(mpa_ord & MPA_V2_WRITE_RTR),
1126 !!(mpa_ord & MPA_V2_READ_RTR));
1127 }
1128}
1129
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03001130int qed_iwarp_connect(void *rdma_cxt,
1131 struct qed_iwarp_connect_in *iparams,
1132 struct qed_iwarp_connect_out *oparams)
1133{
1134 struct qed_hwfn *p_hwfn = rdma_cxt;
1135 struct qed_iwarp_info *iwarp_info;
1136 struct qed_iwarp_ep *ep;
1137 u8 mpa_data_size = 0;
1138 u8 ts_hdr_size = 0;
1139 u32 cid;
1140 int rc;
1141
1142 if ((iparams->cm_info.ord > QED_IWARP_ORD_DEFAULT) ||
1143 (iparams->cm_info.ird > QED_IWARP_IRD_DEFAULT)) {
1144 DP_NOTICE(p_hwfn,
1145 "QP(0x%x) ERROR: Invalid ord(0x%x)/ird(0x%x)\n",
1146 iparams->qp->icid, iparams->cm_info.ord,
1147 iparams->cm_info.ird);
1148
1149 return -EINVAL;
1150 }
1151
1152 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
1153
1154 /* Allocate ep object */
1155 rc = qed_iwarp_alloc_cid(p_hwfn, &cid);
1156 if (rc)
1157 return rc;
1158
1159 rc = qed_iwarp_create_ep(p_hwfn, &ep);
1160 if (rc)
1161 goto err;
1162
1163 ep->tcp_cid = cid;
1164
1165 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1166 list_add_tail(&ep->list_entry, &p_hwfn->p_rdma_info->iwarp.ep_list);
1167 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1168
1169 ep->qp = iparams->qp;
1170 ep->qp->ep = ep;
1171 ether_addr_copy(ep->remote_mac_addr, iparams->remote_mac_addr);
1172 ether_addr_copy(ep->local_mac_addr, iparams->local_mac_addr);
1173 memcpy(&ep->cm_info, &iparams->cm_info, sizeof(ep->cm_info));
1174
1175 ep->cm_info.ord = iparams->cm_info.ord;
1176 ep->cm_info.ird = iparams->cm_info.ird;
1177
1178 ep->rtr_type = iwarp_info->rtr_type;
1179 if (!iwarp_info->peer2peer)
1180 ep->rtr_type = MPA_RTR_TYPE_NONE;
1181
1182 if ((ep->rtr_type & MPA_RTR_TYPE_ZERO_READ) && (ep->cm_info.ord == 0))
1183 ep->cm_info.ord = 1;
1184
1185 ep->mpa_rev = iwarp_info->mpa_rev;
1186
1187 qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size);
1188
1189 ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata;
1190 ep->cm_info.private_data_len = iparams->cm_info.private_data_len +
1191 mpa_data_size;
1192
1193 memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size,
1194 iparams->cm_info.private_data,
1195 iparams->cm_info.private_data_len);
1196
1197 if (p_hwfn->p_rdma_info->iwarp.tcp_flags & QED_IWARP_TS_EN)
1198 ts_hdr_size = TIMESTAMP_HEADER_SIZE;
1199
1200 ep->mss = iparams->mss - ts_hdr_size;
1201 ep->mss = min_t(u16, QED_IWARP_MAX_FW_MSS, ep->mss);
1202
1203 ep->event_cb = iparams->event_cb;
1204 ep->cb_context = iparams->cb_context;
1205 ep->connect_mode = TCP_CONNECT_ACTIVE;
1206
1207 oparams->ep_context = ep;
1208
1209 rc = qed_iwarp_tcp_offload(p_hwfn, ep);
1210
1211 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x) rc = %d\n",
1212 iparams->qp->icid, ep->tcp_cid, rc);
1213
1214 if (rc) {
1215 qed_iwarp_destroy_ep(p_hwfn, ep, true);
1216 goto err;
1217 }
1218
1219 return rc;
1220err:
1221 qed_iwarp_cid_cleaned(p_hwfn, cid);
1222
1223 return rc;
1224}
1225
Kalderon, Michal456a5842017-07-02 10:29:27 +03001226static struct qed_iwarp_ep *qed_iwarp_get_free_ep(struct qed_hwfn *p_hwfn)
1227{
1228 struct qed_iwarp_ep *ep = NULL;
1229 int rc;
1230
1231 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1232
1233 if (list_empty(&p_hwfn->p_rdma_info->iwarp.ep_free_list)) {
1234 DP_ERR(p_hwfn, "Ep list is empty\n");
1235 goto out;
1236 }
1237
1238 ep = list_first_entry(&p_hwfn->p_rdma_info->iwarp.ep_free_list,
1239 struct qed_iwarp_ep, list_entry);
1240
1241 /* in some cases we could have failed allocating a tcp cid when added
1242 * from accept / failure... retry now..this is not the common case.
1243 */
1244 if (ep->tcp_cid == QED_IWARP_INVALID_TCP_CID) {
1245 rc = qed_iwarp_alloc_tcp_cid(p_hwfn, &ep->tcp_cid);
1246
1247 /* if we fail we could look for another entry with a valid
1248 * tcp_cid, but since we don't expect to reach this anyway
1249 * it's not worth the handling
1250 */
1251 if (rc) {
1252 ep->tcp_cid = QED_IWARP_INVALID_TCP_CID;
1253 ep = NULL;
1254 goto out;
1255 }
1256 }
1257
1258 list_del(&ep->list_entry);
1259
1260out:
1261 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1262 return ep;
1263}
1264
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001265#define QED_IWARP_MAX_CID_CLEAN_TIME 100
1266#define QED_IWARP_MAX_NO_PROGRESS_CNT 5
1267
1268/* This function waits for all the bits of a bmap to be cleared, as long as
1269 * there is progress ( i.e. the number of bits left to be cleared decreases )
1270 * the function continues.
1271 */
1272static int
1273qed_iwarp_wait_cid_map_cleared(struct qed_hwfn *p_hwfn, struct qed_bmap *bmap)
1274{
1275 int prev_weight = 0;
1276 int wait_count = 0;
1277 int weight = 0;
1278
1279 weight = bitmap_weight(bmap->bitmap, bmap->max_count);
1280 prev_weight = weight;
1281
1282 while (weight) {
1283 msleep(QED_IWARP_MAX_CID_CLEAN_TIME);
1284
1285 weight = bitmap_weight(bmap->bitmap, bmap->max_count);
1286
1287 if (prev_weight == weight) {
1288 wait_count++;
1289 } else {
1290 prev_weight = weight;
1291 wait_count = 0;
1292 }
1293
1294 if (wait_count > QED_IWARP_MAX_NO_PROGRESS_CNT) {
1295 DP_NOTICE(p_hwfn,
1296 "%s bitmap wait timed out (%d cids pending)\n",
1297 bmap->name, weight);
1298 return -EBUSY;
1299 }
1300 }
1301 return 0;
1302}
1303
1304static int qed_iwarp_wait_for_all_cids(struct qed_hwfn *p_hwfn)
1305{
Kalderon, Michal456a5842017-07-02 10:29:27 +03001306 int rc;
1307 int i;
1308
1309 rc = qed_iwarp_wait_cid_map_cleared(p_hwfn,
1310 &p_hwfn->p_rdma_info->tcp_cid_map);
1311 if (rc)
1312 return rc;
1313
1314 /* Now free the tcp cids from the main cid map */
1315 for (i = 0; i < QED_IWARP_PREALLOC_CNT; i++)
1316 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, i);
1317
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001318 /* Now wait for all cids to be completed */
1319 return qed_iwarp_wait_cid_map_cleared(p_hwfn,
1320 &p_hwfn->p_rdma_info->cid_map);
1321}
1322
Kalderon, Michal456a5842017-07-02 10:29:27 +03001323static void qed_iwarp_free_prealloc_ep(struct qed_hwfn *p_hwfn)
1324{
1325 struct qed_iwarp_ep *ep;
1326
1327 while (!list_empty(&p_hwfn->p_rdma_info->iwarp.ep_free_list)) {
1328 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1329
1330 ep = list_first_entry(&p_hwfn->p_rdma_info->iwarp.ep_free_list,
1331 struct qed_iwarp_ep, list_entry);
1332
1333 if (!ep) {
1334 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1335 break;
1336 }
1337 list_del(&ep->list_entry);
1338
1339 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1340
1341 if (ep->tcp_cid != QED_IWARP_INVALID_TCP_CID)
1342 qed_iwarp_cid_cleaned(p_hwfn, ep->tcp_cid);
1343
1344 qed_iwarp_destroy_ep(p_hwfn, ep, false);
1345 }
1346}
1347
1348static int qed_iwarp_prealloc_ep(struct qed_hwfn *p_hwfn, bool init)
1349{
1350 struct qed_iwarp_ep *ep;
1351 int rc = 0;
1352 int count;
1353 u32 cid;
1354 int i;
1355
1356 count = init ? QED_IWARP_PREALLOC_CNT : 1;
1357 for (i = 0; i < count; i++) {
1358 rc = qed_iwarp_create_ep(p_hwfn, &ep);
1359 if (rc)
1360 return rc;
1361
1362 /* During initialization we allocate from the main pool,
1363 * afterwards we allocate only from the tcp_cid.
1364 */
1365 if (init) {
1366 rc = qed_iwarp_alloc_cid(p_hwfn, &cid);
1367 if (rc)
1368 goto err;
1369 qed_iwarp_set_tcp_cid(p_hwfn, cid);
1370 } else {
1371 /* We don't care about the return code, it's ok if
1372 * tcp_cid remains invalid...in this case we'll
1373 * defer allocation
1374 */
1375 qed_iwarp_alloc_tcp_cid(p_hwfn, &cid);
1376 }
1377
1378 ep->tcp_cid = cid;
1379
1380 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1381 list_add_tail(&ep->list_entry,
1382 &p_hwfn->p_rdma_info->iwarp.ep_free_list);
1383 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1384 }
1385
1386 return rc;
1387
1388err:
1389 qed_iwarp_destroy_ep(p_hwfn, ep, false);
1390
1391 return rc;
1392}
1393
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001394int qed_iwarp_alloc(struct qed_hwfn *p_hwfn)
1395{
Kalderon, Michal456a5842017-07-02 10:29:27 +03001396 int rc;
1397
1398 /* Allocate bitmap for tcp cid. These are used by passive side
1399 * to ensure it can allocate a tcp cid during dpc that was
1400 * pre-acquired and doesn't require dynamic allocation of ilt
1401 */
1402 rc = qed_rdma_bmap_alloc(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map,
1403 QED_IWARP_PREALLOC_CNT, "TCP_CID");
1404 if (rc) {
1405 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1406 "Failed to allocate tcp cid, rc = %d\n", rc);
1407 return rc;
1408 }
1409
1410 INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.ep_free_list);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001411 spin_lock_init(&p_hwfn->p_rdma_info->iwarp.iw_lock);
1412
Kalderon, Michal456a5842017-07-02 10:29:27 +03001413 return qed_iwarp_prealloc_ep(p_hwfn, true);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001414}
1415
1416void qed_iwarp_resc_free(struct qed_hwfn *p_hwfn)
1417{
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001418 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
1419
Kalderon, Michal456a5842017-07-02 10:29:27 +03001420 qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map, 1);
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001421 kfree(iwarp_info->mpa_bufs);
Michal Kalderon469981b2017-10-09 12:37:51 +03001422 kfree(iwarp_info->partial_fpdus);
Kalderon, Michal456a5842017-07-02 10:29:27 +03001423}
1424
1425int qed_iwarp_accept(void *rdma_cxt, struct qed_iwarp_accept_in *iparams)
1426{
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03001427 struct qed_hwfn *p_hwfn = rdma_cxt;
Kalderon, Michal456a5842017-07-02 10:29:27 +03001428 struct qed_iwarp_ep *ep;
1429 u8 mpa_data_size = 0;
1430 int rc;
1431
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03001432 ep = iparams->ep_context;
Kalderon, Michal456a5842017-07-02 10:29:27 +03001433 if (!ep) {
1434 DP_ERR(p_hwfn, "Ep Context receive in accept is NULL\n");
1435 return -EINVAL;
1436 }
1437
1438 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x)\n",
1439 iparams->qp->icid, ep->tcp_cid);
1440
1441 if ((iparams->ord > QED_IWARP_ORD_DEFAULT) ||
1442 (iparams->ird > QED_IWARP_IRD_DEFAULT)) {
1443 DP_VERBOSE(p_hwfn,
1444 QED_MSG_RDMA,
1445 "QP(0x%x) EP(0x%x) ERROR: Invalid ord(0x%x)/ird(0x%x)\n",
1446 iparams->qp->icid,
1447 ep->tcp_cid, iparams->ord, iparams->ord);
1448 return -EINVAL;
1449 }
1450
1451 qed_iwarp_prealloc_ep(p_hwfn, false);
1452
1453 ep->cb_context = iparams->cb_context;
1454 ep->qp = iparams->qp;
1455 ep->qp->ep = ep;
1456
1457 if (ep->mpa_rev == MPA_NEGOTIATION_TYPE_ENHANCED) {
1458 /* Negotiate ord/ird: if upperlayer requested ord larger than
1459 * ird advertised by remote, we need to decrease our ord
1460 */
1461 if (iparams->ord > ep->cm_info.ird)
1462 iparams->ord = ep->cm_info.ird;
1463
1464 if ((ep->rtr_type & MPA_RTR_TYPE_ZERO_READ) &&
1465 (iparams->ird == 0))
1466 iparams->ird = 1;
1467 }
1468
1469 /* Update cm_info ord/ird to be negotiated values */
1470 ep->cm_info.ord = iparams->ord;
1471 ep->cm_info.ird = iparams->ird;
1472
1473 qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size);
1474
1475 ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata;
1476 ep->cm_info.private_data_len = iparams->private_data_len +
1477 mpa_data_size;
1478
1479 memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size,
1480 iparams->private_data, iparams->private_data_len);
1481
1482 rc = qed_iwarp_mpa_offload(p_hwfn, ep);
1483 if (rc)
1484 qed_iwarp_modify_qp(p_hwfn,
1485 iparams->qp, QED_IWARP_QP_STATE_ERROR, 1);
1486
1487 return rc;
1488}
1489
1490int qed_iwarp_reject(void *rdma_cxt, struct qed_iwarp_reject_in *iparams)
1491{
1492 struct qed_hwfn *p_hwfn = rdma_cxt;
1493 struct qed_iwarp_ep *ep;
1494 u8 mpa_data_size = 0;
1495
1496 ep = iparams->ep_context;
1497 if (!ep) {
1498 DP_ERR(p_hwfn, "Ep Context receive in reject is NULL\n");
1499 return -EINVAL;
1500 }
1501
1502 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "EP(0x%x)\n", ep->tcp_cid);
1503
1504 ep->cb_context = iparams->cb_context;
1505 ep->qp = NULL;
1506
1507 qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size);
1508
1509 ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata;
1510 ep->cm_info.private_data_len = iparams->private_data_len +
1511 mpa_data_size;
1512
1513 memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size,
1514 iparams->private_data, iparams->private_data_len);
1515
1516 return qed_iwarp_mpa_offload(p_hwfn, ep);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03001517}
1518
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001519static void
1520qed_iwarp_print_cm_info(struct qed_hwfn *p_hwfn,
1521 struct qed_iwarp_cm_info *cm_info)
1522{
1523 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "ip_version = %d\n",
1524 cm_info->ip_version);
1525
1526 if (cm_info->ip_version == QED_TCP_IPV4)
1527 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1528 "remote_ip %pI4h:%x, local_ip %pI4h:%x vlan=%x\n",
1529 cm_info->remote_ip, cm_info->remote_port,
1530 cm_info->local_ip, cm_info->local_port,
1531 cm_info->vlan);
1532 else
1533 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
Kalderon, Michal91d1ae42017-07-09 13:00:16 +03001534 "remote_ip %pI6:%x, local_ip %pI6:%x vlan=%x\n",
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001535 cm_info->remote_ip, cm_info->remote_port,
1536 cm_info->local_ip, cm_info->local_port,
1537 cm_info->vlan);
1538
1539 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1540 "private_data_len = %x ord = %d, ird = %d\n",
1541 cm_info->private_data_len, cm_info->ord, cm_info->ird);
1542}
1543
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03001544static int
1545qed_iwarp_ll2_post_rx(struct qed_hwfn *p_hwfn,
1546 struct qed_iwarp_ll2_buff *buf, u8 handle)
1547{
1548 int rc;
1549
1550 rc = qed_ll2_post_rx_buffer(p_hwfn, handle, buf->data_phys_addr,
1551 (u16)buf->buff_size, buf, 1);
1552 if (rc) {
1553 DP_NOTICE(p_hwfn,
1554 "Failed to repost rx buffer to ll2 rc = %d, handle=%d\n",
1555 rc, handle);
1556 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buf->buff_size,
1557 buf->data, buf->data_phys_addr);
1558 kfree(buf);
1559 }
1560
1561 return rc;
1562}
1563
Kalderon, Michal456a5842017-07-02 10:29:27 +03001564static bool
1565qed_iwarp_ep_exists(struct qed_hwfn *p_hwfn, struct qed_iwarp_cm_info *cm_info)
1566{
1567 struct qed_iwarp_ep *ep = NULL;
1568 bool found = false;
1569
1570 list_for_each_entry(ep,
1571 &p_hwfn->p_rdma_info->iwarp.ep_list,
1572 list_entry) {
1573 if ((ep->cm_info.local_port == cm_info->local_port) &&
1574 (ep->cm_info.remote_port == cm_info->remote_port) &&
1575 (ep->cm_info.vlan == cm_info->vlan) &&
1576 !memcmp(&ep->cm_info.local_ip, cm_info->local_ip,
1577 sizeof(cm_info->local_ip)) &&
1578 !memcmp(&ep->cm_info.remote_ip, cm_info->remote_ip,
1579 sizeof(cm_info->remote_ip))) {
1580 found = true;
1581 break;
1582 }
1583 }
1584
1585 if (found) {
1586 DP_NOTICE(p_hwfn,
1587 "SYN received on active connection - dropping\n");
1588 qed_iwarp_print_cm_info(p_hwfn, cm_info);
1589
1590 return true;
1591 }
1592
1593 return false;
1594}
1595
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001596static struct qed_iwarp_listener *
1597qed_iwarp_get_listener(struct qed_hwfn *p_hwfn,
1598 struct qed_iwarp_cm_info *cm_info)
1599{
1600 struct qed_iwarp_listener *listener = NULL;
1601 static const u32 ip_zero[4] = { 0, 0, 0, 0 };
1602 bool found = false;
1603
1604 qed_iwarp_print_cm_info(p_hwfn, cm_info);
1605
1606 list_for_each_entry(listener,
1607 &p_hwfn->p_rdma_info->iwarp.listen_list,
1608 list_entry) {
1609 if (listener->port == cm_info->local_port) {
1610 if (!memcmp(listener->ip_addr,
1611 ip_zero, sizeof(ip_zero))) {
1612 found = true;
1613 break;
1614 }
1615
1616 if (!memcmp(listener->ip_addr,
1617 cm_info->local_ip,
1618 sizeof(cm_info->local_ip)) &&
1619 (listener->vlan == cm_info->vlan)) {
1620 found = true;
1621 break;
1622 }
1623 }
1624 }
1625
1626 if (found) {
1627 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener found = %p\n",
1628 listener);
1629 return listener;
1630 }
1631
1632 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener not found\n");
1633 return NULL;
1634}
1635
1636static int
1637qed_iwarp_parse_rx_pkt(struct qed_hwfn *p_hwfn,
1638 struct qed_iwarp_cm_info *cm_info,
1639 void *buf,
1640 u8 *remote_mac_addr,
1641 u8 *local_mac_addr,
1642 int *payload_len, int *tcp_start_offset)
1643{
1644 struct vlan_ethhdr *vethh;
1645 bool vlan_valid = false;
1646 struct ipv6hdr *ip6h;
1647 struct ethhdr *ethh;
1648 struct tcphdr *tcph;
1649 struct iphdr *iph;
1650 int eth_hlen;
1651 int ip_hlen;
1652 int eth_type;
1653 int i;
1654
1655 ethh = buf;
1656 eth_type = ntohs(ethh->h_proto);
1657 if (eth_type == ETH_P_8021Q) {
1658 vlan_valid = true;
1659 vethh = (struct vlan_ethhdr *)ethh;
1660 cm_info->vlan = ntohs(vethh->h_vlan_TCI) & VLAN_VID_MASK;
1661 eth_type = ntohs(vethh->h_vlan_encapsulated_proto);
1662 }
1663
1664 eth_hlen = ETH_HLEN + (vlan_valid ? sizeof(u32) : 0);
1665
Kalderon, Michal456a5842017-07-02 10:29:27 +03001666 ether_addr_copy(remote_mac_addr, ethh->h_source);
1667 ether_addr_copy(local_mac_addr, ethh->h_dest);
Kalderon, Michal65a91a62017-07-02 10:29:26 +03001668
1669 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "eth_type =%d source mac: %pM\n",
1670 eth_type, ethh->h_source);
1671
1672 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "eth_hlen=%d destination mac: %pM\n",
1673 eth_hlen, ethh->h_dest);
1674
1675 iph = (struct iphdr *)((u8 *)(ethh) + eth_hlen);
1676
1677 if (eth_type == ETH_P_IP) {
1678 cm_info->local_ip[0] = ntohl(iph->daddr);
1679 cm_info->remote_ip[0] = ntohl(iph->saddr);
1680 cm_info->ip_version = TCP_IPV4;
1681
1682 ip_hlen = (iph->ihl) * sizeof(u32);
1683 *payload_len = ntohs(iph->tot_len) - ip_hlen;
1684 } else if (eth_type == ETH_P_IPV6) {
1685 ip6h = (struct ipv6hdr *)iph;
1686 for (i = 0; i < 4; i++) {
1687 cm_info->local_ip[i] =
1688 ntohl(ip6h->daddr.in6_u.u6_addr32[i]);
1689 cm_info->remote_ip[i] =
1690 ntohl(ip6h->saddr.in6_u.u6_addr32[i]);
1691 }
1692 cm_info->ip_version = TCP_IPV6;
1693
1694 ip_hlen = sizeof(*ip6h);
1695 *payload_len = ntohs(ip6h->payload_len);
1696 } else {
1697 DP_NOTICE(p_hwfn, "Unexpected ethertype on ll2 %x\n", eth_type);
1698 return -EINVAL;
1699 }
1700
1701 tcph = (struct tcphdr *)((u8 *)iph + ip_hlen);
1702
1703 if (!tcph->syn) {
1704 DP_NOTICE(p_hwfn,
1705 "Only SYN type packet expected on this ll2 conn, iph->ihl=%d source=%d dest=%d\n",
1706 iph->ihl, tcph->source, tcph->dest);
1707 return -EINVAL;
1708 }
1709
1710 cm_info->local_port = ntohs(tcph->dest);
1711 cm_info->remote_port = ntohs(tcph->source);
1712
1713 qed_iwarp_print_cm_info(p_hwfn, cm_info);
1714
1715 *tcp_start_offset = eth_hlen + ip_hlen;
1716
1717 return 0;
1718}
1719
Michal Kalderon469981b2017-10-09 12:37:51 +03001720static struct qed_iwarp_fpdu *qed_iwarp_get_curr_fpdu(struct qed_hwfn *p_hwfn,
1721 u16 cid)
1722{
1723 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
1724 struct qed_iwarp_fpdu *partial_fpdu;
1725 u32 idx;
1726
1727 idx = cid - qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_IWARP);
1728 if (idx >= iwarp_info->max_num_partial_fpdus) {
1729 DP_ERR(p_hwfn, "Invalid cid %x max_num_partial_fpdus=%x\n", cid,
1730 iwarp_info->max_num_partial_fpdus);
1731 return NULL;
1732 }
1733
1734 partial_fpdu = &iwarp_info->partial_fpdus[idx];
1735
1736 return partial_fpdu;
1737}
1738
1739enum qed_iwarp_mpa_pkt_type {
1740 QED_IWARP_MPA_PKT_PACKED,
1741 QED_IWARP_MPA_PKT_PARTIAL,
1742 QED_IWARP_MPA_PKT_UNALIGNED
1743};
1744
Michal Kalderonc7d1d8392017-10-09 12:37:53 +03001745#define QED_IWARP_INVALID_FPDU_LENGTH 0xffff
Michal Kalderon469981b2017-10-09 12:37:51 +03001746#define QED_IWARP_MPA_FPDU_LENGTH_SIZE (2)
1747#define QED_IWARP_MPA_CRC32_DIGEST_SIZE (4)
1748
1749/* Pad to multiple of 4 */
1750#define QED_IWARP_PDU_DATA_LEN_WITH_PAD(data_len) ALIGN(data_len, 4)
1751#define QED_IWARP_FPDU_LEN_WITH_PAD(_mpa_len) \
1752 (QED_IWARP_PDU_DATA_LEN_WITH_PAD((_mpa_len) + \
1753 QED_IWARP_MPA_FPDU_LENGTH_SIZE) + \
1754 QED_IWARP_MPA_CRC32_DIGEST_SIZE)
1755
Michal Kalderonae3488f2017-10-09 12:37:49 +03001756/* fpdu can be fragmented over maximum 3 bds: header, partial mpa, unaligned */
1757#define QED_IWARP_MAX_BDS_PER_FPDU 3
Michal Kalderon469981b2017-10-09 12:37:51 +03001758
1759char *pkt_type_str[] = {
1760 "QED_IWARP_MPA_PKT_PACKED",
1761 "QED_IWARP_MPA_PKT_PARTIAL",
1762 "QED_IWARP_MPA_PKT_UNALIGNED"
1763};
1764
1765static enum qed_iwarp_mpa_pkt_type
1766qed_iwarp_mpa_classify(struct qed_hwfn *p_hwfn,
1767 struct qed_iwarp_fpdu *fpdu,
1768 u16 tcp_payload_len, u8 *mpa_data)
1769{
1770 enum qed_iwarp_mpa_pkt_type pkt_type;
1771 u16 mpa_len;
1772
1773 if (fpdu->incomplete_bytes) {
1774 pkt_type = QED_IWARP_MPA_PKT_UNALIGNED;
1775 goto out;
1776 }
1777
Michal Kalderonc7d1d8392017-10-09 12:37:53 +03001778 /* special case of one byte remaining...
1779 * lower byte will be read next packet
1780 */
1781 if (tcp_payload_len == 1) {
1782 fpdu->fpdu_length = *mpa_data << BITS_PER_BYTE;
1783 pkt_type = QED_IWARP_MPA_PKT_PARTIAL;
1784 goto out;
1785 }
1786
Michal Kalderon469981b2017-10-09 12:37:51 +03001787 mpa_len = ntohs(*((u16 *)(mpa_data)));
1788 fpdu->fpdu_length = QED_IWARP_FPDU_LEN_WITH_PAD(mpa_len);
1789
1790 if (fpdu->fpdu_length <= tcp_payload_len)
1791 pkt_type = QED_IWARP_MPA_PKT_PACKED;
1792 else
1793 pkt_type = QED_IWARP_MPA_PKT_PARTIAL;
1794
1795out:
1796 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1797 "MPA_ALIGN: %s: fpdu_length=0x%x tcp_payload_len:0x%x\n",
1798 pkt_type_str[pkt_type], fpdu->fpdu_length, tcp_payload_len);
1799
1800 return pkt_type;
1801}
1802
1803static void
1804qed_iwarp_init_fpdu(struct qed_iwarp_ll2_buff *buf,
1805 struct qed_iwarp_fpdu *fpdu,
1806 struct unaligned_opaque_data *pkt_data,
1807 u16 tcp_payload_size, u8 placement_offset)
1808{
1809 fpdu->mpa_buf = buf;
1810 fpdu->pkt_hdr = buf->data_phys_addr + placement_offset;
1811 fpdu->pkt_hdr_size = pkt_data->tcp_payload_offset;
1812 fpdu->mpa_frag = buf->data_phys_addr + pkt_data->first_mpa_offset;
1813 fpdu->mpa_frag_virt = (u8 *)(buf->data) + pkt_data->first_mpa_offset;
1814
Michal Kalderonc7d1d8392017-10-09 12:37:53 +03001815 if (tcp_payload_size == 1)
1816 fpdu->incomplete_bytes = QED_IWARP_INVALID_FPDU_LENGTH;
1817 else if (tcp_payload_size < fpdu->fpdu_length)
Michal Kalderon469981b2017-10-09 12:37:51 +03001818 fpdu->incomplete_bytes = fpdu->fpdu_length - tcp_payload_size;
1819 else
1820 fpdu->incomplete_bytes = 0; /* complete fpdu */
1821
1822 fpdu->mpa_frag_len = fpdu->fpdu_length - fpdu->incomplete_bytes;
1823}
1824
Michal Kalderonc7d1d8392017-10-09 12:37:53 +03001825static void
1826qed_iwarp_update_fpdu_length(struct qed_hwfn *p_hwfn,
1827 struct qed_iwarp_fpdu *fpdu, u8 *mpa_data)
1828{
1829 u16 mpa_len;
1830
1831 /* Update incomplete packets if needed */
1832 if (fpdu->incomplete_bytes == QED_IWARP_INVALID_FPDU_LENGTH) {
1833 /* Missing lower byte is now available */
1834 mpa_len = fpdu->fpdu_length | *mpa_data;
1835 fpdu->fpdu_length = QED_IWARP_FPDU_LEN_WITH_PAD(mpa_len);
1836 fpdu->mpa_frag_len = fpdu->fpdu_length;
1837 /* one byte of hdr */
1838 fpdu->incomplete_bytes = fpdu->fpdu_length - 1;
1839 DP_VERBOSE(p_hwfn,
1840 QED_MSG_RDMA,
1841 "MPA_ALIGN: Partial header mpa_len=%x fpdu_length=%x incomplete_bytes=%x\n",
1842 mpa_len, fpdu->fpdu_length, fpdu->incomplete_bytes);
1843 }
1844}
1845
Michal Kalderon469981b2017-10-09 12:37:51 +03001846static int
1847qed_iwarp_send_fpdu(struct qed_hwfn *p_hwfn,
1848 struct qed_iwarp_fpdu *fpdu,
1849 struct unaligned_opaque_data *curr_pkt,
1850 struct qed_iwarp_ll2_buff *buf,
1851 u16 tcp_payload_size, enum qed_iwarp_mpa_pkt_type pkt_type)
1852{
1853 struct qed_ll2_tx_pkt_info tx_pkt;
1854 u8 ll2_handle;
1855 int rc;
1856
1857 memset(&tx_pkt, 0, sizeof(tx_pkt));
1858
1859 /* An unaligned packet means it's split over two tcp segments. So the
1860 * complete packet requires 3 bds, one for the header, one for the
1861 * part of the fpdu of the first tcp segment, and the last fragment
1862 * will point to the remainder of the fpdu. A packed pdu, requires only
1863 * two bds, one for the header and one for the data.
1864 */
1865 tx_pkt.num_of_bds = (pkt_type == QED_IWARP_MPA_PKT_UNALIGNED) ? 3 : 2;
1866 tx_pkt.tx_dest = QED_LL2_TX_DEST_LB;
1867 tx_pkt.l4_hdr_offset_w = fpdu->pkt_hdr_size >> 2; /* offset in words */
1868
1869 /* Send the mpa_buf only with the last fpdu (in case of packed) */
1870 if (pkt_type == QED_IWARP_MPA_PKT_UNALIGNED ||
1871 tcp_payload_size <= fpdu->fpdu_length)
1872 tx_pkt.cookie = fpdu->mpa_buf;
1873
1874 tx_pkt.first_frag = fpdu->pkt_hdr;
1875 tx_pkt.first_frag_len = fpdu->pkt_hdr_size;
1876 tx_pkt.enable_ip_cksum = true;
1877 tx_pkt.enable_l4_cksum = true;
1878 tx_pkt.calc_ip_len = true;
1879 /* vlan overload with enum iwarp_ll2_tx_queues */
1880 tx_pkt.vlan = IWARP_LL2_ALIGNED_TX_QUEUE;
1881
Michal Kalderond5310382017-10-09 12:37:52 +03001882 /* special case of unaligned packet and not packed, need to send
1883 * both buffers as cookie to release.
1884 */
1885 if (tcp_payload_size == fpdu->incomplete_bytes)
1886 fpdu->mpa_buf->piggy_buf = buf;
1887
Michal Kalderon469981b2017-10-09 12:37:51 +03001888 ll2_handle = p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle;
1889
1890 /* Set first fragment to header */
1891 rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_handle, &tx_pkt, true);
1892 if (rc)
1893 goto out;
1894
1895 /* Set second fragment to first part of packet */
1896 rc = qed_ll2_set_fragment_of_tx_packet(p_hwfn, ll2_handle,
1897 fpdu->mpa_frag,
1898 fpdu->mpa_frag_len);
1899 if (rc)
1900 goto out;
1901
1902 if (!fpdu->incomplete_bytes)
1903 goto out;
1904
1905 /* Set third fragment to second part of the packet */
1906 rc = qed_ll2_set_fragment_of_tx_packet(p_hwfn,
1907 ll2_handle,
1908 buf->data_phys_addr +
1909 curr_pkt->first_mpa_offset,
1910 fpdu->incomplete_bytes);
1911out:
1912 DP_VERBOSE(p_hwfn,
1913 QED_MSG_RDMA,
1914 "MPA_ALIGN: Sent FPDU num_bds=%d first_frag_len=%x, mpa_frag_len=0x%x, incomplete_bytes:0x%x rc=%d\n",
1915 tx_pkt.num_of_bds,
1916 tx_pkt.first_frag_len,
1917 fpdu->mpa_frag_len,
1918 fpdu->incomplete_bytes, rc);
1919
1920 return rc;
1921}
1922
Michal Kalderonae3488f2017-10-09 12:37:49 +03001923static void
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001924qed_iwarp_mpa_get_data(struct qed_hwfn *p_hwfn,
1925 struct unaligned_opaque_data *curr_pkt,
1926 u32 opaque_data0, u32 opaque_data1)
1927{
1928 u64 opaque_data;
1929
1930 opaque_data = HILO_64(opaque_data1, opaque_data0);
1931 *curr_pkt = *((struct unaligned_opaque_data *)&opaque_data);
1932
1933 curr_pkt->first_mpa_offset = curr_pkt->tcp_payload_offset +
1934 le16_to_cpu(curr_pkt->first_mpa_offset);
1935 curr_pkt->cid = le32_to_cpu(curr_pkt->cid);
1936}
1937
1938/* This function is called when an unaligned or incomplete MPA packet arrives
1939 * driver needs to align the packet, perhaps using previous data and send
1940 * it down to FW once it is aligned.
1941 */
1942static int
1943qed_iwarp_process_mpa_pkt(struct qed_hwfn *p_hwfn,
1944 struct qed_iwarp_ll2_mpa_buf *mpa_buf)
1945{
Michal Kalderon469981b2017-10-09 12:37:51 +03001946 struct unaligned_opaque_data *curr_pkt = &mpa_buf->data;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001947 struct qed_iwarp_ll2_buff *buf = mpa_buf->ll2_buf;
Michal Kalderon469981b2017-10-09 12:37:51 +03001948 enum qed_iwarp_mpa_pkt_type pkt_type;
1949 struct qed_iwarp_fpdu *fpdu;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001950 int rc = -EINVAL;
Michal Kalderon469981b2017-10-09 12:37:51 +03001951 u8 *mpa_data;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001952
Michal Kalderon469981b2017-10-09 12:37:51 +03001953 fpdu = qed_iwarp_get_curr_fpdu(p_hwfn, curr_pkt->cid & 0xffff);
1954 if (!fpdu) { /* something corrupt with cid, post rx back */
1955 DP_ERR(p_hwfn, "Invalid cid, drop and post back to rx cid=%x\n",
1956 curr_pkt->cid);
1957 goto err;
1958 }
1959
1960 do {
1961 mpa_data = ((u8 *)(buf->data) + curr_pkt->first_mpa_offset);
1962
1963 pkt_type = qed_iwarp_mpa_classify(p_hwfn, fpdu,
1964 mpa_buf->tcp_payload_len,
1965 mpa_data);
1966
1967 switch (pkt_type) {
1968 case QED_IWARP_MPA_PKT_PARTIAL:
1969 qed_iwarp_init_fpdu(buf, fpdu,
1970 curr_pkt,
1971 mpa_buf->tcp_payload_len,
1972 mpa_buf->placement_offset);
1973
1974 mpa_buf->tcp_payload_len = 0;
1975 break;
1976 case QED_IWARP_MPA_PKT_PACKED:
1977 qed_iwarp_init_fpdu(buf, fpdu,
1978 curr_pkt,
1979 mpa_buf->tcp_payload_len,
1980 mpa_buf->placement_offset);
1981
1982 rc = qed_iwarp_send_fpdu(p_hwfn, fpdu, curr_pkt, buf,
1983 mpa_buf->tcp_payload_len,
1984 pkt_type);
1985 if (rc) {
1986 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1987 "Can't send FPDU:reset rc=%d\n", rc);
1988 memset(fpdu, 0, sizeof(*fpdu));
1989 break;
1990 }
1991
1992 mpa_buf->tcp_payload_len -= fpdu->fpdu_length;
1993 curr_pkt->first_mpa_offset += fpdu->fpdu_length;
1994 break;
1995 case QED_IWARP_MPA_PKT_UNALIGNED:
Michal Kalderonc7d1d8392017-10-09 12:37:53 +03001996 qed_iwarp_update_fpdu_length(p_hwfn, fpdu, mpa_data);
Michal Kalderon469981b2017-10-09 12:37:51 +03001997 rc = qed_iwarp_send_fpdu(p_hwfn, fpdu, curr_pkt, buf,
1998 mpa_buf->tcp_payload_len,
1999 pkt_type);
2000 if (rc) {
2001 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2002 "Can't send FPDU:delay rc=%d\n", rc);
2003 /* don't reset fpdu -> we need it for next
2004 * classify
2005 */
2006 break;
2007 }
2008
2009 mpa_buf->tcp_payload_len -= fpdu->incomplete_bytes;
2010 curr_pkt->first_mpa_offset += fpdu->incomplete_bytes;
2011 /* The framed PDU was sent - no more incomplete bytes */
2012 fpdu->incomplete_bytes = 0;
2013 break;
2014 }
2015 } while (mpa_buf->tcp_payload_len && !rc);
2016
2017 return rc;
2018
2019err:
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002020 qed_iwarp_ll2_post_rx(p_hwfn,
2021 buf,
2022 p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle);
2023 return rc;
2024}
2025
2026static void qed_iwarp_process_pending_pkts(struct qed_hwfn *p_hwfn)
2027{
2028 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
2029 struct qed_iwarp_ll2_mpa_buf *mpa_buf = NULL;
2030 int rc;
2031
2032 while (!list_empty(&iwarp_info->mpa_buf_pending_list)) {
2033 mpa_buf = list_first_entry(&iwarp_info->mpa_buf_pending_list,
2034 struct qed_iwarp_ll2_mpa_buf,
2035 list_entry);
2036
2037 rc = qed_iwarp_process_mpa_pkt(p_hwfn, mpa_buf);
2038
2039 /* busy means break and continue processing later, don't
2040 * remove the buf from the pending list.
2041 */
2042 if (rc == -EBUSY)
2043 break;
2044
2045 list_del(&mpa_buf->list_entry);
2046 list_add_tail(&mpa_buf->list_entry, &iwarp_info->mpa_buf_list);
2047
2048 if (rc) { /* different error, don't continue */
2049 DP_NOTICE(p_hwfn, "process pkts failed rc=%d\n", rc);
2050 break;
2051 }
2052 }
2053}
2054
2055static void
Michal Kalderonae3488f2017-10-09 12:37:49 +03002056qed_iwarp_ll2_comp_mpa_pkt(void *cxt, struct qed_ll2_comp_rx_data *data)
2057{
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002058 struct qed_iwarp_ll2_mpa_buf *mpa_buf;
Michal Kalderonae3488f2017-10-09 12:37:49 +03002059 struct qed_iwarp_info *iwarp_info;
2060 struct qed_hwfn *p_hwfn = cxt;
2061
2062 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002063 mpa_buf = list_first_entry(&iwarp_info->mpa_buf_list,
2064 struct qed_iwarp_ll2_mpa_buf, list_entry);
2065 if (!mpa_buf) {
2066 DP_ERR(p_hwfn, "No free mpa buf\n");
2067 goto err;
2068 }
2069
2070 list_del(&mpa_buf->list_entry);
2071 qed_iwarp_mpa_get_data(p_hwfn, &mpa_buf->data,
2072 data->opaque_data_0, data->opaque_data_1);
2073
2074 DP_VERBOSE(p_hwfn,
2075 QED_MSG_RDMA,
2076 "LL2 MPA CompRx payload_len:0x%x\tfirst_mpa_offset:0x%x\ttcp_payload_offset:0x%x\tflags:0x%x\tcid:0x%x\n",
2077 data->length.packet_length, mpa_buf->data.first_mpa_offset,
2078 mpa_buf->data.tcp_payload_offset, mpa_buf->data.flags,
2079 mpa_buf->data.cid);
2080
2081 mpa_buf->ll2_buf = data->cookie;
2082 mpa_buf->tcp_payload_len = data->length.packet_length -
2083 mpa_buf->data.first_mpa_offset;
2084 mpa_buf->data.first_mpa_offset += data->u.placement_offset;
2085 mpa_buf->placement_offset = data->u.placement_offset;
2086
2087 list_add_tail(&mpa_buf->list_entry, &iwarp_info->mpa_buf_pending_list);
2088
2089 qed_iwarp_process_pending_pkts(p_hwfn);
2090 return;
2091err:
Michal Kalderonae3488f2017-10-09 12:37:49 +03002092 qed_iwarp_ll2_post_rx(p_hwfn, data->cookie,
2093 iwarp_info->ll2_mpa_handle);
2094}
2095
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002096static void
2097qed_iwarp_ll2_comp_syn_pkt(void *cxt, struct qed_ll2_comp_rx_data *data)
2098{
2099 struct qed_iwarp_ll2_buff *buf = data->cookie;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002100 struct qed_iwarp_listener *listener;
2101 struct qed_ll2_tx_pkt_info tx_pkt;
2102 struct qed_iwarp_cm_info cm_info;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002103 struct qed_hwfn *p_hwfn = cxt;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002104 u8 remote_mac_addr[ETH_ALEN];
2105 u8 local_mac_addr[ETH_ALEN];
Kalderon, Michal456a5842017-07-02 10:29:27 +03002106 struct qed_iwarp_ep *ep;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002107 int tcp_start_offset;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002108 u8 ts_hdr_size = 0;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002109 u8 ll2_syn_handle;
2110 int payload_len;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002111 u32 hdr_size;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002112 int rc;
2113
2114 memset(&cm_info, 0, sizeof(cm_info));
Michal Kalderon25f45352017-07-03 21:55:25 +03002115 ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle;
Michal Kalderon1e99c492017-09-24 12:09:45 +03002116
2117 /* Check if packet was received with errors... */
2118 if (data->err_flags) {
2119 DP_NOTICE(p_hwfn, "Error received on SYN packet: 0x%x\n",
2120 data->err_flags);
2121 goto err;
2122 }
2123
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002124 if (GET_FIELD(data->parse_flags,
2125 PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED) &&
2126 GET_FIELD(data->parse_flags, PARSING_AND_ERR_FLAGS_L4CHKSMERROR)) {
2127 DP_NOTICE(p_hwfn, "Syn packet received with checksum error\n");
2128 goto err;
2129 }
2130
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002131 rc = qed_iwarp_parse_rx_pkt(p_hwfn, &cm_info, (u8 *)(buf->data) +
2132 data->u.placement_offset, remote_mac_addr,
2133 local_mac_addr, &payload_len,
2134 &tcp_start_offset);
2135 if (rc)
2136 goto err;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002137
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002138 /* Check if there is a listener for this 4-tuple+vlan */
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002139 listener = qed_iwarp_get_listener(p_hwfn, &cm_info);
2140 if (!listener) {
2141 DP_VERBOSE(p_hwfn,
2142 QED_MSG_RDMA,
2143 "SYN received on tuple not listened on parse_flags=%d packet len=%d\n",
2144 data->parse_flags, data->length.packet_length);
2145
2146 memset(&tx_pkt, 0, sizeof(tx_pkt));
2147 tx_pkt.num_of_bds = 1;
2148 tx_pkt.vlan = data->vlan;
2149
2150 if (GET_FIELD(data->parse_flags,
2151 PARSING_AND_ERR_FLAGS_TAG8021QEXIST))
2152 SET_FIELD(tx_pkt.bd_flags,
2153 CORE_TX_BD_DATA_VLAN_INSERTION, 1);
2154
2155 tx_pkt.l4_hdr_offset_w = (data->length.packet_length) >> 2;
2156 tx_pkt.tx_dest = QED_LL2_TX_DEST_LB;
2157 tx_pkt.first_frag = buf->data_phys_addr +
2158 data->u.placement_offset;
2159 tx_pkt.first_frag_len = data->length.packet_length;
2160 tx_pkt.cookie = buf;
2161
2162 rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_syn_handle,
2163 &tx_pkt, true);
2164
2165 if (rc) {
2166 DP_NOTICE(p_hwfn,
2167 "Can't post SYN back to chip rc=%d\n", rc);
2168 goto err;
2169 }
2170 return;
2171 }
2172
2173 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Received syn on listening port\n");
Kalderon, Michal456a5842017-07-02 10:29:27 +03002174 /* There may be an open ep on this connection if this is a syn
2175 * retrasnmit... need to make sure there isn't...
2176 */
2177 if (qed_iwarp_ep_exists(p_hwfn, &cm_info))
2178 goto err;
2179
2180 ep = qed_iwarp_get_free_ep(p_hwfn);
2181 if (!ep)
2182 goto err;
2183
2184 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2185 list_add_tail(&ep->list_entry, &p_hwfn->p_rdma_info->iwarp.ep_list);
2186 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2187
2188 ether_addr_copy(ep->remote_mac_addr, remote_mac_addr);
2189 ether_addr_copy(ep->local_mac_addr, local_mac_addr);
2190
2191 memcpy(&ep->cm_info, &cm_info, sizeof(ep->cm_info));
2192
2193 if (p_hwfn->p_rdma_info->iwarp.tcp_flags & QED_IWARP_TS_EN)
2194 ts_hdr_size = TIMESTAMP_HEADER_SIZE;
2195
2196 hdr_size = ((cm_info.ip_version == QED_TCP_IPV4) ? 40 : 60) +
2197 ts_hdr_size;
2198 ep->mss = p_hwfn->p_rdma_info->iwarp.max_mtu - hdr_size;
2199 ep->mss = min_t(u16, QED_IWARP_MAX_FW_MSS, ep->mss);
2200
2201 ep->event_cb = listener->event_cb;
2202 ep->cb_context = listener->cb_context;
2203 ep->connect_mode = TCP_CONNECT_PASSIVE;
2204
2205 ep->syn = buf;
2206 ep->syn_ip_payload_length = (u16)payload_len;
2207 ep->syn_phy_addr = buf->data_phys_addr + data->u.placement_offset +
2208 tcp_start_offset;
2209
2210 rc = qed_iwarp_tcp_offload(p_hwfn, ep);
2211 if (rc) {
2212 qed_iwarp_return_ep(p_hwfn, ep);
2213 goto err;
2214 }
2215
2216 return;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002217err:
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002218 qed_iwarp_ll2_post_rx(p_hwfn, buf, ll2_syn_handle);
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002219}
2220
2221static void qed_iwarp_ll2_rel_rx_pkt(void *cxt, u8 connection_handle,
2222 void *cookie, dma_addr_t rx_buf_addr,
2223 bool b_last_packet)
2224{
2225 struct qed_iwarp_ll2_buff *buffer = cookie;
2226 struct qed_hwfn *p_hwfn = cxt;
2227
2228 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size,
2229 buffer->data, buffer->data_phys_addr);
2230 kfree(buffer);
2231}
2232
2233static void qed_iwarp_ll2_comp_tx_pkt(void *cxt, u8 connection_handle,
2234 void *cookie, dma_addr_t first_frag_addr,
2235 bool b_last_fragment, bool b_last_packet)
2236{
2237 struct qed_iwarp_ll2_buff *buffer = cookie;
Michal Kalderond5310382017-10-09 12:37:52 +03002238 struct qed_iwarp_ll2_buff *piggy;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002239 struct qed_hwfn *p_hwfn = cxt;
2240
Michal Kalderond5310382017-10-09 12:37:52 +03002241 if (!buffer) /* can happen in packed mpa unaligned... */
2242 return;
2243
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002244 /* this was originally an rx packet, post it back */
Michal Kalderond5310382017-10-09 12:37:52 +03002245 piggy = buffer->piggy_buf;
2246 if (piggy) {
2247 buffer->piggy_buf = NULL;
2248 qed_iwarp_ll2_post_rx(p_hwfn, piggy, connection_handle);
2249 }
2250
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002251 qed_iwarp_ll2_post_rx(p_hwfn, buffer, connection_handle);
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002252
2253 if (connection_handle == p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle)
2254 qed_iwarp_process_pending_pkts(p_hwfn);
2255
2256 return;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002257}
2258
2259static void qed_iwarp_ll2_rel_tx_pkt(void *cxt, u8 connection_handle,
2260 void *cookie, dma_addr_t first_frag_addr,
2261 bool b_last_fragment, bool b_last_packet)
2262{
2263 struct qed_iwarp_ll2_buff *buffer = cookie;
2264 struct qed_hwfn *p_hwfn = cxt;
2265
2266 if (!buffer)
2267 return;
2268
Michal Kalderond5310382017-10-09 12:37:52 +03002269 if (buffer->piggy_buf) {
2270 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
2271 buffer->piggy_buf->buff_size,
2272 buffer->piggy_buf->data,
2273 buffer->piggy_buf->data_phys_addr);
2274
2275 kfree(buffer->piggy_buf);
2276 }
2277
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002278 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size,
2279 buffer->data, buffer->data_phys_addr);
2280
2281 kfree(buffer);
2282}
2283
Michal Kalderon469981b2017-10-09 12:37:51 +03002284/* The only slowpath for iwarp ll2 is unalign flush. When this completion
2285 * is received, need to reset the FPDU.
2286 */
Michal Kalderonae3488f2017-10-09 12:37:49 +03002287void
2288qed_iwarp_ll2_slowpath(void *cxt,
2289 u8 connection_handle,
2290 u32 opaque_data_0, u32 opaque_data_1)
2291{
Michal Kalderon469981b2017-10-09 12:37:51 +03002292 struct unaligned_opaque_data unalign_data;
2293 struct qed_hwfn *p_hwfn = cxt;
2294 struct qed_iwarp_fpdu *fpdu;
2295
2296 qed_iwarp_mpa_get_data(p_hwfn, &unalign_data,
2297 opaque_data_0, opaque_data_1);
2298
2299 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "(0x%x) Flush fpdu\n",
2300 unalign_data.cid);
2301
2302 fpdu = qed_iwarp_get_curr_fpdu(p_hwfn, (u16)unalign_data.cid);
2303 if (fpdu)
2304 memset(fpdu, 0, sizeof(*fpdu));
Michal Kalderonae3488f2017-10-09 12:37:49 +03002305}
2306
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002307static int qed_iwarp_ll2_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2308{
2309 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
2310 int rc = 0;
2311
2312 if (iwarp_info->ll2_syn_handle != QED_IWARP_HANDLE_INVAL) {
2313 rc = qed_ll2_terminate_connection(p_hwfn,
2314 iwarp_info->ll2_syn_handle);
2315 if (rc)
2316 DP_INFO(p_hwfn, "Failed to terminate syn connection\n");
2317
2318 qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_syn_handle);
2319 iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL;
2320 }
2321
Michal Kalderond1abfd02017-09-24 12:09:43 +03002322 if (iwarp_info->ll2_ooo_handle != QED_IWARP_HANDLE_INVAL) {
2323 rc = qed_ll2_terminate_connection(p_hwfn,
2324 iwarp_info->ll2_ooo_handle);
2325 if (rc)
2326 DP_INFO(p_hwfn, "Failed to terminate ooo connection\n");
2327
2328 qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_ooo_handle);
2329 iwarp_info->ll2_ooo_handle = QED_IWARP_HANDLE_INVAL;
2330 }
2331
Michal Kalderonae3488f2017-10-09 12:37:49 +03002332 if (iwarp_info->ll2_mpa_handle != QED_IWARP_HANDLE_INVAL) {
2333 rc = qed_ll2_terminate_connection(p_hwfn,
2334 iwarp_info->ll2_mpa_handle);
2335 if (rc)
2336 DP_INFO(p_hwfn, "Failed to terminate mpa connection\n");
2337
2338 qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_mpa_handle);
2339 iwarp_info->ll2_mpa_handle = QED_IWARP_HANDLE_INVAL;
2340 }
2341
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002342 qed_llh_remove_mac_filter(p_hwfn,
2343 p_ptt, p_hwfn->p_rdma_info->iwarp.mac_addr);
2344 return rc;
2345}
2346
2347static int
2348qed_iwarp_ll2_alloc_buffers(struct qed_hwfn *p_hwfn,
2349 int num_rx_bufs, int buff_size, u8 ll2_handle)
2350{
2351 struct qed_iwarp_ll2_buff *buffer;
2352 int rc = 0;
2353 int i;
2354
2355 for (i = 0; i < num_rx_bufs; i++) {
2356 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
2357 if (!buffer) {
2358 rc = -ENOMEM;
2359 break;
2360 }
2361
2362 buffer->data = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
2363 buff_size,
2364 &buffer->data_phys_addr,
2365 GFP_KERNEL);
2366 if (!buffer->data) {
2367 kfree(buffer);
2368 rc = -ENOMEM;
2369 break;
2370 }
2371
2372 buffer->buff_size = buff_size;
2373 rc = qed_iwarp_ll2_post_rx(p_hwfn, buffer, ll2_handle);
2374 if (rc)
2375 /* buffers will be deallocated by qed_ll2 */
2376 break;
2377 }
2378 return rc;
2379}
2380
2381#define QED_IWARP_MAX_BUF_SIZE(mtu) \
2382 ALIGN((mtu) + ETH_HLEN + 2 * VLAN_HLEN + 2 + ETH_CACHE_LINE_SIZE, \
2383 ETH_CACHE_LINE_SIZE)
2384
2385static int
2386qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn,
2387 struct qed_rdma_start_in_params *params,
2388 struct qed_ptt *p_ptt)
2389{
2390 struct qed_iwarp_info *iwarp_info;
2391 struct qed_ll2_acquire_data data;
2392 struct qed_ll2_cbs cbs;
Michal Kalderonae3488f2017-10-09 12:37:49 +03002393 u32 mpa_buff_size;
Michal Kalderond1abfd02017-09-24 12:09:43 +03002394 u16 n_ooo_bufs;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002395 int rc = 0;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002396 int i;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002397
2398 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
2399 iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL;
Michal Kalderond1abfd02017-09-24 12:09:43 +03002400 iwarp_info->ll2_ooo_handle = QED_IWARP_HANDLE_INVAL;
Michal Kalderonae3488f2017-10-09 12:37:49 +03002401 iwarp_info->ll2_mpa_handle = QED_IWARP_HANDLE_INVAL;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002402
2403 iwarp_info->max_mtu = params->max_mtu;
2404
2405 ether_addr_copy(p_hwfn->p_rdma_info->iwarp.mac_addr, params->mac_addr);
2406
2407 rc = qed_llh_add_mac_filter(p_hwfn, p_ptt, params->mac_addr);
2408 if (rc)
2409 return rc;
2410
2411 /* Start SYN connection */
2412 cbs.rx_comp_cb = qed_iwarp_ll2_comp_syn_pkt;
2413 cbs.rx_release_cb = qed_iwarp_ll2_rel_rx_pkt;
2414 cbs.tx_comp_cb = qed_iwarp_ll2_comp_tx_pkt;
2415 cbs.tx_release_cb = qed_iwarp_ll2_rel_tx_pkt;
2416 cbs.cookie = p_hwfn;
2417
2418 memset(&data, 0, sizeof(data));
2419 data.input.conn_type = QED_LL2_TYPE_IWARP;
2420 data.input.mtu = QED_IWARP_MAX_SYN_PKT_SIZE;
2421 data.input.rx_num_desc = QED_IWARP_LL2_SYN_RX_SIZE;
2422 data.input.tx_num_desc = QED_IWARP_LL2_SYN_TX_SIZE;
2423 data.input.tx_max_bds_per_packet = 1; /* will never be fragmented */
2424 data.input.tx_tc = PKT_LB_TC;
2425 data.input.tx_dest = QED_LL2_TX_DEST_LB;
2426 data.p_connection_handle = &iwarp_info->ll2_syn_handle;
2427 data.cbs = &cbs;
2428
2429 rc = qed_ll2_acquire_connection(p_hwfn, &data);
2430 if (rc) {
2431 DP_NOTICE(p_hwfn, "Failed to acquire LL2 connection\n");
2432 qed_llh_remove_mac_filter(p_hwfn, p_ptt, params->mac_addr);
2433 return rc;
2434 }
2435
2436 rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_syn_handle);
2437 if (rc) {
2438 DP_NOTICE(p_hwfn, "Failed to establish LL2 connection\n");
2439 goto err;
2440 }
2441
2442 rc = qed_iwarp_ll2_alloc_buffers(p_hwfn,
2443 QED_IWARP_LL2_SYN_RX_SIZE,
2444 QED_IWARP_MAX_SYN_PKT_SIZE,
2445 iwarp_info->ll2_syn_handle);
2446 if (rc)
2447 goto err;
2448
Michal Kalderond1abfd02017-09-24 12:09:43 +03002449 /* Start OOO connection */
2450 data.input.conn_type = QED_LL2_TYPE_OOO;
2451 data.input.mtu = params->max_mtu;
2452
2453 n_ooo_bufs = (QED_IWARP_MAX_OOO * QED_IWARP_RCV_WND_SIZE_DEF) /
2454 iwarp_info->max_mtu;
2455 n_ooo_bufs = min_t(u32, n_ooo_bufs, QED_IWARP_LL2_OOO_MAX_RX_SIZE);
2456
2457 data.input.rx_num_desc = n_ooo_bufs;
2458 data.input.rx_num_ooo_buffers = n_ooo_bufs;
2459
2460 data.input.tx_max_bds_per_packet = 1; /* will never be fragmented */
2461 data.input.tx_num_desc = QED_IWARP_LL2_OOO_DEF_TX_SIZE;
2462 data.p_connection_handle = &iwarp_info->ll2_ooo_handle;
2463
2464 rc = qed_ll2_acquire_connection(p_hwfn, &data);
2465 if (rc)
2466 goto err;
2467
2468 rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_ooo_handle);
2469 if (rc)
2470 goto err;
2471
Michal Kalderonae3488f2017-10-09 12:37:49 +03002472 /* Start Unaligned MPA connection */
2473 cbs.rx_comp_cb = qed_iwarp_ll2_comp_mpa_pkt;
2474 cbs.slowpath_cb = qed_iwarp_ll2_slowpath;
2475
2476 memset(&data, 0, sizeof(data));
2477 data.input.conn_type = QED_LL2_TYPE_IWARP;
2478 data.input.mtu = params->max_mtu;
2479 /* FW requires that once a packet arrives OOO, it must have at
2480 * least 2 rx buffers available on the unaligned connection
2481 * for handling the case that it is a partial fpdu.
2482 */
2483 data.input.rx_num_desc = n_ooo_bufs * 2;
2484 data.input.tx_num_desc = data.input.rx_num_desc;
2485 data.input.tx_max_bds_per_packet = QED_IWARP_MAX_BDS_PER_FPDU;
2486 data.p_connection_handle = &iwarp_info->ll2_mpa_handle;
2487 data.input.secondary_queue = true;
2488 data.cbs = &cbs;
2489
2490 rc = qed_ll2_acquire_connection(p_hwfn, &data);
2491 if (rc)
2492 goto err;
2493
2494 rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_mpa_handle);
2495 if (rc)
2496 goto err;
2497
2498 mpa_buff_size = QED_IWARP_MAX_BUF_SIZE(params->max_mtu);
2499 rc = qed_iwarp_ll2_alloc_buffers(p_hwfn,
2500 data.input.rx_num_desc,
2501 mpa_buff_size,
2502 iwarp_info->ll2_mpa_handle);
2503 if (rc)
2504 goto err;
Michal Kalderon469981b2017-10-09 12:37:51 +03002505
2506 iwarp_info->partial_fpdus = kcalloc((u16)p_hwfn->p_rdma_info->num_qps,
2507 sizeof(*iwarp_info->partial_fpdus),
2508 GFP_KERNEL);
2509 if (!iwarp_info->partial_fpdus)
2510 goto err;
2511
2512 iwarp_info->max_num_partial_fpdus = (u16)p_hwfn->p_rdma_info->num_qps;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002513 /* The mpa_bufs array serves for pending RX packets received on the
2514 * mpa ll2 that don't have place on the tx ring and require later
2515 * processing. We can't fail on allocation of such a struct therefore
2516 * we allocate enough to take care of all rx packets
2517 */
2518 iwarp_info->mpa_bufs = kcalloc(data.input.rx_num_desc,
2519 sizeof(*iwarp_info->mpa_bufs),
2520 GFP_KERNEL);
2521 if (!iwarp_info->mpa_bufs)
2522 goto err;
2523
2524 INIT_LIST_HEAD(&iwarp_info->mpa_buf_pending_list);
2525 INIT_LIST_HEAD(&iwarp_info->mpa_buf_list);
2526 for (i = 0; i < data.input.rx_num_desc; i++)
2527 list_add_tail(&iwarp_info->mpa_bufs[i].list_entry,
2528 &iwarp_info->mpa_buf_list);
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002529 return rc;
2530err:
2531 qed_iwarp_ll2_stop(p_hwfn, p_ptt);
2532
2533 return rc;
2534}
2535
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002536int qed_iwarp_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
2537 struct qed_rdma_start_in_params *params)
2538{
2539 struct qed_iwarp_info *iwarp_info;
2540 u32 rcv_wnd_size;
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002541
2542 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
2543
2544 iwarp_info->tcp_flags = QED_IWARP_TS_EN;
2545 rcv_wnd_size = QED_IWARP_RCV_WND_SIZE_DEF;
2546
2547 /* value 0 is used for ilog2(QED_IWARP_RCV_WND_SIZE_MIN) */
2548 iwarp_info->rcv_wnd_scale = ilog2(rcv_wnd_size) -
2549 ilog2(QED_IWARP_RCV_WND_SIZE_MIN);
2550 iwarp_info->crc_needed = QED_IWARP_PARAM_CRC_NEEDED;
2551 iwarp_info->mpa_rev = MPA_NEGOTIATION_TYPE_ENHANCED;
2552
2553 iwarp_info->peer2peer = QED_IWARP_PARAM_P2P;
2554
Kalderon, Michal456a5842017-07-02 10:29:27 +03002555 iwarp_info->rtr_type = MPA_RTR_TYPE_ZERO_SEND |
2556 MPA_RTR_TYPE_ZERO_WRITE |
2557 MPA_RTR_TYPE_ZERO_READ;
2558
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002559 spin_lock_init(&p_hwfn->p_rdma_info->iwarp.qp_lock);
Kalderon, Michal456a5842017-07-02 10:29:27 +03002560 INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.ep_list);
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002561 INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.listen_list);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002562
2563 qed_spq_register_async_cb(p_hwfn, PROTOCOLID_IWARP,
2564 qed_iwarp_async_event);
Michal Kalderond1abfd02017-09-24 12:09:43 +03002565 qed_ooo_setup(p_hwfn);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002566
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002567 return qed_iwarp_ll2_start(p_hwfn, params, p_ptt);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002568}
2569
2570int qed_iwarp_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2571{
2572 int rc;
2573
Kalderon, Michal456a5842017-07-02 10:29:27 +03002574 qed_iwarp_free_prealloc_ep(p_hwfn);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002575 rc = qed_iwarp_wait_for_all_cids(p_hwfn);
2576 if (rc)
2577 return rc;
2578
2579 qed_spq_unregister_async_cb(p_hwfn, PROTOCOLID_IWARP);
2580
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002581 return qed_iwarp_ll2_stop(p_hwfn, p_ptt);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002582}
2583
Kalderon, Michalfc4c6062017-07-02 10:29:29 +03002584void qed_iwarp_qp_in_error(struct qed_hwfn *p_hwfn,
2585 struct qed_iwarp_ep *ep, u8 fw_return_code)
2586{
2587 struct qed_iwarp_cm_event_params params;
2588
2589 qed_iwarp_modify_qp(p_hwfn, ep->qp, QED_IWARP_QP_STATE_ERROR, true);
2590
2591 params.event = QED_IWARP_EVENT_CLOSE;
2592 params.ep_context = ep;
2593 params.cm_info = &ep->cm_info;
2594 params.status = (fw_return_code == IWARP_QP_IN_ERROR_GOOD_CLOSE) ?
2595 0 : -ECONNRESET;
2596
2597 ep->state = QED_IWARP_EP_CLOSED;
2598 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2599 list_del(&ep->list_entry);
2600 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2601
2602 ep->event_cb(ep->cb_context, &params);
2603}
2604
2605void qed_iwarp_exception_received(struct qed_hwfn *p_hwfn,
2606 struct qed_iwarp_ep *ep, int fw_ret_code)
2607{
2608 struct qed_iwarp_cm_event_params params;
2609 bool event_cb = false;
2610
2611 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "EP(0x%x) fw_ret_code=%d\n",
2612 ep->cid, fw_ret_code);
2613
2614 switch (fw_ret_code) {
2615 case IWARP_EXCEPTION_DETECTED_LLP_CLOSED:
2616 params.status = 0;
2617 params.event = QED_IWARP_EVENT_DISCONNECT;
2618 event_cb = true;
2619 break;
2620 case IWARP_EXCEPTION_DETECTED_LLP_RESET:
2621 params.status = -ECONNRESET;
2622 params.event = QED_IWARP_EVENT_DISCONNECT;
2623 event_cb = true;
2624 break;
Kalderon, Michal9816b612017-07-02 10:29:30 +03002625 case IWARP_EXCEPTION_DETECTED_RQ_EMPTY:
2626 params.event = QED_IWARP_EVENT_RQ_EMPTY;
2627 event_cb = true;
2628 break;
2629 case IWARP_EXCEPTION_DETECTED_IRQ_FULL:
2630 params.event = QED_IWARP_EVENT_IRQ_FULL;
2631 event_cb = true;
2632 break;
2633 case IWARP_EXCEPTION_DETECTED_LLP_TIMEOUT:
2634 params.event = QED_IWARP_EVENT_LLP_TIMEOUT;
2635 event_cb = true;
2636 break;
2637 case IWARP_EXCEPTION_DETECTED_REMOTE_PROTECTION_ERROR:
2638 params.event = QED_IWARP_EVENT_REMOTE_PROTECTION_ERROR;
2639 event_cb = true;
2640 break;
2641 case IWARP_EXCEPTION_DETECTED_CQ_OVERFLOW:
2642 params.event = QED_IWARP_EVENT_CQ_OVERFLOW;
2643 event_cb = true;
2644 break;
2645 case IWARP_EXCEPTION_DETECTED_LOCAL_CATASTROPHIC:
2646 params.event = QED_IWARP_EVENT_QP_CATASTROPHIC;
2647 event_cb = true;
2648 break;
2649 case IWARP_EXCEPTION_DETECTED_LOCAL_ACCESS_ERROR:
2650 params.event = QED_IWARP_EVENT_LOCAL_ACCESS_ERROR;
2651 event_cb = true;
2652 break;
2653 case IWARP_EXCEPTION_DETECTED_REMOTE_OPERATION_ERROR:
2654 params.event = QED_IWARP_EVENT_REMOTE_OPERATION_ERROR;
2655 event_cb = true;
2656 break;
2657 case IWARP_EXCEPTION_DETECTED_TERMINATE_RECEIVED:
2658 params.event = QED_IWARP_EVENT_TERMINATE_RECEIVED;
2659 event_cb = true;
2660 break;
Kalderon, Michalfc4c6062017-07-02 10:29:29 +03002661 default:
2662 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2663 "Unhandled exception received...fw_ret_code=%d\n",
2664 fw_ret_code);
2665 break;
2666 }
2667
2668 if (event_cb) {
2669 params.ep_context = ep;
2670 params.cm_info = &ep->cm_info;
2671 ep->event_cb(ep->cb_context, &params);
2672 }
2673}
2674
Kalderon, Michal9816b612017-07-02 10:29:30 +03002675static void
2676qed_iwarp_tcp_connect_unsuccessful(struct qed_hwfn *p_hwfn,
2677 struct qed_iwarp_ep *ep, u8 fw_return_code)
2678{
2679 struct qed_iwarp_cm_event_params params;
2680
2681 memset(&params, 0, sizeof(params));
2682 params.event = QED_IWARP_EVENT_ACTIVE_COMPLETE;
2683 params.ep_context = ep;
2684 params.cm_info = &ep->cm_info;
2685 ep->state = QED_IWARP_EP_CLOSED;
2686
2687 switch (fw_return_code) {
2688 case IWARP_CONN_ERROR_TCP_CONNECT_INVALID_PACKET:
2689 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2690 "%s(0x%x) TCP connect got invalid packet\n",
2691 QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
2692 params.status = -ECONNRESET;
2693 break;
2694 case IWARP_CONN_ERROR_TCP_CONNECTION_RST:
2695 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2696 "%s(0x%x) TCP Connection Reset\n",
2697 QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
2698 params.status = -ECONNRESET;
2699 break;
2700 case IWARP_CONN_ERROR_TCP_CONNECT_TIMEOUT:
2701 DP_NOTICE(p_hwfn, "%s(0x%x) TCP timeout\n",
2702 QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
2703 params.status = -EBUSY;
2704 break;
2705 case IWARP_CONN_ERROR_MPA_NOT_SUPPORTED_VER:
2706 DP_NOTICE(p_hwfn, "%s(0x%x) MPA not supported VER\n",
2707 QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
2708 params.status = -ECONNREFUSED;
2709 break;
2710 case IWARP_CONN_ERROR_MPA_INVALID_PACKET:
2711 DP_NOTICE(p_hwfn, "%s(0x%x) MPA Invalid Packet\n",
2712 QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
2713 params.status = -ECONNRESET;
2714 break;
2715 default:
2716 DP_ERR(p_hwfn,
2717 "%s(0x%x) Unexpected return code tcp connect: %d\n",
2718 QED_IWARP_CONNECT_MODE_STRING(ep),
2719 ep->tcp_cid, fw_return_code);
2720 params.status = -ECONNRESET;
2721 break;
2722 }
2723
2724 if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
2725 ep->tcp_cid = QED_IWARP_INVALID_TCP_CID;
2726 qed_iwarp_return_ep(p_hwfn, ep);
2727 } else {
2728 ep->event_cb(ep->cb_context, &params);
2729 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2730 list_del(&ep->list_entry);
2731 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2732 }
2733}
2734
Kalderon, Michal456a5842017-07-02 10:29:27 +03002735void
2736qed_iwarp_connect_complete(struct qed_hwfn *p_hwfn,
2737 struct qed_iwarp_ep *ep, u8 fw_return_code)
2738{
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002739 u8 ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002740
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002741 if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
2742 /* Done with the SYN packet, post back to ll2 rx */
2743 qed_iwarp_ll2_post_rx(p_hwfn, ep->syn, ll2_syn_handle);
2744
2745 ep->syn = NULL;
2746
2747 /* If connect failed - upper layer doesn't know about it */
Kalderon, Michal9816b612017-07-02 10:29:30 +03002748 if (fw_return_code == RDMA_RETURN_OK)
2749 qed_iwarp_mpa_received(p_hwfn, ep);
2750 else
2751 qed_iwarp_tcp_connect_unsuccessful(p_hwfn, ep,
2752 fw_return_code);
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002753 } else {
Kalderon, Michal9816b612017-07-02 10:29:30 +03002754 if (fw_return_code == RDMA_RETURN_OK)
2755 qed_iwarp_mpa_offload(p_hwfn, ep);
2756 else
2757 qed_iwarp_tcp_connect_unsuccessful(p_hwfn, ep,
2758 fw_return_code);
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002759 }
Kalderon, Michal456a5842017-07-02 10:29:27 +03002760}
2761
2762static inline bool
2763qed_iwarp_check_ep_ok(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
2764{
2765 if (!ep || (ep->sig != QED_EP_SIG)) {
2766 DP_ERR(p_hwfn, "ERROR ON ASYNC ep=%p\n", ep);
2767 return false;
2768 }
2769
2770 return true;
2771}
2772
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002773static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn,
2774 u8 fw_event_code, u16 echo,
2775 union event_ring_data *data,
2776 u8 fw_return_code)
2777{
Kalderon, Michal456a5842017-07-02 10:29:27 +03002778 struct regpair *fw_handle = &data->rdma_data.async_handle;
2779 struct qed_iwarp_ep *ep = NULL;
2780 u16 cid;
2781
2782 ep = (struct qed_iwarp_ep *)(uintptr_t)HILO_64(fw_handle->hi,
2783 fw_handle->lo);
2784
2785 switch (fw_event_code) {
2786 case IWARP_EVENT_TYPE_ASYNC_CONNECT_COMPLETE:
2787 /* Async completion after TCP 3-way handshake */
2788 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2789 return -EINVAL;
2790 DP_VERBOSE(p_hwfn,
2791 QED_MSG_RDMA,
2792 "EP(0x%x) IWARP_EVENT_TYPE_ASYNC_CONNECT_COMPLETE fw_ret_code=%d\n",
2793 ep->tcp_cid, fw_return_code);
2794 qed_iwarp_connect_complete(p_hwfn, ep, fw_return_code);
2795 break;
Kalderon, Michalfc4c6062017-07-02 10:29:29 +03002796 case IWARP_EVENT_TYPE_ASYNC_EXCEPTION_DETECTED:
2797 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2798 return -EINVAL;
2799 DP_VERBOSE(p_hwfn,
2800 QED_MSG_RDMA,
2801 "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_EXCEPTION_DETECTED fw_ret_code=%d\n",
2802 ep->cid, fw_return_code);
2803 qed_iwarp_exception_received(p_hwfn, ep, fw_return_code);
2804 break;
2805 case IWARP_EVENT_TYPE_ASYNC_QP_IN_ERROR_STATE:
2806 /* Async completion for Close Connection ramrod */
2807 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2808 return -EINVAL;
2809 DP_VERBOSE(p_hwfn,
2810 QED_MSG_RDMA,
2811 "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_QP_IN_ERROR_STATE fw_ret_code=%d\n",
2812 ep->cid, fw_return_code);
2813 qed_iwarp_qp_in_error(p_hwfn, ep, fw_return_code);
2814 break;
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002815 case IWARP_EVENT_TYPE_ASYNC_ENHANCED_MPA_REPLY_ARRIVED:
Kalderon, Michalfc4c6062017-07-02 10:29:29 +03002816 /* Async event for active side only */
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002817 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2818 return -EINVAL;
2819 DP_VERBOSE(p_hwfn,
2820 QED_MSG_RDMA,
2821 "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_MPA_REPLY_ARRIVED fw_ret_code=%d\n",
2822 ep->cid, fw_return_code);
2823 qed_iwarp_mpa_reply_arrived(p_hwfn, ep);
2824 break;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002825 case IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE:
2826 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2827 return -EINVAL;
2828 DP_VERBOSE(p_hwfn,
2829 QED_MSG_RDMA,
2830 "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE fw_ret_code=%d\n",
2831 ep->cid, fw_return_code);
2832 qed_iwarp_mpa_complete(p_hwfn, ep, fw_return_code);
2833 break;
2834 case IWARP_EVENT_TYPE_ASYNC_CID_CLEANED:
2835 cid = (u16)le32_to_cpu(fw_handle->lo);
2836 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2837 "(0x%x)IWARP_EVENT_TYPE_ASYNC_CID_CLEANED\n", cid);
2838 qed_iwarp_cid_cleaned(p_hwfn, cid);
2839
2840 break;
Kalderon, Michal9816b612017-07-02 10:29:30 +03002841 case IWARP_EVENT_TYPE_ASYNC_CQ_OVERFLOW:
2842 DP_NOTICE(p_hwfn, "IWARP_EVENT_TYPE_ASYNC_CQ_OVERFLOW\n");
2843
2844 p_hwfn->p_rdma_info->events.affiliated_event(
2845 p_hwfn->p_rdma_info->events.context,
2846 QED_IWARP_EVENT_CQ_OVERFLOW,
2847 (void *)fw_handle);
2848 break;
2849 default:
2850 DP_ERR(p_hwfn, "Received unexpected async iwarp event %d\n",
2851 fw_event_code);
2852 return -EINVAL;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002853 }
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002854 return 0;
2855}
2856
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002857int
2858qed_iwarp_create_listen(void *rdma_cxt,
2859 struct qed_iwarp_listen_in *iparams,
2860 struct qed_iwarp_listen_out *oparams)
2861{
2862 struct qed_hwfn *p_hwfn = rdma_cxt;
2863 struct qed_iwarp_listener *listener;
2864
2865 listener = kzalloc(sizeof(*listener), GFP_KERNEL);
2866 if (!listener)
2867 return -ENOMEM;
2868
2869 listener->ip_version = iparams->ip_version;
2870 memcpy(listener->ip_addr, iparams->ip_addr, sizeof(listener->ip_addr));
2871 listener->port = iparams->port;
2872 listener->vlan = iparams->vlan;
2873
2874 listener->event_cb = iparams->event_cb;
2875 listener->cb_context = iparams->cb_context;
2876 listener->max_backlog = iparams->max_backlog;
2877 oparams->handle = listener;
2878
2879 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2880 list_add_tail(&listener->list_entry,
2881 &p_hwfn->p_rdma_info->iwarp.listen_list);
2882 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2883
2884 DP_VERBOSE(p_hwfn,
2885 QED_MSG_RDMA,
2886 "callback=%p handle=%p ip=%x:%x:%x:%x port=0x%x vlan=0x%x\n",
2887 listener->event_cb,
2888 listener,
2889 listener->ip_addr[0],
2890 listener->ip_addr[1],
2891 listener->ip_addr[2],
2892 listener->ip_addr[3], listener->port, listener->vlan);
2893
2894 return 0;
2895}
2896
2897int qed_iwarp_destroy_listen(void *rdma_cxt, void *handle)
2898{
2899 struct qed_iwarp_listener *listener = handle;
2900 struct qed_hwfn *p_hwfn = rdma_cxt;
2901
2902 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "handle=%p\n", handle);
2903
2904 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2905 list_del(&listener->list_entry);
2906 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2907
2908 kfree(listener);
2909
2910 return 0;
2911}
2912
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002913int qed_iwarp_send_rtr(void *rdma_cxt, struct qed_iwarp_send_rtr_in *iparams)
2914{
2915 struct qed_hwfn *p_hwfn = rdma_cxt;
2916 struct qed_sp_init_data init_data;
2917 struct qed_spq_entry *p_ent;
2918 struct qed_iwarp_ep *ep;
2919 struct qed_rdma_qp *qp;
2920 int rc;
2921
2922 ep = iparams->ep_context;
2923 if (!ep) {
2924 DP_ERR(p_hwfn, "Ep Context receive in send_rtr is NULL\n");
2925 return -EINVAL;
2926 }
2927
2928 qp = ep->qp;
2929
2930 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x)\n",
2931 qp->icid, ep->tcp_cid);
2932
2933 memset(&init_data, 0, sizeof(init_data));
2934 init_data.cid = qp->icid;
2935 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
2936 init_data.comp_mode = QED_SPQ_MODE_CB;
2937
2938 rc = qed_sp_init_request(p_hwfn, &p_ent,
2939 IWARP_RAMROD_CMD_ID_MPA_OFFLOAD_SEND_RTR,
2940 PROTOCOLID_IWARP, &init_data);
2941
2942 if (rc)
2943 return rc;
2944
2945 rc = qed_spq_post(p_hwfn, p_ent, NULL);
2946
2947 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = 0x%x\n", rc);
2948
2949 return rc;
2950}
2951
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002952void
2953qed_iwarp_query_qp(struct qed_rdma_qp *qp,
2954 struct qed_rdma_query_qp_out_params *out_params)
2955{
2956 out_params->state = qed_iwarp2roce_state(qp->iwarp_state);
2957}