summaryrefslogtreecommitdiff
path: root/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c
blob: 7eff3531b9a539802ae4aa931814384f5b3c9ec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2021, MediaTek Inc.
 * Copyright (c) 2021-2022, Intel Corporation.
 *
 * Authors:
 *  Amir Hanania <amir.hanania@intel.com>
 *  Haijun Liu <haijun.liu@mediatek.com>
 *  Moises Veleta <moises.veleta@intel.com>
 *  Ricardo Martinez <ricardo.martinez@linux.intel.com>
 *
 * Contributors:
 *  Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
 *  Eliot Lee <eliot.lee@intel.com>
 *  Sreehari Kancharla <sreehari.kancharla@intel.com>
 */

#include <linux/device.h>
#include <linux/gfp.h>
#include <linux/irqreturn.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/string.h>
#include <linux/wait.h>
#include <linux/workqueue.h>

#include "t7xx_dpmaif.h"
#include "t7xx_hif_dpmaif.h"
#include "t7xx_hif_dpmaif_rx.h"
#include "t7xx_hif_dpmaif_tx.h"
#include "t7xx_pci.h"
#include "t7xx_pcie_mac.h"
#include "t7xx_state_monitor.h"

unsigned int t7xx_ring_buf_get_next_wr_idx(unsigned int buf_len, unsigned int buf_idx)
{
	buf_idx++;

	return buf_idx < buf_len ? buf_idx : 0;
}

unsigned int t7xx_ring_buf_rd_wr_count(unsigned int total_cnt, unsigned int rd_idx,
				       unsigned int wr_idx, enum dpmaif_rdwr rd_wr)
{
	int pkt_cnt;

	if (rd_wr == DPMAIF_READ)
		pkt_cnt = wr_idx - rd_idx;
	else
		pkt_cnt = rd_idx - wr_idx - 1;

	if (pkt_cnt < 0)
		pkt_cnt += total_cnt;

	return (unsigned int)pkt_cnt;
}

static void t7xx_dpmaif_enable_irq(struct dpmaif_ctrl *dpmaif_ctrl)
{
	struct dpmaif_isr_para *isr_para;
	int i;

	for (i = 0; i < ARRAY_SIZE(dpmaif_ctrl->isr_para); i++) {
		isr_para = &dpmaif_ctrl->isr_para[i];
		t7xx_pcie_mac_set_int(dpmaif_ctrl->t7xx_dev, isr_para->pcie_int);
	}
}

static void t7xx_dpmaif_disable_irq(struct dpmaif_ctrl *dpmaif_ctrl)
{
	struct dpmaif_isr_para *isr_para;
	int i;

	for (i = 0; i < ARRAY_SIZE(dpmaif_ctrl->isr_para); i++) {
		isr_para = &dpmaif_ctrl->isr_para[i];
		t7xx_pcie_mac_clear_int(dpmaif_ctrl->t7xx_dev, isr_para->pcie_int);
	}
}

