]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/net/wireless/marvell/libertas_tf/libertas_tf.h
libertas_tf: move hardware callbacks to a separate structure
[linux.git] / drivers / net / wireless / marvell / libertas_tf / libertas_tf.h
1 /*
2  *  Copyright (C) 2008, cozybit Inc.
3  *  Copyright (C) 2007, Red Hat, Inc.
4  *  Copyright (C) 2003-2006, Marvell International Ltd.
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or (at
9  *  your option) any later version.
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 /* Return command are almost always the same as the host command, but with
28  * bit 15 set high.  There are a few exceptions, though...
29  */
30 #define CMD_RET(cmd)                    (0x8000 | cmd)
31
32 /* Command codes */
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 /* Define action or option for CMD_802_11_RESET */
51 #define CMD_ACT_HALT                    0x0003
52
53 /* Define action or option for CMD_MAC_CONTROL */
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 /* Define action or option for CMD_802_11_RADIO_CONTROL */
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 /* Define action or option for CMD_802_11_RF_CHANNEL */
75 #define CMD_OPT_802_11_RF_CHANNEL_GET   0x00
76 #define CMD_OPT_802_11_RF_CHANNEL_SET   0x01
77
78 /* Codes for CMD_802_11_SET_MODE */
79 enum lbtf_mode {
80         LBTF_PASSIVE_MODE,
81         LBTF_STA_MODE,
82         LBTF_AP_MODE,
83 };
84
85 /** Card Event definition */
86 #define MACREG_INT_CODE_FIRMWARE_READY          48
87 /** Buffer Constants */
88
89 /*      The size of SQ memory PPA, DPA are 8 DWORDs, that keep the physical
90 *       addresses of TxPD buffers. Station has only 8 TxPD available, Whereas
91 *       driver has more local TxPDs. Each TxPD on the host memory is associated
92 *       with a Tx control node. The driver maintains 8 RxPD descriptors for
93 *       station firmware to store Rx packet information.
94 *
95 *       Current version of MAC has a 32x6 multicast address buffer.
96 *
97 *       802.11b can have up to  14 channels, the driver keeps the
98 *       BSSID(MAC address) of each APs or Ad hoc stations it has sensed.
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 /** Misc constants */
111 /* This section defines 802.11 specific contants */
112
113 #define MRVDRV_MAX_REGION_CODE                  6
114 /**
115  * the table to keep region code
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 /** RxPD status */
127
128 #define MRVDRV_RXPD_STATUS_OK                0x0001
129
130
131 /* This is for firmware specific length */
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 /** Global Variable Declaration */
151 /** mv_ms_type */
152 enum mv_ms_type {
153         MVMS_DAT = 0,
154         MVMS_CMD = 1,
155         MVMS_TXDONE = 2,
156         MVMS_EVENT
157 };
158
159 extern struct workqueue_struct *lbtf_wq;
160
161 struct lbtf_private;
162
163 struct lbtf_offset_value {
164         u32 offset;
165         u32 value;
166 };
167
168 struct channel_range {
169         u8 regdomain;
170         u8 start;
171         u8 end; /* exclusive (channel must be less than end) */
172 };
173
174 struct if_usb_card;
175
176 struct lbtf_ops {
177         /** Hardware access */
178         int (*hw_host_to_card)(struct lbtf_private *priv, u8 type,
179                                u8 *payload, u16 nb);
180         int (*hw_prog_firmware)(struct if_usb_card *cardp);
181         int (*hw_reset_device)(struct if_usb_card *cardp);
182 };
183
184 /** Private structure for the MV device */
185 struct lbtf_private {
186         void *card;
187         struct ieee80211_hw *hw;
188         const struct lbtf_ops *ops;
189
190         /* Command response buffer */
191         u8 cmd_resp_buff[LBS_UPLD_SIZE];
192         /* Download sent:
193            bit0 1/0=data_sent/data_tx_done,
194            bit1 1/0=cmd_sent/cmd_tx_done,
195            all other bits reserved 0 */
196         struct ieee80211_vif *vif;
197
198         struct work_struct cmd_work;
199         struct work_struct tx_work;
200
201         /** Wlan adapter data structure*/
202         /** STATUS variables */
203         u32 fwrelease;
204         u32 fwcapinfo;
205         /* protected with big lock */
206
207         struct mutex lock;
208
209         /** command-related variables */
210         u16 seqnum;
211         /* protected by big lock */
212
213         struct cmd_ctrl_node *cmd_array;
214         /** Current command */
215         struct cmd_ctrl_node *cur_cmd;
216         /** command Queues */
217         /** Free command buffers */
218         struct list_head cmdfreeq;
219         /** Pending command buffers */
220         struct list_head cmdpendingq;
221
222         /** spin locks */
223         spinlock_t driver_lock;
224
225         /** Timers */
226         struct timer_list command_timer;
227         int nr_retries;
228         int cmd_timed_out;
229
230         u8 cmd_response_rxed;
231
232         /** capability Info used in Association, start, join */
233         u16 capability;
234
235         /** MAC address information */
236         u8 current_addr[ETH_ALEN];
237         u8 multicastlist[MRVDRV_MAX_MULTICAST_LIST_SIZE][ETH_ALEN];
238         u32 nr_of_multicastmacaddr;
239         int cur_freq;
240
241         struct sk_buff *skb_to_tx;
242         struct sk_buff *tx_skb;
243
244         /** NIC Operation characteristics */
245         u16 mac_control;
246         u16 regioncode;
247         struct channel_range range;
248
249         u8 radioon;
250         u32 preamble;
251
252         struct ieee80211_channel channels[14];
253         struct ieee80211_rate rates[12];
254         struct ieee80211_supported_band band;
255         struct lbtf_offset_value offsetvalue;
256
257         u8 fw_ready;
258         u8 surpriseremoved;
259         struct sk_buff_head bc_ps_buf;
260
261         /* Most recently reported noise in dBm */
262         s8 noise;
263 };
264
265 /* 802.11-related definitions */
266
267 /* TxPD descriptor */
268 struct txpd {
269         /* Current Tx packet status */
270         __le32 tx_status;
271         /* Tx control */
272         __le32 tx_control;
273         __le32 tx_packet_location;
274         /* Tx packet length */
275         __le16 tx_packet_length;
276         /* First 2 byte of destination MAC address */
277         u8 tx_dest_addr_high[2];
278         /* Last 4 byte of destination MAC address */
279         u8 tx_dest_addr_low[4];
280         /* Pkt Priority */
281         u8 priority;
282         /* Pkt Trasnit Power control */
283         u8 powermgmt;
284         /* Time the packet has been queued in the driver (units = 2ms) */
285         u8 pktdelay_2ms;
286         /* reserved */
287         u8 reserved1;
288 };
289
290 /* RxPD Descriptor */
291 struct rxpd {
292         /* Current Rx packet status */
293         __le16 status;
294
295         /* SNR */
296         u8 snr;
297
298         /* Tx control */
299         u8 rx_control;
300
301         /* Pkt length */
302         __le16 pkt_len;
303
304         /* Noise Floor */
305         u8 nf;
306
307         /* Rx Packet Rate */
308         u8 rx_rate;
309
310         /* Pkt addr */
311         __le32 pkt_ptr;
312
313         /* Next Rx RxPD addr */
314         __le32 next_rxpd_ptr;
315
316         /* Pkt Priority */
317         u8 priority;
318         u8 reserved[3];
319 };
320
321 struct cmd_header {
322         __le16 command;
323         __le16 size;
324         __le16 seqnum;
325         __le16 result;
326 } __packed;
327
328 struct cmd_ctrl_node {
329         struct list_head list;
330         int result;
331         /* command response */
332         int (*callback)(struct lbtf_private *,
333                         unsigned long, struct cmd_header *);
334         unsigned long callback_arg;
335         /* command data */
336         struct cmd_header *cmdbuf;
337         /* wait queue */
338         u16 cmdwaitqwoken;
339         wait_queue_head_t cmdwait_q;
340 };
341
342 /*
343  * Define data structure for CMD_GET_HW_SPEC
344  * This structure defines the response for the GET_HW_SPEC command
345  */
346 struct cmd_ds_get_hw_spec {
347         struct cmd_header hdr;
348
349         /* HW Interface version number */
350         __le16 hwifversion;
351         /* HW version number */
352         __le16 version;
353         /* Max number of TxPD FW can handle */
354         __le16 nr_txpd;
355         /* Max no of Multicast address */
356         __le16 nr_mcast_adr;
357         /* MAC address */
358         u8 permanentaddr[6];
359
360         /* region Code */
361         __le16 regioncode;
362
363         /* Number of antenna used */
364         __le16 nr_antenna;
365
366         /* FW release number, example 0x01030304 = 2.3.4p1 */
367         __le32 fwrelease;
368
369         /* Base Address of TxPD queue */
370         __le32 wcb_base;
371         /* Read Pointer of RxPd queue */
372         __le32 rxpd_rdptr;
373
374         /* Write Pointer of RxPd queue */
375         __le32 rxpd_wrptr;
376
377         /*FW/HW capability */
378         __le32 fwcapinfo;
379 } __packed;
380
381 struct cmd_ds_mac_control {
382         struct cmd_header hdr;
383         __le16 action;
384         u16 reserved;
385 };
386
387 struct cmd_ds_802_11_mac_address {
388         struct cmd_header hdr;
389
390         __le16 action;
391         uint8_t macadd[ETH_ALEN];
392 };
393
394 struct cmd_ds_mac_multicast_addr {
395         struct cmd_header hdr;
396
397         __le16 action;
398         __le16 nr_of_adrs;
399         u8 maclist[ETH_ALEN * MRVDRV_MAX_MULTICAST_LIST_SIZE];
400 };
401
402 struct cmd_ds_set_mode {
403         struct cmd_header hdr;
404
405         __le16 mode;
406 };
407
408 struct cmd_ds_set_bssid {
409         struct cmd_header hdr;
410
411         u8 bssid[6];
412         u8 activate;
413 };
414
415 struct cmd_ds_802_11_radio_control {
416         struct cmd_header hdr;
417
418         __le16 action;
419         __le16 control;
420 };
421
422
423 struct cmd_ds_802_11_rf_channel {
424         struct cmd_header hdr;
425
426         __le16 action;
427         __le16 channel;
428         __le16 rftype;      /* unused */
429         __le16 reserved;    /* unused */
430         u8 channellist[32]; /* unused */
431 };
432
433 struct cmd_ds_set_boot2_ver {
434         struct cmd_header hdr;
435
436         __le16 action;
437         __le16 version;
438 };
439
440 struct cmd_ds_802_11_reset {
441         struct cmd_header hdr;
442
443         __le16 action;
444 };
445
446 struct cmd_ds_802_11_beacon_control {
447         struct cmd_header hdr;
448
449         __le16 action;
450         __le16 beacon_enable;
451         __le16 beacon_period;
452 };
453
454 struct cmd_ds_802_11_beacon_set {
455         struct cmd_header hdr;
456
457         __le16 len;
458         u8 beacon[MRVL_MAX_BCN_SIZE];
459 };
460
461 struct lbtf_private;
462 struct cmd_ctrl_node;
463
464 /** Function Prototype Declaration */
465 void lbtf_set_mac_control(struct lbtf_private *priv);
466
467 int lbtf_free_cmd_buffer(struct lbtf_private *priv);
468
469 int lbtf_allocate_cmd_buffer(struct lbtf_private *priv);
470 int lbtf_execute_next_command(struct lbtf_private *priv);
471 int lbtf_set_radio_control(struct lbtf_private *priv);
472 int lbtf_update_hw_spec(struct lbtf_private *priv);
473 int lbtf_cmd_set_mac_multicast_addr(struct lbtf_private *priv);
474 void lbtf_set_mode(struct lbtf_private *priv, enum lbtf_mode mode);
475 void lbtf_set_bssid(struct lbtf_private *priv, bool activate, const u8 *bssid);
476 int lbtf_set_mac_address(struct lbtf_private *priv, uint8_t *mac_addr);
477
478 int lbtf_set_channel(struct lbtf_private *priv, u8 channel);
479
480 int lbtf_beacon_set(struct lbtf_private *priv, struct sk_buff *beacon);
481 int lbtf_beacon_ctrl(struct lbtf_private *priv, bool beacon_enable,
482                      int beacon_int);
483
484
485 int lbtf_process_rx_command(struct lbtf_private *priv);
486 void lbtf_complete_command(struct lbtf_private *priv, struct cmd_ctrl_node *cmd,
487                           int result);
488 void lbtf_cmd_response_rx(struct lbtf_private *priv);
489
490 /* main.c */
491 struct chan_freq_power *lbtf_get_region_cfp_table(u8 region,
492         int *cfp_no);
493 struct lbtf_private *lbtf_add_card(void *card, struct device *dmdev,
494                                    const struct lbtf_ops *ops);
495 int lbtf_remove_card(struct lbtf_private *priv);
496 int lbtf_start_card(struct lbtf_private *priv);
497 int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb);
498 void lbtf_send_tx_feedback(struct lbtf_private *priv, u8 retrycnt, u8 fail);
499 void lbtf_bcn_sent(struct lbtf_private *priv);
500
501 /* support functions for cmd.c */
502 /* lbtf_cmd() infers the size of the buffer to copy data back into, from
503    the size of the target of the pointer. Since the command to be sent
504    may often be smaller, that size is set in cmd->size by the caller.*/
505 #define lbtf_cmd(priv, cmdnr, cmd, cb, cb_arg)  ({              \
506         uint16_t __sz = le16_to_cpu((cmd)->hdr.size);           \
507         (cmd)->hdr.size = cpu_to_le16(sizeof(*(cmd)));          \
508         __lbtf_cmd(priv, cmdnr, &(cmd)->hdr, __sz, cb, cb_arg); \
509 })
510
511 #define lbtf_cmd_with_response(priv, cmdnr, cmd)        \
512         lbtf_cmd(priv, cmdnr, cmd, lbtf_cmd_copyback, (unsigned long) (cmd))
513
514 void lbtf_cmd_async(struct lbtf_private *priv, uint16_t command,
515         struct cmd_header *in_cmd, int in_cmd_size);
516
517 int __lbtf_cmd(struct lbtf_private *priv, uint16_t command,
518               struct cmd_header *in_cmd, int in_cmd_size,
519               int (*callback)(struct lbtf_private *, unsigned long,
520                               struct cmd_header *),
521               unsigned long callback_arg);
522
523 int lbtf_cmd_copyback(struct lbtf_private *priv, unsigned long extra,
524                      struct cmd_header *resp);