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 setup_timer(&adapter
->cmd_timer
, mwifiex_cmd_timeout_func
,
87 (unsigned long)adapter
);
92 dev_dbg(adapter
->dev
, "info: leave mwifiex_register with error\n");
94 for (i
= 0; i
< adapter
->priv_num
; i
++)
95 kfree(adapter
->priv
[i
]);
103 * This function unregisters the device and performs all the necessary
106 * The following cleanup operations are performed -
108 * - Free beacon buffers
109 * - Free private structures
110 * - Free adapter structure
112 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
116 if (adapter
->if_ops
.cleanup_if
)
117 adapter
->if_ops
.cleanup_if(adapter
);
119 del_timer_sync(&adapter
->cmd_timer
);
121 /* Free private structures */
122 for (i
= 0; i
< adapter
->priv_num
; i
++) {
123 if (adapter
->priv
[i
]) {
124 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
125 kfree(adapter
->priv
[i
]);
129 vfree(adapter
->chan_stats
);
134 static int mwifiex_process_rx(struct mwifiex_adapter
*adapter
)
139 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
140 if (adapter
->rx_processing
|| adapter
->rx_locked
) {
141 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
144 adapter
->rx_processing
= true;
145 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
148 /* Check for Rx data */
149 while ((skb
= skb_dequeue(&adapter
->rx_data_q
))) {
150 atomic_dec(&adapter
->rx_pending
);
151 if ((adapter
->delay_main_work
||
152 adapter
->iface_type
== MWIFIEX_USB
) &&
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 adapter
->more_task_flag
= true;
194 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
197 adapter
->mwifiex_processing
= true;
201 adapter
->more_task_flag
= false;
202 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
203 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
) ||
204 (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
))
207 /* For non-USB interfaces, If we process interrupts first, it
208 * would increase RX pending even further. Avoid this by
209 * checking if rx_pending has crossed high threshold and
210 * schedule rx work queue and then process interrupts.
211 * For USB interface, there are no interrupts. We already have
212 * HIGH_RX_PENDING check in usb.c
214 if (atomic_read(&adapter
->rx_pending
) >= HIGH_RX_PENDING
&&
215 adapter
->iface_type
!= MWIFIEX_USB
) {
216 adapter
->delay_main_work
= true;
217 if (!adapter
->rx_processing
)
218 queue_work(adapter
->rx_workqueue
,
223 /* Handle pending interrupt if any */
224 if (adapter
->int_status
) {
225 if (adapter
->hs_activated
)
226 mwifiex_process_hs_config(adapter
);
227 if (adapter
->if_ops
.process_int_status
)
228 adapter
->if_ops
.process_int_status(adapter
);
231 if (adapter
->rx_work_enabled
&& adapter
->data_received
)
232 queue_work(adapter
->rx_workqueue
, &adapter
->rx_work
);
234 /* Need to wake up the card ? */
235 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
236 (adapter
->pm_wakeup_card_req
&&
237 !adapter
->pm_wakeup_fw_try
) &&
238 (is_command_pending(adapter
) ||
239 !mwifiex_wmm_lists_empty(adapter
))) {
240 adapter
->pm_wakeup_fw_try
= true;
241 mod_timer(&adapter
->wakeup_timer
, jiffies
+ (HZ
*3));
242 adapter
->if_ops
.wakeup(adapter
);
243 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
247 if (IS_CARD_RX_RCVD(adapter
)) {
248 adapter
->data_received
= false;
249 adapter
->pm_wakeup_fw_try
= false;
250 del_timer(&adapter
->wakeup_timer
);
251 if (adapter
->ps_state
== PS_STATE_SLEEP
)
252 adapter
->ps_state
= PS_STATE_AWAKE
;
254 /* We have tried to wakeup the card already */
255 if (adapter
->pm_wakeup_fw_try
)
257 if (adapter
->ps_state
!= PS_STATE_AWAKE
||
258 adapter
->tx_lock_flag
)
261 if ((!adapter
->scan_chan_gap_enabled
&&
262 adapter
->scan_processing
) || adapter
->data_sent
||
263 mwifiex_wmm_lists_empty(adapter
)) {
264 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
265 (!is_command_pending(adapter
)))
270 /* Check for event */
271 if (adapter
->event_received
) {
272 adapter
->event_received
= false;
273 mwifiex_process_event(adapter
);
276 /* Check for Cmd Resp */
277 if (adapter
->cmd_resp_received
) {
278 adapter
->cmd_resp_received
= false;
279 mwifiex_process_cmdresp(adapter
);
281 /* call mwifiex back when init_fw is done */
282 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
283 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
284 mwifiex_init_fw_complete(adapter
);
288 /* Check if we need to confirm Sleep Request
289 received previously */
290 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) {
291 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
)
292 mwifiex_check_ps_cond(adapter
);
295 /* * The ps_state may have been changed during processing of
296 * Sleep Request event.
298 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
299 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
300 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
) ||
301 adapter
->tx_lock_flag
){
302 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
306 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
) {
307 if (mwifiex_exec_next_cmd(adapter
) == -1) {
313 if ((adapter
->scan_chan_gap_enabled
||
314 !adapter
->scan_processing
) &&
315 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
)) {
316 mwifiex_wmm_process_tx(adapter
);
317 if (adapter
->hs_activated
) {
318 adapter
->is_hs_configured
= false;
319 mwifiex_hs_activated_event
321 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
326 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
327 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
328 mwifiex_wmm_lists_empty(adapter
)) {
329 if (!mwifiex_send_null_packet
330 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
331 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
332 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
333 adapter
->delay_null_pkt
= false;
334 adapter
->ps_state
= PS_STATE_SLEEP
;
338 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
341 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
342 if (adapter
->more_task_flag
)
344 adapter
->mwifiex_processing
= false;
345 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
348 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
)
349 mwifiex_shutdown_drv(adapter
);
352 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
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 cancels all works in the queue and destroys
373 * the main workqueue.
375 static void mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
377 flush_workqueue(adapter
->workqueue
);
378 destroy_workqueue(adapter
->workqueue
);
379 adapter
->workqueue
= NULL
;
381 if (adapter
->rx_workqueue
) {
382 flush_workqueue(adapter
->rx_workqueue
);
383 destroy_workqueue(adapter
->rx_workqueue
);
384 adapter
->rx_workqueue
= NULL
;
389 * This function gets firmware and initializes it.
391 * The main initialization steps followed are -
392 * - Download the correct firmware to card
393 * - Issue the init commands to firmware
395 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
399 struct mwifiex_private
*priv
;
400 struct mwifiex_adapter
*adapter
= context
;
401 struct mwifiex_fw_image fw
;
402 struct semaphore
*sem
= adapter
->card_sem
;
403 bool init_failed
= false;
404 struct wireless_dev
*wdev
;
407 dev_err(adapter
->dev
,
408 "Failed to get firmware %s\n", adapter
->fw_name
);
412 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
413 adapter
->firmware
= firmware
;
414 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
415 fw
.fw_len
= adapter
->firmware
->size
;
417 if (adapter
->if_ops
.dnld_fw
)
418 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
420 ret
= mwifiex_dnld_fw(adapter
, &fw
);
424 dev_notice(adapter
->dev
, "WLAN FW is active\n");
427 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
429 dev_err(adapter
->dev
,
430 "Cal data request_firmware() failed\n");
433 /* enable host interrupt after fw dnld is successful */
434 if (adapter
->if_ops
.enable_int
) {
435 if (adapter
->if_ops
.enable_int(adapter
))
439 adapter
->init_wait_q_woken
= false;
440 ret
= mwifiex_init_fw(adapter
);
444 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
447 /* Wait for mwifiex_init to complete */
448 wait_event_interruptible(adapter
->init_wait_q
,
449 adapter
->init_wait_q_woken
);
450 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
)
453 priv
= adapter
->priv
[MWIFIEX_BSS_ROLE_STA
];
454 if (mwifiex_register_cfg80211(adapter
)) {
455 dev_err(adapter
->dev
, "cannot register with cfg80211\n");
459 if (mwifiex_init_channel_scan_gap(adapter
)) {
460 dev_err(adapter
->dev
, "could not init channel stats table\n");
465 driver_mode
&= MWIFIEX_DRIVER_MODE_BITMASK
;
466 driver_mode
|= MWIFIEX_DRIVER_MODE_STA
;
470 /* Create station interface by default */
471 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d",
472 NL80211_IFTYPE_STATION
, NULL
, NULL
);
474 dev_err(adapter
->dev
, "cannot create default STA interface\n");
479 if (driver_mode
& MWIFIEX_DRIVER_MODE_UAP
) {
480 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "uap%d",
481 NL80211_IFTYPE_AP
, NULL
, NULL
);
483 dev_err(adapter
->dev
, "cannot create AP interface\n");
489 if (driver_mode
& MWIFIEX_DRIVER_MODE_P2P
) {
490 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "p2p%d",
491 NL80211_IFTYPE_P2P_CLIENT
, NULL
,
494 dev_err(adapter
->dev
,
495 "cannot create p2p client interface\n");
502 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
503 dev_notice(adapter
->dev
, "driver_version = %s\n", fmt
);
507 wiphy_unregister(adapter
->wiphy
);
508 wiphy_free(adapter
->wiphy
);
510 if (adapter
->if_ops
.disable_int
)
511 adapter
->if_ops
.disable_int(adapter
);
513 pr_debug("info: %s: unregister device\n", __func__
);
514 if (adapter
->if_ops
.unregister_dev
)
515 adapter
->if_ops
.unregister_dev(adapter
);
517 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
518 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
519 adapter
->init_wait_q_woken
= false;
521 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
522 wait_event_interruptible(adapter
->init_wait_q
,
523 adapter
->init_wait_q_woken
);
525 adapter
->surprise_removed
= true;
526 mwifiex_terminate_workqueue(adapter
);
529 if (adapter
->cal_data
) {
530 release_firmware(adapter
->cal_data
);
531 adapter
->cal_data
= NULL
;
533 if (adapter
->firmware
) {
534 release_firmware(adapter
->firmware
);
535 adapter
->firmware
= NULL
;
538 mwifiex_free_adapter(adapter
);
544 * This function initializes the hardware and gets firmware.
546 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
)
550 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
551 adapter
->dev
, GFP_KERNEL
, adapter
,
554 dev_err(adapter
->dev
,
555 "request_firmware_nowait() returned error %d\n", ret
);
560 * CFG802.11 network device handler for open.
562 * Starts the data queue.
565 mwifiex_open(struct net_device
*dev
)
567 netif_carrier_off(dev
);
573 * CFG802.11 network device handler for close.
576 mwifiex_close(struct net_device
*dev
)
578 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
580 if (priv
->scan_request
) {
581 dev_dbg(priv
->adapter
->dev
, "aborting scan on ndo_stop\n");
582 cfg80211_scan_done(priv
->scan_request
, 1);
583 priv
->scan_request
= NULL
;
584 priv
->scan_aborting
= true;
591 * Add buffer into wmm tx queue and queue work to transmit it.
593 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
595 struct netdev_queue
*txq
;
596 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
598 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
599 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
600 if (!netif_tx_queue_stopped(txq
)) {
601 netif_tx_stop_queue(txq
);
602 dev_dbg(priv
->adapter
->dev
, "stop queue: %d\n", index
);
606 atomic_inc(&priv
->adapter
->tx_pending
);
607 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
609 queue_work(priv
->adapter
->workqueue
, &priv
->adapter
->main_work
);
615 mwifiex_clone_skb_for_tx_status(struct mwifiex_private
*priv
,
616 struct sk_buff
*skb
, u8 flag
, u64
*cookie
)
618 struct sk_buff
*orig_skb
= skb
;
619 struct mwifiex_txinfo
*tx_info
, *orig_tx_info
;
621 skb
= skb_clone(skb
, GFP_ATOMIC
);
626 spin_lock_irqsave(&priv
->ack_status_lock
, flags
);
627 id
= idr_alloc(&priv
->ack_status_frames
, orig_skb
,
628 1, 0xff, GFP_ATOMIC
);
629 spin_unlock_irqrestore(&priv
->ack_status_lock
, flags
);
632 tx_info
= MWIFIEX_SKB_TXCB(skb
);
633 tx_info
->ack_frame_id
= id
;
634 tx_info
->flags
|= flag
;
635 orig_tx_info
= MWIFIEX_SKB_TXCB(orig_skb
);
636 orig_tx_info
->ack_frame_id
= id
;
637 orig_tx_info
->flags
|= flag
;
639 if (flag
== MWIFIEX_BUF_FLAG_ACTION_TX_STATUS
&& cookie
)
640 orig_tx_info
->cookie
= *cookie
;
642 } else if (skb_shared(skb
)) {
649 /* couldn't clone -- lose tx status ... */
657 * CFG802.11 network device handler for data transmission.
660 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
662 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
663 struct sk_buff
*new_skb
;
664 struct mwifiex_txinfo
*tx_info
;
667 dev_dbg(priv
->adapter
->dev
, "data: %lu BSS(%d-%d): Data <= kernel\n",
668 jiffies
, priv
->bss_type
, priv
->bss_num
);
670 if (priv
->adapter
->surprise_removed
) {
672 priv
->stats
.tx_dropped
++;
675 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
676 dev_err(priv
->adapter
->dev
, "Tx: bad skb len %d\n", skb
->len
);
678 priv
->stats
.tx_dropped
++;
681 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
682 dev_dbg(priv
->adapter
->dev
,
683 "data: Tx: insufficient skb headroom %d\n",
685 /* Insufficient skb headroom - allocate a new skb */
687 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
688 if (unlikely(!new_skb
)) {
689 dev_err(priv
->adapter
->dev
, "Tx: cannot alloca new_skb\n");
691 priv
->stats
.tx_dropped
++;
696 dev_dbg(priv
->adapter
->dev
, "info: new skb headroomd %d\n",
700 tx_info
= MWIFIEX_SKB_TXCB(skb
);
701 memset(tx_info
, 0, sizeof(*tx_info
));
702 tx_info
->bss_num
= priv
->bss_num
;
703 tx_info
->bss_type
= priv
->bss_type
;
704 tx_info
->pkt_len
= skb
->len
;
706 multicast
= is_multicast_ether_addr(skb
->data
);
708 if (unlikely(!multicast
&& skb
->sk
&&
709 skb_shinfo(skb
)->tx_flags
& SKBTX_WIFI_STATUS
&&
710 priv
->adapter
->fw_api_ver
== MWIFIEX_FW_V15
))
711 skb
= mwifiex_clone_skb_for_tx_status(priv
,
713 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS
, NULL
);
715 /* Record the current time the packet was queued; used to
716 * determine the amount of time the packet was queued in
717 * the driver before it was sent to the firmware.
718 * The delay is then sent along with the packet to the
719 * firmware for aggregate delay calculation for stats and
720 * MSDU lifetime expiry.
722 __net_timestamp(skb
);
724 if (ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
725 priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
&&
726 !ether_addr_equal_unaligned(priv
->cfg_bssid
, skb
->data
)) {
727 if (priv
->adapter
->auto_tdls
&& priv
->check_tdls_tx
)
728 mwifiex_tdls_check_tx(priv
, skb
);
731 mwifiex_queue_tx_pkt(priv
, skb
);
737 * CFG802.11 network device handler for setting MAC address.
740 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
742 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
743 struct sockaddr
*hw_addr
= addr
;
746 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
748 /* Send request to firmware */
749 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
750 HostCmd_ACT_GEN_SET
, 0, NULL
, true);
753 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
755 dev_err(priv
->adapter
->dev
,
756 "set mac address failed: ret=%d\n", ret
);
758 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
764 * CFG802.11 network device handler for setting multicast list.
766 static void mwifiex_set_multicast_list(struct net_device
*dev
)
768 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
769 struct mwifiex_multicast_list mcast_list
;
771 if (dev
->flags
& IFF_PROMISC
) {
772 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
773 } else if (dev
->flags
& IFF_ALLMULTI
||
774 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
775 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
777 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
778 mcast_list
.num_multicast_addr
=
779 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
781 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
785 * CFG802.11 network device handler for transmission timeout.
788 mwifiex_tx_timeout(struct net_device
*dev
)
790 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
792 priv
->num_tx_timeout
++;
793 priv
->tx_timeout_cnt
++;
794 dev_err(priv
->adapter
->dev
,
795 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
796 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
, priv
->bss_num
);
797 mwifiex_set_trans_start(dev
);
799 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
800 priv
->adapter
->if_ops
.card_reset
) {
801 dev_err(priv
->adapter
->dev
,
802 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
803 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
807 void mwifiex_dump_drv_info(struct mwifiex_adapter
*adapter
)
810 char drv_version
[64];
811 struct usb_card_rec
*cardp
;
812 struct sdio_mmc_card
*sdio_card
;
813 struct mwifiex_private
*priv
;
815 struct netdev_queue
*txq
;
816 struct mwifiex_debug_info
*debug_info
;
818 if (adapter
->drv_info_dump
) {
819 vfree(adapter
->drv_info_dump
);
820 adapter
->drv_info_size
= 0;
823 dev_info(adapter
->dev
, "=== DRIVER INFO DUMP START===\n");
825 adapter
->drv_info_dump
= vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX
);
827 if (!adapter
->drv_info_dump
)
830 p
= (char *)(adapter
->drv_info_dump
);
831 p
+= sprintf(p
, "driver_name = " "\"mwifiex\"\n");
833 mwifiex_drv_get_driver_version(adapter
, drv_version
,
834 sizeof(drv_version
) - 1);
835 p
+= sprintf(p
, "driver_version = %s\n", drv_version
);
837 if (adapter
->iface_type
== MWIFIEX_USB
) {
838 cardp
= (struct usb_card_rec
*)adapter
->card
;
839 p
+= sprintf(p
, "tx_cmd_urb_pending = %d\n",
840 atomic_read(&cardp
->tx_cmd_urb_pending
));
841 p
+= sprintf(p
, "tx_data_urb_pending = %d\n",
842 atomic_read(&cardp
->tx_data_urb_pending
));
843 p
+= sprintf(p
, "rx_cmd_urb_pending = %d\n",
844 atomic_read(&cardp
->rx_cmd_urb_pending
));
845 p
+= sprintf(p
, "rx_data_urb_pending = %d\n",
846 atomic_read(&cardp
->rx_data_urb_pending
));
849 p
+= sprintf(p
, "tx_pending = %d\n",
850 atomic_read(&adapter
->tx_pending
));
851 p
+= sprintf(p
, "rx_pending = %d\n",
852 atomic_read(&adapter
->rx_pending
));
854 if (adapter
->iface_type
== MWIFIEX_SDIO
) {
855 sdio_card
= (struct sdio_mmc_card
*)adapter
->card
;
856 p
+= sprintf(p
, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
857 sdio_card
->mp_rd_bitmap
, sdio_card
->curr_rd_port
);
858 p
+= sprintf(p
, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
859 sdio_card
->mp_wr_bitmap
, sdio_card
->curr_wr_port
);
862 for (i
= 0; i
< adapter
->priv_num
; i
++) {
863 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
865 priv
= adapter
->priv
[i
];
866 p
+= sprintf(p
, "\n[interface : \"%s\"]\n",
868 p
+= sprintf(p
, "wmm_tx_pending[0] = %d\n",
869 atomic_read(&priv
->wmm_tx_pending
[0]));
870 p
+= sprintf(p
, "wmm_tx_pending[1] = %d\n",
871 atomic_read(&priv
->wmm_tx_pending
[1]));
872 p
+= sprintf(p
, "wmm_tx_pending[2] = %d\n",
873 atomic_read(&priv
->wmm_tx_pending
[2]));
874 p
+= sprintf(p
, "wmm_tx_pending[3] = %d\n",
875 atomic_read(&priv
->wmm_tx_pending
[3]));
876 p
+= sprintf(p
, "media_state=\"%s\"\n", !priv
->media_connected
?
877 "Disconnected" : "Connected");
878 p
+= sprintf(p
, "carrier %s\n", (netif_carrier_ok(priv
->netdev
)
880 for (idx
= 0; idx
< priv
->netdev
->num_tx_queues
; idx
++) {
881 txq
= netdev_get_tx_queue(priv
->netdev
, idx
);
882 p
+= sprintf(p
, "tx queue %d:%s ", idx
,
883 netif_tx_queue_stopped(txq
) ?
884 "stopped" : "started");
886 p
+= sprintf(p
, "\n%s: num_tx_timeout = %d\n",
887 priv
->netdev
->name
, priv
->num_tx_timeout
);
890 if (adapter
->iface_type
== MWIFIEX_SDIO
) {
891 p
+= sprintf(p
, "\n=== SDIO register DUMP===\n");
892 if (adapter
->if_ops
.reg_dump
)
893 p
+= adapter
->if_ops
.reg_dump(adapter
, p
);
896 p
+= sprintf(p
, "\n=== MORE DEBUG INFORMATION\n");
897 debug_info
= kzalloc(sizeof(*debug_info
), GFP_KERNEL
);
899 for (i
= 0; i
< adapter
->priv_num
; i
++) {
900 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
902 priv
= adapter
->priv
[i
];
903 mwifiex_get_debug_info(priv
, debug_info
);
904 p
+= mwifiex_debug_info_to_buffer(priv
, p
, debug_info
);
910 adapter
->drv_info_size
= p
- adapter
->drv_info_dump
;
911 dev_info(adapter
->dev
, "=== DRIVER INFO DUMP END===\n");
913 EXPORT_SYMBOL_GPL(mwifiex_dump_drv_info
);
916 * CFG802.11 network device handler for statistics retrieval.
918 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
920 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
926 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
,
927 void *accel_priv
, select_queue_fallback_t fallback
)
929 skb
->priority
= cfg80211_classify8021d(skb
, NULL
);
930 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
933 /* Network device handlers */
934 static const struct net_device_ops mwifiex_netdev_ops
= {
935 .ndo_open
= mwifiex_open
,
936 .ndo_stop
= mwifiex_close
,
937 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
938 .ndo_set_mac_address
= mwifiex_set_mac_address
,
939 .ndo_tx_timeout
= mwifiex_tx_timeout
,
940 .ndo_get_stats
= mwifiex_get_stats
,
941 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
942 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
946 * This function initializes the private structure parameters.
948 * The following wait queues are initialized -
950 * - Command wait queue
951 * - Statistics wait queue
953 * ...and the following default parameters are set -
954 * - Current key index : Set to 0
955 * - Rate index : Set to auto
956 * - Media connected : Set to disconnected
957 * - Adhoc link sensed : Set to false
958 * - Nick name : Set to null
959 * - Number of Tx timeout : Set to 0
960 * - Device address : Set to current address
961 * - Rx histogram statistc : Set to 0
963 * In addition, the CFG80211 work queue is also created.
965 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
966 struct net_device
*dev
)
968 dev
->netdev_ops
= &mwifiex_netdev_ops
;
969 dev
->destructor
= free_netdev
;
970 /* Initialize private structure */
971 priv
->current_key_index
= 0;
972 priv
->media_connected
= false;
973 memset(priv
->mgmt_ie
, 0,
974 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
975 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
976 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
977 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
978 priv
->gen_idx
= MWIFIEX_AUTO_IDX_MASK
;
979 priv
->num_tx_timeout
= 0;
980 ether_addr_copy(priv
->curr_addr
, priv
->adapter
->perm_addr
);
981 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
983 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
||
984 GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_UAP
) {
985 priv
->hist_data
= kmalloc(sizeof(*priv
->hist_data
), GFP_KERNEL
);
987 mwifiex_hist_data_reset(priv
);
992 * This function check if command is pending.
994 int is_command_pending(struct mwifiex_adapter
*adapter
)
997 int is_cmd_pend_q_empty
;
999 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
1000 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
1001 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1003 return !is_cmd_pend_q_empty
;
1007 * This is the RX work queue function.
1009 * It handles the RX operations.
1011 static void mwifiex_rx_work_queue(struct work_struct
*work
)
1013 struct mwifiex_adapter
*adapter
=
1014 container_of(work
, struct mwifiex_adapter
, rx_work
);
1016 if (adapter
->surprise_removed
)
1018 mwifiex_process_rx(adapter
);
1022 * This is the main work queue function.
1024 * It handles the main process, which in turn handles the complete
1025 * driver operations.
1027 static void mwifiex_main_work_queue(struct work_struct
*work
)
1029 struct mwifiex_adapter
*adapter
=
1030 container_of(work
, struct mwifiex_adapter
, main_work
);
1032 if (adapter
->surprise_removed
)
1034 mwifiex_main_process(adapter
);
1038 * This function adds the card.
1040 * This function follows the following major steps to set up the device -
1041 * - Initialize software. This includes probing the card, registering
1042 * the interface operations table, and allocating/initializing the
1044 * - Set up the netlink socket
1045 * - Create and start the main work queue
1046 * - Register the device
1047 * - Initialize firmware and hardware
1048 * - Add logical interfaces
1051 mwifiex_add_card(void *card
, struct semaphore
*sem
,
1052 struct mwifiex_if_ops
*if_ops
, u8 iface_type
)
1054 struct mwifiex_adapter
*adapter
;
1056 if (down_interruptible(sem
))
1059 if (mwifiex_register(card
, if_ops
, (void **)&adapter
)) {
1060 pr_err("%s: software init failed\n", __func__
);
1064 adapter
->iface_type
= iface_type
;
1065 adapter
->card_sem
= sem
;
1067 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
1068 adapter
->surprise_removed
= false;
1069 init_waitqueue_head(&adapter
->init_wait_q
);
1070 adapter
->is_suspended
= false;
1071 adapter
->hs_activated
= false;
1072 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
1073 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
1074 adapter
->cmd_wait_q
.status
= 0;
1075 adapter
->scan_wait_q_woken
= false;
1077 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
) {
1078 adapter
->rx_work_enabled
= true;
1079 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
1082 adapter
->workqueue
=
1083 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1084 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
1085 if (!adapter
->workqueue
)
1088 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
1090 if (adapter
->rx_work_enabled
) {
1091 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1095 if (!adapter
->rx_workqueue
)
1098 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
1101 if (adapter
->if_ops
.iface_work
)
1102 INIT_WORK(&adapter
->iface_work
, adapter
->if_ops
.iface_work
);
1104 /* Register the device. Fill up the private data structure with relevant
1105 information from the card. */
1106 if (adapter
->if_ops
.register_dev(adapter
)) {
1107 pr_err("%s: failed to register mwifiex device\n", __func__
);
1108 goto err_registerdev
;
1111 if (mwifiex_init_hw_fw(adapter
)) {
1112 pr_err("%s: firmware init failed\n", __func__
);
1119 pr_debug("info: %s: unregister device\n", __func__
);
1120 if (adapter
->if_ops
.unregister_dev
)
1121 adapter
->if_ops
.unregister_dev(adapter
);
1122 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
1123 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
1124 adapter
->init_wait_q_woken
= false;
1126 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
1127 wait_event_interruptible(adapter
->init_wait_q
,
1128 adapter
->init_wait_q_woken
);
1131 adapter
->surprise_removed
= true;
1132 mwifiex_terminate_workqueue(adapter
);
1134 mwifiex_free_adapter(adapter
);
1142 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
1145 * This function removes the card.
1147 * This function follows the following major steps to remove the device -
1148 * - Stop data traffic
1149 * - Shutdown firmware
1150 * - Remove the logical interfaces
1151 * - Terminate the work queue
1152 * - Unregister the device
1153 * - Free the adapter structure
1155 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
, struct semaphore
*sem
)
1157 struct mwifiex_private
*priv
= NULL
;
1160 if (down_interruptible(sem
))
1166 /* We can no longer handle interrupts once we start doing the teardown
1168 if (adapter
->if_ops
.disable_int
)
1169 adapter
->if_ops
.disable_int(adapter
);
1171 adapter
->surprise_removed
= true;
1173 mwifiex_terminate_workqueue(adapter
);
1176 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1177 priv
= adapter
->priv
[i
];
1178 if (priv
&& priv
->netdev
) {
1179 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
1180 if (netif_carrier_ok(priv
->netdev
))
1181 netif_carrier_off(priv
->netdev
);
1185 dev_dbg(adapter
->dev
, "cmd: calling mwifiex_shutdown_drv...\n");
1186 adapter
->init_wait_q_woken
= false;
1188 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
1189 wait_event_interruptible(adapter
->init_wait_q
,
1190 adapter
->init_wait_q_woken
);
1191 dev_dbg(adapter
->dev
, "cmd: mwifiex_shutdown_drv done\n");
1192 if (atomic_read(&adapter
->rx_pending
) ||
1193 atomic_read(&adapter
->tx_pending
) ||
1194 atomic_read(&adapter
->cmd_pending
)) {
1195 dev_err(adapter
->dev
, "rx_pending=%d, tx_pending=%d, "
1197 atomic_read(&adapter
->rx_pending
),
1198 atomic_read(&adapter
->tx_pending
),
1199 atomic_read(&adapter
->cmd_pending
));
1202 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1203 priv
= adapter
->priv
[i
];
1210 priv
->wdev
.iftype
!= NL80211_IFTYPE_UNSPECIFIED
)
1211 mwifiex_del_virtual_intf(adapter
->wiphy
, &priv
->wdev
);
1215 wiphy_unregister(adapter
->wiphy
);
1216 wiphy_free(adapter
->wiphy
);
1218 /* Unregister device */
1219 dev_dbg(adapter
->dev
, "info: unregister device\n");
1220 if (adapter
->if_ops
.unregister_dev
)
1221 adapter
->if_ops
.unregister_dev(adapter
);
1222 /* Free adapter structure */
1223 dev_dbg(adapter
->dev
, "info: free adapter\n");
1224 mwifiex_free_adapter(adapter
);
1231 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1234 * This function initializes the module.
1236 * The debug FS is also initialized if configured.
1239 mwifiex_init_module(void)
1241 #ifdef CONFIG_DEBUG_FS
1242 mwifiex_debugfs_init();
1248 * This function cleans up the module.
1250 * The debug FS is removed if available.
1253 mwifiex_cleanup_module(void)
1255 #ifdef CONFIG_DEBUG_FS
1256 mwifiex_debugfs_remove();
1260 module_init(mwifiex_init_module
);
1261 module_exit(mwifiex_cleanup_module
);
1263 MODULE_AUTHOR("Marvell International Ltd.");
1264 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1265 MODULE_VERSION(VERSION
);
1266 MODULE_LICENSE("GPL v2");