Skip to content

Commit 2bfe202

Browse files
committed
libzrdma: Add support for srq
This patch add the following verbs: create_srq destroy_srq modify_srq post_srq_recv get_srq_num on-behalf-of: @ZTE li.fuyan@zte.com.cn Signed-off-by: zte_lifuyan <li.fuyan@zte.com.cn>
1 parent 4518073 commit 2bfe202

File tree

3 files changed

+638
-3
lines changed

3 files changed

+638
-3
lines changed

providers/zrdma/zxdh_hw.c

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,54 @@ void zxdh_clean_cq(void *q, struct zxdh_cq *cq)
24192419
} while (true);
24202420
}
24212421

2422+
/**
2423+
* zxdh_get_srq_wqe_shift - get shift count for maximum srq wqe size
2424+
* @dev_attrs: srq HW attributes
2425+
* @sge: Maximum Scatter Gather Elements wqe
2426+
* @shift: Returns the shift needed based on sge
2427+
*
2428+
* Shift can be used to left shift the srq wqe size based on number of SGEs.
2429+
* For 1 SGE, shift = 1 (wqe size of 2*16 bytes).
2430+
* For 2 or 3 SGEs, shift = 2 (wqe size of 4*16 bytes).
2431+
* For 4-7 SGE's Shift of 3.
2432+
* For 8-15 SGE's Shift of 4 otherwise (wqe size of 512 bytes).
2433+
*/
2434+
void zxdh_get_srq_wqe_shift(struct zxdh_dev_attrs *dev_attrs, __u32 sge,
2435+
__u8 *shift)
2436+
{
2437+
*shift = 0; //16bytes RQE, need to confirm configuration
2438+
if (sge < 2)
2439+
*shift = 1;
2440+
else if (sge < 4)
2441+
*shift = 2;
2442+
else if (sge < 8)
2443+
*shift = 3;
2444+
else if (sge < 16)
2445+
*shift = 4;
2446+
else
2447+
*shift = 5;
2448+
}
2449+
2450+
/*
2451+
* zxdh_get_srqdepth - get SRQ depth (quanta)
2452+
* @max_hw_rq_quanta: HW SRQ size limit
2453+
* @srq_size: SRQ size
2454+
* @shift: shift which determines size of WQE
2455+
* @srqdepth: depth of SRQ
2456+
*/
2457+
int zxdh_get_srqdepth(__u32 max_hw_srq_quanta, __u32 srq_size, __u8 shift,
2458+
__u32 *srqdepth)
2459+
{
2460+
*srqdepth = zxdh_qp_round_up((srq_size << shift) + ZXDH_SRQ_RSVD);
2461+
2462+
if (*srqdepth < (ZXDH_QP_SW_MIN_WQSIZE << shift))
2463+
*srqdepth = ZXDH_QP_SW_MIN_WQSIZE << shift;
2464+
else if ((*srqdepth >> shift) > max_hw_srq_quanta)
2465+
return ZXDH_ERR_INVALID_SIZE;
2466+
2467+
return 0;
2468+
}
2469+
24222470
__le64 *zxdh_get_srq_wqe(struct zxdh_srq *srq, int wqe_index)
24232471
{
24242472
__le64 *wqe;
@@ -2427,6 +2475,73 @@ __le64 *zxdh_get_srq_wqe(struct zxdh_srq *srq, int wqe_index)
24272475
return wqe;
24282476
}
24292477

2478+
__le16 *zxdh_get_srq_list_wqe(struct zxdh_srq *srq, __u16 *idx)
2479+
{
2480+
__le16 *wqe;
2481+
__u16 wqe_idx;
2482+
2483+
wqe_idx = srq->srq_list_ring.tail;
2484+
srq->srq_list_ring.tail++;
2485+
srq->srq_list_ring.tail %= srq->srq_list_ring.size;
2486+
*idx = srq->srq_list_ring.tail;
2487+
2488+
if (!(*idx))
2489+
srq->srq_list_polarity = !srq->srq_list_polarity;
2490+
2491+
wqe = &srq->srq_list_base[wqe_idx];
2492+
2493+
return wqe;
2494+
}
2495+
2496+
/**
2497+
* zxdh_srq_init - initialize srq
2498+
* @srq: hw srq (user and kernel)
2499+
* @info: srq initialization info
2500+
*
2501+
* initializes the vars used in both user and kernel mode.
2502+
* size of the wqe depends on numbers of max. fragements
2503+
* allowed. Then size of wqe * the number of wqes should be the
2504+
* amount of memory allocated for srq.
2505+
*/
2506+
enum zxdh_status_code zxdh_srq_init(struct zxdh_srq *srq,
2507+
struct zxdh_srq_init_info *info)
2508+
{
2509+
__u32 srq_ring_size;
2510+
__u8 srqshift;
2511+
2512+
srq->dev_attrs = info->dev_attrs;
2513+
if (info->max_srq_frag_cnt > srq->dev_attrs->max_hw_wq_frags)
2514+
return -ZXDH_ERR_INVALID_FRAG_COUNT;
2515+
zxdh_get_srq_wqe_shift(srq->dev_attrs, info->max_srq_frag_cnt,
2516+
&srqshift);
2517+
srq->srq_base = info->srq_base;
2518+
srq->srq_list_base = info->srq_list_base;
2519+
srq->srq_db_base = info->srq_db_base;
2520+
srq->srq_wrid_array = info->srq_wrid_array;
2521+
srq->srq_id = info->srq_id;
2522+
srq->srq_size = info->srq_size;
2523+
srq->log2_srq_size = info->log2_srq_size;
2524+
srq->srq_list_size = info->srq_list_size;
2525+
srq->max_srq_frag_cnt = info->max_srq_frag_cnt;
2526+
srq_ring_size = srq->srq_size;
2527+
srq->srq_wqe_size = srqshift;
2528+
srq->srq_wqe_size_multiplier = 1 << srqshift;
2529+
ZXDH_RING_INIT(srq->srq_ring, srq_ring_size);
2530+
ZXDH_RING_INIT(srq->srq_list_ring, srq->srq_list_size);
2531+
srq->srq_ring.tail = srq->srq_size - 1;
2532+
srq->srq_list_polarity = 1;
2533+
zxdh_dbg(ZXDH_DBG_SRQ, "%s srq_wqe_size_multiplier:%d srqshift:%d\n",
2534+
__func__, srq->srq_wqe_size_multiplier, srqshift);
2535+
zxdh_dbg(
2536+
ZXDH_DBG_SRQ,
2537+
"%s srq->srq_id:%d srq_base:0x%p srq_list_base:0x%p srq_db_base:0x%p\n",
2538+
__func__, srq->srq_id, srq->srq_base, srq->srq_list_base,
2539+
srq->srq_db_base);
2540+
zxdh_dbg(ZXDH_DBG_SRQ,
2541+
"%s srq->srq_id:%d srq_ring_size:%d srq->srq_list_size:%d\n",
2542+
__func__, srq->srq_id, srq_ring_size, srq->srq_list_size);
2543+
return 0;
2544+
}
24302545

24312546
void zxdh_free_srq_wqe(struct zxdh_srq *srq, int wqe_index)
24322547
{

0 commit comments

Comments
 (0)