static void t7xx_dpmaif_irq_cb(struct dpmaif_isr_para *isr_para)
{
	struct dpmaif_ctrl *dpmaif_ctrl = isr_para->dpmaif_ctrl;
	struct dpmaif_hw_intr_st_para intr_status;
	struct device *dev = dpmaif_ctrl->dev;
	struct dpmaif_hw_info *hw_info;
	int i;

	memset(&intr_status, 0, sizeof(intr_status));
	hw_info = &dpmaif_ctrl->hw_info;

	if (t7xx_dpmaif_hw_get_intr_cnt(hw_info, &intr_status, isr_para->dlq_id) < 0) {
		dev_err(dev, "Failed to get HW interrupt count\n");
		return;
	}

	t7xx_pcie_mac_clear_int_status(dpmaif_ctrl->t7xx_dev, isr_para->pcie_int);

	for (i = 0; i < intr_status.intr_cnt; i++) {
		switch (intr_status.intr_types[i]) {
		case DPF_INTR_UL_DONE:
			t7xx_dpmaif_irq_tx_done(dpmaif_ctrl, intr_status.intr_queues[i]);
			break;

		case DPF_INTR_UL_DRB_EMPTY:
		case DPF_INTR_UL_MD_NOTREADY:
		case DPF_INTR_UL_MD_PWR_NOTREADY:
			/* No need to log an error for these */
			break;

		case DPF_INTR_DL_BATCNT_LEN_ERR:
			dev_err_ratelimited(dev, "DL interrupt: packet BAT count length error\n");
			t7xx_dpmaif_dl_unmask_batcnt_len_err_intr(hw_info);
			break;

		case DPF_INTR_DL_PITCNT_LEN_ERR:
			dev_err_ratelimited(dev, "DL interrupt: PIT count length error\n");
			t7xx_dpmaif_dl_unmask_pitcnt_len_err_intr(hw_info);
			break;

		case DPF_INTR_DL_Q0_PITCNT_LEN_ERR:
			dev_err_ratelimited(dev, "DL interrupt: DLQ0 PIT count length error\n");
			t7xx_dpmaif_dlq_unmask_pitcnt_len_err_intr(hw_info, DPF_RX_QNO_DFT);
			break;

		case DPF_INTR_DL_Q1_PITCNT_LEN_ERR:
			dev_err_ratelimited(dev, "DL interrupt: DLQ1 PIT count length error\n");
			t7xx_dpmaif_dlq_unmask_pitcnt_len_err_intr(hw_info, DPF_RX_QNO1);
			break;

		case DPF_INTR_DL_DONE:
		case DPF_INTR_DL_Q0_DONE:
		case DPF_INTR_DL_Q1_DONE:
			t7xx_dpmaif_irq_rx_done(dpmaif_ctrl, intr_status.intr_queues[i]);
			break;

		default:
			dev_err_ratelimited(dev, "DL interrupt error: unknown type : %d\n",
					    intr_status.intr_types[i]);
		}
	}
}

static irqreturn_t t7xx_dpmaif_isr_handler(int irq, void *data)
{
	struct dpmaif_isr_para *isr_para = data;
	struct dpmaif_ctrl *dpmaif_ctrl;

	dpmaif_ctrl = isr_para->dpmaif_ctrl;
	if (dpmaif_ctrl->state != DPMAIF_STATE_PWRON) {
		dev_err(dpmaif_ctrl->dev, "Interrupt received before initializing DPMAIF\n");
		return IRQ_HANDLED;
	}

	t7xx_pcie_mac_clear_int(dpmaif_ctrl->t7xx_dev, isr_para->pcie_int);
	t7xx_dpmaif_irq_cb(isr_para);
	t7xx_pcie_mac_set_int(dpmaif_ctrl->t7xx_dev, isr_para->pcie_int);
	return IRQ_HANDLED;
}

static void t7xx_dpmaif_isr_parameter_init(struct dpmaif_ctrl *dpmaif_ctrl)
{
	struct dpmaif_isr_para *isr_para;
	unsigned char i;

	dpmaif_ctrl->rxq_int_mapping[DPF_RX_QNO0] = DPMAIF_INT;
	dpmaif_ctrl->rxq_int_mapping[DPF_RX_QNO1] = DPMAIF2_INT;

	for (i = 0; i < DPMAIF_RXQ_NUM; i++) {
		isr_para = &dpmaif_ctrl->isr_para[i];
		isr_para->dpmaif_ctrl = dpmaif_ctrl;
		isr_para->dlq_id = i;
		isr_para->pcie_int = dpmaif_ctrl->rxq_int_mapping[i];
	}
}

static void t7xx_dpmaif_register_pcie_irq(struct dpmaif_ctrl *dpmaif_ctrl)
{
	struct t7xx_pci_dev *t7xx_dev = dpmaif_ctrl->t7xx_dev;
	struct dpmaif_isr_para *isr_para;
	enum t7xx_int int_type;
	int i;

	t7xx_dpmaif_isr_parameter_init(dpmaif_ctrl);

	for (i = 0; i < DPMAIF_RXQ_NUM; i++) {
		isr_para = &dpmaif_ctrl->isr_para[i];
		int_type = isr_para->pcie_int;
		t7xx_pcie_mac_clear_int(t7xx_dev, int_type);

		t7xx_dev->intr_handler[int_type] = t7xx_dpmaif_isr_handler;
		t7xx_dev->intr_thread[int_type] = NULL;
		t7xx_dev->callback_param[int_type] = isr_para;

		t7xx_pcie_mac_clear_int_status(t7xx_dev, int_type);
		t7xx_pcie_mac_set_int(t7xx_dev, int_type);
	}
}

