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
22 #define WILC1000_FW_PREFIX "atmel/wilc1000_wifi_firmware-"
23 #define __WILC1000_FW(api) WILC1000_FW_PREFIX #api ".bin"
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 wait_for_completion(&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 && ifc->ndev)
170 netif_wake_queue(ifc->ndev);
172 srcu_read_unlock(&wl->srcu, srcu_idx);
174 } while (ret == WILC_VMM_ENTRY_FULL_RETRY && !wl->close);
179 static int wilc_wlan_get_firmware(struct net_device *dev)
181 struct wilc_vif *vif = netdev_priv(dev);
182 struct wilc *wilc = vif->wilc;
184 const struct firmware *wilc_fw;
187 chip_id = wilc_get_chipid(wilc, false);
189 netdev_info(dev, "ChipID [%x] loading firmware [%s]\n", chip_id,
190 WILC1000_FW(WILC1000_API_VER));
192 ret = request_firmware(&wilc_fw, WILC1000_FW(WILC1000_API_VER),
195 netdev_err(dev, "%s - firmware not available\n",
196 WILC1000_FW(WILC1000_API_VER));
199 wilc->firmware = wilc_fw;
204 static int wilc_start_firmware(struct net_device *dev)
206 struct wilc_vif *vif = netdev_priv(dev);
207 struct wilc *wilc = vif->wilc;
210 ret = wilc_wlan_start(wilc);
214 if (!wait_for_completion_timeout(&wilc->sync_event,
215 msecs_to_jiffies(5000)))
221 static int wilc1000_firmware_download(struct net_device *dev)
223 struct wilc_vif *vif = netdev_priv(dev);
224 struct wilc *wilc = vif->wilc;
227 if (!wilc->firmware) {
228 netdev_err(dev, "Firmware buffer is NULL\n");
232 ret = wilc_wlan_firmware_download(wilc, wilc->firmware->data,
233 wilc->firmware->size);
237 release_firmware(wilc->firmware);
238 wilc->firmware = NULL;
240 netdev_dbg(dev, "Download Succeeded\n");
245 static int wilc_init_fw_config(struct net_device *dev, struct wilc_vif *vif)
247 struct wilc_priv *priv = &vif->priv;
248 struct host_if_drv *hif_drv;
253 netdev_dbg(dev, "Start configuring Firmware\n");
254 hif_drv = (struct host_if_drv *)priv->hif_drv;
255 netdev_dbg(dev, "Host = %p\n", hif_drv);
259 if (!wilc_wlan_cfg_set(vif, 1, WID_SET_OPERATION_MODE, (u8 *)&w, 4,
263 b = WILC_FW_BSS_TYPE_INFRA;
264 if (!wilc_wlan_cfg_set(vif, 0, WID_BSS_TYPE, &b, 1, 0, 0))
267 b = WILC_FW_TX_RATE_AUTO;
268 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_TX_RATE, &b, 1, 0, 0))
271 b = WILC_FW_OPER_MODE_G_MIXED_11B_2;
272 if (!wilc_wlan_cfg_set(vif, 0, WID_11G_OPERATING_MODE, &b, 1, 0, 0))
275 b = WILC_FW_PREAMBLE_SHORT;
276 if (!wilc_wlan_cfg_set(vif, 0, WID_PREAMBLE, &b, 1, 0, 0))
279 b = WILC_FW_11N_PROT_AUTO;
280 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_PROT_MECH, &b, 1, 0, 0))
283 b = WILC_FW_ACTIVE_SCAN;
284 if (!wilc_wlan_cfg_set(vif, 0, WID_SCAN_TYPE, &b, 1, 0, 0))
287 b = WILC_FW_SITE_SURVEY_OFF;
288 if (!wilc_wlan_cfg_set(vif, 0, WID_SITE_SURVEY, &b, 1, 0, 0))
293 if (!wilc_wlan_cfg_set(vif, 0, WID_RTS_THRESHOLD, (u8 *)&hw, 2, 0, 0))
298 if (!wilc_wlan_cfg_set(vif, 0, WID_FRAG_THRESHOLD, (u8 *)&hw, 2, 0, 0))
302 if (!wilc_wlan_cfg_set(vif, 0, WID_BCAST_SSID, &b, 1, 0, 0))
306 if (!wilc_wlan_cfg_set(vif, 0, WID_QOS_ENABLE, &b, 1, 0, 0))
309 b = WILC_FW_NO_POWERSAVE;
310 if (!wilc_wlan_cfg_set(vif, 0, WID_POWER_MANAGEMENT, &b, 1, 0, 0))
314 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_MODE, &b, 1, 0, 0))
317 b = WILC_FW_AUTH_OPEN_SYSTEM;
318 if (!wilc_wlan_cfg_set(vif, 0, WID_AUTH_TYPE, &b, 1, 0, 0))
322 if (!wilc_wlan_cfg_set(vif, 0, WID_LISTEN_INTERVAL, &b, 1, 0, 0))
326 if (!wilc_wlan_cfg_set(vif, 0, WID_DTIM_PERIOD, &b, 1, 0, 0))
329 b = WILC_FW_ACK_POLICY_NORMAL;
330 if (!wilc_wlan_cfg_set(vif, 0, WID_ACK_POLICY, &b, 1, 0, 0))
334 if (!wilc_wlan_cfg_set(vif, 0, WID_USER_CONTROL_ON_TX_POWER, &b, 1,
339 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11A, &b, 1, 0, 0))
343 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11B, &b, 1, 0, 0))
348 if (!wilc_wlan_cfg_set(vif, 0, WID_BEACON_INTERVAL, (u8 *)&hw, 2, 0, 0))
351 b = WILC_FW_REKEY_POLICY_DISABLE;
352 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_POLICY, &b, 1, 0, 0))
357 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PERIOD, (u8 *)&w, 4, 0, 0))
362 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PACKET_COUNT, (u8 *)&w, 4, 0,
367 if (!wilc_wlan_cfg_set(vif, 0, WID_SHORT_SLOT_ALLOWED, &b, 1, 0,
371 b = WILC_FW_ERP_PROT_SELF_CTS;
372 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ERP_PROT_TYPE, &b, 1, 0, 0))
376 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ENABLE, &b, 1, 0, 0))
379 b = WILC_FW_11N_OP_MODE_HT_MIXED;
380 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OPERATING_MODE, &b, 1, 0, 0))
384 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_TXOP_PROT_DISABLE, &b, 1, 0, 0))
387 b = WILC_FW_OBBS_NONHT_DETECT_PROTECT_REPORT;
388 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OBSS_NONHT_DETECTION, &b, 1,
392 b = WILC_FW_HT_PROT_RTS_CTS_NONHT;
393 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_HT_PROT_TYPE, &b, 1, 0, 0))
397 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_RIFS_PROT_ENABLE, &b, 1, 0,
402 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_CURRENT_TX_MCS, &b, 1, 0, 0))
406 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_IMMEDIATE_BA_ENABLED, &b, 1,
416 static void wlan_deinitialize_threads(struct net_device *dev)
418 struct wilc_vif *vif = netdev_priv(dev);
419 struct wilc *wl = vif->wilc;
423 complete(&wl->txq_event);
425 if (wl->txq_thread) {
426 kthread_stop(wl->txq_thread);
427 wl->txq_thread = NULL;
431 static void wilc_wlan_deinitialize(struct net_device *dev)
433 struct wilc_vif *vif = netdev_priv(dev);
434 struct wilc *wl = vif->wilc;
437 netdev_err(dev, "wl is NULL\n");
441 if (wl->initialized) {
442 netdev_info(dev, "Deinitializing wilc1000...\n");
444 if (!wl->dev_irq_num &&
445 wl->hif_func->disable_interrupt) {
446 mutex_lock(&wl->hif_cs);
447 wl->hif_func->disable_interrupt(wl);
448 mutex_unlock(&wl->hif_cs);
450 complete(&wl->txq_event);
452 wlan_deinitialize_threads(dev);
455 wilc_wlan_stop(wl, vif);
456 wilc_wlan_cleanup(dev);
458 wl->initialized = false;
460 netdev_dbg(dev, "wilc1000 deinitialization Done\n");
462 netdev_dbg(dev, "wilc1000 is not initialized\n");
466 static int wlan_initialize_threads(struct net_device *dev)
468 struct wilc_vif *vif = netdev_priv(dev);
469 struct wilc *wilc = vif->wilc;
471 wilc->txq_thread = kthread_run(wilc_txq_task, (void *)wilc,
473 if (IS_ERR(wilc->txq_thread)) {
474 netdev_err(dev, "couldn't create TXQ thread\n");
476 return PTR_ERR(wilc->txq_thread);
478 wait_for_completion(&wilc->txq_thread_started);
483 static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
486 struct wilc *wl = vif->wilc;
488 if (!wl->initialized) {
489 wl->mac_status = WILC_MAC_STATUS_INIT;
492 ret = wilc_wlan_init(dev);
496 ret = wlan_initialize_threads(dev);
500 if (wl->dev_irq_num && init_irq(dev)) {
505 if (!wl->dev_irq_num &&
506 wl->hif_func->enable_interrupt &&
507 wl->hif_func->enable_interrupt(wl)) {
512 ret = wilc_wlan_get_firmware(dev);
514 goto fail_irq_enable;
516 ret = wilc1000_firmware_download(dev);
518 goto fail_irq_enable;
520 ret = wilc_start_firmware(dev);
522 goto fail_irq_enable;
524 if (wilc_wlan_cfg_get(vif, 1, WID_FIRMWARE_VERSION, 1, 0)) {
526 char firmware_ver[WILC_MAX_FW_VERSION_STR_SIZE];
528 size = wilc_wlan_cfg_get_val(wl, WID_FIRMWARE_VERSION,
530 sizeof(firmware_ver));
531 firmware_ver[size] = '\0';
532 netdev_dbg(dev, "Firmware Ver = %s\n", firmware_ver);
535 ret = wilc_init_fw_config(dev, vif);
537 netdev_err(dev, "Failed to configure firmware\n");
540 wl->initialized = true;
544 wilc_wlan_stop(wl, vif);
547 if (!wl->dev_irq_num &&
548 wl->hif_func->disable_interrupt)
549 wl->hif_func->disable_interrupt(wl);
554 wlan_deinitialize_threads(dev);
556 wilc_wlan_cleanup(dev);
557 netdev_err(dev, "WLAN initialization FAILED\n");
559 netdev_dbg(dev, "wilc1000 already initialized\n");
564 static int mac_init_fn(struct net_device *ndev)
566 netif_start_queue(ndev);
567 netif_stop_queue(ndev);
572 static int wilc_mac_open(struct net_device *ndev)
574 struct wilc_vif *vif = netdev_priv(ndev);
575 struct wilc *wl = vif->wilc;
577 struct mgmt_frame_regs mgmt_regs = {};
578 u8 addr[ETH_ALEN] __aligned(2);
580 if (!wl || !wl->dev) {
581 netdev_err(ndev, "device not ready\n");
585 netdev_dbg(ndev, "MAC OPEN[%p]\n", ndev);
587 ret = wilc_init_host_int(ndev);
591 ret = wilc_wlan_initialize(ndev, vif);
593 wilc_deinit_host_int(ndev);
597 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif), vif->iftype,
600 if (is_valid_ether_addr(ndev->dev_addr)) {
601 ether_addr_copy(addr, ndev->dev_addr);
602 wilc_set_mac_address(vif, addr);
604 wilc_get_mac_address(vif, addr);
605 eth_hw_addr_set(ndev, addr);
607 netdev_dbg(ndev, "Mac address: %pM\n", ndev->dev_addr);
609 if (!is_valid_ether_addr(ndev->dev_addr)) {
610 netdev_err(ndev, "Wrong MAC address\n");
611 wilc_deinit_host_int(ndev);
612 wilc_wlan_deinitialize(ndev);
616 mgmt_regs.interface_stypes = vif->mgmt_reg_stypes;
617 /* so we detect a change */
618 vif->mgmt_reg_stypes = 0;
619 wilc_update_mgmt_frame_registrations(vif->ndev->ieee80211_ptr->wiphy,
620 vif->ndev->ieee80211_ptr,
622 netif_wake_queue(ndev);
628 static struct net_device_stats *mac_stats(struct net_device *dev)
630 struct wilc_vif *vif = netdev_priv(dev);
632 return &vif->netstats;
635 static int wilc_set_mac_addr(struct net_device *dev, void *p)
638 struct wilc_vif *vif = netdev_priv(dev);
639 struct wilc *wilc = vif->wilc;
640 struct sockaddr *addr = (struct sockaddr *)p;
641 unsigned char mac_addr[ETH_ALEN];
642 struct wilc_vif *tmp_vif;
645 if (!is_valid_ether_addr(addr->sa_data))
646 return -EADDRNOTAVAIL;
648 if (!vif->mac_opened) {
649 eth_commit_mac_addr_change(dev, p);
653 /* Verify MAC Address is not already in use: */
655 srcu_idx = srcu_read_lock(&wilc->srcu);
656 list_for_each_entry_rcu(tmp_vif, &wilc->vif_list, list) {
657 wilc_get_mac_address(tmp_vif, mac_addr);
658 if (ether_addr_equal(addr->sa_data, mac_addr)) {
659 if (vif != tmp_vif) {
660 srcu_read_unlock(&wilc->srcu, srcu_idx);
661 return -EADDRNOTAVAIL;
663 srcu_read_unlock(&wilc->srcu, srcu_idx);
667 srcu_read_unlock(&wilc->srcu, srcu_idx);
669 result = wilc_set_mac_address(vif, (u8 *)addr->sa_data);
673 eth_commit_mac_addr_change(dev, p);
677 static void wilc_set_multicast_list(struct net_device *dev)
679 struct netdev_hw_addr *ha;
680 struct wilc_vif *vif = netdev_priv(dev);
685 if (dev->flags & IFF_PROMISC)
688 if (dev->flags & IFF_ALLMULTI ||
689 dev->mc.count > WILC_MULTICAST_TABLE_SIZE) {
690 wilc_setup_multicast_filter(vif, 0, 0, NULL);
694 if (dev->mc.count == 0) {
695 wilc_setup_multicast_filter(vif, 1, 0, NULL);
699 mc_list = kmalloc_array(dev->mc.count, ETH_ALEN, GFP_ATOMIC);
705 netdev_for_each_mc_addr(ha, dev) {
706 memcpy(cur_mc, ha->addr, ETH_ALEN);
707 netdev_dbg(dev, "Entry[%d]: %pM\n", i, cur_mc);
712 if (wilc_setup_multicast_filter(vif, 1, dev->mc.count, mc_list))
716 static void wilc_tx_complete(void *priv, int status)
718 struct tx_complete_data *pv_data = priv;
720 dev_kfree_skb(pv_data->skb);
724 netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
726 struct wilc_vif *vif = netdev_priv(ndev);
727 struct wilc *wilc = vif->wilc;
728 struct tx_complete_data *tx_data = NULL;
731 if (skb->dev != ndev) {
732 netdev_err(ndev, "Packet not destined to this device\n");
737 tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC);
740 netif_wake_queue(ndev);
744 tx_data->buff = skb->data;
745 tx_data->size = skb->len;
748 vif->netstats.tx_packets++;
749 vif->netstats.tx_bytes += tx_data->size;
750 queue_count = wilc_wlan_txq_add_net_pkt(ndev, tx_data,
751 tx_data->buff, tx_data->size,
754 if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
756 struct wilc_vif *vif;
758 srcu_idx = srcu_read_lock(&wilc->srcu);
759 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
761 netif_stop_queue(vif->ndev);
763 srcu_read_unlock(&wilc->srcu, srcu_idx);
769 static int wilc_mac_close(struct net_device *ndev)
771 struct wilc_vif *vif = netdev_priv(ndev);
772 struct wilc *wl = vif->wilc;
774 netdev_dbg(ndev, "Mac close\n");
776 if (wl->open_ifcs > 0)
782 netif_stop_queue(vif->ndev);
784 wilc_handle_disconnect(vif);
785 wilc_deinit_host_int(vif->ndev);
788 if (wl->open_ifcs == 0) {
789 netdev_dbg(ndev, "Deinitializing wilc1000\n");
791 wilc_wlan_deinitialize(ndev);
799 void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size,
802 unsigned int frame_len = 0;
804 unsigned char *buff_to_send = NULL;
806 struct net_device *wilc_netdev;
807 struct wilc_vif *vif;
812 wilc_netdev = get_if_handler(wilc, buff);
817 vif = netdev_priv(wilc_netdev);
823 skb = dev_alloc_skb(frame_len);
827 skb->dev = wilc_netdev;
829 skb_put_data(skb, buff_to_send, frame_len);
831 skb->protocol = eth_type_trans(skb, wilc_netdev);
832 vif->netstats.rx_packets++;
833 vif->netstats.rx_bytes += frame_len;
834 skb->ip_summed = CHECKSUM_UNNECESSARY;
835 stats = netif_rx(skb);
836 netdev_dbg(wilc_netdev, "netif_rx ret value is: %d\n", stats);
840 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size, bool is_auth)
843 struct wilc_vif *vif;
845 srcu_idx = srcu_read_lock(&wilc->srcu);
846 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
847 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buff;
848 u16 type = le16_to_cpup((__le16 *)buff);
849 u32 type_bit = BIT(type >> 4);
850 u32 auth_bit = BIT(IEEE80211_STYPE_AUTH >> 4);
852 if ((vif->mgmt_reg_stypes & auth_bit &&
853 ieee80211_is_auth(mgmt->frame_control)) &&
854 vif->iftype == WILC_STATION_MODE && is_auth) {
855 wilc_wfi_mgmt_frame_rx(vif, buff, size);
859 if (vif->priv.p2p_listen_state &&
860 vif->mgmt_reg_stypes & type_bit)
861 wilc_wfi_p2p_rx(vif, buff, size);
863 if (vif->monitor_flag)
864 wilc_wfi_monitor_rx(wilc->monitor_dev, buff, size);
866 srcu_read_unlock(&wilc->srcu, srcu_idx);
869 static const struct net_device_ops wilc_netdev_ops = {
870 .ndo_init = mac_init_fn,
871 .ndo_open = wilc_mac_open,
872 .ndo_stop = wilc_mac_close,
873 .ndo_set_mac_address = wilc_set_mac_addr,
874 .ndo_start_xmit = wilc_mac_xmit,
875 .ndo_get_stats = mac_stats,
876 .ndo_set_rx_mode = wilc_set_multicast_list,
879 void wilc_netdev_cleanup(struct wilc *wilc)
881 struct wilc_vif *vif;
882 int srcu_idx, ifc_cnt = 0;
887 if (wilc->firmware) {
888 release_firmware(wilc->firmware);
889 wilc->firmware = NULL;
892 srcu_idx = srcu_read_lock(&wilc->srcu);
893 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
895 unregister_netdev(vif->ndev);
897 srcu_read_unlock(&wilc->srcu, srcu_idx);
899 wilc_wfi_deinit_mon_interface(wilc, false);
900 destroy_workqueue(wilc->hif_workqueue);
902 while (ifc_cnt < WILC_NUM_CONCURRENT_IFC) {
903 mutex_lock(&wilc->vif_mutex);
904 if (wilc->vif_num <= 0) {
905 mutex_unlock(&wilc->vif_mutex);
908 vif = wilc_get_wl_to_vif(wilc);
910 list_del_rcu(&vif->list);
913 mutex_unlock(&wilc->vif_mutex);
914 synchronize_srcu(&wilc->srcu);
918 wilc_wlan_cfg_deinit(wilc);
919 wlan_deinit_locks(wilc);
920 wiphy_unregister(wilc->wiphy);
921 wiphy_free(wilc->wiphy);
923 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
925 static u8 wilc_get_available_idx(struct wilc *wl)
928 struct wilc_vif *vif;
931 srcu_idx = srcu_read_lock(&wl->srcu);
932 list_for_each_entry_rcu(vif, &wl->vif_list, list) {
938 srcu_read_unlock(&wl->srcu, srcu_idx);
942 struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
943 int vif_type, enum nl80211_iftype type,
946 struct net_device *ndev;
947 struct wilc_vif *vif;
950 ndev = alloc_etherdev(sizeof(*vif));
952 return ERR_PTR(-ENOMEM);
954 vif = netdev_priv(ndev);
955 ndev->ieee80211_ptr = &vif->priv.wdev;
956 strcpy(ndev->name, name);
961 ndev->netdev_ops = &wilc_netdev_ops;
963 SET_NETDEV_DEV(ndev, wiphy_dev(wl->wiphy));
965 vif->priv.wdev.wiphy = wl->wiphy;
966 vif->priv.wdev.netdev = ndev;
967 vif->priv.wdev.iftype = type;
968 vif->priv.dev = ndev;
971 ret = cfg80211_register_netdevice(ndev);
973 ret = register_netdev(ndev);
980 wl->hif_workqueue = alloc_ordered_workqueue("%s-wq", WQ_MEM_RECLAIM,
982 if (!wl->hif_workqueue) {
984 goto unregister_netdev;
987 ndev->needs_free_netdev = true;
988 vif->iftype = vif_type;
989 vif->idx = wilc_get_available_idx(wl);
991 mutex_lock(&wl->vif_mutex);
992 list_add_tail_rcu(&vif->list, &wl->vif_list);
994 mutex_unlock(&wl->vif_mutex);
995 synchronize_srcu(&wl->srcu);
1001 cfg80211_unregister_netdevice(ndev);
1003 unregister_netdev(ndev);
1006 return ERR_PTR(ret);
1009 MODULE_LICENSE("GPL");
1010 MODULE_FIRMWARE(WILC1000_FW(WILC1000_API_VER));