1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
32 #include <linux/if_ether.h>
33 #include <linux/if_vlan.h>
35 #include <linux/ipv6.h>
36 #include <linux/spinlock.h>
37 #include <linux/tcp.h>
42 #include "qed_reg_addr.h"
45 #define QED_IWARP_ORD_DEFAULT 32
46 #define QED_IWARP_IRD_DEFAULT 32
47 #define QED_IWARP_RCV_WND_SIZE_DEF (256 * 1024)
48 #define QED_IWARP_RCV_WND_SIZE_MIN (64 * 1024)
49 #define QED_IWARP_TS_EN BIT(0)
50 #define QED_IWARP_PARAM_CRC_NEEDED (1)
51 #define QED_IWARP_PARAM_P2P (1)
53 static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn,
54 u8 fw_event_code, u16 echo,
55 union event_ring_data *data,
58 /* Override devinfo with iWARP specific values */
59 void qed_iwarp_init_devinfo(struct qed_hwfn *p_hwfn)
61 struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
63 dev->max_inline = IWARP_REQ_MAX_INLINE_DATA_SIZE;
64 dev->max_qp = min_t(u32,
66 p_hwfn->p_rdma_info->num_qps);
68 dev->max_cq = dev->max_qp;
70 dev->max_qp_resp_rd_atomic_resc = QED_IWARP_IRD_DEFAULT;
71 dev->max_qp_req_rd_atomic_resc = QED_IWARP_ORD_DEFAULT;
74 void qed_iwarp_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
76 p_hwfn->rdma_prs_search_reg = PRS_REG_SEARCH_TCP;
77 qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1);
78 p_hwfn->b_rdma_enabled_in_prs = true;
81 static void qed_iwarp_cid_cleaned(struct qed_hwfn *p_hwfn, u32 cid)
83 cid -= qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
85 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
86 qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid);
87 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
90 static int qed_iwarp_alloc_cid(struct qed_hwfn *p_hwfn, u32 *cid)
94 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
95 rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid);
96 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
98 DP_NOTICE(p_hwfn, "Failed in allocating iwarp cid\n");
101 *cid += qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
103 rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, *cid);
105 qed_iwarp_cid_cleaned(p_hwfn, *cid);
110 int qed_iwarp_create_qp(struct qed_hwfn *p_hwfn,
111 struct qed_rdma_qp *qp,
112 struct qed_rdma_create_qp_out_params *out_params)
114 struct iwarp_create_qp_ramrod_data *p_ramrod;
115 struct qed_sp_init_data init_data;
116 struct qed_spq_entry *p_ent;
121 qp->shared_queue = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
122 IWARP_SHARED_QUEUE_PAGE_SIZE,
123 &qp->shared_queue_phys_addr,
125 if (!qp->shared_queue)
128 out_params->sq_pbl_virt = (u8 *)qp->shared_queue +
129 IWARP_SHARED_QUEUE_PAGE_SQ_PBL_OFFSET;
130 out_params->sq_pbl_phys = qp->shared_queue_phys_addr +
131 IWARP_SHARED_QUEUE_PAGE_SQ_PBL_OFFSET;
132 out_params->rq_pbl_virt = (u8 *)qp->shared_queue +
133 IWARP_SHARED_QUEUE_PAGE_RQ_PBL_OFFSET;
134 out_params->rq_pbl_phys = qp->shared_queue_phys_addr +
135 IWARP_SHARED_QUEUE_PAGE_RQ_PBL_OFFSET;
137 rc = qed_iwarp_alloc_cid(p_hwfn, &cid);
143 memset(&init_data, 0, sizeof(init_data));
144 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
145 init_data.cid = qp->icid;
146 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
148 rc = qed_sp_init_request(p_hwfn, &p_ent,
149 IWARP_RAMROD_CMD_ID_CREATE_QP,
150 PROTOCOLID_IWARP, &init_data);
154 p_ramrod = &p_ent->ramrod.iwarp_create_qp;
156 SET_FIELD(p_ramrod->flags,
157 IWARP_CREATE_QP_RAMROD_DATA_FMR_AND_RESERVED_EN,
158 qp->fmr_and_reserved_lkey);
160 SET_FIELD(p_ramrod->flags,
161 IWARP_CREATE_QP_RAMROD_DATA_SIGNALED_COMP, qp->signal_all);
163 SET_FIELD(p_ramrod->flags,
164 IWARP_CREATE_QP_RAMROD_DATA_RDMA_RD_EN,
165 qp->incoming_rdma_read_en);
167 SET_FIELD(p_ramrod->flags,
168 IWARP_CREATE_QP_RAMROD_DATA_RDMA_WR_EN,
169 qp->incoming_rdma_write_en);
171 SET_FIELD(p_ramrod->flags,
172 IWARP_CREATE_QP_RAMROD_DATA_ATOMIC_EN,
173 qp->incoming_atomic_en);
175 SET_FIELD(p_ramrod->flags,
176 IWARP_CREATE_QP_RAMROD_DATA_SRQ_FLG, qp->use_srq);
178 p_ramrod->pd = qp->pd;
179 p_ramrod->sq_num_pages = qp->sq_num_pages;
180 p_ramrod->rq_num_pages = qp->rq_num_pages;
182 p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi);
183 p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo);
185 p_ramrod->cq_cid_for_sq =
186 cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->sq_cq_id);
187 p_ramrod->cq_cid_for_rq =
188 cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->rq_cq_id);
190 p_ramrod->dpi = cpu_to_le16(qp->dpi);
192 physical_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
193 p_ramrod->physical_q0 = cpu_to_le16(physical_queue);
194 physical_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK);
195 p_ramrod->physical_q1 = cpu_to_le16(physical_queue);
197 rc = qed_spq_post(p_hwfn, p_ent, NULL);
204 qed_iwarp_cid_cleaned(p_hwfn, cid);
206 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
207 IWARP_SHARED_QUEUE_PAGE_SIZE,
208 qp->shared_queue, qp->shared_queue_phys_addr);
213 static int qed_iwarp_modify_fw(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
215 struct iwarp_modify_qp_ramrod_data *p_ramrod;
216 struct qed_sp_init_data init_data;
217 struct qed_spq_entry *p_ent;
221 memset(&init_data, 0, sizeof(init_data));
222 init_data.cid = qp->icid;
223 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
224 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
226 rc = qed_sp_init_request(p_hwfn, &p_ent,
227 IWARP_RAMROD_CMD_ID_MODIFY_QP,
228 p_hwfn->p_rdma_info->proto, &init_data);
232 p_ramrod = &p_ent->ramrod.iwarp_modify_qp;
233 SET_FIELD(p_ramrod->flags, IWARP_MODIFY_QP_RAMROD_DATA_STATE_TRANS_EN,
235 if (qp->iwarp_state == QED_IWARP_QP_STATE_CLOSING)
236 p_ramrod->transition_to_state = IWARP_MODIFY_QP_STATE_CLOSING;
238 p_ramrod->transition_to_state = IWARP_MODIFY_QP_STATE_ERROR;
240 rc = qed_spq_post(p_hwfn, p_ent, NULL);
242 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x)rc=%d\n", qp->icid, rc);
247 enum qed_iwarp_qp_state qed_roce2iwarp_state(enum qed_roce_qp_state state)
250 case QED_ROCE_QP_STATE_RESET:
251 case QED_ROCE_QP_STATE_INIT:
252 case QED_ROCE_QP_STATE_RTR:
253 return QED_IWARP_QP_STATE_IDLE;
254 case QED_ROCE_QP_STATE_RTS:
255 return QED_IWARP_QP_STATE_RTS;
256 case QED_ROCE_QP_STATE_SQD:
257 return QED_IWARP_QP_STATE_CLOSING;
258 case QED_ROCE_QP_STATE_ERR:
259 return QED_IWARP_QP_STATE_ERROR;
260 case QED_ROCE_QP_STATE_SQE:
261 return QED_IWARP_QP_STATE_TERMINATE;
263 return QED_IWARP_QP_STATE_ERROR;
267 static enum qed_roce_qp_state
268 qed_iwarp2roce_state(enum qed_iwarp_qp_state state)
271 case QED_IWARP_QP_STATE_IDLE:
272 return QED_ROCE_QP_STATE_INIT;
273 case QED_IWARP_QP_STATE_RTS:
274 return QED_ROCE_QP_STATE_RTS;
275 case QED_IWARP_QP_STATE_TERMINATE:
276 return QED_ROCE_QP_STATE_SQE;
277 case QED_IWARP_QP_STATE_CLOSING:
278 return QED_ROCE_QP_STATE_SQD;
279 case QED_IWARP_QP_STATE_ERROR:
280 return QED_ROCE_QP_STATE_ERR;
282 return QED_ROCE_QP_STATE_ERR;
286 const char *iwarp_state_names[] = {
295 qed_iwarp_modify_qp(struct qed_hwfn *p_hwfn,
296 struct qed_rdma_qp *qp,
297 enum qed_iwarp_qp_state new_state, bool internal)
299 enum qed_iwarp_qp_state prev_iw_state;
300 bool modify_fw = false;
303 /* modify QP can be called from upper-layer or as a result of async
304 * RST/FIN... therefore need to protect
306 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
307 prev_iw_state = qp->iwarp_state;
309 if (prev_iw_state == new_state) {
310 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
314 switch (prev_iw_state) {
315 case QED_IWARP_QP_STATE_IDLE:
317 case QED_IWARP_QP_STATE_RTS:
318 qp->iwarp_state = QED_IWARP_QP_STATE_RTS;
320 case QED_IWARP_QP_STATE_ERROR:
321 qp->iwarp_state = QED_IWARP_QP_STATE_ERROR;
329 case QED_IWARP_QP_STATE_RTS:
331 case QED_IWARP_QP_STATE_CLOSING:
335 qp->iwarp_state = QED_IWARP_QP_STATE_CLOSING;
337 case QED_IWARP_QP_STATE_ERROR:
340 qp->iwarp_state = QED_IWARP_QP_STATE_ERROR;
346 case QED_IWARP_QP_STATE_ERROR:
348 case QED_IWARP_QP_STATE_IDLE:
350 qp->iwarp_state = new_state;
352 case QED_IWARP_QP_STATE_CLOSING:
353 /* could happen due to race... do nothing.... */
359 case QED_IWARP_QP_STATE_TERMINATE:
360 case QED_IWARP_QP_STATE_CLOSING:
361 qp->iwarp_state = new_state;
367 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) %s --> %s%s\n",
369 iwarp_state_names[prev_iw_state],
370 iwarp_state_names[qp->iwarp_state],
371 internal ? "internal" : "");
373 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
376 rc = qed_iwarp_modify_fw(p_hwfn, qp);
381 int qed_iwarp_fw_destroy(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
383 struct qed_sp_init_data init_data;
384 struct qed_spq_entry *p_ent;
388 memset(&init_data, 0, sizeof(init_data));
389 init_data.cid = qp->icid;
390 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
391 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
393 rc = qed_sp_init_request(p_hwfn, &p_ent,
394 IWARP_RAMROD_CMD_ID_DESTROY_QP,
395 p_hwfn->p_rdma_info->proto, &init_data);
399 rc = qed_spq_post(p_hwfn, p_ent, NULL);
401 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) rc = %d\n", qp->icid, rc);
406 int qed_iwarp_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
410 if (qp->iwarp_state != QED_IWARP_QP_STATE_ERROR) {
411 rc = qed_iwarp_modify_qp(p_hwfn, qp,
412 QED_IWARP_QP_STATE_ERROR, false);
417 rc = qed_iwarp_fw_destroy(p_hwfn, qp);
419 if (qp->shared_queue)
420 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
421 IWARP_SHARED_QUEUE_PAGE_SIZE,
422 qp->shared_queue, qp->shared_queue_phys_addr);
427 #define QED_IWARP_MAX_CID_CLEAN_TIME 100
428 #define QED_IWARP_MAX_NO_PROGRESS_CNT 5
430 /* This function waits for all the bits of a bmap to be cleared, as long as
431 * there is progress ( i.e. the number of bits left to be cleared decreases )
432 * the function continues.
435 qed_iwarp_wait_cid_map_cleared(struct qed_hwfn *p_hwfn, struct qed_bmap *bmap)
441 weight = bitmap_weight(bmap->bitmap, bmap->max_count);
442 prev_weight = weight;
445 msleep(QED_IWARP_MAX_CID_CLEAN_TIME);
447 weight = bitmap_weight(bmap->bitmap, bmap->max_count);
449 if (prev_weight == weight) {
452 prev_weight = weight;
456 if (wait_count > QED_IWARP_MAX_NO_PROGRESS_CNT) {
458 "%s bitmap wait timed out (%d cids pending)\n",
466 static int qed_iwarp_wait_for_all_cids(struct qed_hwfn *p_hwfn)
468 /* Now wait for all cids to be completed */
469 return qed_iwarp_wait_cid_map_cleared(p_hwfn,
470 &p_hwfn->p_rdma_info->cid_map);
473 int qed_iwarp_alloc(struct qed_hwfn *p_hwfn)
475 spin_lock_init(&p_hwfn->p_rdma_info->iwarp.iw_lock);
480 void qed_iwarp_resc_free(struct qed_hwfn *p_hwfn)
485 qed_iwarp_print_cm_info(struct qed_hwfn *p_hwfn,
486 struct qed_iwarp_cm_info *cm_info)
488 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "ip_version = %d\n",
489 cm_info->ip_version);
491 if (cm_info->ip_version == QED_TCP_IPV4)
492 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
493 "remote_ip %pI4h:%x, local_ip %pI4h:%x vlan=%x\n",
494 cm_info->remote_ip, cm_info->remote_port,
495 cm_info->local_ip, cm_info->local_port,
498 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
499 "remote_ip %pI6h:%x, local_ip %pI6h:%x vlan=%x\n",
500 cm_info->remote_ip, cm_info->remote_port,
501 cm_info->local_ip, cm_info->local_port,
504 DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
505 "private_data_len = %x ord = %d, ird = %d\n",
506 cm_info->private_data_len, cm_info->ord, cm_info->ird);
510 qed_iwarp_ll2_post_rx(struct qed_hwfn *p_hwfn,
511 struct qed_iwarp_ll2_buff *buf, u8 handle)
515 rc = qed_ll2_post_rx_buffer(p_hwfn, handle, buf->data_phys_addr,
516 (u16)buf->buff_size, buf, 1);
519 "Failed to repost rx buffer to ll2 rc = %d, handle=%d\n",
521 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buf->buff_size,
522 buf->data, buf->data_phys_addr);
529 static struct qed_iwarp_listener *
530 qed_iwarp_get_listener(struct qed_hwfn *p_hwfn,
531 struct qed_iwarp_cm_info *cm_info)
533 struct qed_iwarp_listener *listener = NULL;
534 static const u32 ip_zero[4] = { 0, 0, 0, 0 };
537 qed_iwarp_print_cm_info(p_hwfn, cm_info);
539 list_for_each_entry(listener,
540 &p_hwfn->p_rdma_info->iwarp.listen_list,
542 if (listener->port == cm_info->local_port) {
543 if (!memcmp(listener->ip_addr,
544 ip_zero, sizeof(ip_zero))) {
549 if (!memcmp(listener->ip_addr,
551 sizeof(cm_info->local_ip)) &&
552 (listener->vlan == cm_info->vlan)) {
560 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener found = %p\n",
565 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener not found\n");
570 qed_iwarp_parse_rx_pkt(struct qed_hwfn *p_hwfn,
571 struct qed_iwarp_cm_info *cm_info,
575 int *payload_len, int *tcp_start_offset)
577 struct vlan_ethhdr *vethh;
578 bool vlan_valid = false;
579 struct ipv6hdr *ip6h;
589 eth_type = ntohs(ethh->h_proto);
590 if (eth_type == ETH_P_8021Q) {
592 vethh = (struct vlan_ethhdr *)ethh;
593 cm_info->vlan = ntohs(vethh->h_vlan_TCI) & VLAN_VID_MASK;
594 eth_type = ntohs(vethh->h_vlan_encapsulated_proto);
597 eth_hlen = ETH_HLEN + (vlan_valid ? sizeof(u32) : 0);
599 memcpy(remote_mac_addr, ethh->h_source, ETH_ALEN);
601 memcpy(local_mac_addr, ethh->h_dest, ETH_ALEN);
603 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "eth_type =%d source mac: %pM\n",
604 eth_type, ethh->h_source);
606 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "eth_hlen=%d destination mac: %pM\n",
607 eth_hlen, ethh->h_dest);
609 iph = (struct iphdr *)((u8 *)(ethh) + eth_hlen);
611 if (eth_type == ETH_P_IP) {
612 cm_info->local_ip[0] = ntohl(iph->daddr);
613 cm_info->remote_ip[0] = ntohl(iph->saddr);
614 cm_info->ip_version = TCP_IPV4;
616 ip_hlen = (iph->ihl) * sizeof(u32);
617 *payload_len = ntohs(iph->tot_len) - ip_hlen;
618 } else if (eth_type == ETH_P_IPV6) {
619 ip6h = (struct ipv6hdr *)iph;
620 for (i = 0; i < 4; i++) {
621 cm_info->local_ip[i] =
622 ntohl(ip6h->daddr.in6_u.u6_addr32[i]);
623 cm_info->remote_ip[i] =
624 ntohl(ip6h->saddr.in6_u.u6_addr32[i]);
626 cm_info->ip_version = TCP_IPV6;
628 ip_hlen = sizeof(*ip6h);
629 *payload_len = ntohs(ip6h->payload_len);
631 DP_NOTICE(p_hwfn, "Unexpected ethertype on ll2 %x\n", eth_type);
635 tcph = (struct tcphdr *)((u8 *)iph + ip_hlen);
639 "Only SYN type packet expected on this ll2 conn, iph->ihl=%d source=%d dest=%d\n",
640 iph->ihl, tcph->source, tcph->dest);
644 cm_info->local_port = ntohs(tcph->dest);
645 cm_info->remote_port = ntohs(tcph->source);
647 qed_iwarp_print_cm_info(p_hwfn, cm_info);
649 *tcp_start_offset = eth_hlen + ip_hlen;
655 qed_iwarp_ll2_comp_syn_pkt(void *cxt, struct qed_ll2_comp_rx_data *data)
657 struct qed_iwarp_ll2_buff *buf = data->cookie;
658 struct qed_iwarp_listener *listener;
659 struct qed_ll2_tx_pkt_info tx_pkt;
660 struct qed_iwarp_cm_info cm_info;
661 struct qed_hwfn *p_hwfn = cxt;
662 u8 remote_mac_addr[ETH_ALEN];
663 u8 local_mac_addr[ETH_ALEN];
664 int tcp_start_offset;
669 memset(&cm_info, 0, sizeof(cm_info));
671 if (GET_FIELD(data->parse_flags,
672 PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED) &&
673 GET_FIELD(data->parse_flags, PARSING_AND_ERR_FLAGS_L4CHKSMERROR)) {
674 DP_NOTICE(p_hwfn, "Syn packet received with checksum error\n");
678 rc = qed_iwarp_parse_rx_pkt(p_hwfn, &cm_info, (u8 *)(buf->data) +
679 data->u.placement_offset, remote_mac_addr,
680 local_mac_addr, &payload_len,
685 /* Check if there is a listener for this 4-tuple+vlan */
686 ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle;
687 listener = qed_iwarp_get_listener(p_hwfn, &cm_info);
691 "SYN received on tuple not listened on parse_flags=%d packet len=%d\n",
692 data->parse_flags, data->length.packet_length);
694 memset(&tx_pkt, 0, sizeof(tx_pkt));
695 tx_pkt.num_of_bds = 1;
696 tx_pkt.vlan = data->vlan;
698 if (GET_FIELD(data->parse_flags,
699 PARSING_AND_ERR_FLAGS_TAG8021QEXIST))
700 SET_FIELD(tx_pkt.bd_flags,
701 CORE_TX_BD_DATA_VLAN_INSERTION, 1);
703 tx_pkt.l4_hdr_offset_w = (data->length.packet_length) >> 2;
704 tx_pkt.tx_dest = QED_LL2_TX_DEST_LB;
705 tx_pkt.first_frag = buf->data_phys_addr +
706 data->u.placement_offset;
707 tx_pkt.first_frag_len = data->length.packet_length;
710 rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_syn_handle,
715 "Can't post SYN back to chip rc=%d\n", rc);
721 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Received syn on listening port\n");
723 qed_iwarp_ll2_post_rx(p_hwfn, buf, ll2_syn_handle);
726 static void qed_iwarp_ll2_rel_rx_pkt(void *cxt, u8 connection_handle,
727 void *cookie, dma_addr_t rx_buf_addr,
730 struct qed_iwarp_ll2_buff *buffer = cookie;
731 struct qed_hwfn *p_hwfn = cxt;
733 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size,
734 buffer->data, buffer->data_phys_addr);
738 static void qed_iwarp_ll2_comp_tx_pkt(void *cxt, u8 connection_handle,
739 void *cookie, dma_addr_t first_frag_addr,
740 bool b_last_fragment, bool b_last_packet)
742 struct qed_iwarp_ll2_buff *buffer = cookie;
743 struct qed_hwfn *p_hwfn = cxt;
745 /* this was originally an rx packet, post it back */
746 qed_iwarp_ll2_post_rx(p_hwfn, buffer, connection_handle);
749 static void qed_iwarp_ll2_rel_tx_pkt(void *cxt, u8 connection_handle,
750 void *cookie, dma_addr_t first_frag_addr,
751 bool b_last_fragment, bool b_last_packet)
753 struct qed_iwarp_ll2_buff *buffer = cookie;
754 struct qed_hwfn *p_hwfn = cxt;
759 dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size,
760 buffer->data, buffer->data_phys_addr);
765 static int qed_iwarp_ll2_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
767 struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
770 if (iwarp_info->ll2_syn_handle != QED_IWARP_HANDLE_INVAL) {
771 rc = qed_ll2_terminate_connection(p_hwfn,
772 iwarp_info->ll2_syn_handle);
774 DP_INFO(p_hwfn, "Failed to terminate syn connection\n");
776 qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_syn_handle);
777 iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL;
780 qed_llh_remove_mac_filter(p_hwfn,
781 p_ptt, p_hwfn->p_rdma_info->iwarp.mac_addr);
786 qed_iwarp_ll2_alloc_buffers(struct qed_hwfn *p_hwfn,
787 int num_rx_bufs, int buff_size, u8 ll2_handle)
789 struct qed_iwarp_ll2_buff *buffer;
793 for (i = 0; i < num_rx_bufs; i++) {
794 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
800 buffer->data = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
802 &buffer->data_phys_addr,
810 buffer->buff_size = buff_size;
811 rc = qed_iwarp_ll2_post_rx(p_hwfn, buffer, ll2_handle);
813 /* buffers will be deallocated by qed_ll2 */
819 #define QED_IWARP_MAX_BUF_SIZE(mtu) \
820 ALIGN((mtu) + ETH_HLEN + 2 * VLAN_HLEN + 2 + ETH_CACHE_LINE_SIZE, \
824 qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn,
825 struct qed_rdma_start_in_params *params,
826 struct qed_ptt *p_ptt)
828 struct qed_iwarp_info *iwarp_info;
829 struct qed_ll2_acquire_data data;
830 struct qed_ll2_cbs cbs;
833 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
834 iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL;
836 iwarp_info->max_mtu = params->max_mtu;
838 ether_addr_copy(p_hwfn->p_rdma_info->iwarp.mac_addr, params->mac_addr);
840 rc = qed_llh_add_mac_filter(p_hwfn, p_ptt, params->mac_addr);
844 /* Start SYN connection */
845 cbs.rx_comp_cb = qed_iwarp_ll2_comp_syn_pkt;
846 cbs.rx_release_cb = qed_iwarp_ll2_rel_rx_pkt;
847 cbs.tx_comp_cb = qed_iwarp_ll2_comp_tx_pkt;
848 cbs.tx_release_cb = qed_iwarp_ll2_rel_tx_pkt;
851 memset(&data, 0, sizeof(data));
852 data.input.conn_type = QED_LL2_TYPE_IWARP;
853 data.input.mtu = QED_IWARP_MAX_SYN_PKT_SIZE;
854 data.input.rx_num_desc = QED_IWARP_LL2_SYN_RX_SIZE;
855 data.input.tx_num_desc = QED_IWARP_LL2_SYN_TX_SIZE;
856 data.input.tx_max_bds_per_packet = 1; /* will never be fragmented */
857 data.input.tx_tc = PKT_LB_TC;
858 data.input.tx_dest = QED_LL2_TX_DEST_LB;
859 data.p_connection_handle = &iwarp_info->ll2_syn_handle;
862 rc = qed_ll2_acquire_connection(p_hwfn, &data);
864 DP_NOTICE(p_hwfn, "Failed to acquire LL2 connection\n");
865 qed_llh_remove_mac_filter(p_hwfn, p_ptt, params->mac_addr);
869 rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_syn_handle);
871 DP_NOTICE(p_hwfn, "Failed to establish LL2 connection\n");
875 rc = qed_iwarp_ll2_alloc_buffers(p_hwfn,
876 QED_IWARP_LL2_SYN_RX_SIZE,
877 QED_IWARP_MAX_SYN_PKT_SIZE,
878 iwarp_info->ll2_syn_handle);
884 qed_iwarp_ll2_stop(p_hwfn, p_ptt);
889 int qed_iwarp_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
890 struct qed_rdma_start_in_params *params)
892 struct qed_iwarp_info *iwarp_info;
895 iwarp_info = &p_hwfn->p_rdma_info->iwarp;
897 iwarp_info->tcp_flags = QED_IWARP_TS_EN;
898 rcv_wnd_size = QED_IWARP_RCV_WND_SIZE_DEF;
900 /* value 0 is used for ilog2(QED_IWARP_RCV_WND_SIZE_MIN) */
901 iwarp_info->rcv_wnd_scale = ilog2(rcv_wnd_size) -
902 ilog2(QED_IWARP_RCV_WND_SIZE_MIN);
903 iwarp_info->crc_needed = QED_IWARP_PARAM_CRC_NEEDED;
904 iwarp_info->mpa_rev = MPA_NEGOTIATION_TYPE_ENHANCED;
906 iwarp_info->peer2peer = QED_IWARP_PARAM_P2P;
908 spin_lock_init(&p_hwfn->p_rdma_info->iwarp.qp_lock);
909 INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.listen_list);
911 qed_spq_register_async_cb(p_hwfn, PROTOCOLID_IWARP,
912 qed_iwarp_async_event);
914 return qed_iwarp_ll2_start(p_hwfn, params, p_ptt);
917 int qed_iwarp_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
921 rc = qed_iwarp_wait_for_all_cids(p_hwfn);
925 qed_spq_unregister_async_cb(p_hwfn, PROTOCOLID_IWARP);
927 return qed_iwarp_ll2_stop(p_hwfn, p_ptt);
930 static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn,
931 u8 fw_event_code, u16 echo,
932 union event_ring_data *data,
939 qed_iwarp_create_listen(void *rdma_cxt,
940 struct qed_iwarp_listen_in *iparams,
941 struct qed_iwarp_listen_out *oparams)
943 struct qed_hwfn *p_hwfn = rdma_cxt;
944 struct qed_iwarp_listener *listener;
946 listener = kzalloc(sizeof(*listener), GFP_KERNEL);
950 listener->ip_version = iparams->ip_version;
951 memcpy(listener->ip_addr, iparams->ip_addr, sizeof(listener->ip_addr));
952 listener->port = iparams->port;
953 listener->vlan = iparams->vlan;
955 listener->event_cb = iparams->event_cb;
956 listener->cb_context = iparams->cb_context;
957 listener->max_backlog = iparams->max_backlog;
958 oparams->handle = listener;
960 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
961 list_add_tail(&listener->list_entry,
962 &p_hwfn->p_rdma_info->iwarp.listen_list);
963 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
967 "callback=%p handle=%p ip=%x:%x:%x:%x port=0x%x vlan=0x%x\n",
970 listener->ip_addr[0],
971 listener->ip_addr[1],
972 listener->ip_addr[2],
973 listener->ip_addr[3], listener->port, listener->vlan);
978 int qed_iwarp_destroy_listen(void *rdma_cxt, void *handle)
980 struct qed_iwarp_listener *listener = handle;
981 struct qed_hwfn *p_hwfn = rdma_cxt;
983 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "handle=%p\n", handle);
985 spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
986 list_del(&listener->list_entry);
987 spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
995 qed_iwarp_query_qp(struct qed_rdma_qp *qp,
996 struct qed_rdma_query_qp_out_params *out_params)
998 out_params->state = qed_iwarp2roce_state(qp->iwarp_state);