2 * This file contains the initialization for FW and HW
4 #include <linux/firmware.h>
14 * @brief This function checks the validity of Boot2/FW image.
16 * @param data pointer to image
20 static int check_fwfile_format(u8 *data, u32 totlen)
23 u32 blksize, offset, len;
31 blksize = *(u32*)(data + offsetof(struct fwheader, datalength));
33 case FW_HAS_DATA_TO_RECV:
34 offset = sizeof(struct fwheader) + blksize;
40 case FW_HAS_LAST_BLOCK:
51 lbs_pr_err("firmware file format check FAIL\n");
53 lbs_deb_fw("firmware file format check PASS\n");
59 * @brief This function downloads firmware image, gets
60 * HW spec from firmware and set basic parameters to
63 * @param priv A pointer to wlan_private structure
66 static int wlan_setup_station_hw(wlan_private * priv, char *fw_name)
69 wlan_adapter *adapter = priv->adapter;
71 lbs_deb_enter(LBS_DEB_FW);
73 if ((ret = request_firmware(&priv->firmware, fw_name,
74 priv->hotplug_device)) < 0) {
75 lbs_pr_err("request_firmware() failed with %#x\n",
77 lbs_pr_err("firmware %s not found\n", fw_name);
81 if(check_fwfile_format(priv->firmware->data, priv->firmware->size)) {
82 release_firmware(priv->firmware);
86 ret = priv->hw_prog_firmware(priv);
88 release_firmware(priv->firmware);
91 lbs_deb_fw("bootloader in invalid state\n");
97 * Read MAC address from HW
99 memset(adapter->current_addr, 0xff, ETH_ALEN);
101 ret = libertas_prepare_and_send_command(priv, cmd_get_hw_spec,
102 0, cmd_option_waitforrsp, 0, NULL);
109 libertas_set_mac_packet_filter(priv);
111 /* Get the supported Data rates */
112 ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
114 cmd_option_waitforrsp, 0, NULL);
123 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
127 static int wlan_allocate_adapter(wlan_private * priv)
130 wlan_adapter *adapter = priv->adapter;
132 struct bss_descriptor *ptempscantable;
134 /* Allocate buffer to store the BSSID list */
135 ulbufsize = sizeof(struct bss_descriptor) * MRVDRV_MAX_BSSID_LIST;
136 if (!(ptempscantable = kzalloc(ulbufsize, GFP_KERNEL))) {
137 libertas_free_adapter(priv);
140 adapter->scantable = ptempscantable;
142 /* Allocate the command buffers */
143 libertas_allocate_cmd_buffer(priv);
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);
158 static void wlan_init_adapter(wlan_private * priv)
160 wlan_adapter *adapter = priv->adapter;
163 adapter->scanprobes = 0;
165 adapter->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
166 adapter->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
169 adapter->atimwindow = 0;
171 adapter->connect_status = libertas_disconnected;
172 memset(adapter->current_addr, 0xff, ETH_ALEN);
175 adapter->scantype = cmd_scan_type_active;
178 adapter->scanmode = cmd_bss_type_any;
180 /* 802.11 specific */
181 adapter->secinfo.wep_enabled = 0;
182 for (i = 0; i < sizeof(adapter->wep_keys) / sizeof(adapter->wep_keys[0]);
184 memset(&adapter->wep_keys[i], 0, sizeof(struct WLAN_802_11_KEY));
185 adapter->wep_tx_keyidx = 0;
186 adapter->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
187 adapter->mode = IW_MODE_INFRA;
189 adapter->assoc_req = NULL;
191 adapter->numinscantable = 0;
192 adapter->pattemptedbssdesc = NULL;
193 mutex_init(&adapter->lock);
195 adapter->prescan = 1;
197 memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
199 /* PnP and power profile */
200 adapter->surpriseremoved = 0;
202 adapter->currentpacketfilter =
203 cmd_act_mac_rx_on | cmd_act_mac_tx_on;
205 adapter->radioon = RADIO_ON;
206 adapter->txantenna = RF_ANTENNA_2;
207 adapter->rxantenna = RF_ANTENNA_AUTO;
209 adapter->is_datarate_auto = 1;
210 adapter->beaconperiod = MRVDRV_BEACON_INTERVAL;
212 // set default value of capinfo.
213 #define SHORT_PREAMBLE_ALLOWED 1
214 memset(&adapter->capinfo, 0, sizeof(adapter->capinfo));
215 adapter->capinfo.shortpreamble = SHORT_PREAMBLE_ALLOWED;
217 adapter->adhocchannel = DEFAULT_AD_HOC_CHANNEL;
219 adapter->psmode = wlan802_11powermodecam;
220 adapter->multipledtim = MRVDRV_DEFAULT_MULTIPLE_DTIM;
222 adapter->listeninterval = MRVDRV_DEFAULT_LISTEN_INTERVAL;
224 adapter->psstate = PS_STATE_FULL_POWER;
225 adapter->needtowakeup = 0;
226 adapter->locallisteninterval = 0; /* default value in firmware will be used */
228 adapter->datarate = 0; // Initially indicate the rate as auto
230 adapter->adhoc_grate_enabled = 0;
232 adapter->intcounter = 0;
234 adapter->currenttxskb = NULL;
235 adapter->pkttxctrl = 0;
237 memset(&adapter->tx_queue_ps, 0, NR_TX_QUEUE*sizeof(struct sk_buff*));
238 adapter->tx_queue_idx = 0;
239 spin_lock_init(&adapter->txqueue_lock);
244 static void command_timer_fn(unsigned long data);
246 int libertas_init_fw(wlan_private * priv, char *fw_name)
249 wlan_adapter *adapter = priv->adapter;
251 lbs_deb_enter(LBS_DEB_FW);
253 /* Allocate adapter structure */
254 if ((ret = wlan_allocate_adapter(priv)) != 0)
257 /* init adapter structure */
258 wlan_init_adapter(priv);
260 /* init timer etc. */
261 setup_timer(&adapter->command_timer, command_timer_fn,
262 (unsigned long)priv);
264 /* download fimrware etc. */
265 if ((ret = wlan_setup_station_hw(priv, fw_name)) != 0) {
266 del_timer_sync(&adapter->command_timer);
271 libertas_init_11d(priv);
275 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
279 void libertas_free_adapter(wlan_private * priv)
281 wlan_adapter *adapter = priv->adapter;
284 lbs_deb_fw("why double free adapter?\n");
288 lbs_deb_fw("free command buffer\n");
289 libertas_free_cmd_buffer(priv);
291 lbs_deb_fw("free command_timer\n");
292 del_timer(&adapter->command_timer);
294 lbs_deb_fw("free scantable\n");
295 if (adapter->scantable) {
296 kfree(adapter->scantable);
297 adapter->scantable = NULL;
300 /* Free the adapter object itself */
301 lbs_deb_fw("free adapter\n");
303 priv->adapter = NULL;
307 * This function handles the timeout of command sending.
308 * It will re-send the same command again.
310 static void command_timer_fn(unsigned long data)
312 wlan_private *priv = (wlan_private *)data;
313 wlan_adapter *adapter = priv->adapter;
314 struct cmd_ctrl_node *ptempnode;
315 struct cmd_ds_command *cmd;
318 ptempnode = adapter->cur_cmd;
319 if (ptempnode == NULL) {
320 lbs_deb_fw("ptempnode empty\n");
324 cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr;
326 lbs_deb_fw("cmd is NULL\n");
330 lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command);
332 if (!adapter->fw_ready)
335 spin_lock_irqsave(&adapter->driver_lock, flags);
336 adapter->cur_cmd = NULL;
337 spin_unlock_irqrestore(&adapter->driver_lock, flags);
339 lbs_deb_fw("re-sending same command because of timeout\n");
340 libertas_queue_cmd(adapter, ptempnode, 0);
342 wake_up_interruptible(&priv->mainthread.waitq);