2 * Copyright (c) 2014 Redpine Signals Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include "rsi_common.h"
21 * rsi_determine_min_weight_queue() - This function determines the queue with
23 * @common: Pointer to the driver private structure.
25 * Return: q_num: Corresponding queue number.
27 static u8 rsi_determine_min_weight_queue(struct rsi_common *common)
29 struct wmm_qinfo *tx_qinfo = common->tx_qinfo;
33 for (ii = 0; ii < NUM_EDCA_QUEUES; ii++) {
34 q_len = skb_queue_len(&common->tx_queue[ii]);
35 if ((tx_qinfo[ii].pkt_contended) && q_len) {
36 common->min_weight = tx_qinfo[ii].weight;
44 * rsi_recalculate_weights() - This function recalculates the weights
45 * corresponding to each queue.
46 * @common: Pointer to the driver private structure.
48 * Return: recontend_queue bool variable
50 static bool rsi_recalculate_weights(struct rsi_common *common)
52 struct wmm_qinfo *tx_qinfo = common->tx_qinfo;
53 bool recontend_queue = false;
57 for (ii = 0; ii < NUM_EDCA_QUEUES; ii++) {
58 q_len = skb_queue_len(&common->tx_queue[ii]);
59 /* Check for the need of contention */
61 if (tx_qinfo[ii].pkt_contended) {
63 ((tx_qinfo[ii].weight > common->min_weight) ?
64 tx_qinfo[ii].weight - common->min_weight : 0);
66 tx_qinfo[ii].pkt_contended = 1;
67 tx_qinfo[ii].weight = tx_qinfo[ii].wme_params;
68 recontend_queue = true;
70 } else { /* No packets so no contention */
71 tx_qinfo[ii].weight = 0;
72 tx_qinfo[ii].pkt_contended = 0;
76 return recontend_queue;
80 * rsi_core_determine_hal_queue() - This function determines the queue from
81 * which packet has to be dequeued.
82 * @common: Pointer to the driver private structure.
84 * Return: q_num: Corresponding queue number on success.
86 static u8 rsi_core_determine_hal_queue(struct rsi_common *common)
88 bool recontend_queue = false;
90 u8 q_num = INVALID_QUEUE;
93 if (skb_queue_len(&common->tx_queue[MGMT_SOFT_Q])) {
94 if (!common->mgmt_q_block)
99 if (common->pkt_cnt != 0) {
101 return common->selected_qnum;
105 recontend_queue = false;
107 q_num = rsi_determine_min_weight_queue(common);
109 q_len = skb_queue_len(&common->tx_queue[ii]);
112 /* Selecting the queue with least back off */
113 for (; ii < NUM_EDCA_QUEUES; ii++) {
114 if (((common->tx_qinfo[ii].pkt_contended) &&
115 (common->tx_qinfo[ii].weight < min)) && q_len) {
116 min = common->tx_qinfo[ii].weight;
121 if (q_num < NUM_EDCA_QUEUES)
122 common->tx_qinfo[q_num].pkt_contended = 0;
124 /* Adjust the back off values for all queues again */
125 recontend_queue = rsi_recalculate_weights(common);
127 q_len = skb_queue_len(&common->tx_queue[q_num]);
129 /* If any queues are freshly contended and the selected queue
130 * doesn't have any packets
131 * then get the queue number again with fresh values
136 q_num = INVALID_QUEUE;
140 common->selected_qnum = q_num;
141 q_len = skb_queue_len(&common->tx_queue[q_num]);
143 switch (common->selected_qnum) {
145 if (q_len > MAX_CONTINUOUS_VO_PKTS)
146 common->pkt_cnt = (MAX_CONTINUOUS_VO_PKTS - 1);
148 common->pkt_cnt = --q_len;
152 if (q_len > MAX_CONTINUOUS_VI_PKTS)
153 common->pkt_cnt = (MAX_CONTINUOUS_VI_PKTS - 1);
155 common->pkt_cnt = --q_len;
168 * rsi_core_queue_pkt() - This functions enqueues the packet to the queue
169 * specified by the queue number.
170 * @common: Pointer to the driver private structure.
171 * @skb: Pointer to the socket buffer structure.
175 static void rsi_core_queue_pkt(struct rsi_common *common,
178 u8 q_num = skb->priority;
179 if (q_num >= NUM_SOFT_QUEUES) {
180 rsi_dbg(ERR_ZONE, "%s: Invalid Queue Number: q_num = %d\n",
186 skb_queue_tail(&common->tx_queue[q_num], skb);
190 * rsi_core_dequeue_pkt() - This functions dequeues the packet from the queue
191 * specified by the queue number.
192 * @common: Pointer to the driver private structure.
193 * @q_num: Queue number.
195 * Return: Pointer to sk_buff structure.
197 static struct sk_buff *rsi_core_dequeue_pkt(struct rsi_common *common,
200 if (q_num >= NUM_SOFT_QUEUES) {
201 rsi_dbg(ERR_ZONE, "%s: Invalid Queue Number: q_num = %d\n",
206 return skb_dequeue(&common->tx_queue[q_num]);
210 * rsi_core_qos_processor() - This function is used to determine the wmm queue
211 * based on the backoff procedure. Data packets are
212 * dequeued from the selected hal queue and sent to
214 * @common: Pointer to the driver private structure.
218 void rsi_core_qos_processor(struct rsi_common *common)
220 struct rsi_hw *adapter = common->priv;
222 unsigned long tstamp_1, tstamp_2;
228 q_num = rsi_core_determine_hal_queue(common);
229 rsi_dbg(DATA_TX_ZONE,
230 "%s: Queue number = %d\n", __func__, q_num);
232 if (q_num == INVALID_QUEUE) {
233 rsi_dbg(DATA_TX_ZONE, "%s: No More Pkt\n", __func__);
237 mutex_lock(&common->tx_rxlock);
239 status = adapter->check_hw_queue_status(adapter, q_num);
241 mutex_unlock(&common->tx_rxlock);
245 if ((q_num < MGMT_SOFT_Q) &&
246 ((skb_queue_len(&common->tx_queue[q_num])) <=
247 MIN_DATA_QUEUE_WATER_MARK)) {
248 if (ieee80211_queue_stopped(adapter->hw, WME_AC(q_num)))
249 ieee80211_wake_queue(adapter->hw,
253 skb = rsi_core_dequeue_pkt(common, q_num);
255 mutex_unlock(&common->tx_rxlock);
259 if (q_num == MGMT_SOFT_Q)
260 status = rsi_send_mgmt_pkt(common, skb);
262 status = rsi_send_data_pkt(common, skb);
265 mutex_unlock(&common->tx_rxlock);
269 common->tx_stats.total_tx_pkt_send[q_num]++;
272 mutex_unlock(&common->tx_rxlock);
274 if (tstamp_2 > tstamp_1 + (300 * HZ / 1000))
280 * rsi_core_xmit() - This function transmits the packets received from mac80211
281 * @common: Pointer to the driver private structure.
282 * @skb: Pointer to the socket buffer structure.
286 void rsi_core_xmit(struct rsi_common *common, struct sk_buff *skb)
288 struct rsi_hw *adapter = common->priv;
289 struct ieee80211_tx_info *info;
290 struct skb_info *tx_params;
291 struct ieee80211_hdr *tmp_hdr = NULL;
294 if ((!skb) || (!skb->len)) {
295 rsi_dbg(ERR_ZONE, "%s: Null skb/zero Length packet\n",
299 info = IEEE80211_SKB_CB(skb);
300 tx_params = (struct skb_info *)info->driver_data;
301 tmp_hdr = (struct ieee80211_hdr *)&skb->data[0];
303 if (common->fsm_state != FSM_MAC_INIT_DONE) {
304 rsi_dbg(ERR_ZONE, "%s: FSM state not open\n", __func__);
308 if ((ieee80211_is_mgmt(tmp_hdr->frame_control)) ||
309 (ieee80211_is_ctl(tmp_hdr->frame_control))) {
311 skb->priority = q_num;
313 if (ieee80211_is_data_qos(tmp_hdr->frame_control)) {
314 tid = (skb->data[24] & IEEE80211_QOS_TID);
315 skb->priority = TID_TO_WME_AC(tid);
317 tid = IEEE80211_NONQOS_TID;
318 skb->priority = BE_Q;
320 q_num = skb->priority;
321 tx_params->tid = tid;
322 tx_params->sta_id = 0;
325 if ((q_num != MGMT_SOFT_Q) &&
326 ((skb_queue_len(&common->tx_queue[q_num]) + 1) >=
327 DATA_QUEUE_WATER_MARK)) {
328 if (!ieee80211_queue_stopped(adapter->hw, WME_AC(q_num)))
329 ieee80211_stop_queue(adapter->hw, WME_AC(q_num));
330 rsi_set_event(&common->tx_thread.event);
334 rsi_core_queue_pkt(common, skb);
335 rsi_dbg(DATA_TX_ZONE, "%s: ===> Scheduling TX thead <===\n", __func__);
336 rsi_set_event(&common->tx_thread.event);
341 rsi_dbg(ERR_ZONE, "%s: Failed to queue packet\n", __func__);
342 /* Dropping pkt here */
343 ieee80211_free_txskb(common->priv->hw, skb);