dxe.c 21 KB

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