This patch optimizes implementation of iwl_queue_inc_wrap and iwl_queue_inc_wrap based on the fact the hardware queue is power-of-two size. We also add BUG_ON and BUILD_BUG_ON check for queue size against is_power_of_2 in case future hardwares break this rule. Signed-off-by: Zhu Yi <yi.zhu@xxxxxxxxx> --- drivers/net/wireless/iwl-base.c | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/iwl-base.c b/drivers/net/wireless/iwl-base.c index 4d73b86..becaeea 100644 --- a/drivers/net/wireless/iwl-base.c +++ b/drivers/net/wireless/iwl-base.c @@ -160,14 +160,16 @@ static int iwl_queue_space(const struct iwl_queue *q) return s; } +/* XXX: n_bd must be power-of-two size */ static inline int iwl_queue_inc_wrap(int index, int n_bd) { - return (++index == n_bd) ? 0 : index; + return ++index & (n_bd - 1); } +/* XXX: n_bd must be power-of-two size */ static inline int iwl_queue_dec_wrap(int index, int n_bd) { - return (index == 0) ? n_bd - 1 : index - 1; + return --index & (n_bd - 1); } static inline int x2_queue_used(const struct iwl_queue *q, int i) @@ -192,6 +194,10 @@ static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q, q->n_window = slots_num; q->id = id; + /* count must be power-of-two size, otherwise iwl_queue_inc_wrap + * and iwl_queue_dec_wrap are broken. */ + BUG_ON(!is_power_of_2(count)); + q->low_mark = q->n_window / 4; if (q->low_mark < 4) q->low_mark = 4; @@ -266,9 +272,13 @@ int iwl_tx_queue_init(struct iwl_priv *priv, return -ENOMEM; } - txq->need_update = 0; + + /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise + * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ + BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); iwl_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id); + iwl_hw_tx_queue_init(priv, txq); return 0; -- 1.5.2 - To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html