2 * This file contains the initialization for FW and HW
4 #include <linux/module.h>
5 #include <linux/moduleparam.h>
7 #include <linux/vmalloc.h>
8 #include <linux/firmware.h>
9 #include <linux/version.h>
20 char *libertas_fw_name = NULL;
21 module_param_named(fw_name, libertas_fw_name, charp, 0644);
23 unsigned int libertas_debug_flags = 0;
24 module_param_named(debug, libertas_debug_flags, int, 0);
27 * @brief This function checks the validity of Boot2/FW image.
29 * @param data pointer to image
33 static int check_fwfile_format(u8 *data, u32 totlen)
36 u32 blksize, offset, len;
44 blksize = *(u32*)(data + offsetof(struct fwheader, datalength));
46 case FW_HAS_DATA_TO_RECV:
47 offset = sizeof(struct fwheader) + blksize;
53 case FW_HAS_LAST_BLOCK:
64 lbs_pr_err("firmware file format check FAIL\n");
66 lbs_deb_fw("firmware file format check PASS\n");
72 * @brief This function downloads firmware image, gets
73 * HW spec from firmware and set basic parameters to
76 * @param priv A pointer to wlan_private structure
79 static int wlan_setup_station_hw(wlan_private * priv)
82 wlan_adapter *adapter = priv->adapter;
84 lbs_deb_enter(LBS_DEB_FW);
86 if ((ret = request_firmware(&priv->firmware, libertas_fw_name,
87 priv->hotplug_device)) < 0) {
88 lbs_pr_err("request_firmware() failed with %#x\n",
90 lbs_pr_err("firmware %s not found\n", libertas_fw_name);
94 if(check_fwfile_format(priv->firmware->data, priv->firmware->size)) {
95 release_firmware(priv->firmware);
99 ret = libertas_sbi_prog_firmware(priv);
101 release_firmware(priv->firmware);
104 lbs_deb_fw("bootloader in invalid state\n");
110 * Read MAC address from HW
112 memset(adapter->current_addr, 0xff, ETH_ALEN);
114 ret = libertas_prepare_and_send_command(priv, cmd_get_hw_spec,
115 0, cmd_option_waitforrsp, 0, NULL);
122 libertas_set_mac_packet_filter(priv);
124 /* Get the supported Data rates */
125 ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
127 cmd_option_waitforrsp, 0, NULL);
136 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
140 static int wlan_allocate_adapter(wlan_private * priv)
143 wlan_adapter *adapter = priv->adapter;
145 struct bss_descriptor *ptempscantable;
147 /* Allocate buffer to store the BSSID list */
148 ulbufsize = sizeof(struct bss_descriptor) * MRVDRV_MAX_BSSID_LIST;
149 if (!(ptempscantable = kmalloc(ulbufsize, GFP_KERNEL))) {
150 libertas_free_adapter(priv);
154 adapter->scantable = ptempscantable;
155 memset(adapter->scantable, 0, ulbufsize);
157 /* Allocate the command buffers */
158 libertas_allocate_cmd_buffer(priv);
160 memset(&adapter->libertas_ps_confirm_sleep, 0, sizeof(struct PS_CMD_ConfirmSleep));
161 adapter->libertas_ps_confirm_sleep.seqnum = cpu_to_le16(++adapter->seqnum);
162 adapter->libertas_ps_confirm_sleep.command =
163 cpu_to_le16(cmd_802_11_ps_mode);
164 adapter->libertas_ps_confirm_sleep.size =
165 cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep));
166 adapter->libertas_ps_confirm_sleep.result = 0;
167 adapter->libertas_ps_confirm_sleep.action =
168 cpu_to_le16(cmd_subcmd_sleep_confirmed);
173 static void wlan_init_adapter(wlan_private * priv)
175 wlan_adapter *adapter = priv->adapter;
178 adapter->scanprobes = 0;
180 adapter->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
181 adapter->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
184 adapter->atimwindow = 0;
186 adapter->connect_status = libertas_disconnected;
187 memset(adapter->current_addr, 0xff, ETH_ALEN);
190 adapter->scantype = cmd_scan_type_active;
193 adapter->scanmode = cmd_bss_type_any;
195 /* 802.11 specific */
196 adapter->secinfo.wep_enabled = 0;
197 for (i = 0; i < sizeof(adapter->wep_keys) / sizeof(adapter->wep_keys[0]);
199 memset(&adapter->wep_keys[i], 0, sizeof(struct WLAN_802_11_KEY));
200 adapter->wep_tx_keyidx = 0;
201 adapter->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
202 adapter->mode = IW_MODE_INFRA;
204 adapter->assoc_req = NULL;
206 adapter->numinscantable = 0;
207 adapter->pattemptedbssdesc = NULL;
208 mutex_init(&adapter->lock);
210 adapter->prescan = 1;
212 memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
214 /* PnP and power profile */
215 adapter->surpriseremoved = 0;
217 adapter->currentpacketfilter =
218 cmd_act_mac_rx_on | cmd_act_mac_tx_on;
220 adapter->radioon = RADIO_ON;
221 adapter->txantenna = RF_ANTENNA_2;
222 adapter->rxantenna = RF_ANTENNA_AUTO;
224 adapter->is_datarate_auto = 1;
225 adapter->beaconperiod = MRVDRV_BEACON_INTERVAL;
227 // set default value of capinfo.
228 #define SHORT_PREAMBLE_ALLOWED 1
229 memset(&adapter->capinfo, 0, sizeof(adapter->capinfo));
230 adapter->capinfo.shortpreamble = SHORT_PREAMBLE_ALLOWED;
232 adapter->adhocchannel = DEFAULT_AD_HOC_CHANNEL;
234 adapter->psmode = wlan802_11powermodecam;
235 adapter->multipledtim = MRVDRV_DEFAULT_MULTIPLE_DTIM;
237 adapter->listeninterval = MRVDRV_DEFAULT_LISTEN_INTERVAL;
239 adapter->psstate = PS_STATE_FULL_POWER;
240 adapter->needtowakeup = 0;
241 adapter->locallisteninterval = 0; /* default value in firmware will be used */
243 adapter->datarate = 0; // Initially indicate the rate as auto
245 adapter->adhoc_grate_enabled = 0;
247 adapter->intcounter = 0;
249 adapter->currenttxskb = NULL;
250 adapter->pkttxctrl = 0;
252 memset(&adapter->tx_queue_ps, 0, NR_TX_QUEUE*sizeof(struct sk_buff*));
253 adapter->tx_queue_idx = 0;
254 spin_lock_init(&adapter->txqueue_lock);
259 static void command_timer_fn(unsigned long data);
261 int libertas_init_fw(wlan_private * priv)
264 wlan_adapter *adapter = priv->adapter;
266 lbs_deb_enter(LBS_DEB_FW);
268 /* Allocate adapter structure */
269 if ((ret = wlan_allocate_adapter(priv)) != 0)
272 /* init adapter structure */
273 wlan_init_adapter(priv);
275 /* init timer etc. */
276 setup_timer(&adapter->command_timer, command_timer_fn,
277 (unsigned long)priv);
279 /* download fimrware etc. */
280 if ((ret = wlan_setup_station_hw(priv)) != 0) {
281 del_timer_sync(&adapter->command_timer);
286 libertas_init_11d(priv);
290 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
294 void libertas_free_adapter(wlan_private * priv)
296 wlan_adapter *adapter = priv->adapter;
299 lbs_deb_fw("why double free adapter?\n");
303 lbs_deb_fw("free command buffer\n");
304 libertas_free_cmd_buffer(priv);
306 lbs_deb_fw("free command_timer\n");
307 del_timer(&adapter->command_timer);
309 lbs_deb_fw("free scantable\n");
310 if (adapter->scantable) {
311 kfree(adapter->scantable);
312 adapter->scantable = NULL;
315 /* Free the adapter object itself */
316 lbs_deb_fw("free adapter\n");
318 priv->adapter = NULL;
322 * This function handles the timeout of command sending.
323 * It will re-send the same command again.
325 static void command_timer_fn(unsigned long data)
327 wlan_private *priv = (wlan_private *)data;
328 wlan_adapter *adapter = priv->adapter;
329 struct cmd_ctrl_node *ptempnode;
330 struct cmd_ds_command *cmd;
333 ptempnode = adapter->cur_cmd;
334 if (ptempnode == NULL) {
335 lbs_deb_fw("ptempnode empty\n");
339 cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr;
341 lbs_deb_fw("cmd is NULL\n");
345 lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command);
347 if (!adapter->fw_ready)
350 spin_lock_irqsave(&adapter->driver_lock, flags);
351 adapter->cur_cmd = NULL;
352 spin_unlock_irqrestore(&adapter->driver_lock, flags);
354 lbs_deb_fw("re-sending same command because of timeout\n");
355 libertas_queue_cmd(adapter, ptempnode, 0);
357 wake_up_interruptible(&priv->mainthread.waitq);