2 * Marvell Wireless LAN device driver: major functions
4 * Copyright (C) 2011, 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) ";
29 struct mwifiex_adapter
*g_adapter
;
30 EXPORT_SYMBOL_GPL(g_adapter
);
32 static struct mwifiex_bss_attr mwifiex_bss_sta
[] = {
33 {MWIFIEX_BSS_TYPE_STA
, MWIFIEX_DATA_FRAME_TYPE_ETH_II
, true, 0, 0},
36 static int drv_mode
= DRV_MODE_STA
;
38 static char fw_name
[32] = DEFAULT_FW_NAME
;
40 /* Supported drv_mode table */
41 static struct mwifiex_drv_mode mwifiex_drv_mode_tbl
[] = {
43 .drv_mode
= DRV_MODE_STA
,
44 .intf_num
= ARRAY_SIZE(mwifiex_bss_sta
),
45 .bss_attr
= mwifiex_bss_sta
,
50 * This function registers the device and performs all the necessary
53 * The following initialization operations are performed -
54 * - Allocate adapter structure
55 * - Save interface specific operations table in adapter
56 * - Call interface specific initialization routine
57 * - Allocate private structures
58 * - Set default adapter structure parameters
61 * In case of any errors during inittialization, this function also ensures
62 * proper cleanup before exiting.
64 static int mwifiex_register(void *card
, struct mwifiex_if_ops
*if_ops
,
65 struct mwifiex_drv_mode
*drv_mode_ptr
)
67 struct mwifiex_adapter
*adapter
;
70 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
77 /* Save interface specific operations in adapter */
78 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
80 /* card specific initialization has been deferred until now .. */
81 if (adapter
->if_ops
.init_if(adapter
))
84 adapter
->priv_num
= 0;
85 for (i
= 0; i
< drv_mode_ptr
->intf_num
; i
++) {
86 adapter
->priv
[i
] = NULL
;
88 if (!drv_mode_ptr
->bss_attr
[i
].active
)
91 /* Allocate memory for private structure */
92 adapter
->priv
[i
] = kzalloc(sizeof(struct mwifiex_private
),
94 if (!adapter
->priv
[i
]) {
95 dev_err(adapter
->dev
, "%s: failed to alloc priv[%d]\n",
101 adapter
->priv
[i
]->adapter
= adapter
;
102 /* Save bss_type, frame_type & bss_priority */
103 adapter
->priv
[i
]->bss_type
= drv_mode_ptr
->bss_attr
[i
].bss_type
;
104 adapter
->priv
[i
]->frame_type
=
105 drv_mode_ptr
->bss_attr
[i
].frame_type
;
106 adapter
->priv
[i
]->bss_priority
=
107 drv_mode_ptr
->bss_attr
[i
].bss_priority
;
109 if (drv_mode_ptr
->bss_attr
[i
].bss_type
== MWIFIEX_BSS_TYPE_STA
)
110 adapter
->priv
[i
]->bss_role
= MWIFIEX_BSS_ROLE_STA
;
111 else if (drv_mode_ptr
->bss_attr
[i
].bss_type
==
112 MWIFIEX_BSS_TYPE_UAP
)
113 adapter
->priv
[i
]->bss_role
= MWIFIEX_BSS_ROLE_UAP
;
115 /* Save bss_index & bss_num */
116 adapter
->priv
[i
]->bss_index
= i
;
117 adapter
->priv
[i
]->bss_num
= drv_mode_ptr
->bss_attr
[i
].bss_num
;
119 adapter
->drv_mode
= drv_mode_ptr
;
121 if (mwifiex_init_lock_list(adapter
))
124 init_timer(&adapter
->cmd_timer
);
125 adapter
->cmd_timer
.function
= mwifiex_cmd_timeout_func
;
126 adapter
->cmd_timer
.data
= (unsigned long) adapter
;
131 dev_dbg(adapter
->dev
, "info: leave mwifiex_register with error\n");
133 mwifiex_free_lock_list(adapter
);
134 for (i
= 0; i
< drv_mode_ptr
->intf_num
; i
++)
135 kfree(adapter
->priv
[i
]);
142 * This function unregisters the device and performs all the necessary
145 * The following cleanup operations are performed -
147 * - Free beacon buffers
148 * - Free private structures
149 * - Free adapter structure
151 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
155 del_timer(&adapter
->cmd_timer
);
157 /* Free private structures */
158 for (i
= 0; i
< adapter
->priv_num
; i
++) {
159 if (adapter
->priv
[i
]) {
160 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
161 kfree(adapter
->priv
[i
]);
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 /* Handle pending interrupt if any */
206 if (adapter
->int_status
) {
207 if (adapter
->hs_activated
)
208 mwifiex_process_hs_config(adapter
);
209 adapter
->if_ops
.process_int_status(adapter
);
212 /* Need to wake up the card ? */
213 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
214 (adapter
->pm_wakeup_card_req
&&
215 !adapter
->pm_wakeup_fw_try
) &&
216 (is_command_pending(adapter
)
217 || !mwifiex_wmm_lists_empty(adapter
))) {
218 adapter
->pm_wakeup_fw_try
= true;
219 adapter
->if_ops
.wakeup(adapter
);
222 if (IS_CARD_RX_RCVD(adapter
)) {
223 adapter
->pm_wakeup_fw_try
= false;
224 if (adapter
->ps_state
== PS_STATE_SLEEP
)
225 adapter
->ps_state
= PS_STATE_AWAKE
;
227 /* We have tried to wakeup the card already */
228 if (adapter
->pm_wakeup_fw_try
)
230 if (adapter
->ps_state
!= PS_STATE_AWAKE
||
231 adapter
->tx_lock_flag
)
234 if (adapter
->scan_processing
|| adapter
->data_sent
235 || mwifiex_wmm_lists_empty(adapter
)) {
236 if (adapter
->cmd_sent
|| adapter
->curr_cmd
237 || (!is_command_pending(adapter
)))
242 /* Check for Cmd Resp */
243 if (adapter
->cmd_resp_received
) {
244 adapter
->cmd_resp_received
= false;
245 mwifiex_process_cmdresp(adapter
);
247 /* call mwifiex back when init_fw is done */
248 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
249 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
250 mwifiex_init_fw_complete(adapter
);
254 /* Check for event */
255 if (adapter
->event_received
) {
256 adapter
->event_received
= false;
257 mwifiex_process_event(adapter
);
260 /* Check if we need to confirm Sleep Request
261 received previously */
262 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) {
263 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
)
264 mwifiex_check_ps_cond(adapter
);
267 /* * The ps_state may have been changed during processing of
268 * Sleep Request event.
270 if ((adapter
->ps_state
== PS_STATE_SLEEP
)
271 || (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
272 || (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)
273 || adapter
->tx_lock_flag
)
276 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
) {
277 if (mwifiex_exec_next_cmd(adapter
) == -1) {
283 if (!adapter
->scan_processing
&& !adapter
->data_sent
&&
284 !mwifiex_wmm_lists_empty(adapter
)) {
285 mwifiex_wmm_process_tx(adapter
);
286 if (adapter
->hs_activated
) {
287 adapter
->is_hs_configured
= false;
288 mwifiex_hs_activated_event
290 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
295 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
296 !adapter
->curr_cmd
&& !is_command_pending(adapter
)
297 && mwifiex_wmm_lists_empty(adapter
)) {
298 if (!mwifiex_send_null_packet
299 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
300 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
301 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
302 adapter
->delay_null_pkt
= false;
303 adapter
->ps_state
= PS_STATE_SLEEP
;
309 if ((adapter
->int_status
) || IS_CARD_RX_RCVD(adapter
))
312 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
313 adapter
->mwifiex_processing
= false;
314 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
317 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
)
318 mwifiex_shutdown_drv(adapter
);
323 * This function initializes the software.
325 * The main work includes allocating and initializing the adapter structure
326 * and initializing the private structures.
329 mwifiex_init_sw(void *card
, struct mwifiex_if_ops
*if_ops
)
332 struct mwifiex_drv_mode
*drv_mode_ptr
;
334 /* find mwifiex_drv_mode entry from mwifiex_drv_mode_tbl */
336 for (i
= 0; i
< ARRAY_SIZE(mwifiex_drv_mode_tbl
); i
++) {
337 if (mwifiex_drv_mode_tbl
[i
].drv_mode
== drv_mode
) {
338 drv_mode_ptr
= &mwifiex_drv_mode_tbl
[i
];
344 pr_err("invalid drv_mode=%d\n", drv_mode
);
348 if (mwifiex_register(card
, if_ops
, drv_mode_ptr
))
355 * This function frees the adapter structure.
357 * Additionally, this closes the netlink socket, frees the timers
358 * and private structures.
360 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
363 pr_err("%s: adapter is NULL\n", __func__
);
367 mwifiex_unregister(adapter
);
368 pr_debug("info: %s: free adapter\n", __func__
);
372 * This function initializes the hardware and firmware.
374 * The main initialization steps followed are -
375 * - Download the correct firmware to card
376 * - Allocate and initialize the adapter structure
377 * - Initialize the private structures
378 * - Issue the init commands to firmware
380 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
)
384 struct mwifiex_fw_image fw
;
386 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
388 switch (adapter
->revision_id
) {
391 strcpy(fw_name
, SD8787_W1_FW_NAME
);
395 strcpy(fw_name
, SD8787_AX_FW_NAME
);
401 err
= request_firmware(&adapter
->firmware
, fw_name
, adapter
->dev
);
403 dev_err(adapter
->dev
, "request_firmware() returned"
404 " error code %#x\n", err
);
408 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
409 fw
.fw_len
= adapter
->firmware
->size
;
411 ret
= mwifiex_dnld_fw(adapter
, &fw
);
415 dev_notice(adapter
->dev
, "WLAN FW is active\n");
417 adapter
->init_wait_q_woken
= false;
418 ret
= mwifiex_init_fw(adapter
);
422 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
425 /* Wait for mwifiex_init to complete */
426 wait_event_interruptible(adapter
->init_wait_q
,
427 adapter
->init_wait_q_woken
);
428 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
) {
435 if (adapter
->firmware
)
436 release_firmware(adapter
->firmware
);
443 * This function fills a driver buffer.
445 * The function associates a given SKB with the provided driver buffer
446 * and also updates some of the SKB parameters, including IP header,
447 * priority and timestamp.
450 mwifiex_fill_buffer(struct sk_buff
*skb
)
452 struct ethhdr
*eth
= NULL
;
457 eth
= (struct ethhdr
*) skb
->data
;
458 switch (eth
->h_proto
) {
459 case __constant_htons(ETH_P_IP
):
461 tid
= IPTOS_PREC(iph
->tos
);
462 pr_debug("data: packet type ETH_P_IP: %04x, tid=%#x prio=%#x\n",
463 eth
->h_proto
, tid
, skb
->priority
);
465 case __constant_htons(ETH_P_ARP
):
466 pr_debug("data: ARP packet: %04x\n", eth
->h_proto
);
470 /* Offset for TOS field in the IP header */
471 #define IPTOS_OFFSET 5
472 tid
= (tid
>> IPTOS_OFFSET
);
474 /* Record the current time the packet was queued; used to
475 determine the amount of time the packet was queued in
476 the driver before it was sent to the firmware.
477 The delay is then sent along with the packet to the
478 firmware for aggregate delay calculation for stats and
479 MSDU lifetime expiry.
481 do_gettimeofday(&tv
);
482 skb
->tstamp
= timeval_to_ktime(tv
);
486 * CFG802.11 network device handler for open.
488 * Starts the data queue.
491 mwifiex_open(struct net_device
*dev
)
493 netif_start_queue(dev
);
498 * CFG802.11 network device handler for close.
501 mwifiex_close(struct net_device
*dev
)
507 * CFG802.11 network device handler for data transmission.
510 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
512 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
513 struct sk_buff
*new_skb
= NULL
;
514 struct mwifiex_txinfo
*tx_info
;
516 dev_dbg(priv
->adapter
->dev
, "data: %lu BSS(%d): Data <= kernel\n",
517 jiffies
, priv
->bss_index
);
519 if (priv
->adapter
->surprise_removed
) {
521 priv
->stats
.tx_dropped
++;
524 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
525 dev_err(priv
->adapter
->dev
, "Tx: bad skb len %d\n", skb
->len
);
527 priv
->stats
.tx_dropped
++;
530 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
531 dev_dbg(priv
->adapter
->dev
,
532 "data: Tx: insufficient skb headroom %d\n",
534 /* Insufficient skb headroom - allocate a new skb */
536 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
537 if (unlikely(!new_skb
)) {
538 dev_err(priv
->adapter
->dev
, "Tx: cannot alloca new_skb\n");
540 priv
->stats
.tx_dropped
++;
545 dev_dbg(priv
->adapter
->dev
, "info: new skb headroomd %d\n",
549 tx_info
= MWIFIEX_SKB_TXCB(skb
);
550 tx_info
->bss_index
= priv
->bss_index
;
551 mwifiex_fill_buffer(skb
);
553 mwifiex_wmm_add_buf_txqueue(priv
->adapter
, skb
);
554 atomic_inc(&priv
->adapter
->tx_pending
);
556 if (atomic_read(&priv
->adapter
->tx_pending
) >= MAX_TX_PENDING
) {
557 netif_stop_queue(priv
->netdev
);
558 dev
->trans_start
= jiffies
;
561 queue_work(priv
->adapter
->workqueue
, &priv
->adapter
->main_work
);
567 * CFG802.11 network device handler for setting MAC address.
570 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
572 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
573 struct sockaddr
*hw_addr
= (struct sockaddr
*) addr
;
576 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
578 /* Send request to firmware */
579 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
580 HostCmd_ACT_GEN_SET
, 0, NULL
);
583 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
585 dev_err(priv
->adapter
->dev
, "set mac address failed: ret=%d"
588 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
594 * CFG802.11 network device handler for setting multicast list.
596 static void mwifiex_set_multicast_list(struct net_device
*dev
)
598 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
599 struct mwifiex_multicast_list mcast_list
;
601 if (dev
->flags
& IFF_PROMISC
) {
602 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
603 } else if (dev
->flags
& IFF_ALLMULTI
||
604 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
605 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
607 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
608 if (netdev_mc_count(dev
))
609 mcast_list
.num_multicast_addr
=
610 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
612 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
616 * CFG802.11 network device handler for transmission timeout.
619 mwifiex_tx_timeout(struct net_device
*dev
)
621 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
623 dev_err(priv
->adapter
->dev
, "%lu : Tx timeout, bss_index=%d\n",
624 jiffies
, priv
->bss_index
);
625 dev
->trans_start
= jiffies
;
626 priv
->num_tx_timeout
++;
630 * CFG802.11 network device handler for statistics retrieval.
632 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
634 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
639 /* Network device handlers */
640 static const struct net_device_ops mwifiex_netdev_ops
= {
641 .ndo_open
= mwifiex_open
,
642 .ndo_stop
= mwifiex_close
,
643 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
644 .ndo_set_mac_address
= mwifiex_set_mac_address
,
645 .ndo_tx_timeout
= mwifiex_tx_timeout
,
646 .ndo_get_stats
= mwifiex_get_stats
,
647 .ndo_set_multicast_list
= mwifiex_set_multicast_list
,
651 * This function initializes the private structure parameters.
653 * The following wait queues are initialized -
655 * - Command wait queue
656 * - Statistics wait queue
658 * ...and the following default parameters are set -
659 * - Current key index : Set to 0
660 * - Rate index : Set to auto
661 * - Media connected : Set to disconnected
662 * - Adhoc link sensed : Set to false
663 * - Nick name : Set to null
664 * - Number of Tx timeout : Set to 0
665 * - Device address : Set to current address
667 * In addition, the CFG80211 work queue is also created.
670 mwifiex_init_priv_params(struct mwifiex_private
*priv
, struct net_device
*dev
)
672 dev
->netdev_ops
= &mwifiex_netdev_ops
;
673 /* Initialize private structure */
674 priv
->current_key_index
= 0;
675 priv
->media_connected
= false;
676 memset(&priv
->nick_name
, 0, sizeof(priv
->nick_name
));
677 priv
->num_tx_timeout
= 0;
678 priv
->workqueue
= create_singlethread_workqueue("cfg80211_wq");
679 INIT_WORK(&priv
->cfg_workqueue
, mwifiex_cfg80211_results
);
680 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
684 * This function adds a new logical interface.
686 * It allocates, initializes and registers the interface by performing
687 * the following opearations -
688 * - Allocate a new net device structure
689 * - Assign device name
690 * - Register the new device with CFG80211 subsystem
691 * - Initialize semaphore and private structure
692 * - Register the new device with kernel
693 * - Create the complete debug FS structure if configured
695 static struct mwifiex_private
*mwifiex_add_interface(
696 struct mwifiex_adapter
*adapter
,
697 u8 bss_index
, u8 bss_type
)
699 struct net_device
*dev
= NULL
;
700 struct mwifiex_private
*priv
= NULL
;
701 void *mdev_priv
= NULL
;
703 dev
= alloc_netdev_mq(sizeof(struct mwifiex_private
*), "mlan%d",
706 dev_err(adapter
->dev
, "no memory available for netdevice\n");
709 if (dev_alloc_name(dev
, dev
->name
)) {
710 dev_err(adapter
->dev
, "unable to alloc name for netdevice\n");
714 if (mwifiex_register_cfg80211(dev
, adapter
->priv
[bss_index
]->curr_addr
,
715 adapter
->priv
[bss_index
]) != 0) {
716 dev_err(adapter
->dev
, "cannot register netdevice with cfg80211\n");
719 /* Save the priv pointer in netdev */
720 priv
= adapter
->priv
[bss_index
];
721 mdev_priv
= netdev_priv(dev
);
722 *((unsigned long *) mdev_priv
) = (unsigned long) priv
;
726 sema_init(&priv
->async_sem
, 1);
727 priv
->scan_pending_on_block
= false;
729 mwifiex_init_priv_params(priv
, dev
);
731 SET_NETDEV_DEV(dev
, adapter
->dev
);
733 /* Register network device */
734 if (register_netdev(dev
)) {
735 dev_err(adapter
->dev
, "cannot register virtual network device\n");
739 dev_dbg(adapter
->dev
, "info: %s: Marvell 802.11 Adapter\n", dev
->name
);
740 #ifdef CONFIG_DEBUG_FS
741 mwifiex_dev_debugfs_init(priv
);
751 * This function removes a logical interface.
753 * It deregisters, resets and frees the interface by performing
754 * the following operations -
755 * - Disconnect the device if connected, send wireless event to
756 * notify applications.
757 * - Remove the debug FS structure if configured
758 * - Unregister the device from kernel
759 * - Free the net device structure
760 * - Cancel all works and destroy work queue
761 * - Unregister and free the wireless device from CFG80211 subsystem
764 mwifiex_remove_interface(struct mwifiex_adapter
*adapter
, u8 bss_index
)
766 struct net_device
*dev
= NULL
;
767 struct mwifiex_private
*priv
= adapter
->priv
[bss_index
];
773 if (priv
->media_connected
)
774 priv
->media_connected
= false;
776 #ifdef CONFIG_DEBUG_FS
777 mwifiex_dev_debugfs_remove(priv
);
779 /* Last reference is our one */
780 dev_dbg(adapter
->dev
, "info: %s: refcnt = %d\n",
781 dev
->name
, netdev_refcnt_read(dev
));
783 if (dev
->reg_state
== NETREG_REGISTERED
)
784 unregister_netdev(dev
);
786 /* Clear the priv in adapter */
791 cancel_work_sync(&priv
->cfg_workqueue
);
792 flush_workqueue(priv
->workqueue
);
793 destroy_workqueue(priv
->workqueue
);
794 wiphy_unregister(priv
->wdev
->wiphy
);
795 wiphy_free(priv
->wdev
->wiphy
);
800 * This function check if command is pending.
802 int is_command_pending(struct mwifiex_adapter
*adapter
)
805 int is_cmd_pend_q_empty
;
807 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
808 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
809 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
811 return !is_cmd_pend_q_empty
;
815 * This function returns the correct private structure pointer based
816 * upon the BSS number.
818 struct mwifiex_private
*
819 mwifiex_bss_index_to_priv(struct mwifiex_adapter
*adapter
, u8 bss_index
)
821 if (!adapter
|| (bss_index
>= adapter
->priv_num
))
823 return adapter
->priv
[bss_index
];
827 * This is the main work queue function.
829 * It handles the main process, which in turn handles the complete
832 static void mwifiex_main_work_queue(struct work_struct
*work
)
834 struct mwifiex_adapter
*adapter
=
835 container_of(work
, struct mwifiex_adapter
, main_work
);
837 if (adapter
->surprise_removed
)
839 mwifiex_main_process(adapter
);
843 * This function cancels all works in the queue and destroys
844 * the main workqueue.
847 mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
849 flush_workqueue(adapter
->workqueue
);
850 destroy_workqueue(adapter
->workqueue
);
851 adapter
->workqueue
= NULL
;
855 * This function adds the card.
857 * This function follows the following major steps to set up the device -
858 * - Initialize software. This includes probing the card, registering
859 * the interface operations table, and allocating/initializing the
861 * - Set up the netlink socket
862 * - Create and start the main work queue
863 * - Register the device
864 * - Initialize firmware and hardware
865 * - Add logical interfaces
868 mwifiex_add_card(void *card
, struct semaphore
*sem
,
869 struct mwifiex_if_ops
*if_ops
)
872 struct mwifiex_adapter
*adapter
;
874 if (down_interruptible(sem
))
877 if (mwifiex_init_sw(card
, if_ops
)) {
878 pr_err("%s: software init failed\n", __func__
);
884 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
885 adapter
->surprise_removed
= false;
886 init_waitqueue_head(&adapter
->init_wait_q
);
887 adapter
->is_suspended
= false;
888 adapter
->hs_activated
= false;
889 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
890 adapter
->cmd_wait_q_required
= false;
891 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
892 adapter
->cmd_wait_q
.condition
= false;
893 adapter
->cmd_wait_q
.status
= 0;
895 adapter
->workqueue
= create_workqueue("MWIFIEX_WORK_QUEUE");
896 if (!adapter
->workqueue
)
899 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
901 /* Register the device. Fill up the private data structure with relevant
902 information from the card and request for the required IRQ. */
903 if (adapter
->if_ops
.register_dev(adapter
)) {
904 pr_err("%s: failed to register mwifiex device\n", __func__
);
905 goto err_registerdev
;
908 if (mwifiex_init_hw_fw(adapter
)) {
909 pr_err("%s: firmware init failed\n", __func__
);
914 for (i
= 0; i
< adapter
->drv_mode
->intf_num
; i
++) {
915 if (!mwifiex_add_interface(adapter
, i
,
916 adapter
->drv_mode
->bss_attr
[i
].bss_type
)) {
926 for (i
= 0; i
< adapter
->priv_num
; i
++)
927 mwifiex_remove_interface(adapter
, i
);
929 pr_debug("info: %s: unregister device\n", __func__
);
930 adapter
->if_ops
.unregister_dev(adapter
);
932 adapter
->surprise_removed
= true;
933 mwifiex_terminate_workqueue(adapter
);
935 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
936 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
937 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
938 adapter
->init_wait_q_woken
= false;
940 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
941 wait_event_interruptible(adapter
->init_wait_q
,
942 adapter
->init_wait_q_woken
);
945 mwifiex_free_adapter(adapter
);
953 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
956 * This function removes the card.
958 * This function follows the following major steps to remove the device -
959 * - Stop data traffic
960 * - Shutdown firmware
961 * - Remove the logical interfaces
962 * - Terminate the work queue
963 * - Unregister the device
964 * - Free the adapter structure
966 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
, struct semaphore
*sem
)
968 struct mwifiex_private
*priv
= NULL
;
971 if (down_interruptible(sem
))
977 adapter
->surprise_removed
= true;
980 for (i
= 0; i
< adapter
->priv_num
; i
++) {
981 priv
= adapter
->priv
[i
];
983 if (!netif_queue_stopped(priv
->netdev
))
984 netif_stop_queue(priv
->netdev
);
985 if (netif_carrier_ok(priv
->netdev
))
986 netif_carrier_off(priv
->netdev
);
990 dev_dbg(adapter
->dev
, "cmd: calling mwifiex_shutdown_drv...\n");
991 adapter
->init_wait_q_woken
= false;
993 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
994 wait_event_interruptible(adapter
->init_wait_q
,
995 adapter
->init_wait_q_woken
);
996 dev_dbg(adapter
->dev
, "cmd: mwifiex_shutdown_drv done\n");
997 if (atomic_read(&adapter
->rx_pending
) ||
998 atomic_read(&adapter
->tx_pending
) ||
999 atomic_read(&adapter
->cmd_pending
)) {
1000 dev_err(adapter
->dev
, "rx_pending=%d, tx_pending=%d, "
1002 atomic_read(&adapter
->rx_pending
),
1003 atomic_read(&adapter
->tx_pending
),
1004 atomic_read(&adapter
->cmd_pending
));
1007 /* Remove interface */
1008 for (i
= 0; i
< adapter
->priv_num
; i
++)
1009 mwifiex_remove_interface(adapter
, i
);
1011 mwifiex_terminate_workqueue(adapter
);
1013 /* Unregister device */
1014 dev_dbg(adapter
->dev
, "info: unregister device\n");
1015 adapter
->if_ops
.unregister_dev(adapter
);
1016 /* Free adapter structure */
1017 dev_dbg(adapter
->dev
, "info: free adapter\n");
1018 mwifiex_free_adapter(adapter
);
1025 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1028 * This function initializes the module.
1030 * The debug FS is also initialized if configured.
1033 mwifiex_init_module(void)
1035 #ifdef CONFIG_DEBUG_FS
1036 mwifiex_debugfs_init();
1042 * This function cleans up the module.
1044 * The debug FS is removed if available.
1047 mwifiex_cleanup_module(void)
1049 #ifdef CONFIG_DEBUG_FS
1050 mwifiex_debugfs_remove();
1054 module_init(mwifiex_init_module
);
1055 module_exit(mwifiex_cleanup_module
);
1057 MODULE_AUTHOR("Marvell International Ltd.");
1058 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1059 MODULE_VERSION(VERSION
);
1060 MODULE_LICENSE("GPL v2");