2 * Marvell Wireless LAN device driver: major functions
4 * Copyright (C) 2011-2014, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
27 const char driver_version
[] = "mwifiex " VERSION
" (%s) ";
28 static char *cal_data_cfg
;
29 module_param(cal_data_cfg
, charp
, 0);
31 static unsigned short driver_mode
;
32 module_param(driver_mode
, ushort
, 0);
33 MODULE_PARM_DESC(driver_mode
,
34 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
37 * This function registers the device and performs all the necessary
40 * The following initialization operations are performed -
41 * - Allocate adapter structure
42 * - Save interface specific operations table in adapter
43 * - Call interface specific initialization routine
44 * - Allocate private structures
45 * - Set default adapter structure parameters
48 * In case of any errors during inittialization, this function also ensures
49 * proper cleanup before exiting.
51 static int mwifiex_register(void *card
, struct mwifiex_if_ops
*if_ops
,
54 struct mwifiex_adapter
*adapter
;
57 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
64 /* Save interface specific operations in adapter */
65 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
67 /* card specific initialization has been deferred until now .. */
68 if (adapter
->if_ops
.init_if
)
69 if (adapter
->if_ops
.init_if(adapter
))
72 adapter
->priv_num
= 0;
74 for (i
= 0; i
< MWIFIEX_MAX_BSS_NUM
; i
++) {
75 /* Allocate memory for private structure */
77 kzalloc(sizeof(struct mwifiex_private
), GFP_KERNEL
);
78 if (!adapter
->priv
[i
])
81 adapter
->priv
[i
]->adapter
= adapter
;
84 mwifiex_init_lock_list(adapter
);
86 init_timer(&adapter
->cmd_timer
);
87 adapter
->cmd_timer
.function
= mwifiex_cmd_timeout_func
;
88 adapter
->cmd_timer
.data
= (unsigned long) adapter
;
93 dev_dbg(adapter
->dev
, "info: leave mwifiex_register with error\n");
95 for (i
= 0; i
< adapter
->priv_num
; i
++)
96 kfree(adapter
->priv
[i
]);
104 * This function unregisters the device and performs all the necessary
107 * The following cleanup operations are performed -
109 * - Free beacon buffers
110 * - Free private structures
111 * - Free adapter structure
113 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
117 if (adapter
->if_ops
.cleanup_if
)
118 adapter
->if_ops
.cleanup_if(adapter
);
120 del_timer_sync(&adapter
->cmd_timer
);
122 /* Free private structures */
123 for (i
= 0; i
< adapter
->priv_num
; i
++) {
124 if (adapter
->priv
[i
]) {
125 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
126 kfree(adapter
->priv
[i
]);
130 vfree(adapter
->chan_stats
);
135 static int mwifiex_process_rx(struct mwifiex_adapter
*adapter
)
140 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
141 if (adapter
->rx_processing
|| adapter
->rx_locked
) {
142 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
145 adapter
->rx_processing
= true;
146 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
149 /* Check for Rx data */
150 while ((skb
= skb_dequeue(&adapter
->rx_data_q
))) {
151 atomic_dec(&adapter
->rx_pending
);
152 if (adapter
->delay_main_work
&&
153 (atomic_read(&adapter
->rx_pending
) < LOW_RX_PENDING
)) {
154 if (adapter
->if_ops
.submit_rem_rx_urbs
)
155 adapter
->if_ops
.submit_rem_rx_urbs(adapter
);
156 adapter
->delay_main_work
= false;
157 queue_work(adapter
->workqueue
, &adapter
->main_work
);
159 mwifiex_handle_rx_packet(adapter
, skb
);
161 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
162 adapter
->rx_processing
= false;
163 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
172 * This function is the main procedure of the driver and handles various driver
173 * operations. It runs in a loop and provides the core functionalities.
175 * The main responsibilities of this function are -
176 * - Ensure concurrency control
177 * - Handle pending interrupts and call interrupt handlers
178 * - Wake up the card if required
179 * - Handle command responses and call response handlers
180 * - Handle events and call event handlers
181 * - Execute pending commands
182 * - Transmit pending data packets
184 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
189 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
191 /* Check if already processing */
192 if (adapter
->mwifiex_processing
) {
193 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
196 adapter
->mwifiex_processing
= true;
197 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
201 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
) ||
202 (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
))
205 /* If we process interrupts first, it would increase RX pending
206 * even further. Avoid this by checking if rx_pending has
207 * crossed high threshold and schedule rx work queue
208 * and then process interrupts
210 if (atomic_read(&adapter
->rx_pending
) >= HIGH_RX_PENDING
) {
211 adapter
->delay_main_work
= true;
212 if (!adapter
->rx_processing
)
213 queue_work(adapter
->rx_workqueue
,
218 /* Handle pending interrupt if any */
219 if (adapter
->int_status
) {
220 if (adapter
->hs_activated
)
221 mwifiex_process_hs_config(adapter
);
222 if (adapter
->if_ops
.process_int_status
)
223 adapter
->if_ops
.process_int_status(adapter
);
226 if (adapter
->rx_work_enabled
&& adapter
->data_received
)
227 queue_work(adapter
->rx_workqueue
, &adapter
->rx_work
);
229 /* Need to wake up the card ? */
230 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
231 (adapter
->pm_wakeup_card_req
&&
232 !adapter
->pm_wakeup_fw_try
) &&
233 (is_command_pending(adapter
) ||
234 !mwifiex_wmm_lists_empty(adapter
))) {
235 adapter
->pm_wakeup_fw_try
= true;
236 adapter
->if_ops
.wakeup(adapter
);
240 if (IS_CARD_RX_RCVD(adapter
)) {
241 adapter
->data_received
= false;
242 adapter
->pm_wakeup_fw_try
= false;
243 if (adapter
->ps_state
== PS_STATE_SLEEP
)
244 adapter
->ps_state
= PS_STATE_AWAKE
;
246 /* We have tried to wakeup the card already */
247 if (adapter
->pm_wakeup_fw_try
)
249 if (adapter
->ps_state
!= PS_STATE_AWAKE
||
250 adapter
->tx_lock_flag
)
253 if ((!adapter
->scan_chan_gap_enabled
&&
254 adapter
->scan_processing
) || adapter
->data_sent
||
255 mwifiex_wmm_lists_empty(adapter
)) {
256 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
257 (!is_command_pending(adapter
)))
262 /* Check for event */
263 if (adapter
->event_received
) {
264 adapter
->event_received
= false;
265 mwifiex_process_event(adapter
);
268 /* Check for Cmd Resp */
269 if (adapter
->cmd_resp_received
) {
270 adapter
->cmd_resp_received
= false;
271 mwifiex_process_cmdresp(adapter
);
273 /* call mwifiex back when init_fw is done */
274 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
275 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
276 mwifiex_init_fw_complete(adapter
);
280 /* Check if we need to confirm Sleep Request
281 received previously */
282 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) {
283 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
)
284 mwifiex_check_ps_cond(adapter
);
287 /* * The ps_state may have been changed during processing of
288 * Sleep Request event.
290 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
291 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
292 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
) ||
293 adapter
->tx_lock_flag
)
296 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
) {
297 if (mwifiex_exec_next_cmd(adapter
) == -1) {
303 if ((adapter
->scan_chan_gap_enabled
||
304 !adapter
->scan_processing
) &&
305 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
)) {
306 mwifiex_wmm_process_tx(adapter
);
307 if (adapter
->hs_activated
) {
308 adapter
->is_hs_configured
= false;
309 mwifiex_hs_activated_event
311 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
316 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
317 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
318 mwifiex_wmm_lists_empty(adapter
)) {
319 if (!mwifiex_send_null_packet
320 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
321 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
322 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
323 adapter
->delay_null_pkt
= false;
324 adapter
->ps_state
= PS_STATE_SLEEP
;
330 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
331 if (!adapter
->delay_main_work
&&
332 (adapter
->int_status
|| IS_CARD_RX_RCVD(adapter
))) {
333 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
337 adapter
->mwifiex_processing
= false;
338 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
341 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
)
342 mwifiex_shutdown_drv(adapter
);
345 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
348 * This function frees the adapter structure.
350 * Additionally, this closes the netlink socket, frees the timers
351 * and private structures.
353 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
356 pr_err("%s: adapter is NULL\n", __func__
);
360 mwifiex_unregister(adapter
);
361 pr_debug("info: %s: free adapter\n", __func__
);
365 * This function cancels all works in the queue and destroys
366 * the main workqueue.
368 static void mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
370 flush_workqueue(adapter
->workqueue
);
371 destroy_workqueue(adapter
->workqueue
);
372 adapter
->workqueue
= NULL
;
374 if (adapter
->rx_workqueue
) {
375 flush_workqueue(adapter
->rx_workqueue
);
376 destroy_workqueue(adapter
->rx_workqueue
);
377 adapter
->rx_workqueue
= NULL
;
382 * This function gets firmware and initializes it.
384 * The main initialization steps followed are -
385 * - Download the correct firmware to card
386 * - Issue the init commands to firmware
388 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
392 struct mwifiex_private
*priv
;
393 struct mwifiex_adapter
*adapter
= context
;
394 struct mwifiex_fw_image fw
;
395 struct semaphore
*sem
= adapter
->card_sem
;
396 bool init_failed
= false;
397 struct wireless_dev
*wdev
;
400 dev_err(adapter
->dev
,
401 "Failed to get firmware %s\n", adapter
->fw_name
);
405 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
406 adapter
->firmware
= firmware
;
407 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
408 fw
.fw_len
= adapter
->firmware
->size
;
410 if (adapter
->if_ops
.dnld_fw
)
411 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
413 ret
= mwifiex_dnld_fw(adapter
, &fw
);
417 dev_notice(adapter
->dev
, "WLAN FW is active\n");
420 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
422 dev_err(adapter
->dev
,
423 "Cal data request_firmware() failed\n");
426 /* enable host interrupt after fw dnld is successful */
427 if (adapter
->if_ops
.enable_int
) {
428 if (adapter
->if_ops
.enable_int(adapter
))
432 adapter
->init_wait_q_woken
= false;
433 ret
= mwifiex_init_fw(adapter
);
437 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
440 /* Wait for mwifiex_init to complete */
441 wait_event_interruptible(adapter
->init_wait_q
,
442 adapter
->init_wait_q_woken
);
443 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
)
446 priv
= adapter
->priv
[MWIFIEX_BSS_ROLE_STA
];
447 if (mwifiex_register_cfg80211(adapter
)) {
448 dev_err(adapter
->dev
, "cannot register with cfg80211\n");
452 if (mwifiex_init_channel_scan_gap(adapter
)) {
453 dev_err(adapter
->dev
, "could not init channel stats table\n");
458 driver_mode
&= MWIFIEX_DRIVER_MODE_BITMASK
;
459 driver_mode
|= MWIFIEX_DRIVER_MODE_STA
;
463 /* Create station interface by default */
464 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d",
465 NL80211_IFTYPE_STATION
, NULL
, NULL
);
467 dev_err(adapter
->dev
, "cannot create default STA interface\n");
472 if (driver_mode
& MWIFIEX_DRIVER_MODE_UAP
) {
473 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "uap%d",
474 NL80211_IFTYPE_AP
, NULL
, NULL
);
476 dev_err(adapter
->dev
, "cannot create AP interface\n");
482 if (driver_mode
& MWIFIEX_DRIVER_MODE_P2P
) {
483 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "p2p%d",
484 NL80211_IFTYPE_P2P_CLIENT
, NULL
,
487 dev_err(adapter
->dev
,
488 "cannot create p2p client interface\n");
495 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
496 dev_notice(adapter
->dev
, "driver_version = %s\n", fmt
);
500 wiphy_unregister(adapter
->wiphy
);
501 wiphy_free(adapter
->wiphy
);
503 if (adapter
->if_ops
.disable_int
)
504 adapter
->if_ops
.disable_int(adapter
);
506 pr_debug("info: %s: unregister device\n", __func__
);
507 if (adapter
->if_ops
.unregister_dev
)
508 adapter
->if_ops
.unregister_dev(adapter
);
510 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
511 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
512 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
513 adapter
->init_wait_q_woken
= false;
515 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
516 wait_event_interruptible(adapter
->init_wait_q
,
517 adapter
->init_wait_q_woken
);
519 adapter
->surprise_removed
= true;
520 mwifiex_terminate_workqueue(adapter
);
523 if (adapter
->cal_data
) {
524 release_firmware(adapter
->cal_data
);
525 adapter
->cal_data
= NULL
;
527 if (adapter
->firmware
) {
528 release_firmware(adapter
->firmware
);
529 adapter
->firmware
= NULL
;
532 mwifiex_free_adapter(adapter
);
538 * This function initializes the hardware and gets firmware.
540 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
)
544 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
545 adapter
->dev
, GFP_KERNEL
, adapter
,
548 dev_err(adapter
->dev
,
549 "request_firmware_nowait() returned error %d\n", ret
);
554 * CFG802.11 network device handler for open.
556 * Starts the data queue.
559 mwifiex_open(struct net_device
*dev
)
561 netif_tx_start_all_queues(dev
);
566 * CFG802.11 network device handler for close.
569 mwifiex_close(struct net_device
*dev
)
571 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
573 if (priv
->scan_request
) {
574 dev_dbg(priv
->adapter
->dev
, "aborting scan on ndo_stop\n");
575 cfg80211_scan_done(priv
->scan_request
, 1);
576 priv
->scan_request
= NULL
;
577 priv
->scan_aborting
= true;
584 * Add buffer into wmm tx queue and queue work to transmit it.
586 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
588 struct netdev_queue
*txq
;
589 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
591 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
592 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
593 if (!netif_tx_queue_stopped(txq
)) {
594 netif_tx_stop_queue(txq
);
595 dev_dbg(priv
->adapter
->dev
, "stop queue: %d\n", index
);
599 atomic_inc(&priv
->adapter
->tx_pending
);
600 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
602 queue_work(priv
->adapter
->workqueue
, &priv
->adapter
->main_work
);
608 * CFG802.11 network device handler for data transmission.
611 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
613 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
614 struct sk_buff
*new_skb
;
615 struct mwifiex_txinfo
*tx_info
;
617 dev_dbg(priv
->adapter
->dev
, "data: %lu BSS(%d-%d): Data <= kernel\n",
618 jiffies
, priv
->bss_type
, priv
->bss_num
);
620 if (priv
->adapter
->surprise_removed
) {
622 priv
->stats
.tx_dropped
++;
625 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
626 dev_err(priv
->adapter
->dev
, "Tx: bad skb len %d\n", skb
->len
);
628 priv
->stats
.tx_dropped
++;
631 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
632 dev_dbg(priv
->adapter
->dev
,
633 "data: Tx: insufficient skb headroom %d\n",
635 /* Insufficient skb headroom - allocate a new skb */
637 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
638 if (unlikely(!new_skb
)) {
639 dev_err(priv
->adapter
->dev
, "Tx: cannot alloca new_skb\n");
641 priv
->stats
.tx_dropped
++;
646 dev_dbg(priv
->adapter
->dev
, "info: new skb headroomd %d\n",
650 tx_info
= MWIFIEX_SKB_TXCB(skb
);
651 memset(tx_info
, 0, sizeof(*tx_info
));
652 tx_info
->bss_num
= priv
->bss_num
;
653 tx_info
->bss_type
= priv
->bss_type
;
654 tx_info
->pkt_len
= skb
->len
;
656 /* Record the current time the packet was queued; used to
657 * determine the amount of time the packet was queued in
658 * the driver before it was sent to the firmware.
659 * The delay is then sent along with the packet to the
660 * firmware for aggregate delay calculation for stats and
661 * MSDU lifetime expiry.
663 __net_timestamp(skb
);
665 if (ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
666 priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
&&
667 !ether_addr_equal_unaligned(priv
->cfg_bssid
, skb
->data
)) {
668 if (priv
->adapter
->auto_tdls
&& priv
->check_tdls_tx
)
669 mwifiex_tdls_check_tx(priv
, skb
);
672 mwifiex_queue_tx_pkt(priv
, skb
);
678 * CFG802.11 network device handler for setting MAC address.
681 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
683 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
684 struct sockaddr
*hw_addr
= addr
;
687 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
689 /* Send request to firmware */
690 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
691 HostCmd_ACT_GEN_SET
, 0, NULL
, true);
694 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
696 dev_err(priv
->adapter
->dev
,
697 "set mac address failed: ret=%d\n", ret
);
699 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
705 * CFG802.11 network device handler for setting multicast list.
707 static void mwifiex_set_multicast_list(struct net_device
*dev
)
709 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
710 struct mwifiex_multicast_list mcast_list
;
712 if (dev
->flags
& IFF_PROMISC
) {
713 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
714 } else if (dev
->flags
& IFF_ALLMULTI
||
715 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
716 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
718 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
719 mcast_list
.num_multicast_addr
=
720 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
722 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
726 * CFG802.11 network device handler for transmission timeout.
729 mwifiex_tx_timeout(struct net_device
*dev
)
731 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
733 priv
->num_tx_timeout
++;
734 priv
->tx_timeout_cnt
++;
735 dev_err(priv
->adapter
->dev
,
736 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
737 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
, priv
->bss_num
);
738 mwifiex_set_trans_start(dev
);
740 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
741 priv
->adapter
->if_ops
.card_reset
) {
742 dev_err(priv
->adapter
->dev
,
743 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
744 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
749 * CFG802.11 network device handler for statistics retrieval.
751 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
753 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
759 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
,
760 void *accel_priv
, select_queue_fallback_t fallback
)
762 skb
->priority
= cfg80211_classify8021d(skb
, NULL
);
763 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
766 /* Network device handlers */
767 static const struct net_device_ops mwifiex_netdev_ops
= {
768 .ndo_open
= mwifiex_open
,
769 .ndo_stop
= mwifiex_close
,
770 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
771 .ndo_set_mac_address
= mwifiex_set_mac_address
,
772 .ndo_tx_timeout
= mwifiex_tx_timeout
,
773 .ndo_get_stats
= mwifiex_get_stats
,
774 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
775 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
779 * This function initializes the private structure parameters.
781 * The following wait queues are initialized -
783 * - Command wait queue
784 * - Statistics wait queue
786 * ...and the following default parameters are set -
787 * - Current key index : Set to 0
788 * - Rate index : Set to auto
789 * - Media connected : Set to disconnected
790 * - Adhoc link sensed : Set to false
791 * - Nick name : Set to null
792 * - Number of Tx timeout : Set to 0
793 * - Device address : Set to current address
795 * In addition, the CFG80211 work queue is also created.
797 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
798 struct net_device
*dev
)
800 dev
->netdev_ops
= &mwifiex_netdev_ops
;
801 dev
->destructor
= free_netdev
;
802 /* Initialize private structure */
803 priv
->current_key_index
= 0;
804 priv
->media_connected
= false;
805 memset(&priv
->nick_name
, 0, sizeof(priv
->nick_name
));
806 memset(priv
->mgmt_ie
, 0,
807 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
808 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
809 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
810 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
811 priv
->rsn_idx
= MWIFIEX_AUTO_IDX_MASK
;
812 priv
->num_tx_timeout
= 0;
813 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
817 * This function check if command is pending.
819 int is_command_pending(struct mwifiex_adapter
*adapter
)
822 int is_cmd_pend_q_empty
;
824 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
825 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
826 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
828 return !is_cmd_pend_q_empty
;
832 * This is the RX work queue function.
834 * It handles the RX operations.
836 static void mwifiex_rx_work_queue(struct work_struct
*work
)
838 struct mwifiex_adapter
*adapter
=
839 container_of(work
, struct mwifiex_adapter
, rx_work
);
841 if (adapter
->surprise_removed
)
843 mwifiex_process_rx(adapter
);
847 * This is the main work queue function.
849 * It handles the main process, which in turn handles the complete
852 static void mwifiex_main_work_queue(struct work_struct
*work
)
854 struct mwifiex_adapter
*adapter
=
855 container_of(work
, struct mwifiex_adapter
, main_work
);
857 if (adapter
->surprise_removed
)
859 mwifiex_main_process(adapter
);
863 * This function adds the card.
865 * This function follows the following major steps to set up the device -
866 * - Initialize software. This includes probing the card, registering
867 * the interface operations table, and allocating/initializing the
869 * - Set up the netlink socket
870 * - Create and start the main work queue
871 * - Register the device
872 * - Initialize firmware and hardware
873 * - Add logical interfaces
876 mwifiex_add_card(void *card
, struct semaphore
*sem
,
877 struct mwifiex_if_ops
*if_ops
, u8 iface_type
)
879 struct mwifiex_adapter
*adapter
;
881 if (down_interruptible(sem
))
884 if (mwifiex_register(card
, if_ops
, (void **)&adapter
)) {
885 pr_err("%s: software init failed\n", __func__
);
889 adapter
->iface_type
= iface_type
;
890 adapter
->card_sem
= sem
;
892 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
893 adapter
->surprise_removed
= false;
894 init_waitqueue_head(&adapter
->init_wait_q
);
895 adapter
->is_suspended
= false;
896 adapter
->hs_activated
= false;
897 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
898 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
899 adapter
->cmd_wait_q
.status
= 0;
900 adapter
->scan_wait_q_woken
= false;
902 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
) {
903 adapter
->rx_work_enabled
= true;
904 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
908 alloc_workqueue("MWIFIEX_WORK_QUEUE",
909 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
910 if (!adapter
->workqueue
)
913 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
915 if (adapter
->rx_work_enabled
) {
916 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
920 if (!adapter
->rx_workqueue
)
923 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
926 if (adapter
->if_ops
.iface_work
)
927 INIT_WORK(&adapter
->iface_work
, adapter
->if_ops
.iface_work
);
929 /* Register the device. Fill up the private data structure with relevant
930 information from the card. */
931 if (adapter
->if_ops
.register_dev(adapter
)) {
932 pr_err("%s: failed to register mwifiex device\n", __func__
);
933 goto err_registerdev
;
936 if (mwifiex_init_hw_fw(adapter
)) {
937 pr_err("%s: firmware init failed\n", __func__
);
944 pr_debug("info: %s: unregister device\n", __func__
);
945 if (adapter
->if_ops
.unregister_dev
)
946 adapter
->if_ops
.unregister_dev(adapter
);
947 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
948 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
949 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
950 adapter
->init_wait_q_woken
= false;
952 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
953 wait_event_interruptible(adapter
->init_wait_q
,
954 adapter
->init_wait_q_woken
);
957 adapter
->surprise_removed
= true;
958 mwifiex_terminate_workqueue(adapter
);
960 mwifiex_free_adapter(adapter
);
968 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
971 * This function removes the card.
973 * This function follows the following major steps to remove the device -
974 * - Stop data traffic
975 * - Shutdown firmware
976 * - Remove the logical interfaces
977 * - Terminate the work queue
978 * - Unregister the device
979 * - Free the adapter structure
981 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
, struct semaphore
*sem
)
983 struct mwifiex_private
*priv
= NULL
;
986 if (down_interruptible(sem
))
992 /* We can no longer handle interrupts once we start doing the teardown
994 if (adapter
->if_ops
.disable_int
)
995 adapter
->if_ops
.disable_int(adapter
);
997 adapter
->surprise_removed
= true;
1000 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1001 priv
= adapter
->priv
[i
];
1002 if (priv
&& priv
->netdev
) {
1003 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
1004 if (netif_carrier_ok(priv
->netdev
))
1005 netif_carrier_off(priv
->netdev
);
1009 dev_dbg(adapter
->dev
, "cmd: calling mwifiex_shutdown_drv...\n");
1010 adapter
->init_wait_q_woken
= false;
1012 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
1013 wait_event_interruptible(adapter
->init_wait_q
,
1014 adapter
->init_wait_q_woken
);
1015 dev_dbg(adapter
->dev
, "cmd: mwifiex_shutdown_drv done\n");
1016 if (atomic_read(&adapter
->rx_pending
) ||
1017 atomic_read(&adapter
->tx_pending
) ||
1018 atomic_read(&adapter
->cmd_pending
)) {
1019 dev_err(adapter
->dev
, "rx_pending=%d, tx_pending=%d, "
1021 atomic_read(&adapter
->rx_pending
),
1022 atomic_read(&adapter
->tx_pending
),
1023 atomic_read(&adapter
->cmd_pending
));
1026 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1027 priv
= adapter
->priv
[i
];
1033 if (priv
->wdev
&& priv
->netdev
)
1034 mwifiex_del_virtual_intf(adapter
->wiphy
, priv
->wdev
);
1038 wiphy_unregister(adapter
->wiphy
);
1039 wiphy_free(adapter
->wiphy
);
1041 mwifiex_terminate_workqueue(adapter
);
1043 /* Unregister device */
1044 dev_dbg(adapter
->dev
, "info: unregister device\n");
1045 if (adapter
->if_ops
.unregister_dev
)
1046 adapter
->if_ops
.unregister_dev(adapter
);
1047 /* Free adapter structure */
1048 dev_dbg(adapter
->dev
, "info: free adapter\n");
1049 mwifiex_free_adapter(adapter
);
1056 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1059 * This function initializes the module.
1061 * The debug FS is also initialized if configured.
1064 mwifiex_init_module(void)
1066 #ifdef CONFIG_DEBUG_FS
1067 mwifiex_debugfs_init();
1073 * This function cleans up the module.
1075 * The debug FS is removed if available.
1078 mwifiex_cleanup_module(void)
1080 #ifdef CONFIG_DEBUG_FS
1081 mwifiex_debugfs_remove();
1085 module_init(mwifiex_init_module
);
1086 module_exit(mwifiex_cleanup_module
);
1088 MODULE_AUTHOR("Marvell International Ltd.");
1089 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1090 MODULE_VERSION(VERSION
);
1091 MODULE_LICENSE("GPL v2");