2 * This file contains the initialization for FW and HW
4 #include <linux/moduleparam.h>
5 #include <linux/firmware.h>
15 char *libertas_fw_name = NULL;
16 module_param_named(fw_name, libertas_fw_name, charp, 0644);
19 * @brief This function checks the validity of Boot2/FW image.
21 * @param data pointer to image
25 static int check_fwfile_format(u8 *data, u32 totlen)
28 u32 blksize, offset, len;
36 blksize = *(u32*)(data + offsetof(struct fwheader, datalength));
38 case FW_HAS_DATA_TO_RECV:
39 offset = sizeof(struct fwheader) + blksize;
45 case FW_HAS_LAST_BLOCK:
56 lbs_pr_err("firmware file format check FAIL\n");
58 lbs_deb_fw("firmware file format check PASS\n");
64 * @brief This function downloads firmware image, gets
65 * HW spec from firmware and set basic parameters to
68 * @param priv A pointer to wlan_private structure
71 static int wlan_setup_station_hw(wlan_private * priv)
74 wlan_adapter *adapter = priv->adapter;
76 lbs_deb_enter(LBS_DEB_FW);
78 if ((ret = request_firmware(&priv->firmware, libertas_fw_name,
79 priv->hotplug_device)) < 0) {
80 lbs_pr_err("request_firmware() failed with %#x\n",
82 lbs_pr_err("firmware %s not found\n", libertas_fw_name);
86 if(check_fwfile_format(priv->firmware->data, priv->firmware->size)) {
87 release_firmware(priv->firmware);
91 ret = priv->hw_prog_firmware(priv);
93 release_firmware(priv->firmware);
96 lbs_deb_fw("bootloader in invalid state\n");
102 * Read MAC address from HW
104 memset(adapter->current_addr, 0xff, ETH_ALEN);
106 ret = libertas_prepare_and_send_command(priv, cmd_get_hw_spec,
107 0, cmd_option_waitforrsp, 0, NULL);
114 libertas_set_mac_packet_filter(priv);
116 /* Get the supported Data rates */
117 ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
119 cmd_option_waitforrsp, 0, NULL);
128 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
132 static int wlan_allocate_adapter(wlan_private * priv)
135 wlan_adapter *adapter = priv->adapter;
137 struct bss_descriptor *ptempscantable;
139 /* Allocate buffer to store the BSSID list */
140 ulbufsize = sizeof(struct bss_descriptor) * MRVDRV_MAX_BSSID_LIST;
141 if (!(ptempscantable = kzalloc(ulbufsize, GFP_KERNEL))) {
142 libertas_free_adapter(priv);
145 adapter->scantable = ptempscantable;
147 /* Allocate the command buffers */
148 libertas_allocate_cmd_buffer(priv);
150 memset(&adapter->libertas_ps_confirm_sleep, 0, sizeof(struct PS_CMD_ConfirmSleep));
151 adapter->libertas_ps_confirm_sleep.seqnum = cpu_to_le16(++adapter->seqnum);
152 adapter->libertas_ps_confirm_sleep.command =
153 cpu_to_le16(cmd_802_11_ps_mode);
154 adapter->libertas_ps_confirm_sleep.size =
155 cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep));
156 adapter->libertas_ps_confirm_sleep.result = 0;
157 adapter->libertas_ps_confirm_sleep.action =
158 cpu_to_le16(cmd_subcmd_sleep_confirmed);
163 static void wlan_init_adapter(wlan_private * priv)
165 wlan_adapter *adapter = priv->adapter;
168 adapter->scanprobes = 0;
170 adapter->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
171 adapter->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
174 adapter->atimwindow = 0;
176 adapter->connect_status = libertas_disconnected;
177 memset(adapter->current_addr, 0xff, ETH_ALEN);
180 adapter->scantype = cmd_scan_type_active;
183 adapter->scanmode = cmd_bss_type_any;
185 /* 802.11 specific */
186 adapter->secinfo.wep_enabled = 0;
187 for (i = 0; i < sizeof(adapter->wep_keys) / sizeof(adapter->wep_keys[0]);
189 memset(&adapter->wep_keys[i], 0, sizeof(struct WLAN_802_11_KEY));
190 adapter->wep_tx_keyidx = 0;
191 adapter->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
192 adapter->mode = IW_MODE_INFRA;
194 adapter->assoc_req = NULL;
196 adapter->numinscantable = 0;
197 adapter->pattemptedbssdesc = NULL;
198 mutex_init(&adapter->lock);
200 adapter->prescan = 1;
202 memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
204 /* PnP and power profile */
205 adapter->surpriseremoved = 0;
207 adapter->currentpacketfilter =
208 cmd_act_mac_rx_on | cmd_act_mac_tx_on;
210 adapter->radioon = RADIO_ON;
211 adapter->txantenna = RF_ANTENNA_2;
212 adapter->rxantenna = RF_ANTENNA_AUTO;
214 adapter->is_datarate_auto = 1;
215 adapter->beaconperiod = MRVDRV_BEACON_INTERVAL;
217 // set default value of capinfo.
218 #define SHORT_PREAMBLE_ALLOWED 1
219 memset(&adapter->capinfo, 0, sizeof(adapter->capinfo));
220 adapter->capinfo.shortpreamble = SHORT_PREAMBLE_ALLOWED;
222 adapter->adhocchannel = DEFAULT_AD_HOC_CHANNEL;
224 adapter->psmode = wlan802_11powermodecam;
225 adapter->multipledtim = MRVDRV_DEFAULT_MULTIPLE_DTIM;
227 adapter->listeninterval = MRVDRV_DEFAULT_LISTEN_INTERVAL;
229 adapter->psstate = PS_STATE_FULL_POWER;
230 adapter->needtowakeup = 0;
231 adapter->locallisteninterval = 0; /* default value in firmware will be used */
233 adapter->datarate = 0; // Initially indicate the rate as auto
235 adapter->adhoc_grate_enabled = 0;
237 adapter->intcounter = 0;
239 adapter->currenttxskb = NULL;
240 adapter->pkttxctrl = 0;
242 memset(&adapter->tx_queue_ps, 0, NR_TX_QUEUE*sizeof(struct sk_buff*));
243 adapter->tx_queue_idx = 0;
244 spin_lock_init(&adapter->txqueue_lock);
249 static void command_timer_fn(unsigned long data);
251 int libertas_init_fw(wlan_private * priv)
254 wlan_adapter *adapter = priv->adapter;
256 lbs_deb_enter(LBS_DEB_FW);
258 /* Allocate adapter structure */
259 if ((ret = wlan_allocate_adapter(priv)) != 0)
262 /* init adapter structure */
263 wlan_init_adapter(priv);
265 /* init timer etc. */
266 setup_timer(&adapter->command_timer, command_timer_fn,
267 (unsigned long)priv);
269 /* download fimrware etc. */
270 if ((ret = wlan_setup_station_hw(priv)) != 0) {
271 del_timer_sync(&adapter->command_timer);
276 libertas_init_11d(priv);
280 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
284 void libertas_free_adapter(wlan_private * priv)
286 wlan_adapter *adapter = priv->adapter;
289 lbs_deb_fw("why double free adapter?\n");
293 lbs_deb_fw("free command buffer\n");
294 libertas_free_cmd_buffer(priv);
296 lbs_deb_fw("free command_timer\n");
297 del_timer(&adapter->command_timer);
299 lbs_deb_fw("free scantable\n");
300 if (adapter->scantable) {
301 kfree(adapter->scantable);
302 adapter->scantable = NULL;
305 /* Free the adapter object itself */
306 lbs_deb_fw("free adapter\n");
308 priv->adapter = NULL;
312 * This function handles the timeout of command sending.
313 * It will re-send the same command again.
315 static void command_timer_fn(unsigned long data)
317 wlan_private *priv = (wlan_private *)data;
318 wlan_adapter *adapter = priv->adapter;
319 struct cmd_ctrl_node *ptempnode;
320 struct cmd_ds_command *cmd;
323 ptempnode = adapter->cur_cmd;
324 if (ptempnode == NULL) {
325 lbs_deb_fw("ptempnode empty\n");
329 cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr;
331 lbs_deb_fw("cmd is NULL\n");
335 lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command);
337 if (!adapter->fw_ready)
340 spin_lock_irqsave(&adapter->driver_lock, flags);
341 adapter->cur_cmd = NULL;
342 spin_unlock_irqrestore(&adapter->driver_lock, flags);
344 lbs_deb_fw("re-sending same command because of timeout\n");
345 libertas_queue_cmd(adapter, ptempnode, 0);
347 wake_up_interruptible(&priv->mainthread.waitq);