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
[] = {
44 .drv_mode
= DRV_MODE_STA
,
46 .intf_num
= ARRAY_SIZE(mwifiex_bss_sta
),
48 .bss_attr
= mwifiex_bss_sta
,
54 * This function registers the device and performs all the necessary
57 * The following initialization operations are performed -
58 * - Allocate adapter structure
59 * - Save interface specific operations table in adapter
60 * - Call interface specific initialization routine
61 * - Allocate private structures
62 * - Set default adapter structure parameters
65 * In case of any errors during inittialization, this function also ensures
66 * proper cleanup before exiting.
68 static int mwifiex_register(void *card
, struct mwifiex_if_ops
*if_ops
,
69 struct mwifiex_device
*mdevice
, void **padapter
)
72 struct mwifiex_adapter
*adapter
= NULL
;
75 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
76 /* Allocate memory for adapter structure */
83 /* Save interface specific operations in adapter */
84 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
86 /* card specific initialization has been deferred until now .. */
87 ret
= adapter
->if_ops
.init_if(adapter
);
91 adapter
->priv_num
= 0;
92 for (i
= 0; i
< MWIFIEX_MAX_BSS_NUM
; i
++) {
93 adapter
->priv
[i
] = NULL
;
95 if (!mdevice
->bss_attr
[i
].active
)
98 /* For valid bss_attr,
99 allocate memory for private structure */
100 adapter
->priv
[i
] = kzalloc(sizeof(struct mwifiex_private
),
102 if (!adapter
->priv
[i
]) {
103 dev_err(adapter
->dev
, "%s: failed to alloc priv[%d]\n",
109 memset(adapter
->priv
[i
], 0,
110 sizeof(struct mwifiex_private
));
111 adapter
->priv
[i
]->adapter
= adapter
;
112 /* Save bss_type, frame_type & bss_priority */
113 adapter
->priv
[i
]->bss_type
= (u8
) mdevice
->bss_attr
[i
].bss_type
;
114 adapter
->priv
[i
]->frame_type
=
115 (u8
) mdevice
->bss_attr
[i
].frame_type
;
116 adapter
->priv
[i
]->bss_priority
=
117 (u8
) mdevice
->bss_attr
[i
].bss_priority
;
118 if (mdevice
->bss_attr
[i
].bss_type
== MWIFIEX_BSS_TYPE_STA
)
119 adapter
->priv
[i
]->bss_role
= MWIFIEX_BSS_ROLE_STA
;
120 else if (mdevice
->bss_attr
[i
].bss_type
== MWIFIEX_BSS_TYPE_UAP
)
121 adapter
->priv
[i
]->bss_role
= MWIFIEX_BSS_ROLE_UAP
;
123 /* Save bss_index & bss_num */
124 adapter
->priv
[i
]->bss_index
= i
;
125 adapter
->priv
[i
]->bss_num
= mdevice
->bss_attr
[i
].bss_num
;
128 /* Initialize lock variables */
129 if (mwifiex_init_lock_list(adapter
))
132 init_timer(&adapter
->cmd_timer
);
133 adapter
->cmd_timer
.function
= mwifiex_cmd_timeout_func
;
134 adapter
->cmd_timer
.data
= (unsigned long) adapter
;
136 /* Return pointer of struct mwifiex_adapter */
141 dev_dbg(adapter
->dev
, "info: leave mwifiex_register with error\n");
143 /* Free lock variables */
144 mwifiex_free_lock_list(adapter
);
145 for (i
= 0; i
< MWIFIEX_MAX_BSS_NUM
; i
++)
146 kfree(adapter
->priv
[i
]);
153 * This function unregisters the device and performs all the necessary
156 * The following cleanup operations are performed -
158 * - Free beacon buffers
159 * - Free private structures
160 * - Free adapter structure
162 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
166 del_timer(&adapter
->cmd_timer
);
168 /* Free private structures */
169 for (i
= 0; i
< adapter
->priv_num
; i
++) {
170 if (adapter
->priv
[i
]) {
171 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
172 kfree(adapter
->priv
[i
]);
183 * This function is the main procedure of the driver and handles various driver
184 * operations. It runs in a loop and provides the core functionalities.
186 * The main responsibilities of this function are -
187 * - Ensure concurrency control
188 * - Handle pending interrupts and call interrupt handlers
189 * - Wake up the card if required
190 * - Handle command responses and call response handlers
191 * - Handle events and call event handlers
192 * - Execute pending commands
193 * - Transmit pending data packets
195 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
200 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
202 /* Check if already processing */
203 if (adapter
->mwifiex_processing
) {
204 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
207 adapter
->mwifiex_processing
= true;
208 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
212 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
) ||
213 (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
))
216 /* Handle pending interrupt if any */
217 if (adapter
->int_status
) {
218 if (adapter
->hs_activated
)
219 mwifiex_process_hs_config(adapter
);
220 adapter
->if_ops
.process_int_status(adapter
);
223 /* Need to wake up the card ? */
224 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
225 (adapter
->pm_wakeup_card_req
&&
226 !adapter
->pm_wakeup_fw_try
) &&
227 (is_command_pending(adapter
)
228 || !mwifiex_wmm_lists_empty(adapter
))) {
229 adapter
->pm_wakeup_fw_try
= true;
230 adapter
->if_ops
.wakeup(adapter
);
233 if (IS_CARD_RX_RCVD(adapter
)) {
234 adapter
->pm_wakeup_fw_try
= false;
235 if (adapter
->ps_state
== PS_STATE_SLEEP
)
236 adapter
->ps_state
= PS_STATE_AWAKE
;
238 /* We have tried to wakeup the card already */
239 if (adapter
->pm_wakeup_fw_try
)
241 if (adapter
->ps_state
!= PS_STATE_AWAKE
||
242 adapter
->tx_lock_flag
)
245 if (adapter
->scan_processing
|| adapter
->data_sent
246 || mwifiex_wmm_lists_empty(adapter
)) {
247 if (adapter
->cmd_sent
|| adapter
->curr_cmd
248 || (!is_command_pending(adapter
)))
253 /* Check for Cmd Resp */
254 if (adapter
->cmd_resp_received
) {
255 adapter
->cmd_resp_received
= false;
256 mwifiex_process_cmdresp(adapter
);
258 /* call mwifiex back when init_fw is done */
259 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
260 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
261 mwifiex_init_fw_complete(adapter
);
265 /* Check for event */
266 if (adapter
->event_received
) {
267 adapter
->event_received
= false;
268 mwifiex_process_event(adapter
);
271 /* Check if we need to confirm Sleep Request
272 received previously */
273 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) {
274 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
)
275 mwifiex_check_ps_cond(adapter
);
278 /* * The ps_state may have been changed during processing of
279 * Sleep Request event.
281 if ((adapter
->ps_state
== PS_STATE_SLEEP
)
282 || (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
283 || (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)
284 || adapter
->tx_lock_flag
)
287 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
) {
288 if (mwifiex_exec_next_cmd(adapter
) == -1) {
294 if (!adapter
->scan_processing
&& !adapter
->data_sent
&&
295 !mwifiex_wmm_lists_empty(adapter
)) {
296 mwifiex_wmm_process_tx(adapter
);
297 if (adapter
->hs_activated
) {
298 adapter
->is_hs_configured
= false;
299 mwifiex_hs_activated_event
301 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
306 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
307 !adapter
->curr_cmd
&& !is_command_pending(adapter
)
308 && mwifiex_wmm_lists_empty(adapter
)) {
309 if (!mwifiex_send_null_packet
310 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
311 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
312 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
313 adapter
->delay_null_pkt
= false;
314 adapter
->ps_state
= PS_STATE_SLEEP
;
320 if ((adapter
->int_status
) || IS_CARD_RX_RCVD(adapter
))
323 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
324 adapter
->mwifiex_processing
= false;
325 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
328 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
)
329 mwifiex_shutdown_drv(adapter
);
334 * This function initializes the software.
336 * The main work includes allocating and initializing the adapter structure
337 * and initializing the private structures.
340 mwifiex_init_sw(void *card
, struct mwifiex_if_ops
*if_ops
, void **pmwifiex
)
343 struct mwifiex_device device
;
344 struct mwifiex_drv_mode
*drv_mode_ptr
;
346 /* find mwifiex_drv_mode entry from mwifiex_drv_mode_tbl */
348 for (i
= 0; i
< ARRAY_SIZE(mwifiex_drv_mode_tbl
); i
++) {
349 if (mwifiex_drv_mode_tbl
[i
].drv_mode
== drv_mode
) {
350 drv_mode_ptr
= &mwifiex_drv_mode_tbl
[i
];
356 pr_err("invalid drv_mode=%d\n", drv_mode
);
360 memset(&device
, 0, sizeof(struct mwifiex_device
));
362 for (i
= 0; i
< drv_mode_ptr
->intf_num
; i
++) {
363 device
.bss_attr
[i
].bss_type
=
364 drv_mode_ptr
->bss_attr
[i
].bss_type
;
365 device
.bss_attr
[i
].frame_type
=
366 drv_mode_ptr
->bss_attr
[i
].frame_type
;
367 device
.bss_attr
[i
].active
= drv_mode_ptr
->bss_attr
[i
].active
;
368 device
.bss_attr
[i
].bss_priority
=
369 drv_mode_ptr
->bss_attr
[i
].bss_priority
;
370 device
.bss_attr
[i
].bss_num
= drv_mode_ptr
->bss_attr
[i
].bss_num
;
373 if (mwifiex_register(card
, if_ops
, &device
, pmwifiex
))
380 * This function frees the adapter structure.
382 * Additionally, this closes the netlink socket, frees the timers
383 * and private structures.
385 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
388 pr_err("%s: adapter is NULL\n", __func__
);
392 mwifiex_unregister(adapter
);
393 pr_debug("info: %s: free adapter\n", __func__
);
397 * This function initializes the hardware and firmware.
399 * The main initialization steps followed are -
400 * - Download the correct firmware to card
401 * - Allocate and initialize the adapter structure
402 * - Initialize the private structures
403 * - Issue the init commands to firmware
405 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
)
409 struct mwifiex_fw_image fw
;
411 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
413 switch (adapter
->revision_id
) {
416 strcpy(fw_name
, SD8787_W1_FW_NAME
);
420 strcpy(fw_name
, SD8787_AX_FW_NAME
);
426 err
= request_firmware(&adapter
->firmware
, fw_name
, adapter
->dev
);
428 dev_err(adapter
->dev
, "request_firmware() returned"
429 " error code %#x\n", err
);
433 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
434 fw
.fw_len
= adapter
->firmware
->size
;
436 ret
= mwifiex_dnld_fw(adapter
, &fw
);
440 dev_notice(adapter
->dev
, "WLAN FW is active\n");
442 adapter
->init_wait_q_woken
= false;
443 ret
= mwifiex_init_fw(adapter
);
447 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
450 /* Wait for mwifiex_init to complete */
451 wait_event_interruptible(adapter
->init_wait_q
,
452 adapter
->init_wait_q_woken
);
453 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
) {
460 if (adapter
->firmware
)
461 release_firmware(adapter
->firmware
);
468 * This function fills a driver buffer.
470 * The function associates a given SKB with the provided driver buffer
471 * and also updates some of the SKB parameters, including IP header,
472 * priority and timestamp.
475 mwifiex_fill_buffer(struct sk_buff
*skb
)
477 struct ethhdr
*eth
= NULL
;
482 eth
= (struct ethhdr
*) skb
->data
;
483 switch (eth
->h_proto
) {
484 case __constant_htons(ETH_P_IP
):
486 tid
= IPTOS_PREC(iph
->tos
);
487 pr_debug("data: packet type ETH_P_IP: %04x, tid=%#x prio=%#x\n",
488 eth
->h_proto
, tid
, skb
->priority
);
490 case __constant_htons(ETH_P_ARP
):
491 pr_debug("data: ARP packet: %04x\n", eth
->h_proto
);
495 /* Offset for TOS field in the IP header */
496 #define IPTOS_OFFSET 5
497 tid
= (tid
>> IPTOS_OFFSET
);
499 /* Record the current time the packet was queued; used to
500 determine the amount of time the packet was queued in
501 the driver before it was sent to the firmware.
502 The delay is then sent along with the packet to the
503 firmware for aggregate delay calculation for stats and
504 MSDU lifetime expiry.
506 do_gettimeofday(&tv
);
507 skb
->tstamp
= timeval_to_ktime(tv
);
512 * CFG802.11 network device handler for open.
514 * Starts the data queue.
517 mwifiex_open(struct net_device
*dev
)
519 netif_start_queue(dev
);
524 * CFG802.11 network device handler for close.
527 mwifiex_close(struct net_device
*dev
)
533 * CFG802.11 network device handler for data transmission.
536 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
538 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
539 struct sk_buff
*new_skb
= NULL
;
540 struct mwifiex_txinfo
*tx_info
;
542 dev_dbg(priv
->adapter
->dev
, "data: %lu BSS(%d): Data <= kernel\n",
543 jiffies
, priv
->bss_index
);
545 if (priv
->adapter
->surprise_removed
) {
547 priv
->stats
.tx_dropped
++;
550 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
551 dev_err(priv
->adapter
->dev
, "Tx: bad skb len %d\n", skb
->len
);
553 priv
->stats
.tx_dropped
++;
556 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
557 dev_dbg(priv
->adapter
->dev
,
558 "data: Tx: insufficient skb headroom %d\n",
560 /* Insufficient skb headroom - allocate a new skb */
562 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
563 if (unlikely(!new_skb
)) {
564 dev_err(priv
->adapter
->dev
, "Tx: cannot alloca new_skb\n");
566 priv
->stats
.tx_dropped
++;
571 dev_dbg(priv
->adapter
->dev
, "info: new skb headroomd %d\n",
575 tx_info
= MWIFIEX_SKB_TXCB(skb
);
576 tx_info
->bss_index
= priv
->bss_index
;
577 mwifiex_fill_buffer(skb
);
579 mwifiex_wmm_add_buf_txqueue(priv
->adapter
, skb
);
580 atomic_inc(&priv
->adapter
->tx_pending
);
582 if (atomic_read(&priv
->adapter
->tx_pending
) >= MAX_TX_PENDING
) {
583 netif_stop_queue(priv
->netdev
);
584 dev
->trans_start
= jiffies
;
587 queue_work(priv
->adapter
->workqueue
, &priv
->adapter
->main_work
);
593 * CFG802.11 network device handler for setting MAC address.
596 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
598 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
599 struct sockaddr
*hw_addr
= (struct sockaddr
*) addr
;
601 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
603 if (mwifiex_request_set_mac_address(priv
)) {
604 dev_err(priv
->adapter
->dev
, "set MAC address failed\n");
607 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
613 * CFG802.11 network device handler for setting multicast list.
615 static void mwifiex_set_multicast_list(struct net_device
*dev
)
617 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
618 mwifiex_request_set_multicast_list(priv
, dev
);
622 * CFG802.11 network device handler for transmission timeout.
625 mwifiex_tx_timeout(struct net_device
*dev
)
627 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
629 dev_err(priv
->adapter
->dev
, "%lu : Tx timeout, bss_index=%d\n",
630 jiffies
, priv
->bss_index
);
631 dev
->trans_start
= jiffies
;
632 priv
->num_tx_timeout
++;
636 * CFG802.11 network device handler for statistics retrieval.
638 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
640 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
645 /* Network device handlers */
646 static const struct net_device_ops mwifiex_netdev_ops
= {
647 .ndo_open
= mwifiex_open
,
648 .ndo_stop
= mwifiex_close
,
649 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
650 .ndo_set_mac_address
= mwifiex_set_mac_address
,
651 .ndo_tx_timeout
= mwifiex_tx_timeout
,
652 .ndo_get_stats
= mwifiex_get_stats
,
653 .ndo_set_multicast_list
= mwifiex_set_multicast_list
,
657 * This function initializes the private structure parameters.
659 * The following wait queues are initialized -
661 * - Command wait queue
662 * - Statistics wait queue
664 * ...and the following default parameters are set -
665 * - Current key index : Set to 0
666 * - Rate index : Set to auto
667 * - Media connected : Set to disconnected
668 * - Adhoc link sensed : Set to false
669 * - Nick name : Set to null
670 * - Number of Tx timeout : Set to 0
671 * - Device address : Set to current address
673 * In addition, the CFG80211 work queue is also created.
676 mwifiex_init_priv_params(struct mwifiex_private
*priv
, struct net_device
*dev
)
678 dev
->netdev_ops
= &mwifiex_netdev_ops
;
679 /* Initialize private structure */
680 init_waitqueue_head(&priv
->ioctl_wait_q
);
681 init_waitqueue_head(&priv
->cmd_wait_q
);
682 init_waitqueue_head(&priv
->w_stats_wait_q
);
683 priv
->current_key_index
= 0;
684 priv
->media_connected
= false;
685 memset(&priv
->nick_name
, 0, sizeof(priv
->nick_name
));
686 priv
->num_tx_timeout
= 0;
687 priv
->workqueue
= create_singlethread_workqueue("cfg80211_wq");
688 INIT_WORK(&priv
->cfg_workqueue
, mwifiex_cfg80211_results
);
689 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
693 * This function adds a new logical interface.
695 * It allocates, initializes and registers the interface by performing
696 * the following opearations -
697 * - Allocate a new net device structure
698 * - Assign device name
699 * - Register the new device with CFG80211 subsystem
700 * - Initialize semaphore and private structure
701 * - Register the new device with kernel
702 * - Create the complete debug FS structure if configured
704 static struct mwifiex_private
*mwifiex_add_interface(
705 struct mwifiex_adapter
*adapter
,
706 u8 bss_index
, u8 bss_type
)
708 struct net_device
*dev
= NULL
;
709 struct mwifiex_private
*priv
= NULL
;
710 void *mdev_priv
= NULL
;
712 dev
= alloc_netdev_mq(sizeof(struct mwifiex_private
*), "mlan%d",
715 dev_err(adapter
->dev
, "no memory available for netdevice\n");
718 if (dev_alloc_name(dev
, dev
->name
)) {
719 dev_err(adapter
->dev
, "unable to alloc name for netdevice\n");
723 if (mwifiex_register_cfg80211(dev
, adapter
->priv
[bss_index
]->curr_addr
,
724 adapter
->priv
[bss_index
]) != 0) {
725 dev_err(adapter
->dev
, "cannot register netdevice with cfg80211\n");
728 /* Save the priv pointer in netdev */
729 priv
= adapter
->priv
[bss_index
];
730 mdev_priv
= netdev_priv(dev
);
731 *((unsigned long *) mdev_priv
) = (unsigned long) priv
;
735 sema_init(&priv
->async_sem
, 1);
736 priv
->scan_pending_on_block
= false;
738 mwifiex_init_priv_params(priv
, dev
);
740 SET_NETDEV_DEV(dev
, adapter
->dev
);
742 /* Register network device */
743 if (register_netdev(dev
)) {
744 dev_err(adapter
->dev
, "cannot register virtual network device\n");
748 dev_dbg(adapter
->dev
, "info: %s: Marvell 802.11 Adapter\n", dev
->name
);
749 #ifdef CONFIG_DEBUG_FS
750 mwifiex_dev_debugfs_init(priv
);
760 * This function removes a logical interface.
762 * It deregisters, resets and frees the interface by performing
763 * the following operations -
764 * - Disconnect the device if connected, send wireless event to
765 * notify applications.
766 * - Remove the debug FS structure if configured
767 * - Unregister the device from kernel
768 * - Free the net device structure
769 * - Cancel all works and destroy work queue
770 * - Unregister and free the wireless device from CFG80211 subsystem
773 mwifiex_remove_interface(struct mwifiex_adapter
*adapter
, u8 bss_index
)
775 struct net_device
*dev
= NULL
;
776 struct mwifiex_private
*priv
= adapter
->priv
[bss_index
];
782 if (priv
->media_connected
)
783 priv
->media_connected
= false;
785 #ifdef CONFIG_DEBUG_FS
786 mwifiex_dev_debugfs_remove(priv
);
788 /* Last reference is our one */
789 dev_dbg(adapter
->dev
, "info: %s: refcnt = %d\n",
790 dev
->name
, netdev_refcnt_read(dev
));
792 if (dev
->reg_state
== NETREG_REGISTERED
)
793 unregister_netdev(dev
);
795 /* Clear the priv in adapter */
800 cancel_work_sync(&priv
->cfg_workqueue
);
801 flush_workqueue(priv
->workqueue
);
802 destroy_workqueue(priv
->workqueue
);
803 wiphy_unregister(priv
->wdev
->wiphy
);
804 wiphy_free(priv
->wdev
->wiphy
);
811 * Sends IOCTL request to shutdown firmware.
813 * This function allocates the IOCTL request buffer, fills it
814 * with requisite parameters and calls the IOCTL handler.
816 int mwifiex_shutdown_fw(struct mwifiex_private
*priv
, u8 wait_option
)
818 struct mwifiex_wait_queue
*wait
= NULL
;
821 /* Allocate an IOCTL request buffer */
822 wait
= mwifiex_alloc_fill_wait_queue(priv
, wait_option
);
826 status
= mwifiex_misc_ioctl_init_shutdown(priv
->adapter
, wait
,
827 MWIFIEX_FUNC_SHUTDOWN
);
829 status
= mwifiex_request_ioctl(priv
, wait
, status
, wait_option
);
834 EXPORT_SYMBOL_GPL(mwifiex_shutdown_fw
);
837 * This function check if command is pending.
839 int is_command_pending(struct mwifiex_adapter
*adapter
)
842 int is_cmd_pend_q_empty
;
844 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
845 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
846 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
848 return !is_cmd_pend_q_empty
;
852 * This function returns the correct private structure pointer based
853 * upon the BSS number.
855 struct mwifiex_private
*
856 mwifiex_bss_index_to_priv(struct mwifiex_adapter
*adapter
, u8 bss_index
)
858 if (!adapter
|| (bss_index
>= adapter
->priv_num
))
860 return adapter
->priv
[bss_index
];
864 * This is the main work queue function.
866 * It handles the main process, which in turn handles the complete
869 static void mwifiex_main_work_queue(struct work_struct
*work
)
871 struct mwifiex_adapter
*adapter
=
872 container_of(work
, struct mwifiex_adapter
, main_work
);
874 if (adapter
->surprise_removed
)
876 mwifiex_main_process(adapter
);
880 * This function cancels all works in the queue and destroys
881 * the main workqueue.
884 mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
886 flush_workqueue(adapter
->workqueue
);
887 destroy_workqueue(adapter
->workqueue
);
888 adapter
->workqueue
= NULL
;
892 * This function adds the card.
894 * This function follows the following major steps to set up the device -
895 * - Initialize software. This includes probing the card, registering
896 * the interface operations table, and allocating/initializing the
898 * - Set up the netlink socket
899 * - Create and start the main work queue
900 * - Register the device
901 * - Initialize firmware and hardware
902 * - Add logical interfaces
905 mwifiex_add_card(void *card
, struct semaphore
*sem
,
906 struct mwifiex_if_ops
*if_ops
)
910 struct mwifiex_adapter
*adapter
= NULL
;
911 struct mwifiex_drv_mode
*drv_mode_info
= &mwifiex_drv_mode_tbl
[0];
913 if (down_interruptible(sem
))
916 if (mwifiex_init_sw(card
, if_ops
, (void **) &adapter
)) {
917 pr_err("%s: software init failed\n", __func__
);
921 adapter
->drv_mode
= drv_mode_info
;
923 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
924 /* PnP and power profile */
925 adapter
->surprise_removed
= false;
926 init_waitqueue_head(&adapter
->init_wait_q
);
927 adapter
->is_suspended
= false;
928 adapter
->hs_activated
= false;
929 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
931 /* Create workqueue */
932 adapter
->workqueue
= create_workqueue("MWIFIEX_WORK_QUEUE");
933 if (!adapter
->workqueue
)
936 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
938 /* Register the device. Fill up the private data structure with relevant
939 information from the card and request for the required IRQ. */
940 if (adapter
->if_ops
.register_dev(adapter
)) {
941 pr_err("%s: failed to register mwifiex device\n", __func__
);
942 goto err_registerdev
;
946 if (mwifiex_init_hw_fw(adapter
)) {
947 pr_err("%s: firmware init failed\n", __func__
);
951 for (i
= 0; i
< drv_mode_info
->intf_num
; i
++) {
952 if (!mwifiex_add_interface(adapter
, i
,
953 adapter
->drv_mode
->bss_attr
[i
].bss_type
)) {
966 for (i
= 0; i
< adapter
->priv_num
; i
++)
967 mwifiex_remove_interface(adapter
, i
);
969 /* Unregister device */
970 pr_debug("info: %s: unregister device\n", __func__
);
971 adapter
->if_ops
.unregister_dev(adapter
);
973 adapter
->surprise_removed
= true;
974 mwifiex_terminate_workqueue(adapter
);
976 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
977 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
978 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
979 adapter
->init_wait_q_woken
= false;
980 status
= mwifiex_shutdown_drv(adapter
);
981 if (status
== -EINPROGRESS
)
982 wait_event_interruptible(adapter
->init_wait_q
,
983 adapter
->init_wait_q_woken
);
986 mwifiex_free_adapter(adapter
);
994 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
997 * This function removes the card.
999 * This function follows the following major steps to remove the device -
1000 * - Stop data traffic
1001 * - Shutdown firmware
1002 * - Remove the logical interfaces
1003 * - Terminate the work queue
1004 * - Unregister the device
1005 * - Free the adapter structure
1007 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
, struct semaphore
*sem
)
1009 struct mwifiex_private
*priv
= NULL
;
1013 if (down_interruptible(sem
))
1019 adapter
->surprise_removed
= true;
1022 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1023 priv
= adapter
->priv
[i
];
1025 if (!netif_queue_stopped(priv
->netdev
))
1026 netif_stop_queue(priv
->netdev
);
1027 if (netif_carrier_ok(priv
->netdev
))
1028 netif_carrier_off(priv
->netdev
);
1032 dev_dbg(adapter
->dev
, "cmd: calling mwifiex_shutdown_drv...\n");
1033 adapter
->init_wait_q_woken
= false;
1034 status
= mwifiex_shutdown_drv(adapter
);
1035 if (status
== -EINPROGRESS
)
1036 wait_event_interruptible(adapter
->init_wait_q
,
1037 adapter
->init_wait_q_woken
);
1038 dev_dbg(adapter
->dev
, "cmd: mwifiex_shutdown_drv done\n");
1039 if (atomic_read(&adapter
->rx_pending
) ||
1040 atomic_read(&adapter
->tx_pending
) ||
1041 atomic_read(&adapter
->ioctl_pending
)) {
1042 dev_err(adapter
->dev
, "rx_pending=%d, tx_pending=%d, "
1043 "ioctl_pending=%d\n",
1044 atomic_read(&adapter
->rx_pending
),
1045 atomic_read(&adapter
->tx_pending
),
1046 atomic_read(&adapter
->ioctl_pending
));
1049 /* Remove interface */
1050 for (i
= 0; i
< adapter
->priv_num
; i
++)
1051 mwifiex_remove_interface(adapter
, i
);
1053 mwifiex_terminate_workqueue(adapter
);
1055 /* Unregister device */
1056 dev_dbg(adapter
->dev
, "info: unregister device\n");
1057 adapter
->if_ops
.unregister_dev(adapter
);
1058 /* Free adapter structure */
1059 dev_dbg(adapter
->dev
, "info: free adapter\n");
1060 mwifiex_free_adapter(adapter
);
1067 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1070 * This function initializes the module.
1072 * The debug FS is also initialized if configured.
1075 mwifiex_init_module(void)
1077 #ifdef CONFIG_DEBUG_FS
1078 mwifiex_debugfs_init();
1084 * This function cleans up the module.
1086 * The debug FS is removed if available.
1089 mwifiex_cleanup_module(void)
1091 #ifdef CONFIG_DEBUG_FS
1092 mwifiex_debugfs_remove();
1096 module_init(mwifiex_init_module
);
1097 module_exit(mwifiex_cleanup_module
);
1099 MODULE_AUTHOR("Marvell International Ltd.");
1100 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1101 MODULE_VERSION(VERSION
);
1102 MODULE_LICENSE("GPL v2");