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
17 #define WILC_MAX_FW_VERSION_STR_SIZE 50
19 /* latest API version supported */
20 #define WILC1000_API_VER 1
23 #define __WILC1000_FW(api) "/*(DEBLOBBED)*/"
24 #define WILC1000_FW(api) __WILC1000_FW(api)
26 static irqreturn_t isr_uh_routine(int irq, void *user_data)
28 struct wilc *wilc = user_data;
31 pr_err("Can't handle UH interrupt\n");
34 return IRQ_WAKE_THREAD;
37 static irqreturn_t isr_bh_routine(int irq, void *userdata)
39 struct wilc *wilc = userdata;
42 pr_err("Can't handle BH interrupt\n");
46 wilc_handle_isr(wilc);
51 static int init_irq(struct net_device *dev)
53 struct wilc_vif *vif = netdev_priv(dev);
54 struct wilc *wl = vif->wilc;
57 ret = request_threaded_irq(wl->dev_irq_num, isr_uh_routine,
59 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
62 netdev_err(dev, "Failed to request IRQ [%d]\n", ret);
65 netdev_dbg(dev, "IRQ request succeeded IRQ-NUM= %d\n", wl->dev_irq_num);
70 static void deinit_irq(struct net_device *dev)
72 struct wilc_vif *vif = netdev_priv(dev);
73 struct wilc *wilc = vif->wilc;
75 /* Deinitialize IRQ */
76 if (wilc->dev_irq_num)
77 free_irq(wilc->dev_irq_num, wilc);
80 void wilc_mac_indicate(struct wilc *wilc)
84 wilc_wlan_cfg_get_val(wilc, WID_STATUS, &status, 1);
85 if (wilc->mac_status == WILC_MAC_STATUS_INIT) {
86 wilc->mac_status = status;
87 complete(&wilc->sync_event);
89 wilc->mac_status = status;
93 static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header)
95 struct net_device *ndev = NULL;
97 struct ieee80211_hdr *h = (struct ieee80211_hdr *)mac_header;
99 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
100 if (vif->iftype == WILC_STATION_MODE)
101 if (ether_addr_equal_unaligned(h->addr2, vif->bssid)) {
105 if (vif->iftype == WILC_AP_MODE)
106 if (ether_addr_equal_unaligned(h->addr1, vif->bssid)) {
115 void wilc_wlan_set_bssid(struct net_device *wilc_netdev, const u8 *bssid,
118 struct wilc_vif *vif = netdev_priv(wilc_netdev);
121 ether_addr_copy(vif->bssid, bssid);
123 eth_zero_addr(vif->bssid);
128 int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc)
132 struct wilc_vif *vif;
134 srcu_idx = srcu_read_lock(&wilc->srcu);
135 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
136 if (!is_zero_ether_addr(vif->bssid))
139 srcu_read_unlock(&wilc->srcu, srcu_idx);
143 static int wilc_txq_task(void *vp)
147 struct wilc *wl = vp;
149 complete(&wl->txq_thread_started);
151 if (wait_for_completion_interruptible(&wl->txq_event))
154 complete(&wl->txq_thread_started);
156 while (!kthread_should_stop())
161 ret = wilc_wlan_handle_txq(wl, &txq_count);
162 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) {
164 struct wilc_vif *ifc;
166 srcu_idx = srcu_read_lock(&wl->srcu);
167 list_for_each_entry_rcu(ifc, &wl->vif_list,
169 if (ifc->mac_opened &&
170 netif_queue_stopped(ifc->ndev))
171 netif_wake_queue(ifc->ndev);
173 srcu_read_unlock(&wl->srcu, srcu_idx);
175 if (ret != WILC_VMM_ENTRY_FULL_RETRY)
177 /* Back off TX task from sending packets for some time.
178 * msleep_interruptible will allow RX task to run and
179 * free buffers. TX task will be in TASK_INTERRUPTIBLE
180 * state which will put the thread back to CPU running
181 * queue when it's signaled even if the timeout isn't
182 * elapsed. This gives faster chance for reserved SK
183 * buffers to be free.
185 msleep_interruptible(TX_BACKOFF_WEIGHT_MS);
186 } while (!wl->close);
191 static int wilc_wlan_get_firmware(struct net_device *dev)
193 struct wilc_vif *vif = netdev_priv(dev);
194 struct wilc *wilc = vif->wilc;
196 const struct firmware *wilc_fw;
199 chip_id = wilc_get_chipid(wilc, false);
201 netdev_info(dev, "ChipID [%x] loading firmware [%s]\n", chip_id,
202 WILC1000_FW(WILC1000_API_VER));
204 ret = reject_firmware(&wilc_fw, WILC1000_FW(WILC1000_API_VER),
207 netdev_err(dev, "%s - firmware not available\n",
208 WILC1000_FW(WILC1000_API_VER));
211 wilc->firmware = wilc_fw;
216 static int wilc_start_firmware(struct net_device *dev)
218 struct wilc_vif *vif = netdev_priv(dev);
219 struct wilc *wilc = vif->wilc;
222 ret = wilc_wlan_start(wilc);
226 if (!wait_for_completion_timeout(&wilc->sync_event,
227 msecs_to_jiffies(5000)))
233 static int wilc1000_firmware_download(struct net_device *dev)
235 struct wilc_vif *vif = netdev_priv(dev);
236 struct wilc *wilc = vif->wilc;
239 if (!wilc->firmware) {
240 netdev_err(dev, "Firmware buffer is NULL\n");
244 ret = wilc_wlan_firmware_download(wilc, wilc->firmware->data,
245 wilc->firmware->size);
249 release_firmware(wilc->firmware);
250 wilc->firmware = NULL;
252 netdev_dbg(dev, "Download Succeeded\n");
257 static int wilc_init_fw_config(struct net_device *dev, struct wilc_vif *vif)
259 struct wilc_priv *priv = &vif->priv;
260 struct host_if_drv *hif_drv;
265 netdev_dbg(dev, "Start configuring Firmware\n");
266 hif_drv = (struct host_if_drv *)priv->hif_drv;
267 netdev_dbg(dev, "Host = %p\n", hif_drv);
271 if (!wilc_wlan_cfg_set(vif, 1, WID_SET_OPERATION_MODE, (u8 *)&w, 4,
275 b = WILC_FW_BSS_TYPE_INFRA;
276 if (!wilc_wlan_cfg_set(vif, 0, WID_BSS_TYPE, &b, 1, 0, 0))
279 b = WILC_FW_TX_RATE_AUTO;
280 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_TX_RATE, &b, 1, 0, 0))
283 b = WILC_FW_OPER_MODE_G_MIXED_11B_2;
284 if (!wilc_wlan_cfg_set(vif, 0, WID_11G_OPERATING_MODE, &b, 1, 0, 0))
287 b = WILC_FW_PREAMBLE_SHORT;
288 if (!wilc_wlan_cfg_set(vif, 0, WID_PREAMBLE, &b, 1, 0, 0))
291 b = WILC_FW_11N_PROT_AUTO;
292 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_PROT_MECH, &b, 1, 0, 0))
295 b = WILC_FW_ACTIVE_SCAN;
296 if (!wilc_wlan_cfg_set(vif, 0, WID_SCAN_TYPE, &b, 1, 0, 0))
299 b = WILC_FW_SITE_SURVEY_OFF;
300 if (!wilc_wlan_cfg_set(vif, 0, WID_SITE_SURVEY, &b, 1, 0, 0))
305 if (!wilc_wlan_cfg_set(vif, 0, WID_RTS_THRESHOLD, (u8 *)&hw, 2, 0, 0))
310 if (!wilc_wlan_cfg_set(vif, 0, WID_FRAG_THRESHOLD, (u8 *)&hw, 2, 0, 0))
314 if (!wilc_wlan_cfg_set(vif, 0, WID_BCAST_SSID, &b, 1, 0, 0))
318 if (!wilc_wlan_cfg_set(vif, 0, WID_QOS_ENABLE, &b, 1, 0, 0))
321 b = WILC_FW_NO_POWERSAVE;
322 if (!wilc_wlan_cfg_set(vif, 0, WID_POWER_MANAGEMENT, &b, 1, 0, 0))
326 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_MODE, &b, 1, 0, 0))
329 b = WILC_FW_AUTH_OPEN_SYSTEM;
330 if (!wilc_wlan_cfg_set(vif, 0, WID_AUTH_TYPE, &b, 1, 0, 0))
334 if (!wilc_wlan_cfg_set(vif, 0, WID_LISTEN_INTERVAL, &b, 1, 0, 0))
338 if (!wilc_wlan_cfg_set(vif, 0, WID_DTIM_PERIOD, &b, 1, 0, 0))
341 b = WILC_FW_ACK_POLICY_NORMAL;
342 if (!wilc_wlan_cfg_set(vif, 0, WID_ACK_POLICY, &b, 1, 0, 0))
346 if (!wilc_wlan_cfg_set(vif, 0, WID_USER_CONTROL_ON_TX_POWER, &b, 1,
351 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11A, &b, 1, 0, 0))
355 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11B, &b, 1, 0, 0))
360 if (!wilc_wlan_cfg_set(vif, 0, WID_BEACON_INTERVAL, (u8 *)&hw, 2, 0, 0))
363 b = WILC_FW_REKEY_POLICY_DISABLE;
364 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_POLICY, &b, 1, 0, 0))
369 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PERIOD, (u8 *)&w, 4, 0, 0))
374 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PACKET_COUNT, (u8 *)&w, 4, 0,
379 if (!wilc_wlan_cfg_set(vif, 0, WID_SHORT_SLOT_ALLOWED, &b, 1, 0,
383 b = WILC_FW_ERP_PROT_SELF_CTS;
384 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ERP_PROT_TYPE, &b, 1, 0, 0))
388 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ENABLE, &b, 1, 0, 0))
391 b = WILC_FW_11N_OP_MODE_HT_MIXED;
392 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OPERATING_MODE, &b, 1, 0, 0))
396 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_TXOP_PROT_DISABLE, &b, 1, 0, 0))
399 b = WILC_FW_OBBS_NONHT_DETECT_PROTECT_REPORT;
400 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OBSS_NONHT_DETECTION, &b, 1,
404 b = WILC_FW_HT_PROT_RTS_CTS_NONHT;
405 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_HT_PROT_TYPE, &b, 1, 0, 0))
409 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_RIFS_PROT_ENABLE, &b, 1, 0,
414 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_CURRENT_TX_MCS, &b, 1, 0, 0))
418 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_IMMEDIATE_BA_ENABLED, &b, 1,
428 static void wlan_deinitialize_threads(struct net_device *dev)
430 struct wilc_vif *vif = netdev_priv(dev);
431 struct wilc *wl = vif->wilc;
435 complete(&wl->txq_event);
437 if (wl->txq_thread) {
438 kthread_stop(wl->txq_thread);
439 wl->txq_thread = NULL;
443 static void wilc_wlan_deinitialize(struct net_device *dev)
445 struct wilc_vif *vif = netdev_priv(dev);
446 struct wilc *wl = vif->wilc;
449 netdev_err(dev, "wl is NULL\n");
453 if (wl->initialized) {
454 netdev_info(dev, "Deinitializing wilc1000...\n");
456 if (!wl->dev_irq_num &&
457 wl->hif_func->disable_interrupt) {
458 mutex_lock(&wl->hif_cs);
459 wl->hif_func->disable_interrupt(wl);
460 mutex_unlock(&wl->hif_cs);
462 complete(&wl->txq_event);
464 wlan_deinitialize_threads(dev);
467 wilc_wlan_stop(wl, vif);
468 wilc_wlan_cleanup(dev);
470 wl->initialized = false;
472 netdev_dbg(dev, "wilc1000 deinitialization Done\n");
474 netdev_dbg(dev, "wilc1000 is not initialized\n");
478 static int wlan_initialize_threads(struct net_device *dev)
480 struct wilc_vif *vif = netdev_priv(dev);
481 struct wilc *wilc = vif->wilc;
483 wilc->txq_thread = kthread_run(wilc_txq_task, (void *)wilc,
485 if (IS_ERR(wilc->txq_thread)) {
486 netdev_err(dev, "couldn't create TXQ thread\n");
488 return PTR_ERR(wilc->txq_thread);
490 wait_for_completion(&wilc->txq_thread_started);
495 static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
498 struct wilc *wl = vif->wilc;
500 if (!wl->initialized) {
501 wl->mac_status = WILC_MAC_STATUS_INIT;
504 ret = wilc_wlan_init(dev);
508 ret = wlan_initialize_threads(dev);
512 if (wl->dev_irq_num && init_irq(dev)) {
517 if (!wl->dev_irq_num &&
518 wl->hif_func->enable_interrupt &&
519 wl->hif_func->enable_interrupt(wl)) {
524 ret = wilc_wlan_get_firmware(dev);
526 goto fail_irq_enable;
528 ret = wilc1000_firmware_download(dev);
530 goto fail_irq_enable;
532 ret = wilc_start_firmware(dev);
534 goto fail_irq_enable;
536 if (wilc_wlan_cfg_get(vif, 1, WID_FIRMWARE_VERSION, 1, 0)) {
538 char firmware_ver[WILC_MAX_FW_VERSION_STR_SIZE];
540 size = wilc_wlan_cfg_get_val(wl, WID_FIRMWARE_VERSION,
542 sizeof(firmware_ver));
543 firmware_ver[size] = '\0';
544 netdev_dbg(dev, "Firmware Ver = %s\n", firmware_ver);
547 ret = wilc_init_fw_config(dev, vif);
549 netdev_err(dev, "Failed to configure firmware\n");
552 wl->initialized = true;
556 wilc_wlan_stop(wl, vif);
559 if (!wl->dev_irq_num &&
560 wl->hif_func->disable_interrupt)
561 wl->hif_func->disable_interrupt(wl);
566 wlan_deinitialize_threads(dev);
568 wilc_wlan_cleanup(dev);
569 netdev_err(dev, "WLAN initialization FAILED\n");
571 netdev_dbg(dev, "wilc1000 already initialized\n");
576 static int mac_init_fn(struct net_device *ndev)
578 netif_start_queue(ndev);
579 netif_stop_queue(ndev);
584 static int wilc_mac_open(struct net_device *ndev)
586 struct wilc_vif *vif = netdev_priv(ndev);
587 struct wilc *wl = vif->wilc;
589 struct mgmt_frame_regs mgmt_regs = {};
590 u8 addr[ETH_ALEN] __aligned(2);
592 if (!wl || !wl->dev) {
593 netdev_err(ndev, "device not ready\n");
597 netdev_dbg(ndev, "MAC OPEN[%p]\n", ndev);
599 ret = wilc_init_host_int(ndev);
603 ret = wilc_wlan_initialize(ndev, vif);
605 wilc_deinit_host_int(ndev);
609 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif), vif->iftype,
612 if (is_valid_ether_addr(ndev->dev_addr)) {
613 ether_addr_copy(addr, ndev->dev_addr);
614 wilc_set_mac_address(vif, addr);
616 wilc_get_mac_address(vif, addr);
617 eth_hw_addr_set(ndev, addr);
619 netdev_dbg(ndev, "Mac address: %pM\n", ndev->dev_addr);
621 if (!is_valid_ether_addr(ndev->dev_addr)) {
622 netdev_err(ndev, "Wrong MAC address\n");
623 wilc_deinit_host_int(ndev);
624 wilc_wlan_deinitialize(ndev);
628 mgmt_regs.interface_stypes = vif->mgmt_reg_stypes;
629 /* so we detect a change */
630 vif->mgmt_reg_stypes = 0;
631 wilc_update_mgmt_frame_registrations(vif->ndev->ieee80211_ptr->wiphy,
632 vif->ndev->ieee80211_ptr,
634 netif_wake_queue(ndev);
640 static struct net_device_stats *mac_stats(struct net_device *dev)
642 struct wilc_vif *vif = netdev_priv(dev);
644 return &vif->netstats;
647 static int wilc_set_mac_addr(struct net_device *dev, void *p)
650 struct wilc_vif *vif = netdev_priv(dev);
651 struct wilc *wilc = vif->wilc;
652 struct sockaddr *addr = (struct sockaddr *)p;
653 unsigned char mac_addr[ETH_ALEN];
654 struct wilc_vif *tmp_vif;
657 if (!is_valid_ether_addr(addr->sa_data))
658 return -EADDRNOTAVAIL;
660 if (!vif->mac_opened) {
661 eth_commit_mac_addr_change(dev, p);
665 /* Verify MAC Address is not already in use: */
667 srcu_idx = srcu_read_lock(&wilc->srcu);
668 list_for_each_entry_rcu(tmp_vif, &wilc->vif_list, list) {
669 wilc_get_mac_address(tmp_vif, mac_addr);
670 if (ether_addr_equal(addr->sa_data, mac_addr)) {
671 if (vif != tmp_vif) {
672 srcu_read_unlock(&wilc->srcu, srcu_idx);
673 return -EADDRNOTAVAIL;
675 srcu_read_unlock(&wilc->srcu, srcu_idx);
679 srcu_read_unlock(&wilc->srcu, srcu_idx);
681 result = wilc_set_mac_address(vif, (u8 *)addr->sa_data);
685 eth_commit_mac_addr_change(dev, p);
689 static void wilc_set_multicast_list(struct net_device *dev)
691 struct netdev_hw_addr *ha;
692 struct wilc_vif *vif = netdev_priv(dev);
697 if (dev->flags & IFF_PROMISC)
700 if (dev->flags & IFF_ALLMULTI ||
701 dev->mc.count > WILC_MULTICAST_TABLE_SIZE) {
702 wilc_setup_multicast_filter(vif, 0, 0, NULL);
706 if (dev->mc.count == 0) {
707 wilc_setup_multicast_filter(vif, 1, 0, NULL);
711 mc_list = kmalloc_array(dev->mc.count, ETH_ALEN, GFP_ATOMIC);
717 netdev_for_each_mc_addr(ha, dev) {
718 memcpy(cur_mc, ha->addr, ETH_ALEN);
719 netdev_dbg(dev, "Entry[%d]: %pM\n", i, cur_mc);
724 if (wilc_setup_multicast_filter(vif, 1, dev->mc.count, mc_list))
728 static void wilc_tx_complete(void *priv, int status)
730 struct tx_complete_data *pv_data = priv;
732 dev_kfree_skb(pv_data->skb);
736 netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
738 struct wilc_vif *vif = netdev_priv(ndev);
739 struct wilc *wilc = vif->wilc;
740 struct tx_complete_data *tx_data = NULL;
743 if (skb->dev != ndev) {
744 netdev_err(ndev, "Packet not destined to this device\n");
749 tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC);
752 netif_wake_queue(ndev);
756 tx_data->buff = skb->data;
757 tx_data->size = skb->len;
760 vif->netstats.tx_packets++;
761 vif->netstats.tx_bytes += tx_data->size;
762 queue_count = wilc_wlan_txq_add_net_pkt(ndev, tx_data,
763 tx_data->buff, tx_data->size,
766 if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
768 struct wilc_vif *vif;
770 srcu_idx = srcu_read_lock(&wilc->srcu);
771 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
773 netif_stop_queue(vif->ndev);
775 srcu_read_unlock(&wilc->srcu, srcu_idx);
781 static int wilc_mac_close(struct net_device *ndev)
783 struct wilc_vif *vif = netdev_priv(ndev);
784 struct wilc *wl = vif->wilc;
786 netdev_dbg(ndev, "Mac close\n");
788 if (wl->open_ifcs > 0)
794 netif_stop_queue(vif->ndev);
796 wilc_handle_disconnect(vif);
797 wilc_deinit_host_int(vif->ndev);
800 if (wl->open_ifcs == 0) {
801 netdev_dbg(ndev, "Deinitializing wilc1000\n");
803 wilc_wlan_deinitialize(ndev);
811 void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size,
814 unsigned int frame_len = 0;
816 unsigned char *buff_to_send = NULL;
818 struct net_device *wilc_netdev;
819 struct wilc_vif *vif;
824 wilc_netdev = get_if_handler(wilc, buff);
829 vif = netdev_priv(wilc_netdev);
835 skb = dev_alloc_skb(frame_len);
839 skb->dev = wilc_netdev;
841 skb_put_data(skb, buff_to_send, frame_len);
843 skb->protocol = eth_type_trans(skb, wilc_netdev);
844 vif->netstats.rx_packets++;
845 vif->netstats.rx_bytes += frame_len;
846 skb->ip_summed = CHECKSUM_UNNECESSARY;
847 stats = netif_rx(skb);
848 netdev_dbg(wilc_netdev, "netif_rx ret value is: %d\n", stats);
852 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size, bool is_auth)
855 struct wilc_vif *vif;
857 srcu_idx = srcu_read_lock(&wilc->srcu);
858 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
859 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buff;
860 u16 type = le16_to_cpup((__le16 *)buff);
861 u32 type_bit = BIT(type >> 4);
862 u32 auth_bit = BIT(IEEE80211_STYPE_AUTH >> 4);
864 if ((vif->mgmt_reg_stypes & auth_bit &&
865 ieee80211_is_auth(mgmt->frame_control)) &&
866 vif->iftype == WILC_STATION_MODE && is_auth) {
867 wilc_wfi_mgmt_frame_rx(vif, buff, size);
871 if (vif->priv.p2p_listen_state &&
872 vif->mgmt_reg_stypes & type_bit)
873 wilc_wfi_p2p_rx(vif, buff, size);
875 if (vif->monitor_flag)
876 wilc_wfi_monitor_rx(wilc->monitor_dev, buff, size);
878 srcu_read_unlock(&wilc->srcu, srcu_idx);
881 static const struct net_device_ops wilc_netdev_ops = {
882 .ndo_init = mac_init_fn,
883 .ndo_open = wilc_mac_open,
884 .ndo_stop = wilc_mac_close,
885 .ndo_set_mac_address = wilc_set_mac_addr,
886 .ndo_start_xmit = wilc_mac_xmit,
887 .ndo_get_stats = mac_stats,
888 .ndo_set_rx_mode = wilc_set_multicast_list,
891 void wilc_netdev_cleanup(struct wilc *wilc)
893 struct wilc_vif *vif, *vif_tmp;
898 if (wilc->firmware) {
899 release_firmware(wilc->firmware);
900 wilc->firmware = NULL;
903 list_for_each_entry_safe(vif, vif_tmp, &wilc->vif_list, list) {
904 mutex_lock(&wilc->vif_mutex);
905 list_del_rcu(&vif->list);
907 mutex_unlock(&wilc->vif_mutex);
908 synchronize_srcu(&wilc->srcu);
910 unregister_netdev(vif->ndev);
913 wilc_wfi_deinit_mon_interface(wilc, false);
914 destroy_workqueue(wilc->hif_workqueue);
916 wilc_wlan_cfg_deinit(wilc);
917 wlan_deinit_locks(wilc);
918 wiphy_unregister(wilc->wiphy);
919 wiphy_free(wilc->wiphy);
921 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
923 static u8 wilc_get_available_idx(struct wilc *wl)
926 struct wilc_vif *vif;
929 srcu_idx = srcu_read_lock(&wl->srcu);
930 list_for_each_entry_rcu(vif, &wl->vif_list, list) {
936 srcu_read_unlock(&wl->srcu, srcu_idx);
940 struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
941 int vif_type, enum nl80211_iftype type,
944 struct net_device *ndev;
945 struct wilc_vif *vif;
948 ndev = alloc_etherdev(sizeof(*vif));
950 return ERR_PTR(-ENOMEM);
952 vif = netdev_priv(ndev);
953 ndev->ieee80211_ptr = &vif->priv.wdev;
954 strcpy(ndev->name, name);
959 ndev->netdev_ops = &wilc_netdev_ops;
961 SET_NETDEV_DEV(ndev, wiphy_dev(wl->wiphy));
963 vif->priv.wdev.wiphy = wl->wiphy;
964 vif->priv.wdev.netdev = ndev;
965 vif->priv.wdev.iftype = type;
966 vif->priv.dev = ndev;
969 ret = cfg80211_register_netdevice(ndev);
971 ret = register_netdev(ndev);
978 ndev->needs_free_netdev = true;
979 vif->iftype = vif_type;
980 vif->idx = wilc_get_available_idx(wl);
982 mutex_lock(&wl->vif_mutex);
983 list_add_tail_rcu(&vif->list, &wl->vif_list);
985 mutex_unlock(&wl->vif_mutex);
986 synchronize_srcu(&wl->srcu);
992 cfg80211_unregister_netdevice(ndev);
994 unregister_netdev(ndev);
999 MODULE_DESCRIPTION("Atmel WILC1000 core wireless driver");
1000 MODULE_LICENSE("GPL");