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 /* latest API version supported */
19 #define WILC1000_API_VER 1
21 #define WILC1000_FW_PREFIX "atmel/wilc1000_wifi_firmware-"
22 #define __WILC1000_FW(api) WILC1000_FW_PREFIX #api ".bin"
23 #define WILC1000_FW(api) __WILC1000_FW(api)
25 static irqreturn_t isr_uh_routine(int irq, void *user_data)
27 struct net_device *dev = user_data;
28 struct wilc_vif *vif = netdev_priv(dev);
29 struct wilc *wilc = vif->wilc;
32 netdev_err(dev, "Can't handle UH interrupt\n");
35 return IRQ_WAKE_THREAD;
38 static irqreturn_t isr_bh_routine(int irq, void *userdata)
40 struct net_device *dev = userdata;
41 struct wilc_vif *vif = netdev_priv(userdata);
42 struct wilc *wilc = vif->wilc;
45 netdev_err(dev, "Can't handle BH interrupt\n");
49 wilc_handle_isr(wilc);
54 static int init_irq(struct net_device *dev)
56 struct wilc_vif *vif = netdev_priv(dev);
57 struct wilc *wl = vif->wilc;
60 ret = request_threaded_irq(wl->dev_irq_num, isr_uh_routine,
62 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
65 netdev_err(dev, "Failed to request IRQ [%d]\n", ret);
68 netdev_dbg(dev, "IRQ request succeeded IRQ-NUM= %d\n", wl->dev_irq_num);
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)
98 struct net_device *ndev = NULL;
100 struct ieee80211_hdr *h = (struct ieee80211_hdr *)mac_header;
102 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
103 if (vif->mode == WILC_STATION_MODE)
104 if (ether_addr_equal_unaligned(h->addr2, vif->bssid)) {
108 if (vif->mode == WILC_AP_MODE)
109 if (ether_addr_equal_unaligned(h->addr1, vif->bssid)) {
118 void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode)
120 struct wilc_vif *vif = netdev_priv(wilc_netdev);
123 ether_addr_copy(vif->bssid, bssid);
125 eth_zero_addr(vif->bssid);
130 int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc)
134 struct wilc_vif *vif;
136 srcu_idx = srcu_read_lock(&wilc->srcu);
137 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
138 if (!is_zero_ether_addr(vif->bssid))
141 srcu_read_unlock(&wilc->srcu, srcu_idx);
145 static int wilc_txq_task(void *vp)
149 struct wilc *wl = vp;
151 complete(&wl->txq_thread_started);
153 wait_for_completion(&wl->txq_event);
156 complete(&wl->txq_thread_started);
158 while (!kthread_should_stop())
163 ret = wilc_wlan_handle_txq(wl, &txq_count);
164 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) {
166 struct wilc_vif *ifc;
168 srcu_idx = srcu_read_lock(&wl->srcu);
169 list_for_each_entry_rcu(ifc, &wl->vif_list,
171 if (ifc->mac_opened && ifc->ndev)
172 netif_wake_queue(ifc->ndev);
174 srcu_read_unlock(&wl->srcu, srcu_idx);
176 } while (ret == WILC_VMM_ENTRY_FULL_RETRY && !wl->close);
181 static int wilc_wlan_get_firmware(struct net_device *dev)
183 struct wilc_vif *vif = netdev_priv(dev);
184 struct wilc *wilc = vif->wilc;
186 const struct firmware *wilc_fw;
189 chip_id = wilc_get_chipid(wilc, false);
191 netdev_info(dev, "ChipID [%x] loading firmware [%s]\n", chip_id,
192 WILC1000_FW(WILC1000_API_VER));
194 ret = request_firmware(&wilc_fw, WILC1000_FW(WILC1000_API_VER),
197 netdev_err(dev, "%s - firmware not available\n",
198 WILC1000_FW(WILC1000_API_VER));
201 wilc->firmware = wilc_fw;
206 static int wilc_start_firmware(struct net_device *dev)
208 struct wilc_vif *vif = netdev_priv(dev);
209 struct wilc *wilc = vif->wilc;
212 ret = wilc_wlan_start(wilc);
216 if (!wait_for_completion_timeout(&wilc->sync_event,
217 msecs_to_jiffies(5000)))
223 static int wilc1000_firmware_download(struct net_device *dev)
225 struct wilc_vif *vif = netdev_priv(dev);
226 struct wilc *wilc = vif->wilc;
229 if (!wilc->firmware) {
230 netdev_err(dev, "Firmware buffer is NULL\n");
234 ret = wilc_wlan_firmware_download(wilc, wilc->firmware->data,
235 wilc->firmware->size);
239 release_firmware(wilc->firmware);
240 wilc->firmware = NULL;
242 netdev_dbg(dev, "Download Succeeded\n");
247 static int wilc_init_fw_config(struct net_device *dev, struct wilc_vif *vif)
249 struct wilc_priv *priv = &vif->priv;
250 struct host_if_drv *hif_drv;
255 netdev_dbg(dev, "Start configuring Firmware\n");
256 hif_drv = (struct host_if_drv *)priv->hif_drv;
257 netdev_dbg(dev, "Host = %p\n", hif_drv);
261 if (!wilc_wlan_cfg_set(vif, 1, WID_SET_OPERATION_MODE, (u8 *)&w, 4,
265 b = WILC_FW_BSS_TYPE_INFRA;
266 if (!wilc_wlan_cfg_set(vif, 0, WID_BSS_TYPE, &b, 1, 0, 0))
269 b = WILC_FW_TX_RATE_AUTO;
270 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_TX_RATE, &b, 1, 0, 0))
273 b = WILC_FW_OPER_MODE_G_MIXED_11B_2;
274 if (!wilc_wlan_cfg_set(vif, 0, WID_11G_OPERATING_MODE, &b, 1, 0, 0))
277 b = WILC_FW_PREAMBLE_SHORT;
278 if (!wilc_wlan_cfg_set(vif, 0, WID_PREAMBLE, &b, 1, 0, 0))
281 b = WILC_FW_11N_PROT_AUTO;
282 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_PROT_MECH, &b, 1, 0, 0))
285 b = WILC_FW_ACTIVE_SCAN;
286 if (!wilc_wlan_cfg_set(vif, 0, WID_SCAN_TYPE, &b, 1, 0, 0))
289 b = WILC_FW_SITE_SURVEY_OFF;
290 if (!wilc_wlan_cfg_set(vif, 0, WID_SITE_SURVEY, &b, 1, 0, 0))
295 if (!wilc_wlan_cfg_set(vif, 0, WID_RTS_THRESHOLD, (u8 *)&hw, 2, 0, 0))
300 if (!wilc_wlan_cfg_set(vif, 0, WID_FRAG_THRESHOLD, (u8 *)&hw, 2, 0, 0))
304 if (!wilc_wlan_cfg_set(vif, 0, WID_BCAST_SSID, &b, 1, 0, 0))
308 if (!wilc_wlan_cfg_set(vif, 0, WID_QOS_ENABLE, &b, 1, 0, 0))
311 b = WILC_FW_NO_POWERSAVE;
312 if (!wilc_wlan_cfg_set(vif, 0, WID_POWER_MANAGEMENT, &b, 1, 0, 0))
316 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_MODE, &b, 1, 0, 0))
319 b = WILC_FW_AUTH_OPEN_SYSTEM;
320 if (!wilc_wlan_cfg_set(vif, 0, WID_AUTH_TYPE, &b, 1, 0, 0))
324 if (!wilc_wlan_cfg_set(vif, 0, WID_LISTEN_INTERVAL, &b, 1, 0, 0))
328 if (!wilc_wlan_cfg_set(vif, 0, WID_DTIM_PERIOD, &b, 1, 0, 0))
331 b = WILC_FW_ACK_POLICY_NORMAL;
332 if (!wilc_wlan_cfg_set(vif, 0, WID_ACK_POLICY, &b, 1, 0, 0))
336 if (!wilc_wlan_cfg_set(vif, 0, WID_USER_CONTROL_ON_TX_POWER, &b, 1,
341 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11A, &b, 1, 0, 0))
345 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11B, &b, 1, 0, 0))
350 if (!wilc_wlan_cfg_set(vif, 0, WID_BEACON_INTERVAL, (u8 *)&hw, 2, 0, 0))
353 b = WILC_FW_REKEY_POLICY_DISABLE;
354 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_POLICY, &b, 1, 0, 0))
359 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PERIOD, (u8 *)&w, 4, 0, 0))
364 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PACKET_COUNT, (u8 *)&w, 4, 0,
369 if (!wilc_wlan_cfg_set(vif, 0, WID_SHORT_SLOT_ALLOWED, &b, 1, 0,
373 b = WILC_FW_ERP_PROT_SELF_CTS;
374 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ERP_PROT_TYPE, &b, 1, 0, 0))
378 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ENABLE, &b, 1, 0, 0))
381 b = WILC_FW_11N_OP_MODE_HT_MIXED;
382 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OPERATING_MODE, &b, 1, 0, 0))
386 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_TXOP_PROT_DISABLE, &b, 1, 0, 0))
389 b = WILC_FW_OBBS_NONHT_DETECT_PROTECT_REPORT;
390 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OBSS_NONHT_DETECTION, &b, 1,
394 b = WILC_FW_HT_PROT_RTS_CTS_NONHT;
395 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_HT_PROT_TYPE, &b, 1, 0, 0))
399 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_RIFS_PROT_ENABLE, &b, 1, 0,
404 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_CURRENT_TX_MCS, &b, 1, 0, 0))
408 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_IMMEDIATE_BA_ENABLED, &b, 1,
418 static void wlan_deinitialize_threads(struct net_device *dev)
420 struct wilc_vif *vif = netdev_priv(dev);
421 struct wilc *wl = vif->wilc;
425 complete(&wl->txq_event);
427 if (wl->txq_thread) {
428 kthread_stop(wl->txq_thread);
429 wl->txq_thread = NULL;
433 static void wilc_wlan_deinitialize(struct net_device *dev)
435 struct wilc_vif *vif = netdev_priv(dev);
436 struct wilc *wl = vif->wilc;
439 netdev_err(dev, "wl is NULL\n");
443 if (wl->initialized) {
444 netdev_info(dev, "Deinitializing wilc1000...\n");
446 if (!wl->dev_irq_num &&
447 wl->hif_func->disable_interrupt) {
448 mutex_lock(&wl->hif_cs);
449 wl->hif_func->disable_interrupt(wl);
450 mutex_unlock(&wl->hif_cs);
452 complete(&wl->txq_event);
454 wlan_deinitialize_threads(dev);
457 wilc_wlan_stop(wl, vif);
458 wilc_wlan_cleanup(dev);
460 wl->initialized = false;
462 netdev_dbg(dev, "wilc1000 deinitialization Done\n");
464 netdev_dbg(dev, "wilc1000 is not initialized\n");
468 static int wlan_initialize_threads(struct net_device *dev)
470 struct wilc_vif *vif = netdev_priv(dev);
471 struct wilc *wilc = vif->wilc;
473 wilc->txq_thread = kthread_run(wilc_txq_task, (void *)wilc,
475 if (IS_ERR(wilc->txq_thread)) {
476 netdev_err(dev, "couldn't create TXQ thread\n");
478 return PTR_ERR(wilc->txq_thread);
480 wait_for_completion(&wilc->txq_thread_started);
485 static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
488 struct wilc *wl = vif->wilc;
490 if (!wl->initialized) {
491 wl->mac_status = WILC_MAC_STATUS_INIT;
494 ret = wilc_wlan_init(dev);
498 ret = wlan_initialize_threads(dev);
502 if (wl->dev_irq_num && init_irq(dev)) {
507 if (!wl->dev_irq_num &&
508 wl->hif_func->enable_interrupt &&
509 wl->hif_func->enable_interrupt(wl)) {
514 ret = wilc_wlan_get_firmware(dev);
516 goto fail_irq_enable;
518 ret = wilc1000_firmware_download(dev);
520 goto fail_irq_enable;
522 ret = wilc_start_firmware(dev);
524 goto fail_irq_enable;
526 if (wilc_wlan_cfg_get(vif, 1, WID_FIRMWARE_VERSION, 1, 0)) {
528 char firmware_ver[20];
530 size = wilc_wlan_cfg_get_val(wl, WID_FIRMWARE_VERSION,
532 sizeof(firmware_ver));
533 firmware_ver[size] = '\0';
534 netdev_dbg(dev, "Firmware Ver = %s\n", firmware_ver);
537 ret = wilc_init_fw_config(dev, vif);
539 netdev_err(dev, "Failed to configure firmware\n");
542 wl->initialized = true;
546 wilc_wlan_stop(wl, vif);
549 if (!wl->dev_irq_num &&
550 wl->hif_func->disable_interrupt)
551 wl->hif_func->disable_interrupt(wl);
556 wlan_deinitialize_threads(dev);
558 wilc_wlan_cleanup(dev);
559 netdev_err(dev, "WLAN initialization FAILED\n");
561 netdev_dbg(dev, "wilc1000 already initialized\n");
566 static int mac_init_fn(struct net_device *ndev)
568 netif_start_queue(ndev);
569 netif_stop_queue(ndev);
574 static int wilc_mac_open(struct net_device *ndev)
576 struct wilc_vif *vif = netdev_priv(ndev);
577 struct wilc *wl = vif->wilc;
578 unsigned char mac_add[ETH_ALEN] = {0};
580 struct mgmt_frame_regs mgmt_regs = {};
582 if (!wl || !wl->dev) {
583 netdev_err(ndev, "device not ready\n");
587 netdev_dbg(ndev, "MAC OPEN[%p]\n", ndev);
589 ret = wilc_init_host_int(ndev);
593 ret = wilc_wlan_initialize(ndev, vif);
595 wilc_deinit_host_int(ndev);
599 wilc_set_operation_mode(vif, wilc_get_vif_idx(vif), vif->iftype,
601 wilc_get_mac_address(vif, mac_add);
602 netdev_dbg(ndev, "Mac address: %pM\n", mac_add);
603 ether_addr_copy(ndev->dev_addr, mac_add);
605 if (!is_valid_ether_addr(ndev->dev_addr)) {
606 netdev_err(ndev, "Wrong MAC address\n");
607 wilc_deinit_host_int(ndev);
608 wilc_wlan_deinitialize(ndev);
612 mgmt_regs.interface_stypes = vif->mgmt_reg_stypes;
613 /* so we detect a change */
614 vif->mgmt_reg_stypes = 0;
615 wilc_update_mgmt_frame_registrations(vif->ndev->ieee80211_ptr->wiphy,
616 vif->ndev->ieee80211_ptr,
618 netif_wake_queue(ndev);
624 static struct net_device_stats *mac_stats(struct net_device *dev)
626 struct wilc_vif *vif = netdev_priv(dev);
628 return &vif->netstats;
631 static int wilc_set_mac_addr(struct net_device *dev, void *p)
634 struct wilc_vif *vif = netdev_priv(dev);
635 struct wilc *wilc = vif->wilc;
636 struct sockaddr *addr = (struct sockaddr *)p;
637 unsigned char mac_addr[ETH_ALEN];
638 struct wilc_vif *tmp_vif;
641 if (!is_valid_ether_addr(addr->sa_data))
644 srcu_idx = srcu_read_lock(&wilc->srcu);
645 list_for_each_entry_rcu(tmp_vif, &wilc->vif_list, list) {
646 wilc_get_mac_address(tmp_vif, mac_addr);
647 if (ether_addr_equal(addr->sa_data, mac_addr)) {
648 if (vif != tmp_vif) {
649 srcu_read_unlock(&wilc->srcu, srcu_idx);
652 srcu_read_unlock(&wilc->srcu, srcu_idx);
656 srcu_read_unlock(&wilc->srcu, srcu_idx);
658 result = wilc_set_mac_address(vif, (u8 *)addr->sa_data);
662 ether_addr_copy(vif->bssid, addr->sa_data);
663 ether_addr_copy(vif->ndev->dev_addr, addr->sa_data);
668 static void wilc_set_multicast_list(struct net_device *dev)
670 struct netdev_hw_addr *ha;
671 struct wilc_vif *vif = netdev_priv(dev);
676 if (dev->flags & IFF_PROMISC)
679 if (dev->flags & IFF_ALLMULTI ||
680 dev->mc.count > WILC_MULTICAST_TABLE_SIZE) {
681 wilc_setup_multicast_filter(vif, 0, 0, NULL);
685 if (dev->mc.count == 0) {
686 wilc_setup_multicast_filter(vif, 1, 0, NULL);
690 mc_list = kmalloc_array(dev->mc.count, ETH_ALEN, GFP_ATOMIC);
696 netdev_for_each_mc_addr(ha, dev) {
697 memcpy(cur_mc, ha->addr, ETH_ALEN);
698 netdev_dbg(dev, "Entry[%d]: %pM\n", i, cur_mc);
703 if (wilc_setup_multicast_filter(vif, 1, dev->mc.count, mc_list))
707 static void wilc_tx_complete(void *priv, int status)
709 struct tx_complete_data *pv_data = priv;
711 dev_kfree_skb(pv_data->skb);
715 netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
717 struct wilc_vif *vif = netdev_priv(ndev);
718 struct wilc *wilc = vif->wilc;
719 struct tx_complete_data *tx_data = NULL;
722 if (skb->dev != ndev) {
723 netdev_err(ndev, "Packet not destined to this device\n");
727 tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC);
730 netif_wake_queue(ndev);
734 tx_data->buff = skb->data;
735 tx_data->size = skb->len;
738 vif->netstats.tx_packets++;
739 vif->netstats.tx_bytes += tx_data->size;
740 queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,
741 tx_data->buff, tx_data->size,
744 if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
746 struct wilc_vif *vif;
748 srcu_idx = srcu_read_lock(&wilc->srcu);
749 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
751 netif_stop_queue(vif->ndev);
753 srcu_read_unlock(&wilc->srcu, srcu_idx);
759 static int wilc_mac_close(struct net_device *ndev)
761 struct wilc_vif *vif = netdev_priv(ndev);
762 struct wilc *wl = vif->wilc;
764 netdev_dbg(ndev, "Mac close\n");
766 if (wl->open_ifcs > 0)
772 netif_stop_queue(vif->ndev);
774 wilc_deinit_host_int(vif->ndev);
777 if (wl->open_ifcs == 0) {
778 netdev_dbg(ndev, "Deinitializing wilc1000\n");
780 wilc_wlan_deinitialize(ndev);
788 void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size,
791 unsigned int frame_len = 0;
793 unsigned char *buff_to_send = NULL;
795 struct net_device *wilc_netdev;
796 struct wilc_vif *vif;
801 wilc_netdev = get_if_handler(wilc, buff);
806 vif = netdev_priv(wilc_netdev);
812 skb = dev_alloc_skb(frame_len);
816 skb->dev = wilc_netdev;
818 skb_put_data(skb, buff_to_send, frame_len);
820 skb->protocol = eth_type_trans(skb, wilc_netdev);
821 vif->netstats.rx_packets++;
822 vif->netstats.rx_bytes += frame_len;
823 skb->ip_summed = CHECKSUM_UNNECESSARY;
824 stats = netif_rx(skb);
825 netdev_dbg(wilc_netdev, "netif_rx ret value is: %d\n", stats);
829 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
832 struct wilc_vif *vif;
834 srcu_idx = srcu_read_lock(&wilc->srcu);
835 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
836 u16 type = le16_to_cpup((__le16 *)buff);
837 u32 type_bit = BIT(type >> 4);
839 if (vif->priv.p2p_listen_state &&
840 vif->mgmt_reg_stypes & type_bit)
841 wilc_wfi_p2p_rx(vif, buff, size);
843 if (vif->monitor_flag)
844 wilc_wfi_monitor_rx(wilc->monitor_dev, buff, size);
846 srcu_read_unlock(&wilc->srcu, srcu_idx);
849 static const struct net_device_ops wilc_netdev_ops = {
850 .ndo_init = mac_init_fn,
851 .ndo_open = wilc_mac_open,
852 .ndo_stop = wilc_mac_close,
853 .ndo_set_mac_address = wilc_set_mac_addr,
854 .ndo_start_xmit = wilc_mac_xmit,
855 .ndo_get_stats = mac_stats,
856 .ndo_set_rx_mode = wilc_set_multicast_list,
859 void wilc_netdev_cleanup(struct wilc *wilc)
861 struct wilc_vif *vif;
862 int srcu_idx, ifc_cnt = 0;
867 if (wilc->firmware) {
868 release_firmware(wilc->firmware);
869 wilc->firmware = NULL;
872 srcu_idx = srcu_read_lock(&wilc->srcu);
873 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
875 unregister_netdev(vif->ndev);
877 srcu_read_unlock(&wilc->srcu, srcu_idx);
879 wilc_wfi_deinit_mon_interface(wilc, false);
880 flush_workqueue(wilc->hif_workqueue);
881 destroy_workqueue(wilc->hif_workqueue);
883 while (ifc_cnt < WILC_NUM_CONCURRENT_IFC) {
884 mutex_lock(&wilc->vif_mutex);
885 if (wilc->vif_num <= 0) {
886 mutex_unlock(&wilc->vif_mutex);
889 vif = wilc_get_wl_to_vif(wilc);
891 list_del_rcu(&vif->list);
894 mutex_unlock(&wilc->vif_mutex);
895 synchronize_srcu(&wilc->srcu);
899 wilc_wlan_cfg_deinit(wilc);
900 wlan_deinit_locks(wilc);
901 kfree(wilc->bus_data);
902 wiphy_unregister(wilc->wiphy);
903 wiphy_free(wilc->wiphy);
905 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
907 static u8 wilc_get_available_idx(struct wilc *wl)
910 struct wilc_vif *vif;
913 srcu_idx = srcu_read_lock(&wl->srcu);
914 list_for_each_entry_rcu(vif, &wl->vif_list, list) {
920 srcu_read_unlock(&wl->srcu, srcu_idx);
924 struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
925 int vif_type, enum nl80211_iftype type,
928 struct net_device *ndev;
929 struct wilc_vif *vif;
932 ndev = alloc_etherdev(sizeof(*vif));
934 return ERR_PTR(-ENOMEM);
936 vif = netdev_priv(ndev);
937 ndev->ieee80211_ptr = &vif->priv.wdev;
938 strcpy(ndev->name, name);
943 ndev->netdev_ops = &wilc_netdev_ops;
945 SET_NETDEV_DEV(ndev, wiphy_dev(wl->wiphy));
947 vif->priv.wdev.wiphy = wl->wiphy;
948 vif->priv.wdev.netdev = ndev;
949 vif->priv.wdev.iftype = type;
950 vif->priv.dev = ndev;
953 ret = register_netdevice(ndev);
955 ret = register_netdev(ndev);
959 return ERR_PTR(-EFAULT);
962 ndev->needs_free_netdev = true;
963 vif->iftype = vif_type;
964 vif->idx = wilc_get_available_idx(wl);
966 mutex_lock(&wl->vif_mutex);
967 list_add_tail_rcu(&vif->list, &wl->vif_list);
969 mutex_unlock(&wl->vif_mutex);
970 synchronize_srcu(&wl->srcu);
975 MODULE_LICENSE("GPL");
976 MODULE_FIRMWARE(WILC1000_FW(WILC1000_API_VER));