static int t7xx_dpmaif_rxtx_sw_allocs(struct dpmaif_ctrl *dpmaif_ctrl)
{
	struct dpmaif_rx_queue *rx_q;
	struct dpmaif_tx_queue *tx_q;
	int ret, rx_idx, tx_idx, i;

	ret = t7xx_dpmaif_bat_alloc(dpmaif_ctrl, &dpmaif_ctrl->bat_req, BAT_TYPE_NORMAL);
	if (ret) {
		dev_err(dpmaif_ctrl->dev, "Failed to allocate normal BAT table: %d\n", ret);
		return ret;
	}

	ret = t7xx_dpmaif_bat_alloc(dpmaif_ctrl, &dpmaif_ctrl->bat_frag, BAT_TYPE_FRAG);
	if (ret) {
		dev_err(dpmaif_ctrl->dev, "Failed to allocate frag BAT table: %d\n", ret);
		goto err_free_normal_bat;
	}

	for (rx_idx = 0; rx_idx < DPMAIF_RXQ_NUM; rx_idx++) {
		rx_q = &dpmaif_ctrl->rxq[rx_idx];
		rx_q->index = rx_idx;
		rx_q->dpmaif_ctrl = dpmaif_ctrl;
		ret = t7xx_dpmaif_rxq_init(rx_q);
		if (ret)
			goto err_free_rxq;
	}

	for (tx_idx = 0; tx_idx < DPMAIF_TXQ_NUM; tx_idx++) {
		tx_q = &dpmaif_ctrl->txq[tx_idx];
		tx_q->index = tx_idx;
		tx_q->dpmaif_ctrl = dpmaif_ctrl;
		ret = t7xx_dpmaif_txq_init(tx_q);
		if (ret)
			goto err_free_txq;
	}

	ret = t7xx_dpmaif_tx_thread_init(dpmaif_ctrl);
	if (ret) {
		dev_err(dpmaif_ctrl->dev, "Failed to start TX thread\n");
		goto err_free_txq;
	}

	ret = t7xx_dpmaif_bat_rel_wq_alloc(dpmaif_ctrl);
	if (ret)
		goto err_thread_rel;

	return 0;

err_thread_rel:
	t7xx_dpmaif_tx_thread_rel(dpmaif_ctrl);

err_free_txq:
	for (i = 0; i < tx_idx; i++) {
		tx_q = &dpmaif_ctrl->txq[i];
		t7xx_dpmaif_txq_free(tx_q);
	}

err_free_rxq:
	for (i = 0; i < rx_idx; i++) {
		rx_q = &dpmaif_ctrl->rxq[i];
		t7xx_dpmaif_rxq_free(rx_q);
	}

	t7xx_dpmaif_bat_free(dpmaif_ctrl, &dpmaif_ctrl->bat_frag);

err_free_normal_bat:
	t7xx_dpmaif_bat_free(dpmaif_ctrl, &dpmaif_ctrl->bat_req);

	return ret;
}

static void t7xx_dpmaif_sw_release(struct dpmaif_ctrl *dpmaif_ctrl)
{
	struct dpmaif_rx_queue *rx_q;
	struct dpmaif_tx_queue *tx_q;
	int i;

	t7xx_dpmaif_tx_thread_rel(dpmaif_ctrl);
	t7xx_dpmaif_bat_wq_rel(dpmaif_ctrl);

	for (i = 0; i < DPMAIF_TXQ_NUM; i++) {
		tx_q = &dpmaif_ctrl->txq[i];
		t7xx_dpmaif_txq_free(tx_q);
	}

	for (i = 0; i < DPMAIF_RXQ_NUM; i++) {
		rx_q = &dpmaif_ctrl->rxq[i];
		t7xx_dpmaif_rxq_free(rx_q);
	}
}

