rsi_91x_main.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/module.h>
  18. #include <linux/firmware.h>
  19. #include "rsi_mgmt.h"
  20. #include "rsi_common.h"
  21. u32 rsi_zone_enabled = /* INFO_ZONE |
  22. INIT_ZONE |
  23. MGMT_TX_ZONE |
  24. MGMT_RX_ZONE |
  25. DATA_TX_ZONE |
  26. DATA_RX_ZONE |
  27. FSM_ZONE |
  28. ISR_ZONE | */
  29. ERR_ZONE |
  30. 0;
  31. EXPORT_SYMBOL_GPL(rsi_zone_enabled);
  32. /**
  33. * rsi_dbg() - This function outputs informational messages.
  34. * @zone: Zone of interest for output message.
  35. * @fmt: printf-style format for output message.
  36. *
  37. * Return: none
  38. */
  39. void rsi_dbg(u32 zone, const char *fmt, ...)
  40. {
  41. struct va_format vaf;
  42. va_list args;
  43. va_start(args, fmt);
  44. vaf.fmt = fmt;
  45. vaf.va = &args;
  46. if (zone & rsi_zone_enabled)
  47. pr_info("%pV", &vaf);
  48. va_end(args);
  49. }
  50. EXPORT_SYMBOL_GPL(rsi_dbg);
  51. /**
  52. * rsi_prepare_skb() - This function prepares the skb.
  53. * @common: Pointer to the driver private structure.
  54. * @buffer: Pointer to the packet data.
  55. * @pkt_len: Length of the packet.
  56. * @extended_desc: Extended descriptor.
  57. *
  58. * Return: Successfully skb.
  59. */
  60. static struct sk_buff *rsi_prepare_skb(struct rsi_common *common,
  61. u8 *buffer,
  62. u32 pkt_len,
  63. u8 extended_desc)
  64. {
  65. struct ieee80211_tx_info *info;
  66. struct skb_info *rx_params;
  67. struct sk_buff *skb = NULL;
  68. u8 payload_offset;
  69. if (WARN(!pkt_len, "%s: Dummy pkt received", __func__))
  70. return NULL;
  71. if (pkt_len > (RSI_RCV_BUFFER_LEN * 4)) {
  72. rsi_dbg(ERR_ZONE, "%s: Pkt size > max rx buf size %d\n",
  73. __func__, pkt_len);
  74. pkt_len = RSI_RCV_BUFFER_LEN * 4;
  75. }
  76. pkt_len -= extended_desc;
  77. skb = dev_alloc_skb(pkt_len + FRAME_DESC_SZ);
  78. if (skb == NULL)
  79. return NULL;
  80. payload_offset = (extended_desc + FRAME_DESC_SZ);
  81. skb_put(skb, pkt_len);
  82. memcpy((skb->data), (buffer + payload_offset), skb->len);
  83. info = IEEE80211_SKB_CB(skb);
  84. rx_params = (struct skb_info *)info->driver_data;
  85. rx_params->rssi = rsi_get_rssi(buffer);
  86. rx_params->channel = rsi_get_connected_channel(common->priv);
  87. return skb;
  88. }
  89. /**
  90. * rsi_read_pkt() - This function reads frames from the card.
  91. * @common: Pointer to the driver private structure.
  92. * @rcv_pkt_len: Received pkt length. In case of USB it is 0.
  93. *
  94. * Return: 0 on success, -1 on failure.
  95. */
  96. int rsi_read_pkt(struct rsi_common *common, s32 rcv_pkt_len)
  97. {
  98. u8 *frame_desc = NULL, extended_desc = 0;
  99. u32 index, length = 0, queueno = 0;
  100. u16 actual_length = 0, offset;
  101. struct sk_buff *skb = NULL;
  102. index = 0;
  103. do {
  104. frame_desc = &common->rx_data_pkt[index];
  105. actual_length = *(u16 *)&frame_desc[0];
  106. offset = *(u16 *)&frame_desc[2];
  107. queueno = rsi_get_queueno(frame_desc, offset);
  108. length = rsi_get_length(frame_desc, offset);
  109. extended_desc = rsi_get_extended_desc(frame_desc, offset);
  110. switch (queueno) {
  111. case RSI_WIFI_DATA_Q:
  112. skb = rsi_prepare_skb(common,
  113. (frame_desc + offset),
  114. length,
  115. extended_desc);
  116. if (skb == NULL)
  117. goto fail;
  118. rsi_indicate_pkt_to_os(common, skb);
  119. break;
  120. case RSI_WIFI_MGMT_Q:
  121. rsi_mgmt_pkt_recv(common, (frame_desc + offset));
  122. break;
  123. default:
  124. rsi_dbg(ERR_ZONE, "%s: pkt from invalid queue: %d\n",
  125. __func__, queueno);
  126. goto fail;
  127. }
  128. index += actual_length;
  129. rcv_pkt_len -= actual_length;
  130. } while (rcv_pkt_len > 0);
  131. return 0;
  132. fail:
  133. return -EINVAL;
  134. }
  135. EXPORT_SYMBOL_GPL(rsi_read_pkt);
  136. /**
  137. * rsi_tx_scheduler_thread() - This function is a kernel thread to send the
  138. * packets to the device.
  139. * @common: Pointer to the driver private structure.
  140. *
  141. * Return: None.
  142. */
  143. static void rsi_tx_scheduler_thread(struct rsi_common *common)
  144. {
  145. struct rsi_hw *adapter = common->priv;
  146. u32 timeout = EVENT_WAIT_FOREVER;
  147. do {
  148. if (adapter->determine_event_timeout)
  149. timeout = adapter->determine_event_timeout(adapter);
  150. rsi_wait_event(&common->tx_thread.event, timeout);
  151. rsi_reset_event(&common->tx_thread.event);
  152. if (common->init_done)
  153. rsi_core_qos_processor(common);
  154. } while (atomic_read(&common->tx_thread.thread_done) == 0);
  155. complete_and_exit(&common->tx_thread.completion, 0);
  156. }
  157. /**
  158. * rsi_91x_init() - This function initializes os interface operations.
  159. * @void: Void.
  160. *
  161. * Return: Pointer to the adapter structure on success, NULL on failure .
  162. */
  163. struct rsi_hw *rsi_91x_init(void)
  164. {
  165. struct rsi_hw *adapter = NULL;
  166. struct rsi_common *common = NULL;
  167. u8 ii = 0;
  168. adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
  169. if (!adapter)
  170. return NULL;
  171. adapter->priv = kzalloc(sizeof(*common), GFP_KERNEL);
  172. if (adapter->priv == NULL) {
  173. rsi_dbg(ERR_ZONE, "%s: Failed in allocation of memory\n",
  174. __func__);
  175. kfree(adapter);
  176. return NULL;
  177. } else {
  178. common = adapter->priv;
  179. common->priv = adapter;
  180. }
  181. for (ii = 0; ii < NUM_SOFT_QUEUES; ii++)
  182. skb_queue_head_init(&common->tx_queue[ii]);
  183. rsi_init_event(&common->tx_thread.event);
  184. mutex_init(&common->mutex);
  185. mutex_init(&common->tx_rxlock);
  186. if (rsi_create_kthread(common,
  187. &common->tx_thread,
  188. rsi_tx_scheduler_thread,
  189. "Tx-Thread")) {
  190. rsi_dbg(ERR_ZONE, "%s: Unable to init tx thrd\n", __func__);
  191. goto err;
  192. }
  193. common->init_done = true;
  194. return adapter;
  195. err:
  196. kfree(common);
  197. kfree(adapter);
  198. return NULL;
  199. }
  200. EXPORT_SYMBOL_GPL(rsi_91x_init);
  201. /**
  202. * rsi_91x_deinit() - This function de-intializes os intf operations.
  203. * @adapter: Pointer to the adapter structure.
  204. *
  205. * Return: None.
  206. */
  207. void rsi_91x_deinit(struct rsi_hw *adapter)
  208. {
  209. struct rsi_common *common = adapter->priv;
  210. u8 ii;
  211. rsi_dbg(INFO_ZONE, "%s: Performing deinit os ops\n", __func__);
  212. rsi_kill_thread(&common->tx_thread);
  213. for (ii = 0; ii < NUM_SOFT_QUEUES; ii++)
  214. skb_queue_purge(&common->tx_queue[ii]);
  215. common->init_done = false;
  216. kfree(common);
  217. kfree(adapter->rsi_dev);
  218. kfree(adapter);
  219. }
  220. EXPORT_SYMBOL_GPL(rsi_91x_deinit);
  221. /**
  222. * rsi_91x_hal_module_init() - This function is invoked when the module is
  223. * loaded into the kernel.
  224. * It registers the client driver.
  225. * @void: Void.
  226. *
  227. * Return: 0 on success, -1 on failure.
  228. */
  229. static int rsi_91x_hal_module_init(void)
  230. {
  231. rsi_dbg(INIT_ZONE, "%s: Module init called\n", __func__);
  232. return 0;
  233. }
  234. /**
  235. * rsi_91x_hal_module_exit() - This function is called at the time of
  236. * removing/unloading the module.
  237. * It unregisters the client driver.
  238. * @void: Void.
  239. *
  240. * Return: None.
  241. */
  242. static void rsi_91x_hal_module_exit(void)
  243. {
  244. rsi_dbg(INIT_ZONE, "%s: Module exit called\n", __func__);
  245. }
  246. module_init(rsi_91x_hal_module_init);
  247. module_exit(rsi_91x_hal_module_exit);
  248. MODULE_AUTHOR("Redpine Signals Inc");
  249. MODULE_DESCRIPTION("Station driver for RSI 91x devices");
  250. MODULE_SUPPORTED_DEVICE("RSI-91x");
  251. MODULE_VERSION("0.1");
  252. MODULE_LICENSE("Dual BSD/GPL");