1
2
3
4
5
6
7
8
9
10
11#include <linux/spinlock.h>
12#include <linux/device.h>
13#include <linux/kthread.h>
14#include <net/mac80211.h>
15
16#include "deb_defs.h"
17
18#ifndef DRV_NAME
19#define DRV_NAME "libertas_tf"
20#endif
21
22#define MRVL_DEFAULT_RETRIES 9
23#define MRVL_PER_PACKET_RATE 0x10
24#define MRVL_MAX_BCN_SIZE 440
25#define CMD_OPTION_WAITFORRSP 0x0002
26
27
28
29
30#define CMD_RET(cmd) (0x8000 | cmd)
31
32
33#define CMD_GET_HW_SPEC 0x0003
34#define CMD_802_11_RESET 0x0005
35#define CMD_MAC_MULTICAST_ADR 0x0010
36#define CMD_802_11_RADIO_CONTROL 0x001c
37#define CMD_802_11_RF_CHANNEL 0x001d
38#define CMD_802_11_RF_TX_POWER 0x001e
39#define CMD_MAC_CONTROL 0x0028
40#define CMD_802_11_MAC_ADDRESS 0x004d
41#define CMD_SET_BOOT2_VER 0x00a5
42#define CMD_802_11_BEACON_CTRL 0x00b0
43#define CMD_802_11_BEACON_SET 0x00cb
44#define CMD_802_11_SET_MODE 0x00cc
45#define CMD_802_11_SET_BSSID 0x00cd
46
47#define CMD_ACT_GET 0x0000
48#define CMD_ACT_SET 0x0001
49
50
51#define CMD_ACT_HALT 0x0003
52
53
54#define CMD_ACT_MAC_RX_ON 0x0001
55#define CMD_ACT_MAC_TX_ON 0x0002
56#define CMD_ACT_MAC_MULTICAST_ENABLE 0x0020
57#define CMD_ACT_MAC_BROADCAST_ENABLE 0x0040
58#define CMD_ACT_MAC_PROMISCUOUS_ENABLE 0x0080
59#define CMD_ACT_MAC_ALL_MULTICAST_ENABLE 0x0100
60
61
62#define CMD_TYPE_AUTO_PREAMBLE 0x0001
63#define CMD_TYPE_SHORT_PREAMBLE 0x0002
64#define CMD_TYPE_LONG_PREAMBLE 0x0003
65
66#define TURN_ON_RF 0x01
67#define RADIO_ON 0x01
68#define RADIO_OFF 0x00
69
70#define SET_AUTO_PREAMBLE 0x05
71#define SET_SHORT_PREAMBLE 0x03
72#define SET_LONG_PREAMBLE 0x01
73
74
75#define CMD_OPT_802_11_RF_CHANNEL_GET 0x00
76#define CMD_OPT_802_11_RF_CHANNEL_SET 0x01
77
78
79enum lbtf_mode {
80 LBTF_PASSIVE_MODE,
81 LBTF_STA_MODE,
82 LBTF_AP_MODE,
83};
84
85
86#define MACREG_INT_CODE_FIRMWARE_READY 48
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101#define MRVDRV_MAX_MULTICAST_LIST_SIZE 32
102#define LBS_NUM_CMD_BUFFERS 10
103#define LBS_CMD_BUFFER_SIZE (2 * 1024)
104#define MRVDRV_MAX_CHANNEL_SIZE 14
105#define MRVDRV_SNAP_HEADER_LEN 8
106
107#define LBS_UPLD_SIZE 2312
108#define DEV_NAME_LEN 32
109
110
111
112
113#define MRVDRV_MAX_REGION_CODE 6
114
115
116
117#define LBTF_REGDOMAIN_US 0x10
118#define LBTF_REGDOMAIN_CA 0x20
119#define LBTF_REGDOMAIN_EU 0x30
120#define LBTF_REGDOMAIN_SP 0x31
121#define LBTF_REGDOMAIN_FR 0x32
122#define LBTF_REGDOMAIN_JP 0x40
123
124#define SBI_EVENT_CAUSE_SHIFT 3
125
126
127
128#define MRVDRV_RXPD_STATUS_OK 0x0001
129
130
131
132#define EXTRA_LEN 36
133
134#define MRVDRV_ETH_TX_PACKET_BUFFER_SIZE \
135 (ETH_FRAME_LEN + sizeof(struct txpd) + EXTRA_LEN)
136
137#define MRVDRV_ETH_RX_PACKET_BUFFER_SIZE \
138 (ETH_FRAME_LEN + sizeof(struct rxpd) \
139 + MRVDRV_SNAP_HEADER_LEN + EXTRA_LEN)
140
141#define CMD_F_HOSTCMD (1 << 0)
142#define FW_CAPINFO_WPA (1 << 0)
143
144#define RF_ANTENNA_1 0x1
145#define RF_ANTENNA_2 0x2
146#define RF_ANTENNA_AUTO 0xFFFF
147
148#define LBTF_EVENT_BCN_SENT 55
149
150
151
152enum mv_ms_type {
153 MVMS_DAT = 0,
154 MVMS_CMD = 1,
155 MVMS_TXDONE = 2,
156 MVMS_EVENT
157};
158
159extern struct workqueue_struct *lbtf_wq;
160
161struct lbtf_private;
162
163struct lbtf_offset_value {
164 u32 offset;
165 u32 value;
166};
167
168struct channel_range {
169 u8 regdomain;
170 u8 start;
171 u8 end;
172};
173
174struct if_usb_card;
175
176
177struct lbtf_private {
178 void *card;
179 struct ieee80211_hw *hw;
180
181
182 u8 cmd_resp_buff[LBS_UPLD_SIZE];
183
184
185
186
187 struct ieee80211_vif *vif;
188
189 struct work_struct cmd_work;
190 struct work_struct tx_work;
191
192 int (*hw_host_to_card) (struct lbtf_private *priv, u8 type, u8 *payload, u16 nb);
193 int (*hw_prog_firmware) (struct if_usb_card *cardp);
194 int (*hw_reset_device) (struct if_usb_card *cardp);
195
196
197
198
199 u32 fwrelease;
200 u32 fwcapinfo;
201
202
203 struct mutex lock;
204
205
206 u16 seqnum;
207
208
209 struct cmd_ctrl_node *cmd_array;
210
211 struct cmd_ctrl_node *cur_cmd;
212
213
214 struct list_head cmdfreeq;
215
216 struct list_head cmdpendingq;
217
218
219 spinlock_t driver_lock;
220
221
222 struct timer_list command_timer;
223 int nr_retries;
224 int cmd_timed_out;
225
226 u8 cmd_response_rxed;
227
228
229 u16 capability;
230
231
232 u8 current_addr[ETH_ALEN];
233 u8 multicastlist[MRVDRV_MAX_MULTICAST_LIST_SIZE][ETH_ALEN];
234 u32 nr_of_multicastmacaddr;
235 int cur_freq;
236
237 struct sk_buff *skb_to_tx;
238 struct sk_buff *tx_skb;
239
240
241 u16 mac_control;
242 u16 regioncode;
243 struct channel_range range;
244
245 u8 radioon;
246 u32 preamble;
247
248 struct ieee80211_channel channels[14];
249 struct ieee80211_rate rates[12];
250 struct ieee80211_supported_band band;
251 struct lbtf_offset_value offsetvalue;
252
253 u8 fw_ready;
254 u8 surpriseremoved;
255 struct sk_buff_head bc_ps_buf;
256
257
258 s8 noise;
259};
260
261
262
263
264struct txpd {
265
266 __le32 tx_status;
267
268 __le32 tx_control;
269 __le32 tx_packet_location;
270
271 __le16 tx_packet_length;
272
273 u8 tx_dest_addr_high[2];
274
275 u8 tx_dest_addr_low[4];
276
277 u8 priority;
278
279 u8 powermgmt;
280
281 u8 pktdelay_2ms;
282
283 u8 reserved1;
284};
285
286
287struct rxpd {
288
289 __le16 status;
290
291
292 u8 snr;
293
294
295 u8 rx_control;
296
297
298 __le16 pkt_len;
299
300
301 u8 nf;
302
303
304 u8 rx_rate;
305
306
307 __le32 pkt_ptr;
308
309
310 __le32 next_rxpd_ptr;
311
312
313 u8 priority;
314 u8 reserved[3];
315};
316
317struct cmd_header {
318 __le16 command;
319 __le16 size;
320 __le16 seqnum;
321 __le16 result;
322} __packed;
323
324struct cmd_ctrl_node {
325 struct list_head list;
326 int result;
327
328 int (*callback)(struct lbtf_private *,
329 unsigned long, struct cmd_header *);
330 unsigned long callback_arg;
331
332 struct cmd_header *cmdbuf;
333
334 u16 cmdwaitqwoken;
335 wait_queue_head_t cmdwait_q;
336};
337
338
339
340
341
342struct cmd_ds_get_hw_spec {
343 struct cmd_header hdr;
344
345
346 __le16 hwifversion;
347
348 __le16 version;
349
350 __le16 nr_txpd;
351
352 __le16 nr_mcast_adr;
353
354 u8 permanentaddr[6];
355
356
357 __le16 regioncode;
358
359
360 __le16 nr_antenna;
361
362
363 __le32 fwrelease;
364
365
366 __le32 wcb_base;
367
368 __le32 rxpd_rdptr;
369
370
371 __le32 rxpd_wrptr;
372
373
374 __le32 fwcapinfo;
375} __packed;
376
377struct cmd_ds_mac_control {
378 struct cmd_header hdr;
379 __le16 action;
380 u16 reserved;
381};
382
383struct cmd_ds_802_11_mac_address {
384 struct cmd_header hdr;
385
386 __le16 action;
387 uint8_t macadd[ETH_ALEN];
388};
389
390struct cmd_ds_mac_multicast_addr {
391 struct cmd_header hdr;
392
393 __le16 action;
394 __le16 nr_of_adrs;
395 u8 maclist[ETH_ALEN * MRVDRV_MAX_MULTICAST_LIST_SIZE];
396};
397
398struct cmd_ds_set_mode {
399 struct cmd_header hdr;
400
401 __le16 mode;
402};
403
404struct cmd_ds_set_bssid {
405 struct cmd_header hdr;
406
407 u8 bssid[6];
408 u8 activate;
409};
410
411struct cmd_ds_802_11_radio_control {
412 struct cmd_header hdr;
413
414 __le16 action;
415 __le16 control;
416};
417
418
419struct cmd_ds_802_11_rf_channel {
420 struct cmd_header hdr;
421
422 __le16 action;
423 __le16 channel;
424 __le16 rftype;
425 __le16 reserved;
426 u8 channellist[32];
427};
428
429struct cmd_ds_set_boot2_ver {
430 struct cmd_header hdr;
431
432 __le16 action;
433 __le16 version;
434};
435
436struct cmd_ds_802_11_reset {
437 struct cmd_header hdr;
438
439 __le16 action;
440};
441
442struct cmd_ds_802_11_beacon_control {
443 struct cmd_header hdr;
444
445 __le16 action;
446 __le16 beacon_enable;
447 __le16 beacon_period;
448};
449
450struct cmd_ds_802_11_beacon_set {
451 struct cmd_header hdr;
452
453 __le16 len;
454 u8 beacon[MRVL_MAX_BCN_SIZE];
455};
456
457struct lbtf_private;
458struct cmd_ctrl_node;
459
460
461void lbtf_set_mac_control(struct lbtf_private *priv);
462
463int lbtf_free_cmd_buffer(struct lbtf_private *priv);
464
465int lbtf_allocate_cmd_buffer(struct lbtf_private *priv);
466int lbtf_execute_next_command(struct lbtf_private *priv);
467int lbtf_set_radio_control(struct lbtf_private *priv);
468int lbtf_update_hw_spec(struct lbtf_private *priv);
469int lbtf_cmd_set_mac_multicast_addr(struct lbtf_private *priv);
470void lbtf_set_mode(struct lbtf_private *priv, enum lbtf_mode mode);
471void lbtf_set_bssid(struct lbtf_private *priv, bool activate, const u8 *bssid);
472int lbtf_set_mac_address(struct lbtf_private *priv, uint8_t *mac_addr);
473
474int lbtf_set_channel(struct lbtf_private *priv, u8 channel);
475
476int lbtf_beacon_set(struct lbtf_private *priv, struct sk_buff *beacon);
477int lbtf_beacon_ctrl(struct lbtf_private *priv, bool beacon_enable,
478 int beacon_int);
479
480
481int lbtf_process_rx_command(struct lbtf_private *priv);
482void lbtf_complete_command(struct lbtf_private *priv, struct cmd_ctrl_node *cmd,
483 int result);
484void lbtf_cmd_response_rx(struct lbtf_private *priv);
485
486
487struct chan_freq_power *lbtf_get_region_cfp_table(u8 region,
488 int *cfp_no);
489struct lbtf_private *lbtf_add_card(void *card, struct device *dmdev);
490int lbtf_remove_card(struct lbtf_private *priv);
491int lbtf_start_card(struct lbtf_private *priv);
492int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb);
493void lbtf_send_tx_feedback(struct lbtf_private *priv, u8 retrycnt, u8 fail);
494void lbtf_bcn_sent(struct lbtf_private *priv);
495
496
497
498
499
500#define lbtf_cmd(priv, cmdnr, cmd, cb, cb_arg) ({ \
501 uint16_t __sz = le16_to_cpu((cmd)->hdr.size); \
502 (cmd)->hdr.size = cpu_to_le16(sizeof(*(cmd))); \
503 __lbtf_cmd(priv, cmdnr, &(cmd)->hdr, __sz, cb, cb_arg); \
504})
505
506#define lbtf_cmd_with_response(priv, cmdnr, cmd) \
507 lbtf_cmd(priv, cmdnr, cmd, lbtf_cmd_copyback, (unsigned long) (cmd))
508
509void lbtf_cmd_async(struct lbtf_private *priv, uint16_t command,
510 struct cmd_header *in_cmd, int in_cmd_size);
511
512int __lbtf_cmd(struct lbtf_private *priv, uint16_t command,
513 struct cmd_header *in_cmd, int in_cmd_size,
514 int (*callback)(struct lbtf_private *, unsigned long,
515 struct cmd_header *),
516 unsigned long callback_arg);
517
518int lbtf_cmd_copyback(struct lbtf_private *priv, unsigned long extra,
519 struct cmd_header *resp);
520