static int t7xx_dpmaif_start(struct dpmaif_ctrl *dpmaif_ctrl)
{
	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hw_info;
	struct dpmaif_hw_params hw_init_para;
	struct dpmaif_rx_queue *rxq;
	struct dpmaif_tx_queue *txq;
	unsigned int buf_cnt;
	int i, ret = 0;

	if (dpmaif_ctrl->state == DPMAIF_STATE_PWRON)
		return -EFAULT;

	memset(&hw_init_para, 0, sizeof(hw_init_para));

	for (i = 0; i < DPMAIF_RXQ_NUM; i++) {
		rxq = &dpmaif_ctrl->rxq[i];
		rxq->que_started = true;
		rxq->index = i;
		rxq->budget = rxq->bat_req->bat_size_cnt - 1;

		hw_init_para.pkt_bat_base_addr[i] = rxq->bat_req->bat_bus_addr;
		hw_init_para.pkt_bat_size_cnt[i] = rxq->bat_req->bat_size_cnt;
		hw_init_para.pit_base_addr[i] = rxq->pit_bus_addr;
		hw_init_para.pit_size_cnt[i] = rxq->pit_size_cnt;
		hw_init_para.frg_bat_base_addr[i] = rxq->bat_frag->bat_bus_addr;
		hw_init_para.frg_bat_size_cnt[i] = rxq->bat_frag->bat_size_cnt;
	}

	bitmap_zero(dpmaif_ctrl->bat_req.bat_bitmap, dpmaif_ctrl->bat_req.bat_size_cnt);
	buf_cnt = dpmaif_ctrl->bat_req.bat_size_cnt - 1;
	ret = t7xx_dpmaif_rx_buf_alloc(dpmaif_ctrl, &dpmaif_ctrl->bat_req, 0, buf_cnt, true);
	if (ret) {
		dev_err(dpmaif_ctrl->dev, "Failed to allocate RX buffer: %d\n", ret);
		return ret;
	}

	buf_cnt = dpmaif_ctrl->bat_frag.bat_size_cnt - 1;
	ret = t7xx_dpmaif_rx_frag_alloc(dpmaif_ctrl, &dpmaif_ctrl->bat_frag, buf_cnt, true);
	if (ret) {
		dev_err(dpmaif_ctrl->dev, "Failed to allocate frag RX buffer: %d\n", ret);
		goto err_free_normal_bat;
	}

	for (i = 0; i < DPMAIF_TXQ_NUM; i++) {
		txq = &dpmaif_ctrl->txq[i];
		txq->que_started = true;

		hw_init_para.drb_base_addr[i] = txq->drb_bus_addr;
		hw_init_para.drb_size_cnt[i] = txq->drb_size_cnt;
	}

	ret = t7xx_dpmaif_hw_init(hw_info, &hw_init_para);
	if (ret) {
		dev_err(dpmaif_ctrl->dev, "Failed to initialize DPMAIF HW: %d\n", ret);
		goto err_free_frag_bat;
	}

	ret = t7xx_dpmaif_dl_snd_hw_bat_cnt(hw_info, rxq->bat_req->bat_size_cnt - 1);
	if (ret)
		goto err_free_frag_bat;

	ret = t7xx_dpmaif_dl_snd_hw_frg_cnt(hw_info, rxq->bat_frag->bat_size_cnt - 1);
	if (ret)
		goto err_free_frag_bat;

	t7xx_dpmaif_ul_clr_all_intr(hw_info);
	t7xx_dpmaif_dl_clr_all_intr(hw_info);
	dpmaif_ctrl->state = DPMAIF_STATE_PWRON;
	t7xx_dpmaif_enable_irq(dpmaif_ctrl);
	wake_up(&dpmaif_ctrl->tx_wq);
	return 0;

err_free_frag_bat:
	t7xx_dpmaif_bat_free(rxq->dpmaif_ctrl, rxq->bat_frag);

err_free_normal_bat:
	t7xx_dpmaif_bat_free(rxq->dpmaif_ctrl, rxq->bat_req);

	return ret;
}

static void t7xx_dpmaif_stop_sw(struct dpmaif_ctrl *dpmaif_ctrl)
{
	t7xx_dpmaif_tx_stop(dpmaif_ctrl);
	t7xx_dpmaif_rx_stop(dpmaif_ctrl);
}

