blob: aff04ef66266381a642648d6a4318d66e2850e65 [file] [log] [blame]
Eugene Krasnikov8e84c252013-10-08 21:25:58 +01001/*
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
17/* DXE - DMA transfer engine
18 * we have 2 channels(High prio and Low prio) for TX and 2 channels for RX.
19 * through low channels data packets are transfered
20 * through high channels managment packets are transfered
21 */
22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
25#include <linux/interrupt.h>
Bjorn Anderssonf303a932017-01-11 16:32:18 +020026#include <linux/soc/qcom/smem_state.h>
Eugene Krasnikov8e84c252013-10-08 21:25:58 +010027#include "wcn36xx.h"
28#include "txrx.h"
29
Bjorn Andersson05ddce42016-06-19 23:19:45 -070030static void wcn36xx_ccu_write_register(struct wcn36xx *wcn, int addr, int data)
31{
32 wcn36xx_dbg(WCN36XX_DBG_DXE,
33 "wcn36xx_ccu_write_register: addr=%x, data=%x\n",
34 addr, data);
35
36 writel(data, wcn->ccu_base + addr);
37}
38
Eugene Krasnikov8e84c252013-10-08 21:25:58 +010039static void wcn36xx_dxe_write_register(struct wcn36xx *wcn, int addr, int data)
40{
41 wcn36xx_dbg(WCN36XX_DBG_DXE,
42 "wcn36xx_dxe_write_register: addr=%x, data=%x\n",
43 addr, data);
44
Bjorn Andersson05ddce42016-06-19 23:19:45 -070045 writel(data, wcn->dxe_base + addr);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +010046}
47
48static void wcn36xx_dxe_read_register(struct wcn36xx *wcn, int addr, int *data)
49{
Bjorn Andersson05ddce42016-06-19 23:19:45 -070050 *data = readl(wcn->dxe_base + addr);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +010051
52 wcn36xx_dbg(WCN36XX_DBG_DXE,
53 "wcn36xx_dxe_read_register: addr=%x, data=%x\n",
54 addr, *data);
55}
56
57static void wcn36xx_dxe_free_ctl_block(struct wcn36xx_dxe_ch *ch)
58{
59 struct wcn36xx_dxe_ctl *ctl = ch->head_blk_ctl, *next;
60 int i;
61
62 for (i = 0; i < ch->desc_num && ctl; i++) {
63 next = ctl->next;
64 kfree(ctl);
65 ctl = next;
66 }
67}
68
69static int wcn36xx_dxe_allocate_ctl_block(struct wcn36xx_dxe_ch *ch)
70{
71 struct wcn36xx_dxe_ctl *prev_ctl = NULL;
72 struct wcn36xx_dxe_ctl *cur_ctl = NULL;
73 int i;
74
Bob Copeland8e8e54c2015-10-24 13:42:15 -040075 spin_lock_init(&ch->lock);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +010076 for (i = 0; i < ch->desc_num; i++) {
77 cur_ctl = kzalloc(sizeof(*cur_ctl), GFP_KERNEL);
78 if (!cur_ctl)
79 goto out_fail;
80
81 cur_ctl->ctl_blk_order = i;
82 if (i == 0) {
83 ch->head_blk_ctl = cur_ctl;
84 ch->tail_blk_ctl = cur_ctl;
85 } else if (ch->desc_num - 1 == i) {
86 prev_ctl->next = cur_ctl;
87 cur_ctl->next = ch->head_blk_ctl;
88 } else {
89 prev_ctl->next = cur_ctl;
90 }
91 prev_ctl = cur_ctl;
92 }
93
94 return 0;
95
96out_fail:
97 wcn36xx_dxe_free_ctl_block(ch);
98 return -ENOMEM;
99}
100
101int wcn36xx_dxe_alloc_ctl_blks(struct wcn36xx *wcn)
102{
103 int ret;
104
105 wcn->dxe_tx_l_ch.ch_type = WCN36XX_DXE_CH_TX_L;
106 wcn->dxe_tx_h_ch.ch_type = WCN36XX_DXE_CH_TX_H;
107 wcn->dxe_rx_l_ch.ch_type = WCN36XX_DXE_CH_RX_L;
108 wcn->dxe_rx_h_ch.ch_type = WCN36XX_DXE_CH_RX_H;
109
110 wcn->dxe_tx_l_ch.desc_num = WCN36XX_DXE_CH_DESC_NUMB_TX_L;
111 wcn->dxe_tx_h_ch.desc_num = WCN36XX_DXE_CH_DESC_NUMB_TX_H;
112 wcn->dxe_rx_l_ch.desc_num = WCN36XX_DXE_CH_DESC_NUMB_RX_L;
113 wcn->dxe_rx_h_ch.desc_num = WCN36XX_DXE_CH_DESC_NUMB_RX_H;
114
115 wcn->dxe_tx_l_ch.dxe_wq = WCN36XX_DXE_WQ_TX_L;
116 wcn->dxe_tx_h_ch.dxe_wq = WCN36XX_DXE_WQ_TX_H;
117
118 wcn->dxe_tx_l_ch.ctrl_bd = WCN36XX_DXE_CTRL_TX_L_BD;
119 wcn->dxe_tx_h_ch.ctrl_bd = WCN36XX_DXE_CTRL_TX_H_BD;
120
121 wcn->dxe_tx_l_ch.ctrl_skb = WCN36XX_DXE_CTRL_TX_L_SKB;
122 wcn->dxe_tx_h_ch.ctrl_skb = WCN36XX_DXE_CTRL_TX_H_SKB;
123
124 wcn->dxe_tx_l_ch.reg_ctrl = WCN36XX_DXE_REG_CTL_TX_L;
125 wcn->dxe_tx_h_ch.reg_ctrl = WCN36XX_DXE_REG_CTL_TX_H;
126
127 wcn->dxe_tx_l_ch.def_ctrl = WCN36XX_DXE_CH_DEFAULT_CTL_TX_L;
128 wcn->dxe_tx_h_ch.def_ctrl = WCN36XX_DXE_CH_DEFAULT_CTL_TX_H;
129
130 /* DXE control block allocation */
131 ret = wcn36xx_dxe_allocate_ctl_block(&wcn->dxe_tx_l_ch);
132 if (ret)
133 goto out_err;
134 ret = wcn36xx_dxe_allocate_ctl_block(&wcn->dxe_tx_h_ch);
135 if (ret)
136 goto out_err;
137 ret = wcn36xx_dxe_allocate_ctl_block(&wcn->dxe_rx_l_ch);
138 if (ret)
139 goto out_err;
140 ret = wcn36xx_dxe_allocate_ctl_block(&wcn->dxe_rx_h_ch);
141 if (ret)
142 goto out_err;
143
144 /* Initialize SMSM state Clear TX Enable RING EMPTY STATE */
Bjorn Anderssonf303a932017-01-11 16:32:18 +0200145 ret = qcom_smem_state_update_bits(wcn->tx_enable_state,
146 WCN36XX_SMSM_WLAN_TX_ENABLE |
147 WCN36XX_SMSM_WLAN_TX_RINGS_EMPTY,
148 WCN36XX_SMSM_WLAN_TX_RINGS_EMPTY);
149 if (ret)
150 goto out_err;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100151
152 return 0;
153
154out_err:
155 wcn36xx_err("Failed to allocate DXE control blocks\n");
156 wcn36xx_dxe_free_ctl_blks(wcn);
157 return -ENOMEM;
158}
159
160void wcn36xx_dxe_free_ctl_blks(struct wcn36xx *wcn)
161{
162 wcn36xx_dxe_free_ctl_block(&wcn->dxe_tx_l_ch);
163 wcn36xx_dxe_free_ctl_block(&wcn->dxe_tx_h_ch);
164 wcn36xx_dxe_free_ctl_block(&wcn->dxe_rx_l_ch);
165 wcn36xx_dxe_free_ctl_block(&wcn->dxe_rx_h_ch);
166}
167
yfw07225522015-10-26 10:36:22 +0800168static int wcn36xx_dxe_init_descs(struct device *dev, struct wcn36xx_dxe_ch *wcn_ch)
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100169{
170 struct wcn36xx_dxe_desc *cur_dxe = NULL;
171 struct wcn36xx_dxe_desc *prev_dxe = NULL;
172 struct wcn36xx_dxe_ctl *cur_ctl = NULL;
173 size_t size;
174 int i;
175
176 size = wcn_ch->desc_num * sizeof(struct wcn36xx_dxe_desc);
Luis Chamberlain750afb02019-01-04 09:23:09 +0100177 wcn_ch->cpu_addr = dma_alloc_coherent(dev, size, &wcn_ch->dma_addr,
178 GFP_KERNEL);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100179 if (!wcn_ch->cpu_addr)
180 return -ENOMEM;
181
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100182 cur_dxe = (struct wcn36xx_dxe_desc *)wcn_ch->cpu_addr;
183 cur_ctl = wcn_ch->head_blk_ctl;
184
185 for (i = 0; i < wcn_ch->desc_num; i++) {
186 cur_ctl->desc = cur_dxe;
187 cur_ctl->desc_phy_addr = wcn_ch->dma_addr +
188 i * sizeof(struct wcn36xx_dxe_desc);
189
190 switch (wcn_ch->ch_type) {
191 case WCN36XX_DXE_CH_TX_L:
192 cur_dxe->ctrl = WCN36XX_DXE_CTRL_TX_L;
193 cur_dxe->dst_addr_l = WCN36XX_DXE_WQ_TX_L;
194 break;
195 case WCN36XX_DXE_CH_TX_H:
196 cur_dxe->ctrl = WCN36XX_DXE_CTRL_TX_H;
197 cur_dxe->dst_addr_l = WCN36XX_DXE_WQ_TX_H;
198 break;
199 case WCN36XX_DXE_CH_RX_L:
200 cur_dxe->ctrl = WCN36XX_DXE_CTRL_RX_L;
201 cur_dxe->src_addr_l = WCN36XX_DXE_WQ_RX_L;
202 break;
203 case WCN36XX_DXE_CH_RX_H:
204 cur_dxe->ctrl = WCN36XX_DXE_CTRL_RX_H;
205 cur_dxe->src_addr_l = WCN36XX_DXE_WQ_RX_H;
206 break;
207 }
208 if (0 == i) {
209 cur_dxe->phy_next_l = 0;
210 } else if ((0 < i) && (i < wcn_ch->desc_num - 1)) {
211 prev_dxe->phy_next_l =
212 cur_ctl->desc_phy_addr;
213 } else if (i == (wcn_ch->desc_num - 1)) {
214 prev_dxe->phy_next_l =
215 cur_ctl->desc_phy_addr;
216 cur_dxe->phy_next_l =
217 wcn_ch->head_blk_ctl->desc_phy_addr;
218 }
219 cur_ctl = cur_ctl->next;
220 prev_dxe = cur_dxe;
221 cur_dxe++;
222 }
223
224 return 0;
225}
226
Ramon Friedd0bb9502018-01-23 17:20:13 +0200227static void wcn36xx_dxe_deinit_descs(struct device *dev, struct wcn36xx_dxe_ch *wcn_ch)
228{
229 size_t size;
230
231 size = wcn_ch->desc_num * sizeof(struct wcn36xx_dxe_desc);
232 dma_free_coherent(dev, size,wcn_ch->cpu_addr, wcn_ch->dma_addr);
233}
234
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100235static void wcn36xx_dxe_init_tx_bd(struct wcn36xx_dxe_ch *ch,
236 struct wcn36xx_dxe_mem_pool *pool)
237{
238 int i, chunk_size = pool->chunk_size;
239 dma_addr_t bd_phy_addr = pool->phy_addr;
240 void *bd_cpu_addr = pool->virt_addr;
241 struct wcn36xx_dxe_ctl *cur = ch->head_blk_ctl;
242
243 for (i = 0; i < ch->desc_num; i++) {
244 /* Only every second dxe needs a bd pointer,
245 the other will point to the skb data */
246 if (!(i & 1)) {
247 cur->bd_phy_addr = bd_phy_addr;
248 cur->bd_cpu_addr = bd_cpu_addr;
249 bd_phy_addr += chunk_size;
250 bd_cpu_addr += chunk_size;
251 } else {
252 cur->bd_phy_addr = 0;
253 cur->bd_cpu_addr = NULL;
254 }
255 cur = cur->next;
256 }
257}
258
259static int wcn36xx_dxe_enable_ch_int(struct wcn36xx *wcn, u16 wcn_ch)
260{
261 int reg_data = 0;
262
263 wcn36xx_dxe_read_register(wcn,
264 WCN36XX_DXE_INT_MASK_REG,
265 &reg_data);
266
267 reg_data |= wcn_ch;
268
269 wcn36xx_dxe_write_register(wcn,
270 WCN36XX_DXE_INT_MASK_REG,
271 (int)reg_data);
272 return 0;
273}
274
Daniel Mack5151a672018-04-10 17:52:45 +0300275static int wcn36xx_dxe_fill_skb(struct device *dev,
276 struct wcn36xx_dxe_ctl *ctl,
277 gfp_t gfp)
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100278{
279 struct wcn36xx_dxe_desc *dxe = ctl->desc;
280 struct sk_buff *skb;
281
Daniel Mack5151a672018-04-10 17:52:45 +0300282 skb = alloc_skb(WCN36XX_PKT_SIZE, gfp);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100283 if (skb == NULL)
284 return -ENOMEM;
285
yfw07225522015-10-26 10:36:22 +0800286 dxe->dst_addr_l = dma_map_single(dev,
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100287 skb_tail_pointer(skb),
288 WCN36XX_PKT_SIZE,
289 DMA_FROM_DEVICE);
Rob Clark4165cf72017-07-03 09:38:45 -0400290 if (dma_mapping_error(dev, dxe->dst_addr_l)) {
291 dev_err(dev, "unable to map skb\n");
292 kfree_skb(skb);
293 return -ENOMEM;
294 }
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100295 ctl->skb = skb;
296
297 return 0;
298}
299
300static int wcn36xx_dxe_ch_alloc_skb(struct wcn36xx *wcn,
301 struct wcn36xx_dxe_ch *wcn_ch)
302{
303 int i;
304 struct wcn36xx_dxe_ctl *cur_ctl = NULL;
305
306 cur_ctl = wcn_ch->head_blk_ctl;
307
308 for (i = 0; i < wcn_ch->desc_num; i++) {
Daniel Mack5151a672018-04-10 17:52:45 +0300309 wcn36xx_dxe_fill_skb(wcn->dev, cur_ctl, GFP_KERNEL);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100310 cur_ctl = cur_ctl->next;
311 }
312
313 return 0;
314}
315
316static void wcn36xx_dxe_ch_free_skbs(struct wcn36xx *wcn,
317 struct wcn36xx_dxe_ch *wcn_ch)
318{
319 struct wcn36xx_dxe_ctl *cur = wcn_ch->head_blk_ctl;
320 int i;
321
322 for (i = 0; i < wcn_ch->desc_num; i++) {
323 kfree_skb(cur->skb);
324 cur = cur->next;
325 }
326}
327
328void wcn36xx_dxe_tx_ack_ind(struct wcn36xx *wcn, u32 status)
329{
330 struct ieee80211_tx_info *info;
331 struct sk_buff *skb;
332 unsigned long flags;
333
334 spin_lock_irqsave(&wcn->dxe_lock, flags);
335 skb = wcn->tx_ack_skb;
336 wcn->tx_ack_skb = NULL;
Loic Poulainfdf21cc2020-07-24 12:20:48 +0200337 del_timer(&wcn->tx_ack_timer);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100338 spin_unlock_irqrestore(&wcn->dxe_lock, flags);
339
340 if (!skb) {
341 wcn36xx_warn("Spurious TX complete indication\n");
342 return;
343 }
344
345 info = IEEE80211_SKB_CB(skb);
346
347 if (status == 1)
348 info->flags |= IEEE80211_TX_STAT_ACK;
Loic Poulainfdf21cc2020-07-24 12:20:48 +0200349 else
350 info->flags &= ~IEEE80211_TX_STAT_ACK;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100351
352 wcn36xx_dbg(WCN36XX_DBG_DXE, "dxe tx ack status: %d\n", status);
353
354 ieee80211_tx_status_irqsafe(wcn->hw, skb);
355 ieee80211_wake_queues(wcn->hw);
356}
357
Loic Poulainfdf21cc2020-07-24 12:20:48 +0200358static void wcn36xx_dxe_tx_timer(struct timer_list *t)
359{
360 struct wcn36xx *wcn = from_timer(wcn, t, tx_ack_timer);
361 struct ieee80211_tx_info *info;
362 unsigned long flags;
363 struct sk_buff *skb;
364
365 /* TX Timeout */
366 wcn36xx_dbg(WCN36XX_DBG_DXE, "TX timeout\n");
367
368 spin_lock_irqsave(&wcn->dxe_lock, flags);
369 skb = wcn->tx_ack_skb;
370 wcn->tx_ack_skb = NULL;
371 spin_unlock_irqrestore(&wcn->dxe_lock, flags);
372
373 if (!skb)
374 return;
375
376 info = IEEE80211_SKB_CB(skb);
377 info->flags &= ~IEEE80211_TX_STAT_ACK;
378 info->flags &= ~IEEE80211_TX_STAT_NOACK_TRANSMITTED;
379
380 ieee80211_tx_status_irqsafe(wcn->hw, skb);
381 ieee80211_wake_queues(wcn->hw);
382}
383
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100384static void reap_tx_dxes(struct wcn36xx *wcn, struct wcn36xx_dxe_ch *ch)
385{
Bob Copeland8e8e54c2015-10-24 13:42:15 -0400386 struct wcn36xx_dxe_ctl *ctl;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100387 struct ieee80211_tx_info *info;
388 unsigned long flags;
389
390 /*
391 * Make at least one loop of do-while because in case ring is
392 * completely full head and tail are pointing to the same element
393 * and while-do will not make any cycles.
394 */
Bob Copeland8e8e54c2015-10-24 13:42:15 -0400395 spin_lock_irqsave(&ch->lock, flags);
396 ctl = ch->tail_blk_ctl;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100397 do {
Daniel Mack9ff6fde2018-04-10 19:35:58 +0200398 if (READ_ONCE(ctl->desc->ctrl) & WCN36xx_DXE_CTRL_VLD)
Bob Copelandbfa66962015-01-09 14:15:48 -0500399 break;
Daniel Mack18c7ed12018-05-23 11:14:44 +0300400
401 if (ctl->skb &&
402 READ_ONCE(ctl->desc->ctrl) & WCN36xx_DXE_CTRL_EOP) {
yfw07225522015-10-26 10:36:22 +0800403 dma_unmap_single(wcn->dev, ctl->desc->src_addr_l,
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100404 ctl->skb->len, DMA_TO_DEVICE);
405 info = IEEE80211_SKB_CB(ctl->skb);
Loic Poulaina9e79b12021-10-25 16:12:18 +0300406 if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) {
407 if (info->flags & IEEE80211_TX_CTL_NO_ACK) {
408 info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
409 ieee80211_tx_status_irqsafe(wcn->hw, ctl->skb);
410 } else {
411 /* Wait for the TX ack indication or timeout... */
412 spin_lock(&wcn->dxe_lock);
413 if (WARN_ON(wcn->tx_ack_skb))
414 ieee80211_free_txskb(wcn->hw, wcn->tx_ack_skb);
415 wcn->tx_ack_skb = ctl->skb; /* Tracking ref */
416 mod_timer(&wcn->tx_ack_timer, jiffies + HZ / 10);
417 spin_unlock(&wcn->dxe_lock);
418 }
419 /* do not free, ownership transferred to mac80211 status cb */
420 } else {
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100421 ieee80211_free_txskb(wcn->hw, ctl->skb);
422 }
Loic Poulain60625462018-04-06 12:11:28 +0200423
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100424 if (wcn->queues_stopped) {
425 wcn->queues_stopped = false;
426 ieee80211_wake_queues(wcn->hw);
427 }
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100428
429 ctl->skb = NULL;
430 }
431 ctl = ctl->next;
Daniel Mack9ff6fde2018-04-10 19:35:58 +0200432 } while (ctl != ch->head_blk_ctl);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100433
434 ch->tail_blk_ctl = ctl;
Bob Copeland8e8e54c2015-10-24 13:42:15 -0400435 spin_unlock_irqrestore(&ch->lock, flags);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100436}
437
438static irqreturn_t wcn36xx_irq_tx_complete(int irq, void *dev)
439{
440 struct wcn36xx *wcn = (struct wcn36xx *)dev;
441 int int_src, int_reason;
442
443 wcn36xx_dxe_read_register(wcn, WCN36XX_DXE_INT_SRC_RAW_REG, &int_src);
444
445 if (int_src & WCN36XX_INT_MASK_CHAN_TX_H) {
446 wcn36xx_dxe_read_register(wcn,
447 WCN36XX_DXE_CH_STATUS_REG_ADDR_TX_H,
448 &int_reason);
449
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100450 wcn36xx_dxe_write_register(wcn,
451 WCN36XX_DXE_0_INT_CLR,
452 WCN36XX_INT_MASK_CHAN_TX_H);
453
Ramon Fried6767b302018-03-11 14:01:43 +0200454 if (int_reason & WCN36XX_CH_STAT_INT_ERR_MASK ) {
455 wcn36xx_dxe_write_register(wcn,
456 WCN36XX_DXE_0_INT_ERR_CLR,
457 WCN36XX_INT_MASK_CHAN_TX_H);
458
459 wcn36xx_err("DXE IRQ reported error: 0x%x in high TX channel\n",
460 int_src);
461 }
462
463 if (int_reason & WCN36XX_CH_STAT_INT_DONE_MASK) {
464 wcn36xx_dxe_write_register(wcn,
465 WCN36XX_DXE_0_INT_DONE_CLR,
466 WCN36XX_INT_MASK_CHAN_TX_H);
467 }
468
469 if (int_reason & WCN36XX_CH_STAT_INT_ED_MASK) {
470 wcn36xx_dxe_write_register(wcn,
471 WCN36XX_DXE_0_INT_ED_CLR,
472 WCN36XX_INT_MASK_CHAN_TX_H);
473 }
474
Daniel Mackce1d4be2018-05-23 11:14:40 +0300475 wcn36xx_dbg(WCN36XX_DBG_DXE, "dxe tx ready high, reason %08x\n",
476 int_reason);
477
478 if (int_reason & (WCN36XX_CH_STAT_INT_DONE_MASK |
Loic Poulainfdf21cc2020-07-24 12:20:48 +0200479 WCN36XX_CH_STAT_INT_ED_MASK)) {
Daniel Mackce1d4be2018-05-23 11:14:40 +0300480 reap_tx_dxes(wcn, &wcn->dxe_tx_h_ch);
Loic Poulainfdf21cc2020-07-24 12:20:48 +0200481 }
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100482 }
483
484 if (int_src & WCN36XX_INT_MASK_CHAN_TX_L) {
485 wcn36xx_dxe_read_register(wcn,
486 WCN36XX_DXE_CH_STATUS_REG_ADDR_TX_L,
487 &int_reason);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100488
489 wcn36xx_dxe_write_register(wcn,
490 WCN36XX_DXE_0_INT_CLR,
491 WCN36XX_INT_MASK_CHAN_TX_L);
492
Ramon Fried6767b302018-03-11 14:01:43 +0200493 if (int_reason & WCN36XX_CH_STAT_INT_ERR_MASK ) {
494 wcn36xx_dxe_write_register(wcn,
495 WCN36XX_DXE_0_INT_ERR_CLR,
496 WCN36XX_INT_MASK_CHAN_TX_L);
497
498 wcn36xx_err("DXE IRQ reported error: 0x%x in low TX channel\n",
499 int_src);
500 }
501
502 if (int_reason & WCN36XX_CH_STAT_INT_DONE_MASK) {
503 wcn36xx_dxe_write_register(wcn,
504 WCN36XX_DXE_0_INT_DONE_CLR,
505 WCN36XX_INT_MASK_CHAN_TX_L);
506 }
507
508 if (int_reason & WCN36XX_CH_STAT_INT_ED_MASK) {
509 wcn36xx_dxe_write_register(wcn,
510 WCN36XX_DXE_0_INT_ED_CLR,
511 WCN36XX_INT_MASK_CHAN_TX_L);
512 }
513
Daniel Mackce1d4be2018-05-23 11:14:40 +0300514 wcn36xx_dbg(WCN36XX_DBG_DXE, "dxe tx ready low, reason %08x\n",
515 int_reason);
516
517 if (int_reason & (WCN36XX_CH_STAT_INT_DONE_MASK |
Loic Poulainfdf21cc2020-07-24 12:20:48 +0200518 WCN36XX_CH_STAT_INT_ED_MASK)) {
Daniel Mackce1d4be2018-05-23 11:14:40 +0300519 reap_tx_dxes(wcn, &wcn->dxe_tx_l_ch);
Loic Poulainfdf21cc2020-07-24 12:20:48 +0200520 }
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100521 }
522
523 return IRQ_HANDLED;
524}
525
526static irqreturn_t wcn36xx_irq_rx_ready(int irq, void *dev)
527{
528 struct wcn36xx *wcn = (struct wcn36xx *)dev;
529
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100530 wcn36xx_dxe_rx_frame(wcn);
Daniel Mackba437e72018-05-23 11:14:30 +0300531
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100532 return IRQ_HANDLED;
533}
534
535static int wcn36xx_dxe_request_irqs(struct wcn36xx *wcn)
536{
537 int ret;
538
539 ret = request_irq(wcn->tx_irq, wcn36xx_irq_tx_complete,
540 IRQF_TRIGGER_HIGH, "wcn36xx_tx", wcn);
541 if (ret) {
542 wcn36xx_err("failed to alloc tx irq\n");
543 goto out_err;
544 }
545
546 ret = request_irq(wcn->rx_irq, wcn36xx_irq_rx_ready, IRQF_TRIGGER_HIGH,
547 "wcn36xx_rx", wcn);
548 if (ret) {
549 wcn36xx_err("failed to alloc rx irq\n");
550 goto out_txirq;
551 }
552
553 enable_irq_wake(wcn->rx_irq);
554
555 return 0;
556
557out_txirq:
558 free_irq(wcn->tx_irq, wcn);
559out_err:
560 return ret;
561
562}
563
564static int wcn36xx_rx_handle_packets(struct wcn36xx *wcn,
Daniel Mackedd23ab2018-05-23 11:14:35 +0300565 struct wcn36xx_dxe_ch *ch,
566 u32 ctrl,
567 u32 en_mask,
568 u32 int_mask,
569 u32 status_reg)
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100570{
Daniel Mackba437e72018-05-23 11:14:30 +0300571 struct wcn36xx_dxe_desc *dxe;
572 struct wcn36xx_dxe_ctl *ctl;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100573 dma_addr_t dma_addr;
574 struct sk_buff *skb;
Daniel Mackedd23ab2018-05-23 11:14:35 +0300575 u32 int_reason;
576 int ret;
Fengwei Yin2ec77522015-12-20 21:20:40 +0800577
Daniel Mackedd23ab2018-05-23 11:14:35 +0300578 wcn36xx_dxe_read_register(wcn, status_reg, &int_reason);
579 wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_0_INT_CLR, int_mask);
580
581 if (int_reason & WCN36XX_CH_STAT_INT_ERR_MASK) {
582 wcn36xx_dxe_write_register(wcn,
583 WCN36XX_DXE_0_INT_ERR_CLR,
584 int_mask);
585
586 wcn36xx_err("DXE IRQ reported error on RX channel\n");
Fengwei Yin2ec77522015-12-20 21:20:40 +0800587 }
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100588
Daniel Mackedd23ab2018-05-23 11:14:35 +0300589 if (int_reason & WCN36XX_CH_STAT_INT_DONE_MASK)
590 wcn36xx_dxe_write_register(wcn,
591 WCN36XX_DXE_0_INT_DONE_CLR,
592 int_mask);
593
594 if (int_reason & WCN36XX_CH_STAT_INT_ED_MASK)
595 wcn36xx_dxe_write_register(wcn,
596 WCN36XX_DXE_0_INT_ED_CLR,
597 int_mask);
598
Daniel Mackce1d4be2018-05-23 11:14:40 +0300599 if (!(int_reason & (WCN36XX_CH_STAT_INT_DONE_MASK |
600 WCN36XX_CH_STAT_INT_ED_MASK)))
601 return 0;
602
Daniel Mackba437e72018-05-23 11:14:30 +0300603 spin_lock(&ch->lock);
604
605 ctl = ch->head_blk_ctl;
606 dxe = ctl->desc;
607
Daniel Mack9ff6fde2018-04-10 19:35:58 +0200608 while (!(READ_ONCE(dxe->ctrl) & WCN36xx_DXE_CTRL_VLD)) {
Benjamin Li9bfe38e2021-10-22 17:15:28 -0700609 /* do not read until we own DMA descriptor */
610 dma_rmb();
611
612 /* read/modify DMA descriptor */
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100613 skb = ctl->skb;
614 dma_addr = dxe->dst_addr_l;
Daniel Mack5151a672018-04-10 17:52:45 +0300615 ret = wcn36xx_dxe_fill_skb(wcn->dev, ctl, GFP_ATOMIC);
Fengwei Yin2ec77522015-12-20 21:20:40 +0800616 if (0 == ret) {
617 /* new skb allocation ok. Use the new one and queue
618 * the old one to network system.
619 */
620 dma_unmap_single(wcn->dev, dma_addr, WCN36XX_PKT_SIZE,
621 DMA_FROM_DEVICE);
622 wcn36xx_rx_skb(wcn, skb);
Benjamin Li9bfe38e2021-10-22 17:15:28 -0700623 }
624 /* else keep old skb not submitted and reuse it for rx DMA
625 * (dropping the packet that it contained)
626 */
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100627
Benjamin Li9bfe38e2021-10-22 17:15:28 -0700628 /* flush descriptor changes before re-marking as valid */
629 dma_wmb();
Daniel Mackedd23ab2018-05-23 11:14:35 +0300630 dxe->ctrl = ctrl;
Benjamin Li9bfe38e2021-10-22 17:15:28 -0700631
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100632 ctl = ctl->next;
633 dxe = ctl->desc;
634 }
Daniel Mackedd23ab2018-05-23 11:14:35 +0300635 wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_ENCH_ADDR, en_mask);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100636
637 ch->head_blk_ctl = ctl;
Daniel Mackba437e72018-05-23 11:14:30 +0300638
639 spin_unlock(&ch->lock);
640
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100641 return 0;
642}
643
644void wcn36xx_dxe_rx_frame(struct wcn36xx *wcn)
645{
646 int int_src;
647
648 wcn36xx_dxe_read_register(wcn, WCN36XX_DXE_INT_SRC_RAW_REG, &int_src);
649
650 /* RX_LOW_PRI */
Daniel Mackedd23ab2018-05-23 11:14:35 +0300651 if (int_src & WCN36XX_DXE_INT_CH1_MASK)
652 wcn36xx_rx_handle_packets(wcn, &wcn->dxe_rx_l_ch,
653 WCN36XX_DXE_CTRL_RX_L,
654 WCN36XX_DXE_INT_CH1_MASK,
655 WCN36XX_INT_MASK_CHAN_RX_L,
656 WCN36XX_DXE_CH_STATUS_REG_ADDR_RX_L);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100657
658 /* RX_HIGH_PRI */
Daniel Mackedd23ab2018-05-23 11:14:35 +0300659 if (int_src & WCN36XX_DXE_INT_CH3_MASK)
660 wcn36xx_rx_handle_packets(wcn, &wcn->dxe_rx_h_ch,
661 WCN36XX_DXE_CTRL_RX_H,
662 WCN36XX_DXE_INT_CH3_MASK,
663 WCN36XX_INT_MASK_CHAN_RX_H,
664 WCN36XX_DXE_CH_STATUS_REG_ADDR_RX_H);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100665
666 if (!int_src)
667 wcn36xx_warn("No DXE interrupt pending\n");
668}
669
670int wcn36xx_dxe_allocate_mem_pools(struct wcn36xx *wcn)
671{
672 size_t s;
673 void *cpu_addr;
674
675 /* Allocate BD headers for MGMT frames */
676
677 /* Where this come from ask QC */
678 wcn->mgmt_mem_pool.chunk_size = WCN36XX_BD_CHUNK_SIZE +
679 16 - (WCN36XX_BD_CHUNK_SIZE % 8);
680
681 s = wcn->mgmt_mem_pool.chunk_size * WCN36XX_DXE_CH_DESC_NUMB_TX_H;
Luis Chamberlain750afb02019-01-04 09:23:09 +0100682 cpu_addr = dma_alloc_coherent(wcn->dev, s,
683 &wcn->mgmt_mem_pool.phy_addr,
684 GFP_KERNEL);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100685 if (!cpu_addr)
686 goto out_err;
687
688 wcn->mgmt_mem_pool.virt_addr = cpu_addr;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100689
690 /* Allocate BD headers for DATA frames */
691
692 /* Where this come from ask QC */
693 wcn->data_mem_pool.chunk_size = WCN36XX_BD_CHUNK_SIZE +
694 16 - (WCN36XX_BD_CHUNK_SIZE % 8);
695
696 s = wcn->data_mem_pool.chunk_size * WCN36XX_DXE_CH_DESC_NUMB_TX_L;
Luis Chamberlain750afb02019-01-04 09:23:09 +0100697 cpu_addr = dma_alloc_coherent(wcn->dev, s,
698 &wcn->data_mem_pool.phy_addr,
699 GFP_KERNEL);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100700 if (!cpu_addr)
701 goto out_err;
702
703 wcn->data_mem_pool.virt_addr = cpu_addr;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100704
705 return 0;
706
707out_err:
708 wcn36xx_dxe_free_mem_pools(wcn);
709 wcn36xx_err("Failed to allocate BD mempool\n");
710 return -ENOMEM;
711}
712
713void wcn36xx_dxe_free_mem_pools(struct wcn36xx *wcn)
714{
715 if (wcn->mgmt_mem_pool.virt_addr)
yfw07225522015-10-26 10:36:22 +0800716 dma_free_coherent(wcn->dev, wcn->mgmt_mem_pool.chunk_size *
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100717 WCN36XX_DXE_CH_DESC_NUMB_TX_H,
718 wcn->mgmt_mem_pool.virt_addr,
719 wcn->mgmt_mem_pool.phy_addr);
720
721 if (wcn->data_mem_pool.virt_addr) {
yfw07225522015-10-26 10:36:22 +0800722 dma_free_coherent(wcn->dev, wcn->data_mem_pool.chunk_size *
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100723 WCN36XX_DXE_CH_DESC_NUMB_TX_L,
724 wcn->data_mem_pool.virt_addr,
725 wcn->data_mem_pool.phy_addr);
726 }
727}
728
729int wcn36xx_dxe_tx_frame(struct wcn36xx *wcn,
730 struct wcn36xx_vif *vif_priv,
Loic Poulaine5f99082018-03-27 11:26:57 +0300731 struct wcn36xx_tx_bd *bd,
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100732 struct sk_buff *skb,
733 bool is_low)
734{
Daniel Mack9a81cc22018-05-23 11:14:22 +0300735 struct wcn36xx_dxe_desc *desc_bd, *desc_skb;
736 struct wcn36xx_dxe_ctl *ctl_bd, *ctl_skb;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100737 struct wcn36xx_dxe_ch *ch = NULL;
738 unsigned long flags;
Bob Copeland8e8e54c2015-10-24 13:42:15 -0400739 int ret;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100740
741 ch = is_low ? &wcn->dxe_tx_l_ch : &wcn->dxe_tx_h_ch;
742
Bob Copeland8e8e54c2015-10-24 13:42:15 -0400743 spin_lock_irqsave(&ch->lock, flags);
Daniel Mack9a81cc22018-05-23 11:14:22 +0300744 ctl_bd = ch->head_blk_ctl;
745 ctl_skb = ctl_bd->next;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100746
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100747 /*
748 * If skb is not null that means that we reached the tail of the ring
749 * hence ring is full. Stop queues to let mac80211 back off until ring
750 * has an empty slot again.
751 */
Daniel Mack9a81cc22018-05-23 11:14:22 +0300752 if (NULL != ctl_skb->skb) {
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100753 ieee80211_stop_queues(wcn->hw);
754 wcn->queues_stopped = true;
Bob Copeland8e8e54c2015-10-24 13:42:15 -0400755 spin_unlock_irqrestore(&ch->lock, flags);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100756 return -EBUSY;
757 }
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100758
Daniel Mack9a81cc22018-05-23 11:14:22 +0300759 if (unlikely(ctl_skb->bd_cpu_addr)) {
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100760 wcn36xx_err("bd_cpu_addr cannot be NULL for skb DXE\n");
Bob Copeland8e8e54c2015-10-24 13:42:15 -0400761 ret = -EINVAL;
762 goto unlock;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100763 }
764
Daniel Mack9a81cc22018-05-23 11:14:22 +0300765 desc_bd = ctl_bd->desc;
766 desc_skb = ctl_skb->desc;
767
768 ctl_bd->skb = NULL;
769
770 /* write buffer descriptor */
771 memcpy(ctl_bd->bd_cpu_addr, bd, sizeof(*bd));
772
773 /* Set source address of the BD we send */
774 desc_bd->src_addr_l = ctl_bd->bd_phy_addr;
775 desc_bd->dst_addr_l = ch->dxe_wq;
776 desc_bd->fr_len = sizeof(struct wcn36xx_tx_bd);
777
778 wcn36xx_dbg(WCN36XX_DBG_DXE, "DXE TX\n");
779
780 wcn36xx_dbg_dump(WCN36XX_DBG_DXE_DUMP, "DESC1 >>> ",
781 (char *)desc_bd, sizeof(*desc_bd));
782 wcn36xx_dbg_dump(WCN36XX_DBG_DXE_DUMP,
783 "BD >>> ", (char *)ctl_bd->bd_cpu_addr,
784 sizeof(struct wcn36xx_tx_bd));
785
786 desc_skb->src_addr_l = dma_map_single(wcn->dev,
787 skb->data,
788 skb->len,
789 DMA_TO_DEVICE);
790 if (dma_mapping_error(wcn->dev, desc_skb->src_addr_l)) {
Daniel Mack7cae3512018-04-03 18:51:52 +0200791 dev_err(wcn->dev, "unable to DMA map src_addr_l\n");
792 ret = -ENOMEM;
793 goto unlock;
794 }
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100795
Daniel Mack9a81cc22018-05-23 11:14:22 +0300796 ctl_skb->skb = skb;
797 desc_skb->dst_addr_l = ch->dxe_wq;
798 desc_skb->fr_len = ctl_skb->skb->len;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100799
800 wcn36xx_dbg_dump(WCN36XX_DBG_DXE_DUMP, "DESC2 >>> ",
Daniel Mack9a81cc22018-05-23 11:14:22 +0300801 (char *)desc_skb, sizeof(*desc_skb));
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100802 wcn36xx_dbg_dump(WCN36XX_DBG_DXE_DUMP, "SKB >>> ",
Daniel Mack9a81cc22018-05-23 11:14:22 +0300803 (char *)ctl_skb->skb->data, ctl_skb->skb->len);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100804
805 /* Move the head of the ring to the next empty descriptor */
Jiapeng Chong743b5752021-05-26 18:22:48 +0800806 ch->head_blk_ctl = ctl_skb->next;
Daniel Mack9a81cc22018-05-23 11:14:22 +0300807
808 /* Commit all previous writes and set descriptors to VALID */
809 wmb();
810 desc_skb->ctrl = ch->ctrl_skb;
811 wmb();
812 desc_bd->ctrl = ch->ctrl_bd;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100813
814 /*
815 * When connected and trying to send data frame chip can be in sleep
816 * mode and writing to the register will not wake up the chip. Instead
817 * notify chip about new frame through SMSM bus.
818 */
819 if (is_low && vif_priv->pw_state == WCN36XX_BMPS) {
Bjorn Anderssonf303a932017-01-11 16:32:18 +0200820 qcom_smem_state_update_bits(wcn->tx_rings_empty_state,
821 WCN36XX_SMSM_WLAN_TX_ENABLE,
822 WCN36XX_SMSM_WLAN_TX_ENABLE);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100823 } else {
824 /* indicate End Of Packet and generate interrupt on descriptor
825 * done.
826 */
827 wcn36xx_dxe_write_register(wcn,
828 ch->reg_ctrl, ch->def_ctrl);
829 }
830
Bob Copeland8e8e54c2015-10-24 13:42:15 -0400831 ret = 0;
832unlock:
833 spin_unlock_irqrestore(&ch->lock, flags);
834 return ret;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100835}
836
837int wcn36xx_dxe_init(struct wcn36xx *wcn)
838{
839 int reg_data = 0, ret;
840
841 reg_data = WCN36XX_DXE_REG_RESET;
842 wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_REG_CSR_RESET, reg_data);
843
Bjorn Andersson6f10b4e2016-06-19 23:19:46 -0700844 /* Select channels for rx avail and xfer done interrupts... */
845 reg_data = (WCN36XX_DXE_INT_CH3_MASK | WCN36XX_DXE_INT_CH1_MASK) << 16 |
846 WCN36XX_DXE_INT_CH0_MASK | WCN36XX_DXE_INT_CH4_MASK;
847 if (wcn->is_pronto)
848 wcn36xx_ccu_write_register(wcn, WCN36XX_CCU_DXE_INT_SELECT_PRONTO, reg_data);
Bjorn Andersson05ddce42016-06-19 23:19:45 -0700849 else
Bjorn Andersson6f10b4e2016-06-19 23:19:46 -0700850 wcn36xx_ccu_write_register(wcn, WCN36XX_CCU_DXE_INT_SELECT_RIVA, reg_data);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100851
852 /***************************************/
853 /* Init descriptors for TX LOW channel */
854 /***************************************/
Ramon Friedd0bb9502018-01-23 17:20:13 +0200855 ret = wcn36xx_dxe_init_descs(wcn->dev, &wcn->dxe_tx_l_ch);
856 if (ret) {
857 dev_err(wcn->dev, "Error allocating descriptor\n");
858 return ret;
859 }
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100860 wcn36xx_dxe_init_tx_bd(&wcn->dxe_tx_l_ch, &wcn->data_mem_pool);
861
862 /* Write channel head to a NEXT register */
863 wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_CH_NEXT_DESC_ADDR_TX_L,
864 wcn->dxe_tx_l_ch.head_blk_ctl->desc_phy_addr);
865
866 /* Program DMA destination addr for TX LOW */
867 wcn36xx_dxe_write_register(wcn,
868 WCN36XX_DXE_CH_DEST_ADDR_TX_L,
869 WCN36XX_DXE_WQ_TX_L);
870
871 wcn36xx_dxe_read_register(wcn, WCN36XX_DXE_REG_CH_EN, &reg_data);
872 wcn36xx_dxe_enable_ch_int(wcn, WCN36XX_INT_MASK_CHAN_TX_L);
873
874 /***************************************/
875 /* Init descriptors for TX HIGH channel */
876 /***************************************/
Ramon Friedd0bb9502018-01-23 17:20:13 +0200877 ret = wcn36xx_dxe_init_descs(wcn->dev, &wcn->dxe_tx_h_ch);
878 if (ret) {
879 dev_err(wcn->dev, "Error allocating descriptor\n");
880 goto out_err_txh_ch;
881 }
882
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100883 wcn36xx_dxe_init_tx_bd(&wcn->dxe_tx_h_ch, &wcn->mgmt_mem_pool);
884
885 /* Write channel head to a NEXT register */
886 wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_CH_NEXT_DESC_ADDR_TX_H,
887 wcn->dxe_tx_h_ch.head_blk_ctl->desc_phy_addr);
888
889 /* Program DMA destination addr for TX HIGH */
890 wcn36xx_dxe_write_register(wcn,
891 WCN36XX_DXE_CH_DEST_ADDR_TX_H,
892 WCN36XX_DXE_WQ_TX_H);
893
894 wcn36xx_dxe_read_register(wcn, WCN36XX_DXE_REG_CH_EN, &reg_data);
895
896 /* Enable channel interrupts */
897 wcn36xx_dxe_enable_ch_int(wcn, WCN36XX_INT_MASK_CHAN_TX_H);
898
899 /***************************************/
900 /* Init descriptors for RX LOW channel */
901 /***************************************/
Ramon Friedd0bb9502018-01-23 17:20:13 +0200902 ret = wcn36xx_dxe_init_descs(wcn->dev, &wcn->dxe_rx_l_ch);
903 if (ret) {
904 dev_err(wcn->dev, "Error allocating descriptor\n");
905 goto out_err_rxl_ch;
906 }
907
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100908
909 /* For RX we need to preallocated buffers */
910 wcn36xx_dxe_ch_alloc_skb(wcn, &wcn->dxe_rx_l_ch);
911
912 /* Write channel head to a NEXT register */
913 wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_CH_NEXT_DESC_ADDR_RX_L,
914 wcn->dxe_rx_l_ch.head_blk_ctl->desc_phy_addr);
915
916 /* Write DMA source address */
917 wcn36xx_dxe_write_register(wcn,
918 WCN36XX_DXE_CH_SRC_ADDR_RX_L,
919 WCN36XX_DXE_WQ_RX_L);
920
921 /* Program preallocated destination address */
922 wcn36xx_dxe_write_register(wcn,
923 WCN36XX_DXE_CH_DEST_ADDR_RX_L,
924 wcn->dxe_rx_l_ch.head_blk_ctl->desc->phy_next_l);
925
926 /* Enable default control registers */
927 wcn36xx_dxe_write_register(wcn,
928 WCN36XX_DXE_REG_CTL_RX_L,
929 WCN36XX_DXE_CH_DEFAULT_CTL_RX_L);
930
931 /* Enable channel interrupts */
932 wcn36xx_dxe_enable_ch_int(wcn, WCN36XX_INT_MASK_CHAN_RX_L);
933
934 /***************************************/
935 /* Init descriptors for RX HIGH channel */
936 /***************************************/
Ramon Friedd0bb9502018-01-23 17:20:13 +0200937 ret = wcn36xx_dxe_init_descs(wcn->dev, &wcn->dxe_rx_h_ch);
938 if (ret) {
939 dev_err(wcn->dev, "Error allocating descriptor\n");
940 goto out_err_rxh_ch;
941 }
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100942
943 /* For RX we need to prealocat buffers */
944 wcn36xx_dxe_ch_alloc_skb(wcn, &wcn->dxe_rx_h_ch);
945
946 /* Write chanel head to a NEXT register */
947 wcn36xx_dxe_write_register(wcn, WCN36XX_DXE_CH_NEXT_DESC_ADDR_RX_H,
948 wcn->dxe_rx_h_ch.head_blk_ctl->desc_phy_addr);
949
950 /* Write DMA source address */
951 wcn36xx_dxe_write_register(wcn,
952 WCN36XX_DXE_CH_SRC_ADDR_RX_H,
953 WCN36XX_DXE_WQ_RX_H);
954
955 /* Program preallocated destination address */
956 wcn36xx_dxe_write_register(wcn,
957 WCN36XX_DXE_CH_DEST_ADDR_RX_H,
958 wcn->dxe_rx_h_ch.head_blk_ctl->desc->phy_next_l);
959
960 /* Enable default control registers */
961 wcn36xx_dxe_write_register(wcn,
962 WCN36XX_DXE_REG_CTL_RX_H,
963 WCN36XX_DXE_CH_DEFAULT_CTL_RX_H);
964
965 /* Enable channel interrupts */
966 wcn36xx_dxe_enable_ch_int(wcn, WCN36XX_INT_MASK_CHAN_RX_H);
967
968 ret = wcn36xx_dxe_request_irqs(wcn);
969 if (ret < 0)
Ramon Friedd0bb9502018-01-23 17:20:13 +0200970 goto out_err_irq;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100971
Loic Poulainfdf21cc2020-07-24 12:20:48 +0200972 timer_setup(&wcn->tx_ack_timer, wcn36xx_dxe_tx_timer, 0);
973
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100974 return 0;
975
Ramon Friedd0bb9502018-01-23 17:20:13 +0200976out_err_irq:
977 wcn36xx_dxe_deinit_descs(wcn->dev, &wcn->dxe_rx_h_ch);
978out_err_rxh_ch:
979 wcn36xx_dxe_deinit_descs(wcn->dev, &wcn->dxe_rx_l_ch);
980out_err_rxl_ch:
981 wcn36xx_dxe_deinit_descs(wcn->dev, &wcn->dxe_tx_h_ch);
982out_err_txh_ch:
983 wcn36xx_dxe_deinit_descs(wcn->dev, &wcn->dxe_tx_l_ch);
984
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100985 return ret;
986}
987
988void wcn36xx_dxe_deinit(struct wcn36xx *wcn)
989{
990 free_irq(wcn->tx_irq, wcn);
991 free_irq(wcn->rx_irq, wcn);
Loic Poulainfdf21cc2020-07-24 12:20:48 +0200992 del_timer(&wcn->tx_ack_timer);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100993
994 if (wcn->tx_ack_skb) {
995 ieee80211_tx_status_irqsafe(wcn->hw, wcn->tx_ack_skb);
996 wcn->tx_ack_skb = NULL;
997 }
998
999 wcn36xx_dxe_ch_free_skbs(wcn, &wcn->dxe_rx_l_ch);
1000 wcn36xx_dxe_ch_free_skbs(wcn, &wcn->dxe_rx_h_ch);
1001}