1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2021, MediaTek Inc.
4 * Copyright (c) 2021-2022, Intel Corporation.
7 * Amir Hanania <amir.hanania@intel.com>
8 * Haijun Liu <haijun.liu@mediatek.com>
9 * Moises Veleta <moises.veleta@intel.com>
10 * Ricardo Martinez <ricardo.martinez@linux.intel.com>
11 * Sreehari Kancharla <sreehari.kancharla@intel.com>
14 * Andy Shevchenko <andriy.shevchenko@linux.intel.com>
15 * Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
16 * Eliot Lee <eliot.lee@intel.com>
19 #include <linux/bits.h>
20 #include <linux/bitops.h>
21 #include <linux/delay.h>
22 #include <linux/device.h>
23 #include <linux/dmapool.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/dma-direction.h>
26 #include <linux/gfp.h>
28 #include <linux/io-64-nonatomic-lo-hi.h>
29 #include <linux/iopoll.h>
30 #include <linux/irqreturn.h>
31 #include <linux/kernel.h>
32 #include <linux/kthread.h>
33 #include <linux/list.h>
34 #include <linux/netdevice.h>
35 #include <linux/pci.h>
36 #include <linux/pm_runtime.h>
37 #include <linux/sched.h>
38 #include <linux/skbuff.h>
39 #include <linux/slab.h>
40 #include <linux/spinlock.h>
41 #include <linux/types.h>
42 #include <linux/wait.h>
43 #include <linux/workqueue.h>
45 #include "t7xx_cldma.h"
46 #include "t7xx_hif_cldma.h"
47 #include "t7xx_mhccif.h"
49 #include "t7xx_pcie_mac.h"
50 #include "t7xx_port_proxy.h"
52 #include "t7xx_state_monitor.h"
54 #define MAX_TX_BUDGET 16
55 #define MAX_RX_BUDGET 16
57 #define CHECK_Q_STOP_TIMEOUT_US 1000000
58 #define CHECK_Q_STOP_STEP_US 10000
60 #define CLDMA_JUMBO_BUFF_SZ (63 * 1024 + sizeof(struct ccci_header))
62 static void md_cd_queue_struct_reset(struct cldma_queue *queue, struct cldma_ctrl *md_ctrl,
63 enum mtk_txrx tx_rx, unsigned int index)
67 queue->md_ctrl = md_ctrl;
68 queue->tr_ring = NULL;
69 queue->tr_done = NULL;
70 queue->tx_next = NULL;
73 static void md_cd_queue_struct_init(struct cldma_queue *queue, struct cldma_ctrl *md_ctrl,
74 enum mtk_txrx tx_rx, unsigned int index)
76 md_cd_queue_struct_reset(queue, md_ctrl, tx_rx, index);
77 init_waitqueue_head(&queue->req_wq);
78 spin_lock_init(&queue->ring_lock);
81 static void t7xx_cldma_gpd_set_data_ptr(struct cldma_gpd *gpd, dma_addr_t data_ptr)
83 gpd->data_buff_bd_ptr_h = cpu_to_le32(upper_32_bits(data_ptr));
84 gpd->data_buff_bd_ptr_l = cpu_to_le32(lower_32_bits(data_ptr));
87 static void t7xx_cldma_gpd_set_next_ptr(struct cldma_gpd *gpd, dma_addr_t next_ptr)
89 gpd->next_gpd_ptr_h = cpu_to_le32(upper_32_bits(next_ptr));
90 gpd->next_gpd_ptr_l = cpu_to_le32(lower_32_bits(next_ptr));
93 static int t7xx_cldma_alloc_and_map_skb(struct cldma_ctrl *md_ctrl, struct cldma_request *req,
94 size_t size, gfp_t gfp_mask)
96 req->skb = __dev_alloc_skb(size, gfp_mask);
100 req->mapped_buff = dma_map_single(md_ctrl->dev, req->skb->data, size, DMA_FROM_DEVICE);
101 if (dma_mapping_error(md_ctrl->dev, req->mapped_buff)) {
102 dev_kfree_skb_any(req->skb);
104 req->mapped_buff = 0;
105 dev_err(md_ctrl->dev, "DMA mapping failed\n");
112 static int t7xx_cldma_gpd_rx_from_q(struct cldma_queue *queue, int budget, bool *over_budget)
114 struct cldma_ctrl *md_ctrl = queue->md_ctrl;
115 unsigned int hwo_polling_count = 0;
116 struct t7xx_cldma_hw *hw_info;
117 bool rx_not_done = true;
121 hw_info = &md_ctrl->hw_info;
124 struct cldma_request *req;
125 struct cldma_gpd *gpd;
129 req = queue->tr_done;
134 if ((gpd->flags & GPD_FLAGS_HWO) || !req->skb) {
137 if (!pci_device_is_present(to_pci_dev(md_ctrl->dev))) {
138 dev_err(md_ctrl->dev, "PCIe Link disconnected\n");
142 gpd_addr = ioread64(hw_info->ap_pdn_base + REG_CLDMA_DL_CURRENT_ADDRL_0 +
143 queue->index * sizeof(u64));
144 if (req->gpd_addr == gpd_addr || hwo_polling_count++ >= 100)
151 hwo_polling_count = 0;
154 if (req->mapped_buff) {
155 dma_unmap_single(md_ctrl->dev, req->mapped_buff,
156 queue->tr_ring->pkt_size, DMA_FROM_DEVICE);
157 req->mapped_buff = 0;
161 skb_reset_tail_pointer(skb);
162 skb_put(skb, le16_to_cpu(gpd->data_buff_len));
164 ret = md_ctrl->recv_skb(queue, skb);
165 /* Break processing, will try again later */
170 t7xx_cldma_gpd_set_data_ptr(gpd, 0);
172 spin_lock_irqsave(&queue->ring_lock, flags);
173 queue->tr_done = list_next_entry_circular(req, &queue->tr_ring->gpd_ring, entry);
174 spin_unlock_irqrestore(&queue->ring_lock, flags);
175 req = queue->rx_refill;
177 ret = t7xx_cldma_alloc_and_map_skb(md_ctrl, req, queue->tr_ring->pkt_size, GFP_KERNEL);
182 t7xx_cldma_gpd_set_data_ptr(gpd, req->mapped_buff);
183 gpd->data_buff_len = 0;
184 gpd->flags = GPD_FLAGS_IOC | GPD_FLAGS_HWO;
186 spin_lock_irqsave(&queue->ring_lock, flags);
187 queue->rx_refill = list_next_entry_circular(req, &queue->tr_ring->gpd_ring, entry);
188 spin_unlock_irqrestore(&queue->ring_lock, flags);
190 rx_not_done = ++count < budget || !need_resched();
191 } while (rx_not_done);
197 static int t7xx_cldma_gpd_rx_collect(struct cldma_queue *queue, int budget)
199 struct cldma_ctrl *md_ctrl = queue->md_ctrl;
200 struct t7xx_cldma_hw *hw_info;
201 unsigned int pending_rx_int;
202 bool over_budget = false;
206 hw_info = &md_ctrl->hw_info;
209 ret = t7xx_cldma_gpd_rx_from_q(queue, budget, &over_budget);
217 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
218 if (md_ctrl->rxq_active & BIT(queue->index)) {
219 if (!t7xx_cldma_hw_queue_status(hw_info, queue->index, MTK_RX))
220 t7xx_cldma_hw_resume_queue(hw_info, queue->index, MTK_RX);
222 pending_rx_int = t7xx_cldma_hw_int_status(hw_info, BIT(queue->index),
224 if (pending_rx_int) {
225 t7xx_cldma_hw_rx_done(hw_info, pending_rx_int);
228 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
233 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
234 } while (pending_rx_int);
239 static void t7xx_cldma_rx_done(struct work_struct *work)
241 struct cldma_queue *queue = container_of(work, struct cldma_queue, cldma_work);
242 struct cldma_ctrl *md_ctrl = queue->md_ctrl;
245 value = t7xx_cldma_gpd_rx_collect(queue, queue->budget);
246 if (value && md_ctrl->rxq_active & BIT(queue->index)) {
247 queue_work(queue->worker, &queue->cldma_work);
251 t7xx_cldma_clear_ip_busy(&md_ctrl->hw_info);
252 t7xx_cldma_hw_irq_en_txrx(&md_ctrl->hw_info, queue->index, MTK_RX);
253 t7xx_cldma_hw_irq_en_eq(&md_ctrl->hw_info, queue->index, MTK_RX);
254 pm_runtime_mark_last_busy(md_ctrl->dev);
255 pm_runtime_put_autosuspend(md_ctrl->dev);
258 static int t7xx_cldma_gpd_tx_collect(struct cldma_queue *queue)
260 struct cldma_ctrl *md_ctrl = queue->md_ctrl;
261 unsigned int dma_len, count = 0;
262 struct cldma_request *req;
263 struct cldma_gpd *gpd;
268 while (!kthread_should_stop()) {
269 spin_lock_irqsave(&queue->ring_lock, flags);
270 req = queue->tr_done;
272 spin_unlock_irqrestore(&queue->ring_lock, flags);
276 if ((gpd->flags & GPD_FLAGS_HWO) || !req->skb) {
277 spin_unlock_irqrestore(&queue->ring_lock, flags);
281 dma_free = req->mapped_buff;
282 dma_len = le16_to_cpu(gpd->data_buff_len);
285 queue->tr_done = list_next_entry_circular(req, &queue->tr_ring->gpd_ring, entry);
286 spin_unlock_irqrestore(&queue->ring_lock, flags);
289 dma_unmap_single(md_ctrl->dev, dma_free, dma_len, DMA_TO_DEVICE);
290 dev_kfree_skb_any(skb);
294 wake_up_nr(&queue->req_wq, count);
299 static void t7xx_cldma_txq_empty_hndl(struct cldma_queue *queue)
301 struct cldma_ctrl *md_ctrl = queue->md_ctrl;
302 struct cldma_request *req;
303 dma_addr_t ul_curr_addr;
307 if (!(md_ctrl->txq_active & BIT(queue->index)))
310 spin_lock_irqsave(&queue->ring_lock, flags);
311 req = list_prev_entry_circular(queue->tx_next, &queue->tr_ring->gpd_ring, entry);
312 spin_unlock_irqrestore(&queue->ring_lock, flags);
314 pending_gpd = (req->gpd->flags & GPD_FLAGS_HWO) && req->skb;
316 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
318 struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
320 /* Check current processing TGPD, 64-bit address is in a table by Q index */
321 ul_curr_addr = ioread64(hw_info->ap_pdn_base + REG_CLDMA_UL_CURRENT_ADDRL_0 +
322 queue->index * sizeof(u64));
323 if (req->gpd_addr != ul_curr_addr) {
324 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
325 dev_err(md_ctrl->dev, "CLDMA%d queue %d is not empty\n",
326 md_ctrl->hif_id, queue->index);
330 t7xx_cldma_hw_resume_queue(hw_info, queue->index, MTK_TX);
332 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
335 static void t7xx_cldma_tx_done(struct work_struct *work)
337 struct cldma_queue *queue = container_of(work, struct cldma_queue, cldma_work);
338 struct cldma_ctrl *md_ctrl = queue->md_ctrl;
339 struct t7xx_cldma_hw *hw_info;
340 unsigned int l2_tx_int;
343 hw_info = &md_ctrl->hw_info;
344 t7xx_cldma_gpd_tx_collect(queue);
345 l2_tx_int = t7xx_cldma_hw_int_status(hw_info, BIT(queue->index) | EQ_STA_BIT(queue->index),
347 if (l2_tx_int & EQ_STA_BIT(queue->index)) {
348 t7xx_cldma_hw_tx_done(hw_info, EQ_STA_BIT(queue->index));
349 t7xx_cldma_txq_empty_hndl(queue);
352 if (l2_tx_int & BIT(queue->index)) {
353 t7xx_cldma_hw_tx_done(hw_info, BIT(queue->index));
354 queue_work(queue->worker, &queue->cldma_work);
358 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
359 if (md_ctrl->txq_active & BIT(queue->index)) {
360 t7xx_cldma_clear_ip_busy(hw_info);
361 t7xx_cldma_hw_irq_en_eq(hw_info, queue->index, MTK_TX);
362 t7xx_cldma_hw_irq_en_txrx(hw_info, queue->index, MTK_TX);
364 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
366 pm_runtime_mark_last_busy(md_ctrl->dev);
367 pm_runtime_put_autosuspend(md_ctrl->dev);
370 static void t7xx_cldma_ring_free(struct cldma_ctrl *md_ctrl,
371 struct cldma_ring *ring, enum dma_data_direction tx_rx)
373 struct cldma_request *req_cur, *req_next;
375 list_for_each_entry_safe(req_cur, req_next, &ring->gpd_ring, entry) {
376 if (req_cur->mapped_buff && req_cur->skb) {
377 dma_unmap_single(md_ctrl->dev, req_cur->mapped_buff,
378 ring->pkt_size, tx_rx);
379 req_cur->mapped_buff = 0;
382 dev_kfree_skb_any(req_cur->skb);
385 dma_pool_free(md_ctrl->gpd_dmapool, req_cur->gpd, req_cur->gpd_addr);
387 list_del(&req_cur->entry);
392 static struct cldma_request *t7xx_alloc_rx_request(struct cldma_ctrl *md_ctrl, size_t pkt_size)
394 struct cldma_request *req;
397 req = kzalloc(sizeof(*req), GFP_KERNEL);
401 req->gpd = dma_pool_zalloc(md_ctrl->gpd_dmapool, GFP_KERNEL, &req->gpd_addr);
405 val = t7xx_cldma_alloc_and_map_skb(md_ctrl, req, pkt_size, GFP_KERNEL);
412 dma_pool_free(md_ctrl->gpd_dmapool, req->gpd, req->gpd_addr);
420 static int t7xx_cldma_rx_ring_init(struct cldma_ctrl *md_ctrl, struct cldma_ring *ring)
422 struct cldma_request *req;
423 struct cldma_gpd *gpd;
426 INIT_LIST_HEAD(&ring->gpd_ring);
427 ring->length = MAX_RX_BUDGET;
429 for (i = 0; i < ring->length; i++) {
430 req = t7xx_alloc_rx_request(md_ctrl, ring->pkt_size);
432 t7xx_cldma_ring_free(md_ctrl, ring, DMA_FROM_DEVICE);
437 t7xx_cldma_gpd_set_data_ptr(gpd, req->mapped_buff);
438 gpd->rx_data_allow_len = cpu_to_le16(ring->pkt_size);
439 gpd->flags = GPD_FLAGS_IOC | GPD_FLAGS_HWO;
440 INIT_LIST_HEAD(&req->entry);
441 list_add_tail(&req->entry, &ring->gpd_ring);
444 /* Link previous GPD to next GPD, circular */
445 list_for_each_entry(req, &ring->gpd_ring, entry) {
446 t7xx_cldma_gpd_set_next_ptr(gpd, req->gpd_addr);
453 static struct cldma_request *t7xx_alloc_tx_request(struct cldma_ctrl *md_ctrl)
455 struct cldma_request *req;
457 req = kzalloc(sizeof(*req), GFP_KERNEL);
461 req->gpd = dma_pool_zalloc(md_ctrl->gpd_dmapool, GFP_KERNEL, &req->gpd_addr);
470 static int t7xx_cldma_tx_ring_init(struct cldma_ctrl *md_ctrl, struct cldma_ring *ring)
472 struct cldma_request *req;
473 struct cldma_gpd *gpd;
476 INIT_LIST_HEAD(&ring->gpd_ring);
477 ring->length = MAX_TX_BUDGET;
479 for (i = 0; i < ring->length; i++) {
480 req = t7xx_alloc_tx_request(md_ctrl);
482 t7xx_cldma_ring_free(md_ctrl, ring, DMA_TO_DEVICE);
487 gpd->flags = GPD_FLAGS_IOC;
488 INIT_LIST_HEAD(&req->entry);
489 list_add_tail(&req->entry, &ring->gpd_ring);
492 /* Link previous GPD to next GPD, circular */
493 list_for_each_entry(req, &ring->gpd_ring, entry) {
494 t7xx_cldma_gpd_set_next_ptr(gpd, req->gpd_addr);
502 * t7xx_cldma_q_reset() - Reset CLDMA request pointers to their initial values.
503 * @queue: Pointer to the queue structure.
505 * Called with ring_lock (unless called during initialization phase)
507 static void t7xx_cldma_q_reset(struct cldma_queue *queue)
509 struct cldma_request *req;
511 req = list_first_entry(&queue->tr_ring->gpd_ring, struct cldma_request, entry);
512 queue->tr_done = req;
513 queue->budget = queue->tr_ring->length;
515 if (queue->dir == MTK_TX)
516 queue->tx_next = req;
518 queue->rx_refill = req;
521 static void t7xx_cldma_rxq_init(struct cldma_queue *queue)
523 struct cldma_ctrl *md_ctrl = queue->md_ctrl;
526 queue->tr_ring = &md_ctrl->rx_ring[queue->index];
527 t7xx_cldma_q_reset(queue);
530 static void t7xx_cldma_txq_init(struct cldma_queue *queue)
532 struct cldma_ctrl *md_ctrl = queue->md_ctrl;
535 queue->tr_ring = &md_ctrl->tx_ring[queue->index];
536 t7xx_cldma_q_reset(queue);
539 static void t7xx_cldma_enable_irq(struct cldma_ctrl *md_ctrl)
541 t7xx_pcie_mac_set_int(md_ctrl->t7xx_dev, md_ctrl->hw_info.phy_interrupt_id);
544 static void t7xx_cldma_disable_irq(struct cldma_ctrl *md_ctrl)
546 t7xx_pcie_mac_clear_int(md_ctrl->t7xx_dev, md_ctrl->hw_info.phy_interrupt_id);
549 static void t7xx_cldma_irq_work_cb(struct cldma_ctrl *md_ctrl)
551 unsigned long l2_tx_int_msk, l2_rx_int_msk, l2_tx_int, l2_rx_int, val;
552 struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
555 /* L2 raw interrupt status */
556 l2_tx_int = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0);
557 l2_rx_int = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0);
558 l2_tx_int_msk = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2TIMR0);
559 l2_rx_int_msk = ioread32(hw_info->ap_ao_base + REG_CLDMA_L2RIMR0);
560 l2_tx_int &= ~l2_tx_int_msk;
561 l2_rx_int &= ~l2_rx_int_msk;
564 if (l2_tx_int & (TQ_ERR_INT_BITMASK | TQ_ACTIVE_START_ERR_INT_BITMASK)) {
565 /* Read and clear L3 TX interrupt status */
566 val = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L3TISAR0);
567 iowrite32(val, hw_info->ap_pdn_base + REG_CLDMA_L3TISAR0);
568 val = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L3TISAR1);
569 iowrite32(val, hw_info->ap_pdn_base + REG_CLDMA_L3TISAR1);
572 t7xx_cldma_hw_tx_done(hw_info, l2_tx_int);
573 if (l2_tx_int & (TXRX_STATUS_BITMASK | EMPTY_STATUS_BITMASK)) {
574 for_each_set_bit(i, &l2_tx_int, L2_INT_BIT_COUNT) {
575 if (i < CLDMA_TXQ_NUM) {
576 pm_runtime_get(md_ctrl->dev);
577 t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_TX);
578 t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_TX);
579 queue_work(md_ctrl->txq[i].worker,
580 &md_ctrl->txq[i].cldma_work);
582 t7xx_cldma_txq_empty_hndl(&md_ctrl->txq[i - CLDMA_TXQ_NUM]);
589 if (l2_rx_int & (RQ_ERR_INT_BITMASK | RQ_ACTIVE_START_ERR_INT_BITMASK)) {
590 /* Read and clear L3 RX interrupt status */
591 val = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L3RISAR0);
592 iowrite32(val, hw_info->ap_pdn_base + REG_CLDMA_L3RISAR0);
593 val = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L3RISAR1);
594 iowrite32(val, hw_info->ap_pdn_base + REG_CLDMA_L3RISAR1);
597 t7xx_cldma_hw_rx_done(hw_info, l2_rx_int);
598 if (l2_rx_int & (TXRX_STATUS_BITMASK | EMPTY_STATUS_BITMASK)) {
599 l2_rx_int |= l2_rx_int >> CLDMA_RXQ_NUM;
600 for_each_set_bit(i, &l2_rx_int, CLDMA_RXQ_NUM) {
601 pm_runtime_get(md_ctrl->dev);
602 t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_RX);
603 t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_RX);
604 queue_work(md_ctrl->rxq[i].worker, &md_ctrl->rxq[i].cldma_work);
610 static bool t7xx_cldma_qs_are_active(struct cldma_ctrl *md_ctrl)
612 struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
613 unsigned int tx_active;
614 unsigned int rx_active;
616 if (!pci_device_is_present(to_pci_dev(md_ctrl->dev)))
619 tx_active = t7xx_cldma_hw_queue_status(hw_info, CLDMA_ALL_Q, MTK_TX);
620 rx_active = t7xx_cldma_hw_queue_status(hw_info, CLDMA_ALL_Q, MTK_RX);
622 return tx_active || rx_active;
626 * t7xx_cldma_stop() - Stop CLDMA.
627 * @md_ctrl: CLDMA context structure.
629 * Stop TX and RX queues. Disable L1 and L2 interrupts.
630 * Clear status registers.
634 * * -ERROR - Error code from polling cldma_queues_active.
636 int t7xx_cldma_stop(struct cldma_ctrl *md_ctrl)
638 struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
642 md_ctrl->rxq_active = 0;
643 t7xx_cldma_hw_stop_all_qs(hw_info, MTK_RX);
644 md_ctrl->txq_active = 0;
645 t7xx_cldma_hw_stop_all_qs(hw_info, MTK_TX);
646 md_ctrl->txq_started = 0;
647 t7xx_cldma_disable_irq(md_ctrl);
648 t7xx_cldma_hw_stop(hw_info, MTK_RX);
649 t7xx_cldma_hw_stop(hw_info, MTK_TX);
650 t7xx_cldma_hw_tx_done(hw_info, CLDMA_L2TISAR0_ALL_INT_MASK);
651 t7xx_cldma_hw_rx_done(hw_info, CLDMA_L2RISAR0_ALL_INT_MASK);
653 if (md_ctrl->is_late_init) {
654 for (i = 0; i < CLDMA_TXQ_NUM; i++)
655 flush_work(&md_ctrl->txq[i].cldma_work);
657 for (i = 0; i < CLDMA_RXQ_NUM; i++)
658 flush_work(&md_ctrl->rxq[i].cldma_work);
661 ret = read_poll_timeout(t7xx_cldma_qs_are_active, active, !active, CHECK_Q_STOP_STEP_US,
662 CHECK_Q_STOP_TIMEOUT_US, true, md_ctrl);
664 dev_err(md_ctrl->dev, "Could not stop CLDMA%d queues", md_ctrl->hif_id);
669 static void t7xx_cldma_late_release(struct cldma_ctrl *md_ctrl)
673 if (!md_ctrl->is_late_init)
676 for (i = 0; i < CLDMA_TXQ_NUM; i++)
677 t7xx_cldma_ring_free(md_ctrl, &md_ctrl->tx_ring[i], DMA_TO_DEVICE);
679 for (i = 0; i < CLDMA_RXQ_NUM; i++)
680 t7xx_cldma_ring_free(md_ctrl, &md_ctrl->rx_ring[i], DMA_FROM_DEVICE);
682 dma_pool_destroy(md_ctrl->gpd_dmapool);
683 md_ctrl->gpd_dmapool = NULL;
684 md_ctrl->is_late_init = false;
687 void t7xx_cldma_reset(struct cldma_ctrl *md_ctrl)
692 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
693 md_ctrl->txq_active = 0;
694 md_ctrl->rxq_active = 0;
695 t7xx_cldma_disable_irq(md_ctrl);
696 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
698 for (i = 0; i < CLDMA_TXQ_NUM; i++) {
699 cancel_work_sync(&md_ctrl->txq[i].cldma_work);
701 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
702 md_cd_queue_struct_reset(&md_ctrl->txq[i], md_ctrl, MTK_TX, i);
703 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
706 for (i = 0; i < CLDMA_RXQ_NUM; i++) {
707 cancel_work_sync(&md_ctrl->rxq[i].cldma_work);
709 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
710 md_cd_queue_struct_reset(&md_ctrl->rxq[i], md_ctrl, MTK_RX, i);
711 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
714 t7xx_cldma_late_release(md_ctrl);
718 * t7xx_cldma_start() - Start CLDMA.
719 * @md_ctrl: CLDMA context structure.
721 * Set TX/RX start address.
722 * Start all RX queues and enable L2 interrupt.
724 void t7xx_cldma_start(struct cldma_ctrl *md_ctrl)
728 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
729 if (md_ctrl->is_late_init) {
730 struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
733 t7xx_cldma_enable_irq(md_ctrl);
735 for (i = 0; i < CLDMA_TXQ_NUM; i++) {
736 if (md_ctrl->txq[i].tr_done)
737 t7xx_cldma_hw_set_start_addr(hw_info, i,
738 md_ctrl->txq[i].tr_done->gpd_addr,
742 for (i = 0; i < CLDMA_RXQ_NUM; i++) {
743 if (md_ctrl->rxq[i].tr_done)
744 t7xx_cldma_hw_set_start_addr(hw_info, i,
745 md_ctrl->rxq[i].tr_done->gpd_addr,
749 /* Enable L2 interrupt */
750 t7xx_cldma_hw_start_queue(hw_info, CLDMA_ALL_Q, MTK_RX);
751 t7xx_cldma_hw_start(hw_info);
752 md_ctrl->txq_started = 0;
753 md_ctrl->txq_active |= TXRX_STATUS_BITMASK;
754 md_ctrl->rxq_active |= TXRX_STATUS_BITMASK;
756 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
759 static void t7xx_cldma_clear_txq(struct cldma_ctrl *md_ctrl, int qnum)
761 struct cldma_queue *txq = &md_ctrl->txq[qnum];
762 struct cldma_request *req;
763 struct cldma_gpd *gpd;
766 spin_lock_irqsave(&txq->ring_lock, flags);
767 t7xx_cldma_q_reset(txq);
768 list_for_each_entry(req, &txq->tr_ring->gpd_ring, entry) {
770 gpd->flags &= ~GPD_FLAGS_HWO;
771 t7xx_cldma_gpd_set_data_ptr(gpd, 0);
772 gpd->data_buff_len = 0;
773 dev_kfree_skb_any(req->skb);
776 spin_unlock_irqrestore(&txq->ring_lock, flags);
779 static int t7xx_cldma_clear_rxq(struct cldma_ctrl *md_ctrl, int qnum)
781 struct cldma_queue *rxq = &md_ctrl->rxq[qnum];
782 struct cldma_request *req;
783 struct cldma_gpd *gpd;
787 spin_lock_irqsave(&rxq->ring_lock, flags);
788 t7xx_cldma_q_reset(rxq);
789 list_for_each_entry(req, &rxq->tr_ring->gpd_ring, entry) {
791 gpd->flags = GPD_FLAGS_IOC | GPD_FLAGS_HWO;
792 gpd->data_buff_len = 0;
796 skb_reset_tail_pointer(req->skb);
800 list_for_each_entry(req, &rxq->tr_ring->gpd_ring, entry) {
804 ret = t7xx_cldma_alloc_and_map_skb(md_ctrl, req, rxq->tr_ring->pkt_size, GFP_ATOMIC);
808 t7xx_cldma_gpd_set_data_ptr(req->gpd, req->mapped_buff);
810 spin_unlock_irqrestore(&rxq->ring_lock, flags);
815 void t7xx_cldma_clear_all_qs(struct cldma_ctrl *md_ctrl, enum mtk_txrx tx_rx)
819 if (tx_rx == MTK_TX) {
820 for (i = 0; i < CLDMA_TXQ_NUM; i++)
821 t7xx_cldma_clear_txq(md_ctrl, i);
823 for (i = 0; i < CLDMA_RXQ_NUM; i++)
824 t7xx_cldma_clear_rxq(md_ctrl, i);
828 void t7xx_cldma_stop_all_qs(struct cldma_ctrl *md_ctrl, enum mtk_txrx tx_rx)
830 struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
833 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
834 t7xx_cldma_hw_irq_dis_eq(hw_info, CLDMA_ALL_Q, tx_rx);
835 t7xx_cldma_hw_irq_dis_txrx(hw_info, CLDMA_ALL_Q, tx_rx);
837 md_ctrl->rxq_active &= ~TXRX_STATUS_BITMASK;
839 md_ctrl->txq_active &= ~TXRX_STATUS_BITMASK;
840 t7xx_cldma_hw_stop_all_qs(hw_info, tx_rx);
841 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
844 static int t7xx_cldma_gpd_handle_tx_request(struct cldma_queue *queue, struct cldma_request *tx_req,
847 struct cldma_ctrl *md_ctrl = queue->md_ctrl;
848 struct cldma_gpd *gpd = tx_req->gpd;
852 tx_req->mapped_buff = dma_map_single(md_ctrl->dev, skb->data, skb->len, DMA_TO_DEVICE);
854 if (dma_mapping_error(md_ctrl->dev, tx_req->mapped_buff)) {
855 dev_err(md_ctrl->dev, "DMA mapping failed\n");
859 t7xx_cldma_gpd_set_data_ptr(gpd, tx_req->mapped_buff);
860 gpd->data_buff_len = cpu_to_le16(skb->len);
862 /* This lock must cover TGPD setting, as even without a resume operation,
863 * CLDMA can send next HWO=1 if last TGPD just finished.
865 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
866 if (md_ctrl->txq_active & BIT(queue->index))
867 gpd->flags |= GPD_FLAGS_HWO;
869 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
875 /* Called with cldma_lock */
876 static void t7xx_cldma_hw_start_send(struct cldma_ctrl *md_ctrl, int qno,
877 struct cldma_request *prev_req)
879 struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
881 /* Check whether the device was powered off (CLDMA start address is not set) */
882 if (!t7xx_cldma_tx_addr_is_set(hw_info, qno)) {
883 t7xx_cldma_hw_init(hw_info);
884 t7xx_cldma_hw_set_start_addr(hw_info, qno, prev_req->gpd_addr, MTK_TX);
885 md_ctrl->txq_started &= ~BIT(qno);
888 if (!t7xx_cldma_hw_queue_status(hw_info, qno, MTK_TX)) {
889 if (md_ctrl->txq_started & BIT(qno))
890 t7xx_cldma_hw_resume_queue(hw_info, qno, MTK_TX);
892 t7xx_cldma_hw_start_queue(hw_info, qno, MTK_TX);
894 md_ctrl->txq_started |= BIT(qno);
899 * t7xx_cldma_set_recv_skb() - Set the callback to handle RX packets.
900 * @md_ctrl: CLDMA context structure.
901 * @recv_skb: Receiving skb callback.
903 void t7xx_cldma_set_recv_skb(struct cldma_ctrl *md_ctrl,
904 int (*recv_skb)(struct cldma_queue *queue, struct sk_buff *skb))
906 md_ctrl->recv_skb = recv_skb;
910 * t7xx_cldma_send_skb() - Send control data to modem.
911 * @md_ctrl: CLDMA context structure.
912 * @qno: Queue number.
913 * @skb: Socket buffer.
917 * * -ENOMEM - Allocation failure.
918 * * -EINVAL - Invalid queue request.
919 * * -EIO - Queue is not active.
920 * * -ETIMEDOUT - Timeout waiting for the device to wake up.
922 int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb)
924 struct cldma_request *tx_req;
925 struct cldma_queue *queue;
929 if (qno >= CLDMA_TXQ_NUM)
932 ret = pm_runtime_resume_and_get(md_ctrl->dev);
933 if (ret < 0 && ret != -EACCES)
936 t7xx_pci_disable_sleep(md_ctrl->t7xx_dev);
937 queue = &md_ctrl->txq[qno];
939 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
940 if (!(md_ctrl->txq_active & BIT(qno))) {
942 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
945 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
948 spin_lock_irqsave(&queue->ring_lock, flags);
949 tx_req = queue->tx_next;
950 if (queue->budget > 0 && !tx_req->skb) {
951 struct list_head *gpd_ring = &queue->tr_ring->gpd_ring;
954 t7xx_cldma_gpd_handle_tx_request(queue, tx_req, skb);
955 queue->tx_next = list_next_entry_circular(tx_req, gpd_ring, entry);
956 spin_unlock_irqrestore(&queue->ring_lock, flags);
958 if (!t7xx_pci_sleep_disable_complete(md_ctrl->t7xx_dev)) {
963 /* Protect the access to the modem for queues operations (resume/start)
964 * which access shared locations by all the queues.
965 * cldma_lock is independent of ring_lock which is per queue.
967 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
968 t7xx_cldma_hw_start_send(md_ctrl, qno, tx_req);
969 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
973 spin_unlock_irqrestore(&queue->ring_lock, flags);
975 if (!t7xx_pci_sleep_disable_complete(md_ctrl->t7xx_dev)) {
980 if (!t7xx_cldma_hw_queue_status(&md_ctrl->hw_info, qno, MTK_TX)) {
981 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
982 t7xx_cldma_hw_resume_queue(&md_ctrl->hw_info, qno, MTK_TX);
983 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
986 ret = wait_event_interruptible_exclusive(queue->req_wq, queue->budget > 0);
990 t7xx_pci_enable_sleep(md_ctrl->t7xx_dev);
991 pm_runtime_mark_last_busy(md_ctrl->dev);
992 pm_runtime_put_autosuspend(md_ctrl->dev);
996 static int t7xx_cldma_late_init(struct cldma_ctrl *md_ctrl)
998 char dma_pool_name[32];
1001 if (md_ctrl->is_late_init) {
1002 dev_err(md_ctrl->dev, "CLDMA late init was already done\n");
1006 snprintf(dma_pool_name, sizeof(dma_pool_name), "cldma_req_hif%d", md_ctrl->hif_id);
1008 md_ctrl->gpd_dmapool = dma_pool_create(dma_pool_name, md_ctrl->dev,
1009 sizeof(struct cldma_gpd), GPD_DMAPOOL_ALIGN, 0);
1010 if (!md_ctrl->gpd_dmapool) {
1011 dev_err(md_ctrl->dev, "DMA pool alloc fail\n");
1015 for (i = 0; i < CLDMA_TXQ_NUM; i++) {
1016 ret = t7xx_cldma_tx_ring_init(md_ctrl, &md_ctrl->tx_ring[i]);
1018 dev_err(md_ctrl->dev, "control TX ring init fail\n");
1019 goto err_free_tx_ring;
1022 md_ctrl->tx_ring[i].pkt_size = CLDMA_MTU;
1025 for (j = 0; j < CLDMA_RXQ_NUM; j++) {
1026 md_ctrl->rx_ring[j].pkt_size = CLDMA_MTU;
1028 if (j == CLDMA_RXQ_NUM - 1)
1029 md_ctrl->rx_ring[j].pkt_size = CLDMA_JUMBO_BUFF_SZ;
1031 ret = t7xx_cldma_rx_ring_init(md_ctrl, &md_ctrl->rx_ring[j]);
1033 dev_err(md_ctrl->dev, "Control RX ring init fail\n");
1034 goto err_free_rx_ring;
1038 for (i = 0; i < CLDMA_TXQ_NUM; i++)
1039 t7xx_cldma_txq_init(&md_ctrl->txq[i]);
1041 for (j = 0; j < CLDMA_RXQ_NUM; j++)
1042 t7xx_cldma_rxq_init(&md_ctrl->rxq[j]);
1044 md_ctrl->is_late_init = true;
1049 t7xx_cldma_ring_free(md_ctrl, &md_ctrl->rx_ring[j], DMA_FROM_DEVICE);
1053 t7xx_cldma_ring_free(md_ctrl, &md_ctrl->tx_ring[i], DMA_TO_DEVICE);
1058 static void __iomem *t7xx_pcie_addr_transfer(void __iomem *addr, u32 addr_trs1, u32 phy_addr)
1060 return addr + phy_addr - addr_trs1;
1063 static void t7xx_hw_info_init(struct cldma_ctrl *md_ctrl)
1065 struct t7xx_addr_base *pbase = &md_ctrl->t7xx_dev->base_addr;
1066 struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
1067 u32 phy_ao_base, phy_pd_base;
1069 hw_info->hw_mode = MODE_BIT_64;
1071 if (md_ctrl->hif_id == CLDMA_ID_MD) {
1072 phy_ao_base = CLDMA1_AO_BASE;
1073 phy_pd_base = CLDMA1_PD_BASE;
1074 hw_info->phy_interrupt_id = CLDMA1_INT;
1076 phy_ao_base = CLDMA0_AO_BASE;
1077 phy_pd_base = CLDMA0_PD_BASE;
1078 hw_info->phy_interrupt_id = CLDMA0_INT;
1081 hw_info->ap_ao_base = t7xx_pcie_addr_transfer(pbase->pcie_ext_reg_base,
1082 pbase->pcie_dev_reg_trsl_addr, phy_ao_base);
1083 hw_info->ap_pdn_base = t7xx_pcie_addr_transfer(pbase->pcie_ext_reg_base,
1084 pbase->pcie_dev_reg_trsl_addr, phy_pd_base);
1087 static int t7xx_cldma_default_recv_skb(struct cldma_queue *queue, struct sk_buff *skb)
1089 dev_kfree_skb_any(skb);
1093 int t7xx_cldma_alloc(enum cldma_id hif_id, struct t7xx_pci_dev *t7xx_dev)
1095 struct device *dev = &t7xx_dev->pdev->dev;
1096 struct cldma_ctrl *md_ctrl;
1098 md_ctrl = devm_kzalloc(dev, sizeof(*md_ctrl), GFP_KERNEL);
1102 md_ctrl->t7xx_dev = t7xx_dev;
1104 md_ctrl->hif_id = hif_id;
1105 md_ctrl->recv_skb = t7xx_cldma_default_recv_skb;
1106 t7xx_hw_info_init(md_ctrl);
1107 t7xx_dev->md->md_ctrl[hif_id] = md_ctrl;
1111 static void t7xx_cldma_resume_early(struct t7xx_pci_dev *t7xx_dev, void *entity_param)
1113 struct cldma_ctrl *md_ctrl = entity_param;
1114 struct t7xx_cldma_hw *hw_info;
1115 unsigned long flags;
1118 hw_info = &md_ctrl->hw_info;
1120 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
1121 t7xx_cldma_hw_restore(hw_info);
1122 for (qno_t = 0; qno_t < CLDMA_TXQ_NUM; qno_t++) {
1123 t7xx_cldma_hw_set_start_addr(hw_info, qno_t, md_ctrl->txq[qno_t].tx_next->gpd_addr,
1125 t7xx_cldma_hw_set_start_addr(hw_info, qno_t, md_ctrl->rxq[qno_t].tr_done->gpd_addr,
1128 t7xx_cldma_enable_irq(md_ctrl);
1129 t7xx_cldma_hw_start_queue(hw_info, CLDMA_ALL_Q, MTK_RX);
1130 md_ctrl->rxq_active |= TXRX_STATUS_BITMASK;
1131 t7xx_cldma_hw_irq_en_eq(hw_info, CLDMA_ALL_Q, MTK_RX);
1132 t7xx_cldma_hw_irq_en_txrx(hw_info, CLDMA_ALL_Q, MTK_RX);
1133 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
1136 static int t7xx_cldma_resume(struct t7xx_pci_dev *t7xx_dev, void *entity_param)
1138 struct cldma_ctrl *md_ctrl = entity_param;
1139 unsigned long flags;
1141 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
1142 md_ctrl->txq_active |= TXRX_STATUS_BITMASK;
1143 t7xx_cldma_hw_irq_en_txrx(&md_ctrl->hw_info, CLDMA_ALL_Q, MTK_TX);
1144 t7xx_cldma_hw_irq_en_eq(&md_ctrl->hw_info, CLDMA_ALL_Q, MTK_TX);
1145 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
1147 if (md_ctrl->hif_id == CLDMA_ID_MD)
1148 t7xx_mhccif_mask_clr(t7xx_dev, D2H_SW_INT_MASK);
1153 static void t7xx_cldma_suspend_late(struct t7xx_pci_dev *t7xx_dev, void *entity_param)
1155 struct cldma_ctrl *md_ctrl = entity_param;
1156 struct t7xx_cldma_hw *hw_info;
1157 unsigned long flags;
1159 hw_info = &md_ctrl->hw_info;
1161 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
1162 t7xx_cldma_hw_irq_dis_eq(hw_info, CLDMA_ALL_Q, MTK_RX);
1163 t7xx_cldma_hw_irq_dis_txrx(hw_info, CLDMA_ALL_Q, MTK_RX);
1164 md_ctrl->rxq_active &= ~TXRX_STATUS_BITMASK;
1165 t7xx_cldma_hw_stop_all_qs(hw_info, MTK_RX);
1166 t7xx_cldma_clear_ip_busy(hw_info);
1167 t7xx_cldma_disable_irq(md_ctrl);
1168 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
1171 static int t7xx_cldma_suspend(struct t7xx_pci_dev *t7xx_dev, void *entity_param)
1173 struct cldma_ctrl *md_ctrl = entity_param;
1174 struct t7xx_cldma_hw *hw_info;
1175 unsigned long flags;
1177 if (md_ctrl->hif_id == CLDMA_ID_MD)
1178 t7xx_mhccif_mask_set(t7xx_dev, D2H_SW_INT_MASK);
1180 hw_info = &md_ctrl->hw_info;
1182 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
1183 t7xx_cldma_hw_irq_dis_eq(hw_info, CLDMA_ALL_Q, MTK_TX);
1184 t7xx_cldma_hw_irq_dis_txrx(hw_info, CLDMA_ALL_Q, MTK_TX);
1185 md_ctrl->txq_active &= ~TXRX_STATUS_BITMASK;
1186 t7xx_cldma_hw_stop_all_qs(hw_info, MTK_TX);
1187 md_ctrl->txq_started = 0;
1188 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
1193 static int t7xx_cldma_pm_init(struct cldma_ctrl *md_ctrl)
1195 md_ctrl->pm_entity = kzalloc(sizeof(*md_ctrl->pm_entity), GFP_KERNEL);
1196 if (!md_ctrl->pm_entity)
1199 md_ctrl->pm_entity->entity_param = md_ctrl;
1201 if (md_ctrl->hif_id == CLDMA_ID_MD)
1202 md_ctrl->pm_entity->id = PM_ENTITY_ID_CTRL1;
1204 md_ctrl->pm_entity->id = PM_ENTITY_ID_CTRL2;
1206 md_ctrl->pm_entity->suspend = t7xx_cldma_suspend;
1207 md_ctrl->pm_entity->suspend_late = t7xx_cldma_suspend_late;
1208 md_ctrl->pm_entity->resume = t7xx_cldma_resume;
1209 md_ctrl->pm_entity->resume_early = t7xx_cldma_resume_early;
1211 return t7xx_pci_pm_entity_register(md_ctrl->t7xx_dev, md_ctrl->pm_entity);
1214 static int t7xx_cldma_pm_uninit(struct cldma_ctrl *md_ctrl)
1216 if (!md_ctrl->pm_entity)
1219 t7xx_pci_pm_entity_unregister(md_ctrl->t7xx_dev, md_ctrl->pm_entity);
1220 kfree(md_ctrl->pm_entity);
1221 md_ctrl->pm_entity = NULL;
1225 void t7xx_cldma_hif_hw_init(struct cldma_ctrl *md_ctrl)
1227 struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
1228 unsigned long flags;
1230 spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
1231 t7xx_cldma_hw_stop(hw_info, MTK_TX);
1232 t7xx_cldma_hw_stop(hw_info, MTK_RX);
1233 t7xx_cldma_hw_rx_done(hw_info, EMPTY_STATUS_BITMASK | TXRX_STATUS_BITMASK);
1234 t7xx_cldma_hw_tx_done(hw_info, EMPTY_STATUS_BITMASK | TXRX_STATUS_BITMASK);
1235 t7xx_cldma_hw_init(hw_info);
1236 spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
1239 static irqreturn_t t7xx_cldma_isr_handler(int irq, void *data)
1241 struct cldma_ctrl *md_ctrl = data;
1244 interrupt = md_ctrl->hw_info.phy_interrupt_id;
1245 t7xx_pcie_mac_clear_int(md_ctrl->t7xx_dev, interrupt);
1246 t7xx_cldma_irq_work_cb(md_ctrl);
1247 t7xx_pcie_mac_clear_int_status(md_ctrl->t7xx_dev, interrupt);
1248 t7xx_pcie_mac_set_int(md_ctrl->t7xx_dev, interrupt);
1252 static void t7xx_cldma_destroy_wqs(struct cldma_ctrl *md_ctrl)
1256 for (i = 0; i < CLDMA_TXQ_NUM; i++) {
1257 if (md_ctrl->txq[i].worker) {
1258 destroy_workqueue(md_ctrl->txq[i].worker);
1259 md_ctrl->txq[i].worker = NULL;
1263 for (i = 0; i < CLDMA_RXQ_NUM; i++) {
1264 if (md_ctrl->rxq[i].worker) {
1265 destroy_workqueue(md_ctrl->rxq[i].worker);
1266 md_ctrl->rxq[i].worker = NULL;
1272 * t7xx_cldma_init() - Initialize CLDMA.
1273 * @md_ctrl: CLDMA context structure.
1275 * Allocate and initialize device power management entity.
1276 * Initialize HIF TX/RX queue structure.
1277 * Register CLDMA callback ISR with PCIe driver.
1281 * * -ERROR - Error code from failure sub-initializations.
1283 int t7xx_cldma_init(struct cldma_ctrl *md_ctrl)
1285 struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
1288 md_ctrl->txq_active = 0;
1289 md_ctrl->rxq_active = 0;
1290 md_ctrl->is_late_init = false;
1292 ret = t7xx_cldma_pm_init(md_ctrl);
1296 spin_lock_init(&md_ctrl->cldma_lock);
1298 for (i = 0; i < CLDMA_TXQ_NUM; i++) {
1299 md_cd_queue_struct_init(&md_ctrl->txq[i], md_ctrl, MTK_TX, i);
1300 md_ctrl->txq[i].worker =
1301 alloc_ordered_workqueue("md_hif%d_tx%d_worker",
1302 WQ_MEM_RECLAIM | (i ? 0 : WQ_HIGHPRI),
1303 md_ctrl->hif_id, i);
1304 if (!md_ctrl->txq[i].worker)
1307 INIT_WORK(&md_ctrl->txq[i].cldma_work, t7xx_cldma_tx_done);
1310 for (i = 0; i < CLDMA_RXQ_NUM; i++) {
1311 md_cd_queue_struct_init(&md_ctrl->rxq[i], md_ctrl, MTK_RX, i);
1312 INIT_WORK(&md_ctrl->rxq[i].cldma_work, t7xx_cldma_rx_done);
1314 md_ctrl->rxq[i].worker =
1315 alloc_ordered_workqueue("md_hif%d_rx%d_worker",
1317 md_ctrl->hif_id, i);
1318 if (!md_ctrl->rxq[i].worker)
1322 t7xx_pcie_mac_clear_int(md_ctrl->t7xx_dev, hw_info->phy_interrupt_id);
1323 md_ctrl->t7xx_dev->intr_handler[hw_info->phy_interrupt_id] = t7xx_cldma_isr_handler;
1324 md_ctrl->t7xx_dev->intr_thread[hw_info->phy_interrupt_id] = NULL;
1325 md_ctrl->t7xx_dev->callback_param[hw_info->phy_interrupt_id] = md_ctrl;
1326 t7xx_pcie_mac_clear_int_status(md_ctrl->t7xx_dev, hw_info->phy_interrupt_id);
1330 t7xx_cldma_destroy_wqs(md_ctrl);
1331 t7xx_cldma_pm_uninit(md_ctrl);
1335 void t7xx_cldma_switch_cfg(struct cldma_ctrl *md_ctrl)
1337 t7xx_cldma_late_release(md_ctrl);
1338 t7xx_cldma_late_init(md_ctrl);
1341 void t7xx_cldma_exit(struct cldma_ctrl *md_ctrl)
1343 t7xx_cldma_stop(md_ctrl);
1344 t7xx_cldma_late_release(md_ctrl);
1345 t7xx_cldma_destroy_wqs(md_ctrl);
1346 t7xx_cldma_pm_uninit(md_ctrl);