aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIdo Yariv <ido@wizery.com>2013-07-15 11:51:48 -0400
committerJohannes Berg <johannes.berg@intel.com>2013-08-09 08:38:01 -0400
commita9b292464311d32441cd3284109263d92c413a48 (patch)
tree1616ea348a4df921403c3c7c6f77ff79bfc4ba63
parentf4f3c659846587aae9043d2df31f6434934965e1 (diff)
iwlwifi: pcie: Refactor iwl_queue_space
Reduce the ambiguity spares to a single element if the window size is not smaller than the queue size. If smaller, no spares are required at all. Signed-off-by: Ido Yariv <ido@wizery.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/tx.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/drivers/net/wireless/iwlwifi/pcie/tx.c b/drivers/net/wireless/iwlwifi/pcie/tx.c
index 011167c22da8..12c9c0030da6 100644
--- a/drivers/net/wireless/iwlwifi/pcie/tx.c
+++ b/drivers/net/wireless/iwlwifi/pcie/tx.c
@@ -65,18 +65,30 @@
65 ***************************************************/ 65 ***************************************************/
66static int iwl_queue_space(const struct iwl_queue *q) 66static int iwl_queue_space(const struct iwl_queue *q)
67{ 67{
68 int s = q->read_ptr - q->write_ptr; 68 unsigned int max;
69 69 unsigned int used;
70 if (q->read_ptr > q->write_ptr) 70
71 s -= q->n_bd; 71 /*
72 72 * To avoid ambiguity between empty and completely full queues, there
73 if (s <= 0) 73 * should always be less than q->n_bd elements in the queue.
74 s += q->n_window; 74 * If q->n_window is smaller than q->n_bd, there is no need to reserve
75 /* keep some reserve to not confuse empty and full situations */ 75 * any queue entries for this purpose.
76 s -= 2; 76 */
77 if (s < 0) 77 if (q->n_window < q->n_bd)
78 s = 0; 78 max = q->n_window;
79 return s; 79 else
80 max = q->n_bd - 1;
81
82 /*
83 * q->n_bd is a power of 2, so the following is equivalent to modulo by
84 * q->n_bd and is well defined for negative dividends.
85 */
86 used = (q->write_ptr - q->read_ptr) & (q->n_bd - 1);
87
88 if (WARN_ON(used > max))
89 return 0;
90
91 return max - used;
80} 92}
81 93
82/* 94/*