• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef DRV_NAME
17 #define DRV_NAME "libertas_tf"
18 #endif
19 
20 #define	MRVL_DEFAULT_RETRIES			9
21 #define MRVL_PER_PACKET_RATE			0x10
22 #define MRVL_MAX_BCN_SIZE			440
23 #define CMD_OPTION_WAITFORRSP			0x0002
24 
25 /* Return command are almost always the same as the host command, but with
26  * bit 15 set high.  There are a few exceptions, though...
27  */
28 #define CMD_RET(cmd)			(0x8000 | cmd)
29 
30 /* Command codes */
31 #define CMD_GET_HW_SPEC				0x0003
32 #define CMD_802_11_RESET			0x0005
33 #define CMD_MAC_MULTICAST_ADR			0x0010
34 #define CMD_802_11_RADIO_CONTROL		0x001c
35 #define CMD_802_11_RF_CHANNEL			0x001d
36 #define CMD_802_11_RF_TX_POWER			0x001e
37 #define CMD_MAC_CONTROL				0x0028
38 #define CMD_802_11_MAC_ADDRESS			0x004d
39 #define	CMD_SET_BOOT2_VER			0x00a5
40 #define CMD_802_11_BEACON_CTRL			0x00b0
41 #define CMD_802_11_BEACON_SET			0x00cb
42 #define CMD_802_11_SET_MODE			0x00cc
43 #define CMD_802_11_SET_BSSID			0x00cd
44 
45 #define CMD_ACT_GET			0x0000
46 #define CMD_ACT_SET			0x0001
47 
48 /* Define action or option for CMD_802_11_RESET */
49 #define CMD_ACT_HALT			0x0003
50 
51 /* Define action or option for CMD_MAC_CONTROL */
52 #define CMD_ACT_MAC_RX_ON			0x0001
53 #define CMD_ACT_MAC_TX_ON			0x0002
54 #define CMD_ACT_MAC_MULTICAST_ENABLE		0x0020
55 #define CMD_ACT_MAC_BROADCAST_ENABLE		0x0040
56 #define CMD_ACT_MAC_PROMISCUOUS_ENABLE		0x0080
57 #define CMD_ACT_MAC_ALL_MULTICAST_ENABLE	0x0100
58 
59 /* Define action or option for CMD_802_11_RADIO_CONTROL */
60 #define CMD_TYPE_AUTO_PREAMBLE		0x0001
61 #define CMD_TYPE_SHORT_PREAMBLE		0x0002
62 #define CMD_TYPE_LONG_PREAMBLE		0x0003
63 
64 #define TURN_ON_RF			0x01
65 #define RADIO_ON			0x01
66 #define RADIO_OFF			0x00
67 
68 #define SET_AUTO_PREAMBLE		0x05
69 #define SET_SHORT_PREAMBLE		0x03
70 #define SET_LONG_PREAMBLE		0x01
71 
72 /* Define action or option for CMD_802_11_RF_CHANNEL */
73 #define CMD_OPT_802_11_RF_CHANNEL_GET	0x00
74 #define CMD_OPT_802_11_RF_CHANNEL_SET	0x01
75 
76 /* Codes for CMD_802_11_SET_MODE */
77 enum lbtf_mode {
78 	LBTF_PASSIVE_MODE,
79 	LBTF_STA_MODE,
80 	LBTF_AP_MODE,
81 };
82 
83 /** Card Event definition */
84 #define MACREG_INT_CODE_FIRMWARE_READY		48
85 /** Buffer Constants */
86 
87 /*	The size of SQ memory PPA, DPA are 8 DWORDs, that keep the physical
88 *	addresses of TxPD buffers. Station has only 8 TxPD available, Whereas
89 *	driver has more local TxPDs. Each TxPD on the host memory is associated
90 *	with a Tx control node. The driver maintains 8 RxPD descriptors for
91 *	station firmware to store Rx packet information.
92 *
93 *	Current version of MAC has a 32x6 multicast address buffer.
94 *
95 *	802.11b can have up to  14 channels, the driver keeps the
96 *	BSSID(MAC address) of each APs or Ad hoc stations it has sensed.
97 */
98 
99 #define MRVDRV_MAX_MULTICAST_LIST_SIZE	32
100 #define LBS_NUM_CMD_BUFFERS             10
101 #define LBS_CMD_BUFFER_SIZE             (2 * 1024)
102 #define MRVDRV_MAX_CHANNEL_SIZE		14
103 #define MRVDRV_SNAP_HEADER_LEN          8
104 
105 #define	LBS_UPLD_SIZE			2312
106 #define DEV_NAME_LEN			32
107 
108 /** Misc constants */
109 /* This section defines 802.11 specific contants */
110 
111 #define MRVDRV_MAX_REGION_CODE			6
112 /**
113  * the table to keep region code
114  */
115 #define LBTF_REGDOMAIN_US	0x10
116 #define LBTF_REGDOMAIN_CA	0x20
117 #define LBTF_REGDOMAIN_EU	0x30
118 #define LBTF_REGDOMAIN_SP	0x31
119 #define LBTF_REGDOMAIN_FR	0x32
120 #define LBTF_REGDOMAIN_JP	0x40
121 
122 #define SBI_EVENT_CAUSE_SHIFT		3
123 
124 /** RxPD status */
125 
126 #define MRVDRV_RXPD_STATUS_OK                0x0001
127 
128 
129 /* This is for firmware specific length */
130 #define EXTRA_LEN	36
131 
132 #define MRVDRV_ETH_TX_PACKET_BUFFER_SIZE \
133 	(ETH_FRAME_LEN + sizeof(struct txpd) + EXTRA_LEN)
134 
135 #define MRVDRV_ETH_RX_PACKET_BUFFER_SIZE \
136 	(ETH_FRAME_LEN + sizeof(struct rxpd) \
137 	 + MRVDRV_SNAP_HEADER_LEN + EXTRA_LEN)
138 
139 #define	CMD_F_HOSTCMD		(1 << 0)
140 #define FW_CAPINFO_WPA  	(1 << 0)
141 
142 #define RF_ANTENNA_1		0x1
143 #define RF_ANTENNA_2		0x2
144 #define RF_ANTENNA_AUTO		0xFFFF
145 
146 #define LBTF_EVENT_BCN_SENT	55
147 
148 /** Global Variable Declaration */
149 /** mv_ms_type */
150 enum mv_ms_type {
151 	MVMS_DAT = 0,
152 	MVMS_CMD = 1,
153 	MVMS_TXDONE = 2,
154 	MVMS_EVENT
155 };
156 
157 extern struct workqueue_struct *lbtf_wq;
158 
159 struct lbtf_private;
160 
161 struct lbtf_offset_value {
162 	u32 offset;
163 	u32 value;
164 };
165 
166 struct channel_range {
167 	u8 regdomain;
168 	u8 start;
169 	u8 end; /* exclusive (channel must be less than end) */
170 };
171 
172 struct if_usb_card;
173 
174 /** Private structure for the MV device */
175 struct lbtf_private {
176 	void *card;
177 	struct ieee80211_hw *hw;
178 
179 	/* Command response buffer */
180 	u8 cmd_resp_buff[LBS_UPLD_SIZE];
181 	/* Download sent:
182 	   bit0 1/0=data_sent/data_tx_done,
183 	   bit1 1/0=cmd_sent/cmd_tx_done,
184 	   all other bits reserved 0 */
185 	struct ieee80211_vif *vif;
186 
187 	struct work_struct cmd_work;
188 	struct work_struct tx_work;
189 	/** Hardware access */
190 	int (*hw_host_to_card) (struct lbtf_private *priv, u8 type, u8 *payload, u16 nb);
191 	int (*hw_prog_firmware) (struct if_usb_card *cardp);
192 	int (*hw_reset_device) (struct if_usb_card *cardp);
193 
194 
195 	/** Wlan adapter data structure*/
196 	/** STATUS variables */
197 	u32 fwrelease;
198 	u32 fwcapinfo;
199 	/* protected with big lock */
200 
201 	struct mutex lock;
202 
203 	/** command-related variables */
204 	u16 seqnum;
205 	/* protected by big lock */
206 
207 	struct cmd_ctrl_node *cmd_array;
208 	/** Current command */
209 	struct cmd_ctrl_node *cur_cmd;
210 	/** command Queues */
211 	/** Free command buffers */
212 	struct list_head cmdfreeq;
213 	/** Pending command buffers */
214 	struct list_head cmdpendingq;
215 
216 	/** spin locks */
217 	spinlock_t driver_lock;
218 
219 	/** Timers */
220 	struct timer_list command_timer;
221 	int nr_retries;
222 	int cmd_timed_out;
223 
224 	u8 cmd_response_rxed;
225 
226 	/** capability Info used in Association, start, join */
227 	u16 capability;
228 
229 	/** MAC address information */
230 	u8 current_addr[ETH_ALEN];
231 	u8 multicastlist[MRVDRV_MAX_MULTICAST_LIST_SIZE][ETH_ALEN];
232 	u32 nr_of_multicastmacaddr;
233 	int cur_freq;
234 
235 	struct sk_buff *skb_to_tx;
236 	struct sk_buff *tx_skb;
237 
238 	/** NIC Operation characteristics */
239 	u16 mac_control;
240 	u16 regioncode;
241 	struct channel_range range;
242 
243 	u8 radioon;
244 	u32 preamble;
245 
246 	struct ieee80211_channel channels[14];
247 	struct ieee80211_rate rates[12];
248 	struct ieee80211_supported_band band;
249 	struct lbtf_offset_value offsetvalue;
250 
251 	u8 fw_ready;
252 	u8 surpriseremoved;
253 	struct sk_buff_head bc_ps_buf;
254 };
255 
256 /* 802.11-related definitions */
257 
258 /* TxPD descriptor */
259 struct txpd {
260 	/* Current Tx packet status */
261 	__le32 tx_status;
262 	/* Tx control */
263 	__le32 tx_control;
264 	__le32 tx_packet_location;
265 	/* Tx packet length */
266 	__le16 tx_packet_length;
267 	/* First 2 byte of destination MAC address */
268 	u8 tx_dest_addr_high[2];
269 	/* Last 4 byte of destination MAC address */
270 	u8 tx_dest_addr_low[4];
271 	/* Pkt Priority */
272 	u8 priority;
273 	/* Pkt Trasnit Power control */
274 	u8 powermgmt;
275 	/* Time the packet has been queued in the driver (units = 2ms) */
276 	u8 pktdelay_2ms;
277 	/* reserved */
278 	u8 reserved1;
279 };
280 
281 /* RxPD Descriptor */
282 struct rxpd {
283 	/* Current Rx packet status */
284 	__le16 status;
285 
286 	/* SNR */
287 	u8 snr;
288 
289 	/* Tx control */
290 	u8 rx_control;
291 
292 	/* Pkt length */
293 	__le16 pkt_len;
294 
295 	/* Noise Floor */
296 	u8 nf;
297 
298 	/* Rx Packet Rate */
299 	u8 rx_rate;
300 
301 	/* Pkt addr */
302 	__le32 pkt_ptr;
303 
304 	/* Next Rx RxPD addr */
305 	__le32 next_rxpd_ptr;
306 
307 	/* Pkt Priority */
308 	u8 priority;
309 	u8 reserved[3];
310 };
311 
312 struct cmd_header {
313 	__le16 command;
314 	__le16 size;
315 	__le16 seqnum;
316 	__le16 result;
317 } __attribute__ ((packed));
318 
319 struct cmd_ctrl_node {
320 	struct list_head list;
321 	int result;
322 	/* command response */
323 	int (*callback)(struct lbtf_private *,
324 			unsigned long, struct cmd_header *);
325 	unsigned long callback_arg;
326 	/* command data */
327 	struct cmd_header *cmdbuf;
328 	/* wait queue */
329 	u16 cmdwaitqwoken;
330 	wait_queue_head_t cmdwait_q;
331 };
332 
333 /*
334  * Define data structure for CMD_GET_HW_SPEC
335  * This structure defines the response for the GET_HW_SPEC command
336  */
337 struct cmd_ds_get_hw_spec {
338 	struct cmd_header hdr;
339 
340 	/* HW Interface version number */
341 	__le16 hwifversion;
342 	/* HW version number */
343 	__le16 version;
344 	/* Max number of TxPD FW can handle */
345 	__le16 nr_txpd;
346 	/* Max no of Multicast address */
347 	__le16 nr_mcast_adr;
348 	/* MAC address */
349 	u8 permanentaddr[6];
350 
351 	/* region Code */
352 	__le16 regioncode;
353 
354 	/* Number of antenna used */
355 	__le16 nr_antenna;
356 
357 	/* FW release number, example 0x01030304 = 2.3.4p1 */
358 	__le32 fwrelease;
359 
360 	/* Base Address of TxPD queue */
361 	__le32 wcb_base;
362 	/* Read Pointer of RxPd queue */
363 	__le32 rxpd_rdptr;
364 
365 	/* Write Pointer of RxPd queue */
366 	__le32 rxpd_wrptr;
367 
368 	/*FW/HW capability */
369 	__le32 fwcapinfo;
370 } __attribute__ ((packed));
371 
372 struct cmd_ds_mac_control {
373 	struct cmd_header hdr;
374 	__le16 action;
375 	u16 reserved;
376 };
377 
378 struct cmd_ds_802_11_mac_address {
379 	struct cmd_header hdr;
380 
381 	__le16 action;
382 	uint8_t macadd[ETH_ALEN];
383 };
384 
385 struct cmd_ds_mac_multicast_addr {
386 	struct cmd_header hdr;
387 
388 	__le16 action;
389 	__le16 nr_of_adrs;
390 	u8 maclist[ETH_ALEN * MRVDRV_MAX_MULTICAST_LIST_SIZE];
391 };
392 
393 struct cmd_ds_set_mode {
394 	struct cmd_header hdr;
395 
396 	__le16 mode;
397 };
398 
399 struct cmd_ds_set_bssid {
400 	struct cmd_header hdr;
401 
402 	u8 bssid[6];
403 	u8 activate;
404 };
405 
406 struct cmd_ds_802_11_radio_control {
407 	struct cmd_header hdr;
408 
409 	__le16 action;
410 	__le16 control;
411 };
412 
413 
414 struct cmd_ds_802_11_rf_channel {
415 	struct cmd_header hdr;
416 
417 	__le16 action;
418 	__le16 channel;
419 	__le16 rftype;      /* unused */
420 	__le16 reserved;    /* unused */
421 	u8 channellist[32]; /* unused */
422 };
423 
424 struct cmd_ds_set_boot2_ver {
425 	struct cmd_header hdr;
426 
427 	__le16 action;
428 	__le16 version;
429 };
430 
431 struct cmd_ds_802_11_reset {
432 	struct cmd_header hdr;
433 
434 	__le16 action;
435 };
436 
437 struct cmd_ds_802_11_beacon_control {
438 	struct cmd_header hdr;
439 
440 	__le16 action;
441 	__le16 beacon_enable;
442 	__le16 beacon_period;
443 };
444 
445 struct cmd_ds_802_11_beacon_set {
446 	struct cmd_header hdr;
447 
448 	__le16 len;
449 	u8 beacon[MRVL_MAX_BCN_SIZE];
450 };
451 
452 struct lbtf_private;
453 struct cmd_ctrl_node;
454 
455 /** Function Prototype Declaration */
456 void lbtf_set_mac_control(struct lbtf_private *priv);
457 
458 int lbtf_free_cmd_buffer(struct lbtf_private *priv);
459 
460 int lbtf_allocate_cmd_buffer(struct lbtf_private *priv);
461 int lbtf_execute_next_command(struct lbtf_private *priv);
462 int lbtf_set_radio_control(struct lbtf_private *priv);
463 int lbtf_update_hw_spec(struct lbtf_private *priv);
464 int lbtf_cmd_set_mac_multicast_addr(struct lbtf_private *priv);
465 void lbtf_set_mode(struct lbtf_private *priv, enum lbtf_mode mode);
466 void lbtf_set_bssid(struct lbtf_private *priv, bool activate, u8 *bssid);
467 int lbtf_set_mac_address(struct lbtf_private *priv, uint8_t *mac_addr);
468 
469 int lbtf_set_channel(struct lbtf_private *priv, u8 channel);
470 
471 int lbtf_beacon_set(struct lbtf_private *priv, struct sk_buff *beacon);
472 int lbtf_beacon_ctrl(struct lbtf_private *priv, bool beacon_enable,
473 		     int beacon_int);
474 
475 
476 int lbtf_process_rx_command(struct lbtf_private *priv);
477 void lbtf_complete_command(struct lbtf_private *priv, struct cmd_ctrl_node *cmd,
478 			  int result);
479 void lbtf_cmd_response_rx(struct lbtf_private *priv);
480 
481 /* main.c */
482 struct chan_freq_power *lbtf_get_region_cfp_table(u8 region,
483 	int *cfp_no);
484 struct lbtf_private *lbtf_add_card(void *card, struct device *dmdev);
485 int lbtf_remove_card(struct lbtf_private *priv);
486 int lbtf_start_card(struct lbtf_private *priv);
487 int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb);
488 void lbtf_send_tx_feedback(struct lbtf_private *priv, u8 retrycnt, u8 fail);
489 void lbtf_bcn_sent(struct lbtf_private *priv);
490 
491 /* support functions for cmd.c */
492 /* lbtf_cmd() infers the size of the buffer to copy data back into, from
493    the size of the target of the pointer. Since the command to be sent
494    may often be smaller, that size is set in cmd->size by the caller.*/
495 #define lbtf_cmd(priv, cmdnr, cmd, cb, cb_arg)	({		\
496 	uint16_t __sz = le16_to_cpu((cmd)->hdr.size);		\
497 	(cmd)->hdr.size = cpu_to_le16(sizeof(*(cmd)));		\
498 	__lbtf_cmd(priv, cmdnr, &(cmd)->hdr, __sz, cb, cb_arg);	\
499 })
500 
501 #define lbtf_cmd_with_response(priv, cmdnr, cmd)	\
502 	lbtf_cmd(priv, cmdnr, cmd, lbtf_cmd_copyback, (unsigned long) (cmd))
503 
504 void lbtf_cmd_async(struct lbtf_private *priv, uint16_t command,
505 	struct cmd_header *in_cmd, int in_cmd_size);
506 
507 int __lbtf_cmd(struct lbtf_private *priv, uint16_t command,
508 	      struct cmd_header *in_cmd, int in_cmd_size,
509 	      int (*callback)(struct lbtf_private *, unsigned long,
510 			      struct cmd_header *),
511 	      unsigned long callback_arg);
512 
513 int lbtf_cmd_copyback(struct lbtf_private *priv, unsigned long extra,
514 		     struct cmd_header *resp);
515