Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / drivers / staging / vt6656 / device.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4  * All rights reserved.
5  *
6  * File: device.h
7  *
8  * Purpose: MAC Data structure
9  *
10  * Author: Tevin Chen
11  *
12  * Date: Mar 17, 1997
13  *
14  */
15
16 #ifndef __DEVICE_H__
17 #define __DEVICE_H__
18
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/slab.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
24 #include <linux/firmware.h>
25 #include <linux/suspend.h>
26 #include <linux/if_arp.h>
27 #include <linux/wireless.h>
28 #include <linux/timer.h>
29 #include <linux/usb.h>
30 #include <linux/crc32.h>
31 #include <net/mac80211.h>
32
33 #ifdef SIOCETHTOOL
34 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
35 #include <linux/ethtool.h>
36 #else
37 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
38 #endif
39
40 #define RATE_1M         0
41 #define RATE_2M         1
42 #define RATE_5M         2
43 #define RATE_11M        3
44 #define RATE_6M         4
45 #define RATE_9M         5
46 #define RATE_12M        6
47 #define RATE_18M        7
48 #define RATE_24M        8
49 #define RATE_36M        9
50 #define RATE_48M        10
51 #define RATE_54M        11
52 #define RATE_AUTO       12
53
54 #define MAX_RATE                        12
55
56 /*
57  * device specific
58  */
59
60 #include "wcmd.h"
61 #include "desc.h"
62 #include "key.h"
63 #include "card.h"
64
65 #define VNT_USB_VENDOR_ID                     0x160a
66 #define VNT_USB_PRODUCT_ID                    0x3184
67
68 #define DEVICE_NAME                     "vt6656"
69 #define DEVICE_FULL_DRV_NAM             "VIA Networking Wireless LAN USB Driver"
70
71 #define DEVICE_VERSION                  "mac80211"
72
73 #define CONFIG_PATH                     "/etc/vntconfiguration.dat"
74
75 #define MAX_UINTS                       8
76 #define OPTION_DEFAULT                  { [0 ... MAX_UINTS - 1] = -1}
77
78 #define DUPLICATE_RX_CACHE_LENGTH       5
79
80 #define AUTO_FB_NONE            0
81 #define AUTO_FB_0               1
82 #define AUTO_FB_1               2
83
84 #define FB_RATE0                0
85 #define FB_RATE1                1
86
87 /* Antenna Mode */
88 #define ANT_A                   0
89 #define ANT_B                   1
90 #define ANT_DIVERSITY           2
91 #define ANT_RXD_TXA             3
92 #define ANT_RXD_TXB             4
93 #define ANT_UNKNOWN             0xFF
94 #define ANT_TXA                 0
95 #define ANT_TXB                 1
96 #define ANT_RXA                 2
97 #define ANT_RXB                 3
98
99 #define BB_VGA_LEVEL            4
100 #define BB_VGA_CHANGE_THRESHOLD 3
101
102 #define EEP_MAX_CONTEXT_SIZE    256
103
104 /* Contents in the EEPROM */
105 #define EEP_OFS_PAR             0x0
106 #define EEP_OFS_ANTENNA         0x17
107 #define EEP_OFS_RADIOCTL        0x18
108 #define EEP_OFS_RFTYPE          0x1b
109 #define EEP_OFS_MINCHANNEL      0x1c
110 #define EEP_OFS_MAXCHANNEL      0x1d
111 #define EEP_OFS_SIGNATURE       0x1e
112 #define EEP_OFS_ZONETYPE        0x1f
113 #define EEP_OFS_RFTABLE         0x20
114 #define EEP_OFS_PWR_CCK         0x20
115 #define EEP_OFS_SETPT_CCK       0x21
116 #define EEP_OFS_PWR_OFDMG       0x23
117
118 #define EEP_OFS_CALIB_TX_IQ     0x24
119 #define EEP_OFS_CALIB_TX_DC     0x25
120 #define EEP_OFS_CALIB_RX_IQ     0x26
121
122 #define EEP_OFS_MAJOR_VER       0x2e
123 #define EEP_OFS_MINOR_VER       0x2f
124
125 #define EEP_OFS_CCK_PWR_TBL     0x30
126 #define EEP_OFS_OFDM_PWR_TBL    0x40
127 #define EEP_OFS_OFDMA_PWR_TBL   0x50
128
129 /* Bits in EEP_OFS_ANTENNA */
130 #define EEP_ANTENNA_MAIN        0x1
131 #define EEP_ANTENNA_AUX         0x2
132 #define EEP_ANTINV              0x4
133
134 /* Bits in EEP_OFS_RADIOCTL */
135 #define EEP_RADIOCTL_ENABLE     0x80
136
137 /* control commands */
138 #define MESSAGE_TYPE_READ               0x1
139 #define MESSAGE_TYPE_WRITE              0x0
140 #define MESSAGE_TYPE_LOCK_OR            0x2
141 #define MESSAGE_TYPE_LOCK_AND           0x3
142 #define MESSAGE_TYPE_WRITE_MASK         0x4
143 #define MESSAGE_TYPE_CARDINIT           0x5
144 #define MESSAGE_TYPE_INIT_RSP           0x6
145 #define MESSAGE_TYPE_MACSHUTDOWN        0x7
146 #define MESSAGE_TYPE_SETKEY             0x8
147 #define MESSAGE_TYPE_CLRKEYENTRY        0x9
148 #define MESSAGE_TYPE_WRITE_MISCFF       0xa
149 #define MESSAGE_TYPE_SET_ANTMD          0xb
150 #define MESSAGE_TYPE_SELECT_CHANNEL     0xc
151 #define MESSAGE_TYPE_SET_TSFTBTT        0xd
152 #define MESSAGE_TYPE_SET_SSTIFS         0xe
153 #define MESSAGE_TYPE_CHANGE_BBTYPE      0xf
154 #define MESSAGE_TYPE_DISABLE_PS         0x10
155 #define MESSAGE_TYPE_WRITE_IFRF         0x11
156
157 /* command read/write(index) */
158 #define MESSAGE_REQUEST_MEM             0x1
159 #define MESSAGE_REQUEST_BBREG           0x2
160 #define MESSAGE_REQUEST_MACREG          0x3
161 #define MESSAGE_REQUEST_EEPROM          0x4
162 #define MESSAGE_REQUEST_TSF             0x5
163 #define MESSAGE_REQUEST_TBTT            0x6
164 #define MESSAGE_REQUEST_BBAGC           0x7
165 #define MESSAGE_REQUEST_VERSION         0x8
166 #define MESSAGE_REQUEST_RF_INIT         0x9
167 #define MESSAGE_REQUEST_RF_INIT2        0xa
168 #define MESSAGE_REQUEST_RF_CH0          0xb
169 #define MESSAGE_REQUEST_RF_CH1          0xc
170 #define MESSAGE_REQUEST_RF_CH2          0xd
171
172 /* USB registers */
173 #define USB_REG4                        0x604
174
175 #define DEVICE_INIT_COLD        0x0 /* cold init */
176 #define DEVICE_INIT_RESET       0x1 /* reset init or Dx to D0 power remain */
177 #define DEVICE_INIT_DXPL        0x2 /* Dx to D0 power lost init */
178
179 /* Device init */
180 struct vnt_cmd_card_init {
181         u8 init_class;
182         u8 exist_sw_net_addr;
183         u8 sw_net_addr[6];
184         u8 short_retry_limit;
185         u8 long_retry_limit;
186 };
187
188 struct vnt_rsp_card_init {
189         u8 status;
190         u8 net_addr[6];
191         u8 rf_type;
192         u8 min_channel;
193         u8 max_channel;
194 };
195
196 /* USB */
197
198 /*
199  * Enum of context types for SendPacket
200  */
201 enum {
202         CONTEXT_DATA_PACKET = 1,
203         CONTEXT_MGMT_PACKET,
204         CONTEXT_BEACON_PACKET
205 };
206
207 /* RCB (Receive Control Block) */
208 struct vnt_rcb {
209         void *priv;
210         struct urb *urb;
211         struct sk_buff *skb;
212         int in_use;
213 };
214
215 /* used to track bulk out irps */
216 struct vnt_usb_send_context {
217         void *priv;
218         struct sk_buff *skb;
219         struct urb *urb;
220         struct ieee80211_hdr *hdr;
221         unsigned int buf_len;
222         u32 frame_len;
223         u16 tx_hdr_size;
224         u16 tx_rate;
225         u8 type;
226         u8 pkt_no;
227         u8 pkt_type;
228         u8 need_ack;
229         u8 fb_option;
230         bool in_use;
231         unsigned char data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
232 };
233
234 /*
235  * Structure to keep track of USB interrupt packets
236  */
237 struct vnt_interrupt_buffer {
238         u8 *data_buf;
239         bool in_use;
240 };
241
242 /*++ NDIS related */
243
244 enum {
245         STATUS_SUCCESS = 0,
246         STATUS_FAILURE,
247         STATUS_RESOURCES,
248         STATUS_PENDING,
249 };
250
251 /* flags for options */
252 #define DEVICE_FLAGS_UNPLUG             0
253 #define DEVICE_FLAGS_DISCONNECTED       1
254
255 struct vnt_private {
256         /* mac80211 */
257         struct ieee80211_hw *hw;
258         struct ieee80211_vif *vif;
259         u8 mac_hw;
260         /* netdev */
261         struct usb_device *usb;
262
263         u64 tsf_time;
264         u8 rx_rate;
265
266         u32 rx_buf_sz;
267         int mc_list_count;
268
269         spinlock_t lock;
270         struct mutex usb_lock;
271
272         unsigned long flags;
273
274         /* USB */
275         struct urb *interrupt_urb;
276         u32 int_interval;
277
278         /* Variables to track resources for the BULK In Pipe */
279         struct vnt_rcb *rcb[CB_MAX_RX_DESC];
280         u32 num_rcb;
281
282         /* Variables to track resources for the BULK Out Pipe */
283         struct vnt_usb_send_context *tx_context[CB_MAX_TX_DESC];
284         u32 num_tx_context;
285
286         /* Variables to track resources for the Interrupt In Pipe */
287         struct vnt_interrupt_buffer int_buf;
288
289         /* Version control */
290         u16 firmware_version;
291         u8 local_id;
292         u8 rf_type;
293         u8 bb_rx_conf;
294
295         struct vnt_cmd_card_init init_command;
296         struct vnt_rsp_card_init init_response;
297         u8 current_net_addr[ETH_ALEN] __aligned(2);
298         u8 permanent_net_addr[ETH_ALEN] __aligned(2);
299
300         u8 exist_sw_net_addr;
301
302         u64 current_tsf;
303
304         /* 802.11 MAC specific */
305         u32 current_rssi;
306
307         /* Antenna Diversity */
308         int tx_rx_ant_inv;
309         u32 rx_antenna_sel;
310         u8 rx_antenna_mode;
311         u8 tx_antenna_mode;
312         u8 radio_ctl;
313
314         /* IFS & Cw */
315         u32 sifs;  /* Current SIFS */
316         u32 difs;  /* Current DIFS */
317         u32 eifs;  /* Current EIFS */
318         u32 slot;  /* Current SlotTime */
319
320         /* Rate */
321         u8 bb_type; /* 0: 11A, 1:11B, 2:11G */
322         u8 packet_type; /* 0:11a 1:11b 2:11gb 3:11ga */
323         u32 basic_rates;
324         u8 top_ofdm_basic_rate;
325         u8 top_cck_basic_rate;
326
327         u8 eeprom[EEP_MAX_CONTEXT_SIZE];  /*u32 alignment */
328
329         u8 preamble_type;
330
331         /* For RF Power table */
332         u8 cck_pwr;
333         u8 ofdm_pwr_g;
334         u8 ofdm_pwr_a;
335         u8 power;
336         u8 cck_pwr_tbl[14];
337         u8 ofdm_pwr_tbl[14];
338         u8 ofdm_a_pwr_tbl[42];
339
340         u16 current_rate;
341         u16 tx_rate_fb0;
342         u16 tx_rate_fb1;
343
344         u8 short_retry_limit;
345         u8 long_retry_limit;
346
347         enum nl80211_iftype op_mode;
348
349         int short_slot_time;
350
351         /* Power save */
352         u16 current_aid;
353
354         /* Beacon related */
355         u16 seq_counter;
356
357         enum vnt_cmd_state command_state;
358
359         enum vnt_cmd command;
360
361         /* 802.11 counter */
362
363         enum vnt_cmd cmd_queue[CMD_Q_SIZE];
364         u32 cmd_dequeue_idx;
365         u32 cmd_enqueue_idx;
366         u32 free_cmd_queue;
367         int cmd_running;
368
369         unsigned long key_entry_inuse;
370
371         u8 auto_fb_ctrl;
372
373         /* For Update BaseBand VGA Gain Offset */
374         u8 bb_vga[BB_VGA_LEVEL];
375
376         u8 bb_pre_ed_rssi;
377         u8 bb_pre_ed_index;
378
379         u16 wake_up_count;
380
381         /* command timer */
382         struct delayed_work run_command_work;
383
384         struct ieee80211_low_level_stats low_stats;
385 };
386
387 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) {       \
388         if ((uVar) >= ((uModulo) - 1))                  \
389                 (uVar) = 0;                             \
390         else                                            \
391                 (uVar)++;                               \
392 }
393
394 int vnt_init(struct vnt_private *priv);
395
396 #endif