diff options
Diffstat (limited to 'drivers/net/wireless/libertas/fw.c')
-rw-r--r-- | drivers/net/wireless/libertas/fw.c | 346 |
1 files changed, 0 insertions, 346 deletions
diff --git a/drivers/net/wireless/libertas/fw.c b/drivers/net/wireless/libertas/fw.c deleted file mode 100644 index 6c259878da96..000000000000 --- a/drivers/net/wireless/libertas/fw.c +++ /dev/null | |||
@@ -1,346 +0,0 @@ | |||
1 | /** | ||
2 | * This file contains the initialization for FW and HW | ||
3 | */ | ||
4 | #include <linux/firmware.h> | ||
5 | |||
6 | #include "host.h" | ||
7 | #include "defs.h" | ||
8 | #include "decl.h" | ||
9 | #include "dev.h" | ||
10 | #include "wext.h" | ||
11 | #include "if_usb.h" | ||
12 | |||
13 | /** | ||
14 | * @brief This function checks the validity of Boot2/FW image. | ||
15 | * | ||
16 | * @param data pointer to image | ||
17 | * len image length | ||
18 | * @return 0 or -1 | ||
19 | */ | ||
20 | static int check_fwfile_format(u8 *data, u32 totlen) | ||
21 | { | ||
22 | u32 bincmd, exit; | ||
23 | u32 blksize, offset, len; | ||
24 | int ret; | ||
25 | |||
26 | ret = 1; | ||
27 | exit = len = 0; | ||
28 | |||
29 | do { | ||
30 | struct fwheader *fwh = (void *)data; | ||
31 | |||
32 | bincmd = le32_to_cpu(fwh->dnldcmd); | ||
33 | blksize = le32_to_cpu(fwh->datalength); | ||
34 | switch (bincmd) { | ||
35 | case FW_HAS_DATA_TO_RECV: | ||
36 | offset = sizeof(struct fwheader) + blksize; | ||
37 | data += offset; | ||
38 | len += offset; | ||
39 | if (len >= totlen) | ||
40 | exit = 1; | ||
41 | break; | ||
42 | case FW_HAS_LAST_BLOCK: | ||
43 | exit = 1; | ||
44 | ret = 0; | ||
45 | break; | ||
46 | default: | ||
47 | exit = 1; | ||
48 | break; | ||
49 | } | ||
50 | } while (!exit); | ||
51 | |||
52 | if (ret) | ||
53 | lbs_pr_err("firmware file format check FAIL\n"); | ||
54 | else | ||
55 | lbs_deb_fw("firmware file format check PASS\n"); | ||
56 | |||
57 | return ret; | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * @brief This function downloads firmware image, gets | ||
62 | * HW spec from firmware and set basic parameters to | ||
63 | * firmware. | ||
64 | * | ||
65 | * @param priv A pointer to wlan_private structure | ||
66 | * @return 0 or -1 | ||
67 | */ | ||
68 | static int wlan_setup_station_hw(wlan_private * priv, char *fw_name) | ||
69 | { | ||
70 | int ret = -1; | ||
71 | wlan_adapter *adapter = priv->adapter; | ||
72 | |||
73 | lbs_deb_enter(LBS_DEB_FW); | ||
74 | |||
75 | if ((ret = request_firmware(&priv->firmware, fw_name, | ||
76 | priv->hotplug_device)) < 0) { | ||
77 | lbs_pr_err("request_firmware() failed with %#x\n", ret); | ||
78 | lbs_pr_err("firmware %s not found\n", fw_name); | ||
79 | goto done; | ||
80 | } | ||
81 | |||
82 | if (check_fwfile_format(priv->firmware->data, priv->firmware->size)) { | ||
83 | release_firmware(priv->firmware); | ||
84 | goto done; | ||
85 | } | ||
86 | |||
87 | ret = priv->hw_prog_firmware(priv); | ||
88 | |||
89 | release_firmware(priv->firmware); | ||
90 | |||
91 | if (ret) { | ||
92 | lbs_deb_fw("bootloader in invalid state\n"); | ||
93 | ret = -1; | ||
94 | goto done; | ||
95 | } | ||
96 | |||
97 | /* | ||
98 | * Read MAC address from HW | ||
99 | */ | ||
100 | memset(adapter->current_addr, 0xff, ETH_ALEN); | ||
101 | |||
102 | ret = libertas_prepare_and_send_command(priv, CMD_GET_HW_SPEC, | ||
103 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); | ||
104 | |||
105 | if (ret) { | ||
106 | ret = -1; | ||
107 | goto done; | ||
108 | } | ||
109 | |||
110 | libertas_set_mac_packet_filter(priv); | ||
111 | |||
112 | /* Get the supported Data rates */ | ||
113 | ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE, | ||
114 | CMD_ACT_GET_TX_RATE, | ||
115 | CMD_OPTION_WAITFORRSP, 0, NULL); | ||
116 | |||
117 | if (ret) { | ||
118 | ret = -1; | ||
119 | goto done; | ||
120 | } | ||
121 | |||
122 | ret = 0; | ||
123 | done: | ||
124 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); | ||
125 | return ret; | ||
126 | } | ||
127 | |||
128 | static int wlan_allocate_adapter(wlan_private * priv) | ||
129 | { | ||
130 | size_t bufsize; | ||
131 | wlan_adapter *adapter = priv->adapter; | ||
132 | |||
133 | /* Allocate buffer to store the BSSID list */ | ||
134 | bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor); | ||
135 | adapter->networks = kzalloc(bufsize, GFP_KERNEL); | ||
136 | if (!adapter->networks) { | ||
137 | lbs_pr_err("Out of memory allocating beacons\n"); | ||
138 | libertas_free_adapter(priv); | ||
139 | return -ENOMEM; | ||
140 | } | ||
141 | |||
142 | /* Allocate the command buffers */ | ||
143 | libertas_allocate_cmd_buffer(priv); | ||
144 | |||
145 | memset(&adapter->libertas_ps_confirm_sleep, 0, sizeof(struct PS_CMD_ConfirmSleep)); | ||
146 | adapter->libertas_ps_confirm_sleep.seqnum = cpu_to_le16(++adapter->seqnum); | ||
147 | adapter->libertas_ps_confirm_sleep.command = | ||
148 | cpu_to_le16(CMD_802_11_PS_MODE); | ||
149 | adapter->libertas_ps_confirm_sleep.size = | ||
150 | cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep)); | ||
151 | adapter->libertas_ps_confirm_sleep.result = 0; | ||
152 | adapter->libertas_ps_confirm_sleep.action = | ||
153 | cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED); | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | static void wlan_init_adapter(wlan_private * priv) | ||
159 | { | ||
160 | wlan_adapter *adapter = priv->adapter; | ||
161 | int i; | ||
162 | |||
163 | adapter->scanprobes = 0; | ||
164 | |||
165 | adapter->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR; | ||
166 | adapter->data_avg_factor = DEFAULT_DATA_AVG_FACTOR; | ||
167 | |||
168 | /* ATIM params */ | ||
169 | adapter->atimwindow = 0; | ||
170 | |||
171 | adapter->connect_status = LIBERTAS_DISCONNECTED; | ||
172 | memset(adapter->current_addr, 0xff, ETH_ALEN); | ||
173 | |||
174 | /* scan type */ | ||
175 | adapter->scantype = CMD_SCAN_TYPE_ACTIVE; | ||
176 | |||
177 | /* scan mode */ | ||
178 | adapter->scanmode = CMD_BSS_TYPE_ANY; | ||
179 | |||
180 | /* 802.11 specific */ | ||
181 | adapter->secinfo.wep_enabled = 0; | ||
182 | for (i = 0; i < sizeof(adapter->wep_keys) / sizeof(adapter->wep_keys[0]); | ||
183 | i++) | ||
184 | memset(&adapter->wep_keys[i], 0, sizeof(struct enc_key)); | ||
185 | adapter->wep_tx_keyidx = 0; | ||
186 | adapter->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; | ||
187 | adapter->mode = IW_MODE_INFRA; | ||
188 | |||
189 | adapter->pending_assoc_req = NULL; | ||
190 | adapter->in_progress_assoc_req = NULL; | ||
191 | |||
192 | /* Initialize scan result lists */ | ||
193 | INIT_LIST_HEAD(&adapter->network_free_list); | ||
194 | INIT_LIST_HEAD(&adapter->network_list); | ||
195 | for (i = 0; i < MAX_NETWORK_COUNT; i++) { | ||
196 | list_add_tail(&adapter->networks[i].list, | ||
197 | &adapter->network_free_list); | ||
198 | } | ||
199 | |||
200 | mutex_init(&adapter->lock); | ||
201 | |||
202 | adapter->prescan = 1; | ||
203 | |||
204 | memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams)); | ||
205 | adapter->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL; | ||
206 | |||
207 | /* PnP and power profile */ | ||
208 | adapter->surpriseremoved = 0; | ||
209 | |||
210 | adapter->currentpacketfilter = | ||
211 | CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON; | ||
212 | |||
213 | adapter->radioon = RADIO_ON; | ||
214 | adapter->txantenna = RF_ANTENNA_2; | ||
215 | adapter->rxantenna = RF_ANTENNA_AUTO; | ||
216 | |||
217 | adapter->auto_rate = 1; | ||
218 | adapter->cur_rate = 0; | ||
219 | adapter->adhoc_grate_enabled = 0; | ||
220 | |||
221 | adapter->beaconperiod = MRVDRV_BEACON_INTERVAL; | ||
222 | |||
223 | // set default capabilities | ||
224 | adapter->capability = WLAN_CAPABILITY_SHORT_PREAMBLE; | ||
225 | |||
226 | adapter->psmode = WLAN802_11POWERMODECAM; | ||
227 | adapter->multipledtim = MRVDRV_DEFAULT_MULTIPLE_DTIM; | ||
228 | |||
229 | adapter->listeninterval = MRVDRV_DEFAULT_LISTEN_INTERVAL; | ||
230 | |||
231 | adapter->psstate = PS_STATE_FULL_POWER; | ||
232 | adapter->needtowakeup = 0; | ||
233 | adapter->locallisteninterval = 0; /* default value in firmware will be used */ | ||
234 | |||
235 | adapter->intcounter = 0; | ||
236 | |||
237 | adapter->currenttxskb = NULL; | ||
238 | adapter->pkttxctrl = 0; | ||
239 | |||
240 | memset(&adapter->tx_queue_ps, 0, NR_TX_QUEUE*sizeof(struct sk_buff*)); | ||
241 | adapter->tx_queue_idx = 0; | ||
242 | spin_lock_init(&adapter->txqueue_lock); | ||
243 | |||
244 | return; | ||
245 | } | ||
246 | |||
247 | static void command_timer_fn(unsigned long data); | ||
248 | |||
249 | int libertas_init_fw(wlan_private * priv, char *fw_name) | ||
250 | { | ||
251 | int ret = -1; | ||
252 | wlan_adapter *adapter = priv->adapter; | ||
253 | |||
254 | lbs_deb_enter(LBS_DEB_FW); | ||
255 | |||
256 | /* Allocate adapter structure */ | ||
257 | if ((ret = wlan_allocate_adapter(priv)) != 0) | ||
258 | goto done; | ||
259 | |||
260 | /* init adapter structure */ | ||
261 | wlan_init_adapter(priv); | ||
262 | |||
263 | /* init timer etc. */ | ||
264 | setup_timer(&adapter->command_timer, command_timer_fn, | ||
265 | (unsigned long)priv); | ||
266 | |||
267 | /* download fimrware etc. */ | ||
268 | if ((ret = wlan_setup_station_hw(priv, fw_name)) != 0) { | ||
269 | del_timer_sync(&adapter->command_timer); | ||
270 | goto done; | ||
271 | } | ||
272 | |||
273 | /* init 802.11d */ | ||
274 | libertas_init_11d(priv); | ||
275 | |||
276 | ret = 0; | ||
277 | done: | ||
278 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); | ||
279 | return ret; | ||
280 | } | ||
281 | |||
282 | void libertas_free_adapter(wlan_private * priv) | ||
283 | { | ||
284 | wlan_adapter *adapter = priv->adapter; | ||
285 | |||
286 | if (!adapter) { | ||
287 | lbs_deb_fw("why double free adapter?\n"); | ||
288 | return; | ||
289 | } | ||
290 | |||
291 | lbs_deb_fw("free command buffer\n"); | ||
292 | libertas_free_cmd_buffer(priv); | ||
293 | |||
294 | lbs_deb_fw("free command_timer\n"); | ||
295 | del_timer(&adapter->command_timer); | ||
296 | |||
297 | lbs_deb_fw("free scan results table\n"); | ||
298 | kfree(adapter->networks); | ||
299 | adapter->networks = NULL; | ||
300 | |||
301 | /* Free the adapter object itself */ | ||
302 | lbs_deb_fw("free adapter\n"); | ||
303 | kfree(adapter); | ||
304 | priv->adapter = NULL; | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * This function handles the timeout of command sending. | ||
309 | * It will re-send the same command again. | ||
310 | */ | ||
311 | static void command_timer_fn(unsigned long data) | ||
312 | { | ||
313 | wlan_private *priv = (wlan_private *)data; | ||
314 | wlan_adapter *adapter = priv->adapter; | ||
315 | struct cmd_ctrl_node *ptempnode; | ||
316 | struct cmd_ds_command *cmd; | ||
317 | unsigned long flags; | ||
318 | |||
319 | ptempnode = adapter->cur_cmd; | ||
320 | if (ptempnode == NULL) { | ||
321 | lbs_deb_fw("ptempnode empty\n"); | ||
322 | return; | ||
323 | } | ||
324 | |||
325 | cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr; | ||
326 | if (!cmd) { | ||
327 | lbs_deb_fw("cmd is NULL\n"); | ||
328 | return; | ||
329 | } | ||
330 | |||
331 | lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command); | ||
332 | |||
333 | if (!adapter->fw_ready) | ||
334 | return; | ||
335 | |||
336 | spin_lock_irqsave(&adapter->driver_lock, flags); | ||
337 | adapter->cur_cmd = NULL; | ||
338 | spin_unlock_irqrestore(&adapter->driver_lock, flags); | ||
339 | |||
340 | lbs_deb_fw("re-sending same command because of timeout\n"); | ||
341 | libertas_queue_cmd(adapter, ptempnode, 0); | ||
342 | |||
343 | wake_up_interruptible(&priv->waitq); | ||
344 | |||
345 | return; | ||
346 | } | ||