xref: /linux/include/linux/soc/ti/knav_dma.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2014 Texas Instruments Incorporated
4  * Authors:	Sandeep Nair <sandeep_n@ti.com
5  *		Cyril Chemparathy <cyril@ti.com
6 		Santosh Shilimkar <santosh.shilimkar@ti.com>
7  */
8 
9 #ifndef __SOC_TI_KEYSTONE_NAVIGATOR_DMA_H__
10 #define __SOC_TI_KEYSTONE_NAVIGATOR_DMA_H__
11 
12 #include <linux/dmaengine.h>
13 
14 /*
15  * PKTDMA descriptor manipulation macros for host packet descriptor
16  */
17 #define MASK(x)					(BIT(x) - 1)
18 #define KNAV_DMA_DESC_PKT_LEN_MASK		MASK(22)
19 #define KNAV_DMA_DESC_PKT_LEN_SHIFT		0
20 #define KNAV_DMA_DESC_PS_INFO_IN_SOP		BIT(22)
21 #define KNAV_DMA_DESC_PS_INFO_IN_DESC		0
22 #define KNAV_DMA_DESC_TAG_MASK			MASK(8)
23 #define KNAV_DMA_DESC_SAG_HI_SHIFT		24
24 #define KNAV_DMA_DESC_STAG_LO_SHIFT		16
25 #define KNAV_DMA_DESC_DTAG_HI_SHIFT		8
26 #define KNAV_DMA_DESC_DTAG_LO_SHIFT		0
27 #define KNAV_DMA_DESC_HAS_EPIB			BIT(31)
28 #define KNAV_DMA_DESC_NO_EPIB			0
29 #define KNAV_DMA_DESC_PSLEN_SHIFT		24
30 #define KNAV_DMA_DESC_PSLEN_MASK		MASK(6)
31 #define KNAV_DMA_DESC_ERR_FLAG_SHIFT		20
32 #define KNAV_DMA_DESC_ERR_FLAG_MASK		MASK(4)
33 #define KNAV_DMA_DESC_PSFLAG_SHIFT		16
34 #define KNAV_DMA_DESC_PSFLAG_MASK		MASK(4)
35 #define KNAV_DMA_DESC_RETQ_SHIFT		0
36 #define KNAV_DMA_DESC_RETQ_MASK			MASK(14)
37 #define KNAV_DMA_DESC_BUF_LEN_MASK		MASK(22)
38 #define KNAV_DMA_DESC_EFLAGS_MASK		MASK(4)
39 #define KNAV_DMA_DESC_EFLAGS_SHIFT		20
40 
41 #define KNAV_DMA_NUM_EPIB_WORDS			4
42 #define KNAV_DMA_NUM_PS_WORDS			16
43 #define KNAV_DMA_NUM_SW_DATA_WORDS		4
44 #define KNAV_DMA_FDQ_PER_CHAN			4
45 
46 /* Tx channel scheduling priority */
47 enum knav_dma_tx_priority {
48 	DMA_PRIO_HIGH	= 0,
49 	DMA_PRIO_MED_H,
50 	DMA_PRIO_MED_L,
51 	DMA_PRIO_LOW
52 };
53 
54 /* Rx channel error handling mode during buffer starvation */
55 enum knav_dma_rx_err_mode {
56 	DMA_DROP = 0,
57 	DMA_RETRY
58 };
59 
60 /* Rx flow size threshold configuration */
61 enum knav_dma_rx_thresholds {
62 	DMA_THRESH_NONE		= 0,
63 	DMA_THRESH_0		= 1,
64 	DMA_THRESH_0_1		= 3,
65 	DMA_THRESH_0_1_2	= 7
66 };
67 
68 /* Descriptor type */
69 enum knav_dma_desc_type {
70 	DMA_DESC_HOST = 0,
71 	DMA_DESC_MONOLITHIC = 2
72 };
73 
74 /**
75  * struct knav_dma_tx_cfg:	Tx channel configuration
76  * @filt_einfo:			Filter extended packet info
77  * @filt_pswords:		Filter PS words present
78  * @knav_dma_tx_priority:	Tx channel scheduling priority
79  */
80 struct knav_dma_tx_cfg {
81 	bool				filt_einfo;
82 	bool				filt_pswords;
83 	enum knav_dma_tx_priority	priority;
84 };
85 
86 /**
87  * struct knav_dma_rx_cfg:	Rx flow configuration
88  * @einfo_present:		Extended packet info present
89  * @psinfo_present:		PS words present
90  * @knav_dma_rx_err_mode:	Error during buffer starvation
91  * @knav_dma_desc_type:	Host or Monolithic desc
92  * @psinfo_at_sop:		PS word located at start of packet
93  * @sop_offset:			Start of packet offset
94  * @dst_q:			Destination queue for a given flow
95  * @thresh:			Rx flow size threshold
96  * @fdq[]:			Free desc Queue array
97  * @sz_thresh0:			RX packet size threshold 0
98  * @sz_thresh1:			RX packet size threshold 1
99  * @sz_thresh2:			RX packet size threshold 2
100  */
101 struct knav_dma_rx_cfg {
102 	bool				einfo_present;
103 	bool				psinfo_present;
104 	enum knav_dma_rx_err_mode	err_mode;
105 	enum knav_dma_desc_type		desc_type;
106 	bool				psinfo_at_sop;
107 	unsigned int			sop_offset;
108 	unsigned int			dst_q;
109 	enum knav_dma_rx_thresholds	thresh;
110 	unsigned int			fdq[KNAV_DMA_FDQ_PER_CHAN];
111 	unsigned int			sz_thresh0;
112 	unsigned int			sz_thresh1;
113 	unsigned int			sz_thresh2;
114 };
115 
116 /**
117  * struct knav_dma_cfg:	Pktdma channel configuration
118  * @sl_cfg:			Slave configuration
119  * @tx:				Tx channel configuration
120  * @rx:				Rx flow configuration
121  */
122 struct knav_dma_cfg {
123 	enum dma_transfer_direction direction;
124 	union {
125 		struct knav_dma_tx_cfg	tx;
126 		struct knav_dma_rx_cfg	rx;
127 	} u;
128 };
129 
130 /**
131  * struct knav_dma_desc:	Host packet descriptor layout
132  * @desc_info:			Descriptor information like id, type, length
133  * @tag_info:			Flow tag info written in during RX
134  * @packet_info:		Queue Manager, policy, flags etc
135  * @buff_len:			Buffer length in bytes
136  * @buff:			Buffer pointer
137  * @next_desc:			For chaining the descriptors
138  * @orig_len:			length since 'buff_len' can be overwritten
139  * @orig_buff:			buff pointer since 'buff' can be overwritten
140  * @epib:			Extended packet info block
141  * @psdata:			Protocol specific
142  * @sw_data:			Software private data not touched by h/w
143  */
144 struct knav_dma_desc {
145 	__le32	desc_info;
146 	__le32	tag_info;
147 	__le32	packet_info;
148 	__le32	buff_len;
149 	__le32	buff;
150 	__le32	next_desc;
151 	__le32	orig_len;
152 	__le32	orig_buff;
153 	__le32	epib[KNAV_DMA_NUM_EPIB_WORDS];
154 	__le32	psdata[KNAV_DMA_NUM_PS_WORDS];
155 	u32	sw_data[KNAV_DMA_NUM_SW_DATA_WORDS];
156 } ____cacheline_aligned;
157 
158 #if IS_ENABLED(CONFIG_KEYSTONE_NAVIGATOR_DMA)
159 void *knav_dma_open_channel(struct device *dev, const char *name,
160 				struct knav_dma_cfg *config);
161 void knav_dma_close_channel(void *channel);
162 int knav_dma_get_flow(void *channel);
163 bool knav_dma_device_ready(void);
164 #else
knav_dma_open_channel(struct device * dev,const char * name,struct knav_dma_cfg * config)165 static inline void *knav_dma_open_channel(struct device *dev, const char *name,
166 				struct knav_dma_cfg *config)
167 {
168 	return (void *) NULL;
169 }
knav_dma_close_channel(void * channel)170 static inline void knav_dma_close_channel(void *channel)
171 {}
172 
knav_dma_get_flow(void * channel)173 static inline int knav_dma_get_flow(void *channel)
174 {
175 	return -EINVAL;
176 }
177 
knav_dma_device_ready(void)178 static inline bool knav_dma_device_ready(void)
179 {
180 	return false;
181 }
182 
183 #endif
184 
185 #endif /* __SOC_TI_KEYSTONE_NAVIGATOR_DMA_H__ */
186