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>
13 #include "wilc_wfi_cfgoperations.h"
15 #define WILC_MULTICAST_TABLE_SIZE 8
17 static irqreturn_t isr_uh_routine(int irq, void *user_data)
19 struct net_device *dev = user_data;
20 struct wilc_vif *vif = netdev_priv(dev);
21 struct wilc *wilc = vif->wilc;
24 netdev_err(dev, "Can't handle UH interrupt\n");
27 return IRQ_WAKE_THREAD;
30 static irqreturn_t isr_bh_routine(int irq, void *userdata)
32 struct net_device *dev = userdata;
33 struct wilc_vif *vif = netdev_priv(userdata);
34 struct wilc *wilc = vif->wilc;
37 netdev_err(dev, "Can't handle BH interrupt\n");
41 wilc_handle_isr(wilc);
46 static int init_irq(struct net_device *dev)
49 struct wilc_vif *vif = netdev_priv(dev);
50 struct wilc *wl = vif->wilc;
52 ret = gpiod_direction_input(wl->gpio_irq);
54 netdev_err(dev, "could not obtain gpio for WILC_INTR\n");
58 wl->dev_irq_num = gpiod_to_irq(wl->gpio_irq);
60 ret = request_threaded_irq(wl->dev_irq_num, isr_uh_routine,
62 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
65 netdev_err(dev, "Failed to request IRQ\n");
67 netdev_dbg(dev, "IRQ request succeeded IRQ-NUM= %d\n",
73 static void deinit_irq(struct net_device *dev)
75 struct wilc_vif *vif = netdev_priv(dev);
76 struct wilc *wilc = vif->wilc;
78 /* Deinitialize IRQ */
79 if (wilc->dev_irq_num)
80 free_irq(wilc->dev_irq_num, wilc);
83 void wilc_mac_indicate(struct wilc *wilc)
87 wilc_wlan_cfg_get_val(wilc, WID_STATUS, &status, 1);
88 if (wilc->mac_status == WILC_MAC_STATUS_INIT) {
89 wilc->mac_status = status;
90 complete(&wilc->sync_event);
92 wilc->mac_status = status;
96 static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header)
100 struct net_device *ndev = NULL;
102 bssid = mac_header + 10;
103 bssid1 = mac_header + 4;
105 mutex_lock(&wilc->vif_mutex);
106 for (i = 0; i < wilc->vif_num; i++) {
107 if (wilc->vif[i]->mode == WILC_STATION_MODE)
108 if (ether_addr_equal_unaligned(bssid,
109 wilc->vif[i]->bssid)) {
110 ndev = wilc->vif[i]->ndev;
113 if (wilc->vif[i]->mode == WILC_AP_MODE)
114 if (ether_addr_equal_unaligned(bssid1,
115 wilc->vif[i]->bssid)) {
116 ndev = wilc->vif[i]->ndev;
121 mutex_unlock(&wilc->vif_mutex);
125 void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode)
127 struct wilc_vif *vif = netdev_priv(wilc_netdev);
130 ether_addr_copy(vif->bssid, bssid);
132 eth_zero_addr(vif->bssid);
137 int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc)
142 for (i = 0; i < wilc->vif_num; i++)
143 if (!is_zero_ether_addr(wilc->vif[i]->bssid))
149 static int wilc_txq_task(void *vp)
153 struct wilc *wl = vp;
155 complete(&wl->txq_thread_started);
157 wait_for_completion(&wl->txq_event);
160 complete(&wl->txq_thread_started);
162 while (!kthread_should_stop())
167 ret = wilc_wlan_handle_txq(wl, &txq_count);
168 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) {
170 struct wilc_vif *ifc;
172 mutex_lock(&wl->vif_mutex);
173 for (i = 0; i < wl->vif_num; i++) {
175 if (ifc->mac_opened && ifc->ndev)
176 netif_wake_queue(ifc->ndev);
178 mutex_unlock(&wl->vif_mutex);
180 } while (ret == -ENOBUFS && !wl->close);
185 static int wilc_wlan_get_firmware(struct net_device *dev)
187 struct wilc_vif *vif = netdev_priv(dev);
188 struct wilc *wilc = vif->wilc;
189 int chip_id, ret = 0;
190 const struct firmware *wilc_firmware;
193 chip_id = wilc_get_chipid(wilc, false);
195 if (chip_id < 0x1003a0)
196 firmware = FIRMWARE_1002;
198 firmware = FIRMWARE_1003;
200 netdev_info(dev, "loading firmware %s\n", firmware);
202 if (reject_firmware(&wilc_firmware, firmware, wilc->dev) != 0) {
203 netdev_err(dev, "%s - firmware not available\n", firmware);
207 wilc->firmware = wilc_firmware;
214 static int wilc_start_firmware(struct net_device *dev)
216 struct wilc_vif *vif = netdev_priv(dev);
217 struct wilc *wilc = vif->wilc;
220 ret = wilc_wlan_start(wilc);
224 if (!wait_for_completion_timeout(&wilc->sync_event,
225 msecs_to_jiffies(5000)))
231 static int wilc1000_firmware_download(struct net_device *dev)
233 struct wilc_vif *vif = netdev_priv(dev);
234 struct wilc *wilc = vif->wilc;
237 if (!wilc->firmware) {
238 netdev_err(dev, "Firmware buffer is NULL\n");
242 ret = wilc_wlan_firmware_download(wilc, wilc->firmware->data,
243 wilc->firmware->size);
247 release_firmware(wilc->firmware);
248 wilc->firmware = NULL;
250 netdev_dbg(dev, "Download Succeeded\n");
255 static int wilc_init_fw_config(struct net_device *dev, struct wilc_vif *vif)
257 struct wilc_priv *priv = &vif->priv;
258 struct host_if_drv *hif_drv;
263 netdev_dbg(dev, "Start configuring Firmware\n");
264 hif_drv = (struct host_if_drv *)priv->hif_drv;
265 netdev_dbg(dev, "Host = %p\n", hif_drv);
269 if (!wilc_wlan_cfg_set(vif, 1, WID_SET_OPERATION_MODE, (u8 *)&w, 4,
273 b = WILC_FW_BSS_TYPE_INFRA;
274 if (!wilc_wlan_cfg_set(vif, 0, WID_BSS_TYPE, &b, 1, 0, 0))
277 b = WILC_FW_TX_RATE_AUTO;
278 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_TX_RATE, &b, 1, 0, 0))
281 b = WILC_FW_OPER_MODE_G_MIXED_11B_2;
282 if (!wilc_wlan_cfg_set(vif, 0, WID_11G_OPERATING_MODE, &b, 1, 0, 0))
285 b = WILC_FW_PREAMBLE_SHORT;
286 if (!wilc_wlan_cfg_set(vif, 0, WID_PREAMBLE, &b, 1, 0, 0))
289 b = WILC_FW_11N_PROT_AUTO;
290 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_PROT_MECH, &b, 1, 0, 0))
293 b = WILC_FW_ACTIVE_SCAN;
294 if (!wilc_wlan_cfg_set(vif, 0, WID_SCAN_TYPE, &b, 1, 0, 0))
297 b = WILC_FW_SITE_SURVEY_OFF;
298 if (!wilc_wlan_cfg_set(vif, 0, WID_SITE_SURVEY, &b, 1, 0, 0))
303 if (!wilc_wlan_cfg_set(vif, 0, WID_RTS_THRESHOLD, (u8 *)&hw, 2, 0, 0))
308 if (!wilc_wlan_cfg_set(vif, 0, WID_FRAG_THRESHOLD, (u8 *)&hw, 2, 0, 0))
312 if (!wilc_wlan_cfg_set(vif, 0, WID_BCAST_SSID, &b, 1, 0, 0))
316 if (!wilc_wlan_cfg_set(vif, 0, WID_QOS_ENABLE, &b, 1, 0, 0))
319 b = WILC_FW_NO_POWERSAVE;
320 if (!wilc_wlan_cfg_set(vif, 0, WID_POWER_MANAGEMENT, &b, 1, 0, 0))
324 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_MODE, &b, 1, 0, 0))
327 b = WILC_FW_AUTH_OPEN_SYSTEM;
328 if (!wilc_wlan_cfg_set(vif, 0, WID_AUTH_TYPE, &b, 1, 0, 0))
332 if (!wilc_wlan_cfg_set(vif, 0, WID_LISTEN_INTERVAL, &b, 1, 0, 0))
336 if (!wilc_wlan_cfg_set(vif, 0, WID_DTIM_PERIOD, &b, 1, 0, 0))
339 b = WILC_FW_ACK_POLICY_NORMAL;
340 if (!wilc_wlan_cfg_set(vif, 0, WID_ACK_POLICY, &b, 1, 0, 0))
344 if (!wilc_wlan_cfg_set(vif, 0, WID_USER_CONTROL_ON_TX_POWER, &b, 1,
349 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11A, &b, 1, 0, 0))
353 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11B, &b, 1, 0, 0))
358 if (!wilc_wlan_cfg_set(vif, 0, WID_BEACON_INTERVAL, (u8 *)&hw, 2, 0, 0))
361 b = WILC_FW_REKEY_POLICY_DISABLE;
362 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_POLICY, &b, 1, 0, 0))
367 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PERIOD, (u8 *)&w, 4, 0, 0))
372 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PACKET_COUNT, (u8 *)&w, 4, 0,
377 if (!wilc_wlan_cfg_set(vif, 0, WID_SHORT_SLOT_ALLOWED, &b, 1, 0,
381 b = WILC_FW_ERP_PROT_SELF_CTS;
382 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ERP_PROT_TYPE, &b, 1, 0, 0))
386 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ENABLE, &b, 1, 0, 0))
389 b = WILC_FW_11N_OP_MODE_HT_MIXED;
390 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OPERATING_MODE, &b, 1, 0, 0))
394 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_TXOP_PROT_DISABLE, &b, 1, 0, 0))
397 b = WILC_FW_OBBS_NONHT_DETECT_PROTECT_REPORT;
398 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OBSS_NONHT_DETECTION, &b, 1,
402 b = WILC_FW_HT_PROT_RTS_CTS_NONHT;
403 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_HT_PROT_TYPE, &b, 1, 0, 0))
407 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_RIFS_PROT_ENABLE, &b, 1, 0,
412 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_CURRENT_TX_MCS, &b, 1, 0, 0))
416 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_IMMEDIATE_BA_ENABLED, &b, 1,
426 static void wlan_deinit_locks(struct net_device *dev)
428 struct wilc_vif *vif = netdev_priv(dev);
429 struct wilc *wilc = vif->wilc;
431 mutex_destroy(&wilc->hif_cs);
432 mutex_destroy(&wilc->rxq_cs);
433 mutex_destroy(&wilc->cfg_cmd_lock);
434 mutex_destroy(&wilc->txq_add_to_head_cs);
435 mutex_destroy(&wilc->vif_mutex);
438 static void wlan_deinitialize_threads(struct net_device *dev)
440 struct wilc_vif *vif = netdev_priv(dev);
441 struct wilc *wl = vif->wilc;
445 complete(&wl->txq_event);
447 if (wl->txq_thread) {
448 kthread_stop(wl->txq_thread);
449 wl->txq_thread = NULL;
453 static void wilc_wlan_deinitialize(struct net_device *dev)
455 struct wilc_vif *vif = netdev_priv(dev);
456 struct wilc *wl = vif->wilc;
459 netdev_err(dev, "wl is NULL\n");
463 if (wl->initialized) {
464 netdev_info(dev, "Deinitializing wilc1000...\n");
466 if (!wl->dev_irq_num &&
467 wl->hif_func->disable_interrupt) {
468 mutex_lock(&wl->hif_cs);
469 wl->hif_func->disable_interrupt(wl);
470 mutex_unlock(&wl->hif_cs);
472 complete(&wl->txq_event);
474 wlan_deinitialize_threads(dev);
478 wilc_wlan_cleanup(dev);
479 wlan_deinit_locks(dev);
481 wl->initialized = false;
483 netdev_dbg(dev, "wilc1000 deinitialization Done\n");
485 netdev_dbg(dev, "wilc1000 is not initialized\n");
489 static int wlan_initialize_threads(struct net_device *dev)
491 struct wilc_vif *vif = netdev_priv(dev);
492 struct wilc *wilc = vif->wilc;
494 wilc->txq_thread = kthread_run(wilc_txq_task, (void *)wilc,
496 if (IS_ERR(wilc->txq_thread)) {
497 netdev_err(dev, "couldn't create TXQ thread\n");
499 return PTR_ERR(wilc->txq_thread);
501 wait_for_completion(&wilc->txq_thread_started);
506 static int dev_state_ev_handler(struct notifier_block *this,
507 unsigned long event, void *ptr);
508 static struct notifier_block g_dev_notifier = {
509 .notifier_call = dev_state_ev_handler
512 static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
515 struct wilc *wl = vif->wilc;
517 if (!wl->initialized) {
518 wl->mac_status = WILC_MAC_STATUS_INIT;
521 ret = wilc_wlan_init(dev);
525 ret = wlan_initialize_threads(dev);
531 if (wl->gpio_irq && init_irq(dev)) {
536 if (!wl->dev_irq_num &&
537 wl->hif_func->enable_interrupt &&
538 wl->hif_func->enable_interrupt(wl)) {
543 if (wilc_wlan_get_firmware(dev)) {
545 goto fail_irq_enable;
548 ret = wilc1000_firmware_download(dev);
551 goto fail_irq_enable;
554 ret = wilc_start_firmware(dev);
557 goto fail_irq_enable;
560 if (wilc_wlan_cfg_get(vif, 1, WID_FIRMWARE_VERSION, 1, 0)) {
562 char firmware_ver[20];
564 size = wilc_wlan_cfg_get_val(wl, WID_FIRMWARE_VERSION,
566 sizeof(firmware_ver));
567 firmware_ver[size] = '\0';
568 netdev_dbg(dev, "Firmware Ver = %s\n", firmware_ver);
570 ret = wilc_init_fw_config(dev, vif);
573 netdev_err(dev, "Failed to configure firmware\n");
577 register_inetaddr_notifier(&g_dev_notifier);
578 wl->initialized = true;
585 if (!wl->dev_irq_num &&
586 wl->hif_func->disable_interrupt)
587 wl->hif_func->disable_interrupt(wl);
592 wlan_deinitialize_threads(dev);
594 wilc_wlan_cleanup(dev);
595 netdev_err(dev, "WLAN initialization FAILED\n");
597 netdev_dbg(dev, "wilc1000 already initialized\n");
602 static int mac_init_fn(struct net_device *ndev)
604 netif_start_queue(ndev);
605 netif_stop_queue(ndev);
610 static int wilc_mac_open(struct net_device *ndev)
612 struct wilc_vif *vif = netdev_priv(ndev);
613 struct wilc *wl = vif->wilc;
614 struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr);
615 unsigned char mac_add[ETH_ALEN] = {0};
618 if (!wl || !wl->dev) {
619 netdev_err(ndev, "device not ready\n");
623 netdev_dbg(ndev, "MAC OPEN[%p]\n", ndev);
625 ret = wilc_init_host_int(ndev);
629 ret = wilc_wlan_initialize(ndev, vif);
631 wilc_deinit_host_int(ndev);
635 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif), vif->iftype,
637 wilc_set_operation_mode(vif, vif->iftype);
639 wilc_get_mac_address(vif, mac_add);
640 netdev_dbg(ndev, "Mac address: %pM\n", mac_add);
641 ether_addr_copy(ndev->dev_addr, mac_add);
643 if (!is_valid_ether_addr(ndev->dev_addr)) {
644 netdev_err(ndev, "Wrong MAC address\n");
645 wilc_deinit_host_int(ndev);
646 wilc_wlan_deinitialize(ndev);
650 wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy,
651 vif->ndev->ieee80211_ptr,
652 vif->frame_reg[0].type,
653 vif->frame_reg[0].reg);
654 wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy,
655 vif->ndev->ieee80211_ptr,
656 vif->frame_reg[1].type,
657 vif->frame_reg[1].reg);
658 netif_wake_queue(ndev);
660 priv->p2p.local_random = 0x01;
665 static struct net_device_stats *mac_stats(struct net_device *dev)
667 struct wilc_vif *vif = netdev_priv(dev);
669 return &vif->netstats;
672 static void wilc_set_multicast_list(struct net_device *dev)
674 struct netdev_hw_addr *ha;
675 struct wilc_vif *vif = netdev_priv(dev);
680 if (dev->flags & IFF_PROMISC)
683 if (dev->flags & IFF_ALLMULTI ||
684 dev->mc.count > WILC_MULTICAST_TABLE_SIZE) {
685 wilc_setup_multicast_filter(vif, 0, 0, NULL);
689 if (dev->mc.count == 0) {
690 wilc_setup_multicast_filter(vif, 1, 0, NULL);
694 mc_list = kmalloc_array(dev->mc.count, ETH_ALEN, GFP_ATOMIC);
700 netdev_for_each_mc_addr(ha, dev) {
701 memcpy(cur_mc, ha->addr, ETH_ALEN);
702 netdev_dbg(dev, "Entry[%d]: %pM\n", i, cur_mc);
707 if (wilc_setup_multicast_filter(vif, 1, dev->mc.count, mc_list))
711 static void wilc_tx_complete(void *priv, int status)
713 struct tx_complete_data *pv_data = priv;
715 dev_kfree_skb(pv_data->skb);
719 netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
721 struct wilc_vif *vif = netdev_priv(ndev);
722 struct wilc *wilc = vif->wilc;
723 struct tx_complete_data *tx_data = NULL;
726 if (skb->dev != ndev) {
727 netdev_err(ndev, "Packet not destined to this device\n");
731 tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC);
734 netif_wake_queue(ndev);
738 tx_data->buff = skb->data;
739 tx_data->size = skb->len;
742 vif->netstats.tx_packets++;
743 vif->netstats.tx_bytes += tx_data->size;
744 queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,
745 tx_data->buff, tx_data->size,
748 if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
751 mutex_lock(&wilc->vif_mutex);
752 for (i = 0; i < wilc->vif_num; i++) {
753 if (wilc->vif[i]->mac_opened)
754 netif_stop_queue(wilc->vif[i]->ndev);
756 mutex_unlock(&wilc->vif_mutex);
762 static int wilc_mac_close(struct net_device *ndev)
764 struct wilc_vif *vif = netdev_priv(ndev);
765 struct wilc *wl = vif->wilc;
767 netdev_dbg(ndev, "Mac close\n");
769 if (wl->open_ifcs > 0)
775 netif_stop_queue(vif->ndev);
777 wilc_deinit_host_int(vif->ndev);
780 if (wl->open_ifcs == 0) {
781 netdev_dbg(ndev, "Deinitializing wilc1000\n");
783 unregister_inetaddr_notifier(&g_dev_notifier);
784 wilc_wlan_deinitialize(ndev);
792 void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size,
795 unsigned int frame_len = 0;
797 unsigned char *buff_to_send = NULL;
799 struct net_device *wilc_netdev;
800 struct wilc_vif *vif;
805 wilc_netdev = get_if_handler(wilc, buff);
810 vif = netdev_priv(wilc_netdev);
816 skb = dev_alloc_skb(frame_len);
820 skb->dev = wilc_netdev;
822 skb_put_data(skb, buff_to_send, frame_len);
824 skb->protocol = eth_type_trans(skb, wilc_netdev);
825 vif->netstats.rx_packets++;
826 vif->netstats.rx_bytes += frame_len;
827 skb->ip_summed = CHECKSUM_UNNECESSARY;
828 stats = netif_rx(skb);
829 netdev_dbg(wilc_netdev, "netif_rx ret value is: %d\n", stats);
833 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
836 struct wilc_vif *vif;
838 mutex_lock(&wilc->vif_mutex);
839 for (i = 0; i < wilc->vif_num; i++) {
840 u16 type = le16_to_cpup((__le16 *)buff);
842 vif = netdev_priv(wilc->vif[i]->ndev);
843 if ((type == vif->frame_reg[0].type && vif->frame_reg[0].reg) ||
844 (type == vif->frame_reg[1].type && vif->frame_reg[1].reg)) {
845 wilc_wfi_p2p_rx(vif, buff, size);
849 if (vif->monitor_flag) {
850 wilc_wfi_monitor_rx(wilc->monitor_dev, buff, size);
854 mutex_unlock(&wilc->vif_mutex);
857 static const struct net_device_ops wilc_netdev_ops = {
858 .ndo_init = mac_init_fn,
859 .ndo_open = wilc_mac_open,
860 .ndo_stop = wilc_mac_close,
861 .ndo_start_xmit = wilc_mac_xmit,
862 .ndo_get_stats = mac_stats,
863 .ndo_set_rx_mode = wilc_set_multicast_list,
866 static int dev_state_ev_handler(struct notifier_block *this,
867 unsigned long event, void *ptr)
869 struct in_ifaddr *dev_iface = ptr;
870 struct wilc_priv *priv;
871 struct host_if_drv *hif_drv;
872 struct net_device *dev;
873 struct wilc_vif *vif;
875 if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev)
878 dev = (struct net_device *)dev_iface->ifa_dev->dev;
879 if (dev->netdev_ops != &wilc_netdev_ops)
882 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
885 vif = netdev_priv(dev);
888 hif_drv = (struct host_if_drv *)priv->hif_drv;
892 if (vif->iftype == WILC_STATION_MODE ||
893 vif->iftype == WILC_CLIENT_MODE) {
895 vif->obtaining_ip = false;
896 del_timer(&vif->during_ip_timer);
899 if (vif->wilc->enable_ps)
900 wilc_set_power_mgmt(vif, 1, 0);
905 if (vif->iftype == WILC_STATION_MODE ||
906 vif->iftype == WILC_CLIENT_MODE) {
908 vif->obtaining_ip = false;
909 wilc_set_power_mgmt(vif, 0, 0);
912 wilc_resolve_disconnect_aberration(vif);
923 void wilc_netdev_cleanup(struct wilc *wilc)
930 if (wilc->firmware) {
931 release_firmware(wilc->firmware);
932 wilc->firmware = NULL;
935 for (i = 0; i < wilc->vif_num; i++) {
936 if (wilc->vif[i] && wilc->vif[i]->ndev)
937 unregister_netdev(wilc->vif[i]->ndev);
940 wilc_wfi_deinit_mon_interface(wilc, false);
941 flush_workqueue(wilc->hif_workqueue);
942 destroy_workqueue(wilc->hif_workqueue);
943 wilc_wlan_cfg_deinit(wilc);
944 kfree(wilc->bus_data);
945 wiphy_unregister(wilc->wiphy);
946 wiphy_free(wilc->wiphy);
948 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
950 struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
951 int vif_type, enum nl80211_iftype type,
954 struct net_device *ndev;
955 struct wilc_vif *vif;
958 ndev = alloc_etherdev(sizeof(*vif));
960 return ERR_PTR(-ENOMEM);
962 vif = netdev_priv(ndev);
963 ndev->ieee80211_ptr = &vif->priv.wdev;
964 strcpy(ndev->name, name);
969 ndev->netdev_ops = &wilc_netdev_ops;
971 SET_NETDEV_DEV(ndev, wiphy_dev(wl->wiphy));
973 vif->priv.wdev.wiphy = wl->wiphy;
974 vif->priv.wdev.netdev = ndev;
975 vif->priv.wdev.iftype = type;
976 vif->priv.dev = ndev;
979 ret = register_netdevice(ndev);
981 ret = register_netdev(ndev);
985 return ERR_PTR(-EFAULT);
988 ndev->needs_free_netdev = true;
989 vif->iftype = vif_type;
990 vif->wilc->vif[wl->vif_num] = vif;
991 vif->idx = wl->vif_num;
997 MODULE_LICENSE("GPL");