1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2015 - 2021 Intel Corporation */
9 * irdma_set_fragment - set fragment in wqe
10 * @wqe: wqe for setting fragment
11 * @offset: offset value
12 * @sge: sge length and stag
13 * @valid: The wqe valid
15 static void irdma_set_fragment(__le64
*wqe
, u32 offset
, struct ib_sge
*sge
,
19 set_64bit_val(wqe
, offset
,
20 FIELD_PREP(IRDMAQPSQ_FRAG_TO
, sge
->addr
));
21 set_64bit_val(wqe
, offset
+ 8,
22 FIELD_PREP(IRDMAQPSQ_VALID
, valid
) |
23 FIELD_PREP(IRDMAQPSQ_FRAG_LEN
, sge
->length
) |
24 FIELD_PREP(IRDMAQPSQ_FRAG_STAG
, sge
->lkey
));
26 set_64bit_val(wqe
, offset
, 0);
27 set_64bit_val(wqe
, offset
+ 8,
28 FIELD_PREP(IRDMAQPSQ_VALID
, valid
));
33 * irdma_set_fragment_gen_1 - set fragment in wqe
34 * @wqe: wqe for setting fragment
35 * @offset: offset value
36 * @sge: sge length and stag
37 * @valid: wqe valid flag
39 static void irdma_set_fragment_gen_1(__le64
*wqe
, u32 offset
,
40 struct ib_sge
*sge
, u8 valid
)
43 set_64bit_val(wqe
, offset
,
44 FIELD_PREP(IRDMAQPSQ_FRAG_TO
, sge
->addr
));
45 set_64bit_val(wqe
, offset
+ 8,
46 FIELD_PREP(IRDMAQPSQ_GEN1_FRAG_LEN
, sge
->length
) |
47 FIELD_PREP(IRDMAQPSQ_GEN1_FRAG_STAG
, sge
->lkey
));
49 set_64bit_val(wqe
, offset
, 0);
50 set_64bit_val(wqe
, offset
+ 8, 0);
55 * irdma_nop_1 - insert a NOP wqe
58 static int irdma_nop_1(struct irdma_qp_uk
*qp
)
63 bool signaled
= false;
65 if (!qp
->sq_ring
.head
)
68 wqe_idx
= IRDMA_RING_CURRENT_HEAD(qp
->sq_ring
);
69 wqe
= qp
->sq_base
[wqe_idx
].elem
;
71 qp
->sq_wrtrk_array
[wqe_idx
].quanta
= IRDMA_QP_WQE_MIN_QUANTA
;
73 set_64bit_val(wqe
, 0, 0);
74 set_64bit_val(wqe
, 8, 0);
75 set_64bit_val(wqe
, 16, 0);
77 hdr
= FIELD_PREP(IRDMAQPSQ_OPCODE
, IRDMAQP_OP_NOP
) |
78 FIELD_PREP(IRDMAQPSQ_SIGCOMPL
, signaled
) |
79 FIELD_PREP(IRDMAQPSQ_VALID
, qp
->swqe_polarity
);
81 /* make sure WQE is written before valid bit is set */
84 set_64bit_val(wqe
, 24, hdr
);
90 * irdma_clr_wqes - clear next 128 sq entries
92 * @qp_wqe_idx: wqe_idx
94 void irdma_clr_wqes(struct irdma_qp_uk
*qp
, u32 qp_wqe_idx
)
96 struct irdma_qp_quanta
*sq
;
99 if (!(qp_wqe_idx
& 0x7F)) {
100 wqe_idx
= (qp_wqe_idx
+ 128) % qp
->sq_ring
.size
;
101 sq
= qp
->sq_base
+ wqe_idx
;
103 memset(sq
, qp
->swqe_polarity
? 0 : 0xFF,
106 memset(sq
, qp
->swqe_polarity
? 0xFF : 0,
112 * irdma_uk_qp_post_wr - ring doorbell
115 void irdma_uk_qp_post_wr(struct irdma_qp_uk
*qp
)
121 /* valid bit is written and loads completed before reading shadow */
124 /* read the doorbell shadow area */
125 get_64bit_val(qp
->shadow_area
, 0, &temp
);
127 hw_sq_tail
= (u32
)FIELD_GET(IRDMA_QP_DBSA_HW_SQ_TAIL
, temp
);
128 sw_sq_head
= IRDMA_RING_CURRENT_HEAD(qp
->sq_ring
);
129 if (sw_sq_head
!= qp
->initial_ring
.head
) {
130 if (sw_sq_head
!= hw_sq_tail
) {
131 if (sw_sq_head
> qp
->initial_ring
.head
) {
132 if (hw_sq_tail
>= qp
->initial_ring
.head
&&
133 hw_sq_tail
< sw_sq_head
)
134 writel(qp
->qp_id
, qp
->wqe_alloc_db
);
136 if (hw_sq_tail
>= qp
->initial_ring
.head
||
137 hw_sq_tail
< sw_sq_head
)
138 writel(qp
->qp_id
, qp
->wqe_alloc_db
);
143 qp
->initial_ring
.head
= qp
->sq_ring
.head
;
147 * irdma_qp_get_next_send_wqe - pad with NOP if needed, return where next WR should go
149 * @wqe_idx: return wqe index
150 * @quanta: size of WR in quanta
151 * @total_size: size of WR in bytes
154 __le64
*irdma_qp_get_next_send_wqe(struct irdma_qp_uk
*qp
, u32
*wqe_idx
,
155 u16 quanta
, u32 total_size
,
156 struct irdma_post_sq_info
*info
)
159 __le64
*wqe_0
= NULL
;
163 avail_quanta
= qp
->uk_attrs
->max_hw_sq_chunk
-
164 (IRDMA_RING_CURRENT_HEAD(qp
->sq_ring
) %
165 qp
->uk_attrs
->max_hw_sq_chunk
);
166 if (quanta
<= avail_quanta
) {
167 /* WR fits in current chunk */
168 if (quanta
> IRDMA_SQ_RING_FREE_QUANTA(qp
->sq_ring
))
171 /* Need to pad with NOP */
172 if (quanta
+ avail_quanta
>
173 IRDMA_SQ_RING_FREE_QUANTA(qp
->sq_ring
))
176 for (i
= 0; i
< avail_quanta
; i
++) {
178 IRDMA_RING_MOVE_HEAD_NOCHECK(qp
->sq_ring
);
182 *wqe_idx
= IRDMA_RING_CURRENT_HEAD(qp
->sq_ring
);
184 qp
->swqe_polarity
= !qp
->swqe_polarity
;
186 IRDMA_RING_MOVE_HEAD_BY_COUNT_NOCHECK(qp
->sq_ring
, quanta
);
188 wqe
= qp
->sq_base
[*wqe_idx
].elem
;
189 if (qp
->uk_attrs
->hw_rev
== IRDMA_GEN_1
&& quanta
== 1 &&
190 (IRDMA_RING_CURRENT_HEAD(qp
->sq_ring
) & 1)) {
191 wqe_0
= qp
->sq_base
[IRDMA_RING_CURRENT_HEAD(qp
->sq_ring
)].elem
;
192 wqe_0
[3] = cpu_to_le64(FIELD_PREP(IRDMAQPSQ_VALID
, qp
->swqe_polarity
? 0 : 1));
194 qp
->sq_wrtrk_array
[*wqe_idx
].wrid
= info
->wr_id
;
195 qp
->sq_wrtrk_array
[*wqe_idx
].wr_len
= total_size
;
196 qp
->sq_wrtrk_array
[*wqe_idx
].quanta
= quanta
;
202 * irdma_qp_get_next_recv_wqe - get next qp's rcv wqe
204 * @wqe_idx: return wqe index
206 __le64
*irdma_qp_get_next_recv_wqe(struct irdma_qp_uk
*qp
, u32
*wqe_idx
)
211 if (IRDMA_RING_FULL_ERR(qp
->rq_ring
))
214 IRDMA_ATOMIC_RING_MOVE_HEAD(qp
->rq_ring
, *wqe_idx
, ret_code
);
219 qp
->rwqe_polarity
= !qp
->rwqe_polarity
;
220 /* rq_wqe_size_multiplier is no of 32 byte quanta in one rq wqe */
221 wqe
= qp
->rq_base
[*wqe_idx
* qp
->rq_wqe_size_multiplier
].elem
;
227 * irdma_uk_rdma_write - rdma write operation
229 * @info: post sq information
230 * @post_sq: flag to post sq
232 int irdma_uk_rdma_write(struct irdma_qp_uk
*qp
, struct irdma_post_sq_info
*info
,
237 struct irdma_rdma_write
*op_info
;
239 u32 total_size
= 0, byte_off
;
241 u32 frag_cnt
, addl_frag_cnt
;
242 bool read_fence
= false;
245 op_info
= &info
->op
.rdma_write
;
246 if (op_info
->num_lo_sges
> qp
->max_sq_frag_cnt
)
249 for (i
= 0; i
< op_info
->num_lo_sges
; i
++)
250 total_size
+= op_info
->lo_sg_list
[i
].length
;
252 read_fence
|= info
->read_fence
;
254 if (info
->imm_data_valid
)
255 frag_cnt
= op_info
->num_lo_sges
+ 1;
257 frag_cnt
= op_info
->num_lo_sges
;
258 addl_frag_cnt
= frag_cnt
> 1 ? (frag_cnt
- 1) : 0;
259 ret_code
= irdma_fragcnt_to_quanta_sq(frag_cnt
, &quanta
);
263 wqe
= irdma_qp_get_next_send_wqe(qp
, &wqe_idx
, quanta
, total_size
,
268 irdma_clr_wqes(qp
, wqe_idx
);
270 set_64bit_val(wqe
, 16,
271 FIELD_PREP(IRDMAQPSQ_FRAG_TO
, op_info
->rem_addr
.addr
));
273 if (info
->imm_data_valid
) {
274 set_64bit_val(wqe
, 0,
275 FIELD_PREP(IRDMAQPSQ_IMMDATA
, info
->imm_data
));
278 qp
->wqe_ops
.iw_set_fragment(wqe
, 0,
284 for (byte_off
= 32; i
< op_info
->num_lo_sges
; i
++) {
285 qp
->wqe_ops
.iw_set_fragment(wqe
, byte_off
,
286 &op_info
->lo_sg_list
[i
],
291 /* if not an odd number set valid bit in next fragment */
292 if (qp
->uk_attrs
->hw_rev
>= IRDMA_GEN_2
&& !(frag_cnt
& 0x01) &&
294 qp
->wqe_ops
.iw_set_fragment(wqe
, byte_off
, NULL
,
296 if (qp
->uk_attrs
->hw_rev
== IRDMA_GEN_2
)
300 hdr
= FIELD_PREP(IRDMAQPSQ_REMSTAG
, op_info
->rem_addr
.lkey
) |
301 FIELD_PREP(IRDMAQPSQ_OPCODE
, info
->op_type
) |
302 FIELD_PREP(IRDMAQPSQ_IMMDATAFLAG
, info
->imm_data_valid
) |
303 FIELD_PREP(IRDMAQPSQ_REPORTRTT
, info
->report_rtt
) |
304 FIELD_PREP(IRDMAQPSQ_ADDFRAGCNT
, addl_frag_cnt
) |
305 FIELD_PREP(IRDMAQPSQ_READFENCE
, read_fence
) |
306 FIELD_PREP(IRDMAQPSQ_LOCALFENCE
, info
->local_fence
) |
307 FIELD_PREP(IRDMAQPSQ_SIGCOMPL
, info
->signaled
) |
308 FIELD_PREP(IRDMAQPSQ_VALID
, qp
->swqe_polarity
);
310 dma_wmb(); /* make sure WQE is populated before valid bit is set */
312 set_64bit_val(wqe
, 24, hdr
);
315 irdma_uk_qp_post_wr(qp
);
321 * irdma_uk_rdma_read - rdma read command
323 * @info: post sq information
324 * @inv_stag: flag for inv_stag
325 * @post_sq: flag to post sq
327 int irdma_uk_rdma_read(struct irdma_qp_uk
*qp
, struct irdma_post_sq_info
*info
,
328 bool inv_stag
, bool post_sq
)
330 struct irdma_rdma_read
*op_info
;
332 u32 i
, byte_off
, total_size
= 0;
333 bool local_fence
= false;
340 op_info
= &info
->op
.rdma_read
;
341 if (qp
->max_sq_frag_cnt
< op_info
->num_lo_sges
)
344 for (i
= 0; i
< op_info
->num_lo_sges
; i
++)
345 total_size
+= op_info
->lo_sg_list
[i
].length
;
347 ret_code
= irdma_fragcnt_to_quanta_sq(op_info
->num_lo_sges
, &quanta
);
351 wqe
= irdma_qp_get_next_send_wqe(qp
, &wqe_idx
, quanta
, total_size
,
356 irdma_clr_wqes(qp
, wqe_idx
);
358 addl_frag_cnt
= op_info
->num_lo_sges
> 1 ?
359 (op_info
->num_lo_sges
- 1) : 0;
360 local_fence
|= info
->local_fence
;
362 qp
->wqe_ops
.iw_set_fragment(wqe
, 0, op_info
->lo_sg_list
,
364 for (i
= 1, byte_off
= 32; i
< op_info
->num_lo_sges
; ++i
) {
365 qp
->wqe_ops
.iw_set_fragment(wqe
, byte_off
,
366 &op_info
->lo_sg_list
[i
],
371 /* if not an odd number set valid bit in next fragment */
372 if (qp
->uk_attrs
->hw_rev
>= IRDMA_GEN_2
&&
373 !(op_info
->num_lo_sges
& 0x01) && op_info
->num_lo_sges
) {
374 qp
->wqe_ops
.iw_set_fragment(wqe
, byte_off
, NULL
,
376 if (qp
->uk_attrs
->hw_rev
== IRDMA_GEN_2
)
379 set_64bit_val(wqe
, 16,
380 FIELD_PREP(IRDMAQPSQ_FRAG_TO
, op_info
->rem_addr
.addr
));
381 hdr
= FIELD_PREP(IRDMAQPSQ_REMSTAG
, op_info
->rem_addr
.lkey
) |
382 FIELD_PREP(IRDMAQPSQ_REPORTRTT
, (info
->report_rtt
? 1 : 0)) |
383 FIELD_PREP(IRDMAQPSQ_ADDFRAGCNT
, addl_frag_cnt
) |
384 FIELD_PREP(IRDMAQPSQ_OPCODE
,
385 (inv_stag
? IRDMAQP_OP_RDMA_READ_LOC_INV
: IRDMAQP_OP_RDMA_READ
)) |
386 FIELD_PREP(IRDMAQPSQ_READFENCE
, info
->read_fence
) |
387 FIELD_PREP(IRDMAQPSQ_LOCALFENCE
, local_fence
) |
388 FIELD_PREP(IRDMAQPSQ_SIGCOMPL
, info
->signaled
) |
389 FIELD_PREP(IRDMAQPSQ_VALID
, qp
->swqe_polarity
);
391 dma_wmb(); /* make sure WQE is populated before valid bit is set */
393 set_64bit_val(wqe
, 24, hdr
);
396 irdma_uk_qp_post_wr(qp
);
402 * irdma_uk_send - rdma send command
404 * @info: post sq information
405 * @post_sq: flag to post sq
407 int irdma_uk_send(struct irdma_qp_uk
*qp
, struct irdma_post_sq_info
*info
,
411 struct irdma_post_send
*op_info
;
413 u32 i
, wqe_idx
, total_size
= 0, byte_off
;
415 u32 frag_cnt
, addl_frag_cnt
;
416 bool read_fence
= false;
419 op_info
= &info
->op
.send
;
420 if (qp
->max_sq_frag_cnt
< op_info
->num_sges
)
423 for (i
= 0; i
< op_info
->num_sges
; i
++)
424 total_size
+= op_info
->sg_list
[i
].length
;
426 if (info
->imm_data_valid
)
427 frag_cnt
= op_info
->num_sges
+ 1;
429 frag_cnt
= op_info
->num_sges
;
430 ret_code
= irdma_fragcnt_to_quanta_sq(frag_cnt
, &quanta
);
434 wqe
= irdma_qp_get_next_send_wqe(qp
, &wqe_idx
, quanta
, total_size
,
439 irdma_clr_wqes(qp
, wqe_idx
);
441 read_fence
|= info
->read_fence
;
442 addl_frag_cnt
= frag_cnt
> 1 ? (frag_cnt
- 1) : 0;
443 if (info
->imm_data_valid
) {
444 set_64bit_val(wqe
, 0,
445 FIELD_PREP(IRDMAQPSQ_IMMDATA
, info
->imm_data
));
448 qp
->wqe_ops
.iw_set_fragment(wqe
, 0,
449 frag_cnt
? op_info
->sg_list
: NULL
,
454 for (byte_off
= 32; i
< op_info
->num_sges
; i
++) {
455 qp
->wqe_ops
.iw_set_fragment(wqe
, byte_off
, &op_info
->sg_list
[i
],
460 /* if not an odd number set valid bit in next fragment */
461 if (qp
->uk_attrs
->hw_rev
>= IRDMA_GEN_2
&& !(frag_cnt
& 0x01) &&
463 qp
->wqe_ops
.iw_set_fragment(wqe
, byte_off
, NULL
,
465 if (qp
->uk_attrs
->hw_rev
== IRDMA_GEN_2
)
469 set_64bit_val(wqe
, 16,
470 FIELD_PREP(IRDMAQPSQ_DESTQKEY
, op_info
->qkey
) |
471 FIELD_PREP(IRDMAQPSQ_DESTQPN
, op_info
->dest_qp
));
472 hdr
= FIELD_PREP(IRDMAQPSQ_REMSTAG
, info
->stag_to_inv
) |
473 FIELD_PREP(IRDMAQPSQ_AHID
, op_info
->ah_id
) |
474 FIELD_PREP(IRDMAQPSQ_IMMDATAFLAG
,
475 (info
->imm_data_valid
? 1 : 0)) |
476 FIELD_PREP(IRDMAQPSQ_REPORTRTT
, (info
->report_rtt
? 1 : 0)) |
477 FIELD_PREP(IRDMAQPSQ_OPCODE
, info
->op_type
) |
478 FIELD_PREP(IRDMAQPSQ_ADDFRAGCNT
, addl_frag_cnt
) |
479 FIELD_PREP(IRDMAQPSQ_READFENCE
, read_fence
) |
480 FIELD_PREP(IRDMAQPSQ_LOCALFENCE
, info
->local_fence
) |
481 FIELD_PREP(IRDMAQPSQ_SIGCOMPL
, info
->signaled
) |
482 FIELD_PREP(IRDMAQPSQ_UDPHEADER
, info
->udp_hdr
) |
483 FIELD_PREP(IRDMAQPSQ_L4LEN
, info
->l4len
) |
484 FIELD_PREP(IRDMAQPSQ_VALID
, qp
->swqe_polarity
);
486 dma_wmb(); /* make sure WQE is populated before valid bit is set */
488 set_64bit_val(wqe
, 24, hdr
);
491 irdma_uk_qp_post_wr(qp
);
497 * irdma_set_mw_bind_wqe_gen_1 - set mw bind wqe
498 * @wqe: wqe for setting fragment
499 * @op_info: info for setting bind wqe values
501 static void irdma_set_mw_bind_wqe_gen_1(__le64
*wqe
,
502 struct irdma_bind_window
*op_info
)
504 set_64bit_val(wqe
, 0, (uintptr_t)op_info
->va
);
505 set_64bit_val(wqe
, 8,
506 FIELD_PREP(IRDMAQPSQ_PARENTMRSTAG
, op_info
->mw_stag
) |
507 FIELD_PREP(IRDMAQPSQ_MWSTAG
, op_info
->mr_stag
));
508 set_64bit_val(wqe
, 16, op_info
->bind_len
);
512 * irdma_copy_inline_data_gen_1 - Copy inline data to wqe
513 * @wqe: pointer to wqe
514 * @sge_list: table of pointers to inline data
515 * @num_sges: Total inline data length
516 * @polarity: compatibility parameter
518 static void irdma_copy_inline_data_gen_1(u8
*wqe
, struct ib_sge
*sge_list
,
519 u32 num_sges
, u8 polarity
)
521 u32 quanta_bytes_remaining
= 16;
524 for (i
= 0; i
< num_sges
; i
++) {
525 u8
*cur_sge
= (u8
*)(uintptr_t)sge_list
[i
].addr
;
526 u32 sge_len
= sge_list
[i
].length
;
531 bytes_copied
= min(sge_len
, quanta_bytes_remaining
);
532 memcpy(wqe
, cur_sge
, bytes_copied
);
534 cur_sge
+= bytes_copied
;
535 quanta_bytes_remaining
-= bytes_copied
;
536 sge_len
-= bytes_copied
;
538 if (!quanta_bytes_remaining
) {
539 /* Remaining inline bytes reside after hdr */
541 quanta_bytes_remaining
= 32;
548 * irdma_inline_data_size_to_quanta_gen_1 - based on inline data, quanta
549 * @data_size: data size for inline
551 * Gets the quanta based on inline and immediate data.
553 static inline u16
irdma_inline_data_size_to_quanta_gen_1(u32 data_size
)
555 return data_size
<= 16 ? IRDMA_QP_WQE_MIN_QUANTA
: 2;
559 * irdma_set_mw_bind_wqe - set mw bind in wqe
560 * @wqe: wqe for setting mw bind
561 * @op_info: info for setting wqe values
563 static void irdma_set_mw_bind_wqe(__le64
*wqe
,
564 struct irdma_bind_window
*op_info
)
566 set_64bit_val(wqe
, 0, (uintptr_t)op_info
->va
);
567 set_64bit_val(wqe
, 8,
568 FIELD_PREP(IRDMAQPSQ_PARENTMRSTAG
, op_info
->mr_stag
) |
569 FIELD_PREP(IRDMAQPSQ_MWSTAG
, op_info
->mw_stag
));
570 set_64bit_val(wqe
, 16, op_info
->bind_len
);
574 * irdma_copy_inline_data - Copy inline data to wqe
575 * @wqe: pointer to wqe
576 * @sge_list: table of pointers to inline data
577 * @num_sges: number of SGE's
578 * @polarity: polarity of wqe valid bit
580 static void irdma_copy_inline_data(u8
*wqe
, struct ib_sge
*sge_list
,
581 u32 num_sges
, u8 polarity
)
583 u8 inline_valid
= polarity
<< IRDMA_INLINE_VALID_S
;
584 u32 quanta_bytes_remaining
= 8;
585 bool first_quanta
= true;
590 for (i
= 0; i
< num_sges
; i
++) {
591 u8
*cur_sge
= (u8
*)(uintptr_t)sge_list
[i
].addr
;
592 u32 sge_len
= sge_list
[i
].length
;
597 bytes_copied
= min(sge_len
, quanta_bytes_remaining
);
598 memcpy(wqe
, cur_sge
, bytes_copied
);
600 cur_sge
+= bytes_copied
;
601 quanta_bytes_remaining
-= bytes_copied
;
602 sge_len
-= bytes_copied
;
604 if (!quanta_bytes_remaining
) {
605 quanta_bytes_remaining
= 31;
607 /* Remaining inline bytes reside after hdr */
609 first_quanta
= false;
618 if (!first_quanta
&& quanta_bytes_remaining
< 31)
619 *(wqe
+ quanta_bytes_remaining
) = inline_valid
;
623 * irdma_inline_data_size_to_quanta - based on inline data, quanta
624 * @data_size: data size for inline
626 * Gets the quanta based on inline and immediate data.
628 static u16
irdma_inline_data_size_to_quanta(u32 data_size
)
631 return IRDMA_QP_WQE_MIN_QUANTA
;
632 else if (data_size
<= 39)
634 else if (data_size
<= 70)
636 else if (data_size
<= 101)
638 else if (data_size
<= 132)
640 else if (data_size
<= 163)
642 else if (data_size
<= 194)
649 * irdma_uk_inline_rdma_write - inline rdma write operation
651 * @info: post sq information
652 * @post_sq: flag to post sq
654 int irdma_uk_inline_rdma_write(struct irdma_qp_uk
*qp
,
655 struct irdma_post_sq_info
*info
, bool post_sq
)
658 struct irdma_rdma_write
*op_info
;
661 bool read_fence
= false;
662 u32 i
, total_size
= 0;
665 op_info
= &info
->op
.rdma_write
;
667 if (unlikely(qp
->max_sq_frag_cnt
< op_info
->num_lo_sges
))
670 for (i
= 0; i
< op_info
->num_lo_sges
; i
++)
671 total_size
+= op_info
->lo_sg_list
[i
].length
;
673 if (unlikely(total_size
> qp
->max_inline_data
))
676 quanta
= qp
->wqe_ops
.iw_inline_data_size_to_quanta(total_size
);
677 wqe
= irdma_qp_get_next_send_wqe(qp
, &wqe_idx
, quanta
, total_size
,
682 irdma_clr_wqes(qp
, wqe_idx
);
684 read_fence
|= info
->read_fence
;
685 set_64bit_val(wqe
, 16,
686 FIELD_PREP(IRDMAQPSQ_FRAG_TO
, op_info
->rem_addr
.addr
));
688 hdr
= FIELD_PREP(IRDMAQPSQ_REMSTAG
, op_info
->rem_addr
.lkey
) |
689 FIELD_PREP(IRDMAQPSQ_OPCODE
, info
->op_type
) |
690 FIELD_PREP(IRDMAQPSQ_INLINEDATALEN
, total_size
) |
691 FIELD_PREP(IRDMAQPSQ_REPORTRTT
, info
->report_rtt
? 1 : 0) |
692 FIELD_PREP(IRDMAQPSQ_INLINEDATAFLAG
, 1) |
693 FIELD_PREP(IRDMAQPSQ_IMMDATAFLAG
, info
->imm_data_valid
? 1 : 0) |
694 FIELD_PREP(IRDMAQPSQ_READFENCE
, read_fence
) |
695 FIELD_PREP(IRDMAQPSQ_LOCALFENCE
, info
->local_fence
) |
696 FIELD_PREP(IRDMAQPSQ_SIGCOMPL
, info
->signaled
) |
697 FIELD_PREP(IRDMAQPSQ_VALID
, qp
->swqe_polarity
);
699 if (info
->imm_data_valid
)
700 set_64bit_val(wqe
, 0,
701 FIELD_PREP(IRDMAQPSQ_IMMDATA
, info
->imm_data
));
703 qp
->wqe_ops
.iw_copy_inline_data((u8
*)wqe
, op_info
->lo_sg_list
,
704 op_info
->num_lo_sges
,
706 dma_wmb(); /* make sure WQE is populated before valid bit is set */
708 set_64bit_val(wqe
, 24, hdr
);
711 irdma_uk_qp_post_wr(qp
);
717 * irdma_uk_inline_send - inline send operation
719 * @info: post sq information
720 * @post_sq: flag to post sq
722 int irdma_uk_inline_send(struct irdma_qp_uk
*qp
,
723 struct irdma_post_sq_info
*info
, bool post_sq
)
726 struct irdma_post_send
*op_info
;
729 bool read_fence
= false;
730 u32 i
, total_size
= 0;
733 op_info
= &info
->op
.send
;
735 if (unlikely(qp
->max_sq_frag_cnt
< op_info
->num_sges
))
738 for (i
= 0; i
< op_info
->num_sges
; i
++)
739 total_size
+= op_info
->sg_list
[i
].length
;
741 if (unlikely(total_size
> qp
->max_inline_data
))
744 quanta
= qp
->wqe_ops
.iw_inline_data_size_to_quanta(total_size
);
745 wqe
= irdma_qp_get_next_send_wqe(qp
, &wqe_idx
, quanta
, total_size
,
750 irdma_clr_wqes(qp
, wqe_idx
);
752 set_64bit_val(wqe
, 16,
753 FIELD_PREP(IRDMAQPSQ_DESTQKEY
, op_info
->qkey
) |
754 FIELD_PREP(IRDMAQPSQ_DESTQPN
, op_info
->dest_qp
));
756 read_fence
|= info
->read_fence
;
757 hdr
= FIELD_PREP(IRDMAQPSQ_REMSTAG
, info
->stag_to_inv
) |
758 FIELD_PREP(IRDMAQPSQ_AHID
, op_info
->ah_id
) |
759 FIELD_PREP(IRDMAQPSQ_OPCODE
, info
->op_type
) |
760 FIELD_PREP(IRDMAQPSQ_INLINEDATALEN
, total_size
) |
761 FIELD_PREP(IRDMAQPSQ_IMMDATAFLAG
,
762 (info
->imm_data_valid
? 1 : 0)) |
763 FIELD_PREP(IRDMAQPSQ_REPORTRTT
, (info
->report_rtt
? 1 : 0)) |
764 FIELD_PREP(IRDMAQPSQ_INLINEDATAFLAG
, 1) |
765 FIELD_PREP(IRDMAQPSQ_READFENCE
, read_fence
) |
766 FIELD_PREP(IRDMAQPSQ_LOCALFENCE
, info
->local_fence
) |
767 FIELD_PREP(IRDMAQPSQ_SIGCOMPL
, info
->signaled
) |
768 FIELD_PREP(IRDMAQPSQ_UDPHEADER
, info
->udp_hdr
) |
769 FIELD_PREP(IRDMAQPSQ_L4LEN
, info
->l4len
) |
770 FIELD_PREP(IRDMAQPSQ_VALID
, qp
->swqe_polarity
);
772 if (info
->imm_data_valid
)
773 set_64bit_val(wqe
, 0,
774 FIELD_PREP(IRDMAQPSQ_IMMDATA
, info
->imm_data
));
775 qp
->wqe_ops
.iw_copy_inline_data((u8
*)wqe
, op_info
->sg_list
,
776 op_info
->num_sges
, qp
->swqe_polarity
);
778 dma_wmb(); /* make sure WQE is populated before valid bit is set */
780 set_64bit_val(wqe
, 24, hdr
);
783 irdma_uk_qp_post_wr(qp
);
789 * irdma_uk_stag_local_invalidate - stag invalidate operation
791 * @info: post sq information
792 * @post_sq: flag to post sq
794 int irdma_uk_stag_local_invalidate(struct irdma_qp_uk
*qp
,
795 struct irdma_post_sq_info
*info
,
799 struct irdma_inv_local_stag
*op_info
;
802 bool local_fence
= false;
803 struct ib_sge sge
= {};
805 op_info
= &info
->op
.inv_local_stag
;
806 local_fence
= info
->local_fence
;
808 wqe
= irdma_qp_get_next_send_wqe(qp
, &wqe_idx
, IRDMA_QP_WQE_MIN_QUANTA
,
813 irdma_clr_wqes(qp
, wqe_idx
);
815 sge
.lkey
= op_info
->target_stag
;
816 qp
->wqe_ops
.iw_set_fragment(wqe
, 0, &sge
, 0);
818 set_64bit_val(wqe
, 16, 0);
820 hdr
= FIELD_PREP(IRDMAQPSQ_OPCODE
, IRDMA_OP_TYPE_INV_STAG
) |
821 FIELD_PREP(IRDMAQPSQ_READFENCE
, info
->read_fence
) |
822 FIELD_PREP(IRDMAQPSQ_LOCALFENCE
, local_fence
) |
823 FIELD_PREP(IRDMAQPSQ_SIGCOMPL
, info
->signaled
) |
824 FIELD_PREP(IRDMAQPSQ_VALID
, qp
->swqe_polarity
);
826 dma_wmb(); /* make sure WQE is populated before valid bit is set */
828 set_64bit_val(wqe
, 24, hdr
);
831 irdma_uk_qp_post_wr(qp
);
837 * irdma_uk_post_receive - post receive wqe
839 * @info: post rq information
841 int irdma_uk_post_receive(struct irdma_qp_uk
*qp
,
842 struct irdma_post_rq_info
*info
)
844 u32 wqe_idx
, i
, byte_off
;
849 if (qp
->max_rq_frag_cnt
< info
->num_sges
)
852 wqe
= irdma_qp_get_next_recv_wqe(qp
, &wqe_idx
);
856 qp
->rq_wrid_array
[wqe_idx
] = info
->wr_id
;
857 addl_frag_cnt
= info
->num_sges
> 1 ? (info
->num_sges
- 1) : 0;
858 qp
->wqe_ops
.iw_set_fragment(wqe
, 0, info
->sg_list
,
861 for (i
= 1, byte_off
= 32; i
< info
->num_sges
; i
++) {
862 qp
->wqe_ops
.iw_set_fragment(wqe
, byte_off
, &info
->sg_list
[i
],
867 /* if not an odd number set valid bit in next fragment */
868 if (qp
->uk_attrs
->hw_rev
>= IRDMA_GEN_2
&& !(info
->num_sges
& 0x01) &&
870 qp
->wqe_ops
.iw_set_fragment(wqe
, byte_off
, NULL
,
872 if (qp
->uk_attrs
->hw_rev
== IRDMA_GEN_2
)
876 set_64bit_val(wqe
, 16, 0);
877 hdr
= FIELD_PREP(IRDMAQPSQ_ADDFRAGCNT
, addl_frag_cnt
) |
878 FIELD_PREP(IRDMAQPSQ_VALID
, qp
->rwqe_polarity
);
880 dma_wmb(); /* make sure WQE is populated before valid bit is set */
882 set_64bit_val(wqe
, 24, hdr
);
888 * irdma_uk_cq_resize - reset the cq buffer info
890 * @cq_base: new cq buffer addr
891 * @cq_size: number of cqes
893 void irdma_uk_cq_resize(struct irdma_cq_uk
*cq
, void *cq_base
, int cq_size
)
895 cq
->cq_base
= cq_base
;
896 cq
->cq_size
= cq_size
;
897 IRDMA_RING_INIT(cq
->cq_ring
, cq
->cq_size
);
902 * irdma_uk_cq_set_resized_cnt - record the count of the resized buffers
904 * @cq_cnt: the count of the resized cq buffers
906 void irdma_uk_cq_set_resized_cnt(struct irdma_cq_uk
*cq
, u16 cq_cnt
)
914 get_64bit_val(cq
->shadow_area
, 32, &temp_val
);
916 sw_cq_sel
= (u16
)FIELD_GET(IRDMA_CQ_DBSA_SW_CQ_SELECT
, temp_val
);
919 arm_seq_num
= (u8
)FIELD_GET(IRDMA_CQ_DBSA_ARM_SEQ_NUM
, temp_val
);
920 arm_next_se
= (u8
)FIELD_GET(IRDMA_CQ_DBSA_ARM_NEXT_SE
, temp_val
);
921 arm_next
= (u8
)FIELD_GET(IRDMA_CQ_DBSA_ARM_NEXT
, temp_val
);
923 temp_val
= FIELD_PREP(IRDMA_CQ_DBSA_ARM_SEQ_NUM
, arm_seq_num
) |
924 FIELD_PREP(IRDMA_CQ_DBSA_SW_CQ_SELECT
, sw_cq_sel
) |
925 FIELD_PREP(IRDMA_CQ_DBSA_ARM_NEXT_SE
, arm_next_se
) |
926 FIELD_PREP(IRDMA_CQ_DBSA_ARM_NEXT
, arm_next
);
928 set_64bit_val(cq
->shadow_area
, 32, temp_val
);
932 * irdma_uk_cq_request_notification - cq notification request (door bell)
934 * @cq_notify: notification type
936 void irdma_uk_cq_request_notification(struct irdma_cq_uk
*cq
,
937 enum irdma_cmpl_notify cq_notify
)
945 get_64bit_val(cq
->shadow_area
, 32, &temp_val
);
946 arm_seq_num
= (u8
)FIELD_GET(IRDMA_CQ_DBSA_ARM_SEQ_NUM
, temp_val
);
948 sw_cq_sel
= (u16
)FIELD_GET(IRDMA_CQ_DBSA_SW_CQ_SELECT
, temp_val
);
949 arm_next_se
= (u8
)FIELD_GET(IRDMA_CQ_DBSA_ARM_NEXT_SE
, temp_val
);
951 if (cq_notify
== IRDMA_CQ_COMPL_EVENT
)
953 temp_val
= FIELD_PREP(IRDMA_CQ_DBSA_ARM_SEQ_NUM
, arm_seq_num
) |
954 FIELD_PREP(IRDMA_CQ_DBSA_SW_CQ_SELECT
, sw_cq_sel
) |
955 FIELD_PREP(IRDMA_CQ_DBSA_ARM_NEXT_SE
, arm_next_se
) |
956 FIELD_PREP(IRDMA_CQ_DBSA_ARM_NEXT
, arm_next
);
958 set_64bit_val(cq
->shadow_area
, 32, temp_val
);
960 dma_wmb(); /* make sure WQE is populated before valid bit is set */
962 writel(cq
->cq_id
, cq
->cqe_alloc_db
);
966 * irdma_uk_cq_poll_cmpl - get cq completion info
968 * @info: cq poll information returned
970 int irdma_uk_cq_poll_cmpl(struct irdma_cq_uk
*cq
,
971 struct irdma_cq_poll_info
*info
)
973 u64 comp_ctx
, qword0
, qword2
, qword3
;
975 struct irdma_qp_uk
*qp
;
976 struct irdma_ring
*pring
= NULL
;
979 bool move_cq_head
= true;
984 if (cq
->avoid_mem_cflct
)
985 cqe
= IRDMA_GET_CURRENT_EXTENDED_CQ_ELEM(cq
);
987 cqe
= IRDMA_GET_CURRENT_CQ_ELEM(cq
);
989 get_64bit_val(cqe
, 24, &qword3
);
990 polarity
= (u8
)FIELD_GET(IRDMA_CQ_VALID
, qword3
);
991 if (polarity
!= cq
->polarity
)
994 /* Ensure CQE contents are read after valid bit is checked */
997 ext_valid
= (bool)FIELD_GET(IRDMA_CQ_EXTCQE
, qword3
);
1002 if (cq
->avoid_mem_cflct
) {
1003 ext_cqe
= (__le64
*)((u8
*)cqe
+ 32);
1004 get_64bit_val(ext_cqe
, 24, &qword7
);
1005 polarity
= (u8
)FIELD_GET(IRDMA_CQ_VALID
, qword7
);
1007 peek_head
= (cq
->cq_ring
.head
+ 1) % cq
->cq_ring
.size
;
1008 ext_cqe
= cq
->cq_base
[peek_head
].buf
;
1009 get_64bit_val(ext_cqe
, 24, &qword7
);
1010 polarity
= (u8
)FIELD_GET(IRDMA_CQ_VALID
, qword7
);
1014 if (polarity
!= cq
->polarity
)
1017 /* Ensure ext CQE contents are read after ext valid bit is checked */
1020 info
->imm_valid
= (bool)FIELD_GET(IRDMA_CQ_IMMVALID
, qword7
);
1021 if (info
->imm_valid
) {
1024 get_64bit_val(ext_cqe
, 0, &qword4
);
1025 info
->imm_data
= (u32
)FIELD_GET(IRDMA_CQ_IMMDATALOW32
, qword4
);
1027 info
->ud_smac_valid
= (bool)FIELD_GET(IRDMA_CQ_UDSMACVALID
, qword7
);
1028 info
->ud_vlan_valid
= (bool)FIELD_GET(IRDMA_CQ_UDVLANVALID
, qword7
);
1029 if (info
->ud_smac_valid
|| info
->ud_vlan_valid
) {
1030 get_64bit_val(ext_cqe
, 16, &qword6
);
1031 if (info
->ud_vlan_valid
)
1032 info
->ud_vlan
= (u16
)FIELD_GET(IRDMA_CQ_UDVLAN
, qword6
);
1033 if (info
->ud_smac_valid
) {
1034 info
->ud_smac
[5] = qword6
& 0xFF;
1035 info
->ud_smac
[4] = (qword6
>> 8) & 0xFF;
1036 info
->ud_smac
[3] = (qword6
>> 16) & 0xFF;
1037 info
->ud_smac
[2] = (qword6
>> 24) & 0xFF;
1038 info
->ud_smac
[1] = (qword6
>> 32) & 0xFF;
1039 info
->ud_smac
[0] = (qword6
>> 40) & 0xFF;
1043 info
->imm_valid
= false;
1044 info
->ud_smac_valid
= false;
1045 info
->ud_vlan_valid
= false;
1048 info
->q_type
= (u8
)FIELD_GET(IRDMA_CQ_SQ
, qword3
);
1049 info
->error
= (bool)FIELD_GET(IRDMA_CQ_ERROR
, qword3
);
1050 info
->ipv4
= (bool)FIELD_GET(IRDMACQ_IPV4
, qword3
);
1052 info
->major_err
= FIELD_GET(IRDMA_CQ_MAJERR
, qword3
);
1053 info
->minor_err
= FIELD_GET(IRDMA_CQ_MINERR
, qword3
);
1054 if (info
->major_err
== IRDMA_FLUSH_MAJOR_ERR
) {
1055 info
->comp_status
= IRDMA_COMPL_STATUS_FLUSHED
;
1056 /* Set the min error to standard flush error code for remaining cqes */
1057 if (info
->minor_err
!= FLUSH_GENERAL_ERR
) {
1058 qword3
&= ~IRDMA_CQ_MINERR
;
1059 qword3
|= FIELD_PREP(IRDMA_CQ_MINERR
, FLUSH_GENERAL_ERR
);
1060 set_64bit_val(cqe
, 24, qword3
);
1063 info
->comp_status
= IRDMA_COMPL_STATUS_UNKNOWN
;
1066 info
->comp_status
= IRDMA_COMPL_STATUS_SUCCESS
;
1069 get_64bit_val(cqe
, 0, &qword0
);
1070 get_64bit_val(cqe
, 16, &qword2
);
1072 info
->tcp_seq_num_rtt
= (u32
)FIELD_GET(IRDMACQ_TCPSEQNUMRTT
, qword0
);
1073 info
->qp_id
= (u32
)FIELD_GET(IRDMACQ_QPID
, qword2
);
1074 info
->ud_src_qpn
= (u32
)FIELD_GET(IRDMACQ_UDSRCQPN
, qword2
);
1076 get_64bit_val(cqe
, 8, &comp_ctx
);
1078 info
->solicited_event
= (bool)FIELD_GET(IRDMACQ_SOEVENT
, qword3
);
1079 qp
= (struct irdma_qp_uk
*)(unsigned long)comp_ctx
;
1080 if (!qp
|| qp
->destroy_pending
) {
1084 wqe_idx
= (u32
)FIELD_GET(IRDMA_CQ_WQEIDX
, qword3
);
1085 info
->qp_handle
= (irdma_qp_handle
)(unsigned long)qp
;
1086 info
->op_type
= (u8
)FIELD_GET(IRDMACQ_OP
, qword3
);
1088 if (info
->q_type
== IRDMA_CQE_QTYPE_RQ
) {
1091 array_idx
= wqe_idx
/ qp
->rq_wqe_size_multiplier
;
1093 if (info
->comp_status
== IRDMA_COMPL_STATUS_FLUSHED
||
1094 info
->comp_status
== IRDMA_COMPL_STATUS_UNKNOWN
) {
1095 if (!IRDMA_RING_MORE_WORK(qp
->rq_ring
)) {
1100 info
->wr_id
= qp
->rq_wrid_array
[qp
->rq_ring
.tail
];
1101 array_idx
= qp
->rq_ring
.tail
;
1103 info
->wr_id
= qp
->rq_wrid_array
[array_idx
];
1106 info
->bytes_xfered
= (u32
)FIELD_GET(IRDMACQ_PAYLDLEN
, qword0
);
1108 if (qword3
& IRDMACQ_STAG
) {
1109 info
->stag_invalid_set
= true;
1110 info
->inv_stag
= (u32
)FIELD_GET(IRDMACQ_INVSTAG
, qword2
);
1112 info
->stag_invalid_set
= false;
1114 IRDMA_RING_SET_TAIL(qp
->rq_ring
, array_idx
+ 1);
1115 if (info
->comp_status
== IRDMA_COMPL_STATUS_FLUSHED
) {
1116 qp
->rq_flush_seen
= true;
1117 if (!IRDMA_RING_MORE_WORK(qp
->rq_ring
))
1118 qp
->rq_flush_complete
= true;
1120 move_cq_head
= false;
1122 pring
= &qp
->rq_ring
;
1123 } else { /* q_type is IRDMA_CQE_QTYPE_SQ */
1124 if (qp
->first_sq_wq
) {
1125 if (wqe_idx
+ 1 >= qp
->conn_wqes
)
1126 qp
->first_sq_wq
= false;
1128 if (wqe_idx
< qp
->conn_wqes
&& qp
->sq_ring
.head
== qp
->sq_ring
.tail
) {
1129 IRDMA_RING_MOVE_HEAD_NOCHECK(cq
->cq_ring
);
1130 IRDMA_RING_MOVE_TAIL(cq
->cq_ring
);
1131 set_64bit_val(cq
->shadow_area
, 0,
1132 IRDMA_RING_CURRENT_HEAD(cq
->cq_ring
));
1134 sizeof(struct irdma_cq_poll_info
));
1135 return irdma_uk_cq_poll_cmpl(cq
, info
);
1138 if (info
->comp_status
!= IRDMA_COMPL_STATUS_FLUSHED
) {
1139 info
->wr_id
= qp
->sq_wrtrk_array
[wqe_idx
].wrid
;
1140 if (!info
->comp_status
)
1141 info
->bytes_xfered
= qp
->sq_wrtrk_array
[wqe_idx
].wr_len
;
1142 info
->op_type
= (u8
)FIELD_GET(IRDMACQ_OP
, qword3
);
1143 IRDMA_RING_SET_TAIL(qp
->sq_ring
,
1144 wqe_idx
+ qp
->sq_wrtrk_array
[wqe_idx
].quanta
);
1146 if (!IRDMA_RING_MORE_WORK(qp
->sq_ring
)) {
1156 tail
= qp
->sq_ring
.tail
;
1157 sw_wqe
= qp
->sq_base
[tail
].elem
;
1158 get_64bit_val(sw_wqe
, 24,
1160 info
->op_type
= (u8
)FIELD_GET(IRDMAQPSQ_OPCODE
,
1162 IRDMA_RING_SET_TAIL(qp
->sq_ring
,
1163 tail
+ qp
->sq_wrtrk_array
[tail
].quanta
);
1164 if (info
->op_type
!= IRDMAQP_OP_NOP
) {
1165 info
->wr_id
= qp
->sq_wrtrk_array
[tail
].wrid
;
1166 info
->bytes_xfered
= qp
->sq_wrtrk_array
[tail
].wr_len
;
1170 if (info
->op_type
== IRDMA_OP_TYPE_BIND_MW
&&
1171 info
->minor_err
== FLUSH_PROT_ERR
)
1172 info
->minor_err
= FLUSH_MW_BIND_ERR
;
1173 qp
->sq_flush_seen
= true;
1174 if (!IRDMA_RING_MORE_WORK(qp
->sq_ring
))
1175 qp
->sq_flush_complete
= true;
1177 pring
= &qp
->sq_ring
;
1183 if (!ret_code
&& info
->comp_status
== IRDMA_COMPL_STATUS_FLUSHED
)
1184 if (pring
&& IRDMA_RING_MORE_WORK(*pring
))
1185 move_cq_head
= false;
1188 IRDMA_RING_MOVE_HEAD_NOCHECK(cq
->cq_ring
);
1189 if (!IRDMA_RING_CURRENT_HEAD(cq
->cq_ring
))
1192 if (ext_valid
&& !cq
->avoid_mem_cflct
) {
1193 IRDMA_RING_MOVE_HEAD_NOCHECK(cq
->cq_ring
);
1194 if (!IRDMA_RING_CURRENT_HEAD(cq
->cq_ring
))
1198 IRDMA_RING_MOVE_TAIL(cq
->cq_ring
);
1199 if (!cq
->avoid_mem_cflct
&& ext_valid
)
1200 IRDMA_RING_MOVE_TAIL(cq
->cq_ring
);
1201 set_64bit_val(cq
->shadow_area
, 0,
1202 IRDMA_RING_CURRENT_HEAD(cq
->cq_ring
));
1204 qword3
&= ~IRDMA_CQ_WQEIDX
;
1205 qword3
|= FIELD_PREP(IRDMA_CQ_WQEIDX
, pring
->tail
);
1206 set_64bit_val(cqe
, 24, qword3
);
1213 * irdma_qp_round_up - return round up qp wq depth
1214 * @wqdepth: wq depth in quanta to round up
1216 static int irdma_qp_round_up(u32 wqdepth
)
1220 for (wqdepth
--; scount
<= 16; scount
*= 2)
1221 wqdepth
|= wqdepth
>> scount
;
1227 * irdma_get_wqe_shift - get shift count for maximum wqe size
1228 * @uk_attrs: qp HW attributes
1229 * @sge: Maximum Scatter Gather Elements wqe
1230 * @inline_data: Maximum inline data size
1231 * @shift: Returns the shift needed based on sge
1233 * Shift can be used to left shift the wqe size based on number of SGEs and inlind data size.
1234 * For 1 SGE or inline data <= 8, shift = 0 (wqe size of 32
1235 * bytes). For 2 or 3 SGEs or inline data <= 39, shift = 1 (wqe
1236 * size of 64 bytes).
1237 * For 4-7 SGE's and inline <= 101 Shift of 2 otherwise (wqe
1238 * size of 256 bytes).
1240 void irdma_get_wqe_shift(struct irdma_uk_attrs
*uk_attrs
, u32 sge
,
1241 u32 inline_data
, u8
*shift
)
1244 if (uk_attrs
->hw_rev
>= IRDMA_GEN_2
) {
1245 if (sge
> 1 || inline_data
> 8) {
1246 if (sge
< 4 && inline_data
<= 39)
1248 else if (sge
< 8 && inline_data
<= 101)
1253 } else if (sge
> 1 || inline_data
> 16) {
1254 *shift
= (sge
< 4 && inline_data
<= 48) ? 1 : 2;
1259 * irdma_get_sqdepth - get SQ depth (quanta)
1260 * @uk_attrs: qp HW attributes
1262 * @shift: shift which determines size of WQE
1263 * @sqdepth: depth of SQ
1266 int irdma_get_sqdepth(struct irdma_uk_attrs
*uk_attrs
, u32 sq_size
, u8 shift
,
1269 u32 min_size
= (u32
)uk_attrs
->min_hw_wq_size
<< shift
;
1271 *sqdepth
= irdma_qp_round_up((sq_size
<< shift
) + IRDMA_SQ_RSVD
);
1273 if (*sqdepth
< min_size
)
1274 *sqdepth
= min_size
;
1275 else if (*sqdepth
> uk_attrs
->max_hw_wq_quanta
)
1282 * irdma_get_rqdepth - get RQ depth (quanta)
1283 * @uk_attrs: qp HW attributes
1285 * @shift: shift which determines size of WQE
1286 * @rqdepth: depth of RQ
1288 int irdma_get_rqdepth(struct irdma_uk_attrs
*uk_attrs
, u32 rq_size
, u8 shift
,
1291 u32 min_size
= (u32
)uk_attrs
->min_hw_wq_size
<< shift
;
1293 *rqdepth
= irdma_qp_round_up((rq_size
<< shift
) + IRDMA_RQ_RSVD
);
1295 if (*rqdepth
< min_size
)
1296 *rqdepth
= min_size
;
1297 else if (*rqdepth
> uk_attrs
->max_hw_rq_quanta
)
1303 static const struct irdma_wqe_uk_ops iw_wqe_uk_ops
= {
1304 .iw_copy_inline_data
= irdma_copy_inline_data
,
1305 .iw_inline_data_size_to_quanta
= irdma_inline_data_size_to_quanta
,
1306 .iw_set_fragment
= irdma_set_fragment
,
1307 .iw_set_mw_bind_wqe
= irdma_set_mw_bind_wqe
,
1310 static const struct irdma_wqe_uk_ops iw_wqe_uk_ops_gen_1
= {
1311 .iw_copy_inline_data
= irdma_copy_inline_data_gen_1
,
1312 .iw_inline_data_size_to_quanta
= irdma_inline_data_size_to_quanta_gen_1
,
1313 .iw_set_fragment
= irdma_set_fragment_gen_1
,
1314 .iw_set_mw_bind_wqe
= irdma_set_mw_bind_wqe_gen_1
,
1318 * irdma_setup_connection_wqes - setup WQEs necessary to complete
1320 * @qp: hw qp (user and kernel)
1321 * @info: qp initialization info
1323 static void irdma_setup_connection_wqes(struct irdma_qp_uk
*qp
,
1324 struct irdma_qp_uk_init_info
*info
)
1328 if (!info
->legacy_mode
&&
1329 (qp
->uk_attrs
->feature_flags
& IRDMA_FEATURE_RTS_AE
))
1332 qp
->conn_wqes
= move_cnt
;
1333 IRDMA_RING_MOVE_HEAD_BY_COUNT_NOCHECK(qp
->sq_ring
, move_cnt
);
1334 IRDMA_RING_MOVE_TAIL_BY_COUNT(qp
->sq_ring
, move_cnt
);
1335 IRDMA_RING_MOVE_HEAD_BY_COUNT_NOCHECK(qp
->initial_ring
, move_cnt
);
1339 * irdma_uk_calc_shift_wq - calculate WQE shift for both SQ and RQ
1340 * @ukinfo: qp initialization info
1341 * @sq_shift: Returns shift of SQ
1342 * @rq_shift: Returns shift of RQ
1344 void irdma_uk_calc_shift_wq(struct irdma_qp_uk_init_info
*ukinfo
, u8
*sq_shift
,
1347 bool imm_support
= ukinfo
->uk_attrs
->hw_rev
>= IRDMA_GEN_2
;
1349 irdma_get_wqe_shift(ukinfo
->uk_attrs
,
1350 imm_support
? ukinfo
->max_sq_frag_cnt
+ 1 :
1351 ukinfo
->max_sq_frag_cnt
,
1352 ukinfo
->max_inline_data
, sq_shift
);
1354 irdma_get_wqe_shift(ukinfo
->uk_attrs
, ukinfo
->max_rq_frag_cnt
, 0,
1357 if (ukinfo
->uk_attrs
->hw_rev
== IRDMA_GEN_1
) {
1358 if (ukinfo
->abi_ver
> 4)
1359 *rq_shift
= IRDMA_MAX_RQ_WQE_SHIFT_GEN1
;
1364 * irdma_uk_calc_depth_shift_sq - calculate depth and shift for SQ size.
1365 * @ukinfo: qp initialization info
1366 * @sq_depth: Returns depth of SQ
1367 * @sq_shift: Returns shift of SQ
1369 int irdma_uk_calc_depth_shift_sq(struct irdma_qp_uk_init_info
*ukinfo
,
1370 u32
*sq_depth
, u8
*sq_shift
)
1372 bool imm_support
= ukinfo
->uk_attrs
->hw_rev
>= IRDMA_GEN_2
;
1375 irdma_get_wqe_shift(ukinfo
->uk_attrs
,
1376 imm_support
? ukinfo
->max_sq_frag_cnt
+ 1 :
1377 ukinfo
->max_sq_frag_cnt
,
1378 ukinfo
->max_inline_data
, sq_shift
);
1379 status
= irdma_get_sqdepth(ukinfo
->uk_attrs
, ukinfo
->sq_size
,
1380 *sq_shift
, sq_depth
);
1386 * irdma_uk_calc_depth_shift_rq - calculate depth and shift for RQ size.
1387 * @ukinfo: qp initialization info
1388 * @rq_depth: Returns depth of RQ
1389 * @rq_shift: Returns shift of RQ
1391 int irdma_uk_calc_depth_shift_rq(struct irdma_qp_uk_init_info
*ukinfo
,
1392 u32
*rq_depth
, u8
*rq_shift
)
1396 irdma_get_wqe_shift(ukinfo
->uk_attrs
, ukinfo
->max_rq_frag_cnt
, 0,
1399 if (ukinfo
->uk_attrs
->hw_rev
== IRDMA_GEN_1
) {
1400 if (ukinfo
->abi_ver
> 4)
1401 *rq_shift
= IRDMA_MAX_RQ_WQE_SHIFT_GEN1
;
1404 status
= irdma_get_rqdepth(ukinfo
->uk_attrs
, ukinfo
->rq_size
,
1405 *rq_shift
, rq_depth
);
1411 * irdma_uk_qp_init - initialize shared qp
1412 * @qp: hw qp (user and kernel)
1413 * @info: qp initialization info
1415 * initializes the vars used in both user and kernel mode.
1416 * size of the wqe depends on numbers of max. fragements
1417 * allowed. Then size of wqe * the number of wqes should be the
1418 * amount of memory allocated for sq and rq.
1420 int irdma_uk_qp_init(struct irdma_qp_uk
*qp
, struct irdma_qp_uk_init_info
*info
)
1425 qp
->uk_attrs
= info
->uk_attrs
;
1426 if (info
->max_sq_frag_cnt
> qp
->uk_attrs
->max_hw_wq_frags
||
1427 info
->max_rq_frag_cnt
> qp
->uk_attrs
->max_hw_wq_frags
)
1430 qp
->qp_caps
= info
->qp_caps
;
1431 qp
->sq_base
= info
->sq
;
1432 qp
->rq_base
= info
->rq
;
1433 qp
->qp_type
= info
->type
? info
->type
: IRDMA_QP_TYPE_IWARP
;
1434 qp
->shadow_area
= info
->shadow_area
;
1435 qp
->sq_wrtrk_array
= info
->sq_wrtrk_array
;
1437 qp
->rq_wrid_array
= info
->rq_wrid_array
;
1438 qp
->wqe_alloc_db
= info
->wqe_alloc_db
;
1439 qp
->qp_id
= info
->qp_id
;
1440 qp
->sq_size
= info
->sq_size
;
1441 qp
->max_sq_frag_cnt
= info
->max_sq_frag_cnt
;
1442 sq_ring_size
= qp
->sq_size
<< info
->sq_shift
;
1443 IRDMA_RING_INIT(qp
->sq_ring
, sq_ring_size
);
1444 IRDMA_RING_INIT(qp
->initial_ring
, sq_ring_size
);
1445 if (info
->first_sq_wq
) {
1446 irdma_setup_connection_wqes(qp
, info
);
1447 qp
->swqe_polarity
= 1;
1448 qp
->first_sq_wq
= true;
1450 qp
->swqe_polarity
= 0;
1452 qp
->swqe_polarity_deferred
= 1;
1453 qp
->rwqe_polarity
= 0;
1454 qp
->rq_size
= info
->rq_size
;
1455 qp
->max_rq_frag_cnt
= info
->max_rq_frag_cnt
;
1456 qp
->max_inline_data
= info
->max_inline_data
;
1457 qp
->rq_wqe_size
= info
->rq_shift
;
1458 IRDMA_RING_INIT(qp
->rq_ring
, qp
->rq_size
);
1459 qp
->rq_wqe_size_multiplier
= 1 << info
->rq_shift
;
1460 if (qp
->uk_attrs
->hw_rev
== IRDMA_GEN_1
)
1461 qp
->wqe_ops
= iw_wqe_uk_ops_gen_1
;
1463 qp
->wqe_ops
= iw_wqe_uk_ops
;
1468 * irdma_uk_cq_init - initialize shared cq (user and kernel)
1470 * @info: hw cq initialization info
1472 void irdma_uk_cq_init(struct irdma_cq_uk
*cq
,
1473 struct irdma_cq_uk_init_info
*info
)
1475 cq
->cq_base
= info
->cq_base
;
1476 cq
->cq_id
= info
->cq_id
;
1477 cq
->cq_size
= info
->cq_size
;
1478 cq
->cqe_alloc_db
= info
->cqe_alloc_db
;
1479 cq
->cq_ack_db
= info
->cq_ack_db
;
1480 cq
->shadow_area
= info
->shadow_area
;
1481 cq
->avoid_mem_cflct
= info
->avoid_mem_cflct
;
1482 IRDMA_RING_INIT(cq
->cq_ring
, cq
->cq_size
);
1487 * irdma_uk_clean_cq - clean cq entries
1488 * @q: completion context
1491 void irdma_uk_clean_cq(void *q
, struct irdma_cq_uk
*cq
)
1494 u64 qword3
, comp_ctx
;
1498 cq_head
= cq
->cq_ring
.head
;
1499 temp
= cq
->polarity
;
1501 if (cq
->avoid_mem_cflct
)
1502 cqe
= ((struct irdma_extended_cqe
*)(cq
->cq_base
))[cq_head
].buf
;
1504 cqe
= cq
->cq_base
[cq_head
].buf
;
1505 get_64bit_val(cqe
, 24, &qword3
);
1506 polarity
= (u8
)FIELD_GET(IRDMA_CQ_VALID
, qword3
);
1508 if (polarity
!= temp
)
1511 /* Ensure CQE contents are read after valid bit is checked */
1514 get_64bit_val(cqe
, 8, &comp_ctx
);
1515 if ((void *)(unsigned long)comp_ctx
== q
)
1516 set_64bit_val(cqe
, 8, 0);
1518 cq_head
= (cq_head
+ 1) % cq
->cq_ring
.size
;
1525 * irdma_nop - post a nop
1527 * @wr_id: work request id
1528 * @signaled: signaled for completion
1529 * @post_sq: ring doorbell
1531 int irdma_nop(struct irdma_qp_uk
*qp
, u64 wr_id
, bool signaled
, bool post_sq
)
1536 struct irdma_post_sq_info info
= {};
1539 wqe
= irdma_qp_get_next_send_wqe(qp
, &wqe_idx
, IRDMA_QP_WQE_MIN_QUANTA
,
1544 irdma_clr_wqes(qp
, wqe_idx
);
1546 set_64bit_val(wqe
, 0, 0);
1547 set_64bit_val(wqe
, 8, 0);
1548 set_64bit_val(wqe
, 16, 0);
1550 hdr
= FIELD_PREP(IRDMAQPSQ_OPCODE
, IRDMAQP_OP_NOP
) |
1551 FIELD_PREP(IRDMAQPSQ_SIGCOMPL
, signaled
) |
1552 FIELD_PREP(IRDMAQPSQ_VALID
, qp
->swqe_polarity
);
1554 dma_wmb(); /* make sure WQE is populated before valid bit is set */
1556 set_64bit_val(wqe
, 24, hdr
);
1558 irdma_uk_qp_post_wr(qp
);
1564 * irdma_fragcnt_to_quanta_sq - calculate quanta based on fragment count for SQ
1565 * @frag_cnt: number of fragments
1566 * @quanta: quanta for frag_cnt
1568 int irdma_fragcnt_to_quanta_sq(u32 frag_cnt
, u16
*quanta
)
1573 *quanta
= IRDMA_QP_WQE_MIN_QUANTA
;
1600 case 15: /* when immediate data is present */
1611 * irdma_fragcnt_to_wqesize_rq - calculate wqe size based on fragment count for RQ
1612 * @frag_cnt: number of fragments
1613 * @wqe_size: size in bytes given frag_cnt
1615 int irdma_fragcnt_to_wqesize_rq(u32 frag_cnt
, u16
*wqe_size
)