xref: /openwifi/driver/sdr.h (revision 14124d7306727ee7bbae83655e3d9ecacc4c3bee)
1 // Xianjun jiao. [email protected]; [email protected]
2 
3 #ifndef OPENWIFI_SDR
4 #define OPENWIFI_SDR
5 
6 // -------------------for leds--------------------------------
7 struct gpio_led_data { //pleas always align with the leds-gpio.c in linux kernel
8 	struct led_classdev cdev;
9 	struct gpio_desc *gpiod;
10 	u8 can_sleep;
11 	u8 blinking;
12 	gpio_blink_set_t platform_gpio_blink_set;
13 };
14 
15 struct gpio_leds_priv { //pleas always align with the leds-gpio.c in linux kernel
16 	int num_leds;
17 	struct gpio_led_data leds[];
18 };
19 
20 struct openwifi_rf_ops {
21 	char *name;
22 //	void (*init)(struct ieee80211_hw *);
23 //	void (*stop)(struct ieee80211_hw *);
24 	void (*set_chan)(struct ieee80211_hw *, struct ieee80211_conf *);
25 //	u8 (*calc_rssi)(u8 agc, u8 sq);
26 };
27 
28 struct openwifi_buffer_descriptor {
29 	u32 num_dma_byte;
30     u32 sn;
31     u32 hw_queue_idx;
32     u32 retry_limit;
33     u32 need_ack;
34     struct sk_buff *skb_linked;
35     dma_addr_t dma_mapping_addr;
36     u32 reserved;
37 } __packed;
38 
39 struct openwifi_ring {
40 	struct openwifi_buffer_descriptor *bds;
41     u32 bd_wr_idx;
42 	u32 bd_rd_idx;
43     u32 reserved;
44 } __packed;
45 
46 struct openwifi_vif {
47 	struct ieee80211_hw *dev;
48 
49 	int idx; // this vif's idx on the dev
50 
51 	/* beaconing */
52 	struct delayed_work beacon_work;
53 	bool enable_beacon;
54 };
55 
56 union u32_byte4 {
57 	u32 a;
58 	u8 c[4];
59 };
60 union u16_byte2 {
61 	u16 a;
62 	u8 c[2];
63 };
64 
65 #define MAX_NUM_DRV_REG 32
66 #define MAX_NUM_LED 4
67 #define OPENWIFI_LED_MAX_NAME_LEN 32
68 
69 #define MAX_NUM_VIF 4
70 
71 #define LEN_PHY_HEADER 16
72 #define LEN_PHY_CRC 4
73 
74 #define NUM_TX_BD 32
75 #define NUM_RX_BD 16
76 #define TX_BD_BUF_SIZE (8192)
77 #define RX_BD_BUF_SIZE (8192)
78 
79 #define NUM_BIT_MAX_NUM_HW_QUEUE 2
80 #define MAX_NUM_HW_QUEUE 2
81 #define NUM_BIT_MAX_PHY_TX_SN 12
82 #define MAX_PHY_TX_SN ((1<<NUM_BIT_MAX_PHY_TX_SN)-1)
83 
84 #define AD9361_RADIO_OFF_TX_ATT 89750 //please align with ad9361.c
85 #define AD9361_RADIO_ON_TX_ATT 000    //please align with rf_init.sh
86 
87 #define SDR_SUPPORTED_FILTERS	\
88 	(FIF_ALLMULTI |				\
89 	FIF_BCN_PRBRESP_PROMISC |	\
90 	FIF_CONTROL |				\
91 	FIF_OTHER_BSS |				\
92 	FIF_PSPOLL |				\
93 	FIF_PROBE_REQ)
94 
95 #define HIGH_PRIORITY_DISCARD_FLAG ((~0x040)<<16) // don't force drop OTHER_BSS by high priority discard
96 //#define HIGH_PRIORITY_DISCARD_FLAG ((~0x140)<<16) // don't force drop OTHER_BSS and PROB_REQ by high priority discard
97 
98 /* 5G chan 36 - chan 64*/
99 #define SDR_5GHZ_CH36_64	\
100 	REG_RULE(5150-10, 5350+10, 80, 0, 20, 0)
101 /* 5G chan 36 - chan 48*/
102 #define SDR_5GHZ_CH36_48	\
103 	REG_RULE(5150-10, 5270+10, 80, 0, 20, 0)
104 
105 /*
106  *Only these channels all allow active
107  *scan on all world regulatory domains
108  */
109 #define SDR_2GHZ_CH01_13	REG_RULE(2412-10, 2472+10, 40, 0, 20, NL80211_RRF_NO_CCK) // disable 11b
110 #define SDR_2GHZ_CH01_14	REG_RULE(2412-10, 2484+10, 40, 0, 20, NL80211_RRF_NO_CCK) // disable 11b
111 
112 // regulatory.h alpha2
113 //  *	00 - World regulatory domain
114 //  *	99 - built by driver but a specific alpha2 cannot be determined
115 //  *	98 - result of an intersection between two regulatory domains
116 //  *	97 - regulatory domain has not yet been configured
117 static const struct ieee80211_regdomain sdr_regd = { // for wiphy_apply_custom_regulatory
118 	.n_reg_rules = 2,
119 	.alpha2 = "99",
120 	.dfs_region = NL80211_DFS_ETSI,
121 	.reg_rules = {
122 		//SDR_2GHZ_CH01_13,
123 		//SDR_5GHZ_CH36_48, //Avoid radar!
124 		SDR_2GHZ_CH01_14,
125 		SDR_5GHZ_CH36_64,
126 		}
127 };
128 
129 #define CHAN2G(_channel, _freq, _flags) { \
130 	.band			= NL80211_BAND_2GHZ, \
131 	.hw_value		= (_channel), \
132 	.center_freq		= (_freq), \
133 	.flags			= (_flags), \
134 	.max_antenna_gain	= 0, \
135 	.max_power		= 0, \
136 }
137 
138 #define CHAN5G(_channel, _freq, _flags) { \
139 	.band			= NL80211_BAND_5GHZ, \
140 	.hw_value		= (_channel), \
141 	.center_freq		= (_freq), \
142 	.flags			= (_flags), \
143 	.max_antenna_gain	= 0, \
144 	.max_power		= 0, \
145 }
146 
147 static const struct ieee80211_rate openwifi_5GHz_rates[] = {
148 	{ .bitrate = 10,  .hw_value = 0,  .flags = 0},
149 	{ .bitrate = 20,  .hw_value = 1,  .flags = 0},
150 	{ .bitrate = 55,  .hw_value = 2,  .flags = 0},
151 	{ .bitrate = 110, .hw_value = 3,  .flags = 0},
152 	{ .bitrate = 60,  .hw_value = 4,  .flags = IEEE80211_RATE_MANDATORY_A},
153 	{ .bitrate = 90,  .hw_value = 5,  .flags = IEEE80211_RATE_MANDATORY_A},
154 	{ .bitrate = 120, .hw_value = 6,  .flags = IEEE80211_RATE_MANDATORY_A},
155 	{ .bitrate = 180, .hw_value = 7,  .flags = IEEE80211_RATE_MANDATORY_A},
156 	{ .bitrate = 240, .hw_value = 8,  .flags = IEEE80211_RATE_MANDATORY_A},
157 	{ .bitrate = 360, .hw_value = 9,  .flags = IEEE80211_RATE_MANDATORY_A},
158 	{ .bitrate = 480, .hw_value = 10, .flags = IEEE80211_RATE_MANDATORY_A},
159 	{ .bitrate = 540, .hw_value = 11, .flags = IEEE80211_RATE_MANDATORY_A},
160 };
161 
162 static const struct ieee80211_rate openwifi_2GHz_rates[] = {
163 	{ .bitrate = 10,  .hw_value = 0,  .flags = 0},
164 	{ .bitrate = 20,  .hw_value = 1,  .flags = 0},
165 	{ .bitrate = 55,  .hw_value = 2,  .flags = 0},
166 	{ .bitrate = 110, .hw_value = 3,  .flags = 0},
167 	{ .bitrate = 60,  .hw_value = 4,  .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G},
168 	{ .bitrate = 90,  .hw_value = 5,  .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G},
169 	{ .bitrate = 120, .hw_value = 6,  .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G},
170 	{ .bitrate = 180, .hw_value = 7,  .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G},
171 	{ .bitrate = 240, .hw_value = 8,  .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G},
172 	{ .bitrate = 360, .hw_value = 9,  .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G},
173 	{ .bitrate = 480, .hw_value = 10, .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G},
174 	{ .bitrate = 540, .hw_value = 11, .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G},
175 };
176 
177 static const struct ieee80211_channel openwifi_2GHz_channels[] = {
178 	CHAN2G(1, 2412, 0),
179 	CHAN2G(2, 2417, 0),
180 	CHAN2G(3, 2422, 0),
181 	CHAN2G(4, 2427, 0),
182 	CHAN2G(5, 2432, 0),
183 	CHAN2G(6, 2437, 0),
184 	CHAN2G(7, 2442, 0),
185 	CHAN2G(8, 2447, 0),
186 	CHAN2G(9, 2452, 0),
187 	CHAN2G(10, 2457, 0),
188 	CHAN2G(11, 2462, 0),
189 	CHAN2G(12, 2467, 0),
190 	CHAN2G(13, 2472, 0),
191 	CHAN2G(14, 2484, 0),
192 };
193 
194 static const struct ieee80211_channel openwifi_5GHz_channels[] = {
195 	CHAN5G(36, 5180, 0),
196 	CHAN5G(38, 5190, 0),
197 	CHAN5G(40, 5200, 0),
198 	CHAN5G(42, 5210, 0),
199 	CHAN5G(44, 5220, 0),
200 	CHAN5G(46, 5230, 0),
201 	CHAN5G(48, 5240, 0),
202 	CHAN5G(52, 5260, IEEE80211_CHAN_RADAR),
203 	CHAN5G(56, 5280, IEEE80211_CHAN_RADAR),
204 	CHAN5G(60, 5300, IEEE80211_CHAN_RADAR),
205 	CHAN5G(64, 5320, IEEE80211_CHAN_RADAR),
206 	// CHAN5G(100, 5500, 0),
207 	// CHAN5G(104, 5520, 0),
208 	// CHAN5G(108, 5540, 0),
209 	// CHAN5G(112, 5560, 0),
210 	// CHAN5G(116, 5580, 0),
211 	// CHAN5G(120, 5600, 0),
212 	// CHAN5G(124, 5620, 0),
213 	// CHAN5G(128, 5640, 0),
214 	// CHAN5G(132, 5660, 0),
215 	// CHAN5G(136, 5680, 0),
216 	// CHAN5G(140, 5700, 0),
217 	// CHAN5G(144, 5720, 0),
218 	// CHAN5G(149, 5745, 0),
219 	// CHAN5G(153, 5765, 0),
220 	// CHAN5G(157, 5785, 0),
221 	// CHAN5G(161, 5805, 0),
222 	// CHAN5G(165, 5825, 0),
223 	// CHAN5G(169, 5845, 0),
224 };
225 
226 static const struct ieee80211_iface_limit openwifi_if_limits[] = {
227 	{ .max = 2048,	.types = BIT(NL80211_IFTYPE_STATION) },
228 	{ .max = 4,	.types =
229 #ifdef CONFIG_MAC80211_MESH
230 				 BIT(NL80211_IFTYPE_MESH_POINT) |
231 #endif
232 				 BIT(NL80211_IFTYPE_AP) },
233 };
234 
235 static const struct ieee80211_iface_combination openwifi_if_comb = {
236 	.limits = openwifi_if_limits,
237 	.n_limits = ARRAY_SIZE(openwifi_if_limits),
238 	.max_interfaces = 2048,
239 	.num_different_channels = 1,
240 	.radar_detect_widths =	BIT(NL80211_CHAN_WIDTH_20_NOHT) |
241 					BIT(NL80211_CHAN_WIDTH_20) |
242 					BIT(NL80211_CHAN_WIDTH_40) |
243 					BIT(NL80211_CHAN_WIDTH_80),
244 };
245 
246 static const u8  wifi_rate_table_mapping[16] =     { 0,  0,  0,  0,  0,  0,  0,  0, 10,   8,   6,   4, 11,  9,  7, 5};
247 static const u8  wifi_rate_table[16] =             { 0,  0,  0,  0,  0,  0,  0,  0, 48,  24,  12,   6, 54, 36, 18, 9};
248 static const u8  wifi_rate_all[16] =               { 1,  2,  5, 11,  6,  9, 12, 18, 24,  36,  48,  54,  0,  0,  0, 0};
249 static const u8  wifi_mcs_table_11b_force_up[16] = {11, 11, 11, 11, 11, 15, 10, 14,  9,  13,   8,  12,  0,  0,  0, 0};
250 static const u16 wifi_n_dbps_table[16] =           {24, 24, 24, 24, 24, 36, 48, 72, 96, 144, 192, 216,  0,  0,  0, 0};
251 // static const u8 wifi_mcs_table[8] =             {6,9,12,18,24,36,48,54};
252 // static const u8 wifi_mcs_table_phy_tx[8]    =   {11,15,10,14,9,13,8,12};
253 
254 #define RX_DMA_CYCLIC_MODE
255 struct openwifi_priv {
256 	struct platform_device *pdev;
257 	struct ieee80211_vif *vif[MAX_NUM_VIF];
258 
259 	const struct openwifi_rf_ops *rf;
260 
261 	struct cf_axi_dds_state *dds_st;  //axi_ad9361 hdl ref design module, dac channel
262 	struct axiadc_state *adc_st;      //axi_ad9361 hdl ref design module, adc channel
263 	struct ad9361_rf_phy *ad9361_phy; //ad9361 chip
264 	struct ctrl_outs_control ctrl_out;
265 
266 	int rx_freq_offset_to_lo_MHz;
267 	int tx_freq_offset_to_lo_MHz;
268 	u32 rf_bw;
269 	u32 actual_rx_lo;
270 
271 	struct ieee80211_rate rates_2GHz[12];
272 	struct ieee80211_rate rates_5GHz[12];
273 	struct ieee80211_channel channels_2GHz[14];
274 	struct ieee80211_channel channels_5GHz[11];
275 	struct ieee80211_supported_band band_2GHz;
276 	struct ieee80211_supported_band band_5GHz;
277 	bool rfkill_off;
278 
279 	int rssi_correction; // dynamic RSSI correction according to current channel in _rf_set_channel()
280 
281 	enum rx_intf_mode rx_intf_cfg;
282 	enum tx_intf_mode tx_intf_cfg;
283 	enum openofdm_rx_mode openofdm_rx_cfg;
284 	enum openofdm_tx_mode openofdm_tx_cfg;
285 	enum xpu_mode xpu_cfg;
286 
287 	int irq_rx;
288 	int irq_tx;
289 
290 	u8 *rx_cyclic_buf;
291 	dma_addr_t rx_cyclic_buf_dma_mapping_addr;
292 	struct dma_chan *rx_chan;
293 	struct dma_async_tx_descriptor *rxd;
294 	dma_cookie_t rx_cookie;
295 
296 	struct openwifi_ring tx_ring;
297 	struct scatterlist tx_sg;
298 	struct dma_chan *tx_chan;
299 	struct dma_async_tx_descriptor *txd;
300 	dma_cookie_t tx_cookie;
301 	bool tx_queue_stopped;
302 
303 	int phy_tx_sn;
304 	u32 dest_mac_addr_queue_map[MAX_NUM_HW_QUEUE];
305 	u8 mac_addr[ETH_ALEN];
306 	u16 seqno;
307 
308 	bool use_short_slot;
309 	u8 band;
310 	u16 channel;
311 
312 	u32 drv_rx_reg_val[MAX_NUM_DRV_REG];
313 	u32 drv_tx_reg_val[MAX_NUM_DRV_REG];
314 	u32 drv_xpu_reg_val[MAX_NUM_DRV_REG];
315 	// u8 num_led;
316 	// struct led_classdev *led[MAX_NUM_LED];//zc706 has 4 user leds. please find openwifi_dev_probe to see how we get them.
317 	// char led_name[MAX_NUM_LED][OPENWIFI_LED_MAX_NAME_LEN];
318 
319 	spinlock_t lock;
320 };
321 
322 #endif /* OPENWIFI_SDR */
323