Commit 8758768a authored by Shiraz Saleem's avatar Shiraz Saleem Committed by Jason Gunthorpe

i40iw: Use utility function roundup_pow_of_two()

Consolidate all power of 2 round calculations to
use kernel utility function roundup_pow_of_two().
Signed-off-by: default avatarShiraz Saleem <shiraz.saleem@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent f32b766c
...@@ -92,14 +92,9 @@ void i40iw_free_sqbuf(struct i40iw_sc_vsi *vsi, void *bufp) ...@@ -92,14 +92,9 @@ void i40iw_free_sqbuf(struct i40iw_sc_vsi *vsi, void *bufp)
static u8 i40iw_derive_hw_ird_setting(u16 cm_ird) static u8 i40iw_derive_hw_ird_setting(u16 cm_ird)
{ {
u8 encoded_ird_size; u8 encoded_ird_size;
u8 pof2_cm_ird = 1;
/* round-off to next powerof2 */
while (pof2_cm_ird < cm_ird)
pof2_cm_ird *= 2;
/* ird_size field is encoded in qp_ctx */ /* ird_size field is encoded in qp_ctx */
switch (pof2_cm_ird) { switch (cm_ird ? roundup_pow_of_two(cm_ird) : 0) {
case I40IW_HW_IRD_SETTING_64: case I40IW_HW_IRD_SETTING_64:
encoded_ird_size = 3; encoded_ird_size = 3;
break; break;
......
...@@ -3855,7 +3855,6 @@ enum i40iw_status_code i40iw_config_fpm_values(struct i40iw_sc_dev *dev, u32 qp_ ...@@ -3855,7 +3855,6 @@ enum i40iw_status_code i40iw_config_fpm_values(struct i40iw_sc_dev *dev, u32 qp_
struct i40iw_virt_mem virt_mem; struct i40iw_virt_mem virt_mem;
u32 i, mem_size; u32 i, mem_size;
u32 qpwantedoriginal, qpwanted, mrwanted, pblewanted; u32 qpwantedoriginal, qpwanted, mrwanted, pblewanted;
u32 powerof2;
u64 sd_needed; u64 sd_needed;
u32 loop_count = 0; u32 loop_count = 0;
...@@ -3928,16 +3927,10 @@ enum i40iw_status_code i40iw_config_fpm_values(struct i40iw_sc_dev *dev, u32 qp_ ...@@ -3928,16 +3927,10 @@ enum i40iw_status_code i40iw_config_fpm_values(struct i40iw_sc_dev *dev, u32 qp_
if ((loop_count > 1000) || if ((loop_count > 1000) ||
((!(loop_count % 10)) && ((!(loop_count % 10)) &&
(qpwanted > qpwantedoriginal * 2 / 3))) { (qpwanted > qpwantedoriginal * 2 / 3))) {
if (qpwanted > FPM_MULTIPLIER) { if (qpwanted > FPM_MULTIPLIER)
qpwanted -= FPM_MULTIPLIER; qpwanted = roundup_pow_of_two(qpwanted -
powerof2 = 1; FPM_MULTIPLIER);
while (powerof2 < qpwanted) qpwanted >>= 1;
powerof2 *= 2;
powerof2 /= 2;
qpwanted = powerof2;
} else {
qpwanted /= 2;
}
} }
if (mrwanted > FPM_MULTIPLIER * 10) if (mrwanted > FPM_MULTIPLIER * 10)
mrwanted -= FPM_MULTIPLIER * 10; mrwanted -= FPM_MULTIPLIER * 10;
......
...@@ -893,20 +893,6 @@ static enum i40iw_status_code i40iw_cq_poll_completion(struct i40iw_cq_uk *cq, ...@@ -893,20 +893,6 @@ static enum i40iw_status_code i40iw_cq_poll_completion(struct i40iw_cq_uk *cq,
return ret_code; return ret_code;
} }
/**
* i40iw_qp_roundup - return round up QP WQ depth
* @wqdepth: WQ depth in quantas to round up
*/
static int i40iw_qp_round_up(u32 wqdepth)
{
int scount = 1;
for (wqdepth--; scount <= 16; scount *= 2)
wqdepth |= wqdepth >> scount;
return ++wqdepth;
}
/** /**
* i40iw_get_wqe_shift - get shift count for maximum wqe size * i40iw_get_wqe_shift - get shift count for maximum wqe size
* @sge: Maximum Scatter Gather Elements wqe * @sge: Maximum Scatter Gather Elements wqe
...@@ -934,7 +920,7 @@ void i40iw_get_wqe_shift(u32 sge, u32 inline_data, u8 *shift) ...@@ -934,7 +920,7 @@ void i40iw_get_wqe_shift(u32 sge, u32 inline_data, u8 *shift)
*/ */
enum i40iw_status_code i40iw_get_sqdepth(u32 sq_size, u8 shift, u32 *sqdepth) enum i40iw_status_code i40iw_get_sqdepth(u32 sq_size, u8 shift, u32 *sqdepth)
{ {
*sqdepth = i40iw_qp_round_up((sq_size << shift) + I40IW_SQ_RSVD); *sqdepth = roundup_pow_of_two((sq_size << shift) + I40IW_SQ_RSVD);
if (*sqdepth < (I40IW_QP_SW_MIN_WQSIZE << shift)) if (*sqdepth < (I40IW_QP_SW_MIN_WQSIZE << shift))
*sqdepth = I40IW_QP_SW_MIN_WQSIZE << shift; *sqdepth = I40IW_QP_SW_MIN_WQSIZE << shift;
...@@ -953,7 +939,7 @@ enum i40iw_status_code i40iw_get_sqdepth(u32 sq_size, u8 shift, u32 *sqdepth) ...@@ -953,7 +939,7 @@ enum i40iw_status_code i40iw_get_sqdepth(u32 sq_size, u8 shift, u32 *sqdepth)
*/ */
enum i40iw_status_code i40iw_get_rqdepth(u32 rq_size, u8 shift, u32 *rqdepth) enum i40iw_status_code i40iw_get_rqdepth(u32 rq_size, u8 shift, u32 *rqdepth)
{ {
*rqdepth = i40iw_qp_round_up((rq_size << shift) + I40IW_RQ_RSVD); *rqdepth = roundup_pow_of_two((rq_size << shift) + I40IW_RQ_RSVD);
if (*rqdepth < (I40IW_QP_SW_MIN_WQSIZE << shift)) if (*rqdepth < (I40IW_QP_SW_MIN_WQSIZE << shift))
*rqdepth = I40IW_QP_SW_MIN_WQSIZE << shift; *rqdepth = I40IW_QP_SW_MIN_WQSIZE << shift;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment