dxe.c 21 KB

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