static void t7xx_dpmaif_stop_hw(struct dpmaif_ctrl *dpmaif_ctrl)
{
	t7xx_dpmaif_hw_stop_all_txq(&dpmaif_ctrl->hw_info);
	t7xx_dpmaif_hw_stop_all_rxq(&dpmaif_ctrl->hw_info);
}

static int t7xx_dpmaif_stop(struct dpmaif_ctrl *dpmaif_ctrl)
{
	if (!dpmaif_ctrl->dpmaif_sw_init_done) {
		dev_err(dpmaif_ctrl->dev, "dpmaif SW init fail\n");
		return -EFAULT;
	}

	if (dpmaif_ctrl->state == DPMAIF_STATE_PWROFF)
		return -EFAULT;

	t7xx_dpmaif_disable_irq(dpmaif_ctrl);
	dpmaif_ctrl->state = DPMAIF_STATE_PWROFF;
	t7xx_dpmaif_stop_sw(dpmaif_ctrl);
	t7xx_dpmaif_tx_clear(dpmaif_ctrl);
	t7xx_dpmaif_rx_clear(dpmaif_ctrl);
	return 0;
}

static int t7xx_dpmaif_suspend(struct t7xx_pci_dev *t7xx_dev, void *param)
{
	struct dpmaif_ctrl *dpmaif_ctrl = param;

	t7xx_dpmaif_tx_stop(dpmaif_ctrl);
	t7xx_dpmaif_hw_stop_all_txq(&dpmaif_ctrl->hw_info);
	t7xx_dpmaif_hw_stop_all_rxq(&dpmaif_ctrl->hw_info);
	t7xx_dpmaif_disable_irq(dpmaif_ctrl);
	t7xx_dpmaif_rx_stop(dpmaif_ctrl);
	return 0;
}

static void t7xx_dpmaif_unmask_dlq_intr(struct dpmaif_ctrl *dpmaif_ctrl)
{
	int qno;

	for (qno = 0; qno < DPMAIF_RXQ_NUM; qno++)
		t7xx_dpmaif_dlq_unmask_rx_done(&dpmaif_ctrl->hw_info, qno);
}

static void t7xx_dpmaif_start_txrx_qs(struct dpmaif_ctrl *dpmaif_ctrl)
{
	struct dpmaif_rx_queue *rxq;
	struct dpmaif_tx_queue *txq;
	unsigned int que_cnt;

	for (que_cnt = 0; que_cnt < DPMAIF_TXQ_NUM; que_cnt++) {
		txq = &dpmaif_ctrl->txq[que_cnt];
		txq->que_started = true;
	}

	for (que_cnt = 0; que_cnt < DPMAIF_RXQ_NUM; que_cnt++) {
		rxq = &dpmaif_ctrl->rxq[que_cnt];
		rxq->que_started = true;
	}
}

static int t7xx_dpmaif_resume(struct t7xx_pci_dev *t7xx_dev, void *param)
{
	struct dpmaif_ctrl *dpmaif_ctrl = param;

	if (!dpmaif_ctrl)
		return 0;

	t7xx_dpmaif_start_txrx_qs(dpmaif_ctrl);
	t7xx_dpmaif_enable_irq(dpmaif_ctrl);
	t7xx_dpmaif_unmask_dlq_intr(dpmaif_ctrl);
	t7xx_dpmaif_start_hw(&dpmaif_ctrl->hw_info);
	wake_up(&dpmaif_ctrl->tx_wq);
	return 0;
}

static int t7xx_dpmaif_pm_entity_init(struct dpmaif_ctrl *dpmaif_ctrl)
{
	struct md_pm_entity *dpmaif_pm_entity = &dpmaif_ctrl->dpmaif_pm_entity;
	int ret;

	INIT_LIST_HEAD(&dpmaif_pm_entity->entity);
	dpmaif_pm_entity->suspend = &t7xx_dpmaif_suspend;
	dpmaif_pm_entity->suspend_late = NULL;
	dpmaif_pm_entity->resume_early = NULL;
	dpmaif_pm_entity->resume = &t7xx_dpmaif_resume;
	dpmaif_pm_entity->id = PM_ENTITY_ID_DATA;
	dpmaif_pm_entity->entity_param = dpmaif_ctrl;

	ret = t7xx_pci_pm_entity_register(dpmaif_ctrl->t7xx_dev, dpmaif_pm_entity);
	if (ret)
		dev_err(dpmaif_ctrl->dev, "dpmaif register pm_entity fail\n");

	return ret;
}

