rsi_91x_core.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /**
  2. * Copyright (c) 2014 Redpine Signals Inc.
  3. *
  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.
  7. *
  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.
  15. */
  16. #include "rsi_mgmt.h"
  17. #include "rsi_common.h"
  18. /**
  19. * rsi_determine_min_weight_queue() - This function determines the queue with
  20. * the min weight.
  21. * @common: Pointer to the driver private structure.
  22. *
  23. * Return: q_num: Corresponding queue number.
  24. */
  25. static u8 rsi_determine_min_weight_queue(struct rsi_common *common)
  26. {
  27. struct wmm_qinfo *tx_qinfo = common->tx_qinfo;
  28. u32 q_len = 0;
  29. u8 ii = 0;
  30. for (ii = 0; ii < NUM_EDCA_QUEUES; ii++) {
  31. q_len = skb_queue_len(&common->tx_queue[ii]);
  32. if ((tx_qinfo[ii].pkt_contended) && q_len) {
  33. common->min_weight = tx_qinfo[ii].weight;
  34. break;
  35. }
  36. }
  37. return ii;
  38. }
  39. /**
  40. * rsi_recalculate_weights() - This function recalculates the weights
  41. * corresponding to each queue.
  42. * @common: Pointer to the driver private structure.
  43. *
  44. * Return: recontend_queue bool variable
  45. */
  46. static bool rsi_recalculate_weights(struct rsi_common *common)
  47. {
  48. struct wmm_qinfo *tx_qinfo = common->tx_qinfo;
  49. bool recontend_queue = false;
  50. u8 ii = 0;
  51. u32 q_len = 0;
  52. for (ii = 0; ii < NUM_EDCA_QUEUES; ii++) {
  53. q_len = skb_queue_len(&common->tx_queue[ii]);
  54. /* Check for the need of contention */
  55. if (q_len) {
  56. if (tx_qinfo[ii].pkt_contended) {
  57. tx_qinfo[ii].weight =
  58. ((tx_qinfo[ii].weight > common->min_weight) ?
  59. tx_qinfo[ii].weight - common->min_weight : 0);
  60. } else {
  61. tx_qinfo[ii].pkt_contended = 1;
  62. tx_qinfo[ii].weight = tx_qinfo[ii].wme_params;
  63. recontend_queue = true;
  64. }
  65. } else { /* No packets so no contention */
  66. tx_qinfo[ii].weight = 0;
  67. tx_qinfo[ii].pkt_contended = 0;
  68. }
  69. }
  70. return recontend_queue;
  71. }
  72. /**
  73. * rsi_get_num_pkts_dequeue() - This function determines the number of
  74. * packets to be dequeued based on the number
  75. * of bytes calculated using txop.
  76. *
  77. * @common: Pointer to the driver private structure.
  78. * @q_num: the queue from which pkts have to be dequeued
  79. *
  80. * Return: pkt_num: Number of pkts to be dequeued.
  81. */
  82. static u32 rsi_get_num_pkts_dequeue(struct rsi_common *common, u8 q_num)
  83. {
  84. struct rsi_hw *adapter = common->priv;
  85. struct sk_buff *skb;
  86. u32 pkt_cnt = 0;
  87. s16 txop = common->tx_qinfo[q_num].txop * 32;
  88. __le16 r_txop;
  89. struct ieee80211_rate rate;
  90. rate.bitrate = RSI_RATE_MCS0 * 5 * 10; /* Convert to Kbps */
  91. if (q_num == VI_Q)
  92. txop = ((txop << 5) / 80);
  93. if (skb_queue_len(&common->tx_queue[q_num]))
  94. skb = skb_peek(&common->tx_queue[q_num]);
  95. else
  96. return 0;
  97. do {
  98. r_txop = ieee80211_generic_frame_duration(adapter->hw,
  99. adapter->vifs[0],
  100. common->band,
  101. skb->len, &rate);
  102. txop -= le16_to_cpu(r_txop);
  103. pkt_cnt += 1;
  104. /*checking if pkts are still there*/
  105. if (skb_queue_len(&common->tx_queue[q_num]) - pkt_cnt)
  106. skb = skb->next;
  107. else
  108. break;
  109. } while (txop > 0);
  110. return pkt_cnt;
  111. }
  112. /**
  113. * rsi_core_determine_hal_queue() - This function determines the queue from
  114. * which packet has to be dequeued.
  115. * @common: Pointer to the driver private structure.
  116. *
  117. * Return: q_num: Corresponding queue number on success.
  118. */
  119. static u8 rsi_core_determine_hal_queue(struct rsi_common *common)
  120. {
  121. bool recontend_queue = false;
  122. u32 q_len = 0;
  123. u8 q_num = INVALID_QUEUE;
  124. u8 ii = 0;
  125. if (skb_queue_len(&common->tx_queue[MGMT_SOFT_Q])) {
  126. if (!common->mgmt_q_block)
  127. q_num = MGMT_SOFT_Q;
  128. return q_num;
  129. }
  130. if (common->hw_data_qs_blocked)
  131. return q_num;
  132. if (common->pkt_cnt != 0) {
  133. --common->pkt_cnt;
  134. return common->selected_qnum;
  135. }
  136. get_queue_num:
  137. recontend_queue = false;
  138. q_num = rsi_determine_min_weight_queue(common);
  139. ii = q_num;
  140. /* Selecting the queue with least back off */
  141. for (; ii < NUM_EDCA_QUEUES; ii++) {
  142. q_len = skb_queue_len(&common->tx_queue[ii]);
  143. if (((common->tx_qinfo[ii].pkt_contended) &&
  144. (common->tx_qinfo[ii].weight < common->min_weight)) &&
  145. q_len) {
  146. common->min_weight = common->tx_qinfo[ii].weight;
  147. q_num = ii;
  148. }
  149. }
  150. if (q_num < NUM_EDCA_QUEUES)
  151. common->tx_qinfo[q_num].pkt_contended = 0;
  152. /* Adjust the back off values for all queues again */
  153. recontend_queue = rsi_recalculate_weights(common);
  154. q_len = skb_queue_len(&common->tx_queue[q_num]);
  155. if (!q_len) {
  156. /* If any queues are freshly contended and the selected queue
  157. * doesn't have any packets
  158. * then get the queue number again with fresh values
  159. */
  160. if (recontend_queue)
  161. goto get_queue_num;
  162. q_num = INVALID_QUEUE;
  163. return q_num;
  164. }
  165. common->selected_qnum = q_num;
  166. q_len = skb_queue_len(&common->tx_queue[q_num]);
  167. if (q_num == VO_Q || q_num == VI_Q) {
  168. common->pkt_cnt = rsi_get_num_pkts_dequeue(common, q_num);
  169. common->pkt_cnt -= 1;
  170. }
  171. return q_num;
  172. }
  173. /**
  174. * rsi_core_queue_pkt() - This functions enqueues the packet to the queue
  175. * specified by the queue number.
  176. * @common: Pointer to the driver private structure.
  177. * @skb: Pointer to the socket buffer structure.
  178. *
  179. * Return: None.
  180. */
  181. static void rsi_core_queue_pkt(struct rsi_common *common,
  182. struct sk_buff *skb)
  183. {
  184. u8 q_num = skb->priority;
  185. if (q_num >= NUM_SOFT_QUEUES) {
  186. rsi_dbg(ERR_ZONE, "%s: Invalid Queue Number: q_num = %d\n",
  187. __func__, q_num);
  188. dev_kfree_skb(skb);
  189. return;
  190. }
  191. skb_queue_tail(&common->tx_queue[q_num], skb);
  192. }
  193. /**
  194. * rsi_core_dequeue_pkt() - This functions dequeues the packet from the queue
  195. * specified by the queue number.
  196. * @common: Pointer to the driver private structure.
  197. * @q_num: Queue number.
  198. *
  199. * Return: Pointer to sk_buff structure.
  200. */
  201. static struct sk_buff *rsi_core_dequeue_pkt(struct rsi_common *common,
  202. u8 q_num)
  203. {
  204. if (q_num >= NUM_SOFT_QUEUES) {
  205. rsi_dbg(ERR_ZONE, "%s: Invalid Queue Number: q_num = %d\n",
  206. __func__, q_num);
  207. return NULL;
  208. }
  209. return skb_dequeue(&common->tx_queue[q_num]);
  210. }
  211. /**
  212. * rsi_core_qos_processor() - This function is used to determine the wmm queue
  213. * based on the backoff procedure. Data packets are
  214. * dequeued from the selected hal queue and sent to
  215. * the below layers.
  216. * @common: Pointer to the driver private structure.
  217. *
  218. * Return: None.
  219. */
  220. void rsi_core_qos_processor(struct rsi_common *common)
  221. {
  222. struct rsi_hw *adapter = common->priv;
  223. struct sk_buff *skb;
  224. unsigned long tstamp_1, tstamp_2;
  225. u8 q_num;
  226. int status;
  227. tstamp_1 = jiffies;
  228. while (1) {
  229. q_num = rsi_core_determine_hal_queue(common);
  230. rsi_dbg(DATA_TX_ZONE,
  231. "%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__);
  234. break;
  235. }
  236. mutex_lock(&common->tx_rxlock);
  237. status = adapter->check_hw_queue_status(adapter, q_num);
  238. if ((status <= 0)) {
  239. mutex_unlock(&common->tx_rxlock);
  240. break;
  241. }
  242. if ((q_num < MGMT_SOFT_Q) &&
  243. ((skb_queue_len(&common->tx_queue[q_num])) <=
  244. MIN_DATA_QUEUE_WATER_MARK)) {
  245. if (ieee80211_queue_stopped(adapter->hw, WME_AC(q_num)))
  246. ieee80211_wake_queue(adapter->hw,
  247. WME_AC(q_num));
  248. }
  249. skb = rsi_core_dequeue_pkt(common, q_num);
  250. if (skb == NULL) {
  251. rsi_dbg(ERR_ZONE, "skb null\n");
  252. mutex_unlock(&common->tx_rxlock);
  253. break;
  254. }
  255. if (q_num == MGMT_SOFT_Q)
  256. status = rsi_send_mgmt_pkt(common, skb);
  257. else
  258. status = rsi_send_data_pkt(common, skb);
  259. if (status) {
  260. mutex_unlock(&common->tx_rxlock);
  261. break;
  262. }
  263. common->tx_stats.total_tx_pkt_send[q_num]++;
  264. tstamp_2 = jiffies;
  265. mutex_unlock(&common->tx_rxlock);
  266. if (tstamp_2 > tstamp_1 + (300 * HZ / 1000))
  267. schedule();
  268. }
  269. }
  270. /**
  271. * rsi_core_xmit() - This function transmits the packets received from mac80211
  272. * @common: Pointer to the driver private structure.
  273. * @skb: Pointer to the socket buffer structure.
  274. *
  275. * Return: None.
  276. */
  277. void rsi_core_xmit(struct rsi_common *common, struct sk_buff *skb)
  278. {
  279. struct rsi_hw *adapter = common->priv;
  280. struct ieee80211_tx_info *info;
  281. struct skb_info *tx_params;
  282. struct ieee80211_hdr *tmp_hdr = NULL;
  283. u8 q_num, tid = 0;
  284. if ((!skb) || (!skb->len)) {
  285. rsi_dbg(ERR_ZONE, "%s: Null skb/zero Length packet\n",
  286. __func__);
  287. goto xmit_fail;
  288. }
  289. info = IEEE80211_SKB_CB(skb);
  290. tx_params = (struct skb_info *)info->driver_data;
  291. tmp_hdr = (struct ieee80211_hdr *)&skb->data[0];
  292. if (common->fsm_state != FSM_MAC_INIT_DONE) {
  293. rsi_dbg(ERR_ZONE, "%s: FSM state not open\n", __func__);
  294. goto xmit_fail;
  295. }
  296. if ((ieee80211_is_mgmt(tmp_hdr->frame_control)) ||
  297. (ieee80211_is_ctl(tmp_hdr->frame_control)) ||
  298. (ieee80211_is_qos_nullfunc(tmp_hdr->frame_control))) {
  299. q_num = MGMT_SOFT_Q;
  300. skb->priority = q_num;
  301. } else {
  302. if (ieee80211_is_data_qos(tmp_hdr->frame_control)) {
  303. tid = (skb->data[24] & IEEE80211_QOS_TID);
  304. skb->priority = TID_TO_WME_AC(tid);
  305. } else {
  306. tid = IEEE80211_NONQOS_TID;
  307. skb->priority = BE_Q;
  308. }
  309. q_num = skb->priority;
  310. tx_params->tid = tid;
  311. tx_params->sta_id = 0;
  312. }
  313. if ((q_num != MGMT_SOFT_Q) &&
  314. ((skb_queue_len(&common->tx_queue[q_num]) + 1) >=
  315. DATA_QUEUE_WATER_MARK)) {
  316. rsi_dbg(ERR_ZONE, "%s: sw queue full\n", __func__);
  317. if (!ieee80211_queue_stopped(adapter->hw, WME_AC(q_num)))
  318. ieee80211_stop_queue(adapter->hw, WME_AC(q_num));
  319. rsi_set_event(&common->tx_thread.event);
  320. goto xmit_fail;
  321. }
  322. rsi_core_queue_pkt(common, skb);
  323. rsi_dbg(DATA_TX_ZONE, "%s: ===> Scheduling TX thead <===\n", __func__);
  324. rsi_set_event(&common->tx_thread.event);
  325. return;
  326. xmit_fail:
  327. rsi_dbg(ERR_ZONE, "%s: Failed to queue packet\n", __func__);
  328. /* Dropping pkt here */
  329. ieee80211_free_txskb(common->priv->hw, skb);
  330. }