blob: 8b17369af9ef4b80259503e5405c24d16fd87730 [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
1745#define QED_IWARP_MPA_FPDU_LENGTH_SIZE (2)
1746#define QED_IWARP_MPA_CRC32_DIGEST_SIZE (4)
1747
1748/* Pad to multiple of 4 */
1749#define QED_IWARP_PDU_DATA_LEN_WITH_PAD(data_len) ALIGN(data_len, 4)
1750#define QED_IWARP_FPDU_LEN_WITH_PAD(_mpa_len) \
1751 (QED_IWARP_PDU_DATA_LEN_WITH_PAD((_mpa_len) + \
1752 QED_IWARP_MPA_FPDU_LENGTH_SIZE) + \
1753 QED_IWARP_MPA_CRC32_DIGEST_SIZE)
1754
Michal Kalderonae3488f2017-10-09 12:37:49 +03001755/* fpdu can be fragmented over maximum 3 bds: header, partial mpa, unaligned */
1756#define QED_IWARP_MAX_BDS_PER_FPDU 3
Michal Kalderon469981b2017-10-09 12:37:51 +03001757
1758char *pkt_type_str[] = {
1759 "QED_IWARP_MPA_PKT_PACKED",
1760 "QED_IWARP_MPA_PKT_PARTIAL",
1761 "QED_IWARP_MPA_PKT_UNALIGNED"
1762};
1763
1764static enum qed_iwarp_mpa_pkt_type
1765qed_iwarp_mpa_classify(struct qed_hwfn *p_hwfn,
1766 struct qed_iwarp_fpdu *fpdu,
1767 u16 tcp_payload_len, u8 *mpa_data)
1768{
1769 enum qed_iwarp_mpa_pkt_type pkt_type;
1770 u16 mpa_len;
1771
1772 if (fpdu->incomplete_bytes) {
1773 pkt_type = QED_IWARP_MPA_PKT_UNALIGNED;
1774 goto out;
1775 }
1776
1777 mpa_len = ntohs(*((u16 *)(mpa_data)));
1778 fpdu->fpdu_length = QED_IWARP_FPDU_LEN_WITH_PAD(mpa_len);
1779
1780 if (fpdu->fpdu_length <= tcp_payload_len)
1781 pkt_type = QED_IWARP_MPA_PKT_PACKED;
1782 else
1783 pkt_type = QED_IWARP_MPA_PKT_PARTIAL;
1784
1785out:
1786 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1787 "MPA_ALIGN: %s: fpdu_length=0x%x tcp_payload_len:0x%x\n",
1788 pkt_type_str[pkt_type], fpdu->fpdu_length, tcp_payload_len);
1789
1790 return pkt_type;
1791}
1792
1793static void
1794qed_iwarp_init_fpdu(struct qed_iwarp_ll2_buff *buf,
1795 struct qed_iwarp_fpdu *fpdu,
1796 struct unaligned_opaque_data *pkt_data,
1797 u16 tcp_payload_size, u8 placement_offset)
1798{
1799 fpdu->mpa_buf = buf;
1800 fpdu->pkt_hdr = buf->data_phys_addr + placement_offset;
1801 fpdu->pkt_hdr_size = pkt_data->tcp_payload_offset;
1802 fpdu->mpa_frag = buf->data_phys_addr + pkt_data->first_mpa_offset;
1803 fpdu->mpa_frag_virt = (u8 *)(buf->data) + pkt_data->first_mpa_offset;
1804
1805 if (tcp_payload_size < fpdu->fpdu_length)
1806 fpdu->incomplete_bytes = fpdu->fpdu_length - tcp_payload_size;
1807 else
1808 fpdu->incomplete_bytes = 0; /* complete fpdu */
1809
1810 fpdu->mpa_frag_len = fpdu->fpdu_length - fpdu->incomplete_bytes;
1811}
1812
1813static int
1814qed_iwarp_send_fpdu(struct qed_hwfn *p_hwfn,
1815 struct qed_iwarp_fpdu *fpdu,
1816 struct unaligned_opaque_data *curr_pkt,
1817 struct qed_iwarp_ll2_buff *buf,
1818 u16 tcp_payload_size, enum qed_iwarp_mpa_pkt_type pkt_type)
1819{
1820 struct qed_ll2_tx_pkt_info tx_pkt;
1821 u8 ll2_handle;
1822 int rc;
1823
1824 memset(&tx_pkt, 0, sizeof(tx_pkt));
1825
1826 /* An unaligned packet means it's split over two tcp segments. So the
1827 * complete packet requires 3 bds, one for the header, one for the
1828 * part of the fpdu of the first tcp segment, and the last fragment
1829 * will point to the remainder of the fpdu. A packed pdu, requires only
1830 * two bds, one for the header and one for the data.
1831 */
1832 tx_pkt.num_of_bds = (pkt_type == QED_IWARP_MPA_PKT_UNALIGNED) ? 3 : 2;
1833 tx_pkt.tx_dest = QED_LL2_TX_DEST_LB;
1834 tx_pkt.l4_hdr_offset_w = fpdu->pkt_hdr_size >> 2; /* offset in words */
1835
1836 /* Send the mpa_buf only with the last fpdu (in case of packed) */
1837 if (pkt_type == QED_IWARP_MPA_PKT_UNALIGNED ||
1838 tcp_payload_size <= fpdu->fpdu_length)
1839 tx_pkt.cookie = fpdu->mpa_buf;
1840
1841 tx_pkt.first_frag = fpdu->pkt_hdr;
1842 tx_pkt.first_frag_len = fpdu->pkt_hdr_size;
1843 tx_pkt.enable_ip_cksum = true;
1844 tx_pkt.enable_l4_cksum = true;
1845 tx_pkt.calc_ip_len = true;
1846 /* vlan overload with enum iwarp_ll2_tx_queues */
1847 tx_pkt.vlan = IWARP_LL2_ALIGNED_TX_QUEUE;
1848
Michal Kalderond5310382017-10-09 12:37:52 +03001849 /* special case of unaligned packet and not packed, need to send
1850 * both buffers as cookie to release.
1851 */
1852 if (tcp_payload_size == fpdu->incomplete_bytes)
1853 fpdu->mpa_buf->piggy_buf = buf;
1854
Michal Kalderon469981b2017-10-09 12:37:51 +03001855 ll2_handle = p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle;
1856
1857 /* Set first fragment to header */
1858 rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_handle, &tx_pkt, true);
1859 if (rc)
1860 goto out;
1861
1862 /* Set second fragment to first part of packet */
1863 rc = qed_ll2_set_fragment_of_tx_packet(p_hwfn, ll2_handle,
1864 fpdu->mpa_frag,
1865 fpdu->mpa_frag_len);
1866 if (rc)
1867 goto out;
1868
1869 if (!fpdu->incomplete_bytes)
1870 goto out;
1871
1872 /* Set third fragment to second part of the packet */
1873 rc = qed_ll2_set_fragment_of_tx_packet(p_hwfn,
1874 ll2_handle,
1875 buf->data_phys_addr +
1876 curr_pkt->first_mpa_offset,
1877 fpdu->incomplete_bytes);
1878out:
1879 DP_VERBOSE(p_hwfn,
1880 QED_MSG_RDMA,
1881 "MPA_ALIGN: Sent FPDU num_bds=%d first_frag_len=%x, mpa_frag_len=0x%x, incomplete_bytes:0x%x rc=%d\n",
1882 tx_pkt.num_of_bds,
1883 tx_pkt.first_frag_len,
1884 fpdu->mpa_frag_len,
1885 fpdu->incomplete_bytes, rc);
1886
1887 return rc;
1888}
1889
Michal Kalderonae3488f2017-10-09 12:37:49 +03001890static void
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001891qed_iwarp_mpa_get_data(struct qed_hwfn *p_hwfn,
1892 struct unaligned_opaque_data *curr_pkt,
1893 u32 opaque_data0, u32 opaque_data1)
1894{
1895 u64 opaque_data;
1896
1897 opaque_data = HILO_64(opaque_data1, opaque_data0);
1898 *curr_pkt = *((struct unaligned_opaque_data *)&opaque_data);
1899
1900 curr_pkt->first_mpa_offset = curr_pkt->tcp_payload_offset +
1901 le16_to_cpu(curr_pkt->first_mpa_offset);
1902 curr_pkt->cid = le32_to_cpu(curr_pkt->cid);
1903}
1904
1905/* This function is called when an unaligned or incomplete MPA packet arrives
1906 * driver needs to align the packet, perhaps using previous data and send
1907 * it down to FW once it is aligned.
1908 */
1909static int
1910qed_iwarp_process_mpa_pkt(struct qed_hwfn *p_hwfn,
1911 struct qed_iwarp_ll2_mpa_buf *mpa_buf)
1912{
Michal Kalderon469981b2017-10-09 12:37:51 +03001913 struct unaligned_opaque_data *curr_pkt = &mpa_buf->data;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001914 struct qed_iwarp_ll2_buff *buf = mpa_buf->ll2_buf;
Michal Kalderon469981b2017-10-09 12:37:51 +03001915 enum qed_iwarp_mpa_pkt_type pkt_type;
1916 struct qed_iwarp_fpdu *fpdu;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001917 int rc = -EINVAL;
Michal Kalderon469981b2017-10-09 12:37:51 +03001918 u8 *mpa_data;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001919
Michal Kalderon469981b2017-10-09 12:37:51 +03001920 fpdu = qed_iwarp_get_curr_fpdu(p_hwfn, curr_pkt->cid & 0xffff);
1921 if (!fpdu) { /* something corrupt with cid, post rx back */
1922 DP_ERR(p_hwfn, "Invalid cid, drop and post back to rx cid=%x\n",
1923 curr_pkt->cid);
1924 goto err;
1925 }
1926
1927 do {
1928 mpa_data = ((u8 *)(buf->data) + curr_pkt->first_mpa_offset);
1929
1930 pkt_type = qed_iwarp_mpa_classify(p_hwfn, fpdu,
1931 mpa_buf->tcp_payload_len,
1932 mpa_data);
1933
1934 switch (pkt_type) {
1935 case QED_IWARP_MPA_PKT_PARTIAL:
1936 qed_iwarp_init_fpdu(buf, fpdu,
1937 curr_pkt,
1938 mpa_buf->tcp_payload_len,
1939 mpa_buf->placement_offset);
1940
1941 mpa_buf->tcp_payload_len = 0;
1942 break;
1943 case QED_IWARP_MPA_PKT_PACKED:
1944 qed_iwarp_init_fpdu(buf, fpdu,
1945 curr_pkt,
1946 mpa_buf->tcp_payload_len,
1947 mpa_buf->placement_offset);
1948
1949 rc = qed_iwarp_send_fpdu(p_hwfn, fpdu, curr_pkt, buf,
1950 mpa_buf->tcp_payload_len,
1951 pkt_type);
1952 if (rc) {
1953 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1954 "Can't send FPDU:reset rc=%d\n", rc);
1955 memset(fpdu, 0, sizeof(*fpdu));
1956 break;
1957 }
1958
1959 mpa_buf->tcp_payload_len -= fpdu->fpdu_length;
1960 curr_pkt->first_mpa_offset += fpdu->fpdu_length;
1961 break;
1962 case QED_IWARP_MPA_PKT_UNALIGNED:
1963 rc = qed_iwarp_send_fpdu(p_hwfn, fpdu, curr_pkt, buf,
1964 mpa_buf->tcp_payload_len,
1965 pkt_type);
1966 if (rc) {
1967 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
1968 "Can't send FPDU:delay rc=%d\n", rc);
1969 /* don't reset fpdu -> we need it for next
1970 * classify
1971 */
1972 break;
1973 }
1974
1975 mpa_buf->tcp_payload_len -= fpdu->incomplete_bytes;
1976 curr_pkt->first_mpa_offset += fpdu->incomplete_bytes;
1977 /* The framed PDU was sent - no more incomplete bytes */
1978 fpdu->incomplete_bytes = 0;
1979 break;
1980 }
1981 } while (mpa_buf->tcp_payload_len && !rc);
1982
1983 return rc;
1984
1985err:
Michal Kalderonfcb39f62017-10-09 12:37:50 +03001986 qed_iwarp_ll2_post_rx(p_hwfn,
1987 buf,
1988 p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle);
1989 return rc;
1990}
1991
1992static void qed_iwarp_process_pending_pkts(struct qed_hwfn *p_hwfn)
1993{
1994 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
1995 struct qed_iwarp_ll2_mpa_buf *mpa_buf = NULL;
1996 int rc;
1997
1998 while (!list_empty(&iwarp_info->mpa_buf_pending_list)) {
1999 mpa_buf = list_first_entry(&iwarp_info->mpa_buf_pending_list,
2000 struct qed_iwarp_ll2_mpa_buf,
2001 list_entry);
2002
2003 rc = qed_iwarp_process_mpa_pkt(p_hwfn, mpa_buf);
2004
2005 /* busy means break and continue processing later, don't
2006 * remove the buf from the pending list.
2007 */
2008 if (rc == -EBUSY)
2009 break;
2010
2011 list_del(&mpa_buf->list_entry);
2012 list_add_tail(&mpa_buf->list_entry, &iwarp_info->mpa_buf_list);
2013
2014 if (rc) { /* different error, don't continue */
2015 DP_NOTICE(p_hwfn, "process pkts failed rc=%d\n", rc);
2016 break;
2017 }
2018 }
2019}
2020
2021static void
Michal Kalderonae3488f2017-10-09 12:37:49 +03002022qed_iwarp_ll2_comp_mpa_pkt(void *cxt, struct qed_ll2_comp_rx_data *data)
2023{
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002024 struct qed_iwarp_ll2_mpa_buf *mpa_buf;
Michal Kalderonae3488f2017-10-09 12:37:49 +03002025 struct qed_iwarp_info *iwarp_info;
2026 struct qed_hwfn *p_hwfn = cxt;
2027
2028 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002029 mpa_buf = list_first_entry(&iwarp_info->mpa_buf_list,
2030 struct qed_iwarp_ll2_mpa_buf, list_entry);
2031 if (!mpa_buf) {
2032 DP_ERR(p_hwfn, "No free mpa buf\n");
2033 goto err;
2034 }
2035
2036 list_del(&mpa_buf->list_entry);
2037 qed_iwarp_mpa_get_data(p_hwfn, &mpa_buf->data,
2038 data->opaque_data_0, data->opaque_data_1);
2039
2040 DP_VERBOSE(p_hwfn,
2041 QED_MSG_RDMA,
2042 "LL2 MPA CompRx payload_len:0x%x\tfirst_mpa_offset:0x%x\ttcp_payload_offset:0x%x\tflags:0x%x\tcid:0x%x\n",
2043 data->length.packet_length, mpa_buf->data.first_mpa_offset,
2044 mpa_buf->data.tcp_payload_offset, mpa_buf->data.flags,
2045 mpa_buf->data.cid);
2046
2047 mpa_buf->ll2_buf = data->cookie;
2048 mpa_buf->tcp_payload_len = data->length.packet_length -
2049 mpa_buf->data.first_mpa_offset;
2050 mpa_buf->data.first_mpa_offset += data->u.placement_offset;
2051 mpa_buf->placement_offset = data->u.placement_offset;
2052
2053 list_add_tail(&mpa_buf->list_entry, &iwarp_info->mpa_buf_pending_list);
2054
2055 qed_iwarp_process_pending_pkts(p_hwfn);
2056 return;
2057err:
Michal Kalderonae3488f2017-10-09 12:37:49 +03002058 qed_iwarp_ll2_post_rx(p_hwfn, data->cookie,
2059 iwarp_info->ll2_mpa_handle);
2060}
2061
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002062static void
2063qed_iwarp_ll2_comp_syn_pkt(void *cxt, struct qed_ll2_comp_rx_data *data)
2064{
2065 struct qed_iwarp_ll2_buff *buf = data->cookie;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002066 struct qed_iwarp_listener *listener;
2067 struct qed_ll2_tx_pkt_info tx_pkt;
2068 struct qed_iwarp_cm_info cm_info;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002069 struct qed_hwfn *p_hwfn = cxt;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002070 u8 remote_mac_addr[ETH_ALEN];
2071 u8 local_mac_addr[ETH_ALEN];
Kalderon, Michal456a5842017-07-02 10:29:27 +03002072 struct qed_iwarp_ep *ep;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002073 int tcp_start_offset;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002074 u8 ts_hdr_size = 0;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002075 u8 ll2_syn_handle;
2076 int payload_len;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002077 u32 hdr_size;
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002078 int rc;
2079
2080 memset(&cm_info, 0, sizeof(cm_info));
Michal Kalderon25f45352017-07-03 21:55:25 +03002081 ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle;
Michal Kalderon1e99c492017-09-24 12:09:45 +03002082
2083 /* Check if packet was received with errors... */
2084 if (data->err_flags) {
2085 DP_NOTICE(p_hwfn, "Error received on SYN packet: 0x%x\n",
2086 data->err_flags);
2087 goto err;
2088 }
2089
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002090 if (GET_FIELD(data->parse_flags,
2091 PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED) &&
2092 GET_FIELD(data->parse_flags, PARSING_AND_ERR_FLAGS_L4CHKSMERROR)) {
2093 DP_NOTICE(p_hwfn, "Syn packet received with checksum error\n");
2094 goto err;
2095 }
2096
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002097 rc = qed_iwarp_parse_rx_pkt(p_hwfn, &cm_info, (u8 *)(buf->data) +
2098 data->u.placement_offset, remote_mac_addr,
2099 local_mac_addr, &payload_len,
2100 &tcp_start_offset);
2101 if (rc)
2102 goto err;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002103
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002104 /* Check if there is a listener for this 4-tuple+vlan */
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002105 listener = qed_iwarp_get_listener(p_hwfn, &cm_info);
2106 if (!listener) {
2107 DP_VERBOSE(p_hwfn,
2108 QED_MSG_RDMA,
2109 "SYN received on tuple not listened on parse_flags=%d packet len=%d\n",
2110 data->parse_flags, data->length.packet_length);
2111
2112 memset(&tx_pkt, 0, sizeof(tx_pkt));
2113 tx_pkt.num_of_bds = 1;
2114 tx_pkt.vlan = data->vlan;
2115
2116 if (GET_FIELD(data->parse_flags,
2117 PARSING_AND_ERR_FLAGS_TAG8021QEXIST))
2118 SET_FIELD(tx_pkt.bd_flags,
2119 CORE_TX_BD_DATA_VLAN_INSERTION, 1);
2120
2121 tx_pkt.l4_hdr_offset_w = (data->length.packet_length) >> 2;
2122 tx_pkt.tx_dest = QED_LL2_TX_DEST_LB;
2123 tx_pkt.first_frag = buf->data_phys_addr +
2124 data->u.placement_offset;
2125 tx_pkt.first_frag_len = data->length.packet_length;
2126 tx_pkt.cookie = buf;
2127
2128 rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_syn_handle,
2129 &tx_pkt, true);
2130
2131 if (rc) {
2132 DP_NOTICE(p_hwfn,
2133 "Can't post SYN back to chip rc=%d\n", rc);
2134 goto err;
2135 }
2136 return;
2137 }
2138
2139 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Received syn on listening port\n");
Kalderon, Michal456a5842017-07-02 10:29:27 +03002140 /* There may be an open ep on this connection if this is a syn
2141 * retrasnmit... need to make sure there isn't...
2142 */
2143 if (qed_iwarp_ep_exists(p_hwfn, &cm_info))
2144 goto err;
2145
2146 ep = qed_iwarp_get_free_ep(p_hwfn);
2147 if (!ep)
2148 goto err;
2149
2150 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2151 list_add_tail(&ep->list_entry, &p_hwfn->p_rdma_info->iwarp.ep_list);
2152 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2153
2154 ether_addr_copy(ep->remote_mac_addr, remote_mac_addr);
2155 ether_addr_copy(ep->local_mac_addr, local_mac_addr);
2156
2157 memcpy(&ep->cm_info, &cm_info, sizeof(ep->cm_info));
2158
2159 if (p_hwfn->p_rdma_info->iwarp.tcp_flags & QED_IWARP_TS_EN)
2160 ts_hdr_size = TIMESTAMP_HEADER_SIZE;
2161
2162 hdr_size = ((cm_info.ip_version == QED_TCP_IPV4) ? 40 : 60) +
2163 ts_hdr_size;
2164 ep->mss = p_hwfn->p_rdma_info->iwarp.max_mtu - hdr_size;
2165 ep->mss = min_t(u16, QED_IWARP_MAX_FW_MSS, ep->mss);
2166
2167 ep->event_cb = listener->event_cb;
2168 ep->cb_context = listener->cb_context;
2169 ep->connect_mode = TCP_CONNECT_PASSIVE;
2170
2171 ep->syn = buf;
2172 ep->syn_ip_payload_length = (u16)payload_len;
2173 ep->syn_phy_addr = buf->data_phys_addr + data->u.placement_offset +
2174 tcp_start_offset;
2175
2176 rc = qed_iwarp_tcp_offload(p_hwfn, ep);
2177 if (rc) {
2178 qed_iwarp_return_ep(p_hwfn, ep);
2179 goto err;
2180 }
2181
2182 return;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002183err:
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002184 qed_iwarp_ll2_post_rx(p_hwfn, buf, ll2_syn_handle);
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002185}
2186
2187static void qed_iwarp_ll2_rel_rx_pkt(void *cxt, u8 connection_handle,
2188 void *cookie, dma_addr_t rx_buf_addr,
2189 bool b_last_packet)
2190{
2191 struct qed_iwarp_ll2_buff *buffer = cookie;
2192 struct qed_hwfn *p_hwfn = cxt;
2193
2194 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size,
2195 buffer->data, buffer->data_phys_addr);
2196 kfree(buffer);
2197}
2198
2199static void qed_iwarp_ll2_comp_tx_pkt(void *cxt, u8 connection_handle,
2200 void *cookie, dma_addr_t first_frag_addr,
2201 bool b_last_fragment, bool b_last_packet)
2202{
2203 struct qed_iwarp_ll2_buff *buffer = cookie;
Michal Kalderond5310382017-10-09 12:37:52 +03002204 struct qed_iwarp_ll2_buff *piggy;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002205 struct qed_hwfn *p_hwfn = cxt;
2206
Michal Kalderond5310382017-10-09 12:37:52 +03002207 if (!buffer) /* can happen in packed mpa unaligned... */
2208 return;
2209
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002210 /* this was originally an rx packet, post it back */
Michal Kalderond5310382017-10-09 12:37:52 +03002211 piggy = buffer->piggy_buf;
2212 if (piggy) {
2213 buffer->piggy_buf = NULL;
2214 qed_iwarp_ll2_post_rx(p_hwfn, piggy, connection_handle);
2215 }
2216
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002217 qed_iwarp_ll2_post_rx(p_hwfn, buffer, connection_handle);
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002218
2219 if (connection_handle == p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle)
2220 qed_iwarp_process_pending_pkts(p_hwfn);
2221
2222 return;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002223}
2224
2225static void qed_iwarp_ll2_rel_tx_pkt(void *cxt, u8 connection_handle,
2226 void *cookie, dma_addr_t first_frag_addr,
2227 bool b_last_fragment, bool b_last_packet)
2228{
2229 struct qed_iwarp_ll2_buff *buffer = cookie;
2230 struct qed_hwfn *p_hwfn = cxt;
2231
2232 if (!buffer)
2233 return;
2234
Michal Kalderond5310382017-10-09 12:37:52 +03002235 if (buffer->piggy_buf) {
2236 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
2237 buffer->piggy_buf->buff_size,
2238 buffer->piggy_buf->data,
2239 buffer->piggy_buf->data_phys_addr);
2240
2241 kfree(buffer->piggy_buf);
2242 }
2243
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002244 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size,
2245 buffer->data, buffer->data_phys_addr);
2246
2247 kfree(buffer);
2248}
2249
Michal Kalderon469981b2017-10-09 12:37:51 +03002250/* The only slowpath for iwarp ll2 is unalign flush. When this completion
2251 * is received, need to reset the FPDU.
2252 */
Michal Kalderonae3488f2017-10-09 12:37:49 +03002253void
2254qed_iwarp_ll2_slowpath(void *cxt,
2255 u8 connection_handle,
2256 u32 opaque_data_0, u32 opaque_data_1)
2257{
Michal Kalderon469981b2017-10-09 12:37:51 +03002258 struct unaligned_opaque_data unalign_data;
2259 struct qed_hwfn *p_hwfn = cxt;
2260 struct qed_iwarp_fpdu *fpdu;
2261
2262 qed_iwarp_mpa_get_data(p_hwfn, &unalign_data,
2263 opaque_data_0, opaque_data_1);
2264
2265 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "(0x%x) Flush fpdu\n",
2266 unalign_data.cid);
2267
2268 fpdu = qed_iwarp_get_curr_fpdu(p_hwfn, (u16)unalign_data.cid);
2269 if (fpdu)
2270 memset(fpdu, 0, sizeof(*fpdu));
Michal Kalderonae3488f2017-10-09 12:37:49 +03002271}
2272
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002273static int qed_iwarp_ll2_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2274{
2275 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
2276 int rc = 0;
2277
2278 if (iwarp_info->ll2_syn_handle != QED_IWARP_HANDLE_INVAL) {
2279 rc = qed_ll2_terminate_connection(p_hwfn,
2280 iwarp_info->ll2_syn_handle);
2281 if (rc)
2282 DP_INFO(p_hwfn, "Failed to terminate syn connection\n");
2283
2284 qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_syn_handle);
2285 iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL;
2286 }
2287
Michal Kalderond1abfd02017-09-24 12:09:43 +03002288 if (iwarp_info->ll2_ooo_handle != QED_IWARP_HANDLE_INVAL) {
2289 rc = qed_ll2_terminate_connection(p_hwfn,
2290 iwarp_info->ll2_ooo_handle);
2291 if (rc)
2292 DP_INFO(p_hwfn, "Failed to terminate ooo connection\n");
2293
2294 qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_ooo_handle);
2295 iwarp_info->ll2_ooo_handle = QED_IWARP_HANDLE_INVAL;
2296 }
2297
Michal Kalderonae3488f2017-10-09 12:37:49 +03002298 if (iwarp_info->ll2_mpa_handle != QED_IWARP_HANDLE_INVAL) {
2299 rc = qed_ll2_terminate_connection(p_hwfn,
2300 iwarp_info->ll2_mpa_handle);
2301 if (rc)
2302 DP_INFO(p_hwfn, "Failed to terminate mpa connection\n");
2303
2304 qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_mpa_handle);
2305 iwarp_info->ll2_mpa_handle = QED_IWARP_HANDLE_INVAL;
2306 }
2307
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002308 qed_llh_remove_mac_filter(p_hwfn,
2309 p_ptt, p_hwfn->p_rdma_info->iwarp.mac_addr);
2310 return rc;
2311}
2312
2313static int
2314qed_iwarp_ll2_alloc_buffers(struct qed_hwfn *p_hwfn,
2315 int num_rx_bufs, int buff_size, u8 ll2_handle)
2316{
2317 struct qed_iwarp_ll2_buff *buffer;
2318 int rc = 0;
2319 int i;
2320
2321 for (i = 0; i < num_rx_bufs; i++) {
2322 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
2323 if (!buffer) {
2324 rc = -ENOMEM;
2325 break;
2326 }
2327
2328 buffer->data = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
2329 buff_size,
2330 &buffer->data_phys_addr,
2331 GFP_KERNEL);
2332 if (!buffer->data) {
2333 kfree(buffer);
2334 rc = -ENOMEM;
2335 break;
2336 }
2337
2338 buffer->buff_size = buff_size;
2339 rc = qed_iwarp_ll2_post_rx(p_hwfn, buffer, ll2_handle);
2340 if (rc)
2341 /* buffers will be deallocated by qed_ll2 */
2342 break;
2343 }
2344 return rc;
2345}
2346
2347#define QED_IWARP_MAX_BUF_SIZE(mtu) \
2348 ALIGN((mtu) + ETH_HLEN + 2 * VLAN_HLEN + 2 + ETH_CACHE_LINE_SIZE, \
2349 ETH_CACHE_LINE_SIZE)
2350
2351static int
2352qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn,
2353 struct qed_rdma_start_in_params *params,
2354 struct qed_ptt *p_ptt)
2355{
2356 struct qed_iwarp_info *iwarp_info;
2357 struct qed_ll2_acquire_data data;
2358 struct qed_ll2_cbs cbs;
Michal Kalderonae3488f2017-10-09 12:37:49 +03002359 u32 mpa_buff_size;
Michal Kalderond1abfd02017-09-24 12:09:43 +03002360 u16 n_ooo_bufs;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002361 int rc = 0;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002362 int i;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002363
2364 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
2365 iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL;
Michal Kalderond1abfd02017-09-24 12:09:43 +03002366 iwarp_info->ll2_ooo_handle = QED_IWARP_HANDLE_INVAL;
Michal Kalderonae3488f2017-10-09 12:37:49 +03002367 iwarp_info->ll2_mpa_handle = QED_IWARP_HANDLE_INVAL;
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002368
2369 iwarp_info->max_mtu = params->max_mtu;
2370
2371 ether_addr_copy(p_hwfn->p_rdma_info->iwarp.mac_addr, params->mac_addr);
2372
2373 rc = qed_llh_add_mac_filter(p_hwfn, p_ptt, params->mac_addr);
2374 if (rc)
2375 return rc;
2376
2377 /* Start SYN connection */
2378 cbs.rx_comp_cb = qed_iwarp_ll2_comp_syn_pkt;
2379 cbs.rx_release_cb = qed_iwarp_ll2_rel_rx_pkt;
2380 cbs.tx_comp_cb = qed_iwarp_ll2_comp_tx_pkt;
2381 cbs.tx_release_cb = qed_iwarp_ll2_rel_tx_pkt;
2382 cbs.cookie = p_hwfn;
2383
2384 memset(&data, 0, sizeof(data));
2385 data.input.conn_type = QED_LL2_TYPE_IWARP;
2386 data.input.mtu = QED_IWARP_MAX_SYN_PKT_SIZE;
2387 data.input.rx_num_desc = QED_IWARP_LL2_SYN_RX_SIZE;
2388 data.input.tx_num_desc = QED_IWARP_LL2_SYN_TX_SIZE;
2389 data.input.tx_max_bds_per_packet = 1; /* will never be fragmented */
2390 data.input.tx_tc = PKT_LB_TC;
2391 data.input.tx_dest = QED_LL2_TX_DEST_LB;
2392 data.p_connection_handle = &iwarp_info->ll2_syn_handle;
2393 data.cbs = &cbs;
2394
2395 rc = qed_ll2_acquire_connection(p_hwfn, &data);
2396 if (rc) {
2397 DP_NOTICE(p_hwfn, "Failed to acquire LL2 connection\n");
2398 qed_llh_remove_mac_filter(p_hwfn, p_ptt, params->mac_addr);
2399 return rc;
2400 }
2401
2402 rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_syn_handle);
2403 if (rc) {
2404 DP_NOTICE(p_hwfn, "Failed to establish LL2 connection\n");
2405 goto err;
2406 }
2407
2408 rc = qed_iwarp_ll2_alloc_buffers(p_hwfn,
2409 QED_IWARP_LL2_SYN_RX_SIZE,
2410 QED_IWARP_MAX_SYN_PKT_SIZE,
2411 iwarp_info->ll2_syn_handle);
2412 if (rc)
2413 goto err;
2414
Michal Kalderond1abfd02017-09-24 12:09:43 +03002415 /* Start OOO connection */
2416 data.input.conn_type = QED_LL2_TYPE_OOO;
2417 data.input.mtu = params->max_mtu;
2418
2419 n_ooo_bufs = (QED_IWARP_MAX_OOO * QED_IWARP_RCV_WND_SIZE_DEF) /
2420 iwarp_info->max_mtu;
2421 n_ooo_bufs = min_t(u32, n_ooo_bufs, QED_IWARP_LL2_OOO_MAX_RX_SIZE);
2422
2423 data.input.rx_num_desc = n_ooo_bufs;
2424 data.input.rx_num_ooo_buffers = n_ooo_bufs;
2425
2426 data.input.tx_max_bds_per_packet = 1; /* will never be fragmented */
2427 data.input.tx_num_desc = QED_IWARP_LL2_OOO_DEF_TX_SIZE;
2428 data.p_connection_handle = &iwarp_info->ll2_ooo_handle;
2429
2430 rc = qed_ll2_acquire_connection(p_hwfn, &data);
2431 if (rc)
2432 goto err;
2433
2434 rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_ooo_handle);
2435 if (rc)
2436 goto err;
2437
Michal Kalderonae3488f2017-10-09 12:37:49 +03002438 /* Start Unaligned MPA connection */
2439 cbs.rx_comp_cb = qed_iwarp_ll2_comp_mpa_pkt;
2440 cbs.slowpath_cb = qed_iwarp_ll2_slowpath;
2441
2442 memset(&data, 0, sizeof(data));
2443 data.input.conn_type = QED_LL2_TYPE_IWARP;
2444 data.input.mtu = params->max_mtu;
2445 /* FW requires that once a packet arrives OOO, it must have at
2446 * least 2 rx buffers available on the unaligned connection
2447 * for handling the case that it is a partial fpdu.
2448 */
2449 data.input.rx_num_desc = n_ooo_bufs * 2;
2450 data.input.tx_num_desc = data.input.rx_num_desc;
2451 data.input.tx_max_bds_per_packet = QED_IWARP_MAX_BDS_PER_FPDU;
2452 data.p_connection_handle = &iwarp_info->ll2_mpa_handle;
2453 data.input.secondary_queue = true;
2454 data.cbs = &cbs;
2455
2456 rc = qed_ll2_acquire_connection(p_hwfn, &data);
2457 if (rc)
2458 goto err;
2459
2460 rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_mpa_handle);
2461 if (rc)
2462 goto err;
2463
2464 mpa_buff_size = QED_IWARP_MAX_BUF_SIZE(params->max_mtu);
2465 rc = qed_iwarp_ll2_alloc_buffers(p_hwfn,
2466 data.input.rx_num_desc,
2467 mpa_buff_size,
2468 iwarp_info->ll2_mpa_handle);
2469 if (rc)
2470 goto err;
Michal Kalderon469981b2017-10-09 12:37:51 +03002471
2472 iwarp_info->partial_fpdus = kcalloc((u16)p_hwfn->p_rdma_info->num_qps,
2473 sizeof(*iwarp_info->partial_fpdus),
2474 GFP_KERNEL);
2475 if (!iwarp_info->partial_fpdus)
2476 goto err;
2477
2478 iwarp_info->max_num_partial_fpdus = (u16)p_hwfn->p_rdma_info->num_qps;
Michal Kalderonfcb39f62017-10-09 12:37:50 +03002479 /* The mpa_bufs array serves for pending RX packets received on the
2480 * mpa ll2 that don't have place on the tx ring and require later
2481 * processing. We can't fail on allocation of such a struct therefore
2482 * we allocate enough to take care of all rx packets
2483 */
2484 iwarp_info->mpa_bufs = kcalloc(data.input.rx_num_desc,
2485 sizeof(*iwarp_info->mpa_bufs),
2486 GFP_KERNEL);
2487 if (!iwarp_info->mpa_bufs)
2488 goto err;
2489
2490 INIT_LIST_HEAD(&iwarp_info->mpa_buf_pending_list);
2491 INIT_LIST_HEAD(&iwarp_info->mpa_buf_list);
2492 for (i = 0; i < data.input.rx_num_desc; i++)
2493 list_add_tail(&iwarp_info->mpa_bufs[i].list_entry,
2494 &iwarp_info->mpa_buf_list);
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002495 return rc;
2496err:
2497 qed_iwarp_ll2_stop(p_hwfn, p_ptt);
2498
2499 return rc;
2500}
2501
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002502int qed_iwarp_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
2503 struct qed_rdma_start_in_params *params)
2504{
2505 struct qed_iwarp_info *iwarp_info;
2506 u32 rcv_wnd_size;
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002507
2508 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
2509
2510 iwarp_info->tcp_flags = QED_IWARP_TS_EN;
2511 rcv_wnd_size = QED_IWARP_RCV_WND_SIZE_DEF;
2512
2513 /* value 0 is used for ilog2(QED_IWARP_RCV_WND_SIZE_MIN) */
2514 iwarp_info->rcv_wnd_scale = ilog2(rcv_wnd_size) -
2515 ilog2(QED_IWARP_RCV_WND_SIZE_MIN);
2516 iwarp_info->crc_needed = QED_IWARP_PARAM_CRC_NEEDED;
2517 iwarp_info->mpa_rev = MPA_NEGOTIATION_TYPE_ENHANCED;
2518
2519 iwarp_info->peer2peer = QED_IWARP_PARAM_P2P;
2520
Kalderon, Michal456a5842017-07-02 10:29:27 +03002521 iwarp_info->rtr_type = MPA_RTR_TYPE_ZERO_SEND |
2522 MPA_RTR_TYPE_ZERO_WRITE |
2523 MPA_RTR_TYPE_ZERO_READ;
2524
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002525 spin_lock_init(&p_hwfn->p_rdma_info->iwarp.qp_lock);
Kalderon, Michal456a5842017-07-02 10:29:27 +03002526 INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.ep_list);
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002527 INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.listen_list);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002528
2529 qed_spq_register_async_cb(p_hwfn, PROTOCOLID_IWARP,
2530 qed_iwarp_async_event);
Michal Kalderond1abfd02017-09-24 12:09:43 +03002531 qed_ooo_setup(p_hwfn);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002532
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002533 return qed_iwarp_ll2_start(p_hwfn, params, p_ptt);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002534}
2535
2536int qed_iwarp_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2537{
2538 int rc;
2539
Kalderon, Michal456a5842017-07-02 10:29:27 +03002540 qed_iwarp_free_prealloc_ep(p_hwfn);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002541 rc = qed_iwarp_wait_for_all_cids(p_hwfn);
2542 if (rc)
2543 return rc;
2544
2545 qed_spq_unregister_async_cb(p_hwfn, PROTOCOLID_IWARP);
2546
Kalderon, Michalb5c29ca2017-07-02 10:29:25 +03002547 return qed_iwarp_ll2_stop(p_hwfn, p_ptt);
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002548}
2549
Kalderon, Michalfc4c6062017-07-02 10:29:29 +03002550void qed_iwarp_qp_in_error(struct qed_hwfn *p_hwfn,
2551 struct qed_iwarp_ep *ep, u8 fw_return_code)
2552{
2553 struct qed_iwarp_cm_event_params params;
2554
2555 qed_iwarp_modify_qp(p_hwfn, ep->qp, QED_IWARP_QP_STATE_ERROR, true);
2556
2557 params.event = QED_IWARP_EVENT_CLOSE;
2558 params.ep_context = ep;
2559 params.cm_info = &ep->cm_info;
2560 params.status = (fw_return_code == IWARP_QP_IN_ERROR_GOOD_CLOSE) ?
2561 0 : -ECONNRESET;
2562
2563 ep->state = QED_IWARP_EP_CLOSED;
2564 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2565 list_del(&ep->list_entry);
2566 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2567
2568 ep->event_cb(ep->cb_context, &params);
2569}
2570
2571void qed_iwarp_exception_received(struct qed_hwfn *p_hwfn,
2572 struct qed_iwarp_ep *ep, int fw_ret_code)
2573{
2574 struct qed_iwarp_cm_event_params params;
2575 bool event_cb = false;
2576
2577 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "EP(0x%x) fw_ret_code=%d\n",
2578 ep->cid, fw_ret_code);
2579
2580 switch (fw_ret_code) {
2581 case IWARP_EXCEPTION_DETECTED_LLP_CLOSED:
2582 params.status = 0;
2583 params.event = QED_IWARP_EVENT_DISCONNECT;
2584 event_cb = true;
2585 break;
2586 case IWARP_EXCEPTION_DETECTED_LLP_RESET:
2587 params.status = -ECONNRESET;
2588 params.event = QED_IWARP_EVENT_DISCONNECT;
2589 event_cb = true;
2590 break;
Kalderon, Michal9816b612017-07-02 10:29:30 +03002591 case IWARP_EXCEPTION_DETECTED_RQ_EMPTY:
2592 params.event = QED_IWARP_EVENT_RQ_EMPTY;
2593 event_cb = true;
2594 break;
2595 case IWARP_EXCEPTION_DETECTED_IRQ_FULL:
2596 params.event = QED_IWARP_EVENT_IRQ_FULL;
2597 event_cb = true;
2598 break;
2599 case IWARP_EXCEPTION_DETECTED_LLP_TIMEOUT:
2600 params.event = QED_IWARP_EVENT_LLP_TIMEOUT;
2601 event_cb = true;
2602 break;
2603 case IWARP_EXCEPTION_DETECTED_REMOTE_PROTECTION_ERROR:
2604 params.event = QED_IWARP_EVENT_REMOTE_PROTECTION_ERROR;
2605 event_cb = true;
2606 break;
2607 case IWARP_EXCEPTION_DETECTED_CQ_OVERFLOW:
2608 params.event = QED_IWARP_EVENT_CQ_OVERFLOW;
2609 event_cb = true;
2610 break;
2611 case IWARP_EXCEPTION_DETECTED_LOCAL_CATASTROPHIC:
2612 params.event = QED_IWARP_EVENT_QP_CATASTROPHIC;
2613 event_cb = true;
2614 break;
2615 case IWARP_EXCEPTION_DETECTED_LOCAL_ACCESS_ERROR:
2616 params.event = QED_IWARP_EVENT_LOCAL_ACCESS_ERROR;
2617 event_cb = true;
2618 break;
2619 case IWARP_EXCEPTION_DETECTED_REMOTE_OPERATION_ERROR:
2620 params.event = QED_IWARP_EVENT_REMOTE_OPERATION_ERROR;
2621 event_cb = true;
2622 break;
2623 case IWARP_EXCEPTION_DETECTED_TERMINATE_RECEIVED:
2624 params.event = QED_IWARP_EVENT_TERMINATE_RECEIVED;
2625 event_cb = true;
2626 break;
Kalderon, Michalfc4c6062017-07-02 10:29:29 +03002627 default:
2628 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2629 "Unhandled exception received...fw_ret_code=%d\n",
2630 fw_ret_code);
2631 break;
2632 }
2633
2634 if (event_cb) {
2635 params.ep_context = ep;
2636 params.cm_info = &ep->cm_info;
2637 ep->event_cb(ep->cb_context, &params);
2638 }
2639}
2640
Kalderon, Michal9816b612017-07-02 10:29:30 +03002641static void
2642qed_iwarp_tcp_connect_unsuccessful(struct qed_hwfn *p_hwfn,
2643 struct qed_iwarp_ep *ep, u8 fw_return_code)
2644{
2645 struct qed_iwarp_cm_event_params params;
2646
2647 memset(&params, 0, sizeof(params));
2648 params.event = QED_IWARP_EVENT_ACTIVE_COMPLETE;
2649 params.ep_context = ep;
2650 params.cm_info = &ep->cm_info;
2651 ep->state = QED_IWARP_EP_CLOSED;
2652
2653 switch (fw_return_code) {
2654 case IWARP_CONN_ERROR_TCP_CONNECT_INVALID_PACKET:
2655 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2656 "%s(0x%x) TCP connect got invalid packet\n",
2657 QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
2658 params.status = -ECONNRESET;
2659 break;
2660 case IWARP_CONN_ERROR_TCP_CONNECTION_RST:
2661 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2662 "%s(0x%x) TCP Connection Reset\n",
2663 QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
2664 params.status = -ECONNRESET;
2665 break;
2666 case IWARP_CONN_ERROR_TCP_CONNECT_TIMEOUT:
2667 DP_NOTICE(p_hwfn, "%s(0x%x) TCP timeout\n",
2668 QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
2669 params.status = -EBUSY;
2670 break;
2671 case IWARP_CONN_ERROR_MPA_NOT_SUPPORTED_VER:
2672 DP_NOTICE(p_hwfn, "%s(0x%x) MPA not supported VER\n",
2673 QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
2674 params.status = -ECONNREFUSED;
2675 break;
2676 case IWARP_CONN_ERROR_MPA_INVALID_PACKET:
2677 DP_NOTICE(p_hwfn, "%s(0x%x) MPA Invalid Packet\n",
2678 QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
2679 params.status = -ECONNRESET;
2680 break;
2681 default:
2682 DP_ERR(p_hwfn,
2683 "%s(0x%x) Unexpected return code tcp connect: %d\n",
2684 QED_IWARP_CONNECT_MODE_STRING(ep),
2685 ep->tcp_cid, fw_return_code);
2686 params.status = -ECONNRESET;
2687 break;
2688 }
2689
2690 if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
2691 ep->tcp_cid = QED_IWARP_INVALID_TCP_CID;
2692 qed_iwarp_return_ep(p_hwfn, ep);
2693 } else {
2694 ep->event_cb(ep->cb_context, &params);
2695 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2696 list_del(&ep->list_entry);
2697 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2698 }
2699}
2700
Kalderon, Michal456a5842017-07-02 10:29:27 +03002701void
2702qed_iwarp_connect_complete(struct qed_hwfn *p_hwfn,
2703 struct qed_iwarp_ep *ep, u8 fw_return_code)
2704{
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002705 u8 ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002706
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002707 if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
2708 /* Done with the SYN packet, post back to ll2 rx */
2709 qed_iwarp_ll2_post_rx(p_hwfn, ep->syn, ll2_syn_handle);
2710
2711 ep->syn = NULL;
2712
2713 /* If connect failed - upper layer doesn't know about it */
Kalderon, Michal9816b612017-07-02 10:29:30 +03002714 if (fw_return_code == RDMA_RETURN_OK)
2715 qed_iwarp_mpa_received(p_hwfn, ep);
2716 else
2717 qed_iwarp_tcp_connect_unsuccessful(p_hwfn, ep,
2718 fw_return_code);
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002719 } else {
Kalderon, Michal9816b612017-07-02 10:29:30 +03002720 if (fw_return_code == RDMA_RETURN_OK)
2721 qed_iwarp_mpa_offload(p_hwfn, ep);
2722 else
2723 qed_iwarp_tcp_connect_unsuccessful(p_hwfn, ep,
2724 fw_return_code);
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002725 }
Kalderon, Michal456a5842017-07-02 10:29:27 +03002726}
2727
2728static inline bool
2729qed_iwarp_check_ep_ok(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
2730{
2731 if (!ep || (ep->sig != QED_EP_SIG)) {
2732 DP_ERR(p_hwfn, "ERROR ON ASYNC ep=%p\n", ep);
2733 return false;
2734 }
2735
2736 return true;
2737}
2738
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002739static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn,
2740 u8 fw_event_code, u16 echo,
2741 union event_ring_data *data,
2742 u8 fw_return_code)
2743{
Kalderon, Michal456a5842017-07-02 10:29:27 +03002744 struct regpair *fw_handle = &data->rdma_data.async_handle;
2745 struct qed_iwarp_ep *ep = NULL;
2746 u16 cid;
2747
2748 ep = (struct qed_iwarp_ep *)(uintptr_t)HILO_64(fw_handle->hi,
2749 fw_handle->lo);
2750
2751 switch (fw_event_code) {
2752 case IWARP_EVENT_TYPE_ASYNC_CONNECT_COMPLETE:
2753 /* Async completion after TCP 3-way handshake */
2754 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2755 return -EINVAL;
2756 DP_VERBOSE(p_hwfn,
2757 QED_MSG_RDMA,
2758 "EP(0x%x) IWARP_EVENT_TYPE_ASYNC_CONNECT_COMPLETE fw_ret_code=%d\n",
2759 ep->tcp_cid, fw_return_code);
2760 qed_iwarp_connect_complete(p_hwfn, ep, fw_return_code);
2761 break;
Kalderon, Michalfc4c6062017-07-02 10:29:29 +03002762 case IWARP_EVENT_TYPE_ASYNC_EXCEPTION_DETECTED:
2763 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2764 return -EINVAL;
2765 DP_VERBOSE(p_hwfn,
2766 QED_MSG_RDMA,
2767 "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_EXCEPTION_DETECTED fw_ret_code=%d\n",
2768 ep->cid, fw_return_code);
2769 qed_iwarp_exception_received(p_hwfn, ep, fw_return_code);
2770 break;
2771 case IWARP_EVENT_TYPE_ASYNC_QP_IN_ERROR_STATE:
2772 /* Async completion for Close Connection ramrod */
2773 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2774 return -EINVAL;
2775 DP_VERBOSE(p_hwfn,
2776 QED_MSG_RDMA,
2777 "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_QP_IN_ERROR_STATE fw_ret_code=%d\n",
2778 ep->cid, fw_return_code);
2779 qed_iwarp_qp_in_error(p_hwfn, ep, fw_return_code);
2780 break;
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002781 case IWARP_EVENT_TYPE_ASYNC_ENHANCED_MPA_REPLY_ARRIVED:
Kalderon, Michalfc4c6062017-07-02 10:29:29 +03002782 /* Async event for active side only */
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002783 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2784 return -EINVAL;
2785 DP_VERBOSE(p_hwfn,
2786 QED_MSG_RDMA,
2787 "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_MPA_REPLY_ARRIVED fw_ret_code=%d\n",
2788 ep->cid, fw_return_code);
2789 qed_iwarp_mpa_reply_arrived(p_hwfn, ep);
2790 break;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002791 case IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE:
2792 if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
2793 return -EINVAL;
2794 DP_VERBOSE(p_hwfn,
2795 QED_MSG_RDMA,
2796 "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE fw_ret_code=%d\n",
2797 ep->cid, fw_return_code);
2798 qed_iwarp_mpa_complete(p_hwfn, ep, fw_return_code);
2799 break;
2800 case IWARP_EVENT_TYPE_ASYNC_CID_CLEANED:
2801 cid = (u16)le32_to_cpu(fw_handle->lo);
2802 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
2803 "(0x%x)IWARP_EVENT_TYPE_ASYNC_CID_CLEANED\n", cid);
2804 qed_iwarp_cid_cleaned(p_hwfn, cid);
2805
2806 break;
Kalderon, Michal9816b612017-07-02 10:29:30 +03002807 case IWARP_EVENT_TYPE_ASYNC_CQ_OVERFLOW:
2808 DP_NOTICE(p_hwfn, "IWARP_EVENT_TYPE_ASYNC_CQ_OVERFLOW\n");
2809
2810 p_hwfn->p_rdma_info->events.affiliated_event(
2811 p_hwfn->p_rdma_info->events.context,
2812 QED_IWARP_EVENT_CQ_OVERFLOW,
2813 (void *)fw_handle);
2814 break;
2815 default:
2816 DP_ERR(p_hwfn, "Received unexpected async iwarp event %d\n",
2817 fw_event_code);
2818 return -EINVAL;
Kalderon, Michal456a5842017-07-02 10:29:27 +03002819 }
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002820 return 0;
2821}
2822
Kalderon, Michal65a91a62017-07-02 10:29:26 +03002823int
2824qed_iwarp_create_listen(void *rdma_cxt,
2825 struct qed_iwarp_listen_in *iparams,
2826 struct qed_iwarp_listen_out *oparams)
2827{
2828 struct qed_hwfn *p_hwfn = rdma_cxt;
2829 struct qed_iwarp_listener *listener;
2830
2831 listener = kzalloc(sizeof(*listener), GFP_KERNEL);
2832 if (!listener)
2833 return -ENOMEM;
2834
2835 listener->ip_version = iparams->ip_version;
2836 memcpy(listener->ip_addr, iparams->ip_addr, sizeof(listener->ip_addr));
2837 listener->port = iparams->port;
2838 listener->vlan = iparams->vlan;
2839
2840 listener->event_cb = iparams->event_cb;
2841 listener->cb_context = iparams->cb_context;
2842 listener->max_backlog = iparams->max_backlog;
2843 oparams->handle = listener;
2844
2845 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2846 list_add_tail(&listener->list_entry,
2847 &p_hwfn->p_rdma_info->iwarp.listen_list);
2848 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2849
2850 DP_VERBOSE(p_hwfn,
2851 QED_MSG_RDMA,
2852 "callback=%p handle=%p ip=%x:%x:%x:%x port=0x%x vlan=0x%x\n",
2853 listener->event_cb,
2854 listener,
2855 listener->ip_addr[0],
2856 listener->ip_addr[1],
2857 listener->ip_addr[2],
2858 listener->ip_addr[3], listener->port, listener->vlan);
2859
2860 return 0;
2861}
2862
2863int qed_iwarp_destroy_listen(void *rdma_cxt, void *handle)
2864{
2865 struct qed_iwarp_listener *listener = handle;
2866 struct qed_hwfn *p_hwfn = rdma_cxt;
2867
2868 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "handle=%p\n", handle);
2869
2870 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2871 list_del(&listener->list_entry);
2872 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
2873
2874 kfree(listener);
2875
2876 return 0;
2877}
2878
Kalderon, Michal4b0fdd72017-07-02 10:29:28 +03002879int qed_iwarp_send_rtr(void *rdma_cxt, struct qed_iwarp_send_rtr_in *iparams)
2880{
2881 struct qed_hwfn *p_hwfn = rdma_cxt;
2882 struct qed_sp_init_data init_data;
2883 struct qed_spq_entry *p_ent;
2884 struct qed_iwarp_ep *ep;
2885 struct qed_rdma_qp *qp;
2886 int rc;
2887
2888 ep = iparams->ep_context;
2889 if (!ep) {
2890 DP_ERR(p_hwfn, "Ep Context receive in send_rtr is NULL\n");
2891 return -EINVAL;
2892 }
2893
2894 qp = ep->qp;
2895
2896 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x)\n",
2897 qp->icid, ep->tcp_cid);
2898
2899 memset(&init_data, 0, sizeof(init_data));
2900 init_data.cid = qp->icid;
2901 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
2902 init_data.comp_mode = QED_SPQ_MODE_CB;
2903
2904 rc = qed_sp_init_request(p_hwfn, &p_ent,
2905 IWARP_RAMROD_CMD_ID_MPA_OFFLOAD_SEND_RTR,
2906 PROTOCOLID_IWARP, &init_data);
2907
2908 if (rc)
2909 return rc;
2910
2911 rc = qed_spq_post(p_hwfn, p_ent, NULL);
2912
2913 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = 0x%x\n", rc);
2914
2915 return rc;
2916}
2917
Kalderon, Michal67b40dc2017-07-02 10:29:22 +03002918void
2919qed_iwarp_query_qp(struct qed_rdma_qp *qp,
2920 struct qed_rdma_query_qp_out_params *out_params)
2921{
2922 out_params->state = qed_iwarp2roce_state(qp->iwarp_state);
2923}