1*3ec648c6SKrzysztof Kozlowski // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2551c46edSMustafa Ismail /* Copyright (c) 2015 - 2021 Intel Corporation */
3551c46edSMustafa Ismail #include "osdep.h"
4551c46edSMustafa Ismail #include "defs.h"
5551c46edSMustafa Ismail #include "user.h"
6551c46edSMustafa Ismail #include "irdma.h"
7551c46edSMustafa Ismail
8551c46edSMustafa Ismail /**
9551c46edSMustafa Ismail * irdma_set_fragment - set fragment in wqe
10551c46edSMustafa Ismail * @wqe: wqe for setting fragment
11551c46edSMustafa Ismail * @offset: offset value
12551c46edSMustafa Ismail * @sge: sge length and stag
13551c46edSMustafa Ismail * @valid: The wqe valid
14551c46edSMustafa Ismail */
irdma_set_fragment(__le64 * wqe,u32 offset,struct ib_sge * sge,u8 valid)159ed8110cSZhu Yanjun static void irdma_set_fragment(__le64 *wqe, u32 offset, struct ib_sge *sge,
16551c46edSMustafa Ismail u8 valid)
17551c46edSMustafa Ismail {
18551c46edSMustafa Ismail if (sge) {
19551c46edSMustafa Ismail set_64bit_val(wqe, offset,
209ed8110cSZhu Yanjun FIELD_PREP(IRDMAQPSQ_FRAG_TO, sge->addr));
21551c46edSMustafa Ismail set_64bit_val(wqe, offset + 8,
22551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, valid) |
239ed8110cSZhu Yanjun FIELD_PREP(IRDMAQPSQ_FRAG_LEN, sge->length) |
249ed8110cSZhu Yanjun FIELD_PREP(IRDMAQPSQ_FRAG_STAG, sge->lkey));
25551c46edSMustafa Ismail } else {
26551c46edSMustafa Ismail set_64bit_val(wqe, offset, 0);
27551c46edSMustafa Ismail set_64bit_val(wqe, offset + 8,
28551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, valid));
29551c46edSMustafa Ismail }
30551c46edSMustafa Ismail }
31551c46edSMustafa Ismail
32551c46edSMustafa Ismail /**
33551c46edSMustafa Ismail * irdma_set_fragment_gen_1 - set fragment in wqe
34551c46edSMustafa Ismail * @wqe: wqe for setting fragment
35551c46edSMustafa Ismail * @offset: offset value
36551c46edSMustafa Ismail * @sge: sge length and stag
37551c46edSMustafa Ismail * @valid: wqe valid flag
38551c46edSMustafa Ismail */
irdma_set_fragment_gen_1(__le64 * wqe,u32 offset,struct ib_sge * sge,u8 valid)39551c46edSMustafa Ismail static void irdma_set_fragment_gen_1(__le64 *wqe, u32 offset,
409ed8110cSZhu Yanjun struct ib_sge *sge, u8 valid)
41551c46edSMustafa Ismail {
42551c46edSMustafa Ismail if (sge) {
43551c46edSMustafa Ismail set_64bit_val(wqe, offset,
449ed8110cSZhu Yanjun FIELD_PREP(IRDMAQPSQ_FRAG_TO, sge->addr));
45551c46edSMustafa Ismail set_64bit_val(wqe, offset + 8,
469ed8110cSZhu Yanjun FIELD_PREP(IRDMAQPSQ_GEN1_FRAG_LEN, sge->length) |
479ed8110cSZhu Yanjun FIELD_PREP(IRDMAQPSQ_GEN1_FRAG_STAG, sge->lkey));
48551c46edSMustafa Ismail } else {
49551c46edSMustafa Ismail set_64bit_val(wqe, offset, 0);
50551c46edSMustafa Ismail set_64bit_val(wqe, offset + 8, 0);
51551c46edSMustafa Ismail }
52551c46edSMustafa Ismail }
53551c46edSMustafa Ismail
54551c46edSMustafa Ismail /**
55551c46edSMustafa Ismail * irdma_nop_1 - insert a NOP wqe
56551c46edSMustafa Ismail * @qp: hw qp ptr
57551c46edSMustafa Ismail */
irdma_nop_1(struct irdma_qp_uk * qp)582c4b14eaSShiraz Saleem static int irdma_nop_1(struct irdma_qp_uk *qp)
59551c46edSMustafa Ismail {
60551c46edSMustafa Ismail u64 hdr;
61551c46edSMustafa Ismail __le64 *wqe;
62551c46edSMustafa Ismail u32 wqe_idx;
63551c46edSMustafa Ismail bool signaled = false;
64551c46edSMustafa Ismail
65551c46edSMustafa Ismail if (!qp->sq_ring.head)
662c4b14eaSShiraz Saleem return -EINVAL;
67551c46edSMustafa Ismail
68551c46edSMustafa Ismail wqe_idx = IRDMA_RING_CURRENT_HEAD(qp->sq_ring);
69551c46edSMustafa Ismail wqe = qp->sq_base[wqe_idx].elem;
70551c46edSMustafa Ismail
71551c46edSMustafa Ismail qp->sq_wrtrk_array[wqe_idx].quanta = IRDMA_QP_WQE_MIN_QUANTA;
72551c46edSMustafa Ismail
73551c46edSMustafa Ismail set_64bit_val(wqe, 0, 0);
74551c46edSMustafa Ismail set_64bit_val(wqe, 8, 0);
75551c46edSMustafa Ismail set_64bit_val(wqe, 16, 0);
76551c46edSMustafa Ismail
77551c46edSMustafa Ismail hdr = FIELD_PREP(IRDMAQPSQ_OPCODE, IRDMAQP_OP_NOP) |
78551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_SIGCOMPL, signaled) |
79551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, qp->swqe_polarity);
80551c46edSMustafa Ismail
81551c46edSMustafa Ismail /* make sure WQE is written before valid bit is set */
82551c46edSMustafa Ismail dma_wmb();
83551c46edSMustafa Ismail
84551c46edSMustafa Ismail set_64bit_val(wqe, 24, hdr);
85551c46edSMustafa Ismail
86551c46edSMustafa Ismail return 0;
87551c46edSMustafa Ismail }
88551c46edSMustafa Ismail
89551c46edSMustafa Ismail /**
90551c46edSMustafa Ismail * irdma_clr_wqes - clear next 128 sq entries
91551c46edSMustafa Ismail * @qp: hw qp ptr
92551c46edSMustafa Ismail * @qp_wqe_idx: wqe_idx
93551c46edSMustafa Ismail */
irdma_clr_wqes(struct irdma_qp_uk * qp,u32 qp_wqe_idx)94551c46edSMustafa Ismail void irdma_clr_wqes(struct irdma_qp_uk *qp, u32 qp_wqe_idx)
95551c46edSMustafa Ismail {
96b002760fSArnd Bergmann struct irdma_qp_quanta *sq;
97551c46edSMustafa Ismail u32 wqe_idx;
98551c46edSMustafa Ismail
99551c46edSMustafa Ismail if (!(qp_wqe_idx & 0x7F)) {
100551c46edSMustafa Ismail wqe_idx = (qp_wqe_idx + 128) % qp->sq_ring.size;
101b002760fSArnd Bergmann sq = qp->sq_base + wqe_idx;
102551c46edSMustafa Ismail if (wqe_idx)
103b002760fSArnd Bergmann memset(sq, qp->swqe_polarity ? 0 : 0xFF,
104b002760fSArnd Bergmann 128 * sizeof(*sq));
105551c46edSMustafa Ismail else
106b002760fSArnd Bergmann memset(sq, qp->swqe_polarity ? 0xFF : 0,
107b002760fSArnd Bergmann 128 * sizeof(*sq));
108551c46edSMustafa Ismail }
109551c46edSMustafa Ismail }
110551c46edSMustafa Ismail
111551c46edSMustafa Ismail /**
112551c46edSMustafa Ismail * irdma_uk_qp_post_wr - ring doorbell
113551c46edSMustafa Ismail * @qp: hw qp ptr
114551c46edSMustafa Ismail */
irdma_uk_qp_post_wr(struct irdma_qp_uk * qp)115551c46edSMustafa Ismail void irdma_uk_qp_post_wr(struct irdma_qp_uk *qp)
116551c46edSMustafa Ismail {
117551c46edSMustafa Ismail u64 temp;
118551c46edSMustafa Ismail u32 hw_sq_tail;
119551c46edSMustafa Ismail u32 sw_sq_head;
120551c46edSMustafa Ismail
121551c46edSMustafa Ismail /* valid bit is written and loads completed before reading shadow */
122551c46edSMustafa Ismail mb();
123551c46edSMustafa Ismail
124551c46edSMustafa Ismail /* read the doorbell shadow area */
125551c46edSMustafa Ismail get_64bit_val(qp->shadow_area, 0, &temp);
126551c46edSMustafa Ismail
127551c46edSMustafa Ismail hw_sq_tail = (u32)FIELD_GET(IRDMA_QP_DBSA_HW_SQ_TAIL, temp);
128551c46edSMustafa Ismail sw_sq_head = IRDMA_RING_CURRENT_HEAD(qp->sq_ring);
129551c46edSMustafa Ismail if (sw_sq_head != qp->initial_ring.head) {
130295c95aaSShiraz Saleem if (sw_sq_head != hw_sq_tail) {
131551c46edSMustafa Ismail if (sw_sq_head > qp->initial_ring.head) {
132551c46edSMustafa Ismail if (hw_sq_tail >= qp->initial_ring.head &&
133551c46edSMustafa Ismail hw_sq_tail < sw_sq_head)
134551c46edSMustafa Ismail writel(qp->qp_id, qp->wqe_alloc_db);
135551c46edSMustafa Ismail } else {
136551c46edSMustafa Ismail if (hw_sq_tail >= qp->initial_ring.head ||
137551c46edSMustafa Ismail hw_sq_tail < sw_sq_head)
138551c46edSMustafa Ismail writel(qp->qp_id, qp->wqe_alloc_db);
139551c46edSMustafa Ismail }
140551c46edSMustafa Ismail }
141551c46edSMustafa Ismail }
142551c46edSMustafa Ismail
143551c46edSMustafa Ismail qp->initial_ring.head = qp->sq_ring.head;
144551c46edSMustafa Ismail }
145551c46edSMustafa Ismail
146551c46edSMustafa Ismail /**
147551c46edSMustafa Ismail * irdma_qp_get_next_send_wqe - pad with NOP if needed, return where next WR should go
148551c46edSMustafa Ismail * @qp: hw qp ptr
149551c46edSMustafa Ismail * @wqe_idx: return wqe index
150551c46edSMustafa Ismail * @quanta: size of WR in quanta
151551c46edSMustafa Ismail * @total_size: size of WR in bytes
152551c46edSMustafa Ismail * @info: info on WR
153551c46edSMustafa Ismail */
irdma_qp_get_next_send_wqe(struct irdma_qp_uk * qp,u32 * wqe_idx,u16 quanta,u32 total_size,struct irdma_post_sq_info * info)154551c46edSMustafa Ismail __le64 *irdma_qp_get_next_send_wqe(struct irdma_qp_uk *qp, u32 *wqe_idx,
155551c46edSMustafa Ismail u16 quanta, u32 total_size,
156551c46edSMustafa Ismail struct irdma_post_sq_info *info)
157551c46edSMustafa Ismail {
158551c46edSMustafa Ismail __le64 *wqe;
159551c46edSMustafa Ismail __le64 *wqe_0 = NULL;
160551c46edSMustafa Ismail u16 avail_quanta;
161551c46edSMustafa Ismail u16 i;
162551c46edSMustafa Ismail
163551c46edSMustafa Ismail avail_quanta = qp->uk_attrs->max_hw_sq_chunk -
164551c46edSMustafa Ismail (IRDMA_RING_CURRENT_HEAD(qp->sq_ring) %
165551c46edSMustafa Ismail qp->uk_attrs->max_hw_sq_chunk);
166551c46edSMustafa Ismail if (quanta <= avail_quanta) {
167551c46edSMustafa Ismail /* WR fits in current chunk */
168551c46edSMustafa Ismail if (quanta > IRDMA_SQ_RING_FREE_QUANTA(qp->sq_ring))
169551c46edSMustafa Ismail return NULL;
170551c46edSMustafa Ismail } else {
171551c46edSMustafa Ismail /* Need to pad with NOP */
172551c46edSMustafa Ismail if (quanta + avail_quanta >
173551c46edSMustafa Ismail IRDMA_SQ_RING_FREE_QUANTA(qp->sq_ring))
174551c46edSMustafa Ismail return NULL;
175551c46edSMustafa Ismail
176551c46edSMustafa Ismail for (i = 0; i < avail_quanta; i++) {
177551c46edSMustafa Ismail irdma_nop_1(qp);
178551c46edSMustafa Ismail IRDMA_RING_MOVE_HEAD_NOCHECK(qp->sq_ring);
179551c46edSMustafa Ismail }
180551c46edSMustafa Ismail }
181551c46edSMustafa Ismail
182551c46edSMustafa Ismail *wqe_idx = IRDMA_RING_CURRENT_HEAD(qp->sq_ring);
183551c46edSMustafa Ismail if (!*wqe_idx)
184551c46edSMustafa Ismail qp->swqe_polarity = !qp->swqe_polarity;
185551c46edSMustafa Ismail
186551c46edSMustafa Ismail IRDMA_RING_MOVE_HEAD_BY_COUNT_NOCHECK(qp->sq_ring, quanta);
187551c46edSMustafa Ismail
188551c46edSMustafa Ismail wqe = qp->sq_base[*wqe_idx].elem;
189551c46edSMustafa Ismail if (qp->uk_attrs->hw_rev == IRDMA_GEN_1 && quanta == 1 &&
190551c46edSMustafa Ismail (IRDMA_RING_CURRENT_HEAD(qp->sq_ring) & 1)) {
191551c46edSMustafa Ismail wqe_0 = qp->sq_base[IRDMA_RING_CURRENT_HEAD(qp->sq_ring)].elem;
192551c46edSMustafa Ismail wqe_0[3] = cpu_to_le64(FIELD_PREP(IRDMAQPSQ_VALID, qp->swqe_polarity ? 0 : 1));
193551c46edSMustafa Ismail }
194551c46edSMustafa Ismail qp->sq_wrtrk_array[*wqe_idx].wrid = info->wr_id;
195551c46edSMustafa Ismail qp->sq_wrtrk_array[*wqe_idx].wr_len = total_size;
196551c46edSMustafa Ismail qp->sq_wrtrk_array[*wqe_idx].quanta = quanta;
197551c46edSMustafa Ismail
198551c46edSMustafa Ismail return wqe;
199551c46edSMustafa Ismail }
200551c46edSMustafa Ismail
201551c46edSMustafa Ismail /**
202551c46edSMustafa Ismail * irdma_qp_get_next_recv_wqe - get next qp's rcv wqe
203551c46edSMustafa Ismail * @qp: hw qp ptr
204551c46edSMustafa Ismail * @wqe_idx: return wqe index
205551c46edSMustafa Ismail */
irdma_qp_get_next_recv_wqe(struct irdma_qp_uk * qp,u32 * wqe_idx)206551c46edSMustafa Ismail __le64 *irdma_qp_get_next_recv_wqe(struct irdma_qp_uk *qp, u32 *wqe_idx)
207551c46edSMustafa Ismail {
208551c46edSMustafa Ismail __le64 *wqe;
2092c4b14eaSShiraz Saleem int ret_code;
210551c46edSMustafa Ismail
211551c46edSMustafa Ismail if (IRDMA_RING_FULL_ERR(qp->rq_ring))
212551c46edSMustafa Ismail return NULL;
213551c46edSMustafa Ismail
214551c46edSMustafa Ismail IRDMA_ATOMIC_RING_MOVE_HEAD(qp->rq_ring, *wqe_idx, ret_code);
215551c46edSMustafa Ismail if (ret_code)
216551c46edSMustafa Ismail return NULL;
217551c46edSMustafa Ismail
218551c46edSMustafa Ismail if (!*wqe_idx)
219551c46edSMustafa Ismail qp->rwqe_polarity = !qp->rwqe_polarity;
220551c46edSMustafa Ismail /* rq_wqe_size_multiplier is no of 32 byte quanta in one rq wqe */
221551c46edSMustafa Ismail wqe = qp->rq_base[*wqe_idx * qp->rq_wqe_size_multiplier].elem;
222551c46edSMustafa Ismail
223551c46edSMustafa Ismail return wqe;
224551c46edSMustafa Ismail }
225551c46edSMustafa Ismail
226551c46edSMustafa Ismail /**
227551c46edSMustafa Ismail * irdma_uk_rdma_write - rdma write operation
228551c46edSMustafa Ismail * @qp: hw qp ptr
229551c46edSMustafa Ismail * @info: post sq information
230551c46edSMustafa Ismail * @post_sq: flag to post sq
231551c46edSMustafa Ismail */
irdma_uk_rdma_write(struct irdma_qp_uk * qp,struct irdma_post_sq_info * info,bool post_sq)2322c4b14eaSShiraz Saleem int irdma_uk_rdma_write(struct irdma_qp_uk *qp, struct irdma_post_sq_info *info,
233551c46edSMustafa Ismail bool post_sq)
234551c46edSMustafa Ismail {
235551c46edSMustafa Ismail u64 hdr;
236551c46edSMustafa Ismail __le64 *wqe;
237551c46edSMustafa Ismail struct irdma_rdma_write *op_info;
238551c46edSMustafa Ismail u32 i, wqe_idx;
239551c46edSMustafa Ismail u32 total_size = 0, byte_off;
2402c4b14eaSShiraz Saleem int ret_code;
241551c46edSMustafa Ismail u32 frag_cnt, addl_frag_cnt;
242551c46edSMustafa Ismail bool read_fence = false;
243551c46edSMustafa Ismail u16 quanta;
244551c46edSMustafa Ismail
245551c46edSMustafa Ismail op_info = &info->op.rdma_write;
246551c46edSMustafa Ismail if (op_info->num_lo_sges > qp->max_sq_frag_cnt)
2472c4b14eaSShiraz Saleem return -EINVAL;
248551c46edSMustafa Ismail
249551c46edSMustafa Ismail for (i = 0; i < op_info->num_lo_sges; i++)
2509ed8110cSZhu Yanjun total_size += op_info->lo_sg_list[i].length;
251551c46edSMustafa Ismail
252551c46edSMustafa Ismail read_fence |= info->read_fence;
253551c46edSMustafa Ismail
254551c46edSMustafa Ismail if (info->imm_data_valid)
255551c46edSMustafa Ismail frag_cnt = op_info->num_lo_sges + 1;
256551c46edSMustafa Ismail else
257551c46edSMustafa Ismail frag_cnt = op_info->num_lo_sges;
258551c46edSMustafa Ismail addl_frag_cnt = frag_cnt > 1 ? (frag_cnt - 1) : 0;
259551c46edSMustafa Ismail ret_code = irdma_fragcnt_to_quanta_sq(frag_cnt, &quanta);
260551c46edSMustafa Ismail if (ret_code)
261551c46edSMustafa Ismail return ret_code;
262551c46edSMustafa Ismail
263551c46edSMustafa Ismail wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, quanta, total_size,
264551c46edSMustafa Ismail info);
265551c46edSMustafa Ismail if (!wqe)
2662c4b14eaSShiraz Saleem return -ENOMEM;
267551c46edSMustafa Ismail
268551c46edSMustafa Ismail irdma_clr_wqes(qp, wqe_idx);
269551c46edSMustafa Ismail
270551c46edSMustafa Ismail set_64bit_val(wqe, 16,
2719ed8110cSZhu Yanjun FIELD_PREP(IRDMAQPSQ_FRAG_TO, op_info->rem_addr.addr));
272551c46edSMustafa Ismail
273551c46edSMustafa Ismail if (info->imm_data_valid) {
274551c46edSMustafa Ismail set_64bit_val(wqe, 0,
275551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_IMMDATA, info->imm_data));
276551c46edSMustafa Ismail i = 0;
277551c46edSMustafa Ismail } else {
278551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, 0,
279551c46edSMustafa Ismail op_info->lo_sg_list,
280551c46edSMustafa Ismail qp->swqe_polarity);
281551c46edSMustafa Ismail i = 1;
282551c46edSMustafa Ismail }
283551c46edSMustafa Ismail
284551c46edSMustafa Ismail for (byte_off = 32; i < op_info->num_lo_sges; i++) {
285551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, byte_off,
286551c46edSMustafa Ismail &op_info->lo_sg_list[i],
287551c46edSMustafa Ismail qp->swqe_polarity);
288551c46edSMustafa Ismail byte_off += 16;
289551c46edSMustafa Ismail }
290551c46edSMustafa Ismail
291551c46edSMustafa Ismail /* if not an odd number set valid bit in next fragment */
292551c46edSMustafa Ismail if (qp->uk_attrs->hw_rev >= IRDMA_GEN_2 && !(frag_cnt & 0x01) &&
293551c46edSMustafa Ismail frag_cnt) {
294551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, byte_off, NULL,
295551c46edSMustafa Ismail qp->swqe_polarity);
296551c46edSMustafa Ismail if (qp->uk_attrs->hw_rev == IRDMA_GEN_2)
297551c46edSMustafa Ismail ++addl_frag_cnt;
298551c46edSMustafa Ismail }
299551c46edSMustafa Ismail
3009ed8110cSZhu Yanjun hdr = FIELD_PREP(IRDMAQPSQ_REMSTAG, op_info->rem_addr.lkey) |
301551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_OPCODE, info->op_type) |
302551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_IMMDATAFLAG, info->imm_data_valid) |
303551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_REPORTRTT, info->report_rtt) |
304551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_ADDFRAGCNT, addl_frag_cnt) |
305551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_READFENCE, read_fence) |
306551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_LOCALFENCE, info->local_fence) |
307551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_SIGCOMPL, info->signaled) |
308551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, qp->swqe_polarity);
309551c46edSMustafa Ismail
310551c46edSMustafa Ismail dma_wmb(); /* make sure WQE is populated before valid bit is set */
311551c46edSMustafa Ismail
312551c46edSMustafa Ismail set_64bit_val(wqe, 24, hdr);
313295c95aaSShiraz Saleem
314551c46edSMustafa Ismail if (post_sq)
315551c46edSMustafa Ismail irdma_uk_qp_post_wr(qp);
316551c46edSMustafa Ismail
317551c46edSMustafa Ismail return 0;
318551c46edSMustafa Ismail }
319551c46edSMustafa Ismail
320551c46edSMustafa Ismail /**
321551c46edSMustafa Ismail * irdma_uk_rdma_read - rdma read command
322551c46edSMustafa Ismail * @qp: hw qp ptr
323551c46edSMustafa Ismail * @info: post sq information
324551c46edSMustafa Ismail * @inv_stag: flag for inv_stag
325551c46edSMustafa Ismail * @post_sq: flag to post sq
326551c46edSMustafa Ismail */
irdma_uk_rdma_read(struct irdma_qp_uk * qp,struct irdma_post_sq_info * info,bool inv_stag,bool post_sq)3272c4b14eaSShiraz Saleem int irdma_uk_rdma_read(struct irdma_qp_uk *qp, struct irdma_post_sq_info *info,
328551c46edSMustafa Ismail bool inv_stag, bool post_sq)
329551c46edSMustafa Ismail {
330551c46edSMustafa Ismail struct irdma_rdma_read *op_info;
3312c4b14eaSShiraz Saleem int ret_code;
332551c46edSMustafa Ismail u32 i, byte_off, total_size = 0;
333551c46edSMustafa Ismail bool local_fence = false;
334551c46edSMustafa Ismail u32 addl_frag_cnt;
335551c46edSMustafa Ismail __le64 *wqe;
336551c46edSMustafa Ismail u32 wqe_idx;
337551c46edSMustafa Ismail u16 quanta;
338551c46edSMustafa Ismail u64 hdr;
339551c46edSMustafa Ismail
340551c46edSMustafa Ismail op_info = &info->op.rdma_read;
341551c46edSMustafa Ismail if (qp->max_sq_frag_cnt < op_info->num_lo_sges)
3422c4b14eaSShiraz Saleem return -EINVAL;
343551c46edSMustafa Ismail
344551c46edSMustafa Ismail for (i = 0; i < op_info->num_lo_sges; i++)
3459ed8110cSZhu Yanjun total_size += op_info->lo_sg_list[i].length;
346551c46edSMustafa Ismail
347551c46edSMustafa Ismail ret_code = irdma_fragcnt_to_quanta_sq(op_info->num_lo_sges, &quanta);
348551c46edSMustafa Ismail if (ret_code)
349551c46edSMustafa Ismail return ret_code;
350551c46edSMustafa Ismail
351551c46edSMustafa Ismail wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, quanta, total_size,
352551c46edSMustafa Ismail info);
353551c46edSMustafa Ismail if (!wqe)
3542c4b14eaSShiraz Saleem return -ENOMEM;
355551c46edSMustafa Ismail
356551c46edSMustafa Ismail irdma_clr_wqes(qp, wqe_idx);
357551c46edSMustafa Ismail
358551c46edSMustafa Ismail addl_frag_cnt = op_info->num_lo_sges > 1 ?
359551c46edSMustafa Ismail (op_info->num_lo_sges - 1) : 0;
360551c46edSMustafa Ismail local_fence |= info->local_fence;
361551c46edSMustafa Ismail
362551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, 0, op_info->lo_sg_list,
363551c46edSMustafa Ismail qp->swqe_polarity);
364551c46edSMustafa Ismail for (i = 1, byte_off = 32; i < op_info->num_lo_sges; ++i) {
365551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, byte_off,
366551c46edSMustafa Ismail &op_info->lo_sg_list[i],
367551c46edSMustafa Ismail qp->swqe_polarity);
368551c46edSMustafa Ismail byte_off += 16;
369551c46edSMustafa Ismail }
370551c46edSMustafa Ismail
371551c46edSMustafa Ismail /* if not an odd number set valid bit in next fragment */
372551c46edSMustafa Ismail if (qp->uk_attrs->hw_rev >= IRDMA_GEN_2 &&
373551c46edSMustafa Ismail !(op_info->num_lo_sges & 0x01) && op_info->num_lo_sges) {
374551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, byte_off, NULL,
375551c46edSMustafa Ismail qp->swqe_polarity);
376551c46edSMustafa Ismail if (qp->uk_attrs->hw_rev == IRDMA_GEN_2)
377551c46edSMustafa Ismail ++addl_frag_cnt;
378551c46edSMustafa Ismail }
379551c46edSMustafa Ismail set_64bit_val(wqe, 16,
3809ed8110cSZhu Yanjun FIELD_PREP(IRDMAQPSQ_FRAG_TO, op_info->rem_addr.addr));
3819ed8110cSZhu Yanjun hdr = FIELD_PREP(IRDMAQPSQ_REMSTAG, op_info->rem_addr.lkey) |
382551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_REPORTRTT, (info->report_rtt ? 1 : 0)) |
383551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_ADDFRAGCNT, addl_frag_cnt) |
384551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_OPCODE,
385551c46edSMustafa Ismail (inv_stag ? IRDMAQP_OP_RDMA_READ_LOC_INV : IRDMAQP_OP_RDMA_READ)) |
386551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_READFENCE, info->read_fence) |
387551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_LOCALFENCE, local_fence) |
388551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_SIGCOMPL, info->signaled) |
389551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, qp->swqe_polarity);
390551c46edSMustafa Ismail
391551c46edSMustafa Ismail dma_wmb(); /* make sure WQE is populated before valid bit is set */
392551c46edSMustafa Ismail
393551c46edSMustafa Ismail set_64bit_val(wqe, 24, hdr);
394295c95aaSShiraz Saleem
395551c46edSMustafa Ismail if (post_sq)
396551c46edSMustafa Ismail irdma_uk_qp_post_wr(qp);
397551c46edSMustafa Ismail
398551c46edSMustafa Ismail return 0;
399551c46edSMustafa Ismail }
400551c46edSMustafa Ismail
401551c46edSMustafa Ismail /**
402551c46edSMustafa Ismail * irdma_uk_send - rdma send command
403551c46edSMustafa Ismail * @qp: hw qp ptr
404551c46edSMustafa Ismail * @info: post sq information
405551c46edSMustafa Ismail * @post_sq: flag to post sq
406551c46edSMustafa Ismail */
irdma_uk_send(struct irdma_qp_uk * qp,struct irdma_post_sq_info * info,bool post_sq)4072c4b14eaSShiraz Saleem int irdma_uk_send(struct irdma_qp_uk *qp, struct irdma_post_sq_info *info,
408551c46edSMustafa Ismail bool post_sq)
409551c46edSMustafa Ismail {
410551c46edSMustafa Ismail __le64 *wqe;
411551c46edSMustafa Ismail struct irdma_post_send *op_info;
412551c46edSMustafa Ismail u64 hdr;
413551c46edSMustafa Ismail u32 i, wqe_idx, total_size = 0, byte_off;
4142c4b14eaSShiraz Saleem int ret_code;
415551c46edSMustafa Ismail u32 frag_cnt, addl_frag_cnt;
416551c46edSMustafa Ismail bool read_fence = false;
417551c46edSMustafa Ismail u16 quanta;
418551c46edSMustafa Ismail
419551c46edSMustafa Ismail op_info = &info->op.send;
420551c46edSMustafa Ismail if (qp->max_sq_frag_cnt < op_info->num_sges)
4212c4b14eaSShiraz Saleem return -EINVAL;
422551c46edSMustafa Ismail
423551c46edSMustafa Ismail for (i = 0; i < op_info->num_sges; i++)
4249ed8110cSZhu Yanjun total_size += op_info->sg_list[i].length;
425551c46edSMustafa Ismail
426551c46edSMustafa Ismail if (info->imm_data_valid)
427551c46edSMustafa Ismail frag_cnt = op_info->num_sges + 1;
428551c46edSMustafa Ismail else
429551c46edSMustafa Ismail frag_cnt = op_info->num_sges;
430551c46edSMustafa Ismail ret_code = irdma_fragcnt_to_quanta_sq(frag_cnt, &quanta);
431551c46edSMustafa Ismail if (ret_code)
432551c46edSMustafa Ismail return ret_code;
433551c46edSMustafa Ismail
434551c46edSMustafa Ismail wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, quanta, total_size,
435551c46edSMustafa Ismail info);
436551c46edSMustafa Ismail if (!wqe)
4372c4b14eaSShiraz Saleem return -ENOMEM;
438551c46edSMustafa Ismail
439551c46edSMustafa Ismail irdma_clr_wqes(qp, wqe_idx);
440551c46edSMustafa Ismail
441551c46edSMustafa Ismail read_fence |= info->read_fence;
442551c46edSMustafa Ismail addl_frag_cnt = frag_cnt > 1 ? (frag_cnt - 1) : 0;
443551c46edSMustafa Ismail if (info->imm_data_valid) {
444551c46edSMustafa Ismail set_64bit_val(wqe, 0,
445551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_IMMDATA, info->imm_data));
446551c46edSMustafa Ismail i = 0;
447551c46edSMustafa Ismail } else {
4482c884443SSindhu-Devale qp->wqe_ops.iw_set_fragment(wqe, 0,
4492c884443SSindhu-Devale frag_cnt ? op_info->sg_list : NULL,
450551c46edSMustafa Ismail qp->swqe_polarity);
451551c46edSMustafa Ismail i = 1;
452551c46edSMustafa Ismail }
453551c46edSMustafa Ismail
454551c46edSMustafa Ismail for (byte_off = 32; i < op_info->num_sges; i++) {
455551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, byte_off, &op_info->sg_list[i],
456551c46edSMustafa Ismail qp->swqe_polarity);
457551c46edSMustafa Ismail byte_off += 16;
458551c46edSMustafa Ismail }
459551c46edSMustafa Ismail
460551c46edSMustafa Ismail /* if not an odd number set valid bit in next fragment */
461551c46edSMustafa Ismail if (qp->uk_attrs->hw_rev >= IRDMA_GEN_2 && !(frag_cnt & 0x01) &&
462551c46edSMustafa Ismail frag_cnt) {
463551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, byte_off, NULL,
464551c46edSMustafa Ismail qp->swqe_polarity);
465551c46edSMustafa Ismail if (qp->uk_attrs->hw_rev == IRDMA_GEN_2)
466551c46edSMustafa Ismail ++addl_frag_cnt;
467551c46edSMustafa Ismail }
468551c46edSMustafa Ismail
469551c46edSMustafa Ismail set_64bit_val(wqe, 16,
470551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_DESTQKEY, op_info->qkey) |
471551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_DESTQPN, op_info->dest_qp));
472551c46edSMustafa Ismail hdr = FIELD_PREP(IRDMAQPSQ_REMSTAG, info->stag_to_inv) |
473551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_AHID, op_info->ah_id) |
474551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_IMMDATAFLAG,
475551c46edSMustafa Ismail (info->imm_data_valid ? 1 : 0)) |
476551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_REPORTRTT, (info->report_rtt ? 1 : 0)) |
477551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_OPCODE, info->op_type) |
478551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_ADDFRAGCNT, addl_frag_cnt) |
479551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_READFENCE, read_fence) |
480551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_LOCALFENCE, info->local_fence) |
481551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_SIGCOMPL, info->signaled) |
482551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_UDPHEADER, info->udp_hdr) |
483551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_L4LEN, info->l4len) |
484551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, qp->swqe_polarity);
485551c46edSMustafa Ismail
486551c46edSMustafa Ismail dma_wmb(); /* make sure WQE is populated before valid bit is set */
487551c46edSMustafa Ismail
488551c46edSMustafa Ismail set_64bit_val(wqe, 24, hdr);
489295c95aaSShiraz Saleem
490551c46edSMustafa Ismail if (post_sq)
491551c46edSMustafa Ismail irdma_uk_qp_post_wr(qp);
492551c46edSMustafa Ismail
493551c46edSMustafa Ismail return 0;
494551c46edSMustafa Ismail }
495551c46edSMustafa Ismail
496551c46edSMustafa Ismail /**
497551c46edSMustafa Ismail * irdma_set_mw_bind_wqe_gen_1 - set mw bind wqe
498551c46edSMustafa Ismail * @wqe: wqe for setting fragment
499551c46edSMustafa Ismail * @op_info: info for setting bind wqe values
500551c46edSMustafa Ismail */
irdma_set_mw_bind_wqe_gen_1(__le64 * wqe,struct irdma_bind_window * op_info)501551c46edSMustafa Ismail static void irdma_set_mw_bind_wqe_gen_1(__le64 *wqe,
502551c46edSMustafa Ismail struct irdma_bind_window *op_info)
503551c46edSMustafa Ismail {
504551c46edSMustafa Ismail set_64bit_val(wqe, 0, (uintptr_t)op_info->va);
505551c46edSMustafa Ismail set_64bit_val(wqe, 8,
506551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_PARENTMRSTAG, op_info->mw_stag) |
507551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_MWSTAG, op_info->mr_stag));
508551c46edSMustafa Ismail set_64bit_val(wqe, 16, op_info->bind_len);
509551c46edSMustafa Ismail }
510551c46edSMustafa Ismail
511551c46edSMustafa Ismail /**
512551c46edSMustafa Ismail * irdma_copy_inline_data_gen_1 - Copy inline data to wqe
5134f44e519SMustafa Ismail * @wqe: pointer to wqe
5144f44e519SMustafa Ismail * @sge_list: table of pointers to inline data
5154f44e519SMustafa Ismail * @num_sges: Total inline data length
516551c46edSMustafa Ismail * @polarity: compatibility parameter
517551c46edSMustafa Ismail */
irdma_copy_inline_data_gen_1(u8 * wqe,struct ib_sge * sge_list,u32 num_sges,u8 polarity)5184f44e519SMustafa Ismail static void irdma_copy_inline_data_gen_1(u8 *wqe, struct ib_sge *sge_list,
5194f44e519SMustafa Ismail u32 num_sges, u8 polarity)
520551c46edSMustafa Ismail {
5214f44e519SMustafa Ismail u32 quanta_bytes_remaining = 16;
5224f44e519SMustafa Ismail int i;
5234f44e519SMustafa Ismail
5244f44e519SMustafa Ismail for (i = 0; i < num_sges; i++) {
5254f44e519SMustafa Ismail u8 *cur_sge = (u8 *)(uintptr_t)sge_list[i].addr;
5264f44e519SMustafa Ismail u32 sge_len = sge_list[i].length;
5274f44e519SMustafa Ismail
5284f44e519SMustafa Ismail while (sge_len) {
5294f44e519SMustafa Ismail u32 bytes_copied;
5304f44e519SMustafa Ismail
5314f44e519SMustafa Ismail bytes_copied = min(sge_len, quanta_bytes_remaining);
5324f44e519SMustafa Ismail memcpy(wqe, cur_sge, bytes_copied);
5334f44e519SMustafa Ismail wqe += bytes_copied;
5344f44e519SMustafa Ismail cur_sge += bytes_copied;
5354f44e519SMustafa Ismail quanta_bytes_remaining -= bytes_copied;
5364f44e519SMustafa Ismail sge_len -= bytes_copied;
5374f44e519SMustafa Ismail
5384f44e519SMustafa Ismail if (!quanta_bytes_remaining) {
5394f44e519SMustafa Ismail /* Remaining inline bytes reside after hdr */
5404f44e519SMustafa Ismail wqe += 16;
5414f44e519SMustafa Ismail quanta_bytes_remaining = 32;
5424f44e519SMustafa Ismail }
5434f44e519SMustafa Ismail }
544551c46edSMustafa Ismail }
545551c46edSMustafa Ismail }
546551c46edSMustafa Ismail
547551c46edSMustafa Ismail /**
548551c46edSMustafa Ismail * irdma_inline_data_size_to_quanta_gen_1 - based on inline data, quanta
549551c46edSMustafa Ismail * @data_size: data size for inline
550551c46edSMustafa Ismail *
551551c46edSMustafa Ismail * Gets the quanta based on inline and immediate data.
552551c46edSMustafa Ismail */
irdma_inline_data_size_to_quanta_gen_1(u32 data_size)553551c46edSMustafa Ismail static inline u16 irdma_inline_data_size_to_quanta_gen_1(u32 data_size)
554551c46edSMustafa Ismail {
555551c46edSMustafa Ismail return data_size <= 16 ? IRDMA_QP_WQE_MIN_QUANTA : 2;
556551c46edSMustafa Ismail }
557551c46edSMustafa Ismail
558551c46edSMustafa Ismail /**
559551c46edSMustafa Ismail * irdma_set_mw_bind_wqe - set mw bind in wqe
560551c46edSMustafa Ismail * @wqe: wqe for setting mw bind
561551c46edSMustafa Ismail * @op_info: info for setting wqe values
562551c46edSMustafa Ismail */
irdma_set_mw_bind_wqe(__le64 * wqe,struct irdma_bind_window * op_info)563551c46edSMustafa Ismail static void irdma_set_mw_bind_wqe(__le64 *wqe,
564551c46edSMustafa Ismail struct irdma_bind_window *op_info)
565551c46edSMustafa Ismail {
566551c46edSMustafa Ismail set_64bit_val(wqe, 0, (uintptr_t)op_info->va);
567551c46edSMustafa Ismail set_64bit_val(wqe, 8,
568551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_PARENTMRSTAG, op_info->mr_stag) |
569551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_MWSTAG, op_info->mw_stag));
570551c46edSMustafa Ismail set_64bit_val(wqe, 16, op_info->bind_len);
571551c46edSMustafa Ismail }
572551c46edSMustafa Ismail
573551c46edSMustafa Ismail /**
574551c46edSMustafa Ismail * irdma_copy_inline_data - Copy inline data to wqe
5754f44e519SMustafa Ismail * @wqe: pointer to wqe
5764f44e519SMustafa Ismail * @sge_list: table of pointers to inline data
5774f44e519SMustafa Ismail * @num_sges: number of SGE's
578551c46edSMustafa Ismail * @polarity: polarity of wqe valid bit
579551c46edSMustafa Ismail */
irdma_copy_inline_data(u8 * wqe,struct ib_sge * sge_list,u32 num_sges,u8 polarity)5804f44e519SMustafa Ismail static void irdma_copy_inline_data(u8 *wqe, struct ib_sge *sge_list,
5814f44e519SMustafa Ismail u32 num_sges, u8 polarity)
582551c46edSMustafa Ismail {
583551c46edSMustafa Ismail u8 inline_valid = polarity << IRDMA_INLINE_VALID_S;
5844f44e519SMustafa Ismail u32 quanta_bytes_remaining = 8;
5854f44e519SMustafa Ismail bool first_quanta = true;
5864f44e519SMustafa Ismail int i;
587551c46edSMustafa Ismail
5884f44e519SMustafa Ismail wqe += 8;
5894f44e519SMustafa Ismail
5904f44e519SMustafa Ismail for (i = 0; i < num_sges; i++) {
5914f44e519SMustafa Ismail u8 *cur_sge = (u8 *)(uintptr_t)sge_list[i].addr;
5924f44e519SMustafa Ismail u32 sge_len = sge_list[i].length;
5934f44e519SMustafa Ismail
5944f44e519SMustafa Ismail while (sge_len) {
5954f44e519SMustafa Ismail u32 bytes_copied;
5964f44e519SMustafa Ismail
5974f44e519SMustafa Ismail bytes_copied = min(sge_len, quanta_bytes_remaining);
5984f44e519SMustafa Ismail memcpy(wqe, cur_sge, bytes_copied);
5994f44e519SMustafa Ismail wqe += bytes_copied;
6004f44e519SMustafa Ismail cur_sge += bytes_copied;
6014f44e519SMustafa Ismail quanta_bytes_remaining -= bytes_copied;
6024f44e519SMustafa Ismail sge_len -= bytes_copied;
6034f44e519SMustafa Ismail
6044f44e519SMustafa Ismail if (!quanta_bytes_remaining) {
6054f44e519SMustafa Ismail quanta_bytes_remaining = 31;
6064f44e519SMustafa Ismail
6074f44e519SMustafa Ismail /* Remaining inline bytes reside after hdr */
6084f44e519SMustafa Ismail if (first_quanta) {
6094f44e519SMustafa Ismail first_quanta = false;
6104f44e519SMustafa Ismail wqe += 16;
6114f44e519SMustafa Ismail } else {
6124f44e519SMustafa Ismail *wqe = inline_valid;
6134f44e519SMustafa Ismail wqe++;
614551c46edSMustafa Ismail }
615551c46edSMustafa Ismail }
616551c46edSMustafa Ismail }
6174f44e519SMustafa Ismail }
6184f44e519SMustafa Ismail if (!first_quanta && quanta_bytes_remaining < 31)
6194f44e519SMustafa Ismail *(wqe + quanta_bytes_remaining) = inline_valid;
6204f44e519SMustafa Ismail }
621551c46edSMustafa Ismail
622551c46edSMustafa Ismail /**
623551c46edSMustafa Ismail * irdma_inline_data_size_to_quanta - based on inline data, quanta
624551c46edSMustafa Ismail * @data_size: data size for inline
625551c46edSMustafa Ismail *
626551c46edSMustafa Ismail * Gets the quanta based on inline and immediate data.
627551c46edSMustafa Ismail */
irdma_inline_data_size_to_quanta(u32 data_size)628551c46edSMustafa Ismail static u16 irdma_inline_data_size_to_quanta(u32 data_size)
629551c46edSMustafa Ismail {
630551c46edSMustafa Ismail if (data_size <= 8)
631551c46edSMustafa Ismail return IRDMA_QP_WQE_MIN_QUANTA;
632551c46edSMustafa Ismail else if (data_size <= 39)
633551c46edSMustafa Ismail return 2;
634551c46edSMustafa Ismail else if (data_size <= 70)
635551c46edSMustafa Ismail return 3;
636551c46edSMustafa Ismail else if (data_size <= 101)
637551c46edSMustafa Ismail return 4;
638551c46edSMustafa Ismail else if (data_size <= 132)
639551c46edSMustafa Ismail return 5;
640551c46edSMustafa Ismail else if (data_size <= 163)
641551c46edSMustafa Ismail return 6;
642551c46edSMustafa Ismail else if (data_size <= 194)
643551c46edSMustafa Ismail return 7;
644551c46edSMustafa Ismail else
645551c46edSMustafa Ismail return 8;
646551c46edSMustafa Ismail }
647551c46edSMustafa Ismail
648551c46edSMustafa Ismail /**
649551c46edSMustafa Ismail * irdma_uk_inline_rdma_write - inline rdma write operation
650551c46edSMustafa Ismail * @qp: hw qp ptr
651551c46edSMustafa Ismail * @info: post sq information
652551c46edSMustafa Ismail * @post_sq: flag to post sq
653551c46edSMustafa Ismail */
irdma_uk_inline_rdma_write(struct irdma_qp_uk * qp,struct irdma_post_sq_info * info,bool post_sq)6542c4b14eaSShiraz Saleem int irdma_uk_inline_rdma_write(struct irdma_qp_uk *qp,
6552c4b14eaSShiraz Saleem struct irdma_post_sq_info *info, bool post_sq)
656551c46edSMustafa Ismail {
657551c46edSMustafa Ismail __le64 *wqe;
6584f44e519SMustafa Ismail struct irdma_rdma_write *op_info;
659551c46edSMustafa Ismail u64 hdr = 0;
660551c46edSMustafa Ismail u32 wqe_idx;
661551c46edSMustafa Ismail bool read_fence = false;
6624f44e519SMustafa Ismail u32 i, total_size = 0;
663551c46edSMustafa Ismail u16 quanta;
664551c46edSMustafa Ismail
6654f44e519SMustafa Ismail op_info = &info->op.rdma_write;
666551c46edSMustafa Ismail
6674f44e519SMustafa Ismail if (unlikely(qp->max_sq_frag_cnt < op_info->num_lo_sges))
6682c4b14eaSShiraz Saleem return -EINVAL;
669551c46edSMustafa Ismail
6704f44e519SMustafa Ismail for (i = 0; i < op_info->num_lo_sges; i++)
6714f44e519SMustafa Ismail total_size += op_info->lo_sg_list[i].length;
6724f44e519SMustafa Ismail
6734f44e519SMustafa Ismail if (unlikely(total_size > qp->max_inline_data))
6744f44e519SMustafa Ismail return -EINVAL;
6754f44e519SMustafa Ismail
6764f44e519SMustafa Ismail quanta = qp->wqe_ops.iw_inline_data_size_to_quanta(total_size);
6774f44e519SMustafa Ismail wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, quanta, total_size,
678551c46edSMustafa Ismail info);
679551c46edSMustafa Ismail if (!wqe)
6802c4b14eaSShiraz Saleem return -ENOMEM;
681551c46edSMustafa Ismail
682551c46edSMustafa Ismail irdma_clr_wqes(qp, wqe_idx);
683551c46edSMustafa Ismail
684551c46edSMustafa Ismail read_fence |= info->read_fence;
685551c46edSMustafa Ismail set_64bit_val(wqe, 16,
6869ed8110cSZhu Yanjun FIELD_PREP(IRDMAQPSQ_FRAG_TO, op_info->rem_addr.addr));
687551c46edSMustafa Ismail
6889ed8110cSZhu Yanjun hdr = FIELD_PREP(IRDMAQPSQ_REMSTAG, op_info->rem_addr.lkey) |
689551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_OPCODE, info->op_type) |
6904f44e519SMustafa Ismail FIELD_PREP(IRDMAQPSQ_INLINEDATALEN, total_size) |
691551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_REPORTRTT, info->report_rtt ? 1 : 0) |
692551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_INLINEDATAFLAG, 1) |
693551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_IMMDATAFLAG, info->imm_data_valid ? 1 : 0) |
694551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_READFENCE, read_fence) |
695551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_LOCALFENCE, info->local_fence) |
696551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_SIGCOMPL, info->signaled) |
697551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, qp->swqe_polarity);
698551c46edSMustafa Ismail
699551c46edSMustafa Ismail if (info->imm_data_valid)
700551c46edSMustafa Ismail set_64bit_val(wqe, 0,
701551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_IMMDATA, info->imm_data));
702551c46edSMustafa Ismail
7034f44e519SMustafa Ismail qp->wqe_ops.iw_copy_inline_data((u8 *)wqe, op_info->lo_sg_list,
7044f44e519SMustafa Ismail op_info->num_lo_sges,
705551c46edSMustafa Ismail qp->swqe_polarity);
706551c46edSMustafa Ismail dma_wmb(); /* make sure WQE is populated before valid bit is set */
707551c46edSMustafa Ismail
708551c46edSMustafa Ismail set_64bit_val(wqe, 24, hdr);
709551c46edSMustafa Ismail
710551c46edSMustafa Ismail if (post_sq)
711551c46edSMustafa Ismail irdma_uk_qp_post_wr(qp);
712551c46edSMustafa Ismail
713551c46edSMustafa Ismail return 0;
714551c46edSMustafa Ismail }
715551c46edSMustafa Ismail
716551c46edSMustafa Ismail /**
717551c46edSMustafa Ismail * irdma_uk_inline_send - inline send operation
718551c46edSMustafa Ismail * @qp: hw qp ptr
719551c46edSMustafa Ismail * @info: post sq information
720551c46edSMustafa Ismail * @post_sq: flag to post sq
721551c46edSMustafa Ismail */
irdma_uk_inline_send(struct irdma_qp_uk * qp,struct irdma_post_sq_info * info,bool post_sq)7222c4b14eaSShiraz Saleem int irdma_uk_inline_send(struct irdma_qp_uk *qp,
7232c4b14eaSShiraz Saleem struct irdma_post_sq_info *info, bool post_sq)
724551c46edSMustafa Ismail {
725551c46edSMustafa Ismail __le64 *wqe;
7264f44e519SMustafa Ismail struct irdma_post_send *op_info;
727551c46edSMustafa Ismail u64 hdr;
728551c46edSMustafa Ismail u32 wqe_idx;
729551c46edSMustafa Ismail bool read_fence = false;
7304f44e519SMustafa Ismail u32 i, total_size = 0;
731551c46edSMustafa Ismail u16 quanta;
732551c46edSMustafa Ismail
7334f44e519SMustafa Ismail op_info = &info->op.send;
734551c46edSMustafa Ismail
7354f44e519SMustafa Ismail if (unlikely(qp->max_sq_frag_cnt < op_info->num_sges))
7362c4b14eaSShiraz Saleem return -EINVAL;
737551c46edSMustafa Ismail
7384f44e519SMustafa Ismail for (i = 0; i < op_info->num_sges; i++)
7394f44e519SMustafa Ismail total_size += op_info->sg_list[i].length;
7404f44e519SMustafa Ismail
7414f44e519SMustafa Ismail if (unlikely(total_size > qp->max_inline_data))
7424f44e519SMustafa Ismail return -EINVAL;
7434f44e519SMustafa Ismail
7444f44e519SMustafa Ismail quanta = qp->wqe_ops.iw_inline_data_size_to_quanta(total_size);
7454f44e519SMustafa Ismail wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, quanta, total_size,
746551c46edSMustafa Ismail info);
747551c46edSMustafa Ismail if (!wqe)
7482c4b14eaSShiraz Saleem return -ENOMEM;
749551c46edSMustafa Ismail
750551c46edSMustafa Ismail irdma_clr_wqes(qp, wqe_idx);
751551c46edSMustafa Ismail
752551c46edSMustafa Ismail set_64bit_val(wqe, 16,
753551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_DESTQKEY, op_info->qkey) |
754551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_DESTQPN, op_info->dest_qp));
755551c46edSMustafa Ismail
756551c46edSMustafa Ismail read_fence |= info->read_fence;
757551c46edSMustafa Ismail hdr = FIELD_PREP(IRDMAQPSQ_REMSTAG, info->stag_to_inv) |
758551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_AHID, op_info->ah_id) |
759551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_OPCODE, info->op_type) |
7604f44e519SMustafa Ismail FIELD_PREP(IRDMAQPSQ_INLINEDATALEN, total_size) |
761551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_IMMDATAFLAG,
762551c46edSMustafa Ismail (info->imm_data_valid ? 1 : 0)) |
763551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_REPORTRTT, (info->report_rtt ? 1 : 0)) |
764551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_INLINEDATAFLAG, 1) |
765551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_READFENCE, read_fence) |
766551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_LOCALFENCE, info->local_fence) |
767551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_SIGCOMPL, info->signaled) |
768551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_UDPHEADER, info->udp_hdr) |
769551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_L4LEN, info->l4len) |
770551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, qp->swqe_polarity);
771551c46edSMustafa Ismail
772551c46edSMustafa Ismail if (info->imm_data_valid)
773551c46edSMustafa Ismail set_64bit_val(wqe, 0,
774551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_IMMDATA, info->imm_data));
7754f44e519SMustafa Ismail qp->wqe_ops.iw_copy_inline_data((u8 *)wqe, op_info->sg_list,
7764f44e519SMustafa Ismail op_info->num_sges, qp->swqe_polarity);
777551c46edSMustafa Ismail
778551c46edSMustafa Ismail dma_wmb(); /* make sure WQE is populated before valid bit is set */
779551c46edSMustafa Ismail
780551c46edSMustafa Ismail set_64bit_val(wqe, 24, hdr);
781551c46edSMustafa Ismail
782551c46edSMustafa Ismail if (post_sq)
783551c46edSMustafa Ismail irdma_uk_qp_post_wr(qp);
784551c46edSMustafa Ismail
785551c46edSMustafa Ismail return 0;
786551c46edSMustafa Ismail }
787551c46edSMustafa Ismail
788551c46edSMustafa Ismail /**
789551c46edSMustafa Ismail * irdma_uk_stag_local_invalidate - stag invalidate operation
790551c46edSMustafa Ismail * @qp: hw qp ptr
791551c46edSMustafa Ismail * @info: post sq information
792551c46edSMustafa Ismail * @post_sq: flag to post sq
793551c46edSMustafa Ismail */
irdma_uk_stag_local_invalidate(struct irdma_qp_uk * qp,struct irdma_post_sq_info * info,bool post_sq)7942c4b14eaSShiraz Saleem int irdma_uk_stag_local_invalidate(struct irdma_qp_uk *qp,
7952c4b14eaSShiraz Saleem struct irdma_post_sq_info *info,
7962c4b14eaSShiraz Saleem bool post_sq)
797551c46edSMustafa Ismail {
798551c46edSMustafa Ismail __le64 *wqe;
799551c46edSMustafa Ismail struct irdma_inv_local_stag *op_info;
800551c46edSMustafa Ismail u64 hdr;
801551c46edSMustafa Ismail u32 wqe_idx;
802551c46edSMustafa Ismail bool local_fence = false;
8039ed8110cSZhu Yanjun struct ib_sge sge = {};
804551c46edSMustafa Ismail
805551c46edSMustafa Ismail op_info = &info->op.inv_local_stag;
806551c46edSMustafa Ismail local_fence = info->local_fence;
807551c46edSMustafa Ismail
808551c46edSMustafa Ismail wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, IRDMA_QP_WQE_MIN_QUANTA,
809551c46edSMustafa Ismail 0, info);
810551c46edSMustafa Ismail if (!wqe)
8112c4b14eaSShiraz Saleem return -ENOMEM;
812551c46edSMustafa Ismail
813551c46edSMustafa Ismail irdma_clr_wqes(qp, wqe_idx);
814551c46edSMustafa Ismail
8159ed8110cSZhu Yanjun sge.lkey = op_info->target_stag;
816551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, 0, &sge, 0);
817551c46edSMustafa Ismail
818551c46edSMustafa Ismail set_64bit_val(wqe, 16, 0);
819551c46edSMustafa Ismail
820551c46edSMustafa Ismail hdr = FIELD_PREP(IRDMAQPSQ_OPCODE, IRDMA_OP_TYPE_INV_STAG) |
821551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_READFENCE, info->read_fence) |
822551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_LOCALFENCE, local_fence) |
823551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_SIGCOMPL, info->signaled) |
824551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, qp->swqe_polarity);
825551c46edSMustafa Ismail
826551c46edSMustafa Ismail dma_wmb(); /* make sure WQE is populated before valid bit is set */
827551c46edSMustafa Ismail
828551c46edSMustafa Ismail set_64bit_val(wqe, 24, hdr);
829551c46edSMustafa Ismail
830551c46edSMustafa Ismail if (post_sq)
831551c46edSMustafa Ismail irdma_uk_qp_post_wr(qp);
832551c46edSMustafa Ismail
833551c46edSMustafa Ismail return 0;
834551c46edSMustafa Ismail }
835551c46edSMustafa Ismail
836551c46edSMustafa Ismail /**
837551c46edSMustafa Ismail * irdma_uk_post_receive - post receive wqe
838551c46edSMustafa Ismail * @qp: hw qp ptr
839551c46edSMustafa Ismail * @info: post rq information
840551c46edSMustafa Ismail */
irdma_uk_post_receive(struct irdma_qp_uk * qp,struct irdma_post_rq_info * info)8412c4b14eaSShiraz Saleem int irdma_uk_post_receive(struct irdma_qp_uk *qp,
842551c46edSMustafa Ismail struct irdma_post_rq_info *info)
843551c46edSMustafa Ismail {
8446407c69dSTatyana Nikolova u32 wqe_idx, i, byte_off;
845551c46edSMustafa Ismail u32 addl_frag_cnt;
846551c46edSMustafa Ismail __le64 *wqe;
847551c46edSMustafa Ismail u64 hdr;
848551c46edSMustafa Ismail
849551c46edSMustafa Ismail if (qp->max_rq_frag_cnt < info->num_sges)
8502c4b14eaSShiraz Saleem return -EINVAL;
851551c46edSMustafa Ismail
852551c46edSMustafa Ismail wqe = irdma_qp_get_next_recv_wqe(qp, &wqe_idx);
853551c46edSMustafa Ismail if (!wqe)
8542c4b14eaSShiraz Saleem return -ENOMEM;
855551c46edSMustafa Ismail
856551c46edSMustafa Ismail qp->rq_wrid_array[wqe_idx] = info->wr_id;
857551c46edSMustafa Ismail addl_frag_cnt = info->num_sges > 1 ? (info->num_sges - 1) : 0;
858551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, 0, info->sg_list,
859551c46edSMustafa Ismail qp->rwqe_polarity);
860551c46edSMustafa Ismail
861551c46edSMustafa Ismail for (i = 1, byte_off = 32; i < info->num_sges; i++) {
862551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, byte_off, &info->sg_list[i],
863551c46edSMustafa Ismail qp->rwqe_polarity);
864551c46edSMustafa Ismail byte_off += 16;
865551c46edSMustafa Ismail }
866551c46edSMustafa Ismail
867551c46edSMustafa Ismail /* if not an odd number set valid bit in next fragment */
868551c46edSMustafa Ismail if (qp->uk_attrs->hw_rev >= IRDMA_GEN_2 && !(info->num_sges & 0x01) &&
869551c46edSMustafa Ismail info->num_sges) {
870551c46edSMustafa Ismail qp->wqe_ops.iw_set_fragment(wqe, byte_off, NULL,
871551c46edSMustafa Ismail qp->rwqe_polarity);
872551c46edSMustafa Ismail if (qp->uk_attrs->hw_rev == IRDMA_GEN_2)
873551c46edSMustafa Ismail ++addl_frag_cnt;
874551c46edSMustafa Ismail }
875551c46edSMustafa Ismail
876551c46edSMustafa Ismail set_64bit_val(wqe, 16, 0);
877551c46edSMustafa Ismail hdr = FIELD_PREP(IRDMAQPSQ_ADDFRAGCNT, addl_frag_cnt) |
878551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, qp->rwqe_polarity);
879551c46edSMustafa Ismail
880551c46edSMustafa Ismail dma_wmb(); /* make sure WQE is populated before valid bit is set */
881551c46edSMustafa Ismail
882551c46edSMustafa Ismail set_64bit_val(wqe, 24, hdr);
883551c46edSMustafa Ismail
884551c46edSMustafa Ismail return 0;
885551c46edSMustafa Ismail }
886551c46edSMustafa Ismail
887551c46edSMustafa Ismail /**
888551c46edSMustafa Ismail * irdma_uk_cq_resize - reset the cq buffer info
889551c46edSMustafa Ismail * @cq: cq to resize
890551c46edSMustafa Ismail * @cq_base: new cq buffer addr
891551c46edSMustafa Ismail * @cq_size: number of cqes
892551c46edSMustafa Ismail */
irdma_uk_cq_resize(struct irdma_cq_uk * cq,void * cq_base,int cq_size)893551c46edSMustafa Ismail void irdma_uk_cq_resize(struct irdma_cq_uk *cq, void *cq_base, int cq_size)
894551c46edSMustafa Ismail {
895551c46edSMustafa Ismail cq->cq_base = cq_base;
896551c46edSMustafa Ismail cq->cq_size = cq_size;
897551c46edSMustafa Ismail IRDMA_RING_INIT(cq->cq_ring, cq->cq_size);
898551c46edSMustafa Ismail cq->polarity = 1;
899551c46edSMustafa Ismail }
900551c46edSMustafa Ismail
901551c46edSMustafa Ismail /**
902551c46edSMustafa Ismail * irdma_uk_cq_set_resized_cnt - record the count of the resized buffers
903551c46edSMustafa Ismail * @cq: cq to resize
904551c46edSMustafa Ismail * @cq_cnt: the count of the resized cq buffers
905551c46edSMustafa Ismail */
irdma_uk_cq_set_resized_cnt(struct irdma_cq_uk * cq,u16 cq_cnt)906551c46edSMustafa Ismail void irdma_uk_cq_set_resized_cnt(struct irdma_cq_uk *cq, u16 cq_cnt)
907551c46edSMustafa Ismail {
908551c46edSMustafa Ismail u64 temp_val;
909551c46edSMustafa Ismail u16 sw_cq_sel;
910551c46edSMustafa Ismail u8 arm_next_se;
911551c46edSMustafa Ismail u8 arm_next;
912551c46edSMustafa Ismail u8 arm_seq_num;
913551c46edSMustafa Ismail
914551c46edSMustafa Ismail get_64bit_val(cq->shadow_area, 32, &temp_val);
915551c46edSMustafa Ismail
916551c46edSMustafa Ismail sw_cq_sel = (u16)FIELD_GET(IRDMA_CQ_DBSA_SW_CQ_SELECT, temp_val);
917551c46edSMustafa Ismail sw_cq_sel += cq_cnt;
918551c46edSMustafa Ismail
919551c46edSMustafa Ismail arm_seq_num = (u8)FIELD_GET(IRDMA_CQ_DBSA_ARM_SEQ_NUM, temp_val);
920551c46edSMustafa Ismail arm_next_se = (u8)FIELD_GET(IRDMA_CQ_DBSA_ARM_NEXT_SE, temp_val);
921551c46edSMustafa Ismail arm_next = (u8)FIELD_GET(IRDMA_CQ_DBSA_ARM_NEXT, temp_val);
922551c46edSMustafa Ismail
923551c46edSMustafa Ismail temp_val = FIELD_PREP(IRDMA_CQ_DBSA_ARM_SEQ_NUM, arm_seq_num) |
924551c46edSMustafa Ismail FIELD_PREP(IRDMA_CQ_DBSA_SW_CQ_SELECT, sw_cq_sel) |
925551c46edSMustafa Ismail FIELD_PREP(IRDMA_CQ_DBSA_ARM_NEXT_SE, arm_next_se) |
926551c46edSMustafa Ismail FIELD_PREP(IRDMA_CQ_DBSA_ARM_NEXT, arm_next);
927551c46edSMustafa Ismail
928551c46edSMustafa Ismail set_64bit_val(cq->shadow_area, 32, temp_val);
929551c46edSMustafa Ismail }
930551c46edSMustafa Ismail
931551c46edSMustafa Ismail /**
932551c46edSMustafa Ismail * irdma_uk_cq_request_notification - cq notification request (door bell)
933551c46edSMustafa Ismail * @cq: hw cq
934551c46edSMustafa Ismail * @cq_notify: notification type
935551c46edSMustafa Ismail */
irdma_uk_cq_request_notification(struct irdma_cq_uk * cq,enum irdma_cmpl_notify cq_notify)936551c46edSMustafa Ismail void irdma_uk_cq_request_notification(struct irdma_cq_uk *cq,
937551c46edSMustafa Ismail enum irdma_cmpl_notify cq_notify)
938551c46edSMustafa Ismail {
939551c46edSMustafa Ismail u64 temp_val;
940551c46edSMustafa Ismail u16 sw_cq_sel;
941551c46edSMustafa Ismail u8 arm_next_se = 0;
942551c46edSMustafa Ismail u8 arm_next = 0;
943551c46edSMustafa Ismail u8 arm_seq_num;
944551c46edSMustafa Ismail
945551c46edSMustafa Ismail get_64bit_val(cq->shadow_area, 32, &temp_val);
946551c46edSMustafa Ismail arm_seq_num = (u8)FIELD_GET(IRDMA_CQ_DBSA_ARM_SEQ_NUM, temp_val);
947551c46edSMustafa Ismail arm_seq_num++;
948551c46edSMustafa Ismail sw_cq_sel = (u16)FIELD_GET(IRDMA_CQ_DBSA_SW_CQ_SELECT, temp_val);
949551c46edSMustafa Ismail arm_next_se = (u8)FIELD_GET(IRDMA_CQ_DBSA_ARM_NEXT_SE, temp_val);
950551c46edSMustafa Ismail arm_next_se |= 1;
951551c46edSMustafa Ismail if (cq_notify == IRDMA_CQ_COMPL_EVENT)
952551c46edSMustafa Ismail arm_next = 1;
953551c46edSMustafa Ismail temp_val = FIELD_PREP(IRDMA_CQ_DBSA_ARM_SEQ_NUM, arm_seq_num) |
954551c46edSMustafa Ismail FIELD_PREP(IRDMA_CQ_DBSA_SW_CQ_SELECT, sw_cq_sel) |
955551c46edSMustafa Ismail FIELD_PREP(IRDMA_CQ_DBSA_ARM_NEXT_SE, arm_next_se) |
956551c46edSMustafa Ismail FIELD_PREP(IRDMA_CQ_DBSA_ARM_NEXT, arm_next);
957551c46edSMustafa Ismail
958551c46edSMustafa Ismail set_64bit_val(cq->shadow_area, 32, temp_val);
959551c46edSMustafa Ismail
960551c46edSMustafa Ismail dma_wmb(); /* make sure WQE is populated before valid bit is set */
961551c46edSMustafa Ismail
962551c46edSMustafa Ismail writel(cq->cq_id, cq->cqe_alloc_db);
963551c46edSMustafa Ismail }
964551c46edSMustafa Ismail
965551c46edSMustafa Ismail /**
966551c46edSMustafa Ismail * irdma_uk_cq_poll_cmpl - get cq completion info
967551c46edSMustafa Ismail * @cq: hw cq
968551c46edSMustafa Ismail * @info: cq poll information returned
969551c46edSMustafa Ismail */
irdma_uk_cq_poll_cmpl(struct irdma_cq_uk * cq,struct irdma_cq_poll_info * info)9702c4b14eaSShiraz Saleem int irdma_uk_cq_poll_cmpl(struct irdma_cq_uk *cq,
9712c4b14eaSShiraz Saleem struct irdma_cq_poll_info *info)
972551c46edSMustafa Ismail {
973551c46edSMustafa Ismail u64 comp_ctx, qword0, qword2, qword3;
974551c46edSMustafa Ismail __le64 *cqe;
975551c46edSMustafa Ismail struct irdma_qp_uk *qp;
976551c46edSMustafa Ismail struct irdma_ring *pring = NULL;
97724419777SMustafa Ismail u32 wqe_idx;
9782c4b14eaSShiraz Saleem int ret_code;
979551c46edSMustafa Ismail bool move_cq_head = true;
980551c46edSMustafa Ismail u8 polarity;
981551c46edSMustafa Ismail bool ext_valid;
982551c46edSMustafa Ismail __le64 *ext_cqe;
983551c46edSMustafa Ismail
984551c46edSMustafa Ismail if (cq->avoid_mem_cflct)
985551c46edSMustafa Ismail cqe = IRDMA_GET_CURRENT_EXTENDED_CQ_ELEM(cq);
986551c46edSMustafa Ismail else
987551c46edSMustafa Ismail cqe = IRDMA_GET_CURRENT_CQ_ELEM(cq);
988551c46edSMustafa Ismail
989551c46edSMustafa Ismail get_64bit_val(cqe, 24, &qword3);
990551c46edSMustafa Ismail polarity = (u8)FIELD_GET(IRDMA_CQ_VALID, qword3);
991551c46edSMustafa Ismail if (polarity != cq->polarity)
9922c4b14eaSShiraz Saleem return -ENOENT;
993551c46edSMustafa Ismail
994551c46edSMustafa Ismail /* Ensure CQE contents are read after valid bit is checked */
995551c46edSMustafa Ismail dma_rmb();
996551c46edSMustafa Ismail
997551c46edSMustafa Ismail ext_valid = (bool)FIELD_GET(IRDMA_CQ_EXTCQE, qword3);
998551c46edSMustafa Ismail if (ext_valid) {
999551c46edSMustafa Ismail u64 qword6, qword7;
1000551c46edSMustafa Ismail u32 peek_head;
1001551c46edSMustafa Ismail
1002551c46edSMustafa Ismail if (cq->avoid_mem_cflct) {
1003551c46edSMustafa Ismail ext_cqe = (__le64 *)((u8 *)cqe + 32);
1004551c46edSMustafa Ismail get_64bit_val(ext_cqe, 24, &qword7);
1005e93c7d8eSShiraz Saleem polarity = (u8)FIELD_GET(IRDMA_CQ_VALID, qword7);
1006551c46edSMustafa Ismail } else {
1007551c46edSMustafa Ismail peek_head = (cq->cq_ring.head + 1) % cq->cq_ring.size;
1008551c46edSMustafa Ismail ext_cqe = cq->cq_base[peek_head].buf;
1009551c46edSMustafa Ismail get_64bit_val(ext_cqe, 24, &qword7);
1010e93c7d8eSShiraz Saleem polarity = (u8)FIELD_GET(IRDMA_CQ_VALID, qword7);
1011551c46edSMustafa Ismail if (!peek_head)
1012551c46edSMustafa Ismail polarity ^= 1;
1013551c46edSMustafa Ismail }
1014551c46edSMustafa Ismail if (polarity != cq->polarity)
10152c4b14eaSShiraz Saleem return -ENOENT;
1016551c46edSMustafa Ismail
1017551c46edSMustafa Ismail /* Ensure ext CQE contents are read after ext valid bit is checked */
1018551c46edSMustafa Ismail dma_rmb();
1019551c46edSMustafa Ismail
1020551c46edSMustafa Ismail info->imm_valid = (bool)FIELD_GET(IRDMA_CQ_IMMVALID, qword7);
1021551c46edSMustafa Ismail if (info->imm_valid) {
1022551c46edSMustafa Ismail u64 qword4;
1023551c46edSMustafa Ismail
1024551c46edSMustafa Ismail get_64bit_val(ext_cqe, 0, &qword4);
1025551c46edSMustafa Ismail info->imm_data = (u32)FIELD_GET(IRDMA_CQ_IMMDATALOW32, qword4);
1026551c46edSMustafa Ismail }
1027551c46edSMustafa Ismail info->ud_smac_valid = (bool)FIELD_GET(IRDMA_CQ_UDSMACVALID, qword7);
1028551c46edSMustafa Ismail info->ud_vlan_valid = (bool)FIELD_GET(IRDMA_CQ_UDVLANVALID, qword7);
1029551c46edSMustafa Ismail if (info->ud_smac_valid || info->ud_vlan_valid) {
1030551c46edSMustafa Ismail get_64bit_val(ext_cqe, 16, &qword6);
1031551c46edSMustafa Ismail if (info->ud_vlan_valid)
1032551c46edSMustafa Ismail info->ud_vlan = (u16)FIELD_GET(IRDMA_CQ_UDVLAN, qword6);
1033551c46edSMustafa Ismail if (info->ud_smac_valid) {
1034551c46edSMustafa Ismail info->ud_smac[5] = qword6 & 0xFF;
1035551c46edSMustafa Ismail info->ud_smac[4] = (qword6 >> 8) & 0xFF;
1036551c46edSMustafa Ismail info->ud_smac[3] = (qword6 >> 16) & 0xFF;
1037551c46edSMustafa Ismail info->ud_smac[2] = (qword6 >> 24) & 0xFF;
1038551c46edSMustafa Ismail info->ud_smac[1] = (qword6 >> 32) & 0xFF;
1039551c46edSMustafa Ismail info->ud_smac[0] = (qword6 >> 40) & 0xFF;
1040551c46edSMustafa Ismail }
1041551c46edSMustafa Ismail }
1042551c46edSMustafa Ismail } else {
1043551c46edSMustafa Ismail info->imm_valid = false;
1044551c46edSMustafa Ismail info->ud_smac_valid = false;
1045551c46edSMustafa Ismail info->ud_vlan_valid = false;
1046551c46edSMustafa Ismail }
1047551c46edSMustafa Ismail
104824419777SMustafa Ismail info->q_type = (u8)FIELD_GET(IRDMA_CQ_SQ, qword3);
1049551c46edSMustafa Ismail info->error = (bool)FIELD_GET(IRDMA_CQ_ERROR, qword3);
1050551c46edSMustafa Ismail info->ipv4 = (bool)FIELD_GET(IRDMACQ_IPV4, qword3);
1051551c46edSMustafa Ismail if (info->error) {
1052551c46edSMustafa Ismail info->major_err = FIELD_GET(IRDMA_CQ_MAJERR, qword3);
1053551c46edSMustafa Ismail info->minor_err = FIELD_GET(IRDMA_CQ_MINERR, qword3);
1054551c46edSMustafa Ismail if (info->major_err == IRDMA_FLUSH_MAJOR_ERR) {
1055551c46edSMustafa Ismail info->comp_status = IRDMA_COMPL_STATUS_FLUSHED;
1056551c46edSMustafa Ismail /* Set the min error to standard flush error code for remaining cqes */
1057551c46edSMustafa Ismail if (info->minor_err != FLUSH_GENERAL_ERR) {
1058551c46edSMustafa Ismail qword3 &= ~IRDMA_CQ_MINERR;
1059551c46edSMustafa Ismail qword3 |= FIELD_PREP(IRDMA_CQ_MINERR, FLUSH_GENERAL_ERR);
1060551c46edSMustafa Ismail set_64bit_val(cqe, 24, qword3);
1061551c46edSMustafa Ismail }
1062551c46edSMustafa Ismail } else {
1063551c46edSMustafa Ismail info->comp_status = IRDMA_COMPL_STATUS_UNKNOWN;
1064551c46edSMustafa Ismail }
1065551c46edSMustafa Ismail } else {
1066551c46edSMustafa Ismail info->comp_status = IRDMA_COMPL_STATUS_SUCCESS;
1067551c46edSMustafa Ismail }
1068551c46edSMustafa Ismail
1069551c46edSMustafa Ismail get_64bit_val(cqe, 0, &qword0);
1070551c46edSMustafa Ismail get_64bit_val(cqe, 16, &qword2);
1071551c46edSMustafa Ismail
1072551c46edSMustafa Ismail info->tcp_seq_num_rtt = (u32)FIELD_GET(IRDMACQ_TCPSEQNUMRTT, qword0);
1073551c46edSMustafa Ismail info->qp_id = (u32)FIELD_GET(IRDMACQ_QPID, qword2);
1074551c46edSMustafa Ismail info->ud_src_qpn = (u32)FIELD_GET(IRDMACQ_UDSRCQPN, qword2);
1075551c46edSMustafa Ismail
1076551c46edSMustafa Ismail get_64bit_val(cqe, 8, &comp_ctx);
1077551c46edSMustafa Ismail
1078551c46edSMustafa Ismail info->solicited_event = (bool)FIELD_GET(IRDMACQ_SOEVENT, qword3);
1079551c46edSMustafa Ismail qp = (struct irdma_qp_uk *)(unsigned long)comp_ctx;
1080551c46edSMustafa Ismail if (!qp || qp->destroy_pending) {
10812c4b14eaSShiraz Saleem ret_code = -EFAULT;
1082551c46edSMustafa Ismail goto exit;
1083551c46edSMustafa Ismail }
1084551c46edSMustafa Ismail wqe_idx = (u32)FIELD_GET(IRDMA_CQ_WQEIDX, qword3);
1085551c46edSMustafa Ismail info->qp_handle = (irdma_qp_handle)(unsigned long)qp;
10863bfb25faSSindhu Devale info->op_type = (u8)FIELD_GET(IRDMACQ_OP, qword3);
1087551c46edSMustafa Ismail
108824419777SMustafa Ismail if (info->q_type == IRDMA_CQE_QTYPE_RQ) {
1089551c46edSMustafa Ismail u32 array_idx;
1090551c46edSMustafa Ismail
1091551c46edSMustafa Ismail array_idx = wqe_idx / qp->rq_wqe_size_multiplier;
1092551c46edSMustafa Ismail
1093551c46edSMustafa Ismail if (info->comp_status == IRDMA_COMPL_STATUS_FLUSHED ||
1094551c46edSMustafa Ismail info->comp_status == IRDMA_COMPL_STATUS_UNKNOWN) {
1095551c46edSMustafa Ismail if (!IRDMA_RING_MORE_WORK(qp->rq_ring)) {
10962c4b14eaSShiraz Saleem ret_code = -ENOENT;
1097551c46edSMustafa Ismail goto exit;
1098551c46edSMustafa Ismail }
1099551c46edSMustafa Ismail
1100551c46edSMustafa Ismail info->wr_id = qp->rq_wrid_array[qp->rq_ring.tail];
1101551c46edSMustafa Ismail array_idx = qp->rq_ring.tail;
1102551c46edSMustafa Ismail } else {
1103551c46edSMustafa Ismail info->wr_id = qp->rq_wrid_array[array_idx];
1104551c46edSMustafa Ismail }
1105551c46edSMustafa Ismail
1106551c46edSMustafa Ismail info->bytes_xfered = (u32)FIELD_GET(IRDMACQ_PAYLDLEN, qword0);
1107551c46edSMustafa Ismail
1108551c46edSMustafa Ismail if (qword3 & IRDMACQ_STAG) {
1109551c46edSMustafa Ismail info->stag_invalid_set = true;
1110551c46edSMustafa Ismail info->inv_stag = (u32)FIELD_GET(IRDMACQ_INVSTAG, qword2);
1111551c46edSMustafa Ismail } else {
1112551c46edSMustafa Ismail info->stag_invalid_set = false;
1113551c46edSMustafa Ismail }
1114551c46edSMustafa Ismail IRDMA_RING_SET_TAIL(qp->rq_ring, array_idx + 1);
1115551c46edSMustafa Ismail if (info->comp_status == IRDMA_COMPL_STATUS_FLUSHED) {
1116551c46edSMustafa Ismail qp->rq_flush_seen = true;
1117551c46edSMustafa Ismail if (!IRDMA_RING_MORE_WORK(qp->rq_ring))
1118551c46edSMustafa Ismail qp->rq_flush_complete = true;
1119551c46edSMustafa Ismail else
1120551c46edSMustafa Ismail move_cq_head = false;
1121551c46edSMustafa Ismail }
1122551c46edSMustafa Ismail pring = &qp->rq_ring;
1123551c46edSMustafa Ismail } else { /* q_type is IRDMA_CQE_QTYPE_SQ */
1124551c46edSMustafa Ismail if (qp->first_sq_wq) {
1125551c46edSMustafa Ismail if (wqe_idx + 1 >= qp->conn_wqes)
1126551c46edSMustafa Ismail qp->first_sq_wq = false;
1127551c46edSMustafa Ismail
1128551c46edSMustafa Ismail if (wqe_idx < qp->conn_wqes && qp->sq_ring.head == qp->sq_ring.tail) {
1129551c46edSMustafa Ismail IRDMA_RING_MOVE_HEAD_NOCHECK(cq->cq_ring);
1130551c46edSMustafa Ismail IRDMA_RING_MOVE_TAIL(cq->cq_ring);
1131551c46edSMustafa Ismail set_64bit_val(cq->shadow_area, 0,
1132551c46edSMustafa Ismail IRDMA_RING_CURRENT_HEAD(cq->cq_ring));
1133551c46edSMustafa Ismail memset(info, 0,
1134551c46edSMustafa Ismail sizeof(struct irdma_cq_poll_info));
1135551c46edSMustafa Ismail return irdma_uk_cq_poll_cmpl(cq, info);
1136551c46edSMustafa Ismail }
1137551c46edSMustafa Ismail }
1138551c46edSMustafa Ismail if (info->comp_status != IRDMA_COMPL_STATUS_FLUSHED) {
1139551c46edSMustafa Ismail info->wr_id = qp->sq_wrtrk_array[wqe_idx].wrid;
1140551c46edSMustafa Ismail if (!info->comp_status)
1141551c46edSMustafa Ismail info->bytes_xfered = qp->sq_wrtrk_array[wqe_idx].wr_len;
1142551c46edSMustafa Ismail info->op_type = (u8)FIELD_GET(IRDMACQ_OP, qword3);
1143551c46edSMustafa Ismail IRDMA_RING_SET_TAIL(qp->sq_ring,
1144551c46edSMustafa Ismail wqe_idx + qp->sq_wrtrk_array[wqe_idx].quanta);
1145551c46edSMustafa Ismail } else {
1146551c46edSMustafa Ismail if (!IRDMA_RING_MORE_WORK(qp->sq_ring)) {
11472c4b14eaSShiraz Saleem ret_code = -ENOENT;
1148551c46edSMustafa Ismail goto exit;
1149551c46edSMustafa Ismail }
1150551c46edSMustafa Ismail
1151551c46edSMustafa Ismail do {
1152551c46edSMustafa Ismail __le64 *sw_wqe;
1153551c46edSMustafa Ismail u64 wqe_qword;
1154551c46edSMustafa Ismail u32 tail;
1155551c46edSMustafa Ismail
1156551c46edSMustafa Ismail tail = qp->sq_ring.tail;
1157551c46edSMustafa Ismail sw_wqe = qp->sq_base[tail].elem;
1158551c46edSMustafa Ismail get_64bit_val(sw_wqe, 24,
1159551c46edSMustafa Ismail &wqe_qword);
116024419777SMustafa Ismail info->op_type = (u8)FIELD_GET(IRDMAQPSQ_OPCODE,
116124419777SMustafa Ismail wqe_qword);
1162551c46edSMustafa Ismail IRDMA_RING_SET_TAIL(qp->sq_ring,
1163551c46edSMustafa Ismail tail + qp->sq_wrtrk_array[tail].quanta);
116424419777SMustafa Ismail if (info->op_type != IRDMAQP_OP_NOP) {
1165551c46edSMustafa Ismail info->wr_id = qp->sq_wrtrk_array[tail].wrid;
1166551c46edSMustafa Ismail info->bytes_xfered = qp->sq_wrtrk_array[tail].wr_len;
1167551c46edSMustafa Ismail break;
1168551c46edSMustafa Ismail }
1169551c46edSMustafa Ismail } while (1);
117024419777SMustafa Ismail if (info->op_type == IRDMA_OP_TYPE_BIND_MW &&
117124419777SMustafa Ismail info->minor_err == FLUSH_PROT_ERR)
1172dcb23bbbSSindhu-Devale info->minor_err = FLUSH_MW_BIND_ERR;
1173551c46edSMustafa Ismail qp->sq_flush_seen = true;
1174551c46edSMustafa Ismail if (!IRDMA_RING_MORE_WORK(qp->sq_ring))
1175551c46edSMustafa Ismail qp->sq_flush_complete = true;
1176551c46edSMustafa Ismail }
1177551c46edSMustafa Ismail pring = &qp->sq_ring;
1178551c46edSMustafa Ismail }
1179551c46edSMustafa Ismail
1180551c46edSMustafa Ismail ret_code = 0;
1181551c46edSMustafa Ismail
1182551c46edSMustafa Ismail exit:
1183551c46edSMustafa Ismail if (!ret_code && info->comp_status == IRDMA_COMPL_STATUS_FLUSHED)
1184551c46edSMustafa Ismail if (pring && IRDMA_RING_MORE_WORK(*pring))
1185551c46edSMustafa Ismail move_cq_head = false;
1186551c46edSMustafa Ismail
1187551c46edSMustafa Ismail if (move_cq_head) {
1188551c46edSMustafa Ismail IRDMA_RING_MOVE_HEAD_NOCHECK(cq->cq_ring);
1189551c46edSMustafa Ismail if (!IRDMA_RING_CURRENT_HEAD(cq->cq_ring))
1190551c46edSMustafa Ismail cq->polarity ^= 1;
1191551c46edSMustafa Ismail
1192551c46edSMustafa Ismail if (ext_valid && !cq->avoid_mem_cflct) {
1193551c46edSMustafa Ismail IRDMA_RING_MOVE_HEAD_NOCHECK(cq->cq_ring);
1194551c46edSMustafa Ismail if (!IRDMA_RING_CURRENT_HEAD(cq->cq_ring))
1195551c46edSMustafa Ismail cq->polarity ^= 1;
1196551c46edSMustafa Ismail }
1197551c46edSMustafa Ismail
1198551c46edSMustafa Ismail IRDMA_RING_MOVE_TAIL(cq->cq_ring);
1199551c46edSMustafa Ismail if (!cq->avoid_mem_cflct && ext_valid)
1200551c46edSMustafa Ismail IRDMA_RING_MOVE_TAIL(cq->cq_ring);
1201551c46edSMustafa Ismail set_64bit_val(cq->shadow_area, 0,
1202551c46edSMustafa Ismail IRDMA_RING_CURRENT_HEAD(cq->cq_ring));
1203551c46edSMustafa Ismail } else {
1204551c46edSMustafa Ismail qword3 &= ~IRDMA_CQ_WQEIDX;
1205551c46edSMustafa Ismail qword3 |= FIELD_PREP(IRDMA_CQ_WQEIDX, pring->tail);
1206551c46edSMustafa Ismail set_64bit_val(cqe, 24, qword3);
1207551c46edSMustafa Ismail }
1208551c46edSMustafa Ismail
1209551c46edSMustafa Ismail return ret_code;
1210551c46edSMustafa Ismail }
1211551c46edSMustafa Ismail
1212551c46edSMustafa Ismail /**
1213551c46edSMustafa Ismail * irdma_qp_round_up - return round up qp wq depth
1214551c46edSMustafa Ismail * @wqdepth: wq depth in quanta to round up
1215551c46edSMustafa Ismail */
irdma_qp_round_up(u32 wqdepth)1216551c46edSMustafa Ismail static int irdma_qp_round_up(u32 wqdepth)
1217551c46edSMustafa Ismail {
1218551c46edSMustafa Ismail int scount = 1;
1219551c46edSMustafa Ismail
1220551c46edSMustafa Ismail for (wqdepth--; scount <= 16; scount *= 2)
1221551c46edSMustafa Ismail wqdepth |= wqdepth >> scount;
1222551c46edSMustafa Ismail
1223551c46edSMustafa Ismail return ++wqdepth;
1224551c46edSMustafa Ismail }
1225551c46edSMustafa Ismail
1226551c46edSMustafa Ismail /**
1227551c46edSMustafa Ismail * irdma_get_wqe_shift - get shift count for maximum wqe size
1228551c46edSMustafa Ismail * @uk_attrs: qp HW attributes
1229551c46edSMustafa Ismail * @sge: Maximum Scatter Gather Elements wqe
1230551c46edSMustafa Ismail * @inline_data: Maximum inline data size
1231551c46edSMustafa Ismail * @shift: Returns the shift needed based on sge
1232551c46edSMustafa Ismail *
1233551c46edSMustafa Ismail * Shift can be used to left shift the wqe size based on number of SGEs and inlind data size.
1234551c46edSMustafa Ismail * For 1 SGE or inline data <= 8, shift = 0 (wqe size of 32
1235551c46edSMustafa Ismail * bytes). For 2 or 3 SGEs or inline data <= 39, shift = 1 (wqe
1236551c46edSMustafa Ismail * size of 64 bytes).
1237551c46edSMustafa Ismail * For 4-7 SGE's and inline <= 101 Shift of 2 otherwise (wqe
1238551c46edSMustafa Ismail * size of 256 bytes).
1239551c46edSMustafa Ismail */
irdma_get_wqe_shift(struct irdma_uk_attrs * uk_attrs,u32 sge,u32 inline_data,u8 * shift)1240551c46edSMustafa Ismail void irdma_get_wqe_shift(struct irdma_uk_attrs *uk_attrs, u32 sge,
1241551c46edSMustafa Ismail u32 inline_data, u8 *shift)
1242551c46edSMustafa Ismail {
1243551c46edSMustafa Ismail *shift = 0;
1244551c46edSMustafa Ismail if (uk_attrs->hw_rev >= IRDMA_GEN_2) {
1245551c46edSMustafa Ismail if (sge > 1 || inline_data > 8) {
1246551c46edSMustafa Ismail if (sge < 4 && inline_data <= 39)
1247551c46edSMustafa Ismail *shift = 1;
1248551c46edSMustafa Ismail else if (sge < 8 && inline_data <= 101)
1249551c46edSMustafa Ismail *shift = 2;
1250551c46edSMustafa Ismail else
1251551c46edSMustafa Ismail *shift = 3;
1252551c46edSMustafa Ismail }
1253551c46edSMustafa Ismail } else if (sge > 1 || inline_data > 16) {
1254551c46edSMustafa Ismail *shift = (sge < 4 && inline_data <= 48) ? 1 : 2;
1255551c46edSMustafa Ismail }
1256551c46edSMustafa Ismail }
1257551c46edSMustafa Ismail
1258551c46edSMustafa Ismail /*
1259551c46edSMustafa Ismail * irdma_get_sqdepth - get SQ depth (quanta)
1260551c46edSMustafa Ismail * @uk_attrs: qp HW attributes
1261551c46edSMustafa Ismail * @sq_size: SQ size
1262551c46edSMustafa Ismail * @shift: shift which determines size of WQE
1263551c46edSMustafa Ismail * @sqdepth: depth of SQ
1264551c46edSMustafa Ismail *
1265551c46edSMustafa Ismail */
irdma_get_sqdepth(struct irdma_uk_attrs * uk_attrs,u32 sq_size,u8 shift,u32 * sqdepth)12662c4b14eaSShiraz Saleem int irdma_get_sqdepth(struct irdma_uk_attrs *uk_attrs, u32 sq_size, u8 shift,
12672c4b14eaSShiraz Saleem u32 *sqdepth)
1268551c46edSMustafa Ismail {
126972d422c2SSindhu Devale u32 min_size = (u32)uk_attrs->min_hw_wq_size << shift;
127072d422c2SSindhu Devale
1271551c46edSMustafa Ismail *sqdepth = irdma_qp_round_up((sq_size << shift) + IRDMA_SQ_RSVD);
1272551c46edSMustafa Ismail
127372d422c2SSindhu Devale if (*sqdepth < min_size)
127472d422c2SSindhu Devale *sqdepth = min_size;
1275551c46edSMustafa Ismail else if (*sqdepth > uk_attrs->max_hw_wq_quanta)
12762c4b14eaSShiraz Saleem return -EINVAL;
1277551c46edSMustafa Ismail
1278551c46edSMustafa Ismail return 0;
1279551c46edSMustafa Ismail }
1280551c46edSMustafa Ismail
1281551c46edSMustafa Ismail /*
1282551c46edSMustafa Ismail * irdma_get_rqdepth - get RQ depth (quanta)
1283551c46edSMustafa Ismail * @uk_attrs: qp HW attributes
1284551c46edSMustafa Ismail * @rq_size: RQ size
1285551c46edSMustafa Ismail * @shift: shift which determines size of WQE
1286551c46edSMustafa Ismail * @rqdepth: depth of RQ
1287551c46edSMustafa Ismail */
irdma_get_rqdepth(struct irdma_uk_attrs * uk_attrs,u32 rq_size,u8 shift,u32 * rqdepth)12882c4b14eaSShiraz Saleem int irdma_get_rqdepth(struct irdma_uk_attrs *uk_attrs, u32 rq_size, u8 shift,
12892c4b14eaSShiraz Saleem u32 *rqdepth)
1290551c46edSMustafa Ismail {
129172d422c2SSindhu Devale u32 min_size = (u32)uk_attrs->min_hw_wq_size << shift;
129272d422c2SSindhu Devale
1293551c46edSMustafa Ismail *rqdepth = irdma_qp_round_up((rq_size << shift) + IRDMA_RQ_RSVD);
1294551c46edSMustafa Ismail
129572d422c2SSindhu Devale if (*rqdepth < min_size)
129672d422c2SSindhu Devale *rqdepth = min_size;
1297551c46edSMustafa Ismail else if (*rqdepth > uk_attrs->max_hw_rq_quanta)
12982c4b14eaSShiraz Saleem return -EINVAL;
1299551c46edSMustafa Ismail
1300551c46edSMustafa Ismail return 0;
1301551c46edSMustafa Ismail }
1302551c46edSMustafa Ismail
1303551c46edSMustafa Ismail static const struct irdma_wqe_uk_ops iw_wqe_uk_ops = {
1304551c46edSMustafa Ismail .iw_copy_inline_data = irdma_copy_inline_data,
1305551c46edSMustafa Ismail .iw_inline_data_size_to_quanta = irdma_inline_data_size_to_quanta,
1306551c46edSMustafa Ismail .iw_set_fragment = irdma_set_fragment,
1307551c46edSMustafa Ismail .iw_set_mw_bind_wqe = irdma_set_mw_bind_wqe,
1308551c46edSMustafa Ismail };
1309551c46edSMustafa Ismail
1310551c46edSMustafa Ismail static const struct irdma_wqe_uk_ops iw_wqe_uk_ops_gen_1 = {
1311551c46edSMustafa Ismail .iw_copy_inline_data = irdma_copy_inline_data_gen_1,
1312551c46edSMustafa Ismail .iw_inline_data_size_to_quanta = irdma_inline_data_size_to_quanta_gen_1,
1313551c46edSMustafa Ismail .iw_set_fragment = irdma_set_fragment_gen_1,
1314551c46edSMustafa Ismail .iw_set_mw_bind_wqe = irdma_set_mw_bind_wqe_gen_1,
1315551c46edSMustafa Ismail };
1316551c46edSMustafa Ismail
1317551c46edSMustafa Ismail /**
1318551c46edSMustafa Ismail * irdma_setup_connection_wqes - setup WQEs necessary to complete
1319551c46edSMustafa Ismail * connection.
1320551c46edSMustafa Ismail * @qp: hw qp (user and kernel)
1321551c46edSMustafa Ismail * @info: qp initialization info
1322551c46edSMustafa Ismail */
irdma_setup_connection_wqes(struct irdma_qp_uk * qp,struct irdma_qp_uk_init_info * info)1323551c46edSMustafa Ismail static void irdma_setup_connection_wqes(struct irdma_qp_uk *qp,
1324551c46edSMustafa Ismail struct irdma_qp_uk_init_info *info)
1325551c46edSMustafa Ismail {
1326551c46edSMustafa Ismail u16 move_cnt = 1;
1327551c46edSMustafa Ismail
1328551c46edSMustafa Ismail if (!info->legacy_mode &&
1329551c46edSMustafa Ismail (qp->uk_attrs->feature_flags & IRDMA_FEATURE_RTS_AE))
1330551c46edSMustafa Ismail move_cnt = 3;
1331551c46edSMustafa Ismail
1332551c46edSMustafa Ismail qp->conn_wqes = move_cnt;
1333551c46edSMustafa Ismail IRDMA_RING_MOVE_HEAD_BY_COUNT_NOCHECK(qp->sq_ring, move_cnt);
1334551c46edSMustafa Ismail IRDMA_RING_MOVE_TAIL_BY_COUNT(qp->sq_ring, move_cnt);
1335551c46edSMustafa Ismail IRDMA_RING_MOVE_HEAD_BY_COUNT_NOCHECK(qp->initial_ring, move_cnt);
1336551c46edSMustafa Ismail }
1337551c46edSMustafa Ismail
1338551c46edSMustafa Ismail /**
13393a849872SSindhu Devale * irdma_uk_calc_shift_wq - calculate WQE shift for both SQ and RQ
13403a849872SSindhu Devale * @ukinfo: qp initialization info
13413a849872SSindhu Devale * @sq_shift: Returns shift of SQ
13423a849872SSindhu Devale * @rq_shift: Returns shift of RQ
13433a849872SSindhu Devale */
irdma_uk_calc_shift_wq(struct irdma_qp_uk_init_info * ukinfo,u8 * sq_shift,u8 * rq_shift)13443a849872SSindhu Devale void irdma_uk_calc_shift_wq(struct irdma_qp_uk_init_info *ukinfo, u8 *sq_shift,
13453a849872SSindhu Devale u8 *rq_shift)
13463a849872SSindhu Devale {
13473a849872SSindhu Devale bool imm_support = ukinfo->uk_attrs->hw_rev >= IRDMA_GEN_2;
13483a849872SSindhu Devale
13493a849872SSindhu Devale irdma_get_wqe_shift(ukinfo->uk_attrs,
13503a849872SSindhu Devale imm_support ? ukinfo->max_sq_frag_cnt + 1 :
13513a849872SSindhu Devale ukinfo->max_sq_frag_cnt,
13523a849872SSindhu Devale ukinfo->max_inline_data, sq_shift);
13533a849872SSindhu Devale
13543a849872SSindhu Devale irdma_get_wqe_shift(ukinfo->uk_attrs, ukinfo->max_rq_frag_cnt, 0,
13553a849872SSindhu Devale rq_shift);
13563a849872SSindhu Devale
13573a849872SSindhu Devale if (ukinfo->uk_attrs->hw_rev == IRDMA_GEN_1) {
13583a849872SSindhu Devale if (ukinfo->abi_ver > 4)
13593a849872SSindhu Devale *rq_shift = IRDMA_MAX_RQ_WQE_SHIFT_GEN1;
13603a849872SSindhu Devale }
13613a849872SSindhu Devale }
13623a849872SSindhu Devale
13633a849872SSindhu Devale /**
13643a849872SSindhu Devale * irdma_uk_calc_depth_shift_sq - calculate depth and shift for SQ size.
13653a849872SSindhu Devale * @ukinfo: qp initialization info
13663a849872SSindhu Devale * @sq_depth: Returns depth of SQ
13673a849872SSindhu Devale * @sq_shift: Returns shift of SQ
13683a849872SSindhu Devale */
irdma_uk_calc_depth_shift_sq(struct irdma_qp_uk_init_info * ukinfo,u32 * sq_depth,u8 * sq_shift)13693a849872SSindhu Devale int irdma_uk_calc_depth_shift_sq(struct irdma_qp_uk_init_info *ukinfo,
13703a849872SSindhu Devale u32 *sq_depth, u8 *sq_shift)
13713a849872SSindhu Devale {
13723a849872SSindhu Devale bool imm_support = ukinfo->uk_attrs->hw_rev >= IRDMA_GEN_2;
13733a849872SSindhu Devale int status;
13743a849872SSindhu Devale
13753a849872SSindhu Devale irdma_get_wqe_shift(ukinfo->uk_attrs,
13763a849872SSindhu Devale imm_support ? ukinfo->max_sq_frag_cnt + 1 :
13773a849872SSindhu Devale ukinfo->max_sq_frag_cnt,
13783a849872SSindhu Devale ukinfo->max_inline_data, sq_shift);
13793a849872SSindhu Devale status = irdma_get_sqdepth(ukinfo->uk_attrs, ukinfo->sq_size,
13803a849872SSindhu Devale *sq_shift, sq_depth);
13813a849872SSindhu Devale
13823a849872SSindhu Devale return status;
13833a849872SSindhu Devale }
13843a849872SSindhu Devale
13853a849872SSindhu Devale /**
13863a849872SSindhu Devale * irdma_uk_calc_depth_shift_rq - calculate depth and shift for RQ size.
13873a849872SSindhu Devale * @ukinfo: qp initialization info
13883a849872SSindhu Devale * @rq_depth: Returns depth of RQ
13893a849872SSindhu Devale * @rq_shift: Returns shift of RQ
13903a849872SSindhu Devale */
irdma_uk_calc_depth_shift_rq(struct irdma_qp_uk_init_info * ukinfo,u32 * rq_depth,u8 * rq_shift)13913a849872SSindhu Devale int irdma_uk_calc_depth_shift_rq(struct irdma_qp_uk_init_info *ukinfo,
13923a849872SSindhu Devale u32 *rq_depth, u8 *rq_shift)
13933a849872SSindhu Devale {
13943a849872SSindhu Devale int status;
13953a849872SSindhu Devale
13963a849872SSindhu Devale irdma_get_wqe_shift(ukinfo->uk_attrs, ukinfo->max_rq_frag_cnt, 0,
13973a849872SSindhu Devale rq_shift);
13983a849872SSindhu Devale
13993a849872SSindhu Devale if (ukinfo->uk_attrs->hw_rev == IRDMA_GEN_1) {
14003a849872SSindhu Devale if (ukinfo->abi_ver > 4)
14013a849872SSindhu Devale *rq_shift = IRDMA_MAX_RQ_WQE_SHIFT_GEN1;
14023a849872SSindhu Devale }
14033a849872SSindhu Devale
14043a849872SSindhu Devale status = irdma_get_rqdepth(ukinfo->uk_attrs, ukinfo->rq_size,
14053a849872SSindhu Devale *rq_shift, rq_depth);
14063a849872SSindhu Devale
14073a849872SSindhu Devale return status;
14083a849872SSindhu Devale }
14093a849872SSindhu Devale
14103a849872SSindhu Devale /**
1411551c46edSMustafa Ismail * irdma_uk_qp_init - initialize shared qp
1412551c46edSMustafa Ismail * @qp: hw qp (user and kernel)
1413551c46edSMustafa Ismail * @info: qp initialization info
1414551c46edSMustafa Ismail *
1415551c46edSMustafa Ismail * initializes the vars used in both user and kernel mode.
1416551c46edSMustafa Ismail * size of the wqe depends on numbers of max. fragements
1417551c46edSMustafa Ismail * allowed. Then size of wqe * the number of wqes should be the
1418551c46edSMustafa Ismail * amount of memory allocated for sq and rq.
1419551c46edSMustafa Ismail */
irdma_uk_qp_init(struct irdma_qp_uk * qp,struct irdma_qp_uk_init_info * info)14202c4b14eaSShiraz Saleem int irdma_uk_qp_init(struct irdma_qp_uk *qp, struct irdma_qp_uk_init_info *info)
1421551c46edSMustafa Ismail {
14222c4b14eaSShiraz Saleem int ret_code = 0;
1423551c46edSMustafa Ismail u32 sq_ring_size;
1424551c46edSMustafa Ismail
1425551c46edSMustafa Ismail qp->uk_attrs = info->uk_attrs;
1426551c46edSMustafa Ismail if (info->max_sq_frag_cnt > qp->uk_attrs->max_hw_wq_frags ||
1427551c46edSMustafa Ismail info->max_rq_frag_cnt > qp->uk_attrs->max_hw_wq_frags)
14282c4b14eaSShiraz Saleem return -EINVAL;
1429551c46edSMustafa Ismail
1430551c46edSMustafa Ismail qp->qp_caps = info->qp_caps;
1431551c46edSMustafa Ismail qp->sq_base = info->sq;
1432551c46edSMustafa Ismail qp->rq_base = info->rq;
1433551c46edSMustafa Ismail qp->qp_type = info->type ? info->type : IRDMA_QP_TYPE_IWARP;
1434551c46edSMustafa Ismail qp->shadow_area = info->shadow_area;
1435551c46edSMustafa Ismail qp->sq_wrtrk_array = info->sq_wrtrk_array;
1436551c46edSMustafa Ismail
1437551c46edSMustafa Ismail qp->rq_wrid_array = info->rq_wrid_array;
1438551c46edSMustafa Ismail qp->wqe_alloc_db = info->wqe_alloc_db;
1439551c46edSMustafa Ismail qp->qp_id = info->qp_id;
1440551c46edSMustafa Ismail qp->sq_size = info->sq_size;
1441551c46edSMustafa Ismail qp->max_sq_frag_cnt = info->max_sq_frag_cnt;
14423a849872SSindhu Devale sq_ring_size = qp->sq_size << info->sq_shift;
1443551c46edSMustafa Ismail IRDMA_RING_INIT(qp->sq_ring, sq_ring_size);
1444551c46edSMustafa Ismail IRDMA_RING_INIT(qp->initial_ring, sq_ring_size);
1445551c46edSMustafa Ismail if (info->first_sq_wq) {
1446551c46edSMustafa Ismail irdma_setup_connection_wqes(qp, info);
1447551c46edSMustafa Ismail qp->swqe_polarity = 1;
1448551c46edSMustafa Ismail qp->first_sq_wq = true;
1449551c46edSMustafa Ismail } else {
1450551c46edSMustafa Ismail qp->swqe_polarity = 0;
1451551c46edSMustafa Ismail }
1452551c46edSMustafa Ismail qp->swqe_polarity_deferred = 1;
1453551c46edSMustafa Ismail qp->rwqe_polarity = 0;
1454551c46edSMustafa Ismail qp->rq_size = info->rq_size;
1455551c46edSMustafa Ismail qp->max_rq_frag_cnt = info->max_rq_frag_cnt;
1456551c46edSMustafa Ismail qp->max_inline_data = info->max_inline_data;
14573a849872SSindhu Devale qp->rq_wqe_size = info->rq_shift;
1458551c46edSMustafa Ismail IRDMA_RING_INIT(qp->rq_ring, qp->rq_size);
14593a849872SSindhu Devale qp->rq_wqe_size_multiplier = 1 << info->rq_shift;
1460551c46edSMustafa Ismail if (qp->uk_attrs->hw_rev == IRDMA_GEN_1)
1461551c46edSMustafa Ismail qp->wqe_ops = iw_wqe_uk_ops_gen_1;
1462551c46edSMustafa Ismail else
1463551c46edSMustafa Ismail qp->wqe_ops = iw_wqe_uk_ops;
1464551c46edSMustafa Ismail return ret_code;
1465551c46edSMustafa Ismail }
1466551c46edSMustafa Ismail
1467551c46edSMustafa Ismail /**
1468551c46edSMustafa Ismail * irdma_uk_cq_init - initialize shared cq (user and kernel)
1469551c46edSMustafa Ismail * @cq: hw cq
1470551c46edSMustafa Ismail * @info: hw cq initialization info
1471551c46edSMustafa Ismail */
irdma_uk_cq_init(struct irdma_cq_uk * cq,struct irdma_cq_uk_init_info * info)1472dede33daSZhu Yanjun void irdma_uk_cq_init(struct irdma_cq_uk *cq,
1473551c46edSMustafa Ismail struct irdma_cq_uk_init_info *info)
1474551c46edSMustafa Ismail {
1475551c46edSMustafa Ismail cq->cq_base = info->cq_base;
1476551c46edSMustafa Ismail cq->cq_id = info->cq_id;
1477551c46edSMustafa Ismail cq->cq_size = info->cq_size;
1478551c46edSMustafa Ismail cq->cqe_alloc_db = info->cqe_alloc_db;
1479551c46edSMustafa Ismail cq->cq_ack_db = info->cq_ack_db;
1480551c46edSMustafa Ismail cq->shadow_area = info->shadow_area;
1481551c46edSMustafa Ismail cq->avoid_mem_cflct = info->avoid_mem_cflct;
1482551c46edSMustafa Ismail IRDMA_RING_INIT(cq->cq_ring, cq->cq_size);
1483551c46edSMustafa Ismail cq->polarity = 1;
1484551c46edSMustafa Ismail }
1485551c46edSMustafa Ismail
1486551c46edSMustafa Ismail /**
1487551c46edSMustafa Ismail * irdma_uk_clean_cq - clean cq entries
1488551c46edSMustafa Ismail * @q: completion context
1489551c46edSMustafa Ismail * @cq: cq to clean
1490551c46edSMustafa Ismail */
irdma_uk_clean_cq(void * q,struct irdma_cq_uk * cq)1491551c46edSMustafa Ismail void irdma_uk_clean_cq(void *q, struct irdma_cq_uk *cq)
1492551c46edSMustafa Ismail {
1493551c46edSMustafa Ismail __le64 *cqe;
1494551c46edSMustafa Ismail u64 qword3, comp_ctx;
1495551c46edSMustafa Ismail u32 cq_head;
1496551c46edSMustafa Ismail u8 polarity, temp;
1497551c46edSMustafa Ismail
1498551c46edSMustafa Ismail cq_head = cq->cq_ring.head;
1499551c46edSMustafa Ismail temp = cq->polarity;
1500551c46edSMustafa Ismail do {
1501551c46edSMustafa Ismail if (cq->avoid_mem_cflct)
1502551c46edSMustafa Ismail cqe = ((struct irdma_extended_cqe *)(cq->cq_base))[cq_head].buf;
1503551c46edSMustafa Ismail else
1504551c46edSMustafa Ismail cqe = cq->cq_base[cq_head].buf;
1505551c46edSMustafa Ismail get_64bit_val(cqe, 24, &qword3);
1506551c46edSMustafa Ismail polarity = (u8)FIELD_GET(IRDMA_CQ_VALID, qword3);
1507551c46edSMustafa Ismail
1508551c46edSMustafa Ismail if (polarity != temp)
1509551c46edSMustafa Ismail break;
1510551c46edSMustafa Ismail
15114984eb51SShiraz Saleem /* Ensure CQE contents are read after valid bit is checked */
15124984eb51SShiraz Saleem dma_rmb();
15134984eb51SShiraz Saleem
1514551c46edSMustafa Ismail get_64bit_val(cqe, 8, &comp_ctx);
1515551c46edSMustafa Ismail if ((void *)(unsigned long)comp_ctx == q)
1516551c46edSMustafa Ismail set_64bit_val(cqe, 8, 0);
1517551c46edSMustafa Ismail
1518551c46edSMustafa Ismail cq_head = (cq_head + 1) % cq->cq_ring.size;
1519551c46edSMustafa Ismail if (!cq_head)
1520551c46edSMustafa Ismail temp ^= 1;
1521551c46edSMustafa Ismail } while (true);
1522551c46edSMustafa Ismail }
1523551c46edSMustafa Ismail
1524551c46edSMustafa Ismail /**
1525551c46edSMustafa Ismail * irdma_nop - post a nop
1526551c46edSMustafa Ismail * @qp: hw qp ptr
1527551c46edSMustafa Ismail * @wr_id: work request id
1528551c46edSMustafa Ismail * @signaled: signaled for completion
1529551c46edSMustafa Ismail * @post_sq: ring doorbell
1530551c46edSMustafa Ismail */
irdma_nop(struct irdma_qp_uk * qp,u64 wr_id,bool signaled,bool post_sq)15312c4b14eaSShiraz Saleem int irdma_nop(struct irdma_qp_uk *qp, u64 wr_id, bool signaled, bool post_sq)
1532551c46edSMustafa Ismail {
1533551c46edSMustafa Ismail __le64 *wqe;
1534551c46edSMustafa Ismail u64 hdr;
1535551c46edSMustafa Ismail u32 wqe_idx;
1536551c46edSMustafa Ismail struct irdma_post_sq_info info = {};
1537551c46edSMustafa Ismail
1538551c46edSMustafa Ismail info.wr_id = wr_id;
1539551c46edSMustafa Ismail wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, IRDMA_QP_WQE_MIN_QUANTA,
1540551c46edSMustafa Ismail 0, &info);
1541551c46edSMustafa Ismail if (!wqe)
15422c4b14eaSShiraz Saleem return -ENOMEM;
1543551c46edSMustafa Ismail
1544551c46edSMustafa Ismail irdma_clr_wqes(qp, wqe_idx);
1545551c46edSMustafa Ismail
1546551c46edSMustafa Ismail set_64bit_val(wqe, 0, 0);
1547551c46edSMustafa Ismail set_64bit_val(wqe, 8, 0);
1548551c46edSMustafa Ismail set_64bit_val(wqe, 16, 0);
1549551c46edSMustafa Ismail
1550551c46edSMustafa Ismail hdr = FIELD_PREP(IRDMAQPSQ_OPCODE, IRDMAQP_OP_NOP) |
1551551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_SIGCOMPL, signaled) |
1552551c46edSMustafa Ismail FIELD_PREP(IRDMAQPSQ_VALID, qp->swqe_polarity);
1553551c46edSMustafa Ismail
1554551c46edSMustafa Ismail dma_wmb(); /* make sure WQE is populated before valid bit is set */
1555551c46edSMustafa Ismail
1556551c46edSMustafa Ismail set_64bit_val(wqe, 24, hdr);
1557551c46edSMustafa Ismail if (post_sq)
1558551c46edSMustafa Ismail irdma_uk_qp_post_wr(qp);
1559551c46edSMustafa Ismail
1560551c46edSMustafa Ismail return 0;
1561551c46edSMustafa Ismail }
1562551c46edSMustafa Ismail
1563551c46edSMustafa Ismail /**
1564551c46edSMustafa Ismail * irdma_fragcnt_to_quanta_sq - calculate quanta based on fragment count for SQ
1565551c46edSMustafa Ismail * @frag_cnt: number of fragments
1566551c46edSMustafa Ismail * @quanta: quanta for frag_cnt
1567551c46edSMustafa Ismail */
irdma_fragcnt_to_quanta_sq(u32 frag_cnt,u16 * quanta)15682c4b14eaSShiraz Saleem int irdma_fragcnt_to_quanta_sq(u32 frag_cnt, u16 *quanta)
1569551c46edSMustafa Ismail {
1570551c46edSMustafa Ismail switch (frag_cnt) {
1571551c46edSMustafa Ismail case 0:
1572551c46edSMustafa Ismail case 1:
1573551c46edSMustafa Ismail *quanta = IRDMA_QP_WQE_MIN_QUANTA;
1574551c46edSMustafa Ismail break;
1575551c46edSMustafa Ismail case 2:
1576551c46edSMustafa Ismail case 3:
1577551c46edSMustafa Ismail *quanta = 2;
1578551c46edSMustafa Ismail break;
1579551c46edSMustafa Ismail case 4:
1580551c46edSMustafa Ismail case 5:
1581551c46edSMustafa Ismail *quanta = 3;
1582551c46edSMustafa Ismail break;
1583551c46edSMustafa Ismail case 6:
1584551c46edSMustafa Ismail case 7:
1585551c46edSMustafa Ismail *quanta = 4;
1586551c46edSMustafa Ismail break;
1587551c46edSMustafa Ismail case 8:
1588551c46edSMustafa Ismail case 9:
1589551c46edSMustafa Ismail *quanta = 5;
1590551c46edSMustafa Ismail break;
1591551c46edSMustafa Ismail case 10:
1592551c46edSMustafa Ismail case 11:
1593551c46edSMustafa Ismail *quanta = 6;
1594551c46edSMustafa Ismail break;
1595551c46edSMustafa Ismail case 12:
1596551c46edSMustafa Ismail case 13:
1597551c46edSMustafa Ismail *quanta = 7;
1598551c46edSMustafa Ismail break;
1599551c46edSMustafa Ismail case 14:
1600551c46edSMustafa Ismail case 15: /* when immediate data is present */
1601551c46edSMustafa Ismail *quanta = 8;
1602551c46edSMustafa Ismail break;
1603551c46edSMustafa Ismail default:
16042c4b14eaSShiraz Saleem return -EINVAL;
1605551c46edSMustafa Ismail }
1606551c46edSMustafa Ismail
1607551c46edSMustafa Ismail return 0;
1608551c46edSMustafa Ismail }
1609551c46edSMustafa Ismail
1610551c46edSMustafa Ismail /**
1611551c46edSMustafa Ismail * irdma_fragcnt_to_wqesize_rq - calculate wqe size based on fragment count for RQ
1612551c46edSMustafa Ismail * @frag_cnt: number of fragments
1613551c46edSMustafa Ismail * @wqe_size: size in bytes given frag_cnt
1614551c46edSMustafa Ismail */
irdma_fragcnt_to_wqesize_rq(u32 frag_cnt,u16 * wqe_size)16152c4b14eaSShiraz Saleem int irdma_fragcnt_to_wqesize_rq(u32 frag_cnt, u16 *wqe_size)
1616551c46edSMustafa Ismail {
1617551c46edSMustafa Ismail switch (frag_cnt) {
1618551c46edSMustafa Ismail case 0:
1619551c46edSMustafa Ismail case 1:
1620551c46edSMustafa Ismail *wqe_size = 32;
1621551c46edSMustafa Ismail break;
1622551c46edSMustafa Ismail case 2:
1623551c46edSMustafa Ismail case 3:
1624551c46edSMustafa Ismail *wqe_size = 64;
1625551c46edSMustafa Ismail break;
1626551c46edSMustafa Ismail case 4:
1627551c46edSMustafa Ismail case 5:
1628551c46edSMustafa Ismail case 6:
1629551c46edSMustafa Ismail case 7:
1630551c46edSMustafa Ismail *wqe_size = 128;
1631551c46edSMustafa Ismail break;
1632551c46edSMustafa Ismail case 8:
1633551c46edSMustafa Ismail case 9:
1634551c46edSMustafa Ismail case 10:
1635551c46edSMustafa Ismail case 11:
1636551c46edSMustafa Ismail case 12:
1637551c46edSMustafa Ismail case 13:
1638551c46edSMustafa Ismail case 14:
1639551c46edSMustafa Ismail *wqe_size = 256;
1640551c46edSMustafa Ismail break;
1641551c46edSMustafa Ismail default:
16422c4b14eaSShiraz Saleem return -EINVAL;
1643551c46edSMustafa Ismail }
1644551c46edSMustafa Ismail
1645551c46edSMustafa Ismail return 0;
1646551c46edSMustafa Ismail }
1647