static int t7xx_dpmaif_pm_entity_release(struct dpmaif_ctrl *dpmaif_ctrl)
{
	struct md_pm_entity *dpmaif_pm_entity = &dpmaif_ctrl->dpmaif_pm_entity;
	int ret;

	ret = t7xx_pci_pm_entity_unregister(dpmaif_ctrl->t7xx_dev, dpmaif_pm_entity);
	if (ret < 0)
		dev_err(dpmaif_ctrl->dev, "dpmaif register pm_entity fail\n");

	return ret;
}

int t7xx_dpmaif_md_state_callback(struct dpmaif_ctrl *dpmaif_ctrl, enum md_state state)
{
	int ret = 0;

	switch (state) {
	case MD_STATE_WAITING_FOR_HS1:
		ret = t7xx_dpmaif_start(dpmaif_ctrl);
		break;

	case MD_STATE_EXCEPTION:
		ret = t7xx_dpmaif_stop(dpmaif_ctrl);
		break;

	case MD_STATE_STOPPED:
		ret = t7xx_dpmaif_stop(dpmaif_ctrl);
		break;

	case MD_STATE_WAITING_TO_STOP:
		t7xx_dpmaif_stop_hw(dpmaif_ctrl);
		break;

	default:
		break;
	}

	return ret;
}

/**
 * t7xx_dpmaif_hif_init() - Initialize data path.
 * @t7xx_dev: MTK context structure.
 * @callbacks: Callbacks implemented by the network layer to handle RX skb and
 *	       event notifications.
 *
 * Allocate and initialize datapath control block.
 * Register datapath ISR, TX and RX resources.
 *
 * Return:
 * * dpmaif_ctrl pointer - Pointer to DPMAIF context structure.
 * * NULL		 - In case of error.
 */
struct dpmaif_ctrl *t7xx_dpmaif_hif_init(struct t7xx_pci_dev *t7xx_dev,
					 struct dpmaif_callbacks *callbacks)
{
	struct device *dev = &t7xx_dev->pdev->dev;
	struct dpmaif_ctrl *dpmaif_ctrl;
	int ret;

	if (!callbacks)
		return NULL;

	dpmaif_ctrl = devm_kzalloc(dev, sizeof(*dpmaif_ctrl), GFP_KERNEL);
	if (!dpmaif_ctrl)
		return NULL;

	dpmaif_ctrl->t7xx_dev = t7xx_dev;
	dpmaif_ctrl->callbacks = callbacks;
	dpmaif_ctrl->dev = dev;
	dpmaif_ctrl->dpmaif_sw_init_done = false;
	dpmaif_ctrl->hw_info.dev = dev;
	dpmaif_ctrl->hw_info.pcie_base = t7xx_dev->base_addr.pcie_ext_reg_base -
					 t7xx_dev->base_addr.pcie_dev_reg_trsl_addr;

	ret = t7xx_dpmaif_pm_entity_init(dpmaif_ctrl);
	if (ret)
		return NULL;

	t7xx_dpmaif_register_pcie_irq(dpmaif_ctrl);
	t7xx_dpmaif_disable_irq(dpmaif_ctrl);

	ret = t7xx_dpmaif_rxtx_sw_allocs(dpmaif_ctrl);
	if (ret) {
		t7xx_dpmaif_pm_entity_release(dpmaif_ctrl);
		dev_err(dev, "Failed to allocate RX/TX SW resources: %d\n", ret);
		return NULL;
	}

	dpmaif_ctrl->dpmaif_sw_init_done = true;
	return dpmaif_ctrl;
}

void t7xx_dpmaif_hif_exit(struct dpmaif_ctrl *dpmaif_ctrl)
{
	if (dpmaif_ctrl->dpmaif_sw_init_done) {
		t7xx_dpmaif_stop(dpmaif_ctrl);
		t7xx_dpmaif_pm_entity_release(dpmaif_ctrl);
		t7xx_dpmaif_sw_release(dpmaif_ctrl);
		dpmaif_ctrl->dpmaif_sw_init_done = false;
	}
}