xref: /freebsd/sys/dev/qlnx/qlnxr/qlnxr_cm.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1fa790ea9SDavid C Somayajulu /*
2fa790ea9SDavid C Somayajulu  * Copyright (c) 2018-2019 Cavium, Inc.
3fa790ea9SDavid C Somayajulu  * All rights reserved.
4fa790ea9SDavid C Somayajulu  *
5fa790ea9SDavid C Somayajulu  *  Redistribution and use in source and binary forms, with or without
6fa790ea9SDavid C Somayajulu  *  modification, are permitted provided that the following conditions
7fa790ea9SDavid C Somayajulu  *  are met:
8fa790ea9SDavid C Somayajulu  *
9fa790ea9SDavid C Somayajulu  *  1. Redistributions of source code must retain the above copyright
10fa790ea9SDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer.
11fa790ea9SDavid C Somayajulu  *  2. Redistributions in binary form must reproduce the above copyright
12fa790ea9SDavid C Somayajulu  *     notice, this list of conditions and the following disclaimer in the
13fa790ea9SDavid C Somayajulu  *     documentation and/or other materials provided with the distribution.
14fa790ea9SDavid C Somayajulu  *
15fa790ea9SDavid C Somayajulu  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16fa790ea9SDavid C Somayajulu  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17fa790ea9SDavid C Somayajulu  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18fa790ea9SDavid C Somayajulu  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19fa790ea9SDavid C Somayajulu  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20fa790ea9SDavid C Somayajulu  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21fa790ea9SDavid C Somayajulu  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22fa790ea9SDavid C Somayajulu  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23fa790ea9SDavid C Somayajulu  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24fa790ea9SDavid C Somayajulu  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25fa790ea9SDavid C Somayajulu  *  POSSIBILITY OF SUCH DAMAGE.
26fa790ea9SDavid C Somayajulu  */
27fa790ea9SDavid C Somayajulu 
28fa790ea9SDavid C Somayajulu #include <sys/cdefs.h>
29fa790ea9SDavid C Somayajulu #include "qlnxr_def.h"
30fa790ea9SDavid C Somayajulu #include "rdma_common.h"
31fa790ea9SDavid C Somayajulu #include "qlnxr_cm.h"
32fa790ea9SDavid C Somayajulu 
33fa790ea9SDavid C Somayajulu void
qlnxr_inc_sw_gsi_cons(struct qlnxr_qp_hwq_info * info)34fa790ea9SDavid C Somayajulu qlnxr_inc_sw_gsi_cons(struct qlnxr_qp_hwq_info *info)
35fa790ea9SDavid C Somayajulu {
36fa790ea9SDavid C Somayajulu 	info->gsi_cons = (info->gsi_cons + 1) % info->max_wr;
37fa790ea9SDavid C Somayajulu }
38fa790ea9SDavid C Somayajulu 
39fa790ea9SDavid C Somayajulu void
qlnxr_store_gsi_qp_cq(struct qlnxr_dev * dev,struct qlnxr_qp * qp,struct ib_qp_init_attr * attrs)40fa790ea9SDavid C Somayajulu qlnxr_store_gsi_qp_cq(struct qlnxr_dev *dev,
41fa790ea9SDavid C Somayajulu 		struct qlnxr_qp *qp,
42fa790ea9SDavid C Somayajulu 		struct ib_qp_init_attr *attrs)
43fa790ea9SDavid C Somayajulu {
44fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
45fa790ea9SDavid C Somayajulu 
46fa790ea9SDavid C Somayajulu 	dev->gsi_qp_created = 1;
47fa790ea9SDavid C Somayajulu 	dev->gsi_sqcq = get_qlnxr_cq((attrs->send_cq));
48fa790ea9SDavid C Somayajulu 	dev->gsi_rqcq = get_qlnxr_cq((attrs->recv_cq));
49fa790ea9SDavid C Somayajulu 	dev->gsi_qp = qp;
50fa790ea9SDavid C Somayajulu 
51fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit\n");
52fa790ea9SDavid C Somayajulu 
53fa790ea9SDavid C Somayajulu 	return;
54fa790ea9SDavid C Somayajulu }
55fa790ea9SDavid C Somayajulu 
56fa790ea9SDavid C Somayajulu void
qlnxr_ll2_complete_tx_packet(void * cxt,uint8_t connection_handle,void * cookie,dma_addr_t first_frag_addr,bool b_last_fragment,bool b_last_packet)57fa790ea9SDavid C Somayajulu qlnxr_ll2_complete_tx_packet(void *cxt,
58fa790ea9SDavid C Somayajulu 		uint8_t connection_handle,
59fa790ea9SDavid C Somayajulu 		void *cookie,
60fa790ea9SDavid C Somayajulu 		dma_addr_t first_frag_addr,
61fa790ea9SDavid C Somayajulu 		bool b_last_fragment,
62fa790ea9SDavid C Somayajulu 		bool b_last_packet)
63fa790ea9SDavid C Somayajulu {
64fa790ea9SDavid C Somayajulu 	struct qlnxr_dev *dev = (struct qlnxr_dev *)cxt;
65fa790ea9SDavid C Somayajulu 	struct ecore_roce_ll2_packet *pkt = cookie;
66fa790ea9SDavid C Somayajulu 	struct qlnxr_cq *cq = dev->gsi_sqcq;
67fa790ea9SDavid C Somayajulu 	struct qlnxr_qp *qp = dev->gsi_qp;
68fa790ea9SDavid C Somayajulu 	unsigned long flags;
69fa790ea9SDavid C Somayajulu 
70fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
71fa790ea9SDavid C Somayajulu 
72fa790ea9SDavid C Somayajulu 	qlnx_dma_free_coherent(&dev->ha->cdev, pkt->header.vaddr,
73fa790ea9SDavid C Somayajulu 			pkt->header.baddr, pkt->header.len);
74fa790ea9SDavid C Somayajulu 	kfree(pkt);
75fa790ea9SDavid C Somayajulu 
76fa790ea9SDavid C Somayajulu 	spin_lock_irqsave(&qp->q_lock, flags);
77fa790ea9SDavid C Somayajulu 
78fa790ea9SDavid C Somayajulu 	qlnxr_inc_sw_gsi_cons(&qp->sq);
79fa790ea9SDavid C Somayajulu 
80fa790ea9SDavid C Somayajulu 	spin_unlock_irqrestore(&qp->q_lock, flags);
81fa790ea9SDavid C Somayajulu 
82fa790ea9SDavid C Somayajulu 	if (cq->ibcq.comp_handler)
83fa790ea9SDavid C Somayajulu 		(*cq->ibcq.comp_handler) (&cq->ibcq, cq->ibcq.cq_context);
84fa790ea9SDavid C Somayajulu 
85fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit\n");
86fa790ea9SDavid C Somayajulu 
87fa790ea9SDavid C Somayajulu 	return;
88fa790ea9SDavid C Somayajulu }
89fa790ea9SDavid C Somayajulu 
90fa790ea9SDavid C Somayajulu void
qlnxr_ll2_complete_rx_packet(void * cxt,struct ecore_ll2_comp_rx_data * data)91fa790ea9SDavid C Somayajulu qlnxr_ll2_complete_rx_packet(void *cxt,
92fa790ea9SDavid C Somayajulu 		struct ecore_ll2_comp_rx_data *data)
93fa790ea9SDavid C Somayajulu {
94fa790ea9SDavid C Somayajulu 	struct qlnxr_dev *dev = (struct qlnxr_dev *)cxt;
95fa790ea9SDavid C Somayajulu 	struct qlnxr_cq *cq = dev->gsi_rqcq;
96fa790ea9SDavid C Somayajulu 	// struct qlnxr_qp *qp = dev->gsi_qp;
97fa790ea9SDavid C Somayajulu 	struct qlnxr_qp *qp = NULL;
98fa790ea9SDavid C Somayajulu 	unsigned long flags;
99fa790ea9SDavid C Somayajulu 	// uint32_t delay_count = 0, gsi_cons = 0;
100fa790ea9SDavid C Somayajulu 	//void * dest_va;
101fa790ea9SDavid C Somayajulu 
102fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
103fa790ea9SDavid C Somayajulu 
104fa790ea9SDavid C Somayajulu 	if (data->u.data_length_error) {
105fa790ea9SDavid C Somayajulu 		/* TODO: add statistic */
106fa790ea9SDavid C Somayajulu 	}
107fa790ea9SDavid C Somayajulu 
108fa790ea9SDavid C Somayajulu 	if (data->cookie == NULL) {
109fa790ea9SDavid C Somayajulu 		QL_DPRINT12(dev->ha, "cookie is NULL, bad sign\n");
110fa790ea9SDavid C Somayajulu 	}
111fa790ea9SDavid C Somayajulu 
112fa790ea9SDavid C Somayajulu 	if (data->qp_id == 1) {
113fa790ea9SDavid C Somayajulu 		qp = dev->gsi_qp;
114fa790ea9SDavid C Somayajulu 	} else {
115fa790ea9SDavid C Somayajulu 		/* TODO: This will be needed for UD QP support */
116fa790ea9SDavid C Somayajulu 		/* For RoCEv1 this is invalid */
117fa790ea9SDavid C Somayajulu 		QL_DPRINT12(dev->ha, "invalid QP\n");
118fa790ea9SDavid C Somayajulu 		return;
119fa790ea9SDavid C Somayajulu 	}
120fa790ea9SDavid C Somayajulu 	/* note: currently only one recv sg is supported */
121fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "MAD received on QP : %x\n", data->rx_buf_addr);
122fa790ea9SDavid C Somayajulu 
123fa790ea9SDavid C Somayajulu 	spin_lock_irqsave(&qp->q_lock, flags);
124fa790ea9SDavid C Somayajulu 
125fa790ea9SDavid C Somayajulu 	qp->rqe_wr_id[qp->rq.gsi_cons].rc =
126fa790ea9SDavid C Somayajulu 		data->u.data_length_error ? -EINVAL : 0;
127fa790ea9SDavid C Somayajulu 	qp->rqe_wr_id[qp->rq.gsi_cons].vlan_id = data->vlan;
128fa790ea9SDavid C Somayajulu 	/* note: length stands for data length i.e. GRH is excluded */
129fa790ea9SDavid C Somayajulu 	qp->rqe_wr_id[qp->rq.gsi_cons].sg_list[0].length =
130fa790ea9SDavid C Somayajulu 		data->length.data_length;
131fa790ea9SDavid C Somayajulu 	*((u32 *)&qp->rqe_wr_id[qp->rq.gsi_cons].smac[0]) =
132fa790ea9SDavid C Somayajulu 		ntohl(data->opaque_data_0);
133fa790ea9SDavid C Somayajulu 	*((u16 *)&qp->rqe_wr_id[qp->rq.gsi_cons].smac[4]) =
134fa790ea9SDavid C Somayajulu 		ntohs((u16)data->opaque_data_1);
135fa790ea9SDavid C Somayajulu 
136fa790ea9SDavid C Somayajulu 	qlnxr_inc_sw_gsi_cons(&qp->rq);
137fa790ea9SDavid C Somayajulu 
138fa790ea9SDavid C Somayajulu 	spin_unlock_irqrestore(&qp->q_lock, flags);
139fa790ea9SDavid C Somayajulu 
140fa790ea9SDavid C Somayajulu 	if (cq->ibcq.comp_handler)
141fa790ea9SDavid C Somayajulu 		(*cq->ibcq.comp_handler) (&cq->ibcq, cq->ibcq.cq_context);
142fa790ea9SDavid C Somayajulu 
143fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit\n");
144fa790ea9SDavid C Somayajulu 
145fa790ea9SDavid C Somayajulu 	return;
146fa790ea9SDavid C Somayajulu }
147fa790ea9SDavid C Somayajulu 
qlnxr_ll2_release_rx_packet(void * cxt,u8 connection_handle,void * cookie,dma_addr_t rx_buf_addr,bool b_last_packet)148fa790ea9SDavid C Somayajulu void qlnxr_ll2_release_rx_packet(void *cxt,
149fa790ea9SDavid C Somayajulu 		u8 connection_handle,
150fa790ea9SDavid C Somayajulu 		void *cookie,
151fa790ea9SDavid C Somayajulu 		dma_addr_t rx_buf_addr,
152fa790ea9SDavid C Somayajulu 		bool b_last_packet)
153fa790ea9SDavid C Somayajulu {
154fa790ea9SDavid C Somayajulu 	/* Do nothing... */
155fa790ea9SDavid C Somayajulu }
156fa790ea9SDavid C Somayajulu 
157fa790ea9SDavid C Somayajulu static void
qlnxr_destroy_gsi_cq(struct qlnxr_dev * dev,struct ib_qp_init_attr * attrs)158fa790ea9SDavid C Somayajulu qlnxr_destroy_gsi_cq(struct qlnxr_dev *dev,
159fa790ea9SDavid C Somayajulu 		struct ib_qp_init_attr *attrs)
160fa790ea9SDavid C Somayajulu {
161fa790ea9SDavid C Somayajulu 	struct ecore_rdma_destroy_cq_in_params iparams;
162fa790ea9SDavid C Somayajulu 	struct ecore_rdma_destroy_cq_out_params oparams;
163fa790ea9SDavid C Somayajulu 	struct qlnxr_cq *cq;
164fa790ea9SDavid C Somayajulu 
165fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
166fa790ea9SDavid C Somayajulu 
167fa790ea9SDavid C Somayajulu 	cq = get_qlnxr_cq((attrs->send_cq));
168fa790ea9SDavid C Somayajulu 	iparams.icid = cq->icid;
169fa790ea9SDavid C Somayajulu 	ecore_rdma_destroy_cq(dev->rdma_ctx, &iparams, &oparams);
170fa790ea9SDavid C Somayajulu 	ecore_chain_free(&dev->ha->cdev, &cq->pbl);
171fa790ea9SDavid C Somayajulu 
172fa790ea9SDavid C Somayajulu 	cq = get_qlnxr_cq((attrs->recv_cq));
173fa790ea9SDavid C Somayajulu 	/* if a dedicated recv_cq was used, delete it too */
174fa790ea9SDavid C Somayajulu 	if (iparams.icid != cq->icid) {
175fa790ea9SDavid C Somayajulu 		iparams.icid = cq->icid;
176fa790ea9SDavid C Somayajulu 		ecore_rdma_destroy_cq(dev->rdma_ctx, &iparams, &oparams);
177fa790ea9SDavid C Somayajulu 		ecore_chain_free(&dev->ha->cdev, &cq->pbl);
178fa790ea9SDavid C Somayajulu 	}
179fa790ea9SDavid C Somayajulu 
180fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit\n");
181fa790ea9SDavid C Somayajulu 
182fa790ea9SDavid C Somayajulu 	return;
183fa790ea9SDavid C Somayajulu }
184fa790ea9SDavid C Somayajulu 
185fa790ea9SDavid C Somayajulu static inline int
qlnxr_check_gsi_qp_attrs(struct qlnxr_dev * dev,struct ib_qp_init_attr * attrs)186fa790ea9SDavid C Somayajulu qlnxr_check_gsi_qp_attrs(struct qlnxr_dev *dev,
187fa790ea9SDavid C Somayajulu 		struct ib_qp_init_attr *attrs)
188fa790ea9SDavid C Somayajulu {
189fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
190fa790ea9SDavid C Somayajulu 
191fa790ea9SDavid C Somayajulu 	if (attrs->cap.max_recv_sge > QLNXR_GSI_MAX_RECV_SGE) {
192fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha,
193fa790ea9SDavid C Somayajulu 			"(attrs->cap.max_recv_sge > QLNXR_GSI_MAX_RECV_SGE)\n");
194fa790ea9SDavid C Somayajulu 		return -EINVAL;
195fa790ea9SDavid C Somayajulu 	}
196fa790ea9SDavid C Somayajulu 
197fa790ea9SDavid C Somayajulu 	if (attrs->cap.max_recv_wr > QLNXR_GSI_MAX_RECV_WR) {
198fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha,
199fa790ea9SDavid C Somayajulu 			"(attrs->cap.max_recv_wr > QLNXR_GSI_MAX_RECV_WR)\n");
200fa790ea9SDavid C Somayajulu 		return -EINVAL;
201fa790ea9SDavid C Somayajulu 	}
202fa790ea9SDavid C Somayajulu 
203fa790ea9SDavid C Somayajulu 	if (attrs->cap.max_send_wr > QLNXR_GSI_MAX_SEND_WR) {
204fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha,
205fa790ea9SDavid C Somayajulu 			"(attrs->cap.max_send_wr > QLNXR_GSI_MAX_SEND_WR)\n");
206fa790ea9SDavid C Somayajulu 		return -EINVAL;
207fa790ea9SDavid C Somayajulu 	}
208fa790ea9SDavid C Somayajulu 
209fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit\n");
210fa790ea9SDavid C Somayajulu 
211fa790ea9SDavid C Somayajulu 	return 0;
212fa790ea9SDavid C Somayajulu }
213fa790ea9SDavid C Somayajulu 
214fa790ea9SDavid C Somayajulu static int
qlnxr_ll2_post_tx(struct qlnxr_dev * dev,struct ecore_roce_ll2_packet * pkt)215fa790ea9SDavid C Somayajulu qlnxr_ll2_post_tx(struct qlnxr_dev *dev, struct ecore_roce_ll2_packet *pkt)
216fa790ea9SDavid C Somayajulu {
217fa790ea9SDavid C Somayajulu 	enum ecore_ll2_roce_flavor_type roce_flavor;
218fa790ea9SDavid C Somayajulu 	struct ecore_ll2_tx_pkt_info ll2_tx_pkt;
219fa790ea9SDavid C Somayajulu 	int rc;
220fa790ea9SDavid C Somayajulu 	int i;
221fa790ea9SDavid C Somayajulu 
222fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
223fa790ea9SDavid C Somayajulu 
224fa790ea9SDavid C Somayajulu 	memset(&ll2_tx_pkt, 0, sizeof(ll2_tx_pkt));
225fa790ea9SDavid C Somayajulu 
226fa790ea9SDavid C Somayajulu 	if (pkt->roce_mode != ROCE_V1) {
227fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "roce_mode != ROCE_V1\n");
228fa790ea9SDavid C Somayajulu 		return (-1);
229fa790ea9SDavid C Somayajulu 	}
230fa790ea9SDavid C Somayajulu 
231fa790ea9SDavid C Somayajulu 	roce_flavor = (pkt->roce_mode == ROCE_V1) ?
232fa790ea9SDavid C Somayajulu 		ECORE_LL2_ROCE : ECORE_LL2_RROCE;
233fa790ea9SDavid C Somayajulu 
234fa790ea9SDavid C Somayajulu 	ll2_tx_pkt.num_of_bds = 1 /* hdr */ +  pkt->n_seg;
235fa790ea9SDavid C Somayajulu 	ll2_tx_pkt.vlan = 0; /* ??? */
236fa790ea9SDavid C Somayajulu 	ll2_tx_pkt.tx_dest = ECORE_LL2_TX_DEST_NW;
237fa790ea9SDavid C Somayajulu 	ll2_tx_pkt.ecore_roce_flavor = roce_flavor;
238fa790ea9SDavid C Somayajulu 	ll2_tx_pkt.first_frag = pkt->header.baddr;
239fa790ea9SDavid C Somayajulu 	ll2_tx_pkt.first_frag_len = pkt->header.len;
240fa790ea9SDavid C Somayajulu 	ll2_tx_pkt.cookie = pkt;
241fa790ea9SDavid C Somayajulu 	ll2_tx_pkt.enable_ip_cksum = 1; // Only for RoCEv2:IPv4
242fa790ea9SDavid C Somayajulu 
243fa790ea9SDavid C Somayajulu 	/* tx header */
244fa790ea9SDavid C Somayajulu 	rc = ecore_ll2_prepare_tx_packet(dev->rdma_ctx,
245fa790ea9SDavid C Somayajulu 			dev->gsi_ll2_handle,
246fa790ea9SDavid C Somayajulu 			&ll2_tx_pkt,
247fa790ea9SDavid C Somayajulu 			1);
248fa790ea9SDavid C Somayajulu 	if (rc) {
249fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "ecore_ll2_prepare_tx_packet failed\n");
250fa790ea9SDavid C Somayajulu 
251fa790ea9SDavid C Somayajulu 		/* TX failed while posting header - release resources*/
252fa790ea9SDavid C Somayajulu                 qlnx_dma_free_coherent(&dev->ha->cdev,
253fa790ea9SDavid C Somayajulu 			pkt->header.vaddr,
254fa790ea9SDavid C Somayajulu 			pkt->header.baddr,
255fa790ea9SDavid C Somayajulu                         pkt->header.len);
256fa790ea9SDavid C Somayajulu 
257fa790ea9SDavid C Somayajulu 		kfree(pkt);
258fa790ea9SDavid C Somayajulu 
259fa790ea9SDavid C Somayajulu 		return rc;
260fa790ea9SDavid C Somayajulu 	}
261fa790ea9SDavid C Somayajulu 
262fa790ea9SDavid C Somayajulu 	/* tx payload */
263fa790ea9SDavid C Somayajulu 	for (i = 0; i < pkt->n_seg; i++) {
264fa790ea9SDavid C Somayajulu 		rc = ecore_ll2_set_fragment_of_tx_packet(dev->rdma_ctx,
265fa790ea9SDavid C Somayajulu 						       dev->gsi_ll2_handle,
266fa790ea9SDavid C Somayajulu 						       pkt->payload[i].baddr,
267fa790ea9SDavid C Somayajulu 						       pkt->payload[i].len);
268fa790ea9SDavid C Somayajulu 		if (rc) {
269fa790ea9SDavid C Somayajulu 			/* if failed not much to do here, partial packet has
270fa790ea9SDavid C Somayajulu 			 * been posted we can't free memory, will need to wait
271fa790ea9SDavid C Somayajulu 			 * for completion
272fa790ea9SDavid C Somayajulu 			 */
273fa790ea9SDavid C Somayajulu 			QL_DPRINT11(dev->ha,
274fa790ea9SDavid C Somayajulu 				"ecore_ll2_set_fragment_of_tx_packet failed\n");
275fa790ea9SDavid C Somayajulu 			return rc;
276fa790ea9SDavid C Somayajulu 		}
277fa790ea9SDavid C Somayajulu 	}
278fa790ea9SDavid C Somayajulu 	struct ecore_ll2_stats stats = {0};
279fa790ea9SDavid C Somayajulu 	rc = ecore_ll2_get_stats(dev->rdma_ctx, dev->gsi_ll2_handle, &stats);
280fa790ea9SDavid C Somayajulu 	if (rc) {
281fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "failed to obtain ll2 stats\n");
282fa790ea9SDavid C Somayajulu 	}
283fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit\n");
284fa790ea9SDavid C Somayajulu 
285fa790ea9SDavid C Somayajulu 	return 0;
286fa790ea9SDavid C Somayajulu }
287fa790ea9SDavid C Somayajulu 
288fa790ea9SDavid C Somayajulu int
qlnxr_ll2_stop(struct qlnxr_dev * dev)289fa790ea9SDavid C Somayajulu qlnxr_ll2_stop(struct qlnxr_dev *dev)
290fa790ea9SDavid C Somayajulu {
291fa790ea9SDavid C Somayajulu 	int rc;
292fa790ea9SDavid C Somayajulu 
293fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
294fa790ea9SDavid C Somayajulu 
295fa790ea9SDavid C Somayajulu 	if (dev->gsi_ll2_handle == 0xFF)
296fa790ea9SDavid C Somayajulu 		return 0;
297fa790ea9SDavid C Somayajulu 
298fa790ea9SDavid C Somayajulu 	/* remove LL2 MAC address filter */
299fa790ea9SDavid C Somayajulu 	rc = qlnx_rdma_ll2_set_mac_filter(dev->rdma_ctx,
300fa790ea9SDavid C Somayajulu 			  dev->gsi_ll2_mac_address, NULL);
301fa790ea9SDavid C Somayajulu 
302fa790ea9SDavid C Somayajulu 	rc = ecore_ll2_terminate_connection(dev->rdma_ctx,
303fa790ea9SDavid C Somayajulu 			dev->gsi_ll2_handle);
304fa790ea9SDavid C Somayajulu 
305fa790ea9SDavid C Somayajulu 	ecore_ll2_release_connection(dev->rdma_ctx, dev->gsi_ll2_handle);
306fa790ea9SDavid C Somayajulu 
307fa790ea9SDavid C Somayajulu 	dev->gsi_ll2_handle = 0xFF;
308fa790ea9SDavid C Somayajulu 
309fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit rc = %d\n", rc);
310fa790ea9SDavid C Somayajulu 	return rc;
311fa790ea9SDavid C Somayajulu }
312fa790ea9SDavid C Somayajulu 
qlnxr_ll2_start(struct qlnxr_dev * dev,struct ib_qp_init_attr * attrs,struct qlnxr_qp * qp)313fa790ea9SDavid C Somayajulu int qlnxr_ll2_start(struct qlnxr_dev *dev,
314fa790ea9SDavid C Somayajulu 		   struct ib_qp_init_attr *attrs,
315fa790ea9SDavid C Somayajulu 		   struct qlnxr_qp *qp)
316fa790ea9SDavid C Somayajulu {
317fa790ea9SDavid C Somayajulu 	struct ecore_ll2_acquire_data data;
318fa790ea9SDavid C Somayajulu 	struct ecore_ll2_cbs cbs;
319fa790ea9SDavid C Somayajulu 	int rc;
320fa790ea9SDavid C Somayajulu 
321fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
322fa790ea9SDavid C Somayajulu 
323fa790ea9SDavid C Somayajulu 	/* configure and start LL2 */
324fa790ea9SDavid C Somayajulu 	cbs.rx_comp_cb = qlnxr_ll2_complete_rx_packet;
325fa790ea9SDavid C Somayajulu 	cbs.tx_comp_cb = qlnxr_ll2_complete_tx_packet;
326fa790ea9SDavid C Somayajulu 	cbs.rx_release_cb = qlnxr_ll2_release_rx_packet;
327fa790ea9SDavid C Somayajulu 	cbs.tx_release_cb = qlnxr_ll2_complete_tx_packet;
328fa790ea9SDavid C Somayajulu 	cbs.cookie = dev;
329fa790ea9SDavid C Somayajulu 	dev->gsi_ll2_handle = 0xFF;
330fa790ea9SDavid C Somayajulu 
331fa790ea9SDavid C Somayajulu 	memset(&data, 0, sizeof(data));
332fa790ea9SDavid C Somayajulu 	data.input.conn_type = ECORE_LL2_TYPE_ROCE;
333*727bfe38SJustin Hibbits 	data.input.mtu = if_getmtu(dev->ha->ifp);
334fa790ea9SDavid C Somayajulu 	data.input.rx_num_desc = 8 * 1024;
335fa790ea9SDavid C Somayajulu 	data.input.rx_drop_ttl0_flg = 1;
336fa790ea9SDavid C Somayajulu 	data.input.rx_vlan_removal_en = 0;
337fa790ea9SDavid C Somayajulu 	data.input.tx_num_desc = 8 * 1024;
338fa790ea9SDavid C Somayajulu 	data.input.tx_tc = 0;
339fa790ea9SDavid C Somayajulu 	data.input.tx_dest = ECORE_LL2_TX_DEST_NW;
340fa790ea9SDavid C Somayajulu 	data.input.ai_err_packet_too_big = ECORE_LL2_DROP_PACKET;
341fa790ea9SDavid C Somayajulu 	data.input.ai_err_no_buf = ECORE_LL2_DROP_PACKET;
342fa790ea9SDavid C Somayajulu 	data.input.gsi_enable = 1;
343fa790ea9SDavid C Somayajulu 	data.p_connection_handle = &dev->gsi_ll2_handle;
344fa790ea9SDavid C Somayajulu 	data.cbs = &cbs;
345fa790ea9SDavid C Somayajulu 
346fa790ea9SDavid C Somayajulu 	rc = ecore_ll2_acquire_connection(dev->rdma_ctx, &data);
347fa790ea9SDavid C Somayajulu 
348fa790ea9SDavid C Somayajulu 	if (rc) {
349fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha,
350fa790ea9SDavid C Somayajulu 			"ecore_ll2_acquire_connection failed: %d\n",
351fa790ea9SDavid C Somayajulu 			rc);
352fa790ea9SDavid C Somayajulu 		return rc;
353fa790ea9SDavid C Somayajulu 	}
354fa790ea9SDavid C Somayajulu 
355fa790ea9SDavid C Somayajulu 	QL_DPRINT11(dev->ha,
356fa790ea9SDavid C Somayajulu 		"ll2 connection acquired successfully\n");
357fa790ea9SDavid C Somayajulu 	rc = ecore_ll2_establish_connection(dev->rdma_ctx,
358fa790ea9SDavid C Somayajulu 		dev->gsi_ll2_handle);
359fa790ea9SDavid C Somayajulu 
360fa790ea9SDavid C Somayajulu 	if (rc) {
361fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha,
362fa790ea9SDavid C Somayajulu 			"ecore_ll2_establish_connection failed\n", rc);
363fa790ea9SDavid C Somayajulu 		goto err1;
364fa790ea9SDavid C Somayajulu 	}
365fa790ea9SDavid C Somayajulu 
366fa790ea9SDavid C Somayajulu 	QL_DPRINT11(dev->ha,
367fa790ea9SDavid C Somayajulu 		"ll2 connection established successfully\n");
368fa790ea9SDavid C Somayajulu 	rc = qlnx_rdma_ll2_set_mac_filter(dev->rdma_ctx, NULL,
369fa790ea9SDavid C Somayajulu 			dev->ha->primary_mac);
370fa790ea9SDavid C Somayajulu 	if (rc) {
371fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "qlnx_rdma_ll2_set_mac_filter failed\n", rc);
372fa790ea9SDavid C Somayajulu 		goto err2;
373fa790ea9SDavid C Somayajulu 	}
374fa790ea9SDavid C Somayajulu 
375fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit rc = %d\n", rc);
376fa790ea9SDavid C Somayajulu 	return 0;
377fa790ea9SDavid C Somayajulu 
378fa790ea9SDavid C Somayajulu err2:
379fa790ea9SDavid C Somayajulu 	ecore_ll2_terminate_connection(dev->rdma_ctx, dev->gsi_ll2_handle);
380fa790ea9SDavid C Somayajulu err1:
381fa790ea9SDavid C Somayajulu 	ecore_ll2_release_connection(dev->rdma_ctx, dev->gsi_ll2_handle);
382fa790ea9SDavid C Somayajulu 
383fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit rc = %d\n", rc);
384fa790ea9SDavid C Somayajulu 	return rc;
385fa790ea9SDavid C Somayajulu }
386fa790ea9SDavid C Somayajulu 
387fa790ea9SDavid C Somayajulu struct ib_qp*
qlnxr_create_gsi_qp(struct qlnxr_dev * dev,struct ib_qp_init_attr * attrs,struct qlnxr_qp * qp)388fa790ea9SDavid C Somayajulu qlnxr_create_gsi_qp(struct qlnxr_dev *dev,
389fa790ea9SDavid C Somayajulu 		 struct ib_qp_init_attr *attrs,
390fa790ea9SDavid C Somayajulu 		 struct qlnxr_qp *qp)
391fa790ea9SDavid C Somayajulu {
392fa790ea9SDavid C Somayajulu 	int rc;
393fa790ea9SDavid C Somayajulu 
394fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
395fa790ea9SDavid C Somayajulu 
396fa790ea9SDavid C Somayajulu 	rc = qlnxr_check_gsi_qp_attrs(dev, attrs);
397fa790ea9SDavid C Somayajulu 
398fa790ea9SDavid C Somayajulu 	if (rc) {
399fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "qlnxr_check_gsi_qp_attrs failed\n");
400fa790ea9SDavid C Somayajulu 		return ERR_PTR(rc);
401fa790ea9SDavid C Somayajulu 	}
402fa790ea9SDavid C Somayajulu 
403fa790ea9SDavid C Somayajulu 	rc = qlnxr_ll2_start(dev, attrs, qp);
404fa790ea9SDavid C Somayajulu 	if (rc) {
405fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "qlnxr_ll2_start failed\n");
406fa790ea9SDavid C Somayajulu 		return ERR_PTR(rc);
407fa790ea9SDavid C Somayajulu 	}
408fa790ea9SDavid C Somayajulu 
409fa790ea9SDavid C Somayajulu 	/* create QP */
410fa790ea9SDavid C Somayajulu 	qp->ibqp.qp_num = 1;
411fa790ea9SDavid C Somayajulu 	qp->rq.max_wr = attrs->cap.max_recv_wr;
412fa790ea9SDavid C Somayajulu 	qp->sq.max_wr = attrs->cap.max_send_wr;
413fa790ea9SDavid C Somayajulu 
414fa790ea9SDavid C Somayajulu 	qp->rqe_wr_id = kzalloc(qp->rq.max_wr * sizeof(*qp->rqe_wr_id),
415fa790ea9SDavid C Somayajulu 				GFP_KERNEL);
416fa790ea9SDavid C Somayajulu 	if (!qp->rqe_wr_id) {
417fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "(!qp->rqe_wr_id)\n");
418fa790ea9SDavid C Somayajulu 		goto err;
419fa790ea9SDavid C Somayajulu 	}
420fa790ea9SDavid C Somayajulu 
421fa790ea9SDavid C Somayajulu 	qp->wqe_wr_id = kzalloc(qp->sq.max_wr * sizeof(*qp->wqe_wr_id),
422fa790ea9SDavid C Somayajulu 				GFP_KERNEL);
423fa790ea9SDavid C Somayajulu 	if (!qp->wqe_wr_id) {
424fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "(!qp->wqe_wr_id)\n");
425fa790ea9SDavid C Somayajulu 		goto err;
426fa790ea9SDavid C Somayajulu 	}
427fa790ea9SDavid C Somayajulu 
428fa790ea9SDavid C Somayajulu 	qlnxr_store_gsi_qp_cq(dev, qp, attrs);
429fa790ea9SDavid C Somayajulu 	memcpy(dev->gsi_ll2_mac_address, dev->ha->primary_mac, ETH_ALEN);
430fa790ea9SDavid C Somayajulu 
431fa790ea9SDavid C Somayajulu 	/* the GSI CQ is handled by the driver so remove it from the FW */
432fa790ea9SDavid C Somayajulu 	qlnxr_destroy_gsi_cq(dev, attrs);
433fa790ea9SDavid C Somayajulu 	dev->gsi_rqcq->cq_type = QLNXR_CQ_TYPE_GSI;
434fa790ea9SDavid C Somayajulu 	dev->gsi_rqcq->cq_type = QLNXR_CQ_TYPE_GSI;
435fa790ea9SDavid C Somayajulu 
436fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit &qp->ibqp = %p\n", &qp->ibqp);
437fa790ea9SDavid C Somayajulu 
438fa790ea9SDavid C Somayajulu 	return &qp->ibqp;
439fa790ea9SDavid C Somayajulu err:
440fa790ea9SDavid C Somayajulu 	kfree(qp->rqe_wr_id);
441fa790ea9SDavid C Somayajulu 
442fa790ea9SDavid C Somayajulu 	rc = qlnxr_ll2_stop(dev);
443fa790ea9SDavid C Somayajulu 
444fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit with error\n");
445fa790ea9SDavid C Somayajulu 
446fa790ea9SDavid C Somayajulu 	return ERR_PTR(-ENOMEM);
447fa790ea9SDavid C Somayajulu }
448fa790ea9SDavid C Somayajulu 
449fa790ea9SDavid C Somayajulu int
qlnxr_destroy_gsi_qp(struct qlnxr_dev * dev)450fa790ea9SDavid C Somayajulu qlnxr_destroy_gsi_qp(struct qlnxr_dev *dev)
451fa790ea9SDavid C Somayajulu {
452fa790ea9SDavid C Somayajulu 	int rc = 0;
453fa790ea9SDavid C Somayajulu 
454fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
455fa790ea9SDavid C Somayajulu 
456fa790ea9SDavid C Somayajulu 	rc = qlnxr_ll2_stop(dev);
457fa790ea9SDavid C Somayajulu 
458fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit rc = %d\n", rc);
459fa790ea9SDavid C Somayajulu 	return (rc);
460fa790ea9SDavid C Somayajulu }
461fa790ea9SDavid C Somayajulu 
462fa790ea9SDavid C Somayajulu static inline bool
qlnxr_get_vlan_id_gsi(struct ib_ah_attr * ah_attr,u16 * vlan_id)463fa790ea9SDavid C Somayajulu qlnxr_get_vlan_id_gsi(struct ib_ah_attr *ah_attr, u16 *vlan_id)
464fa790ea9SDavid C Somayajulu {
465fa790ea9SDavid C Somayajulu 	u16 tmp_vlan_id;
466fa790ea9SDavid C Somayajulu 	union ib_gid *dgid = &ah_attr->grh.dgid;
467fa790ea9SDavid C Somayajulu 
468fa790ea9SDavid C Somayajulu 	tmp_vlan_id = (dgid->raw[11] << 8) | dgid->raw[12];
469fa790ea9SDavid C Somayajulu 	if (tmp_vlan_id < 0x1000) {
470fa790ea9SDavid C Somayajulu 		*vlan_id = tmp_vlan_id;
471fa790ea9SDavid C Somayajulu 		return true;
472fa790ea9SDavid C Somayajulu 	} else {
473fa790ea9SDavid C Somayajulu 		*vlan_id = 0;
474fa790ea9SDavid C Somayajulu 		return false;
475fa790ea9SDavid C Somayajulu 	}
476fa790ea9SDavid C Somayajulu }
477fa790ea9SDavid C Somayajulu 
478fa790ea9SDavid C Somayajulu #define QLNXR_MAX_UD_HEADER_SIZE	(100)
479fa790ea9SDavid C Somayajulu #define QLNXR_GSI_QPN		(1)
480fa790ea9SDavid C Somayajulu static inline int
qlnxr_gsi_build_header(struct qlnxr_dev * dev,struct qlnxr_qp * qp,const struct ib_send_wr * swr,struct ib_ud_header * udh,int * roce_mode)481fa790ea9SDavid C Somayajulu qlnxr_gsi_build_header(struct qlnxr_dev *dev,
482fa790ea9SDavid C Somayajulu 		struct qlnxr_qp *qp,
483c3987b8eSHans Petter Selasky 		const struct ib_send_wr *swr,
484fa790ea9SDavid C Somayajulu 		struct ib_ud_header *udh,
485fa790ea9SDavid C Somayajulu 		int *roce_mode)
486fa790ea9SDavid C Somayajulu {
487fa790ea9SDavid C Somayajulu 	bool has_vlan = false, has_grh_ipv6 = true;
488fa790ea9SDavid C Somayajulu 	struct ib_ah_attr *ah_attr = &get_qlnxr_ah((ud_wr(swr)->ah))->attr;
489fa790ea9SDavid C Somayajulu 	struct ib_global_route *grh = &ah_attr->grh;
490fa790ea9SDavid C Somayajulu 	union ib_gid sgid;
491fa790ea9SDavid C Somayajulu 	int send_size = 0;
492fa790ea9SDavid C Somayajulu 	u16 vlan_id = 0;
493fa790ea9SDavid C Somayajulu 	u16 ether_type;
494fa790ea9SDavid C Somayajulu 
495fa790ea9SDavid C Somayajulu 	int rc = 0;
496fa790ea9SDavid C Somayajulu 	int ip_ver = 0;
497fa790ea9SDavid C Somayajulu 	bool has_udp = false;
498fa790ea9SDavid C Somayajulu 
499fa790ea9SDavid C Somayajulu 	int i;
500fa790ea9SDavid C Somayajulu 
501fa790ea9SDavid C Somayajulu 	send_size = 0;
502fa790ea9SDavid C Somayajulu 	for (i = 0; i < swr->num_sge; ++i)
503fa790ea9SDavid C Somayajulu 		send_size += swr->sg_list[i].length;
504fa790ea9SDavid C Somayajulu 
505fa790ea9SDavid C Somayajulu 	has_vlan = qlnxr_get_vlan_id_gsi(ah_attr, &vlan_id);
506fa790ea9SDavid C Somayajulu 	ether_type = ETH_P_ROCE;
507fa790ea9SDavid C Somayajulu 	*roce_mode = ROCE_V1;
508fa790ea9SDavid C Somayajulu 	if (grh->sgid_index < QLNXR_MAX_SGID)
509fa790ea9SDavid C Somayajulu 		sgid = dev->sgid_tbl[grh->sgid_index];
510fa790ea9SDavid C Somayajulu 	else
511fa790ea9SDavid C Somayajulu 		sgid = dev->sgid_tbl[0];
512fa790ea9SDavid C Somayajulu 
513fa790ea9SDavid C Somayajulu 	rc = ib_ud_header_init(send_size, false /* LRH */, true /* ETH */,
514fa790ea9SDavid C Somayajulu 			has_vlan, has_grh_ipv6, ip_ver, has_udp,
515fa790ea9SDavid C Somayajulu 			0 /* immediate */, udh);
516fa790ea9SDavid C Somayajulu 
517fa790ea9SDavid C Somayajulu 	if (rc) {
518fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "gsi post send: failed to init header\n");
519fa790ea9SDavid C Somayajulu 		return rc;
520fa790ea9SDavid C Somayajulu 	}
521fa790ea9SDavid C Somayajulu 
522fa790ea9SDavid C Somayajulu 	/* ENET + VLAN headers*/
523fa790ea9SDavid C Somayajulu 	memcpy(udh->eth.dmac_h, ah_attr->dmac, ETH_ALEN);
524fa790ea9SDavid C Somayajulu 	memcpy(udh->eth.smac_h, dev->ha->primary_mac, ETH_ALEN);
525fa790ea9SDavid C Somayajulu 	if (has_vlan) {
526fa790ea9SDavid C Somayajulu 		udh->eth.type = htons(ETH_P_8021Q);
527fa790ea9SDavid C Somayajulu 		udh->vlan.tag = htons(vlan_id);
528fa790ea9SDavid C Somayajulu 		udh->vlan.type = htons(ether_type);
529fa790ea9SDavid C Somayajulu 	} else {
530fa790ea9SDavid C Somayajulu 		udh->eth.type = htons(ether_type);
531fa790ea9SDavid C Somayajulu 	}
532fa790ea9SDavid C Somayajulu 
533fa790ea9SDavid C Somayajulu 	for (int j = 0; j < 4; j++) {
534fa790ea9SDavid C Somayajulu 		QL_DPRINT12(dev->ha, "destination mac: %x\n",
535fa790ea9SDavid C Somayajulu 				udh->eth.dmac_h[j]);
536fa790ea9SDavid C Somayajulu 	}
537fa790ea9SDavid C Somayajulu 	for (int j = 0; j < 4; j++) {
538fa790ea9SDavid C Somayajulu 		QL_DPRINT12(dev->ha, "source mac: %x\n",
539fa790ea9SDavid C Somayajulu 				udh->eth.smac_h[j]);
540fa790ea9SDavid C Somayajulu 	}
541fa790ea9SDavid C Somayajulu 
542fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "QP: %p, opcode: %d, wq: %lx, roce: %x, hops:%d,"
543fa790ea9SDavid C Somayajulu 			"imm : %d, vlan :%d, AH: %p\n",
544fa790ea9SDavid C Somayajulu 			qp, swr->opcode, swr->wr_id, *roce_mode, grh->hop_limit,
545fa790ea9SDavid C Somayajulu 			0, has_vlan, get_qlnxr_ah((ud_wr(swr)->ah)));
546fa790ea9SDavid C Somayajulu 
547fa790ea9SDavid C Somayajulu 	if (has_grh_ipv6) {
548fa790ea9SDavid C Somayajulu 		/* GRH / IPv6 header */
549fa790ea9SDavid C Somayajulu 		udh->grh.traffic_class = grh->traffic_class;
550fa790ea9SDavid C Somayajulu 		udh->grh.flow_label = grh->flow_label;
551fa790ea9SDavid C Somayajulu 		udh->grh.hop_limit = grh->hop_limit;
552fa790ea9SDavid C Somayajulu 		udh->grh.destination_gid = grh->dgid;
553fa790ea9SDavid C Somayajulu 		memcpy(&udh->grh.source_gid.raw, &sgid.raw,
554fa790ea9SDavid C Somayajulu 		       sizeof(udh->grh.source_gid.raw));
555fa790ea9SDavid C Somayajulu 		QL_DPRINT12(dev->ha, "header: tc: %x, flow_label : %x, "
556fa790ea9SDavid C Somayajulu 			"hop_limit: %x \n", udh->grh.traffic_class,
557fa790ea9SDavid C Somayajulu 			udh->grh.flow_label, udh->grh.hop_limit);
558fa790ea9SDavid C Somayajulu 		for (i = 0; i < 16; i++) {
559fa790ea9SDavid C Somayajulu 			QL_DPRINT12(dev->ha, "udh dgid = %x\n", udh->grh.destination_gid.raw[i]);
560fa790ea9SDavid C Somayajulu 		}
561fa790ea9SDavid C Somayajulu 		for (i = 0; i < 16; i++) {
562fa790ea9SDavid C Somayajulu 			QL_DPRINT12(dev->ha, "udh sgid = %x\n", udh->grh.source_gid.raw[i]);
563fa790ea9SDavid C Somayajulu 		}
564fa790ea9SDavid C Somayajulu 		udh->grh.next_header = 0x1b;
565fa790ea9SDavid C Somayajulu 	}
566fa790ea9SDavid C Somayajulu #ifdef DEFINE_IB_UD_HEADER_INIT_UDP_PRESENT
567fa790ea9SDavid C Somayajulu         /* This is for RoCEv2 */
568fa790ea9SDavid C Somayajulu 	else {
569fa790ea9SDavid C Somayajulu                 /* IPv4 header */
570fa790ea9SDavid C Somayajulu                 u32 ipv4_addr;
571fa790ea9SDavid C Somayajulu 
572fa790ea9SDavid C Somayajulu                 udh->ip4.protocol = IPPROTO_UDP;
573fa790ea9SDavid C Somayajulu                 udh->ip4.tos = htonl(grh->flow_label);
574fa790ea9SDavid C Somayajulu                 udh->ip4.frag_off = htons(IP_DF);
575fa790ea9SDavid C Somayajulu                 udh->ip4.ttl = grh->hop_limit;
576fa790ea9SDavid C Somayajulu 
577fa790ea9SDavid C Somayajulu                 ipv4_addr = qedr_get_ipv4_from_gid(sgid.raw);
578fa790ea9SDavid C Somayajulu                 udh->ip4.saddr = ipv4_addr;
579fa790ea9SDavid C Somayajulu                 ipv4_addr = qedr_get_ipv4_from_gid(grh->dgid.raw);
580fa790ea9SDavid C Somayajulu                 udh->ip4.daddr = ipv4_addr;
581fa790ea9SDavid C Somayajulu                 /* note: checksum is calculated by the device */
582fa790ea9SDavid C Somayajulu         }
583fa790ea9SDavid C Somayajulu #endif
584fa790ea9SDavid C Somayajulu 
585fa790ea9SDavid C Somayajulu 	/* BTH */
586fa790ea9SDavid C Somayajulu 	udh->bth.solicited_event = !!(swr->send_flags & IB_SEND_SOLICITED);
587fa790ea9SDavid C Somayajulu 	udh->bth.pkey = QLNXR_ROCE_PKEY_DEFAULT;/* TODO: ib_get_cahced_pkey?! */
588fa790ea9SDavid C Somayajulu 	//udh->bth.destination_qpn = htonl(ud_wr(swr)->remote_qpn);
589fa790ea9SDavid C Somayajulu 	udh->bth.destination_qpn = OSAL_CPU_TO_BE32(ud_wr(swr)->remote_qpn);
590fa790ea9SDavid C Somayajulu 	//udh->bth.psn = htonl((qp->sq_psn++) & ((1 << 24) - 1));
591fa790ea9SDavid C Somayajulu 	udh->bth.psn = OSAL_CPU_TO_BE32((qp->sq_psn++) & ((1 << 24) - 1));
592fa790ea9SDavid C Somayajulu 	udh->bth.opcode = IB_OPCODE_UD_SEND_ONLY;
593fa790ea9SDavid C Somayajulu 
594fa790ea9SDavid C Somayajulu 	/* DETH */
595fa790ea9SDavid C Somayajulu 	//udh->deth.qkey = htonl(0x80010000); /* qp->qkey */ /* TODO: what is?! */
596fa790ea9SDavid C Somayajulu 	//udh->deth.source_qpn = htonl(QLNXR_GSI_QPN);
597fa790ea9SDavid C Somayajulu 	udh->deth.qkey = OSAL_CPU_TO_BE32(0x80010000); /* qp->qkey */ /* TODO: what is?! */
598fa790ea9SDavid C Somayajulu 	udh->deth.source_qpn = OSAL_CPU_TO_BE32(QLNXR_GSI_QPN);
599fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit\n");
600fa790ea9SDavid C Somayajulu 	return 0;
601fa790ea9SDavid C Somayajulu }
602fa790ea9SDavid C Somayajulu 
603fa790ea9SDavid C Somayajulu static inline int
qlnxr_gsi_build_packet(struct qlnxr_dev * dev,struct qlnxr_qp * qp,const struct ib_send_wr * swr,struct ecore_roce_ll2_packet ** p_packet)604fa790ea9SDavid C Somayajulu qlnxr_gsi_build_packet(struct qlnxr_dev *dev,
605c3987b8eSHans Petter Selasky 	struct qlnxr_qp *qp, const struct ib_send_wr *swr,
606fa790ea9SDavid C Somayajulu 	struct ecore_roce_ll2_packet **p_packet)
607fa790ea9SDavid C Somayajulu {
608fa790ea9SDavid C Somayajulu 	u8 ud_header_buffer[QLNXR_MAX_UD_HEADER_SIZE];
609fa790ea9SDavid C Somayajulu 	struct ecore_roce_ll2_packet *packet;
610fa790ea9SDavid C Somayajulu 	int roce_mode, header_size;
611fa790ea9SDavid C Somayajulu 	struct ib_ud_header udh;
612fa790ea9SDavid C Somayajulu 	int i, rc;
613fa790ea9SDavid C Somayajulu 
614fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
615fa790ea9SDavid C Somayajulu 
616fa790ea9SDavid C Somayajulu 	*p_packet = NULL;
617fa790ea9SDavid C Somayajulu 
618fa790ea9SDavid C Somayajulu 	rc = qlnxr_gsi_build_header(dev, qp, swr, &udh, &roce_mode);
619fa790ea9SDavid C Somayajulu 	if (rc) {
620fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha,
621fa790ea9SDavid C Somayajulu 			"qlnxr_gsi_build_header failed rc = %d\n", rc);
622fa790ea9SDavid C Somayajulu 		return rc;
623fa790ea9SDavid C Somayajulu 	}
624fa790ea9SDavid C Somayajulu 
625fa790ea9SDavid C Somayajulu 	header_size = ib_ud_header_pack(&udh, &ud_header_buffer);
626fa790ea9SDavid C Somayajulu 
627fa790ea9SDavid C Somayajulu 	packet = kzalloc(sizeof(*packet), GFP_ATOMIC);
628fa790ea9SDavid C Somayajulu 	if (!packet) {
629fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "packet == NULL\n");
630fa790ea9SDavid C Somayajulu 		return -ENOMEM;
631fa790ea9SDavid C Somayajulu 	}
632fa790ea9SDavid C Somayajulu 
633fa790ea9SDavid C Somayajulu 	packet->header.vaddr = qlnx_dma_alloc_coherent(&dev->ha->cdev,
634fa790ea9SDavid C Somayajulu 					&packet->header.baddr,
635fa790ea9SDavid C Somayajulu 					header_size);
636fa790ea9SDavid C Somayajulu 	if (!packet->header.vaddr) {
637fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "packet->header.vaddr == NULL\n");
638fa790ea9SDavid C Somayajulu 		kfree(packet);
639fa790ea9SDavid C Somayajulu 		return -ENOMEM;
640fa790ea9SDavid C Somayajulu 	}
641fa790ea9SDavid C Somayajulu 
642fa790ea9SDavid C Somayajulu 	if (memcmp(udh.eth.smac_h, udh.eth.dmac_h, ETH_ALEN))
643fa790ea9SDavid C Somayajulu 		packet->tx_dest = ECORE_ROCE_LL2_TX_DEST_NW;
644fa790ea9SDavid C Somayajulu 	else
645fa790ea9SDavid C Somayajulu 		packet->tx_dest = ECORE_ROCE_LL2_TX_DEST_LB;
646fa790ea9SDavid C Somayajulu 
647fa790ea9SDavid C Somayajulu 	packet->roce_mode = roce_mode;
648fa790ea9SDavid C Somayajulu 	memcpy(packet->header.vaddr, ud_header_buffer, header_size);
649fa790ea9SDavid C Somayajulu 	packet->header.len = header_size;
650fa790ea9SDavid C Somayajulu 	packet->n_seg = swr->num_sge;
651fa790ea9SDavid C Somayajulu 	qp->wqe_wr_id[qp->sq.prod].bytes_len = IB_GRH_BYTES; //RDMA_GRH_BYTES
652fa790ea9SDavid C Somayajulu 	for (i = 0; i < packet->n_seg; i++) {
653fa790ea9SDavid C Somayajulu 		packet->payload[i].baddr = swr->sg_list[i].addr;
654fa790ea9SDavid C Somayajulu 		packet->payload[i].len = swr->sg_list[i].length;
655fa790ea9SDavid C Somayajulu 		qp->wqe_wr_id[qp->sq.prod].bytes_len +=
656fa790ea9SDavid C Somayajulu 			packet->payload[i].len;
657fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "baddr: %p, len: %d\n",
658fa790ea9SDavid C Somayajulu 				packet->payload[i].baddr,
659fa790ea9SDavid C Somayajulu 				packet->payload[i].len);
660fa790ea9SDavid C Somayajulu 	}
661fa790ea9SDavid C Somayajulu 
662fa790ea9SDavid C Somayajulu 	*p_packet = packet;
663fa790ea9SDavid C Somayajulu 
664fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit, packet->n_seg: %d\n", packet->n_seg);
665fa790ea9SDavid C Somayajulu 	return 0;
666fa790ea9SDavid C Somayajulu }
667fa790ea9SDavid C Somayajulu 
668fa790ea9SDavid C Somayajulu int
qlnxr_gsi_post_send(struct ib_qp * ibqp,const struct ib_send_wr * wr,const struct ib_send_wr ** bad_wr)669fa790ea9SDavid C Somayajulu qlnxr_gsi_post_send(struct ib_qp *ibqp,
670c3987b8eSHans Petter Selasky 		const struct ib_send_wr *wr,
671c3987b8eSHans Petter Selasky 		const struct ib_send_wr **bad_wr)
672fa790ea9SDavid C Somayajulu {
673fa790ea9SDavid C Somayajulu 	struct ecore_roce_ll2_packet *pkt = NULL;
674fa790ea9SDavid C Somayajulu 	struct qlnxr_qp *qp = get_qlnxr_qp(ibqp);
675fa790ea9SDavid C Somayajulu 	struct qlnxr_dev *dev = qp->dev;
676fa790ea9SDavid C Somayajulu 	unsigned long flags;
677fa790ea9SDavid C Somayajulu 	int rc;
678fa790ea9SDavid C Somayajulu 
679fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit\n");
680fa790ea9SDavid C Somayajulu 
681fa790ea9SDavid C Somayajulu 	if (qp->state != ECORE_ROCE_QP_STATE_RTS) {
682fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha,
683fa790ea9SDavid C Somayajulu 			"(qp->state != ECORE_ROCE_QP_STATE_RTS)\n");
684fa790ea9SDavid C Somayajulu 		*bad_wr = wr;
685fa790ea9SDavid C Somayajulu 		return -EINVAL;
686fa790ea9SDavid C Somayajulu 	}
687fa790ea9SDavid C Somayajulu 
688fa790ea9SDavid C Somayajulu 	if (wr->num_sge > RDMA_MAX_SGE_PER_SQ_WQE) {
689fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha,
690fa790ea9SDavid C Somayajulu 			"(wr->num_sge > RDMA_MAX_SGE_PER_SQ_WQE)\n");
691fa790ea9SDavid C Somayajulu 		rc = -EINVAL;
692fa790ea9SDavid C Somayajulu 		goto err;
693fa790ea9SDavid C Somayajulu 	}
694fa790ea9SDavid C Somayajulu 
695fa790ea9SDavid C Somayajulu 	if (wr->opcode != IB_WR_SEND) {
696fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "(wr->opcode > IB_WR_SEND)\n");
697fa790ea9SDavid C Somayajulu 		rc = -EINVAL;
698fa790ea9SDavid C Somayajulu 		goto err;
699fa790ea9SDavid C Somayajulu 	}
700fa790ea9SDavid C Somayajulu 
701fa790ea9SDavid C Somayajulu 	spin_lock_irqsave(&qp->q_lock, flags);
702fa790ea9SDavid C Somayajulu 
703fa790ea9SDavid C Somayajulu 	rc = qlnxr_gsi_build_packet(dev, qp, wr, &pkt);
704fa790ea9SDavid C Somayajulu 	if(rc) {
705fa790ea9SDavid C Somayajulu 		spin_unlock_irqrestore(&qp->q_lock, flags);
706fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "qlnxr_gsi_build_packet failed\n");
707fa790ea9SDavid C Somayajulu 		goto err;
708fa790ea9SDavid C Somayajulu 	}
709fa790ea9SDavid C Somayajulu 
710fa790ea9SDavid C Somayajulu 	rc = qlnxr_ll2_post_tx(dev, pkt);
711fa790ea9SDavid C Somayajulu 
712fa790ea9SDavid C Somayajulu 	if (!rc) {
713fa790ea9SDavid C Somayajulu 		qp->wqe_wr_id[qp->sq.prod].wr_id = wr->wr_id;
714fa790ea9SDavid C Somayajulu 		qp->wqe_wr_id[qp->sq.prod].signaled =
715fa790ea9SDavid C Somayajulu 			!!(wr->send_flags & IB_SEND_SIGNALED);
716fa790ea9SDavid C Somayajulu 		qp->wqe_wr_id[qp->sq.prod].opcode = IB_WC_SEND;
717fa790ea9SDavid C Somayajulu 		qlnxr_inc_sw_prod(&qp->sq);
718fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "packet sent over gsi qp\n");
719fa790ea9SDavid C Somayajulu 	} else {
720fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "qlnxr_ll2_post_tx failed\n");
721fa790ea9SDavid C Somayajulu 		rc = -EAGAIN;
722fa790ea9SDavid C Somayajulu 		*bad_wr = wr;
723fa790ea9SDavid C Somayajulu 	}
724fa790ea9SDavid C Somayajulu 
725fa790ea9SDavid C Somayajulu 	spin_unlock_irqrestore(&qp->q_lock, flags);
726fa790ea9SDavid C Somayajulu 
727fa790ea9SDavid C Somayajulu 	if (wr->next != NULL) {
728fa790ea9SDavid C Somayajulu 		*bad_wr = wr->next;
729fa790ea9SDavid C Somayajulu 		rc=-EINVAL;
730fa790ea9SDavid C Somayajulu 	}
731fa790ea9SDavid C Somayajulu 
732fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit\n");
733fa790ea9SDavid C Somayajulu 	return rc;
734fa790ea9SDavid C Somayajulu 
735fa790ea9SDavid C Somayajulu err:
736fa790ea9SDavid C Somayajulu 	*bad_wr = wr;
737fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit error\n");
738fa790ea9SDavid C Somayajulu 	return rc;
739fa790ea9SDavid C Somayajulu }
740fa790ea9SDavid C Somayajulu 
741fa790ea9SDavid C Somayajulu #define	QLNXR_LL2_RX_BUFFER_SIZE	(4 * 1024)
742fa790ea9SDavid C Somayajulu int
qlnxr_gsi_post_recv(struct ib_qp * ibqp,const struct ib_recv_wr * wr,const struct ib_recv_wr ** bad_wr)743fa790ea9SDavid C Somayajulu qlnxr_gsi_post_recv(struct ib_qp *ibqp,
744c3987b8eSHans Petter Selasky 		const struct ib_recv_wr *wr,
745c3987b8eSHans Petter Selasky 		const struct ib_recv_wr **bad_wr)
746fa790ea9SDavid C Somayajulu {
747fa790ea9SDavid C Somayajulu 	struct qlnxr_dev *dev = get_qlnxr_dev((ibqp->device));
748fa790ea9SDavid C Somayajulu 	struct qlnxr_qp *qp = get_qlnxr_qp(ibqp);
749fa790ea9SDavid C Somayajulu 	unsigned long flags;
750fa790ea9SDavid C Somayajulu 	int rc = 0;
751fa790ea9SDavid C Somayajulu 
752fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter, wr: %p\n", wr);
753fa790ea9SDavid C Somayajulu 
754fa790ea9SDavid C Somayajulu 	if ((qp->state != ECORE_ROCE_QP_STATE_RTR) &&
755fa790ea9SDavid C Somayajulu 	    (qp->state != ECORE_ROCE_QP_STATE_RTS)) {
756fa790ea9SDavid C Somayajulu 		*bad_wr = wr;
757fa790ea9SDavid C Somayajulu 		QL_DPRINT11(dev->ha, "exit 0\n");
758fa790ea9SDavid C Somayajulu 		return -EINVAL;
759fa790ea9SDavid C Somayajulu 	}
760fa790ea9SDavid C Somayajulu 
761fa790ea9SDavid C Somayajulu 	spin_lock_irqsave(&qp->q_lock, flags);
762fa790ea9SDavid C Somayajulu 
763fa790ea9SDavid C Somayajulu 	while (wr) {
764fa790ea9SDavid C Somayajulu 		if (wr->num_sge > QLNXR_GSI_MAX_RECV_SGE) {
765fa790ea9SDavid C Somayajulu 			QL_DPRINT11(dev->ha, "exit 1\n");
766fa790ea9SDavid C Somayajulu 			goto err;
767fa790ea9SDavid C Somayajulu 		}
768fa790ea9SDavid C Somayajulu 
769fa790ea9SDavid C Somayajulu 		rc = ecore_ll2_post_rx_buffer(dev->rdma_ctx,
770fa790ea9SDavid C Somayajulu 				dev->gsi_ll2_handle,
771fa790ea9SDavid C Somayajulu 				wr->sg_list[0].addr,
772fa790ea9SDavid C Somayajulu 				wr->sg_list[0].length,
773fa790ea9SDavid C Somayajulu 				0 /* cookie */,
774fa790ea9SDavid C Somayajulu 				1 /* notify_fw */);
775fa790ea9SDavid C Somayajulu 		if (rc) {
776fa790ea9SDavid C Somayajulu 			QL_DPRINT11(dev->ha, "exit 2\n");
777fa790ea9SDavid C Somayajulu 			goto err;
778fa790ea9SDavid C Somayajulu 		}
779fa790ea9SDavid C Somayajulu 
780fa790ea9SDavid C Somayajulu 		memset(&qp->rqe_wr_id[qp->rq.prod], 0,
781fa790ea9SDavid C Somayajulu 			sizeof(qp->rqe_wr_id[qp->rq.prod]));
782fa790ea9SDavid C Somayajulu 		qp->rqe_wr_id[qp->rq.prod].sg_list[0] = wr->sg_list[0];
783fa790ea9SDavid C Somayajulu 		qp->rqe_wr_id[qp->rq.prod].wr_id = wr->wr_id;
784fa790ea9SDavid C Somayajulu 
785fa790ea9SDavid C Somayajulu 		qlnxr_inc_sw_prod(&qp->rq);
786fa790ea9SDavid C Somayajulu 
787fa790ea9SDavid C Somayajulu 		wr = wr->next;
788fa790ea9SDavid C Somayajulu 	}
789fa790ea9SDavid C Somayajulu 
790fa790ea9SDavid C Somayajulu 	spin_unlock_irqrestore(&qp->q_lock, flags);
791fa790ea9SDavid C Somayajulu 
792fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit rc = %d\n", rc);
793fa790ea9SDavid C Somayajulu 	return rc;
794fa790ea9SDavid C Somayajulu err:
795fa790ea9SDavid C Somayajulu 
796fa790ea9SDavid C Somayajulu 	spin_unlock_irqrestore(&qp->q_lock, flags);
797fa790ea9SDavid C Somayajulu 	*bad_wr = wr;
798fa790ea9SDavid C Somayajulu 
799fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit with -ENOMEM\n");
800fa790ea9SDavid C Somayajulu 	return -ENOMEM;
801fa790ea9SDavid C Somayajulu }
802fa790ea9SDavid C Somayajulu 
803fa790ea9SDavid C Somayajulu int
qlnxr_gsi_poll_cq(struct ib_cq * ibcq,int num_entries,struct ib_wc * wc)804fa790ea9SDavid C Somayajulu qlnxr_gsi_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)
805fa790ea9SDavid C Somayajulu {
806fa790ea9SDavid C Somayajulu 	struct qlnxr_dev *dev = get_qlnxr_dev((ibcq->device));
807fa790ea9SDavid C Somayajulu 	struct qlnxr_cq *cq = get_qlnxr_cq(ibcq);
808fa790ea9SDavid C Somayajulu 	struct qlnxr_qp *qp = dev->gsi_qp;
809fa790ea9SDavid C Somayajulu 	unsigned long flags;
810fa790ea9SDavid C Somayajulu 	int i = 0;
811fa790ea9SDavid C Somayajulu 
812fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "enter\n");
813fa790ea9SDavid C Somayajulu 
814fa790ea9SDavid C Somayajulu 	spin_lock_irqsave(&cq->cq_lock, flags);
815fa790ea9SDavid C Somayajulu 
816fa790ea9SDavid C Somayajulu 	while (i < num_entries && qp->rq.cons != qp->rq.gsi_cons) {
817fa790ea9SDavid C Somayajulu 		memset(&wc[i], 0, sizeof(*wc));
818fa790ea9SDavid C Somayajulu 
819fa790ea9SDavid C Somayajulu 		wc[i].qp = &qp->ibqp;
820fa790ea9SDavid C Somayajulu 		wc[i].wr_id = qp->rqe_wr_id[qp->rq.cons].wr_id;
821fa790ea9SDavid C Somayajulu 		wc[i].opcode = IB_WC_RECV;
822fa790ea9SDavid C Somayajulu 		wc[i].pkey_index = 0;
823fa790ea9SDavid C Somayajulu 		wc[i].status = (qp->rqe_wr_id[qp->rq.cons].rc)?
824fa790ea9SDavid C Somayajulu 			       IB_WC_GENERAL_ERR:IB_WC_SUCCESS;
825fa790ea9SDavid C Somayajulu 		/* 0 - currently only one recv sg is supported */
826fa790ea9SDavid C Somayajulu 		wc[i].byte_len = qp->rqe_wr_id[qp->rq.cons].sg_list[0].length;
827fa790ea9SDavid C Somayajulu 		wc[i].wc_flags |= IB_WC_GRH | IB_WC_IP_CSUM_OK;
828fa790ea9SDavid C Somayajulu 
829fa790ea9SDavid C Somayajulu 		memcpy(&wc[i].smac, qp->rqe_wr_id[qp->rq.cons].smac, ETH_ALEN);
830fa790ea9SDavid C Somayajulu 		wc[i].wc_flags |= IB_WC_WITH_SMAC;
831fa790ea9SDavid C Somayajulu 
832fa790ea9SDavid C Somayajulu 		if (qp->rqe_wr_id[qp->rq.cons].vlan_id) {
833fa790ea9SDavid C Somayajulu 			wc[i].wc_flags |= IB_WC_WITH_VLAN;
834fa790ea9SDavid C Somayajulu 			wc[i].vlan_id = qp->rqe_wr_id[qp->rq.cons].vlan_id;
835fa790ea9SDavid C Somayajulu 		}
836fa790ea9SDavid C Somayajulu 
837fa790ea9SDavid C Somayajulu 		qlnxr_inc_sw_cons(&qp->rq);
838fa790ea9SDavid C Somayajulu 		i++;
839fa790ea9SDavid C Somayajulu 	}
840fa790ea9SDavid C Somayajulu 
841fa790ea9SDavid C Somayajulu 	while (i < num_entries && qp->sq.cons != qp->sq.gsi_cons) {
842fa790ea9SDavid C Somayajulu 		memset(&wc[i], 0, sizeof(*wc));
843fa790ea9SDavid C Somayajulu 
844fa790ea9SDavid C Somayajulu 		wc[i].qp = &qp->ibqp;
845fa790ea9SDavid C Somayajulu 		wc[i].wr_id = qp->wqe_wr_id[qp->sq.cons].wr_id;
846fa790ea9SDavid C Somayajulu 		wc[i].opcode = IB_WC_SEND;
847fa790ea9SDavid C Somayajulu 		wc[i].status = IB_WC_SUCCESS;
848fa790ea9SDavid C Somayajulu 
849fa790ea9SDavid C Somayajulu 		qlnxr_inc_sw_cons(&qp->sq);
850fa790ea9SDavid C Somayajulu 		i++;
851fa790ea9SDavid C Somayajulu 	}
852fa790ea9SDavid C Somayajulu 
853fa790ea9SDavid C Somayajulu 	spin_unlock_irqrestore(&cq->cq_lock, flags);
854fa790ea9SDavid C Somayajulu 
855fa790ea9SDavid C Somayajulu 	QL_DPRINT12(dev->ha, "exit i = %d\n", i);
856fa790ea9SDavid C Somayajulu 	return i;
857fa790ea9SDavid C Somayajulu }
858