GNU Linux-libre 5.19-rc6-gnu
[releases.git] / drivers / net / wireless / intersil / p54 / p54.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Shared defines for all mac80211 Prism54 code
4  *
5  * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
6  *
7  * Based on the islsm (softmac prism54) driver, which is:
8  * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
9  */
10
11 #ifndef P54_H
12 #define P54_H
13
14 #ifdef CONFIG_P54_LEDS
15 #include <linux/leds.h>
16 #endif /* CONFIG_P54_LEDS */
17
18 #define ISL38XX_DEV_FIRMWARE_ADDR 0x20000
19
20 #define BR_CODE_MIN                     0x80000000
21 #define BR_CODE_COMPONENT_ID            0x80000001
22 #define BR_CODE_COMPONENT_VERSION       0x80000002
23 #define BR_CODE_DEPENDENT_IF            0x80000003
24 #define BR_CODE_EXPOSED_IF              0x80000004
25 #define BR_CODE_DESCR                   0x80000101
26 #define BR_CODE_MAX                     0x8FFFFFFF
27 #define BR_CODE_END_OF_BRA              0xFF0000FF
28 #define LEGACY_BR_CODE_END_OF_BRA       0xFFFFFFFF
29
30 struct bootrec {
31         __le32 code;
32         __le32 len;
33         u32 data[10];
34 } __packed;
35
36 /* Interface role definitions */
37 #define BR_INTERFACE_ROLE_SERVER        0x0000
38 #define BR_INTERFACE_ROLE_CLIENT        0x8000
39
40 #define BR_DESC_PRIV_CAP_WEP            BIT(0)
41 #define BR_DESC_PRIV_CAP_TKIP           BIT(1)
42 #define BR_DESC_PRIV_CAP_MICHAEL        BIT(2)
43 #define BR_DESC_PRIV_CAP_CCX_CP         BIT(3)
44 #define BR_DESC_PRIV_CAP_CCX_MIC        BIT(4)
45 #define BR_DESC_PRIV_CAP_AESCCMP        BIT(5)
46
47 struct bootrec_desc {
48         __le16 modes;
49         __le16 flags;
50         __le32 rx_start;
51         __le32 rx_end;
52         u8 headroom;
53         u8 tailroom;
54         u8 tx_queues;
55         u8 tx_depth;
56         u8 privacy_caps;
57         u8 rx_keycache_size;
58         u8 time_size;
59         u8 padding;
60         u8 rates[16];
61         u8 padding2[4];
62         __le16 rx_mtu;
63 } __packed;
64
65 #define FW_FMAC 0x464d4143
66 #define FW_LM86 0x4c4d3836
67 #define FW_LM87 0x4c4d3837
68 #define FW_LM20 0x4c4d3230
69
70 struct bootrec_comp_id {
71         __le32 fw_variant;
72 } __packed;
73
74 struct bootrec_comp_ver {
75         char fw_version[24];
76 } __packed;
77
78 struct bootrec_end {
79         __le16 crc;
80         u8 padding[2];
81         u8 md5[16];
82 } __packed;
83
84 /* provide 16 bytes for the transport back-end */
85 #define P54_TX_INFO_DATA_SIZE           16
86
87 /* stored in ieee80211_tx_info's rate_driver_data */
88 struct p54_tx_info {
89         u32 start_addr;
90         u32 end_addr;
91         union {
92                 void *data[P54_TX_INFO_DATA_SIZE / sizeof(void *)];
93                 struct {
94                         u32 extra_len;
95                 };
96         };
97 };
98
99 #define P54_MAX_CTRL_FRAME_LEN          0x1000
100
101 #define P54_SET_QUEUE(queue, ai_fs, cw_min, cw_max, _txop)      \
102 do {                                                            \
103         queue.aifs = cpu_to_le16(ai_fs);                        \
104         queue.cwmin = cpu_to_le16(cw_min);                      \
105         queue.cwmax = cpu_to_le16(cw_max);                      \
106         queue.txop = cpu_to_le16(_txop);                        \
107 } while (0)
108
109 struct p54_edcf_queue_param {
110         __le16 aifs;
111         __le16 cwmin;
112         __le16 cwmax;
113         __le16 txop;
114 } __packed;
115
116 struct p54_rssi_db_entry {
117         u16 freq;
118         s16 mul;
119         s16 add;
120         s16 longbow_unkn;
121         s16 longbow_unk2;
122 };
123
124 struct p54_cal_database {
125         size_t entries;
126         size_t entry_size;
127         size_t offset;
128         size_t len;
129         u8 data[];
130 };
131
132 #define EEPROM_READBACK_LEN 0x3fc
133
134 enum fw_state {
135         FW_STATE_OFF,
136         FW_STATE_BOOTING,
137         FW_STATE_READY,
138         FW_STATE_RESET,
139         FW_STATE_RESETTING,
140 };
141
142 #ifdef CONFIG_P54_LEDS
143
144 #define P54_LED_MAX_NAME_LEN 31
145
146 struct p54_led_dev {
147         struct ieee80211_hw *hw_dev;
148         struct led_classdev led_dev;
149         char name[P54_LED_MAX_NAME_LEN + 1];
150
151         unsigned int toggled;
152         unsigned int index;
153         unsigned int registered;
154 };
155
156 #endif /* CONFIG_P54_LEDS */
157
158 struct p54_tx_queue_stats {
159         unsigned int len;
160         unsigned int limit;
161         unsigned int count;
162 };
163
164 struct p54_common {
165         struct ieee80211_hw *hw;
166         struct ieee80211_vif *vif;
167         void (*tx)(struct ieee80211_hw *dev, struct sk_buff *skb);
168         int (*open)(struct ieee80211_hw *dev);
169         void (*stop)(struct ieee80211_hw *dev);
170         struct sk_buff_head tx_pending;
171         struct sk_buff_head tx_queue;
172         struct mutex conf_mutex;
173         bool registered;
174
175         /* memory management (as seen by the firmware) */
176         u32 rx_start;
177         u32 rx_end;
178         u16 rx_mtu;
179         u8 headroom;
180         u8 tailroom;
181
182         /* firmware/hardware info */
183         unsigned int tx_hdr_len;
184         unsigned int fw_var;
185         unsigned int fw_interface;
186         u8 version;
187
188         /* (e)DCF / QOS state */
189         bool use_short_slot;
190         spinlock_t tx_stats_lock;
191         struct p54_tx_queue_stats tx_stats[8];
192         struct p54_edcf_queue_param qos_params[8];
193
194         /* Radio data */
195         u16 rxhw;
196         u8 rx_diversity_mask;
197         u8 tx_diversity_mask;
198         unsigned int output_power;
199         struct p54_rssi_db_entry *cur_rssi;
200         struct ieee80211_channel *curchan;
201         struct survey_info *survey;
202         unsigned int chan_num;
203         struct completion stat_comp;
204         bool update_stats;
205         struct {
206                 unsigned int timestamp;
207                 unsigned int cached_cca;
208                 unsigned int cached_tx;
209                 unsigned int cached_rssi;
210                 u64 active;
211                 u64 cca;
212                 u64 tx;
213                 u64 rssi;
214         } survey_raw;
215
216         int noise;
217         /* calibration, output power limit and rssi<->dBm conversation data */
218         struct pda_iq_autocal_entry *iq_autocal;
219         unsigned int iq_autocal_len;
220         struct p54_cal_database *curve_data;
221         struct p54_cal_database *output_limit;
222         struct p54_cal_database *rssi_db;
223         struct ieee80211_supported_band *band_table[NUM_NL80211_BANDS];
224
225         /* BBP/MAC state */
226         u8 mac_addr[ETH_ALEN];
227         u8 bssid[ETH_ALEN];
228         u8 mc_maclist[4][ETH_ALEN];
229         u16 wakeup_timer;
230         unsigned int filter_flags;
231         int mc_maclist_num;
232         int mode;
233         u32 tsf_low32, tsf_high32;
234         u32 basic_rate_mask;
235         u16 aid;
236         u8 coverage_class;
237         bool phy_idle;
238         bool phy_ps;
239         bool powersave_override;
240         __le32 beacon_req_id;
241         struct completion beacon_comp;
242
243         /* cryptographic engine information */
244         u8 privacy_caps;
245         u8 rx_keycache_size;
246         unsigned long *used_rxkeys;
247
248         /* LED management */
249 #ifdef CONFIG_P54_LEDS
250         struct p54_led_dev leds[4];
251         struct delayed_work led_work;
252 #endif /* CONFIG_P54_LEDS */
253         u16 softled_state;              /* bit field of glowing LEDs */
254
255         /* statistics */
256         struct ieee80211_low_level_stats stats;
257         struct delayed_work work;
258
259         /* eeprom handling */
260         void *eeprom;
261         struct completion eeprom_comp;
262         struct mutex eeprom_mutex;
263 };
264
265 /* interfaces for the drivers */
266 int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb);
267 void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb);
268 int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw);
269 int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len);
270 int p54_read_eeprom(struct ieee80211_hw *dev);
271
272 struct ieee80211_hw *p54_init_common(size_t priv_data_len);
273 int p54_register_common(struct ieee80211_hw *dev, struct device *pdev);
274 void p54_free_common(struct ieee80211_hw *dev);
275
276 void p54_unregister_common(struct ieee80211_hw *dev);
277
278 #endif /* P54_H */