1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
8 #include <linux/kthread.h>
9 #include <linux/firmware.h>
10 #include <linux/netdevice.h>
11 #include <linux/inetdevice.h>
16 #define WILC_MULTICAST_TABLE_SIZE 8
18 static irqreturn_t
isr_uh_routine(int irq
, void *user_data
)
20 struct net_device
*dev
= user_data
;
21 struct wilc_vif
*vif
= netdev_priv(dev
);
22 struct wilc
*wilc
= vif
->wilc
;
25 netdev_err(dev
, "Can't handle UH interrupt\n");
28 return IRQ_WAKE_THREAD
;
31 static irqreturn_t
isr_bh_routine(int irq
, void *userdata
)
33 struct net_device
*dev
= userdata
;
34 struct wilc_vif
*vif
= netdev_priv(userdata
);
35 struct wilc
*wilc
= vif
->wilc
;
38 netdev_err(dev
, "Can't handle BH interrupt\n");
42 wilc_handle_isr(wilc
);
47 static int init_irq(struct net_device
*dev
)
49 struct wilc_vif
*vif
= netdev_priv(dev
);
50 struct wilc
*wl
= vif
->wilc
;
53 ret
= request_threaded_irq(wl
->dev_irq_num
, isr_uh_routine
,
55 IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
,
58 netdev_err(dev
, "Failed to request IRQ [%d]\n", ret
);
61 netdev_dbg(dev
, "IRQ request succeeded IRQ-NUM= %d\n", wl
->dev_irq_num
);
66 static void deinit_irq(struct net_device
*dev
)
68 struct wilc_vif
*vif
= netdev_priv(dev
);
69 struct wilc
*wilc
= vif
->wilc
;
71 /* Deinitialize IRQ */
72 if (wilc
->dev_irq_num
)
73 free_irq(wilc
->dev_irq_num
, wilc
);
76 void wilc_mac_indicate(struct wilc
*wilc
)
80 wilc_wlan_cfg_get_val(wilc
, WID_STATUS
, &status
, 1);
81 if (wilc
->mac_status
== WILC_MAC_STATUS_INIT
) {
82 wilc
->mac_status
= status
;
83 complete(&wilc
->sync_event
);
85 wilc
->mac_status
= status
;
89 static struct net_device
*get_if_handler(struct wilc
*wilc
, u8
*mac_header
)
91 struct net_device
*ndev
= NULL
;
93 struct ieee80211_hdr
*h
= (struct ieee80211_hdr
*)mac_header
;
95 list_for_each_entry_rcu(vif
, &wilc
->vif_list
, list
) {
96 if (vif
->mode
== WILC_STATION_MODE
)
97 if (ether_addr_equal_unaligned(h
->addr2
, vif
->bssid
)) {
101 if (vif
->mode
== WILC_AP_MODE
)
102 if (ether_addr_equal_unaligned(h
->addr1
, vif
->bssid
)) {
111 void wilc_wlan_set_bssid(struct net_device
*wilc_netdev
, u8
*bssid
, u8 mode
)
113 struct wilc_vif
*vif
= netdev_priv(wilc_netdev
);
116 ether_addr_copy(vif
->bssid
, bssid
);
118 eth_zero_addr(vif
->bssid
);
123 int wilc_wlan_get_num_conn_ifcs(struct wilc
*wilc
)
127 struct wilc_vif
*vif
;
129 srcu_idx
= srcu_read_lock(&wilc
->srcu
);
130 list_for_each_entry_rcu(vif
, &wilc
->vif_list
, list
) {
131 if (!is_zero_ether_addr(vif
->bssid
))
134 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
138 static int wilc_txq_task(void *vp
)
142 struct wilc
*wl
= vp
;
144 complete(&wl
->txq_thread_started
);
146 wait_for_completion(&wl
->txq_event
);
149 complete(&wl
->txq_thread_started
);
151 while (!kthread_should_stop())
156 ret
= wilc_wlan_handle_txq(wl
, &txq_count
);
157 if (txq_count
< FLOW_CONTROL_LOWER_THRESHOLD
) {
159 struct wilc_vif
*ifc
;
161 srcu_idx
= srcu_read_lock(&wl
->srcu
);
162 list_for_each_entry_rcu(ifc
, &wl
->vif_list
,
164 if (ifc
->mac_opened
&& ifc
->ndev
)
165 netif_wake_queue(ifc
->ndev
);
167 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
169 } while (ret
== WILC_VMM_ENTRY_FULL_RETRY
&& !wl
->close
);
174 static int wilc_wlan_get_firmware(struct net_device
*dev
)
176 struct wilc_vif
*vif
= netdev_priv(dev
);
177 struct wilc
*wilc
= vif
->wilc
;
179 const struct firmware
*wilc_firmware
;
182 chip_id
= wilc_get_chipid(wilc
, false);
184 if (chip_id
< 0x1003a0)
185 firmware
= FIRMWARE_1002
;
187 firmware
= FIRMWARE_1003
;
189 netdev_info(dev
, "loading firmware %s\n", firmware
);
191 if (request_firmware(&wilc_firmware
, firmware
, wilc
->dev
) != 0) {
192 netdev_err(dev
, "%s - firmware not available\n", firmware
);
195 wilc
->firmware
= wilc_firmware
;
200 static int wilc_start_firmware(struct net_device
*dev
)
202 struct wilc_vif
*vif
= netdev_priv(dev
);
203 struct wilc
*wilc
= vif
->wilc
;
206 ret
= wilc_wlan_start(wilc
);
210 if (!wait_for_completion_timeout(&wilc
->sync_event
,
211 msecs_to_jiffies(5000)))
217 static int wilc1000_firmware_download(struct net_device
*dev
)
219 struct wilc_vif
*vif
= netdev_priv(dev
);
220 struct wilc
*wilc
= vif
->wilc
;
223 if (!wilc
->firmware
) {
224 netdev_err(dev
, "Firmware buffer is NULL\n");
228 ret
= wilc_wlan_firmware_download(wilc
, wilc
->firmware
->data
,
229 wilc
->firmware
->size
);
233 release_firmware(wilc
->firmware
);
234 wilc
->firmware
= NULL
;
236 netdev_dbg(dev
, "Download Succeeded\n");
241 static int wilc_init_fw_config(struct net_device
*dev
, struct wilc_vif
*vif
)
243 struct wilc_priv
*priv
= &vif
->priv
;
244 struct host_if_drv
*hif_drv
;
249 netdev_dbg(dev
, "Start configuring Firmware\n");
250 hif_drv
= (struct host_if_drv
*)priv
->hif_drv
;
251 netdev_dbg(dev
, "Host = %p\n", hif_drv
);
255 if (!wilc_wlan_cfg_set(vif
, 1, WID_SET_OPERATION_MODE
, (u8
*)&w
, 4,
259 b
= WILC_FW_BSS_TYPE_INFRA
;
260 if (!wilc_wlan_cfg_set(vif
, 0, WID_BSS_TYPE
, &b
, 1, 0, 0))
263 b
= WILC_FW_TX_RATE_AUTO
;
264 if (!wilc_wlan_cfg_set(vif
, 0, WID_CURRENT_TX_RATE
, &b
, 1, 0, 0))
267 b
= WILC_FW_OPER_MODE_G_MIXED_11B_2
;
268 if (!wilc_wlan_cfg_set(vif
, 0, WID_11G_OPERATING_MODE
, &b
, 1, 0, 0))
271 b
= WILC_FW_PREAMBLE_SHORT
;
272 if (!wilc_wlan_cfg_set(vif
, 0, WID_PREAMBLE
, &b
, 1, 0, 0))
275 b
= WILC_FW_11N_PROT_AUTO
;
276 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_PROT_MECH
, &b
, 1, 0, 0))
279 b
= WILC_FW_ACTIVE_SCAN
;
280 if (!wilc_wlan_cfg_set(vif
, 0, WID_SCAN_TYPE
, &b
, 1, 0, 0))
283 b
= WILC_FW_SITE_SURVEY_OFF
;
284 if (!wilc_wlan_cfg_set(vif
, 0, WID_SITE_SURVEY
, &b
, 1, 0, 0))
289 if (!wilc_wlan_cfg_set(vif
, 0, WID_RTS_THRESHOLD
, (u8
*)&hw
, 2, 0, 0))
294 if (!wilc_wlan_cfg_set(vif
, 0, WID_FRAG_THRESHOLD
, (u8
*)&hw
, 2, 0, 0))
298 if (!wilc_wlan_cfg_set(vif
, 0, WID_BCAST_SSID
, &b
, 1, 0, 0))
302 if (!wilc_wlan_cfg_set(vif
, 0, WID_QOS_ENABLE
, &b
, 1, 0, 0))
305 b
= WILC_FW_NO_POWERSAVE
;
306 if (!wilc_wlan_cfg_set(vif
, 0, WID_POWER_MANAGEMENT
, &b
, 1, 0, 0))
310 if (!wilc_wlan_cfg_set(vif
, 0, WID_11I_MODE
, &b
, 1, 0, 0))
313 b
= WILC_FW_AUTH_OPEN_SYSTEM
;
314 if (!wilc_wlan_cfg_set(vif
, 0, WID_AUTH_TYPE
, &b
, 1, 0, 0))
318 if (!wilc_wlan_cfg_set(vif
, 0, WID_LISTEN_INTERVAL
, &b
, 1, 0, 0))
322 if (!wilc_wlan_cfg_set(vif
, 0, WID_DTIM_PERIOD
, &b
, 1, 0, 0))
325 b
= WILC_FW_ACK_POLICY_NORMAL
;
326 if (!wilc_wlan_cfg_set(vif
, 0, WID_ACK_POLICY
, &b
, 1, 0, 0))
330 if (!wilc_wlan_cfg_set(vif
, 0, WID_USER_CONTROL_ON_TX_POWER
, &b
, 1,
335 if (!wilc_wlan_cfg_set(vif
, 0, WID_TX_POWER_LEVEL_11A
, &b
, 1, 0, 0))
339 if (!wilc_wlan_cfg_set(vif
, 0, WID_TX_POWER_LEVEL_11B
, &b
, 1, 0, 0))
344 if (!wilc_wlan_cfg_set(vif
, 0, WID_BEACON_INTERVAL
, (u8
*)&hw
, 2, 0, 0))
347 b
= WILC_FW_REKEY_POLICY_DISABLE
;
348 if (!wilc_wlan_cfg_set(vif
, 0, WID_REKEY_POLICY
, &b
, 1, 0, 0))
353 if (!wilc_wlan_cfg_set(vif
, 0, WID_REKEY_PERIOD
, (u8
*)&w
, 4, 0, 0))
358 if (!wilc_wlan_cfg_set(vif
, 0, WID_REKEY_PACKET_COUNT
, (u8
*)&w
, 4, 0,
363 if (!wilc_wlan_cfg_set(vif
, 0, WID_SHORT_SLOT_ALLOWED
, &b
, 1, 0,
367 b
= WILC_FW_ERP_PROT_SELF_CTS
;
368 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_ERP_PROT_TYPE
, &b
, 1, 0, 0))
372 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_ENABLE
, &b
, 1, 0, 0))
375 b
= WILC_FW_11N_OP_MODE_HT_MIXED
;
376 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_OPERATING_MODE
, &b
, 1, 0, 0))
380 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_TXOP_PROT_DISABLE
, &b
, 1, 0, 0))
383 b
= WILC_FW_OBBS_NONHT_DETECT_PROTECT_REPORT
;
384 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_OBSS_NONHT_DETECTION
, &b
, 1,
388 b
= WILC_FW_HT_PROT_RTS_CTS_NONHT
;
389 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_HT_PROT_TYPE
, &b
, 1, 0, 0))
393 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_RIFS_PROT_ENABLE
, &b
, 1, 0,
398 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_CURRENT_TX_MCS
, &b
, 1, 0, 0))
402 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_IMMEDIATE_BA_ENABLED
, &b
, 1,
412 static void wlan_deinitialize_threads(struct net_device
*dev
)
414 struct wilc_vif
*vif
= netdev_priv(dev
);
415 struct wilc
*wl
= vif
->wilc
;
419 complete(&wl
->txq_event
);
421 if (wl
->txq_thread
) {
422 kthread_stop(wl
->txq_thread
);
423 wl
->txq_thread
= NULL
;
427 static void wilc_wlan_deinitialize(struct net_device
*dev
)
429 struct wilc_vif
*vif
= netdev_priv(dev
);
430 struct wilc
*wl
= vif
->wilc
;
433 netdev_err(dev
, "wl is NULL\n");
437 if (wl
->initialized
) {
438 netdev_info(dev
, "Deinitializing wilc1000...\n");
440 if (!wl
->dev_irq_num
&&
441 wl
->hif_func
->disable_interrupt
) {
442 mutex_lock(&wl
->hif_cs
);
443 wl
->hif_func
->disable_interrupt(wl
);
444 mutex_unlock(&wl
->hif_cs
);
446 complete(&wl
->txq_event
);
448 wlan_deinitialize_threads(dev
);
451 wilc_wlan_stop(wl
, vif
);
452 wilc_wlan_cleanup(dev
);
454 wl
->initialized
= false;
456 netdev_dbg(dev
, "wilc1000 deinitialization Done\n");
458 netdev_dbg(dev
, "wilc1000 is not initialized\n");
462 static int wlan_initialize_threads(struct net_device
*dev
)
464 struct wilc_vif
*vif
= netdev_priv(dev
);
465 struct wilc
*wilc
= vif
->wilc
;
467 wilc
->txq_thread
= kthread_run(wilc_txq_task
, (void *)wilc
,
469 if (IS_ERR(wilc
->txq_thread
)) {
470 netdev_err(dev
, "couldn't create TXQ thread\n");
472 return PTR_ERR(wilc
->txq_thread
);
474 wait_for_completion(&wilc
->txq_thread_started
);
479 static int wilc_wlan_initialize(struct net_device
*dev
, struct wilc_vif
*vif
)
482 struct wilc
*wl
= vif
->wilc
;
484 if (!wl
->initialized
) {
485 wl
->mac_status
= WILC_MAC_STATUS_INIT
;
488 ret
= wilc_wlan_init(dev
);
492 ret
= wlan_initialize_threads(dev
);
496 if (wl
->dev_irq_num
&& init_irq(dev
)) {
501 if (!wl
->dev_irq_num
&&
502 wl
->hif_func
->enable_interrupt
&&
503 wl
->hif_func
->enable_interrupt(wl
)) {
508 ret
= wilc_wlan_get_firmware(dev
);
510 goto fail_irq_enable
;
512 ret
= wilc1000_firmware_download(dev
);
514 goto fail_irq_enable
;
516 ret
= wilc_start_firmware(dev
);
518 goto fail_irq_enable
;
520 if (wilc_wlan_cfg_get(vif
, 1, WID_FIRMWARE_VERSION
, 1, 0)) {
522 char firmware_ver
[20];
524 size
= wilc_wlan_cfg_get_val(wl
, WID_FIRMWARE_VERSION
,
526 sizeof(firmware_ver
));
527 firmware_ver
[size
] = '\0';
528 netdev_dbg(dev
, "Firmware Ver = %s\n", firmware_ver
);
531 ret
= wilc_init_fw_config(dev
, vif
);
533 netdev_err(dev
, "Failed to configure firmware\n");
536 wl
->initialized
= true;
540 wilc_wlan_stop(wl
, vif
);
543 if (!wl
->dev_irq_num
&&
544 wl
->hif_func
->disable_interrupt
)
545 wl
->hif_func
->disable_interrupt(wl
);
550 wlan_deinitialize_threads(dev
);
552 wilc_wlan_cleanup(dev
);
553 netdev_err(dev
, "WLAN initialization FAILED\n");
555 netdev_dbg(dev
, "wilc1000 already initialized\n");
560 static int mac_init_fn(struct net_device
*ndev
)
562 netif_start_queue(ndev
);
563 netif_stop_queue(ndev
);
568 static int wilc_mac_open(struct net_device
*ndev
)
570 struct wilc_vif
*vif
= netdev_priv(ndev
);
571 struct wilc
*wl
= vif
->wilc
;
572 unsigned char mac_add
[ETH_ALEN
] = {0};
575 if (!wl
|| !wl
->dev
) {
576 netdev_err(ndev
, "device not ready\n");
580 netdev_dbg(ndev
, "MAC OPEN[%p]\n", ndev
);
582 ret
= wilc_init_host_int(ndev
);
586 ret
= wilc_wlan_initialize(ndev
, vif
);
588 wilc_deinit_host_int(ndev
);
592 wilc_set_operation_mode(vif
, wilc_get_vif_idx(vif
), vif
->iftype
,
594 wilc_get_mac_address(vif
, mac_add
);
595 netdev_dbg(ndev
, "Mac address: %pM\n", mac_add
);
596 ether_addr_copy(ndev
->dev_addr
, mac_add
);
598 if (!is_valid_ether_addr(ndev
->dev_addr
)) {
599 netdev_err(ndev
, "Wrong MAC address\n");
600 wilc_deinit_host_int(ndev
);
601 wilc_wlan_deinitialize(ndev
);
605 wilc_mgmt_frame_register(vif
->ndev
->ieee80211_ptr
->wiphy
,
606 vif
->ndev
->ieee80211_ptr
,
607 vif
->frame_reg
[0].type
,
608 vif
->frame_reg
[0].reg
);
609 wilc_mgmt_frame_register(vif
->ndev
->ieee80211_ptr
->wiphy
,
610 vif
->ndev
->ieee80211_ptr
,
611 vif
->frame_reg
[1].type
,
612 vif
->frame_reg
[1].reg
);
613 netif_wake_queue(ndev
);
619 static struct net_device_stats
*mac_stats(struct net_device
*dev
)
621 struct wilc_vif
*vif
= netdev_priv(dev
);
623 return &vif
->netstats
;
626 static void wilc_set_multicast_list(struct net_device
*dev
)
628 struct netdev_hw_addr
*ha
;
629 struct wilc_vif
*vif
= netdev_priv(dev
);
634 if (dev
->flags
& IFF_PROMISC
)
637 if (dev
->flags
& IFF_ALLMULTI
||
638 dev
->mc
.count
> WILC_MULTICAST_TABLE_SIZE
) {
639 wilc_setup_multicast_filter(vif
, 0, 0, NULL
);
643 if (dev
->mc
.count
== 0) {
644 wilc_setup_multicast_filter(vif
, 1, 0, NULL
);
648 mc_list
= kmalloc_array(dev
->mc
.count
, ETH_ALEN
, GFP_ATOMIC
);
654 netdev_for_each_mc_addr(ha
, dev
) {
655 memcpy(cur_mc
, ha
->addr
, ETH_ALEN
);
656 netdev_dbg(dev
, "Entry[%d]: %pM\n", i
, cur_mc
);
661 if (wilc_setup_multicast_filter(vif
, 1, dev
->mc
.count
, mc_list
))
665 static void wilc_tx_complete(void *priv
, int status
)
667 struct tx_complete_data
*pv_data
= priv
;
669 dev_kfree_skb(pv_data
->skb
);
673 netdev_tx_t
wilc_mac_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
675 struct wilc_vif
*vif
= netdev_priv(ndev
);
676 struct wilc
*wilc
= vif
->wilc
;
677 struct tx_complete_data
*tx_data
= NULL
;
680 if (skb
->dev
!= ndev
) {
681 netdev_err(ndev
, "Packet not destined to this device\n");
685 tx_data
= kmalloc(sizeof(*tx_data
), GFP_ATOMIC
);
688 netif_wake_queue(ndev
);
692 tx_data
->buff
= skb
->data
;
693 tx_data
->size
= skb
->len
;
696 vif
->netstats
.tx_packets
++;
697 vif
->netstats
.tx_bytes
+= tx_data
->size
;
698 queue_count
= wilc_wlan_txq_add_net_pkt(ndev
, (void *)tx_data
,
699 tx_data
->buff
, tx_data
->size
,
702 if (queue_count
> FLOW_CONTROL_UPPER_THRESHOLD
) {
704 struct wilc_vif
*vif
;
706 srcu_idx
= srcu_read_lock(&wilc
->srcu
);
707 list_for_each_entry_rcu(vif
, &wilc
->vif_list
, list
) {
709 netif_stop_queue(vif
->ndev
);
711 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
717 static int wilc_mac_close(struct net_device
*ndev
)
719 struct wilc_vif
*vif
= netdev_priv(ndev
);
720 struct wilc
*wl
= vif
->wilc
;
722 netdev_dbg(ndev
, "Mac close\n");
724 if (wl
->open_ifcs
> 0)
730 netif_stop_queue(vif
->ndev
);
732 wilc_deinit_host_int(vif
->ndev
);
735 if (wl
->open_ifcs
== 0) {
736 netdev_dbg(ndev
, "Deinitializing wilc1000\n");
738 wilc_wlan_deinitialize(ndev
);
746 void wilc_frmw_to_host(struct wilc
*wilc
, u8
*buff
, u32 size
,
749 unsigned int frame_len
= 0;
751 unsigned char *buff_to_send
= NULL
;
753 struct net_device
*wilc_netdev
;
754 struct wilc_vif
*vif
;
759 wilc_netdev
= get_if_handler(wilc
, buff
);
764 vif
= netdev_priv(wilc_netdev
);
770 skb
= dev_alloc_skb(frame_len
);
774 skb
->dev
= wilc_netdev
;
776 skb_put_data(skb
, buff_to_send
, frame_len
);
778 skb
->protocol
= eth_type_trans(skb
, wilc_netdev
);
779 vif
->netstats
.rx_packets
++;
780 vif
->netstats
.rx_bytes
+= frame_len
;
781 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
782 stats
= netif_rx(skb
);
783 netdev_dbg(wilc_netdev
, "netif_rx ret value is: %d\n", stats
);
787 void wilc_wfi_mgmt_rx(struct wilc
*wilc
, u8
*buff
, u32 size
)
790 struct wilc_vif
*vif
;
792 srcu_idx
= srcu_read_lock(&wilc
->srcu
);
793 list_for_each_entry_rcu(vif
, &wilc
->vif_list
, list
) {
794 u16 type
= le16_to_cpup((__le16
*)buff
);
796 if (vif
->priv
.p2p_listen_state
&&
797 ((type
== vif
->frame_reg
[0].type
&&
798 vif
->frame_reg
[0].reg
) ||
799 (type
== vif
->frame_reg
[1].type
&&
800 vif
->frame_reg
[1].reg
)))
801 wilc_wfi_p2p_rx(vif
, buff
, size
);
803 if (vif
->monitor_flag
)
804 wilc_wfi_monitor_rx(wilc
->monitor_dev
, buff
, size
);
806 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
809 static const struct net_device_ops wilc_netdev_ops
= {
810 .ndo_init
= mac_init_fn
,
811 .ndo_open
= wilc_mac_open
,
812 .ndo_stop
= wilc_mac_close
,
813 .ndo_start_xmit
= wilc_mac_xmit
,
814 .ndo_get_stats
= mac_stats
,
815 .ndo_set_rx_mode
= wilc_set_multicast_list
,
818 void wilc_netdev_cleanup(struct wilc
*wilc
)
820 struct wilc_vif
*vif
;
821 int srcu_idx
, ifc_cnt
= 0;
826 if (wilc
->firmware
) {
827 release_firmware(wilc
->firmware
);
828 wilc
->firmware
= NULL
;
831 srcu_idx
= srcu_read_lock(&wilc
->srcu
);
832 list_for_each_entry_rcu(vif
, &wilc
->vif_list
, list
) {
834 unregister_netdev(vif
->ndev
);
836 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
838 wilc_wfi_deinit_mon_interface(wilc
, false);
839 flush_workqueue(wilc
->hif_workqueue
);
840 destroy_workqueue(wilc
->hif_workqueue
);
842 while (ifc_cnt
< WILC_NUM_CONCURRENT_IFC
) {
843 mutex_lock(&wilc
->vif_mutex
);
844 if (wilc
->vif_num
<= 0) {
845 mutex_unlock(&wilc
->vif_mutex
);
848 vif
= wilc_get_wl_to_vif(wilc
);
850 list_del_rcu(&vif
->list
);
853 mutex_unlock(&wilc
->vif_mutex
);
854 synchronize_srcu(&wilc
->srcu
);
858 wilc_wlan_cfg_deinit(wilc
);
859 wlan_deinit_locks(wilc
);
860 kfree(wilc
->bus_data
);
861 wiphy_unregister(wilc
->wiphy
);
862 wiphy_free(wilc
->wiphy
);
864 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup
);
866 static u8
wilc_get_available_idx(struct wilc
*wl
)
869 struct wilc_vif
*vif
;
872 srcu_idx
= srcu_read_lock(&wl
->srcu
);
873 list_for_each_entry_rcu(vif
, &wl
->vif_list
, list
) {
879 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
883 struct wilc_vif
*wilc_netdev_ifc_init(struct wilc
*wl
, const char *name
,
884 int vif_type
, enum nl80211_iftype type
,
887 struct net_device
*ndev
;
888 struct wilc_vif
*vif
;
891 ndev
= alloc_etherdev(sizeof(*vif
));
893 return ERR_PTR(-ENOMEM
);
895 vif
= netdev_priv(ndev
);
896 ndev
->ieee80211_ptr
= &vif
->priv
.wdev
;
897 strcpy(ndev
->name
, name
);
902 ndev
->netdev_ops
= &wilc_netdev_ops
;
904 SET_NETDEV_DEV(ndev
, wiphy_dev(wl
->wiphy
));
906 vif
->priv
.wdev
.wiphy
= wl
->wiphy
;
907 vif
->priv
.wdev
.netdev
= ndev
;
908 vif
->priv
.wdev
.iftype
= type
;
909 vif
->priv
.dev
= ndev
;
912 ret
= register_netdevice(ndev
);
914 ret
= register_netdev(ndev
);
918 return ERR_PTR(-EFAULT
);
921 ndev
->needs_free_netdev
= true;
922 vif
->iftype
= vif_type
;
923 vif
->idx
= wilc_get_available_idx(wl
);
925 mutex_lock(&wl
->vif_mutex
);
926 list_add_tail_rcu(&vif
->list
, &wl
->vif_list
);
928 mutex_unlock(&wl
->vif_mutex
);
929 synchronize_srcu(&wl
->srcu
);
934 MODULE_LICENSE("GPL");