@@ -2434,6 +2434,54 @@ void zxdh_clean_cq(void *q, struct zxdh_cq *cq)
24342434 } while (true);
24352435}
24362436
2437+ /**
2438+ * zxdh_get_srq_wqe_shift - get shift count for maximum srq wqe size
2439+ * @dev_attrs: srq HW attributes
2440+ * @sge: Maximum Scatter Gather Elements wqe
2441+ * @shift: Returns the shift needed based on sge
2442+ *
2443+ * Shift can be used to left shift the srq wqe size based on number of SGEs.
2444+ * For 1 SGE, shift = 1 (wqe size of 2*16 bytes).
2445+ * For 2 or 3 SGEs, shift = 2 (wqe size of 4*16 bytes).
2446+ * For 4-7 SGE's Shift of 3.
2447+ * For 8-15 SGE's Shift of 4 otherwise (wqe size of 512 bytes).
2448+ */
2449+ void zxdh_get_srq_wqe_shift (struct zxdh_dev_attrs * dev_attrs , __u32 sge ,
2450+ __u8 * shift )
2451+ {
2452+ * shift = 0 ; //16bytes RQE, need to confirm configuration
2453+ if (sge < 2 )
2454+ * shift = 1 ;
2455+ else if (sge < 4 )
2456+ * shift = 2 ;
2457+ else if (sge < 8 )
2458+ * shift = 3 ;
2459+ else if (sge < 16 )
2460+ * shift = 4 ;
2461+ else
2462+ * shift = 5 ;
2463+ }
2464+
2465+ /*
2466+ * zxdh_get_srqdepth - get SRQ depth (quanta)
2467+ * @max_hw_rq_quanta: HW SRQ size limit
2468+ * @srq_size: SRQ size
2469+ * @shift: shift which determines size of WQE
2470+ * @srqdepth: depth of SRQ
2471+ */
2472+ int zxdh_get_srqdepth (__u32 max_hw_srq_quanta , __u32 srq_size , __u8 shift ,
2473+ __u32 * srqdepth )
2474+ {
2475+ * srqdepth = zxdh_qp_round_up ((srq_size << shift ) + ZXDH_SRQ_RSVD );
2476+
2477+ if (* srqdepth < (ZXDH_QP_SW_MIN_WQSIZE << shift ))
2478+ * srqdepth = ZXDH_QP_SW_MIN_WQSIZE << shift ;
2479+ else if ((* srqdepth >> shift ) > max_hw_srq_quanta )
2480+ return ZXDH_ERR_INVALID_SIZE ;
2481+
2482+ return 0 ;
2483+ }
2484+
24372485__le64 * zxdh_get_srq_wqe (struct zxdh_srq * srq , int wqe_index )
24382486{
24392487 __le64 * wqe ;
@@ -2442,6 +2490,73 @@ __le64 *zxdh_get_srq_wqe(struct zxdh_srq *srq, int wqe_index)
24422490 return wqe ;
24432491}
24442492
2493+ __le16 * zxdh_get_srq_list_wqe (struct zxdh_srq * srq , __u16 * idx )
2494+ {
2495+ __le16 * wqe ;
2496+ __u16 wqe_idx ;
2497+
2498+ wqe_idx = srq -> srq_list_ring .tail ;
2499+ srq -> srq_list_ring .tail ++ ;
2500+ srq -> srq_list_ring .tail %= srq -> srq_list_ring .size ;
2501+ * idx = srq -> srq_list_ring .tail ;
2502+
2503+ if (!(* idx ))
2504+ srq -> srq_list_polarity = !srq -> srq_list_polarity ;
2505+
2506+ wqe = & srq -> srq_list_base [wqe_idx ];
2507+
2508+ return wqe ;
2509+ }
2510+
2511+ /**
2512+ * zxdh_srq_init - initialize srq
2513+ * @srq: hw srq (user and kernel)
2514+ * @info: srq initialization info
2515+ *
2516+ * initializes the vars used in both user and kernel mode.
2517+ * size of the wqe depends on numbers of max. fragements
2518+ * allowed. Then size of wqe * the number of wqes should be the
2519+ * amount of memory allocated for srq.
2520+ */
2521+ enum zxdh_status_code zxdh_srq_init (struct zxdh_srq * srq ,
2522+ struct zxdh_srq_init_info * info )
2523+ {
2524+ __u32 srq_ring_size ;
2525+ __u8 srqshift ;
2526+
2527+ srq -> dev_attrs = info -> dev_attrs ;
2528+ if (info -> max_srq_frag_cnt > srq -> dev_attrs -> max_hw_wq_frags )
2529+ return - ZXDH_ERR_INVALID_FRAG_COUNT ;
2530+ zxdh_get_srq_wqe_shift (srq -> dev_attrs , info -> max_srq_frag_cnt ,
2531+ & srqshift );
2532+ srq -> srq_base = info -> srq_base ;
2533+ srq -> srq_list_base = info -> srq_list_base ;
2534+ srq -> srq_db_base = info -> srq_db_base ;
2535+ srq -> srq_wrid_array = info -> srq_wrid_array ;
2536+ srq -> srq_id = info -> srq_id ;
2537+ srq -> srq_size = info -> srq_size ;
2538+ srq -> log2_srq_size = info -> log2_srq_size ;
2539+ srq -> srq_list_size = info -> srq_list_size ;
2540+ srq -> max_srq_frag_cnt = info -> max_srq_frag_cnt ;
2541+ srq_ring_size = srq -> srq_size ;
2542+ srq -> srq_wqe_size = srqshift ;
2543+ srq -> srq_wqe_size_multiplier = 1 << srqshift ;
2544+ ZXDH_RING_INIT (srq -> srq_ring , srq_ring_size );
2545+ ZXDH_RING_INIT (srq -> srq_list_ring , srq -> srq_list_size );
2546+ srq -> srq_ring .tail = srq -> srq_size - 1 ;
2547+ srq -> srq_list_polarity = 1 ;
2548+ zxdh_dbg (ZXDH_DBG_SRQ , "%s srq_wqe_size_multiplier:%d srqshift:%d\n" ,
2549+ __func__ , srq -> srq_wqe_size_multiplier , srqshift );
2550+ zxdh_dbg (
2551+ ZXDH_DBG_SRQ ,
2552+ "%s srq->srq_id:%d srq_base:0x%p srq_list_base:0x%p srq_db_base:0x%p\n" ,
2553+ __func__ , srq -> srq_id , srq -> srq_base , srq -> srq_list_base ,
2554+ srq -> srq_db_base );
2555+ zxdh_dbg (ZXDH_DBG_SRQ ,
2556+ "%s srq->srq_id:%d srq_ring_size:%d srq->srq_list_size:%d\n" ,
2557+ __func__ , srq -> srq_id , srq_ring_size , srq -> srq_list_size );
2558+ return 0 ;
2559+ }
24452560
24462561void zxdh_free_srq_wqe (struct zxdh_srq * srq , int wqe_index )
24472562{
0 commit comments