dxe.c 22 KB

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