dxe.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /*
  2. * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
  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 ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /* DXE - DMA transfer engine
  17. * we have 2 channels(High prio and Low prio) for TX and 2 channels for RX.
  18. * through low channels data packets are transfered
  19. * through high channels managment packets are transfered
  20. */
  21. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <linux/interrupt.h>
  23. #include "wcn36xx.h"
  24. #include "txrx.h"
  25. void *wcn36xx_dxe_get_next_bd(struct wcn36xx *wcn, bool is_low)
  26. {
  27. struct wcn36xx_dxe_ch *ch = is_low ?
  28. &wcn->dxe_tx_l_ch :
  29. &wcn->dxe_tx_h_ch;
  30. return ch->head_blk_ctl->bd_cpu_addr;
  31. }
  32. static void wcn36xx_dxe_write_register(struct wcn36xx *wcn, int addr, int data)
  33. {
  34. wcn36xx_dbg(WCN36XX_DBG_DXE,
  35. "wcn36xx_dxe_write_register: addr=%x, data=%x\n",
  36. addr, data);
  37. writel(data, wcn->mmio + addr);
  38. }
  39. static void wcn36xx_dxe_read_register(struct wcn36xx *wcn, int addr, int *data)
  40. {
  41. *data = readl(wcn->mmio + addr);
  42. wcn36xx_dbg(WCN36XX_DBG_DXE,
  43. "wcn36xx_dxe_read_register: addr=%x, data=%x\n",
  44. addr, *data);
  45. }
  46. static void wcn36xx_dxe_free_ctl_block(struct wcn36xx_dxe_ch *ch)
  47. {
  48. struct wcn36xx_dxe_ctl *ctl = ch->head_blk_ctl, *next;
  49. int i;
  50. for (i = 0; i < ch->desc_num && ctl; i++) {
  51. next = ctl->next;
  52. kfree(ctl);
  53. ctl = next;
  54. }
  55. }
  56. static int wcn36xx_dxe_allocate_ctl_block(struct wcn36xx_dxe_ch *ch)
  57. {
  58. struct wcn36xx_dxe_ctl *prev_ctl = NULL;
  59. struct wcn36xx_dxe_ctl *cur_ctl = NULL;
  60. int i;
  61. for (i = 0; i < ch->desc_num; i++) {
  62. cur_ctl = kzalloc(sizeof(*cur_ctl), GFP_KERNEL);
  63. if (!cur_ctl)
  64. goto out_fail;
  65. cur_ctl->ctl_blk_order = i;
  66. if (i == 0) {
  67. ch->head_blk_ctl = cur_ctl;
  68. ch->tail_blk_ctl = cur_ctl;
  69. } else if (ch->desc_num - 1 == i) {
  70. prev_ctl->next = cur_ctl;
  71. cur_ctl->next = ch->head_blk_ctl;
  72. } else {
  73. prev_ctl->next = cur_ctl;
  74. }
  75. prev_ctl = cur_ctl;
  76. }
  77. return 0;
  78. out_fail:
  79. wcn36xx_dxe_free_ctl_block(ch);
  80. return -ENOMEM;
  81. }
  82. int wcn36xx_dxe_alloc_ctl_blks(struct wcn36xx *wcn)
  83. {
  84. int ret;
  85. wcn->dxe_tx_l_ch.ch_type = WCN36XX_DXE_CH_TX_L;
  86. wcn->dxe_tx_h_ch.ch_type = WCN36XX_DXE_CH_TX_H;
  87. wcn->dxe_rx_l_ch.ch_type = WCN36XX_DXE_CH_RX_L;
  88. wcn->dxe_rx_h_ch.ch_type = WCN36XX_DXE_CH_RX_H;
  89. wcn->dxe_tx_l_ch.desc_num = WCN36XX_DXE_CH_DESC_NUMB_TX_L;
  90. wcn->dxe_tx_h_ch.desc_num = WCN36XX_DXE_CH_DESC_NUMB_TX_H;
  91. wcn->dxe_rx_l_ch.desc_num = WCN36XX_DXE_CH_DESC_NUMB_RX_L;
  92. wcn->dxe_rx_h_ch.desc_num = WCN36XX_DXE_CH_DESC_NUMB_RX_H;
  93. wcn->dxe_tx_l_ch.dxe_wq = WCN36XX_DXE_WQ_TX_L;
  94. wcn->dxe_tx_h_ch.dxe_wq = WCN36XX_DXE_WQ_TX_H;
  95. wcn->dxe_tx_l_ch.ctrl_bd = WCN36XX_DXE_CTRL_TX_L_BD;
  96. wcn->dxe_tx_h_ch.ctrl_bd = WCN36XX_DXE_CTRL_TX_H_BD;
  97. wcn->dxe_tx_l_ch.ctrl_skb = WCN36XX_DXE_CTRL_TX_L_SKB;
  98. wcn->dxe_tx_h_ch.ctrl_skb = WCN36XX_DXE_CTRL_TX_H_SKB;
  99. wcn->dxe_tx_l_ch.reg_ctrl = WCN36XX_DXE_REG_CTL_TX_L;
  100. wcn->dxe_tx_h_ch.reg_ctrl = WCN36XX_DXE_REG_CTL_TX_H;
  101. wcn->dxe_tx_l_ch.def_ctrl = WCN36XX_DXE_CH_DEFAULT_CTL_TX_L;
  102. wcn->dxe_tx_h_ch.def_ctrl = WCN36XX_DXE_CH_DEFAULT_CTL_TX_H;
  103. /* DXE control block allocation */
  104. ret = wcn36xx_dxe_allocate_ctl_block(&wcn->dxe_tx_l_ch);
  105. if (ret)
  106. goto out_err;
  107. ret = wcn36xx_dxe_allocate_ctl_block(&wcn->dxe_tx_h_ch);
  108. if (ret)
  109. goto out_err;
  110. ret = wcn36xx_dxe_allocate_ctl_block(&wcn->dxe_rx_l_ch);
  111. if (ret)
  112. goto out_err;
  113. ret = wcn36xx_dxe_allocate_ctl_block(&wcn->dxe_rx_h_ch);
  114. if (ret)
  115. goto out_err;
  116. /* Initialize SMSM state Clear TX Enable RING EMPTY STATE */
  117. ret = wcn->ctrl_ops->smsm_change_state(
  118. WCN36XX_SMSM_WLAN_TX_ENABLE,
  119. WCN36XX_SMSM_WLAN_TX_RINGS_EMPTY);
  120. return 0;
  121. out_err:
  122. wcn36xx_err("Failed to allocate DXE control blocks\n");
  123. wcn36xx_dxe_free_ctl_blks(wcn);
  124. return -ENOMEM;
  125. }
  126. void wcn36xx_dxe_free_ctl_blks(struct wcn36xx *wcn)
  127. {
  128. wcn36xx_dxe_free_ctl_block(&wcn->dxe_tx_l_ch);
  129. wcn36xx_dxe_free_ctl_block(&wcn->dxe_tx_h_ch);
  130. wcn36xx_dxe_free_ctl_block(&wcn->dxe_rx_l_ch);
  131. wcn36xx_dxe_free_ctl_block(&wcn->dxe_rx_h_ch);
  132. }
  133. static int wcn36xx_dxe_init_descs(struct wcn36xx_dxe_ch *wcn_ch)
  134. {
  135. struct wcn36xx_dxe_desc *cur_dxe = NULL;
  136. struct wcn36xx_dxe_desc *prev_dxe = NULL;
  137. struct wcn36xx_dxe_ctl *cur_ctl = NULL;
  138. size_t size;
  139. int i;
  140. size = wcn_ch->desc_num * sizeof(struct wcn36xx_dxe_desc);
  141. wcn_ch->cpu_addr = dma_alloc_coherent(NULL, size, &wcn_ch->dma_addr,
  142. GFP_KERNEL);
  143. if (!wcn_ch->cpu_addr)
  144. return -ENOMEM;
  145. memset(wcn_ch->cpu_addr, 0, size);
  146. cur_dxe = (struct wcn36xx_dxe_desc *)wcn_ch->cpu_addr;
  147. cur_ctl = wcn_ch->head_blk_ctl;
  148. for (i = 0; i < wcn_ch->desc_num; i++) {
  149. cur_ctl->desc = cur_dxe;
  150. cur_ctl->desc_phy_addr = wcn_ch->dma_addr +
  151. i * sizeof(struct wcn36xx_dxe_desc);
  152. switch (wcn_ch->ch_type) {
  153. case WCN36XX_DXE_CH_TX_L:
  154. cur_dxe->ctrl = WCN36XX_DXE_CTRL_TX_L;
  155. cur_dxe->dst_addr_l = WCN36XX_DXE_WQ_TX_L;
  156. break;
  157. case WCN36XX_DXE_CH_TX_H:
  158. cur_dxe->ctrl = WCN36XX_DXE_CTRL_TX_H;
  159. cur_dxe->dst_addr_l = WCN36XX_DXE_WQ_TX_H;
  160. break;
  161. case WCN36XX_DXE_CH_RX_L:
  162. cur_dxe->ctrl = WCN36XX_DXE_CTRL_RX_L;
  163. cur_dxe->src_addr_l = WCN36XX_DXE_WQ_RX_L;
  164. break;
  165. case WCN36XX_DXE_CH_RX_H:
  166. cur_dxe->ctrl = WCN36XX_DXE_CTRL_RX_H;
  167. cur_dxe->src_addr_l = WCN36XX_DXE_WQ_RX_H;
  168. break;
  169. }
  170. if (0 == i) {
  171. cur_dxe->phy_next_l = 0;
  172. } else if ((0 < i) && (i < wcn_ch->desc_num - 1)) {
  173. prev_dxe->phy_next_l =
  174. cur_ctl->desc_phy_addr;
  175. } else if (i == (wcn_ch->desc_num - 1)) {
  176. prev_dxe->phy_next_l =
  177. cur_ctl->desc_phy_addr;
  178. cur_dxe->phy_next_l =
  179. wcn_ch->head_blk_ctl->desc_phy_addr;
  180. }
  181. cur_ctl = cur_ctl->next;
  182. prev_dxe = cur_dxe;
  183. cur_dxe++;
  184. }
  185. return 0;
  186. }
  187. static void wcn36xx_dxe_init_tx_bd(struct wcn36xx_dxe_ch *ch,
  188. struct wcn36xx_dxe_mem_pool *pool)
  189. {
  190. int i, chunk_size = pool->chunk_size;
  191. dma_addr_t bd_phy_addr = pool->phy_addr;
  192. void *bd_cpu_addr = pool->virt_addr;
  193. struct wcn36xx_dxe_ctl *cur = ch->head_blk_ctl;
  194. for (i = 0; i < ch->desc_num; i++) {
  195. /* Only every second dxe needs a bd pointer,
  196. the other will point to the skb data */
  197. if (!(i & 1)) {
  198. cur->bd_phy_addr = bd_phy_addr;
  199. cur->bd_cpu_addr = bd_cpu_addr;
  200. bd_phy_addr += chunk_size;
  201. bd_cpu_addr += chunk_size;
  202. } else {
  203. cur->bd_phy_addr = 0;
  204. cur->bd_cpu_addr = NULL;
  205. }
  206. cur = cur->next;
  207. }
  208. }
  209. static int wcn36xx_dxe_enable_ch_int(struct wcn36xx *wcn, u16 wcn_ch)
  210. {
  211. int reg_data = 0;
  212. wcn36xx_dxe_read_register(wcn,
  213. WCN36XX_DXE_INT_MASK_REG,
  214. &reg_data);
  215. reg_data |= wcn_ch;
  216. wcn36xx_dxe_write_register(wcn,
  217. WCN36XX_DXE_INT_MASK_REG,
  218. (int)reg_data);
  219. return 0;
  220. }
  221. static int wcn36xx_dxe_fill_skb(struct wcn36xx_dxe_ctl *ctl)
  222. {
  223. struct wcn36xx_dxe_desc *dxe = ctl->desc;
  224. struct sk_buff *skb;
  225. skb = alloc_skb(WCN36XX_PKT_SIZE, GFP_ATOMIC);
  226. if (skb == NULL)
  227. return -ENOMEM;
  228. dxe->dst_addr_l = dma_map_single(NULL,
  229. skb_tail_pointer(skb),
  230. WCN36XX_PKT_SIZE,
  231. DMA_FROM_DEVICE);
  232. ctl->skb = skb;
  233. return 0;
  234. }
  235. static int wcn36xx_dxe_ch_alloc_skb(struct wcn36xx *wcn,
  236. struct wcn36xx_dxe_ch *wcn_ch)
  237. {
  238. int i;
  239. struct wcn36xx_dxe_ctl *cur_ctl = NULL;
  240. cur_ctl = wcn_ch->head_blk_ctl;
  241. for (i = 0; i < wcn_ch->desc_num; i++) {
  242. wcn36xx_dxe_fill_skb(cur_ctl);
  243. cur_ctl = cur_ctl->next;
  244. }
  245. return 0;
  246. }
  247. static void wcn36xx_dxe_ch_free_skbs(struct wcn36xx *wcn,
  248. struct wcn36xx_dxe_ch *wcn_ch)
  249. {
  250. struct wcn36xx_dxe_ctl *cur = wcn_ch->head_blk_ctl;
  251. int i;
  252. for (i = 0; i < wcn_ch->desc_num; i++) {
  253. kfree_skb(cur->skb);
  254. cur = cur->next;
  255. }
  256. }
  257. void wcn36xx_dxe_tx_ack_ind(struct wcn36xx *wcn, u32 status)
  258. {
  259. struct ieee80211_tx_info *info;
  260. struct sk_buff *skb;
  261. unsigned long flags;
  262. spin_lock_irqsave(&wcn->dxe_lock, flags);
  263. skb = wcn->tx_ack_skb;
  264. wcn->tx_ack_skb = NULL;
  265. spin_unlock_irqrestore(&wcn->dxe_lock, flags);
  266. if (!skb) {
  267. wcn36xx_warn("Spurious TX complete indication\n");
  268. return;
  269. }
  270. info = IEEE80211_SKB_CB(skb);
  271. if (status == 1)
  272. info->flags |= IEEE80211_TX_STAT_ACK;
  273. wcn36xx_dbg(WCN36XX_DBG_DXE, "dxe tx ack status: %d\n", status);
  274. ieee80211_tx_status_irqsafe(wcn->hw, skb);
  275. ieee80211_wake_queues(wcn->hw);
  276. }
  277. static void reap_tx_dxes(struct wcn36xx *wcn, struct wcn36xx_dxe_ch *ch)
  278. {
  279. struct wcn36xx_dxe_ctl *ctl = ch->tail_blk_ctl;
  280. struct ieee80211_tx_info *info;
  281. unsigned long flags;
  282. /*
  283. * Make at least one loop of do-while because in case ring is
  284. * completely full head and tail are pointing to the same element
  285. * and while-do will not make any cycles.
  286. */
  287. do {
  288. if (ctl->skb) {
  289. dma_unmap_single(NULL, ctl->desc->src_addr_l,
  290. ctl->skb->len, DMA_TO_DEVICE);
  291. info = IEEE80211_SKB_CB(ctl->skb);
  292. if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)) {
  293. /* Keep frame until TX status comes */
  294. ieee80211_free_txskb(wcn->hw, ctl->skb);
  295. }
  296. spin_lock_irqsave(&ctl->skb_lock, flags);
  297. if (wcn->queues_stopped) {
  298. wcn->queues_stopped = false;
  299. ieee80211_wake_queues(wcn->hw);
  300. }
  301. spin_unlock_irqrestore(&ctl->skb_lock, flags);
  302. ctl->skb = NULL;
  303. }
  304. ctl = ctl->next;
  305. } while (ctl != ch->head_blk_ctl &&
  306. !(ctl->desc->ctrl & WCN36XX_DXE_CTRL_VALID_MASK));
  307. ch->tail_blk_ctl = ctl;
  308. }
  309. static irqreturn_t wcn36xx_irq_tx_complete(int irq, void *dev)
  310. {
  311. struct wcn36xx *wcn = (struct wcn36xx *)dev;
  312. int int_src, int_reason;
  313. wcn36xx_dxe_read_register(wcn, WCN36XX_DXE_INT_SRC_RAW_REG, &int_src);
  314. if (int_src & WCN36XX_INT_MASK_CHAN_TX_H) {
  315. wcn36xx_dxe_read_register(wcn,
  316. WCN36XX_DXE_CH_STATUS_REG_ADDR_TX_H,
  317. &int_reason);
  318. /* TODO: Check int_reason */
  319. wcn36xx_dxe_write_register(wcn,
  320. WCN36XX_DXE_0_INT_CLR,
  321. WCN36XX_INT_MASK_CHAN_TX_H);
  322. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_0_INT_ED_CLR,
  323. WCN36XX_INT_MASK_CHAN_TX_H);
  324. wcn36xx_dbg(WCN36XX_DBG_DXE, "dxe tx ready high\n");
  325. reap_tx_dxes(wcn, &wcn->dxe_tx_h_ch);
  326. }
  327. if (int_src & WCN36XX_INT_MASK_CHAN_TX_L) {
  328. wcn36xx_dxe_read_register(wcn,
  329. WCN36XX_DXE_CH_STATUS_REG_ADDR_TX_L,
  330. &int_reason);
  331. /* TODO: Check int_reason */
  332. wcn36xx_dxe_write_register(wcn,
  333. WCN36XX_DXE_0_INT_CLR,
  334. WCN36XX_INT_MASK_CHAN_TX_L);
  335. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_0_INT_ED_CLR,
  336. WCN36XX_INT_MASK_CHAN_TX_L);
  337. wcn36xx_dbg(WCN36XX_DBG_DXE, "dxe tx ready low\n");
  338. reap_tx_dxes(wcn, &wcn->dxe_tx_l_ch);
  339. }
  340. return IRQ_HANDLED;
  341. }
  342. static irqreturn_t wcn36xx_irq_rx_ready(int irq, void *dev)
  343. {
  344. struct wcn36xx *wcn = (struct wcn36xx *)dev;
  345. disable_irq_nosync(wcn->rx_irq);
  346. wcn36xx_dxe_rx_frame(wcn);
  347. enable_irq(wcn->rx_irq);
  348. return IRQ_HANDLED;
  349. }
  350. static int wcn36xx_dxe_request_irqs(struct wcn36xx *wcn)
  351. {
  352. int ret;
  353. ret = request_irq(wcn->tx_irq, wcn36xx_irq_tx_complete,
  354. IRQF_TRIGGER_HIGH, "wcn36xx_tx", wcn);
  355. if (ret) {
  356. wcn36xx_err("failed to alloc tx irq\n");
  357. goto out_err;
  358. }
  359. ret = request_irq(wcn->rx_irq, wcn36xx_irq_rx_ready, IRQF_TRIGGER_HIGH,
  360. "wcn36xx_rx", wcn);
  361. if (ret) {
  362. wcn36xx_err("failed to alloc rx irq\n");
  363. goto out_txirq;
  364. }
  365. enable_irq_wake(wcn->rx_irq);
  366. return 0;
  367. out_txirq:
  368. free_irq(wcn->tx_irq, wcn);
  369. out_err:
  370. return ret;
  371. }
  372. static int wcn36xx_rx_handle_packets(struct wcn36xx *wcn,
  373. struct wcn36xx_dxe_ch *ch)
  374. {
  375. struct wcn36xx_dxe_ctl *ctl = ch->head_blk_ctl;
  376. struct wcn36xx_dxe_desc *dxe = ctl->desc;
  377. dma_addr_t dma_addr;
  378. struct sk_buff *skb;
  379. while (!(dxe->ctrl & WCN36XX_DXE_CTRL_VALID_MASK)) {
  380. skb = ctl->skb;
  381. dma_addr = dxe->dst_addr_l;
  382. wcn36xx_dxe_fill_skb(ctl);
  383. switch (ch->ch_type) {
  384. case WCN36XX_DXE_CH_RX_L:
  385. dxe->ctrl = WCN36XX_DXE_CTRL_RX_L;
  386. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_ENCH_ADDR,
  387. WCN36XX_DXE_INT_CH1_MASK);
  388. break;
  389. case WCN36XX_DXE_CH_RX_H:
  390. dxe->ctrl = WCN36XX_DXE_CTRL_RX_H;
  391. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_ENCH_ADDR,
  392. WCN36XX_DXE_INT_CH3_MASK);
  393. break;
  394. default:
  395. wcn36xx_warn("Unknown channel\n");
  396. }
  397. dma_unmap_single(NULL, dma_addr, WCN36XX_PKT_SIZE,
  398. DMA_FROM_DEVICE);
  399. wcn36xx_rx_skb(wcn, skb);
  400. ctl = ctl->next;
  401. dxe = ctl->desc;
  402. }
  403. ch->head_blk_ctl = ctl;
  404. return 0;
  405. }
  406. void wcn36xx_dxe_rx_frame(struct wcn36xx *wcn)
  407. {
  408. int int_src;
  409. wcn36xx_dxe_read_register(wcn, WCN36XX_DXE_INT_SRC_RAW_REG, &int_src);
  410. /* RX_LOW_PRI */
  411. if (int_src & WCN36XX_DXE_INT_CH1_MASK) {
  412. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_0_INT_CLR,
  413. WCN36XX_DXE_INT_CH1_MASK);
  414. wcn36xx_rx_handle_packets(wcn, &(wcn->dxe_rx_l_ch));
  415. }
  416. /* RX_HIGH_PRI */
  417. if (int_src & WCN36XX_DXE_INT_CH3_MASK) {
  418. /* Clean up all the INT within this channel */
  419. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_0_INT_CLR,
  420. WCN36XX_DXE_INT_CH3_MASK);
  421. wcn36xx_rx_handle_packets(wcn, &(wcn->dxe_rx_h_ch));
  422. }
  423. if (!int_src)
  424. wcn36xx_warn("No DXE interrupt pending\n");
  425. }
  426. int wcn36xx_dxe_allocate_mem_pools(struct wcn36xx *wcn)
  427. {
  428. size_t s;
  429. void *cpu_addr;
  430. /* Allocate BD headers for MGMT frames */
  431. /* Where this come from ask QC */
  432. wcn->mgmt_mem_pool.chunk_size = WCN36XX_BD_CHUNK_SIZE +
  433. 16 - (WCN36XX_BD_CHUNK_SIZE % 8);
  434. s = wcn->mgmt_mem_pool.chunk_size * WCN36XX_DXE_CH_DESC_NUMB_TX_H;
  435. cpu_addr = dma_alloc_coherent(NULL, s, &wcn->mgmt_mem_pool.phy_addr,
  436. GFP_KERNEL);
  437. if (!cpu_addr)
  438. goto out_err;
  439. wcn->mgmt_mem_pool.virt_addr = cpu_addr;
  440. memset(cpu_addr, 0, s);
  441. /* Allocate BD headers for DATA frames */
  442. /* Where this come from ask QC */
  443. wcn->data_mem_pool.chunk_size = WCN36XX_BD_CHUNK_SIZE +
  444. 16 - (WCN36XX_BD_CHUNK_SIZE % 8);
  445. s = wcn->data_mem_pool.chunk_size * WCN36XX_DXE_CH_DESC_NUMB_TX_L;
  446. cpu_addr = dma_alloc_coherent(NULL, s, &wcn->data_mem_pool.phy_addr,
  447. GFP_KERNEL);
  448. if (!cpu_addr)
  449. goto out_err;
  450. wcn->data_mem_pool.virt_addr = cpu_addr;
  451. memset(cpu_addr, 0, s);
  452. return 0;
  453. out_err:
  454. wcn36xx_dxe_free_mem_pools(wcn);
  455. wcn36xx_err("Failed to allocate BD mempool\n");
  456. return -ENOMEM;
  457. }
  458. void wcn36xx_dxe_free_mem_pools(struct wcn36xx *wcn)
  459. {
  460. if (wcn->mgmt_mem_pool.virt_addr)
  461. dma_free_coherent(NULL, wcn->mgmt_mem_pool.chunk_size *
  462. WCN36XX_DXE_CH_DESC_NUMB_TX_H,
  463. wcn->mgmt_mem_pool.virt_addr,
  464. wcn->mgmt_mem_pool.phy_addr);
  465. if (wcn->data_mem_pool.virt_addr) {
  466. dma_free_coherent(NULL, wcn->data_mem_pool.chunk_size *
  467. WCN36XX_DXE_CH_DESC_NUMB_TX_L,
  468. wcn->data_mem_pool.virt_addr,
  469. wcn->data_mem_pool.phy_addr);
  470. }
  471. }
  472. int wcn36xx_dxe_tx_frame(struct wcn36xx *wcn,
  473. struct wcn36xx_vif *vif_priv,
  474. struct sk_buff *skb,
  475. bool is_low)
  476. {
  477. struct wcn36xx_dxe_ctl *ctl = NULL;
  478. struct wcn36xx_dxe_desc *desc = NULL;
  479. struct wcn36xx_dxe_ch *ch = NULL;
  480. unsigned long flags;
  481. ch = is_low ? &wcn->dxe_tx_l_ch : &wcn->dxe_tx_h_ch;
  482. ctl = ch->head_blk_ctl;
  483. spin_lock_irqsave(&ctl->next->skb_lock, flags);
  484. /*
  485. * If skb is not null that means that we reached the tail of the ring
  486. * hence ring is full. Stop queues to let mac80211 back off until ring
  487. * has an empty slot again.
  488. */
  489. if (NULL != ctl->next->skb) {
  490. ieee80211_stop_queues(wcn->hw);
  491. wcn->queues_stopped = true;
  492. spin_unlock_irqrestore(&ctl->next->skb_lock, flags);
  493. return -EBUSY;
  494. }
  495. spin_unlock_irqrestore(&ctl->next->skb_lock, flags);
  496. ctl->skb = NULL;
  497. desc = ctl->desc;
  498. /* Set source address of the BD we send */
  499. desc->src_addr_l = ctl->bd_phy_addr;
  500. desc->dst_addr_l = ch->dxe_wq;
  501. desc->fr_len = sizeof(struct wcn36xx_tx_bd);
  502. desc->ctrl = ch->ctrl_bd;
  503. wcn36xx_dbg(WCN36XX_DBG_DXE, "DXE TX\n");
  504. wcn36xx_dbg_dump(WCN36XX_DBG_DXE_DUMP, "DESC1 >>> ",
  505. (char *)desc, sizeof(*desc));
  506. wcn36xx_dbg_dump(WCN36XX_DBG_DXE_DUMP,
  507. "BD >>> ", (char *)ctl->bd_cpu_addr,
  508. sizeof(struct wcn36xx_tx_bd));
  509. /* Set source address of the SKB we send */
  510. ctl = ctl->next;
  511. ctl->skb = skb;
  512. desc = ctl->desc;
  513. if (ctl->bd_cpu_addr) {
  514. wcn36xx_err("bd_cpu_addr cannot be NULL for skb DXE\n");
  515. return -EINVAL;
  516. }
  517. desc->src_addr_l = dma_map_single(NULL,
  518. ctl->skb->data,
  519. ctl->skb->len,
  520. DMA_TO_DEVICE);
  521. desc->dst_addr_l = ch->dxe_wq;
  522. desc->fr_len = ctl->skb->len;
  523. /* set dxe descriptor to VALID */
  524. desc->ctrl = ch->ctrl_skb;
  525. wcn36xx_dbg_dump(WCN36XX_DBG_DXE_DUMP, "DESC2 >>> ",
  526. (char *)desc, sizeof(*desc));
  527. wcn36xx_dbg_dump(WCN36XX_DBG_DXE_DUMP, "SKB >>> ",
  528. (char *)ctl->skb->data, ctl->skb->len);
  529. /* Move the head of the ring to the next empty descriptor */
  530. ch->head_blk_ctl = ctl->next;
  531. /*
  532. * When connected and trying to send data frame chip can be in sleep
  533. * mode and writing to the register will not wake up the chip. Instead
  534. * notify chip about new frame through SMSM bus.
  535. */
  536. if (is_low && vif_priv->pw_state == WCN36XX_BMPS) {
  537. wcn->ctrl_ops->smsm_change_state(
  538. 0,
  539. WCN36XX_SMSM_WLAN_TX_ENABLE);
  540. } else {
  541. /* indicate End Of Packet and generate interrupt on descriptor
  542. * done.
  543. */
  544. wcn36xx_dxe_write_register(wcn,
  545. ch->reg_ctrl, ch->def_ctrl);
  546. }
  547. return 0;
  548. }
  549. int wcn36xx_dxe_init(struct wcn36xx *wcn)
  550. {
  551. int reg_data = 0, ret;
  552. reg_data = WCN36XX_DXE_REG_RESET;
  553. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_REG_CSR_RESET, reg_data);
  554. /* Setting interrupt path */
  555. reg_data = WCN36XX_DXE_CCU_INT;
  556. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_REG_CCU_INT, reg_data);
  557. /***************************************/
  558. /* Init descriptors for TX LOW channel */
  559. /***************************************/
  560. wcn36xx_dxe_init_descs(&wcn->dxe_tx_l_ch);
  561. wcn36xx_dxe_init_tx_bd(&wcn->dxe_tx_l_ch, &wcn->data_mem_pool);
  562. /* Write channel head to a NEXT register */
  563. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_CH_NEXT_DESC_ADDR_TX_L,
  564. wcn->dxe_tx_l_ch.head_blk_ctl->desc_phy_addr);
  565. /* Program DMA destination addr for TX LOW */
  566. wcn36xx_dxe_write_register(wcn,
  567. WCN36XX_DXE_CH_DEST_ADDR_TX_L,
  568. WCN36XX_DXE_WQ_TX_L);
  569. wcn36xx_dxe_read_register(wcn, WCN36XX_DXE_REG_CH_EN, &reg_data);
  570. wcn36xx_dxe_enable_ch_int(wcn, WCN36XX_INT_MASK_CHAN_TX_L);
  571. /***************************************/
  572. /* Init descriptors for TX HIGH channel */
  573. /***************************************/
  574. wcn36xx_dxe_init_descs(&wcn->dxe_tx_h_ch);
  575. wcn36xx_dxe_init_tx_bd(&wcn->dxe_tx_h_ch, &wcn->mgmt_mem_pool);
  576. /* Write channel head to a NEXT register */
  577. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_CH_NEXT_DESC_ADDR_TX_H,
  578. wcn->dxe_tx_h_ch.head_blk_ctl->desc_phy_addr);
  579. /* Program DMA destination addr for TX HIGH */
  580. wcn36xx_dxe_write_register(wcn,
  581. WCN36XX_DXE_CH_DEST_ADDR_TX_H,
  582. WCN36XX_DXE_WQ_TX_H);
  583. wcn36xx_dxe_read_register(wcn, WCN36XX_DXE_REG_CH_EN, &reg_data);
  584. /* Enable channel interrupts */
  585. wcn36xx_dxe_enable_ch_int(wcn, WCN36XX_INT_MASK_CHAN_TX_H);
  586. /***************************************/
  587. /* Init descriptors for RX LOW channel */
  588. /***************************************/
  589. wcn36xx_dxe_init_descs(&wcn->dxe_rx_l_ch);
  590. /* For RX we need to preallocated buffers */
  591. wcn36xx_dxe_ch_alloc_skb(wcn, &wcn->dxe_rx_l_ch);
  592. /* Write channel head to a NEXT register */
  593. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_CH_NEXT_DESC_ADDR_RX_L,
  594. wcn->dxe_rx_l_ch.head_blk_ctl->desc_phy_addr);
  595. /* Write DMA source address */
  596. wcn36xx_dxe_write_register(wcn,
  597. WCN36XX_DXE_CH_SRC_ADDR_RX_L,
  598. WCN36XX_DXE_WQ_RX_L);
  599. /* Program preallocated destination address */
  600. wcn36xx_dxe_write_register(wcn,
  601. WCN36XX_DXE_CH_DEST_ADDR_RX_L,
  602. wcn->dxe_rx_l_ch.head_blk_ctl->desc->phy_next_l);
  603. /* Enable default control registers */
  604. wcn36xx_dxe_write_register(wcn,
  605. WCN36XX_DXE_REG_CTL_RX_L,
  606. WCN36XX_DXE_CH_DEFAULT_CTL_RX_L);
  607. /* Enable channel interrupts */
  608. wcn36xx_dxe_enable_ch_int(wcn, WCN36XX_INT_MASK_CHAN_RX_L);
  609. /***************************************/
  610. /* Init descriptors for RX HIGH channel */
  611. /***************************************/
  612. wcn36xx_dxe_init_descs(&wcn->dxe_rx_h_ch);
  613. /* For RX we need to prealocat buffers */
  614. wcn36xx_dxe_ch_alloc_skb(wcn, &wcn->dxe_rx_h_ch);
  615. /* Write chanel head to a NEXT register */
  616. wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_CH_NEXT_DESC_ADDR_RX_H,
  617. wcn->dxe_rx_h_ch.head_blk_ctl->desc_phy_addr);
  618. /* Write DMA source address */
  619. wcn36xx_dxe_write_register(wcn,
  620. WCN36XX_DXE_CH_SRC_ADDR_RX_H,
  621. WCN36XX_DXE_WQ_RX_H);
  622. /* Program preallocated destination address */
  623. wcn36xx_dxe_write_register(wcn,
  624. WCN36XX_DXE_CH_DEST_ADDR_RX_H,
  625. wcn->dxe_rx_h_ch.head_blk_ctl->desc->phy_next_l);
  626. /* Enable default control registers */
  627. wcn36xx_dxe_write_register(wcn,
  628. WCN36XX_DXE_REG_CTL_RX_H,
  629. WCN36XX_DXE_CH_DEFAULT_CTL_RX_H);
  630. /* Enable channel interrupts */
  631. wcn36xx_dxe_enable_ch_int(wcn, WCN36XX_INT_MASK_CHAN_RX_H);
  632. ret = wcn36xx_dxe_request_irqs(wcn);
  633. if (ret < 0)
  634. goto out_err;
  635. return 0;
  636. out_err:
  637. return ret;
  638. }
  639. void wcn36xx_dxe_deinit(struct wcn36xx *wcn)
  640. {
  641. free_irq(wcn->tx_irq, wcn);
  642. free_irq(wcn->rx_irq, wcn);
  643. if (wcn->tx_ack_skb) {
  644. ieee80211_tx_status_irqsafe(wcn->hw, wcn->tx_ack_skb);
  645. wcn->tx_ack_skb = NULL;
  646. }
  647. wcn36xx_dxe_ch_free_skbs(wcn, &wcn->dxe_rx_l_ch);
  648. wcn36xx_dxe_ch_free_skbs(wcn, &wcn->dxe_rx_h_ch);
  649. }