1 /*
2  * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
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
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 #ifndef __MT76_DMA_H
17 #define __MT76_DMA_H
18 
19 #define MT_RING_SIZE			0x10
20 
21 #define MT_DMA_CTL_SD_LEN1		GENMASK(13, 0)
22 #define MT_DMA_CTL_LAST_SEC1		BIT(14)
23 #define MT_DMA_CTL_BURST		BIT(15)
24 #define MT_DMA_CTL_SD_LEN0		GENMASK(29, 16)
25 #define MT_DMA_CTL_LAST_SEC0		BIT(30)
26 #define MT_DMA_CTL_DMA_DONE		BIT(31)
27 
28 #define MT_TXD_INFO_LEN			GENMASK(15, 0)
29 #define MT_TXD_INFO_NEXT_VLD		BIT(16)
30 #define MT_TXD_INFO_TX_BURST		BIT(17)
31 #define MT_TXD_INFO_80211		BIT(19)
32 #define MT_TXD_INFO_TSO			BIT(20)
33 #define MT_TXD_INFO_CSO			BIT(21)
34 #define MT_TXD_INFO_WIV			BIT(24)
35 #define MT_TXD_INFO_QSEL		GENMASK(26, 25)
36 #define MT_TXD_INFO_DPORT		GENMASK(29, 27)
37 #define MT_TXD_INFO_TYPE		GENMASK(31, 30)
38 
39 #define MT_RX_FCE_INFO_LEN		GENMASK(13, 0)
40 #define MT_RX_FCE_INFO_SELF_GEN		BIT(15)
41 #define MT_RX_FCE_INFO_CMD_SEQ		GENMASK(19, 16)
42 #define MT_RX_FCE_INFO_EVT_TYPE		GENMASK(23, 20)
43 #define MT_RX_FCE_INFO_PCIE_INTR	BIT(24)
44 #define MT_RX_FCE_INFO_QSEL		GENMASK(26, 25)
45 #define MT_RX_FCE_INFO_D_PORT		GENMASK(29, 27)
46 #define MT_RX_FCE_INFO_TYPE		GENMASK(31, 30)
47 
48 /* MCU request message header  */
49 #define MT_MCU_MSG_LEN			GENMASK(15, 0)
50 #define MT_MCU_MSG_CMD_SEQ		GENMASK(19, 16)
51 #define MT_MCU_MSG_CMD_TYPE		GENMASK(26, 20)
52 #define MT_MCU_MSG_PORT			GENMASK(29, 27)
53 #define MT_MCU_MSG_TYPE			GENMASK(31, 30)
54 #define MT_MCU_MSG_TYPE_CMD		BIT(30)
55 
56 #define MT_DMA_HDR_LEN			4
57 #define MT_RX_INFO_LEN			4
58 #define MT_FCE_INFO_LEN			4
59 #define MT_RX_RXWI_LEN			32
60 
61 struct mt76_desc {
62 	__le32 buf0;
63 	__le32 ctrl;
64 	__le32 buf1;
65 	__le32 info;
66 } __packed __aligned(4);
67 
68 enum dma_msg_port {
69 	WLAN_PORT,
70 	CPU_RX_PORT,
71 	CPU_TX_PORT,
72 	HOST_PORT,
73 	VIRTUAL_CPU_RX_PORT,
74 	VIRTUAL_CPU_TX_PORT,
75 	DISCARD,
76 };
77 
78 int mt76_dma_attach(struct mt76_dev *dev);
79 void mt76_dma_cleanup(struct mt76_dev *dev);
80 
81 #endif
82